Mod directory flag

This commit is contained in:
snit 2024-11-14 15:21:36 -06:00
parent f702065a7c
commit 4f93992fba
5 changed files with 41 additions and 14 deletions

View File

@ -2,9 +2,13 @@
A list of things I'd like to accomplish A list of things I'd like to accomplish
## In Progress ## In Progress
* Tick-based game loop * Add a lua modding API
* Load mods
* Handle mod dependencies
## Completed ## Completed
* Specify mods directory
* Tick-based game loop
* Split game ticking and socket connecting logic (can only tick on connection atm) * Split game ticking and socket connecting logic (can only tick on connection atm)
* Client send request * Client send request
* Server handle request and send response * Server handle request and send response
@ -26,9 +30,6 @@ A list of things I'd like to accomplish
* Display environment and pan camera * Display environment and pan camera
* Time controls (play/pause/speed up) * Time controls (play/pause/speed up)
* See creature stats * See creature stats
* Add a lua modding API
* Load mods
* Handle mod dependencies
* Remove rendering from serverside * Remove rendering from serverside
* Client-side resource files for each mod * Client-side resource files for each mod
* Real error handling (right now I just pass up to main and immediately exit) * Real error handling (right now I just pass up to main and immediately exit)

View File

@ -7,20 +7,40 @@ if ! [ -d ".git" ]; then
exit 1 exit 1
fi 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 ./scripts/build.sh
echo "### DAEMON ###" echo "### DAEMON ###"
./build/server/simworld-daemon & ./build/server/simworld-daemon ${server_args} &
sleep 1 sleep 1
echo "### CLIENT 1 ###" echo "### CLIENT 1 ###"
./build/client/simworld-client ./build/client/simworld-client ${client1_args}
echo "### CLIENT 2 ###" echo "### CLIENT 2 ###"
./build/client/simworld-client ./build/client/simworld-client ${client2_args}
echo "### CLIENT 3 ###" echo "### CLIENT 3 ###"
sleep 1 sleep 1
./build/client/simworld-client ./build/client/simworld-client ${client3_args}
killall simworld-daemon killall simworld-daemon

View File

@ -100,20 +100,20 @@ int main(int argc, char **argv) {
// Socket handler thread // Socket handler thread
pthread_t pthread_socket; pthread_t pthread_socket;
err = socket_thread(&pthread_socket, &data); err = socket_thread(&pthread_socket, &data);
if (err) goto handle_error; if (err) goto handle_error_world;
// Simulation thread // Simulation thread
pthread_t pthread_simulation; pthread_t pthread_simulation;
err = simulation_thread(&pthread_simulation, &data); err = simulation_thread(&pthread_simulation, &data);
if (err) goto handle_error; if (err) goto handle_error_world;
// Join threads // Join threads
// TODO: A way to shut down the program properly // TODO: A way to shut down the program properly
pthread_join(pthread_socket, (void **)&err); // No way this is correct lol 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); pthread_join(pthread_simulation, (void **)&err);
if (err) goto handle_error; if (err) goto handle_error_world;
// Deinitialisation // Deinitialisation
pthread_mutex_destroy(&data.world_lock); pthread_mutex_destroy(&data.world_lock);

View File

@ -1,5 +1,6 @@
// opts.c // opts.c
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <sys/syslog.h> #include <sys/syslog.h>
@ -11,22 +12,26 @@
void opts_default(struct options_t *options) { void opts_default(struct options_t *options) {
options->daemonise = false; options->daemonise = false;
options->mods_directory = NULL;
} }
enum error_t opts_parse(struct options_t *options, int argc, char **argv) { enum error_t opts_parse(struct options_t *options, int argc, char **argv) {
struct option const long_options[] = { 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) { while (true) {
int option_index = 0; 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; if (c == -1) break;
switch (c) { switch (c) {
case 'd': options->daemonise = true; break; case 'd': options->daemonise = true; break;
case 'm': options->mods_directory = optarg; break;
default: return ERR_INPUT; default: return ERR_INPUT;
} }
} }

View File

@ -6,6 +6,7 @@
#include <error.h> #include <error.h>
struct options_t { struct options_t {
char const* mods_directory;
bool daemonise; bool daemonise;
}; };