shithub: orca

Download patch

ref: 563847be9b3c3c7fc47b4ba5a998c6f7e26d92e0
parent: 74c414bcf0a4f33140e7ac22fbc65c32222b3dbb
author: cancel <cancel@cancel.fm>
date: Wed Nov 28 06:54:04 EST 2018

Add more oper setup for bank storage

--- a/bank.c
+++ b/bank.c
@@ -58,10 +58,9 @@
 }
 
 Usz bank_read(char const* bank_data, Usz bank_size,
-              Bank_cursor* restrict cursor, Usz index, Usz num_to_read,
-              Glyph* restrict dest, Usz dest_count) {
+              Bank_cursor* restrict cursor, Usz index, Glyph* restrict dest,
+              Usz dest_count) {
   assert(index <= ORCA_BANK_INDEX_MAX);
-  assert(num_to_read <= ORCA_BANK_ENTRY_GLYPHS_MAX);
   Usz offset = *cursor;
   Bank_entry* entry;
   Usz entry_index;
--- a/bank.h
+++ b/bank.h
@@ -25,5 +25,5 @@
 Usz bank_append(Bank* restrict bank, Usz cur_size, Usz index,
                 Glyph* restrict glyphs, Usz glyph_count);
 Usz bank_read(char const* bank_data, Usz bank_size,
-              Bank_cursor* restrict cursor, Usz index, Usz num_to_read,
-              Glyph* restrict dest, Usz dest_count);
+              Bank_cursor* restrict cursor, Usz index, Glyph* restrict dest,
+              Usz dest_count);
--- a/sim.c
+++ b/sim.c
@@ -42,6 +42,9 @@
   return indexed_glyphs[ib == 0 ? 0 : (ia % ib)];
 }
 
+// todo check if these inlines are actually being inlinded -- might be bad,
+// should probably mark them not inlined
+
 static inline bool oper_has_neighboring_bang(Gbuffer gbuf, Usz h, Usz w, Usz y,
                                              Usz x) {
   return gbuffer_peek_relative(gbuf, h, w, y, x, 0, 1) == '*' ||
@@ -71,7 +74,31 @@
   gbuf[y * width + x] = '.';
 }
 
-static inline Usz UCLAMP(Usz val, Usz min, Usz max) {
+typedef struct {
+  Bank* bank;
+  Usz size;
+  Bank_cursor read_cursor;
+} Oper_bank_params;
+
+// static may cause warning if programmer doesn't use bank storage
+void oper_bank_store(Oper_bank_params* bank_params, Usz width, Usz y, Usz x,
+                     Glyph* restrict glyphs, Usz num_glyphs) {
+  assert(num_glyphs > 0);
+  Usz index = y * width + x;
+  assert(index < ORCA_BANK_INDEX_MAX);
+  bank_params->size = bank_append(bank_params->bank, bank_params->size, index,
+                                  glyphs, num_glyphs);
+}
+Usz oper_bank_load(Oper_bank_params* bank_params, Usz width, Usz y, Usz x,
+                   Glyph* restrict out_glyphs, Usz out_count) {
+  Usz index = y * width + x;
+  assert(index < ORCA_BANK_INDEX_MAX);
+  return bank_read(bank_params->bank->data, bank_params->size,
+                   &bank_params->read_cursor, index, out_glyphs, out_count);
+}
+
+ORCA_FORCE_STATIC_INLINE
+Usz UCLAMP(Usz val, Usz min, Usz max) {
   if (val < min)
     return min;
   if (val > max)