Christian Semmler 5080e372f9
Emscripten port (#229)
* Emscripten port

* Fix NCC

* Update CMakeLists.txt

Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>

* Update CMakeLists.txt

Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>

* Update CMakeLists.txt

Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>

* Update CMakeLists.txt

* cmake: set iniparser cmake options in local scope

* ci: try adding emscripten to test matrix

* cmake: try to make CMake install package more usable

* cmake: fix typo

* Update CMakeLists.txt

Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>

* Add support for .ini loading

* Different default full screen behavior for Emscripten

* Add comments

* Add web platform

---------

Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
Co-authored-by: Anonymous Maarten <anonymous.maarten@gmail.com>
2025-06-13 00:26:43 +02:00

39 lines
1.0 KiB
C++

#include "events.h"
#include "mxdsaction.h"
#include <emscripten.h>
// clang-format off
void Emscripten_SendEvent(const char* p_event, const char* p_json)
{
MAIN_THREAD_EM_ASM({
const eventName = UTF8ToString($0);
let eventDetail = {};
if ($1 && UTF8ToString($1).length > 0) {
eventDetail = JSON.parse(UTF8ToString($1));
}
const targetElement = Module.canvas || window;
const event = new CustomEvent(eventName, {detail : eventDetail});
targetElement.dispatchEvent(event);
}, p_event, p_json);
}
// clang-format on
void Emscripten_SendPresenterProgress(MxPresenter* p_presenter, MxPresenter::TickleState p_tickleState)
{
char buf[128];
SDL_snprintf(
buf,
sizeof(buf),
"{\"objectId\": %d, \"objectName\": \"%s\", \"tickleState\": %d}",
p_presenter->GetAction() ? p_presenter->GetAction()->GetObjectId() : 0,
p_presenter->GetAction() ? p_presenter->GetAction()->GetObjectName() : "",
p_tickleState
);
Emscripten_SendEvent("presenterProgress", buf);
}