Add GTrace

Make Fonts an Asset
Add FormatMillis and FormatNanos
This commit is contained in:
2025-12-08 18:37:12 +01:00
parent 88e367a299
commit d85610a0bd
11 changed files with 298 additions and 18 deletions

View File

@@ -27,6 +27,7 @@ void NpiD7CxxExceptionHandler() {
#endif
namespace Amy {
void RegisterCxxExceptionHandler() {
#ifdef AMY_3DS
std::set_terminate(NpiD7CxxExceptionHandler);

View File

@@ -1,5 +1,6 @@
#include <amethyst/assets.hpp>
#include <amethyst/c3d.hpp>
#include <amethyst/iron.hpp>
#include <amethyst/texture.hpp>
namespace Amy {
@@ -13,6 +14,10 @@ void AssetMgr::AutoLoad(const ID& id, ksr path) {
auto shader = C3D::Shader::New();
shader->Load(path);
Add(id, shader);
} else if (path.ends_with(".ttf")) {
auto font = Iron::Font::New();
font->LoadTTF(path);
Add(id, font);
} else {
throw std::runtime_error("[amy]: assets: " + id.GetName() + " (" + path +
") is unsupported for AssetMgr::AutoLoad!");

14
source/godtrace.cpp Normal file
View File

@@ -0,0 +1,14 @@
#include <amethyst/godtrace.hpp>
#include <amethyst/utils.hpp>
Amy::GTrace::TraceMap Amy::GTrace::pTraces;
void Amy::GTrace::Beg(ksr id) {
auto trace = GetTraceRef(id);
trace->SetStart(Amy::Utils::GetTimeNano());
}
void Amy::GTrace::End(ksr id) {
auto trace = GetTraceRef(id);
trace->SetEnd(Amy::Utils::GetTimeNano());
}

View File

@@ -144,6 +144,42 @@ std::string U16toU8(us* in, size_t max) {
return result;
}
kstr FormatNanos(ull nanos) {
// Based on some code of my minecraft plugins
if (nanos < 1000) {
return std::format("{}ns", nanos);
} else if (nanos < 1000000) {
ull micros = nanos / 1000;
return std::format("{}us {}ns", micros, nanos % 1000);
} else if (nanos < 1000000000) {
ull millis = nanos / 1000000;
return std::format("{}ms {}us", millis, (nanos % 1000000) / 1000);
} else if (nanos < 60000000000ULL) {
ull seconds = nanos / 1000000000;
return std::format("{}s {}ms", seconds, (nanos % 1000000000) / 1000000);
} else {
ull minutes = nanos / 60000000000ULL;
ull seconds = (nanos % 60000000000ULL) / 1000000000;
return std::format("{}m {}s", minutes, seconds);
}
return "";
}
kstr FormatMillis(ull millis) {
// Original Code can be found in some of my mc plugins
if (millis < 1000) {
return std::format("{}ms", millis);
} else if (millis < 60000) {
ull seconds = millis / 1000;
return std::format("{}s {}ms", seconds, (millis % 1000));
} else {
ull minutes = millis / 60000;
ull seconds = (millis % 60000) / 1000;
return std::format("{}m {}s {}ms", minutes, seconds, (millis % 1000));
}
return "";
}
namespace Image {
void ReverseBuf(vec<uc>& buf, int w, int h, int c) {
vec<uc> cpy = buf;