- more network fixes to make lag and disconnects more stable

- changed the way the game end logic happens to try to make it more stable
This commit is contained in:
Mark Vejvoda 2010-08-07 04:49:06 +00:00
parent fe8d3b3130
commit a5bf684493
7 changed files with 53 additions and 17 deletions

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2009 Martiño Figueroa
// Copyright (C) 2001-2009 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -73,7 +73,9 @@ void AutoTest::updateGame(Game *game){
// quit if we've espend enough time in the game
if(time(NULL)-gameStartTime>gameTime){
game->quitGame();
Program *program = game->getProgram();
Stats endStats = game->quitGame();
Game::exitGameState(program, endStats);
}
}

View File

@ -118,8 +118,11 @@ bool Game::quitTriggered() {
return quitTriggeredIndicator;
}
void Game::quitAndToggleState() {
quitGame();
Stats Game::quitAndToggleState() {
//quitGame();
//Program *program = game->getProgram();
return quitGame();
//Game::exitGameState(program, endStats);
}
// ==================== init and load ====================
@ -1123,15 +1126,15 @@ void Game::keyPress(char c){
chatManager.keyPress(c);
}
void Game::quitGame(){
Stats Game::quitGame() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//Stats stats = *(world.getStats());
Stats *endStats = new Stats();
Stats endStats;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
*endStats = *(world.getStats());
endStats = *(world.getStats());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -1140,16 +1143,25 @@ void Game::quitGame(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
ProgramState *newState = new BattleEnd(program, endStats);
//ProgramState *newState = new BattleEnd(program, endStats);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//program->setState(newState);
return endStats;
}
void Game::exitGameState(Program *program, Stats &endStats) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
delete endStats;
endStats = NULL;
ProgramState *newState = new BattleEnd(program, &endStats);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
program->setState(newState);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
// ==================== PRIVATE ====================

View File

@ -128,8 +128,9 @@ public:
virtual bool isInSpecialKeyCaptureEvent() { return chatManager.getEditEnabled(); }
virtual bool quitTriggered();
virtual void quitAndToggleState();
void quitGame();
virtual Stats quitAndToggleState();
Stats quitGame();
static void exitGameState(Program *program, Stats &endStats);
private:
//render

View File

@ -233,8 +233,15 @@ void Program::loopWorker() {
if(this->programState->quitTriggered() == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
this->programState->quitAndToggleState();
Stats endStats = this->programState->quitAndToggleState();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Game::exitGameState(this, endStats);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return;
}
ProgramState *prevState = this->programState;

View File

@ -19,6 +19,7 @@
#include "components.h"
#include "window.h"
#include "simple_threads.h"
#include "stats.h"
using Shared::Platform::MouseButton;
using Shared::Graphics::Context;
@ -77,7 +78,8 @@ public:
virtual void restoreToStartXY() { SDL_WarpMouse(startX, startY); }
virtual bool isInSpecialKeyCaptureEvent() { return false; }
virtual bool quitTriggered() { return false; }
virtual void quitAndToggleState() {};
virtual Stats quitAndToggleState() { return Stats(); };
virtual Program * getProgram() { return program; }
};
// ===============================

View File

@ -101,7 +101,9 @@ void NetworkMessage::send(Socket* socket, const void* data, int dataSize) const
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket = %p, data = %p, dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,socket,data,dataSize);
if(socket != NULL) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket = %p, data = %p, dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,socket,data,dataSize);
int sendResult = socket->send(data, dataSize);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket = %p, data = %p, dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,socket,data,dataSize);
if(sendResult != dataSize) {
if(socket != NULL && socket->getSocketId() > 0) {
char szBuf[1024]="";
@ -340,7 +342,7 @@ bool NetworkMessageCommandList::receive(Socket* socket) {
}
void NetworkMessageCommandList::send(Socket* socket) const{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtCommandList, frameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,data.header.frameCount);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtCommandList, frameCount = %d, data.header.commandCount = %d, data.header.messageType = %d\n",__FILE__,__FUNCTION__,__LINE__,data.header.frameCount,data.header.commandCount,data.header.messageType);
assert(data.header.messageType==nmtCommandList);
int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);

View File

@ -972,18 +972,25 @@ int Socket::getDataToRead(bool wantImmediateReply) {
}
int Socket::send(const void *data, int dataSize) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
ssize_t bytesSent= 0;
if(isSocketValid() == true) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
errno = 0;
MutexSafeWrapper safeMutex(&dataSynchAccessor);
bytesSent = ::send(sock, reinterpret_cast<const char*>(data), dataSize, 0);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
bytesSent = ::send(sock, data, dataSize, MSG_NOSIGNAL);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
// TEST errors
//bytesSent = -1;
// END TEST
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
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());
//throwException(szBuf);
@ -1001,13 +1008,16 @@ int Socket::send(const void *data, int dataSize) {
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);
MutexSafeWrapper safeMutex(&dataSynchAccessor);
bytesSent = ::send(sock, reinterpret_cast<const char*>(data), dataSize, 0);
bytesSent = ::send(sock, data, dataSize, MSG_NOSIGNAL);
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);
}
}
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
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());