a few small performance improvements based on perf tool

This commit is contained in:
Mark Vejvoda 2013-11-01 06:42:57 +00:00
parent e7fb242716
commit 2612774078
2 changed files with 57 additions and 35 deletions

View File

@ -2050,13 +2050,13 @@ int64 Unit::getUpdateProgress() {
int64 heightFactor = getHeightFactor(PROGRESS_SPEED_MULTIPLIER); int64 heightFactor = getHeightFactor(PROGRESS_SPEED_MULTIPLIER);
//update progresses //update progresses
const Game *game = Renderer::getInstance().getGame(); // const Game *game = Renderer::getInstance().getGame();
if(game == NULL) { // if(game == NULL) {
throw megaglest_runtime_error("game == NULL"); // throw megaglest_runtime_error("game == NULL");
} // }
if(game->getWorld() == NULL) { // if(game->getWorld() == NULL) {
throw megaglest_runtime_error("game->getWorld() == NULL"); // throw megaglest_runtime_error("game->getWorld() == NULL");
} // }
newProgress = getUpdatedProgress(progress, GameConstants::updateFps, newProgress = getUpdatedProgress(progress, GameConstants::updateFps,
speed, diagonalFactor, heightFactor); speed, diagonalFactor, heightFactor);
@ -2128,10 +2128,12 @@ int64 Unit::getUpdatedProgress(int64 currentProgress, int64 updateFPS, int64 spe
progressIncrease = 1; progressIncrease = 1;
} }
char szBuf[8096]=""; if(isNetworkCRCEnabled() == true) {
snprintf(szBuf,8095,"currentProgress = " MG_I64_SPECIFIER " updateFPS = " MG_I64_SPECIFIER " speed = " MG_I64_SPECIFIER " diagonalFactor = " MG_I64_SPECIFIER " heightFactor = " MG_I64_SPECIFIER " speedDenominator = " MG_I64_SPECIFIER " progressIncrease = " MG_I64_SPECIFIER " [" MG_I64_SPECIFIER "]", char szBuf[8096]="";
currentProgress,updateFPS,speed,diagonalFactor,heightFactor,speedDenominator,progressIncrease,((speed * diagonalFactor * heightFactor) / speedDenominator)); snprintf(szBuf,8095,"currentProgress = " MG_I64_SPECIFIER " updateFPS = " MG_I64_SPECIFIER " speed = " MG_I64_SPECIFIER " diagonalFactor = " MG_I64_SPECIFIER " heightFactor = " MG_I64_SPECIFIER " speedDenominator = " MG_I64_SPECIFIER " progressIncrease = " MG_I64_SPECIFIER " [" MG_I64_SPECIFIER "]",
networkCRCLogInfo = szBuf; currentProgress,updateFPS,speed,diagonalFactor,heightFactor,speedDenominator,progressIncrease,((speed * diagonalFactor * heightFactor) / speedDenominator));
networkCRCLogInfo = szBuf;
}
newProgress += progressIncrease; newProgress += progressIncrease;

View File

