You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We could minimize or even completely ditch (in cases) editing existing raylib programms using some tricks. At least, the editing I suggest I see as less intrusive.
We can reuse main function as our frame generator. We will initialize the programm on the first main call, but will skip the loop by setting WindowShouldClose in js as always true. All subsequent calls we'll skip initialization and jump straight into frame update and draw.
Here is the simple example:
By saying "less intrusive" I mean that it's just inserts or replacements, no or at least less moving existing stuff around. Which leads us to macros. In some simple programms we can factor all modifications out to raylib.h or other header and put it under #ifdef PLATFORM_WEB. If we can threat BeginDrawing and EndDrawing as loop brackets (no updates or anything in loop but outside them), and don't have anything meaningful after CloseWindow.
C macros are quite restricted, so as the next enhancement, to make it more robust we could implement our own preprocessing step. E.g. it would be better to automatically put begin_frame label right at the start of the loop. So I tryed a macro for this as well but no luck.
#define WindowShouldClose()) true) ; begin_frame: if (true)
The text was updated successfully, but these errors were encountered:
k00lagin
changed the title
Preprocessing and labels
Preprocessing and labels trick
May 10, 2024
We could minimize or even completely ditch (in cases) editing existing raylib programms using some tricks. At least, the editing I suggest I see as less intrusive.
We can reuse
main
function as our frame generator. We will initialize the programm on the first main call, but will skip the loop by settingWindowShouldClose
in js as always true. All subsequent calls we'll skip initialization and jump straight into frame update and draw.Here is the simple example:
By saying "less intrusive" I mean that it's just inserts or replacements, no or at least less moving existing stuff around. Which leads us to macros. In some simple programms we can factor all modifications out to raylib.h or other header and put it under
#ifdef PLATFORM_WEB
. If we can threat BeginDrawing and EndDrawing as loop brackets (no updates or anything in loop but outside them), and don't have anything meaningful after CloseWindow.C macros are quite restricted, so as the next enhancement, to make it more robust we could implement our own preprocessing step. E.g. it would be better to automatically put
begin_frame
label right at the start of the loop. So I tryed a macro for this as well but no luck.The text was updated successfully, but these errors were encountered: