- more memory cleanup
This commit is contained in:
parent
63cf199322
commit
958184e018
|
@ -40,30 +40,41 @@ const int PathFinder::pathFindRefresh= 10;
|
|||
|
||||
|
||||
PathFinder::PathFinder(){
|
||||
nodePool= NULL;
|
||||
//nodePool= NULL;
|
||||
nodePool.clear();
|
||||
map=NULL;
|
||||
}
|
||||
|
||||
PathFinder::PathFinder(const Map *map){
|
||||
nodePool= NULL;
|
||||
//nodePool= NULL;
|
||||
nodePool.clear();
|
||||
map=NULL;
|
||||
init(map);
|
||||
}
|
||||
|
||||
void PathFinder::init(const Map *map){
|
||||
if(nodePool != NULL) {
|
||||
delete [] nodePool;
|
||||
nodePool = NULL;
|
||||
}
|
||||
nodePool= new Node[pathFindNodesMax];
|
||||
//if(nodePool != NULL) {
|
||||
// delete [] nodePool;
|
||||
// nodePool = NULL;
|
||||
//}
|
||||
//nodePool= new Node[pathFindNodesMax];
|
||||
nodePool.resize(pathFindNodesMax);
|
||||
|
||||
this->map= map;
|
||||
}
|
||||
|
||||
PathFinder::~PathFinder(){
|
||||
delete [] nodePool;
|
||||
nodePool = NULL;
|
||||
//delete [] nodePool;
|
||||
//nodePool = NULL;
|
||||
nodePool.clear();
|
||||
map=NULL;
|
||||
}
|
||||
|
||||
TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){
|
||||
|
||||
if(map == NULL) {
|
||||
throw runtime_error("map == NULL");
|
||||
}
|
||||
//route cache
|
||||
UnitPathInterface *path= unit->getPath();
|
||||
if(finalPos==unit->getPos()) {
|
||||
|
@ -148,6 +159,10 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){
|
|||
Chrono chrono;
|
||||
chrono.start();
|
||||
|
||||
if(map == NULL) {
|
||||
throw runtime_error("map == NULL");
|
||||
}
|
||||
|
||||
nodePoolCount= 0;
|
||||
const Vec2i finalPos= computeNearestFreePos(unit, targetPos);
|
||||
|
||||
|
@ -163,8 +178,9 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){
|
|||
assert(firstNode!=NULL);;
|
||||
firstNode->next= NULL;
|
||||
firstNode->prev= NULL;
|
||||
firstNode->pos= unit->getPos();
|
||||
firstNode->heuristic= heuristic(unit->getPos(), finalPos);
|
||||
const Vec2i unitPos = unit->getPos();
|
||||
firstNode->pos= unitPos;
|
||||
firstNode->heuristic= heuristic(unitPos, finalPos);
|
||||
firstNode->exploredCell= true;
|
||||
openNodes.push_back(firstNode);
|
||||
|
||||
|
@ -188,7 +204,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){
|
|||
node= *it;
|
||||
|
||||
//b3) if minHeuristic is the finalNode, or the path is no more explored => path was found
|
||||
if(node->pos==finalPos || !node->exploredCell){
|
||||
if(node->pos == finalPos || node->exploredCell == false) {
|
||||
pathFound= true;
|
||||
break;
|
||||
}
|
||||
|
@ -200,7 +216,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){
|
|||
for(int i=-1; i<=1 && !nodeLimitReached; ++i){
|
||||
for(int j=-1; j<=1 && !nodeLimitReached; ++j){
|
||||
Vec2i sucPos= node->pos + Vec2i(i, j);
|
||||
if(!openPos(sucPos) && map->aproxCanMove(unit, node->pos, sucPos)){
|
||||
if(openPos(sucPos) == false && map->aproxCanMove(unit, node->pos, sucPos)){
|
||||
//if node is not open and canMove then generate another node
|
||||
Node *sucNode= newNode();
|
||||
if(sucNode!=NULL){
|
||||
|
@ -257,7 +273,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){
|
|||
|
||||
currNode= firstNode;
|
||||
for(int i=0; currNode->next!=NULL && i<pathFindRefresh; currNode= currNode->next, i++){
|
||||
path->push(currNode->next->pos);
|
||||
path->add(currNode->next->pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,6 +296,9 @@ PathFinder::Node *PathFinder::newNode(){
|
|||
}
|
||||
|
||||
Vec2i PathFinder::computeNearestFreePos(const Unit *unit, const Vec2i &finalPos){
|
||||
if(map == NULL) {
|
||||
throw runtime_error("map == NULL");
|
||||
}
|
||||
|
||||
//unit data
|
||||
Vec2i unitPos= unit->getPos();
|
||||
|
|
|
@ -34,7 +34,14 @@ class Unit;
|
|||
|
||||
class PathFinder {
|
||||
public:
|
||||
struct Node{
|
||||
class Node {
|
||||
public:
|
||||
Node() : pos(0,0) {
|
||||
next=NULL;
|
||||
prev=NULL;
|
||||
heuristic=0.0;
|
||||
exploredCell=false;
|
||||
}
|
||||
Vec2i pos;
|
||||
Node *next;
|
||||
Node *prev;
|
||||
|
@ -51,7 +58,8 @@ public:
|
|||
private:
|
||||
Nodes openNodes;
|
||||
Nodes closedNodes;
|
||||
Node *nodePool;
|
||||
//Node *nodePool;
|
||||
std::vector<Node> nodePool;
|
||||
int nodePoolCount;
|
||||
const Map *map;
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@ Game::Game(Program *program, const GameSettings *gameSettings):
|
|||
// GameConstants::cameraFps= 50;
|
||||
GameConstants::updateFps= 40;
|
||||
GameConstants::cameraFps= 100;
|
||||
captureAvgTestStatus = false;
|
||||
lastRenderLog2d = 0;
|
||||
|
||||
quitTriggeredIndicator = false;
|
||||
originalDisplayMsgCallback = NULL;
|
||||
|
@ -1502,7 +1504,7 @@ void Game::render2d(){
|
|||
perfLogging = true;
|
||||
}
|
||||
|
||||
string str;
|
||||
string str="";
|
||||
std::map<int,string> factionDebugInfo;
|
||||
|
||||
if( renderer.getShowDebugUI() == true ||
|
||||
|
|
|
@ -59,7 +59,7 @@ void UnitPathBasic::incBlockCount() {
|
|||
blockCount++;
|
||||
}
|
||||
|
||||
void UnitPathBasic::push(const Vec2i &path){
|
||||
void UnitPathBasic::add(const Vec2i &path){
|
||||
pathQueue.push_back(path);
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ public:
|
|||
virtual void clear() = 0;
|
||||
virtual void clearBlockCount() = 0;
|
||||
virtual void incBlockCount() = 0;
|
||||
virtual void push(const Vec2i &path) = 0;
|
||||
virtual void add(const Vec2i &path) = 0;
|
||||
//virtual Vec2i pop() = 0;
|
||||
|
||||
virtual std::string toString() const = 0;
|
||||
|
@ -129,7 +129,7 @@ public:
|
|||
virtual void clear();
|
||||
virtual void clearBlockCount() { blockCount = 0; }
|
||||
virtual void incBlockCount();
|
||||
virtual void push(const Vec2i &path);
|
||||
virtual void add(const Vec2i &path);
|
||||
Vec2i pop();
|
||||
|
||||
virtual std::string toString() const;
|
||||
|
@ -156,9 +156,9 @@ public:
|
|||
virtual void clear() {list<Vec2i>::clear(); blockCount = 0;} /**< clear the path */
|
||||
virtual void clearBlockCount() { blockCount = 0; }
|
||||
virtual void incBlockCount() {++blockCount;} /**< increment block counter */
|
||||
virtual void push(const Vec2i &pos) {push_front(pos);} /**< push onto front of path */
|
||||
virtual void push(Vec2i &pos) {push_front(pos);} /**< push onto front of path */
|
||||
bool empty() const {return list<Vec2i>::empty();} /**< is path empty */
|
||||
void push(Vec2i &pos) {push_front(pos);} /**< push onto front of path */
|
||||
virtual void add(const Vec2i &pos) { push_front(pos);} /**< push onto front of path */
|
||||
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Martiño Figueroa
|
||||
// Copyright (C) 2001-2008 Martio Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
|
@ -28,6 +28,16 @@ namespace Glest{ namespace Game{
|
|||
// class ResourceType
|
||||
// =====================================================
|
||||
|
||||
ResourceType::ResourceType() {
|
||||
resourceClass=rcTech;
|
||||
tilesetObject=0;
|
||||
resourceNumber=0;
|
||||
interval=0;
|
||||
defResPerPatch=0;
|
||||
recoup_cost = false;
|
||||
model = NULL;
|
||||
}
|
||||
|
||||
void ResourceType::load(const string &dir, Checksum* checksum){
|
||||
|
||||
string path, str;
|
||||
|
|
|
@ -47,6 +47,7 @@ private:
|
|||
Model *model;
|
||||
|
||||
public:
|
||||
ResourceType();
|
||||
void load(const string &dir, Checksum* checksum);
|
||||
|
||||
//get
|
||||
|
|
|
@ -198,6 +198,9 @@ const ResourceType *TechTree::getTechResourceType(int i) const{
|
|||
for(int j=0; j < getResourceTypeCount(); ++j){
|
||||
const ResourceType *rt= getResourceType(j);
|
||||
assert(rt != NULL);
|
||||
if(rt == NULL) {
|
||||
throw runtime_error("rt == NULL");
|
||||
}
|
||||
if(rt->getResourceNumber() == i && rt->getClass() == rcTech)
|
||||
return getResourceType(j);
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ UnitType::UnitType(){
|
|||
light= false;
|
||||
multiSelect= false;
|
||||
armorType= NULL;
|
||||
rotatedBuildPos=0;
|
||||
|
||||
for(int i=0; i<ccCount; ++i){
|
||||
firstCommandTypeOfClass[i]= NULL;
|
||||
|
|
|
@ -33,6 +33,7 @@ class Vec2{
|
|||
public:
|
||||
T x;
|
||||
T y;
|
||||
|
||||
public:
|
||||
Vec2(){
|
||||
};
|
||||
|
@ -52,6 +53,11 @@ public:
|
|||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
}
|
||||
template<typename S>
|
||||
explicit Vec2(Vec2<S> &v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
}
|
||||
|
||||
Vec2(T x, T y){
|
||||
this->x= x;
|
||||
|
@ -66,6 +72,12 @@ public:
|
|||
return reinterpret_cast<const T*>(this);
|
||||
}
|
||||
|
||||
Vec2<T> & operator=(const Vec2<T> &v) {
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator ==(const Vec2<T> &v) const{
|
||||
return x==v.x && y==v.y;
|
||||
}
|
||||
|
@ -201,6 +213,13 @@ public:
|
|||
this->z= v.z;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
explicit Vec3(Vec3<S> &v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
}
|
||||
|
||||
Vec3(T x, T y, T z){
|
||||
this->x= x;
|
||||
this->y= y;
|
||||
|
@ -221,6 +240,13 @@ public:
|
|||
return reinterpret_cast<const T*>(this);
|
||||
}
|
||||
|
||||
Vec3<T> & operator=(const Vec3<T> &v) {
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator ==(const Vec3<T> &v) const{
|
||||
return x==v.x && y==v.y && z==v.z;
|
||||
}
|
||||
|
@ -387,6 +413,14 @@ public:
|
|||
this->w= v.w;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
explicit Vec4(Vec4<S> &v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
this->w= v.w;
|
||||
}
|
||||
|
||||
Vec4(T x, T y, T z, T w){
|
||||
this->x= x;
|
||||
this->y= y;
|
||||
|
@ -416,6 +450,14 @@ public:
|
|||
return reinterpret_cast<const T*>(this);
|
||||
}
|
||||
|
||||
Vec4<T> & operator=(const Vec4<T> &v) {
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
this->w= v.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator ==(const Vec4<T> &v) const{
|
||||
return x==v.x && y==v.y && z==v.z && w==v.w;
|
||||
}
|
||||
|
|
|
@ -369,6 +369,7 @@ UnitParticleSystem::UnitParticleSystem(int particleCount): ParticleSystem(partic
|
|||
fixed=false;
|
||||
rotation=0.0f;
|
||||
relativeDirection=true;
|
||||
relative=false;
|
||||
|
||||
cRotation= Vec3f(1.0f,1.0f,1.0f);
|
||||
fixedAddition = Vec3f(0.0f,0.0f,0.0f);
|
||||
|
@ -437,7 +438,7 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
|
|||
p->speed= p->speed * speed;
|
||||
p->accel= Vec3f(0.0f, -gravity, 0.0f);
|
||||
|
||||
if(!relative){
|
||||
if(relative == false) {
|
||||
p->pos= Vec3f(pos.x+x+offset.x, pos.y+random.randRange(-radius/2, radius/2)+offset.y, pos.z+y+offset.z);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -105,25 +105,25 @@ string boolToStr(bool b){
|
|||
}
|
||||
|
||||
string intToStr(int i){
|
||||
char str[strSize];
|
||||
char str[strSize]="";
|
||||
sprintf(str, "%d", i);
|
||||
return str;
|
||||
}
|
||||
|
||||
string intToHex(int i){
|
||||
char str[strSize];
|
||||
char str[strSize]="";
|
||||
sprintf(str, "%x", i);
|
||||
return str;
|
||||
}
|
||||
|
||||
string floatToStr(float f,int precsion){
|
||||
char str[strSize];
|
||||
char str[strSize]="";
|
||||
sprintf(str, "%.*f", precsion,f);
|
||||
return str;
|
||||
}
|
||||
|
||||
string doubleToStr(double d,int precsion){
|
||||
char str[strSize];
|
||||
char str[strSize]="";
|
||||
sprintf(str, "%.*f", precsion,d);
|
||||
return str;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue