- added more bug fixes related to network disconnects.

- Added a new global message box to display error messages on top of any graphics window being displayed.
This commit is contained in:
Mark Vejvoda 2010-07-08 08:29:51 +00:00
parent ff21d26161
commit ab655162cb
18 changed files with 275 additions and 127 deletions

View File

@ -154,7 +154,7 @@ void ChatManager::updateNetwork() {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameNetworkInterface->getChatText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameNetworkInterface->getChatText().c_str()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameNetworkInterface->getChatText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameNetworkInterface->getChatText().c_str());
if(gameNetworkInterface->getChatTextList().empty() == false) { if(gameNetworkInterface != NULL && gameNetworkInterface->getChatTextList().empty() == false) {
for(int idx = 0; idx < gameNetworkInterface->getChatTextList().size(); idx++) { for(int idx = 0; idx < gameNetworkInterface->getChatTextList().size(); idx++) {
const ChatMsgInfo &msg = gameNetworkInterface->getChatTextList()[idx]; const ChatMsgInfo &msg = gameNetworkInterface->getChatTextList()[idx];
int teamIndex= msg.chatTeamIndex; int teamIndex= msg.chatTeamIndex;

View File

@ -1235,6 +1235,7 @@ void Game::render2d(){
Vec3f(1.0f), 200, 680, false); Vec3f(1.0f), 200, 680, false);
} }
if(program != NULL) program->renderProgramMsgBox();
renderer.renderChatManager(&chatManager); renderer.renderChatManager(&chatManager);

View File

@ -133,6 +133,9 @@ void Intro::render(){
} }
} }
} }
if(program != NULL) program->renderProgramMsgBox();
renderer.swapBuffers(); renderer.swapBuffers();
} }

View File

