* added missing #include "leak_dumper.h" to new cpp files

* fix for map names not being formatted (and replaced explicit loops to do the same to tileSet & techTree)
 * fix exploration state for fog-of-war off & multiplayer (note: also turns off for AI, diff. behaviour to before)
 * added fogOfWar to GameSettings and added to cutom game menu/menu_state_custom_game.cpp
This commit is contained in:
James McCulloch 2010-03-27 07:09:34 +00:00
parent c1ec8f97df
commit a9026f8c20
26 changed files with 869 additions and 123 deletions

View File

@ -146,11 +146,6 @@ void Game::init()
mainMessageBox.init(lang.get("Yes"), lang.get("No"));
mainMessageBox.setEnabled(false);
//check fog of war
if(!Config::getInstance().getBool("FogOfWar") && networkManager.isNetworkGame() ){
throw runtime_error("Can not play online games with for of war disabled");
}
//init world, and place camera
commander.init(&world);
world.init(this, gameSettings.getDefaultUnits());

View File

@ -0,0 +1,98 @@
// ==============================================================
// 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_GAMESETTINGS_H_
#define _GLEST_GAME_GAMESETTINGS_H_
#include "game_constants.h"
namespace Glest{ namespace Game{
// =====================================================
// class GameSettings
// =====================================================
class GameSettings{
private:
string description;
string map;
string tileset;
string tech;
string scenario;
string scenarioDir;
string factionTypeNames[GameConstants::maxPlayers]; //faction names
ControlType factionControls[GameConstants::maxPlayers];
int thisFactionIndex;
int factionCount;
int teams[GameConstants::maxPlayers];
int startLocationIndex[GameConstants::maxPlayers];
bool defaultUnits;
bool defaultResources;
bool defaultVictoryConditions;
bool fogOfWar;
public:
GameSettings() { }
// default copy constructor will do fine, and will maintain itself ;)
//get
const string &getDescription() const {return description;}
const string &getMap() const {return map;}
const string &getTileset() const {return tileset;}
const string &getTech() const {return tech;}
const string &getScenario() const {return scenario;}
const string &getScenarioDir() const {return scenarioDir;}
const string &getFactionTypeName(int factionIndex) const {return factionTypeNames[factionIndex];}
ControlType getFactionControl(int factionIndex) const {return factionControls[factionIndex];}
int getThisFactionIndex() const {return thisFactionIndex;}
int getFactionCount() const {return factionCount;}
int getTeam(int factionIndex) const {return teams[factionIndex];}
int getStartLocationIndex(int factionIndex) const {return startLocationIndex[factionIndex];}
bool getDefaultUnits() const {return defaultUnits;}
bool getDefaultResources() const {return defaultResources;}
bool getDefaultVictoryConditions() const {return defaultVictoryConditions;}
bool getFogOfWar() const {return fogOfWar;}
//set
void setDescription(const string& description) {this->description= description;}
void setMap(const string& map) {this->map= map;}
void setTileset(const string& tileset) {this->tileset= tileset;}
void setTech(const string& tech) {this->tech= tech;}
void setScenario(const string& scenario) {this->scenario= scenario;}
void setScenarioDir(const string& scenarioDir) {this->scenarioDir= scenarioDir;}
void setFactionTypeName(int factionIndex, const string& factionTypeName) {this->factionTypeNames[factionIndex]= factionTypeName;}
void setFactionControl(int factionIndex, ControlType controller) {this->factionControls[factionIndex]= controller;}
void setThisFactionIndex(int thisFactionIndex) {this->thisFactionIndex= thisFactionIndex;}
void setFactionCount(int factionCount) {this->factionCount= factionCount;}
void setTeam(int factionIndex, int team) {this->teams[factionIndex]= team;}
void setStartLocationIndex(int factionIndex, int startLocationIndex) {this->startLocationIndex[factionIndex]= startLocationIndex;}
void setDefaultUnits(bool defaultUnits) {this->defaultUnits= defaultUnits;}
void setDefaultResources(bool defaultResources) {this->defaultResources= defaultResources;}
void setDefaultVictoryConditions(bool defaultVictoryConditions) {this->defaultVictoryConditions= defaultVictoryConditions;}
void setFogOfWar(bool fogOfWar) {this->fogOfWar = fogOfWar;}
};
}}//end namespace
#endif

View File

