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