diff --git a/CMakeLists.txt b/CMakeLists.txt index edd79f0..4045b54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 3.15) project(eco2d) set(CMAKE_C_STANDARD 11) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/) include_directories(eco2d-client code/vendors code/common) include_directories(eco2d-server code/vendors code/common) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/) add_subdirectory(code/apps/client) add_subdirectory(code/apps/server) diff --git a/code/apps/client/header/game.h b/code/apps/client/header/game.h index 6d1dc61..f026fb6 100644 --- a/code/apps/client/header/game.h +++ b/code/apps/client/header/game.h @@ -1,8 +1,8 @@ +#pragma once +void game_init(); +void game_shutdown(); -void game_init(); -void game_shutdown(); - -void game_input(); -void game_update(); -void game_render(); +void game_input(); +void game_update(); +void game_render(); diff --git a/code/apps/client/header/network.h b/code/apps/client/header/network.h index 019dafa..6f70f09 100644 --- a/code/apps/client/header/network.h +++ b/code/apps/client/header/network.h @@ -1,2 +1 @@ -#include "librg.h" - +#pragma once diff --git a/code/apps/client/header/renderer.h b/code/apps/client/header/renderer.h index acfad71..a4df5ea 100644 --- a/code/apps/client/header/renderer.h +++ b/code/apps/client/header/renderer.h @@ -1,3 +1,4 @@ +#pragma once void gfx_init(); void gfx_shutdown(); diff --git a/code/apps/client/source/game.c b/code/apps/client/source/game.c index 7a3e238..4f1bc34 100644 --- a/code/apps/client/source/game.c +++ b/code/apps/client/source/game.c @@ -1,24 +1,24 @@ #include "game.h" #include "renderer.h" -void game_init() { +void game_init() { gfx_init(); } -void game_shutdown() { +void game_shutdown() { gfx_shutdown(); } -void game_input() { +void game_input() { } -void game_update() { +void game_update() { } -void game_render() { +void game_render() { gfx_render(); } diff --git a/code/apps/client/source/main.c b/code/apps/client/source/main.c index 41e358e..6fbd72c 100644 --- a/code/apps/client/source/main.c +++ b/code/apps/client/source/main.c @@ -4,7 +4,7 @@ int main(void) { game_init(); - while (!WindowShouldClose()) // Detect window close button or ESC key + while (!WindowShouldClose()) { game_input(); game_update(); diff --git a/code/apps/client/source/network.c b/code/apps/client/source/network.c index 48e0e01..19e2912 100644 --- a/code/apps/client/source/network.c +++ b/code/apps/client/source/network.c @@ -4,3 +4,5 @@ #define LIBRG_IMPL #define LIBRG_CUSTOM_ZPL #include "librg.h" + +#include "network.h" diff --git a/code/apps/client/source/renderer.c b/code/apps/client/source/renderer.c index 1223536..8438dd9 100644 --- a/code/apps/client/source/renderer.c +++ b/code/apps/client/source/renderer.c @@ -6,7 +6,7 @@ const uint16_t screenWidth = 800; const uint16_t screenHeight = 450; void gfx_init() { - InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); + InitWindow(screenWidth, screenHeight, "eco2d - client"); SetTargetFPS(60); } diff --git a/code/apps/server/CMakeLists.txt b/code/apps/server/CMakeLists.txt index bd69899..d002ee7 100644 --- a/code/apps/server/CMakeLists.txt +++ b/code/apps/server/CMakeLists.txt @@ -1,9 +1,17 @@ add_executable(eco2d-server source/main.c source/network.c + source/perlin.c + source/options.c + source/world.c + source/blocks.c header/network.h + header/perlin.h + header/options.h + header/world.h + header/blocks.h ) -include_directories(header/) +include_directories(eco2d-server header) target_link_libraries(eco2d-server raylib) diff --git a/code/apps/server/header/blocks.h b/code/apps/server/header/blocks.h new file mode 100644 index 0000000..1fb83bc --- /dev/null +++ b/code/apps/server/header/blocks.h @@ -0,0 +1,3 @@ +#pragma once +#include "system.h" + diff --git a/code/apps/server/header/network.h b/code/apps/server/header/network.h index e69de29..6f70f09 100644 --- a/code/apps/server/header/network.h +++ b/code/apps/server/header/network.h @@ -0,0 +1 @@ +#pragma once diff --git a/code/apps/server/header/options.h b/code/apps/server/header/options.h new file mode 100644 index 0000000..59f3fa2 --- /dev/null +++ b/code/apps/server/header/options.h @@ -0,0 +1,4 @@ +#pragma once +#include "system.h" + +void generate_minimap(int32_t seed); diff --git a/code/apps/server/header/perlin.h b/code/apps/server/header/perlin.h new file mode 100644 index 0000000..66f184d --- /dev/null +++ b/code/apps/server/header/perlin.h @@ -0,0 +1,6 @@ +#pragma once + +#include "system.h" + +double perlin_noise2d(int32_t seed, double x, double y); +double perlin_fbm(int32_t seed, double x, double y, double freq, uint32_t octaves); diff --git a/code/apps/server/header/world.h b/code/apps/server/header/world.h new file mode 100644 index 0000000..49d4534 --- /dev/null +++ b/code/apps/server/header/world.h @@ -0,0 +1,10 @@ +#pragma once +#include "system.h" + +#define WORLD_ERROR_NONE +0x0000 +#define WORLD_ERROR_OUTOFMEM -0x0001 +#define WORLD_ERROR_INVALID_BLOCKS -0x0002 +#define WORLD_ERROR_INVALID_DIMENSIONS -0x0003 +#define WORLD_ERROR_INVALID_BUFFER -0x0004 + +int32_t world_gen(int32_t seed, uint8_t width, uint8_t height, uint8_t *buffer, uint32_t size); diff --git a/code/apps/server/source/blocks.c b/code/apps/server/source/blocks.c new file mode 100644 index 0000000..d57a58b --- /dev/null +++ b/code/apps/server/source/blocks.c @@ -0,0 +1,3 @@ +#include "blocks.h" + +// todo: csv parsing + utils diff --git a/code/apps/server/source/main.c b/code/apps/server/source/main.c index 9ccd42a..f3c8db1 100644 --- a/code/apps/server/source/main.c +++ b/code/apps/server/source/main.c @@ -1,7 +1,36 @@ +#define ZPL_IMPL +#include "zpl.h" + #define LIBRG_IMPL +#define LIBRG_CUSTOM_ZPL #include "librg.h" -int main(void) { +#include "system.h" +#include "options.h" + +#define DEFAULT_WORLD_SEED 302097 + +int main(int argc, char** argv) { + zpl_opts opts={0}; + zpl_opts_init(&opts, zpl_heap(), argv[0]); + + zpl_opts_add(&opts, "?", "help", "the HELP section", ZPL_OPTS_FLAG); + zpl_opts_add(&opts, "p", "preview-map", "draw world preview", ZPL_OPTS_FLAG); + zpl_opts_add(&opts, "s", "seed", "world seed", ZPL_OPTS_INT); + uint32_t ok = zpl_opts_compile(&opts, argc, argv); + + if (!ok) { + zpl_opts_print_errors(&opts); + zpl_opts_print_help(&opts); + return -1; + } + int32_t seed = zpl_opts_integer(&opts, "seed", DEFAULT_WORLD_SEED); + + if (zpl_opts_has_arg(&opts, "preview-map")) { + generate_minimap(seed); + return 0; + } + printf("hello world\n"); return 0; } diff --git a/code/apps/server/source/options.c b/code/apps/server/source/options.c new file mode 100644 index 0000000..a75e0b6 --- /dev/null +++ b/code/apps/server/source/options.c @@ -0,0 +1,18 @@ +#include "options.h" +#include "perlin.h" +#include "zpl.h" + +#define TEST_MAP_DIM 32 +#define TEST_MAP_DEPTH 18 + +static char *map_pattern = "~~..,,oo---OO^^^@@"; + +void generate_minimap(int32_t seed) { + for (uint32_t y=0; y diff --git a/data/blocks.csv b/data/blocks.csv new file mode 100644 index 0000000..2722fe1 --- /dev/null +++ b/data/blocks.csv @@ -0,0 +1,3 @@ +id,name,flags +0,base_ground,0 +1,base_wall,1