@ -31,6 +31,12 @@ namespace Glest{ namespace Game{
using namespace Shared::Util;
struct FormatString {
void operator()(string &s) {
s = formatString(s);
}
};
// =====================================================
// class MenuStateCustomGame
// =====================================================
@ -40,67 +46,69 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
{
Lang &lang= Lang::getInstance();
NetworkManager &networkManager= NetworkManager::getInstance();
Config &config = Config::getInstance();
needToSetChangedGameSettings = false;
lastSetChangedGameSettings = time(NULL);;
vector<string> glestMaps, megaMaps, teamItems, controlItems;
vector<string> teamItems, controlItems, results;
//create
buttonReturn.init(350, 180, 125);
buttonPlayNow.init(525, 180, 125);
//map listBox
Config &config = Config::getInstance();
findAll(config.getPathListForType(ptMaps), "*.gbm", glestMaps, true, false);
findAll(config.getPathListForType(ptMaps), "*.mgm", megaMaps, true, false);
// 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)
set<string> allMaps;
if (!glestMaps.empty()) {
copy(glestMaps.begin(), glestMaps.end(), std::inserter(allMaps, allMaps.begin()));
}
if (!megaMaps.empty()) {
copy(megaMaps.begin(), megaMaps.end(), std::inserter(allMaps, allMaps.begin()));
}
if(allMaps.size()==0){
throw runtime_error("There are no maps");
}
std::copy(allMaps.begin(), allMaps.end(), std::back_inserter(mapFiles));
listBoxMap.init(200, 260, 150);
listBoxMap.setItems(mapFiles);
labelMap.init(200, 290);
labelMapInfo.init(200, 230, 200, 40);
findAll(config.getPathListForType(ptMaps), "*.gbm", results, true, false);
copy(results.begin(), results.end(), std::inserter(allMaps, allMaps.begin()));
results.clear();
findAll(config.getPathListForType(ptMaps), "*.mgm", results, true, false);
copy(results.begin(), results.end(), std::inserter(allMaps, allMaps.begin()));
results.clear();
vector<string> results;
if (allMaps.empty()) {
throw runtime_error("No maps were found!");
}
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
mapFiles = results;
std::for_each(results.begin(), results.end(), FormatString());
listBoxMap.init(100, 260, 200);
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("On"));
listBoxFogOfWar.pushBackItem(lang.get("Off"));
listBoxFogOfWar.setSelectedItemIndex(0);
//tileset listBox
findDirs(config.getPathListForType(ptTilesets), results);
if(results.size() == 0) {
throw runtime_error("There is no tile set");
if (results.empty()) {
throw runtime_error("No tile-sets were found!");
}
tilesetFiles= results;
for(int i= 0; i<results.size(); ++i){
results[i]= formatString(results[i]);
}
listBoxTileset.init(400, 260, 150);
std::for_each(results.begin(), results.end(), FormatString());
listBoxTileset.init(500, 260, 150);
listBoxTileset.setItems(results);
labelTileset.init(400, 290);
labelTileset.init(500, 290);
//tech Tree listBox
findDirs(config.getPathListForType(ptTechs), results);
if(results.size() == 0) {
throw runtime_error("There are no tech trees");
if(results.empty()) {
throw runtime_error("No tech-trees were found!");
}
techTreeFiles= results;
for(int i= 0; i<results.size(); ++i){
results[i]= formatString(results[i]);
}
listBoxTechTree.init(600, 260, 150);
std::for_each(results.begin(), results.end(), FormatString());
listBoxTechTree.init(700, 260, 150);
listBoxTechTree.setItems(results);
labelTechTree.init(600, 290);
labelTechTree.init(700, 290);
//list boxes
for(int i=0; i<GameConstants::maxPlayers; ++i){
@ -160,6 +168,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
}
labelMap.setText(lang.get("Map"));
labelFogOfWar.setText(lang.get("FogOfWar"));
labelTileset.setText(lang.get("Tileset"));
labelTechTree.setText(lang.get("TechTree"));
labelControl.setText(lang.get("Control"));
@ -232,6 +241,13 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
labelMapInfo.setText(mapInfo.desc);
updateControlers();
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);;
}
}
else if (listBoxFogOfWar.mouseClick(x, y)) {
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
@ -325,6 +341,7 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){
listBoxTeams[i].mouseMove(x, y);
}
listBoxMap.mouseMove(x, y);
listBoxFogOfWar.mouseMove(x, y);
listBoxTileset.mouseMove(x, y);
listBoxTechTree.mouseMove(x, y);
}
@ -348,6 +365,7 @@ void MenuStateCustomGame::render(){
}
}
renderer.renderLabel(&labelMap);
renderer.renderLabel(&labelFogOfWar);
renderer.renderLabel(&labelTileset);
renderer.renderLabel(&labelTechTree);
renderer.renderLabel(&labelControl);
@ -356,6 +374,7 @@ void MenuStateCustomGame::render(){
renderer.renderLabel(&labelMapInfo);
renderer.renderListBox(&listBoxMap);
renderer.renderListBox(&listBoxFogOfWar);
renderer.renderListBox(&listBoxTileset);
renderer.renderListBox(&listBoxTechTree);
@ -493,6 +512,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings)
gameSettings->setDefaultUnits(true);
gameSettings->setDefaultResources(true);
gameSettings->setDefaultVictoryConditions(true);
gameSettings->setFogOfWar(listBoxFogOfWar.getSelectedItemIndex() == 0);
for(int i=0; i<mapInfo.players; ++i)
{
@ -668,5 +688,4 @@ void MenuStateCustomGame::keyPress(char c)
chatManager.keyPress(c);
}
}}//end namespace

