streamline assets=

master
Dominik Madarász 2024-05-29 10:45:43 +02:00
parent a9ea1e9335
commit b348400c1a
12 changed files with 277 additions and 210 deletions

View File

@ -134,11 +134,12 @@ float game_time() {
return (float)get_cached_time();
}
void game_init(const char *ip, uint16_t port, 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_setup(const char *ip, uint16_t port, 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;
game_should_close = false;
db_init();
entity_default_spawnlist();
game_init(db_init());
#ifndef _DEBUG
const char *host_ip = "lab.zakto.pw";
@ -182,6 +183,8 @@ void game_init(const char *ip, uint16_t port, game_kind play_mode, uint32_t num_
}
}
game_init_ecs();
if (game_mode == GAMEKIND_SINGLE) {
for (uint32_t i = 0; i < num_viewers; i++) {
pkt_00_init_send(i);

View File

@ -11,7 +11,7 @@ typedef enum {
FORCE_GAMEKIND_UINT8 = UINT8_MAX
} game_kind;
void game_init(const char *ip, uint16_t port, 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_setup(const char *ip, uint16_t port, 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();
void game_request_close();
uint8_t game_is_running();
@ -21,6 +21,8 @@ game_kind game_get_kind(void);
//~ NOTE(zaklaus): game events
// Implemented by games
void game_init(bool new_db);
void game_init_ecs(); // called once the world is initialised
void game_input();
void game_update();
void game_render();

View File

@ -28,7 +28,7 @@ void sql_asset(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
sqlite3_result_null(ctx);
}
void db_init() {
bool db_init() {
bool new_db = !zpl_fs_exists(ECO2D_DB);
sqlite3_open(ECO2D_DB, &db);
assert(db && "Failed to open database.");
@ -37,7 +37,7 @@ void db_init() {
sqlite3_create_function(db, "asset", 1, SQLITE_UTF8, NULL, sql_asset, NULL, NULL);
if (new_db) {
zpl_printf("[INFO] Creating new database.\n");
zpl_printf("[INFO] Creating new database...\n");
db_exec_file("art/queries/tables.sql");
assets_db_init();
@ -48,10 +48,12 @@ void db_init() {
}
// initialise models db
assets_db();
blocks_db();
craft_db();
item_db();
zpl_printf("[INFO] Loading models from database...\n");
assets_db(); zpl_printf("[INFO] Assets loaded.\n");
blocks_db(); zpl_printf("[INFO] Blocks loaded.\n");
craft_db(); zpl_printf("[INFO] Recipes loaded.\n");
item_db(); zpl_printf("[INFO] Items loaded.\n");
return new_db;
}
void db_shutdown() {

View File

@ -2,7 +2,7 @@
#include "platform/system.h"
#include "zpl.h"
void db_init();
bool db_init();
void db_shutdown();
// raw query data getters

View File

@ -8,8 +8,45 @@
#include "systems/systems.h"
#include "zpl.h"
typedef struct {
asset_id id;
uint64_t (*proc)();
uint64_t (*proc_udata)(void*);
} spawndef;
static spawndef *entity_spawnlist;
void entity_add_spawndef(uint16_t id, uint64_t (*proc)()) {
spawndef def={0};
def.id = id;
def.proc = proc;
zpl_array_append(entity_spawnlist, def);
}
void entity_add_spawndef_data(uint16_t id, uint64_t (*proc)(void*)) {
spawndef def={0};
def.id = id;
def.proc_udata = proc;
zpl_array_append(entity_spawnlist, def);
}
// NOTE(zaklaus): bring in entity spawnlist
#include "lists/entity_spawnlist.c"
// #include "lists/entity_spawnlist.c"
#include "models/prefabs/prefabs_list.c"
#define MAX_ENTITY_SPAWNDEFS ((size_t)zpl_array_count(entity_spawnlist))
void entity_default_spawnlist(void) {
zpl_array_init(entity_spawnlist, zpl_heap());
entity_add_spawndef(ASSET_CHEST, storage_spawn);
entity_add_spawndef(ASSET_FURNACE, furnace_spawn);
entity_add_spawndef(ASSET_CRAFTBENCH, craftbench_spawn);
entity_add_spawndef(ASSET_SPLITTER, splitter_spawn);
entity_add_spawndef(ASSET_ASSEMBLER, assembler_spawn);
entity_add_spawndef(ASSET_CREATURE, creature_spawn);
entity_add_spawndef(ASSET_MOB, mob_spawn);
entity_add_spawndef_data(ASSET_BLUEPRINT, blueprint_spawn_udata);
}
uint64_t entity_spawn(uint16_t class_id) {
ecs_entity_t e = ecs_new(world_ecs(), 0);

View File

@ -11,6 +11,11 @@ void entity_batch_despawn(uint64_t *ids, size_t num_ids);
void entity_despawn(uint64_t ent_id);
void entity_set_position(uint64_t ent_id, float x, float y);
// NOTE(zaklaus): spawndef manager
void entity_add_spawndef(uint16_t id, uint64_t (*proc)());
void entity_add_spawndef_data(uint16_t id, uint64_t (*proc)(void*));
void entity_default_spawnlist(void);
// NOTE(zaklaus): action-based entity stream throttling
void entity_wake(uint64_t ent_id);

View File

@ -1,5 +1,13 @@
#include "core/game.h"
void game_init(bool new_db) {
}
void game_init_ecs() {
}
void game_input() {
game_core_input();
}

View File

@ -69,7 +69,7 @@ int main(int argc, char** argv) {
}
sighandler_register();
game_init(host, port, play_mode, 1, seed, chunk_size, world_size, 0);
game_setup(host, port, play_mode, 1, seed, chunk_size, world_size, 0);
game_run();

View File

@ -1,5 +1,13 @@
#include "core/game.h"
void game_init(bool new_db) {
}
void game_init_ecs() {
}
void game_input() {
game_core_input();
}
@ -12,7 +20,6 @@ void game_render() {
game_core_render();
}
void game_player_joined(uint64_t ent) {
ecs_set(world_ecs(), ent, Inventory, {0});
ecs_set(world_ecs(), ent, HealthRegen, {15.f});

View File

@ -73,7 +73,7 @@ int main(int argc, char** argv) {
}
sighandler_register();
game_init(host, port, play_mode, num_viewers, seed, chunk_size, world_size, is_dash_enabled);
game_setup(host, port, play_mode, num_viewers, seed, chunk_size, world_size, is_dash_enabled);
game_run();

View File

@ -83,6 +83,10 @@ void mob_systems(ecs_world_t *ecs) {
ECS_OBSERVER(ecs, MobOnDead, EcsOnAdd, components.Mob, components.Sprite, components.Velocity, components.Dead);
}
void game_init(bool new_db) {
}
void game_input() {
game_core_input();
}
@ -95,7 +99,7 @@ void game_render() {
game_core_render();
}
void game_setup_ecs() {
void game_init_ecs() {
mob_systems(world_ecs());
}

View File

@ -90,8 +90,7 @@ int main(int argc, char** argv) {
}
sighandler_register();
game_init(host, port, play_mode, 1, seed, chunk_size, world_size, is_dash_enabled);
game_setup_ecs();
game_setup(host, port, play_mode, 1, seed, chunk_size, world_size, is_dash_enabled);
game_run();
game_shutdown();