- network related bugfixes:

menu slowdown when picking network slots
clients can once again change network slots
performance fixes for network receiving
This commit is contained in:
Mark Vejvoda 2010-06-29 06:50:35 +00:00
parent a7954abc02
commit 9508dad51b
11 changed files with 284 additions and 248 deletions

View File

@ -46,6 +46,8 @@ public:
static const char *folder_path_techs;
static const char *folder_path_tilesets;
static const char *folder_path_tutorials;
static const char *NETWORK_SLOT_UNCONNECTED_SLOTNAME;
};
enum PathType {

View File

@ -37,6 +37,7 @@ const char *GameConstants::folder_path_techs = "techs";
const char *GameConstants::folder_path_tilesets = "tilesets";
const char *GameConstants::folder_path_tutorials = "tutorials";
const char *GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME = "???";
// =====================================================
// class Config

View File

@ -154,6 +154,7 @@ const Vec4f Renderer::defDiffuseColor= Vec4f(1.f, 1.f, 1.f, 1.f);
const Vec4f Renderer::defAmbientColor= Vec4f(1.f * ambFactor, 1.f * ambFactor, 1.f * ambFactor, 1.f);
const Vec4f Renderer::defColor= Vec4f(1.f, 1.f, 1.f, 1.f);
//const float Renderer::maxLightDist= 100.f;
const float Renderer::maxLightDist= 1000.f;
// ==================== constructor and destructor ====================
@ -666,10 +667,12 @@ void Renderer::renderMouse3d() {
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color.ptr());
const Model *buildingModel= building->getFirstStOfClass(scStop)->getAnimation();
if(gui->getSelectedFacing() != CardinalDir::NORTH) {
float rotateAmount = gui->getSelectedFacing() * 90.f;
if(rotateAmount > 0) {
glRotatef(rotateAmount, 0.f, 1.f, 0.f);
}
}
buildingModel->updateInterpolationData(0.f, false);
modelRenderer->render(buildingModel);

View File

@ -235,7 +235,8 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
break;
}
}
if((listBoxControls[i].getSelectedItemIndex()==ctNetwork) && (labelNetStatus[i].getText()=="???")){
if((listBoxControls[i].getSelectedItemIndex() == ctNetwork) &&
(labelNetStatus[i].getText() == GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME)) {
if(grabSlotButton[i].mouseClick(x, y) )
{
soundRenderer.playFx(coreData.getClickSoundA());
@ -354,7 +355,8 @@ void MenuStateConnectedGame::render(){
renderer.renderListBox(&listBoxTeams[i]);
//renderer.renderLabel(&labelNetStatus[i]);
if((listBoxControls[i].getSelectedItemIndex()==ctNetwork) && (labelNetStatus[i].getText()=="???")){
if((listBoxControls[i].getSelectedItemIndex() == ctNetwork) &&
(labelNetStatus[i].getText() == GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME)) {
renderer.renderButton(&grabSlotButton[i]);
}
else if((listBoxControls[i].getSelectedItemIndex()==ctNetwork) ||

View File

@ -1167,7 +1167,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
gameSettings->setNetworkPlayerName(slotIndex, connectionSlot->getName());
}
else {
gameSettings->setNetworkPlayerName(slotIndex, "Network");
gameSettings->setNetworkPlayerName(slotIndex, GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME);
}
}
else if (listBoxControls[i].getSelectedItemIndex() == ctHuman) {

View File

@ -273,6 +273,9 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
soundRenderer.playFx(coreData.getClickSoundB());
needUpdateFromServer = false;
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//BaseThread::shutdownAndWait(updateFromMasterserverThread);
delete updateFromMasterserverThread;
updateFromMasterserverThread = NULL;

View File

@ -211,14 +211,18 @@ void ConnectionSlot::update(bool checkForNewClients) {
// Is the listener socket ready to be read?
//if(serverInterface->getServerSocket()->isReadable() == true)
if(checkForNewClients == true) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] BEFORE accept new client connection, serverInterface->getOpenSlotCount() = %d\n",__FILE__,__FUNCTION__,serverInterface->getOpenSlotCount());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] BEFORE accept new client connection, serverInterface->getOpenSlotCount() = %d\n",__FILE__,__FUNCTION__,serverInterface->getOpenSlotCount());
bool hasOpenSlots = (serverInterface->getOpenSlotCount() > 0);
if(serverInterface->getServerSocket()->hasDataToRead() == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex);
socket = serverInterface->getServerSocket()->accept();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex);
if(socket != NULL) {
serverInterface->updateListen();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex);
}
}
//send intro message when connected
if(socket != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] accepted new client connection, serverInterface->getOpenSlotCount() = %d\n",__FILE__,__FUNCTION__,serverInterface->getOpenSlotCount());
@ -253,9 +257,10 @@ void ConnectionSlot::update(bool checkForNewClients) {
chatSender.clear();
chatTeamIndex= -1;
if(socket->hasDataToRead() == true) {
NetworkMessageType networkMessageType= getNextMessageType();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] networkMessageType = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageType);
//process incoming commands
switch(networkMessageType) {
@ -495,6 +500,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
}
}
}
}
if(gotIntro == false && difftime(time(NULL),connectedTime) > GameConstants::maxClientConnectHandshakeSecs) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %d\n",__FILE__,__FUNCTION__,__LINE__,difftime(time(NULL),connectedTime));
@ -506,6 +512,8 @@ void ConnectionSlot::update(bool checkForNewClients) {
close();
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
}
catch(const exception &ex) {

View File

@ -39,7 +39,7 @@ namespace Glest{ namespace Game{
bool enabledThreadedClientCommandBroadcast = false;
// The maximum amount of network update iterations a client is allowed to fall behind
int maxFrameCountLagAllowed = 20;
int maxFrameCountLagAllowed = 30;
// 65% of max we warn all users about the lagged client
double warnFrameCountLagPercent = 0.65;
// Should we wait for lagged clients instead of disconnect them?
@ -242,9 +242,9 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
msgTemplate = "%s exceeded max allowed LAG count of %d, clientLag = %d, pausing game to wait for client to catch up...";
}
#ifdef WIN32
_snprintf(szBuf,4095,msgTemplate,Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()).c_str(),maxFrameCountLagAllowed,clientLagCount);
_snprintf(szBuf,4095,msgTemplate,connectionSlot->getName().c_str() ,maxFrameCountLagAllowed,clientLagCount);
#else
snprintf(szBuf,4095,msgTemplate,Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()).c_str(),maxFrameCountLagAllowed,clientLagCount);
snprintf(szBuf,4095,msgTemplate,connectionSlot->getName().c_str(),maxFrameCountLagAllowed,clientLagCount);
#endif
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,szBuf);
@ -282,10 +282,11 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
return clientLagExceeded;
}
void ServerInterface::signalClientReceiveCommands(ConnectionSlot* connectionSlot,
bool ServerInterface::signalClientReceiveCommands(ConnectionSlot* connectionSlot,
int slotIndex,
bool socketTriggered,
ConnectionSlotEvent &event) {
bool slotSignalled = false;
//bool socketTriggered = (connectionSlot != NULL && connectionSlot->getSocket() != NULL ? socketTriggeredList[connectionSlot->getSocket()->getSocketId()] : false);
//ConnectionSlotEvent &event = eventList[i];
event.eventType = eReceiveSocketData;
@ -294,13 +295,19 @@ void ServerInterface::signalClientReceiveCommands(ConnectionSlot* connectionSlot
event.socketTriggered = socketTriggered;
event.triggerId = slotIndex;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] slotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,slotIndex);
// Step #1 tell all connection slot worker threads to receive socket data
if(connectionSlot != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] slotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,slotIndex);
if(socketTriggered == true || connectionSlot->isConnected() == false) {
connectionSlot->signalUpdate(&event);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
slotSignalled = true;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] slotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,slotIndex);
}
}
return slotSignalled;
}
void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &socketTriggeredList) {
@ -308,7 +315,7 @@ void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
ConnectionSlot* connectionSlot= slots[i];
if(connectionSlot != NULL && connectionSlot->getSocket() != NULL &&
slots[i]->getSocket()->getSocketId() > 0) {
slots[i]->getSocket()->isSocketValid() == true) {
socketTriggeredList[connectionSlot->getSocket()->getSocketId()] = false;
}
}
@ -328,6 +335,8 @@ void ServerInterface::update() {
if(hasData) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] hasData == true\n",__FILE__,__FUNCTION__);
if(gameHasBeenInitiated == false || hasData == true) {
std::map<int,bool> mapSlotSignalledList;
// Step #1 tell all connection slot worker threads to receive socket data
bool checkForNewClients = true;
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
@ -337,7 +346,7 @@ void ServerInterface::update() {
bool socketTriggered = (connectionSlot != NULL && connectionSlot->getSocket() != NULL ? socketTriggeredList[connectionSlot->getSocket()->getSocketId()] : false);
ConnectionSlotEvent &event = eventList[i];
signalClientReceiveCommands(connectionSlot,i,socketTriggered,event);
mapSlotSignalledList[i] = signalClientReceiveCommands(connectionSlot,i,socketTriggered,event);
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
@ -349,7 +358,9 @@ void ServerInterface::update() {
// Examine all threads for completion of delegation
for(int i= 0; i< GameConstants::maxPlayers; ++i) {
ConnectionSlot* connectionSlot = slots[i];
if(connectionSlot != NULL && slotsCompleted.find(i) == slotsCompleted.end()) {
if(connectionSlot != NULL &&
mapSlotSignalledList[i] == true &&
slotsCompleted.find(i) == slotsCompleted.end()) {
std::vector<std::string> errorList = connectionSlot->getThreadErrorList();
// Show any collected errors from threads
if(errorList.size() > 0) {
@ -360,16 +371,16 @@ void ServerInterface::update() {
connectionSlot->clearThreadErrorList();
}
// Not done waiting for data yet
if(connectionSlot->updateCompleted() == false) {
threadsDone = false;
sleep(0);
break;
}
else {
// New lag check
bool clientLagExceeded = false;
if(connectionSlot->isConnected() == true) {
if(gameHasBeenInitiated == true && connectionSlot->isConnected() == true) {
clientLagExceeded = clientLagCheck(connectionSlot);
}
// If the client has exceeded lag and the server wants
@ -379,6 +390,7 @@ void ServerInterface::update() {
bool socketTriggered = (connectionSlot != NULL && connectionSlot->getSocket() != NULL ? socketTriggeredList[connectionSlot->getSocket()->getSocketId()] : false);
ConnectionSlotEvent &event = eventList[i];
signalClientReceiveCommands(connectionSlot,i,socketTriggered,event);
sleep(0);
}
else {
slotsCompleted[i] = true;
@ -386,10 +398,12 @@ void ServerInterface::update() {
}
}
}
sleep(0);
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
// Step #3 dispatch network commands to the pending list so that they are done in proper order
if(gameHasBeenInitiated == true) {
for(int i= 0; i< GameConstants::maxPlayers; ++i) {
ConnectionSlot* connectionSlot= slots[i];
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
@ -411,7 +425,7 @@ void ServerInterface::update() {
}
}
}
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
// Step #4 dispatch pending chat messages

View File

@ -82,7 +82,7 @@ public:
int getCurrentFrameCount() const { return currentFrameCount; }
bool clientLagCheck(ConnectionSlot* connectionSlot);
void signalClientReceiveCommands(ConnectionSlot* connectionSlot,
bool signalClientReceiveCommands(ConnectionSlot* connectionSlot,
int slotIndex,
bool socketTriggered,
ConnectionSlotEvent &event);

View File

@ -100,7 +100,7 @@ void BaseThread::shutdownAndWait(BaseThread *pThread) {
pThread->signalQuit();
//sleep(0);
for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= 5; ) {
for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= 7; ) {
if(pThread->getRunningStatus() == false) {
break;
}

View File

@ -117,6 +117,9 @@ std::string SystemFlags::getHTTP(std::string URL,CURL *handle) {
char errbuf[CURL_ERROR_SIZE]="";
curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errbuf);
// max 5 seconds to connect to the URL
curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, 5);
/* get contents from the URL */
CURLcode result = curl_easy_perform(handle);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] return code [%d] [%s]\n",__FILE__,__FUNCTION__,__LINE__,result,errbuf);