Skip to content

Commit

Permalink
Support switching to horizontal cards, need work in CardIo
Browse files Browse the repository at this point in the history
  • Loading branch information
GXTX committed Jan 10, 2024
1 parent fc5c347 commit 29a27be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
36 changes: 23 additions & 13 deletions Includes/Printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
bool Printer::RegisterFont(std::vector<uint8_t>& data)
{
// Real data size is 0x48, but the first byte indicates slot position
constexpr const uint8_t glyphDataLength = 0x49;
constexpr uint8_t glyphDataLength = 0x49;
if (data.size() != glyphDataLength)
return false;

uint8_t slot = data[0];
data.erase(data.begin());
std::vector<bool> bits = ConvertToBits(data);

constexpr const uint8_t maxDimentions = 24;
constexpr uint8_t maxDimentions = 24;
// FIXME: Doesn't need to be a 32-bit surface
SDL_Surface* glyph = SDL_CreateRGBSurface(
0,
Expand All @@ -59,7 +59,7 @@ bool Printer::RegisterFont(std::vector<uint8_t>& data)
SDL_UnlockSurface(glyph);

// The default 25x25 glyph is just slighly too small to match up with our font, so resize it
constexpr const uint8_t newDimentions = 30;
constexpr uint8_t newDimentions = 30;
SDL_Surface* scaledGlyph = SDL_CreateRGBSurface(
0,
newDimentions,
Expand Down Expand Up @@ -92,8 +92,8 @@ bool Printer::QueuePrintLine(std::vector<uint8_t>& data)
LoadCardImage(m_localName);

// Microsoft in their infinite wisdom defines min in windows.h, so we can't use std::min
constexpr auto maxOffset = 0x14;
uint8_t offset = data[2];
constexpr uint8_t maxOffset = 0x14;
const uint8_t offset = data[2] < maxOffset ? data[2] : maxOffset;

if (static_cast<BufferControl>(data[1]) == BufferControl::Clear)
m_printQueue.clear();
Expand All @@ -114,16 +114,17 @@ void Printer::PrintLine()
return;

TTF_Init();
constexpr const uint8_t defaultFontSize = 36;
constexpr uint8_t defaultFontSize = 36;
TTF_Font* font = TTF_OpenFont("kochi-gothic-subst.ttf", defaultFontSize);
if (font == nullptr) {
g_logger->warn("Printer::PrintLine: Unable to initialize TTF_Font with \"kochi-gothic-subst.ttf\"");
return;
}

constexpr const uint8_t defaultX = 95;
constexpr const uint8_t defaultY = 120; // FIXME: Needs to be variable, 120 for vertical, 85 for horiz
constexpr const SDL_Color color = { 0x64, 0x64, 0x96, 0xFF };
constexpr uint8_t defaultX = 95; // This is good for *most* cards
const uint8_t defaultY = m_horizontalCard ? 85 : 120;
constexpr SDL_Color color = { 0x64, 0x64, 0x96, 0xFF };
constexpr uint8_t verticalCardOffset = 4;

enum Commands {
Return = '\r',
Expand Down Expand Up @@ -151,8 +152,11 @@ void Printer::PrintLine()
utf8_int32_t currentChar = '\0';

// We don't run this for a single line skip as the FontLineSkip isn't the same as our defaultY
if (print.offset > 1)
yPos += (TTF_FontLineSkip(font) * (print.offset - 1)) + ((print.offset - 1) * 4);
if (print.offset > 1) {
yPos += TTF_FontLineSkip(font) * (print.offset - 1);
if (!m_horizontalCard)
yPos += (print.offset - 1) * verticalCardOffset;
}

// TODO: Have converted be a custom type where we can just iterate with converted[n]
for (auto i = utf8codepoint(converted, &currentChar); currentChar != '\0'; i = utf8codepoint(i, &currentChar)) {
Expand All @@ -166,7 +170,7 @@ void Printer::PrintLine()
switch (static_cast<Commands>(currentChar)) {
case Return:
TTF_SetFontSize(font, defaultFontSize * std::atoi(&yScale));
yPos += TTF_FontLineSkip(font) + 4; // FIXME: +4 for vertical cards : 0 for horiz
yPos += TTF_FontLineSkip(font) + m_horizontalCard ? 0 : verticalCardOffset;
TTF_SetFontSize(font, defaultFontSize);
xPos = defaultX;
yScale = '1';
Expand Down Expand Up @@ -208,7 +212,7 @@ void Printer::PrintLine()
continue;
}

// FIXME: Solid does not function as expected, scaled characters aren't blitted, Blended works, also doesn't need to be 32bit depth
// TODO: Solid produces a better glyph but with non-transparent backgrounds
SDL_Surface* glyph = TTF_RenderGlyph32_Blended(font, currentChar, color);
SDL_Surface* scaledGlyph = SDL_CreateRGBSurface(
0,
Expand All @@ -227,6 +231,12 @@ void Printer::PrintLine()

int advance = 0;
TTF_GlyphMetrics32(font, currentChar, NULL, NULL, NULL, NULL, &advance);
// TODO: F-Zero AX has odd spacing, if we use the default spacing it's too much, but it works for every other game?
#if 0
if (currentChar == 0x20)
xPos += 15 * std::atoi(&xScale);
else
#endif
xPos += advance * std::atoi(&xScale);

SDL_FreeSurface(glyph);
Expand Down
3 changes: 3 additions & 0 deletions Includes/Printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class Printer
bool RegisterFont(std::vector<uint8_t>& data);
bool QueuePrintLine(std::vector<uint8_t>& data);
std::string m_localName = {};

// Default state is a vertical card on the mechs
bool m_horizontalCard = false;
protected:
struct PrintCommand {
uint8_t offset = 0;
Expand Down
9 changes: 1 addition & 8 deletions Includes/WebIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,8 @@ const std::string WebIo::GenerateCardListJSON(std::string basepath)
#else
list.append(card.substr(card.find_last_of("/") + 1));
#endif
// TODO: Support card images

list.append("\",\"image\":\"");
g_logger->warn("{}", card);
#if 0
find = card.find(".bin");
if (find != std::string::npos) {
card.replace(find, 4, ".png");
}
#endif
card.append(".png");

std::string base64 = {};
Expand Down

0 comments on commit 29a27be

Please sign in to comment.