fixed some uninitialized value and bad deletion of pointer

This commit is contained in:
Lendemor 2016-05-28 10:55:34 +02:00
parent ff64c7b780
commit d34076c4d4
6 changed files with 52 additions and 20 deletions

View File

@ -7,25 +7,25 @@
extern "C" void generate(Map *mapPtr)
{
Map &map = *mapPtr;
int w = map.getWidth();
int h = map.getHeight();
int n = map.getNbTeams();
int i, j, k;
Map &map = *mapPtr;
int w = map.getWidth();
int h = map.getHeight();
int n = map.getNbTeams();
int i, j, k;
for(i=0; i<n; i++)
map.team(i) = Coord((w/(n*2))*(1+i*2), h/2);
for(i=0; i<n; i++)
map.team(i) = Coord((w/(n*2))*(1+i*2), h/2);
int r = h;
if(n != 0)
r = (w/n < h ? w/n : h)/2;
int r = h;
if(n != 0)
r = (w/n < h ? w/n : h)/2;
//génération de la carte
for (i=0;i<w;i++){
for(j=0;j<h;j++){
int d = std::max(w, h);
if(n == 0)
d = h;
d = h;
for(k=0; k<n; k++){
d = std::min(d, map.team(k).dist(i, j));
if(!d)

View File

@ -0,0 +1,36 @@
#include <map.h>
#include <cmath>
#include <cstdlib>
#include <algorithm>
// g++ -shared test_library.cpp -o test_library.so -I../src -fPIC
extern "C" void generate(Map *mapPtr)
{
Map &map = *mapPtr;
int w = map.getWidth();
int h = map.getHeight();
int n = map.getNbTeams();
int i, j, k;
for(i=0;i<w;i++){
for(j=0;j<h;j++){
map[i][j].type = GRASS;
}
}
for(i=0; i<n; i++)
map.team(i) = Coord((w/(n*2))*(1+i*2), h/2);
Coord north = Coord(NORTH);
for(i=0; i<n; i++){
// Coord &spawn = map.team(i);
Coord lib(map.team(i));
lib+=north;
lib+=north;
map[map.team(i)].type=SPAWN;
map[map.team(i)].data.nbRes = 1;
map[lib].type=LIBRARY;
map[lib].data.knowledge = new char[LIBRARY_SIZE];
}
}

View File

@ -18,7 +18,7 @@ Map::Map(int nbTeams, int width, int height) :
Map::~Map()
{
delete m_map;
delete[] m_map;
if(m_nbTeams)
delete m_teams;
}

View File

@ -38,7 +38,7 @@ MapScene::~MapScene()
glDeleteVertexArrays(1, &m_vao);
m_vao = 0;
}
delete m_teamColors;
delete[] m_teamColors;
}
void MapScene::updatePixel(const Coord &c)

View File

@ -11,7 +11,7 @@
struct MapScene : public Map, public BasicScene
{
public:
MapScene(int n, int w, int h=0) : Map(n, w, h), m_teamColors(new TeamColor[n]) {}
MapScene(int n, int w, int h=0) : Map(n, w, h), m_teamColors(new TeamColor[n]),m_vao(0),m_vbo(0) {}
~MapScene();

View File

@ -37,17 +37,15 @@ void Simulation::update()
if(t.updateSpawn())
{
Coord spawnPos = p_map->team(i) + Coord(Dir(rand()%4));
std::cout << p_map->getPixel(spawnPos).type << std::endl;
if(PixelProperty::isWalkable(p_map->getPixel(spawnPos).type))
{
Dude *dude = new Dude(spawnPos,p_map,i);
(*p_map)[spawnPos].data.dudePtr = dude;
p_map->updatePixel(spawnPos);
m_dudes.push_back(dude);
}
}/*
else
std::cout << "Unpopable" << std::endl;
// TODO check other case or delay the spawning
// TODO check other case or delay the spawning*/
}
}
}
@ -213,8 +211,6 @@ void Simulation::handleAction(const Action &action, Dude *dude)
}
else{
target.writeBook(action.com_data);
// TODO: understand what the fuck this line is doing bis
//memcpy(target.data.knowledge + action->com_data.flag, action->com_data.data, COM_SIZE);
dude->setSuccess(true);
}
break;