*NOTE: This is not backwards compatible with previous builds

- disable the alpha fog of war cache as it takes too much RAM (not sure if it really improves performance that much)
- inline some common functions for speed
This commit is contained in:
Mark Vejvoda
2012-07-03 19:31:52 +00:00
parent b75527cdd6
commit d9e2a64bb3
3 changed files with 92 additions and 81 deletions

View File

@@ -45,7 +45,7 @@ time_t ExploredCellsLookupItem::lastDebug = 0;
// ===================== PUBLIC ======================== // ===================== PUBLIC ========================
World::World(){ World::World() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Config &config= Config::getInstance(); Config &config= Config::getInstance();
@@ -56,6 +56,8 @@ World::World(){
ExploredCellsLookupItemCacheTimer.clear(); ExploredCellsLookupItemCacheTimer.clear();
ExploredCellsLookupItemCacheTimerCount = 0; ExploredCellsLookupItemCacheTimerCount = 0;
FowAlphaCellsLookupItemCache.clear(); FowAlphaCellsLookupItemCache.clear();
// Disable this cache as it takes too much RAM (not sure if its worth the performance gain)
enableFowAlphaCellsLookupItemCache = false;
nextCommandGroupId = 0; nextCommandGroupId = 0;
techTree = NULL; techTree = NULL;
@@ -65,6 +67,7 @@ World::World(){
fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip"); fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip");
MaxExploredCellsLookupItemCache= config.getInt("MaxExploredCellsLookupItemCache",intToStr(MaxExploredCellsLookupItemCache).c_str()); MaxExploredCellsLookupItemCache= config.getInt("MaxExploredCellsLookupItemCache",intToStr(MaxExploredCellsLookupItemCache).c_str());
//MaxExploredCellsLookupItemCache = 0;
routePlanner = 0; routePlanner = 0;
cartographer = 0; cartographer = 0;
@@ -1773,15 +1776,16 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex) {
} }
//explore //explore
float posLength = currRelPos.length();
//if(Vec2i(0).dist(currRelPos) < surfSightRange + indirectSightRange + 1) { //if(Vec2i(0).dist(currRelPos) < surfSightRange + indirectSightRange + 1) {
if(currRelPos.length() < surfSightRange + indirectSightRange + 1) { if(posLength < surfSightRange + indirectSightRange + 1) {
sc->setExplored(teamIndex, true); sc->setExplored(teamIndex, true);
item.exploredCellList.push_back(sc); item.exploredCellList.push_back(sc);
} }
//visible //visible
//if(Vec2i(0).dist(currRelPos) < surfSightRange) { //if(Vec2i(0).dist(currRelPos) < surfSightRange) {
if(currRelPos.length() < surfSightRange) { if(posLength < surfSightRange) {
sc->setVisible(teamIndex, true); sc->setVisible(teamIndex, true);
item.visibleCellList.push_back(sc); item.visibleCellList.push_back(sc);
} }
@@ -1966,6 +1970,7 @@ void World::computeFow(int factionIdxToTick) {
int sightRange= unit->getType()->getSight(); int sightRange= unit->getType()->getSight();
bool foundInCache = false; bool foundInCache = false;
if(enableFowAlphaCellsLookupItemCache == true) {
std::map<Vec2i, std::map<int, FowAlphaCellsLookupItem > >::iterator iterMap = FowAlphaCellsLookupItemCache.find(unit->getPos()); std::map<Vec2i, std::map<int, FowAlphaCellsLookupItem > >::iterator iterMap = FowAlphaCellsLookupItemCache.find(unit->getPos());
if(iterMap != FowAlphaCellsLookupItemCache.end()) { if(iterMap != FowAlphaCellsLookupItemCache.end()) {
std::map<int, FowAlphaCellsLookupItem>::iterator iterMap2 = iterMap->second.find(sightRange); std::map<int, FowAlphaCellsLookupItem>::iterator iterMap2 = iterMap->second.find(sightRange);
@@ -1981,6 +1986,7 @@ void World::computeFow(int factionIdxToTick) {
} }
} }
} }
}
if(foundInCache == false) { if(foundInCache == false) {
FowAlphaCellsLookupItem itemCache; FowAlphaCellsLookupItem itemCache;
@@ -2012,6 +2018,7 @@ void World::computeFow(int factionIdxToTick) {
itemCache.alphaList.push_back(alpha); itemCache.alphaList.push_back(alpha);
} }
if(enableFowAlphaCellsLookupItemCache == true) {
if(itemCache.surfPosList.empty() == false) { if(itemCache.surfPosList.empty() == false) {
FowAlphaCellsLookupItemCache[unit->getPos()][sightRange] = itemCache; FowAlphaCellsLookupItemCache[unit->getPos()][sightRange] = itemCache;
} }
@@ -2021,6 +2028,7 @@ void World::computeFow(int factionIdxToTick) {
} }
} }
} }
}
} }
GameSettings * World::getGameSettingsPtr() { GameSettings * World::getGameSettingsPtr() {

View File

@@ -95,6 +95,7 @@ private:
std::map<int,ExploredCellsLookupKey> ExploredCellsLookupItemCacheTimer; std::map<int,ExploredCellsLookupKey> ExploredCellsLookupItemCacheTimer;
int ExploredCellsLookupItemCacheTimerCount; int ExploredCellsLookupItemCacheTimerCount;
bool enableFowAlphaCellsLookupItemCache;
std::map<Vec2i, std::map<int, FowAlphaCellsLookupItem > > FowAlphaCellsLookupItemCache; std::map<Vec2i, std::map<int, FowAlphaCellsLookupItem > > FowAlphaCellsLookupItemCache;
public: public:

View File

@@ -114,73 +114,73 @@ public:
// return a == b; // return a == b;
//} //}
T *ptr(){ inline T *ptr(){
return reinterpret_cast<T*>(this); return reinterpret_cast<T*>(this);
} }
const T *ptr() const{ inline const T *ptr() const {
return reinterpret_cast<const T*>(this); return reinterpret_cast<const T*>(this);
} }
Vec2<T> & operator=(const Vec2<T> &v) { inline Vec2<T> & operator=(const Vec2<T> &v) {
this->x= v.x; this->x= v.x;
this->y= v.y; this->y= v.y;
return *this; return *this;
} }
bool operator ==(const Vec2<T> &v) const{ inline bool operator ==(const Vec2<T> &v) const{
return x==v.x && y==v.y; return x==v.x && y==v.y;
} }
bool operator !=(const Vec2<T> &v) const{ inline bool operator !=(const Vec2<T> &v) const{
return x!=v.x || y!=v.y; return x!=v.x || y!=v.y;
} }
Vec2<T> operator +(const Vec2<T> &v) const{ inline Vec2<T> operator +(const Vec2<T> &v) const{
return Vec2(x+v.x, y+v.y); return Vec2(x+v.x, y+v.y);
} }
Vec2<T> operator -(const Vec2<T> &v) const{ inline Vec2<T> operator -(const Vec2<T> &v) const{
return Vec2(x-v.x, y-v.y); return Vec2(x-v.x, y-v.y);
} }
Vec2<T> operator -() const{ inline Vec2<T> operator -() const{
return Vec2(-x, -y); return Vec2(-x, -y);
} }
Vec2<T> operator *(const Vec2<T> &v) const{ inline Vec2<T> operator *(const Vec2<T> &v) const{
return Vec2(x*v.x, y*v.y); return Vec2(x*v.x, y*v.y);
} }
Vec2<T> operator *(T s) const{ inline Vec2<T> operator *(T s) const{
return Vec2(x*s, y*s); return Vec2(x*s, y*s);
} }
Vec2<T> operator /(const Vec2<T> &v) const{ inline Vec2<T> operator /(const Vec2<T> &v) const{
return Vec2(x/v.x, y/v.y); return Vec2(x/v.x, y/v.y);
} }
Vec2<T> operator /(T s) const{ inline Vec2<T> operator /(T s) const{
return Vec2(x/s, y/s); return Vec2(x/s, y/s);
} }
Vec2<T> operator +=(const Vec2<T> &v){ inline Vec2<T> operator +=(const Vec2<T> &v){
x+=v.x; x+=v.x;
y+=v.y; y+=v.y;
return *this; return *this;
} }
Vec2<T> operator -=(const Vec2<T> &v){ inline Vec2<T> operator -=(const Vec2<T> &v){
x-=v.x; x-=v.x;
y-=v.y; y-=v.y;
return *this; return *this;
} }
Vec2<T> lerp(T t, const Vec2<T> &v) const{ inline Vec2<T> lerp(T t, const Vec2<T> &v) const{
return *this + (v - *this)*t; return *this + (v - *this)*t;
} }
T dot(const Vec2<T> &v) const{ inline T dot(const Vec2<T> &v) const{
return x*v.x+y*v.y; return x*v.x+y*v.y;
} }
@@ -189,11 +189,11 @@ public:
} }
// strict week ordering, so Vec2<T> can be used as key for set<> or map<> // strict week ordering, so Vec2<T> can be used as key for set<> or map<>
bool operator<(const Vec2<T> &v) const { inline bool operator<(const Vec2<T> &v) const {
return x < v.x || (x == v.x && y < v.y); return x < v.x || (x == v.x && y < v.y);
} }
float length() const{ inline float length() const{
#ifdef USE_STREFLOP #ifdef USE_STREFLOP
return static_cast<float>(streflop::sqrt(static_cast<streflop::Simple>(x*x + y*y))); return static_cast<float>(streflop::sqrt(static_cast<streflop::Simple>(x*x + y*y)));
#else #else
@@ -201,13 +201,13 @@ public:
#endif #endif
} }
void normalize(){ inline void normalize(){
T m= length(); T m= length();
x/= m; x/= m;
y/= m; y/= m;
} }
Vec2<T> rotate(float rad){ inline Vec2<T> rotate(float rad){
const float const float
#ifdef USE_STREFLOP #ifdef USE_STREFLOP
c = streflop::cosf(rad), c = streflop::cosf(rad),
@@ -219,11 +219,11 @@ public:
return Vec2<T>(x*c-y*s,x*s+y*c); return Vec2<T>(x*c-y*s,x*s+y*c);
} }
Vec2<T> rotateAround(float rad,const Vec2<T>& pt){ inline Vec2<T> rotateAround(float rad,const Vec2<T>& pt){
return pt+(*this-pt).rotate(rad); return pt+(*this-pt).rotate(rad);
} }
std::string getString() const { inline std::string getString() const {
std::ostringstream streamOut; std::ostringstream streamOut;
streamOut << "x [" << x; streamOut << "x [" << x;
streamOut << "] y [" << y << "]"; streamOut << "] y [" << y << "]";
@@ -263,7 +263,7 @@ public:
}; };
template <typename T> template <typename T>
std::ostream& operator<<(std::ostream &stream, const Vec2<T> &vec) { inline std::ostream& operator<<(std::ostream &stream, const Vec2<T> &vec) {
return stream << "(" << vec.x << ", " << vec.y << ")"; return stream << "(" << vec.x << ", " << vec.y << ")";
} }
@@ -327,80 +327,80 @@ public:
this->z= v.z; this->z= v.z;
} }
T *ptr(){ inline T *ptr(){
return reinterpret_cast<T*>(this); return reinterpret_cast<T*>(this);
} }
const T *ptr() const{ inline const T *ptr() const{
return reinterpret_cast<const T*>(this); return reinterpret_cast<const T*>(this);
} }
Vec3<T> & operator=(const Vec3<T> &v) { inline Vec3<T> & operator=(const Vec3<T> &v) {
this->x= v.x; this->x= v.x;
this->y= v.y; this->y= v.y;
this->z= v.z; this->z= v.z;
return *this; return *this;
} }
bool operator ==(const Vec3<T> &v) const{ inline 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;
} }
bool operator !=(const Vec3<T> &v) const{ inline 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;
} }
Vec3<T> operator +(const Vec3<T> &v) const{ inline Vec3<T> operator +(const Vec3<T> &v) const{
return Vec3(x+v.x, y+v.y, z+v.z); return Vec3(x+v.x, y+v.y, z+v.z);
} }
Vec3<T> operator -(const Vec3<T> &v) const{ inline Vec3<T> operator -(const Vec3<T> &v) const{
return Vec3(x-v.x, y-v.y, z-v.z); return Vec3(x-v.x, y-v.y, z-v.z);
} }
Vec3<T> operator -() const{ inline Vec3<T> operator -() const{
return Vec3(-x, -y, -z); return Vec3(-x, -y, -z);
} }
Vec3<T> operator *(const Vec3<T> &v) const{ inline Vec3<T> operator *(const Vec3<T> &v) const{
return Vec3(x*v.x, y*v.y, z*v.z); return Vec3(x*v.x, y*v.y, z*v.z);
} }
Vec3<T> operator *(T s) const{ inline Vec3<T> operator *(T s) const{
return Vec3(x*s, y*s, z*s); return Vec3(x*s, y*s, z*s);
} }
Vec3<T> operator /(const Vec3<T> &v) const{ inline Vec3<T> operator /(const Vec3<T> &v) const{
return Vec3(x/v.x, y/v.y, z/v.z); return Vec3(x/v.x, y/v.y, z/v.z);
} }
Vec3<T> operator /(T s) const{ inline Vec3<T> operator /(T s) const{
return Vec3(x/s, y/s, z/s); return Vec3(x/s, y/s, z/s);
} }
Vec3<T> operator +=(const Vec3<T> &v){ inline Vec3<T> operator +=(const Vec3<T> &v){
x+=v.x; x+=v.x;
y+=v.y; y+=v.y;
z+=v.z; z+=v.z;
return *this; return *this;
} }
Vec3<T> operator -=(const Vec3<T> &v){ inline Vec3<T> operator -=(const Vec3<T> &v){
x-=v.x; x-=v.x;
y-=v.y; y-=v.y;
z-=v.z; z-=v.z;
return *this; return *this;
} }
bool operator <(const Vec3<T> &v) const { inline bool operator <(const Vec3<T> &v) const {
return x < v.x || (x == v.x && y < v.y) || (x == v.x && y == v.y && z < v.z); return x < v.x || (x == v.x && y < v.y) || (x == v.x && y == v.y && z < v.z);
} }
Vec3<T> lerp(T t, const Vec3<T> &v) const{ inline Vec3<T> lerp(T t, const Vec3<T> &v) const{
return *this + (v - *this) * t; return *this + (v - *this) * t;
} }
T dot(const Vec3<T> &v) const{ inline T dot(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;
} }
@@ -408,7 +408,7 @@ public:
return Vec3<T>(v-*this).length(); return Vec3<T>(v-*this).length();
} }
float length() const{ inline float length() const{
#ifdef USE_STREFLOP #ifdef USE_STREFLOP
return static_cast<float>(streflop::sqrt(static_cast<streflop::Simple>(x*x + y*y + z*z))); return static_cast<float>(streflop::sqrt(static_cast<streflop::Simple>(x*x + y*y + z*z)));
#else #else
@@ -416,33 +416,33 @@ public:
#endif #endif
} }
void normalize(){ inline void normalize(){
T m= length(); T m= length();
x/= m; x/= m;
y/= m; y/= m;
z/= m; z/= m;
} }
Vec3<T> getNormalized() const{ inline Vec3<T> getNormalized() const{
T m= length(); T m= length();
return Vec3<T>(x/m, y/m, z/m); return Vec3<T>(x/m, y/m, z/m);
} }
Vec3<T> cross(const Vec3<T> &v) const{ inline Vec3<T> cross(const Vec3<T> &v) const{
return Vec3<T>( return Vec3<T>(
this->y*v.z-this->z*v.y, this->y*v.z-this->z*v.y,
this->z*v.x-this->x*v.z, this->z*v.x-this->x*v.z,
this->x*v.y-this->y*v.x); this->x*v.y-this->y*v.x);
} }
Vec3<T> normal(const Vec3<T> &p1, const Vec3<T> &p2) const{ inline Vec3<T> normal(const Vec3<T> &p1, const Vec3<T> &p2) const{
Vec3<T> rv; Vec3<T> rv;
rv= (p2-*this).cross(p1-*this); rv= (p2-*this).cross(p1-*this);
rv.normalize(); rv.normalize();
return rv; return rv;
} }
Vec3<T> normal(const Vec3<T> &p1, const Vec3<T> &p2, const Vec3<T> &p3, const Vec3<T> &p4) const{ inline Vec3<T> normal(const Vec3<T> &p1, const Vec3<T> &p2, const Vec3<T> &p3, const Vec3<T> &p4) const{
Vec3<T> rv; Vec3<T> rv;
rv= this->normal(p1, p2); rv= this->normal(p1, p2);
@@ -453,7 +453,7 @@ public:
return rv; return rv;
} }
std::string getString() const { inline std::string getString() const {
std::ostringstream streamOut; std::ostringstream streamOut;
streamOut << "x [" << x; streamOut << "x [" << x;
streamOut << "] y [" << y; streamOut << "] y [" << y;
@@ -580,15 +580,15 @@ public:
this->w= 1; this->w= 1;
} }
T *ptr(){ inline T *ptr(){
return reinterpret_cast<T*>(this); return reinterpret_cast<T*>(this);
} }
const T *ptr() const{ inline const T *ptr() const{
return reinterpret_cast<const T*>(this); return reinterpret_cast<const T*>(this);
} }
Vec4<T> & operator=(const Vec4<T> &v) { inline Vec4<T> & operator=(const Vec4<T> &v) {
this->x= v.x; this->x= v.x;
this->y= v.y; this->y= v.y;
this->z= v.z; this->z= v.z;
@@ -596,43 +596,43 @@ public:
return *this; return *this;
} }
bool operator ==(const Vec4<T> &v) const{ inline 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;
} }
bool operator !=(const Vec4<T> &v) const{ inline 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;
} }
Vec4<T> operator +(const Vec4<T> &v) const{ inline Vec4<T> operator +(const Vec4<T> &v) const{
return Vec4(x+v.x, y+v.y, z+v.z, w+v.w); return Vec4(x+v.x, y+v.y, z+v.z, w+v.w);
} }
Vec4<T> operator -(const Vec4<T> &v) const{ inline Vec4<T> operator -(const Vec4<T> &v) const{
return Vec4(x-v.x, y-v.y, z-v.z, w-v.w); return Vec4(x-v.x, y-v.y, z-v.z, w-v.w);
} }
Vec4<T> operator -() const{ inline Vec4<T> operator -() const{
return Vec4(-x, -y, -z, -w); return Vec4(-x, -y, -z, -w);
} }
Vec4<T> operator *(const Vec4<T> &v) const{ inline Vec4<T> operator *(const Vec4<T> &v) const{
return Vec4(x*v.x, y*v.y, z*v.z, w*v.w); return Vec4(x*v.x, y*v.y, z*v.z, w*v.w);
} }
Vec4<T> operator *(T s) const{ inline Vec4<T> operator *(T s) const{
return Vec4(x*s, y*s, z*s, w*s); return Vec4(x*s, y*s, z*s, w*s);
} }
Vec4<T> operator /(const Vec4<T> &v) const{ inline Vec4<T> operator /(const Vec4<T> &v) const{
return Vec4(x/v.x, y/v.y, z/v.z, w/v.w); return Vec4(x/v.x, y/v.y, z/v.z, w/v.w);
} }
Vec4<T> operator /(T s) const{ inline Vec4<T> operator /(T s) const{
return Vec4(x/s, y/s, z/s, w/s); return Vec4(x/s, y/s, z/s, w/s);
} }
Vec4<T> operator +=(const Vec4<T> &v){ inline Vec4<T> operator +=(const Vec4<T> &v){
x+=v.x; x+=v.x;
y+=v.y; y+=v.y;
z+=v.z; z+=v.z;
@@ -640,26 +640,28 @@ public:
return *this; return *this;
} }
Vec4<T> operator -=(const Vec4<T> &v){ inline Vec4<T> operator -=(const Vec4<T> &v){
x-=v.x; x-=v.x;
y-=v.y; y-=v.y;
z-=v.z; z-=v.z;
w-=w.z; w-=w.z;
return *this; return *this;
} }
bool operator <(const Vec4<T> &v) const { inline bool operator <(const Vec4<T> &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); 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<T> lerp(T t, const Vec4<T> &v) const{ inline Vec4<T> lerp(T t, const Vec4<T> &v) const{
return *this + (v - *this) *t; return *this + (v - *this) *t;
} }
T dot(const Vec4<T> &v) const{ inline T dot(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;
} }
std::string getString() const { inline std::string getString() const {
std::ostringstream streamOut; std::ostringstream streamOut;
streamOut << "x [" << x; streamOut << "x [" << x;
streamOut << "] y [" << y; streamOut << "] y [" << y;