Fix inconsistent EOL

This commit is contained in:
2025-01-08 22:27:37 +01:00
parent 57671ac79d
commit 1f7141c517
184 changed files with 13686 additions and 13685 deletions

View File

@@ -1,41 +1,41 @@
include $(JABY_ENGINE_DIR)/mkfile/common/RebuildTarget.mk
ARTIFACT = libFontWriter
BUILD_DIR = bin
DEFAULT_FONT_IMAGE = src/default_font_data.hpp
CCFLAGS += -I../../include -I$(JABY_ENGINE_DIR)/include
CCFLAGS += -save-temps=obj
include $(JABY_ENGINE_DIR)/mkfile/common/Wildcard.mk
SRCS = $(call rwildcard, src, c cpp s)
include $(JABY_ENGINE_DIR)/mkfile/Makefile
LIB_DIR = ../../lib/$(CONFIG_NAME)
LIB_OBJS = $(filter-out $(MAIN_BOOT_OBJ) $(OVERLAY_BOOT_OBJ),$(OBJS))
#$(info $$var is [${MAIN_BOOT_OBJ}])
#$(info $$var2 is [${LIB_OBJS}])
$(DEFAULT_FONT_IMAGE): ressources/DefaultFont.png
psxfileconv --lz4 $< simple-tim clut4 --semi-trans --color-trans | cpp_out --name default_font_data -o $@
#Linking rule
$(TARGET).a: $(LIB_OBJS)
@mkdir -p $(dir $@)
$(AR) rcs $(TARGET).a $(LIB_OBJS)
#Copy rules
$(LIB_DIR)/$(ARTIFACT).a: $(TARGET).a
@mkdir -p $(LIB_DIR)
cp $(TARGET).a $(LIB_DIR)/$(ARTIFACT).a
#Rules section for default compilation and linking
all: $(DEFAULT_FONT_IMAGE) $(LIB_DIR)/$(ARTIFACT).a
clean:
rm -fr $(DEFAULT_FONT_IMAGE)
rm -fr $(OUTPUT_DIR)
include $(JABY_ENGINE_DIR)/mkfile/common/RebuildTarget.mk
ARTIFACT = libFontWriter
BUILD_DIR = bin
DEFAULT_FONT_IMAGE = src/default_font_data.hpp
CCFLAGS += -I../../include -I$(JABY_ENGINE_DIR)/include
CCFLAGS += -save-temps=obj
include $(JABY_ENGINE_DIR)/mkfile/common/Wildcard.mk
SRCS = $(call rwildcard, src, c cpp s)
include $(JABY_ENGINE_DIR)/mkfile/Makefile
LIB_DIR = ../../lib/$(CONFIG_NAME)
LIB_OBJS = $(filter-out $(MAIN_BOOT_OBJ) $(OVERLAY_BOOT_OBJ),$(OBJS))
#$(info $$var is [${MAIN_BOOT_OBJ}])
#$(info $$var2 is [${LIB_OBJS}])
$(DEFAULT_FONT_IMAGE): ressources/DefaultFont.png
psxfileconv --lz4 $< simple-tim clut4 --semi-trans --color-trans | cpp_out --name default_font_data -o $@
#Linking rule
$(TARGET).a: $(LIB_OBJS)
@mkdir -p $(dir $@)
$(AR) rcs $(TARGET).a $(LIB_OBJS)
#Copy rules
$(LIB_DIR)/$(ARTIFACT).a: $(TARGET).a
@mkdir -p $(LIB_DIR)
cp $(TARGET).a $(LIB_DIR)/$(ARTIFACT).a
#Rules section for default compilation and linking
all: $(DEFAULT_FONT_IMAGE) $(LIB_DIR)/$(ARTIFACT).a
clean:
rm -fr $(DEFAULT_FONT_IMAGE)
rm -fr $(OUTPUT_DIR)
rm -fr $(LIB_DIR)/$(ARTIFACT).a

View File

