Skip to content

Commit

Permalink
code: added ability to set owner invisibility to own entity
Browse files Browse the repository at this point in the history
  • Loading branch information
inlife committed Dec 26, 2022
1 parent d60a288 commit 6710e7c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
5 changes: 0 additions & 5 deletions code/source/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,6 @@ int8_t librg_entity_visibility_owner_set(librg_world *world, int64_t entity_id,
librg_entity_t *entity = librg_table_ent_get(&wld->entity_map, entity_id);
if (entity == NULL) return LIBRG_ENTITY_UNTRACKED;

/* prevent setting visibility, for your own entity, it will be always visible */
if (entity->owner_id == owner_id) {
return LIBRG_ENTITY_VISIBILITY_IGNORED;
}

if (!entity->flag_visbility_owner_enabled) {
entity->flag_visbility_owner_enabled = LIBRG_TRUE;
librg_table_i8_init(&entity->owner_visibility_map, wld->allocator);
Expand Down
6 changes: 5 additions & 1 deletion code/source/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ int32_t librg_world_query(librg_world *world, int64_t owner_id, uint8_t chunk_ra
librg_entity_t *entity = librg_table_ent_get(&wld->entity_map, entity_id);

/* allways add self-owned entities */
librg_push_entity(entity_id);
int8_t vis_owner = librg_entity_visibility_owner_get(world, entity_id, owner_id);
if (vis_owner != LIBRG_VISIBLITY_NEVER) {
/* prevent from being included */
librg_push_entity(entity_id);
}

/* immidiately skip, if entity was not placed correctly */
if (entity->chunks[0] == LIBRG_CHUNK_INVALID) continue;
Expand Down
30 changes: 27 additions & 3 deletions code/tests/cases/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,31 @@ MODULE(query, {
librg_world_destroy(world);
});

IT("should properly include always-owner-visible entity without regards of chunk radius", {
IT("should properly exclude owner-invisible own entity", {
librg_world *world = librg_world_create();

r = librg_entity_track(world, 1); EQUALS(r, LIBRG_OK);
r = librg_entity_track(world, 2); EQUALS(r, LIBRG_OK);
r = librg_entity_track(world, 3); EQUALS(r, LIBRG_OK);

r = librg_entity_chunk_set(world, 1, 1); EQUALS(r, LIBRG_OK);
r = librg_entity_chunk_set(world, 2, 1); EQUALS(r, LIBRG_OK);
r = librg_entity_chunk_set(world, 3, 1); EQUALS(r, LIBRG_OK);

r = librg_entity_owner_set(world, 1, 1); EQUALS(r, LIBRG_OK);
r = librg_entity_visibility_owner_set(world, 2, 1, LIBRG_VISIBLITY_NEVER); EQUALS(r, LIBRG_OK);
r = librg_entity_visibility_owner_set(world, 1, 1, LIBRG_VISIBLITY_NEVER); EQUALS(r, LIBRG_OK);

int64_t results[16] = {0};
size_t amt = 16;
librg_world_query(world, 1, 0, results, &amt);
EQUALS(amt, 1);
EQUALS(results[0], 3);

librg_world_destroy(world);
});

IT("should properly include default-owner-visible entity without regards of chunk radius", {
librg_world *world = librg_world_create();

r = librg_entity_track(world, 1); EQUALS(r, LIBRG_OK);
Expand All @@ -444,7 +468,7 @@ MODULE(query, {
librg_world_destroy(world);
});

IT("should properly include always-owner-visible entity without regards of dimension", {
IT("should properly include default-owner-visible entity without regards of dimension", {
librg_world *world = librg_world_create();

r = librg_entity_track(world, 1); EQUALS(r, LIBRG_OK);
Expand Down Expand Up @@ -495,7 +519,7 @@ MODULE(query, {
librg_world_destroy(world);
});

IT("should properly include always-owner-visible entity overriding always-globally-visible", {
IT("should exclude default-owner-visible entity overriding always-globally-visible", {
librg_world *world = librg_world_create();

r = librg_entity_track(world, 1); EQUALS(r, LIBRG_OK);
Expand Down

0 comments on commit 6710e7c

Please sign in to comment.