eco2d/code/game/source/packets/pkt_01_welcome.c

43 lines
1.7 KiB
C
Raw Normal View History

2021-05-05 13:14:02 +00:00
#include "packets/pkt_01_welcome.h"
#include "packet.h"
2021-05-05 09:25:05 +00:00
#include "world/world.h"
2021-05-04 19:45:51 +00:00
#include "game.h"
2021-05-05 09:25:05 +00:00
#include "entity_view.h"
2021-05-05 10:14:52 +00:00
#include "camera.h"
2021-05-05 09:25:05 +00:00
2021-05-04 11:04:15 +00:00
pkt_desc pkt_01_welcome_desc[] = {
2021-05-05 09:25:05 +00:00
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, ent_id) },
2021-05-04 17:39:50 +00:00
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, block_size) },
2021-05-03 23:57:19 +00:00
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, chunk_size) },
2021-05-04 17:39:50 +00:00
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, world_size) },
2021-05-03 23:57:19 +00:00
{ PKT_END },
};
2021-05-03 22:44:39 +00:00
2021-05-04 11:04:15 +00:00
size_t pkt_01_welcome_encode(pkt_01_welcome *table) {
cw_pack_context pc = {0};
2021-05-04 21:12:32 +00:00
pkt_pack_msg(&pc, pkt_pack_desc_args(pkt_01_welcome_desc));
2021-05-04 11:04:15 +00:00
pkt_pack_struct(&pc, pkt_01_welcome_desc, PKT_STRUCT_PTR(table));
return pkt_pack_msg_size(&pc);
}
2021-05-06 15:30:38 +00:00
size_t pkt_01_welcome_send(uint64_t peer_id,
uint16_t view_id,
uint64_t ent_id,
uint16_t block_size,
uint16_t chunk_size,
uint16_t world_size) {
pkt_01_welcome table = {.ent_id = ent_id, .block_size = block_size, .chunk_size = chunk_size, .world_size = world_size};
return pkt_world_write(MSG_ID_01_WELCOME, pkt_01_welcome_encode(&table), 1, view_id, (void*)peer_id);
}
2021-05-04 11:04:15 +00:00
2021-05-03 22:44:39 +00:00
int32_t pkt_01_welcome_handler(pkt_header *header) {
pkt_01_welcome table;
2021-05-04 21:12:32 +00:00
PKT_IF(pkt_msg_decode(header, pkt_01_welcome_desc, pkt_pack_desc_args(pkt_01_welcome_desc), PKT_STRUCT_PTR(&table)));
2021-05-05 09:25:05 +00:00
2021-05-06 15:30:38 +00:00
world_view *view = game_world_view_get(header->view_id);
zpl_printf("[INFO] initializing read-only world view ...\n");
world_view_init(view, table.ent_id, table.block_size, table.chunk_size, table.world_size);
2021-05-07 11:47:45 +00:00
game_world_view_set_active(view);
2021-05-03 22:44:39 +00:00
return 0;
}