@ -86,7 +86,7 @@ public:
} }
static int DisplayMessage(const char *msg, bool exitApp) { static int DisplayMessage(const char *msg, bool exitApp) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,msg); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] msg [%s] exitApp = %d\n",__FILE__,__FUNCTION__,__LINE__,msg,exitApp);
Program *program = Program::getInstance(); Program *program = Program::getInstance();
if(program && gameInitialized == true) { if(program && gameInitialized == true) {
@ -130,6 +130,20 @@ void MainWindow::eventMouseDown(int x, int y, MouseButton mouseButton){
throw runtime_error("In [MainWindow::eventMouseDown] ERROR, program == NULL!"); throw runtime_error("In [MainWindow::eventMouseDown] ERROR, program == NULL!");
} }
switch(mouseButton) {
case mbLeft:
program->mouseDownLeft(vx, vy);
break;
case mbRight:
//program->mouseDownRight(vx, vy);
break;
case mbCenter:
//program->mouseDownCenter(vx, vy);
break;
default:
break;
}
ProgramState *programState = program->getState(); ProgramState *programState = program->getState();
if(programState != NULL) { if(programState != NULL) {
switch(mouseButton) { switch(mouseButton) {
@ -215,6 +229,8 @@ void MainWindow::eventMouseMove(int x, int y, const MouseState *ms){
throw runtime_error("In [MainWindow::eventMouseMove] ERROR, program == NULL!"); throw runtime_error("In [MainWindow::eventMouseMove] ERROR, program == NULL!");
} }
program->eventMouseMove(vx, vy, ms);
ProgramState *programState = program->getState(); ProgramState *programState = program->getState();
if(programState != NULL) { if(programState != NULL) {
programState->mouseMove(vx, vy, ms); programState->mouseMove(vx, vy, ms);

View File

@ -120,6 +120,11 @@ Program::Program() {
programState= NULL; programState= NULL;
singleton = this; singleton = this;
soundThreadManager = NULL; soundThreadManager = NULL;
//mesage box
Lang &lang= Lang::getInstance();
msgBox.init(lang.get("Ok"));
msgBox.setEnabled(false);
} }
void Program::initNormal(WindowGl *window){ void Program::initNormal(WindowGl *window){
@ -168,6 +173,15 @@ Program::~Program(){
} }
void Program::keyDown(char key){ void Program::keyDown(char key){
if(msgBox.getEnabled()) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(key == vkEscape || key == vkReturn) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
msgBox.setEnabled(false);
}
}
//delegate event //delegate event
programState->keyDown(key); programState->keyDown(key);
} }
@ -180,6 +194,23 @@ void Program::keyPress(char c){
programState->keyPress(c); programState->keyPress(c);
} }
void Program::mouseDownLeft(int x, int y) {
if(msgBox.getEnabled()) {
int button= 1;
if(msgBox.mouseClick(x, y, button)) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//close message box
msgBox.setEnabled(false);
}
}
}
void Program::eventMouseMove(int x, int y, const MouseState *ms) {
if (msgBox.getEnabled()) {
msgBox.mouseMove(x, y);
}
}
void Program::simpleTask() { void Program::simpleTask() {
loopWorker(); loopWorker();
} }
@ -189,21 +220,27 @@ void Program::loop() {
} }
void Program::loopWorker() { void Program::loopWorker() {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] programState = %p\n",__FILE__,__FUNCTION__,__LINE__,programState);
Chrono chrono; Chrono chrono;
chrono.start(); chrono.start();
//getWindow()->makeCurrentGl(); //getWindow()->makeCurrentGl();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//render //render
assert(programState != NULL); assert(programState != NULL);
ProgramState *prevState = this->programState;
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
programState->render(); programState->render();
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
//update camera //update camera
chrono.start(); chrono.start();
while(updateCameraTimer.isTime()){ while(updateCameraTimer.isTime()){
@ -216,36 +253,44 @@ void Program::loopWorker() {
//update world //update world
chrono.start(); chrono.start();
while(updateTimer.isTime()){
while(prevState == this->programState && updateTimer.isTime()) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
GraphicComponent::update(); GraphicComponent::update();
programState->update(); programState->update();
if(prevState == this->programState) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); if(soundThreadManager == NULL) {
SoundRenderer::getInstance().update();
}
if(soundThreadManager == NULL) { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SoundRenderer::getInstance().update();
NetworkManager::getInstance().update();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
NetworkManager::getInstance().update();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//fps timer if(prevState == this->programState) {
chrono.start(); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
while(fpsTimer.isTime()){
programState->tick(); //fps timer
chrono.start();
while(fpsTimer.isTime()) {
programState->tick();
}
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
} }
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
void Program::resize(SizeState sizeState){ void Program::resize(SizeState sizeState){
@ -264,18 +309,12 @@ void Program::resize(SizeState sizeState){
// ==================== misc ==================== // ==================== misc ====================
//Your filter function should look something like: void Program::renderProgramMsgBox() {
int SDLEventFilter(const SDL_Event* filterEvent) { if(msgBox.getEnabled()) {
if(filterEvent->type == SDL_KEYDOWN || /**< Keys pressed */ Renderer &renderer= Renderer::getInstance();
filterEvent->type == SDL_KEYUP || /**< Keys released */ renderer.renderMessageBox(&msgBox);
filterEvent->type == SDL_MOUSEMOTION || /**< Mouse moved */ }
filterEvent->type == SDL_MOUSEBUTTONDOWN || /**< Mouse button pressed */ }
filterEvent->type == SDL_MOUSEBUTTONUP) /**< Mouse button released */
{
return 0;
}
return 1;
}
void Program::setState(ProgramState *programState, bool cleanupOldState) void Program::setState(ProgramState *programState, bool cleanupOldState)
{ {
@ -309,6 +348,11 @@ void Program::setState(ProgramState *programState, bool cleanupOldState)
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//mesage box
Lang &lang= Lang::getInstance();
msgBox.init(lang.get("Ok"));
msgBox.setEnabled(false);
this->programState= programState; this->programState= programState;
programState->load(); programState->load();
@ -481,7 +525,15 @@ void Program::restoreDisplaySettings(){
} }
void Program::showMessage(const char *msg) { void Program::showMessage(const char *msg) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] msg [%s]\n",__FILE__,__FUNCTION__,__LINE__,msg);
msgBox.setText(msg);
//msgBox.setHeader(header);
msgBox.setEnabled(true);
/*
int showMouseState = SDL_ShowCursor(SDL_QUERY);
ProgramState *originalState = NULL; ProgramState *originalState = NULL;
if(this->programState) { if(this->programState) {
@ -491,17 +543,15 @@ void Program::showMessage(const char *msg) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
showCursor(true);
//SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
ShowMessageProgramState *showMsg = new ShowMessageProgramState(this, msg); ShowMessageProgramState *showMsg = new ShowMessageProgramState(this, msg);
//this->programState = showMsg;
this->programState = NULL; this->programState = NULL;
setState(showMsg); setState(showMsg);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
showCursor(true);
while(Window::handleEvent() && showMsg->wantExit() == false) { while(Window::handleEvent() && showMsg->wantExit() == false) {
loop(); loop();
} }
@ -514,13 +564,11 @@ void Program::showMessage(const char *msg) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
Config &config = Config::getInstance(); Config &config = Config::getInstance();
if(config.getBool("No2DMouseRendering","false") == false) { //if(config.getBool("No2DMouseRendering","false") == false) {
showCursor(false); showCursor((showMouseState == SDL_ENABLE));
} //}
//MainWindow *mainWindow= new MainWindow(this);
init(this->window,false); init(this->window,false);
//setState(originalState);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
@ -529,20 +577,9 @@ void Program::showMessage(const char *msg) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
this->programState= originalState; this->programState= originalState;
//programState->load();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
*/
//programState->init();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
//updateTimer.reset();
//updateCameraTimer.reset();
//fpsTimer.reset();
//this->programState = originalState;
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }

View File

@ -116,6 +116,8 @@ private:
WindowGl *window; WindowGl *window;
static Program *singleton; static Program *singleton;
GraphicMessageBox msgBox;
public: public:
Program(); Program();
~Program(); ~Program();
@ -145,6 +147,11 @@ public:
virtual void simpleTask(); virtual void simpleTask();
void mouseDownLeft(int x, int y);
void eventMouseMove(int x, int y, const MouseState *ms);
void renderProgramMsgBox();
private: private:
void setDisplaySettings(); void setDisplaySettings();

View File

@ -91,6 +91,9 @@ void MenuStateAbout::render(){
renderer.renderLabel(&labelTeammateName[i]); renderer.renderLabel(&labelTeammateName[i]);
renderer.renderLabel(&labelTeammateRole[i]); renderer.renderLabel(&labelTeammateRole[i]);
} }
if(program != NULL) program->renderProgramMsgBox();
} }
}}//end namespace }}//end namespace

View File

@ -290,14 +290,23 @@ void MenuStateConnectedGame::mouseMove(int x, int y, const MouseState *ms){
void MenuStateConnectedGame::render(){ void MenuStateConnectedGame::render(){
try { try {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if (!settingsReceivedFromServer) return; if (!settingsReceivedFromServer) return;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
Renderer &renderer= Renderer::getInstance(); Renderer &renderer= Renderer::getInstance();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
int i; int i;
renderer.renderButton(&buttonDisconnect); renderer.renderButton(&buttonDisconnect);
//renderer.renderButton(&buttonPlayNow); //renderer.renderButton(&buttonPlayNow);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(i=0; i<GameConstants::maxPlayers; ++i){ for(i=0; i<GameConstants::maxPlayers; ++i){
renderer.renderLabel(&labelPlayers[i]); renderer.renderLabel(&labelPlayers[i]);
renderer.renderListBox(&listBoxControls[i]); renderer.renderListBox(&listBoxControls[i]);
@ -316,6 +325,8 @@ void MenuStateConnectedGame::render(){
} }
} }
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderLabel(&labelStatus); renderer.renderLabel(&labelStatus);
renderer.renderLabel(&labelInfo); renderer.renderLabel(&labelInfo);
renderer.renderLabel(&labelMap); renderer.renderLabel(&labelMap);
@ -332,6 +343,8 @@ void MenuStateConnectedGame::render(){
renderer.renderListBox(&listBoxTileset); renderer.renderListBox(&listBoxTileset);
renderer.renderListBox(&listBoxTechTree); renderer.renderListBox(&listBoxTechTree);
if(program != NULL) program->renderProgramMsgBox();
renderer.renderChatManager(&chatManager); renderer.renderChatManager(&chatManager);
renderer.renderConsole(&console,showFullConsole,true); renderer.renderConsole(&console,showFullConsole,true);
} }
@ -348,8 +361,7 @@ void MenuStateConnectedGame::update()
Lang &lang= Lang::getInstance(); Lang &lang= Lang::getInstance();
//update status label //update status label
if(clientInterface->isConnected()) if(clientInterface != NULL && clientInterface->isConnected()) {
{
buttonDisconnect.setText(lang.get("Disconnect")); buttonDisconnect.setText(lang.get("Disconnect"));
if(clientInterface->getAllowDownloadDataSynch() == false) if(clientInterface->getAllowDownloadDataSynch() == false)
@ -439,12 +451,14 @@ void MenuStateConnectedGame::update()
labelStatus.setText(szBuf); labelStatus.setText(szBuf);
} }
} }
else else {
{ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(clientInterface->getSocket() != NULL)
{ if(clientInterface != NULL && clientInterface->isConnected() == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
clientInterface->close(); clientInterface->close();
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
returnToJoinMenu(); returnToJoinMenu();
return; return;
} }
@ -535,41 +549,43 @@ void MenuStateConnectedGame::update()
//update lobby //update lobby
clientInterface->updateLobby(); clientInterface->updateLobby();
//call the chat manager clientInterface= NetworkManager::getInstance().getClientInterface();
chatManager.updateNetwork(); if(clientInterface != NULL && clientInterface->isConnected()) {
//call the chat manager
chatManager.updateNetwork();
//console //console
console.update(); console.update();
//intro //intro
if(clientInterface->getIntroDone()) if(clientInterface->getIntroDone())
{ {
labelInfo.setText(lang.get("WaitingHost")); labelInfo.setText(lang.get("WaitingHost"));
//servers.setString(clientInterface->getServerName(), Ip(labelServerIp.getText()).getString()); //servers.setString(clientInterface->getServerName(), Ip(labelServerIp.getText()).getString());
}
//launch
if(clientInterface->getLaunchGame())
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//servers.save(serversSavedFile);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
assert(clientInterface != NULL);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
program->setState(new Game(program, clientInterface->getGameSettings()));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
} }
//launch
if(clientInterface->getLaunchGame())
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//servers.save(serversSavedFile);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
assert(clientInterface != NULL);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
program->setState(new Game(program, clientInterface->getGameSettings()));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
if(clientInterface->getLaunchGame()) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - D\n",__FILE__,__FUNCTION__); if(clientInterface != NULL && clientInterface->getLaunchGame()) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - D\n",__FILE__,__FUNCTION__);
} }

