Banjo API 1.0.0-rc.2
Low-level C99 game development API
Loading...
Searching...
No Matches
template_callbacks.c
Go to the documentation of this file.
1
11
12#include <banjo/app.h>
13#include <banjo/main.h>
14#include <banjo/log.h>
15#include <banjo/system.h>
16
17// Called once at program startup. Initialize your resources here.
18static void* setup(struct bj_app* app, void* init_data) {
19 (void)init_data;
20
21 // Initialize Banjo subsystems. Same as in template.c.
23 bj_quit_app(app, 1);
24 return 0;
25 }
26 return 0;
27}
28
29// Called repeatedly in a loop. Your main logic goes here. Call bj_quit_app
30// to exit the loop and proceed to teardown.
31static void step(struct bj_app* app, struct bj_tick_info tick, void* user_data) {
32 (void)tick;
33 (void)user_data;
34
35 bj_info("Hello Banjo!");
36
37 // Exit after one iteration for this simple example. In a real program,
38 // you'd keep iterating until the user closes the window or some exit
39 // condition is met.
40 bj_quit_app(app, 0);
41}
42
43// Called once after the loop ends. Cleanup your resources here.
44static void teardown(struct bj_app* app, void* user_data) {
45 (void)user_data;
46
47 // Shutdown Banjo and release resources.
48 bj_end();
49}
50
51int main(int argc, char* argv[]) {
52 (void)argc; (void)argv;
53 return bj_run_app(setup, step, 0, teardown, 0);
54}
Application lifecycle: callback-driven setup, step, and teardown.
int main(int argc, char *argv[])
Definition audio_pcm.c:177
static void step(struct bj_app *app, struct bj_tick_info tick, void *user_data)
Definition audio_pcm.c:144
static void teardown(struct bj_app *app, void *user_data)
Definition audio_pcm.c:170
static void * setup(struct bj_app *app, void *init_data)
Definition audio_pcm.c:107
int bj_run_app(bj_app_setup_fn setup, bj_app_step_fn step, bj_app_fixed_step_fn fixed_step, bj_app_teardown_fn teardown, void *init_data)
Drive the application lifecycle.
void bj_quit_app(struct bj_app *app, int exit_code)
Signal the given application to exit on the next iteration.
Timing snapshot handed to the step and fixed-step callbacks.
Definition app.h:106
#define bj_info(...)
Log a message using the BJ_LOG_INFO level.
Definition log.h:141
bj_bool bj_begin(int systems, struct bj_error **error)
Initialises the system.
void bj_end(void)
De-initialises the system.
@ BJ_VIDEO_SYSTEM
Definition system.h:81
@ BJ_AUDIO_SYSTEM
Definition system.h:80
Logging utility functions.
Portable main() replacement with platform-aware entry shim.
Header file for system interactions.