diff --git a/CMakeLists.txt b/CMakeLists.txt index 15b1e214c9..a1660233b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten") #Debug information #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --profiling-funcs -Oz -g4 -s PTHREAD_POOL_SIZE=8 -s DEMANGLE_SUPPORT=1 -pthread -s DISABLE_EXCEPTION_CATCHING=0 -s ASSERTIONS=1 -s USE_PTHREADS=1 -s USE_SDL_IMAGE=2 -s USE_SDL_TTF=2 -s USE_ZLIB=1" ) - + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --profiling-funcs -O3 -g0 --llvm-lto 1 --llvm-opts 3 -s PTHREAD_POOL_SIZE=8 -pthread -s DISABLE_EXCEPTION_CATCHING=1 -s USE_PTHREADS=1 -s USE_SDL_IMAGE=2 -s USE_SDL_TTF=2 -s USE_ZLIB=1" ) @@ -43,7 +43,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten") #set(SDL2_MIXER_LIBRARIES "-s USE_SDL_MIXER=2") set(SDL2_TTF_LIBRARIES "--no-check-features -s USE_SDL_TTF=2") set(SDL2_ZLIB_LIBRARIES "-s USE_ZLIB=1") - + endif() @@ -148,7 +148,7 @@ if (USE_PACKAGE_MANAGER) "--preload-file ${CMAKE_CURRENT_BINARY_DIR}/resources@/resources" #include resources dir in .data file "-s USE_PTHREADS=1" "--use-preload-plugins" - # "--source-map-base" + # "--source-map-base" "-s WASM=1" "-s WASM_MEM_MAX=512MB" # ALLOW_MEMORY_GROWTH demands MEM_MAX to be set "-s ALLOW_MEMORY_GROWTH=1" #seems necessary for pthreads and dynamic memory allocation diff --git a/src/Game.cxx b/src/Game.cxx index 78dc5217eb..3379801de1 100644 --- a/src/Game.cxx +++ b/src/Game.cxx @@ -13,10 +13,10 @@ #include #ifdef __EMSCRIPTEN__ - #include +#include #endif -void gameLoop(void* arg_); +void gameLoop(void *arg_); #ifdef USE_ANGELSCRIPT #include "Scripting/ScriptEngine.hxx" @@ -33,16 +33,17 @@ void gameLoop(void* arg_); template void Game::LoopMain(Game::GameContext &, Game::GameVisitor); template void Game::LoopMain(Game::GameContext &, Game::UIVisitor); -typedef struct loop_arg { +typedef struct loop_arg +{ Engine *engine; EventManager *evManager; UIManager *uiManager; } loop_arg; - // FPS Counter variables - const float fpsIntervall = 1.0; // interval the fps counter is refreshed in seconds. - Uint32 fpsLastTime = SDL_GetTicks(); - Uint32 fpsFrames = 0; +// FPS Counter variables +const float fpsIntervall = 1.0; // interval the fps counter is refreshed in seconds. +Uint32 fpsLastTime = SDL_GetTicks(); +Uint32 fpsFrames = 0; Game::Game() : m_GameContext(&m_UILoopMQ, &m_GameLoopMQ, @@ -257,7 +258,7 @@ void Game::mainMenu() void Game::run(bool SkipMenu) { - loop_arg* arg = new loop_arg; + loop_arg *arg = new loop_arg; Timer benchmarkTimer; LOG(LOG_INFO) << VERSION; @@ -265,7 +266,6 @@ void Game::run(bool SkipMenu) EventManager &evManager = EventManager::instance(); UIManager &uiManager = UIManager::instance(); - if (SkipMenu) { Engine::instance().newGame(); @@ -278,10 +278,9 @@ void Game::run(bool SkipMenu) arg->engine = &engine; arg->evManager = &evManager; arg->uiManager = &uiManager; - - LOG(LOG_DEBUG) << "Map initialized in " << benchmarkTimer.getElapsedTime() << "ms"; - Camera::centerScreenOnMapCenter(); + LOG(LOG_DEBUG) << "Map initialized in " << benchmarkTimer.getElapsedTime() << "ms"; + Camera::centerScreenOnMapCenter(); uiManager.init(); @@ -310,10 +309,10 @@ void Game::run(bool SkipMenu) // GameLoop while (engine.isGameRunning()) { - gameLoop( arg); + gameLoop(arg); } - #endif - +#endif + delete arg; } @@ -359,49 +358,49 @@ template void Game::LoopMain(GameContext &co } } -void gameLoop(void* arg_) +void gameLoop(void *arg_) // void gameLoop(Engine &engine, EventManager &evManager, UIManager &uiManager) { -loop_arg* arg = (loop_arg*)arg_; - #ifdef MICROPROFILE_ENABLED - MICROPROFILE_SCOPEI("Map", "Gameloop", MP_GREEN); + loop_arg *arg = (loop_arg *)arg_; +#ifdef MICROPROFILE_ENABLED + MICROPROFILE_SCOPEI("Map", "Gameloop", MP_GREEN); #endif - SDL_RenderClear(WindowManager::instance().getRenderer()); -SDL_Event event; - arg->evManager->checkEvents(event, *arg->engine); + SDL_RenderClear(WindowManager::instance().getRenderer()); + SDL_Event event; + arg->evManager->checkEvents(event, *arg->engine); - // render the tileMap - if (arg->engine->map != nullptr) - arg->engine->map->renderMap(); + // render the tileMap + if (arg->engine->map != nullptr) + arg->engine->map->renderMap(); - // render the ui - // TODO: This is only temporary until the new UI is ready. Remove this afterwards - if (GameStates::instance().drawUI) - { - uiManager.drawUI(); - } + // render the ui + // TODO: This is only temporary until the new UI is ready. Remove this afterwards + if (GameStates::instance().drawUI) + { + uiManager.drawUI(); + } - // reset renderer color back to black - SDL_SetRenderDrawColor(WindowManager::instance().getRenderer(), 0, 0, 0, SDL_ALPHA_OPAQUE); + // reset renderer color back to black + SDL_SetRenderDrawColor(WindowManager::instance().getRenderer(), 0, 0, 0, SDL_ALPHA_OPAQUE); - // Render the Frame - SDL_RenderPresent(WindowManager::instance().getRenderer()); + // Render the Frame + SDL_RenderPresent(WindowManager::instance().getRenderer()); - fpsFrames++; + fpsFrames++; - if (fpsLastTime < SDL_GetTicks() - fpsIntervall * 1000) - { - fpsLastTime = SDL_GetTicks(); - arg->uiManager->setFPSCounterText(std::to_string(fpsFrames) + " FPS"); - fpsFrames = 0; - } + if (fpsLastTime < SDL_GetTicks() - fpsIntervall * 1000) + { + fpsLastTime = SDL_GetTicks(); + arg->uiManager->setFPSCounterText(std::to_string(fpsFrames) + " FPS"); + fpsFrames = 0; + } #ifndef __EMSCRIPTEN__ - SDL_Delay(1); + SDL_Delay(1); #endif #ifdef MICROPROFILE_ENABLED - MicroProfileFlip(nullptr); + MicroProfileFlip(nullptr); #endif } diff --git a/src/main.cxx b/src/main.cxx index 061018e315..10b80580d9 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -26,10 +26,10 @@ int protected_main(int argc, char **argv) skipMenu = true; } } - - #ifdef __EMSCRIPTEN__ - skipMenu = true; - #endif + +#ifdef __EMSCRIPTEN__ + skipMenu = true; +#endif LOG(LOG_DEBUG) << "Launching Cytopia";