32#define SCREEN_WIDTH 800
33#define SCREEN_HEIGHT 600
39#define FB_PIXEL_MODE BJ_PIXEL_MODE_XRGB8888
42#define BALLS_RADIUS BJ_F(3.0)
43#define GRAVITY BJ_F(50.0)
65 const uint8_t r = (uint8_t)(128 + rand() % 128);
66 const uint8_t g = (uint8_t)(128 + rand() % 128);
67 const uint8_t b = (uint8_t)(128 + rand() % 128);
83 balls[at].initial_velocity.x =
bj_cos(angle) * magnitude;
84 balls[at].initial_velocity.y =
bj_sin(angle) * magnitude;
85 balls[at].time_alive = 0;
107 for(
size_t b = 0 ; b <
BALLS_LEN ; ++b) {
109 balls[b].time_alive += dt;
120 balls[b].initial_velocity,
142 for(
size_t b = 0 ; b <
BALLS_LEN ; ++b) {
156 (void)w; (void)dirty; (void)user_data;
160static void*
setup(
struct bj_app* app,
void* init_data) {
162 srand((
unsigned)time(NULL));
182 (void)app; (void)user_data;
187 (void)tick; (void)user_data;
196static void teardown(
struct bj_app* app,
void* user_data) {
202int main(
int argc,
char* argv[]) {
203 (void)argc; (void)argv;
Application lifecycle: callback-driven setup, step, and teardown.
int main(int argc, char *argv[])
static void step(struct bj_app *app, struct bj_tick_info tick, void *user_data)
static void teardown(struct bj_app *app, void *user_data)
static void * setup(struct bj_app *app, void *init_data)
static void on_draw(struct bj_window *w, struct bj_render_target *target, const struct bj_rect *dirty, void *user_data)
Header file for Bitmap drawing functions.
void draw(bj_bitmap *bmp)
Sytem event management API.
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.
void bj_clear_bitmap(struct bj_bitmap *bitmap)
Fills the entire bitmap with the clear colour.
struct bj_render_target bj_render_target
struct bj_bitmap bj_bitmap
struct bj_window bj_window
void bj_draw_filled_circle(struct bj_bitmap *bitmap, int cx, int cy, int radius, uint32_t color)
Draw a filled circle onto a bitmap.
void bj_dispatch_events(void)
Poll and dispatch all pending events.
void bj_close_on_escape(struct bj_window *window, const struct bj_key_event *event, void *user_data)
Handle the ESC key to close a window.
bj_key_callback_fn bj_set_key_callback(bj_key_callback_fn callback, void *user_data)
Set the global callback for keyboard key events.
#define BJ_PI
PI in the selected bj_real precision.
#define BJ_F(x)
Literal suffix helper for bj_real when float is selected.
float bj_real
Selected real type for float configuration.
Axis-aligned rectangle: a top-left corner plus a width and height.
2D vector of bj_real components.
struct bj_vec2 bj_compute_kinematics_2d(struct bj_vec2 position, struct bj_vec2 velocity, struct bj_vec2 acceleration, bj_real time)
Integrate constant-acceleration 2D kinematics: position at time t.
uint32_t bj_get_pixel_value(enum bj_pixel_mode mode, uint8_t red, uint8_t green, uint8_t blue)
Returns an opaque value representing a pixel colour, given its RGB composition.
bj_bool bj_begin(int systems, struct bj_error **error)
Initialises the system.
void bj_end(void)
De-initialises the system.
void bj_set_draw_callback(struct bj_window *window, bj_window_draw_fn fn, void *user_data)
Register the redraw callback for window.
static void bj_invalidate_window(struct bj_window *window)
Mark the whole window as needing a repaint.
struct bj_window * bj_bind_window(const char *title, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t flags, struct bj_error **error)
Create a new struct bj_window with the specified attributes.
struct bj_bitmap * bj_render_target_bitmap(struct bj_render_target *target)
Reach the software framebuffer behind a render target.
bj_bool bj_should_close_window(struct bj_window *window)
Get the close flag state of a window.
void bj_unbind_window(struct bj_window *window)
Deletes a struct bj_window object and releases associated memory.
static void fixed_step(struct bj_app *app, struct bj_tick_info tick, void *ud)
Logging utility functions.
Portable main() replacement with platform-aware entry shim.
Physics helpers (SI units, but dimensionally consistent with any unit system).
static void initialize_balls()
static void reset_ball(size_t at)
struct @075336127262265255345326341123106263042221024322 balls[1000]
static void update(bj_real dt)
Header file for general pixel manipulation facilities.
Header file for system interactions.
Header file for time manipulation utilities.
Fixed-size vector types (2D, 3D, 4D) and inline operations.
Header file for bj_window type.