rework blueprinting to use asset ids instead
parent
686149829e
commit
7f098734f5
|
@ -157,7 +157,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
uint8_t w;
|
||||
uint8_t h;
|
||||
char plan[256];
|
||||
asset_id plan[256];
|
||||
} Blueprint;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -64,7 +64,7 @@ typedef struct {
|
|||
struct {
|
||||
uint8_t w;
|
||||
uint8_t h;
|
||||
const char plan[256];
|
||||
const asset_id *plan;
|
||||
} blueprint;
|
||||
};
|
||||
} item_desc;
|
||||
|
|
|
@ -9,7 +9,11 @@ static item_desc items[] = {
|
|||
ITEM_ENERGY(ASSET_WOOD, ASSET_FURNACE, 64, 15.0f),
|
||||
ITEM_HOLD(ASSET_TREE, 64),
|
||||
|
||||
ITEM_BLUEPRINT(ASSET_BLUEPRINT, 1, 4, 4, "]]]]]CF] ]]]]]"),
|
||||
// ITEM_BLUEPRINT(ASSET_BLUEPRINT, 1, 4, 4, "]]]]]CF] ]]]]]"),
|
||||
ITEM_BLUEPRINT(ASSET_BLUEPRINT, 1, 4, 4, PROT({ ASSET_WOOD,ASSET_WOOD,ASSET_WOOD,ASSET_WOOD,
|
||||
ASSET_WOOD,ASSET_FURNACE,ASSET_CHEST,ASSET_WOOD,
|
||||
ASSET_FENCE,ASSET_EMPTY,ASSET_EMPTY,ASSET_WOOD,
|
||||
ASSET_WALL,ASSET_EMPTY,ASSET_EMPTY,ASSET_WOOD})),
|
||||
|
||||
ITEM_SELF_DIR(ASSET_BELT, 999),
|
||||
ITEM_PROXY(ASSET_BELT_LEFT, ASSET_BELT),
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
.blueprint = {\
|
||||
.w = w_,\
|
||||
.h = h_,\
|
||||
.plan = plan_\
|
||||
.plan = (const asset_id[])plan_\
|
||||
},\
|
||||
.place_item = {\
|
||||
.id = asset\
|
||||
|
|
|
@ -8,15 +8,14 @@
|
|||
#include "models/items.h"
|
||||
#include "models/components.h"
|
||||
|
||||
uint64_t blueprint_spawn(uint8_t w, uint8_t h, const char *plan) {
|
||||
ZPL_ASSERT((w*h) == zpl_strlen(plan));
|
||||
uint64_t blueprint_spawn(uint8_t w, uint8_t h, const asset_id *plan) {
|
||||
ZPL_ASSERT((w*h) < 256);
|
||||
ecs_entity_t e = device_spawn(ASSET_BLUEPRINT);
|
||||
|
||||
Blueprint *blueprint = ecs_get_mut(world_ecs(), e, Blueprint);
|
||||
blueprint->w = w;
|
||||
blueprint->h = h;
|
||||
zpl_memcopy(blueprint->plan, plan, w*h);
|
||||
zpl_memcopy(blueprint->plan, plan, w*h*sizeof(asset_id));
|
||||
|
||||
return (uint64_t)e;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include "platform/system.h"
|
||||
|
||||
uint64_t blueprint_spawn(uint8_t w, uint8_t h, const char *plan);
|
||||
uint64_t blueprint_spawn(uint8_t w, uint8_t h, const uint16_t *plan);
|
||||
uint64_t blueprint_spawn_udata(void* udata);
|
||||
void blueprint_despawn(uint64_t id);
|
||||
|
||||
|
|
|
@ -18,3 +18,5 @@ void reset_cached_time(void);
|
|||
uint32_t defer_var = (s, 0); \
|
||||
!defer_var; \
|
||||
(defer_var += 1), e)
|
||||
|
||||
#define PROT(...) __VA_ARGS__
|
||||
|
|
|
@ -12,10 +12,10 @@ void BuildBlueprints(ecs_iter_t *it) {
|
|||
|
||||
for (int y = 0; y < blueprint[i].h; y++) {
|
||||
for (int x = 0; x < blueprint[i].w; x++) {
|
||||
char c = blueprint[i].plan[y*w + x];
|
||||
if (c == ' ') continue;
|
||||
asset_id c = blueprint[i].plan[y*w + x];
|
||||
if (c == ASSET_EMPTY) continue;
|
||||
world_block_lookup l = world_block_from_realpos(p[i].x + x * WORLD_BLOCK_SIZE - (w * WORLD_BLOCK_SIZE)/2, p[i].y + y * WORLD_BLOCK_SIZE - (h * WORLD_BLOCK_SIZE)/2);
|
||||
world_chunk_place_block(l.chunk_id, l.id, blocks_find_by_symbol(c));
|
||||
world_chunk_place_block(l.chunk_id, l.id, blocks_find(c));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue