// *************************************************************** // Function: UpdateLoop.cpp // *************************************************************** #include "Main.h" int ProcessPackets(); void InternalCommunicationsProcess(); int Shutdown(); //************************************ // Name: UpdateLoop // // The main program loop. Keeps the program moving. // // Parameters: // // Return: // - true //************************************ bool UpdateLoop() { //Update the network server and process messages continuously int last_gm=GetTickCount(); int gm_delta_time=0; while(true) { //Update the database stuff gDatabase.Update(); //Cycle through all local data and process the database query results gDatabase.ProcessResults, PLAYER_DATA>(&GameServInfo); gpInternalComm->Update(); InternalCommunicationsProcess(); gpGameServer->Update(); ProcessPackets(); //Update all the instances hash_map::iterator hitr; for (hitr=gInstances.begin(); hitr!=gInstances.end(); hitr++) { (hitr)->second.Update(); } //Check for instances that need to be deleted for (hitr=gInstances.begin(); hitr!=gInstances.end(); hitr++) { if ((hitr)->second.KillMe()) { //Cycle through all the players to prevent any loose pointers hash_map::iterator itr32; for (itr32=GameServInfo.begin(); itr32!=GameServInfo.end(); itr32++) { if ((itr32)->second.instanceId==hitr->second.GetInstanceId()) { (itr32)->second.instanceId=NULL; } } gInstanceIds.FreeID(hitr->second.GetInstanceId()); gInstances.erase(hitr->second.GetInstanceId()); break; } } //Continue running scripts =D if (gpScriptMan->GetVM()->Execute(gm_delta_time)) { // Dump run time errors to output bool first = true; const char* pMessage; while((pMessage = gpScriptMan->GetVM()->GetLog().GetEntry(first))) { gCoreLog.always("%s", pMessage); } gpScriptMan->GetVM()->GetLog().Reset(); } //Calculate the time int current_time=GetTickCount(); gm_delta_time=current_time-last_gm; last_gm=current_time; if (gServerConfig.throttleCpu) { Sleep(1); } if (gpInternalComm->mFatalError) gShuttingDown=true; if (gpGameServer->mFatalError) gShuttingDown=true; //ShuttingDown=true; if (gShuttingDown) break; } //Shutdown the server Shutdown(); return true; }