Skip to content

Commit

Permalink
code: updated example apps to support new radius system
Browse files Browse the repository at this point in the history
  • Loading branch information
inlife committed May 8, 2021
1 parent 06ca629 commit 0f2296d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
3 changes: 2 additions & 1 deletion code/apps/example-enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ int server_update() {
librg_entity_track(server_world, entity_id);
librg_entity_owner_set(server_world, entity_id, event.peer->incomingPeerID);
librg_entity_chunk_set(server_world, entity_id, 1);
librg_entity_radius_set(server_world, entity_id, 2); /* 2 chunk radius visibility */
librg_entity_userdata_set(server_world, entity_id, event.peer); /* save ptr to peer */

/* allocate and store entity position in the data part of peer */
Expand Down Expand Up @@ -191,6 +190,7 @@ int server_update() {
librg_world_write(
server_world,
currentPeer->incomingPeerID,
2, /* chunk radius */
buffer,
&buffer_length,
NULL
Expand Down Expand Up @@ -341,6 +341,7 @@ int client_update(int ID, librg_world *world) {
librg_world_write(
world,
ID,
0,
buffer,
&buffer_length,
NULL
Expand Down
4 changes: 2 additions & 2 deletions code/apps/example-packing.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ int main() {
/* and track a special entity for our owner */
const int owner = 42;
const int owner_entity = 777;
const int radius = 1;
librg_entity_track(world, owner_entity);
librg_entity_chunk_set(world, owner_entity, 1);
librg_entity_owner_set(world, owner_entity, owner);
librg_entity_radius_set(world, owner_entity, 1);

/* since we've placed our entities in chunks 0,1,2,3 */
/* and our owner entity is in chunk 1, with visibility radius of 1 */
Expand All @@ -76,7 +76,7 @@ int main() {

/* write owner viewport to the buffer */
char buffer[256] = {0}; size_t total_size = 256;
librg_world_write(world, owner, buffer, &total_size, NULL);
librg_world_write(world, owner, radius, buffer, &total_size, NULL);

/* now our buffer contains packed world data */
/* specific for that given owner id (42) */
Expand Down
5 changes: 2 additions & 3 deletions code/apps/example-simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ int main() {
librg_entity_track(world, 1);
librg_entity_owner_set(world, 1, 1);
librg_entity_chunk_set(world, 1, 1);
librg_entity_radius_set(world, 1, 1);

/* fetch entities via query */
int64_t entities[64] = {0};
size_t entity_amount = 64;
librg_world_query(world, 1, entities, &entity_amount);
librg_world_query(world, 1, 0, entities, &entity_amount);

/* write owner's point of view to a buffer */
char buffer[256] = {0};
size_t buffer_legnth = 256;
librg_world_write(world, 1, buffer, &buffer_legnth, NULL);
librg_world_write(world, 1, 0, buffer, &buffer_legnth, NULL);
printf("written a buffer of length %d\n", (int)buffer_legnth);

librg_world_destroy(world);
Expand Down
5 changes: 2 additions & 3 deletions code/apps/manual-testing.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ int main() {
zpl_printf("setting chunk to: %lld\n", chunkId);
librg_entity_chunk_set(world, myId, chunkId);
librg_entity_owner_set(world, myId, 1);
librg_entity_radius_set(world, myId, observerRadius);

const int totalEnts = 40000;
for (int i=0;i<totalEnts;i++) {
Expand All @@ -82,7 +81,7 @@ int main() {

zpl_f64 tstart = zpl_time_rel();
size_t amount = RESSIZE;
librg_world_query(world, 1, results, &amount);
librg_world_query(world, 1, observerRadius, results, &amount);
zpl_printf("query found %d results of %d in (%.3f ms)\n", amount, totalEnts, zpl_time_rel() - tstart);
// for (int i=0; i<amount; i++) zpl_printf("result #%d: %lld\n", i, results[i]);

Expand All @@ -91,7 +90,7 @@ int main() {
tstart = zpl_time_rel();

size_t buffer_size = 10000;
int32_t result = librg_world_write(world, 1, buffer, &buffer_size, NULL);
int32_t result = librg_world_write(world, 1, observerRadius, buffer, &buffer_size, NULL);

if (result > 0) {
printf("AAA, you didnt have enough space to write stuff in your buffer mister\n");
Expand Down

0 comments on commit 0f2296d

Please sign in to comment.