entity_view + packets changes
parent
3af10cd782
commit
c679773e51
|
@ -7,3 +7,7 @@ function(link_system_libs target_name)
|
|||
target_link_libraries(${target_name} pthread m dl atomic)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
macro(populate_pkt_srcs)
|
||||
file(GLOB PKT_SRCS ../../common/packets/*.h ../../common/packets/*.c)
|
||||
endmacro()
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
include(FindRaylib.cmake)
|
||||
|
||||
populate_pkt_srcs()
|
||||
add_library(client-common STATIC
|
||||
source/network.c
|
||||
source/game.c
|
||||
source/main.c
|
||||
source/entity_view.c
|
||||
|
||||
source/utils/options.c
|
||||
|
||||
header/network.h
|
||||
${PKT_SRCS}
|
||||
)
|
||||
|
||||
add_executable(eco2d-client
|
||||
|
@ -17,6 +21,7 @@ add_executable(eco2d-cli
|
|||
source/platform_text.c
|
||||
)
|
||||
|
||||
target_compile_definitions(client-common PRIVATE CLIENT)
|
||||
set(LIBS client-common cwpack eco2d-common eco2d-modules flecs-bundle)
|
||||
|
||||
include_directories(header ../../modules)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
#include "system.h"
|
||||
|
||||
#define ZPL_PICO
|
||||
#include "zpl.h"
|
||||
|
||||
typedef struct entity_view {
|
||||
double X;
|
||||
double Y;
|
||||
} entity_view;
|
||||
|
||||
ZPL_TABLE_DECLARE(, entity_view_tbl, entity_view_tbl_, entity_view);
|
||||
|
||||
void entity_view_init(void);
|
||||
void entity_view_free(void);
|
||||
|
||||
void entity_view_update_or_create(uint64_t ent_id, entity_view data);
|
||||
void entity_view_destroy(uint64_t ent_id);
|
||||
|
||||
entity_view *entity_view_get(uint64_t ent_id);
|
||||
void entity_view_map(void (*map_proc)(uint64_t key, entity_view value));
|
|
@ -0,0 +1,30 @@
|
|||
#include "entity_view.h"
|
||||
|
||||
ZPL_TABLE_DEFINE(entity_view_tbl, entity_view_tbl_, entity_view);
|
||||
|
||||
static entity_view_tbl cli_entities = {0};
|
||||
|
||||
|
||||
void entity_view_init(void) {
|
||||
entity_view_tbl_init(&cli_entities, zpl_heap());
|
||||
}
|
||||
|
||||
void entity_view_free(void) {
|
||||
entity_view_tbl_destroy(&cli_entities);
|
||||
}
|
||||
|
||||
void entity_view_update_or_create(uint64_t ent_id, entity_view data) {
|
||||
entity_view_tbl_set(&cli_entities, ent_id, data);
|
||||
}
|
||||
|
||||
void entity_view_destroy(uint64_t ent_id) {
|
||||
entity_view_tbl_remove(&cli_entities, ent_id);
|
||||
}
|
||||
|
||||
entity_view *entity_view_get(uint64_t ent_id) {
|
||||
return entity_view_tbl_get(&cli_entities, ent_id);
|
||||
}
|
||||
|
||||
void entity_view_map(void (*map_proc)(uint64_t key, entity_view value)) {
|
||||
entity_view_tbl_map(&cli_entities, map_proc);
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
#include "game.h"
|
||||
#include "platform.h"
|
||||
#include "world/world.h"
|
||||
#include "packets/packet.h"
|
||||
#include "packet.h"
|
||||
#include "signal_handling.h"
|
||||
#include "network.h"
|
||||
#include "entity_view.h"
|
||||
|
||||
#include "flecs/flecs.h"
|
||||
#include "flecs/flecs_dash.h"
|
||||
|
@ -41,6 +42,7 @@ static WORLD_PKT_WRITER(mp_pkt_writer) {
|
|||
void game_init(int8_t play_mode, int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size) {
|
||||
is_networked_play = play_mode;
|
||||
platform_init();
|
||||
entity_view_init();
|
||||
|
||||
if (is_networked_play) {
|
||||
world_init_minimal(0, 0, 0, pkt_reader, mp_pkt_writer);
|
||||
|
@ -61,7 +63,7 @@ void game_init(int8_t play_mode, int32_t seed, uint16_t block_size, uint16_t chu
|
|||
|
||||
sp_player = player_spawn("unnamed");
|
||||
|
||||
pkt_01_welcome table = {.block_size = block_size, .chunk_size = chunk_size, .world_size = world_size};
|
||||
pkt_01_welcome table = {.ent_id = 0, .block_size = block_size, .chunk_size = chunk_size, .world_size = world_size};
|
||||
pkt_world_write(MSG_ID_01_WELCOME, pkt_01_welcome_encode(&table), 1, NULL);
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +73,8 @@ int8_t game_is_networked() {
|
|||
}
|
||||
|
||||
void game_shutdown() {
|
||||
entity_view_free();
|
||||
|
||||
if (is_networked_play) {
|
||||
network_client_disconnect();
|
||||
network_destroy();
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "librg.h"
|
||||
|
||||
#include "network.h"
|
||||
#include "packets/packet.h"
|
||||
#include "packet.h"
|
||||
|
||||
#define NETWORK_UPDATE_DELAY 0.100
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "platform.h"
|
||||
#include "raylib.h"
|
||||
#include "network.h"
|
||||
#include "game.h"
|
||||
#include "entity_view.h"
|
||||
|
||||
const uint16_t screenWidth = 800;
|
||||
const uint16_t screenHeight = 450;
|
||||
|
@ -20,10 +22,12 @@ uint8_t platform_is_running() {
|
|||
|
||||
void display_conn_status();
|
||||
|
||||
void DEBUG_draw_entities(uint64_t key, entity_view data);
|
||||
|
||||
void platform_render() {
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
DrawText("NOBODY EXPECTS SPANISH INQUISITION!", 190, 200, 20, RED);
|
||||
entity_view_map(DEBUG_draw_entities);
|
||||
display_conn_status();
|
||||
EndDrawing();
|
||||
}
|
||||
|
@ -39,3 +43,7 @@ void display_conn_status() {
|
|||
DrawText("Connection: single-player", 5, 5, 12, BLUE);
|
||||
}
|
||||
}
|
||||
|
||||
void DEBUG_draw_entities(uint64_t key, entity_view data) {
|
||||
DrawCircle(data.X, data.Y, 15.0f, RAYWHITE);
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
populate_pkt_srcs()
|
||||
add_executable(playground
|
||||
source/main.c
|
||||
source/game.c
|
||||
|
||||
${PKT_SRCS}
|
||||
)
|
||||
|
||||
include_directories(header ../modules ../common)
|
||||
|
|
|
@ -1,13 +1,4 @@
|
|||
#include "game.h"
|
||||
#include "platform.h"
|
||||
#include "world/world.h"
|
||||
#include "packets/packet.h"
|
||||
#include "signal_handling.h"
|
||||
|
||||
#include "flecs/flecs.h"
|
||||
#include "flecs/flecs_dash.h"
|
||||
#include "flecs/flecs_systems_civetweb.h"
|
||||
#include "flecs/flecs_os_api_stdcpp.h"
|
||||
|
||||
void game_init(int8_t play_mode, int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size) {
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
#define LIBRG_CUSTOM_ZPL
|
||||
#include "librg.h"
|
||||
|
||||
#include "packets/packet.h"
|
||||
#include "packet.h"
|
||||
#include "game.h"
|
||||
|
||||
int32_t mock_pkt_decode(pkt_desc *desc, uint32_t args, size_t msg_size, void *data, uint32_t size) {
|
||||
pkt_header header = {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
populate_pkt_srcs()
|
||||
add_executable(eco2d-server
|
||||
source/main.c
|
||||
source/network.c
|
||||
|
@ -6,6 +7,8 @@ add_executable(eco2d-server
|
|||
|
||||
header/network.h
|
||||
header/utils/options.h
|
||||
|
||||
${PKT_SRCS}
|
||||
)
|
||||
|
||||
include_directories(header ../../modules)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "game.h"
|
||||
#include "platform.h"
|
||||
#include "world/world.h"
|
||||
#include "packets/packet.h"
|
||||
#include "packet.h"
|
||||
#include "signal_handling.h"
|
||||
#include "network.h"
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include "system.h"
|
||||
#include "network.h"
|
||||
#include "packets/packet.h"
|
||||
#include "packet.h"
|
||||
#include "world/world.h"
|
||||
|
||||
#include "player.h"
|
||||
|
@ -86,7 +86,7 @@ int32_t network_server_tick(void) {
|
|||
// TODO: Make sure ent_id does not get truncated with large entity numbers.
|
||||
event.peer->data = (void*)((uint32_t)ent_id);
|
||||
|
||||
pkt_01_welcome table = {.block_size = world_block_size(), .chunk_size = world_chunk_size(), .world_size = world_world_size()};
|
||||
pkt_01_welcome table = {.ent_id = ent_id, .block_size = world_block_size(), .chunk_size = world_chunk_size(), .world_size = world_world_size()};
|
||||
pkt_world_write(MSG_ID_01_WELCOME, pkt_01_welcome_encode(&table), 1, event.peer);
|
||||
} break;
|
||||
case ENET_EVENT_TYPE_DISCONNECT:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
file(GLOB SRCS *.h *.c packets/*.c packets/*.h world/*.h)
|
||||
file(GLOB SRCS *.h *.c packets/*.h world/*.h)
|
||||
set(SRCS ${SRCS}
|
||||
world/blocks.c
|
||||
world/perlin.c
|
||||
|
|
|
@ -34,4 +34,4 @@ extern uint8_t pkt_buffer[];
|
|||
|
||||
// NOTE(zaklaus): packets
|
||||
|
||||
#include "pkt_01_welcome.h"
|
||||
#include "packets/pkt_01_welcome.h"
|
|
@ -1,9 +1,14 @@
|
|||
#include "pkt_01_welcome.h"
|
||||
#include "packet_utils.h"
|
||||
#include "world.h"
|
||||
#include "world/world.h"
|
||||
#include "game.h"
|
||||
|
||||
#ifdef CLIENT
|
||||
#include "entity_view.h"
|
||||
#endif
|
||||
|
||||
pkt_desc pkt_01_welcome_desc[] = {
|
||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, ent_id) },
|
||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, block_size) },
|
||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, chunk_size) },
|
||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, world_size) },
|
||||
|
@ -21,10 +26,13 @@ int32_t pkt_01_welcome_handler(pkt_header *header) {
|
|||
pkt_01_welcome table;
|
||||
PKT_IF(pkt_msg_decode(header, pkt_01_welcome_desc, pkt_pack_desc_args(pkt_01_welcome_desc), PKT_STRUCT_PTR(&table)));
|
||||
|
||||
zpl_printf("we received: block_size: %d, chunk_size: %d and world_size: %d\n", table.block_size, table.chunk_size, table.world_size);
|
||||
|
||||
#ifdef CLIENT
|
||||
if (game_is_networked()) {
|
||||
zpl_printf("[INFO] initializing read-only world view ...\n");
|
||||
world_init_minimal(table.block_size, table.chunk_size, table.world_size, NULL, NULL);
|
||||
}
|
||||
|
||||
entity_view_update_or_create(table.ent_id, (entity_view){0});
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "packet_utils.h"
|
||||
|
||||
typedef struct {
|
||||
uint64_t ent_id;
|
||||
uint16_t block_size;
|
||||
uint16_t chunk_size;
|
||||
uint16_t world_size;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include "system.h"
|
||||
#include "librg.h"
|
||||
#include "packets/packet.h"
|
||||
#include "packet.h"
|
||||
#include "flecs/flecs.h"
|
||||
|
||||
#define WORLD_ERROR_NONE +0x0000
|
||||
|
|
|
@ -15,6 +15,7 @@ patterns =
|
|||
"*.sh",
|
||||
"*.4coder",
|
||||
"*.txt",
|
||||
"*.cmake",
|
||||
};
|
||||
|
||||
blacklist_patterns =
|
||||
|
|
Loading…
Reference in New Issue