View File

@ -0,0 +1,81 @@
// ==============================================================
// 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
// ==============================================================
#ifndef _GLEST_GAME_MENUSTATECUSTOMGAME_H_
#define _GLEST_GAME_MENUSTATECUSTOMGAME_H_
#include "main_menu.h"
#include "chat_manager.h"
namespace Glest{ namespace Game{
// ===============================
// class MenuStateCustomGame
// ===============================
class MenuStateCustomGame: public MenuState{
private:
GraphicButton buttonReturn;
GraphicButton buttonPlayNow;
GraphicLabel labelControl;
GraphicLabel labelFaction;
GraphicLabel labelTeam;
GraphicLabel labelMap;
GraphicLabel labelFogOfWar;
GraphicLabel labelTechTree;
GraphicLabel labelTileset;
GraphicLabel labelMapInfo;
GraphicListBox listBoxMap;
GraphicListBox listBoxFogOfWar;
GraphicListBox listBoxTechTree;
GraphicListBox listBoxTileset;
vector<string> mapFiles;
vector<string> techTreeFiles;
vector<string> tilesetFiles;
vector<string> 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:
MenuStateCustomGame(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 loadGameSettings(GameSettings *gameSettings);
void loadMapInfo(string file, MapInfo *mapInfo);
void reloadFactions();
void updateControlers();
void closeUnusedSlots();
void updateNetworkSlots();
};
}}//end namespace
#endif

View File

@ -218,17 +218,7 @@ void ClientInterface::updateLobby()
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] mapCRC mismatch, local = %d, remote = %d\n",
__FILE__,__FUNCTION__,mapCRC,networkMessageSynchNetworkGameData.getMapCRC());
}
this->setNetworkGameDataSynchCheckOkFogOfWar((getFogOfWar() == networkMessageSynchNetworkGameData.getFogOfWar()));
if(this->getNetworkGameDataSynchCheckOkFogOfWar() == false)
{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] getFogOfWar mismatch, local = %d, remote = %d\n",
__FILE__,__FUNCTION__,getFogOfWar(),networkMessageSynchNetworkGameData.getFogOfWar());
}
NetworkMessageSynchNetworkGameDataStatus sendNetworkMessageSynchNetworkGameDataStatus(mapCRC,tilesetCRC,techCRC,getFogOfWar());
NetworkMessageSynchNetworkGameDataStatus sendNetworkMessageSynchNetworkGameDataStatus(mapCRC,tilesetCRC,techCRC);
sendMessage(&sendNetworkMessageSynchNetworkGameDataStatus);
}
}
@ -569,10 +559,10 @@ void ClientInterface::close()
delete clientSocket;
clientSocket= NULL;
}
/*
bool ClientInterface::getFogOfWar()
{
return Config::getInstance().getBool("FogOfWar");
}
*/
}}//end namespace

View File

@ -0,0 +1,85 @@
// ==============================================================
// 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_CLIENTINTERFACE_H_
#define _GLEST_GAME_CLIENTINTERFACE_H_
#include <vector>
#include "network_interface.h"
//#include "game_settings.h"
#include "socket.h"
using Shared::Platform::Ip;
using Shared::Platform::ClientSocket;
using std::vector;
namespace Glest{ namespace Game{
// =====================================================
// class ClientInterface
// =====================================================
class ClientInterface: public GameNetworkInterface{
private:
static const int messageWaitTimeout;
static const int waitSleepTime;
private:
ClientSocket *clientSocket;
//GameSettings gameSettings;
string serverName;
bool introDone;
bool launchGame;
int playerIndex;
Ip ip;
int port;
public:
ClientInterface();
virtual ~ClientInterface();
virtual Socket* getSocket() {return clientSocket;}
virtual const Socket* getSocket() const {return clientSocket;}
virtual void close();
//message processing
virtual void update();
virtual void updateLobby();
virtual void updateKeyframe(int frameCount);
virtual void waitUntilReady(Checksum* checksum);
// message sending
virtual void sendTextMessage(const string &text, int teamIndex);
virtual void quitGame(bool userManuallyQuit);
//misc
virtual string getNetworkStatus() const;
//accessors
string getServerName() const {return serverName;}
bool getLaunchGame() const {return launchGame;}
bool getIntroDone() const {return introDone;}
int getPlayerIndex() const {return playerIndex;}
//const GameSettings *getGameSettings() {return &gameSettings;}
void connect(const Ip &ip, int port);
void reset();
private:
void waitForMessage();
};
}}//end namespace
#endif

View File

@ -186,7 +186,6 @@ void ConnectionSlot::update(bool checkForNewClients)
networkGameDataSynchCheckOkMap = (networkMessageSynchNetworkGameDataStatus.getMapCRC() == mapCRC);
networkGameDataSynchCheckOkTile = (networkMessageSynchNetworkGameDataStatus.getTilesetCRC() == tilesetCRC);
networkGameDataSynchCheckOkTech = (networkMessageSynchNetworkGameDataStatus.getTechCRC() == techCRC);
networkGameDataSynchCheckOkFogOfWar = (networkMessageSynchNetworkGameDataStatus.getFogOfWar() == serverInterface->getFogOfWar() == true);
// For testing
//techCRC++;
@ -203,7 +202,6 @@ void ConnectionSlot::update(bool checkForNewClients)
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)
{

View File

@ -93,7 +93,6 @@ public:
virtual bool getNetworkGameDataSynchCheckOkMap() { return networkGameDataSynchCheckOkMap; }
virtual bool getNetworkGameDataSynchCheckOkTile() { return networkGameDataSynchCheckOkTile; }
virtual bool getNetworkGameDataSynchCheckOkTech() { return networkGameDataSynchCheckOkTech; }
virtual bool getFogOfWar()=0;
virtual bool getNetworkGameDataSynchCheckOkFogOfWar() { return networkGameDataSynchCheckOkFogOfWar; }
virtual void setNetworkGameDataSynchCheckOkFogOfWar(bool value) { networkGameDataSynchCheckOkFogOfWar = value; }

View File

@ -0,0 +1,79 @@
// ==============================================================
// 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 "network_manager.h"
#include "leak_dumper.h"
namespace Glest{ namespace Game{
// =====================================================
// class NetworkManager
// =====================================================
NetworkManager &NetworkManager::getInstance(){
static NetworkManager networkManager;
return networkManager;
}
NetworkManager::NetworkManager(){
gameNetworkInterface= NULL;
networkRole= nrIdle;
}
void NetworkManager::init(NetworkRole networkRole)
{
assert(gameNetworkInterface==NULL);
this->networkRole = networkRole;
if(networkRole==nrServer){
gameNetworkInterface = new ServerInterface();
}
else
{
gameNetworkInterface = new ClientInterface();
}
}
void NetworkManager::end(){
delete gameNetworkInterface;
gameNetworkInterface= NULL;
networkRole= nrIdle;
}
void NetworkManager::update(){
if(gameNetworkInterface!=NULL){
gameNetworkInterface->update();
}
}
bool NetworkManager::isNetworkGame(){
return networkRole==nrClient || getServerInterface()->getConnectedSlotCount()>0;
}
GameNetworkInterface* NetworkManager::getGameNetworkInterface(){
assert(gameNetworkInterface!=NULL);
return gameNetworkInterface;
}
ServerInterface* NetworkManager::getServerInterface(){
assert(gameNetworkInterface!=NULL);
assert(networkRole==nrServer);
return static_cast<ServerInterface*>(gameNetworkInterface);
}
ClientInterface* NetworkManager::getClientInterface(){
assert(gameNetworkInterface!=NULL);
assert(networkRole==nrClient);
return static_cast<ClientInterface*>(gameNetworkInterface);
}
}}//end namespace

View File

@ -177,6 +177,7 @@ NetworkMessageLaunch::NetworkMessageLaunch(const GameSettings *gameSettings){
data.defaultResources= gameSettings->getDefaultResources();
data.defaultUnits= gameSettings->getDefaultUnits();
data.defaultVictoryConditions= gameSettings->getDefaultVictoryConditions();
data.fogOfWar = gameSettings->getFogOfWar();
for(int i= 0; i<data.factionCount; ++i){
data.factionTypeNames[i]= gameSettings->getFactionTypeName(i);
@ -196,6 +197,7 @@ void NetworkMessageLaunch::buildGameSettings(GameSettings *gameSettings) const{
gameSettings->setDefaultResources(data.defaultResources);
gameSettings->setDefaultUnits(data.defaultUnits);
gameSettings->setDefaultVictoryConditions(data.defaultVictoryConditions);
gameSettings->setFogOfWar(data.fogOfWar);
for(int i= 0; i<data.factionCount; ++i){
gameSettings->setFactionTypeName(i, data.factionTypeNames[i].getString());
@ -344,8 +346,6 @@ NetworkMessageSynchNetworkGameData::NetworkMessageSynchNetworkGameData(const Gam
checksum.addFile(file);
data.mapCRC = checksum.getSum();
//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");;
}
bool NetworkMessageSynchNetworkGameData::receive(Socket* socket)
@ -364,15 +364,13 @@ void NetworkMessageSynchNetworkGameData::send(Socket* socket) const
// class NetworkMessageSynchNetworkGameDataStatus
// =====================================================
NetworkMessageSynchNetworkGameDataStatus::NetworkMessageSynchNetworkGameDataStatus(int32 mapCRC, int32 tilesetCRC, int32 techCRC, int8 hasFogOfWar)
NetworkMessageSynchNetworkGameDataStatus::NetworkMessageSynchNetworkGameDataStatus(int32 mapCRC, int32 tilesetCRC, int32 techCRC)
{
data.messageType= nmtSynchNetworkGameDataStatus;
data.tilesetCRC = tilesetCRC;
data.techCRC = techCRC;
data.mapCRC = mapCRC;
data.hasFogOfWar = hasFogOfWar;
}
bool NetworkMessageSynchNetworkGameDataStatus::receive(Socket* socket)

View File

@ -149,6 +149,7 @@ private:
int8 defaultResources;
int8 defaultUnits;
int8 defaultVictoryConditions;
int8 fogOfWar;
};
private:
@ -279,7 +280,6 @@ private:
int32 mapCRC;
int32 tilesetCRC;
int32 techCRC;
int8 hasFogOfWar;
};
private:
@ -299,8 +299,6 @@ public:
int32 getMapCRC() const {return data.mapCRC;}
int32 getTilesetCRC() const {return data.tilesetCRC;}
int32 getTechCRC() const {return data.techCRC;}
int8 getFogOfWar() const { return data.hasFogOfWar; }
};
// =====================================================
@ -323,7 +321,6 @@ private:
int32 tilesetCRC;
int32 techCRC;
int8 hasFogOfWar;
};
private:
@ -331,7 +328,7 @@ private:
public:
NetworkMessageSynchNetworkGameDataStatus() {};
NetworkMessageSynchNetworkGameDataStatus(int32 mapCRC, int32 tilesetCRC, int32 techCRC, int8 hasFogOfWar);
NetworkMessageSynchNetworkGameDataStatus(int32 mapCRC, int32 tilesetCRC, int32 techCRC);
virtual bool receive(Socket* socket);
virtual void send(Socket* socket) const;
@ -339,8 +336,6 @@ public:
int32 getMapCRC() const {return data.mapCRC;}
int32 getTilesetCRC() const {return data.tilesetCRC;}
int32 getTechCRC() const {return data.techCRC;}
int8 getFogOfWar() const { return data.hasFogOfWar; }
};
// =====================================================

