improve build mode

isolation_bkp/dynres
Dominik Madarász 2021-11-03 16:29:45 +01:00
parent 428e59c69e
commit 9d6993d7b1
4 changed files with 34 additions and 15 deletions

View File

@ -80,18 +80,7 @@ ActEraseWorldChanges(void) {
for (int y = 0; y < 100; y++) { for (int y = 0; y < 100; y++) {
for (int x = 0; x < 100; x++) { for (int x = 0; x < 100; x++) {
world_block_lookup l = world_block_from_realpos((p->x - (x*bs)/2.0f), p->y - (y*bs)/2.0f); world_chunk_destroy_block((p->x - (x*bs)/2.0f), (p->y - (y*bs)/2.0f), true);
world_chunk_place_block(l.chunk_id, l.id, 0);
if (l.is_outer && l.block_id > 0) {
asset_id item_asset = blocks_get_asset(l.block_id);
if (item_find(item_asset) == ASSET_INVALID) continue;
uint64_t e = item_spawn(item_asset, 1);
Position *dest = ecs_get_mut(world_ecs(), e, Position, NULL);
dest->x = (p->x - (x*bs)/2.0f);
dest->y = (p->y - (y*bs)/2.0f);
}
} }
} }

View File

@ -54,7 +54,10 @@ void item_use(ecs_world_t *ecs, ItemDrop *it, Position p, uint64_t udata) {
case UKIND_HOLD: /* NOOP */ break; case UKIND_HOLD: /* NOOP */ break;
case UKIND_PLACE:{ case UKIND_PLACE:{
world_block_lookup l = world_block_from_realpos(p.x, p.y); world_block_lookup l = world_block_from_realpos(p.x, p.y);
if (world_chunk_place_block(l.chunk_id, l.id, blocks_find(desc->place.kind + (asset_id)udata)) ) if (l.block_id > 0) {
world_chunk_destroy_block(p.x, p.y, true);
}
world_chunk_replace_block(l.chunk_id, l.id, blocks_find(desc->place.kind + (asset_id)udata));
it->quantity--; it->quantity--;
}break; }break;
} }

View File

@ -430,6 +430,21 @@ world_block_lookup world_block_from_realpos(float x, float y) {
return lookup; return lookup;
} }
void world_chunk_destroy_block(float x, float y, bool drop_item) {
world_block_lookup l = world_block_from_realpos(x, y);
world_chunk_replace_block(l.chunk_id, l.id, 0);
if (l.is_outer && l.block_id > 0 && drop_item) {
asset_id item_asset = blocks_get_asset(l.block_id);
if (item_find(item_asset) == ASSET_INVALID) return;
uint64_t e = item_spawn(item_asset, 1);
Position *dest = ecs_get_mut(world_ecs(), e, Position, NULL);
dest->x = x;
dest->y = 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) {
uint8_t block_id = world.outer_block_mapping[id][block_idx]; uint8_t block_id = world.outer_block_mapping[id][block_idx];
if (block_id == 0) { if (block_id == 0) {
@ -455,12 +470,18 @@ 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_worldgen_block(int64_t id, uint16_t block_idx, uint8_t block_id) {
ZPL_ASSERT(block_idx >= 0 && block_idx < zpl_square(world.chunk_size)); ZPL_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(world.chunk_mapping[id]);
} }
void world_chunk_replace_block(int64_t id, uint16_t block_idx, uint8_t block_id) {
ZPL_ASSERT(block_idx >= 0 && block_idx < zpl_square(world.chunk_size));
world.outer_block_mapping[id][block_idx] = block_id;
world_chunk_mark_dirty(world.chunk_mapping[id]);
}
bool world_chunk_place_block(int64_t id, uint16_t block_idx, uint8_t block_id) { bool world_chunk_place_block(int64_t id, uint16_t block_idx, uint8_t block_id) {
ZPL_ASSERT(block_idx >= 0 && block_idx < zpl_square(world.chunk_size)); ZPL_ASSERT(block_idx >= 0 && block_idx < zpl_square(world.chunk_size));
if (world.outer_block_mapping[id][block_idx] != 0 && block_id != 0) return false; if (world.outer_block_mapping[id][block_idx] != 0 && block_id != 0) return false;

View File

@ -89,8 +89,14 @@ 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_worldgen_block(int64_t id, uint16_t block_idx, uint8_t block_id);
void world_chunk_replace_block(int64_t id, uint16_t block_idx, uint8_t block_id); void world_chunk_replace_block(int64_t id, uint16_t block_idx, uint8_t block_id);
bool world_chunk_place_block(int64_t id, uint16_t block_idx, uint8_t block_id); bool world_chunk_place_block(int64_t id, uint16_t block_idx, uint8_t block_id);
void world_chunk_destroy_block(float x, float y, bool drop_item);
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_entity_t e);
uint8_t world_chunk_is_dirty(ecs_entity_t e); uint8_t world_chunk_is_dirty(ecs_entity_t e);