various improvements
parent
4ee2524773
commit
30f34d51e5
|
@ -59,10 +59,12 @@ void assets_destroy(void) {
|
|||
}
|
||||
|
||||
uint16_t assets_find(asset_id id) {
|
||||
for (uint32_t i=0; i<ASSETS_COUNT; i++) {
|
||||
for (uint16_t i=0; i<ASSETS_COUNT; i++) {
|
||||
if (assets[i].id == id)
|
||||
return i;
|
||||
}
|
||||
|
||||
ZPL_PANIC("Unknown asset id: %d\n", id);
|
||||
return ASSET_INVALID;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,15 @@ ActEraseWorldChanges(void) {
|
|||
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_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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,19 +11,6 @@
|
|||
#include "items_list.c"
|
||||
#define ITEMS_COUNT (sizeof(items)/sizeof(item_desc))
|
||||
|
||||
uint64_t item_spawn(asset_id kind, uint32_t qty) {
|
||||
ecs_entity_t e = entity_spawn(EKIND_ITEM);
|
||||
|
||||
ItemDrop *d = ecs_get_mut(world_ecs(), e, ItemDrop, NULL);
|
||||
*d = (ItemDrop){
|
||||
.kind = kind,
|
||||
.quantity = qty,
|
||||
.merger_time = 0,
|
||||
};
|
||||
|
||||
return (uint64_t)e;
|
||||
}
|
||||
|
||||
static inline uint16_t item_resolve_proxy(uint16_t id) {
|
||||
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT);
|
||||
item_usage usage = items[id].usage;
|
||||
|
@ -33,11 +20,30 @@ static inline uint16_t item_resolve_proxy(uint16_t id) {
|
|||
return id;
|
||||
}
|
||||
|
||||
static inline asset_id item_fix_kind(asset_id id) {
|
||||
return items[item_find(id)].kind;
|
||||
}
|
||||
|
||||
uint64_t item_spawn(asset_id kind, uint32_t qty) {
|
||||
ecs_entity_t e = entity_spawn(EKIND_ITEM);
|
||||
|
||||
ItemDrop *d = ecs_get_mut(world_ecs(), e, ItemDrop, NULL);
|
||||
*d = (ItemDrop){
|
||||
.kind = item_fix_kind(kind),
|
||||
.quantity = qty,
|
||||
.merger_time = 0,
|
||||
};
|
||||
|
||||
return (uint64_t)e;
|
||||
}
|
||||
|
||||
uint16_t item_find(asset_id kind) {
|
||||
for (uint16_t i=0; i<ITEMS_COUNT; i++) {
|
||||
if (items[i].kind == kind)
|
||||
return item_resolve_proxy(i);
|
||||
}
|
||||
|
||||
ZPL_PANIC("Unknown asset id: %d\n", kind);
|
||||
return ASSET_INVALID;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,10 @@ uint8_t blocks_find(asset_id kind) {
|
|||
return 0xF;
|
||||
}
|
||||
|
||||
asset_id blocks_get_asset(uint8_t id) {
|
||||
return blocks[id].kind;
|
||||
}
|
||||
|
||||
char blocks_get_symbol(uint8_t id) {
|
||||
return blocks[id].symbol;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ void blocks_destroy(void);
|
|||
|
||||
uint8_t blocks_find(asset_id kind);
|
||||
|
||||
char *blocks_get_name(uint8_t id);
|
||||
asset_id blocks_get_asset(uint8_t id);
|
||||
char blocks_get_symbol(uint8_t id);
|
||||
uint32_t blocks_get_flags(uint8_t id);
|
||||
float blocks_get_drag(uint8_t id);
|
||||
|
|
|
@ -18,8 +18,8 @@ static block blocks[] = {
|
|||
BLOCK(ASSET_WOOD, BLOCK_FLAG_COLLISION, '#', .drag = 1.0f , .friction = 1.0f, .bounce = 0.0f),
|
||||
BLOCK(ASSET_TREE, BLOCK_FLAG_COLLISION, '@', .drag = 1.0f , .friction = 1.0f, .bounce = 0.0f),
|
||||
|
||||
BLOCK(ASSET_BELT_LEFT, 0, '@', .drag = 1.0f , .friction = 1.0f, .velx = -90.0f),
|
||||
BLOCK(ASSET_BELT_RIGHT, 0, '@', .drag = 1.0f , .friction = 1.0f, .velx = 90.0f),
|
||||
BLOCK(ASSET_BELT_UP, 0, '@', .drag = 1.0f , .friction = 1.0f, .vely = -90.0f),
|
||||
BLOCK(ASSET_BELT_DOWN, 0, '@', .drag = 1.0f , .friction = 1.0f, .vely = 90.0f),
|
||||
BLOCK(ASSET_BELT_LEFT, 0, '@', .drag = 1.0f , .friction = 1.0f, .velx = -120.0f),
|
||||
BLOCK(ASSET_BELT_RIGHT, 0, '@', .drag = 1.0f , .friction = 1.0f, .velx = 120.0f),
|
||||
BLOCK(ASSET_BELT_UP, 0, '@', .drag = 1.0f , .friction = 1.0f, .vely = -120.0f),
|
||||
BLOCK(ASSET_BELT_DOWN, 0, '@', .drag = 1.0f , .friction = 1.0f, .vely = 120.0f),
|
||||
};
|
||||
|
|
|
@ -403,12 +403,14 @@ world_block_lookup world_block_from_realpos(float x, float y) {
|
|||
float chx = x - chunk_x * size;
|
||||
float chy = y - chunk_y * size;
|
||||
|
||||
uint32_t bx = (uint32_t)chx / WORLD_BLOCK_SIZE;
|
||||
uint32_t by = (uint32_t)chy / WORLD_BLOCK_SIZE;
|
||||
uint32_t block_idx = (by*world.chunk_size)+bx;
|
||||
uint16_t bx = (uint16_t)chx / WORLD_BLOCK_SIZE;
|
||||
uint16_t by = (uint16_t)chy / WORLD_BLOCK_SIZE;
|
||||
uint16_t block_idx = (by*world.chunk_size)+bx;
|
||||
uint8_t block_id = world.outer_block_mapping[chunk_id][block_idx];
|
||||
bool is_outer = true;
|
||||
if (block_id == 0) {
|
||||
block_id = world.block_mapping[chunk_id][block_idx];
|
||||
is_outer = false;
|
||||
}
|
||||
|
||||
// NOTE(zaklaus): pos relative to block's center
|
||||
|
@ -422,6 +424,7 @@ world_block_lookup world_block_from_realpos(float x, float y) {
|
|||
.chunk_e = e,
|
||||
.ox = box,
|
||||
.oy = boy,
|
||||
.is_outer = is_outer,
|
||||
};
|
||||
|
||||
return lookup;
|
||||
|
|
|
@ -77,11 +77,12 @@ uint16_t world_dim(void);
|
|||
ecs_entity_t world_chunk_mapping(librg_chunk id);
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
uint16_t id;
|
||||
uint8_t block_id;
|
||||
ecs_entity_t chunk_e;
|
||||
int64_t chunk_id;
|
||||
float ox, oy;
|
||||
bool is_outer;
|
||||
} world_block_lookup;
|
||||
|
||||
world_block_lookup world_block_from_realpos(float x, float y);
|
||||
|
|
Loading…
Reference in New Issue