View File

@ -571,9 +571,4 @@ void ServerInterface::close()
//serverSocket = ServerSocket();
}
bool ServerInterface::getFogOfWar()
{
return Config::getInstance().getBool("FogOfWar");
}
}}//end namespace

View File

@ -0,0 +1,85 @@
// ==============================================================
// 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_SERVERINTERFACE_H_
#define _GLEST_GAME_SERVERINTERFACE_H_
#include <vector>
#include "game_constants.h"
#include "network_interface.h"
#include "connection_slot.h"
#include "socket.h"
using std::vector;
using Shared::Platform::ServerSocket;
namespace Glest{ namespace Game{
// =====================================================
// class ServerInterface
// =====================================================
typedef struct
{
string chatText;
string chatSender;
int chatTeamIndex;
int sourceTeamIndex;
} TeamMessageData;
class ServerInterface: public GameNetworkInterface{
private:
ConnectionSlot* slots[GameConstants::maxPlayers];
ServerSocket serverSocket;
bool gameHasBeenInitiated;
int gameSettingsUpdateCount;
public:
ServerInterface();
virtual ~ServerInterface();
virtual Socket* getSocket() {return &serverSocket;}
virtual const Socket* getSocket() const {return &serverSocket;}
virtual void close();
//message processing
virtual void update();
virtual void updateLobby(){};
virtual void updateKeyframe(int frameCount);
virtual void waitUntilReady(Checksum* checksum);
// message sending
virtual void sendTextMessage(const string &text, int teamIndex);
virtual void quitGame(bool userManuallyQuit);
//misc
virtual string getNetworkStatus() const;
ServerSocket* getServerSocket() {return &serverSocket;}
void addSlot(int playerIndex);
void removeSlot(int playerIndex);
ConnectionSlot* getSlot(int playerIndex);
int getConnectedSlotCount();
bool launchGame(const GameSettings* gameSettings);
virtual void setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck = false);
private:
void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1);
void updateListen();
void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1);
};
}}//end namespace
#endif

View File

