mirror of
https://github.com/glest/glest-source.git
synced 2025-08-20 07:01:21 +02:00
- 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:
@@ -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-2009 Marti<EFBFBD>o Figueroa
|
// Copyright (C) 2001-2009 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
|
||||||
@@ -73,7 +73,9 @@ void AutoTest::updateGame(Game *game){
|
|||||||
|
|
||||||
// quit if we've espend enough time in the game
|
// quit if we've espend enough time in the game
|
||||||
if(time(NULL)-gameStartTime>gameTime){
|
if(time(NULL)-gameStartTime>gameTime){
|
||||||
game->quitGame();
|
Program *program = game->getProgram();
|
||||||
|
Stats endStats = game->quitGame();
|
||||||
|
Game::exitGameState(program, endStats);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -118,8 +118,11 @@ bool Game::quitTriggered() {
|
|||||||
return quitTriggeredIndicator;
|
return quitTriggeredIndicator;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::quitAndToggleState() {
|
Stats Game::quitAndToggleState() {
|
||||||
quitGame();
|
//quitGame();
|
||||||
|
//Program *program = game->getProgram();
|
||||||
|
return quitGame();
|
||||||
|
//Game::exitGameState(program, endStats);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== init and load ====================
|
// ==================== init and load ====================
|
||||||
@@ -1123,15 +1126,15 @@ void Game::keyPress(char c){
|
|||||||
chatManager.keyPress(c);
|
chatManager.keyPress(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::quitGame(){
|
Stats Game::quitGame() {
|
||||||
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__);
|
||||||
|
|
||||||
//Stats stats = *(world.getStats());
|
//Stats stats = *(world.getStats());
|
||||||
Stats *endStats = new Stats();
|
Stats endStats;
|
||||||
|
|
||||||
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__);
|
||||||
|
|
||||||
*endStats = *(world.getStats());
|
endStats = *(world.getStats());
|
||||||
|
|
||||||
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__);
|
||||||
|
|
||||||
@@ -1140,16 +1143,25 @@ void Game::quitGame(){
|
|||||||
|
|
||||||
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__);
|
||||||
|
|
||||||
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__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
delete endStats;
|
ProgramState *newState = new BattleEnd(program, &endStats);
|
||||||
endStats = NULL;
|
|
||||||
|
|
||||||
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__);
|
||||||
|
|
||||||
program->setState(newState);
|
program->setState(newState);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== PRIVATE ====================
|
// ==================== PRIVATE ====================
|
||||||
|
@@ -128,8 +128,9 @@ public:
|
|||||||
virtual bool isInSpecialKeyCaptureEvent() { return chatManager.getEditEnabled(); }
|
virtual bool isInSpecialKeyCaptureEvent() { return chatManager.getEditEnabled(); }
|
||||||
|
|
||||||
virtual bool quitTriggered();
|
virtual bool quitTriggered();
|
||||||
virtual void quitAndToggleState();
|
virtual Stats quitAndToggleState();
|
||||||
void quitGame();
|
Stats quitGame();
|
||||||
|
static void exitGameState(Program *program, Stats &endStats);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//render
|
//render
|
||||||
|
@@ -233,8 +233,15 @@ void Program::loopWorker() {
|
|||||||
|
|
||||||
if(this->programState->quitTriggered() == true) {
|
if(this->programState->quitTriggered() == true) {
|
||||||
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__);
|
||||||
this->programState->quitAndToggleState();
|
|
||||||
|
Stats endStats = this->programState->quitAndToggleState();
|
||||||
|
|
||||||
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__);
|
||||||
|
|
||||||
|
Game::exitGameState(this, endStats);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ProgramState *prevState = this->programState;
|
ProgramState *prevState = this->programState;
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include "components.h"
|
#include "components.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "simple_threads.h"
|
#include "simple_threads.h"
|
||||||
|
#include "stats.h"
|
||||||
|
|
||||||
using Shared::Platform::MouseButton;
|
using Shared::Platform::MouseButton;
|
||||||
using Shared::Graphics::Context;
|
using Shared::Graphics::Context;
|
||||||
@@ -77,7 +78,8 @@ public:
|
|||||||
virtual void restoreToStartXY() { SDL_WarpMouse(startX, startY); }
|
virtual void restoreToStartXY() { SDL_WarpMouse(startX, startY); }
|
||||||
virtual bool isInSpecialKeyCaptureEvent() { return false; }
|
virtual bool isInSpecialKeyCaptureEvent() { return false; }
|
||||||
virtual bool quitTriggered() { return false; }
|
virtual bool quitTriggered() { return false; }
|
||||||
virtual void quitAndToggleState() {};
|
virtual Stats quitAndToggleState() { return Stats(); };
|
||||||
|
virtual Program * getProgram() { return program; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// ===============================
|
// ===============================
|
||||||
|
@@ -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);
|
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) {
|
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);
|
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(sendResult != dataSize) {
|
||||||
if(socket != NULL && socket->getSocketId() > 0) {
|
if(socket != NULL && socket->getSocketId() > 0) {
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
@@ -340,7 +342,7 @@ bool NetworkMessageCommandList::receive(Socket* socket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NetworkMessageCommandList::send(Socket* socket) const{
|
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);
|
assert(data.header.messageType==nmtCommandList);
|
||||||
int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);
|
int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);
|
||||||
|
@@ -972,18 +972,25 @@ int Socket::getDataToRead(bool wantImmediateReply) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Socket::send(const void *data, int dataSize) {
|
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;
|
ssize_t bytesSent= 0;
|
||||||
if(isSocketValid() == true) {
|
if(isSocketValid() == true) {
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessor);
|
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
|
// TEST errors
|
||||||
//bytesSent = -1;
|
//bytesSent = -1;
|
||||||
// END TEST
|
// END TEST
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
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);
|
||||||
@@ -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);
|
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);
|
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] #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] attemptCount = %d\n",__FILE__,__FUNCTION__,__LINE__,attemptCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
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());
|
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());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user