code: updated librg + zpl dependencies
parent
599621fdd8
commit
c74c1efe7c
|
@ -2213,6 +2213,7 @@ LIBRG_API int8_t librg_world_destroy(librg_world *world);
|
||||||
LIBRG_API int8_t librg_world_valid(librg_world *world);
|
LIBRG_API int8_t librg_world_valid(librg_world *world);
|
||||||
LIBRG_API int8_t librg_world_userdata_set(librg_world *world, void *data);
|
LIBRG_API int8_t librg_world_userdata_set(librg_world *world, void *data);
|
||||||
LIBRG_API void * librg_world_userdata_get(librg_world *world);
|
LIBRG_API void * librg_world_userdata_get(librg_world *world);
|
||||||
|
LIBRG_API int64_t librg_world_entities_tracked();
|
||||||
|
|
||||||
// =======================================================================//
|
// =======================================================================//
|
||||||
// !
|
// !
|
||||||
|
@ -2291,13 +2292,15 @@ LIBRG_API int8_t librg_entity_dimension_set(librg_world *world, int64_t e
|
||||||
LIBRG_API int32_t librg_entity_dimension_get(librg_world *world, int64_t entity_id);
|
LIBRG_API int32_t librg_entity_dimension_get(librg_world *world, int64_t entity_id);
|
||||||
LIBRG_API int8_t librg_entity_owner_set(librg_world *world, int64_t entity_id, int64_t owner_id);
|
LIBRG_API int8_t librg_entity_owner_set(librg_world *world, int64_t entity_id, int64_t owner_id);
|
||||||
LIBRG_API int64_t librg_entity_owner_get(librg_world *world, int64_t entity_id);
|
LIBRG_API int64_t librg_entity_owner_get(librg_world *world, int64_t entity_id);
|
||||||
LIBRG_API int8_t librg_entity_radius_set(librg_world *world, int64_t entity_id, int8_t observed_chunk_radius);
|
|
||||||
LIBRG_API int8_t librg_entity_radius_get(librg_world *world, int64_t entity_id);
|
|
||||||
LIBRG_API int8_t librg_entity_visibility_global_set(librg_world *world, int64_t entity_id, librg_visibility value);
|
LIBRG_API int8_t librg_entity_visibility_global_set(librg_world *world, int64_t entity_id, librg_visibility value);
|
||||||
LIBRG_API int8_t librg_entity_visibility_global_get(librg_world *world, int64_t entity_id);
|
LIBRG_API int8_t librg_entity_visibility_global_get(librg_world *world, int64_t entity_id);
|
||||||
LIBRG_API int8_t librg_entity_visibility_owner_set(librg_world *world, int64_t entity_id, int64_t owner_id, librg_visibility value);
|
LIBRG_API int8_t librg_entity_visibility_owner_set(librg_world *world, int64_t entity_id, int64_t owner_id, librg_visibility value);
|
||||||
LIBRG_API int8_t librg_entity_visibility_owner_get(librg_world *world, int64_t entity_id, int64_t owner_id);
|
LIBRG_API int8_t librg_entity_visibility_owner_get(librg_world *world, int64_t entity_id, int64_t owner_id);
|
||||||
|
|
||||||
|
/* deprecated since 7.0 */
|
||||||
|
LIBRG_API int8_t librg_entity_radius_set(librg_world *world, int64_t entity_id, int8_t observed_chunk_radius);
|
||||||
|
LIBRG_API int8_t librg_entity_radius_get(librg_world *world, int64_t entity_id);
|
||||||
|
|
||||||
#if 0 /* for future releases */
|
#if 0 /* for future releases */
|
||||||
LIBRG_API int8_t librg_entity_behavior_set(librg_world *world, int64_t entity_id, librg_behavior key, int32_t value);
|
LIBRG_API int8_t librg_entity_behavior_set(librg_world *world, int64_t entity_id, librg_behavior key, int32_t value);
|
||||||
LIBRG_API int32_t librg_entity_behavior_get(librg_world *world, int64_t entity_id, librg_behavior key);
|
LIBRG_API int32_t librg_entity_behavior_get(librg_world *world, int64_t entity_id, librg_behavior key);
|
||||||
|
@ -2390,6 +2393,8 @@ LIBRG_END_C_DECLS
|
||||||
https://github.com/zpl-c/zpl
|
https://github.com/zpl-c/zpl
|
||||||
|
|
||||||
Version History:
|
Version History:
|
||||||
|
18.1.0 - added table _clear method
|
||||||
|
18.0.4 - fix memory arena alignment & added tests
|
||||||
18.0.3 - fix emscripten support
|
18.0.3 - fix emscripten support
|
||||||
18.0.2 - fix global-buffer-overflow in print module
|
18.0.2 - fix global-buffer-overflow in print module
|
||||||
- raise ZPL_PRINTF_MAXLEN to 64kb
|
- raise ZPL_PRINTF_MAXLEN to 64kb
|
||||||
|
@ -2759,8 +2764,8 @@ LIBRG_END_C_DECLS
|
||||||
#define ZPL_H
|
#define ZPL_H
|
||||||
|
|
||||||
#define ZPL_VERSION_MAJOR 18
|
#define ZPL_VERSION_MAJOR 18
|
||||||
#define ZPL_VERSION_MINOR 0
|
#define ZPL_VERSION_MINOR 1
|
||||||
#define ZPL_VERSION_PATCH 3
|
#define ZPL_VERSION_PATCH 1
|
||||||
#define ZPL_VERSION_PRE ""
|
#define ZPL_VERSION_PRE ""
|
||||||
|
|
||||||
// file: zpl_hedley.h
|
// file: zpl_hedley.h
|
||||||
|
@ -6641,10 +6646,18 @@ LIBRG_END_C_DECLS
|
||||||
zpl_isize entry_index;
|
zpl_isize entry_index;
|
||||||
} zpl_hash_table_find_result;
|
} zpl_hash_table_find_result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combined macro for a quick delcaration + definition
|
||||||
|
*/
|
||||||
|
|
||||||
#define ZPL_TABLE(PREFIX, NAME, FUNC, VALUE) \
|
#define ZPL_TABLE(PREFIX, NAME, FUNC, VALUE) \
|
||||||
ZPL_TABLE_DECLARE(PREFIX, NAME, FUNC, VALUE); \
|
ZPL_TABLE_DECLARE(PREFIX, NAME, FUNC, VALUE); \
|
||||||
ZPL_TABLE_DEFINE(NAME, FUNC, VALUE);
|
ZPL_TABLE_DEFINE(NAME, FUNC, VALUE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table delcaration macro that generates the interface
|
||||||
|
*/
|
||||||
|
|
||||||
#define ZPL_TABLE_DECLARE(PREFIX, NAME, FUNC, VALUE) \
|
#define ZPL_TABLE_DECLARE(PREFIX, NAME, FUNC, VALUE) \
|
||||||
typedef struct ZPL_JOIN2(NAME, Entry) { \
|
typedef struct ZPL_JOIN2(NAME, Entry) { \
|
||||||
zpl_u64 key; \
|
zpl_u64 key; \
|
||||||
|
@ -6657,18 +6670,23 @@ LIBRG_END_C_DECLS
|
||||||
zpl_array(ZPL_JOIN2(NAME, Entry)) entries; \
|
zpl_array(ZPL_JOIN2(NAME, Entry)) entries; \
|
||||||
} NAME; \
|
} NAME; \
|
||||||
\
|
\
|
||||||
PREFIX void ZPL_JOIN2(FUNC, init)(NAME * h, zpl_allocator a); \
|
PREFIX void ZPL_JOIN2(FUNC, init) (NAME *h, zpl_allocator a); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, destroy)(NAME * h); \
|
PREFIX void ZPL_JOIN2(FUNC, destroy) (NAME *h); \
|
||||||
PREFIX VALUE *ZPL_JOIN2(FUNC, get)(NAME * h, zpl_u64 key); \
|
PREFIX void ZPL_JOIN2(FUNC, clear) (NAME *h); \
|
||||||
PREFIX zpl_isize ZPL_JOIN2(FUNC, slot)(NAME * h, zpl_u64 key); \
|
PREFIX VALUE *ZPL_JOIN2(FUNC, get) (NAME *h, zpl_u64 key); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, set)(NAME * h, zpl_u64 key, VALUE value); \
|
PREFIX zpl_isize ZPL_JOIN2(FUNC, slot) (NAME *h, zpl_u64 key); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, grow)(NAME * h); \
|
PREFIX void ZPL_JOIN2(FUNC, set) (NAME *h, zpl_u64 key, VALUE value); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, rehash)(NAME * h, zpl_isize new_count); \
|
PREFIX void ZPL_JOIN2(FUNC, grow) (NAME *h); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, rehash_fast)(NAME * h); \
|
PREFIX void ZPL_JOIN2(FUNC, rehash) (NAME *h, zpl_isize new_count); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, map)(NAME * h, void (*map_proc)(zpl_u64 key, VALUE value)); \
|
PREFIX void ZPL_JOIN2(FUNC, rehash_fast) (NAME *h); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, map_mut)(NAME * h, void (*map_proc)(zpl_u64 key, VALUE * value)); \
|
PREFIX void ZPL_JOIN2(FUNC, map) (NAME *h, void (*map_proc) (zpl_u64 key, VALUE value)); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, remove)(NAME * h, zpl_u64 key); \
|
PREFIX void ZPL_JOIN2(FUNC, map_mut) (NAME *h, void (*map_proc) (zpl_u64 key, VALUE * value)); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, remove_entry)(NAME * h, zpl_isize idx);
|
PREFIX void ZPL_JOIN2(FUNC, remove) (NAME *h, zpl_u64 key); \
|
||||||
|
PREFIX void ZPL_JOIN2(FUNC, remove_entry) (NAME *h, zpl_isize idx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table definition interfaces that generates the implementation
|
||||||
|
*/
|
||||||
|
|
||||||
#define ZPL_TABLE_DEFINE(NAME, FUNC, VALUE) \
|
#define ZPL_TABLE_DEFINE(NAME, FUNC, VALUE) \
|
||||||
void ZPL_JOIN2(FUNC, init)(NAME * h, zpl_allocator a) { \
|
void ZPL_JOIN2(FUNC, init)(NAME * h, zpl_allocator a) { \
|
||||||
|
@ -6681,14 +6699,19 @@ LIBRG_END_C_DECLS
|
||||||
if (h->hashes) zpl_array_free(h->hashes); \
|
if (h->hashes) zpl_array_free(h->hashes); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
void ZPL_JOIN2(FUNC, clear)(NAME * h) { \
|
||||||
|
for (int i = 0; i < zpl_array_count(h->hashes); i++) h->hashes[i] = -1; \
|
||||||
|
zpl_array_clear(h->entries); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
zpl_isize ZPL_JOIN2(FUNC, slot)(NAME * h, zpl_u64 key) { \
|
zpl_isize ZPL_JOIN2(FUNC, slot)(NAME * h, zpl_u64 key) { \
|
||||||
for (zpl_isize i = 0; i < zpl_array_count(h->entries); i++) {\
|
for (zpl_isize i = 0; i < zpl_array_count(h->entries); i++) { \
|
||||||
if (h->entries[i].key == key) {\
|
if (h->entries[i].key == key) { \
|
||||||
return i; \
|
return i; \
|
||||||
} \
|
} \
|
||||||
}\
|
} \
|
||||||
return -1;\
|
return -1; \
|
||||||
}\
|
} \
|
||||||
\
|
\
|
||||||
zpl_internal zpl_isize ZPL_JOIN2(FUNC, _add_entry)(NAME * h, zpl_u64 key) { \
|
zpl_internal zpl_isize ZPL_JOIN2(FUNC, _add_entry)(NAME * h, zpl_u64 key) { \
|
||||||
zpl_isize index; \
|
zpl_isize index; \
|
||||||
|
@ -6790,6 +6813,7 @@ LIBRG_END_C_DECLS
|
||||||
map_proc(h->entries[i].key, h->entries[i].value); \
|
map_proc(h->entries[i].key, h->entries[i].value); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
void ZPL_JOIN2(FUNC, map_mut)(NAME * h, void (*map_proc)(zpl_u64 key, VALUE * value)) { \
|
void ZPL_JOIN2(FUNC, map_mut)(NAME * h, void (*map_proc)(zpl_u64 key, VALUE * value)) { \
|
||||||
ZPL_ASSERT_NOT_NULL(h); \
|
ZPL_ASSERT_NOT_NULL(h); \
|
||||||
ZPL_ASSERT_NOT_NULL(map_proc); \
|
ZPL_ASSERT_NOT_NULL(map_proc); \
|
||||||
|
@ -6815,7 +6839,7 @@ LIBRG_END_C_DECLS
|
||||||
} \
|
} \
|
||||||
h->entries[index].value = value; \
|
h->entries[index].value = value; \
|
||||||
if (ZPL_JOIN2(FUNC, _full)(h)) ZPL_JOIN2(FUNC, grow)(h); \
|
if (ZPL_JOIN2(FUNC, _full)(h)) ZPL_JOIN2(FUNC, grow)(h); \
|
||||||
}\
|
}
|
||||||
|
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
|
@ -10825,11 +10849,11 @@ LIBRG_END_C_DECLS
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ZPL_ALLOCATION_ALLOC: {
|
case ZPL_ALLOCATION_ALLOC: {
|
||||||
void *end = zpl_pointer_add(arena->physical_start, arena->total_allocated);
|
void *end = zpl_pointer_add(arena->physical_start, arena->total_allocated);
|
||||||
zpl_isize total_size = size + alignment;
|
zpl_isize total_size = zpl_align_forward_i64(size, alignment);
|
||||||
|
|
||||||
// NOTE: Out of memory
|
// NOTE: Out of memory
|
||||||
if (arena->total_allocated + total_size > cast(zpl_isize) arena->total_size) {
|
if (arena->total_allocated + total_size > cast(zpl_isize) arena->total_size) {
|
||||||
zpl__printf_err("%s", "Arena out of memory\n");
|
// zpl__printf_err("%s", "Arena out of memory\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20730,6 +20754,11 @@ typedef struct librg_event_t {
|
||||||
void * userdata; /* userpointer that is passed from librg_world_write/librg_world_read fns */
|
void * userdata; /* userpointer that is passed from librg_world_write/librg_world_read fns */
|
||||||
} librg_event_t;
|
} librg_event_t;
|
||||||
|
|
||||||
|
typedef struct librg_owner_entity_pair_t {
|
||||||
|
int64_t owner_id; /* id of the owner who this event is called for */
|
||||||
|
int64_t entity_id; /* id of an entity which this event is called about */
|
||||||
|
} librg_owner_entity_pair_t;
|
||||||
|
|
||||||
typedef struct librg_world_t {
|
typedef struct librg_world_t {
|
||||||
uint8_t valid;
|
uint8_t valid;
|
||||||
zpl_allocator allocator;
|
zpl_allocator allocator;
|
||||||
|
@ -20743,6 +20772,12 @@ typedef struct librg_world_t {
|
||||||
librg_table_ent entity_map;
|
librg_table_ent entity_map;
|
||||||
librg_table_tbl owner_map;
|
librg_table_tbl owner_map;
|
||||||
|
|
||||||
|
librg_table_tbl dimensions;
|
||||||
|
|
||||||
|
/* owner-entity pair, needed for more effective query */
|
||||||
|
/* achieved by caching only owned entities and reducing the first iteration cycle */
|
||||||
|
zpl_array(librg_owner_entity_pair_t) owner_entity_pairs;
|
||||||
|
|
||||||
void *userdata;
|
void *userdata;
|
||||||
} librg_world_t;
|
} librg_world_t;
|
||||||
|
|
||||||
|
@ -20815,6 +20850,9 @@ librg_world *librg_world_create() {
|
||||||
librg_table_ent_init(&wld->entity_map, wld->allocator);
|
librg_table_ent_init(&wld->entity_map, wld->allocator);
|
||||||
librg_table_tbl_init(&wld->owner_map, wld->allocator);
|
librg_table_tbl_init(&wld->owner_map, wld->allocator);
|
||||||
zpl_random_init(&wld->random);
|
zpl_random_init(&wld->random);
|
||||||
|
zpl_array_init(wld->owner_entity_pairs, wld->allocator);
|
||||||
|
|
||||||
|
librg_table_tbl_init(&wld->dimensions, wld->allocator);
|
||||||
|
|
||||||
return (librg_world *)wld;
|
return (librg_world *)wld;
|
||||||
}
|
}
|
||||||
|
@ -20843,6 +20881,9 @@ int8_t librg_world_destroy(librg_world *world) {
|
||||||
librg_table_tbl_destroy(&wld->owner_map);
|
librg_table_tbl_destroy(&wld->owner_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zpl_array_free(wld->owner_entity_pairs);
|
||||||
|
librg_table_tbl_destroy(&wld->dimensions);
|
||||||
|
|
||||||
/* mark it invalid */
|
/* mark it invalid */
|
||||||
wld->valid = LIBRG_FALSE;
|
wld->valid = LIBRG_FALSE;
|
||||||
|
|
||||||
|
@ -20869,6 +20910,12 @@ void *librg_world_userdata_get(librg_world *world) {
|
||||||
return wld->userdata;
|
return wld->userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t librg_world_entities_tracked(librg_world *world) {
|
||||||
|
LIBRG_ASSERT(world); if (!world) return LIBRG_WORLD_INVALID;
|
||||||
|
librg_world_t *wld = (librg_world_t *)world;
|
||||||
|
return zpl_array_count(wld->entity_map.entries);
|
||||||
|
}
|
||||||
|
|
||||||
// =======================================================================//
|
// =======================================================================//
|
||||||
// !
|
// !
|
||||||
// ! Runtime configuration
|
// ! Runtime configuration
|
||||||
|
@ -21138,6 +21185,14 @@ int8_t librg_entity_untrack(librg_world *world, int64_t entity_id) {
|
||||||
librg_table_i64_destroy(snapshot);
|
librg_table_i64_destroy(snapshot);
|
||||||
librg_table_tbl_remove(&wld->owner_map, entity->owner_id);
|
librg_table_tbl_remove(&wld->owner_map, entity->owner_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* cleanup owner-entity pair */
|
||||||
|
for (int i = 0; i < zpl_array_count(wld->owner_entity_pairs); ++i) {
|
||||||
|
if (wld->owner_entity_pairs[i].entity_id == entity_id) {
|
||||||
|
zpl_array_remove_at(wld->owner_entity_pairs, i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cleanup owner visibility */
|
/* cleanup owner visibility */
|
||||||
|
@ -21215,6 +21270,35 @@ int8_t librg_entity_owner_set(librg_world *world, int64_t entity_id, int64_t own
|
||||||
return LIBRG_ENTITY_FOREIGN;
|
return LIBRG_ENTITY_FOREIGN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* update owner-entity pairing */
|
||||||
|
if (owner_id != LIBRG_OWNER_INVALID) {
|
||||||
|
bool ownership_pair_found = false;
|
||||||
|
for (int i = 0; i < zpl_array_count(wld->owner_entity_pairs) && !ownership_pair_found; ++i) {
|
||||||
|
if (wld->owner_entity_pairs[i].entity_id == entity_id) {
|
||||||
|
ownership_pair_found = true;
|
||||||
|
|
||||||
|
/* update owner if we found the entity */
|
||||||
|
if (wld->owner_entity_pairs[i].owner_id != owner_id) {
|
||||||
|
wld->owner_entity_pairs[i].owner_id = owner_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!ownership_pair_found) {
|
||||||
|
librg_owner_entity_pair_t pair = { owner_id, entity_id };
|
||||||
|
zpl_array_append(wld->owner_entity_pairs, pair);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (entity->owner_id != LIBRG_OWNER_INVALID) {
|
||||||
|
/* cleanup owner-entity pair */
|
||||||
|
for (int i = 0; i < zpl_array_count(wld->owner_entity_pairs); ++i) {
|
||||||
|
if (wld->owner_entity_pairs[i].entity_id == entity_id) {
|
||||||
|
zpl_array_remove_at(wld->owner_entity_pairs, i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entity->owner_id = owner_id;
|
entity->owner_id = owner_id;
|
||||||
entity->flag_owner_updated = LIBRG_TRUE;
|
entity->flag_owner_updated = LIBRG_TRUE;
|
||||||
|
|
||||||
|
@ -21537,22 +21621,22 @@ int32_t librg_world_query(librg_world *world, int64_t owner_id, uint8_t chunk_ra
|
||||||
|
|
||||||
size_t buffer_limit = *entity_amount;
|
size_t buffer_limit = *entity_amount;
|
||||||
size_t total_count = zpl_array_count(wld->entity_map.entries);
|
size_t total_count = zpl_array_count(wld->entity_map.entries);
|
||||||
|
size_t result_amount = 0;
|
||||||
|
|
||||||
librg_table_i64 results = {0};
|
/* mini helper for pushing entity */
|
||||||
librg_table_tbl dimensions = {0};
|
/* if it will overflow do not push, just increase counter for future statistics */
|
||||||
|
#define librg_push_entity(entity_id) \
|
||||||
librg_table_i64_init(&results, wld->allocator);
|
{ if (result_amount + 1 <= buffer_limit) entity_ids[result_amount++] = entity_id; else result_amount++; }
|
||||||
librg_table_tbl_init(&dimensions, wld->allocator);
|
|
||||||
|
|
||||||
/* generate a map of visible chunks (only counting owned entities) */
|
/* generate a map of visible chunks (only counting owned entities) */
|
||||||
for (size_t i=0; i < total_count; ++i) {
|
for (int i = 0; i < zpl_array_count(wld->owner_entity_pairs); ++i) {
|
||||||
uint64_t entity_id = wld->entity_map.entries[i].key;
|
if (wld->owner_entity_pairs[i].owner_id != owner_id) continue;
|
||||||
librg_entity_t *entity = &wld->entity_map.entries[i].value;
|
|
||||||
|
uint64_t entity_id = wld->owner_entity_pairs[i].entity_id;
|
||||||
|
librg_entity_t *entity = librg_table_ent_get(&wld->entity_map, entity_id);
|
||||||
|
|
||||||
/* allways add self-owned entities */
|
/* allways add self-owned entities */
|
||||||
if (entity->owner_id == owner_id) {
|
librg_push_entity(entity_id);
|
||||||
librg_table_i64_set(&results, entity_id, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* immidiately skip, if entity was not placed correctly */
|
/* immidiately skip, if entity was not placed correctly */
|
||||||
if (entity->chunks[0] == LIBRG_CHUNK_INVALID) continue;
|
if (entity->chunks[0] == LIBRG_CHUNK_INVALID) continue;
|
||||||
|
@ -21560,12 +21644,12 @@ int32_t librg_world_query(librg_world *world, int64_t owner_id, uint8_t chunk_ra
|
||||||
if (entity->owner_id != owner_id) continue;
|
if (entity->owner_id != owner_id) continue;
|
||||||
|
|
||||||
/* fetch, or create chunk set in this dimension if does not exist */
|
/* fetch, or create chunk set in this dimension if does not exist */
|
||||||
librg_table_i64 *dim_chunks = librg_table_tbl_get(&dimensions, entity->dimension);
|
librg_table_i64 *dim_chunks = librg_table_tbl_get(&wld->dimensions, entity->dimension);
|
||||||
|
|
||||||
if (!dim_chunks) {
|
if (!dim_chunks) {
|
||||||
librg_table_i64 _chunks = {0};
|
librg_table_i64 _chunks = {0};
|
||||||
librg_table_tbl_set(&dimensions, entity->dimension, _chunks);
|
librg_table_tbl_set(&wld->dimensions, entity->dimension, _chunks);
|
||||||
dim_chunks = librg_table_tbl_get(&dimensions, entity->dimension);
|
dim_chunks = librg_table_tbl_get(&wld->dimensions, entity->dimension);
|
||||||
librg_table_i64_init(dim_chunks, wld->allocator);
|
librg_table_i64_init(dim_chunks, wld->allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21579,16 +21663,13 @@ int32_t librg_world_query(librg_world *world, int64_t owner_id, uint8_t chunk_ra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* a slightly increased buffer_limit, that includes own entities */
|
|
||||||
/* that allows us to prevent edge-cases where the code below will include our entities in the result as well */
|
|
||||||
size_t owned_entities = zpl_array_count(results.entries);
|
|
||||||
size_t buffer_limit_extended = buffer_limit + owned_entities;
|
|
||||||
|
|
||||||
/* iterate on all entities, and check if they are inside of the interested chunks */
|
/* iterate on all entities, and check if they are inside of the interested chunks */
|
||||||
for (size_t i=0; i < LIBRG_MIN(buffer_limit_extended, total_count); ++i) {
|
for (size_t i=0; i < total_count; ++i) {
|
||||||
uint64_t entity_id = wld->entity_map.entries[i].key;
|
uint64_t entity_id = wld->entity_map.entries[i].key;
|
||||||
librg_entity_t *entity = &wld->entity_map.entries[i].value;
|
librg_entity_t *entity = &wld->entity_map.entries[i].value;
|
||||||
librg_table_i64 *chunks = librg_table_tbl_get(&dimensions, entity->dimension);
|
librg_table_i64 *chunks = librg_table_tbl_get(&wld->dimensions, entity->dimension);
|
||||||
|
|
||||||
|
if (entity->owner_id == owner_id) continue;
|
||||||
|
|
||||||
/* owner visibility (personal)*/
|
/* owner visibility (personal)*/
|
||||||
int8_t vis_owner = librg_entity_visibility_owner_get(world, entity_id, owner_id);
|
int8_t vis_owner = librg_entity_visibility_owner_get(world, entity_id, owner_id);
|
||||||
|
@ -21596,7 +21677,7 @@ int32_t librg_world_query(librg_world *world, int64_t owner_id, uint8_t chunk_ra
|
||||||
continue; /* prevent from being included */
|
continue; /* prevent from being included */
|
||||||
}
|
}
|
||||||
else if (vis_owner == LIBRG_VISIBLITY_ALWAYS) {
|
else if (vis_owner == LIBRG_VISIBLITY_ALWAYS) {
|
||||||
librg_table_i64_set(&results, entity_id, 1); /* always included */
|
librg_push_entity(entity_id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21606,7 +21687,7 @@ int32_t librg_world_query(librg_world *world, int64_t owner_id, uint8_t chunk_ra
|
||||||
continue; /* prevent from being included */
|
continue; /* prevent from being included */
|
||||||
}
|
}
|
||||||
else if (vis_global == LIBRG_VISIBLITY_ALWAYS) {
|
else if (vis_global == LIBRG_VISIBLITY_ALWAYS) {
|
||||||
librg_table_i64_set(&results, entity_id, 1); /* always included */
|
librg_push_entity(entity_id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21623,27 +21704,23 @@ int32_t librg_world_query(librg_world *world, int64_t owner_id, uint8_t chunk_ra
|
||||||
|
|
||||||
/* add entity and continue to the next one */
|
/* add entity and continue to the next one */
|
||||||
if (entity->chunks[j] == chunk) {
|
if (entity->chunks[j] == chunk) {
|
||||||
librg_table_i64_set(&results, entity_id, 1);
|
librg_push_entity(entity_id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy/transform results to a plain array */
|
|
||||||
size_t count = zpl_array_count(results.entries);
|
|
||||||
for (size_t i = 0; i < LIBRG_MIN(buffer_limit, count); ++i)
|
|
||||||
entity_ids[i] = results.entries[i].key;
|
|
||||||
|
|
||||||
/* free up temp data */
|
/* free up temp data */
|
||||||
for (int i = 0; i < zpl_array_count(dimensions.entries); ++i)
|
for (int i = 0; i < zpl_array_count(wld->dimensions.entries); ++i)
|
||||||
librg_table_i64_destroy(&dimensions.entries[i].value);
|
librg_table_i64_destroy(&wld->dimensions.entries[i].value);
|
||||||
|
|
||||||
librg_table_tbl_destroy(&dimensions);
|
librg_table_tbl_clear(&wld->dimensions);
|
||||||
librg_table_i64_destroy(&results);
|
|
||||||
|
|
||||||
*entity_amount = LIBRG_MIN(buffer_limit, count);
|
#undef librg_push_entity
|
||||||
return LIBRG_MAX(0, (int32_t)(count - buffer_limit));
|
|
||||||
|
*entity_amount = LIBRG_MIN(buffer_limit, result_amount);
|
||||||
|
return LIBRG_MAX(0, (int32_t)(result_amount - buffer_limit));
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBRG_END_C_DECLS
|
LIBRG_END_C_DECLS
|
||||||
|
@ -22001,3 +22078,4 @@ LIBRG_END_C_DECLS
|
||||||
#endif // LIBRG_IMPLEMENTATION
|
#endif // LIBRG_IMPLEMENTATION
|
||||||
|
|
||||||
#endif // LIBRG_H
|
#endif // LIBRG_H
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@ GitHub:
|
||||||
https://github.com/zpl-c/zpl
|
https://github.com/zpl-c/zpl
|
||||||
|
|
||||||
Version History:
|
Version History:
|
||||||
|
18.1.0 - added table _clear method
|
||||||
|
18.0.4 - fix memory arena alignment & added tests
|
||||||
18.0.3 - fix emscripten support
|
18.0.3 - fix emscripten support
|
||||||
18.0.2 - fix global-buffer-overflow in print module
|
18.0.2 - fix global-buffer-overflow in print module
|
||||||
- raise ZPL_PRINTF_MAXLEN to 64kb
|
- raise ZPL_PRINTF_MAXLEN to 64kb
|
||||||
|
@ -403,8 +405,8 @@ License:
|
||||||
#define ZPL_H
|
#define ZPL_H
|
||||||
|
|
||||||
#define ZPL_VERSION_MAJOR 18
|
#define ZPL_VERSION_MAJOR 18
|
||||||
#define ZPL_VERSION_MINOR 0
|
#define ZPL_VERSION_MINOR 1
|
||||||
#define ZPL_VERSION_PATCH 3
|
#define ZPL_VERSION_PATCH 1
|
||||||
#define ZPL_VERSION_PRE ""
|
#define ZPL_VERSION_PRE ""
|
||||||
|
|
||||||
// file: zpl_hedley.h
|
// file: zpl_hedley.h
|
||||||
|
@ -4285,10 +4287,18 @@ License:
|
||||||
zpl_isize entry_index;
|
zpl_isize entry_index;
|
||||||
} zpl_hash_table_find_result;
|
} zpl_hash_table_find_result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combined macro for a quick delcaration + definition
|
||||||
|
*/
|
||||||
|
|
||||||
#define ZPL_TABLE(PREFIX, NAME, FUNC, VALUE) \
|
#define ZPL_TABLE(PREFIX, NAME, FUNC, VALUE) \
|
||||||
ZPL_TABLE_DECLARE(PREFIX, NAME, FUNC, VALUE); \
|
ZPL_TABLE_DECLARE(PREFIX, NAME, FUNC, VALUE); \
|
||||||
ZPL_TABLE_DEFINE(NAME, FUNC, VALUE);
|
ZPL_TABLE_DEFINE(NAME, FUNC, VALUE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table delcaration macro that generates the interface
|
||||||
|
*/
|
||||||
|
|
||||||
#define ZPL_TABLE_DECLARE(PREFIX, NAME, FUNC, VALUE) \
|
#define ZPL_TABLE_DECLARE(PREFIX, NAME, FUNC, VALUE) \
|
||||||
typedef struct ZPL_JOIN2(NAME, Entry) { \
|
typedef struct ZPL_JOIN2(NAME, Entry) { \
|
||||||
zpl_u64 key; \
|
zpl_u64 key; \
|
||||||
|
@ -4301,18 +4311,23 @@ License:
|
||||||
zpl_array(ZPL_JOIN2(NAME, Entry)) entries; \
|
zpl_array(ZPL_JOIN2(NAME, Entry)) entries; \
|
||||||
} NAME; \
|
} NAME; \
|
||||||
\
|
\
|
||||||
PREFIX void ZPL_JOIN2(FUNC, init)(NAME * h, zpl_allocator a); \
|
PREFIX void ZPL_JOIN2(FUNC, init) (NAME *h, zpl_allocator a); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, destroy)(NAME * h); \
|
PREFIX void ZPL_JOIN2(FUNC, destroy) (NAME *h); \
|
||||||
PREFIX VALUE *ZPL_JOIN2(FUNC, get)(NAME * h, zpl_u64 key); \
|
PREFIX void ZPL_JOIN2(FUNC, clear) (NAME *h); \
|
||||||
PREFIX zpl_isize ZPL_JOIN2(FUNC, slot)(NAME * h, zpl_u64 key); \
|
PREFIX VALUE *ZPL_JOIN2(FUNC, get) (NAME *h, zpl_u64 key); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, set)(NAME * h, zpl_u64 key, VALUE value); \
|
PREFIX zpl_isize ZPL_JOIN2(FUNC, slot) (NAME *h, zpl_u64 key); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, grow)(NAME * h); \
|
PREFIX void ZPL_JOIN2(FUNC, set) (NAME *h, zpl_u64 key, VALUE value); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, rehash)(NAME * h, zpl_isize new_count); \
|
PREFIX void ZPL_JOIN2(FUNC, grow) (NAME *h); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, rehash_fast)(NAME * h); \
|
PREFIX void ZPL_JOIN2(FUNC, rehash) (NAME *h, zpl_isize new_count); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, map)(NAME * h, void (*map_proc)(zpl_u64 key, VALUE value)); \
|
PREFIX void ZPL_JOIN2(FUNC, rehash_fast) (NAME *h); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, map_mut)(NAME * h, void (*map_proc)(zpl_u64 key, VALUE * value)); \
|
PREFIX void ZPL_JOIN2(FUNC, map) (NAME *h, void (*map_proc) (zpl_u64 key, VALUE value)); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, remove)(NAME * h, zpl_u64 key); \
|
PREFIX void ZPL_JOIN2(FUNC, map_mut) (NAME *h, void (*map_proc) (zpl_u64 key, VALUE * value)); \
|
||||||
PREFIX void ZPL_JOIN2(FUNC, remove_entry)(NAME * h, zpl_isize idx);
|
PREFIX void ZPL_JOIN2(FUNC, remove) (NAME *h, zpl_u64 key); \
|
||||||
|
PREFIX void ZPL_JOIN2(FUNC, remove_entry) (NAME *h, zpl_isize idx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table definition interfaces that generates the implementation
|
||||||
|
*/
|
||||||
|
|
||||||
#define ZPL_TABLE_DEFINE(NAME, FUNC, VALUE) \
|
#define ZPL_TABLE_DEFINE(NAME, FUNC, VALUE) \
|
||||||
void ZPL_JOIN2(FUNC, init)(NAME * h, zpl_allocator a) { \
|
void ZPL_JOIN2(FUNC, init)(NAME * h, zpl_allocator a) { \
|
||||||
|
@ -4325,14 +4340,19 @@ License:
|
||||||
if (h->hashes) zpl_array_free(h->hashes); \
|
if (h->hashes) zpl_array_free(h->hashes); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
void ZPL_JOIN2(FUNC, clear)(NAME * h) { \
|
||||||
|
for (int i = 0; i < zpl_array_count(h->hashes); i++) h->hashes[i] = -1; \
|
||||||
|
zpl_array_clear(h->entries); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
zpl_isize ZPL_JOIN2(FUNC, slot)(NAME * h, zpl_u64 key) { \
|
zpl_isize ZPL_JOIN2(FUNC, slot)(NAME * h, zpl_u64 key) { \
|
||||||
for (zpl_isize i = 0; i < zpl_array_count(h->entries); i++) {\
|
for (zpl_isize i = 0; i < zpl_array_count(h->entries); i++) { \
|
||||||
if (h->entries[i].key == key) {\
|
if (h->entries[i].key == key) { \
|
||||||
return i; \
|
return i; \
|
||||||
} \
|
} \
|
||||||
}\
|
} \
|
||||||
return -1;\
|
return -1; \
|
||||||
}\
|
} \
|
||||||
\
|
\
|
||||||
zpl_internal zpl_isize ZPL_JOIN2(FUNC, _add_entry)(NAME * h, zpl_u64 key) { \
|
zpl_internal zpl_isize ZPL_JOIN2(FUNC, _add_entry)(NAME * h, zpl_u64 key) { \
|
||||||
zpl_isize index; \
|
zpl_isize index; \
|
||||||
|
@ -4434,6 +4454,7 @@ License:
|
||||||
map_proc(h->entries[i].key, h->entries[i].value); \
|
map_proc(h->entries[i].key, h->entries[i].value); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
void ZPL_JOIN2(FUNC, map_mut)(NAME * h, void (*map_proc)(zpl_u64 key, VALUE * value)) { \
|
void ZPL_JOIN2(FUNC, map_mut)(NAME * h, void (*map_proc)(zpl_u64 key, VALUE * value)) { \
|
||||||
ZPL_ASSERT_NOT_NULL(h); \
|
ZPL_ASSERT_NOT_NULL(h); \
|
||||||
ZPL_ASSERT_NOT_NULL(map_proc); \
|
ZPL_ASSERT_NOT_NULL(map_proc); \
|
||||||
|
@ -4459,7 +4480,7 @@ License:
|
||||||
} \
|
} \
|
||||||
h->entries[index].value = value; \
|
h->entries[index].value = value; \
|
||||||
if (ZPL_JOIN2(FUNC, _full)(h)) ZPL_JOIN2(FUNC, grow)(h); \
|
if (ZPL_JOIN2(FUNC, _full)(h)) ZPL_JOIN2(FUNC, grow)(h); \
|
||||||
}\
|
}
|
||||||
|
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
|
@ -8469,11 +8490,11 @@ License:
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ZPL_ALLOCATION_ALLOC: {
|
case ZPL_ALLOCATION_ALLOC: {
|
||||||
void *end = zpl_pointer_add(arena->physical_start, arena->total_allocated);
|
void *end = zpl_pointer_add(arena->physical_start, arena->total_allocated);
|
||||||
zpl_isize total_size = size + alignment;
|
zpl_isize total_size = zpl_align_forward_i64(size, alignment);
|
||||||
|
|
||||||
// NOTE: Out of memory
|
// NOTE: Out of memory
|
||||||
if (arena->total_allocated + total_size > cast(zpl_isize) arena->total_size) {
|
if (arena->total_allocated + total_size > cast(zpl_isize) arena->total_size) {
|
||||||
zpl__printf_err("%s", "Arena out of memory\n");
|
// zpl__printf_err("%s", "Arena out of memory\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue