diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2025-01-12 12:13:56 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2025-01-12 12:13:56 +0100 |
commit | 29d736aecc5db0deb67053931e5b1cf03a9defc3 (patch) | |
tree | 50caf18887aeda07b24bee5d4143130f8546aff7 /examples/particles.c | |
parent | 464575c72a8a20b5e565f91cebfeb470edc8542e (diff) | |
download | reduced_system_layer-29d736aecc5db0deb67053931e5b1cf03a9defc3.zip |
f32 colors; g_ prefix
Diffstat (limited to 'examples/particles.c')
-rw-r--r--[-rwxr-xr-x] | examples/particles.c | 66 |
1 files changed, 19 insertions, 47 deletions
diff --git a/examples/particles.c b/examples/particles.c index bf90123..37a77a5 100755..100644 --- a/examples/particles.c +++ b/examples/particles.c @@ -1,30 +1,3 @@ -#if 0 /* -#/ ================================================================ -#/ -#/ particles.c -#/ -#/ ================================================================ -#/ -#/ Self-compilation shell script -#/ -SRC=${0##*./} -BIN=${SRC%.*} -gcc \ - -Wall -Wextra -Werror -pedantic \ - -Wno-old-style-declaration \ - -Wno-missing-braces \ - -Wno-unused-variable \ - -Wno-unused-but-set-variable \ - -Wno-unused-parameter \ - -Wno-overlength-strings \ - -O3 \ - -fsanitize=undefined,address,leak \ - -lX11 -lm -lasound \ - -o $BIN $SRC && \ - ./$BIN $@ && rm $BIN -exit $? # */ -#endif - #include "../graphics.c" typedef struct { @@ -40,9 +13,9 @@ typedef struct { Entity entities[10 * 1024 * 1024]; } World; -World world = {0}; -u32 background; -i64 time_0; +World world = {0}; +vec3_f32 background = { .0f, .0f, .08f }; +i64 time_0; void update_and_render_frame(void) { p_handle_events(); @@ -50,21 +23,21 @@ void update_and_render_frame(void) { i64 time_elapsed = p_time() - time_0; time_0 += time_elapsed; - if (platform.key_pressed[BUTTON_LEFT]) { + if (g_platform.key_pressed[BUTTON_LEFT]) { i64 n = world.num_entities++; world.entities[n] = (Entity) { - .x = (f64) platform.cursor_x - (f64) platform.frame_width / 2, - .y = -((f64) platform.cursor_y - (f64) platform.frame_height / 2), + .x = (f64) g_platform.cursor_x - (f64) g_platform.frame_width / 2, + .y = -((f64) g_platform.cursor_y - (f64) g_platform.frame_height / 2), }; } if (time_elapsed > 0) { - if (platform.key_down[BUTTON_RIGHT]) { + if (g_platform.key_down[BUTTON_RIGHT]) { for (i64 n = 0; n < time_elapsed; ++n) world.entities[world.num_entities + n] = (Entity) { - .x = (f64) platform.cursor_x - (f64) platform.frame_width / 2, - .y = -((f64) platform.cursor_y - (f64) platform.frame_height / 2), + .x = (f64) g_platform.cursor_x - (f64) g_platform.frame_width / 2, + .y = -((f64) g_platform.cursor_y - (f64) g_platform.frame_height / 2), }; world.num_entities += time_elapsed; @@ -111,23 +84,23 @@ void update_and_render_frame(void) { world.time += time_elapsed; } - for (i32 j = 0; j < platform.frame_height; ++j) - for (i32 i = 0; i < platform.frame_width; ++i) - platform.pixels[j * platform.frame_width + i] = background; + for (i32 j = 0; j < g_platform.frame_height; ++j) + for (i32 i = 0; i < g_platform.frame_width; ++i) + g_platform.pixels[j * g_platform.frame_width + i] = background; for (i64 n = 0; n < world.num_entities; ++n) { Entity *e = &world.entities[n]; - i32 x = platform.frame_width / 2 + (i32) floor(e->x + .5); - i32 y = platform.frame_height / 2 - (i32) floor(e->y + .5); + i32 x = g_platform.frame_width / 2 + (i32) floor(e->x + .5); + i32 y = g_platform.frame_height / 2 - (i32) floor(e->y + .5); for (i32 j = y - 10; j <= y + 10; ++j) { - if (j < 0 || j >= platform.frame_height) continue; + if (j < 0 || j >= g_platform.frame_height) continue; for (i32 i = x - 10; i <= x + 10; ++i) { - if (i < 0 || i >= platform.frame_width) continue; + if (i < 0 || i >= g_platform.frame_width) continue; if ((i - x) * (i - x) + (j - y) * (j - y) > 100) continue; f64 v = (e->vx * e->vx + e->vy * e->vy) * 8.; - platform.pixels[j * platform.frame_width + i] = u32_from_rgb(-.2 + v * 2., .1 + v * .7, 1. - v); + g_platform.pixels[j * g_platform.frame_width + i] = (vec3_f32) { -.2 + v * 2., .1 + v * .7, 1. - v }; } } } @@ -139,14 +112,13 @@ i32 main(i32 argc, c8 **argv) { (void) argc; (void) argv; - platform = (Platform) { + g_platform = (Platform) { .title = "Gravity", .frame_width = 960, .frame_height = 720, }; - background = u32_from_rgb(.0f, .0f, .08f); - time_0 = p_time(); + time_0 = p_time(); srand(p_time()); |