fix underlying comp cache issue

efd/v1
Dominik Madarász 2022-10-16 14:27:56 +02:00
parent ec6d489526
commit 3f30bb5079
5 changed files with 16 additions and 29 deletions

View File

@ -8,7 +8,7 @@ game_rulesdef game_rules = {
.item_pick_radius = 25.0f, .item_pick_radius = 25.0f,
.item_merger_radius = 75.0f, .item_merger_radius = 75.0f,
.item_attract_radius = 75.0f, .item_attract_radius = 75.0f,
.item_attract_force = .98f, .item_attract_force = 1.98f,
.item_container_reach_radius = 105.0f, .item_container_reach_radius = 105.0f,
.item_drop_pickup_time = 2.5f, .item_drop_pickup_time = 2.5f,
.item_drop_merger_time = 6.5f, .item_drop_merger_time = 6.5f,

View File

@ -18,19 +18,10 @@ uint64_t entity_spawn(uint16_t class_id) {
entity_wake(e); entity_wake(e);
if (class_id != EKIND_SERVER) { if (class_id != EKIND_SERVER) {
ecs_set(world_ecs(), e, Velocity, {0});
Position *pos = ecs_get_mut(world_ecs(), e, Position);
#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;
#endif
librg_entity_track(world_tracker(), e); librg_entity_track(world_tracker(), e);
librg_entity_chunk_set(world_tracker(), e, librg_chunk_from_realpos(world_tracker(), pos->x, pos->y, 0)); ecs_set(world_ecs(), e, Velocity, {0});
entity_set_position(e, (float)(rand() % world_dim()), (float)(rand() % world_dim()));
librg_entity_owner_set(world_tracker(), e, (int64_t)e); librg_entity_owner_set(world_tracker(), e, (int64_t)e);
} }
@ -69,7 +60,7 @@ void entity_despawn(uint64_t ent_id) {
} }
void entity_set_position(uint64_t ent_id, float x, float y) { void entity_set_position(uint64_t ent_id, float x, float y) {
Position *p = ecs_get_mut(world_ecs(), ent_id, Position); Position *p = ecs_get_mut_ex(world_ecs(), ent_id, Position);
p->x = x; p->x = x;
p->y = y; p->y = y;
librg_entity_chunk_set(world_tracker(), ent_id, librg_chunk_from_realpos(world_tracker(), x, y, 0)); librg_entity_chunk_set(world_tracker(), ent_id, librg_chunk_from_realpos(world_tracker(), x, y, 0));
@ -77,7 +68,7 @@ void entity_set_position(uint64_t ent_id, float x, float y) {
} }
void entity_wake(uint64_t ent_id) { void entity_wake(uint64_t ent_id) {
StreamInfo *si = ecs_get_mut(world_ecs(), ent_id, StreamInfo); StreamInfo *si = ecs_get_mut_ex(world_ecs(), ent_id, StreamInfo);
si->tick_delay = 0.0f; si->tick_delay = 0.0f;
si->last_update = 0.0f; si->last_update = 0.0f;
} }
@ -108,6 +99,6 @@ void entity_update_action_timers() {
} }
bool entity_can_stream(uint64_t ent_id) { bool entity_can_stream(uint64_t ent_id) {
StreamInfo *si = ecs_get_mut(world_ecs(), ent_id, StreamInfo); StreamInfo *si = ecs_get_mut_ex(world_ecs(), ent_id, StreamInfo);
return (si->last_update < get_cached_time()); return (si->last_update < get_cached_time());
} }

View File

@ -29,14 +29,7 @@ int32_t pkt_00_init_handler(pkt_header *header) {
uint64_t peer_id = (uint64_t)header->udata; uint64_t peer_id = (uint64_t)header->udata;
uint64_t ent_id = player_spawn(NULL); uint64_t ent_id = player_spawn(NULL);
Position *pos = ecs_get_mut(world_ecs(), ent_id, Position);
#if 1
entity_set_position(ent_id, world_dim()/2.0f + rand()%15*15.0f, 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();
#endif
zpl_printf("[INFO] initializing player entity id: %d with view id: %d for peer id: %d...\n", ent_id, table.view_id, peer_id); zpl_printf("[INFO] initializing player entity id: %d with view id: %d for peer id: %d...\n", ent_id, table.view_id, peer_id);
ecs_set(world_ecs(), ent_id, ClientInfo, {.peer = peer_id, .view_id = header->view_id, .active = false }); ecs_set(world_ecs(), ent_id, ClientInfo, {.peer = peer_id, .view_id = header->view_id, .active = false });

View File

@ -37,7 +37,8 @@ void IntegratePositions(ecs_iter_t *it) {
if (ecs_get(it->world, it->entities[i], IsInVehicle)) { if (ecs_get(it->world, it->entities[i], IsInVehicle)) {
continue; continue;
} }
if (zpl_abs(v[i].x) >= 0.001f || zpl_abs(v[i].y) >= 0.001f) { if (zpl_abs(v[i].x) >= 0.001f || zpl_abs(v[i].y) >= 0.001f)
{
// NOTE(zaklaus): world bounds // NOTE(zaklaus): world bounds
{ {
float w = (float)world_dim(); float w = (float)world_dim();

View File

@ -76,7 +76,7 @@ entity_view *world_build_entity_view(int64_t e) {
view.inside_vehicle = ecs_get(world_ecs(), e, IsInVehicle) != 0 ? true : false; view.inside_vehicle = ecs_get(world_ecs(), e, IsInVehicle) != 0 ? true : false;
Inventory *inv = 0; Inventory *inv = 0;
if ((inv = ecs_get_mut_if(world_ecs(), e, Inventory))) { if ((inv = ecs_get_mut_if_ex(world_ecs(), e, Inventory))) {
view.has_items = true; view.has_items = true;
for (int i = 0; i < ITEMS_INVENTORY_SIZE; i += 1) { for (int i = 0; i < ITEMS_INVENTORY_SIZE; i += 1) {
@ -92,7 +92,7 @@ entity_view *world_build_entity_view(int64_t e) {
if (world_entity_valid(in->storage_ent)){ if (world_entity_valid(in->storage_ent)){
ItemContainer *ic = 0; ItemContainer *ic = 0;
if ((ic = ecs_get_mut_if(world_ecs(), in->storage_ent, ItemContainer))){ if ((ic = ecs_get_mut_if_ex(world_ecs(), in->storage_ent, ItemContainer))){
view.has_storage_items = true; view.has_storage_items = true;
for (int i = 0; i < ITEMS_CONTAINER_SIZE; i += 1) { for (int i = 0; i < ITEMS_CONTAINER_SIZE; i += 1) {
@ -640,8 +640,10 @@ bool world_entity_valid(ecs_entity_t e) {
return ecs_is_alive(world_ecs(), e); return ecs_is_alive(world_ecs(), e);
} }
void * world_component_cached(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id) { void * world_component_cached(ecs_world_t *world_ecs, ecs_entity_t entity, ecs_id_t id) {
// return ecs_get_mut_id(world, entity, id); if (!component_cache.entries || world.ecs_stage == NULL) {
return ecs_get_mut_id(world_ecs, entity, id);
}
static char buffer[256] = {0}; static char buffer[256] = {0};
zpl_snprintf(buffer, 256, "%llu_%llu", entity, id); zpl_snprintf(buffer, 256, "%llu_%llu", entity, id);
@ -650,7 +652,7 @@ void * world_component_cached(ecs_world_t *world, ecs_entity_t entity, ecs_id_t
zpl_uintptr *value = world_component_cache_get(&component_cache, uid); zpl_uintptr *value = world_component_cache_get(&component_cache, uid);
if (!value) { if (!value) {
void *the_value = ecs_get_mut_id(world, entity, id); void *the_value = ecs_get_mut_id(world_ecs, entity, id);
world_component_cache_set(&component_cache, uid, (zpl_uintptr)the_value); world_component_cache_set(&component_cache, uid, (zpl_uintptr)the_value);
value = world_component_cache_get(&component_cache, uid); value = world_component_cache_get(&component_cache, uid);
} }