- bugfixes for joining network games
This commit is contained in:
parent
54c026bb3e
commit
69925fb887
|
@ -96,6 +96,17 @@ PathFinder::~PathFinder() {
|
||||||
factionMutex = NULL;
|
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) {
|
void PathFinder::clearUnitPrecache(Unit *unit) {
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(factionMutex,mutexOwnerId);
|
MutexSafeWrapper safeMutex(factionMutex,mutexOwnerId);
|
||||||
|
|
|
@ -162,6 +162,7 @@ public:
|
||||||
TravelState findPath(Unit *unit, const Vec2i &finalPos, bool *wasStuck=NULL,int frameIndex=-1);
|
TravelState findPath(Unit *unit, const Vec2i &finalPos, bool *wasStuck=NULL,int frameIndex=-1);
|
||||||
void clearUnitPrecache(Unit *unit);
|
void clearUnitPrecache(Unit *unit);
|
||||||
void removeUnitPrecache(Unit *unit);
|
void removeUnitPrecache(Unit *unit);
|
||||||
|
void clearCaches();
|
||||||
|
|
||||||
int findNodeIndex(Node *node, Nodes &nodeList);
|
int findNodeIndex(Node *node, Nodes &nodeList);
|
||||||
int findNodeIndex(Node *node, std::vector<Node> &nodeList);
|
int findNodeIndex(Node *node, std::vector<Node> &nodeList);
|
||||||
|
|
|
@ -79,6 +79,7 @@ Game::Game() : ProgramState(NULL) {
|
||||||
avgRenderFps=0;
|
avgRenderFps=0;
|
||||||
currentAvgRenderFpsTotal=0;
|
currentAvgRenderFpsTotal=0;
|
||||||
paused=false;
|
paused=false;
|
||||||
|
pauseStateChanged=false;
|
||||||
gameOver=false;
|
gameOver=false;
|
||||||
renderNetworkStatus=false;
|
renderNetworkStatus=false;
|
||||||
showFullConsole=false;
|
showFullConsole=false;
|
||||||
|
@ -233,6 +234,7 @@ void Game::resetMembers() {
|
||||||
currentAvgRenderFpsTotal=0;
|
currentAvgRenderFpsTotal=0;
|
||||||
tickCount=0;
|
tickCount=0;
|
||||||
paused= false;
|
paused= false;
|
||||||
|
pauseStateChanged=false;
|
||||||
gameOver= false;
|
gameOver= false;
|
||||||
renderNetworkStatus= false;
|
renderNetworkStatus= false;
|
||||||
speed= 1;
|
speed= 1;
|
||||||
|
@ -1990,6 +1992,47 @@ void Game::update() {
|
||||||
//return;
|
//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) {
|
else if(server->getUnPauseForInGameConnection() == true && paused == true) {
|
||||||
//printf("^^^ getUnPauseForInGameConnection triggered!\n");
|
//printf("^^^ getUnPauseForInGameConnection triggered!\n");
|
||||||
|
|
||||||
|
@ -5193,6 +5236,7 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches
|
||||||
if(value == false) {
|
if(value == false) {
|
||||||
console.addLine(lang.get("GameResumed"));
|
console.addLine(lang.get("GameResumed"));
|
||||||
paused= false;
|
paused= false;
|
||||||
|
pauseStateChanged = true;
|
||||||
|
|
||||||
if(clearCaches == true) {
|
if(clearCaches == true) {
|
||||||
world.clearCaches();
|
world.clearCaches();
|
||||||
|
@ -5206,41 +5250,14 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches
|
||||||
else {
|
else {
|
||||||
console.addLine(lang.get("GamePaused"));
|
console.addLine(lang.get("GamePaused"));
|
||||||
paused= true;
|
paused= true;
|
||||||
|
pauseStateChanged = true;
|
||||||
|
//!!!
|
||||||
|
|
||||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
if(clearCaches == true) {
|
||||||
NetworkRole role = networkManager.getNetworkRole();
|
world.clearCaches();
|
||||||
|
|
||||||
if(role == nrServer) {
|
|
||||||
bool saveNetworkGame = false;
|
|
||||||
|
|
||||||
ServerInterface *server = NetworkManager::getInstance().getServerInterface();
|
|
||||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||||
Faction *faction = world.getFaction(i);
|
Faction *faction = world.getFaction(i);
|
||||||
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
faction->clearCaches();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,7 @@ private:
|
||||||
int totalRenderFps, renderFps, lastRenderFps, avgRenderFps,currentAvgRenderFpsTotal;
|
int totalRenderFps, renderFps, lastRenderFps, avgRenderFps,currentAvgRenderFpsTotal;
|
||||||
uint64 tickCount;
|
uint64 tickCount;
|
||||||
bool paused;
|
bool paused;
|
||||||
|
bool pauseStateChanged;
|
||||||
bool gameOver;
|
bool gameOver;
|
||||||
bool renderNetworkStatus;
|
bool renderNetworkStatus;
|
||||||
bool showFullConsole;
|
bool showFullConsole;
|
||||||
|
|
|
@ -4134,10 +4134,15 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
|
||||||
result->rotation = unitNode->getAttribute("rotation")->getFloatValue();
|
result->rotation = unitNode->getAttribute("rotation")->getFloatValue();
|
||||||
|
|
||||||
//world->placeUnitAtLocation(newUnitPos, generationArea, unit, true);
|
//world->placeUnitAtLocation(newUnitPos, generationArea, unit, true);
|
||||||
result->setPos(newUnitPos);
|
//result->setPos(newUnitPos);
|
||||||
Vec2i meetingPos = newUnitPos-Vec2i(1);
|
//Vec2i meetingPos = newUnitPos-Vec2i(1);
|
||||||
result->setMeetingPos(meetingPos);
|
//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();
|
result->hp = unitNode->getAttribute("hp")->getIntValue();
|
||||||
|
@ -4511,6 +4516,8 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
|
||||||
//result->born();
|
//result->born();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result->pos = newUnitPos;
|
||||||
|
result->lastPos = Vec2i::strToVec2(unitNode->getAttribute("lastPos")->getValue());
|
||||||
result->meetingPos = Vec2i::strToVec2(unitNode->getAttribute("meetingPos")->getValue());
|
result->meetingPos = Vec2i::strToVec2(unitNode->getAttribute("meetingPos")->getValue());
|
||||||
|
|
||||||
if(unitNode->hasAttribute("currentPathFinderDesiredFinalPos")) {
|
if(unitNode->hasAttribute("currentPathFinderDesiredFinalPos")) {
|
||||||
|
|
|
@ -2625,6 +2625,12 @@ void UnitUpdater::saveGame(XmlNode *rootNode) {
|
||||||
// std::map<Vec2i, std::map<int, std::map<int, UnitRangeCellsLookupItem > > > UnitRangeCellsLookupItemCache;
|
// 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) {
|
void UnitUpdater::loadGame(const XmlNode *rootNode) {
|
||||||
const XmlNode *unitupdaterNode = rootNode->getChild("UnitUpdater");
|
const XmlNode *unitupdaterNode = rootNode->getChild("UnitUpdater");
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,8 @@ public:
|
||||||
void saveGame(XmlNode *rootNode);
|
void saveGame(XmlNode *rootNode);
|
||||||
void loadGame(const XmlNode *rootNode);
|
void loadGame(const XmlNode *rootNode);
|
||||||
|
|
||||||
|
void clearCaches();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//attack
|
//attack
|
||||||
void hit(Unit *attacker);
|
void hit(Unit *attacker);
|
||||||
|
|
|
@ -1428,6 +1428,8 @@ void World::clearCaches() {
|
||||||
ExploredCellsLookupItemCache.clear();
|
ExploredCellsLookupItemCache.clear();
|
||||||
ExploredCellsLookupItemCacheTimer.clear();
|
ExploredCellsLookupItemCacheTimer.clear();
|
||||||
ExploredCellsLookupItemCacheTimerCount = 0;
|
ExploredCellsLookupItemCacheTimerCount = 0;
|
||||||
|
|
||||||
|
unitUpdater.clearCaches();
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::togglePauseGame(bool pauseStatus,bool forceAllowPauseStateChange) {
|
void World::togglePauseGame(bool pauseStatus,bool forceAllowPauseStateChange) {
|
||||||
|
|
Loading…
Reference in New Issue