@ -120,7 +120,11 @@ private:
public: public:
Mutex(string ownerId=""); Mutex(string ownerId="");
~Mutex(); ~Mutex();
void setOwnerId(string ownerId) { this->ownerId = ownerId; } void setOwnerId(string ownerId) {
if(this->ownerId != ownerId) {
this->ownerId = ownerId;
}
}
void p(); void p();
void v(); void v();
int getRefCount() const { return refCount; } int getRefCount() const { return refCount; }
@ -140,7 +144,9 @@ public:
MutexSafeWrapper(Mutex *mutex,string ownerId="") { MutexSafeWrapper(Mutex *mutex,string ownerId="") {
this->mutex = mutex; this->mutex = mutex;
this->ownerId = ownerId; if(this->ownerId != ownerId) {
this->ownerId = ownerId;
}
Lock(); Lock();
} }
~MutexSafeWrapper() { ~MutexSafeWrapper() {
@ -149,7 +155,9 @@ public:
void setMutex(Mutex *mutex,string ownerId="") { void setMutex(Mutex *mutex,string ownerId="") {
this->mutex = mutex; this->mutex = mutex;
this->ownerId = ownerId; if(this->ownerId != ownerId) {
this->ownerId = ownerId;
}
Lock(); Lock();
} }
bool isValidMutex() const { bool isValidMutex() const {
@ -159,8 +167,8 @@ public:
void Lock() { void Lock() {
if(this->mutex != NULL) { if(this->mutex != NULL) {
#ifdef DEBUG_MUTEXES #ifdef DEBUG_MUTEXES
if(ownerId != "") { if(this->ownerId != "") {
printf("Locking Mutex [%s] refCount: %d\n",ownerId.c_str(),this->mutex->getRefCount()); printf("Locking Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
} }
#endif #endif
@ -179,8 +187,8 @@ public:
#endif #endif
#ifdef DEBUG_MUTEXES #ifdef DEBUG_MUTEXES
if(ownerId != "") { if(this->ownerId != "") {
printf("Locked Mutex [%s] refCount: %d\n",ownerId.c_str(),this->mutex->getRefCount()); printf("Locked Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
} }
#endif #endif
} }
@ -188,8 +196,8 @@ public:
void ReleaseLock(bool keepMutex=false,bool deleteMutexOnRelease=false) { void ReleaseLock(bool keepMutex=false,bool deleteMutexOnRelease=false) {
if(this->mutex != NULL) { if(this->mutex != NULL) {
#ifdef DEBUG_MUTEXES #ifdef DEBUG_MUTEXES
if(ownerId != "") { if(this->ownerId != "") {
printf("UnLocking Mutex [%s] refCount: %d\n",ownerId.c_str(),this->mutex->getRefCount()); printf("UnLocking Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
} }
#endif #endif
@ -200,8 +208,8 @@ public:
#endif #endif
#ifdef DEBUG_MUTEXES #ifdef DEBUG_MUTEXES
if(ownerId != "") { if(this->ownerId != "") {
printf("UnLocked Mutex [%s] refCount: %d\n",ownerId.c_str(),this->mutex->getRefCount()); printf("UnLocked Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
} }
#endif #endif
@ -249,7 +257,11 @@ public:
void UnLockWrite(); void UnLockWrite();
int maxReaders(); int maxReaders();
void setOwnerId(string ownerId) { this->ownerId = ownerId; } void setOwnerId(string ownerId) {
if(this->ownerId != ownerId) {
this->ownerId = ownerId;
}
}
private: private:
Semaphore semaphore; Semaphore semaphore;
@ -274,8 +286,12 @@ public:
ReadWriteMutexSafeWrapper(ReadWriteMutex *mutex,bool isReadLock=true, string ownerId="") { ReadWriteMutexSafeWrapper(ReadWriteMutex *mutex,bool isReadLock=true, string ownerId="") {
this->mutex = mutex; this->mutex = mutex;
this->isReadLock = isReadLock; if(this->isReadLock != isReadLock) {
this->ownerId = ownerId; this->isReadLock = isReadLock;
}
if(this->ownerId != ownerId) {
this->ownerId = ownerId;
}
Lock(); Lock();
} }
~ReadWriteMutexSafeWrapper() { ~ReadWriteMutexSafeWrapper() {
@ -284,8 +300,12 @@ public:
void setReadWriteMutex(ReadWriteMutex *mutex,bool isReadLock=true,string ownerId="") { void setReadWriteMutex(ReadWriteMutex *mutex,bool isReadLock=true,string ownerId="") {
this->mutex = mutex; this->mutex = mutex;
this->isReadLock = isReadLock; if(this->isReadLock != isReadLock) {
this->ownerId = ownerId; this->isReadLock = isReadLock;
}
if(this->ownerId != ownerId) {
this->ownerId = ownerId;
}
Lock(); Lock();
} }
bool isValidReadWriteMutex() const { bool isValidReadWriteMutex() const {
@ -295,8 +315,8 @@ public:
void Lock() { void Lock() {
if(this->mutex != NULL) { if(this->mutex != NULL) {
#ifdef DEBUG_MUTEXES #ifdef DEBUG_MUTEXES
if(ownerId != "") { if(this->ownerId != "") {
printf("Locking Mutex [%s] refCount: %d\n",ownerId.c_str(),this->mutex->getRefCount()); printf("Locking Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
} }
#endif #endif
@ -317,8 +337,8 @@ public:
#endif #endif
#ifdef DEBUG_MUTEXES #ifdef DEBUG_MUTEXES
if(ownerId != "") { if(this->ownerId != "") {
printf("Locked Mutex [%s] refCount: %d\n",ownerId.c_str(),this->mutex->getRefCount()); printf("Locked Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
} }
#endif #endif
} }
@ -326,8 +346,8 @@ public:
void ReleaseLock(bool keepMutex=false) { void ReleaseLock(bool keepMutex=false) {
if(this->mutex != NULL) { if(this->mutex != NULL) {
#ifdef DEBUG_MUTEXES #ifdef DEBUG_MUTEXES
if(ownerId != "") { if(this->ownerId != "") {
printf("UnLocking Mutex [%s] refCount: %d\n",ownerId.c_str(),this->mutex->getRefCount()); printf("UnLocking Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
} }
#endif #endif
@ -343,8 +363,8 @@ public:
#endif #endif
#ifdef DEBUG_MUTEXES #ifdef DEBUG_MUTEXES
if(ownerId != "") { if(this->ownerId != "") {
printf("UnLocked Mutex [%s] refCount: %d\n",ownerId.c_str(),this->mutex->getRefCount()); printf("UnLocked Mutex [%s] refCount: %d\n",this->ownerId.c_str(),this->mutex->getRefCount());
} }
#endif #endif