Rename 'State' to 'Cursor'

This commit is contained in:
Jaby 2024-01-05 12:33:14 -06:00
parent f69e60b2de
commit 5d370d40e1
3 changed files with 18 additions and 27 deletions

View File

@ -32,23 +32,14 @@ namespace JabyEngine {
} }
}; };
struct State { struct Cursor {
GPU::PositionI16 pos; GPU::PositionI16 pos;
uint8_t wiggle_count; uint8_t wiggle_count;
static constexpr State create(GPU::PositionI16 pos, uint8_t wiggle_count = 0) { static constexpr Cursor create(GPU::PositionI16 pos, uint8_t wiggle_count = 0) {
return State{.pos = pos, .wiggle_count = wiggle_count}; return Cursor{.pos = pos, .wiggle_count = wiggle_count};
} }
}; };
using Wiggle = GPU::PositionI8[8]; using Wiggle = GPU::PositionI8[8];
/*struct Wiggle {
GPU::PositionI8 offset[8];
uint8_t count;
GPU::PositionI8 next() {
return this->offset[(this->count++)&0x7];
}
};*/
} }

View File

@ -8,7 +8,7 @@ namespace JabyEngine {
#define __write_impl(start, color, wiggle) \ #define __write_impl(start, color, wiggle) \
va_list list; \ va_list list; \
va_start(list, start); \ va_start(list, start); \
FontWriter::write(state, str, color, wiggle, list); \ FontWriter::write(cursor, str, color, wiggle, list); \
va_end(list) va_end(list)
GPU::TexPage::Linked tex_page[2]; GPU::TexPage::Linked tex_page[2];
@ -36,16 +36,16 @@ namespace JabyEngine {
void clear(); void clear();
void write(State& state, const char* str, ...) { void write(Cursor& cursor, const char* str, ...) {
__write_impl(str, GPU::Color24::Grey(), nullptr); __write_impl(str, GPU::Color24::Grey(), nullptr);
} }
void write(State& state, const char* str, GPU::Color24 color, ...) { void write(Cursor& cursor, const char* str, GPU::Color24 color, ...) {
__write_impl(color, color, nullptr); __write_impl(color, color, nullptr);
} }
void write(State& state, const char* str, GPU::Color24 color, const Wiggle* wiggle, ...) { void write(Cursor& cursor, const char* str, GPU::Color24 color, const Wiggle* wiggle, ...) {
__write_impl(wiggle, color, wiggle); __write_impl(wiggle, color, wiggle);
} }
void write(State& state, const char* str, GPU::Color24 color, const Wiggle* wiggle, va_list list); void write(Cursor& cursor, const char* str, GPU::Color24 color, const Wiggle* wiggle, va_list list);
void render(); void render();
#undef __write_impl #undef __write_impl

View File

@ -67,7 +67,7 @@ namespace JabyEngine {
this->last_primitive = &this->tex_page[GPU::update_id()]; this->last_primitive = &this->tex_page[GPU::update_id()];
} }
void FontWriter :: write(State& state, const char* str, GPU::Color24 color, const Wiggle* wiggle, va_list list) { void FontWriter :: write(Cursor& cursor, const char* str, GPU::Color24 color, const Wiggle* wiggle, va_list list) {
static const auto exchang_str = [](const char* str, const char* new_str) -> pair<const char*, const char*> { static const auto exchang_str = [](const char* str, const char* new_str) -> pair<const char*, const char*> {
return {str + 1, new_str}; return {str + 1, new_str};
}; };
@ -78,13 +78,13 @@ namespace JabyEngine {
const auto sprt_size = GPU::SizeI16::from(this->render_info.font_size); const auto sprt_size = GPU::SizeI16::from(this->render_info.font_size);
const auto row_count = 256/sprt_size.width; const auto row_count = 256/sprt_size.width;
const auto push_char = [&](State& state, char cur_char) -> bool { const auto push_char = [&](Cursor& cursor, char cur_char) -> bool {
auto& primitive = GlobalPrimitiveFactory.new_primitive(); auto& primitive = GlobalPrimitiveFactory.new_primitive();
primitive->position = state.pos; primitive->position = cursor.pos;
primitive->size = sprt_size; primitive->size = sprt_size;
if(wiggle) { if(wiggle) {
const auto [off_x, off_y] = (*wiggle)[(state.wiggle_count++)&0x7]; const auto [off_x, off_y] = (*wiggle)[(cursor.wiggle_count++)&0x7];
primitive->position.move(off_x, off_y); primitive->position.move(off_x, off_y);
} }
primitive->tex_offset = GPU::PageOffset::from_tile_id(cur_char - '!', row_count, sprt_size); primitive->tex_offset = GPU::PageOffset::from_tile_id(cur_char - '!', row_count, sprt_size);
@ -93,10 +93,10 @@ namespace JabyEngine {
this->last_primitive->concat(primitive); this->last_primitive->concat(primitive);
this->last_primitive = &primitive; this->last_primitive = &primitive;
state.pos.move(this->render_info.kern_size.width, 0); cursor.pos.move(this->render_info.kern_size.width, 0);
return true; return true;
}; };
const auto old_x = state.pos.x; const auto old_x = cursor.pos.x;
const char* prev_str = nullptr; const char* prev_str = nullptr;
char buffer[32]; char buffer[32];
@ -112,12 +112,12 @@ namespace JabyEngine {
return; return;
case '\n': case '\n':
state.pos.x = old_x; cursor.pos.x = old_x;
state.pos.y += this->render_info.kern_size.height; cursor.pos.y += this->render_info.kern_size.height;
continue; continue;
case ' ': case ' ':
state.pos.x += this->render_info.kern_size.width; cursor.pos.x += this->render_info.kern_size.width;
continue; continue;
case '%': case '%':
@ -140,7 +140,7 @@ namespace JabyEngine {
} }
default: default:
if(!push_char(state, cur_char)) { if(!push_char(cursor, cur_char)) {
return; return;
} }
} }