@ -0,0 +1,157 @@
// ==============================================================
// 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 "minimap.h"
#include <cassert>
#include "world.h"
#include "vec.h"
#include "renderer.h"
#include "config.h"
#include "object.h"
#include "leak_dumper.h"
using namespace Shared::Graphics;
namespace Glest{ namespace Game{
// =====================================================
// class Minimap
// =====================================================
const float Minimap::exploredAlpha= 0.5f;
Minimap::Minimap(){
fowPixmap0= NULL;
fowPixmap1= NULL;
fogOfWar= true;//Config::getInstance().getBool("FogOfWar");
}
void Minimap::init(int w, int h, const World *world, bool fogOfWar){
int scaledW= w/Map::cellScale;
int scaledH= h/Map::cellScale;
this->fogOfWar = fogOfWar;
Renderer &renderer= Renderer::getInstance();
//fow pixmaps
float f= 0.f;
fowPixmap0= new Pixmap2D(next2Power(scaledW), next2Power(scaledH), 1);
fowPixmap1= new Pixmap2D(next2Power(scaledW), next2Power(scaledH), 1);
fowPixmap0->setPixels(&f);
fowPixmap1->setPixels(&f);
//fow tex
fowTex= renderer.newTexture2D(rsGame);
fowTex->setMipmap(false);
fowTex->setPixmapInit(false);
fowTex->setFormat(Texture::fAlpha);
fowTex->getPixmap()->init(next2Power(scaledW), next2Power(scaledH), 1);
fowTex->getPixmap()->setPixels(&f);
//tex
tex= renderer.newTexture2D(rsGame);
tex->getPixmap()->init(scaledW, scaledH, 3);
tex->setMipmap(false);
computeTexture(world);
}
Minimap::~Minimap(){
Logger::getInstance().add("Minimap", true);
delete fowPixmap0;
delete fowPixmap1;
}
// ==================== set ====================
void Minimap::incFowTextureAlphaSurface(const Vec2i &sPos, float alpha){
assert(sPos.x<fowPixmap1->getW() && sPos.y<fowPixmap1->getH());
if(fowPixmap1->getPixelf(sPos.x, sPos.y)<alpha){
fowPixmap1->setPixel(sPos.x, sPos.y, alpha);
}
}
void Minimap::resetFowTex(){
Pixmap2D *tmpPixmap= fowPixmap0;
fowPixmap0= fowPixmap1;
fowPixmap1= tmpPixmap;
for(int i=0; i<fowTex->getPixmap()->getW(); ++i){
for(int j=0; j<fowTex->getPixmap()->getH(); ++j){
if(fogOfWar){
float p0= fowPixmap0->getPixelf(i, j);
float p1= fowPixmap1->getPixelf(i, j);
if(p1>exploredAlpha){
fowPixmap1->setPixel(i, j, exploredAlpha);
}
if(p0>p1){
fowPixmap1->setPixel(i, j, p0);
}
}
else{
fowPixmap1->setPixel(i, j, 1.f);
}
}
}
}
void Minimap::updateFowTex(float t){
for(int i=0; i<fowPixmap0->getW(); ++i){
for(int j=0; j<fowPixmap0->getH(); ++j){
float p1= fowPixmap1->getPixelf(i, j);
if(p1!=fowTex->getPixmap()->getPixelf(i, j)){
float p0= fowPixmap0->getPixelf(i, j);
fowTex->getPixmap()->setPixel(i, j, p0+(t*(p1-p0)));
}
}
}
}
// ==================== PRIVATE ====================
void Minimap::computeTexture(const World *world){
Vec3f color;
const Map *map= world->getMap();
tex->getPixmap()->setPixels(Vec4f(1.f, 1.f, 1.f, 0.1f).ptr());
for(int j=0; j<tex->getPixmap()->getH(); ++j){
for(int i=0; i<tex->getPixmap()->getW(); ++i){
SurfaceCell *sc= map->getSurfaceCell(i, j);
if(sc->getObject()==NULL || sc->getObject()->getType()==NULL){
const Pixmap2D *p= world->getTileset()->getSurfPixmap(sc->getSurfaceType(), 0);
color= p->getPixel3f(p->getW()/2, p->getH()/2);
color= color * static_cast<float>(sc->getVertex().y/6.f);
if(sc->getVertex().y<= world->getMap()->getWaterLevel()){
color+= Vec3f(0.5f, 0.5f, 1.0f);
}
if(color.x>1.f) color.x=1.f;
if(color.y>1.f) color.y=1.f;
if(color.z>1.f) color.z=1.f;
}
else{
color= sc->getObject()->getType()->getColor();
}
tex->getPixmap()->setPixel(i, j, color);
}
}
}
}}//end namespace

View File

