diff --git a/src/core.h b/src/core.h index d7cd60bf..6c43a420 100644 --- a/src/core.h +++ b/src/core.h @@ -61,6 +61,11 @@ static inline int isnan(float f) } #endif +/* If using NaCl, override main with our version */ +#if defined __native_client__ +# define main lol_nacl_main +#endif + // Base types #include "lol/debug.h" #include "math/trig.h" diff --git a/src/platform/nacl/nacl_instance.cpp b/src/platform/nacl/nacl_instance.cpp index 8a040425..de801733 100644 --- a/src/platform/nacl/nacl_instance.cpp +++ b/src/platform/nacl/nacl_instance.cpp @@ -25,6 +25,14 @@ #include "platform/nacl/nacl_instance.h" #include "platform/nacl/opengl_context.h" +/* One of these wrappers will be overridden by the user's version */ +void lol_nacl_main(void) __attribute__((weak)); +void lol_nacl_main(void) {} +void lol_nacl_main(int argc, char **argv) __attribute__((weak)); +void lol_nacl_main(int argc, char **argv) {} +void lol_nacl_main(int argc, char **argv, char **envp) __attribute__((weak)); +void lol_nacl_main(int argc, char **argv, char **envp) {} + namespace lol { @@ -53,26 +61,20 @@ void TickCallback(void* data, int32_t result) DELTA_MS, pp::CompletionCallback(&TickCallback, data), PP_OK); } -} -#define main OLDMAIN -#include "../test/tutorial/tut03.cpp" -#undef main -namespace lol { - -bool NaClInstance::Init(uint32_t /* argc */, +bool NaClInstance::Init(uint32_t argc, const char* /* argn */[], - const char* /* argv */[]) + const char* argv[]) { - Ticker::Setup(60.0f); - - //new Kub(); - //new DebugQuad(); - new Fractal(ivec2(640, 480)); - // My timer callback pp::Module::Get()->core()->CallOnMainThread( DELTA_MS, pp::CompletionCallback(&TickCallback, this), PP_OK); + /* Call the user's main() function. FIXME: run it in a thread */ + char *env[] = { NULL }; + lol_nacl_main(); + lol_nacl_main(argc, const_cast(argv)); + lol_nacl_main(argc, const_cast(argv), (char **)env); + return true; } diff --git a/src/platform/nacl/nacl_instance.h b/src/platform/nacl/nacl_instance.h index ab08b891..0d1a3f20 100644 --- a/src/platform/nacl/nacl_instance.h +++ b/src/platform/nacl/nacl_instance.h @@ -45,6 +45,10 @@ class NaClInstance : public pp::Instance { SharedOpenGLContext opengl_context_; ivec2 m_size; + +private: + static void CallIntMainWrappers(int argc, char const* argn[]); + static void CallVoidMainWrappers(int argc, char const* argn[]); }; } // namespace lol