aboutsummaryrefslogtreecommitdiffstats
path: root/03-wolfrand
diff options
context:
space:
mode:
authorkatherine <ageha@airen-no-jikken.icu>2021-02-11 17:18:37 -0700
committerkatherine <ageha@airen-no-jikken.icu>2021-02-11 17:18:37 -0700
commit3f073ddee13b08941467c98f4c46698eee7a1f43 (patch)
tree481e50e943bc73b5a48307739ce1f3fdb96a02b1 /03-wolfrand
parent519801b33a17a26c07e5f15cca7cb2f307b1388a (diff)
downloadallegro-sketches-3f073ddee13b08941467c98f4c46698eee7a1f43.tar.gz
optimise
Diffstat (limited to '03-wolfrand')
-rw-r--r--03-wolfrand/screenshot.gifbin128974 -> 101948 bytes
-rw-r--r--03-wolfrand/src/main.c34
2 files changed, 21 insertions, 13 deletions
diff --git a/03-wolfrand/screenshot.gif b/03-wolfrand/screenshot.gif
index fd8ad07..f92007e 100644
--- a/03-wolfrand/screenshot.gif
+++ b/03-wolfrand/screenshot.gif
Binary files differ
diff --git a/03-wolfrand/src/main.c b/03-wolfrand/src/main.c
index 4d4fa34..5d90690 100644
--- a/03-wolfrand/src/main.c
+++ b/03-wolfrand/src/main.c
@@ -11,7 +11,7 @@
#define DISP_WIDTH 640
#define DISP_HEIGHT 480
-#define FPS 3.3
+#define FPS 15.0
#define DO_INIT(check, desc) \
if (!(check)) { \
@@ -46,9 +46,10 @@ int main(int argc, char **argv)
bool pause = 0;
- ALLEGRO_DISPLAY* d = NULL;
- ALLEGRO_TIMER* t = NULL;
- ALLEGRO_EVENT_QUEUE* eq = NULL;
+ ALLEGRO_DISPLAY *d = NULL;
+ ALLEGRO_BITMAP *b = NULL;
+ ALLEGRO_TIMER *t = NULL;
+ ALLEGRO_EVENT_QUEUE *eq = NULL;
ALLEGRO_EVENT e;
@@ -63,6 +64,8 @@ int main(int argc, char **argv)
al_set_new_display_option(ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_REQUIRE);
DO_INIT(d = al_create_display(DISP_WIDTH, DISP_HEIGHT), "display");
+ al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
+ DO_INIT(b = al_create_bitmap(DISP_WIDTH, DISP_HEIGHT), "buffer");
al_register_event_source(eq, al_get_keyboard_event_source());
al_register_event_source(eq, al_get_display_event_source(d));
@@ -126,7 +129,7 @@ int main(int argc, char **argv)
memset(bits[1], 0, (DISP_HEIGHT - 1) * DISP_WIDTH / 8);
for (x = 1; x < DISP_WIDTH - 1; x++) {
- if (randombytes_random() < 0x20000000)
+ if (randombytes_random() < 0x10000000)
bit_toggle(bits[0], x);
}
@@ -148,20 +151,23 @@ int main(int argc, char **argv)
/* draw frame */
- al_clear_to_color(al_map_rgb(0, 0, 0));
+ al_lock_bitmap(b, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY);
+
+ al_set_target_bitmap(b);
for (y = 0; y < DISP_HEIGHT; y++) {
for (x = 0; x < DISP_WIDTH; x++) {
- if (bit_get(bits[y], x)) {
- al_draw_filled_rectangle(
- (float)x, (float)y,
- (float)(x + 1), (float)(y + 1),
- al_map_rgb(255, 255, 255)
- );
- }
+ if (bit_get(bits[y], x))
+ al_put_pixel(x, y, al_map_rgb(255, 255, 255));
+ else
+ al_put_pixel(x, y, al_map_rgb(0, 0, 0));
}
}
+ al_unlock_bitmap(b);
+
+ al_set_target_backbuffer(d);
+ al_draw_bitmap(b, 0, 0, 0);
al_flip_display();
}
}
@@ -171,6 +177,8 @@ done:
if (d)
al_destroy_display(d);
+ if (b)
+ al_destroy_bitmap(b);
if (t)
al_destroy_timer(t);
if (eq)