Emscripten: Add compatible main loop
This commit is contained in:
parent
bef2fb01d0
commit
9f71eb9d77
@ -510,10 +510,7 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
}
|
||||
|
||||
while (engine.Running())
|
||||
{
|
||||
EngineProcess();
|
||||
}
|
||||
MainLoop();
|
||||
};
|
||||
|
||||
if (enableBluescreen)
|
||||
|
@ -26,6 +26,7 @@ extern bool mouseDown;
|
||||
extern bool calculatedInitialMouse;
|
||||
extern bool hasMouseMoved;
|
||||
|
||||
void MainLoop();
|
||||
void EngineProcess();
|
||||
void StartTextInput();
|
||||
void StopTextInput();
|
||||
|
10
src/PowderToySDLCommon.cpp
Normal file
10
src/PowderToySDLCommon.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "PowderToySDL.h"
|
||||
#include "gui/interface/Engine.h"
|
||||
|
||||
void MainLoop()
|
||||
{
|
||||
while (ui::Engine::Ref().Running())
|
||||
{
|
||||
EngineProcess();
|
||||
}
|
||||
}
|
37
src/PowderToySDLEmscripten.cpp
Normal file
37
src/PowderToySDLEmscripten.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include "PowderToySDL.h"
|
||||
#include "gui/interface/Engine.h"
|
||||
#include <emscripten.h>
|
||||
#include <iostream>
|
||||
|
||||
static float lastFpsLimit;
|
||||
static void updateFpsLimit()
|
||||
{
|
||||
lastFpsLimit = ui::Engine::Ref().FpsLimit;
|
||||
if (lastFpsLimit == 60.0f) // TODO: rework FPS cap so 60.0 is not the default
|
||||
{
|
||||
emscripten_set_main_loop_timing(EM_TIMING_RAF, 1);
|
||||
std::cerr << "implicit fps limit via vsync" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto delay = int(1000.f / lastFpsLimit);
|
||||
emscripten_set_main_loop_timing(EM_TIMING_SETTIMEOUT, delay);
|
||||
std::cerr << "explicit fps limit: " << delay << "ms delays" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void mainLoopBody()
|
||||
{
|
||||
EngineProcess();
|
||||
if (lastFpsLimit != ui::Engine::Ref().FpsLimit)
|
||||
{
|
||||
updateFpsLimit();
|
||||
}
|
||||
}
|
||||
|
||||
void MainLoop()
|
||||
{
|
||||
emscripten_set_main_loop(mainLoopBody, 0, 0);
|
||||
updateFpsLimit();
|
||||
mainLoopBody();
|
||||
}
|
@ -3,7 +3,6 @@
|
||||
#include "common/tpt-rand.h"
|
||||
#include "Config.h"
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@ -108,20 +107,4 @@ bool WriteFile(const std::vector<char> &fileData, ByteString filename)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::list<ExitFunc> exitFuncs;
|
||||
|
||||
void Atexit(ExitFunc exitFunc)
|
||||
{
|
||||
exitFuncs.push_front(exitFunc);
|
||||
}
|
||||
|
||||
void Exit(int code)
|
||||
{
|
||||
for (auto exitFunc : exitFuncs)
|
||||
{
|
||||
exitFunc();
|
||||
}
|
||||
exit(code);
|
||||
}
|
||||
}
|
||||
|
@ -29,4 +29,12 @@ bool Install()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Atexit(ExitFunc exitFunc)
|
||||
{
|
||||
}
|
||||
|
||||
void Exit(int code)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
22
src/common/platform/ExitCommon.cpp
Normal file
22
src/common/platform/ExitCommon.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "Platform.h"
|
||||
#include <cstdlib>
|
||||
#include <list>
|
||||
|
||||
namespace Platform
|
||||
{
|
||||
std::list<ExitFunc> exitFuncs;
|
||||
|
||||
void Atexit(ExitFunc exitFunc)
|
||||
{
|
||||
exitFuncs.push_front(exitFunc);
|
||||
}
|
||||
|
||||
void Exit(int code)
|
||||
{
|
||||
for (auto exitFunc : exitFuncs)
|
||||
{
|
||||
exitFunc();
|
||||
}
|
||||
exit(code);
|
||||
}
|
||||
}
|
@ -10,18 +10,21 @@ if host_platform == 'windows'
|
||||
path_sep_char = '\\\\'
|
||||
common_files += files(
|
||||
'Windows.cpp',
|
||||
'ExitCommon.cpp',
|
||||
)
|
||||
elif host_platform == 'darwin'
|
||||
can_install_enforce_no = true
|
||||
common_files += files(
|
||||
'Darwin.cpp',
|
||||
'Posix.cpp',
|
||||
'ExitCommon.cpp',
|
||||
)
|
||||
elif host_platform == 'android'
|
||||
can_install_enforce_no = true
|
||||
common_files += files(
|
||||
'Android.cpp',
|
||||
'Posix.cpp',
|
||||
'ExitCommon.cpp',
|
||||
)
|
||||
elif host_platform == 'emscripten'
|
||||
use_bluescreen = false
|
||||
@ -36,12 +39,14 @@ elif host_platform == 'linux'
|
||||
common_files += files(
|
||||
'Linux.cpp',
|
||||
'Posix.cpp',
|
||||
'ExitCommon.cpp',
|
||||
)
|
||||
else
|
||||
can_install_enforce_no = true
|
||||
common_files += files(
|
||||
'Null.cpp',
|
||||
'Posix.cpp',
|
||||
'ExitCommon.cpp',
|
||||
)
|
||||
endif
|
||||
conf_data.set('SET_WINDOW_ICON', set_window_icon ? 'true' : 'false')
|
||||
|
@ -46,6 +46,15 @@ powder_files = files(
|
||||
'lua/TPTScriptInterface.cpp',
|
||||
'lua/TPTSTypes.cpp',
|
||||
)
|
||||
if host_platform == 'emscripten'
|
||||
powder_files += files(
|
||||
'PowderToySDLEmscripten.cpp',
|
||||
)
|
||||
else
|
||||
powder_files += files(
|
||||
'PowderToySDLCommon.cpp',
|
||||
)
|
||||
endif
|
||||
if is_x86
|
||||
powder_files += files('X86KillDenormals.cpp')
|
||||
endif
|
||||
|
Loading…
Reference in New Issue
Block a user