update tracker pos conditionally + optimisations

isolation_bkp/dynres
Dominik Madarász 2022-09-14 08:02:35 +00:00 committed by GitHub
parent 449ebc6de2
commit c4e4ff0587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 961 additions and 951 deletions

View File

@ -16,6 +16,7 @@ ActSpawnCar(void) {
Position const* origin = ecs_get(world_ecs(), plr, Position);
Position * dest = ecs_get_mut(world_ecs(), e, Position);
*dest = *origin;
entity_set_position(e, dest->x, dest->y);
debug_replay_special_action(RPKIND_SPAWN_CAR);
}
@ -28,6 +29,7 @@ ActSpawnIcemaker(void) {
Position const* origin = ecs_get(world_ecs(), plr, Position);
Position * dest = ecs_get_mut(world_ecs(), e, Position);
*dest = *origin;
entity_set_position(e, dest->x, dest->y);
debug_replay_special_action(RPKIND_SPAWN_ICEMAKER_ITEM);
}
@ -40,6 +42,7 @@ ActSpawnChest(void) {
Position const* origin = ecs_get(world_ecs(), plr, Position);
Position * dest = ecs_get_mut(world_ecs(), e, Position);
*dest = *origin;
entity_set_position(e, dest->x, dest->y);
debug_replay_special_action(RPKIND_SPAWN_CHEST);
}
@ -52,6 +55,7 @@ ActSpawnBelt(void) {
Position const* origin = ecs_get(world_ecs(), plr, Position);
Position * dest = ecs_get_mut(world_ecs(), e, Position);
*dest = *origin;
entity_set_position(e, dest->x, dest->y);
debug_replay_special_action(RPKIND_SPAWN_BELT);
}
@ -67,6 +71,8 @@ ActSpawnCirclingDriver(void) {
Position *dest = ecs_get_mut(world_ecs(), e, Position);
*veh_dest = *origin;
*dest = *origin;
entity_set_position(ve, veh_dest->x, veh_dest->y);
entity_set_position(e, dest->x, dest->y);
Input *input = ecs_get_mut(world_ecs(), e, Input);
zpl_zero_item(input);

View File

@ -20,6 +20,7 @@ uint64_t entity_spawn(uint16_t class_id) {
#if 1
pos->x=(float)(rand() % world_dim());
pos->y=(float)(rand() % world_dim());
entity_set_position(e, pos->x, pos->y);
#else
pos->x=350.0f;
pos->y=88.0f;
@ -63,7 +64,7 @@ void entity_set_position(uint64_t ent_id, float x, float y) {
Position *p = ecs_get_mut(world_ecs(), ent_id, Position);
p->x = x;
p->y = y;
librg_entity_chunk_set(world_tracker(), ent_id, librg_chunk_from_realpos(world_tracker(), x, y, 0));
entity_wake(ent_id);
}

View File

@ -86,9 +86,7 @@ void item_use(ecs_world_t *ecs, ItemDrop *it, Position p, uint64_t udata) {
ecs_entity_t e = entity_spawn_id(desc->place_item.id);
ZPL_ASSERT(world_entity_valid(e));
Position *pos = ecs_get_mut(ecs, e, Position);
pos->x = p.x;
pos->y = p.y;
entity_set_position(e, p.x, p.y);
it->quantity--;
}break;

View File

@ -7,6 +7,7 @@
#include "entity_view.h"
#include "camera.h"
#include "player.h"
#include "entity.h"
#include "modules/components.h"
#include "modules/systems.h"
@ -31,8 +32,7 @@ int32_t pkt_00_init_handler(pkt_header *header) {
Position *pos = ecs_get_mut(world_ecs(), ent_id, Position);
#if 1
pos->x = world_dim()/2.0f + rand()%15*15.0f;
pos->y = world_dim()/2.0f + rand()%15*15.0f;
entity_set_position(ent_id, world_dim()/2.0f + rand()%15*15.0f, world_dim()/2.0f + rand()%15*15.0f);
#else
pos->x = rand()%world_dim();
pos->y = rand()%world_dim();

View File

@ -8,6 +8,7 @@
#include "world/perlin.h"
#include "modules/components.h"
#include "entity.h"
#include "vehicle.h"
#include "items.h"
#include "world/blocks_info.h"
@ -133,6 +134,9 @@ static WORLD_BLOCK_OBSERVER(shaper_noise05b) {
return world_perlin_cond_offset(block_idx, 0.05, 32, 0) ? shaper(data, id, block_idx) : BLOCK_INVALID;
}
static WORLD_BLOCK_OBSERVER(shaper_noise01b) {
return world_perlin_cond_offset(block_idx, 0.01, 32, 0) ? shaper(data, id, block_idx) : BLOCK_INVALID;
}
#else
static WORLD_BLOCK_OBSERVER(shaper_noise80) {
return rand()%10 < 8 ? shaper(id, block_idx) : BLOCK_INVALID;
@ -177,7 +181,7 @@ int32_t worldgen_test(world_data *wld) {
// ground
world_fill_rect(world->data, grnd_id, 1, 1, world->dim-2, world->dim-2, NULL);
world_fill_rect(world->data, dirt_id, 1, 1, world->dim-2, world->dim-2, shaper_noise05);
world_fill_rect(world->outer_data, tree_id, 1, 1, world->dim-2, world->dim-2, shaper_noise05b);
world_fill_rect(world->outer_data, tree_id, 1, 1, world->dim-2, world->dim-2, shaper_noise01b);
// water
#if 1
@ -215,6 +219,7 @@ int32_t worldgen_test(world_data *wld) {
Position *dest = ecs_get_mut(world_ecs(), e, Position);
dest->x = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
dest->y = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
entity_set_position(e, dest->x, dest->y);
}
#endif
@ -226,6 +231,7 @@ int32_t worldgen_test(world_data *wld) {
Position *dest = ecs_get_mut(world_ecs(), e, Position);
dest->x = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
dest->y = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
entity_set_position(e, dest->x, dest->y);
}
for (int i=0; i<RAND_RANGE(328, 164); i++) {
@ -234,6 +240,7 @@ int32_t worldgen_test(world_data *wld) {
Position *dest = ecs_get_mut(world_ecs(), e, Position);
dest->x = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
dest->y = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
entity_set_position(e, dest->x, dest->y);
}
for (int i=0; i<RAND_RANGE(328, 164); i++) {
@ -242,6 +249,7 @@ int32_t worldgen_test(world_data *wld) {
Position *dest = ecs_get_mut(world_ecs(), e, Position);
dest->x = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
dest->y = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
entity_set_position(e, dest->x, dest->y);
}
for (int i=0; i<RAND_RANGE(128, 564); i++) {
@ -250,6 +258,7 @@ int32_t worldgen_test(world_data *wld) {
Position *dest = ecs_get_mut(world_ecs(), e, Position);
dest->x = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
dest->y = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
entity_set_position(e, dest->x, dest->y);
}
for (int i=0; i<RAND_RANGE(128, 964); i++) {
@ -258,6 +267,7 @@ int32_t worldgen_test(world_data *wld) {
Position *dest = ecs_get_mut(world_ecs(), e, Position);
dest->x = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
dest->y = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
entity_set_position(e, dest->x, dest->y);
}
#endif

View File

@ -57,8 +57,7 @@ void IntegratePositions(ecs_iter_t *it) {
}
#endif
p[i].x += v[i].x * safe_dt(it);
p[i].y += v[i].y * safe_dt(it);
entity_set_position(it->entities[i], p[i].x+v[i].x*safe_dt(it), p[i].y+v[i].y*safe_dt(it));
}
{
@ -70,20 +69,6 @@ void IntegratePositions(ecs_iter_t *it) {
}
}
void UpdateTrackerPos(ecs_iter_t *it) {
Position *p = ecs_field(it, Position, 1);
for (int i = 0; i < it->count; i++){
librg_entity_chunk_set(world_tracker(), it->entities[i], librg_chunk_from_realpos(world_tracker(), p[i].x, p[i].y, 0));
{
debug_v2 a = {p[i].x-2.5f, p[i].y-2.5f};
debug_v2 b = {p[i].x+2.5f, p[i].y+2.5f};
debug_push_rect(a, b, 0x00FFFFFF);
}
}
}
#define HAZARD_BLOCK_TIME 1.0f
#define HAZARD_BLOCK_DMG 5.0f
@ -228,8 +213,6 @@ void SystemsImport(ecs_world_t *ecs) {
ECS_SYSTEM(ecs, ResetActivators, EcsPostUpdate, components.Input);
ECS_SYSTEM(ecs, UpdateTrackerPos, EcsPostUpdate, components.Position, components.Velocity);
ECS_SYSTEM(ecs, ClearVehicle, EcsUnSet, components.Vehicle);
ECS_SYSTEM(ecs, DisableWorldEdit, EcsPostUpdate);

View File

@ -3,7 +3,7 @@
#define ITEM_PICK_RADIUS 25.0f
#define ITEM_MERGER_RADIUS 75.0f
#define ITEM_ATTRACT_RADIUS 75.0f
#define ITEM_ATTRACT_FORCE 0.63f
#define ITEM_ATTRACT_FORCE 6.f
#define ITEM_CONTAINER_REACH_RADIUS 105.0f
@ -13,6 +13,7 @@ void PickItem(ecs_iter_t *it) {
for (int i = 0; i < it->count; i++) {
if (inv[i].pickup_time > game_time()) continue;
inv[i].pickup_time = game_time() + 0.5f;
size_t ents_count;
int64_t *ents = world_chunk_query_entities(it->entities[i], &ents_count, 2);
@ -20,6 +21,7 @@ void PickItem(ecs_iter_t *it) {
ItemDrop *drop = 0;
if ((drop = ecs_get_mut_if(it->world, ents[j], ItemDrop))) {
Position *p2 = ecs_get_mut(it->world, ents[j], Position);
Velocity *v2 = ecs_get_mut(it->world, ents[j], Velocity);
float dx = p2->x - p[i].x;
float dy = p2->y - p[i].y;
@ -43,9 +45,8 @@ void PickItem(ecs_iter_t *it) {
}
}
} else if (range <= ITEM_ATTRACT_RADIUS) {
entity_set_position(ents[j],
zpl_lerp(p2->x, p[i].x, ITEM_ATTRACT_FORCE*it->delta_time),
zpl_lerp(p2->y, p[i].y, ITEM_ATTRACT_FORCE*it->delta_time));
v2->x = (p[i].x - p2->x) * ITEM_ATTRACT_FORCE;
v2->y = (p[i].y - p2->y) * ITEM_ATTRACT_FORCE;
}
}
}

View File

@ -155,11 +155,9 @@ void VehicleHandling(ecs_iter_t *it) {
// NOTE(zaklaus): Update passenger position
{
Position *p2 = ecs_get_mut(it->world, pe, Position);
Velocity *v2 = ecs_get_mut(it->world, pe, Velocity);
*p2 = p[i];
entity_set_position(pe, p[i].x+v[i].x, p[i].y+v[i].y);
*v2 = v[i];
entity_wake(pe);
}
}

25
code/vendors/librg.h vendored
View File

@ -21520,11 +21520,13 @@ int32_t librg_world_query(librg_world *world, int64_t owner_id, uint8_t chunk_ra
size_t buffer_limit = *entity_amount;
size_t total_count = zpl_array_count(wld->entity_map.entries);
librg_table_i64 results = {0};
librg_table_tbl dimensions = {0};
static librg_table_i64 results = {0};
static librg_table_tbl dimensions = {0};
librg_table_i64_init(&results, wld->allocator);
librg_table_tbl_init(&dimensions, wld->allocator);
if (!results.entries) {
librg_table_i64_init(&results, wld->allocator);
librg_table_tbl_init(&dimensions, wld->allocator);
}
/* generate a map of visible chunks (only counting owned entities) */
for (size_t i=0; i < total_count; ++i) {
@ -21621,8 +21623,19 @@ int32_t librg_world_query(librg_world *world, int64_t owner_id, uint8_t chunk_ra
for (int i = 0; i < zpl_array_count(dimensions.entries); ++i)
librg_table_i64_destroy(&dimensions.entries[i].value);
librg_table_tbl_destroy(&dimensions);
librg_table_i64_destroy(&results);
// NOTE(zaklaus): clear out our streaming snapshot
// TODO(zaklaus): move this to zpl
{
zpl_array_clear(results.hashes);
zpl_array_clear(results.entries);
}
// NOTE(zaklaus): clear out our streaming snapshot
// TODO(zaklaus): move this to zpl
{
zpl_array_clear(dimensions.hashes);
zpl_array_clear(dimensions.entries);
}
*entity_amount = LIBRG_MIN(buffer_limit, count);
return LIBRG_MAX(0, (int32_t)(count - buffer_limit));