New wiggle approach

This commit is contained in:
2023-12-01 22:24:00 -05:00
parent 6324234cf9
commit b5e3ccde5a
6 changed files with 60 additions and 19 deletions

View File

@@ -11,6 +11,15 @@ namespace JabyEngine {
GPU::SizeU16 font_size;
};
struct State {
GPU::PositionI16 pos;
uint8_t wiggle_count;
static constexpr State create(GPU::PositionI16 pos, uint8_t wiggle_count = 0) {
return State{.pos = pos, .wiggle_count = wiggle_count};
}
};
struct FontBufferInfo {
FontPrimitive* double_buffer[2];
size_t single_buffer_length;
@@ -24,4 +33,15 @@ namespace JabyEngine {
return FontBufferInfo{.double_buffer = {buffer[0], buffer[1]}, .single_buffer_length = N};
}
};
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

@@ -24,7 +24,7 @@ namespace JabyEngine {
FontWriter::setup(buffer_info, vram_dst, Make::SizeI16(font_info.font_size.width, font_info.font_size.height));
}
GPU::PositionI16 write(GPU::PositionI16 pos, const char* str, GPU::Color24 color = GPU::Color24::Grey(), uint8_t wiggle_count = 0);
void render();
void write(State& state, const char* str, GPU::Color24 color = GPU::Color24::Grey(), Wiggle* wiggle = nullptr);
void render();
};
}

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() {