fixed framebuffer bug, added map preview

This commit is contained in:
Anselme 2016-05-20 13:24:13 +02:00
parent 88d43e9f74
commit 865b64ede0
7 changed files with 37 additions and 15 deletions

1
.gitignore vendored
View File

@ -1,6 +1,5 @@
*.user
build*
*.so
teams/*.dll
teams/*.so
generators/*.dll

View File

@ -3,7 +3,7 @@
#define HEX_TO_VEC3(hex) glm::vec3(float((hex & 0xFF0000) >> 16)/255, float((hex & 0x00FF00) >> 8)/255, float(hex & 0x0000FF)/255)
inline glm::vec3 getColor(Pixel::Type type)
glm::vec3 MapScene::getColor(Pixel::Type type)
{
switch(type){
case Pixel::BEDROCK : return HEX_TO_VEC3(0x101020);

View File

@ -9,13 +9,6 @@
struct MapScene : public Map, public BasicScene
{
public:
struct Pix
{
glm::vec2 pos;
glm::vec3 color;
Pix(glm::vec2 p, glm::vec3 c) : pos(p), color(c) {}
};
MapScene(int n, int w, int h=0) : Map(n, w, h) {}
~MapScene();
@ -24,11 +17,18 @@ public:
void initDraw();
bool updateNecessary() { return !m_pixels.empty(); }
void draw();
static glm::vec3 getColor(Pixel::Type type);
private:
unsigned int m_vao;
unsigned int m_vbo;
struct Pix
{
glm::vec2 pos;
glm::vec3 color;
Pix(glm::vec2 p, glm::vec3 c) : pos(p), color(c) {}
};
std::vector<Pix> m_pixels;
};

View File

@ -5,7 +5,7 @@
#include "dude.h"
#include "mapscene.h"
Simulation::Simulation(Map *_map, std::vector<BehaviorFunction> &_behaviors):
Simulation::Simulation(MapScene *_map, std::vector<BehaviorFunction> &_behaviors):
p_map(_map)
{
int i=0;

View File

@ -10,11 +10,11 @@ class MapScene;
class Simulation
{
private:
Map *p_map;
MapScene *p_map;
std::vector<Dude*> m_dudes;
std::vector<Team> m_teams;
public:
Simulation(Map *_map, std::vector<BehaviorFunction> &_behaviors);
Simulation(MapScene *_map, std::vector<BehaviorFunction> &_behaviors);
MapScene* getMap() { return (MapScene*) p_map; }
/**

View File

@ -26,6 +26,7 @@ SimulationDialog::SimulationDialog(QWidget *parent) :
refreshBehaviors();
refreshGenerators();
ui->generatorsList->setCurrentRow(0);
updatePreview();
}
SimulationDialog::~SimulationDialog()
@ -117,13 +118,34 @@ void SimulationDialog::generateMap()
{
m_map = new MapScene(m_selectedBehaviors.size(), ui->mapSizeSpinBox->value());
func((Map*)m_map);
// QPixmap preview();
// TODO : display map in preview
updatePreview();
}
lib.unload();
}
}
void SimulationDialog::updatePreview()
{
int w = ui->mapSizeSpinBox->value();
int h = w/2;
QImage preview(w, h, QImage::Format_RGB32);
// init pixels
if(m_map != NULL)
{
for(int i=0; i<w; ++i)
for(int j=0; j<h; ++j)
{
const Pixel &p = m_map->getPixel(Coord(i, j));
glm::vec3 color = MapScene::getColor(p.type);
preview.setPixel(i, j, qRgb(int(color.r*255), int(color.g*255), int(color.b*255)));
}
}
else
preview.fill(Qt::black);
// update preview
ui->mapPreview->setPixmap(QPixmap::fromImage(preview));
}
void SimulationDialog::selectBehavior(const QModelIndex &index)
{
QListWidgetItem* item = ui->behaviorsList->item(index.row());

View File

@ -31,6 +31,7 @@ private slots:
void refreshBehaviors();
void refreshGenerators();
void generateMap();
void updatePreview();
void selectBehavior(const QModelIndex &index);
private: