43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#include <deerith/engine.h>
|
|
#include <deerith/graphics/input.h>
|
|
#include <deerith/graphics/window.h>
|
|
#include <deerith/network/router.h>
|
|
#include <deerith/network/packets.h>
|
|
#include <deerith/world/entity.h>
|
|
|
|
#include "world/world_internals.h"
|
|
|
|
namespace deerith
|
|
{
|
|
|
|
}
|
|
|
|
void deerith::process_player_input()
|
|
{
|
|
if (self_entity == entt::null)
|
|
return;
|
|
|
|
glm::vec2 movment = get_joystick_axes(0, 0);
|
|
if (!is_windows_focused())
|
|
{
|
|
movment = glm::vec2(0, 0);
|
|
}
|
|
|
|
entity_sync_client_position_t &entity_sync_position = get_component<entity_sync_client_position_t>(self_entity);
|
|
|
|
entity_sync_position.move_input = movment;
|
|
entity_sync_position.position = entity_sync_position.position.read_value() + movment * 0.1f;
|
|
}
|
|
|
|
void deerith::send_player_input()
|
|
{
|
|
if (self_entity == entt::null)
|
|
return;
|
|
entity_sync_client_position_t &entity_sync_position = get_component<entity_sync_client_position_t>(self_entity);
|
|
|
|
sync_entity_player_position_packet_t packet{};
|
|
packet.input_transport.load(entity_sync_position.move_input);
|
|
packet.position_transport.load(entity_sync_position.position);
|
|
|
|
router_send_packet(packet, get_server_client());
|
|
} |