From 563847be9b3c3c7fc47b4ba5a998c6f7e26d92e0 Mon Sep 17 00:00:00 2001 From: cancel Date: Wed, 28 Nov 2018 11:54:04 +0900 Subject: [PATCH] Add more oper setup for bank storage --- bank.c | 5 ++--- bank.h | 4 ++-- sim.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/bank.c b/bank.c index c7dabef..8754d70 100644 --- a/bank.c +++ b/bank.c @@ -58,10 +58,9 @@ Usz bank_append(Bank* restrict bank, Usz cur_size, Usz index, } 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; diff --git a/bank.h b/bank.h index e723ebc..e4a37c2 100644 --- a/bank.h +++ b/bank.h @@ -25,5 +25,5 @@ static inline void bank_cursor_reset(Bank_cursor* cursor) { *cursor = 0; } 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); diff --git a/sim.c b/sim.c index 3561e0b..75d1499 100644 --- a/sim.c +++ b/sim.c @@ -42,6 +42,9 @@ static inline Glyph glyphs_mod(Glyph a, Glyph b) { 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 @@ static inline void oper_move_relative_or_explode(Gbuffer gbuf, Mbuffer mbuf, 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)