new headers
authorksg <ken@mihrtec.com>
Thu, 30 Jun 2016 16:57:51 +0000 (09:57 -0700)
committerksg <ken@mihrtec.com>
Thu, 30 Jun 2016 16:57:51 +0000 (09:57 -0700)
src/core/engine.h [new file with mode: 0644]
src/core/io.c [new file with mode: 0644]
src/core/trigger.h [new file with mode: 0644]

diff --git a/src/core/engine.h b/src/core/engine.h
new file mode 100644 (file)
index 0000000..9af038f
--- /dev/null
@@ -0,0 +1,36 @@
+/*!@file
+  \brief   Engine config
+  \details Contains various global compile-time defines such as rendering FPS
+           which loads initial game data, before finally invoking the
+           main loop gameloop(void)
+  \author  K
+  \date    2016
+   ------------------------------------------------------------------------------*/
+#ifndef _ENGINE_H_
+#define _ENGINE_H_
+
+#ifndef __EMSCRIPTEN__
+#define LOOP_YIELD_OPTIONAL
+#endif
+
+/* debug level */
+#ifndef DEBUG
+#define DEBUG 1
+#endif
+
+/* Exit Codes */
+#define EXIT_GRACEFUL 1
+#define EXIT_DEBUG 2
+#define EXIT_PANIC 3
+
+
+/* Target frames per second */
+#ifndef TARGET_FPS
+#define TARGET_FPS 60
+#endif
+
+/* Target milliseconds per frame */
+#define TARGET_DT (1000 / TARGET_FPS)
+
+#endif //_ENGINE_H_
+
diff --git a/src/core/io.c b/src/core/io.c
new file mode 100644 (file)
index 0000000..631a452
--- /dev/null
@@ -0,0 +1,42 @@
+/*!@file
+  \brief   I/O system
+  \details Transpilable I/O system for web and native, including log abstraction
+  \author  K
+  \date    2016
+  ------------------------------------------------------------------------------*/
+#ifdef __EMSCRIPTEN__
+/* Web Environment */
+#include <SDL_ttf.h>
+#include <emscripten/emscripten.h>
+#else
+/* Traditional Environment */
+#ifdef __Win32
+#include <windows.h>
+#endif //__Win32
+#include <SDL2/SDL_ttf.h>
+#endif
+/* ENVIRONMENT-AGNOSTIC DEFINES */
+#include <SDL2/SDL.h>
+#include <SDL2/SDL_image.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <stdio.h>
+
+/* exposed functions */
+int         io_init(void);
+const char* io_get_error(void);
+void        io_quit(void);
+
+/** IO initializer */
+int
+io_init()
+{}
+
+const char*
+io_get_error()
+{}
+
+void
+io_quit()
+{}
+
diff --git a/src/core/trigger.h b/src/core/trigger.h
new file mode 100644 (file)
index 0000000..b1a8b71
--- /dev/null
@@ -0,0 +1,87 @@
+/*!@file
+  \brief   Trigger Mechanism
+  \details includes a small, 15 (by default) element list of function pointers
+           that may be registered and triggered like a stack of functions.
+           Useful for synchronizing function calls.
+
+           Usage example:
+           #include <trigger.h>
+
+           void trigger_test(void);
+
+           extern void hack_the_planet(void);
+           extern void hack_the_plants(void);
+           extern void hack_robert_plant(void);
+
+           void
+           trigger_test()
+           { TRIGGER_SET(hack_the_planet);
+             TRIGGER_SET(hack_the_plants);
+             TRIGGER_SET(hack_robert_plant);
+
+             //Don't worry robert!
+             TRIGGER_POP();
+
+             TRIGGER();
+           }
+
+           Advanced Usage Example:
+           #define MAX_TRIGGER_FUNCS 2
+           #define TRIGGERS kill_trigger flush_trigger
+           #include <trigger.h>
+           #include <hack_functions.h>
+
+           void
+           advanced_trigger_test()
+           { TRIGGER_SET(kill_trigger, hack_the_planet);
+             TRIGGER_SET(kill_trigger, hack_the_missiles);
+             TRIGGER_SET(flush_trigger, hack_the_government);
+             TRIGGER_SET(flush trigger, hack_my_tax_bill);
+
+             if (robert_plant_hacked())
+               { TRIGGER(kill_trigger);
+
+                 TRIGGER_POP(flush_trigger);
+                 TRIGGER_SET(flush_trigger, hack_the_missile_defenses);
+               }
+             TRIGGER(flush_trigger);
+           }
+
+
+  \author  K
+  \date    2016
+  ------------------------------------------------------------------------------*/
+
+#ifndef _TRIGGER_H_
+#define _TRIGGER_H_
+
+/* Function trigger stack for "unwinding" initialization of modules */
+#ifndef MAX_TRIGGER_FUNCS
+#define MAX_TRIGGER_FUNCS 15
+#endif
+
+/* Internal macro prototypes */
+#define _TRIGGER_POP(TARG) --TARG.num_funcs
+#define _TRIGGER_SET(TARG, FUNC) TARG.func[TARG.num_funcs++] = FUNC
+#define _TRIGGER(TARG) while(TARG.num_funcs) (TARG.func[TRIGGER_POP(TARG)])()
+
+/* If TRIGGERS is not defined, use only a default trigger and define shorthand
+   functions for easy use.
+*******************************************************************************/
+#ifndef TRIGGERS
+#define TRIGGERS default_trigger
+#define TRIGGER_POP() _TRIGGER_POP(default_trigger)
+#define TRIGGER_SET(FUNC) _TRIGGER_SET(default_trigger, FUNC)
+#define TRIGGER() _TRIGGER(default_trigger)
+#else
+#define TRIGGER_POP(TARG) _TRIGGER_POP(TARG)
+#define TRIGGER_SET(TARG,FUNC) _TRIGGER_SET(TARG,FUNC)
+#define TRIGGER(TARG) _TRIGGER(TARG)
+#endif
+
+static struct call_trigger
+{ int num_funcs;
+  void (*func[MAX_TRIGGER_FUNCS])(void);
+} TRIGGERS;
+
+#endif //_TRIGGER_H_