Remove ctru / Add pre font work

This commit is contained in:
2025-12-05 19:33:58 +01:00
parent d136e6ac5e
commit c18ef2161a
8 changed files with 109 additions and 39 deletions

View File

@@ -20,7 +20,6 @@ add_library(${PROJECT_NAME} STATIC
source/texture.cpp
source/utils.cpp
source/c3d.cpp
source/ctru.cpp
source/iron/iron.cpp
source/iron/drawlist.cpp
source/maths/mat.cpp
@@ -29,6 +28,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC include)
#target_link_libraries(${PROJECT_NAME} PUBLIC pica::pica)
target_link_libraries(${PROJECT_NAME} PUBLIC m z ctru citro3d)
target_compile_definitions(${PROJECT_NAME} PUBLIC AMY_3DS AMY_STB_IMAGE=${AMY_BUILD_STB_IMAGE})
target_compile_options(${PROJECT_NAME} PUBLIC -Wno-psabi)
add_subdirectory(example)

View File

@@ -4,7 +4,8 @@
class Example : public Amy::App {
public:
Example() {
Ctr::Init();
gfxInitDefault();
romfsInit();
consoleInit(GFX_BOTTOM, NULL);
C3D::Init();
Top = C3D::CreateScreen(GFX_TOP);
@@ -19,6 +20,8 @@ class Example : public Amy::App {
delete Mgr;
Iron::Exit();
C3D::Deinit();
romfsExit();
gfxExit();
}
void Main() {

View File

@@ -3,7 +3,6 @@
#include <amethyst/app.hpp>
#include <amethyst/assets.hpp>
#include <amethyst/c3d.hpp>
#include <amethyst/ctru.hpp>
#include <amethyst/image.hpp>
#include <amethyst/iron.hpp>
#include <amethyst/renderer.hpp>
@@ -14,5 +13,4 @@ void RegisterCxxExceptionHandler();
}
using Iron = Amy::Iron;
namespace Ctr = Amy::Ctr;
using C3D = Amy::C3D;

View File

@@ -1,17 +0,0 @@
#pragma once
#include <amethyst/types.hpp>
namespace Amy {
namespace Ctr {
enum Services {
Romfs = 1 << 0,
Cfgu = 1 << 1,
Gfx = 1 << 2,
GfxDefault = 1 << 3,
Default = Romfs | GfxDefault,
};
void Init(ui srv = Default);
ull GetTime();
} // namespace Ctr
} // namespace Amy

View File

@@ -52,6 +52,36 @@ class Iron {
int Index = 0;
Texture* Tex = nullptr;
};
class Font {
public:
struct Codepoint {
ui Cp = 0;
fvec4 Uv;
Texture* Tex;
fvec2 Size;
float Offset = 0; // Unused??
bool Valid = true;
};
Font() = default;
~Font() = default;
void LoadTTF(ksr path, int pxh = 32);
void LoadTTF(kvr<uc> data, int pxh = 32);
Codepoint& GetCodepoint(ui c);
fvec2 GetTextBounds(ksr text, float scale);
void CmdTextEx(vec<Command::ref>& cmds, const fvec2& pos, ui color,
float scale, ksr text, ui flags = 0, const fvec2& box = 0);
void pMakeAtlas(bool final, vec<uc>& pixels, int size, Texture* tex);
int PxHeight;
int PxFactor = 24;
vec<Texture*> Textures;
};
class Drawlist {
public:
Drawlist() { DrawSolid(); }

View File

@@ -1,7 +1,6 @@
#include <3ds.h>
#include <amethyst/app.hpp>
#include <amethyst/ctru.hpp>
#include <amethyst/utils.hpp>
namespace Amy {

View File

@@ -1,17 +0,0 @@
#include <3ds.h>
#include <amethyst/ctru.hpp>
namespace Amy {
namespace Ctr {
void Init(ui srvs) {
if (srvs & Romfs) {
romfsInit();
}
if (srvs & GfxDefault) {
gfxInitDefault();
}
}
ull GetTime() { return osGetTime(); }
} // namespace Ctr
} // namespace Amy

View File

@@ -70,6 +70,80 @@ ull GetTimeMilli() {
.count();
}
void String2U16(us* res, const std::string& src, size_t max) {
/// GOT FORCED TO REPLACE std::wstring_convert by some
/// manual work as it got removed in cxx20
/// TODO ///
/// ADD SOME ERROR API IN HERE
if (max == 0) return;
size_t len = 0;
size_t i = 0;
while (i < src.size() && len < max) {
uc c = src[i];
if (c < 0x80) {
// 1byte
res[len++] = c;
i++;
} else if ((c >> 5) == 0x6) {
// 2byte
if (i + 1 >= src.size())
throw std::invalid_argument("Invalid UTF-8 sequence");
res[len++] = ((c & 0x1F) << 6) | (src[i + 1] & 0x3F);
i += 2;
} else if ((c >> 4) == 0xE) {
// 3byte
if (i + 2 >= src.size())
throw std::invalid_argument("Invalid UTF-8 sequence");
res[len++] =
((c & 0x0F) << 12) | ((src[i + 1] & 0x3F) << 6) | (src[i + 2] & 0x3F);
i += 3;
} else if ((c >> 3) == 0x1E) {
// 4byte
if (i + 3 >= src.size())
throw std::invalid_argument("Invalid UTF-8 sequence");
ui codepoint = ((c & 0x07) << 18) | ((src[i + 1] & 0x3F) << 12) |
((src[i + 2] & 0x3F) << 6) | (src[i + 3] & 0x3F);
codepoint -= 0x10000;
res[len++] = 0xD800 | ((codepoint >> 10) & 0x3FF);
res[len++] = 0xDC00 | (codepoint & 0x3FF);
i += 4;
} else {
return;
}
}
}
std::string U16toU8(us* in, size_t max) {
/// GOT FORCED TO REPLACE std::wstring_convert by some
/// manual work as it got removed in cxx20
if (!in || max == 0) {
return "";
}
std::string result;
result.reserve(max * 3);
for (size_t i = 0; i < max; i++) {
uint16_t c = in[i];
if (c < 0x80) {
result.push_back(static_cast<char>(c));
} else if (c < 0x800) {
result.push_back(static_cast<char>(0xC0 | (c >> 6)));
result.push_back(static_cast<char>(0x80 | (c & 0x3F)));
} else if (c < 0x10000) {
result.push_back(static_cast<char>(0xE0 | (c >> 12)));
result.push_back(static_cast<char>(0x80 | ((c >> 6) & 0x3F)));
result.push_back(static_cast<char>(0x80 | (c & 0x3F)));
} else {
continue;
}
}
return result;
}
namespace Image {
void ReverseBuf(vec<uc>& buf, int w, int h, int c) {
vec<uc> cpy = buf;