Skip to content

Commit

Permalink
code: added radius to query and write, deprecated entity radius
Browse files Browse the repository at this point in the history
  • Loading branch information
inlife committed May 8, 2021
1 parent f4db15a commit 99150ee
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 27 deletions.
2 changes: 1 addition & 1 deletion code/header/packing.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ LIBRG_BEGIN_C_DECLS
// =======================================================================//

LIBRG_API int32_t librg_world_read(librg_world *world, int64_t owner_id, LIBRG_IN const char *buffer, size_t size, void *userdata);
LIBRG_API int32_t librg_world_write(librg_world *world, int64_t owner_id, LIBRG_OUT char *buffer, LIBRG_INOUT size_t *size, void *userdata);
LIBRG_API int32_t librg_world_write(librg_world *world, int64_t owner_id, uint8_t chunk_radius, LIBRG_OUT char *buffer, LIBRG_INOUT size_t *size, void *userdata);

LIBRG_END_C_DECLS
2 changes: 1 addition & 1 deletion code/header/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ LIBRG_API int32_t librg_world_fetch_chunk(librg_world *world, librg_chunk chunk,
LIBRG_API int32_t librg_world_fetch_chunkarray(librg_world *world, const librg_chunk *chunks, size_t chunk_amount, LIBRG_OUT int64_t *entity_ids, LIBRG_INOUT size_t *entity_amount);
LIBRG_API int32_t librg_world_fetch_owner(librg_world *world, int64_t owner_id, LIBRG_OUT int64_t *entity_ids, LIBRG_INOUT size_t *entity_amount);
LIBRG_API int32_t librg_world_fetch_ownerarray(librg_world *world, const int64_t *owner_ids, size_t owner_amount, LIBRG_OUT int64_t *entity_ids, LIBRG_INOUT size_t *entity_amount);
LIBRG_API int32_t librg_world_query(librg_world *world, int64_t owner_id, LIBRG_OUT int64_t *entity_ids, LIBRG_INOUT size_t *entity_amount);
LIBRG_API int32_t librg_world_query(librg_world *world, int64_t owner_id, uint8_t chunk_radius, LIBRG_OUT int64_t *entity_ids, LIBRG_INOUT size_t *entity_amount);

LIBRG_END_C_DECLS
27 changes: 9 additions & 18 deletions code/source/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,17 @@ int64_t librg_entity_owner_get(librg_world *world, int64_t entity_id) {
return entity->owner_id;
}


int8_t librg_entity_radius_set(librg_world *world, int64_t entity_id, int8_t observed_chunk_radius) {
LIBRG_ASSERT(world); if (!world) return LIBRG_WORLD_INVALID;
librg_world_t *wld = (librg_world_t *)world;

librg_entity_t *entity = librg_table_ent_get(&wld->entity_map, entity_id);
if (entity == NULL) return LIBRG_ENTITY_UNTRACKED;

entity->observed_radius = observed_chunk_radius;
return LIBRG_OK;
LIBRG_DEPRECATED(7.0) int8_t librg_entity_radius_set(librg_world *world, int64_t entity_id, int8_t observed_chunk_radius) {
zpl_unused(world);
zpl_unused(entity_id);
zpl_unused(observed_chunk_radius);
return -1;
}

int8_t librg_entity_radius_get(librg_world *world, int64_t entity_id) {
LIBRG_ASSERT(world); if (!world) return LIBRG_WORLD_INVALID;
librg_world_t *wld = (librg_world_t *)world;

librg_entity_t *entity = librg_table_ent_get(&wld->entity_map, entity_id);
if (entity == NULL) return LIBRG_ENTITY_UNTRACKED;

return entity->observed_radius;
LIBRG_DEPRECATED(7.0) int8_t librg_entity_radius_get(librg_world *world, int64_t entity_id) {
zpl_unused(world);
zpl_unused(entity_id);
return -1;
}

int8_t librg_entity_dimension_set(librg_world *world, int64_t entity_id, int32_t dimension) {
Expand Down
4 changes: 2 additions & 2 deletions code/source/packing.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ LIBRG_STATIC_ASSERT(sizeof(librg_segment_t) == 8, "packed librg_segment_t should
// !
// =======================================================================//

int32_t librg_world_write(librg_world *world, int64_t owner_id, char *buffer, size_t *size, void *userdata) {
int32_t librg_world_write(librg_world *world, int64_t owner_id, uint8_t chunk_radius, char *buffer, size_t *size, void *userdata) {
LIBRG_ASSERT(world); if (!world) return LIBRG_WORLD_INVALID;
librg_world_t *wld = (librg_world_t *)world;
librg_table_i64 *last_snapshot = librg_table_tbl_get(&wld->owner_map, owner_id);
Expand All @@ -54,7 +54,7 @@ int32_t librg_world_write(librg_world *world, int64_t owner_id, char *buffer, si

int64_t *results = (int64_t *)LIBRG_MEM_ALLOC(LIBRG_WORLDWRITE_MAXQUERY * sizeof(int64_t));
size_t total_amount = LIBRG_WORLDWRITE_MAXQUERY;
librg_world_query(world, owner_id, results, &total_amount);
librg_world_query(world, owner_id, chunk_radius, results, &total_amount);

size_t total_written = 0;
librg_event_t evt = {0};
Expand Down
6 changes: 2 additions & 4 deletions code/source/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static LIBRG_ALWAYS_INLINE void librg_util_chunkrange(librg_world *w, librg_tabl
return;
}

int32_t librg_world_query(librg_world *world, int64_t owner_id, int64_t *entity_ids, size_t *entity_amount) {
int32_t librg_world_query(librg_world *world, int64_t owner_id, uint8_t chunk_radius, int64_t *entity_ids, size_t *entity_amount) {
LIBRG_ASSERT(world); if (!world) return LIBRG_WORLD_INVALID;
LIBRG_ASSERT(entity_amount); if (!entity_amount) return LIBRG_NULL_REFERENCE;
librg_world_t *wld = (librg_world_t *)world;
Expand Down Expand Up @@ -150,8 +150,6 @@ int32_t librg_world_query(librg_world *world, int64_t owner_id, int64_t *entity_
if (entity->chunks[0] == LIBRG_CHUNK_INVALID) continue;
/* and skip, if used is not an owner of the entity */
if (entity->owner_id != owner_id) continue;
/* and skip if entity is not an observer */
if (entity->observed_radius == 0) continue;

/* fetch, or create chunk set in this dimension if does not exist */
librg_table_i64 *dim_chunks = librg_table_tbl_get(&dimensions, entity->dimension);
Expand All @@ -169,7 +167,7 @@ int32_t librg_world_query(librg_world *world, int64_t owner_id, int64_t *entity_

int16_t chx=0, chy=0, chz=0;
librg_chunk_to_chunkpos(world, entity->chunks[k], &chx, &chy, &chz);
librg_util_chunkrange(world, dim_chunks, chx, chy, chz, entity->observed_radius);
librg_util_chunkrange(world, dim_chunks, chx, chy, chz, chunk_radius);
}
}

Expand Down
1 change: 0 additions & 1 deletion code/source/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ typedef struct librg_entity_t {
uint8_t flag_visbility_owner_enabled : 1;
uint8_t flag_unused2 : 1;

int8_t observed_radius;
uint16_t ownership_token;

int32_t dimension;
Expand Down

0 comments on commit 99150ee

Please sign in to comment.