From cf6d43247d69bea6b3dadabe747456673c715d3d Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 5 Jun 2010 07:52:14 +0000 Subject: [PATCH] added networkframeperiod support to gamesettings and added possibility to over-ride in glest.ini for now --- source/glest_game/game/commander.cpp | 10 ++++++---- source/glest_game/game/game_constants.h | 4 ++-- source/glest_game/game/game_settings.h | 5 +++++ source/glest_game/global/config.cpp | 3 ++- source/glest_game/main/main.cpp | 3 +++ .../glest_game/menu/menu_state_connected_game.cpp | 6 ++++-- source/glest_game/menu/menu_state_custom_game.cpp | 15 ++++++++++++++- source/glest_game/menu/menu_state_custom_game.h | 1 + source/glest_game/network/network_message.cpp | 2 ++ source/glest_game/network/network_message.h | 1 + 10 files changed, 40 insertions(+), 10 deletions(-) diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index 40eb8c74..35eae9bd 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -21,7 +21,8 @@ #include "console.h" #include "config.h" #include "platform_util.h" -#include "leak_dumper.h" +#include "game.h" +#include "game_settings.h" #include "game.h" using namespace Shared::Graphics; @@ -259,11 +260,12 @@ CommandResult Commander::pushNetworkCommand(const NetworkCommand* networkCommand return cr; } -void Commander::updateNetwork(){ +void Commander::updateNetwork() { NetworkManager &networkManager= NetworkManager::getInstance(); - //chech that this is a keyframe - if( !networkManager.isNetworkGame() || (world->getFrameCount() % GameConstants::networkFramePeriod)==0){ + //check that this is a keyframe + GameSettings *gameSettings = this->world->getGame()->getGameSettings(); + if( !networkManager.isNetworkGame() || (world->getFrameCount() % gameSettings->getNetworkFramePeriod()) == 0) { GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); diff --git a/source/glest_game/game/game_constants.h b/source/glest_game/game/game_constants.h index 8facaf80..85e52c13 100644 --- a/source/glest_game/game/game_constants.h +++ b/source/glest_game/game/game_constants.h @@ -37,8 +37,8 @@ public: static const int serverPort= 61357; static const int updateFps= 40; static const int cameraFps= 100; - static const int networkFramePeriod= 20; - static const int networkExtraLatency= 200; + static int networkFramePeriod; + //static const int networkExtraLatency= 200; static const int maxClientConnectHandshakeSecs= 10; static const char *folder_path_maps; diff --git a/source/glest_game/game/game_settings.h b/source/glest_game/game/game_settings.h index 35f03368..01b494dd 100644 --- a/source/glest_game/game/game_settings.h +++ b/source/glest_game/game/game_settings.h @@ -49,6 +49,7 @@ private: bool fogOfWar; bool enableObserverModeAtEndGame; bool enableServerControlledAI; + int networkFramePeriod; public: @@ -57,6 +58,7 @@ public: fogOfWar = true; enableObserverModeAtEndGame = false; enableServerControlledAI = false; + networkFramePeriod = GameConstants::networkFramePeriod; } // default copy constructor will do fine, and will maintain itself ;) @@ -94,6 +96,7 @@ public: bool getFogOfWar() const {return fogOfWar;} bool getEnableObserverModeAtEndGame() const {return enableObserverModeAtEndGame;} bool getEnableServerControlledAI() const {return enableServerControlledAI;} + int getNetworkFramePeriod() const {return networkFramePeriod; } //set void setDescription(const string& description) {this->description= description;} @@ -118,6 +121,7 @@ public: void setFogOfWar(bool fogOfWar) {this->fogOfWar = fogOfWar;} void setEnableObserverModeAtEndGame(bool value) {this->enableObserverModeAtEndGame = value;} void setEnableServerControlledAI(bool value) {this->enableServerControlledAI = value;} + void setNetworkFramePeriod(int value) {this->networkFramePeriod = value; } string toString() const { string result = ""; @@ -147,6 +151,7 @@ public: result += "fogOfWar = " + intToStr(fogOfWar) + "\n"; result += "enableObserverModeAtEndGame = " + intToStr(enableObserverModeAtEndGame) + "\n"; result += "enableServerControlledAI = " + intToStr(enableServerControlledAI) + "\n"; + result += "networkFramePeriod = " + intToStr(networkFramePeriod) + "\n"; return result; } diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index 836848c5..423fb878 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -22,6 +22,7 @@ using namespace Shared::Util; namespace Glest{ namespace Game{ +int GameConstants::networkFramePeriod= 20; const char *GameConstants::folder_path_maps = "maps"; const char *GameConstants::folder_path_scenarios = "scenarios"; diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index ed6efe55..350f80cb 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -350,6 +350,9 @@ int glestMain(int argc, char** argv){ MeshCallbackTeamColor::noTeamColors = true; } + // Over-ride default network command framecount + GameConstants::networkFramePeriod = config.getInt("NetworkFramePeriod",intToStr(GameConstants::networkFramePeriod).c_str()); + //float pingTime = Socket::getAveragePingMS("soft-haus.com"); //printf("Ping time = %f\n",pingTime); diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 105837ac..3ec01673 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -434,9 +434,10 @@ void MenuStateConnectedGame::update() label += " - data synch is ok"; } + std::string networkFrameString = lang.get("NetworkFramePeriod") + " " + intToStr(clientInterface->getGameSettings()->getNetworkFramePeriod()); float pingTime = clientInterface->getThreadedPingMS(clientInterface->getServerIpAddress().c_str()); char szBuf[1024]=""; - sprintf(szBuf,"%s, ping = %.2fms",label.c_str(),pingTime); + sprintf(szBuf,"%s, ping = %.2fms, %s",label.c_str(),pingTime,networkFrameString.c_str()); labelStatus.setText(szBuf); } @@ -475,9 +476,10 @@ void MenuStateConnectedGame::update() label += " - data synch is ok"; } + std::string networkFrameString = lang.get("NetworkFramePeriod") + " " + intToStr(clientInterface->getGameSettings()->getNetworkFramePeriod()); float pingTime = clientInterface->getThreadedPingMS(clientInterface->getServerIpAddress().c_str()); char szBuf[1024]=""; - sprintf(szBuf,"%s, ping = %.2fms",label.c_str(),pingTime); + sprintf(szBuf,"%s, ping = %.2fms, %s",label.c_str(),pingTime,networkFrameString.c_str()); labelStatus.setText(szBuf); } diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 8af238ae..bc8b696d 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -168,6 +168,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b listBoxEnableServerControlledAI.pushBackItem(lang.get("No")); listBoxEnableServerControlledAI.setSelectedItemIndex(0); + labelNetworkFramePeriod.init(420, networkHeadPos, 80); //list boxes for(int i=0; igetFogOfWar(); data.enableObserverModeAtEndGame = gameSettings->getEnableObserverModeAtEndGame(); data.enableServerControlledAI = gameSettings->getEnableServerControlledAI(); + data.networkFramePeriod = gameSettings->getNetworkFramePeriod(); for(int i= 0; igetFactionTypeName(i); @@ -211,6 +212,7 @@ void NetworkMessageLaunch::buildGameSettings(GameSettings *gameSettings) const{ gameSettings->setFogOfWar(data.fogOfWar); gameSettings->setEnableObserverModeAtEndGame(data.enableObserverModeAtEndGame); gameSettings->setEnableServerControlledAI(data.enableServerControlledAI); + gameSettings->setNetworkFramePeriod(data.networkFramePeriod); for(int i= 0; isetFactionTypeName(i, data.factionTypeNames[i].getString()); diff --git a/source/glest_game/network/network_message.h b/source/glest_game/network/network_message.h index 0ff19f3f..32a79acf 100644 --- a/source/glest_game/network/network_message.h +++ b/source/glest_game/network/network_message.h @@ -167,6 +167,7 @@ private: int8 fogOfWar; int8 enableObserverModeAtEndGame; int8 enableServerControlledAI; + uint8 networkFramePeriod; // allowed values 0 - 255 }; private: