small refactor of game layer

efd/v1
Dominik Madarász 2023-02-02 13:24:16 +01:00
parent 0760d1809d
commit 65766d8748
16 changed files with 109 additions and 32 deletions

View File

@ -228,14 +228,14 @@ game_kind game_get_kind(void) {
return game_mode;
}
void game_input() {
void game_core_input() {
if (game_mode != GAMEKIND_HEADLESS) {
platform_input();
UpdateNuklear(game_ui);
}
}
void game_update() {
void game_core_update() {
static double last_update = 0.0f;
if (game_mode == GAMEKIND_CLIENT) {
network_client_tick();
@ -257,7 +257,7 @@ void game_update() {
last_update = get_cached_time();
}
void game_render() {
void game_core_render() {
if (game_mode != GAMEKIND_HEADLESS) {
platform_render();
}

View File

@ -19,13 +19,18 @@ float game_time();
game_kind game_get_kind(void);
//~ NOTE(zaklaus): game events
// Implemented by games
void game_input();
void game_update();
void game_render();
void game_player_joined(uint64_t ent);
void game_player_departed(uint64_t ent);
// base methods called from games
void game_core_input();
void game_core_update();
void game_core_render();
//~ Called from platform.c
void game_draw_ui();

View File

@ -0,0 +1,3 @@
#pragma once
void notification_push(const char* title, const char* text);

View File

@ -4,6 +4,7 @@ add_executable(minimal
src/worldgen.c
src/texgen.c
src/rules.c
src/game.c
)
target_compile_definitions(minimal PRIVATE CLIENT)

View File

@ -0,0 +1,22 @@
#include "core/game.h"
void game_input() {
game_core_input();
}
void game_update() {
game_core_update();
}
void game_render() {
game_core_render();
}
void game_player_joined(uint64_t ent) {
}
void game_player_departed(uint64_t ent) {
}

View File

@ -80,7 +80,3 @@ int main(int argc, char** argv) {
zpl_opts_free(&opts);
return 0;
}
//------------------------------------------------------------------------
void game_player_joined(uint64_t ent) {}
void game_player_departed(uint64_t ent) {}

View File

@ -22,6 +22,7 @@ ZPL_DIAGNOSTIC_POP
#include "platform/arch.h"
#include "gui/tooltip.c"
#include "gui/notifications.c"
#include "renderer.c"

View File

@ -4,6 +4,7 @@ add_executable(eco2d
src/worldgen.c
src/texgen.c
src/rules.c
src/game.c
)
target_compile_definitions(eco2d PRIVATE CLIENT)

View File

@ -0,0 +1,22 @@
#include "core/game.h"
void game_input() {
game_core_input();
}
void game_update() {
game_core_update();
}
void game_render() {
game_core_render();
}
void game_player_joined(uint64_t ent) {
}
void game_player_departed(uint64_t ent) {
}

View File

@ -84,7 +84,3 @@ int main(int argc, char** argv) {
zpl_opts_free(&opts);
return 0;
}
//------------------------------------------------------------------------
void game_player_joined(uint64_t ent) {}
void game_player_departed(uint64_t ent) {}

View File

@ -4,6 +4,7 @@ add_executable(survival
src/worldgen.c
src/texgen.c
src/rules.c
src/game.c
)
target_compile_definitions(minimal PRIVATE CLIENT)

View File

@ -0,0 +1,43 @@
#include "core/game.h"
#include "game.h"
#include "world/world.h"
#include "models/components.h"
#include "systems/systems.h"
#include "models/entity.h"
#include "world/entity_view.h"
#include "gui/notifications.h"
// custom systems
#include "system_mob.c"
void mob_systems(ecs_world_t *ecs) {
ECS_SYSTEM_TICKED_EX(ecs, MobDetectPlayers, EcsPostUpdate, 100.0f, components.Position, components.Mob);
ECS_SYSTEM(ecs, MobMovement, EcsPostUpdate, components.Velocity, components.Position, components.MobHuntPlayer);
ECS_SYSTEM_TICKED(ecs, MobMeleeAtk, EcsPostUpdate, components.Position, components.Mob, components.MobHuntPlayer, components.MobMelee);
//ECS_OBSERVER(ecs, MobDetectPlayers1, EcsOnAdd, components.Mob);
}
void game_input() {
game_core_input();
}
void game_update() {
game_core_update();
}
void game_render() {
game_core_render();
}
void game_setup_ecs() {
mob_systems(world_ecs());
}
void game_player_joined(uint64_t ent) {
notification_push("test1", "Hello World!");
}
void game_player_departed(uint64_t ent) {
}

View File

@ -0,0 +1,3 @@
#pragma once
void game_setup_ecs();

View File

@ -2,6 +2,7 @@
#include "zpl.h"
#include "platform/system.h"
#include "core/game.h"
#include "game.h"
#include "models/entity.h"
#include "world/entity_view.h"
#include "utils/options.h"
@ -37,14 +38,6 @@ ZPL_DIAGNOSTIC_POP
- somewhat believable world gen, small hamlets with cols, etc
*/
#include "system_mob.c"
void mob_systems(ecs_world_t *ecs) {
ECS_SYSTEM_TICKED_EX(ecs, MobDetectPlayers, EcsPostUpdate, 100.0f, components.Position, components.Mob);
ECS_SYSTEM(ecs, MobMovement, EcsPostUpdate, components.Velocity, components.Position, components.MobHuntPlayer);
ECS_SYSTEM_TICKED(ecs, MobMeleeAtk, EcsPostUpdate, components.Position, components.Mob, components.MobHuntPlayer, components.MobMelee);
//ECS_OBSERVER(ecs, MobDetectPlayers1, EcsOnAdd, components.Mob);
}
int main(int argc, char** argv) {
zpl_opts opts={0};
@ -96,11 +89,7 @@ int main(int argc, char** argv) {
sighandler_register();
game_init(host, port, play_mode, 1, seed, chunk_size, world_size, 0);
{
mob_systems(world_ecs());
}
game_setup_ecs();
game_run();
game_shutdown();
@ -110,7 +99,3 @@ int main(int argc, char** argv) {
zpl_opts_free(&opts);
return 0;
}
//------------------------------------------------------------------------
void game_player_joined(uint64_t ent) {}
void game_player_departed(uint64_t ent) {}

View File

@ -34,8 +34,6 @@ ZPL_DIAGNOSTIC_POP
void platform_init() {
platform_create_window("horde survival game");
renderer_init();
notification_push("test1", "Hello World!");
}
void platform_shutdown() {

View File

@ -28,7 +28,7 @@ void MobDetectPlayers(ecs_iter_t *it) {
}
void MobDetectPlayers1(ecs_iter_t *it) {
MobDetectPlayers(it);
}
#define MOB_MOVEMENT_SPEED 300.0f