From 965a7ac2ba7dd15713fafdcf6631b549b8a65517 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 19 Mar 2010 23:26:00 +0000 Subject: [PATCH] Updated debug logic to use a debug class to better control debug logging and centralize the control of it. --- source/glest_game/game/chat_manager.cpp | 111 +++++ source/glest_game/game/commander.cpp | 24 +- source/glest_game/game/game.cpp | 14 +- source/glest_game/gui/gui.cpp | 46 +- source/glest_game/main/main.cpp | 4 +- .../menu/menu_state_custom_game.cpp | 24 +- .../glest_game/menu/menu_state_join_game.cpp | 410 ++++++++++++++++++ .../glest_game/network/client_interface.cpp | 103 ++--- source/glest_game/network/connection_slot.cpp | 40 +- .../glest_game/network/network_interface.cpp | 14 +- source/glest_game/network/network_message.cpp | 24 +- .../glest_game/network/server_interface.cpp | 67 +-- source/glest_game/type_instances/unit.cpp | 44 +- source/glest_game/types/unit_type.cpp | 8 +- source/glest_game/world/unit_updater.cpp | 16 +- .../include/platform/posix/socket.h | 3 - source/shared_lib/include/util/util.h | 73 ++++ .../sources/platform/posix/socket.cpp | 24 +- .../sources/platform/sdl/platform_util.cpp | 14 +- .../sources/platform/win32/platform_util.cpp | 13 +- .../sources/platform/win32/socket.cpp | 28 +- source/shared_lib/sources/util/util.cpp | 189 ++++++++ 22 files changed, 1026 insertions(+), 267 deletions(-) create mode 100644 source/glest_game/game/chat_manager.cpp create mode 100644 source/glest_game/menu/menu_state_join_game.cpp create mode 100644 source/shared_lib/include/util/util.h create mode 100644 source/shared_lib/sources/util/util.cpp diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp new file mode 100644 index 00000000..f21ab814 --- /dev/null +++ b/source/glest_game/game/chat_manager.cpp @@ -0,0 +1,111 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2008 Martiņo Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "chat_manager.h" + +#include "window.h" +#include "console.h" +#include "network_manager.h" +#include "lang.h" +#include "util.h" +#include "leak_dumper.h" + +using namespace Shared::Platform; +using namespace Shared::Util; + +namespace Glest{ namespace Game{ + +// ===================================================== +// class ChatManager +// ===================================================== + +const int ChatManager::maxTextLenght= 64; + +ChatManager::ChatManager(){ + console= NULL; + editEnabled= false; + teamMode= false; + thisTeamIndex= -1; +} + +void ChatManager::init(Console* console, int thisTeamIndex){ + this->console= console; + this->thisTeamIndex= thisTeamIndex; +} + +void ChatManager::keyDown(char key){ + + Lang &lang= Lang::getInstance(); + + //toggle team mode + if(!editEnabled && key=='H'){ + if(teamMode){ + teamMode= false; + console->addLine(lang.get("ChatMode") + ": " + lang.get("All")); + } + else{ + teamMode= true; + console->addLine(lang.get("ChatMode") + ": " + lang.get("Team")); + } + } + + if(key==vkReturn){ + if(editEnabled){ + GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); + + editEnabled= false; + if(!text.empty()){ + console->addLine(gameNetworkInterface->getHostName() + ": " + text); + gameNetworkInterface->sendTextMessage(text, teamMode? thisTeamIndex: -1); + } + } + else{ + editEnabled= true; + text.clear(); + } + } + else if(key==vkBack){ + if(!text.empty()){ + text.erase(text.end() -1); + } + } +} + +void ChatManager::keyPress(char c){ + if(editEnabled && text.size()=' '){ + text+= c; + } + } +} + +void ChatManager::updateNetwork() +{ + GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); + string text; + string sender; + + if(!gameNetworkInterface->getChatText().empty()) + { + int teamIndex= gameNetworkInterface->getChatTeamIndex(); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] got nmtText [%s] for team = %d\n",__FILE__,__FUNCTION__,gameNetworkInterface->getChatText().c_str(),teamIndex); + + if(teamIndex==-1 || teamIndex==thisTeamIndex){ + console->addLine(gameNetworkInterface->getChatSender()+": "+gameNetworkInterface->getChatText(), true); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Added text to console\n",__FILE__,__FUNCTION__); + } + } +} + +}}//end namespace diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index fbd4a2fd..7569aae5 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -248,10 +248,10 @@ void Commander::updateNetwork(){ void Commander::giveNetworkCommandSpecial(const NetworkCommand* networkCommand) const { switch(networkCommand->getNetworkCommandType()) { case nctNetworkCommand: { - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] found nctNetworkCommand\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctNetworkCommand\n",__FILE__,__FUNCTION__,__LINE__); switch(networkCommand->getCommandTypeId()) { case ncstRotateUnit: { - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] found ncstRotateUnit [%d]\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->getTargetId()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found ncstRotateUnit [%d]\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->getTargetId()); //!!! int unitTypeId = networkCommand->getUnitId(); @@ -264,18 +264,18 @@ void Commander::giveNetworkCommandSpecial(const NetworkCommand* networkCommand) char unitKey[50]=""; sprintf(unitKey,"%d_%d",unitTypeId,factionIndex); - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] unitKey = [%s]\n",__FILE__,__FUNCTION__,__LINE__,unitKey); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unitKey = [%s]\n",__FILE__,__FUNCTION__,__LINE__,unitKey); Game *game = this->world->getGame(); Gui *gui = game->getGui(); gui->setUnitTypeBuildRotation(unitKey,rotateAmount); //unit->setRotateAmount(networkCommand->getTargetId()); - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] found ncstRotateUnit [%d]\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->getTargetId()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found ncstRotateUnit [%d]\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->getTargetId()); } break; } - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] found nctNetworkCommand\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctNetworkCommand\n",__FILE__,__FUNCTION__,__LINE__); } break; default: @@ -297,24 +297,24 @@ void Commander::giveNetworkCommand(const NetworkCommand* networkCommand) const { case nctGiveCommand:{ assert(networkCommand->getCommandTypeId()!=CommandType::invalidId); - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] found nctGiveCommand networkCommand->getUnitId() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->getUnitId()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctGiveCommand networkCommand->getUnitId() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->getUnitId()); Command* command= buildCommand(networkCommand); unit->giveCommand(command); - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] found nctGiveCommand networkCommand->getUnitId() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->getUnitId()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctGiveCommand networkCommand->getUnitId() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->getUnitId()); } break; case nctCancelCommand: { - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] found nctCancelCommand\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctCancelCommand\n",__FILE__,__FUNCTION__,__LINE__); unit->cancelCommand(); - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] found nctCancelCommand\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctCancelCommand\n",__FILE__,__FUNCTION__,__LINE__); } break; case nctSetMeetingPoint: { - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] found nctSetMeetingPoint\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctSetMeetingPoint\n",__FILE__,__FUNCTION__,__LINE__); unit->setMeetingPos(networkCommand->getPosition()); - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] found nctSetMeetingPoint\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctSetMeetingPoint\n",__FILE__,__FUNCTION__,__LINE__); } break; default: @@ -322,7 +322,7 @@ void Commander::giveNetworkCommand(const NetworkCommand* networkCommand) const { } } else { - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] NULL Unit for id = %d, networkCommand->getNetworkCommandType() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->getUnitId(),networkCommand->getNetworkCommandType()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] NULL Unit for id = %d, networkCommand->getNetworkCommandType() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->getUnitId(),networkCommand->getNetworkCommandType()); } } } diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 5bc21e62..54fb6ef4 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -118,7 +118,7 @@ void Game::load(){ void Game::init() { - if(Socket::enableDebugText) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); Lang &lang= Lang::getInstance(); Logger &logger= Logger::getInstance(); @@ -127,7 +127,7 @@ void Game::init() Map *map= world.getMap(); NetworkManager &networkManager= NetworkManager::getInstance(); - if(Socket::enableDebugText) printf("In [%s::%s] Initializing\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Initializing\n",__FILE__,__FUNCTION__); logger.setState(lang.get("Initializing")); //mesage box @@ -149,7 +149,7 @@ void Game::init() gameCamera.setPos(Vec2f(v.x, v.y)); scriptManager.init(&world, &gameCamera); - if(Socket::enableDebugText) printf("In [%s::%s] creating AI's\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] creating AI's\n",__FILE__,__FUNCTION__); //create IAs aiInterfaces.resize(world.getFactionCount()); @@ -182,7 +182,7 @@ void Game::init() } //init renderer state - if(Socket::enableDebugText) printf("In [%s::%s] Initializing renderer\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Initializing renderer\n",__FILE__,__FUNCTION__); logger.add("Initializing renderer", true); renderer.initGame(this); @@ -204,18 +204,18 @@ void Game::init() soundRenderer.playAmbient(ambientSounds->getSnow()); } - if(Socket::enableDebugText) printf("In [%s::%s] Waiting for network\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Waiting for network\n",__FILE__,__FUNCTION__); logger.add("Waiting for network", true); networkManager.getGameNetworkInterface()->waitUntilReady(&checksum); - if(Socket::enableDebugText) printf("In [%s::%s] Starting music stream\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Starting music stream\n",__FILE__,__FUNCTION__); logger.add("Starting music stream", true); StrSound *gameMusic= world.getThisFaction()->getType()->getMusic(); soundRenderer.playMusic(gameMusic); logger.add("Launching game"); - if(Socket::enableDebugText) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 221437af..1b070b53 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -92,7 +92,7 @@ void SelectionQuad::disable(){ //constructor Gui::Gui(){ - if(Socket::enableDebugText) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); allowRotateUnits = Config::getInstance().getBool("AllowRotateUnits","0"); @@ -106,7 +106,7 @@ Gui::Gui(){ selectingMeetingPoint= false; activePos= invalidPos; - if(Socket::enableDebugText) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } void Gui::init(Game *game){ @@ -179,12 +179,12 @@ void Gui::mouseDownLeftDisplay(int x, int y){ if(selection.isComandable()){ if(selectingBuilding){ - //if(Socket::enableDebugText) printf("In [%s::%s] selectingBuilding == true\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] selectingBuilding == true\n",__FILE__,__FUNCTION__); mouseDownDisplayUnitBuild(posDisplay); } else{ - //if(Socket::enableDebugText) printf("In [%s::%s] selectingBuilding == false\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] selectingBuilding == false\n",__FILE__,__FUNCTION__); mouseDownDisplayUnitSkills(posDisplay); } @@ -198,17 +198,17 @@ void Gui::mouseDownLeftDisplay(int x, int y){ } void Gui::mouseMoveDisplay(int x, int y){ - //if(Socket::enableDebugText) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); computeInfoString(computePosDisplay(x, y)); } void Gui::mouseDownLeftGraphics(int x, int y){ - //if(Socket::enableDebugText) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); if(selectingPos){ - //if(Socket::enableDebugText) printf("In [%s::%s] selectingPos == true\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] selectingPos == true\n",__FILE__,__FUNCTION__); //give standard orders giveTwoClickOrders(x, y); @@ -216,16 +216,16 @@ void Gui::mouseDownLeftGraphics(int x, int y){ } //set meeting point else if(selectingMeetingPoint){ - //if(Socket::enableDebugText) printf("In [%s::%s] selectingMeetingPoint == true\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] selectingMeetingPoint == true\n",__FILE__,__FUNCTION__); if(selection.isComandable()){ - //if(Socket::enableDebugText) printf("In [%s::%s] selection.isComandable() == true\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] selection.isComandable() == true\n",__FILE__,__FUNCTION__); Vec2i targetPos; if(Renderer::getInstance().computePosition(Vec2i(x, y), targetPos)){ - //if(Socket::enableDebugText) printf("In [%s::%s] computePosition() == true\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] computePosition() == true\n",__FILE__,__FUNCTION__); commander->trySetMeetingPoint(selection.getFrontUnit(), targetPos); } @@ -233,19 +233,19 @@ void Gui::mouseDownLeftGraphics(int x, int y){ resetState(); } else{ - //if(Socket::enableDebugText) printf("In [%s::%s] selectionQuad()\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] selectionQuad()\n",__FILE__,__FUNCTION__); selectionQuad.setPosDown(Vec2i(x, y)); computeSelected(false); } computeDisplay(); - //if(Socket::enableDebugText) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } void Gui::mouseDownRightGraphics(int x, int y){ - //if(Socket::enableDebugText) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); if(selectingPos || selectingMeetingPoint){ resetState(); @@ -255,11 +255,11 @@ void Gui::mouseDownRightGraphics(int x, int y){ } computeDisplay(); - //if(Socket::enableDebugText) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } void Gui::mouseUpLeftGraphics(int x, int y){ - //if(Socket::enableDebugText) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); if(!selectingPos && !selectingMeetingPoint){ if(selectionQuad.isEnabled()){ @@ -274,7 +274,7 @@ void Gui::mouseUpLeftGraphics(int x, int y){ } } - //if(Socket::enableDebugText) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } void Gui::mouseMoveGraphics(int x, int y){ @@ -290,7 +290,7 @@ void Gui::mouseMoveGraphics(int x, int y){ //compute position for building if(isPlacingBuilding()){ - //if(Socket::enableDebugText) printf("In [%s::%s] isPlacingBuilding() == true\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] isPlacingBuilding() == true\n",__FILE__,__FUNCTION__); validPosObjWorld= Renderer::getInstance().computePosition(Vec2i(x,y), posObjWorld); } @@ -331,7 +331,7 @@ float Gui::getUnitTypeBuildRotation(string unitKey) const { void Gui::hotKey(char key){ - //if(Socket::enableDebugText) printf("In [%s::%s] key = [%c]\n",__FILE__,__FUNCTION__,key); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] key = [%c]\n",__FILE__,__FUNCTION__,key); if(key==' '){ centerCameraOnSelection(); @@ -351,7 +351,7 @@ void Gui::hotKey(char key){ sprintf(unitKey,"%d_%d",unitType->getId(),factionIndex); float unitTypeRotation = getUnitTypeBuildRotation(unitKey); - if(Socket::enableDebugText) printf("In [%s::%s] factionIndex = %d unitType->getId() = %d unitTypeRotation = %f\n",__FILE__,__FUNCTION__,factionIndex,unitType->getId(),unitTypeRotation); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] factionIndex = %d unitType->getId() = %d unitTypeRotation = %f\n",__FILE__,__FUNCTION__,factionIndex,unitType->getId(),unitTypeRotation); if(unitTypeRotation < 0) { unitTypeRotation = 0; @@ -364,7 +364,7 @@ void Gui::hotKey(char key){ //!!! //if(allowRotateUnits == true && unitRotation > 0) { - if(Socket::enableDebugText) printf("In [%s::%s] before sending nctNetworkCommand RotateUnit unitTypeid = %d, factionIndex = %d, unitTypeRotation = %f\n",__FILE__,__FUNCTION__,unitType->getId(),factionIndex,unitTypeRotation); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] before sending nctNetworkCommand RotateUnit unitTypeid = %d, factionIndex = %d, unitTypeRotation = %f\n",__FILE__,__FUNCTION__,unitType->getId(),factionIndex,unitTypeRotation); //unitRotation = 0; NetworkCommand networkCommand(nctNetworkCommand, ncstRotateUnit, unitType->getId(), factionIndex, (int)unitTypeRotation); @@ -372,11 +372,11 @@ void Gui::hotKey(char key){ GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); gameNetworkInterface->requestCommand(&networkCommand); - //if(Socket::enableDebugText) printf("In [%s::%s] after sending nctNetworkCommand RotateUnit [%d] result = %d\n",__FILE__,__FUNCTION__,builtUnit->getId(),result); - if(Socket::enableDebugText) printf("In [%s::%s] after sending nctNetworkCommand RotateUnit unitTypeid = %d, factionIndex = %d, unitTypeRotation = %f\n",__FILE__,__FUNCTION__,unitType->getId(),factionIndex,unitTypeRotation); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] after sending nctNetworkCommand RotateUnit [%d] result = %d\n",__FILE__,__FUNCTION__,builtUnit->getId(),result); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] after sending nctNetworkCommand RotateUnit unitTypeid = %d, factionIndex = %d, unitTypeRotation = %f\n",__FILE__,__FUNCTION__,unitType->getId(),factionIndex,unitTypeRotation); //} - if(Socket::enableDebugText) printf("In [%s::%s] unitType->getId() = %d NEW unitTypeRotation = %f\n",__FILE__,__FUNCTION__,unitType->getId(),unitTypeRotation); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] unitType->getId() = %d NEW unitTypeRotation = %f\n",__FILE__,__FUNCTION__,unitType->getId(),unitTypeRotation); } else { selectInterestingUnit(iutProducer); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index a6cb9fb5..647c302d 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -160,7 +160,9 @@ int glestMain(int argc, char** argv){ try{ Config &config = Config::getInstance(); - Socket::enableNetworkDebugInfo = (config.getBool("DebugMode","0") || config.getBool("DebugNetwork","0")); + SystemFlags::enableNetworkDebugInfo = config.getBool("DebugNetwork","0"); + SystemFlags::enableDebugText = config.getBool("DebugMode","0"); + NetworkInterface::setDisplayMessageFunction(ExceptionHandler::DisplayMessage); showCursor(config.getBool("Windowed")); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 21120a92..ea15763c 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -224,7 +224,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ } } else if(listBoxMap.mouseClick(x, y)){ - printf("%s\n", mapFiles[listBoxMap.getSelectedItemIndex()].c_str()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", mapFiles[listBoxMap.getSelectedItemIndex()].c_str()); loadMapInfo(Map::getMapPath(mapFiles[listBoxMap.getSelectedItemIndex()]), &mapInfo); labelMapInfo.setText(mapInfo.desc); @@ -372,18 +372,18 @@ void MenuStateCustomGame::update() { if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) { - //if(Socket::enableDebugText) printf("In [%s::%s] START - ctNetwork\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START - ctNetwork\n",__FILE__,__FUNCTION__); ConnectionSlot* connectionSlot= serverInterface->getSlot(i); assert(connectionSlot!=NULL); - //if(Socket::enableDebugText) printf("In [%s::%s] A - ctNetwork\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] A - ctNetwork\n",__FILE__,__FUNCTION__); if(connectionSlot->isConnected()) { haveAtLeastOneNetworkClientConnected = true; - //if(Socket::enableDebugText) printf("In [%s::%s] B - ctNetwork\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] B - ctNetwork\n",__FILE__,__FUNCTION__); string label = connectionSlot->getName(); if(connectionSlot->getAllowDownloadDataSynch() == true && @@ -445,12 +445,12 @@ void MenuStateCustomGame::update() } else { - //if(Socket::enableDebugText) printf("In [%s::%s] C - ctNetwork\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] C - ctNetwork\n",__FILE__,__FUNCTION__); labelNetStatus[i].setText(lang.get("NotConnected")); } - //if(Socket::enableDebugText) printf("In [%s::%s] END - ctNetwork\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END - ctNetwork\n",__FILE__,__FUNCTION__); } else{ labelNetStatus[i].setText(""); @@ -480,7 +480,7 @@ void MenuStateCustomGame::update() void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { - //if(Socket::enableDebugText) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); int factionCount= 0; @@ -510,11 +510,11 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) } gameSettings->setFactionCount(factionCount); - //if(Socket::enableDebugText) printf("In [%s::%s] gameSettings->getTileset() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTileset().c_str()); - //if(Socket::enableDebugText) printf("In [%s::%s] gameSettings->getTech() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTech().c_str()); - //if(Socket::enableDebugText) printf("In [%s::%s] gameSettings->getMap() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getMap().c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTileset() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTileset().c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTech() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTech().c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getMap() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getMap().c_str()); - //if(Socket::enableDebugText) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } // ============ PRIVATE =========================== @@ -599,7 +599,7 @@ void MenuStateCustomGame::reloadFactions(){ for(int i= 0; iisConnected()){ + //server type + if(listBoxServerType.mouseClick(x, y)){ + if(!listBoxServers.getText().empty()){ + labelServerIp.setText(servers.getString(listBoxServers.getText())+"_"); + } + } + + //server list + else if(listBoxServerType.getSelectedItemIndex()!=newServerIndex){ + if(listBoxServers.mouseClick(x, y)){ + labelServerIp.setText(servers.getString(listBoxServers.getText())+"_"); + } + } + } + + //return + if(buttonReturn.mouseClick(x, y)) + { + soundRenderer.playFx(coreData.getClickSoundA()); + + if(clientInterface->getSocket() != NULL) + { + if(clientInterface->isConnected() == true) + { + string sQuitText = clientInterface->getHostName() + " has chosen to leave the game!"; + clientInterface->sendTextMessage(sQuitText,-1); + } + clientInterface->close(); + } + + mainMenu->setState(new MenuStateRoot(program, mainMenu)); + } + + //connect + else if(buttonConnect.mouseClick(x, y)) + { + ClientInterface* clientInterface= networkManager.getClientInterface(); + + soundRenderer.playFx(coreData.getClickSoundA()); + labelInfo.setText(""); + + if(clientInterface->isConnected()) + { + clientInterface->reset(); + } + else + { + connectToServer(); + } + } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); +} + +void MenuStateJoinGame::mouseMove(int x, int y, const MouseState *ms){ + buttonReturn.mouseMove(x, y); + buttonConnect.mouseMove(x, y); + listBoxServerType.mouseMove(x, y); + + //hide-show options depending on the selection + if(listBoxServers.getSelectedItemIndex()==newServerIndex){ + labelServerIp.mouseMove(x, y); + } + else{ + listBoxServers.mouseMove(x, y); + } +} + +void MenuStateJoinGame::render(){ + Renderer &renderer= Renderer::getInstance(); + + renderer.renderButton(&buttonReturn); + renderer.renderLabel(&labelServer); + renderer.renderLabel(&labelServerType); + renderer.renderLabel(&labelStatus); + renderer.renderLabel(&labelInfo); + renderer.renderButton(&buttonConnect); + renderer.renderListBox(&listBoxServerType); + + if(listBoxServerType.getSelectedItemIndex()==newServerIndex){ + renderer.renderLabel(&labelServerIp); + } + else + { + renderer.renderListBox(&listBoxServers); + } + + renderer.renderChatManager(&chatManager); + renderer.renderConsole(&console); +} + +void MenuStateJoinGame::update() +{ + ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface(); + Lang &lang= Lang::getInstance(); + + //update status label + if(clientInterface->isConnected()) + { + buttonConnect.setText(lang.get("Disconnect")); + + if(clientInterface->getAllowDownloadDataSynch() == false) + { + string label = lang.get("ConnectedToServer"); + + if(!clientInterface->getServerName().empty()) + { + label = label + " " + clientInterface->getServerName(); + } + + if(clientInterface->getAllowGameDataSynchCheck() == true && + clientInterface->getNetworkGameDataSynchCheckOk() == false) + { + label = label + " - warning synch mismatch for:"; + if(clientInterface->getNetworkGameDataSynchCheckOkMap() == false) + { + label = label + " map"; + } + if(clientInterface->getNetworkGameDataSynchCheckOkTile() == false) + { + label = label + " tile"; + } + if(clientInterface->getNetworkGameDataSynchCheckOkTech() == false) + { + label = label + " techtree"; + } + if(clientInterface->getNetworkGameDataSynchCheckOkFogOfWar() == false) + { + label = label + " FogOfWar == false"; + } + } + else if(clientInterface->getAllowGameDataSynchCheck() == true) + { + label += " - data synch is ok"; + } + + labelStatus.setText(label); + } + else + { + string label = lang.get("ConnectedToServer"); + + if(!clientInterface->getServerName().empty()) + { + label = label + " " + clientInterface->getServerName(); + } + + if(clientInterface->getAllowGameDataSynchCheck() == true && + clientInterface->getNetworkGameDataSynchCheckOk() == false) + { + label = label + " - waiting to synch:"; + if(clientInterface->getNetworkGameDataSynchCheckOkMap() == false) + { + label = label + " map"; + } + if(clientInterface->getNetworkGameDataSynchCheckOkTile() == false) + { + label = label + " tile"; + } + if(clientInterface->getNetworkGameDataSynchCheckOkTech() == false) + { + label = label + " techtree"; + } + if(clientInterface->getNetworkGameDataSynchCheckOkFogOfWar() == false) + { + label = label + " FogOfWar == false"; + } + } + else if(clientInterface->getAllowGameDataSynchCheck() == true) + { + label += " - data synch is ok"; + } + + labelStatus.setText(label); + } + } + else + { + buttonConnect.setText(lang.get("Connect")); + labelStatus.setText(lang.get("NotConnected")); + labelInfo.setText(""); + } + + //process network messages + if(clientInterface->isConnected()) + { + //update lobby + clientInterface->updateLobby(); + + //call the chat manager + chatManager.updateNetwork(); + + //console + console.update(); + + //intro + if(clientInterface->getIntroDone()) + { + labelInfo.setText(lang.get("WaitingHost")); + servers.setString(clientInterface->getServerName(), Ip(labelServerIp.getText()).getString()); + } + + //launch + if(clientInterface->getLaunchGame()) + { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - A\n",__FILE__,__FUNCTION__); + + servers.save(serverFileName); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - B\n",__FILE__,__FUNCTION__); + + program->setState(new Game(program, clientInterface->getGameSettings())); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - C\n",__FILE__,__FUNCTION__); + } + } + + if(clientInterface->getLaunchGame()) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - D\n",__FILE__,__FUNCTION__); +} + +void MenuStateJoinGame::keyDown(char key){ + ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface(); + + if(!clientInterface->isConnected()) + { + if(key==vkBack){ + string text= labelServerIp.getText(); + + if(text.size()>1){ + text.erase(text.end()-2); + } + + labelServerIp.setText(text); + } + } + else + { + //send key to the chat manager + chatManager.keyDown(key); + } +} + +void MenuStateJoinGame::keyPress(char c){ + ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface(); + + if(!clientInterface->isConnected()) + { + int maxTextSize= 16; + + if(c>='0' && c<='9'){ + + if(labelServerIp.getText().size()connect(serverIp, GameConstants::serverPort); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] server - [%s]\n",__FILE__,__FUNCTION__,serverIp.getString().c_str()); + + labelServerIp.setText(serverIp.getString()+'_'); + labelInfo.setText(""); + + //save server ip + config.setString("ServerIp", serverIp.getString()); + config.save(); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); +} + +}}//end namespace diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 1e15b81a..3bf62701 100755 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -51,7 +51,7 @@ ClientInterface::ClientInterface(){ ClientInterface::~ClientInterface() { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); if(clientSocket != NULL && clientSocket->isConnected() == true) { @@ -62,12 +62,12 @@ ClientInterface::~ClientInterface() delete clientSocket; clientSocket = NULL; - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } void ClientInterface::connect(const Ip &ip, int port) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); delete clientSocket; @@ -78,7 +78,7 @@ void ClientInterface::connect(const Ip &ip, int port) clientSocket->setBlock(false); clientSocket->connect(ip, port); - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END - socket = %d\n",__FILE__,__FUNCTION__,clientSocket->getSocketId()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END - socket = %d\n",__FILE__,__FUNCTION__,clientSocket->getSocketId()); } void ClientInterface::reset() @@ -134,7 +134,7 @@ void ClientInterface::updateLobby() if(receiveMessage(&networkMessageIntro)) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got NetworkMessageIntro\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got NetworkMessageIntro\n",__FILE__,__FUNCTION__); //check consistency @@ -178,7 +178,7 @@ void ClientInterface::updateLobby() if(receiveMessage(&networkMessageSynchNetworkGameData)) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got NetworkMessageSynchNetworkGameData\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got NetworkMessageSynchNetworkGameData\n",__FILE__,__FUNCTION__); // check the checksum's int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(string(GameConstants::folder_path_tilesets) + "/" + @@ -187,7 +187,7 @@ void ClientInterface::updateLobby() this->setNetworkGameDataSynchCheckOkTile((tilesetCRC == networkMessageSynchNetworkGameData.getTilesetCRC())); if(this->getNetworkGameDataSynchCheckOkTile() == false) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] tilesetCRC mismatch, local = %d, remote = %d\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] tilesetCRC mismatch, local = %d, remote = %d\n", __FILE__,__FUNCTION__,tilesetCRC,networkMessageSynchNetworkGameData.getTilesetCRC()); } @@ -200,7 +200,7 @@ void ClientInterface::updateLobby() if(this->getNetworkGameDataSynchCheckOkTech() == false) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] techCRC mismatch, local = %d, remote = %d\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] techCRC mismatch, local = %d, remote = %d\n", __FILE__,__FUNCTION__,techCRC,networkMessageSynchNetworkGameData.getTechCRC()); } @@ -209,13 +209,13 @@ void ClientInterface::updateLobby() string file = Map::getMapPath(networkMessageSynchNetworkGameData.getMap()); checksum.addFile(file); int32 mapCRC = checksum.getSum(); - //if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] file = [%s] checksum = %d\n",__FILE__,__FUNCTION__,file.c_str(),mapCRC); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] file = [%s] checksum = %d\n",__FILE__,__FUNCTION__,file.c_str(),mapCRC); this->setNetworkGameDataSynchCheckOkMap((mapCRC == networkMessageSynchNetworkGameData.getMapCRC())); if(this->getNetworkGameDataSynchCheckOkMap() == false) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] mapCRC mismatch, local = %d, remote = %d\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] mapCRC mismatch, local = %d, remote = %d\n", __FILE__,__FUNCTION__,mapCRC,networkMessageSynchNetworkGameData.getMapCRC()); } @@ -224,7 +224,7 @@ void ClientInterface::updateLobby() if(this->getNetworkGameDataSynchCheckOkFogOfWar() == false) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] getFogOfWar mismatch, local = %d, remote = %d\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] getFogOfWar mismatch, local = %d, remote = %d\n", __FILE__,__FUNCTION__,getFogOfWar(),networkMessageSynchNetworkGameData.getFogOfWar()); } @@ -239,49 +239,42 @@ void ClientInterface::updateLobby() NetworkMessageSynchNetworkGameDataFileCRCCheck networkMessageSynchNetworkGameDataFileCRCCheck; if(receiveMessage(&networkMessageSynchNetworkGameDataFileCRCCheck)) { - /* - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got nmtSynchNetworkGameDataFileCRCCheck totalfiles = %d, fileindex = %d, crc = %d, file [%s]\n", - __FILE__,__FUNCTION__,networkMessageSynchNetworkGameDataFileCRCCheck.getTotalFileCount(), - networkMessageSynchNetworkGameDataFileCRCCheck.getFileIndex(), - networkMessageSynchNetworkGameDataFileCRCCheck.getFileCRC(), - networkMessageSynchNetworkGameDataFileCRCCheck.getFileName().c_str()); - */ - Checksum checksum; - string file = networkMessageSynchNetworkGameDataFileCRCCheck.getFileName(); - checksum.addFile(file); - int32 fileCRC = checksum.getSum(); + Checksum checksum; + string file = networkMessageSynchNetworkGameDataFileCRCCheck.getFileName(); + checksum.addFile(file); + int32 fileCRC = checksum.getSum(); - if(fileCRC != networkMessageSynchNetworkGameDataFileCRCCheck.getFileCRC()) - { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got nmtSynchNetworkGameDataFileCRCCheck localCRC = %d, remoteCRC = %d, file [%s]\n", - __FILE__,__FUNCTION__,fileCRC, - networkMessageSynchNetworkGameDataFileCRCCheck.getFileCRC(), - networkMessageSynchNetworkGameDataFileCRCCheck.getFileName().c_str()); + if(fileCRC != networkMessageSynchNetworkGameDataFileCRCCheck.getFileCRC()) + { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataFileCRCCheck localCRC = %d, remoteCRC = %d, file [%s]\n", + __FILE__,__FUNCTION__,fileCRC, + networkMessageSynchNetworkGameDataFileCRCCheck.getFileCRC(), + networkMessageSynchNetworkGameDataFileCRCCheck.getFileName().c_str()); - // Here we initiate a download of missing or mismatched content + // Here we initiate a download of missing or mismatched content - NetworkMessageSynchNetworkGameDataFileGet sendNetworkMessageSynchNetworkGameDataFileGet(networkMessageSynchNetworkGameDataFileCRCCheck.getFileName()); - sendMessage(&sendNetworkMessageSynchNetworkGameDataFileGet); + NetworkMessageSynchNetworkGameDataFileGet sendNetworkMessageSynchNetworkGameDataFileGet(networkMessageSynchNetworkGameDataFileCRCCheck.getFileName()); + sendMessage(&sendNetworkMessageSynchNetworkGameDataFileGet); - FileTransferInfo fileInfo; - fileInfo.hostType = eClient; - fileInfo.serverIP = this->ip.getString(); - fileInfo.serverPort = this->port; - fileInfo.fileName = networkMessageSynchNetworkGameDataFileCRCCheck.getFileName(); + FileTransferInfo fileInfo; + fileInfo.hostType = eClient; + fileInfo.serverIP = this->ip.getString(); + fileInfo.serverPort = this->port; + fileInfo.fileName = networkMessageSynchNetworkGameDataFileCRCCheck.getFileName(); - FileTransferSocketThread *fileXferThread = new FileTransferSocketThread(fileInfo); - fileXferThread->start(); - } + FileTransferSocketThread *fileXferThread = new FileTransferSocketThread(fileInfo); + fileXferThread->start(); + } - if(networkMessageSynchNetworkGameDataFileCRCCheck.getFileIndex() < networkMessageSynchNetworkGameDataFileCRCCheck.getTotalFileCount()) - { - NetworkMessageSynchNetworkGameDataFileCRCCheck sendNetworkMessageSynchNetworkGameDataFileCRCCheck( - networkMessageSynchNetworkGameDataFileCRCCheck.getTotalFileCount(), - networkMessageSynchNetworkGameDataFileCRCCheck.getFileIndex() + 1, - 0, - ""); - sendMessage(&sendNetworkMessageSynchNetworkGameDataFileCRCCheck); - } + if(networkMessageSynchNetworkGameDataFileCRCCheck.getFileIndex() < networkMessageSynchNetworkGameDataFileCRCCheck.getTotalFileCount()) + { + NetworkMessageSynchNetworkGameDataFileCRCCheck sendNetworkMessageSynchNetworkGameDataFileCRCCheck( + networkMessageSynchNetworkGameDataFileCRCCheck.getTotalFileCount(), + networkMessageSynchNetworkGameDataFileCRCCheck.getFileIndex() + 1, + 0, + ""); + sendMessage(&sendNetworkMessageSynchNetworkGameDataFileCRCCheck); + } } } break; @@ -291,7 +284,7 @@ void ClientInterface::updateLobby() NetworkMessageText networkMessageText; if(receiveMessage(&networkMessageText)) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__); chatText = networkMessageText.getText(); chatSender = networkMessageText.getSender(); @@ -306,7 +299,7 @@ void ClientInterface::updateLobby() if(receiveMessage(&networkMessageLaunch)) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got NetworkMessageLaunch\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got NetworkMessageLaunch\n",__FILE__,__FUNCTION__); networkMessageLaunch.buildGameSettings(&gameSettings); @@ -427,7 +420,7 @@ void ClientInterface::updateKeyframe(int frameCount) void ClientInterface::waitUntilReady(Checksum* checksum) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); Logger &logger= Logger::getInstance(); @@ -512,7 +505,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) //delay the start a bit, so clients have nore room to get messages sleep(GameConstants::networkExtraLatency); - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } void ClientInterface::sendTextMessage(const string &text, int teamIndex){ @@ -557,7 +550,7 @@ void ClientInterface::waitForMessage() void ClientInterface::quitGame(bool userManuallyQuit) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); if(clientSocket != NULL && userManuallyQuit == true) { @@ -566,12 +559,12 @@ void ClientInterface::quitGame(bool userManuallyQuit) close(); } - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } void ClientInterface::close() { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); delete clientSocket; clientSocket= NULL; diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index c02f2779..551753d0 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -52,11 +52,11 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex ConnectionSlot::~ConnectionSlot() { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); close(); - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } void ConnectionSlot::update() @@ -82,7 +82,7 @@ void ConnectionSlot::update(bool checkForNewClients) //send intro message when connected if(socket != NULL) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] accepted new client connection\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] accepted new client connection\n",__FILE__,__FUNCTION__); chatText.clear(); chatSender.clear(); @@ -111,7 +111,7 @@ void ConnectionSlot::update(bool checkForNewClients) case nmtText: { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__); NetworkMessageText networkMessageText; if(receiveMessage(&networkMessageText)) @@ -120,7 +120,7 @@ void ConnectionSlot::update(bool checkForNewClients) chatSender = networkMessageText.getSender(); chatTeamIndex = networkMessageText.getTeamIndex(); - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,chatText.c_str(),chatSender.c_str(),chatTeamIndex); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,chatText.c_str(),chatSender.c_str(),chatTeamIndex); } } break; @@ -128,7 +128,7 @@ void ConnectionSlot::update(bool checkForNewClients) //command list case nmtCommandList: { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got nmtCommandList\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtCommandList\n",__FILE__,__FUNCTION__); NetworkMessageCommandList networkMessageCommandList; if(receiveMessage(&networkMessageCommandList)) @@ -145,18 +145,18 @@ void ConnectionSlot::update(bool checkForNewClients) case nmtIntro: { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got nmtIntro\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtIntro\n",__FILE__,__FUNCTION__); NetworkMessageIntro networkMessageIntro; if(receiveMessage(&networkMessageIntro)) { name= networkMessageIntro.getName(); - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got name [%s]\n",__FILE__,__FUNCTION__,name.c_str()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got name [%s]\n",__FILE__,__FUNCTION__,name.c_str()); if(getAllowGameDataSynchCheck() == true && serverInterface->getGameSettings() != NULL) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] sending NetworkMessageSynchNetworkGameData\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] sending NetworkMessageSynchNetworkGameData\n",__FILE__,__FUNCTION__); NetworkMessageSynchNetworkGameData networkMessageSynchNetworkGameData(serverInterface->getGameSettings()); sendMessage(&networkMessageSynchNetworkGameData); @@ -169,7 +169,7 @@ void ConnectionSlot::update(bool checkForNewClients) case nmtSynchNetworkGameDataStatus: { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got nmtSynchNetworkGameDataStatus\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataStatus\n",__FILE__,__FUNCTION__); NetworkMessageSynchNetworkGameDataStatus networkMessageSynchNetworkGameDataStatus; if(receiveMessage(&networkMessageSynchNetworkGameDataStatus)) @@ -196,14 +196,14 @@ void ConnectionSlot::update(bool checkForNewClients) networkGameDataSynchCheckOkTech == true && networkGameDataSynchCheckOkFogOfWar == true) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] client data synch ok\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] client data synch ok\n",__FILE__,__FUNCTION__); } else { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] mapCRC = %d, remote = %d\n",__FILE__,__FUNCTION__,mapCRC,networkMessageSynchNetworkGameDataStatus.getMapCRC()); - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] tilesetCRC = %d, remote = %d\n",__FILE__,__FUNCTION__,tilesetCRC,networkMessageSynchNetworkGameDataStatus.getTilesetCRC()); - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] techCRC = %d, remote = %d\n",__FILE__,__FUNCTION__,techCRC,networkMessageSynchNetworkGameDataStatus.getTechCRC()); - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] serverInterface->getFogOfWar() = %d, remote = %d\n",__FILE__,__FUNCTION__,serverInterface->getFogOfWar(),networkMessageSynchNetworkGameDataStatus.getFogOfWar()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] mapCRC = %d, remote = %d\n",__FILE__,__FUNCTION__,mapCRC,networkMessageSynchNetworkGameDataStatus.getMapCRC()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] tilesetCRC = %d, remote = %d\n",__FILE__,__FUNCTION__,tilesetCRC,networkMessageSynchNetworkGameDataStatus.getTilesetCRC()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] techCRC = %d, remote = %d\n",__FILE__,__FUNCTION__,techCRC,networkMessageSynchNetworkGameDataStatus.getTechCRC()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] serverInterface->getFogOfWar() = %d, remote = %d\n",__FILE__,__FUNCTION__,serverInterface->getFogOfWar(),networkMessageSynchNetworkGameDataStatus.getFogOfWar()); if(allowDownloadDataSynch == true) { @@ -251,7 +251,7 @@ void ConnectionSlot::update(bool checkForNewClients) case nmtSynchNetworkGameDataFileCRCCheck: { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got nmtSynchNetworkGameDataFileCRCCheck\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataFileCRCCheck\n",__FILE__,__FUNCTION__); NetworkMessageSynchNetworkGameDataFileCRCCheck networkMessageSynchNetworkGameDataFileCRCCheck; if(receiveMessage(&networkMessageSynchNetworkGameDataFileCRCCheck)) @@ -266,7 +266,7 @@ void ConnectionSlot::update(bool checkForNewClients) case nmtSynchNetworkGameDataFileGet: { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] got nmtSynchNetworkGameDataFileGet\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataFileGet\n",__FILE__,__FUNCTION__); NetworkMessageSynchNetworkGameDataFileGet networkMessageSynchNetworkGameDataFileGet; if(receiveMessage(&networkMessageSynchNetworkGameDataFileGet)) @@ -295,7 +295,7 @@ void ConnectionSlot::update(bool checkForNewClients) } else { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] calling close...\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] calling close...\n",__FILE__,__FUNCTION__); close(); } @@ -304,7 +304,7 @@ void ConnectionSlot::update(bool checkForNewClients) void ConnectionSlot::close() { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); delete socket; socket= NULL; @@ -313,7 +313,7 @@ void ConnectionSlot::close() chatSender.clear(); chatTeamIndex= -1; - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } bool ConnectionSlot::getFogOfWar() diff --git a/source/glest_game/network/network_interface.cpp b/source/glest_game/network/network_interface.cpp index e052268d..7024c367 100644 --- a/source/glest_game/network/network_interface.cpp +++ b/source/glest_game/network/network_interface.cpp @@ -17,9 +17,10 @@ #include "types.h" #include "conversion.h" #include "platform_util.h" +#include +#include "util.h" #include "leak_dumper.h" -#include using namespace Shared::Platform; using namespace Shared::Util; @@ -56,11 +57,11 @@ NetworkMessageType NetworkInterface::getNextMessageType(bool checkHasDataFirst) //peek message type int dataSize = socket->getDataToRead(); if(dataSize >= sizeof(messageType)){ - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] socket->getDataToRead() dataSize = %d\n",__FILE__,__FUNCTION__,dataSize); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() dataSize = %d\n",__FILE__,__FUNCTION__,dataSize); int iPeek = socket->peek(&messageType, sizeof(messageType)); - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] socket->getDataToRead() iPeek = %d, messageType = %d\n",__FILE__,__FUNCTION__,iPeek,messageType); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() iPeek = %d, messageType = %d\n",__FILE__,__FUNCTION__,iPeek,messageType); } //sanity check new message type @@ -74,7 +75,7 @@ NetworkMessageType NetworkInterface::getNextMessageType(bool checkHasDataFirst) bool NetworkInterface::receiveMessage(NetworkMessage* networkMessage){ - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s]\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s]\n",__FILE__,__FUNCTION__); Socket* socket= getSocket(); @@ -82,12 +83,7 @@ bool NetworkInterface::receiveMessage(NetworkMessage* networkMessage){ } bool NetworkInterface::isConnected(){ - //if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); - bool result = (getSocket()!=NULL && getSocket()->isConnected()); - - //if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); - return result; } diff --git a/source/glest_game/network/network_message.cpp b/source/glest_game/network/network_message.cpp index c3277802..1fcc26bd 100644 --- a/source/glest_game/network/network_message.cpp +++ b/source/glest_game/network/network_message.cpp @@ -49,18 +49,18 @@ bool NetworkMessage::receive(Socket* socket, void* data, int dataSize) } else { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__); } } else { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] dataSize = %d\n",__FILE__,__FUNCTION__,dataSize); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] dataSize = %d\n",__FILE__,__FUNCTION__,dataSize); } return true; } else { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] socket->getDataToRead() returned %d\n",__FILE__,__FUNCTION__,ipeekdatalen); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() returned %d\n",__FILE__,__FUNCTION__,ipeekdatalen); } return false; } @@ -75,7 +75,7 @@ void NetworkMessage::send(Socket* socket, const void* data, int dataSize) const } else { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__); } } } @@ -208,22 +208,22 @@ bool NetworkMessageCommandList::receive(Socket* socket){ // read type, commandCount & frame num first. if (!NetworkMessage::receive(socket, &data, networkPacketMsgTypeSize)) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s %d] NetworkMessage::receive failed!\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] NetworkMessage::receive failed!\n",__FILE__,__FUNCTION__,__LINE__); return false; } - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s %d] messageType = %d, frameCount = %d, data.commandCount = %d\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] messageType = %d, frameCount = %d, data.commandCount = %d\n", __FILE__,__FUNCTION__,__LINE__,data.messageType,data.frameCount,data.commandCount); // read data.commandCount commands. if (data.commandCount) { bool result = NetworkMessage::receive(socket, &data.commands, sizeof(NetworkCommand) * data.commandCount); - if(Socket::enableNetworkDebugInfo) { + if(SystemFlags::enableNetworkDebugInfo) { for(int idx = 0 ; idx < data.commandCount; ++idx) { const NetworkCommand &cmd = data.commands[idx]; - printf("In [%s::%s %d] index = %d, networkCommandType = %d, unitId = %d, commandTypeId = %d, positionX = %d, positionY = %d, unitTypeId = %d, targetId = %d\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] index = %d, networkCommandType = %d, unitId = %d, commandTypeId = %d, positionX = %d, positionY = %d, unitTypeId = %d, targetId = %d\n", __FILE__,__FUNCTION__,__LINE__,idx, cmd.getNetworkCommandType(),cmd.getUnitId(), cmd.getCommandTypeId(), cmd.getPosition().x,cmd.getPosition().y, cmd.getUnitTypeId(), cmd.getTargetId()); } @@ -239,15 +239,15 @@ void NetworkMessageCommandList::send(Socket* socket) const{ //NetworkMessage::send(socket, &data, sizeof(data)); NetworkMessage::send(socket, &data, networkPacketMsgTypeSize + sizeof(NetworkCommand) * data.commandCount); - if(Socket::enableNetworkDebugInfo) { - printf("In [%s::%s %d] messageType = %d, frameCount = %d, data.commandCount = %d\n", + if(SystemFlags::enableNetworkDebugInfo) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] messageType = %d, frameCount = %d, data.commandCount = %d\n", __FILE__,__FUNCTION__,__LINE__,data.messageType,data.frameCount,data.commandCount); if (data.commandCount) { for(int idx = 0 ; idx < data.commandCount; ++idx) { const NetworkCommand &cmd = data.commands[idx]; - printf("In [%s::%s %d] index = %d, networkCommandType = %d, unitId = %d, commandTypeId = %d, positionX = %d, positionY = %d, unitTypeId = %d, targetId = %d\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] index = %d, networkCommandType = %d, unitId = %d, commandTypeId = %d, positionX = %d, positionY = %d, unitTypeId = %d, targetId = %d\n", __FILE__,__FUNCTION__,__LINE__,idx, cmd.getNetworkCommandType(),cmd.getUnitId(), cmd.getCommandTypeId(), cmd.getPosition().x,cmd.getPosition().y, cmd.getUnitTypeId(), cmd.getTargetId()); } @@ -315,7 +315,7 @@ NetworkMessageSynchNetworkGameData::NetworkMessageSynchNetworkGameData(const Gam string file = Map::getMapPath(gameSettings->getMap()); checksum.addFile(file); data.mapCRC = checksum.getSum(); - //if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] file = [%s] checksum = %d\n",__FILE__,__FUNCTION__,file.c_str(),data.mapCRC); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] file = [%s] checksum = %d\n",__FILE__,__FUNCTION__,file.c_str(),data.mapCRC); data.hasFogOfWar = Config::getInstance().getBool("FogOfWar");; } diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 5b354b3a..41657aa5 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -18,10 +18,11 @@ #include "conversion.h" #include "config.h" #include "lang.h" - -#include "leak_dumper.h" #include "logger.h" #include +#include "util.h" + +#include "leak_dumper.h" using namespace std; using namespace Shared::Platform; @@ -45,7 +46,7 @@ ServerInterface::ServerInterface(){ } ServerInterface::~ServerInterface(){ - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); for(int i= 0; i=0 && playerIndex 0) { - if(gameHasBeenInitiated && Socket::enableNetworkDebugInfo) printf("In [%s::%s] socketTriggeredList.size() = %d\n",__FILE__,__FUNCTION__,socketTriggeredList.size()); + if(gameHasBeenInitiated) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socketTriggeredList.size() = %d\n",__FILE__,__FUNCTION__,socketTriggeredList.size()); bool hasData = Socket::hasDataToRead(socketTriggeredList); - if(hasData && Socket::enableNetworkDebugInfo) printf("In [%s::%s] hasData == true\n",__FILE__,__FUNCTION__); + if(hasData) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] hasData == true\n",__FILE__,__FUNCTION__); if(gameHasBeenInitiated == false || hasData == true) { @@ -138,16 +139,16 @@ void ServerInterface::update() if(connectionSlot->isConnected() == false || (socketTriggeredList[connectionSlot->getSocket()->getSocketId()] == true)) { - if(gameHasBeenInitiated && Socket::enableNetworkDebugInfo) printf("In [%s::%s] socketTriggeredList[i] = %i\n",__FILE__,__FUNCTION__,(socketTriggeredList[connectionSlot->getSocket()->getSocketId()] ? 1 : 0)); + if(gameHasBeenInitiated) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socketTriggeredList[i] = %i\n",__FILE__,__FUNCTION__,(socketTriggeredList[connectionSlot->getSocket()->getSocketId()] ? 1 : 0)); if(connectionSlot->isConnected()) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] calling slots[i]->update() for slot = %d socketId = %d\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] calling slots[i]->update() for slot = %d socketId = %d\n", __FILE__,__FUNCTION__,i,connectionSlot->getSocket()->getSocketId()); } else { - if(gameHasBeenInitiated && Socket::enableNetworkDebugInfo) printf("In [%s::%s] slot = %d getSocket() == NULL\n",__FILE__,__FUNCTION__,i); + if(gameHasBeenInitiated) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] slot = %d getSocket() == NULL\n",__FILE__,__FUNCTION__,i); } connectionSlot->update(checkForNewClients); @@ -172,7 +173,7 @@ void ServerInterface::update() //teamMessageData.sourceTeamIndex = i; //vctTeamMessages.push_back(teamMessageData); - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] #1 about to broadcast nmtText chatText [%s] chatSender [%s] chatTeamIndex = %d for SlotIndex# %d\n",__FILE__,__FUNCTION__,chatText.c_str(),chatSender.c_str(),chatTeamIndex,i); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #1 about to broadcast nmtText chatText [%s] chatSender [%s] chatTeamIndex = %d for SlotIndex# %d\n",__FILE__,__FUNCTION__,chatText.c_str(),chatSender.c_str(),chatTeamIndex,i); NetworkMessageText networkMessageText(chatText,chatSender,chatTeamIndex); broadcastMessage(&networkMessageText, i); @@ -198,7 +199,7 @@ void ServerInterface::update() { if(connectionSlot->isConnected() && socketTriggeredList[connectionSlot->getSocket()->getSocketId()] == true) { - if(connectionSlot->getSocket() != NULL && Socket::enableNetworkDebugInfo) printf("In [%s::%s] calling connectionSlot->getNextMessageType() for slots[i]->getSocket()->getSocketId() = %d\n", + if(connectionSlot->getSocket() != NULL) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] calling connectionSlot->getNextMessageType() for slots[i]->getSocket()->getSocketId() = %d\n", __FILE__,__FUNCTION__,connectionSlot->getSocket()->getSocketId()); if(connectionSlot->getNextMessageType() == nmtText) @@ -206,7 +207,7 @@ void ServerInterface::update() NetworkMessageText networkMessageText; if(connectionSlot->receiveMessage(&networkMessageText)) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] #2 about to broadcast nmtText msg for SlotIndex# %d\n",__FILE__,__FUNCTION__,i); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 about to broadcast nmtText msg for SlotIndex# %d\n",__FILE__,__FUNCTION__,i); broadcastMessage(&networkMessageText, i); chatText= networkMessageText.getText(); @@ -244,7 +245,7 @@ void ServerInterface::updateKeyframe(int frameCount){ void ServerInterface::waitUntilReady(Checksum* checksum){ - if(Socket::enableNetworkDebugInfo) printf("In [%s] START\n",__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] START\n",__FUNCTION__); Logger &logger= Logger::getInstance(); gameHasBeenInitiated = true; @@ -273,7 +274,7 @@ void ServerInterface::waitUntilReady(Checksum* checksum){ if(networkMessageType == nmtReady && connectionSlot->receiveMessage(&networkMessageReady)) { - if(Socket::enableNetworkDebugInfo) printf("In [%s] networkMessageType==nmtReady\n",__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] networkMessageType==nmtReady\n",__FUNCTION__); connectionSlot->setReady(); } @@ -330,7 +331,7 @@ void ServerInterface::waitUntilReady(Checksum* checksum){ // FOR TESTING ONLY - delay to see the client count up while waiting //sleep(5000); - if(Socket::enableNetworkDebugInfo) printf("In [%s] PART B (telling client we are ready!\n",__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] PART B (telling client we are ready!\n",__FUNCTION__); //send ready message after, so clients start delayed for(int i= 0; i < GameConstants::maxPlayers; ++i) @@ -344,7 +345,7 @@ void ServerInterface::waitUntilReady(Checksum* checksum){ } } - if(Socket::enableNetworkDebugInfo) printf("In [%s] END\n",__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] END\n",__FUNCTION__); } void ServerInterface::sendTextMessage(const string &text, int teamIndex){ @@ -420,7 +421,7 @@ bool ServerInterface::launchGame(const GameSettings* gameSettings){ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot){ - //if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); for(int i= 0; iisConnected()) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] before sendMessage\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] before sendMessage\n",__FILE__,__FUNCTION__); connectionSlot->sendMessage(networkMessage); } else if(gameHasBeenInitiated == true) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] #1 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,i); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #1 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,i); removeSlot(i); } } else if(i == excludeSlot && gameHasBeenInitiated == true && connectionSlot != NULL && connectionSlot->isConnected() == false) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] #2 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,i); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,i); removeSlot(i); } } - //if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } void ServerInterface::broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot){ - //if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); for(int i= 0; iisConnected()){ - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] before sendMessage\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] before sendMessage\n",__FILE__,__FUNCTION__); connectionSlot->sendMessage(networkMessage); } } } - //if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } void ServerInterface::updateListen() @@ -489,13 +490,13 @@ void ServerInterface::updateListen() void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START gameSettingsUpdateCount = %d\n",__FILE__,__FUNCTION__,gameSettingsUpdateCount); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START gameSettingsUpdateCount = %d\n",__FILE__,__FUNCTION__,gameSettingsUpdateCount); if(getAllowGameDataSynchCheck() == true) { if(waitForClientAck == true && gameSettingsUpdateCount > 0) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] Waiting for client acks #1\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Waiting for client acks #1\n",__FILE__,__FUNCTION__); time_t tStart = time(NULL); bool gotAckFromAllClients = false; @@ -534,7 +535,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai if(waitForClientAck == true) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] Waiting for client acks #2\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Waiting for client acks #2\n",__FILE__,__FUNCTION__); time_t tStart = time(NULL); bool gotAckFromAllClients = false; @@ -560,12 +561,12 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai gameSettingsUpdateCount++; } - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } void ServerInterface::close() { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); //serverSocket = ServerSocket(); } diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 7fb01758..214cb607 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -106,7 +106,7 @@ const int Unit::invalidId= -1; Unit::Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, float unitPlacementRotation) { - if(Socket::enableDebugText) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); allowRotateUnits = Config::getInstance().getBool("AllowRotateUnits","0"); rotateAmount= -1; @@ -120,9 +120,9 @@ Unit::Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map level= NULL; cellMap= NULL; - //if(Socket::enableDebugText) printf("In [%s::%s] A\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] A\n",__FILE__,__FUNCTION__); setRotateAmount(unitPlacementRotation); - //if(Socket::enableDebugText) printf("In [%s::%s] B unit id = %d [%s] rotate amount = %f\n",__FILE__,__FUNCTION__,getId(), getFullName().c_str(),unitPlacementRotation); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] B unit id = %d [%s] rotate amount = %f\n",__FILE__,__FUNCTION__,getId(), getFullName().c_str(),unitPlacementRotation); Config &config= Config::getInstance(); showUnitParticles= config.getBool("UnitParticles"); @@ -162,7 +162,7 @@ Unit::Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map //starting skill this->currSkill=getType()->getFirstStOfClass(scStop); - //if(Socket::enableDebugText) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } Unit::~Unit(){ @@ -455,47 +455,47 @@ unsigned int Unit::getCommandSize() const{ //give one command (clear, and push back) CommandResult Unit::giveCommand(Command *command){ - if(Socket::enableDebugText) printf("In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); if(command->getCommandType()->isQueuable()){ //cancel current command if it is not queuable - if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(!commands.empty() && !commands.front()->getCommandType()->isQueuable()){ - if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); cancelCommand(); } } else{ //empty command queue - if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); clearCommands(); unitPath.clear(); } - //if(Socket::enableDebugText) printf("In [%s::%s] A\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] A\n",__FILE__,__FUNCTION__); //check command - if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); CommandResult result= checkCommand(command); if(result==crSuccess){ - if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); applyCommand(command); } - //if(Socket::enableDebugText) printf("In [%s::%s] B\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] B\n",__FILE__,__FUNCTION__); //push back command if(result== crSuccess){ - if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); commands.push_back(command); } else{ - if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); delete command; } - if(Socket::enableDebugText) printf("In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); return result; } @@ -1134,8 +1134,7 @@ bool Unit::getCellMapCell(int x, int y) const { void Unit::setRotateAmount(float value) { if(allowRotateUnits == true) { rotateAmount = value; - //if(Socket::enableDebugText && rotateAmount > 0) printf("In [%s::%s Line: %d] unit id = %d [%s] rotate amount = %f\n",__FILE__,__FUNCTION__,__LINE__, getId(), getFullName().c_str(),rotateAmount); - if(Socket::enableDebugText ) printf("In [%s::%s Line: %d] unit id = %d rotate amount = %f cellMap = %s\n",__FILE__,__FUNCTION__,__LINE__, getId(), rotateAmount,(cellMap == NULL ? "NULL" : "Valid")); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit id = %d rotate amount = %f cellMap = %s\n",__FILE__,__FUNCTION__,__LINE__, getId(), rotateAmount,(cellMap == NULL ? "NULL" : "Valid")); const UnitType *ut= getType(); if(ut != NULL && ut->hasCellMap() == true) { @@ -1149,7 +1148,7 @@ void Unit::setRotateAmount(float value) { for(int iRow = 0; iRow < matrixSize; ++iRow) { for(int iCol = 0; iCol < matrixSize; ++iCol) { bool getCellResult = ut->getCellMapCell(iCol, iRow); - //if(Socket::enableDebugText) printf("In [%s::%s] [%d,%d] = %d\n",__FILE__,__FUNCTION__,iRow,iCol,getCellResult); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] [%d,%d] = %d\n",__FILE__,__FUNCTION__,iRow,iCol,getCellResult); int newRow = 0; int newCol = 0; @@ -1171,7 +1170,7 @@ void Unit::setRotateAmount(float value) { } - //if(Socket::enableDebugText) printf("In [%s::%s] ABOUT TO Transform to [%d,%d] = %d\n",__FILE__,__FUNCTION__,newRow,newCol,getCellResult); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] ABOUT TO Transform to [%d,%d] = %d\n",__FILE__,__FUNCTION__,newRow,newCol,getCellResult); // bool getCellMapCell(int x, int y) const {return cellMap[size*y+x];} // cellMap[i*size+j]= row[j]=='0'? false: true; @@ -1180,20 +1179,19 @@ void Unit::setRotateAmount(float value) { } } - //if(Socket::enableDebugText) printf("In [%s::%s] Transformed matrix below:\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Transformed matrix below:\n",__FILE__,__FUNCTION__); /* for(int iRow = 0; iRow < matrixSize; ++iRow) { for(int iCol = 0; iCol < matrixSize; ++iCol) { bool getCellResult = ut->getCellMapCell(iCol, iRow); bool getCellResultRotated = getCellMapCell(iRow, iCol); - if(Socket::enableDebugText) printf("In [%s::%s] matrix [%d,%d] = %d, rotated = %d\n",__FILE__,__FUNCTION__,iRow,iCol,getCellResult,getCellResultRotated); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] matrix [%d,%d] = %d, rotated = %d\n",__FILE__,__FUNCTION__,iRow,iCol,getCellResult,getCellResultRotated); } } */ } - //if(Socket::enableDebugText && rotateAmount > 0) printf("In [%s::%s Line: %d] unit id = %d [%s] rotate amount = %f\n",__FILE__,__FUNCTION__,__LINE__, getId(), getFullName().c_str(),rotateAmount); - if(Socket::enableDebugText ) printf("In [%s::%s Line: %d] unit id = %d rotate amount = %f\n",__FILE__,__FUNCTION__,__LINE__, getId(),rotateAmount); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit id = %d rotate amount = %f\n",__FILE__,__FUNCTION__,__LINE__, getId(),rotateAmount); } } diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 3259db82..04902bf3 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -173,15 +173,15 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa } /* - if(Socket::enableDebugText) printf("In [%s::%s] Original Unit cellmap matrix below [%s] [%s]:\n",__FILE__,__FUNCTION__,getName().c_str(),path.c_str()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Original Unit cellmap matrix below [%s] [%s]:\n",__FILE__,__FUNCTION__,getName().c_str(),path.c_str()); for(int iRow = 0; iRow < size; ++iRow) { const XmlNode *rowNode= cellMapNode->getChild("row", iRow); string row= rowNode->getAttribute("value")->getRestrictedValue(); - if(Socket::enableDebugText) printf("In [%s::%s] row = %s\n",__FILE__,__FUNCTION__,row.c_str()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] row = %s\n",__FILE__,__FUNCTION__,row.c_str()); for(int iCol = 0; iCol < size; ++iCol) { bool getCellResult = getCellMapCell(iCol, iRow); - if(Socket::enableDebugText) printf("In [%s::%s] matrix [%d,%d] = %d\n",__FILE__,__FUNCTION__,iRow,iCol,getCellResult); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] matrix [%d,%d] = %d\n",__FILE__,__FUNCTION__,iRow,iCol,getCellResult); } } */ @@ -522,7 +522,7 @@ void UnitType::computeFirstStOfClass(){ } void UnitType::computeFirstCtOfClass(){ - printf("In [%s::%s Line: %d] \n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] \n",__FILE__,__FUNCTION__,__LINE__); for(int j=0; jupdate()){ - //if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); updateUnitCommand(unit); @@ -124,10 +124,10 @@ void UnitUpdater::updateUnitCommand(Unit *unit){ //if no commands stop and add stop command if(!unit->anyCommand() && unit->isOperative()){ - //if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); unit->setCurrSkill(scStop); if(unit->getType()->hasCommandClass(ccStop)){ - if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccStop))); } } @@ -160,7 +160,7 @@ void UnitUpdater::updateStop(Unit *unit){ //use it to attack if(ast!=NULL){ if(attackableOnSight(unit, &sighted, ast)){ - if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); unit->giveCommand(new Command(ct, sighted->getPos())); break; } @@ -172,7 +172,7 @@ void UnitUpdater::updateStop(Unit *unit){ else if(unit->getType()->hasCommandClass(ccMove)){ if(attackerOnSight(unit, &sighted)){ Vec2i escapePos= unit->getPos()*2-sighted->getPos(); - if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccMove), escapePos)); } } @@ -295,13 +295,13 @@ void UnitUpdater::updateBuild(Unit *unit){ //!!! float unitRotation = -1; if(allowRotateUnits == true) { - if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); char unitKey[50]=""; sprintf(unitKey,"%d_%d",builtUnitType->getId(),unit->getFaction()->getIndex()); unitRotation = gui->getUnitTypeBuildRotation(unitKey); - if(Socket::enableDebugText) printf("In [%s::%s Line: %d] builtUnitType->getId() = %d unitRotation = %f\n",__FILE__,__FUNCTION__,__LINE__,builtUnitType->getId(),unitRotation); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] builtUnitType->getId() = %d unitRotation = %f\n",__FILE__,__FUNCTION__,__LINE__,builtUnitType->getId(),unitRotation); } Unit *builtUnit= new Unit(world->getNextUnitId(), command->getPos(), builtUnitType, unit->getFaction(), world->getMap(),unitRotation); builtUnit->create(); @@ -575,7 +575,7 @@ void UnitUpdater::updateProduce(Unit *unit){ world->getStats()->produce(unit->getFactionIndex()); const CommandType *ct= produced->computeCommandType(unit->getMeetingPos()); if(ct!=NULL){ - if(Socket::enableDebugText) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); produced->giveCommand(new Command(ct, unit->getMeetingPos())); } scriptManager->onUnitCreated(produced); diff --git a/source/shared_lib/include/platform/posix/socket.h b/source/shared_lib/include/platform/posix/socket.h index 7812a481..90cb8e49 100644 --- a/source/shared_lib/include/platform/posix/socket.h +++ b/source/shared_lib/include/platform/posix/socket.h @@ -59,9 +59,6 @@ public: Socket(); ~Socket(); - static bool enableDebugText; - static bool enableNetworkDebugInfo; - // Int lookup is socket fd while bool result is whether or not that socket was signalled for reading static bool hasDataToRead(std::map &socketTriggeredList); static bool hasDataToRead(int socket); diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h new file mode 100644 index 00000000..341c7c16 --- /dev/null +++ b/source/shared_lib/include/util/util.h @@ -0,0 +1,73 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2008 Martiņo Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef _SHARED_UTIL_UTIL_H_ +#define _SHARED_UTIL_UTIL_H_ + +#include + +using std::string; + +namespace Shared{ namespace Util{ + +class SystemFlags +{ +public: + + enum DebugType { + debugSystem, + debugNetwork + }; + + static bool enableDebugText; + static bool enableNetworkDebugInfo; + + static void OutputDebug(DebugType type, const char *fmt, ...); +}; + +const string sharedLibVersionString= "v0.4.1"; + +//string fcs +string lastDir(const string &s); +string lastFile(const string &s); +string cutLastFile(const string &s); +string cutLastExt(const string &s); +string ext(const string &s); +string replaceBy(const string &s, char c1, char c2); +string toLower(const string &s); +void copyStringToBuffer(char *buffer, int bufferSize, const string& s); + +//numeric fcs +int clamp(int value, int min, int max); +float clamp(float value, float min, float max); +float saturate(float value); +int round(float f); + +//misc +bool fileExists(const string &path); + +template +void deleteValues(T beginIt, T endIt){ + for(T it= beginIt; it!=endIt; ++it){ + delete *it; + } +} + +template +void deleteMapValues(T beginIt, T endIt){ + for(T it= beginIt; it!=endIt; ++it){ + delete it->second; + } +} + +}}//end namespace + +#endif diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 1055c6cc..191ad137 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -22,15 +22,13 @@ #endif #include "conversion.h" +#include "util.h" using namespace std; using namespace Shared::Util; namespace Shared{ namespace Platform{ -bool Socket::enableDebugText = true; -bool Socket::enableNetworkDebugInfo = true; - // ===================================================== // class Ip // ===================================================== @@ -85,26 +83,26 @@ Socket::Socket() Socket::~Socket() { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock); disconnectSocket(); - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock); } void Socket::disconnectSocket() { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock); if(sock > 0) { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] calling shutdown and close for socket = %d...\n",__FILE__,__FUNCTION__,sock); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] calling shutdown and close for socket = %d...\n",__FILE__,__FUNCTION__,sock); ::shutdown(sock,2); ::close(sock); sock = -1; } - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock); } // Int lookup is socket fd while bool result is whether or not that socket was signalled for reading @@ -149,7 +147,7 @@ bool Socket::hasDataToRead(std::map &socketTriggeredList) { bResult = true; - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] select detected data imaxsocket = %d...\n",__FILE__,__FUNCTION__,imaxsocket); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] select detected data imaxsocket = %d...\n",__FILE__,__FUNCTION__,imaxsocket); for(std::map::iterator itermap = socketTriggeredList.begin(); itermap != socketTriggeredList.end(); itermap++) @@ -157,7 +155,7 @@ bool Socket::hasDataToRead(std::map &socketTriggeredList) int socket = itermap->first; if (FD_ISSET(socket, &rfds)) { - if(Socket::enableNetworkDebugInfo) printf("In [%s] FD_ISSET true for socket %d...\n",__FUNCTION__,socket); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] FD_ISSET true for socket %d...\n",__FUNCTION__,socket); itermap->second = true; } @@ -167,7 +165,7 @@ bool Socket::hasDataToRead(std::map &socketTriggeredList) } } - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] socketTriggeredList->size() = %d\n",__FILE__,__FUNCTION__,socketTriggeredList.size()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socketTriggeredList->size() = %d\n",__FILE__,__FUNCTION__,socketTriggeredList.size()); } } } @@ -288,7 +286,7 @@ int Socket::send(const void *data, int dataSize) { //throwException(szBuf); } - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] sock = %d, bytesSent = %d\n",__FILE__,__FUNCTION__,sock,bytesSent); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] sock = %d, bytesSent = %d\n",__FILE__,__FUNCTION__,sock,bytesSent); return static_cast(bytesSent); } @@ -687,7 +685,7 @@ Socket *ServerSocket::accept() if(newSock < 0) { char szBuf[1024]=""; - if(Socket::enableNetworkDebugInfo) printf(szBuf, "In [%s::%s] Error accepting socket connection sock = %d, err = %d, errno = %d\n",__FILE__,__FUNCTION__,sock,newSock,errno); + sprintf(szBuf, "In [%s::%s] Error accepting socket connection sock = %d, err = %d, errno = %d\n",__FILE__,__FUNCTION__,sock,newSock,errno); if(errno == EAGAIN) { diff --git a/source/shared_lib/sources/platform/sdl/platform_util.cpp b/source/shared_lib/sources/platform/sdl/platform_util.cpp index 7687d6ad..c540edc1 100644 --- a/source/shared_lib/sources/platform/sdl/platform_util.cpp +++ b/source/shared_lib/sources/platform/sdl/platform_util.cpp @@ -144,11 +144,7 @@ void findDirs(const vector &paths, vector &results, bool errorOn const string current_folder = current_results[folder_index]; const string current_folder_path = paths[idx] + "/" + current_folder; - //printf("current_folder = [%s]\n",current_folder_path.c_str()); - if(isdir(current_folder_path.c_str()) == true) { - //printf("%s is a folder.\n",current_folder_path.c_str()); - if(std::find(results.begin(),results.end(),current_folder) == results.end()) { results.push_back(current_folder); } @@ -193,7 +189,7 @@ void findAll(const string &path, vector &results, bool cutExtension, boo mypath += "*"; } - if(Socket::enableDebugText) printf("In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,mypath.c_str()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,mypath.c_str()); glob_t globbuf; @@ -251,7 +247,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string Checksum checksum = (recursiveChecksum == NULL ? Checksum() : *recursiveChecksum); - //if(Socket::enableDebugText) printf("In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); std::string mypath = path; /** Stupid win32 is searching for all files without extension when *. is @@ -292,7 +288,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string if(addFile) { - //if(Socket::enableDebugText) printf("In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); checksum.addFile(p); } @@ -333,7 +329,7 @@ vector > getFolderTreeContentsCheckSumListRecursively(co vector > checksumFiles = (recursiveMap == NULL ? vector >() : *recursiveMap); - //if(Socket::enableDebugText) printf("In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); std::string mypath = path; /** Stupid win32 is searching for all files without extension when *. is @@ -374,7 +370,7 @@ vector > getFolderTreeContentsCheckSumListRecursively(co if(addFile) { - //if(Socket::enableDebugText) printf("In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); Checksum checksum; checksum.addFile(p); diff --git a/source/shared_lib/sources/platform/win32/platform_util.cpp b/source/shared_lib/sources/platform/win32/platform_util.cpp index 85a9125b..9a9d4a28 100644 --- a/source/shared_lib/sources/platform/win32/platform_util.cpp +++ b/source/shared_lib/sources/platform/win32/platform_util.cpp @@ -172,12 +172,7 @@ void findDirs(const vector &paths, vector &results, bool errorOn for(int folder_index = 0; folder_index < current_results.size(); folder_index++) { const string current_folder = current_results[folder_index]; const string current_folder_path = paths[idx] + "/" + current_folder; - - //printf("current_folder = [%s]\n",current_folder_path.c_str()); - if(isdir(current_folder_path.c_str()) == true) { - //printf("%s is a folder.\n",current_folder_path.c_str()); - if(std::find(results.begin(),results.end(),current_folder) == results.end()) { results.push_back(current_folder); } @@ -273,7 +268,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string /* MV - PORT THIS to win32 - //if(Socket::enableDebugText) printf("In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); std::string mypath = path; // Stupid win32 is searching for all files without extension when *. is specified as wildcard @@ -312,7 +307,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string if(addFile) { - //if(Socket::enableDebugText) printf("In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); checksum.addFile(p); } @@ -354,7 +349,7 @@ vector > getFolderTreeContentsCheckSumListRecursively(co /* MV - PORT THIS to win32 - //if(Socket::enableDebugText) printf("In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); std::string mypath = path; // Stupid win32 is searching for all files without extension when *. is specified as wildcard @@ -393,7 +388,7 @@ vector > getFolderTreeContentsCheckSumListRecursively(co if(addFile) { - //if(Socket::enableDebugText) printf("In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); Checksum checksum; checksum.addFile(p); diff --git a/source/shared_lib/sources/platform/win32/socket.cpp b/source/shared_lib/sources/platform/win32/socket.cpp index 9911f2cd..187416e8 100644 --- a/source/shared_lib/sources/platform/win32/socket.cpp +++ b/source/shared_lib/sources/platform/win32/socket.cpp @@ -202,12 +202,12 @@ Socket::SocketManager::SocketManager(){ WORD wVersionRequested = MAKEWORD(2, 0); WSAStartup(wVersionRequested, &wsaData); //dont throw exceptions here, this is a static initializacion - printf("Winsock initialized.\n"); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Winsock initialized.\n"); } Socket::SocketManager::~SocketManager(){ WSACleanup(); - printf("Winsock cleanup complete.\n"); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Winsock cleanup complete.\n"); } Socket::Socket(SOCKET sock){ @@ -223,16 +223,16 @@ Socket::Socket(){ Socket::~Socket() { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock); disconnectSocket(); - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock); } void Socket::disconnectSocket() { - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock); if(sock > 0) { @@ -241,7 +241,7 @@ void Socket::disconnectSocket() sock = -1; } - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock); } // Int lookup is socket fd while bool result is whether or not that socket was signalled for reading @@ -285,7 +285,7 @@ bool Socket::hasDataToRead(std::map &socketTriggeredList) { bResult = true; - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] select detected data imaxsocket = %d...\n",__FILE__,__FUNCTION__,imaxsocket); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] select detected data imaxsocket = %d...\n",__FILE__,__FUNCTION__,imaxsocket); for(std::map::iterator itermap = socketTriggeredList.begin(); itermap != socketTriggeredList.end(); itermap++) @@ -293,7 +293,7 @@ bool Socket::hasDataToRead(std::map &socketTriggeredList) int socket = itermap->first; if (FD_ISSET(socket, &rfds)) { - if(Socket::enableNetworkDebugInfo) printf("In [%s] FD_ISSET true for socket %d...\n",__FUNCTION__,socket); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] FD_ISSET true for socket %d...\n",__FUNCTION__,socket); itermap->second = true; } @@ -303,7 +303,7 @@ bool Socket::hasDataToRead(std::map &socketTriggeredList) } } - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] socketTriggeredList->size() = %d\n",__FILE__,__FUNCTION__,socketTriggeredList.size()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socketTriggeredList->size() = %d\n",__FILE__,__FUNCTION__,socketTriggeredList.size()); } } } @@ -378,7 +378,7 @@ int Socket::getDataToRead(){ } else if(err == 0) { - //if(Socket::enableNetworkDebugInfo) printf("In [%s] ioctl returned = %d, size = %ld\n",__FUNCTION__,err,size); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] ioctl returned = %d, size = %ld\n",__FUNCTION__,err,size); } } @@ -400,7 +400,7 @@ int Socket::send(const void *data, int dataSize) { } else if(bytesSent < 0 && WSAGetLastError() == WSAEWOULDBLOCK) { - printf("In [%s::%s] #1 WSAEWOULDBLOCK during send, trying again...\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #1 WSAEWOULDBLOCK during send, trying again...\n",__FILE__,__FUNCTION__); time_t tStartTimer = time(NULL); while((bytesSent < 0 && WSAGetLastError() == WSAEWOULDBLOCK) && (difftime(time(NULL),tStartTimer) <= 5)) @@ -409,7 +409,7 @@ int Socket::send(const void *data, int dataSize) { { bytesSent = ::send(sock, reinterpret_cast(data), dataSize, 0); - printf("In [%s::%s] #2 WSAEWOULDBLOCK during send, trying again returned: %d\n",__FILE__,__FUNCTION__,bytesSent); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 WSAEWOULDBLOCK during send, trying again returned: %d\n",__FILE__,__FUNCTION__,bytesSent); } } } @@ -424,7 +424,7 @@ int Socket::send(const void *data, int dataSize) { //throwException(szBuf); } - if(Socket::enableNetworkDebugInfo) printf("In [%s::%s] sock = %d, bytesSent = %d\n",__FILE__,__FUNCTION__,sock,bytesSent); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] sock = %d, bytesSent = %d\n",__FILE__,__FUNCTION__,sock,bytesSent); return static_cast(bytesSent); } @@ -674,7 +674,7 @@ void ClientSocket::connect(const Ip &ip, int port) addr.sin_addr.s_addr= inet_addr(ip.getString().c_str()); addr.sin_port= htons(port); - fprintf(stderr, "Connecting to host [%s] on port = %d\n", ip.getString().c_str(),port); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Connecting to host [%s] on port = %d\n", ip.getString().c_str(),port); int err= ::connect(sock, reinterpret_cast(&addr), sizeof(addr)); if(err < 0) diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp new file mode 100644 index 00000000..e1b732b9 --- /dev/null +++ b/source/shared_lib/sources/util/util.cpp @@ -0,0 +1,189 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2008 Martiņo Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "util.h" + +#include +#include +#include +#include +#include +#include + +#include "leak_dumper.h" + +using namespace std; + +namespace Shared{ namespace Util{ + + +bool SystemFlags::enableDebugText = false; +bool SystemFlags::enableNetworkDebugInfo = false; + +void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { + if((type == debugSystem && SystemFlags::enableDebugText == false) || + (type == debugNetwork && SystemFlags::enableNetworkDebugInfo == false)) { + return; + } + + va_list argList; + va_start(argList, fmt); + + vprintf(fmt, argList); + + va_end(argList); +} + +string lastDir(const string &s){ + size_t i= s.find_last_of('/'); + size_t j= s.find_last_of('\\'); + size_t pos; + + if(i==string::npos){ + pos= j; + } + else if(j==string::npos){ + pos= i; + } + else{ + pos= i1.f){ + return 1.f; + } + return value; +} + +int clamp(int value, int min, int max){ + if (valuemax){ + return max; + } + return value; +} + +float clamp(float value, float min, float max){ + if (valuemax){ + return max; + } + return value; +} + +int round(float f){ + return (int) f; +} + +// ==================== misc ==================== + +bool fileExists(const string &path){ + FILE* file= fopen(path.c_str(), "rb"); + if(file!=NULL){ + fclose(file); + return true; + } + return false; +} + +}}//end namespace