more user friendly error handling, try to display most errors in a nice messagebox in-game

This commit is contained in:
Mark Vejvoda 2010-05-29 07:58:58 +00:00
parent 3fdc1d2a18
commit b31531db1f
2 changed files with 416 additions and 342 deletions

View File

@ -398,11 +398,14 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const{
const UnitType* unitType= world->findUnitTypeById(unit->getFaction()->getType(), networkCommand->getUnitTypeId());
ct= unit->getType()->findCommandTypeById(networkCommand->getCommandTypeId());
// debug test!
//throw runtime_error("Test missing command type!");
//validate command type
if(ct == NULL) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s Line: %d] Can not find command type for\nnetwork command = [%s]\n%s\n in unit = %d [%s][%s].\nGame out of synch.",
__FILE__,__FUNCTION__,__LINE__,networkCommand->toString().c_str(),unit->getType()->getCommandTypeListDesc().c_str(),unit->getId(), unit->getFullName().c_str(),unit->getDesc().c_str());
sprintf(szBuf,"In [%s::%s Line: %d]\nCan not find command type for network command = [%s]\n%s\nfor unit = %d\n[%s]\n[%s]\nactual local factionIndex = %d.\nGame out of synch.",
__FILE__,__FUNCTION__,__LINE__,networkCommand->toString().c_str(),unit->getType()->getCommandTypeListDesc().c_str(),unit->getId(), unit->getFullName().c_str(),unit->getDesc().c_str(),unit->getFaction()->getIndex());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",szBuf);

View File

@ -376,6 +376,8 @@ void Game::simpleTask() {
void Game::update(){
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
try {
// a) Updates non dependent on speed
//misc
@ -447,6 +449,13 @@ void Game::update(){
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
NetworkManager &networkManager= NetworkManager::getInstance();
networkManager.getGameNetworkInterface()->quitGame(true);
ErrorDisplayMessage(ex.what(),true);
}
}
void Game::updateCamera(){
gameCamera.update();
@ -514,6 +523,7 @@ void Game::tick(){
void Game::mouseDownLeft(int x, int y){
try {
Map *map= world.getMap();
const Metrics &metrics= Metrics::getInstance();
NetworkManager &networkManager= NetworkManager::getInstance();
@ -579,16 +589,40 @@ void Game::mouseDownLeft(int x, int y){
}
}
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
NetworkManager &networkManager= NetworkManager::getInstance();
networkManager.getGameNetworkInterface()->quitGame(true);
ErrorDisplayMessage(ex.what(),true);
}
}
void Game::mouseDownRight(int x, int y){
try {
gui.mouseDownRightGraphics(x, y);
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
NetworkManager &networkManager= NetworkManager::getInstance();
networkManager.getGameNetworkInterface()->quitGame(true);
ErrorDisplayMessage(ex.what(),true);
}
}
void Game::mouseUpLeft(int x, int y){
try {
gui.mouseUpLeftGraphics(x, y);
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
NetworkManager &networkManager= NetworkManager::getInstance();
networkManager.getGameNetworkInterface()->quitGame(true);
ErrorDisplayMessage(ex.what(),true);
}
}
void Game::mouseDoubleClickLeft(int x, int y){
try {
const Metrics &metrics= Metrics::getInstance();
//display panel
@ -603,8 +637,16 @@ void Game::mouseDoubleClickLeft(int x, int y){
//graphics panel
gui.mouseDoubleClickLeftGraphics(x, y);
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
NetworkManager &networkManager= NetworkManager::getInstance();
networkManager.getGameNetworkInterface()->quitGame(true);
ErrorDisplayMessage(ex.what(),true);
}
}
void Game::mouseMove(int x, int y, const MouseState *ms){
try {
const Metrics &metrics = Metrics::getInstance();
mouseX = x;
@ -683,16 +725,31 @@ void Game::mouseMove(int x, int y, const MouseState *ms){
lastMousePos.x = mouseX;
lastMousePos.y = mouseY;
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
NetworkManager &networkManager= NetworkManager::getInstance();
networkManager.getGameNetworkInterface()->quitGame(true);
ErrorDisplayMessage(ex.what(),true);
}
}
void Game::eventMouseWheel(int x, int y, int zDelta) {
try {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//gameCamera.transitionXYZ(0.0f, -(float)zDelta / 30.0f, 0.0f);
gameCamera.zoom((float)zDelta / 60.0f);
//gameCamera.setMoveY(1);
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
NetworkManager &networkManager= NetworkManager::getInstance();
networkManager.getGameNetworkInterface()->quitGame(true);
ErrorDisplayMessage(ex.what(),true);
}
}
void Game::keyDown(char key){
try {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = %d\n",__FILE__,__FUNCTION__,__LINE__,key);
Lang &lang= Lang::getInstance();
@ -831,9 +888,16 @@ void Game::keyDown(char key){
}
}
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
NetworkManager &networkManager= NetworkManager::getInstance();
networkManager.getGameNetworkInterface()->quitGame(true);
ErrorDisplayMessage(ex.what(),true);
}
}
void Game::keyUp(char key){
try {
if(chatManager.getEditEnabled()){
//send key to the chat manager
chatManager.keyUp(key);
@ -868,6 +932,13 @@ void Game::keyUp(char key){
}
}
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
NetworkManager &networkManager= NetworkManager::getInstance();
networkManager.getGameNetworkInterface()->quitGame(true);
ErrorDisplayMessage(ex.what(),true);
}
}
void Game::keyPress(char c){
chatManager.keyPress(c);