diff --git a/code/game/src/world/world.c b/code/game/src/world/world.c index ef97de1..2868ac6 100644 --- a/code/game/src/world/world.c +++ b/code/game/src/world/world.c @@ -365,26 +365,26 @@ int64_t world_chunk_from_entity(ecs_entity_t id) { return librg_entity_chunk_get(world.tracker, id); } -void world_chunk_replace_block(int64_t id, uint16_t block_idx, uint8_t block_id) { +void world_chunk_replace_block(ecs_world_t *ecs, int64_t id, uint16_t block_idx, uint8_t block_id) { assert(block_idx >= 0 && block_idx < zpl_square(world.chunk_size)); world.block_mapping[id][block_idx] = block_id; - world_chunk_mark_dirty(world.chunk_mapping[id]); + world_chunk_mark_dirty(ecs, world.chunk_mapping[id]); } uint8_t *world_chunk_get_blocks(int64_t id) { return world.block_mapping[id]; } -void world_chunk_mark_dirty(ecs_entity_t e) { +void world_chunk_mark_dirty(ecs_world_t *ecs, ecs_entity_t e) { bool was_added=false; - Chunk *chunk = ecs_get_mut(world_ecs(), e, Chunk, &was_added); + Chunk *chunk = ecs_get_mut(ecs, e, Chunk, &was_added); assert(!was_added); if (chunk) chunk->is_dirty = true; } -uint8_t world_chunk_is_dirty(ecs_entity_t e) { +uint8_t world_chunk_is_dirty(ecs_world_t *ecs, ecs_entity_t e) { bool was_added=false; - Chunk *chunk = ecs_get_mut(world_ecs(), e, Chunk, &was_added); + Chunk *chunk = ecs_get_mut(ecs, e, Chunk, &was_added); assert(!was_added); if (chunk) return chunk->is_dirty; return false; diff --git a/code/game/src/world/world.h b/code/game/src/world/world.h index 6359338..c861e94 100644 --- a/code/game/src/world/world.h +++ b/code/game/src/world/world.h @@ -73,10 +73,10 @@ world_block_lookup world_block_from_realpos(float x, float y); world_block_lookup world_block_from_index(int64_t id, uint16_t block_idx); int64_t world_chunk_from_realpos(float x, float y); int64_t world_chunk_from_entity(ecs_entity_t id); -void world_chunk_replace_block(int64_t id, uint16_t block_idx, uint8_t block_id); +void world_chunk_replace_block(ecs_world_t *ecs, int64_t id, uint16_t block_idx, uint8_t block_id); uint8_t *world_chunk_get_blocks(int64_t id); -void world_chunk_mark_dirty(ecs_entity_t e); -uint8_t world_chunk_is_dirty(ecs_entity_t e); +void world_chunk_mark_dirty(ecs_world_t *ecs, ecs_entity_t e); +uint8_t world_chunk_is_dirty(ecs_world_t *ecs, ecs_entity_t e); // NOTE(zaklaus): Uses locally persistent buffer !! int64_t *world_chunk_fetch_entities(librg_chunk chunk_id, size_t *ents_len); diff --git a/code/modules/modules/systems.c b/code/modules/modules/systems.c index 4874cc0..7a7e5b4 100644 --- a/code/modules/modules/systems.c +++ b/code/modules/modules/systems.c @@ -103,10 +103,10 @@ void SystemsImport(ecs_world_t *ecs) { ECS_MODULE(ecs, Systems); ECS_SYSTEM(ecs, MovementImpulse, EcsOnLoad, components.Input, components.Velocity, !components.IsInVehicle); - //ECS_SYSTEM(ecs, DemoPlaceIceBlock, EcsOnLoad, components.Input, components.Position); ECS_SYSTEM(ecs, DemoNPCMoveAround, EcsOnLoad, components.Velocity, components.EcsDemoNPC); ECS_SYSTEM(ecs, EnterVehicle, EcsOnLoad, components.Input, components.Position, !components.IsInVehicle); ECS_SYSTEM(ecs, LeaveVehicle, EcsOnLoad, components.Input, components.IsInVehicle); + ECS_SYSTEM(ecs, DemoPlaceIceBlock, EcsOnLoad, components.Input, components.Position, !components.IsInVehicle); ECS_SYSTEM(ecs, MoveWalk, EcsOnUpdate, components.Position, components.Velocity); ECS_SYSTEM(ecs, HurtOnHazardBlock, EcsOnUpdate, components.Position, components.Health); diff --git a/code/modules/source/system_demo.c b/code/modules/source/system_demo.c index 93b4add..f886c8f 100644 --- a/code/modules/source/system_demo.c +++ b/code/modules/source/system_demo.c @@ -17,8 +17,9 @@ void DemoPlaceIceBlock(ecs_iter_t *it) { for (int i = 0; i < it->count; i++) { if (in[i].use) { + in[i].use = false; world_block_lookup l = world_block_from_realpos(p[i].x, p[i].y); - world_chunk_replace_block(l.chunk_id, l.id, watr_id); + world_chunk_replace_block(it->world, l.chunk_id, l.id, watr_id); } } } diff --git a/code/modules/source/system_vehicle.c b/code/modules/source/system_vehicle.c index 99ef4f5..32bb610 100644 --- a/code/modules/source/system_vehicle.c +++ b/code/modules/source/system_vehicle.c @@ -7,7 +7,6 @@ void LeaveVehicle(ecs_iter_t *it) { for (int i = 0; i < it->count; i++) { if (!in[i].use) continue; - in[i].use = false; Vehicle *veh = 0; if ((veh = ecs_get_mut_if(it->world, vehp->veh, Vehicle))) { @@ -18,6 +17,7 @@ void LeaveVehicle(ecs_iter_t *it) { } } + in[i].use = false; ecs_remove(it->world, it->entities[i], IsInVehicle); } else { ZPL_PANIC("unreachable code"); @@ -31,7 +31,6 @@ void EnterVehicle(ecs_iter_t *it) { for (int i = 0; i < it->count; i++) { if (!in[i].use) continue; - in[i].use = false; size_t ents_count; int64_t *ents = world_chunk_query_entities(it->entities[i], &ents_count, 2); @@ -54,6 +53,7 @@ void EnterVehicle(ecs_iter_t *it) { .veh = ents[j] }); p[i] = *p2; + in[i].use = false; break; } }