summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xexamples/echo.c2
-rwxr-xr-xexamples/julia_set.c32
-rwxr-xr-xreduced_system_layer.c6
3 files changed, 28 insertions, 12 deletions
diff --git a/examples/echo.c b/examples/echo.c
index 671d609..7790c6a 100755
--- a/examples/echo.c
+++ b/examples/echo.c
@@ -57,7 +57,7 @@ i32 main(i32 argc, c8 **argv) {
switch (mode) {
case MODE_RECV: {
- printf("Recieving UDP messages on port %d\n\n", PORT);
+ printf("Receiving UDP messages on port %d\n\n", PORT);
for (;;) {
i64 n = p_recv(
diff --git a/examples/julia_set.c b/examples/julia_set.c
index 9d12bb8..747c339 100755
--- a/examples/julia_set.c
+++ b/examples/julia_set.c
@@ -45,13 +45,28 @@ i32 main(i32 argc, c8 **argv) {
f64 view_y = 0.;
f64 view_s = 1.;
- f64 cx = -.8;
- f64 cy = .1;
+ f64 cx = -.771;
+ f64 cy = .1005;
f64 radius = 2.;
i64 limit = 1024;
+ i64 time = p_time();
+
while (!platform.done) {
- p_wait_events();
+ i32 num_events = p_handle_events();
+
+ i64 time_elapsed = p_time() - time;
+ time += time_elapsed;
+
+ b8 left = platform.key_down[KEY_LEFT];
+ b8 right = platform.key_down[KEY_RIGHT];
+ b8 up = platform.key_down[KEY_UP];
+ b8 down = platform.key_down[KEY_DOWN];
+
+ if (!left && !right && !up && !down && num_events == 0) {
+ p_sleep_for(1);
+ continue;
+ }
if (platform.key_pressed['\n'])
p = (p == 1 ? 4 : 1);
@@ -62,13 +77,12 @@ i32 main(i32 argc, c8 **argv) {
view_s = 1.;
}
- f64 d = platform.key_down[MOD_CTRL] ? .0005 : .01;
-
- if (platform.key_pressed['q']) cx -= d;
- if (platform.key_pressed['w']) cx += d;
- if (platform.key_pressed['a']) cy -= d;
- if (platform.key_pressed['s']) cy += d;
+ f64 d = (platform.key_down[MOD_CTRL] ? .00005 : .001) * view_s * time_elapsed;
+ if (left) { cx -= d; cy -= d; }
+ if (right) { cx += d; cy += d; }
+ if (up) { cx += d; cy -= d; }
+ if (down) { cx -= d; cy += d; }
if (platform.key_down[BUTTON_LEFT]) {
view_x += platform.cursor_dx * view_s;
diff --git a/reduced_system_layer.c b/reduced_system_layer.c
index ffcec97..9318098 100755
--- a/reduced_system_layer.c
+++ b/reduced_system_layer.c
@@ -29,10 +29,10 @@
#/ To-Do list
#/
#/ - Examples
-#/ - Landscape
#/ - Conway's Game if Life
#/ - Julia Set
#/ - Labyrinth
+#/ - Landscape
#/ - Features
#/ - Sound
#/ - Clipboard daemon
@@ -226,7 +226,7 @@ void p_queue_sound(i64 delay, i64 num_samples, f32 *samples);
i64 p_recv(u16 slot, IP_Address address, i64 size, u8 *data, u16 *local_port, IP_Address *remote_address);
i64 p_send(u16 slot, IP_Address address, i64 size, u8 *data, u16 *local_port);
-Platform platform = {0};
+extern Platform platform;
// ================================================================
@@ -274,6 +274,8 @@ i32 main(i32 argc, c8 **argv) {
#ifndef REDUCED_SYSTEM_LAYER_IMPLEMENTATION_GUARD_
#define REDUCED_SYSTEM_LAYER_IMPLEMENTATION_GUARD_
+Platform platform = {0};
+
// ================================================================
//
// Utilities