123456789101112131415161718192021222324252627282930313233343536 |
- #include "server/network/Server.h"
- #include "server/GameServer.h"
- #include "server/Clock.h"
- static const u64 NANOS_PER_TICK = 50000000;
- int main() {
- Socket listener;
- if(listener.hasError() || listener.setNonLinger() || listener.listenOnPort(25565, 5)) {
- return 0;
- }
- Clock tps;
- GameServer gameServer(tps);
- Server server(listener, 20, gameServer);
- ServerCommands serverCommands;
- CommandEditor editor;
-
- Clock clock;
- u64 lag = 0;
- while(serverCommands.isRunning()) {
- lag += clock.update();
- while(lag >= NANOS_PER_TICK) {
- lag -= NANOS_PER_TICK;
- tps.update();
- editor.preTick();
- gameServer.handleCommands(editor, serverCommands);
- gameServer.tick();
- editor.postTick();
- }
- u64 waitNanos = NANOS_PER_TICK - lag;
- if(waitNanos > 300000) {
- clock.wait(waitNanos);
- }
- }
- return 0;
- }
|