View File

@ -717,6 +717,8 @@ void MenuStateCustomGame::render(){
renderer.renderListBox(&listBoxNetworkFramePeriod); renderer.renderListBox(&listBoxNetworkFramePeriod);
} }
} }
if(program != NULL) program->renderProgramMsgBox();
} }
catch(const std::exception &ex) { catch(const std::exception &ex) {
char szBuf[1024]=""; char szBuf[1024]="";

View File

@ -305,6 +305,8 @@ void MenuStateJoinGame::render(){
renderer.renderChatManager(&chatManager); renderer.renderChatManager(&chatManager);
renderer.renderConsole(&console); renderer.renderConsole(&console);
if(program != NULL) program->renderProgramMsgBox();
} }
void MenuStateJoinGame::update() void MenuStateJoinGame::update()
@ -402,35 +404,37 @@ void MenuStateJoinGame::update()
//update lobby //update lobby
clientInterface->updateLobby(); clientInterface->updateLobby();
//call the chat manager clientInterface= NetworkManager::getInstance().getClientInterface();
chatManager.updateNetwork(); if(clientInterface != NULL && clientInterface->isConnected()) {
//call the chat manager
chatManager.updateNetwork();
//console //console
console.update(); console.update();
//intro //intro
if(clientInterface->getIntroDone()) if(clientInterface->getIntroDone())
{ {
labelInfo.setText(lang.get("WaitingHost")); labelInfo.setText(lang.get("WaitingHost"));
servers.setString(clientInterface->getServerName(), Ip(labelServerIp.getText()).getString()); servers.setString(clientInterface->getServerName(), Ip(labelServerIp.getText()).getString());
}
//launch
if(clientInterface->getLaunchGame())
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - A\n",__FILE__,__FUNCTION__);
servers.save(serversSavedFile);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - B\n",__FILE__,__FUNCTION__);
abortAutoFind = true;
clientInterface->stopServerDiscovery();
program->setState(new Game(program, clientInterface->getGameSettings()));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - C\n",__FILE__,__FUNCTION__);
}
} }
//launch
if(clientInterface->getLaunchGame())
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - A\n",__FILE__,__FUNCTION__);
servers.save(serversSavedFile);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - B\n",__FILE__,__FUNCTION__);
abortAutoFind = true;
clientInterface->stopServerDiscovery();
program->setState(new Game(program, clientInterface->getGameSettings()));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - C\n",__FILE__,__FUNCTION__);
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
else if(autoConnectToServer == true) { else if(autoConnectToServer == true) {
@ -438,7 +442,7 @@ void MenuStateJoinGame::update()
connectToServer(); connectToServer();
} }
if(clientInterface->getLaunchGame()) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - D\n",__FILE__,__FUNCTION__); if(clientInterface != NULL && clientInterface->getLaunchGame()) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - D\n",__FILE__,__FUNCTION__);
} }
void MenuStateJoinGame::keyDown(char key){ void MenuStateJoinGame::keyDown(char key){

View File

@ -356,7 +356,8 @@ void MenuStateMasterserver::render(){
for(int i=0; i<serverLines.size(); ++i){ for(int i=0; i<serverLines.size(); ++i){
serverLines[i]->render(); serverLines[i]->render();
} }
} }
if(program != NULL) program->renderProgramMsgBox();
} }
void MenuStateMasterserver::update(){ void MenuStateMasterserver::update(){

View File

@ -87,6 +87,8 @@ void MenuStateNewGame::render(){
renderer.renderButton(&buttonScenario); renderer.renderButton(&buttonScenario);
renderer.renderButton(&buttonTutorial); renderer.renderButton(&buttonTutorial);
renderer.renderButton(&buttonReturn); renderer.renderButton(&buttonReturn);
if(program != NULL) program->renderProgramMsgBox();
} }
void MenuStateNewGame::update(){ void MenuStateNewGame::update(){

View File

@ -425,6 +425,8 @@ void MenuStateOptions::render(){
renderer.renderLabel(&labelFullscreenWindowed); renderer.renderLabel(&labelFullscreenWindowed);
renderer.renderListBox(&listBoxFullscreenWindowed); renderer.renderListBox(&listBoxFullscreenWindowed);
} }
if(program != NULL) program->renderProgramMsgBox();
} }
void MenuStateOptions::saveConfig(){ void MenuStateOptions::saveConfig(){

View File

@ -149,7 +149,7 @@ void MenuStateRoot::render(){
if(mainMessageBox.getEnabled()){ if(mainMessageBox.getEnabled()){
renderer.renderMessageBox(&mainMessageBox); renderer.renderMessageBox(&mainMessageBox);
} }
if(program != NULL) program->renderProgramMsgBox();
} }
void MenuStateRoot::update(){ void MenuStateRoot::update(){

View File

@ -1,7 +1,7 @@
// ============================================================== // ==============================================================
// This file is part of Glest (www.glest.org) // This file is part of Glest (www.glest.org)
// //
// Copyright (C) 2001-2005 Martiño Figueroa // Copyright (C) 2001-2005 Martio Figueroa
// //
// You can redistribute this code and/or modify it under // You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published // the terms of the GNU General Public License as published
@ -108,6 +108,8 @@ void MenuStateScenario::render(){
renderer.renderButton(&buttonReturn); renderer.renderButton(&buttonReturn);
renderer.renderButton(&buttonPlayNow); renderer.renderButton(&buttonPlayNow);
if(program != NULL) program->renderProgramMsgBox();
} }
void MenuStateScenario::update(){ void MenuStateScenario::update(){

View File

@ -158,7 +158,6 @@ void ClientInterface::updateLobby()
clearChatInfo(); clearChatInfo();
NetworkMessageType networkMessageType = getNextMessageType(true); NetworkMessageType networkMessageType = getNextMessageType(true);
switch(networkMessageType) switch(networkMessageType)
{ {
case nmtInvalid: case nmtInvalid:
@ -171,10 +170,12 @@ void ClientInterface::updateLobby()
if(receiveMessage(&networkMessageIntro)) { if(receiveMessage(&networkMessageIntro)) {
gotIntro = true; gotIntro = true;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got NetworkMessageIntro, networkMessageIntro.getGameState() = %d\n",__FILE__,__FUNCTION__,networkMessageIntro.getGameState()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got NetworkMessageIntro, networkMessageIntro.getGameState() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageIntro.getGameState());
//check consistency //check consistency
if(networkMessageIntro.getVersionString() != getNetworkVersionString()) { if(networkMessageIntro.getVersionString() != getNetworkVersionString()) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool versionMatched = false; bool versionMatched = false;
string platformFreeVersion = getNetworkPlatformFreeVersionString(); string platformFreeVersion = getNetworkPlatformFreeVersionString();
string sErr = ""; string sErr = "";
@ -213,7 +214,11 @@ void ClientInterface::updateLobby()
} }
} }
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(networkMessageIntro.getGameState() == nmgstOk) { if(networkMessageIntro.getGameState() == nmgstOk) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//send intro message //send intro message
NetworkMessageIntro sendNetworkMessageIntro(getNetworkVersionString(), Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()), -1, nmgstOk); NetworkMessageIntro sendNetworkMessageIntro(getNetworkVersionString(), Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()), -1, nmgstOk);
@ -221,14 +226,32 @@ void ClientInterface::updateLobby()
serverName= networkMessageIntro.getName(); serverName= networkMessageIntro.getName();
sendMessage(&sendNetworkMessageIntro); sendMessage(&sendNetworkMessageIntro);
assert(playerIndex>=0 && playerIndex<GameConstants::maxPlayers); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
introDone= true;
if(clientSocket == NULL || clientSocket->isConnected() == false) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string sErr = "Disconnected from server during intro handshake.";
DisplayErrorMessage(sErr);
quit= true;
close();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return;
}
else {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
assert(playerIndex>=0 && playerIndex<GameConstants::maxPlayers);
introDone= true;
}
} }
else if(networkMessageIntro.getGameState() == nmgstNoSlots) { else if(networkMessageIntro.getGameState() == nmgstNoSlots) {
string sErr = "Cannot join the server because there are no open slots for new players."; string sErr = "Cannot join the server because there are no open slots for new players.";
DisplayErrorMessage(sErr); DisplayErrorMessage(sErr);
quit= true; quit= true;
close(); close();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return; return;
} }
else { else {
@ -236,6 +259,7 @@ void ClientInterface::updateLobby()
DisplayErrorMessage(sErr); DisplayErrorMessage(sErr);
quit= true; quit= true;
close(); close();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return; return;
} }
} }
@ -454,7 +478,8 @@ void ClientInterface::updateLobby()
} }
} }
if(gotIntro == false && difftime(time(NULL),connectedTime) > GameConstants::maxClientConnectHandshakeSecs) { if( clientSocket != NULL && clientSocket->isConnected() == true &&
gotIntro == false && difftime(time(NULL),connectedTime) > GameConstants::maxClientConnectHandshakeSecs) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %f\n",__FILE__,__FUNCTION__,__LINE__,difftime(time(NULL),connectedTime)); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %f\n",__FILE__,__FUNCTION__,__LINE__,difftime(time(NULL),connectedTime));
close(); close();
} }
@ -795,13 +820,15 @@ void ClientInterface::quitGame(bool userManuallyQuit)
void ClientInterface::close() void ClientInterface::close()
{ {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] START, clientSocket = %p\n",__FILE__,__FUNCTION__,__LINE__,clientSocket);
delete clientSocket; delete clientSocket;
clientSocket= NULL; clientSocket= NULL;
connectedTime = 0; connectedTime = 0;
gotIntro = false; gotIntro = false;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] END\n",__FILE__,__FUNCTION__,__LINE__);
} }
void ClientInterface::discoverServers(DiscoveredServersInterface *cb) { void ClientInterface::discoverServers(DiscoveredServersInterface *cb) {
@ -892,6 +919,14 @@ bool ClientInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess
this->receiveMessage(&msg); this->receiveMessage(&msg);
} }
break; break;
case nmtBroadCastSetup:
{
discard = true;
NetworkMessageLaunch msg = NetworkMessageLaunch();
this->receiveMessage(&msg);
}
break;
case nmtPlayerIndexMessage: case nmtPlayerIndexMessage:
{ {
discard = true; discard = true;

View File

@ -1073,9 +1073,11 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int
catch(const exception &ex) { catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
//throw runtime_error(ex.what()); //throw runtime_error(ex.what());
DisplayErrorMessage(ex.what());
//DisplayErrorMessage(ex.what());
string sMsg = ex.what();
sendTextMessage(sMsg,-1, true);
} }
//serverSynchAccessor.v();
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
} }

