From 3eb2d3400cba9c94475815850fa9c51129d259f8 Mon Sep 17 00:00:00 2001 From: ksg Date: Thu, 30 Jun 2016 09:57:51 -0700 Subject: [PATCH] new headers --- src/core/engine.h | 36 +++++++++++++++++++ src/core/io.c | 42 ++++++++++++++++++++++ src/core/trigger.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 src/core/engine.h create mode 100644 src/core/io.c create mode 100644 src/core/trigger.h diff --git a/src/core/engine.h b/src/core/engine.h new file mode 100644 index 0000000..9af038f --- /dev/null +++ b/src/core/engine.h @@ -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 index 0000000..631a452 --- /dev/null +++ b/src/core/io.c @@ -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 +#include +#else +/* Traditional Environment */ +#ifdef __Win32 +#include +#endif //__Win32 +#include +#endif +/* ENVIRONMENT-AGNOSTIC DEFINES */ +#include +#include +#include +#include +#include + +/* 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 index 0000000..b1a8b71 --- /dev/null +++ b/src/core/trigger.h @@ -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 + + 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 + #include + + 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_ -- 2.18.0