introduce wip block texgen
parent
fb5c2fae86
commit
e5b99d829f
|
@ -9,7 +9,7 @@ typedef enum {
|
|||
FORCE_GAMEKIND_UINT8 = UINT8_MAX
|
||||
} game_kind;
|
||||
|
||||
void game_init(game_kind play_mode, uint32_t num_viewers, int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount, int8_t is_dash_enabled);
|
||||
void game_init(game_kind play_mode, uint32_t num_viewers, int32_t seed, uint16_t chunk_size, uint16_t chunk_amount, int8_t is_dash_enabled);
|
||||
void game_shutdown();
|
||||
uint8_t game_is_running();
|
||||
int8_t game_is_networked();
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
typedef struct {
|
||||
uint64_t ent_id;
|
||||
uint16_t block_size;
|
||||
uint16_t chunk_size;
|
||||
uint16_t world_size;
|
||||
} pkt_01_welcome;
|
||||
|
@ -12,7 +11,6 @@ typedef struct {
|
|||
size_t pkt_01_welcome_send(uint64_t peer_id,
|
||||
uint16_t view_id,
|
||||
uint64_t ent_id,
|
||||
uint16_t block_size,
|
||||
uint16_t chunk_size,
|
||||
uint16_t world_size);
|
||||
size_t pkt_01_welcome_encode(pkt_01_welcome *table);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "system.h"
|
||||
#include "raylib.h"
|
||||
#include "world/blocks.h"
|
||||
|
||||
static inline
|
||||
void DrawTextEco(const char *text, float posX, float posY, int fontSize, Color color, float spacing) {
|
||||
|
@ -47,3 +48,8 @@ void DrawRectangleEco(float posX, float posY, int width, int height, Color color
|
|||
{
|
||||
DrawRectangleV((Vector2){ (float)posX , (float)posY }, (Vector2){ (float)width , (float)height }, color);
|
||||
}
|
||||
|
||||
static inline
|
||||
Texture2D GetBlockTexture(uint8_t id) {
|
||||
return *(Texture2D*)blocks_get_tex(id);
|
||||
}
|
|
@ -9,6 +9,9 @@ typedef enum {
|
|||
|
||||
#include "blocks_info.h"
|
||||
|
||||
int32_t blocks_setup(void);
|
||||
void blocks_destroy(void);
|
||||
|
||||
uint8_t blocks_find(uint32_t biome, uint32_t kind);
|
||||
|
||||
char *blocks_get_name(uint8_t id);
|
||||
|
@ -16,3 +19,6 @@ char blocks_get_symbol(uint8_t id);
|
|||
uint32_t blocks_get_flags(uint8_t id);
|
||||
uint32_t blocks_get_biome(uint8_t id);
|
||||
uint32_t blocks_get_kind(uint8_t id);
|
||||
|
||||
// NOTE(zaklaus): viewer-related functions
|
||||
void *blocks_get_tex(uint8_t id);
|
|
@ -16,6 +16,7 @@
|
|||
#define WORLD_TRACKER_UPDATE_FAST_MS 100
|
||||
#define WORLD_TRACKER_UPDATE_NORMAL_MS 500
|
||||
#define WORLD_TRACKER_UPDATE_SLOW_MS 1000
|
||||
#define WORLD_BLOCK_SIZE 16
|
||||
|
||||
#define WORLD_PKT_READER(name) int32_t name(void* data, uint32_t datalen, void *udata)
|
||||
typedef WORLD_PKT_READER(world_pkt_reader_proc);
|
||||
|
@ -27,7 +28,6 @@ typedef struct {
|
|||
uint8_t *data;
|
||||
uint32_t seed;
|
||||
uint32_t size;
|
||||
uint16_t block_size;
|
||||
uint16_t chunk_size;
|
||||
uint16_t chunk_amount;
|
||||
uint16_t dim;
|
||||
|
@ -41,7 +41,7 @@ typedef struct {
|
|||
} world_data;
|
||||
|
||||
void world_setup_pkt_handlers(world_pkt_reader_proc *reader_proc, world_pkt_writer_proc *writer_proc);
|
||||
int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount);
|
||||
int32_t world_init(int32_t seed, uint16_t chunk_size, uint16_t chunk_amount);
|
||||
int32_t world_destroy(void);
|
||||
int32_t world_update(void);
|
||||
|
||||
|
@ -52,7 +52,6 @@ uint32_t world_buf(uint8_t const **ptr, uint32_t *width);
|
|||
ecs_world_t * world_ecs(void);
|
||||
librg_world * world_tracker(void);
|
||||
|
||||
uint16_t world_block_size(void);
|
||||
uint16_t world_chunk_size(void);
|
||||
uint16_t world_chunk_amount(void);
|
||||
uint16_t world_dim(void);
|
||||
|
|
|
@ -11,7 +11,6 @@ typedef struct {
|
|||
|
||||
uint32_t size;
|
||||
uint32_t dim;
|
||||
uint16_t block_size;
|
||||
uint16_t chunk_size;
|
||||
uint16_t chunk_amount;
|
||||
|
||||
|
@ -22,5 +21,5 @@ typedef struct {
|
|||
} world_view;
|
||||
|
||||
world_view world_view_create(uint16_t view_id);
|
||||
void world_view_init(world_view *view, uint64_t ent_id, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount);
|
||||
void world_view_init(world_view *view, uint64_t ent_id, uint16_t chunk_size, uint16_t chunk_amount);
|
||||
void world_view_destroy(world_view *view);
|
||||
|
|
|
@ -104,7 +104,7 @@ void flecs_dash_init() {
|
|||
ecs_set(world_ecs(), 0, EcsDashServer, {.port = 27001});
|
||||
}
|
||||
|
||||
void game_init(game_kind play_mode, uint32_t num_viewers, int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount, int8_t is_dash_enabled) {
|
||||
void game_init(game_kind play_mode, uint32_t num_viewers, int32_t seed, uint16_t chunk_size, uint16_t chunk_amount, int8_t is_dash_enabled) {
|
||||
game_mode = play_mode;
|
||||
platform_init();
|
||||
world_viewers_init(num_viewers);
|
||||
|
@ -118,7 +118,7 @@ void game_init(game_kind play_mode, uint32_t num_viewers, int32_t seed, uint16_t
|
|||
} else {
|
||||
stdcpp_set_os_api();
|
||||
world_setup_pkt_handlers(pkt_reader, sp_pkt_writer);
|
||||
world_init(seed, block_size, chunk_size, chunk_amount);
|
||||
world_init(seed, chunk_size, chunk_amount);
|
||||
if (is_dash_enabled) flecs_dash_init();
|
||||
ecs_set_target_fps(world_ecs(), 60);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include "modules/controllers.h"
|
||||
|
||||
#define DEFAULT_WORLD_SEED 302097
|
||||
#define DEFAULT_BLOCK_SIZE 16 /* amount of units within a block (single axis) */
|
||||
#define DEFAULT_CHUNK_SIZE 16 /* amount of blocks within a chunk (single axis) */
|
||||
#define DEFAULT_WORLD_SIZE 32 /* amount of chunks within a world (single axis) */
|
||||
|
||||
|
@ -32,7 +31,6 @@ int main(int argc, char** argv)
|
|||
zpl_opts_add(&opts, "ed", "enable-dash", "enables flecs dash", ZPL_OPTS_FLAG);
|
||||
zpl_opts_add(&opts, "s", "seed", "world seed", ZPL_OPTS_INT);
|
||||
zpl_opts_add(&opts, "r", "random-seed", "generate random world seed", ZPL_OPTS_FLAG);
|
||||
zpl_opts_add(&opts, "bs", "block-size", "amount of units within a block (single axis)", ZPL_OPTS_INT);
|
||||
zpl_opts_add(&opts, "cs", "chunk-size", "amount of blocks within a chunk (single axis)", ZPL_OPTS_INT);
|
||||
zpl_opts_add(&opts, "ws", "world-size", "amount of chunks within a world (single axis)", ZPL_OPTS_INT);
|
||||
zpl_opts_add(&opts, "n", "npc-count", "amount of demo npcs to spawn", ZPL_OPTS_INT);
|
||||
|
@ -49,7 +47,6 @@ int main(int argc, char** argv)
|
|||
int8_t is_dash_enabled = zpl_opts_has_arg(&opts, "enable-dash");
|
||||
int32_t seed = zpl_opts_integer(&opts, "seed", DEFAULT_WORLD_SEED);
|
||||
uint16_t num_viewers = zpl_opts_integer(&opts, "viewer-count", 1);
|
||||
uint16_t block_size = zpl_opts_integer(&opts, "block-size", DEFAULT_BLOCK_SIZE);
|
||||
uint16_t chunk_size = zpl_opts_integer(&opts, "chunk-size", DEFAULT_CHUNK_SIZE);
|
||||
uint16_t world_size = zpl_opts_integer(&opts, "world-size", DEFAULT_WORLD_SIZE);
|
||||
uint32_t npc_count = zpl_opts_integer(&opts, "npc-count", 1000);
|
||||
|
@ -62,13 +59,12 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
if (zpl_opts_has_arg(&opts, "preview-map")) {
|
||||
generate_minimap(seed, block_size, chunk_size, world_size);
|
||||
generate_minimap(seed, WORLD_BLOCK_SIZE, chunk_size, world_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sighandler_register();
|
||||
game_init(is_viewer_only, num_viewers, seed, block_size, chunk_size, world_size, is_dash_enabled);
|
||||
|
||||
game_init(is_viewer_only, num_viewers, seed, chunk_size, world_size, is_dash_enabled);
|
||||
|
||||
// TODO(zaklaus): VERY TEMPORARY -- SPAWN SOME NPCS THAT RANDOMLY MOVE
|
||||
{
|
||||
|
|
|
@ -34,6 +34,6 @@ int32_t pkt_00_init_handler(pkt_header *header) {
|
|||
uint64_t peer_id = (uint64_t)header->udata;
|
||||
uint64_t ent_id = player_spawn(NULL);
|
||||
ecs_set(world_ecs(), ent_id, ClientInfo, {.peer = ent_id, .view_id = header->view_id });
|
||||
pkt_01_welcome_send(peer_id, header->view_id, ent_id, world_block_size(), world_chunk_size(), world_chunk_amount());
|
||||
pkt_01_welcome_send(peer_id, header->view_id, ent_id, world_chunk_size(), world_chunk_amount());
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
pkt_desc pkt_01_welcome_desc[] = {
|
||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, ent_id) },
|
||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, block_size) },
|
||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, chunk_size) },
|
||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, world_size) },
|
||||
{ PKT_END },
|
||||
|
@ -22,10 +21,9 @@ size_t pkt_01_welcome_encode(pkt_01_welcome *table) {
|
|||
size_t pkt_01_welcome_send(uint64_t peer_id,
|
||||
uint16_t view_id,
|
||||
uint64_t ent_id,
|
||||
uint16_t block_size,
|
||||
uint16_t chunk_size,
|
||||
uint16_t world_size) {
|
||||
pkt_01_welcome table = {.ent_id = ent_id, .block_size = block_size, .chunk_size = chunk_size, .world_size = world_size};
|
||||
pkt_01_welcome table = {.ent_id = ent_id, .chunk_size = chunk_size, .world_size = world_size};
|
||||
return pkt_world_write(MSG_ID_01_WELCOME, pkt_01_welcome_encode(&table), 1, view_id, (void*)peer_id);
|
||||
}
|
||||
|
||||
|
@ -36,7 +34,7 @@ int32_t pkt_01_welcome_handler(pkt_header *header) {
|
|||
world_view *view = game_world_view_get(header->view_id);
|
||||
|
||||
zpl_printf("[INFO] initializing read-only world view ...\n");
|
||||
world_view_init(view, table.ent_id, table.block_size, table.chunk_size, table.world_size);
|
||||
world_view_init(view, table.ent_id, table.chunk_size, table.world_size);
|
||||
game_world_view_set_active(view);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "prediction.h"
|
||||
#include "camera.h"
|
||||
#include "math.h"
|
||||
#include "world/blocks.h"
|
||||
#include "utils/raylib_helpers.h"
|
||||
|
||||
uint16_t screenWidth = 1600;
|
||||
|
@ -41,9 +42,12 @@ void platform_init() {
|
|||
int text_w = MeasureText(loading_text, 120);
|
||||
DrawText(loading_text, GetScreenWidth()-text_w-15, GetScreenHeight()-135, 120, RAYWHITE);
|
||||
EndDrawing();
|
||||
|
||||
blocks_setup();
|
||||
}
|
||||
|
||||
void platform_shutdown() {
|
||||
blocks_destroy();
|
||||
CloseWindow();
|
||||
}
|
||||
|
||||
|
@ -146,11 +150,12 @@ void DEBUG_draw_ground(uint64_t key, entity_view * data) {
|
|||
switch (data->kind) {
|
||||
case EKIND_CHUNK: {
|
||||
world_view *view = game_world_view_get_active();
|
||||
int32_t size = view->chunk_size * view->block_size;
|
||||
int32_t size = view->chunk_size * WORLD_BLOCK_SIZE;
|
||||
int16_t offset = 0;
|
||||
|
||||
float x = data->x * size + offset;
|
||||
float y = data->y * size + offset;
|
||||
|
||||
DrawRectangleEco(x, y, size-offset, size-offset, ColorAlpha(LIME, data->tran_time));
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "utils/options.h"
|
||||
|
||||
void generate_minimap(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size) {
|
||||
world_init(seed, block_size, chunk_size, world_size);
|
||||
world_init(seed, chunk_size, world_size);
|
||||
|
||||
uint8_t const *world;
|
||||
uint32_t world_length = chunk_size * world_size;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#define ZPL_PICO
|
||||
#include "zpl.h"
|
||||
#include "world/world.h"
|
||||
#include "world/blocks.h"
|
||||
#include "raylib.h"
|
||||
|
||||
|
@ -13,11 +14,30 @@ typedef struct {
|
|||
char symbol;
|
||||
|
||||
// NOTE(zaklaus): viewer data
|
||||
Image tex;
|
||||
Texture2D tex;
|
||||
} block;
|
||||
|
||||
#include "blocks_list.c"
|
||||
|
||||
int32_t blocks_setup(void) {
|
||||
for (uint32_t i=0; i<BLOCKS_COUNT; i++) {
|
||||
block *b = &blocks[i];
|
||||
|
||||
// TODO(zaklaus): introduce texgen
|
||||
Image img = GenImageColor(WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE, RAYWHITE);
|
||||
|
||||
b->tex = LoadTextureFromImage(img);
|
||||
UnloadImage(img);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void blocks_destroy(void) {
|
||||
for (uint32_t i=0; i<BLOCKS_COUNT; i++) {
|
||||
UnloadTexture(blocks[i].tex);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t blocks_find(uint32_t biome, uint32_t kind) {
|
||||
for (uint32_t i=0; i<BLOCKS_COUNT; i++) {
|
||||
if (blocks[i].biome == biome && blocks[i].kind == kind)
|
||||
|
@ -45,3 +65,7 @@ uint32_t blocks_get_biome(uint8_t id) {
|
|||
uint32_t blocks_get_kind(uint8_t id) {
|
||||
return blocks[id].kind;
|
||||
}
|
||||
|
||||
void *blocks_get_tex(uint8_t id) {
|
||||
return (void*)&blocks[id].tex;
|
||||
}
|
|
@ -91,7 +91,7 @@ void world_setup_pkt_handlers(world_pkt_reader_proc *reader_proc, world_pkt_writ
|
|||
world.writer_proc = writer_proc;
|
||||
}
|
||||
|
||||
int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount) {
|
||||
int32_t world_init(int32_t seed, uint16_t chunk_size, uint16_t chunk_amount) {
|
||||
if (world.data) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -100,7 +100,6 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1
|
|||
world.chunk_size = chunk_size;
|
||||
world.chunk_amount = chunk_amount;
|
||||
|
||||
world.block_size = block_size;
|
||||
world.dim = (world.chunk_size * world.chunk_amount);
|
||||
world.size = world.dim * world.dim;
|
||||
|
||||
|
@ -114,7 +113,7 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1
|
|||
}
|
||||
|
||||
/* config our world grid */
|
||||
librg_config_chunksize_set(world.tracker, block_size * world.chunk_size, block_size * world.chunk_size, 0);
|
||||
librg_config_chunksize_set(world.tracker, WORLD_BLOCK_SIZE * world.chunk_size, WORLD_BLOCK_SIZE * world.chunk_size, 0);
|
||||
librg_config_chunkamount_set(world.tracker, world.chunk_amount, world.chunk_amount, 0);
|
||||
librg_config_chunkoffset_set(world.tracker, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG);
|
||||
|
||||
|
@ -238,10 +237,6 @@ librg_world * world_tracker() {
|
|||
return world.tracker;
|
||||
}
|
||||
|
||||
uint16_t world_block_size(void) {
|
||||
return world.block_size;
|
||||
}
|
||||
|
||||
uint16_t world_chunk_size(void) {
|
||||
return world.chunk_size;
|
||||
}
|
||||
|
@ -251,5 +246,5 @@ uint16_t world_chunk_amount(void) {
|
|||
}
|
||||
|
||||
uint16_t world_dim(void) {
|
||||
return world.block_size * world.chunk_size * world.chunk_amount;
|
||||
return WORLD_BLOCK_SIZE * world.chunk_size * world.chunk_amount;
|
||||
}
|
||||
|
|
|
@ -70,15 +70,14 @@ world_view world_view_create(uint16_t view_id) {
|
|||
return view;
|
||||
}
|
||||
|
||||
void world_view_init(world_view *view, uint64_t ent_id, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount) {
|
||||
void world_view_init(world_view *view, uint64_t ent_id, uint16_t chunk_size, uint16_t chunk_amount) {
|
||||
view->owner_id = ent_id;
|
||||
view->block_size = block_size;
|
||||
view->chunk_size = chunk_size;
|
||||
view->chunk_amount = chunk_amount;
|
||||
view->dim = block_size * chunk_size * chunk_amount;
|
||||
view->dim = WORLD_BLOCK_SIZE * chunk_size * chunk_amount;
|
||||
view->size = view->dim * view->dim;
|
||||
|
||||
librg_config_chunksize_set(view->tracker, block_size * chunk_size, block_size * chunk_size, 1);
|
||||
librg_config_chunksize_set(view->tracker, WORLD_BLOCK_SIZE * chunk_size, WORLD_BLOCK_SIZE * chunk_size, 1);
|
||||
librg_config_chunkamount_set(view->tracker, chunk_amount, chunk_amount, 1);
|
||||
librg_config_chunkoffset_set(view->tracker, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG, 0);
|
||||
|
||||
|
|
Loading…
Reference in New Issue