Created
October 4, 2018 20:17
-
-
Save ChristianHohlfeld/71376b1f67ff75a09f8d81d97fb1f792 to your computer and use it in GitHub Desktop.
Server Update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double sTime = 100.0f; | |
void HelloWorld::initServer() { | |
GameConnectionConfig config; | |
yojimbo::Address* serverAddress = new Address(localProperties.GetProperty("SERVER_IP_ADDRESS").c_str(), 4000); //TODO: delete | |
server = new GameServer(GetDefaultAllocator(), serverAddress, adapter, config, sTime);//TODO: delete | |
server->Start(); | |
char addressString[256]; | |
server->GetAddress().ToString(addressString, sizeof(addressString)); | |
log("server address is %s\n", addressString); | |
} | |
bool isServerInitialized = false; | |
void HelloWorld::UpdateServer(float dt) { | |
physics->tick(dt); | |
if (!isServerInitialized) | |
{ | |
initServer(); | |
isServerInitialized = true; | |
} | |
else { | |
numCon = server->GetNumConnectedClients(); | |
} | |
double currentTime = time(nullptr); | |
if (sTime <= currentTime) { | |
sTime += deltaTime; | |
server->AdvanceTime(sTime); | |
server->ReceivePackets(); | |
server->ProcessMessages(); | |
if (!server->IsRunning()) | |
return; | |
sTime += fixedDt; | |
//... send messages to client ... | |
// Update Server | |
server->SendPackets(); | |
// End Update Server | |
} | |
else { | |
// do nothing | |
} | |
//TODO: | |
//server->Stop() conditions (while(!quit)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment