summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..68080b6
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,55 @@
+#include "TZR.h"
+#include "cfg.h"
+#include "log.h"
+#include "netcode.h"
+
+static void deinit(void);
+static int main_loop(void *udata);
+
+int
+main(int argc, char **argv)
+{
+ (void)argc, (void)argv;
+
+ if (argc > 1) {
+ log_info("client, connecting to %s", argv[1]);
+ if (netcode_init_client(argv[1], 8177)) {
+ log_error("netcode_init_client failed");
+ return -1;
+ }
+ } else {
+ log_info("host");
+ if (netcode_init_host(8177)) {
+ log_error("netcode_init_host failed");
+ return -1;
+ }
+ }
+
+ if (TZR_Init(.width=DWIDTH, .height=DHEIGHT, .target_fps=FPS))
+ return 1;
+ if (atexit(deinit)) {
+ deinit();
+ return 1;
+ }
+
+ return TZR_MainLoop(main_loop, NULL);
+}
+
+static void
+deinit(void)
+{
+ TZR_Quit();
+ log_info("closing connection");
+ netcode_deinit();
+}
+
+static int
+main_loop(void *udata)
+{
+ (void)udata;
+
+ TZR_DrawBegin();
+ TZR_DrawEnd();
+
+ return 0;
+}