eco2d/code/common/packets/pkt_send_keystate.c

44 lines
1.4 KiB
C
Raw Normal View History

2021-05-05 13:14:02 +00:00
#include "packet_utils.h"
#include "packets/pkt_send_keystate.h"
2021-05-07 14:43:54 +00:00
#include "modules/controllers.h"
#include "world/world.h"
2021-05-05 13:14:02 +00:00
pkt_desc pkt_send_keystate_desc[] = {
2021-05-07 14:43:54 +00:00
{ PKT_REAL(pkt_send_keystate, x) },
{ PKT_REAL(pkt_send_keystate, y) },
{ PKT_UINT(pkt_send_keystate, use) },
2021-05-05 13:14:02 +00:00
{ PKT_END },
};
2021-05-07 14:43:54 +00:00
size_t pkt_send_keystate_send(uint16_t view_id,
double x,
double y,
uint8_t use) {
pkt_send_keystate table = { .x = x, .y = y, .use = use };
return pkt_world_write(MSG_ID_SEND_KEYSTATE, pkt_send_keystate_encode(&table), 1, view_id, NULL);
}
2021-05-05 13:14:02 +00:00
size_t pkt_send_keystate_encode(pkt_send_keystate *table) {
cw_pack_context pc = {0};
pkt_pack_msg(&pc, pkt_pack_desc_args(pkt_send_keystate_desc));
pkt_pack_struct(&pc, pkt_send_keystate_desc, PKT_STRUCT_PTR(table));
return pkt_pack_msg_size(&pc);
}
int32_t pkt_send_keystate_handler(pkt_header *header) {
pkt_send_keystate table;
PKT_IF(pkt_msg_decode(header, pkt_send_keystate_desc, pkt_pack_desc_args(pkt_send_keystate_desc), PKT_STRUCT_PTR(&table)));
2021-05-07 14:43:54 +00:00
ecs_entity_t e = PKT_GET_ENT(header);
ecs_world_t *ecs = world_ecs();
ECS_IMPORT(ecs, Controllers);
Input *i = ecs_get_mut(world_ecs(), e, Input, NULL);
if (i) {
i->x = table.x;
i->y = table.y;
i->use = table.use;
}
2021-05-05 13:14:02 +00:00
return 0;
}