mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 12:12:25 +01:00
- Added better error handling for in-game errors
This commit is contained in:
parent
7753435b3a
commit
8b6af02ece
@ -32,6 +32,8 @@ using namespace Shared::Platform;
|
||||
|
||||
namespace Glest{ namespace Game{
|
||||
|
||||
Game *thisGamePtr = NULL;
|
||||
|
||||
// =====================================================
|
||||
// class Game
|
||||
// =====================================================
|
||||
@ -41,6 +43,9 @@ namespace Glest{ namespace Game{
|
||||
Game::Game(Program *program, const GameSettings *gameSettings):
|
||||
ProgramState(program), lastMousePos(0)
|
||||
{
|
||||
originalDisplayMsgCallback = NULL;
|
||||
thisGamePtr = this;
|
||||
|
||||
this->gameSettings= *gameSettings;
|
||||
scrollSpeed = Config::getInstance().getFloat("UiScrollSpeed","1.5");
|
||||
|
||||
@ -80,12 +85,30 @@ Game::~Game(){
|
||||
|
||||
gui.end(); //selection must be cleared before deleting units
|
||||
world.end(); //must die before selection because of referencers
|
||||
|
||||
thisGamePtr = NULL;
|
||||
if(originalDisplayMsgCallback != NULL) {
|
||||
NetworkInterface::setDisplayMessageFunction(originalDisplayMsgCallback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ==================== init and load ====================
|
||||
|
||||
int Game::ErrorDisplayMessage(const char *msg, bool exitApp) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,msg);
|
||||
|
||||
if(thisGamePtr != NULL) {
|
||||
string text = msg;
|
||||
thisGamePtr->showMessageBox(text, "Error detected", false);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Game::load(){
|
||||
originalDisplayMsgCallback = NetworkInterface::getDisplayMessageFunction();
|
||||
NetworkInterface::setDisplayMessageFunction(ErrorDisplayMessage);
|
||||
|
||||
Logger &logger= Logger::getInstance();
|
||||
string mapName= gameSettings.getMap();
|
||||
@ -410,7 +433,8 @@ void Game::update(){
|
||||
chatManager.updateNetwork();
|
||||
|
||||
//check for quiting status
|
||||
if(NetworkManager::getInstance().getGameNetworkInterface()->getQuit()){
|
||||
if(NetworkManager::getInstance().getGameNetworkInterface()->getQuit() && mainMessageBox.getEnabled() == false) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
quitGame();
|
||||
}
|
||||
|
||||
@ -419,6 +443,8 @@ void Game::update(){
|
||||
AutoTest::getInstance().updateGame(this);
|
||||
}
|
||||
|
||||
//throw runtime_error("Test!");
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
@ -539,15 +565,14 @@ void Game::mouseDownLeft(int x, int y){
|
||||
//exit message box, has to be the last thing to do in this function
|
||||
if(mainMessageBox.getEnabled()){
|
||||
int button= 1;
|
||||
if(mainMessageBox.mouseClick(x, y, button))
|
||||
{
|
||||
if(button==1)
|
||||
{
|
||||
if(mainMessageBox.mouseClick(x, y, button)) {
|
||||
if(button==1) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
networkManager.getGameNetworkInterface()->quitGame(true);
|
||||
quitGame();
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//close message box
|
||||
mainMessageBox.setEnabled(false);
|
||||
}
|
||||
@ -849,6 +874,7 @@ void Game::keyPress(char c){
|
||||
}
|
||||
|
||||
void Game::quitGame(){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
program->setState(new BattleEnd(program, world.getStats()));
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "script_manager.h"
|
||||
#include "game_settings.h"
|
||||
#include "simple_threads.h"
|
||||
#include "network_interface.h"
|
||||
|
||||
using std::vector;
|
||||
using namespace Shared::PlatformCommon;
|
||||
@ -81,6 +82,7 @@ private:
|
||||
GameSettings gameSettings;
|
||||
Vec2i lastMousePos;
|
||||
time_t lastRenderLog2d;
|
||||
DisplayMessageFunction originalDisplayMsgCallback;
|
||||
|
||||
public:
|
||||
Game(Program *program, const GameSettings *gameSettings);
|
||||
@ -140,6 +142,7 @@ private:
|
||||
void showWinMessageBox();
|
||||
void showMessageBox(const string &text, const string &header, bool toggle);
|
||||
void renderWorker();
|
||||
static int ErrorDisplayMessage(const char *msg, bool exitApp);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
@ -671,6 +671,15 @@ string ClientInterface::getNetworkStatus() const{
|
||||
|
||||
void ClientInterface::waitForMessage()
|
||||
{
|
||||
// Debug!
|
||||
/*
|
||||
sendTextMessage("Timeout waiting for message",-1);
|
||||
DisplayErrorMessage("Timeout waiting for message");
|
||||
quit= true;
|
||||
close();
|
||||
return;
|
||||
*/
|
||||
|
||||
Chrono chrono;
|
||||
chrono.start();
|
||||
|
||||
@ -686,6 +695,7 @@ void ClientInterface::waitForMessage()
|
||||
}
|
||||
|
||||
if(chrono.getMillis() > messageWaitTimeout) {
|
||||
//if(1) {
|
||||
//throw runtime_error("Timeout waiting for message");
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
@ -69,6 +69,8 @@ public:
|
||||
virtual void close()= 0;
|
||||
|
||||
static void setDisplayMessageFunction(DisplayMessageFunction pDisplayMessage) { pCB_DisplayMessage = pDisplayMessage; }
|
||||
static DisplayMessageFunction getDisplayMessageFunction() { return pCB_DisplayMessage; }
|
||||
|
||||
string getIp() const {return getSocket()->getIp();}
|
||||
string getHostName() const {return getSocket()->getHostName();}
|
||||
|
||||
|
@ -691,28 +691,33 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int
|
||||
//serverSynchAccessor.p();
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
try {
|
||||
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
|
||||
if(i != excludeSlot && connectionSlot != NULL) {
|
||||
if(connectionSlot->isConnected()) {
|
||||
if(i != excludeSlot && connectionSlot != NULL) {
|
||||
if(connectionSlot->isConnected()) {
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] before sendMessage\n",__FILE__,__FUNCTION__);
|
||||
connectionSlot->sendMessage(networkMessage);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] before sendMessage\n",__FILE__,__FUNCTION__);
|
||||
connectionSlot->sendMessage(networkMessage);
|
||||
}
|
||||
else if(gameHasBeenInitiated == true) {
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #1 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,i);
|
||||
removeSlot(i);
|
||||
}
|
||||
}
|
||||
else if(gameHasBeenInitiated == true) {
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #1 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,i);
|
||||
else if(i == excludeSlot && gameHasBeenInitiated == true &&
|
||||
connectionSlot != NULL && connectionSlot->isConnected() == false) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,i);
|
||||
removeSlot(i);
|
||||
}
|
||||
}
|
||||
else if(i == excludeSlot && gameHasBeenInitiated == true &&
|
||||
connectionSlot != NULL && connectionSlot->isConnected() == false) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,i);
|
||||
removeSlot(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
throw runtime_error(ex.what());
|
||||
}
|
||||
//serverSynchAccessor.v();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
Loading…
x
Reference in New Issue
Block a user