From 06660e3a171e01b1b3629faefe1e1b9b0c412265 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Wed, 21 Apr 2010 23:13:39 +0000 Subject: [PATCH] clients can see which setups are made on the server. ( work in progress !) menu gfx-components can be set editable/non editable now + in addition fixed several memory problems and FOW in scenarios ...) --- source/glest_game/facilities/components.cpp | 7 + source/glest_game/facilities/components.h | 186 ++++++ source/glest_game/game/game_settings.h | 6 +- source/glest_game/graphics/renderer.cpp | 20 +- source/glest_game/menu/main_menu.cpp | 5 +- .../menu/menu_state_connected_game.cpp | 630 ++++++++++++++++++ .../menu/menu_state_connected_game.h | 80 +++ .../menu/menu_state_custom_game.cpp | 13 +- .../glest_game/menu/menu_state_join_game.cpp | 9 +- .../glest_game/menu/menu_state_new_game.cpp | 2 +- .../glest_game/network/client_interface.cpp | 30 + source/glest_game/network/client_interface.h | 2 + source/glest_game/network/network_message.cpp | 5 +- source/glest_game/network/network_message.h | 6 +- .../glest_game/network/server_interface.cpp | 12 +- source/glest_game/network/server_interface.h | 3 +- 16 files changed, 996 insertions(+), 20 deletions(-) create mode 100644 source/glest_game/facilities/components.h create mode 100644 source/glest_game/menu/menu_state_connected_game.cpp create mode 100644 source/glest_game/menu/menu_state_connected_game.h diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index 9129a968..fcb6bca4 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -35,6 +35,7 @@ const float GraphicComponent::fadeSpeed= 0.01f; GraphicComponent::GraphicComponent(){ enabled= true; + editable= true; } void GraphicComponent::init(int x, int y, int w, int h){ @@ -133,6 +134,12 @@ void GraphicListBox::setSelectedItemIndex(int index){ setText(getSelectedItem()); } +void GraphicListBox::setEditable(bool editable){ + graphButton1.setEditable(editable); + graphButton2.setEditable(editable); + editable=true; +} + void GraphicListBox::setSelectedItem(string item){ vector::iterator iter; diff --git a/source/glest_game/facilities/components.h b/source/glest_game/facilities/components.h new file mode 100644 index 00000000..8fac6a1e --- /dev/null +++ b/source/glest_game/facilities/components.h @@ -0,0 +1,186 @@ +// ============================================================== +// 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 +// ============================================================== + +#ifndef _GLEST_GAME_GRAPHCOMPONENT_H_ +#define _GLEST_GAME_GRAPHCOMPONENT_H_ + +#include +#include + +#include "font.h" + +using std::string; +using std::vector; + +using Shared::Graphics::Font2D; + +namespace Glest{ namespace Game{ + +// =========================================================== +// class GraphicComponent +// +// OpenGL renderer GUI components +// =========================================================== + +class GraphicComponent{ +public: + static const float animSpeed; + static const float fadeSpeed; + +protected: + int x, y, w, h; + string text; + const Font2D *font; + bool enabled; + bool editable; + + static float anim; + static float fade; + +public: + GraphicComponent(); + virtual ~GraphicComponent(){} + + void init(int x, int y, int w, int h); + + int getX() const {return x;} + int getY() const {return y;} + int getW() const {return w;} + int getH() const {return h;} + const string &getText() const {return text;} + const Font2D *getFont() const {return font;} + bool getEnabled() const {return enabled;} + bool getEditable() const {return editable;} + + void setX(int x) {this->x= x;} + void setY(int y) {this->y= y;} + void setText(const string &text) {this->text= text;} + void setFont(const Font2D *font) {this->font= font;} + void setEnabled(bool enabled) {this->enabled= enabled;} + void setEditable(bool editable) {this->editable= editable;} + + virtual bool mouseMove(int x, int y); + virtual bool mouseClick(int x, int y); + + static void update(); + static void resetFade(); + static float getAnim() {return anim;} + static float getFade() {return fade;} +}; + +// =========================================================== +// class GraphicLabel +// =========================================================== + +class GraphicLabel: public GraphicComponent{ +public: + static const int defH; + static const int defW; + +private: + bool centered; + +public: + void init(int x, int y, int w=defW, int h=defH, bool centered= false); + + bool getCentered() const {return centered;} + + void setCentered(bool centered) {this->centered= centered;} +}; + +// =========================================================== +// class GraphicButton +// =========================================================== + +class GraphicButton: public GraphicComponent{ +public: + static const int defH; + static const int defW; + +private: + bool lighted; + +public: + void init(int x, int y, int w=defW, int h=defH); + + bool getLighted() const {return lighted;} + + void setLighted(bool lighted) {this->lighted= lighted;} + virtual bool mouseMove(int x, int y); +}; + +// =========================================================== +// class GraphicListBox +// =========================================================== + +class GraphicListBox: public GraphicComponent{ +public: + static const int defH; + static const int defW; + +private: + GraphicButton graphButton1, graphButton2; + vector items; + int selectedItemIndex; + +public: + void init(int x, int y, int w=defW, int h=defH); + + int getItemCount() const {return items.size();} + int getSelectedItemIndex() const {return selectedItemIndex;} + string getSelectedItem() const {return items[selectedItemIndex];} + const GraphicButton *getButton1() const {return &graphButton1;} + const GraphicButton *getButton2() const {return &graphButton2;} + + void pushBackItem(string item); + void setItems(const vector &items); + void setSelectedItemIndex(int index); + void setSelectedItem(string item); + void setEditable(bool editable); + + virtual bool mouseMove(int x, int y); + virtual bool mouseClick(int x, int y); +}; + +// =========================================================== +// class GraphicMessageBox +// =========================================================== + +class GraphicMessageBox: public GraphicComponent{ +public: + static const int defH; + static const int defW; + +private: + GraphicButton button1; + GraphicButton button2; + int buttonCount; + string header; + +public: + void init(const string &button1Str, const string &button2Str); + void init(const string &button1Str); + + int getButtonCount() const {return buttonCount;} + const GraphicButton *getButton1() const {return &button1;} + const GraphicButton *getButton2() const {return &button2;} + string getHeader() const {return header;} + + void setHeader(string header) {this->header= header;} + + virtual bool mouseMove(int x, int y); + virtual bool mouseClick(int x, int y); + bool mouseClick(int x, int y, int &clickedButton); +}; + +}}//end namespace + +#endif diff --git a/source/glest_game/game/game_settings.h b/source/glest_game/game/game_settings.h index 84f2c03f..3efd3eac 100644 --- a/source/glest_game/game/game_settings.h +++ b/source/glest_game/game/game_settings.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// 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 @@ -46,7 +46,9 @@ private: public: - GameSettings() { } + GameSettings() { + fogOfWar = true; + } // default copy constructor will do fine, and will maintain itself ;) diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index dd60b434..e165b179 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -960,6 +960,8 @@ void Renderer::renderButton(const GraphicButton *button){ int h= button->getH(); int w= button->getW(); + const Vec3f disabledTextColor= Vec3f(0.25f,0.25f,0.25f); + glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT); //background @@ -996,7 +998,7 @@ void Renderer::renderButton(const GraphicButton *button){ float anim= GraphicComponent::getAnim(); if(anim>0.5f) anim= 1.f-anim; - if(button->getLighted()){ + if(button->getLighted() && button->getEditable()){ const int lightSize= 0; const Vec4f color1= Vec4f(1.f, 1.f, 1.f, 0.1f+anim*0.5f); const Vec4f color2= Vec4f(1.f, 1.f, 1.f, 0.3f+anim); @@ -1029,9 +1031,19 @@ void Renderer::renderButton(const GraphicButton *button){ Vec2i textPos= Vec2i(x+w/2, y+h/2); - renderText( - button->getText(), button->getFont(), GraphicButton::getFade(), - x+w/2, y+h/2, true); + if(button->getEditable()){ + renderText( + button->getText(), button->getFont(), GraphicButton::getFade(), + x+w/2, y+h/2, true); + } + else { + renderText( + button->getText(), button->getFont(),disabledTextColor, + x+w/2, y+h/2, true); +// renderText( +// button->getText(), button->getFont(), 0.2f, +// x+w/2, y+h/2, true); + } glPopAttrib(); } diff --git a/source/glest_game/menu/main_menu.cpp b/source/glest_game/menu/main_menu.cpp index 0dc9e868..2b73406c 100644 --- a/source/glest_game/menu/main_menu.cpp +++ b/source/glest_game/menu/main_menu.cpp @@ -42,6 +42,7 @@ namespace Glest{ namespace Game{ // ===================================================== // ===================== PUBLIC ======================== +MenuState *oldstate=NULL; MainMenu::MainMenu(Program *program): ProgramState(program) @@ -154,10 +155,10 @@ void MainMenu::keyPress(char c){ } void MainMenu::setState(MenuState *state){ - delete this->state; + if(oldstate!=NULL) delete oldstate; + MenuState *oldstate=this->state; this->state= state; GraphicComponent::resetFade(); - menuBackground.setTargetCamera(state->getCamera()); } diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp new file mode 100644 index 00000000..fcdc6267 --- /dev/null +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -0,0 +1,630 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2005 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 "menu_state_connected_game.h" + +#include "menu_state_join_game.h" +#include "renderer.h" +#include "sound_renderer.h" +#include "core_data.h" +#include "config.h" +#include "menu_state_new_game.h" +#include "metrics.h" +#include "network_manager.h" +#include "network_message.h" +#include "client_interface.h" +#include "conversion.h" +#include "socket.h" +#include "game.h" +#include +#include + +#include "leak_dumper.h" + + +namespace Glest{ namespace Game{ + +using namespace Shared::Util; + +struct FormatString { + void operator()(string &s) { + s = formatString(s); + } +}; + +string currentFactionName=""; +string currentMap=""; +// ===================================================== +// class MenuStateConnectedGame +// ===================================================== + +MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots): + MenuState(program, mainMenu, "join-game") +{ + Lang &lang= Lang::getInstance(); + NetworkManager &networkManager= NetworkManager::getInstance(); + Config &config = Config::getInstance(); + needToSetChangedGameSettings = false; + lastSetChangedGameSettings = time(NULL);; + + vector teamItems, controlItems, results; + //state + labelStatus.init(330, 700); + labelStatus.setText(""); + + labelInfo.init(30, 700); + labelInfo.setText(""); + + + + //create + buttonDisconnect.init(350, 180, 125); + buttonPlayNow.init(525, 180, 125); + + //map listBox + // put them all in a set, to weed out duplicates (gbm & mgm with same name) + // will also ensure they are alphabetically listed (rather than how the OS provides them) + listBoxMap.init(100, 260, 200); + listBoxMap.setEditable(false); + + //listBoxMap.setItems(results); + labelMap.init(100, 290); + labelMapInfo.init(100, 230, 200, 40); + + + // fog - o - war + // @350 ? 300 ? + labelFogOfWar.init(350, 290, 100); + listBoxFogOfWar.init(350, 260, 100); + listBoxFogOfWar.pushBackItem(lang.get("Yes")); + listBoxFogOfWar.pushBackItem(lang.get("No")); + listBoxFogOfWar.setSelectedItemIndex(0); + listBoxFogOfWar.setEditable(false); + + //tileset listBox + listBoxTileset.init(500, 260, 150); + listBoxTileset.setEditable(false); + //listBoxTileset.setItems(results); + labelTileset.init(500, 290); + + //tech Tree listBox + listBoxTechTree.init(700, 260, 150); + listBoxTechTree.setEditable(false); + //listBoxTechTree.setItems(results); + labelTechTree.init(700, 290); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + //list boxes + for(int i=0; igetSocket() != NULL) + { + if(clientInterface->isConnected() == true) + { + string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!"; + clientInterface->sendTextMessage(sQuitText,-1); + } + clientInterface->close(); + } + clientInterface->reset(); + networkManager.end(); + currentFactionName=""; + currentMap=""; + mainMenu->setState(new MenuStateJoinGame(program, mainMenu)); + } + else if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + soundRenderer.playFx(coreData.getClickSoundC()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + } + else if(listBoxMap.mouseClick(x, y)){ + + } + else if (listBoxFogOfWar.mouseClick(x, y)) { + } + else if(listBoxTileset.mouseClick(x, y)){ + } + else if(listBoxTechTree.mouseClick(x, y)){ + //reloadFactions(); + + if(hasNetworkGameSettings() == true) + { + needToSetChangedGameSettings = true; + lastSetChangedGameSettings = time(NULL);; + } + } + else + { +// for(int i=0; i(listBoxControls[j].getSelectedItemIndex()); +// if(ct==ctHuman){ +// if(humanIndex1==-1){ +// humanIndex1= j; +// } +// else{ +// humanIndex2= j; +// } +// } +// } +// +// //no human +// if(humanIndex1==-1 && humanIndex2==-1){ +// listBoxControls[i].setSelectedItemIndex(ctHuman); +// } +// +// //2 humans +// if(humanIndex1!=-1 && humanIndex2!=-1){ +// listBoxControls[humanIndex1==i? humanIndex2: humanIndex1].setSelectedItemIndex(ctClosed); +// } +// +// if(hasNetworkGameSettings() == true) +// { +// needToSetChangedGameSettings = true; +// lastSetChangedGameSettings = time(NULL);; +// } +// } +// else if(listBoxFactions[i].mouseClick(x, y)){ +// +// if(hasNetworkGameSettings() == true) +// { +// needToSetChangedGameSettings = true; +// lastSetChangedGameSettings = time(NULL);; +// } +// } +// else if(listBoxTeams[i].mouseClick(x, y)) +// { +// if(hasNetworkGameSettings() == true) +// { +// needToSetChangedGameSettings = true; +// lastSetChangedGameSettings = time(NULL);; +// } +// } +// } + } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); +} + +void MenuStateConnectedGame::mouseMove(int x, int y, const MouseState *ms){ + + buttonDisconnect.mouseMove(x, y); + buttonPlayNow.mouseMove(x, y); + + for(int i=0; iisConnected()) + { + buttonDisconnect.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 + { + if(clientInterface->getSocket() != NULL) + { + clientInterface->close(); + } + mainMenu->setState(new MenuStateJoinGame(program, mainMenu)); + } + + //process network messages + if(clientInterface->isConnected()) + { + if(clientInterface->getGameSettingsReceived()){ + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + vector maps,tilesets,techtree; + const GameSettings *gameSettings=clientInterface->getGameSettings(); + + + // tileset + tilesets.push_back(formatString(gameSettings->getTileset())); + listBoxTileset.setItems(tilesets); + + // techtree + techtree.push_back(formatString(gameSettings->getTech())); + listBoxTechTree.setItems(techtree); + + // factions + if(currentFactionName!=gameSettings->getTech()) + { + currentFactionName=gameSettings->getTech(); + loadFactions(gameSettings); + } + + // map + maps.push_back(formatString(gameSettings->getMap())); + listBoxMap.setItems(maps); + if(currentMap!=gameSettings->getMap()) + {// load the setup again + currentMap=gameSettings->getMap(); + } + + + // FogOfWar + if(gameSettings->getFogOfWar()){ + listBoxFogOfWar.setSelectedItemIndex(0); + } + else + { + listBoxFogOfWar.setSelectedItemIndex(1); + } + + // Control + for(int i=0; igetFactionCount(); ++i){ + int slot=gameSettings->getStartLocationIndex(i); + listBoxControls[slot].setSelectedItemIndex(gameSettings->getFactionControl(i)); + listBoxTeams[slot].setSelectedItemIndex(gameSettings->getTeam(i)); + listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i))); + } + } + //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(serversSavedFile); + + 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__); + } + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + } + + if(clientInterface->getLaunchGame()) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - D\n",__FILE__,__FUNCTION__); + +} + + +void MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + vector results; + + Config &config = Config::getInstance(); + + vector techPaths = config.getPathListForType(ptTechs); + for(int idx = 0; idx < techPaths.size(); idx++) { + string &techPath = techPaths[idx]; + + findAll(techPath + "/" + gameSettings->getTech() + "/factions/*.", results, false, false); + if(results.size() > 0) { + break; + } + } + + if(results.size() == 0) { + throw runtime_error("(2)There are no factions for the tech tree [" + gameSettings->getTech() + "]"); + } + factionFiles= results; + for(int i= 0; igetTech().c_str(),results[i].c_str()); + } + for(int i=0; i(listBoxControls[i].getSelectedItemIndex()); + if(ct != ctClosed) + { + if(ct == ctNetwork) + { + hasNetworkSlot = true; + break; + } + } + } + } + catch(const std::exception &ex) { + char szBuf[1024]=""; + sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + throw runtime_error(szBuf); + } + + return hasNetworkSlot; +} + + + +void MenuStateConnectedGame::reloadFactions(){ + + vector results; + + Config &config = Config::getInstance(); + + vector techPaths = config.getPathListForType(ptTechs); + for(int idx = 0; idx < techPaths.size(); idx++) { + string &techPath = techPaths[idx]; + + findAll(techPath + "/" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "/factions/*.", results, false, false); + if(results.size() > 0) { + break; + } + } + + if(results.size() == 0) { + throw runtime_error("(2)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]"); + } + factionFiles= results; + for(int i= 0; i mapFiles; + vector techTreeFiles; + vector tilesetFiles; + vector factionFiles; + GraphicLabel labelPlayers[GameConstants::maxPlayers]; + GraphicListBox listBoxControls[GameConstants::maxPlayers]; + GraphicListBox listBoxFactions[GameConstants::maxPlayers]; + GraphicListBox listBoxTeams[GameConstants::maxPlayers]; + GraphicLabel labelNetStatus[GameConstants::maxPlayers]; + MapInfo mapInfo; + + bool needToSetChangedGameSettings; + time_t lastSetChangedGameSettings; + + Console console; + ChatManager chatManager; + +public: + MenuStateConnectedGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots= false); + + void mouseClick(int x, int y, MouseButton mouseButton); + void mouseMove(int x, int y, const MouseState *mouseState); + void render(); + void update(); + + virtual void keyDown(char key); + virtual void keyPress(char c); + +private: + + bool hasNetworkGameSettings(); + void reloadFactions(); + void loadFactions(const GameSettings *gameSettings); +}; + +}}//end namespace + +#endif diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index f9af4946..2304c69f 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -520,7 +520,14 @@ void MenuStateCustomGame::update() serverInterface->setGameSettings(&gameSettings); needToSetChangedGameSettings = false; - lastSetChangedGameSettings = time(NULL); + } + + if(difftime(time(NULL),lastSetChangedGameSettings) >= 2) + { + GameSettings gameSettings; + loadGameSettings(&gameSettings); + serverInterface->setGameSettings(&gameSettings); + serverInterface->broadcastGameSetup(&gameSettings); } //call the chat manager @@ -529,6 +536,10 @@ void MenuStateCustomGame::update() //console console.update(); + if(difftime(time(NULL),lastSetChangedGameSettings) >= 2) + {// reset timer here on bottom becasue used for different things + lastSetChangedGameSettings = time(NULL); + } //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } catch(const std::exception &ex) { diff --git a/source/glest_game/menu/menu_state_join_game.cpp b/source/glest_game/menu/menu_state_join_game.cpp index 6c7eb877..98b5ab11 100644 --- a/source/glest_game/menu/menu_state_join_game.cpp +++ b/source/glest_game/menu/menu_state_join_game.cpp @@ -11,6 +11,7 @@ #include "menu_state_join_game.h" +#include "menu_state_connected_game.h" #include "renderer.h" #include "sound_renderer.h" #include "core_data.h" @@ -37,12 +38,14 @@ using namespace Shared::Util; const int MenuStateJoinGame::newServerIndex= 0; const string MenuStateJoinGame::serverFileName= "servers.ini"; + MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool connect, Ip serverIp): MenuState(program, mainMenu, "join-game") { Lang &lang= Lang::getInstance(); Config &config= Config::getInstance(); NetworkManager &networkManager= NetworkManager::getInstance(); + networkManager.end(); serversSavedFile = serverFileName; if(getGameReadWritePath() != "") { @@ -189,7 +192,6 @@ void MenuStateJoinGame::mouseClick(int x, int y, MouseButton mouseButton) } clientInterface->close(); } - mainMenu->setState(new MenuStateRoot(program, mainMenu)); } @@ -315,7 +317,6 @@ void MenuStateJoinGame::update() { label += " - data synch is ok"; } - labelStatus.setText(label); } else @@ -487,7 +488,9 @@ void MenuStateJoinGame::connectToServer() //save server ip config.setString("ServerIp", serverIp.getString()); config.save(); - + + mainMenu->setState(new MenuStateConnectedGame(program, mainMenu)); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } diff --git a/source/glest_game/menu/menu_state_new_game.cpp b/source/glest_game/menu/menu_state_new_game.cpp index 4cf0e834..d894f7bc 100644 --- a/source/glest_game/menu/menu_state_new_game.cpp +++ b/source/glest_game/menu/menu_state_new_game.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2005 Martiño Figueroa +// Copyright (C) 2001-2005 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 3803ae8a..e9474e0a 100755 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -43,6 +43,7 @@ ClientInterface::ClientInterface(){ launchGame= false; introDone= false; playerIndex= -1; + gameSettingsReceived=false; networkGameDataSynchCheckOkMap = false; networkGameDataSynchCheckOkTile = false; @@ -324,6 +325,35 @@ void ClientInterface::updateLobby() } } break; + case nmtBroadCastSetup: + { + NetworkMessageLaunch networkMessageLaunch; + + if(receiveMessage(&networkMessageLaunch)) + { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got NetworkMessageLaunch\n",__FILE__,__FUNCTION__); + + networkMessageLaunch.buildGameSettings(&gameSettings); + + //replace server player by network + for(int i= 0; igetDescription(); data.map= gameSettings->getMap(); @@ -214,7 +214,6 @@ bool NetworkMessageLaunch::receive(Socket* socket){ } void NetworkMessageLaunch::send(Socket* socket) const{ - assert(data.messageType==nmtLaunch); NetworkMessage::send(socket, &data, sizeof(data)); } diff --git a/source/glest_game/network/network_message.h b/source/glest_game/network/network_message.h index 7f275b51..cb6d2aea 100644 --- a/source/glest_game/network/network_message.h +++ b/source/glest_game/network/network_message.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// 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 @@ -37,6 +37,8 @@ enum NetworkMessageType{ nmtSynchNetworkGameDataStatus, nmtSynchNetworkGameDataFileCRCCheck, nmtSynchNetworkGameDataFileGet, + nmtBroadCastSetup, + nmtCount }; @@ -157,7 +159,7 @@ private: public: NetworkMessageLaunch(); - NetworkMessageLaunch(const GameSettings *gameSettings); + NetworkMessageLaunch(const GameSettings *gameSettings,int8 messageType); void buildGameSettings(GameSettings *gameSettings) const; diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index ed6898a2..35fc808b 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -437,7 +437,7 @@ bool ServerInterface::launchGame(const GameSettings* gameSettings){ { serverSocket.stopBroadCastThread(); - NetworkMessageLaunch networkMessageLaunch(gameSettings); + NetworkMessageLaunch networkMessageLaunch(gameSettings,nmtLaunch); broadcastMessage(&networkMessageLaunch); } @@ -446,6 +446,16 @@ bool ServerInterface::launchGame(const GameSettings* gameSettings){ return bOkToStart; } +void ServerInterface::broadcastGameSetup(const GameSettings* gameSettings){ + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + + NetworkMessageLaunch networkMessageLaunch(gameSettings,nmtBroadCastSetup); + broadcastMessage(&networkMessageLaunch); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); +} + + void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot){ //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index 3b0f16f2..ad22d244 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// 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 @@ -73,6 +73,7 @@ public: bool launchGame(const GameSettings* gameSettings); virtual void setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck = false); + void broadcastGameSetup(const GameSettings* gameSettings); private: void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1);