From a373bad6c73927b68f603646bfb9b62bdbbadeff Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 19 Dec 2021 13:08:12 +0100 Subject: [PATCH] hyper-main:: convenience functions for the shared library --- hyper-main.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/hyper-main.cpp b/hyper-main.cpp index bd753ea3..f399a9f7 100644 --- a/hyper-main.cpp +++ b/hyper-main.cpp @@ -31,8 +31,10 @@ void moreStack() { namespace hr { EX hookset hooks_main; -EX int hyper_main(int argc, char **argv) { - using namespace hr; +EX bool initialized = false; + +/** convenience function for libhyper.so: initialize libhyper with given parameters */ +EX int hyper_init(int argc, char **argv) { #if ISWEB emscripten_get_commandline(); #elif ISMOBILE @@ -53,6 +55,29 @@ EX int hyper_main(int argc, char **argv) { arg::read(3); start_game(); #endif + initialized = true; + return 1; + } + +EX int hyper_init() { + return hyper_init(0, nullptr); + } + +/** \brief convenience function for libhyper.so: play the game loop + * sample use: + * ./mymake -O3 -shared + * cling -DFHS -DLINUX -I /usr/include/SDL -l libhyper.so -include hyper.h "-DRun=using namespace hr; hyper_loop();" + * Run + **/ + +EX void hyper_loop() { + if(!initialized) hyper_init(); + quitmainloop = false; + mainloop(); + } + +EX int hyper_main(int argc, char **argv) { + if(!hyper_init(argc, argv)) return 0; #if !ISWEB if(showstartmenu && !vid.skipstart) { #if CAP_STARTANIM