- try to get threaded client working without lag

This commit is contained in:
Mark Vejvoda 2013-03-02 00:53:55 +00:00
parent c49962c644
commit 6603e08c96
3 changed files with 29 additions and 5 deletions

View File

@ -1717,17 +1717,31 @@ void Game::update() {
//updateLoops = 80;
}
NetworkManager &networkManager= NetworkManager::getInstance();
bool enableServerControlledAI = this->gameSettings.getEnableServerControlledAI();
bool isNetworkGame = this->gameSettings.isNetworkGame();
NetworkRole role = networkManager.getNetworkRole();
if(role == nrClient && updateLoops == 1) {
ClientInterface *clientInterface = dynamic_cast<ClientInterface *>(networkManager.getClientInterface());
if(clientInterface != NULL) {
uint64 lastNetworkFrameFromServer = clientInterface->getCachedLastPendingFrameCount();
if(lastNetworkFrameFromServer > 0 && lastNetworkFrameFromServer > world.getFrameCount() + gameSettings.getNetworkFramePeriod()) {
int frameDifference = lastNetworkFrameFromServer - world.getFrameCount();
printf("Client will speed up: %d frames lastNetworkFrameFromServer: %lld world.getFrameCount() = %d updateLoops = %d\n",frameDifference,(long long int)lastNetworkFrameFromServer,world.getFrameCount(),updateLoops);
updateLoops += frameDifference;
}
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
NetworkManager &networkManager= NetworkManager::getInstance();
bool enableServerControlledAI = this->gameSettings.getEnableServerControlledAI();
bool isNetworkGame = this->gameSettings.isNetworkGame();
NetworkRole role = networkManager.getNetworkRole();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [before ReplaceDisconnectedNetworkPlayersWithAI]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());

View File

@ -946,6 +946,14 @@ void ClientInterface::updateFrame(int *checkFrame) {
}
}
uint64 ClientInterface::getCachedLastPendingFrameCount() {
MutexSafeWrapper safeMutex(networkCommandListThreadAccessor,CODE_AT_LINE);
uint64 result = cachedLastPendingFrameCount;
safeMutex.ReleaseLock();
return result;
}
void ClientInterface::simpleTask(BaseThread *callingThread) {
Chrono chrono;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();

View File

@ -90,6 +90,8 @@ public:
bool getResumeInGameJoin() const { return resumeInGameJoin; }
void sendResumeGameMessage();
uint64 getCachedLastPendingFrameCount();
//message processing
virtual void update();
virtual void updateLobby();