Browse Source

Rename Markmap_buffer to Mbuffer

master
cancel 6 years ago
parent
commit
f5dd21b4bb
  1. 2
      mark.c
  2. 20
      mark.h
  3. 36
      sim.c
  4. 2
      sim.h

2
mark.c

@ -16,7 +16,7 @@ void markmap_reusable_ensure_size(Markmap_reusable* map, Usz height,
void markmap_reusable_deinit(Markmap_reusable* map) { free(map->buffer); } void markmap_reusable_deinit(Markmap_reusable* map) { free(map->buffer); }
void markmap_clear(Markmap_buffer map, Usz height, Usz width) { void mbuffer_clear(Mbuffer map, Usz height, Usz width) {
Usz cleared_size = height * width; Usz cleared_size = height * width;
memset(map, 0, cleared_size); memset(map, 0, cleared_size);
} }

20
mark.h

@ -10,10 +10,10 @@ typedef enum {
Mark_flag_sleep = 1 << 4, Mark_flag_sleep = 1 << 4,
} Mark_flags; } Mark_flags;
typedef U8* Markmap_buffer; typedef U8* Mbuffer;
typedef struct Markmap_reusable { typedef struct Markmap_reusable {
Markmap_buffer buffer; Mbuffer buffer;
Usz capacity; Usz capacity;
} Markmap_reusable; } Markmap_reusable;
@ -21,21 +21,21 @@ void markmap_reusable_init(Markmap_reusable* map);
void markmap_reusable_ensure_size(Markmap_reusable* map, Usz height, Usz width); void markmap_reusable_ensure_size(Markmap_reusable* map, Usz height, Usz width);
void markmap_reusable_deinit(Markmap_reusable* map); void markmap_reusable_deinit(Markmap_reusable* map);
void markmap_clear(Markmap_buffer map, Usz height, Usz width); void mbuffer_clear(Mbuffer map, Usz height, Usz width);
ORCA_FORCE_INLINE ORCA_FORCE_INLINE
Mark_flags markmap_peek_relative(Markmap_buffer map, Usz map_height, Mark_flags mbuffer_peek_relative(Mbuffer map, Usz map_height,
Usz map_width, Usz y, Usz x, Isz offs_y, Usz map_width, Usz y, Usz x, Isz offs_y,
Isz offs_x); Isz offs_x);
ORCA_FORCE_INLINE ORCA_FORCE_INLINE
void markmap_poke_relative(Markmap_buffer map, Usz map_height, Usz map_width, void mbuffer_poke_relative(Mbuffer map, Usz map_height, Usz map_width,
Usz y, Usz x, Isz offs_y, Isz offs_x, Usz y, Usz x, Isz offs_y, Isz offs_x,
Mark_flags flags); Mark_flags flags);
// Inline implementation // Inline implementation
ORCA_FORCE_INLINE ORCA_FORCE_INLINE
Mark_flags markmap_peek_relative(Markmap_buffer map, Usz map_height, Mark_flags mbuffer_peek_relative(Mbuffer map, Usz map_height,
Usz map_width, Usz y, Usz x, Isz offs_y, Usz map_width, Usz y, Usz x, Isz offs_y,
Isz offs_x) { Isz offs_x) {
Isz y0 = (Isz)y + offs_y; Isz y0 = (Isz)y + offs_y;
@ -46,7 +46,7 @@ Mark_flags markmap_peek_relative(Markmap_buffer map, Usz map_height,
} }
ORCA_FORCE_INLINE ORCA_FORCE_INLINE
void markmap_poke_relative(Markmap_buffer map, Usz map_height, Usz map_width, void mbuffer_poke_relative(Mbuffer map, Usz map_height, Usz map_width,
Usz y, Usz x, Isz offs_y, Isz offs_x, Usz y, Usz x, Isz offs_y, Isz offs_x,
Mark_flags flags) { Mark_flags flags) {
Isz y0 = (Isz)y + offs_y; Isz y0 = (Isz)y + offs_y;
@ -57,7 +57,7 @@ void markmap_poke_relative(Markmap_buffer map, Usz map_height, Usz map_width,
} }
ORCA_FORCE_INLINE ORCA_FORCE_INLINE
void markmap_poke_relative_flags_or(Markmap_buffer map, Usz map_height, void mbuffer_poke_relative_flags_or(Mbuffer map, Usz map_height,
Usz map_width, Usz y, Usz x, Isz offs_y, Usz map_width, Usz y, Usz x, Isz offs_y,
Isz offs_x, Mark_flags flags) { Isz offs_x, Mark_flags flags) {
Isz y0 = (Isz)y + offs_y; Isz y0 = (Isz)y + offs_y;
@ -68,14 +68,14 @@ void markmap_poke_relative_flags_or(Markmap_buffer map, Usz map_height,
} }
ORCA_FORCE_INLINE ORCA_FORCE_INLINE
void markmap_poke_flags_or(Markmap_buffer map, Usz map_height, Usz map_width, void mbuffer_poke_flags_or(Mbuffer map, Usz map_height, Usz map_width,
Usz y, Usz x, Mark_flags flags) { Usz y, Usz x, Mark_flags flags) {
(void)map_height; (void)map_height;
map[y * map_width + x] |= (U8)flags; map[y * map_width + x] |= (U8)flags;
} }
ORCA_FORCE_INLINE ORCA_FORCE_INLINE
Mark_flags markmap_peek(Markmap_buffer map, Usz map_height, Usz map_width, Mark_flags mbuffer_peek(Mbuffer map, Usz map_height, Usz map_width,
Usz y, Usz x) { Usz y, Usz x) {
(void)map_height; (void)map_height;
return map[y * map_width + x]; return map[y * map_width + x];

36
sim.c

@ -48,8 +48,7 @@ static inline bool oper_has_neighboring_bang(Gbuffer gbuf, Usz h, Usz w, Usz y,
gbuffer_peek_relative(gbuf, h, w, y, x, -1, 0) == '*'; gbuffer_peek_relative(gbuf, h, w, y, x, -1, 0) == '*';
} }
static inline void oper_move_relative_or_explode(Gbuffer gbuf, static inline void oper_move_relative_or_explode(Gbuffer gbuf, Mbuffer mbuf,
Markmap_buffer markmap,
Usz height, Usz width, Usz height, Usz width,
Glyph moved, Usz y, Usz x, Glyph moved, Usz y, Usz x,
Isz delta_y, Isz delta_x) { Isz delta_y, Isz delta_x) {
@ -62,19 +61,17 @@ static inline void oper_move_relative_or_explode(Gbuffer gbuf,
Glyph* at_dest = gbuf + (Usz)y0 * width + (Usz)x0; Glyph* at_dest = gbuf + (Usz)y0 * width + (Usz)x0;
if (*at_dest != '.') { if (*at_dest != '.') {
gbuf[y * width + x] = '*'; gbuf[y * width + x] = '*';
markmap_poke_flags_or(markmap, height, width, y, x, Mark_flag_sleep); mbuffer_poke_flags_or(mbuf, height, width, y, x, Mark_flag_sleep);
return; return;
} }
*at_dest = moved; *at_dest = moved;
markmap_poke_flags_or(markmap, height, width, (Usz)y0, (Usz)x0, mbuffer_poke_flags_or(mbuf, height, width, (Usz)y0, (Usz)x0, Mark_flag_sleep);
Mark_flag_sleep);
gbuf[y * width + x] = '.'; gbuf[y * width + x] = '.';
} }
static inline void oper_lock_relative(Markmap_buffer markmap, Usz height, static inline void oper_lock_relative(Mbuffer mbuf, Usz height, Usz width,
Usz width, Usz y, Usz x, Isz delta_y, Usz y, Usz x, Isz delta_y, Isz delta_x) {
Isz delta_x) { mbuffer_poke_relative_flags_or(mbuf, height, width, y, x, delta_y, delta_x,
markmap_poke_relative_flags_or(markmap, height, width, y, x, delta_y, delta_x,
Mark_flag_lock); Mark_flag_lock);
} }
@ -86,10 +83,9 @@ static inline void oper_lock_relative(Markmap_buffer markmap, Usz height,
#define OPER_PHASE_N(_phase_number, _oper_name) \ #define OPER_PHASE_N(_phase_number, _oper_name) \
static inline void oper_phase##_phase_number##_##_oper_name( \ static inline void oper_phase##_phase_number##_##_oper_name( \
Gbuffer gbuffer, Markmap_buffer markmap, Usz height, Usz width, Usz y, \ Gbuffer gbuffer, Mbuffer mbuffer, Usz height, Usz width, Usz y, Usz x) { \
Usz x) { \
(void)gbuffer; \ (void)gbuffer; \
(void)markmap; \ (void)mbuffer; \
(void)height; \ (void)height; \
(void)width; \ (void)width; \
(void)y; \ (void)y; \
@ -115,10 +111,10 @@ static inline void oper_lock_relative(Markmap_buffer markmap, Usz height,
return return
#define OPER_LOCK_RELATIVE(_delta_y, _delta_x) \ #define OPER_LOCK_RELATIVE(_delta_y, _delta_x) \
oper_lock_relative(markmap, height, width, y, x, _delta_y, _delta_x) oper_lock_relative(mbuffer, height, width, y, x, _delta_y, _delta_x)
#define OPER_MOVE_OR_EXPLODE(_delta_y, _delta_x) \ #define OPER_MOVE_OR_EXPLODE(_delta_y, _delta_x) \
oper_move_relative_or_explode(gbuffer, markmap, height, width, \ oper_move_relative_or_explode(gbuffer, mbuffer, height, width, \
This_oper_char, y, x, _delta_y, _delta_x) This_oper_char, y, x, _delta_y, _delta_x)
#define OPER_DEFINE_UPPERCASE_DIRECTIONAL(_oper_name, _delta_y, _delta_x) \ #define OPER_DEFINE_UPPERCASE_DIRECTIONAL(_oper_name, _delta_y, _delta_x) \
@ -210,19 +206,19 @@ OPER_END
OPER_PHASE_2(bang) OPER_PHASE_2(bang)
OPER_END OPER_END
void orca_run(Gbuffer gbuf, Markmap_buffer markmap, Usz height, Usz width) { void orca_run(Gbuffer gbuf, Mbuffer mbuf, Usz height, Usz width) {
markmap_clear(markmap, height, width); mbuffer_clear(mbuf, height, width);
// Phase 0 // Phase 0
for (Usz iy = 0; iy < height; ++iy) { for (Usz iy = 0; iy < height; ++iy) {
Glyph* glyph_row = gbuf + iy * width; Glyph* glyph_row = gbuf + iy * width;
for (Usz ix = 0; ix < width; ++ix) { for (Usz ix = 0; ix < width; ++ix) {
Glyph c = glyph_row[ix]; Glyph c = glyph_row[ix];
if (markmap_peek(markmap, height, width, iy, ix) & Mark_flag_sleep) if (mbuffer_peek(mbuf, height, width, iy, ix) & Mark_flag_sleep)
continue; continue;
switch (c) { switch (c) {
#define X(_oper_name, _oper_char) \ #define X(_oper_name, _oper_char) \
case _oper_char: \ case _oper_char: \
oper_phase0_##_oper_name(gbuf, markmap, height, width, iy, ix); \ oper_phase0_##_oper_name(gbuf, mbuf, height, width, iy, ix); \
break; break;
ORCA_OPERATORS(X) ORCA_OPERATORS(X)
#undef X #undef X
@ -233,13 +229,13 @@ void orca_run(Gbuffer gbuf, Markmap_buffer markmap, Usz height, Usz width) {
for (Usz iy = 0; iy < height; ++iy) { for (Usz iy = 0; iy < height; ++iy) {
Glyph* glyph_row = gbuf + iy * width; Glyph* glyph_row = gbuf + iy * width;
for (Usz ix = 0; ix < width; ++ix) { for (Usz ix = 0; ix < width; ++ix) {
if (markmap_peek(markmap, height, width, iy, ix) & Mark_flag_sleep) if (mbuffer_peek(mbuf, height, width, iy, ix) & Mark_flag_sleep)
continue; continue;
Glyph c = glyph_row[ix]; Glyph c = glyph_row[ix];
switch (c) { switch (c) {
#define X(_oper_name, _oper_char) \ #define X(_oper_name, _oper_char) \
case _oper_char: \ case _oper_char: \
oper_phase1_##_oper_name(gbuf, markmap, height, width, iy, ix); \ oper_phase1_##_oper_name(gbuf, mbuf, height, width, iy, ix); \
break; break;
ORCA_OPERATORS(X) ORCA_OPERATORS(X)
#undef X #undef X

2
sim.h

@ -2,4 +2,4 @@
#include "base.h" #include "base.h"
#include "mark.h" #include "mark.h"
void orca_run(Gbuffer gbuf, Markmap_buffer markmap, Usz height, Usz width); void orca_run(Gbuffer gbuf, Mbuffer markmap, Usz height, Usz width);

Loading…
Cancel
Save