code: reenable demo replace block

isolation_bkp/dynres
Dominik Madarász 2021-08-11 11:24:44 +02:00
parent ba345065bb
commit 27bdc1f3a1
5 changed files with 14 additions and 13 deletions

View File

@ -365,26 +365,26 @@ int64_t world_chunk_from_entity(ecs_entity_t id) {
return librg_entity_chunk_get(world.tracker, 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)); assert(block_idx >= 0 && block_idx < zpl_square(world.chunk_size));
world.block_mapping[id][block_idx] = block_id; 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) { uint8_t *world_chunk_get_blocks(int64_t id) {
return world.block_mapping[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; 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); assert(!was_added);
if (chunk) chunk->is_dirty = true; 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; 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); assert(!was_added);
if (chunk) return chunk->is_dirty; if (chunk) return chunk->is_dirty;
return false; return false;

View File

@ -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); 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_realpos(float x, float y);
int64_t world_chunk_from_entity(ecs_entity_t id); 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); uint8_t *world_chunk_get_blocks(int64_t id);
void world_chunk_mark_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_entity_t e); uint8_t world_chunk_is_dirty(ecs_world_t *ecs, ecs_entity_t e);
// NOTE(zaklaus): Uses locally persistent buffer !! // NOTE(zaklaus): Uses locally persistent buffer !!
int64_t *world_chunk_fetch_entities(librg_chunk chunk_id, size_t *ents_len); int64_t *world_chunk_fetch_entities(librg_chunk chunk_id, size_t *ents_len);

View File

@ -103,10 +103,10 @@ void SystemsImport(ecs_world_t *ecs) {
ECS_MODULE(ecs, Systems); ECS_MODULE(ecs, Systems);
ECS_SYSTEM(ecs, MovementImpulse, EcsOnLoad, components.Input, components.Velocity, !components.IsInVehicle); 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, DemoNPCMoveAround, EcsOnLoad, components.Velocity, components.EcsDemoNPC);
ECS_SYSTEM(ecs, EnterVehicle, EcsOnLoad, components.Input, components.Position, !components.IsInVehicle); ECS_SYSTEM(ecs, EnterVehicle, EcsOnLoad, components.Input, components.Position, !components.IsInVehicle);
ECS_SYSTEM(ecs, LeaveVehicle, EcsOnLoad, components.Input, 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, MoveWalk, EcsOnUpdate, components.Position, components.Velocity);
ECS_SYSTEM(ecs, HurtOnHazardBlock, EcsOnUpdate, components.Position, components.Health); ECS_SYSTEM(ecs, HurtOnHazardBlock, EcsOnUpdate, components.Position, components.Health);

View File

@ -17,8 +17,9 @@ void DemoPlaceIceBlock(ecs_iter_t *it) {
for (int i = 0; i < it->count; i++) { for (int i = 0; i < it->count; i++) {
if (in[i].use) { if (in[i].use) {
in[i].use = false;
world_block_lookup l = world_block_from_realpos(p[i].x, p[i].y); 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);
} }
} }
} }

View File

@ -7,7 +7,6 @@ void LeaveVehicle(ecs_iter_t *it) {
for (int i = 0; i < it->count; i++) { for (int i = 0; i < it->count; i++) {
if (!in[i].use) continue; if (!in[i].use) continue;
in[i].use = false;
Vehicle *veh = 0; Vehicle *veh = 0;
if ((veh = ecs_get_mut_if(it->world, vehp->veh, Vehicle))) { 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); ecs_remove(it->world, it->entities[i], IsInVehicle);
} else { } else {
ZPL_PANIC("unreachable code"); ZPL_PANIC("unreachable code");
@ -31,7 +31,6 @@ void EnterVehicle(ecs_iter_t *it) {
for (int i = 0; i < it->count; i++) { for (int i = 0; i < it->count; i++) {
if (!in[i].use) continue; if (!in[i].use) continue;
in[i].use = false;
size_t ents_count; size_t ents_count;
int64_t *ents = world_chunk_query_entities(it->entities[i], &ents_count, 2); 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] .veh = ents[j]
}); });
p[i] = *p2; p[i] = *p2;
in[i].use = false;
break; break;
} }
} }