62 lines
1.1 KiB
C++
62 lines
1.1 KiB
C++
#include <deerith/server/world.h>
|
|
#include <deerith/core/log.h>
|
|
#include <deerith/network/router.h>
|
|
|
|
#include <deerith/server/network/network_internals.h>
|
|
#include <deerith/server/world/world_internals.h>
|
|
|
|
#include <deerith/world/components.h>
|
|
#include <deerith/network/packets.h>
|
|
|
|
#include <csignal>
|
|
#include <atomic>
|
|
|
|
namespace deerith
|
|
{
|
|
int world_tick = 0;
|
|
void world_simulation();
|
|
|
|
std::atomic<bool> running = true;
|
|
|
|
void create_client(ENetPeer *peer);
|
|
void handle_signal(int signal);
|
|
}
|
|
|
|
void deerith::handle_signal(int signal)
|
|
{
|
|
if (signal == SIGTERM)
|
|
running = false;
|
|
}
|
|
|
|
void deerith::run_world(int port)
|
|
{
|
|
std::signal(SIGTERM, handle_signal);
|
|
|
|
if (!init_server(port))
|
|
{
|
|
deerith_error("could not init server");
|
|
return;
|
|
}
|
|
|
|
deerith_trace("server init on port {}", port);
|
|
while (running)
|
|
{
|
|
world_simulation();
|
|
}
|
|
}
|
|
|
|
void deerith::world_simulation()
|
|
{
|
|
flush_network_events();
|
|
|
|
// process movments
|
|
update_players_characters();
|
|
|
|
if (get_world_tick() % 2 == 0)
|
|
{
|
|
send_entity_data();
|
|
}
|
|
|
|
wait_till_next_tick();
|
|
}
|