- bugfixes for in game joining
This commit is contained in:
parent
e771b53f1c
commit
54c026bb3e
|
@ -483,13 +483,13 @@ void Commander::tryDisconnectNetworkPlayer(const Faction* faction, int playerInd
|
||||||
pushNetworkCommand(&command);
|
pushNetworkCommand(&command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Commander::tryPauseGame() const {
|
void Commander::tryPauseGame(bool clearCaches) const {
|
||||||
NetworkCommand command(this->world,nctPauseResume, 1);
|
NetworkCommand command(this->world,nctPauseResume, 1, (clearCaches == true ? 1 : 0));
|
||||||
pushNetworkCommand(&command);
|
pushNetworkCommand(&command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Commander::tryResumeGame() const {
|
void Commander::tryResumeGame(bool clearCaches) const {
|
||||||
NetworkCommand command(this->world,nctPauseResume, 0);
|
NetworkCommand command(this->world,nctPauseResume, 0, (clearCaches == true ? 1 : 0));
|
||||||
pushNetworkCommand(&command);
|
pushNetworkCommand(&command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,6 +613,7 @@ void Commander::updateNetwork(Game *game) {
|
||||||
GameSettings *gameSettings = game->getGameSettings();
|
GameSettings *gameSettings = game->getGameSettings();
|
||||||
if( networkManager.isNetworkGame() == false ||
|
if( networkManager.isNetworkGame() == false ||
|
||||||
(world->getFrameCount() % gameSettings->getNetworkFramePeriod()) == 0) {
|
(world->getFrameCount() % gameSettings->getNetworkFramePeriod()) == 0) {
|
||||||
|
//printf("Commander world->getFrameCount() = %d gameSettings->getNetworkFramePeriod() = %d\n",world->getFrameCount(),gameSettings->getNetworkFramePeriod());
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] networkManager.isNetworkGame() = %d,world->getFrameCount() = %d, gameSettings->getNetworkFramePeriod() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkManager.isNetworkGame(),world->getFrameCount(),gameSettings->getNetworkFramePeriod());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] networkManager.isNetworkGame() = %d,world->getFrameCount() = %d, gameSettings->getNetworkFramePeriod() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkManager.isNetworkGame(),world->getFrameCount(),gameSettings->getNetworkFramePeriod());
|
||||||
|
|
||||||
|
@ -870,11 +871,12 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const {
|
||||||
|
|
||||||
commandWasHandled = true;
|
commandWasHandled = true;
|
||||||
|
|
||||||
bool pauseGame = networkCommand->getUnitId() != 0;
|
bool pauseGame = networkCommand->getUnitId() != 0;
|
||||||
|
bool clearCaches = networkCommand->getCommandTypeId();
|
||||||
Game *game = this->world->getGame();
|
Game *game = this->world->getGame();
|
||||||
|
|
||||||
//printf("nctPauseResume pauseGame = %d\n",pauseGame);
|
//printf("nctPauseResume pauseGame = %d\n",pauseGame);
|
||||||
game->setPaused(pauseGame,true);
|
game->setPaused(pauseGame,true,clearCaches);
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctPauseResume\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctPauseResume\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,8 +114,8 @@ public:
|
||||||
void trySwitchTeam(const Faction* faction, int teamIndex) const;
|
void trySwitchTeam(const Faction* faction, int teamIndex) const;
|
||||||
void trySwitchTeamVote(const Faction* faction, SwitchTeamVote *vote) const;
|
void trySwitchTeamVote(const Faction* faction, SwitchTeamVote *vote) const;
|
||||||
void tryDisconnectNetworkPlayer(const Faction* faction, int playerIndex) const;
|
void tryDisconnectNetworkPlayer(const Faction* faction, int playerIndex) const;
|
||||||
void tryPauseGame() const;
|
void tryPauseGame(bool clearCaches) const;
|
||||||
void tryResumeGame() const;
|
void tryResumeGame(bool clearCaches) const;
|
||||||
void tryNetworkPlayerDisconnected(int factionIndex) const;
|
void tryNetworkPlayerDisconnected(int factionIndex) const;
|
||||||
|
|
||||||
Command* buildCommand(const NetworkCommand* networkCommand) const;
|
Command* buildCommand(const NetworkCommand* networkCommand) const;
|
||||||
|
|
|
@ -1416,10 +1416,6 @@ void Game::init(bool initForPreviewOnly) {
|
||||||
|
|
||||||
void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) {
|
void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) {
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
//Logger &logger= Logger::getInstance();
|
|
||||||
//CoreData &coreData= CoreData::getInstance();
|
|
||||||
//Renderer &renderer= Renderer::getInstance();
|
|
||||||
//Map *map= world.getMap();
|
|
||||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||||
NetworkRole role = networkManager.getNetworkRole();
|
NetworkRole role = networkManager.getNetworkRole();
|
||||||
ClientInterface *clientInterface = NULL;
|
ClientInterface *clientInterface = NULL;
|
||||||
|
@ -1442,6 +1438,14 @@ void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) {
|
||||||
(clientInterface != NULL &&
|
(clientInterface != NULL &&
|
||||||
(gameSettings.getMasterserver_admin() != clientInterface->getSessionKey() &&
|
(gameSettings.getMasterserver_admin() != clientInterface->getSessionKey() &&
|
||||||
clientInterface->isMasterServerAdminOverride() == true))) {
|
clientInterface->isMasterServerAdminOverride() == true))) {
|
||||||
|
exitGamePopupMenuIndex = -1;
|
||||||
|
joinTeamPopupMenuIndex = -1;
|
||||||
|
pauseGamePopupMenuIndex = -1;
|
||||||
|
saveGamePopupMenuIndex = -1;
|
||||||
|
loadGamePopupMenuIndex = -1;
|
||||||
|
keyboardSetupPopupMenuIndex = -1;
|
||||||
|
disconnectPlayerPopupMenuIndex = -1;
|
||||||
|
|
||||||
if(checkClientAdminOverrideOnly == true) {
|
if(checkClientAdminOverrideOnly == true) {
|
||||||
gameSettings.setMasterserver_admin(clientInterface->getSessionKey());
|
gameSettings.setMasterserver_admin(clientInterface->getSessionKey());
|
||||||
gameSettings.setMasterserver_admin_faction_index(clientInterface->getPlayerIndex());
|
gameSettings.setMasterserver_admin_faction_index(clientInterface->getPlayerIndex());
|
||||||
|
@ -1474,6 +1478,11 @@ void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) {
|
||||||
// loadGamePopupMenuIndex= menuItems.size() - 1;
|
// loadGamePopupMenuIndex= menuItems.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//printf("Checking disconnect menu: %d\n",gameSettings.isNetworkGame());
|
||||||
|
//for(int idx = 0; idx < GameConstants::maxPlayers; ++idx) {
|
||||||
|
// printf("Faction Index: %d, control: %d\n",idx,gameSettings.getFactionControl(idx));
|
||||||
|
//}
|
||||||
|
|
||||||
if(gameSettings.isNetworkGame() == true){
|
if(gameSettings.isNetworkGame() == true){
|
||||||
menuItems.push_back(lang.get("DisconnectNetorkPlayer"));
|
menuItems.push_back(lang.get("DisconnectNetorkPlayer"));
|
||||||
disconnectPlayerPopupMenuIndex= menuItems.size() - 1;
|
disconnectPlayerPopupMenuIndex= menuItems.size() - 1;
|
||||||
|
@ -1588,107 +1597,6 @@ void Game::update() {
|
||||||
perfList.push_back(perfBuf);
|
perfList.push_back(perfBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(role == nrServer) {
|
|
||||||
ServerInterface *server = NetworkManager::getInstance().getServerInterface();
|
|
||||||
if(server->getPauseForInGameConnection() == true && paused == false) {
|
|
||||||
|
|
||||||
//printf("================= Switching player pausing game\n");
|
|
||||||
|
|
||||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
|
||||||
Faction *faction = world.getFaction(i);
|
|
||||||
|
|
||||||
//printf("Switching player check %d from: %d connected: %d, startindex = %d, connected #2: %d\n",i,faction->getControlType(),server->isClientConnected(faction->getStartLocationIndex()),faction->getStartLocationIndex(),server->isClientConnected(i));
|
|
||||||
//printf("Slot: %d faction name: %s\n",i,faction->getType()->getName().c_str());
|
|
||||||
|
|
||||||
if( faction->getControlType() != ctNetwork &&
|
|
||||||
faction->getControlType() != ctHuman &&
|
|
||||||
server->isClientConnected(faction->getStartLocationIndex()) == true) {
|
|
||||||
|
|
||||||
//printf("Switching player %d from: %d to %d\n",i,faction->getControlType(),ctNetwork);
|
|
||||||
//printf("Slot: %d faction name: %s GS faction: %s\n",i,faction->getType()->getName().c_str(),server->gameSettings.getFactionTypeName(i).c_str());
|
|
||||||
|
|
||||||
server->gameSettings.setFactionControl(i,ctNetwork);
|
|
||||||
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
|
||||||
server->gameSettings.setNetworkPlayerName(i,slot->getName());
|
|
||||||
|
|
||||||
this->gameSettings.setFactionControl(i,ctNetwork);
|
|
||||||
this->gameSettings.setNetworkPlayerName(i,server->gameSettings.getNetworkPlayerName(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//printf("#1 Data synch: lmap %u ltile: %d ltech: %u\n",gameSettings.getMapCRC(),gameSettings.getTilesetCRC(),gameSettings.getTechCRC());
|
|
||||||
//printf("#2 Data synch: lmap %u ltile: %d ltech: %u\n",server->gameSettings.getMapCRC(),server->gameSettings.getTilesetCRC(),server->gameSettings.getTechCRC());
|
|
||||||
server->broadcastGameSetup(&server->gameSettings,true);
|
|
||||||
|
|
||||||
server->setPauseForInGameConnection(false);
|
|
||||||
}
|
|
||||||
else if(server->getStartInGameConnectionLaunch() == true) {
|
|
||||||
//printf("^^^ getStartInGameConnectionLaunch triggered!\n");
|
|
||||||
|
|
||||||
server->setStartInGameConnectionLaunch(false);
|
|
||||||
|
|
||||||
Lang &lang= Lang::getInstance();
|
|
||||||
bool pauseAndSaveGameForNewClient = false;
|
|
||||||
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) {
|
|
||||||
//printf("$$$ signalling client to start game [deleting AI player] factionIndex: %d slot: %d startlocation: %d!\n",i,slot->getPlayerIndex(),faction->getStartLocationIndex());
|
|
||||||
|
|
||||||
this->gameSettings.setFactionControl(i,ctNetwork);
|
|
||||||
this->gameSettings.setNetworkPlayerName(i,server->gameSettings.getNetworkPlayerName(i));
|
|
||||||
|
|
||||||
//printf("START Purging AI player for index: %d\n",i);
|
|
||||||
masterController.clearSlaves(true);
|
|
||||||
delete aiInterfaces[i];
|
|
||||||
aiInterfaces[i] = NULL;
|
|
||||||
//printf("END Purging AI player for index: %d\n",i);
|
|
||||||
|
|
||||||
Faction *faction = world.getFaction(i);
|
|
||||||
faction->setControlType(ctNetwork);
|
|
||||||
|
|
||||||
pauseAndSaveGameForNewClient = true;
|
|
||||||
}
|
|
||||||
else if((slot == NULL || slot->isConnected() == false) &&
|
|
||||||
this->gameSettings.getFactionControl(i) == ctNetwork &&
|
|
||||||
aiInterfaces[i] == NULL) {
|
|
||||||
faction->setFactionDisconnectHandled(false);
|
|
||||||
//this->gameSettings.setNetworkPlayerName(i,lang.get("AI") + intToStr(i+1));
|
|
||||||
//server->gameSettings.setNetworkPlayerName(i,lang.get("AI") + intToStr(i+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pauseAndSaveGameForNewClient == true) {
|
|
||||||
commander.tryPauseGame();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(server->getUnPauseForInGameConnection() == true && paused == true) {
|
|
||||||
//printf("^^^ getUnPauseForInGameConnection triggered!\n");
|
|
||||||
|
|
||||||
server->setUnPauseForInGameConnection(false);
|
|
||||||
commander.tryResumeGame();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// handle setting changes from clients
|
|
||||||
Map *map= world.getMap();
|
|
||||||
//printf("switchSetupRequests != NULL\n");
|
|
||||||
|
|
||||||
bool switchRequested = switchSetupForSlots(server, 0, map->getMaxPlayers(), false);
|
|
||||||
switchRequested = switchRequested || switchSetupForSlots(server, map->getMaxPlayers(), GameConstants::maxPlayers, true);
|
|
||||||
|
|
||||||
if(switchRequested == true) {
|
|
||||||
//printf("Send new game setup from switch: %d\n",switchRequested);
|
|
||||||
|
|
||||||
//for(int i= 0; i < gameSettings.getFactionCount(); ++i) {
|
|
||||||
//printf("#1 Faction Index: %d control: %d startlocation: %d\n",i,gameSettings.getFactionControl(i),gameSettings.getStartLocationIndex(i));
|
|
||||||
|
|
||||||
//printf("#2 Faction Index: %d control: %d startlocation: %d\n",i,server->gameSettings.getFactionControl(i),server->gameSettings.getStartLocationIndex(i));
|
|
||||||
//}
|
|
||||||
|
|
||||||
server->broadcastGameSetup(&server->gameSettings,true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check to see if we are playing a network game and if any players
|
// Check to see if we are playing a network game and if any players
|
||||||
// have disconnected?
|
// have disconnected?
|
||||||
ReplaceDisconnectedNetworkPlayersWithAI(isNetworkGame, role);
|
ReplaceDisconnectedNetworkPlayersWithAI(isNetworkGame, role);
|
||||||
|
@ -1712,6 +1620,7 @@ void Game::update() {
|
||||||
if(replayTotal > 0) {
|
if(replayTotal > 0) {
|
||||||
chronoReplay.start();
|
chronoReplay.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if(replayTotal > 0) {
|
if(replayTotal > 0) {
|
||||||
replayCommandsPlayed = (replayTotal - commander.getReplayCommandListForFrameCount());
|
replayCommandsPlayed = (replayTotal - commander.getReplayCommandListForFrameCount());
|
||||||
|
@ -2006,6 +1915,111 @@ void Game::update() {
|
||||||
perfList.push_back(perfBuf);
|
perfList.push_back(perfBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// START - Handle joining in progress games
|
||||||
|
if(role == nrServer) {
|
||||||
|
ServerInterface *server = NetworkManager::getInstance().getServerInterface();
|
||||||
|
if(server->getPauseForInGameConnection() == true && paused == false) {
|
||||||
|
|
||||||
|
//printf("================= Switching player pausing game\n");
|
||||||
|
|
||||||
|
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||||
|
Faction *faction = world.getFaction(i);
|
||||||
|
|
||||||
|
//printf("Switching player check %d from: %d connected: %d, startindex = %d, connected #2: %d\n",i,faction->getControlType(),server->isClientConnected(faction->getStartLocationIndex()),faction->getStartLocationIndex(),server->isClientConnected(i));
|
||||||
|
//printf("Slot: %d faction name: %s\n",i,faction->getType()->getName().c_str());
|
||||||
|
|
||||||
|
if( faction->getControlType() != ctNetwork &&
|
||||||
|
faction->getControlType() != ctHuman &&
|
||||||
|
server->isClientConnected(faction->getStartLocationIndex()) == true) {
|
||||||
|
|
||||||
|
//printf("Switching player %d from: %d to %d\n",i,faction->getControlType(),ctNetwork);
|
||||||
|
//printf("Slot: %d faction name: %s GS faction: %s\n",i,faction->getType()->getName().c_str(),server->gameSettings.getFactionTypeName(i).c_str());
|
||||||
|
|
||||||
|
server->gameSettings.setFactionControl(i,ctNetwork);
|
||||||
|
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||||
|
server->gameSettings.setNetworkPlayerName(i,slot->getName());
|
||||||
|
|
||||||
|
this->gameSettings.setFactionControl(i,ctNetwork);
|
||||||
|
this->gameSettings.setNetworkPlayerName(i,server->gameSettings.getNetworkPlayerName(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//printf("#1 Data synch: lmap %u ltile: %d ltech: %u\n",gameSettings.getMapCRC(),gameSettings.getTilesetCRC(),gameSettings.getTechCRC());
|
||||||
|
//printf("#2 Data synch: lmap %u ltile: %d ltech: %u\n",server->gameSettings.getMapCRC(),server->gameSettings.getTilesetCRC(),server->gameSettings.getTechCRC());
|
||||||
|
server->broadcastGameSetup(&server->gameSettings,true);
|
||||||
|
|
||||||
|
server->setPauseForInGameConnection(false);
|
||||||
|
}
|
||||||
|
else if(server->getStartInGameConnectionLaunch() == true) {
|
||||||
|
//printf("^^^ getStartInGameConnectionLaunch triggered!\n");
|
||||||
|
|
||||||
|
server->setStartInGameConnectionLaunch(false);
|
||||||
|
|
||||||
|
Lang &lang= Lang::getInstance();
|
||||||
|
bool pauseAndSaveGameForNewClient = false;
|
||||||
|
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) {
|
||||||
|
//printf("$$$ signalling client to start game [deleting AI player] factionIndex: %d slot: %d startlocation: %d!\n",i,slot->getPlayerIndex(),faction->getStartLocationIndex());
|
||||||
|
|
||||||
|
this->gameSettings.setFactionControl(i,ctNetwork);
|
||||||
|
this->gameSettings.setNetworkPlayerName(i,server->gameSettings.getNetworkPlayerName(i));
|
||||||
|
|
||||||
|
//printf("START Purging AI player for index: %d\n",i);
|
||||||
|
masterController.clearSlaves(true);
|
||||||
|
delete aiInterfaces[i];
|
||||||
|
aiInterfaces[i] = NULL;
|
||||||
|
//printf("END Purging AI player for index: %d\n",i);
|
||||||
|
|
||||||
|
Faction *faction = world.getFaction(i);
|
||||||
|
faction->setControlType(ctNetwork);
|
||||||
|
|
||||||
|
pauseAndSaveGameForNewClient = true;
|
||||||
|
}
|
||||||
|
else if((slot == NULL || slot->isConnected() == false) &&
|
||||||
|
this->gameSettings.getFactionControl(i) == ctNetwork &&
|
||||||
|
aiInterfaces[i] == NULL) {
|
||||||
|
faction->setFactionDisconnectHandled(false);
|
||||||
|
//this->gameSettings.setNetworkPlayerName(i,lang.get("AI") + intToStr(i+1));
|
||||||
|
//server->gameSettings.setNetworkPlayerName(i,lang.get("AI") + intToStr(i+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pauseAndSaveGameForNewClient == true) {
|
||||||
|
commander.tryPauseGame(true);
|
||||||
|
//return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(server->getUnPauseForInGameConnection() == true && paused == true) {
|
||||||
|
//printf("^^^ getUnPauseForInGameConnection triggered!\n");
|
||||||
|
|
||||||
|
server->setUnPauseForInGameConnection(false);
|
||||||
|
commander.tryResumeGame(false);
|
||||||
|
//return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// handle setting changes from clients
|
||||||
|
Map *map= world.getMap();
|
||||||
|
//printf("switchSetupRequests != NULL\n");
|
||||||
|
|
||||||
|
bool switchRequested = switchSetupForSlots(server, 0, map->getMaxPlayers(), false);
|
||||||
|
switchRequested = switchRequested || switchSetupForSlots(server, map->getMaxPlayers(), GameConstants::maxPlayers, true);
|
||||||
|
|
||||||
|
if(switchRequested == true) {
|
||||||
|
//printf("Send new game setup from switch: %d\n",switchRequested);
|
||||||
|
|
||||||
|
//for(int i= 0; i < gameSettings.getFactionCount(); ++i) {
|
||||||
|
//printf("#1 Faction Index: %d control: %d startlocation: %d\n",i,gameSettings.getFactionControl(i),gameSettings.getStartLocationIndex(i));
|
||||||
|
|
||||||
|
//printf("#2 Faction Index: %d control: %d startlocation: %d\n",i,server->gameSettings.getFactionControl(i),server->gameSettings.getStartLocationIndex(i));
|
||||||
|
//}
|
||||||
|
|
||||||
|
server->broadcastGameSetup(&server->gameSettings,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// END - Handle joining in progress games
|
||||||
|
|
||||||
//update auto test
|
//update auto test
|
||||||
if(Config::getInstance().getBool("AutoTest")){
|
if(Config::getInstance().getBool("AutoTest")){
|
||||||
AutoTest::getInstance().updateGame(this);
|
AutoTest::getInstance().updateGame(this);
|
||||||
|
@ -2869,14 +2883,14 @@ void Game::tryPauseToggle(bool pauseValue) {
|
||||||
|
|
||||||
if(allowAdminMenuItems) {
|
if(allowAdminMenuItems) {
|
||||||
if(pauseValue == true) {
|
if(pauseValue == true) {
|
||||||
commander.tryPauseGame();
|
commander.tryPauseGame(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(isNetworkGame == false) {
|
if(isNetworkGame == false) {
|
||||||
setPaused(pauseValue, true);
|
setPaused(pauseValue, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
commander.tryResumeGame();
|
commander.tryResumeGame(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3049,6 +3063,8 @@ void Game::mouseDownLeft(int x, int y) {
|
||||||
std::pair<int,string> result = popupMenu.mouseClickedMenuItem(x, y);
|
std::pair<int,string> result = popupMenu.mouseClickedMenuItem(x, y);
|
||||||
//printf("In popup callback menuItemSelected [%s] menuIndexSelected = %d\n",result.second.c_str(),result.first);
|
//printf("In popup callback menuItemSelected [%s] menuIndexSelected = %d\n",result.second.c_str(),result.first);
|
||||||
|
|
||||||
|
//printf("popupMenu.mouseClick == true result.first = %d disconnectPlayerPopupMenuIndex = %d\n",result.first,disconnectPlayerPopupMenuIndex);
|
||||||
|
|
||||||
popupMenu.setEnabled(false);
|
popupMenu.setEnabled(false);
|
||||||
popupMenu.setVisible(false);
|
popupMenu.setVisible(false);
|
||||||
|
|
||||||
|
@ -3168,10 +3184,10 @@ void Game::mouseDownLeft(int x, int y) {
|
||||||
|
|
||||||
if(allowAdminMenuItems) {
|
if(allowAdminMenuItems) {
|
||||||
if(getPaused() == false) {
|
if(getPaused() == false) {
|
||||||
commander.tryPauseGame();
|
commander.tryPauseGame(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
commander.tryResumeGame();
|
commander.tryResumeGame(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4078,10 +4094,10 @@ void Game::keyDown(SDL_KeyboardEvent key) {
|
||||||
|
|
||||||
if(allowAdminMenuItems) {
|
if(allowAdminMenuItems) {
|
||||||
if(getPaused() == false) {
|
if(getPaused() == false) {
|
||||||
commander.tryPauseGame();
|
commander.tryPauseGame(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
commander.tryResumeGame();
|
commander.tryResumeGame(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5166,7 +5182,7 @@ void Game::decSpeed() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::setPaused(bool value,bool forceAllowPauseStateChange) {
|
void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches) {
|
||||||
bool speedChangesAllowed= !NetworkManager::getInstance().isNetworkGame();
|
bool speedChangesAllowed= !NetworkManager::getInstance().isNetworkGame();
|
||||||
//printf("Toggle pause value = %d, speedChangesAllowed = %d, forceAllowPauseStateChange = %d\n",value,speedChangesAllowed,forceAllowPauseStateChange);
|
//printf("Toggle pause value = %d, speedChangesAllowed = %d, forceAllowPauseStateChange = %d\n",value,speedChangesAllowed,forceAllowPauseStateChange);
|
||||||
|
|
||||||
|
@ -5177,6 +5193,15 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange) {
|
||||||
if(value == false) {
|
if(value == false) {
|
||||||
console.addLine(lang.get("GameResumed"));
|
console.addLine(lang.get("GameResumed"));
|
||||||
paused= false;
|
paused= false;
|
||||||
|
|
||||||
|
if(clearCaches == true) {
|
||||||
|
world.clearCaches();
|
||||||
|
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||||
|
Faction *faction = world.getFaction(i);
|
||||||
|
faction->clearCaches();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setupPopupMenus(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.addLine(lang.get("GamePaused"));
|
console.addLine(lang.get("GamePaused"));
|
||||||
|
|
|
@ -239,7 +239,7 @@ public:
|
||||||
|
|
||||||
Uint64 getTickCount() {return tickCount;}
|
Uint64 getTickCount() {return tickCount;}
|
||||||
bool getPaused();
|
bool getPaused();
|
||||||
void setPaused(bool value, bool forceAllowPauseStateChange=false);
|
void setPaused(bool value, bool forceAllowPauseStateChange=false,bool clearCaches=false);
|
||||||
void tryPauseToggle(bool pause);
|
void tryPauseToggle(bool pause);
|
||||||
void setupRenderForVideo();
|
void setupRenderForVideo();
|
||||||
void saveGame();
|
void saveGame();
|
||||||
|
|
|
@ -634,13 +634,14 @@ void ClientInterface::updateLobby() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nmtReady:
|
case nmtReady:
|
||||||
{
|
{
|
||||||
NetworkMessageReady networkMessageReady;
|
NetworkMessageReady networkMessageReady;
|
||||||
if(receiveMessage(&networkMessageReady)) {
|
if(receiveMessage(&networkMessageReady)) {
|
||||||
this->readyForInGameJoin = true;
|
this->readyForInGameJoin = true;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
break;
|
||||||
|
|
||||||
case nmtCommandList:
|
case nmtCommandList:
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1332,17 +1333,19 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
joinGameInProgress = false;
|
||||||
|
|
||||||
//printf("Client signalServerWhenReadyToStartJoinedGame = %d\n",signalServerWhenReadyToStartJoinedGame);
|
//printf("Client signalServerWhenReadyToStartJoinedGame = %d\n",signalServerWhenReadyToStartJoinedGame);
|
||||||
if(signalServerWhenReadyToStartJoinedGame == true) {
|
if(signalServerWhenReadyToStartJoinedGame == true) {
|
||||||
NetworkMessageReady networkMessageReady;
|
NetworkMessageReady networkMessageReady;
|
||||||
sendMessage(&networkMessageReady);
|
sendMessage(&networkMessageReady);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
joinGameInProgress = false;
|
// delay the start a bit, so clients have more room to get messages
|
||||||
// delay the start a bit, so clients have more room to get messages
|
// This is to ensure clients don't start ahead of the server and thus
|
||||||
// This is to ensure clients don't start ahead of the server and thus
|
// constantly freeze because they are waiting for the server to catch up
|
||||||
// constantly freeze because they are waiting for the server to catch up
|
sleep(120);
|
||||||
sleep(120);
|
}
|
||||||
|
|
||||||
// This triggers LAG update packets to begin as required
|
// This triggers LAG update packets to begin as required
|
||||||
lastNetworkCommandListSendTime = time(NULL);
|
lastNetworkCommandListSendTime = time(NULL);
|
||||||
|
|
|
@ -1842,6 +1842,20 @@ bool Faction::canCreateUnit(const UnitType *ut, bool checkBuild, bool checkProdu
|
||||||
return foundUnit;
|
return foundUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Faction::clearCaches() {
|
||||||
|
cacheResourceTargetList.clear();
|
||||||
|
cachedCloseResourceTargetLookupList.clear();
|
||||||
|
mapSharedPathFinderCache.clear();
|
||||||
|
|
||||||
|
unsigned int unitCount = this->getUnitCount();
|
||||||
|
for(unsigned int i = 0; i < unitCount; ++i) {
|
||||||
|
Unit *unit = this->getUnit(i);
|
||||||
|
if(unit != NULL) {
|
||||||
|
unit->clearCaches();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint64 Faction::getCacheKBytes(uint64 *cache1Size, uint64 *cache2Size) {
|
uint64 Faction::getCacheKBytes(uint64 *cache1Size, uint64 *cache2Size) {
|
||||||
uint64 cache1Count = 0;
|
uint64 cache1Count = 0;
|
||||||
uint64 cache2Count = 0;
|
uint64 cache2Count = 0;
|
||||||
|
|
|
@ -344,6 +344,8 @@ public:
|
||||||
void saveGame(XmlNode *rootNode);
|
void saveGame(XmlNode *rootNode);
|
||||||
void loadGame(const XmlNode *rootNode, int factionIndex,GameSettings *settings,World *world);
|
void loadGame(const XmlNode *rootNode, int factionIndex,GameSettings *settings,World *world);
|
||||||
|
|
||||||
|
void clearCaches();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
void resetResourceAmount(const ResourceType *rt);
|
void resetResourceAmount(const ResourceType *rt);
|
||||||
|
|
|
@ -84,6 +84,12 @@ void UnitPathBasic::dumpMemoryList() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void UnitPathBasic::clearCaches() {
|
||||||
|
this->blockCount = 0;
|
||||||
|
this->pathQueue.clear();
|
||||||
|
this->lastPathCacheQueue.clear();
|
||||||
|
}
|
||||||
|
|
||||||
bool UnitPathBasic::isEmpty() const {
|
bool UnitPathBasic::isEmpty() const {
|
||||||
return pathQueue.empty();
|
return pathQueue.empty();
|
||||||
}
|
}
|
||||||
|
@ -178,6 +184,30 @@ void UnitPathBasic::saveGame(XmlNode *rootNode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnitPathBasic::loadGame(const XmlNode *rootNode) {
|
||||||
|
const XmlNode *unitPathBasicNode = rootNode->getChild("UnitPathBasic");
|
||||||
|
|
||||||
|
blockCount = unitPathBasicNode->getAttribute("blockCount")->getIntValue();
|
||||||
|
|
||||||
|
pathQueue.clear();
|
||||||
|
vector<XmlNode *> pathqueueNodeList = unitPathBasicNode->getChildList("pathQueue");
|
||||||
|
for(unsigned int i = 0; i < pathqueueNodeList.size(); ++i) {
|
||||||
|
XmlNode *node = pathqueueNodeList[i];
|
||||||
|
|
||||||
|
Vec2i vec = Vec2i::strToVec2(node->getAttribute("vec")->getValue());
|
||||||
|
pathQueue.push_back(vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
lastPathCacheQueue.clear();
|
||||||
|
vector<XmlNode *> lastpathqueueNodeList = unitPathBasicNode->getChildList("lastPathCacheQueue");
|
||||||
|
for(unsigned int i = 0; i < lastpathqueueNodeList.size(); ++i) {
|
||||||
|
XmlNode *node = lastpathqueueNodeList[i];
|
||||||
|
|
||||||
|
Vec2i vec = Vec2i::strToVec2(node->getAttribute("vec")->getValue());
|
||||||
|
lastPathCacheQueue.push_back(vec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class UnitPath
|
// class UnitPath
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@ -1508,13 +1538,6 @@ std::pair<CommandResult,string> Unit::giveCommand(Command *command, bool tryQueu
|
||||||
//empty command queue
|
//empty command queue
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Clear commands because current is NOT queable.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Clear commands because current is NOT queable.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
// bool willChangedActiveCommand = (commands.size() > 0);
|
|
||||||
// if(willChangedActiveCommand && getCurrCommand()->getCommandType()->getClass() == command->getCommandType()->getClass()) {
|
|
||||||
// willChangedActiveCommand = false;
|
|
||||||
// }
|
|
||||||
// clearCommands();
|
|
||||||
// changedActiveCommand = willChangedActiveCommand;
|
|
||||||
|
|
||||||
bool willChangedActiveCommand= (commands.empty() == false);
|
bool willChangedActiveCommand= (commands.empty() == false);
|
||||||
if(willChangedActiveCommand){
|
if(willChangedActiveCommand){
|
||||||
CommandClass currCommandClass=getCurrCommand()->getCommandType()->getClass();
|
CommandClass currCommandClass=getCurrCommand()->getCommandType()->getClass();
|
||||||
|
@ -3677,6 +3700,16 @@ Vec2i Unit::getPos() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Unit::clearCaches() {
|
||||||
|
cachedFow.alphaList.clear();
|
||||||
|
cachedFow.surfPosList.clear();
|
||||||
|
cachedFowPos = Vec2i(0,0);
|
||||||
|
|
||||||
|
//unitPath->clearCaches();
|
||||||
|
|
||||||
|
lastHarvestedResourcePos = Vec2i(0,0);
|
||||||
|
}
|
||||||
|
|
||||||
std::string Unit::toString() const {
|
std::string Unit::toString() const {
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
|
|
||||||
|
@ -4091,6 +4124,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
|
||||||
throw megaglest_runtime_error("detected unsupported pathfinder type!");
|
throw megaglest_runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newpath->loadGame(unitNode);
|
||||||
//Unit *result = new Unit(getNextUnitId(f), newpath, Vec2i(0), ut, f, &map, CardinalDir::NORTH);
|
//Unit *result = new Unit(getNextUnitId(f), newpath, Vec2i(0), ut, f, &map, CardinalDir::NORTH);
|
||||||
//Unit(int id, UnitPathInterface *path, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
|
//Unit(int id, UnitPathInterface *path, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
|
||||||
Unit *result = new Unit(newUnitId, newpath, newUnitPos, ut, faction, world->getMapPtr(), newModelFacing);
|
Unit *result = new Unit(newUnitId, newpath, newUnitPos, ut, faction, world->getMapPtr(), newModelFacing);
|
||||||
|
|
|
@ -161,6 +161,9 @@ public:
|
||||||
virtual Map * getMap() = 0;
|
virtual Map * getMap() = 0;
|
||||||
|
|
||||||
virtual void saveGame(XmlNode *rootNode) = 0;
|
virtual void saveGame(XmlNode *rootNode) = 0;
|
||||||
|
virtual void loadGame(const XmlNode *rootNode) = 0;
|
||||||
|
|
||||||
|
virtual void clearCaches() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UnitPathBasic : public UnitPathInterface {
|
class UnitPathBasic : public UnitPathInterface {
|
||||||
|
@ -209,6 +212,8 @@ public:
|
||||||
virtual std::string toString() const;
|
virtual std::string toString() const;
|
||||||
|
|
||||||
virtual void saveGame(XmlNode *rootNode);
|
virtual void saveGame(XmlNode *rootNode);
|
||||||
|
virtual void loadGame(const XmlNode *rootNode);
|
||||||
|
virtual void clearCaches();
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@ -227,6 +232,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UnitPath() : UnitPathInterface(), blockCount(0), map(NULL) {} /**< Construct path object */
|
UnitPath() : UnitPathInterface(), blockCount(0), map(NULL) {} /**< Construct path object */
|
||||||
|
|
||||||
virtual bool isBlocked() const {return blockCount >= maxBlockCount;} /**< is this path blocked */
|
virtual bool isBlocked() const {return blockCount >= maxBlockCount;} /**< is this path blocked */
|
||||||
virtual bool isEmpty() const {return list<Vec2i>::empty();} /**< is path empty */
|
virtual bool isEmpty() const {return list<Vec2i>::empty();} /**< is path empty */
|
||||||
virtual bool isStuck() const {return false; }
|
virtual bool isStuck() const {return false; }
|
||||||
|
@ -267,6 +273,8 @@ public:
|
||||||
virtual std::string toString() const;
|
virtual std::string toString() const;
|
||||||
|
|
||||||
virtual void saveGame(XmlNode *rootNode) {};
|
virtual void saveGame(XmlNode *rootNode) {};
|
||||||
|
virtual void loadGame(const XmlNode *rootNode) {};
|
||||||
|
virtual void clearCaches() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
class WaypointPath : public list<Vec2i> {
|
class WaypointPath : public list<Vec2i> {
|
||||||
|
@ -739,6 +747,8 @@ public:
|
||||||
void saveGame(XmlNode *rootNode);
|
void saveGame(XmlNode *rootNode);
|
||||||
static Unit * loadGame(const XmlNode *rootNode,GameSettings *settings,Faction *faction, World *world);
|
static Unit * loadGame(const XmlNode *rootNode,GameSettings *settings,Faction *faction, World *world);
|
||||||
|
|
||||||
|
void clearCaches();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float computeHeight(const Vec2i &pos) const;
|
float computeHeight(const Vec2i &pos) const;
|
||||||
void calculateXZRotation();
|
void calculateXZRotation();
|
||||||
|
|
|
@ -1424,6 +1424,12 @@ void World::moveToUnit(int unitId, int destUnitId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::clearCaches() {
|
||||||
|
ExploredCellsLookupItemCache.clear();
|
||||||
|
ExploredCellsLookupItemCacheTimer.clear();
|
||||||
|
ExploredCellsLookupItemCacheTimerCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void World::togglePauseGame(bool pauseStatus,bool forceAllowPauseStateChange) {
|
void World::togglePauseGame(bool pauseStatus,bool forceAllowPauseStateChange) {
|
||||||
game->setPaused(pauseStatus, forceAllowPauseStateChange);
|
game->setPaused(pauseStatus, forceAllowPauseStateChange);
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,6 +318,8 @@ public:
|
||||||
void saveGame(XmlNode *rootNode);
|
void saveGame(XmlNode *rootNode);
|
||||||
void loadGame(const XmlNode *rootNode);
|
void loadGame(const XmlNode *rootNode);
|
||||||
|
|
||||||
|
void clearCaches();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void initCells(bool fogOfWar);
|
void initCells(bool fogOfWar);
|
||||||
|
|
Loading…
Reference in New Issue