From 8478ab80b3c946561156c5c6d8fa6abbd5d0449c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 6 Jul 2010 05:30:34 +0000 Subject: [PATCH] - bugfixes for malformed debug statements - updated version to 3.3.5.1 - added more null checks - changes to try to fix crash when ending a game (delete cells bug) --- mk/linux/configure.ac | 2 +- source/glest_game/facilities/game_util.cpp | 14 +- source/glest_game/game/chat_manager.cpp | 2 +- source/glest_game/game/commander.cpp | 4 +- source/glest_game/game/game.cpp | 56 +++--- source/glest_game/graphics/renderer.cpp | 22 +-- source/glest_game/main/main.cpp | 129 +++++++++---- source/glest_game/main/program.cpp | 11 +- .../glest_game/network/client_interface.cpp | 182 ++++++++++++------ source/glest_game/network/client_interface.h | 4 +- source/glest_game/network/connection_slot.cpp | 2 +- .../glest_game/network/server_interface.cpp | 15 +- source/glest_game/world/world.cpp | 14 +- source/shared_lib/include/util/util.h | 4 + .../sources/platform/posix/socket.cpp | 6 +- .../sources/platform/sdl/window.cpp | 23 ++- .../sources/sound/sound_file_loader.cpp | 2 +- 17 files changed, 313 insertions(+), 179 deletions(-) diff --git a/mk/linux/configure.ac b/mk/linux/configure.ac index 058ba23c..06758c01 100644 --- a/mk/linux/configure.ac +++ b/mk/linux/configure.ac @@ -4,7 +4,7 @@ #---------------------------------------------------------------------------- AC_PREREQ([2.54]) -AC_INIT([megaglest], [3.3.5], [matze@braunis.de]) +AC_INIT([megaglest], [3.3.5.1], [matze@braunis.de]) AC_CONFIG_SRCDIR([mk/jam/build.jam]) AC_CONFIG_AUX_DIR([mk/autoconf]) diff --git a/source/glest_game/facilities/game_util.cpp b/source/glest_game/facilities/game_util.cpp index bfc15d8d..9711cd01 100644 --- a/source/glest_game/facilities/game_util.cpp +++ b/source/glest_game/facilities/game_util.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 @@ -26,7 +26,7 @@ using namespace Shared::Platform; namespace Glest{ namespace Game{ const string mailString= "contact_game@glest.org"; -const string glestVersionString= "v3.3.5"; +const string glestVersionString= "v3.3.5.1"; string getCrashDumpFileName(){ return "glest" + glestVersionString + ".dmp"; @@ -116,11 +116,11 @@ string getAboutString2(int i){ string getTeammateName(int i){ switch(i){ - case 0: return "Martiño Figueroa"; - case 1: return "José Luis González"; - case 2: return "Tucho Fernández"; - case 3: return "José Zanni"; - case 4: return "Félix Menéndez"; + case 0: return "Martio Figueroa"; + case 1: return "Jos Luis Gonzlez"; + case 2: return "Tucho Fernndez"; + case 3: return "Jos Zanni"; + case 4: return "Flix Menndez"; case 5: return "Marcos Caruncho"; case 6: return "Matthias Braun"; case 7: return "Titus Tscharntke"; diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index 4f8afc8c..a356c767 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -76,7 +76,7 @@ void ChatManager::setDisableTeamMode(bool value) { } void ChatManager::keyDown(char key){ - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); try { Lang &lang= Lang::getInstance(); diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index a7f43f8d..8ef56a8c 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -275,14 +275,14 @@ void Commander::updateNetwork() { perfTimer.start(); //update the keyframe gameNetworkInterface->updateKeyframe(world->getFrameCount()); - if(perfTimer.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] gameNetworkInterface->updateKeyframe for %d took %d msecs\n",__FILE__,__FUNCTION__,__LINE__,world->getFrameCount(),perfTimer.getMillis()); + if(perfTimer.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] gameNetworkInterface->updateKeyframe for %d took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,world->getFrameCount(),perfTimer.getMillis()); perfTimer.start(); //give pending commands for(int i= 0; i < gameNetworkInterface->getPendingCommandCount(); ++i){ giveNetworkCommand(gameNetworkInterface->getPendingCommand(i)); } - if(perfTimer.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] giveNetworkCommand took %d msecs\n",__FILE__,__FUNCTION__,__LINE__,perfTimer.getMillis()); + if(perfTimer.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] giveNetworkCommand took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,perfTimer.getMillis()); gameNetworkInterface->clearPendingCommands(); } } diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index f804ae80..ee9a01b6 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -76,6 +76,13 @@ Game::Game(Program *program, const GameSettings *gameSettings): Game::~Game(){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + thisGamePtr = NULL; + if(originalDisplayMsgCallback != NULL) { + NetworkInterface::setDisplayMessageFunction(originalDisplayMsgCallback); + } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + Logger &logger= Logger::getInstance(); Renderer &renderer= Renderer::getInstance(); @@ -94,7 +101,7 @@ Game::~Game(){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); NetworkManager::getInstance().end(); - sleep(15); + sleep(0); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -108,14 +115,7 @@ Game::~Game(){ world.end(); //must die before selection because of referencers - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - thisGamePtr = NULL; - if(originalDisplayMsgCallback != NULL) { - NetworkInterface::setDisplayMessageFunction(originalDisplayMsgCallback); - } - - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } // ==================== init and load ==================== @@ -485,7 +485,7 @@ void Game::update(){ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); NetworkManager &networkManager= NetworkManager::getInstance(); //update @@ -503,22 +503,22 @@ void Game::update(){ } } } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //World world.update(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); // Commander commander.updateNetwork(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //Gui gui.update(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //Particle systems @@ -528,7 +528,7 @@ void Game::update(){ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.updateParticleManager(rsGame); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__); } @@ -1120,77 +1120,77 @@ void Game::render3d(){ //init //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.reset3d(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); renderer.computeVisibleQuad(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); renderer.loadGameCameraMatrix(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); renderer.setupLighting(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //shadow map //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); renderer.renderShadowsToTexture(lastRenderFps); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //clear buffers //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); renderer.clearBuffers(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //surface //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); renderer.renderSurface(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //selection circles //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); renderer.renderSelectionEffects(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //units //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); renderer.renderUnits(lastRenderFps,world.getFrameCount()); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //objects //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); renderer.renderObjects(lastRenderFps,world.getFrameCount()); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //water //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); renderer.renderWater(); renderer.renderWaterEffects(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //particles //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); renderer.renderParticleManager(rsGame); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //mouse 3d //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); renderer.renderMouse3d(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); } void Game::render2d(){ diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 11b78123..07fd7126 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -2349,7 +2349,7 @@ void Renderer::renderShadowsToTexture(const int renderFps){ if(shadowMapFrame==0){ - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); chrono.start(); assertGl(); @@ -2367,7 +2367,7 @@ void Renderer::renderShadowsToTexture(const int renderFps){ glClear(GL_COLOR_BUFFER_BIT); } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); chrono.start(); //clear color buffer @@ -2410,7 +2410,7 @@ void Renderer::renderShadowsToTexture(const int renderFps){ glTranslatef(static_cast(-pos.x), 0, static_cast(-pos.z)); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); chrono.start(); } else{ @@ -2429,7 +2429,7 @@ void Renderer::renderShadowsToTexture(const int renderFps){ glRotatef(-90, -1, 0, 0); glTranslatef(-nearestLightPos.x, -nearestLightPos.y-2, -nearestLightPos.z); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); chrono.start(); } @@ -2437,24 +2437,24 @@ void Renderer::renderShadowsToTexture(const int renderFps){ glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0f, 0.001f); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); chrono.start(); } //render 3d renderUnitsFast(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); chrono.start(); renderObjectsFast(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); chrono.start(); //read color buffer glBindTexture(GL_TEXTURE_2D, shadowMapHandle); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowTextureSize, shadowTextureSize); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); chrono.start(); //get elemental matrices @@ -2478,7 +2478,7 @@ void Renderer::renderShadowsToTexture(const int renderFps){ glMatrixMode(GL_PROJECTION); glPushMatrix(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); chrono.start(); //compute texture matrix @@ -2494,13 +2494,13 @@ void Renderer::renderShadowsToTexture(const int renderFps){ assertGl(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); chrono.start(); } } } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); } diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 24de528e..8caf8728 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -118,28 +118,33 @@ MainWindow::MainWindow(Program *program){ MainWindow::~MainWindow(){ delete program; + program = NULL; } void MainWindow::eventMouseDown(int x, int y, MouseButton mouseButton){ - const Metrics &metrics = Metrics::getInstance(); int vx = metrics.toVirtualX(x); int vy = metrics.toVirtualY(getH() - y); - ProgramState *programState = program->getState(); + if(program == NULL) { + throw runtime_error("In [MainWindow::eventMouseDown] ERROR, program == NULL!"); + } - switch(mouseButton) { - case mbLeft: - programState->mouseDownLeft(vx, vy); - break; - case mbRight: - programState->mouseDownRight(vx, vy); - break; - case mbCenter: - programState->mouseDownCenter(vx, vy); - break; - default: - break; + ProgramState *programState = program->getState(); + if(programState != NULL) { + switch(mouseButton) { + case mbLeft: + programState->mouseDownLeft(vx, vy); + break; + case mbRight: + programState->mouseDownRight(vx, vy); + break; + case mbCenter: + programState->mouseDownCenter(vx, vy); + break; + default: + break; + } } } @@ -149,43 +154,54 @@ void MainWindow::eventMouseUp(int x, int y, MouseButton mouseButton){ int vx = metrics.toVirtualX(x); int vy = metrics.toVirtualY(getH() - y); + if(program == NULL) { + throw runtime_error("In [MainWindow::eventMouseUp] ERROR, program == NULL!"); + } + ProgramState *programState = program->getState(); - switch(mouseButton) { - case mbLeft: - programState->mouseUpLeft(vx, vy); - break; - case mbRight: - programState->mouseUpRight(vx, vy); - break; - case mbCenter: - programState->mouseUpCenter(vx, vy); - break; - default: - break; + if(programState != NULL) { + switch(mouseButton) { + case mbLeft: + programState->mouseUpLeft(vx, vy); + break; + case mbRight: + programState->mouseUpRight(vx, vy); + break; + case mbCenter: + programState->mouseUpCenter(vx, vy); + break; + default: + break; + } } } void MainWindow::eventMouseDoubleClick(int x, int y, MouseButton mouseButton){ - const Metrics &metrics= Metrics::getInstance(); int vx = metrics.toVirtualX(x); int vy = metrics.toVirtualY(getH() - y); + if(program == NULL) { + throw runtime_error("In [MainWindow::eventMouseDoubleClick] ERROR, program == NULL!"); + } + ProgramState *programState = program->getState(); - switch(mouseButton){ - case mbLeft: - programState->mouseDoubleClickLeft(vx, vy); - break; - case mbRight: - programState->mouseDoubleClickRight(vx, vy); - break; - case mbCenter: - programState->mouseDoubleClickCenter(vx, vy); - break; - default: - break; + if(programState != NULL) { + switch(mouseButton){ + case mbLeft: + programState->mouseDoubleClickLeft(vx, vy); + break; + case mbRight: + programState->mouseDoubleClickRight(vx, vy); + break; + case mbCenter: + programState->mouseDoubleClickCenter(vx, vy); + break; + default: + break; + } } } @@ -195,8 +211,14 @@ void MainWindow::eventMouseMove(int x, int y, const MouseState *ms){ int vx = metrics.toVirtualX(x); int vy = metrics.toVirtualY(getH() - y); + if(program == NULL) { + throw runtime_error("In [MainWindow::eventMouseMove] ERROR, program == NULL!"); + } + ProgramState *programState = program->getState(); - programState->mouseMove(vx, vy, ms); + if(programState != NULL) { + programState->mouseMove(vx, vy, ms); + } } void MainWindow::eventMouseWheel(int x, int y, int zDelta) { @@ -207,14 +229,26 @@ void MainWindow::eventMouseWheel(int x, int y, int zDelta) { int vx = metrics.toVirtualX(x); int vy = metrics.toVirtualY(getH() - y); + if(program == NULL) { + throw runtime_error("In [MainWindow::eventMouseMove] ERROR, program == NULL!"); + } + ProgramState *programState = program->getState(); - programState->eventMouseWheel(vx, vy, zDelta); + + if(programState != NULL) { + programState->eventMouseWheel(vx, vy, zDelta); + } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void MainWindow::eventKeyDown(char key){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c][%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); + + if(program == NULL) { + throw runtime_error("In [MainWindow::eventKeyDown] ERROR, program == NULL!"); + } + program->keyDown(key); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -241,10 +275,18 @@ void MainWindow::eventKeyDown(char key){ } void MainWindow::eventKeyUp(char key){ + if(program == NULL) { + throw runtime_error("In [MainWindow::eventKeyUp] ERROR, program == NULL!"); + } + program->keyUp(key); } void MainWindow::eventKeyPress(char c){ + if(program == NULL) { + throw runtime_error("In [MainWindow::eventKeyPress] ERROR, program == NULL!"); + } + program->keyPress(c); Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); @@ -259,7 +301,6 @@ void MainWindow::eventKeyPress(char c){ Renderer &renderer= Renderer::getInstance(); renderer.setNo2DMouseRendering(showCursorState); } - } void MainWindow::eventActivate(bool active){ @@ -269,6 +310,10 @@ void MainWindow::eventActivate(bool active){ } void MainWindow::eventResize(SizeState sizeState){ + if(program == NULL) { + throw runtime_error("In [MainWindow::eventResize] ERROR, program == NULL!"); + } + program->resize(sizeState); } diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index 8c9dd029..83c3ec27 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -200,7 +200,7 @@ void Program::loopWorker() { assert(programState != NULL); programState->render(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -212,7 +212,7 @@ void Program::loopWorker() { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->updateCamera took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->updateCamera took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //update world chrono.start(); @@ -235,7 +235,7 @@ void Program::loopWorker() { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -245,7 +245,7 @@ void Program::loopWorker() { programState->tick(); } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); } void Program::resize(SizeState sizeState){ @@ -283,6 +283,8 @@ void Program::setState(ProgramState *programState, bool cleanupOldState) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(dynamic_cast(programState) != NULL) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + int X = 0; int Y = 0; SDL_GetMouseState(&X,&Y); @@ -293,6 +295,7 @@ void Program::setState(ProgramState *programState, bool cleanupOldState) showCursor(true); SDL_PumpEvents(); sleep(0); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } if(cleanupOldState == true) { diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index f9a09912..53128309 100755 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -366,10 +366,6 @@ void ClientInterface::updateLobby() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__); - //chatText = networkMessageText.getText(); - //chatSender = networkMessageText.getSender(); - //chatTeamIndex = networkMessageText.getTeamIndex(); - ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex()); this->addChatInfo(msg); } @@ -455,7 +451,7 @@ void ClientInterface::updateLobby() } if(gotIntro == false && difftime(time(NULL),connectedTime) > GameConstants::maxClientConnectHandshakeSecs) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %d\n",__FILE__,__FUNCTION__,__LINE__,difftime(time(NULL),connectedTime)); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %f\n",__FILE__,__FUNCTION__,__LINE__,difftime(time(NULL),connectedTime)); close(); } } @@ -490,7 +486,7 @@ void ClientInterface::updateKeyframe(int frameCount) waitCount++; } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] receiveMessage took %d msecs, waitCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),waitCount); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] receiveMessage took %lld msecs, waitCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),waitCount); chrono.start(); //check that we are in the right frame @@ -509,7 +505,7 @@ void ClientInterface::updateKeyframe(int frameCount) pendingCommands.push_back(*networkMessageCommandList.getCommand(i)); } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] transfer network commands took %d msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] transfer network commands took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); done= true; } @@ -604,61 +600,65 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { return; } NetworkMessageType networkMessageType = getNextMessageType(true); - if(networkMessageType == nmtReady) { - if(receiveMessage(&networkMessageReady)) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - break; + + // consume old messages from the lobby + bool discarded = shouldDiscardNetworkMessage(networkMessageType); + if(discarded == false) { + if(networkMessageType == nmtReady) { + if(receiveMessage(&networkMessageReady)) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + break; + } } - } - else if(networkMessageType == nmtInvalid) { - if(chrono.getMillis() > readyWaitTimeout) { + else if(networkMessageType == nmtInvalid) { + if(chrono.getMillis() > readyWaitTimeout) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + //throw runtime_error("Timeout waiting for server"); + string sErr = "Timeout waiting for server"; + sendTextMessage(sErr,-1, true); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + + DisplayErrorMessage(sErr); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + + quit= true; + close(); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + return; + } + else { + if(chrono.getMillis() / 1000 > lastMillisCheck) { + lastMillisCheck = (chrono.getMillis() / 1000); + + char szBuf[1024]=""; + sprintf(szBuf,"Waiting for network: %llu seconds elapsed (maximum wait time: %d seconds)",lastMillisCheck,int(readyWaitTimeout / 1000)); + logger.add(szBuf, true); + } + } + } + else { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - //throw runtime_error("Timeout waiting for server"); - string sErr = "Timeout waiting for server"; - sendTextMessage(sErr,-1, true); + //throw runtime_error(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType) ); + sendTextMessage("Unexpected network message: " + intToStr(networkMessageType),-1, true); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - DisplayErrorMessage(sErr); + DisplayErrorMessage(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType)); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); quit= true; close(); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - return; - } - else { - if(chrono.getMillis() / 1000 > lastMillisCheck) { - lastMillisCheck = (chrono.getMillis() / 1000); - - char szBuf[1024]=""; - sprintf(szBuf,"Waiting for network: %llu seconds elapsed (maximum wait time: %d seconds)",lastMillisCheck,int(readyWaitTimeout / 1000)); - logger.add(szBuf, true); - } + return; } + // sleep a bit + sleep(waitSleepTime); } - else { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - //throw runtime_error(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType) ); - sendTextMessage("Unexpected network message: " + intToStr(networkMessageType),-1, true); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - - DisplayErrorMessage(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType)); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - - quit= true; - close(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - return; - } - - // sleep a bit - sleep(waitSleepTime); } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); @@ -768,7 +768,7 @@ void ClientInterface::waitForMessage() waitLoopCount++; } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] waiting took %d msecs, waitLoopCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),waitLoopCount); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] waiting took %lld msecs, waitLoopCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),waitLoopCount); } void ClientInterface::quitGame(bool userManuallyQuit) @@ -821,10 +821,80 @@ void ClientInterface::sendSwitchSetupRequest(string selectedFactionName, int8 cu SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } -/* -bool ClientInterface::getFogOfWar() -{ - return Config::getInstance().getBool("FogOfWar"); +bool ClientInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMessageType) { + bool discard = false; + + switch(networkMessageType) { + case nmtIntro: + { + discard = true; + NetworkMessageIntro msg = NetworkMessageIntro(); + this->receiveMessage(&msg); + } + break; + case nmtLaunch: + { + discard = true; + NetworkMessageLaunch msg = NetworkMessageLaunch(); + this->receiveMessage(&msg); + } + break; + case nmtText: + { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got nmtText\n",__FILE__,__FUNCTION__,__LINE__); + discard = true; + NetworkMessageText netMsg = NetworkMessageText(); + this->receiveMessage(&netMsg); + + ChatMsgInfo msg(netMsg.getText().c_str(),netMsg.getSender().c_str(),netMsg.getTeamIndex()); + this->addChatInfo(msg); + } + break; + case nmtSynchNetworkGameData: + { + discard = true; + NetworkMessageSynchNetworkGameData msg = NetworkMessageSynchNetworkGameData(); + this->receiveMessage(&msg); + } + break; + case nmtSynchNetworkGameDataStatus: + { + discard = true; + NetworkMessageSynchNetworkGameDataStatus msg = NetworkMessageSynchNetworkGameDataStatus(); + this->receiveMessage(&msg); + } + break; + case nmtSynchNetworkGameDataFileCRCCheck: + { + discard = true; + NetworkMessageSynchNetworkGameDataFileCRCCheck msg = NetworkMessageSynchNetworkGameDataFileCRCCheck(); + this->receiveMessage(&msg); + } + break; + case nmtSynchNetworkGameDataFileGet: + { + discard = true; + NetworkMessageSynchNetworkGameDataFileGet msg = NetworkMessageSynchNetworkGameDataFileGet(); + this->receiveMessage(&msg); + } + break; + case nmtSwitchSetupRequest: + { + discard = true; + SwitchSetupRequest msg = SwitchSetupRequest(); + this->receiveMessage(&msg); + } + break; + case nmtPlayerIndexMessage: + { + discard = true; + PlayerIndexMessage msg = PlayerIndexMessage(0); + this->receiveMessage(&msg); + } + break; + } + + return discard; } -*/ + }}//end namespace diff --git a/source/glest_game/network/client_interface.h b/source/glest_game/network/client_interface.h index a5fb32a7..df818b1a 100644 --- a/source/glest_game/network/client_interface.h +++ b/source/glest_game/network/client_interface.h @@ -97,10 +97,8 @@ public: protected: Mutex * getServerSynchAccessor() { return NULL; } - -private: - void waitForMessage(); + bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType); }; }}//end namespace diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index ac235415..27234e73 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -509,7 +509,7 @@ void ConnectionSlot::update(bool checkForNewClients) { } if(gotIntro == false && difftime(time(NULL),connectedTime) > GameConstants::maxClientConnectHandshakeSecs) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %d\n",__FILE__,__FUNCTION__,__LINE__,difftime(time(NULL),connectedTime)); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %f\n",__FILE__,__FUNCTION__,__LINE__,difftime(time(NULL),connectedTime)); close(); } } diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index cd5ba4d6..3682e41e 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -62,7 +62,7 @@ ServerInterface::ServerInterface(){ maxClientLagTimeAllowed = Config::getInstance().getInt("MaxClientLagTimeAllowed",intToStr(maxClientLagTimeAllowed).c_str()); warnFrameCountLagPercent = Config::getInstance().getFloat("WarnFrameCountLagPercent",doubleToStr(warnFrameCountLagPercent).c_str()); pauseGameForLaggedClients = Config::getInstance().getFloat("PauseGameForLaggedClients",boolToStr(pauseGameForLaggedClients).c_str()); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] enabledThreadedClientCommandBroadcast = %d, maxFrameCountLagAllowed = %f, maxClientLagTimeAllowed = %d, pauseGameForLaggedClients = %d\n",__FILE__,__FUNCTION__,__LINE__,enabledThreadedClientCommandBroadcast,maxFrameCountLagAllowed,maxClientLagTimeAllowed,pauseGameForLaggedClients); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] enabledThreadedClientCommandBroadcast = %d, maxFrameCountLagAllowed = %f, maxClientLagTimeAllowed = %f, pauseGameForLaggedClients = %d\n",__FILE__,__FUNCTION__,__LINE__,enabledThreadedClientCommandBroadcast,maxFrameCountLagAllowed,maxClientLagTimeAllowed,pauseGameForLaggedClients); for(int i= 0; i 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] build command list took %lld msecs, networkMessageCommandList.getCommandCount() = %d, frameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),networkMessageCommandList.getCommandCount(),frameCount); //broadcast commands broadcastMessage(&networkMessageCommandList); @@ -668,7 +668,7 @@ void ServerInterface::updateKeyframe(int frameCount){ DisplayErrorMessage(ex.what()); } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] broadcastMessage took %d msecs, networkMessageCommandList.getCommandCount() = %d, frameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),networkMessageCommandList.getCommandCount(),frameCount); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] broadcastMessage took %lld msecs, networkMessageCommandList.getCommandCount() = %d, frameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),networkMessageCommandList.getCommandCount(),frameCount); } bool ServerInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMessageType, @@ -693,8 +693,11 @@ bool ServerInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess case nmtText: { discard = true; - NetworkMessageText msg = NetworkMessageText(); - connectionSlot->receiveMessage(&msg); + NetworkMessageText netMsg = NetworkMessageText(); + connectionSlot->receiveMessage(&netMsg); + + ChatMsgInfo msg(netMsg.getText().c_str(),netMsg.getSender().c_str(),netMsg.getTeamIndex()); + this->addChatInfo(msg); } break; case nmtSynchNetworkGameData: diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index ae756e31..f59222a2 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -184,11 +184,11 @@ void World::update(){ //time timeFlow.update(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //water effects waterEffects.update(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //units for(int i=0; igetUnit(j)); } } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //undertake the dead for(int i=0; i 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //food costs for(int i=0; igetResourceTypeCount(); ++i){ @@ -221,21 +221,21 @@ void World::update(){ } } } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //fow smoothing if(fogOfWarSmoothing && ((frameCount+1) % (fogOfWarSmoothingFrameSkip+1))==0){ float fogFactor= static_cast(frameCount%GameConstants::updateFps)/GameConstants::updateFps; minimap.updateFowTex(clamp(fogFactor, 0.f, 1.f)); } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //tick if(frameCount%GameConstants::updateFps==0){ computeFow(); tick(); } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); } void World::tick(){ diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h index bfe1cbf5..d8452acd 100644 --- a/source/shared_lib/include/util/util.h +++ b/source/shared_lib/include/util/util.h @@ -17,6 +17,7 @@ #include #include "thread.h" #include +#include using std::string; using namespace Shared::Platform; @@ -130,6 +131,9 @@ public: #ifndef WIN32 #define OutputDebug(type, fmt, ...) SystemFlags::handleDebug (type, fmt, ##__VA_ARGS__) +// Uncomment the line below to get the compiler to warn us of badly formatted printf like statements which could trash memory +//#define OutputDebug(type, fmt, ...) type; printf(fmt, ##__VA_ARGS__) + #else #define OutputDebug(type, fmt, ...) handleDebug (type, fmt, ##__VA_ARGS__) #endif diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 6f1a3451..06fc0573 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -920,10 +920,10 @@ int Socket::getDataToRead(){ break; } else if(hasDataToRead() == true) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING PEEKING SOCKET DATA, (hasDataToRead() == true) err = %d, sock = %d, size = %u, loopCount = %d\n",__FILE__,__FUNCTION__,__LINE__,err,sock,size,loopCount); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING PEEKING SOCKET DATA, (hasDataToRead() == true) err = %d, sock = %d, size = %lu, loopCount = %d\n",__FILE__,__FUNCTION__,__LINE__,err,sock,size,loopCount); } else { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING PEEKING SOCKET DATA, err = %d, sock = %d, size = %u, loopCount = %d\n",__FILE__,__FUNCTION__,__LINE__,err,sock,size,loopCount); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING PEEKING SOCKET DATA, err = %d, sock = %d, size = %lu, loopCount = %d\n",__FILE__,__FUNCTION__,__LINE__,err,sock,size,loopCount); break; } @@ -1320,7 +1320,7 @@ void ClientSocket::connect(const Ip &ip, int port) } else { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Connected to host [%s] on port = %d sock = %d err = %d", ip.getString().c_str(),port,err); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Connected to host [%s] on port = %d sock = %d err = %d", ip.getString().c_str(),port,sock,err); } } diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index ea0bc492..5029fe34 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -249,18 +249,23 @@ bool Window::handleEvent() { break; } } - catch(std::runtime_error& e) { - std::cerr << "(a) Couldn't process event: " << e.what() << " codelocation = " << codeLocation << "\n"; - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] (a) Couldn't process event: [%s] codeLocation = %s\n",__FILE__,__FUNCTION__,__LINE__,e.what(),codeLocation.c_str()); + catch(const char *e){ + std::cerr << "(a1) Couldn't process event: " << e << " codelocation = " << codeLocation << "\n"; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] (a1) Couldn't process event: [%s] codeLocation = %s\n",__FILE__,__FUNCTION__,__LINE__,e,codeLocation.c_str()); + throw runtime_error(e); + } + catch(const std::runtime_error& e) { + std::cerr << "(a2) Couldn't process event: " << e.what() << " codelocation = " << codeLocation << "\n"; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] (a2) Couldn't process event: [%s] codeLocation = %s\n",__FILE__,__FUNCTION__,__LINE__,e.what(),codeLocation.c_str()); throw runtime_error(e.what()); } - catch(std::exception& e) { + catch(const std::exception& e) { std::cerr << "(b) Couldn't process event: " << e.what() << " codelocation = " << codeLocation << "\n"; SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] (b) Couldn't process event: [%s] codeLocation = %s\n",__FILE__,__FUNCTION__,__LINE__,e.what(),codeLocation.c_str()); } catch(...) { std::cerr << "(c) Couldn't process event: [UNKNOWN ERROR] " << " codelocation = " << codeLocation << "\n"; - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] (b) Couldn't process event: [UNKNOWN ERROR] codeLocation = %s\n",__FILE__,__FUNCTION__,__LINE__,codeLocation.c_str()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] (c) Couldn't process event: [UNKNOWN ERROR] codeLocation = %s\n",__FILE__,__FUNCTION__,__LINE__,codeLocation.c_str()); } //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -448,7 +453,13 @@ void Window::toggleFullscreen() { #else if(Window::allowAltEnterFullscreenToggle == true) { - SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + SDL_Surface *cur_surface = SDL_GetVideoSurface(); + if(cur_surface != NULL) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + SDL_WM_ToggleFullScreen(cur_surface); + } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); } #endif diff --git a/source/shared_lib/sources/sound/sound_file_loader.cpp b/source/shared_lib/sources/sound/sound_file_loader.cpp index a1ebc53e..371fff1f 100644 --- a/source/shared_lib/sources/sound/sound_file_loader.cpp +++ b/source/shared_lib/sources/sound/sound_file_loader.cpp @@ -159,7 +159,7 @@ void OggSoundFileLoader::open(const string &path, SoundInfo *soundInfo){ throw runtime_error("Can't read ogg header info for file: "+path); } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] vi->version = %d, vi->channels = %d, vi->rate = %d, vi->bitrate_upper = %d, vi->bitrate_nominal = %d, vi->bitrate_lower = %d, vi->bitrate_window = %d\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),vi->version,vi->channels,vi->rate,vi->bitrate_upper,vi->bitrate_nominal,vi->bitrate_lower,vi->bitrate_window); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] vi->version = %d, vi->channels = %d, vi->rate = %ld, vi->bitrate_upper = %ld, vi->bitrate_nominal = %ld, vi->bitrate_lower = %ld, vi->bitrate_window = %ld\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),vi->version,vi->channels,vi->rate,vi->bitrate_upper,vi->bitrate_nominal,vi->bitrate_lower,vi->bitrate_window); soundInfo->setChannels(vi->channels); soundInfo->setsamplesPerSecond(vi->rate);