@@ -1,24 +1,24 @@
#include "default_font_data.hpp"
#include <FontWriter/fonts.hpp>
#include <PSX/File/Processor/file_processor.hpp>
#include <PSX/Auxiliary/lz4_decompressor.hpp>
#include <stdio.hpp>
namespace JabyEngine {
static size_t decompress_font(uint32_t* work_area) {
LZ4Decompressor lz4_decomp(reinterpret_cast<uint8_t*>(work_area));
const auto [progress, bytes_ready] = lz4_decomp.process(ArrayRange(default_font_data, sizeof(default_font_data)), true);
if(progress == Progress::Error) {
return 0;
}
return bytes_ready;
}
void DefaultFont :: load(uint32_t* work_area, SimpleTIM vram_dst) {
const auto bytes_ready = decompress_font(work_area);
auto processor = FileProcessor::create(work_area, vram_dst);
processor.process(bytes_ready);
}
#include "default_font_data.hpp"
#include <FontWriter/fonts.hpp>
#include <PSX/File/Processor/file_processor.hpp>
#include <PSX/Auxiliary/lz4_decompressor.hpp>
#include <stdio.hpp>
namespace JabyEngine {
static size_t decompress_font(uint32_t* work_area) {
LZ4Decompressor lz4_decomp(reinterpret_cast<uint8_t*>(work_area));
const auto [progress, bytes_ready] = lz4_decomp.process(ArrayRange(default_font_data, sizeof(default_font_data)), true);
if(progress == Progress::Error) {
return 0;
}
return bytes_ready;
}
void DefaultFont :: load(uint32_t* work_area, SimpleTIM vram_dst) {
const auto bytes_ready = decompress_font(work_area);
auto processor = FileProcessor::create(work_area, vram_dst);
processor.process(bytes_ready);
}
}

View File

@@ -1,155 +1,155 @@
#include "include/global_primitive_buffer.hpp"
#include <PSX/GPU/gpu.hpp>
#include <PSX/GPU/make_gpu_primitives.hpp>
#include <FontWriter/font_writer.hpp>
namespace JabyEngine {
static constexpr auto ITOABufferSize = 32;
// Can we not find a better version of this?
static char* simple_itoa(char (&buffer)[ITOABufferSize], bool is_neg, uint32_t value, uint32_t base) {
// v terminating 0 and space for sign
int i = ITOABufferSize - 2;
if(value == 0) {
buffer[0] = '0';
buffer[1] = '\0';
return buffer;
}
for(; value && i; i--, value /= base) {
char chr = '0' + value%base;
if(chr > '9') {
chr += ('A' - '9' - 1);
}
buffer[i] = chr;
}
buffer[ITOABufferSize - 1] = '\0';
if(is_neg) {
buffer[i] = '-';
return &buffer[i];
}
return &buffer[i + 1];
}
static const char* simple_itoa(char (&buffer)[ITOABufferSize], int32_t value, uint32_t base) {
const auto is_neg = value < 0;
if(is_neg) {
value *= -1;
}
return simple_itoa(buffer, is_neg, value, base);
}
static const char* simple_ptoa(char (&buffer)[ITOABufferSize], void* value) {
// v terminating 0
static constexpr auto BufferStartID = ITOABufferSize - 1 - 8;
char* str = simple_itoa(buffer, false, reinterpret_cast<int>(value), 16);
while(str > &buffer[BufferStartID]) {
str--;
*str = '0';
}
return &buffer[BufferStartID];
}
void FontWriter :: setup(const SimpleTIM& vram_dst, const FontInfo::RenderInfo& font_render_info) {
for(auto& tex_page : this->tex_page) {
tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TextureColorMode::clut4).linked();
}
this->render_info = font_render_info;
this->clut = Make::PageClut(vram_dst.get_clut_position());
this->last_primitive = nullptr;
}
void FontWriter :: clear() {
this->last_primitive = &this->tex_page[GPU::update_id()];
}
void FontWriter :: write(Cursor& cursor, const char* str, GPU::Color24 color, const Wiggle* wiggle, va_list list) {
static const auto exchang_str = [](const char* str, const char* new_str) -> pair<const char*, const char*> {
return {str + 1, new_str};
};
if(!this->last_primitive) {
FontWriter::clear();
}
const auto sprt_size = GPU::SizeI16::from(this->render_info.font_size);
const auto row_count = 256/sprt_size.width;
const auto push_char = [&](Cursor& cursor, char cur_char) -> bool {
auto& primitive = GlobalPrimitiveFactory.new_primitive();
primitive->position = cursor.pos;
primitive->size = sprt_size;
if(wiggle) {
const auto [off_x, off_y] = (*wiggle)[(cursor.wiggle_count++)&0x7];
primitive->position.move(off_x, off_y);
}
primitive->tex_offset = GPU::PageOffset::from_tile_id(cur_char - '!', row_count, sprt_size);
primitive->clut = this->clut;
primitive->color = color;
this->last_primitive->concat(primitive);
this->last_primitive = &primitive;
cursor.pos.move(this->render_info.kern_size.width, 0);
return true;
};
const auto old_x = cursor.pos.x;
const char* prev_str = nullptr;
char buffer[32];
while(true) {
auto cur_char = *str++;
switch(cur_char) {
case '\0':
if(prev_str) {
str = prev_str;
prev_str = nullptr;
continue;
}
return;
case '\n':
cursor.pos.x = old_x;
cursor.pos.y += this->render_info.kern_size.height;
continue;
case ' ':
cursor.pos.x += this->render_info.kern_size.width;
continue;
case '%':
switch(*str) {
case '%':
str++;
break;
case 'i':
tie(prev_str, str) = exchang_str(str, simple_itoa(buffer, va_arg(list, int), 10));
continue;
case 'p':
tie(prev_str, str) = exchang_str(str, simple_ptoa(buffer, va_arg(list, void*)));
continue;
case 's':
tie(prev_str, str) = exchang_str(str, va_arg(list, const char*));
continue;
}
default:
if(!push_char(cursor, cur_char)) {
return;
}
}
}
}
void FontWriter :: render() {
this->last_primitive->terminate();
this->last_primitive = nullptr;
GPU::render(this->tex_page[GPU::render_id()]);
}
#include "include/global_primitive_buffer.hpp"
#include <PSX/GPU/gpu.hpp>
#include <PSX/GPU/make_gpu_primitives.hpp>
#include <FontWriter/font_writer.hpp>
namespace JabyEngine {
static constexpr auto ITOABufferSize = 32;
// Can we not find a better version of this?
static char* simple_itoa(char (&buffer)[ITOABufferSize], bool is_neg, uint32_t value, uint32_t base) {
// v terminating 0 and space for sign
int i = ITOABufferSize - 2;
if(value == 0) {
buffer[0] = '0';
buffer[1] = '\0';
return buffer;
}
for(; value && i; i--, value /= base) {
char chr = '0' + value%base;
if(chr > '9') {
chr += ('A' - '9' - 1);
}
buffer[i] = chr;
}
buffer[ITOABufferSize - 1] = '\0';
if(is_neg) {
buffer[i] = '-';
return &buffer[i];
}
return &buffer[i + 1];
}
static const char* simple_itoa(char (&buffer)[ITOABufferSize], int32_t value, uint32_t base) {
const auto is_neg = value < 0;
if(is_neg) {
value *= -1;
}
return simple_itoa(buffer, is_neg, value, base);
}
static const char* simple_ptoa(char (&buffer)[ITOABufferSize], void* value) {
// v terminating 0
static constexpr auto BufferStartID = ITOABufferSize - 1 - 8;
char* str = simple_itoa(buffer, false, reinterpret_cast<int>(value), 16);
while(str > &buffer[BufferStartID]) {
str--;
*str = '0';
}
return &buffer[BufferStartID];
}
void FontWriter :: setup(const SimpleTIM& vram_dst, const FontInfo::RenderInfo& font_render_info) {
for(auto& tex_page : this->tex_page) {
tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TextureColorMode::clut4).linked();
}
this->render_info = font_render_info;
this->clut = Make::PageClut(vram_dst.get_clut_position());
this->last_primitive = nullptr;
}
void FontWriter :: clear() {
this->last_primitive = &this->tex_page[GPU::update_id()];
}
void FontWriter :: write(Cursor& cursor, const char* str, GPU::Color24 color, const Wiggle* wiggle, va_list list) {
static const auto exchang_str = [](const char* str, const char* new_str) -> pair<const char*, const char*> {
return {str + 1, new_str};
};
if(!this->last_primitive) {
FontWriter::clear();
}
const auto sprt_size = GPU::SizeI16::from(this->render_info.font_size);
const auto row_count = 256/sprt_size.width;
const auto push_char = [&](Cursor& cursor, char cur_char) -> bool {
auto& primitive = GlobalPrimitiveFactory.new_primitive();
primitive->position = cursor.pos;
primitive->size = sprt_size;
if(wiggle) {
const auto [off_x, off_y] = (*wiggle)[(cursor.wiggle_count++)&0x7];
primitive->position.move(off_x, off_y);
}
primitive->tex_offset = GPU::PageOffset::from_tile_id(cur_char - '!', row_count, sprt_size);
primitive->clut = this->clut;
primitive->color = color;
this->last_primitive->concat(primitive);
this->last_primitive = &primitive;
cursor.pos.move(this->render_info.kern_size.width, 0);
return true;
};
const auto old_x = cursor.pos.x;
const char* prev_str = nullptr;
char buffer[32];
while(true) {
auto cur_char = *str++;
switch(cur_char) {
case '\0':
if(prev_str) {
str = prev_str;
prev_str = nullptr;
continue;
}
return;
case '\n':
cursor.pos.x = old_x;
cursor.pos.y += this->render_info.kern_size.height;
continue;
case ' ':
cursor.pos.x += this->render_info.kern_size.width;
continue;
case '%':
switch(*str) {
case '%':
str++;
break;
case 'i':
tie(prev_str, str) = exchang_str(str, simple_itoa(buffer, va_arg(list, int), 10));
continue;
case 'p':
tie(prev_str, str) = exchang_str(str, simple_ptoa(buffer, va_arg(list, void*)));
continue;
case 's':
tie(prev_str, str) = exchang_str(str, va_arg(list, const char*));
continue;
}
default:
if(!push_char(cursor, cur_char)) {
return;
}
}
}
}
void FontWriter :: render() {
this->last_primitive->terminate();
this->last_primitive = nullptr;
GPU::render(this->tex_page[GPU::render_id()]);
}
}

