Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" )


Expand All @@ -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()


Expand Down Expand Up @@ -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
Expand Down
87 changes: 43 additions & 44 deletions src/Game.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include <SDL_ttf.h>

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <emscripten.h>
#endif

void gameLoop(void* arg_);
void gameLoop(void *arg_);

#ifdef USE_ANGELSCRIPT
#include "Scripting/ScriptEngine.hxx"
Expand All @@ -33,16 +33,17 @@ void gameLoop(void* arg_);
template void Game::LoopMain<GameLoopMQ, Game::GameVisitor>(Game::GameContext &, Game::GameVisitor);
template void Game::LoopMain<UILoopMQ, Game::UIVisitor>(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,
Expand Down Expand Up @@ -257,15 +258,14 @@ 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;

Engine &engine = Engine::instance();
EventManager &evManager = EventManager::instance();
UIManager &uiManager = UIManager::instance();


if (SkipMenu)
{
Engine::instance().newGame();
Expand All @@ -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();

Expand Down Expand Up @@ -310,10 +309,10 @@ void Game::run(bool SkipMenu)
// GameLoop
while (engine.isGameRunning())
{
gameLoop( arg);
gameLoop(arg);
}
#endif
#endif

delete arg;
}

Expand Down Expand Up @@ -359,49 +358,49 @@ template <typename MQType, typename Visitor> 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
}
8 changes: 4 additions & 4 deletions src/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down