various improvements + release build fix

isolation_bkp/dynres
Dominik Madarász 2022-09-13 10:02:36 +00:00 committed by GitHub
parent e3f56ffa46
commit 05144764bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 86 additions and 76 deletions

View File

@ -15,7 +15,7 @@ if(MSVC)
endif() endif()
if (EMSCRIPTEN) if (EMSCRIPTEN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -D_DEBUG") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g -s USE_GLFW=3 --profiling -s ASSERTIONS=1 -s WASM=1 -s INITIAL_MEMORY=268435456 -s FORCE_FILESYSTEM=1 --preload-file ${CMAKE_SOURCE_DIR}/art@art/ --shell-file ${CMAKE_SOURCE_DIR}/web/eco2d.html") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g -s USE_GLFW=3 --profiling -s ASSERTIONS=1 -s WASM=1 -s INITIAL_MEMORY=268435456 -s FORCE_FILESYSTEM=1 --preload-file ${CMAKE_SOURCE_DIR}/art@art/ --shell-file ${CMAKE_SOURCE_DIR}/web/eco2d.html")
set(CMAKE_EXECUTABLE_SUFFIX ".html") # This line is used to set your executable to build with the emscripten html template so that you can directly open it. set(CMAKE_EXECUTABLE_SUFFIX ".html") # This line is used to set your executable to build with the emscripten html template so that you can directly open it.
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)

View File

@ -42,5 +42,6 @@ add_executable(eco2d
target_compile_definitions(eco2d PRIVATE CLIENT) target_compile_definitions(eco2d PRIVATE CLIENT)
include_directories(src ../modules ../../art/gen) include_directories(src ../modules ../../art/gen)
target_link_libraries(eco2d raylib cwpack eco2d-modules flecs-bundle vendors-bundle) target_link_libraries(eco2d raylib cwpack eco2d-modules flecs-bundle vendors-bundle)
target_compile_options(eco2d PRIVATE -Werror -Wall -Wextra -Wno-unused-function -Wno-unknown-pragmas -Wno-unused-variable -Wno-unused-parameter)
link_system_libs(eco2d) link_system_libs(eco2d)

View File

@ -87,7 +87,7 @@ void entity_update_action_timers() {
while (ecs_query_next(&it)) { while (ecs_query_next(&it)) {
StreamInfo *si = ecs_field(&it, StreamInfo, 1); StreamInfo *si = ecs_field(&it, StreamInfo, 1);
for (size_t i = 0; i < it.count; i++) { for (int32_t i = 0; i < it.count; i++) {
if (si[i].last_update < zpl_time_rel()) { if (si[i].last_update < zpl_time_rel()) {
si[i].last_update = zpl_time_rel() + si[i].tick_delay; si[i].last_update = zpl_time_rel() + si[i].tick_delay;
si[i].tick_delay += (zpl_time_rel() - last_update_time) * 0.5f; si[i].tick_delay += (zpl_time_rel() - last_update_time) * 0.5f;

View File

@ -73,7 +73,7 @@ void world_viewers_init(uint32_t num_viewers) {
} }
void world_viewers_destroy() { void world_viewers_destroy() {
for (uint32_t i = 0; i < zpl_buffer_count(world_viewers); i++) { for (zpl_isize i = 0; i < zpl_buffer_count(world_viewers); i++) {
world_view_destroy(&world_viewers[i]); world_view_destroy(&world_viewers[i]);
} }
zpl_buffer_free(world_viewers); zpl_buffer_free(world_viewers);

View File

@ -45,7 +45,7 @@ void buildmode_draw(void) {
ItemDrop *item = &e->items[e->selected_item]; ItemDrop *item = &e->items[e->selected_item];
if (e->has_items && !e->inside_vehicle && item->quantity > 0 && !is_outside_range || build_is_deletion_mode) { if (e->has_items && !e->inside_vehicle && item->quantity > 0 && (!is_outside_range || build_is_deletion_mode)) {
item_usage usage = 0; item_usage usage = 0;
uint16_t item_id = 0; uint16_t item_id = 0;
if (!build_is_deletion_mode){ if (!build_is_deletion_mode){
@ -127,4 +127,4 @@ void buildmode_draw(void) {
} }
} }
} }

View File

@ -105,6 +105,7 @@ int32_t pkt_unpack_struct(cw_unpack_context *uc, pkt_desc *desc, void *raw_blob,
} }
int32_t pkt_pack_struct(cw_pack_context *pc, pkt_desc *desc, void *raw_blob, uint32_t blob_size) { int32_t pkt_pack_struct(cw_pack_context *pc, pkt_desc *desc, void *raw_blob, uint32_t blob_size) {
(void)blob_size;
uint8_t *blob = (uint8_t*)raw_blob; uint8_t *blob = (uint8_t*)raw_blob;
for (pkt_desc *field = desc; field->type != CWP_NOT_AN_ITEM; ++field) { for (pkt_desc *field = desc; field->type != CWP_NOT_AN_ITEM; ++field) {
if (field->skip_count != 0) { if (field->skip_count != 0) {
@ -158,6 +159,7 @@ int32_t pkt_pack_struct(cw_pack_context *pc, pkt_desc *desc, void *raw_blob, uin
} }
void pkt_dump_struct(pkt_desc *desc, void* raw_blob, uint32_t blob_size) { void pkt_dump_struct(pkt_desc *desc, void* raw_blob, uint32_t blob_size) {
(void)blob_size;
uint8_t *blob = (uint8_t*)raw_blob; uint8_t *blob = (uint8_t*)raw_blob;
zpl_printf("{\n"); zpl_printf("{\n");
for (pkt_desc *field = desc; field->type != CWP_NOT_AN_ITEM; ++field) { for (pkt_desc *field = desc; field->type != CWP_NOT_AN_ITEM; ++field) {

View File

@ -30,7 +30,7 @@ int32_t pkt_00_init_handler(pkt_header *header) {
Position *pos = ecs_get_mut(world_ecs(), ent_id, Position); Position *pos = ecs_get_mut(world_ecs(), ent_id, Position);
#if 0 #if 1
pos->x = world_dim()/2.0f + rand()%15*15.0f; pos->x = world_dim()/2.0f + rand()%15*15.0f;
pos->y = world_dim()/2.0f + rand()%15*15.0f; pos->y = world_dim()/2.0f + rand()%15*15.0f;
#else #else

View File

@ -29,7 +29,7 @@ int32_t pkt_01_welcome_handler(pkt_header *header) {
world_view *view = game_world_view_get(header->view_id); world_view *view = game_world_view_get(header->view_id);
zpl_printf("[INFO] initializing read-only world view id: %d...\n", header->view_id); zpl_printf("[INFO] initializing read-only world view id: %d... (chunk_size: %d, world_size: %d)\n", header->view_id, table.chunk_size, table.world_size);
world_view_init(view, table.seed, table.ent_id, table.chunk_size, table.world_size); world_view_init(view, table.seed, table.ent_id, table.chunk_size, table.world_size);
game_world_view_set_active(view); game_world_view_set_active(view);
return 0; return 0;

View File

@ -25,6 +25,7 @@ static BOOL WINAPI _sighandler_win32_control_handler(DWORD control_type)
#else //POSIX complaint #else //POSIX complaint
#include <sys/types.h> #include <sys/types.h>
static void _sighandler_posix_signal_handler(int sig) { static void _sighandler_posix_signal_handler(int sig) {
(void)sig;
game_request_close(); game_request_close();
} }
#endif #endif

View File

@ -5,6 +5,7 @@
#include "utils/options.h" #include "utils/options.h"
void generate_minimap(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size) { void generate_minimap(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size) {
(void)block_size;
world_init(seed, chunk_size, world_size); world_init(seed, chunk_size, world_size);
block_id const *world; block_id const *world;

View File

@ -157,6 +157,12 @@ void EcoDrawCube(Vector3 position, float width, float height, float length, floa
// Draw codepoint at specified position in 3D space // Draw codepoint at specified position in 3D space
void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, float fontSize, bool backface, Color tint) void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, float fontSize, bool backface, Color tint)
{ {
(void)font;
(void)codepoint;
(void)position;
(void)fontSize;
(void)backface;
(void)tint;
#if 0 #if 0
// Character index position in sprite font // Character index position in sprite font
// NOTE: In case a codepoint is not available in the font, index returned points to '?' // NOTE: In case a codepoint is not available in the font, index returned points to '?'

View File

@ -22,80 +22,80 @@ static world_snapshot streamer_snapshot;
entity_view world_build_entity_view(int64_t e) { entity_view world_build_entity_view(int64_t e) {
entity_view *cached_ev = world_snapshot_get(&streamer_snapshot, e); entity_view *cached_ev = world_snapshot_get(&streamer_snapshot, e);
if (cached_ev) return *cached_ev; if (cached_ev) return *cached_ev;
entity_view view = {0}; entity_view view = {0};
const Classify *classify = ecs_get(world_ecs(), e, Classify); const Classify *classify = ecs_get(world_ecs(), e, Classify);
ZPL_ASSERT(classify); ZPL_ASSERT(classify);
view.kind = classify->id; view.kind = classify->id;
const Position *pos = ecs_get(world_ecs(), e, Position); const Position *pos = ecs_get(world_ecs(), e, Position);
if (pos) { if (pos) {
view.x = pos->x; view.x = pos->x;
view.y = pos->y; view.y = pos->y;
} }
const Velocity *vel = ecs_get(world_ecs(), e, Velocity); const Velocity *vel = ecs_get(world_ecs(), e, Velocity);
if (vel) { if (vel) {
view.flag |= EFLAG_INTERP; view.flag |= EFLAG_INTERP;
view.vx = vel->x; view.vx = vel->x;
view.vy = vel->y; view.vy = vel->y;
} }
const Health *health = ecs_get(world_ecs(), e, Health); const Health *health = ecs_get(world_ecs(), e, Health);
if (health) { if (health) {
view.hp = health->hp; view.hp = health->hp;
view.max_hp = health->max_hp; view.max_hp = health->max_hp;
} }
if (ecs_get(world_ecs(), e, Vehicle)) { if (ecs_get(world_ecs(), e, Vehicle)) {
Vehicle const* veh = ecs_get(world_ecs(), e, Vehicle); Vehicle const* veh = ecs_get(world_ecs(), e, Vehicle);
view.heading = veh->heading; view.heading = veh->heading;
} }
if (ecs_get(world_ecs(), e, ItemDrop)) { if (ecs_get(world_ecs(), e, ItemDrop)) {
ItemDrop const* dr = ecs_get(world_ecs(), e, ItemDrop); ItemDrop const* dr = ecs_get(world_ecs(), e, ItemDrop);
view.asset = dr->kind; view.asset = dr->kind;
view.quantity = dr->quantity; view.quantity = dr->quantity;
} }
if (ecs_get(world_ecs(), e, Device)) { if (ecs_get(world_ecs(), e, Device)) {
Device const* dev = ecs_get(world_ecs(), e, Device); Device const* dev = ecs_get(world_ecs(), e, Device);
view.asset = dev->asset; view.asset = dev->asset;
} }
view.inside_vehicle = ecs_get(world_ecs(), e, IsInVehicle) != 0 ? true : false; view.inside_vehicle = ecs_get(world_ecs(), e, IsInVehicle) != 0 ? true : false;
Inventory *inv = 0; Inventory *inv = 0;
if ((inv = ecs_get_mut_if(world_ecs(), e, Inventory))) { if ((inv = ecs_get_mut_if(world_ecs(), e, Inventory))) {
view.has_items = true; view.has_items = true;
for (int i = 0; i < ITEMS_INVENTORY_SIZE; i += 1) { for (int i = 0; i < ITEMS_INVENTORY_SIZE; i += 1) {
view.items[i] = inv->items[i]; view.items[i] = inv->items[i];
} }
const Input *in = ecs_get(world_ecs(), e, Input); const Input *in = ecs_get(world_ecs(), e, Input);
if (in){ if (in){
view.selected_item = in->selected_item; view.selected_item = in->selected_item;
view.pick_ent = (uint64_t)in->pick_ent; view.pick_ent = (uint64_t)in->pick_ent;
view.sel_ent = (uint64_t)in->sel_ent; view.sel_ent = (uint64_t)in->sel_ent;
if (world_entity_valid(in->storage_ent)){ if (world_entity_valid(in->storage_ent)){
ItemContainer *ic = 0; ItemContainer *ic = 0;
if ((ic = ecs_get_mut_if(world_ecs(), in->storage_ent, ItemContainer))){ if ((ic = ecs_get_mut_if(world_ecs(), in->storage_ent, ItemContainer))){
view.has_storage_items = true; view.has_storage_items = true;
for (int i = 0; i < ITEMS_CONTAINER_SIZE; i += 1) { for (int i = 0; i < ITEMS_CONTAINER_SIZE; i += 1) {
view.storage_items[i] = ic->items[i]; view.storage_items[i] = ic->items[i];
} }
view.storage_selected_item = in->storage_selected_item; view.storage_selected_item = in->storage_selected_item;
} }
} }
} }
} }
Chunk *chunk = 0; Chunk *chunk = 0;
if ((chunk = ecs_get_mut_if(world_ecs(), e, Chunk))) { if ((chunk = ecs_get_mut_if(world_ecs(), e, Chunk))) {
view.x = chunk->x; view.x = chunk->x;
@ -103,16 +103,16 @@ entity_view world_build_entity_view(int64_t e) {
view.blocks_used = 1; view.blocks_used = 1;
view.is_dirty = chunk->is_dirty; view.is_dirty = chunk->is_dirty;
chunk->is_dirty = false; chunk->is_dirty = false;
for (int i = 0; i < world.chunk_size*world.chunk_size; i += 1) { for (int i = 0; i < world.chunk_size*world.chunk_size; i += 1) {
view.blocks[i] = world.block_mapping[chunk->id][i]; view.blocks[i] = world.block_mapping[chunk->id][i];
} }
for (int i = 0; i < world.chunk_size*world.chunk_size; i += 1) { for (int i = 0; i < world.chunk_size*world.chunk_size; i += 1) {
view.outer_blocks[i] = world.outer_block_mapping[chunk->id][i]; view.outer_blocks[i] = world.outer_block_mapping[chunk->id][i];
} }
} }
world_snapshot_set(&streamer_snapshot, e, view); world_snapshot_set(&streamer_snapshot, e, view);
return view; return view;
} }
@ -127,7 +127,7 @@ int32_t tracker_write_create(librg_world *w, librg_event *e) {
#endif #endif
size_t actual_length = librg_event_size_get(w, e); size_t actual_length = librg_event_size_get(w, e);
char *buffer = librg_event_buffer_get(w, e); char *buffer = librg_event_buffer_get(w, e);
return (int32_t)entity_view_pack_struct(buffer, actual_length, world_build_entity_view(entity_id)); return (int32_t)entity_view_pack_struct(buffer, actual_length, world_build_entity_view(entity_id));
} }
@ -148,14 +148,14 @@ int32_t tracker_write_update(librg_world *w, librg_event *e) {
size_t actual_length = librg_event_size_get(w, e); size_t actual_length = librg_event_size_get(w, e);
char *buffer = librg_event_buffer_get(w, e); char *buffer = librg_event_buffer_get(w, e);
entity_view view = world_build_entity_view(entity_id); entity_view view = world_build_entity_view(entity_id);
// NOTE(zaklaus): exclude chunks from updates as they never move // NOTE(zaklaus): exclude chunks from updates as they never move
{ {
if (view.kind == EKIND_CHUNK && !view.is_dirty) { if (view.kind == EKIND_CHUNK && !view.is_dirty) {
return LIBRG_WRITE_REJECT; return LIBRG_WRITE_REJECT;
} }
} }
// NOTE(zaklaus): action-based updates // NOTE(zaklaus): action-based updates
#if ECO2D_STREAM_ACTIONFILTER #if ECO2D_STREAM_ACTIONFILTER
{ {
@ -164,7 +164,7 @@ int32_t tracker_write_update(librg_world *w, librg_event *e) {
} }
} }
#endif #endif
return (int32_t)entity_view_pack_struct(buffer, actual_length, view); return (int32_t)entity_view_pack_struct(buffer, actual_length, view);
} }
@ -187,15 +187,15 @@ void world_chunk_setup_grid(void) {
world.outer_block_mapping[i] = zpl_malloc(sizeof(block_id)*zpl_square(world.chunk_size)); world.outer_block_mapping[i] = zpl_malloc(sizeof(block_id)*zpl_square(world.chunk_size));
chunk->id = i; chunk->id = i;
chunk->is_dirty = false; chunk->is_dirty = false;
for (int y = 0; y < world.chunk_size; y += 1) { for (int y = 0; y < world.chunk_size; y += 1) {
for (int x = 0; x < world.chunk_size; x += 1) { for (int x = 0; x < world.chunk_size; x += 1) {
int chk_x = chunk->x * world.chunk_size; int chk_x = chunk->x * world.chunk_size;
int chk_y = chunk->y * world.chunk_size; int chk_y = chunk->y * world.chunk_size;
block_id *c = &world.block_mapping[i][(y*world.chunk_size)+x]; block_id *c = &world.block_mapping[i][(y*world.chunk_size)+x];
*c = world.data[(chk_y+y)*world.dim + (chk_x+x)]; *c = world.data[(chk_y+y)*world.dim + (chk_x+x)];
c = &world.outer_block_mapping[i][(y*world.chunk_size)+x]; c = &world.outer_block_mapping[i][(y*world.chunk_size)+x];
*c = world.outer_data[(chk_y+y)*world.dim + (chk_x+x)]; *c = world.outer_data[(chk_y+y)*world.dim + (chk_x+x)];
} }
@ -206,14 +206,14 @@ void world_chunk_setup_grid(void) {
static inline static inline
void world_configure_tracker(void) { void world_configure_tracker(void) {
world.tracker = librg_world_create(); world.tracker = librg_world_create();
ZPL_ASSERT_MSG(world.tracker, "[ERROR] An error occurred while trying to create a server world."); ZPL_ASSERT_MSG(world.tracker, "[ERROR] An error occurred while trying to create a server world.");
/* config our world grid */ /* config our world grid */
librg_config_chunksize_set(world.tracker, WORLD_BLOCK_SIZE * world.chunk_size, WORLD_BLOCK_SIZE * world.chunk_size, 0); librg_config_chunksize_set(world.tracker, WORLD_BLOCK_SIZE * world.chunk_size, WORLD_BLOCK_SIZE * world.chunk_size, 1);
librg_config_chunkamount_set(world.tracker, world.chunk_amount, world.chunk_amount, 0); librg_config_chunkamount_set(world.tracker, world.chunk_amount, world.chunk_amount, 0);
librg_config_chunkoffset_set(world.tracker, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG); librg_config_chunkoffset_set(world.tracker, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG);
librg_event_set(world.tracker, LIBRG_WRITE_CREATE, tracker_write_create); librg_event_set(world.tracker, LIBRG_WRITE_CREATE, tracker_write_create);
librg_event_set(world.tracker, LIBRG_WRITE_REMOVE, tracker_write_remove); librg_event_set(world.tracker, LIBRG_WRITE_REMOVE, tracker_write_remove);
librg_event_set(world.tracker, LIBRG_WRITE_UPDATE, tracker_write_update); librg_event_set(world.tracker, LIBRG_WRITE_UPDATE, tracker_write_update);
@ -223,14 +223,14 @@ static inline
void world_init_worldgen_data(void) { void world_init_worldgen_data(void) {
world.data = zpl_malloc(sizeof(block_id)*world.size); world.data = zpl_malloc(sizeof(block_id)*world.size);
world.outer_data = zpl_malloc(sizeof(block_id)*world.size); world.outer_data = zpl_malloc(sizeof(block_id)*world.size);
ZPL_ASSERT(world.data && world.outer_data); ZPL_ASSERT(world.data && world.outer_data);
} }
static inline static inline
void world_setup_ecs(void) { void world_setup_ecs(void) {
world.ecs = ecs_init(); world.ecs = ecs_init();
ECS_IMPORT(world.ecs, Components); ECS_IMPORT(world.ecs, Components);
ECS_IMPORT(world.ecs, Systems); ECS_IMPORT(world.ecs, Systems);
world.ecs_update = ecs_query_new(world.ecs, "components.ClientInfo, components.Position"); world.ecs_update = ecs_query_new(world.ecs, "components.ClientInfo, components.Position");
@ -249,7 +249,7 @@ static inline
void world_generate_instance(void) { void world_generate_instance(void) {
int32_t world_build_status = worldgen_test(&world); int32_t world_build_status = worldgen_test(&world);
ZPL_ASSERT(world_build_status >= 0); ZPL_ASSERT(world_build_status >= 0);
for (int i = 0; i < zpl_square(world.dim); ++i) { for (int i = 0; i < zpl_square(world.dim); ++i) {
if (world.data[i] == 0) { if (world.data[i] == 0) {
ZPL_PANIC("Worldgen failure! Block %d is unset!\n", i); ZPL_PANIC("Worldgen failure! Block %d is unset!\n", i);
@ -271,10 +271,10 @@ int32_t world_init(int32_t seed, uint16_t chunk_size, uint16_t chunk_amount) {
world.seed = seed; world.seed = seed;
world.chunk_size = chunk_size; world.chunk_size = chunk_size;
world.chunk_amount = chunk_amount; world.chunk_amount = chunk_amount;
world.dim = (world.chunk_size * world.chunk_amount); world.dim = (world.chunk_size * world.chunk_amount);
world.size = world.dim * world.dim; world.size = world.dim * world.dim;
world_configure_tracker(); world_configure_tracker();
world_setup_ecs(); world_setup_ecs();
world_init_worldgen_data(); world_init_worldgen_data();
@ -282,9 +282,9 @@ int32_t world_init(int32_t seed, uint16_t chunk_size, uint16_t chunk_amount) {
world_init_mapping(); world_init_mapping();
world_chunk_setup_grid(); world_chunk_setup_grid();
world_free_worldgen_data(); world_free_worldgen_data();
zpl_printf("[INFO] Created a new server world\n"); zpl_printf("[INFO] Created a new server world\n");
return WORLD_ERROR_NONE; return WORLD_ERROR_NONE;
} }
@ -309,33 +309,33 @@ int32_t world_destroy(void) {
static void world_tracker_update(uint8_t ticker, float freq, uint8_t radius) { static void world_tracker_update(uint8_t ticker, float freq, uint8_t radius) {
if (world.tracker_update[ticker] > (float)zpl_time_rel()) return; if (world.tracker_update[ticker] > (float)zpl_time_rel()) return;
world.tracker_update[ticker] = (float)zpl_time_rel() + freq; world.tracker_update[ticker] = (float)zpl_time_rel() + freq;
profile(PROF_WORLD_WRITE) { profile(PROF_WORLD_WRITE) {
ecs_iter_t it = ecs_query_iter(world_ecs(), world.ecs_update); ecs_iter_t it = ecs_query_iter(world_ecs(), world.ecs_update);
static char buffer[WORLD_LIBRG_BUFSIZ] = {0}; static char buffer[WORLD_LIBRG_BUFSIZ] = {0};
world.active_layer_id = ticker; world.active_layer_id = ticker;
while (ecs_query_next(&it)) { while (ecs_query_next(&it)) {
ClientInfo *p = ecs_field(&it, ClientInfo, 1); ClientInfo *p = ecs_field(&it, ClientInfo, 1);
for (int i = 0; i < it.count; i++) { for (int i = 0; i < it.count; i++) {
size_t datalen = WORLD_LIBRG_BUFSIZ; size_t datalen = WORLD_LIBRG_BUFSIZ;
if (!p[i].active) if (!p[i].active)
continue; continue;
int32_t result = librg_world_write(world_tracker(), it.entities[i], radius, buffer, &datalen, NULL); int32_t result = librg_world_write(world_tracker(), it.entities[i], radius, buffer, &datalen, NULL);
if (result > 0) { if (result > 0) {
zpl_printf("[info] buffer size was not enough, please increase it by at least: %d\n", result); zpl_printf("[info] buffer size was not enough, please increase it by at least: %d\n", result);
} else if (result < 0) { } else if (result < 0) {
zpl_printf("[error] an error happened writing the world %d\n", result); zpl_printf("[error] an error happened writing the world %d\n", result);
} }
pkt_send_librg_update((uint64_t)p[i].peer, p[i].view_id, ticker, buffer, datalen); pkt_send_librg_update((uint64_t)p[i].peer, p[i].view_id, ticker, buffer, datalen);
} }
} }
// NOTE(zaklaus): clear out our streaming snapshot // NOTE(zaklaus): clear out our streaming snapshot
// TODO(zaklaus): move this to zpl // TODO(zaklaus): move this to zpl
{ {
@ -349,21 +349,21 @@ int32_t world_update() {
profile (PROF_UPDATE_SYSTEMS) { profile (PROF_UPDATE_SYSTEMS) {
ecs_progress(world.ecs, 0.0f); ecs_progress(world.ecs, 0.0f);
} }
float fast_ms = WORLD_TRACKER_UPDATE_FAST_MS; float fast_ms = WORLD_TRACKER_UPDATE_FAST_MS;
float normal_ms = WORLD_TRACKER_UPDATE_NORMAL_MS; float normal_ms = WORLD_TRACKER_UPDATE_NORMAL_MS;
float slow_ms = WORLD_TRACKER_UPDATE_SLOW_MS; float slow_ms = WORLD_TRACKER_UPDATE_SLOW_MS;
if (game_get_kind() != GAMEKIND_SINGLE) { if (game_get_kind() != GAMEKIND_SINGLE) {
fast_ms = WORLD_TRACKER_UPDATE_MP_FAST_MS; fast_ms = WORLD_TRACKER_UPDATE_MP_FAST_MS;
normal_ms = WORLD_TRACKER_UPDATE_MP_NORMAL_MS; normal_ms = WORLD_TRACKER_UPDATE_MP_NORMAL_MS;
slow_ms = WORLD_TRACKER_UPDATE_MP_SLOW_MS; slow_ms = WORLD_TRACKER_UPDATE_MP_SLOW_MS;
} }
world_tracker_update(0, fast_ms, 1); world_tracker_update(0, fast_ms, 1);
world_tracker_update(1, normal_ms, 2); world_tracker_update(1, normal_ms, 2);
world_tracker_update(2, slow_ms, 3); world_tracker_update(2, slow_ms, 3);
entity_update_action_timers(); entity_update_action_timers();
debug_replay_update(); debug_replay_update();
return 0; return 0;
@ -459,11 +459,11 @@ world_block_lookup world_block_from_realpos(float x, float y) {
int32_t size = world.chunk_size * WORLD_BLOCK_SIZE; int32_t size = world.chunk_size * WORLD_BLOCK_SIZE;
int16_t chunk_x, chunk_y; int16_t chunk_x, chunk_y;
librg_chunk_to_chunkpos(world.tracker, chunk_id, &chunk_x, &chunk_y, NULL); librg_chunk_to_chunkpos(world.tracker, chunk_id, &chunk_x, &chunk_y, NULL);
// NOTE(zaklaus): pos relative to chunk // NOTE(zaklaus): pos relative to chunk
float chx = x - chunk_x * size; float chx = x - chunk_x * size;
float chy = y - chunk_y * size; float chy = y - chunk_y * size;
uint16_t bx = (uint16_t)chx / WORLD_BLOCK_SIZE; uint16_t bx = (uint16_t)chx / WORLD_BLOCK_SIZE;
uint16_t by = (uint16_t)chy / WORLD_BLOCK_SIZE; uint16_t by = (uint16_t)chy / WORLD_BLOCK_SIZE;
uint16_t block_idx = (by*world.chunk_size)+bx; uint16_t block_idx = (by*world.chunk_size)+bx;
@ -473,11 +473,11 @@ world_block_lookup world_block_from_realpos(float x, float y) {
bid = world.block_mapping[chunk_id][block_idx]; bid = world.block_mapping[chunk_id][block_idx];
is_outer = false; is_outer = false;
} }
// NOTE(zaklaus): pos relative to block's center // NOTE(zaklaus): pos relative to block's center
float box = chx - bx * WORLD_BLOCK_SIZE - WORLD_BLOCK_SIZE/2.0f; float box = chx - bx * WORLD_BLOCK_SIZE - WORLD_BLOCK_SIZE/2.0f;
float boy = chy - by * WORLD_BLOCK_SIZE - WORLD_BLOCK_SIZE/2.0f; float boy = chy - by * WORLD_BLOCK_SIZE - WORLD_BLOCK_SIZE/2.0f;
world_block_lookup lookup = { world_block_lookup lookup = {
.id = block_idx, .id = block_idx,
.bid = bid, .bid = bid,
@ -487,7 +487,7 @@ world_block_lookup world_block_from_realpos(float x, float y) {
.oy = boy, .oy = boy,
.is_outer = is_outer, .is_outer = is_outer,
}; };
return lookup; return lookup;
} }
@ -495,12 +495,12 @@ void world_chunk_destroy_block(float x, float y, bool drop_item) {
world_block_lookup l = world_block_from_realpos(x, y); world_block_lookup l = world_block_from_realpos(x, y);
if (blocks_get_flags(l.bid) & BLOCK_FLAG_ESSENTIAL) return; if (blocks_get_flags(l.bid) & BLOCK_FLAG_ESSENTIAL) return;
world_chunk_replace_block(l.chunk_id, l.id, 0); world_chunk_replace_block(l.chunk_id, l.id, 0);
if (l.is_outer && l.bid > 0 && drop_item) { if (l.is_outer && l.bid > 0 && drop_item) {
asset_id item_asset = blocks_get_asset(l.bid); asset_id item_asset = blocks_get_asset(l.bid);
if (item_find(item_asset) == ASSET_INVALID) return; if (item_find(item_asset) == ASSET_INVALID) return;
uint64_t e = item_spawn(item_asset, 1); uint64_t e = item_spawn(item_asset, 1);
Position *dest = ecs_get_mut(world_ecs(), e, Position); Position *dest = ecs_get_mut(world_ecs(), e, Position);
dest->x = x; dest->x = x;
dest->y = y; dest->y = y;
@ -512,14 +512,14 @@ world_block_lookup world_block_from_index(int64_t id, uint16_t block_idx) {
if (bid == 0) { if (bid == 0) {
bid = world.block_mapping[id][block_idx]; bid = world.block_mapping[id][block_idx];
} }
world_block_lookup lookup = { world_block_lookup lookup = {
.id = block_idx, .id = block_idx,
.bid = bid, .bid = bid,
.chunk_id = id, .chunk_id = id,
.chunk_e = world.chunk_mapping[id], .chunk_e = world.chunk_mapping[id],
}; };
return lookup; return lookup;
} }

17
code/vendors/librg.h vendored
View File

@ -157,7 +157,7 @@
#define LIBRG_VERSION_MAJOR 7 #define LIBRG_VERSION_MAJOR 7
#define LIBRG_VERSION_MINOR 0 #define LIBRG_VERSION_MINOR 0
#define LIBRG_VERSION_PATCH 1 #define LIBRG_VERSION_PATCH 2
#define LIBRG_VERSION_PRE "" #define LIBRG_VERSION_PRE ""
// file: librg_hedley.h // file: librg_hedley.h
@ -21033,14 +21033,14 @@ int8_t librg_chunk_to_chunkpos(librg_world *world, librg_chunk id, int16_t *chun
return LIBRG_CHUNK_INVALID; return LIBRG_CHUNK_INVALID;
} }
int16_t z = (int16_t)(id / (wld->worldsize.x * wld->worldsize.y)); int64_t z = (int64_t)(id / (wld->worldsize.x * wld->worldsize.y));
int16_t r1 = (int16_t)(id % (wld->worldsize.x * wld->worldsize.y)); int64_t r1 = (int64_t)(id % (wld->worldsize.x * wld->worldsize.y));
int16_t y = r1 / wld->worldsize.x; int64_t y = r1 / wld->worldsize.x;
int16_t x = r1 % wld->worldsize.x; int64_t x = r1 % wld->worldsize.x;
if (chunk_x) *chunk_x = x - librg_util_chunkoffset_line(0, wld->chunkoffset.x, wld->worldsize.x); if (chunk_x) *chunk_x = (int16_t)(x - librg_util_chunkoffset_line(0, wld->chunkoffset.x, wld->worldsize.x));
if (chunk_y) *chunk_y = y - librg_util_chunkoffset_line(0, wld->chunkoffset.y, wld->worldsize.y); if (chunk_y) *chunk_y = (int16_t)(y - librg_util_chunkoffset_line(0, wld->chunkoffset.y, wld->worldsize.y));
if (chunk_z) *chunk_z = z - librg_util_chunkoffset_line(0, wld->chunkoffset.z, wld->worldsize.z); if (chunk_z) *chunk_z = (int16_t)(z - librg_util_chunkoffset_line(0, wld->chunkoffset.z, wld->worldsize.z));
return LIBRG_OK; return LIBRG_OK;
} }
@ -21983,4 +21983,3 @@ LIBRG_END_C_DECLS
#endif // LIBRG_IMPLEMENTATION #endif // LIBRG_IMPLEMENTATION
#endif // LIBRG_H #endif // LIBRG_H

View File

@ -17,4 +17,4 @@ emsdk activate latest
source ./emsdk/emsdk_env.sh source ./emsdk/emsdk_env.sh
# Setup web build # Setup web build
emcmake cmake -S . -B build_web -DCMAKE_BUILD_TYPE=Debug -DPLATFORM=Web emcmake cmake -S . -B build_web -DCMAKE_BUILD_TYPE=Release -DPLATFORM=Web