Browse Source

Add more oper setup for bank storage

master
cancel 6 years ago
parent
commit
563847be9b
  1. 5
      bank.c
  2. 4
      bank.h
  3. 29
      sim.c

5
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, Usz bank_read(char const* bank_data, Usz bank_size,
Bank_cursor* restrict cursor, Usz index, Usz num_to_read, Bank_cursor* restrict cursor, Usz index, Glyph* restrict dest,
Glyph* restrict dest, Usz dest_count) { Usz dest_count) {
assert(index <= ORCA_BANK_INDEX_MAX); assert(index <= ORCA_BANK_INDEX_MAX);
assert(num_to_read <= ORCA_BANK_ENTRY_GLYPHS_MAX);
Usz offset = *cursor; Usz offset = *cursor;
Bank_entry* entry; Bank_entry* entry;
Usz entry_index; Usz entry_index;

4
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, Usz bank_append(Bank* restrict bank, Usz cur_size, Usz index,
Glyph* restrict glyphs, Usz glyph_count); Glyph* restrict glyphs, Usz glyph_count);
Usz bank_read(char const* bank_data, Usz bank_size, Usz bank_read(char const* bank_data, Usz bank_size,
Bank_cursor* restrict cursor, Usz index, Usz num_to_read, Bank_cursor* restrict cursor, Usz index, Glyph* restrict dest,
Glyph* restrict dest, Usz dest_count); Usz dest_count);

29
sim.c

@ -42,6 +42,9 @@ static inline Glyph glyphs_mod(Glyph a, Glyph b) {
return indexed_glyphs[ib == 0 ? 0 : (ia % ib)]; 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, static inline bool oper_has_neighboring_bang(Gbuffer gbuf, Usz h, Usz w, Usz y,
Usz x) { Usz x) {
return gbuffer_peek_relative(gbuf, h, w, y, x, 0, 1) == '*' || 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] = '.'; 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) if (val < min)
return min; return min;
if (val > max) if (val > max)

Loading…
Cancel
Save