fixed framebuffer bug, added map preview
This commit is contained in:
parent
88d43e9f74
commit
865b64ede0
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,5 @@
|
||||
*.user
|
||||
build*
|
||||
*.so
|
||||
teams/*.dll
|
||||
teams/*.so
|
||||
generators/*.dll
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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; }
|
||||
|
||||
/**
|
||||
|
@ -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());
|
||||
|
@ -31,6 +31,7 @@ private slots:
|
||||
void refreshBehaviors();
|
||||
void refreshGenerators();
|
||||
void generateMap();
|
||||
void updatePreview();
|
||||
void selectBehavior(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user