New wiggle approach

This commit is contained in:
Jaby
2023-12-01 22:24:00 -05:00
parent 3e897b67cc
commit 5d5b1ae6de
6 changed files with 60 additions and 19 deletions

View File

@@ -4,8 +4,6 @@
#include <stdio.h>
namespace JabyEngine {
static constexpr int8_t WiggleValues[] = {0, 3, 5, 1, -2, -5, -4, 1};//{0, 2, 6, 2, 0, -2, -6, -2};
void FontWriter :: setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const GPU::SizeI16& font_size) {
this->prim_buffer = buffer_info;
this->tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked();
@@ -21,37 +19,38 @@ namespace JabyEngine {
}
}
GPU::PositionI16 FontWriter :: write(GPU::PositionI16 pos, const char* str, GPU::Color24 color, uint8_t wiggle_count) {
void FontWriter :: write(State& state, const char* str, GPU::Color24 color, Wiggle* wiggle) {
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 = pos.x;
const auto old_x = state.pos.x;
while(this->cur_primitive < primitive_end && *str != '\0') {
const auto cur_char = *str++;
if(cur_char == '\n') {
pos.x = old_x;
pos.y += font_size.height;
state.pos.x = old_x;
state.pos.y += font_size.height;
continue;
}
if(cur_char == ' ') {
pos.x += font_size.width;
state.pos.x += font_size.width;
continue;
}
auto& primitive = *this->cur_primitive++;
primitive->position = pos;
primitive->position.move(0, -WiggleValues[wiggle_count&0b111]);
primitive->position = state.pos;
if(wiggle) {
const auto [off_x, off_y] = (*wiggle)[(state.wiggle_count++)&0x7];
primitive->position.move(off_x, off_y);
}
primitive->tex_offset = GPU::PageOffset::from_tile_id(cur_char - '!', row_count, font_size);
primitive->color = color;
primitive.concat(*this->cur_primitive);
pos.move(primitive->size.width, 0);
wiggle_count++;
state.pos.move(primitive->size.width, 0);
}
return pos;
}
void FontWriter :: render() {