1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #include "network/ENet.h"
- #include "server/Game.h"
- #include "server/GameServer.h"
- #include "server/commands/Commands.h"
- #include "server/snuviscript/Snuvi.h"
- #include "utils/Logger.h"
- void loop() {
- Clock clock;
- constexpr Clock::Nanos NANOS_PER_TICK = 50000000;
- Clock::Nanos lag = 0;
- while(Game::isRunning()) {
- lag += clock.update();
- while(lag >= NANOS_PER_TICK) {
- lag -= NANOS_PER_TICK;
- GameServer::tick();
- Game::tick();
- }
- Clock::Nanos waitNanos = NANOS_PER_TICK - lag;
- if(waitNanos > 300000) {
- clock.wait(waitNanos);
- }
- }
- }
- void init(Server* server) {
- Snuvi::init();
- Commands::init();
- GameServer::init(server);
- Game::testWorld();
- }
- int main() {
- ENet enet;
- if(enet.init()) {
- LOG_ERROR("cannot initialize enet");
- return 0;
- }
- Server server(11196, 50);
- if(server.hasError()) {
- LOG_ERROR(server.getError());
- return 0;
- }
- init(&server);
- loop();
- return 0;
- }
|