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
|
*.user
|
||||||
build*
|
build*
|
||||||
*.so
|
|
||||||
teams/*.dll
|
teams/*.dll
|
||||||
teams/*.so
|
teams/*.so
|
||||||
generators/*.dll
|
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)
|
#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){
|
switch(type){
|
||||||
case Pixel::BEDROCK : return HEX_TO_VEC3(0x101020);
|
case Pixel::BEDROCK : return HEX_TO_VEC3(0x101020);
|
||||||
|
@ -9,13 +9,6 @@
|
|||||||
struct MapScene : public Map, public BasicScene
|
struct MapScene : public Map, public BasicScene
|
||||||
{
|
{
|
||||||
public:
|
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(int n, int w, int h=0) : Map(n, w, h) {}
|
||||||
|
|
||||||
~MapScene();
|
~MapScene();
|
||||||
@ -24,11 +17,18 @@ public:
|
|||||||
void initDraw();
|
void initDraw();
|
||||||
bool updateNecessary() { return !m_pixels.empty(); }
|
bool updateNecessary() { return !m_pixels.empty(); }
|
||||||
void draw();
|
void draw();
|
||||||
|
static glm::vec3 getColor(Pixel::Type type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int m_vao;
|
unsigned int m_vao;
|
||||||
unsigned int m_vbo;
|
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;
|
std::vector<Pix> m_pixels;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "dude.h"
|
#include "dude.h"
|
||||||
#include "mapscene.h"
|
#include "mapscene.h"
|
||||||
|
|
||||||
Simulation::Simulation(Map *_map, std::vector<BehaviorFunction> &_behaviors):
|
Simulation::Simulation(MapScene *_map, std::vector<BehaviorFunction> &_behaviors):
|
||||||
p_map(_map)
|
p_map(_map)
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
|
@ -10,11 +10,11 @@ class MapScene;
|
|||||||
class Simulation
|
class Simulation
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Map *p_map;
|
MapScene *p_map;
|
||||||
std::vector<Dude*> m_dudes;
|
std::vector<Dude*> m_dudes;
|
||||||
std::vector<Team> m_teams;
|
std::vector<Team> m_teams;
|
||||||
public:
|
public:
|
||||||
Simulation(Map *_map, std::vector<BehaviorFunction> &_behaviors);
|
Simulation(MapScene *_map, std::vector<BehaviorFunction> &_behaviors);
|
||||||
MapScene* getMap() { return (MapScene*) p_map; }
|
MapScene* getMap() { return (MapScene*) p_map; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,6 +26,7 @@ SimulationDialog::SimulationDialog(QWidget *parent) :
|
|||||||
refreshBehaviors();
|
refreshBehaviors();
|
||||||
refreshGenerators();
|
refreshGenerators();
|
||||||
ui->generatorsList->setCurrentRow(0);
|
ui->generatorsList->setCurrentRow(0);
|
||||||
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
SimulationDialog::~SimulationDialog()
|
SimulationDialog::~SimulationDialog()
|
||||||
@ -117,13 +118,34 @@ void SimulationDialog::generateMap()
|
|||||||
{
|
{
|
||||||
m_map = new MapScene(m_selectedBehaviors.size(), ui->mapSizeSpinBox->value());
|
m_map = new MapScene(m_selectedBehaviors.size(), ui->mapSizeSpinBox->value());
|
||||||
func((Map*)m_map);
|
func((Map*)m_map);
|
||||||
// QPixmap preview();
|
updatePreview();
|
||||||
// TODO : display map in preview
|
|
||||||
}
|
}
|
||||||
lib.unload();
|
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)
|
void SimulationDialog::selectBehavior(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->behaviorsList->item(index.row());
|
QListWidgetItem* item = ui->behaviorsList->item(index.row());
|
||||||
|
@ -31,6 +31,7 @@ private slots:
|
|||||||
void refreshBehaviors();
|
void refreshBehaviors();
|
||||||
void refreshGenerators();
|
void refreshGenerators();
|
||||||
void generateMap();
|
void generateMap();
|
||||||
|
void updatePreview();
|
||||||
void selectBehavior(const QModelIndex &index);
|
void selectBehavior(const QModelIndex &index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user