View File

@@ -1,16 +1,16 @@
#include "include/global_primitive_buffer.hpp"
#include <FontWriter/font_writer.hpp>
namespace JabyEngine {
PrimitiveFactory GlobalPrimitiveFactory = PrimitiveFactory::empty();
void GlobalFontPrimitivePool :: setup(FontPrimitive* start, size_t length) {
const auto*const buffer_end = start + length;
for(auto* cur_prim = start; cur_prim < buffer_end; cur_prim++) {
*cur_prim = FontPrimitive::create(Make::SPRT(Make::AreaI16(), Make::OffsetPageWithClut()));
}
GlobalPrimitiveFactory = PrimitiveFactory::create(start, length);
}
#include "include/global_primitive_buffer.hpp"
#include <FontWriter/font_writer.hpp>
namespace JabyEngine {
PrimitiveFactory GlobalPrimitiveFactory = PrimitiveFactory::empty();
void GlobalFontPrimitivePool :: setup(FontPrimitive* start, size_t length) {
const auto*const buffer_end = start + length;
for(auto* cur_prim = start; cur_prim < buffer_end; cur_prim++) {
*cur_prim = FontPrimitive::create(Make::SPRT(Make::AreaI16(), Make::OffsetPageWithClut()));
}
GlobalPrimitiveFactory = PrimitiveFactory::create(start, length);
}
}

View File

@@ -1,29 +1,29 @@
#pragma once
#include <FontWriter/Type/types.hpp>
namespace JabyEngine {
struct PrimitiveFactory {
FontPrimitive* start_adr;
FontPrimitive* end_adr;
FontPrimitive* cur_element;
static constexpr PrimitiveFactory empty() {
return PrimitiveFactory{.start_adr = nullptr, .end_adr = nullptr, .cur_element = nullptr};
}
static constexpr PrimitiveFactory create(FontPrimitive* start, size_t length) {
return PrimitiveFactory{.start_adr = start, .end_adr = start + length, .cur_element = start};
}
FontPrimitive& new_primitive() {
auto& new_primitive = *this->cur_element++;
if(this->cur_element == this->end_adr) {
this->cur_element = this->start_adr;
}
return new_primitive;
}
};
extern PrimitiveFactory GlobalPrimitiveFactory;
#pragma once
#include <FontWriter/Type/types.hpp>
namespace JabyEngine {
struct PrimitiveFactory {
FontPrimitive* start_adr;
FontPrimitive* end_adr;
FontPrimitive* cur_element;
static constexpr PrimitiveFactory empty() {
return PrimitiveFactory{.start_adr = nullptr, .end_adr = nullptr, .cur_element = nullptr};
}
static constexpr PrimitiveFactory create(FontPrimitive* start, size_t length) {
return PrimitiveFactory{.start_adr = start, .end_adr = start + length, .cur_element = start};
}
FontPrimitive& new_primitive() {
auto& new_primitive = *this->cur_element++;
if(this->cur_element == this->end_adr) {
this->cur_element = this->start_adr;
}
return new_primitive;
}
};
extern PrimitiveFactory GlobalPrimitiveFactory;
}

View File

@@ -1,6 +1,6 @@
.PHONY: FontWriter
FontWriter:
$(MAKE) -C $(JABY_ENGINE_DIR)/support/src/FontWriter $(MAKECMDGOALS)
.PHONY: FontWriter
FontWriter:
$(MAKE) -C $(JABY_ENGINE_DIR)/support/src/FontWriter $(MAKECMDGOALS)
all: FontWriter