From 143206529b713d1816a072f1316a54166e838843 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sat, 25 Jun 2022 15:10:06 +0800 Subject: [PATCH] Refactor code Rename files in order to prepare for extraction for publishing subsystems independently. --- CMakeLists.txt | 10 +++++----- src/packages/game/IZ_app.h | 7 ++++--- src/packages/game/IZ_app_config.c | 12 ++++++++++++ src/packages/game/IZ_app_config.h | 8 ++++++++ src/packages/game/{input/IZ_app.c => IZ_app_input.c} | 2 +- src/packages/game/IZ_app_input.h | 8 ++++++++ src/packages/game/{net/IZ_app.c => IZ_app_net.c} | 2 +- src/packages/game/{net/IZ_app.h => IZ_app_net.h} | 8 ++++---- .../game/{output/video/IZ_app.c => IZ_app_video.c} | 2 +- src/packages/game/IZ_app_video.h | 9 +++++++++ src/packages/game/{ => config}/IZ_config.c | 11 ----------- src/packages/game/{ => config}/IZ_config.h | 5 ++--- src/packages/game/input/IZ_app.h | 8 -------- src/packages/game/net/IZ_net.h | 2 +- src/packages/game/output/video/IZ_app.h | 9 --------- src/packages/game/output/video/IZ_video.h | 2 +- src/packages/server/net/IZ_net.h | 1 - 17 files changed, 57 insertions(+), 49 deletions(-) create mode 100644 src/packages/game/IZ_app_config.c create mode 100644 src/packages/game/IZ_app_config.h rename src/packages/game/{input/IZ_app.c => IZ_app_input.c} (98%) create mode 100644 src/packages/game/IZ_app_input.h rename src/packages/game/{net/IZ_app.c => IZ_app_net.c} (99%) rename src/packages/game/{net/IZ_app.h => IZ_app_net.h} (91%) rename src/packages/game/{output/video/IZ_app.c => IZ_app_video.c} (99%) create mode 100644 src/packages/game/IZ_app_video.h rename src/packages/game/{ => config}/IZ_config.c (95%) rename src/packages/game/{ => config}/IZ_config.h (93%) delete mode 100644 src/packages/game/input/IZ_app.h delete mode 100644 src/packages/game/output/video/IZ_app.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4666ecf..db74745 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,8 +60,8 @@ add_executable( src/packages/game/input/IZ_joystick.h src/packages/game/input/IZ_keyboard.c src/packages/game/input/IZ_keyboard.h - src/packages/game/IZ_config.c - src/packages/game/IZ_config.h + src/packages/game/config/IZ_config.c + src/packages/game/config/IZ_config.h src/packages/game/geometry/IZ_point2d.c src/packages/game/geometry/IZ_point2d.h src/packages/game/geometry/IZ_vector2d.c @@ -90,7 +90,7 @@ add_executable( src/packages/game/util/IZ_midi.h src/packages/game/net/core/IZ_websocket.h src/packages/game/net/core/IZ_websocket.c - src/packages/game/net/IZ_net.c src/packages/game/net/IZ_net.h src/packages/game/net/IZ_app.c src/packages/game/net/IZ_app.h src/packages/game/output/video/IZ_app.c src/packages/game/output/video/IZ_app.h src/packages/game/IZ_subsystem.h src/packages/game/input/IZ_app.c src/packages/game/input/IZ_app.h) + src/packages/game/net/IZ_net.c src/packages/game/net/IZ_net.h src/packages/game/IZ_app_net.c src/packages/game/IZ_app_net.h src/packages/game/IZ_app_video.c src/packages/game/IZ_app_video.h src/packages/game/IZ_subsystem.h src/packages/game/IZ_app_input.c src/packages/game/IZ_app_input.h src/packages/game/IZ_app_config.c src/packages/game/IZ_app_config.h) target_link_libraries( game @@ -130,7 +130,7 @@ add_executable( __mocks__/SDL_stdinc.mock.h __mocks__/portmidi.mock.h - src/packages/game/IZ_config.h + src/packages/game/config/IZ_config.h src/packages/game/input/IZ_keyboard.h src/packages/game/input/IZ_keyboard.c @@ -157,7 +157,7 @@ add_executable( __mocks__/SDL_stdinc.mock.h __mocks__/SDL_render.mock.h - src/packages/game/IZ_config.h + src/packages/game/config/IZ_config.h src/packages/game/output/video/IZ_video.h src/packages/game/output/video/IZ_video.c diff --git a/src/packages/game/IZ_app.h b/src/packages/game/IZ_app.h index 42765b1..bf38ef7 100644 --- a/src/packages/game/IZ_app.h +++ b/src/packages/game/IZ_app.h @@ -3,10 +3,11 @@ #include #include +#include "IZ_app_config.h" #include "memory/IZ_pool.h" -#include "input/IZ_app.h" -#include "net/IZ_app.h" -#include "output/video/IZ_app.h" +#include "IZ_app_input.h" +#include "IZ_app_net.h" +#include "IZ_app_video.h" typedef enum { IZ_APP_RUN_RESULT_OK, diff --git a/src/packages/game/IZ_app_config.c b/src/packages/game/IZ_app_config.c new file mode 100644 index 0000000..37729e2 --- /dev/null +++ b/src/packages/game/IZ_app_config.c @@ -0,0 +1,12 @@ +#include "IZ_app_config.h" + +void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) { +#ifdef IZ_DEBUG + const char* config_path_dir = SDL_GetBasePath(); +#else + const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME); +#endif + + memcpy_s(config_path, string_size, config_path_dir, 128); + strcat_s(config_path, string_size, "config-game.ini"); +} diff --git a/src/packages/game/IZ_app_config.h b/src/packages/game/IZ_app_config.h new file mode 100644 index 0000000..02e51c1 --- /dev/null +++ b/src/packages/game/IZ_app_config.h @@ -0,0 +1,8 @@ +#ifndef IZ_APP_CONFIG_H +#define IZ_APP_CONFIG_H + +#include "SDL_filesystem.h" +#include "IZ_subsystem.h" +#include "config/IZ_config.h" + +#endif diff --git a/src/packages/game/input/IZ_app.c b/src/packages/game/IZ_app_input.c similarity index 98% rename from src/packages/game/input/IZ_app.c rename to src/packages/game/IZ_app_input.c index 44bd1a6..15f9538 100644 --- a/src/packages/game/input/IZ_app.c +++ b/src/packages/game/IZ_app_input.c @@ -1,4 +1,4 @@ -#include "IZ_app.h" +#include "IZ_app_input.h" IZ_ProcedureResult IZ_AppHandleSDLEvents(struct IZ_App* app) { SDL_Event e; diff --git a/src/packages/game/IZ_app_input.h b/src/packages/game/IZ_app_input.h new file mode 100644 index 0000000..1277aed --- /dev/null +++ b/src/packages/game/IZ_app_input.h @@ -0,0 +1,8 @@ +#ifndef IZ_APP_INPUT_H +#define IZ_APP_INPUT_H + +#include "IZ_subsystem.h" + +IZ_ProcedureResult IZ_AppHandleInputEvents(struct IZ_App*); + +#endif diff --git a/src/packages/game/net/IZ_app.c b/src/packages/game/IZ_app_net.c similarity index 99% rename from src/packages/game/net/IZ_app.c rename to src/packages/game/IZ_app_net.c index f7006ba..a0c4049 100644 --- a/src/packages/game/net/IZ_app.c +++ b/src/packages/game/IZ_app_net.c @@ -1,4 +1,4 @@ -#include "IZ_app.h" +#include "IZ_app_net.h" void IZ_AppHandleNetworkingInboundBinaryEvents(struct IZ_App* app, void* binary_raw, size_t len) { u8* binary = binary_raw; diff --git a/src/packages/game/net/IZ_app.h b/src/packages/game/IZ_app_net.h similarity index 91% rename from src/packages/game/net/IZ_app.h rename to src/packages/game/IZ_app_net.h index 1095d64..e1d73a5 100644 --- a/src/packages/game/net/IZ_app.h +++ b/src/packages/game/IZ_app_net.h @@ -1,8 +1,8 @@ -#ifndef IZ_NET_APP_H -#define IZ_NET_APP_H +#ifndef IZ_APP_NET_H +#define IZ_APP_NET_H -#include "IZ_net.h" -#include "../IZ_subsystem.h" +#include "net/IZ_net.h" +#include "IZ_subsystem.h" typedef enum { IZ_MESSAGE_KIND_ACTION_SYNC = 0, diff --git a/src/packages/game/output/video/IZ_app.c b/src/packages/game/IZ_app_video.c similarity index 99% rename from src/packages/game/output/video/IZ_app.c rename to src/packages/game/IZ_app_video.c index 9da9196..d621a07 100644 --- a/src/packages/game/output/video/IZ_app.c +++ b/src/packages/game/IZ_app_video.c @@ -1,4 +1,4 @@ -#include "IZ_app.h" +#include "IZ_app_video.h" void IZ_VideoUpdateForDebugTicks(IZ_VideoState* video_state, uint64_t ticks) { SDL_SetRenderDrawColor(video_state->renderer, 0x00, 0xff, 0xff, 0xff); diff --git a/src/packages/game/IZ_app_video.h b/src/packages/game/IZ_app_video.h new file mode 100644 index 0000000..7f12c9d --- /dev/null +++ b/src/packages/game/IZ_app_video.h @@ -0,0 +1,9 @@ +#ifndef IZ_APP_VIDEO_H +#define IZ_APP_VIDEO_H + +#include "output/video/IZ_video.h" +#include "IZ_subsystem.h" + +void IZ_VideoUpdate(IZ_VideoState*); + +#endif diff --git a/src/packages/game/IZ_config.c b/src/packages/game/config/IZ_config.c similarity index 95% rename from src/packages/game/IZ_config.c rename to src/packages/game/config/IZ_config.c index 89f4d6d..ad4fef6 100644 --- a/src/packages/game/IZ_config.c +++ b/src/packages/game/config/IZ_config.c @@ -1,16 +1,5 @@ #include "IZ_config.h" -void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) { -#ifdef IZ_DEBUG - const char* config_path_dir = SDL_GetBasePath(); -#else - const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME); -#endif - - memcpy_s(config_path, string_size, config_path_dir, 128); - strcat_s(config_path, string_size, "config-game.ini"); -} - const char* IZ_ConfigGetCommandlineOption(u8 argc, const char* argv[], const char* val) { size_t n = strlen(val); int c = argc; diff --git a/src/packages/game/IZ_config.h b/src/packages/game/config/IZ_config.h similarity index 93% rename from src/packages/game/IZ_config.h rename to src/packages/game/config/IZ_config.h index 68aa0d8..a26873f 100644 --- a/src/packages/game/IZ_config.h +++ b/src/packages/game/config/IZ_config.h @@ -1,11 +1,10 @@ #ifndef IZ_CONFIG_H #define IZ_CONFIG_H -#include #include -#include #include -#include "IZ_common.h" +#include +#include "../IZ_common.h" typedef enum { IZ_CONFIG_TYPE_VOID, diff --git a/src/packages/game/input/IZ_app.h b/src/packages/game/input/IZ_app.h deleted file mode 100644 index a6832c6..0000000 --- a/src/packages/game/input/IZ_app.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef IZ_INPUT_APP_H -#define IZ_INPUT_APP_H - -#include "../IZ_subsystem.h" - -IZ_ProcedureResult IZ_AppHandleInputEvents(struct IZ_App*); - -#endif diff --git a/src/packages/game/net/IZ_net.h b/src/packages/game/net/IZ_net.h index 8e1c066..19109b3 100644 --- a/src/packages/game/net/IZ_net.h +++ b/src/packages/game/net/IZ_net.h @@ -4,7 +4,7 @@ #include #include #include "../IZ_common.h" -#include "../IZ_config.h" +#include "../config/IZ_config.h" #include "../input/IZ_action.h" #include "core/IZ_websocket.h" #include "svc/IZ_wsclient.h" diff --git a/src/packages/game/output/video/IZ_app.h b/src/packages/game/output/video/IZ_app.h deleted file mode 100644 index bc1775f..0000000 --- a/src/packages/game/output/video/IZ_app.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef IZ_VIDEO_APP_H -#define IZ_VIDEO_APP_H - -#include "IZ_video.h" -#include "../../IZ_subsystem.h" - -void IZ_VideoUpdate(IZ_VideoState*); - -#endif diff --git a/src/packages/game/output/video/IZ_video.h b/src/packages/game/output/video/IZ_video.h index df74861..d373b50 100644 --- a/src/packages/game/output/video/IZ_video.h +++ b/src/packages/game/output/video/IZ_video.h @@ -8,7 +8,7 @@ #include "../../input/IZ_input.h" #include "../../net/IZ_net.h" #include "../../IZ_common.h" -#include "../../IZ_config.h" +#include "../../config/IZ_config.h" #define MAX_ACTIVE_SPRITES 32 diff --git a/src/packages/server/net/IZ_net.h b/src/packages/server/net/IZ_net.h index aba10ce..bc69d21 100644 --- a/src/packages/server/net/IZ_net.h +++ b/src/packages/server/net/IZ_net.h @@ -8,7 +8,6 @@ #define IZ_DEFAULT_MOTD "" - typedef struct { u16 port; char name[64];