some steps, x11 not found

This commit is contained in:
arthur.jamet
2021-05-28 17:35:50 +02:00
parent c2588696fa
commit b667e3ac71
5 changed files with 86 additions and 0 deletions
+34
View File
@@ -15,6 +15,12 @@
#include "System/System.hpp"
#include "Models/Callback.hpp"
#ifdef PLATFORM_WEB
#include <emscripten/emscripten.h>
WAL::Wal *walPtr = nullptr;
void *callbackPtr = nullptr;
#endif
namespace WAL
{
//! @brief The main WAL class, it is used to setup and run the ECS.
@@ -109,7 +115,14 @@ namespace WAL
void run(const std::function<void (Wal &, T &)> &callback, T state = T())
{
Callback<Wal &, T &> update(callback);
#ifdef PLATFORM_WEB
walPtr = this;
callbackPtr = &callback;
return emscripten_set_main_loop_arg(runWASM, &state, 0, 1);
#else
return this->run(update, state);
#endif
}
//! @brief Start the game loop
@@ -137,6 +150,27 @@ namespace WAL
}
}
#ifdef PLATFORM_WEB
template<typename T>
static void runIteration(T *state)
{
static std::function<void (Wal &, T &)> callback = callbackPtr;
static auto lastTick = std::chrono::steady_clock::now();
static std::chrono::nanoseconds fBehind(0);
auto now = std::chrono::steady_clock::now();
std::chrono::nanoseconds dtime = now - lastTick;
fBehind += dtime;
lastTick = now;
while (fBehind > Wal::timestep) {
fBehind -= Wal::timestep;
this->_fixedUpdate();
}
walPtr->_update(dtime);
callback(wal, state);
}
#endif
//! @brief A default constructor
Wal() = default;
//! @brief A WAL can't be copy constructed