56 lines
980 B
C++
56 lines
980 B
C++
#include <deerith/engine.h>
|
|
#include <deerith/server/world.h>
|
|
|
|
#include <deerith/server/internals/world.h>
|
|
#include <deerith/server/internals/network.h>
|
|
|
|
#include <deerith/world/world_core.h>
|
|
|
|
namespace deerith
|
|
{
|
|
void server_loop();
|
|
void init_world();
|
|
|
|
world_settings_t world_settings;
|
|
}
|
|
|
|
void deerith::run_world(const world_settings_t &__world_settings)
|
|
{
|
|
world_settings = __world_settings;
|
|
if (!init_server(world_settings.port))
|
|
{
|
|
deerith_error("could not init server");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
deerith_trace("server init on port {}", world_settings.port);
|
|
}
|
|
|
|
init_world();
|
|
|
|
while (true)
|
|
{
|
|
server_loop();
|
|
}
|
|
|
|
shutdown_world();
|
|
}
|
|
|
|
void deerith::server_loop()
|
|
{
|
|
flush_network_events();
|
|
|
|
// process movments
|
|
update_players_characters();
|
|
|
|
if (get_world_tick() % 2 == 0)
|
|
{
|
|
send_clients_environment_data();
|
|
|
|
send_entity_data();
|
|
}
|
|
|
|
wait_till_next_tick();
|
|
}
|