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
## 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)

View File

@ -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

View File

@ -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);

View File

@ -1,5 +1,6 @@
// opts.c
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/syslog.h>
@ -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;
}
}

View File

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