diff --git a/doc/TODO.gmi b/doc/TODO.gmi index dc98ef6..1d3acf2 100644 --- a/doc/TODO.gmi +++ b/doc/TODO.gmi @@ -2,9 +2,13 @@ A list of things I'd like to accomplish ## In Progress -* Tick-based game loop +* Add a lua modding API +* Load mods +* Handle mod dependencies ## Completed +* Specify mods directory +* Tick-based game loop * Split game ticking and socket connecting logic (can only tick on connection atm) * Client send request * Server handle request and send response @@ -26,9 +30,6 @@ A list of things I'd like to accomplish * Display environment and pan camera * Time controls (play/pause/speed up) * See creature stats -* Add a lua modding API -* Load mods -* Handle mod dependencies * Remove rendering from serverside * Client-side resource files for each mod * Real error handling (right now I just pass up to main and immediately exit) diff --git a/scripts/run.sh b/scripts/run.sh index 7a3ed48..402e197 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -7,20 +7,40 @@ if ! [ -d ".git" ]; then exit 1 fi +OPTIND=1 + +server_args="" +client1_args="" +client2_args="" +client3_args="" + +while getopts "d:1:2:3:" opt; do + case "${opt}" in + d) server_args="${OPTARG}" ;; + 1) client1_args="${OPTARG}" ;; + 2) client2_args="${OPTARG}" ;; + 3) client3_args="${OPTARG}" ;; + *) echo "Invalid flag"; exit 1 + esac +done + +shift $((OPTIND - 1)) +[ "${1:-}" = "--" ] && shift + ./scripts/build.sh echo "### DAEMON ###" -./build/server/simworld-daemon & +./build/server/simworld-daemon ${server_args} & sleep 1 echo "### CLIENT 1 ###" -./build/client/simworld-client +./build/client/simworld-client ${client1_args} echo "### CLIENT 2 ###" -./build/client/simworld-client +./build/client/simworld-client ${client2_args} echo "### CLIENT 3 ###" sleep 1 -./build/client/simworld-client +./build/client/simworld-client ${client3_args} killall simworld-daemon diff --git a/server/src/main.c b/server/src/main.c index 0a89654..ed04089 100644 --- a/server/src/main.c +++ b/server/src/main.c @@ -100,20 +100,20 @@ int main(int argc, char **argv) { // Socket handler thread pthread_t pthread_socket; err = socket_thread(&pthread_socket, &data); - if (err) goto handle_error; + if (err) goto handle_error_world; // Simulation thread pthread_t pthread_simulation; err = simulation_thread(&pthread_simulation, &data); - if (err) goto handle_error; + if (err) goto handle_error_world; // Join threads // TODO: A way to shut down the program properly pthread_join(pthread_socket, (void **)&err); // No way this is correct lol - if (err) goto handle_error; + if (err) goto handle_error_world; pthread_join(pthread_simulation, (void **)&err); - if (err) goto handle_error; + if (err) goto handle_error_world; // Deinitialisation pthread_mutex_destroy(&data.world_lock); diff --git a/server/src/opts.c b/server/src/opts.c index 67f9dd2..4fdb4c0 100644 --- a/server/src/opts.c +++ b/server/src/opts.c @@ -1,5 +1,6 @@ // opts.c +#include #include #include #include @@ -11,22 +12,26 @@ void opts_default(struct options_t *options) { options->daemonise = false; + options->mods_directory = NULL; } enum error_t opts_parse(struct options_t *options, int argc, char **argv) { struct option const long_options[] = { - { "daemon", no_argument, 0, 'd' }, + { "daemon", no_argument, 0, 'd' }, + { "mods-directory", required_argument, 0, 'm' }, + { NULL, 0, 0, 0 } }; while (true) { int option_index = 0; - int c = getopt_long(argc, argv, "d", long_options, &option_index); + int c = getopt_long(argc, argv, "dm:", long_options, &option_index); if (c == -1) break; switch (c) { case 'd': options->daemonise = true; break; + case 'm': options->mods_directory = optarg; break; default: return ERR_INPUT; } } diff --git a/server/src/opts.h b/server/src/opts.h index 001eb21..c0f90f9 100644 --- a/server/src/opts.h +++ b/server/src/opts.h @@ -6,6 +6,7 @@ #include struct options_t { + char const* mods_directory; bool daemonise; };