44 lines
1.5 KiB
C++
44 lines
1.5 KiB
C++
#include <deerith/server/world/world_internals.h>
|
|
|
|
#include <deerith/server/world.h>
|
|
#include <deerith/world/components.h>
|
|
#include <deerith/network/packets.h>
|
|
#include <deerith/network/router.h>
|
|
|
|
void deerith::update_players_characters()
|
|
{
|
|
auto view = get_entity_registry().view<component_player_sync_input_t, component_client_link_t, component_sync_coordinates_t>();
|
|
|
|
for (auto [entity, position_input, client, sync_coords] : view.each())
|
|
{
|
|
glm::vec2 ps{};
|
|
if (position_input.position.read_synced(ps))
|
|
{
|
|
sync_coords.position = ps;
|
|
}
|
|
else
|
|
{
|
|
sync_coords.position = sync_coords.position;
|
|
}
|
|
}
|
|
}
|
|
|
|
void deerith::send_entity_data()
|
|
{
|
|
packet_update_entities_coordinates_t sync_entities_coordinates;
|
|
|
|
auto coordinates_view = get_entity_registry().view<component_network_id_t, component_sync_coordinates_t>();
|
|
for (auto [entity, network_id, sync_coords] : coordinates_view.each())
|
|
{
|
|
sync_entities_coordinates.entities_ids.push_back(network_id.network_id);
|
|
sync_entities_coordinates.positions_to_update.push_back({});
|
|
sync_variable_transport_t<glm::vec2> &position_trasport = sync_entities_coordinates.positions_to_update.back();
|
|
position_trasport.load(sync_coords.position);
|
|
}
|
|
|
|
auto clients_view = get_entity_registry().view<component_client_link_t>();
|
|
for (auto [entity, client] : clients_view.each())
|
|
{
|
|
router_send_packet(sync_entities_coordinates, client.client);
|
|
}
|
|
} |