@ -0,0 +1,69 @@
// ==============================================================
// 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_MINIMAP_H_
#define _GLEST_GAME_MINIMAP_H_
#include "pixmap.h"
#include "texture.h"
namespace Glest{ namespace Game{
using Shared::Graphics::Vec4f;
using Shared::Graphics::Vec3f;
using Shared::Graphics::Vec2i;
using Shared::Graphics::Pixmap2D;
using Shared::Graphics::Texture2D;
class World;
enum ExplorationState{
esNotExplored,
esExplored,
esVisible
};
// =====================================================
// class Minimap
//
/// State of the in-game minimap
// =====================================================
class Minimap{
private:
Pixmap2D *fowPixmap0;
Pixmap2D *fowPixmap1;
Texture2D *tex;
Texture2D *fowTex; //Fog Of War Texture2D
bool fogOfWar;
private:
static const float exploredAlpha;
public:
void init(int x, int y, const World *world, bool fogOfWar);
Minimap();
~Minimap();
const Texture2D *getFowTexture() const {return fowTex;}
const Texture2D *getTexture() const {return tex;}
void incFowTextureAlphaSurface(const Vec2i &sPos, float alpha);
void resetFowTex();
void updateFowTex(float t);
private:
void computeTexture(const World *world);
};
}}//end namespace
#endif

View File