View File

@ -937,8 +937,14 @@ int Socket::getDataToRead(){
int Socket::send(const void *data, int dataSize) { int Socket::send(const void *data, int dataSize) {
ssize_t bytesSent= 0; ssize_t bytesSent= 0;
if(isSocketValid() == true) { if(isSocketValid() == true) {
errno = 0;
bytesSent = ::send(sock, reinterpret_cast<const char*>(data), dataSize, 0); bytesSent = ::send(sock, reinterpret_cast<const char*>(data), dataSize, 0);
} }
// TEST errors
//bytesSent = -1;
// END TEST
if(bytesSent < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) { if(bytesSent < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR WRITING SOCKET DATA, err = %d error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesSent,getLastSocketErrorFormattedText().c_str()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR WRITING SOCKET DATA, err = %d error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesSent,getLastSocketErrorFormattedText().c_str());
//throwException(szBuf); //throwException(szBuf);
@ -946,16 +952,25 @@ int Socket::send(const void *data, int dataSize) {
else if(bytesSent < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) { else if(bytesSent < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 EAGAIN during send, trying again...\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 EAGAIN during send, trying again...\n",__FILE__,__FUNCTION__,__LINE__);
int attemptCount = 0;
time_t tStartTimer = time(NULL); time_t tStartTimer = time(NULL);
while((bytesSent < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) && (difftime(time(NULL),tStartTimer) <= 5)) { while((bytesSent < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) && (difftime(time(NULL),tStartTimer) <= 5)) {
attemptCount++;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d\n",__FILE__,__FUNCTION__,__LINE__,attemptCount);
if(Socket::isWritable(true) == true) { if(Socket::isWritable(true) == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d, sock = %d, dataSize = %d, data = %p\n",__FILE__,__FUNCTION__,__LINE__,attemptCount,sock,dataSize,data);
bytesSent = ::send(sock, reinterpret_cast<const char*>(data), dataSize, 0); bytesSent = ::send(sock, reinterpret_cast<const char*>(data), dataSize, 0);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,bytesSent); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,bytesSent);
} }
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d\n",__FILE__,__FUNCTION__,__LINE__,attemptCount);
} }
} }
if(bytesSent <= 0) { if(bytesSent <= 0) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR WRITING SOCKET DATA, err = %d error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesSent,getLastSocketErrorFormattedText().c_str());
int iErr = getLastSocketError(); int iErr = getLastSocketError();
disconnectSocket(); disconnectSocket();