Parcourir la source

Add help

Make sure to have help messages for both the game and the server.
feature/data-structs
TheoryOfNekomata il y a 2 ans
Parent
révision
d1530e0ae0
7 fichiers modifiés avec 88 ajouts et 14 suppressions
  1. +7
    -1
      CMakeLists.txt
  2. +35
    -9
      src/packages/game/IZ_app.c
  3. +6
    -1
      src/packages/game/net/IZ_net.c
  4. +6
    -1
      src/packages/game/output/video/IZ_video.c
  5. +27
    -0
      src/packages/server/IZ_app.c
  6. +1
    -1
      src/packages/server/db/IZ_repo.c
  7. +6
    -1
      src/packages/server/net/IZ_net.c

+ 7
- 1
CMakeLists.txt Voir le fichier

@@ -13,7 +13,13 @@ if (WIN32)
endif ()
endif ()

add_definitions(-DIZ_APP_NAME="Izanagi" -DIZ_PLAYERS=1)
add_definitions(
-DIZ_APP_NAME="Izanagi"
-DIZ_APP_DESCRIPTION="Run and gun game"
-DIZ_APP_SERVER_DESCRIPTION="Dedicated server"
-DIZ_PLAYERS=1
)

if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
add_definitions(-DIZ_DEBUG)
endif()


+ 35
- 9
src/packages/game/IZ_app.c Voir le fichier

@@ -18,6 +18,16 @@ IZ_InputState* IZ_AppGetInputState(struct IZ_App* app) {

IZ_ProcedureResult IZ_AppInitialize(struct IZ_App* app, u8 argc, const char* argv[]) {
memset(app, 0, sizeof(struct IZ_App));

const char* cmdline_buffer;
char config_path[128];
// TODO abstract command line args parsing
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) {
memcpy_s(config_path, 128, cmdline_buffer, 128);
} else {
IZ_ConfigGetDefaultPath(config_path, 128);
}

u32 flags = (
SDL_INIT_VIDEO
| SDL_INIT_GAMECONTROLLER
@@ -29,15 +39,6 @@ IZ_ProcedureResult IZ_AppInitialize(struct IZ_App* app, u8 argc, const char* arg
return IZ_APP_RUN_SDL_INIT_ERROR;
}

const char* cmdline_buffer;
char config_path[128];
// TODO abstract command line args parsing
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) {
memcpy_s(config_path, 128, cmdline_buffer, 128);
} else {
IZ_ConfigGetDefaultPath(config_path, 128);
}

if (IZ_VideoInitialize(&app->video_state, app, config_path, argc, argv)) {
return IZ_APP_RUN_VIDEO_INIT_ERROR;
}
@@ -65,6 +66,31 @@ void IZ_AppTeardown(struct IZ_App* app) {
}

IZ_ProcedureResult IZ_AppRun(struct IZ_App* app, u8 argc, const char* argv[]) {
if (IZ_ConfigGetCommandlineOption(argc, argv, "-h")) {
printf(
(
"\n"
"%s - %s\n"
"\n"
"Usage:\n"
"\n"
" %s [options]\n"
"\n"
"Options:\n"
"\n"
" -c <path> Specifies the path to the config file. (default: \"./config-game.ini\")\n"
" -f <value> Specifies the frames per second. (default: 30)\n"
" -h Displays this help file.\n"
" -i <value> Specifies the interval of sending packets (default: 200)\n"
" in milliseconds.\n"
),
IZ_APP_NAME,
IZ_APP_DESCRIPTION,
"game.exe"
);
return IZ_APP_RUN_RESULT_OK;
}

IZ_ProcedureResult init_result = IZ_AppInitialize(app, argc, argv);
if (init_result) {
return init_result;


+ 6
- 1
src/packages/game/net/IZ_net.c Voir le fichier

@@ -44,8 +44,13 @@ IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState* state, const char* config_path)

void IZ_NetOverrideConfig(IZ_NetState* state, u8 argc, const char* argv[]) {
const char* cmdline_buffer;
char* rest_of_string;
u16 packet_interval_ms;
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-i"))) {
state->config.packet_interval_ms = atoi(cmdline_buffer);
packet_interval_ms = strtol(cmdline_buffer, &rest_of_string, 10);
if (strcmp(cmdline_buffer, rest_of_string) != 0) {
state->config.packet_interval_ms = packet_interval_ms;
}
}
}



+ 6
- 1
src/packages/game/output/video/IZ_video.c Voir le fichier

@@ -22,8 +22,13 @@ void IZ_VideoLoadConfig(IZ_VideoState* state, const char* config_path) {

void IZ_VideoOverrideConfig(IZ_VideoState* state, u8 argc, const char* argv[]) {
const char* cmdline_buffer;
char* rest_of_string;
u8 max_fps;
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-f"))) {
state->config.max_fps = atoi(cmdline_buffer);
max_fps = strtol(cmdline_buffer, &rest_of_string, 10);
if (strcmp(cmdline_buffer, rest_of_string) != 0) {
state->config.max_fps = max_fps;
}
}
}



+ 27
- 0
src/packages/server/IZ_app.c Voir le fichier

@@ -42,6 +42,33 @@ void IZ_AppTeardown(IZ_App* app) {
}

IZ_ProcedureResult IZ_AppRun(IZ_App *app, u8 argc, const char **argv) {
if (IZ_ConfigGetCommandlineOption(argc, argv, "-h")) {
printf(
(
"\n"
"%s - %s\n"
"\n"
"Usage:\n"
"\n"
" %s [options]\n"
"\n"
"Options:\n"
"\n"
" -c <path> Specifies the path to the config file. (default: \"./config-server.ini\")\n"
" -d <path> Specifies the path to the database. (default: \"./db.sqlite\")\n"
" -h Displays this help file.\n"
" -m <value> Specifies the message of the day. (default: \"\")\n"
" -n <value> Specifies the name of the server. (default: \"%s\")\n"
" -p <value> Specifies the port where the server runs. (default: 42069)\n"
),
IZ_APP_NAME,
IZ_APP_SERVER_DESCRIPTION,
"server.exe",
IZ_APP_NAME
);
return 0;
}

if (IZ_AppInitialize(app, argc, argv)) {
return -1;
}


+ 1
- 1
src/packages/server/db/IZ_repo.c Voir le fichier

@@ -17,7 +17,7 @@ IZ_ProcedureResult IZ_RepoSaveConfig(IZ_RepoState* state, const char* config_pat

void IZ_RepoOverrideConfig(IZ_RepoState* state, u8 argc, const char* argv[]) {
const char* cmdline_buffer;
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-n"))) {
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-d"))) {
memcpy_s(state->config.path, 64, cmdline_buffer, 64);
}
}


+ 6
- 1
src/packages/server/net/IZ_net.c Voir le fichier

@@ -30,8 +30,13 @@ IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState* state, const char* config_path)

void IZ_NetOverrideConfig(IZ_NetState* state, u8 argc, const char* argv[]) {
const char* cmdline_buffer;
char* rest_of_string;
u16 port;
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-p"))) {
state->config.port = atoi(cmdline_buffer);
port = strtol(cmdline_buffer, &rest_of_string, 10);
if (strcmp(cmdline_buffer, rest_of_string) != 0) {
state->config.port = port;
}
}

if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-n"))) {


Chargement…
Annuler
Enregistrer