@ -39,7 +39,6 @@ const float World::airHeight= 5.f;
World::World(){
Config &config= Config::getInstance();
fogOfWar= config.getBool("FogOfWar");
fogOfWarSmoothing= config.getBool("FogOfWarSmoothing");
fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip");
@ -70,8 +69,11 @@ void World::init(Game *game, bool createUnits){
unitUpdater.init(game);
initFactionTypes(game->getGameSettings());
initCells(); //must be done after knowing faction number and dimensions
GameSettings *gs = game->getGameSettings();
fogOfWar = gs->getFogOfWar();
initFactionTypes(gs);
initCells(fogOfWar); //must be done after knowing faction number and dimensions
initMap();
initSplattedTextures();
@ -80,7 +82,7 @@ void World::init(Game *game, bool createUnits){
if(createUnits){
initUnits();
}
initExplorationState();
//initExplorationState(); ... was only for !fog-of-war, now handled in initCells()
computeFow();
}
@ -487,7 +489,7 @@ int World::getUnitCountOfType(int factionIndex, const string &typeName){
// ==================== private init ====================
//init basic cell state
void World::initCells(){
void World::initCells(bool fogOfWar){
Logger::getInstance().add("State cells", true);
for(int i=0; i<map.getSurfaceW(); ++i){
@ -499,10 +501,10 @@ void World::initCells(){
i/(next2Power(map.getSurfaceW())-1.f),
j/(next2Power(map.getSurfaceH())-1.f)));
for(int k=0; k<GameConstants::maxPlayers; k++){
sc->setExplored(k, false);
sc->setVisible(k, 0);
}
for (int k = 0; k < GameConstants::maxPlayers; k++) {
sc->setExplored(k, !fogOfWar);
sc->setVisible(k, !fogOfWar);
}
}
}
}
@ -558,7 +560,7 @@ void World::initFactionTypes(GameSettings *gs){
}
void World::initMinimap(){
minimap.init(map.getW(), map.getH(), this);
minimap.init(map.getW(), map.getH(), this, game->getGameSettings()->getFogOfWar());
Logger::getInstance().add("Compute minimap surface", true);
}
@ -600,18 +602,6 @@ void World::initMap(){
map.init();
}
void World::initExplorationState(){
if(!fogOfWar){
for(int i=0; i<map.getSurfaceW(); ++i){
for(int j=0; j<map.getSurfaceH(); ++j){
map.getSurfaceCell(i, j)->setVisible(thisTeamIndex, true);
map.getSurfaceCell(i, j)->setExplored(thisTeamIndex, true);
}
}
}
}
// ==================== exploration ====================
void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){

View File

@ -151,13 +151,13 @@ public:
private:
void initCells();
void initCells(bool fogOfWar);
void initSplattedTextures();
void initFactionTypes(GameSettings *gs);
void initMinimap();
void initUnits();
void initMap();
void initExplorationState();
//void initExplorationState();
//misc
void tick();

View File

@ -0,0 +1,121 @@
// ==============================================================
// 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 _LEAKDUMPER_H_
#define _LEAKDUMPER_H_
#define SL_LEAK_DUMP
//SL_LEAK_DUMP controls if leak dumping is enabled or not
#ifdef SL_LEAK_DUMP
#include <cstdlib>
#include <cstdio>
//including this header in any file of a project will cause all
//leaks to be dumped into leak_dump.txt, but only allocations that
//ocurred in a file where this header is included will have
//file and line number
struct AllocInfo{
int line;
const char *file;
size_t bytes;
void *ptr;
bool free;
bool array;
AllocInfo();
AllocInfo(void* ptr, const char* file, int line, size_t bytes, bool array);
};
// =====================================================
// class AllocRegistry
// =====================================================
class AllocRegistry{
private:
static const unsigned maxAllocs= 40000;
private:
AllocRegistry();
private:
AllocInfo allocs[maxAllocs]; //array to store allocation info
int allocCount; //allocations
size_t allocBytes; //bytes allocated
int nonMonitoredCount;
size_t nonMonitoredBytes;
public:
~AllocRegistry();
static AllocRegistry &getInstance();
void allocate(AllocInfo info);
void deallocate(void* ptr, bool array);
void reset();
void dump(const char *path);
};
//if an allocation ocurrs in a file where "leaks_dumper.h" is not included
//this operator new is called and file and line will be unknown
inline void * operator new (size_t bytes){
void *ptr= malloc(bytes);
AllocRegistry::getInstance().allocate(AllocInfo(ptr, "unknown", 0, bytes, false));
return ptr;
}
inline void operator delete(void *ptr){
AllocRegistry::getInstance().deallocate(ptr, false);
free(ptr);
}
inline void * operator new[](size_t bytes){
void *ptr= malloc(bytes);
AllocRegistry::getInstance().allocate(AllocInfo(ptr, "unknown", 0, bytes, true));
return ptr;
}
inline void operator delete [](void *ptr){
AllocRegistry::getInstance().deallocate(ptr, true);
free(ptr);
}
//if an allocation ocurrs in a file where "leaks_dumper.h" is included
//this operator new is called and file and line will be known
inline void * operator new (size_t bytes, char* file, int line){
void *ptr= malloc(bytes);
AllocRegistry::getInstance().allocate(AllocInfo(ptr, file, line, bytes, false));
return ptr;
}
inline void operator delete(void *ptr, char* file, int line){
AllocRegistry::getInstance().deallocate(ptr, false);
free(ptr);
}
inline void * operator new[](size_t bytes, char* file, int line){
void *ptr= malloc(bytes);
AllocRegistry::getInstance().allocate(AllocInfo(ptr, file, line, bytes, true));
return ptr;
}
inline void operator delete [](void *ptr, char* file, int line){
AllocRegistry::getInstance().deallocate(ptr, true);
free(ptr);
}
#define new new(__FILE__, __LINE__)
#endif
#endif

View File

@ -14,6 +14,8 @@
#include "pixmap.h"
#include <stdexcept>
#include "leak_dumper.h"
using std::runtime_error;
namespace Shared{ namespace Graphics{

View File

@ -10,6 +10,7 @@
// ==============================================================
#include "ImageReaders.h"
#include "leak_dumper.h"
namespace Shared{ namespace Graphics{

View File

@ -18,6 +18,8 @@
#include <jpeglib.h>
#include <setjmp.h>
#include "leak_dumper.h"
using std::runtime_error;
using std::ios;

View File

@ -17,6 +17,8 @@
#include <png.h>
#include <setjmp.h>
#include "leak_dumper.h"
using std::runtime_error;
using std::ios;

View File

@ -15,6 +15,8 @@
#include <stdexcept>
#include <iostream>
#include "leak_dumper.h"
using std::runtime_error;
namespace Shared{ namespace Graphics{
@ -146,6 +148,6 @@ Pixmap2D* TGAReader::read(ifstream& in, const string& path, Pixmap2D* ret) const
std::cout << " ";
}*/
return ret;
}
}
}} //end namespace

View File

@ -18,13 +18,10 @@
#include "util.h"
#include "math_util.h"
#include "random.h"
#include "leak_dumper.h"
#include "FileReader.h"
//Readers
#include "ImageReaders.h"
#include "leak_dumper.h"
using namespace Shared::Util;
using namespace std;

View File

@ -13,22 +13,12 @@
#ifdef SL_LEAK_DUMP
AllocInfo::AllocInfo(){
ptr= NULL;
file= "";
line= -1;
bytes= -1;
array= false;
free= true;
AllocInfo::AllocInfo()
: ptr(0), file(""), line(-1), bytes(-1), array(false), free(false) {
}
AllocInfo::AllocInfo(void* ptr, const char* file, int line, size_t bytes, bool array){
this->ptr= ptr;
this->file= file;
this->line= line;
this->bytes= bytes;
this->array= array;
free= false;
AllocInfo::AllocInfo(void* ptr, const char* file, int line, size_t bytes, bool array)
: ptr(ptr), file(file), line(line), bytes(bytes), array(array), free(false) {
}
// =====================================================
@ -53,12 +43,7 @@ AllocRegistry &AllocRegistry::getInstance(){
AllocRegistry::~AllocRegistry(){
string leakLog = "leak_dump.log";
if(getGameReadWritePath() != "") {
leakLog = getGameReadWritePath() + leakLog;
}
dump(leakLog.c_str());
dump("leak_dump.log");
}
void AllocRegistry::allocate(AllocInfo info){

View File

@ -14,6 +14,7 @@
#ifdef SL_PROFILE
#include <stdexcept>
#include "leak_dumper.h"
using namespace std;