New wiggle approach
This commit is contained in:
parent
3e897b67cc
commit
5d5b1ae6de
|
@ -15,10 +15,11 @@ using NewFontWriter = ::JabyEngine::FontWriter;
|
|||
static object::Paco paco;
|
||||
static FontPrimitive font_buffer[2][256];
|
||||
static NewFontWriter new_font_writer;
|
||||
static Wiggle wiggle = {Make::PositionI8(0, 0), Make::PositionI8(1, -2), Make::PositionI8(0, -4), Make::PositionI8(-1, -2), Make::PositionI8(0, 0), Make::PositionI8(1, 2), Make::PositionI8(0, 4), Make::PositionI8(-1, 2)};
|
||||
static uint8_t wiggle_count = 0;
|
||||
|
||||
static void setup() {
|
||||
static constexpr auto FontTIM = SimpleTIM(320, 0, 320, DefaultFont::Info.VRAMSize.height);
|
||||
static constexpr auto FontTIM = SimpleTIM(320, 0, 320, DefaultFont::Info.texture_size.height);
|
||||
|
||||
DefaultFont::load(&__heap_start, FontTIM);
|
||||
new_font_writer.setup(FontBufferInfo::from(font_buffer), FontTIM, DefaultFont::Info);
|
||||
|
@ -35,10 +36,11 @@ static void update() {
|
|||
const auto end_pos = cursor.write(FontWriter::Position::create(0, 32), "Cody is cute\n&\na \x1b[8;0;0mBAAAAABY!!!");
|
||||
cursor.write(end_pos, "\x1b[0;7;7mJaby was\nhere c:");
|
||||
|
||||
new_font_writer.write(Make::PositionI16(8, 8), "012345 ABCDEFGHIJKL\nabcedfghijkl", GPU::Color24::Blue(), wiggle_count);
|
||||
auto state = State::create(Make::PositionI16(8, 8), wiggle_count);
|
||||
new_font_writer.write(state, "012345 ABCDEFGHIJKL\nabcedfghijkl", GPU::Color24::Blue(), &wiggle);
|
||||
if(paco.update()) {
|
||||
wiggle_count++;
|
||||
}wiggle_count++;
|
||||
}
|
||||
}
|
||||
|
||||
static void render() {
|
||||
|
|
|
@ -32,6 +32,24 @@ namespace JabyEngine {
|
|||
static constexpr GPU::SizeU16 SizeU16(uint16_t x, uint16_t y) {
|
||||
return creator_template<GPU::SizeU16>(x, y);
|
||||
}
|
||||
|
||||
// ###################################################################
|
||||
|
||||
static constexpr GPU::PositionI8 PositionI8() {
|
||||
return creator_template<GPU::PositionI8>(0_i8, 0_i8);
|
||||
}
|
||||
static constexpr GPU::PositionI8 PositionI8(int8_t x, int8_t y) {
|
||||
return creator_template<GPU::PositionI8>(x, y);
|
||||
}
|
||||
|
||||
// ###################################################################
|
||||
|
||||
static constexpr GPU::PositionU8 PositionU8() {
|
||||
return creator_template<GPU::PositionU8>(0_u8, 0_u8);
|
||||
}
|
||||
static constexpr GPU::PositionU8 PositionU8(int8_t x, int8_t y) {
|
||||
return creator_template<GPU::PositionU8>(x, y);
|
||||
}
|
||||
|
||||
// ###################################################################
|
||||
|
||||
|
|
|
@ -141,8 +141,10 @@ namespace JabyEngine {
|
|||
return Position{.x = x, .y = y};
|
||||
}
|
||||
};
|
||||
typedef Position<int16_t> PositionI16;
|
||||
typedef Position<uint16_t> PositionU16;
|
||||
using PositionI8 = Position<int8_t>;
|
||||
using PositionU8 = Position<uint8_t>;
|
||||
using PositionI16 = Position<int16_t>;
|
||||
using PositionU16 = Position<uint16_t>;
|
||||
|
||||
template<typename T>
|
||||
struct Size {
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
};*/
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
}
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue