Application API #10
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
OragonEfreet/banjo#10
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The current
<banjo/main.h>mixes two concepts that should be separate:main/WinMain/UIApplicationMain/ Emscripten's no-mainstory. Where the OS hands control to your code.Hot reloading (future) only blurs the entry-point side; the lifecycle stays clean. Splitting now means hot reload doesn't have to re-think the whole header later.
Outcome
Split
<banjo/main.h>into two headers; the lifecycle side becomes a runtime API rather than a compile-time macro mode.<banjo/main.h>(narrowed, macro-free, include-only opt-in)Optional. Include it on platforms where the OS calls something other than
main()(Windows GUI subsystem, Emscripten, future iOS). The include itself is the opt-in — noBJ_AUTOMAINmacro. On Linux / macOS / Win32-console you just write a normalmain()and don't include this header at all.Banjo handles the platform handshake internally (e.g.
#define main bj_mainso banjo can provide the realmain/WinMain/emscripten_set_main_loopstub that calls into the user's function). The user always writesint main(int, char*[]).<banjo/app.h>(new)Application lifecycle. Pass-by-struct config, no setters, no macros.
User writes (Linux / macOS / Win32 console):
Or with the entry-point abstraction (Windows GUI / Emscripten / iOS):
Same source body either way. Only the include of main.h differs. Some programs will include it unconditionally on every platform (no-op where it isn't needed) for portability.
BJ_AUTOMAINandBJ_AUTOMAIN_CALLBACKSretiredBoth macros are gone. The callback mode that
BJ_AUTOMAIN_CALLBACKSenabled becomes the only mode — every banjo program registers callbacks viastruct bj_app. The opt-in for the platform stub is the<banjo/main.h>include itself.Window creation lives in
setup; window-level callbacks (redraw, key, button, cursor, enter) live in<banjo/window.h>and are registered on each window after creation.Design notes
mainandbj_app_rundoesn't return until the loop ends.src/app.c. Same as GLFW.Per-platform
bj_app_runwhile (!quit) bj_app_step_internal();then teardownemscripten_set_main_loop(internal_step, 0, 1)and return; JS runtime drives the loopUIApplicationMain; the run loop calls our step internallyPer-platform
<banjo/main.h>content/SUBSYSTEM:WINDOWS)WinMainstub that callsbj_main(renamed usermainvia#define)mainis reachable viaemscripten_set_main_loop_argUIApplicationMainstubBanjo can provide both
mainandWinMainstubs on Windows unconditionally — the linker picks whichever the chosen subsystem expects. No user-side discrimination needed.Out of scope
bj_app_stepfor users running their own outer loop — can come later if asked.Migration
BJ_AUTOMAINandBJ_AUTOMAIN_CALLBACKSdeleted. Examples using either are rewritten to use the struct.examples/start.ctutorial rewritten as the canonical "create struct, call run" shape.\fileblock at the top of<banjo/main.h>(currently describingbj_mainas the user-facing function) is rewritten to reflect that the user writesmain()and banjo's machinery handles the platform handshake.Depends on / blocks
Lands together with the redraw-callback card since
setupis where users register the redraw callback on the window they just created.The animation example doesn't seem to compileto Application API