*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 ========================
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<Vec2i, std::map<int, FowAlphaCellsLookupItem > >::iterator iterMap = FowAlphaCellsLookupItemCache.find(unit->getPos());
if(iterMap != FowAlphaCellsLookupItemCache.end()) {
std::map<int, FowAlphaCellsLookupItem>::iterator iterMap2 = iterMap->second.find(sightRange);
if(iterMap2 != iterMap->second.end()) {
foundInCache = true;
if(enableFowAlphaCellsLookupItemCache == true) {
std::map<Vec2i, std::map<int, FowAlphaCellsLookupItem > >::iterator iterMap = FowAlphaCellsLookupItemCache.find(unit->getPos());
if(iterMap != FowAlphaCellsLookupItemCache.end()) {
std::map<int, FowAlphaCellsLookupItem>::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;
}
}
}
}

View File

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

View File

@ -114,73 +114,73 @@ public:
// return a == b;
//}
T *ptr(){
inline T *ptr(){
return reinterpret_cast<T*>(this);
}
const T *ptr() const{
inline const T *ptr() const {
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->y= v.y;
return *this;
}
bool operator ==(const Vec2<T> &v) const{
inline bool operator ==(const Vec2<T> &v) const{
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;
}
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);
}
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);
}
Vec2<T> operator -() const{
inline Vec2<T> operator -() const{
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);
}
Vec2<T> operator *(T s) const{
inline Vec2<T> operator *(T s) const{
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);
}
Vec2<T> operator /(T s) const{
inline Vec2<T> operator /(T s) const{
return Vec2(x/s, y/s);
}
Vec2<T> operator +=(const Vec2<T> &v){
inline Vec2<T> operator +=(const Vec2<T> &v){
x+=v.x;
y+=v.y;
return *this;
}
Vec2<T> operator -=(const Vec2<T> &v){
inline Vec2<T> operator -=(const Vec2<T> &v){
x-=v.x;
y-=v.y;
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;
}
T dot(const Vec2<T> &v) const{
inline T dot(const Vec2<T> &v) const{
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<>
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);
}
float length() const{
inline float length() const{
#ifdef USE_STREFLOP
return static_cast<float>(streflop::sqrt(static_cast<streflop::Simple>(x*x + y*y)));
#else
@ -201,13 +201,13 @@ public:
#endif
}
void normalize(){
inline void normalize(){
T m= length();
x/= m;
y/= m;
}
Vec2<T> rotate(float rad){
inline Vec2<T> rotate(float rad){
const float
#ifdef USE_STREFLOP
c = streflop::cosf(rad),
@ -219,11 +219,11 @@ public:
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);
}
std::string getString() const {
inline std::string getString() const {
std::ostringstream streamOut;
streamOut << "x [" << x;
streamOut << "] y [" << y << "]";
@ -263,7 +263,7 @@ public:
};
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 << ")";
}
@ -327,80 +327,80 @@ public:
this->z= v.z;
}
T *ptr(){
inline T *ptr(){
return reinterpret_cast<T*>(this);
}
const T *ptr() const{
inline const T *ptr() const{
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->y= v.y;
this->z= v.z;
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;
}
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;
}
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);
}
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);
}
Vec3<T> operator -() const{
inline Vec3<T> operator -() const{
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);
}
Vec3<T> operator *(T s) const{
inline Vec3<T> operator *(T s) const{
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);
}
Vec3<T> operator /(T s) const{
inline Vec3<T> operator /(T s) const{
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;
y+=v.y;
z+=v.z;
return *this;
}
Vec3<T> operator -=(const Vec3<T> &v){
inline Vec3<T> operator -=(const Vec3<T> &v){
x-=v.x;
y-=v.y;
z-=v.z;
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);
}
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;
}
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;
}
@ -408,7 +408,7 @@ public:
return Vec3<T>(v-*this).length();
}
float length() const{
inline float length() const{
#ifdef USE_STREFLOP
return static_cast<float>(streflop::sqrt(static_cast<streflop::Simple>(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<T> getNormalized() const{
inline Vec3<T> getNormalized() const{
T m= length();
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>(
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<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;
rv= (p2-*this).cross(p1-*this);
rv.normalize();
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;
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<T*>(this);
}
const T *ptr() const{
inline const T *ptr() const{
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->y= v.y;
this->z= v.z;
@ -596,43 +596,43 @@ public:
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;
}
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;
}
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);
}
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);
}
Vec4<T> operator -() const{
inline Vec4<T> operator -() const{
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);
}
Vec4<T> operator *(T s) const{
inline Vec4<T> operator *(T s) const{
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);
}
Vec4<T> operator /(T s) const{
inline Vec4<T> operator /(T s) const{
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;
y+=v.y;
z+=v.z;
@ -640,26 +640,28 @@ public:
return *this;
}
Vec4<T> operator -=(const Vec4<T> &v){
inline Vec4<T> operator -=(const Vec4<T> &v){
x-=v.x;
y-=v.y;
z-=v.z;
w-=w.z;
return *this;
}
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);
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);
}
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;
}
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;
}
std::string getString() const {
inline std::string getString() const {
std::ostringstream streamOut;
streamOut << "x [" << x;
streamOut << "] y [" << y;