Create local push_char lambda function

This commit is contained in:
Jaby 2023-12-04 21:09:16 -05:00
parent eefe7b9050
commit c548edc14d
1 changed files with 29 additions and 17 deletions

View File

@ -23,23 +23,11 @@ namespace JabyEngine {
const auto* primitive_end = &this->prim_buffer.double_buffer[GPU::Display::current_id][this->prim_buffer.single_buffer_length];
const auto font_size = this->prim_buffer.double_buffer[0][0]->size;
const auto row_count = 256/font_size.width;
const auto old_x = state.pos.x;
while(this->cur_primitive < primitive_end && *str != '\0') {
const auto cur_char = *str++;
if(cur_char == '\n') {
state.pos.x = old_x;
state.pos.y += font_size.height;
continue;
const auto push_char = [&](State& state, FontPrimitive& primitive, char cur_char) -> bool {
if(&primitive >= primitive_end) {
return false;
}
if(cur_char == ' ') {
state.pos.x += font_size.width;
continue;
}
auto& primitive = *this->cur_primitive++;
primitive->position = state.pos;
if(wiggle) {
const auto [off_x, off_y] = (*wiggle)[(state.wiggle_count++)&0x7];
@ -48,8 +36,32 @@ namespace JabyEngine {
primitive->tex_offset = GPU::PageOffset::from_tile_id(cur_char - '!', row_count, font_size);
primitive->color = color;
primitive.concat(*this->cur_primitive);
state.pos.move(primitive->size.width, 0);
return true;
};
const auto old_x = state.pos.x;
while(true) {
const auto cur_char = *str++;
switch(cur_char) {
case '\0':
return;
case '\n':
state.pos.x = old_x;
state.pos.y += font_size.height;
continue;
case ' ':
state.pos.x += font_size.width;
continue;
default:
auto& primitive = *this->cur_primitive++;
if(!push_char(state, primitive, cur_char)) {
return;
}
}
}
}