#include "libwasm.h" #include "drawings.h" extern "C" { extern void __wasm_call_ctors(); extern void EXPORT(Init) (const int memlen); extern void EXPORT(setWeight)(const int n, const int val); extern void EXPORT(setSpeed) (const int n); extern void EXPORT(graph) (int w, int h); extern int EXPORT(gEnabled) (); extern void EXPORT(Reset) (); extern void * EXPORT(bg_data)(); extern void * EXPORT(fg_data)(); extern void * EXPORT(gStep) (); // extern void IMPORT(drawPass) (); }; static CommonPlots * pContainer = nullptr; void Init (int memlen) { _HEAP_MAX = reinterpret_cast (memlen); // před prvním voláním malloc() - může být i v konstruktorech __wasm_call_ctors(); // nutné volání statických konstruktorů pokud máme statické třídy printf("Module Init()"); }; void setWeight (const int n, const int val) { //printf ("slider %d to %d\n", n, val); if (pContainer) { pContainer->fg->setWeight (n, val); pContainer->fg->drawings (); // drawPass (); } } void setSpeed (const int n) { if (pContainer) pContainer->fg->changeSpeed(n); } void graph (int w, int h) { if (pContainer) { delete pContainer; pContainer = nullptr; } pContainer = new CommonPlots (w, h); printf("Create pContainer %d x %d\n", w, h); } int gEnabled () { pContainer->StartStop = ! pContainer->StartStop; return pContainer->StartStop ? 1 : 0; } void Reset () { if (pContainer) pContainer->fg->reset(); } struct PtrLen { void * ptr; int len; }; void * bg_data () { static PtrLen pl; pl.ptr = pContainer->bg->getData(); pl.len = pContainer->bg->getSize(); return & pl; } void * fg_data () { static PtrLen pl; pl.ptr = pContainer->fg->getData(); pl.len = pContainer->fg->getSize(); return & pl; } void * gStep () { pContainer->fg->step(); static PtrLen pl; pl.ptr = pContainer->fg->getData(); pl.len = pContainer->fg->getSize(); return & pl; }