Create local push_char lambda function
This commit is contained in:
parent
891818bef9
commit
4f44f69b40
|
@ -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* 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 font_size = this->prim_buffer.double_buffer[0][0]->size;
|
||||||
const auto row_count = 256/font_size.width;
|
const auto row_count = 256/font_size.width;
|
||||||
const auto old_x = state.pos.x;
|
const auto push_char = [&](State& state, FontPrimitive& primitive, char cur_char) -> bool {
|
||||||
|
if(&primitive >= primitive_end) {
|
||||||
while(this->cur_primitive < primitive_end && *str != '\0') {
|
return false;
|
||||||
const auto cur_char = *str++;
|
|
||||||
if(cur_char == '\n') {
|
|
||||||
state.pos.x = old_x;
|
|
||||||
state.pos.y += font_size.height;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cur_char == ' ') {
|
|
||||||
state.pos.x += font_size.width;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& primitive = *this->cur_primitive++;
|
|
||||||
|
|
||||||
primitive->position = state.pos;
|
primitive->position = state.pos;
|
||||||
if(wiggle) {
|
if(wiggle) {
|
||||||
const auto [off_x, off_y] = (*wiggle)[(state.wiggle_count++)&0x7];
|
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->tex_offset = GPU::PageOffset::from_tile_id(cur_char - '!', row_count, font_size);
|
||||||
primitive->color = color;
|
primitive->color = color;
|
||||||
primitive.concat(*this->cur_primitive);
|
primitive.concat(*this->cur_primitive);
|
||||||
|
|
||||||
state.pos.move(primitive->size.width, 0);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue