#include #include #include #include #include #include namespace deerith { std::unique_ptr world_thread; std::atomic world_running = false; entity_t self_entity = entt::null; void world_simulation(); } bool deerith::connect_to_world(const char *address, int port) { deerith_assert(!world_running, "connect_to_world failed because there is a current running world"); shutdown_world(); connect_to_server(address, port); if (!wait_till_connected_to_server()) { deerith_error("engine was not able to connect to server"); return false; } world_running = true; world_thread = std::make_unique(world_simulation); return true; } bool deerith::is_world_running() { return world_running; } void deerith::world_simulation() { while (world_running) { flush_network_events(); if (get_world_tick() % 2 == 0) { send_player_input(); } wait_till_next_tick(); } world_running = false; deerith_trace("world shutdown"); } void deerith::shutdown_world() { world_running = false; if (world_thread && world_thread->joinable()) world_thread->join(); world_thread.reset(); }