shithub: orca

Download patch

ref: a89b2ace5180ff58e71886c77539cbb39f296a37
parent: b87bcd287c6a5eae12cc57ffe556ec52871491b6
author: cancel <cancel@cancel.fm>
date: Thu Jan 2 12:35:27 EST 2020

Change orca_run() to not clear input buffers

Callers are now in charge of clearing/cleanup

--- a/cli_main.c
+++ b/cli_main.c
@@ -1,6 +1,7 @@
 #include "bank.h"
 #include "base.h"
 #include "field.h"
+#include "gbuffer.h"
 #include "sim.h"
 #include <getopt.h>
 
@@ -102,6 +103,8 @@
   oevent_list_init(&oevent_list);
   Usz max_ticks = (Usz)ticks;
   for (Usz i = 0; i < max_ticks; ++i) {
+    mbuffer_clear(mbuf_r.buffer, field.height, field.width);
+    oevent_list_clear(&oevent_list);
     orca_run(field.buffer, mbuf_r.buffer, field.height, field.width, i,
              &oevent_list, 0);
   }
--- a/sim.c
+++ b/sim.c
@@ -741,8 +741,6 @@
               Usz tick_number, Oevent_list* oevent_list, Usz random_seed) {
   Glyph vars_slots[Glyphs_index_count];
   memset(vars_slots, '.', sizeof(vars_slots));
-  mbuffer_clear(mbuf, height, width);
-  oevent_list_clear(oevent_list);
   Oper_extra_params extras;
   extras.vars_slots = &vars_slots[0];
   extras.oevent_list = oevent_list;
--- a/tui_main.c
+++ b/tui_main.c
@@ -1097,6 +1097,14 @@
 
 void ged_reset_clock(Ged* a) { a->clock = stm_now(); }
 
+void clear_and_run_vm(Glyph* restrict gbuf, Mark* restrict mbuf, Usz height,
+                      Usz width, Usz tick_number, Oevent_list* oevent_list,
+                      Usz random_seed) {
+  mbuffer_clear(mbuf, height, width);
+  oevent_list_clear(oevent_list);
+  orca_run(gbuf, mbuf, height, width, tick_number, oevent_list, random_seed);
+}
+
 void ged_do_stuff(Ged* a) {
   double secs_span = 60.0 / (double)a->bpm / 4.0;
   Oosc_dev* oosc_dev = a->oosc_dev;
@@ -1143,8 +1151,9 @@
   if (do_play) {
     apply_time_to_sustained_notes(oosc_dev, midi_mode, secs_span,
                                   &a->susnote_list, &a->time_to_next_note_off);
-    orca_run(a->field.buffer, a->mbuf_r.buffer, a->field.height, a->field.width,
-             a->tick_num, &a->oevent_list, a->random_seed);
+    clear_and_run_vm(a->field.buffer, a->mbuf_r.buffer, a->field.height,
+                     a->field.width, a->tick_num, &a->oevent_list,
+                     a->random_seed);
     ++a->tick_num;
     a->needs_remarking = true;
     a->is_draw_dirty = true;
@@ -1234,9 +1243,9 @@
                                   a->field.width);
     field_copy(&a->field, &a->scratch_field);
     mbuf_reusable_ensure_size(&a->mbuf_r, a->field.height, a->field.width);
-    orca_run(a->scratch_field.buffer, a->mbuf_r.buffer, a->field.height,
-             a->field.width, a->tick_num, &a->scratch_oevent_list,
-             a->random_seed);
+    clear_and_run_vm(a->scratch_field.buffer, a->mbuf_r.buffer, a->field.height,
+                     a->field.width, a->tick_num, &a->scratch_oevent_list,
+                     a->random_seed);
     a->needs_remarking = false;
   }
   int win_h = a->win_h;
@@ -1641,8 +1650,9 @@
     break;
   case Ged_input_cmd_step_forward:
     undo_history_push(&a->undo_hist, &a->field, a->tick_num);
-    orca_run(a->field.buffer, a->mbuf_r.buffer, a->field.height, a->field.width,
-             a->tick_num, &a->oevent_list, a->random_seed);
+    clear_and_run_vm(a->field.buffer, a->mbuf_r.buffer, a->field.height,
+                     a->field.width, a->tick_num, &a->oevent_list,
+                     a->random_seed);
     ++a->tick_num;
     a->activity_counter += a->oevent_list.count;
     a->needs_remarking = true;