diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 83a9763db..e19d5cfd7 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -45,7 +45,7 @@ time_t ExploredCellsLookupItem::lastDebug = 0; // ===================== PUBLIC ======================== -World::World(){ +World::World() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Config &config= Config::getInstance(); @@ -56,6 +56,8 @@ World::World(){ ExploredCellsLookupItemCacheTimer.clear(); ExploredCellsLookupItemCacheTimerCount = 0; FowAlphaCellsLookupItemCache.clear(); + // Disable this cache as it takes too much RAM (not sure if its worth the performance gain) + enableFowAlphaCellsLookupItemCache = false; nextCommandGroupId = 0; techTree = NULL; @@ -65,6 +67,7 @@ World::World(){ fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip"); MaxExploredCellsLookupItemCache= config.getInt("MaxExploredCellsLookupItemCache",intToStr(MaxExploredCellsLookupItemCache).c_str()); + //MaxExploredCellsLookupItemCache = 0; routePlanner = 0; cartographer = 0; @@ -1773,15 +1776,16 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex) { } //explore + float posLength = currRelPos.length(); //if(Vec2i(0).dist(currRelPos) < surfSightRange + indirectSightRange + 1) { - if(currRelPos.length() < surfSightRange + indirectSightRange + 1) { + if(posLength < surfSightRange + indirectSightRange + 1) { sc->setExplored(teamIndex, true); item.exploredCellList.push_back(sc); } //visible //if(Vec2i(0).dist(currRelPos) < surfSightRange) { - if(currRelPos.length() < surfSightRange) { + if(posLength < surfSightRange) { sc->setVisible(teamIndex, true); item.visibleCellList.push_back(sc); } @@ -1966,18 +1970,20 @@ void World::computeFow(int factionIdxToTick) { int sightRange= unit->getType()->getSight(); bool foundInCache = false; - std::map >::iterator iterMap = FowAlphaCellsLookupItemCache.find(unit->getPos()); - if(iterMap != FowAlphaCellsLookupItemCache.end()) { - std::map::iterator iterMap2 = iterMap->second.find(sightRange); - if(iterMap2 != iterMap->second.end()) { - foundInCache = true; + if(enableFowAlphaCellsLookupItemCache == true) { + std::map >::iterator iterMap = FowAlphaCellsLookupItemCache.find(unit->getPos()); + if(iterMap != FowAlphaCellsLookupItemCache.end()) { + std::map::iterator iterMap2 = iterMap->second.find(sightRange); + if(iterMap2 != iterMap->second.end()) { + foundInCache = true; - FowAlphaCellsLookupItem &cellList = iterMap2->second; - for(int k = 0; k < cellList.surfPosList.size(); ++k) { - Vec2i &surfPos = cellList.surfPosList[k]; - float &alpha = cellList.alphaList[k]; + FowAlphaCellsLookupItem &cellList = iterMap2->second; + for(int k = 0; k < cellList.surfPosList.size(); ++k) { + Vec2i &surfPos = cellList.surfPosList[k]; + float &alpha = cellList.alphaList[k]; - minimap.incFowTextureAlphaSurface(surfPos, alpha); + minimap.incFowTextureAlphaSurface(surfPos, alpha); + } } } } @@ -2012,8 +2018,10 @@ void World::computeFow(int factionIdxToTick) { itemCache.alphaList.push_back(alpha); } - if(itemCache.surfPosList.empty() == false) { - FowAlphaCellsLookupItemCache[unit->getPos()][sightRange] = itemCache; + if(enableFowAlphaCellsLookupItemCache == true) { + if(itemCache.surfPosList.empty() == false) { + FowAlphaCellsLookupItemCache[unit->getPos()][sightRange] = itemCache; + } } } } diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 1e72e228e..2affebaad 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -95,6 +95,7 @@ private: std::map ExploredCellsLookupItemCacheTimer; int ExploredCellsLookupItemCacheTimerCount; + bool enableFowAlphaCellsLookupItemCache; std::map > FowAlphaCellsLookupItemCache; public: diff --git a/source/shared_lib/include/graphics/vec.h b/source/shared_lib/include/graphics/vec.h index 37cbe8504..654a1a30f 100644 --- a/source/shared_lib/include/graphics/vec.h +++ b/source/shared_lib/include/graphics/vec.h @@ -114,73 +114,73 @@ public: // return a == b; //} - T *ptr(){ + inline T *ptr(){ return reinterpret_cast(this); } - const T *ptr() const{ + inline const T *ptr() const { return reinterpret_cast(this); } - Vec2 & operator=(const Vec2 &v) { + inline Vec2 & operator=(const Vec2 &v) { this->x= v.x; this->y= v.y; return *this; } - bool operator ==(const Vec2 &v) const{ + inline bool operator ==(const Vec2 &v) const{ return x==v.x && y==v.y; } - bool operator !=(const Vec2 &v) const{ + inline bool operator !=(const Vec2 &v) const{ return x!=v.x || y!=v.y; } - Vec2 operator +(const Vec2 &v) const{ + inline Vec2 operator +(const Vec2 &v) const{ return Vec2(x+v.x, y+v.y); } - Vec2 operator -(const Vec2 &v) const{ + inline Vec2 operator -(const Vec2 &v) const{ return Vec2(x-v.x, y-v.y); } - Vec2 operator -() const{ + inline Vec2 operator -() const{ return Vec2(-x, -y); } - Vec2 operator *(const Vec2 &v) const{ + inline Vec2 operator *(const Vec2 &v) const{ return Vec2(x*v.x, y*v.y); } - Vec2 operator *(T s) const{ + inline Vec2 operator *(T s) const{ return Vec2(x*s, y*s); } - Vec2 operator /(const Vec2 &v) const{ + inline Vec2 operator /(const Vec2 &v) const{ return Vec2(x/v.x, y/v.y); } - Vec2 operator /(T s) const{ + inline Vec2 operator /(T s) const{ return Vec2(x/s, y/s); } - Vec2 operator +=(const Vec2 &v){ + inline Vec2 operator +=(const Vec2 &v){ x+=v.x; y+=v.y; return *this; } - Vec2 operator -=(const Vec2 &v){ + inline Vec2 operator -=(const Vec2 &v){ x-=v.x; y-=v.y; return *this; } - Vec2 lerp(T t, const Vec2 &v) const{ + inline Vec2 lerp(T t, const Vec2 &v) const{ return *this + (v - *this)*t; } - T dot(const Vec2 &v) const{ + inline T dot(const Vec2 &v) const{ return x*v.x+y*v.y; } @@ -189,11 +189,11 @@ public: } // strict week ordering, so Vec2 can be used as key for set<> or map<> - bool operator<(const Vec2 &v) const { + inline bool operator<(const Vec2 &v) const { return x < v.x || (x == v.x && y < v.y); } - float length() const{ + inline float length() const{ #ifdef USE_STREFLOP return static_cast(streflop::sqrt(static_cast(x*x + y*y))); #else @@ -201,13 +201,13 @@ public: #endif } - void normalize(){ + inline void normalize(){ T m= length(); x/= m; y/= m; } - Vec2 rotate(float rad){ + inline Vec2 rotate(float rad){ const float #ifdef USE_STREFLOP c = streflop::cosf(rad), @@ -219,11 +219,11 @@ public: return Vec2(x*c-y*s,x*s+y*c); } - Vec2 rotateAround(float rad,const Vec2& pt){ + inline Vec2 rotateAround(float rad,const Vec2& pt){ return pt+(*this-pt).rotate(rad); } - std::string getString() const { + inline std::string getString() const { std::ostringstream streamOut; streamOut << "x [" << x; streamOut << "] y [" << y << "]"; @@ -263,7 +263,7 @@ public: }; template -std::ostream& operator<<(std::ostream &stream, const Vec2 &vec) { +inline std::ostream& operator<<(std::ostream &stream, const Vec2 &vec) { return stream << "(" << vec.x << ", " << vec.y << ")"; } @@ -327,80 +327,80 @@ public: this->z= v.z; } - T *ptr(){ + inline T *ptr(){ return reinterpret_cast(this); } - const T *ptr() const{ + inline const T *ptr() const{ return reinterpret_cast(this); } - Vec3 & operator=(const Vec3 &v) { + inline Vec3 & operator=(const Vec3 &v) { this->x= v.x; this->y= v.y; this->z= v.z; return *this; } - bool operator ==(const Vec3 &v) const{ + inline bool operator ==(const Vec3 &v) const{ return x==v.x && y==v.y && z==v.z; } - bool operator !=(const Vec3 &v) const{ + inline bool operator !=(const Vec3 &v) const{ return x!=v.x || y!=v.y || z!=v.z; } - Vec3 operator +(const Vec3 &v) const{ + inline Vec3 operator +(const Vec3 &v) const{ return Vec3(x+v.x, y+v.y, z+v.z); } - Vec3 operator -(const Vec3 &v) const{ + inline Vec3 operator -(const Vec3 &v) const{ return Vec3(x-v.x, y-v.y, z-v.z); } - Vec3 operator -() const{ + inline Vec3 operator -() const{ return Vec3(-x, -y, -z); } - Vec3 operator *(const Vec3 &v) const{ + inline Vec3 operator *(const Vec3 &v) const{ return Vec3(x*v.x, y*v.y, z*v.z); } - Vec3 operator *(T s) const{ + inline Vec3 operator *(T s) const{ return Vec3(x*s, y*s, z*s); } - Vec3 operator /(const Vec3 &v) const{ + inline Vec3 operator /(const Vec3 &v) const{ return Vec3(x/v.x, y/v.y, z/v.z); } - Vec3 operator /(T s) const{ + inline Vec3 operator /(T s) const{ return Vec3(x/s, y/s, z/s); } - Vec3 operator +=(const Vec3 &v){ + inline Vec3 operator +=(const Vec3 &v){ x+=v.x; y+=v.y; z+=v.z; return *this; } - Vec3 operator -=(const Vec3 &v){ + inline Vec3 operator -=(const Vec3 &v){ x-=v.x; y-=v.y; z-=v.z; return *this; } - bool operator <(const Vec3 &v) const { + inline bool operator <(const Vec3 &v) const { return x < v.x || (x == v.x && y < v.y) || (x == v.x && y == v.y && z < v.z); } - Vec3 lerp(T t, const Vec3 &v) const{ + inline Vec3 lerp(T t, const Vec3 &v) const{ return *this + (v - *this) * t; } - T dot(const Vec3 &v) const{ + inline T dot(const Vec3 &v) const{ return x*v.x + y*v.y + z*v.z; } @@ -408,7 +408,7 @@ public: return Vec3(v-*this).length(); } - float length() const{ + inline float length() const{ #ifdef USE_STREFLOP return static_cast(streflop::sqrt(static_cast(x*x + y*y + z*z))); #else @@ -416,33 +416,33 @@ public: #endif } - void normalize(){ + inline void normalize(){ T m= length(); x/= m; y/= m; z/= m; } - Vec3 getNormalized() const{ + inline Vec3 getNormalized() const{ T m= length(); return Vec3(x/m, y/m, z/m); } - Vec3 cross(const Vec3 &v) const{ + inline Vec3 cross(const Vec3 &v) const{ return Vec3( this->y*v.z-this->z*v.y, this->z*v.x-this->x*v.z, this->x*v.y-this->y*v.x); } - Vec3 normal(const Vec3 &p1, const Vec3 &p2) const{ + inline Vec3 normal(const Vec3 &p1, const Vec3 &p2) const{ Vec3 rv; rv= (p2-*this).cross(p1-*this); rv.normalize(); return rv; } - Vec3 normal(const Vec3 &p1, const Vec3 &p2, const Vec3 &p3, const Vec3 &p4) const{ + inline Vec3 normal(const Vec3 &p1, const Vec3 &p2, const Vec3 &p3, const Vec3 &p4) const{ Vec3 rv; rv= this->normal(p1, p2); @@ -453,7 +453,7 @@ public: return rv; } - std::string getString() const { + inline std::string getString() const { std::ostringstream streamOut; streamOut << "x [" << x; streamOut << "] y [" << y; @@ -580,15 +580,15 @@ public: this->w= 1; } - T *ptr(){ + inline T *ptr(){ return reinterpret_cast(this); } - const T *ptr() const{ + inline const T *ptr() const{ return reinterpret_cast(this); } - Vec4 & operator=(const Vec4 &v) { + inline Vec4 & operator=(const Vec4 &v) { this->x= v.x; this->y= v.y; this->z= v.z; @@ -596,43 +596,43 @@ public: return *this; } - bool operator ==(const Vec4 &v) const{ + inline bool operator ==(const Vec4 &v) const{ return x==v.x && y==v.y && z==v.z && w==v.w; } - bool operator !=(const Vec4 &v) const{ + inline bool operator !=(const Vec4 &v) const{ return x!=v.x || y!=v.y || z!=v.z || w!=v.w; } - Vec4 operator +(const Vec4 &v) const{ + inline Vec4 operator +(const Vec4 &v) const{ return Vec4(x+v.x, y+v.y, z+v.z, w+v.w); } - Vec4 operator -(const Vec4 &v) const{ + inline Vec4 operator -(const Vec4 &v) const{ return Vec4(x-v.x, y-v.y, z-v.z, w-v.w); } - Vec4 operator -() const{ + inline Vec4 operator -() const{ return Vec4(-x, -y, -z, -w); } - Vec4 operator *(const Vec4 &v) const{ + inline Vec4 operator *(const Vec4 &v) const{ return Vec4(x*v.x, y*v.y, z*v.z, w*v.w); } - Vec4 operator *(T s) const{ + inline Vec4 operator *(T s) const{ return Vec4(x*s, y*s, z*s, w*s); } - Vec4 operator /(const Vec4 &v) const{ + inline Vec4 operator /(const Vec4 &v) const{ return Vec4(x/v.x, y/v.y, z/v.z, w/v.w); } - Vec4 operator /(T s) const{ + inline Vec4 operator /(T s) const{ return Vec4(x/s, y/s, z/s, w/s); } - Vec4 operator +=(const Vec4 &v){ + inline Vec4 operator +=(const Vec4 &v){ x+=v.x; y+=v.y; z+=v.z; @@ -640,26 +640,28 @@ public: return *this; } - Vec4 operator -=(const Vec4 &v){ + inline Vec4 operator -=(const Vec4 &v){ x-=v.x; y-=v.y; z-=v.z; w-=w.z; return *this; } - bool operator <(const Vec4 &v) const { - return x < v.x || (x == v.x && y < v.y) || (x == v.x && y == v.y && z < v.z) || (x == v.x && y == v.y && z == v.z && w < v.w); + inline bool operator <(const Vec4 &v) const { + return x < v.x || (x == v.x && y < v.y) || + (x == v.x && y == v.y && z < v.z) || + (x == v.x && y == v.y && z == v.z && w < v.w); } - Vec4 lerp(T t, const Vec4 &v) const{ + inline Vec4 lerp(T t, const Vec4 &v) const{ return *this + (v - *this) *t; } - T dot(const Vec4 &v) const{ + inline T dot(const Vec4 &v) const{ return x*v.x + y*v.y + z*v.z + w*v.w; } - std::string getString() const { + inline std::string getString() const { std::ostringstream streamOut; streamOut << "x [" << x; streamOut << "] y [" << y;