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