mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- bugfixes for joining network games
This commit is contained in:
parent
54c026bb3e
commit
69925fb887
@ -96,6 +96,17 @@ PathFinder::~PathFinder() {
|
||||
factionMutex = NULL;
|
||||
}
|
||||
|
||||
void PathFinder::clearCaches() {
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
MutexSafeWrapper safeMutex(factionMutex,mutexOwnerId);
|
||||
|
||||
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
||||
factions[i].precachedTravelState.clear();
|
||||
factions[i].precachedPath.clear();
|
||||
factions[i].badCellList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void PathFinder::clearUnitPrecache(Unit *unit) {
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
MutexSafeWrapper safeMutex(factionMutex,mutexOwnerId);
|
||||
|
@ -162,6 +162,7 @@ public:
|
||||
TravelState findPath(Unit *unit, const Vec2i &finalPos, bool *wasStuck=NULL,int frameIndex=-1);
|
||||
void clearUnitPrecache(Unit *unit);
|
||||
void removeUnitPrecache(Unit *unit);
|
||||
void clearCaches();
|
||||
|
||||
int findNodeIndex(Node *node, Nodes &nodeList);
|
||||
int findNodeIndex(Node *node, std::vector<Node> &nodeList);
|
||||
|
@ -79,6 +79,7 @@ Game::Game() : ProgramState(NULL) {
|
||||
avgRenderFps=0;
|
||||
currentAvgRenderFpsTotal=0;
|
||||
paused=false;
|
||||
pauseStateChanged=false;
|
||||
gameOver=false;
|
||||
renderNetworkStatus=false;
|
||||
showFullConsole=false;
|
||||
@ -233,6 +234,7 @@ void Game::resetMembers() {
|
||||
currentAvgRenderFpsTotal=0;
|
||||
tickCount=0;
|
||||
paused= false;
|
||||
pauseStateChanged=false;
|
||||
gameOver= false;
|
||||
renderNetworkStatus= false;
|
||||
speed= 1;
|
||||
@ -1990,6 +1992,47 @@ void Game::update() {
|
||||
//return;
|
||||
}
|
||||
}
|
||||
//else if(server->getPauseForInGameConnection() == true && paused == true &&
|
||||
else if(paused == true && pauseStateChanged == true) {
|
||||
pauseStateChanged = false;
|
||||
|
||||
//NetworkManager &networkManager= NetworkManager::getInstance();
|
||||
//NetworkRole role = networkManager.getNetworkRole();
|
||||
|
||||
//if(role == nrServer) {
|
||||
bool saveNetworkGame = false;
|
||||
|
||||
ServerInterface *server = NetworkManager::getInstance().getServerInterface();
|
||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||
Faction *faction = world.getFaction(i);
|
||||
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||
if(slot != NULL && slot->getJoinGameInProgress() == true) {
|
||||
saveNetworkGame = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(saveNetworkGame == true) {
|
||||
//printf("Saved network game to disk\n");
|
||||
|
||||
string file = this->saveGame(GameConstants::saveNetworkGameFileServer,"temp/");
|
||||
char szBuf[8096]="";
|
||||
Lang &lang= Lang::getInstance();
|
||||
snprintf(szBuf,8096,lang.get("GameSaved","",true).c_str(),file.c_str());
|
||||
console.addLine(szBuf);
|
||||
|
||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||
Faction *faction = world.getFaction(i);
|
||||
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||
if(slot != NULL && slot->getJoinGameInProgress() == true) {
|
||||
|
||||
NetworkMessageReady networkMessageReady(0);
|
||||
slot->sendMessage(&networkMessageReady);
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
else if(server->getUnPauseForInGameConnection() == true && paused == true) {
|
||||
//printf("^^^ getUnPauseForInGameConnection triggered!\n");
|
||||
|
||||
@ -5193,6 +5236,7 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches
|
||||
if(value == false) {
|
||||
console.addLine(lang.get("GameResumed"));
|
||||
paused= false;
|
||||
pauseStateChanged = true;
|
||||
|
||||
if(clearCaches == true) {
|
||||
world.clearCaches();
|
||||
@ -5206,41 +5250,14 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches
|
||||
else {
|
||||
console.addLine(lang.get("GamePaused"));
|
||||
paused= true;
|
||||
pauseStateChanged = true;
|
||||
//!!!
|
||||
|
||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||
NetworkRole role = networkManager.getNetworkRole();
|
||||
|
||||
if(role == nrServer) {
|
||||
bool saveNetworkGame = false;
|
||||
|
||||
ServerInterface *server = NetworkManager::getInstance().getServerInterface();
|
||||
if(clearCaches == true) {
|
||||
world.clearCaches();
|
||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||
Faction *faction = world.getFaction(i);
|
||||
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||
if(slot != NULL && slot->getJoinGameInProgress() == true) {
|
||||
saveNetworkGame = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(saveNetworkGame == true) {
|
||||
//printf("Saved network game to disk\n");
|
||||
|
||||
string file = this->saveGame(GameConstants::saveNetworkGameFileServer,"temp/");
|
||||
char szBuf[8096]="";
|
||||
Lang &lang= Lang::getInstance();
|
||||
snprintf(szBuf,8096,lang.get("GameSaved","",true).c_str(),file.c_str());
|
||||
console.addLine(szBuf);
|
||||
|
||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||
Faction *faction = world.getFaction(i);
|
||||
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||
if(slot != NULL && slot->getJoinGameInProgress() == true) {
|
||||
|
||||
NetworkMessageReady networkMessageReady(0);
|
||||
slot->sendMessage(&networkMessageReady);
|
||||
}
|
||||
}
|
||||
faction->clearCaches();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ private:
|
||||
int totalRenderFps, renderFps, lastRenderFps, avgRenderFps,currentAvgRenderFpsTotal;
|
||||
uint64 tickCount;
|
||||
bool paused;
|
||||
bool pauseStateChanged;
|
||||
bool gameOver;
|
||||
bool renderNetworkStatus;
|
||||
bool showFullConsole;
|
||||
|
@ -4134,10 +4134,15 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
|
||||
result->rotation = unitNode->getAttribute("rotation")->getFloatValue();
|
||||
|
||||
//world->placeUnitAtLocation(newUnitPos, generationArea, unit, true);
|
||||
result->setPos(newUnitPos);
|
||||
Vec2i meetingPos = newUnitPos-Vec2i(1);
|
||||
result->setMeetingPos(meetingPos);
|
||||
|
||||
//result->setPos(newUnitPos);
|
||||
//Vec2i meetingPos = newUnitPos-Vec2i(1);
|
||||
//result->setMeetingPos(meetingPos);
|
||||
result->pos = newUnitPos;
|
||||
result->lastPos = Vec2i::strToVec2(unitNode->getAttribute("lastPos")->getValue());
|
||||
result->meetingPos = Vec2i::strToVec2(unitNode->getAttribute("meetingPos")->getValue());
|
||||
// Attempt to improve performance
|
||||
//result->exploreCells();
|
||||
//result->calculateFogOfWarRadius();
|
||||
// --------------------------
|
||||
|
||||
result->hp = unitNode->getAttribute("hp")->getIntValue();
|
||||
@ -4511,6 +4516,8 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
|
||||
//result->born();
|
||||
}
|
||||
|
||||
result->pos = newUnitPos;
|
||||
result->lastPos = Vec2i::strToVec2(unitNode->getAttribute("lastPos")->getValue());
|
||||
result->meetingPos = Vec2i::strToVec2(unitNode->getAttribute("meetingPos")->getValue());
|
||||
|
||||
if(unitNode->hasAttribute("currentPathFinderDesiredFinalPos")) {
|
||||
|
@ -2625,6 +2625,12 @@ void UnitUpdater::saveGame(XmlNode *rootNode) {
|
||||
// std::map<Vec2i, std::map<int, std::map<int, UnitRangeCellsLookupItem > > > UnitRangeCellsLookupItemCache;
|
||||
}
|
||||
|
||||
void UnitUpdater::clearCaches() {
|
||||
if(pathFinder != NULL) {
|
||||
pathFinder->clearCaches();
|
||||
}
|
||||
}
|
||||
|
||||
void UnitUpdater::loadGame(const XmlNode *rootNode) {
|
||||
const XmlNode *unitupdaterNode = rootNode->getChild("UnitUpdater");
|
||||
|
||||
|
@ -136,6 +136,8 @@ public:
|
||||
void saveGame(XmlNode *rootNode);
|
||||
void loadGame(const XmlNode *rootNode);
|
||||
|
||||
void clearCaches();
|
||||
|
||||
private:
|
||||
//attack
|
||||
void hit(Unit *attacker);
|
||||
|
@ -1428,6 +1428,8 @@ void World::clearCaches() {
|
||||
ExploredCellsLookupItemCache.clear();
|
||||
ExploredCellsLookupItemCacheTimer.clear();
|
||||
ExploredCellsLookupItemCacheTimerCount = 0;
|
||||
|
||||
unitUpdater.clearCaches();
|
||||
}
|
||||
|
||||
void World::togglePauseGame(bool pauseStatus,bool forceAllowPauseStateChange) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user