# Rewrite Stage 1

- Switch to CMake build system
- delete everything for a new structure
- Add SmartCtor class and saperate New func
- New Faster and Open Lithium Command API
- Rewritten Text Renderer to ghet rid of all that janky code
- New TimeTrace System and use of NanoTime using GetTimeNano
- Overall going to a more Object oriented way
- Updated vec api to support vec2 input on vec3
## Todo
- Support vec2 and vec3 in vec4 as inputs
- Continue UI7
- Fix SystemFont on 3ds freezing the system
- Fix TTF Font UV Mapping
## Warning
Creating Apps for the 3ds is not possible yet as the 3ds is Freezing and this is only stage 1 of ?   Emulator works perfect
This commit is contained in:
2025-01-09 20:22:49 +01:00
parent d5c01b2988
commit d815bb5674
131 changed files with 21457 additions and 30844 deletions

66
source/common/app.cpp Normal file
View File

@ -0,0 +1,66 @@
/*
MIT License
Copyright (c) 2024 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <3ds.h>
#include <pd/common/app.hpp>
#include <pd/common/sys.hpp>
namespace PD {
void App::Run() {
this->PreInit();
this->Init();
last_time = Sys::GetTime();
while (aptMainLoop()) {
u64 current = Sys::GetTime();
u64 dt = current - last_time;
app_time += float(dt / 1000.f);
last_time = current;
fps = 1000.f / (float)dt;
PD::TT::Beg("App_MainLoop");
if (!this->MainLoop(dt, app_time)) {
break;
}
PD::TT::End("App_MainLoop");
renderer->Render();
}
this->Deinit();
this->PostDeinit();
}
void App::PreInit() {
osSetSpeedupEnable(true);
gfxInitDefault();
cfguInit();
romfsInit();
renderer = LI::Renderer::New();
}
void App::PostDeinit() {
renderer = nullptr;
gfxExit();
cfguExit();
romfsExit();
}
} // namespace PD

32
source/common/common.cpp Normal file
View File

@ -0,0 +1,32 @@
/*
MIT License
Copyright (c) 2024 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/common/common.hpp>
#ifndef PALLADIUM_VERSION
#define PALLADIUM_VERSION "unknown"
#endif
#ifndef PALLADIUM_GIT_COMMIT
#define PALLADIUM_GIT_COMMIT "unknown"
#endif

50
source/common/error.cpp Normal file
View File

@ -0,0 +1,50 @@
/*
MIT License
Copyright (c) 2024 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <3ds.h>
#include <pd/common/error.hpp>
namespace PD {
void Error(const std::string& msg) {
gfxInitDefault();
consoleInit(GFX_TOP, NULL);
std::cout << "Palladium - ERROR MANAGER\n" << std::endl;
std::cout << msg << std::endl << std::endl;
std::cout << "Press Start to Exit" << std::endl;
while (aptMainLoop()) {
hidScanInput();
if (hidKeysDown() & KEY_START) {
break;
}
gfxSwapBuffers();
}
gfxExit();
exit(0);
}
void Assert(bool v, const std::string& msg) {
if (v == false) {
Error("Assert Failed:\n" + msg);
}
}
} // namespace PD

61
source/common/lang.cpp Normal file
View File

@ -0,0 +1,61 @@
/*
MIT License
Copyright (c) 2024 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/common/lang.hpp>
#include <pd/external/json.hpp>
namespace PD {
void Lang::LoadFile(const std::string &path) {
nlohmann::json js;
std::fstream iff(path, std::ios::in);
if (iff.is_open()) {
js = nlohmann::json::parse(iff);
iff.close();
if (js.is_discarded()) {
return;
}
if (!js.contains("ver") || !js.contains("id") || !js.contains("name") ||
!js.contains("author") || !js.contains("keys")) {
return;
}
if (js["ver"].get<int>() != ver) {
return;
}
lang_id = js["id"];
lang_name = js["name"];
lang_author = js["author"];
ltable.clear();
for (auto k : js["keys"].items()) {
ltable.insert(std::make_pair(k.key(), k.value().get<std::string>()));
}
}
}
const std::string &Lang::Get(const std::string &k) {
auto e = ltable.find(k);
if (e != ltable.end()) {
return e->second;
}
return k;
}
} // namespace PD

128
source/common/strings.cpp Normal file
View File

@ -0,0 +1,128 @@
/*
MIT License
Copyright (c) 2024 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/common/strings.hpp>
namespace PD::Strings {
bool StringEndsWith(const std::string& str,
const std::vector<std::string>& exts) {
// Changed order to not do an substr on empty string
if (str.empty()) {
return false;
} else if (str.substr(0, 2) == "._") {
return false;
}
// Use a more modern way here now
// to avoid strcasecmp
if (exts.size() != 0) {
for (const auto& ext : exts) {
if (str.substr(str.length() - ext.length()) == ext) {
return true;
}
}
}
return false;
}
std::wstring MakeWstring(const std::string& s) {
return std::wstring(s.begin(), s.end());
}
const std::string FormatNanos(unsigned long long nanos) {
// Based on some code of my minecraft plugins
if (nanos < 1000) {
return std::format("{}ns", nanos);
} else if (nanos < 1000000) {
unsigned long long micros = nanos / 1000;
return std::format("{}us {}ns", micros, nanos % 1000);
} else if (nanos < 1000000000) {
unsigned long long millis = nanos / 1000000;
return std::format("{}ms {}us", millis, (nanos % 1000000) / 1000);
} else if (nanos < 60000000000ULL) {
unsigned long long seconds = nanos / 1000000000;
return std::format("{}s {}ms", seconds, (nanos % 1000000000) / 1000000);
} else {
unsigned long long minutes = nanos / 60000000000ULL;
unsigned long long seconds = (nanos % 60000000000ULL) / 1000000000;
return std::format("{}m {}s", minutes, seconds);
}
return "";
}
const std::string FormatMillis(unsigned long long millis) {
// Original Code can be found in some of my mv plugins
if (millis < 1000) {
return std::format("{}ms", millis);
} else if (millis < 60000) {
unsigned long long seconds = millis / 1000;
return std::format("{}s {}ms", seconds, (millis % 1000));
} else {
unsigned long long minutes = millis / 60000;
unsigned long long seconds = (millis % 60000) / 1000;
return std::format("{}m {}s {}ms", minutes, seconds, (millis % 1000));
}
return "";
}
const std::string FormatBytes(unsigned long long bytes) {
static const std::vector<std::string> endings = {
"B", "KB", "MB", "GB", "TB", "Unk",
};
int i = 0;
double b = bytes;
while (b > 1024.0) {
i++;
b /= 1024;
}
if (i >= (int)endings.size()) {
i = (int)endings.size() - 1;
}
return std::format("{:.1f} {}", b, endings[i]);
}
const std::string GetFileName(const std::string& path,
const std::string& saperators) {
auto pos = path.find_last_of(saperators);
if (pos != path.npos) {
return path.substr(pos + 1);
}
// If No saperator was found return the entire path
return path;
}
const std::string PathRemoveExtension(const std::string& path) {
auto pos = path.find_last_of('.');
if (pos != path.npos) {
return path.substr(0, pos);
}
// If No saperator was found return the entire path
return path;
}
template <typename T>
const std::string ToHex(const T& v) {
std::stringstream s;
s << "0x" << std::setfill('0') << std::setw(sizeof(v) * 2) << std::hex << v;
return s.str();
}
} // namespace PD::Strings

48
source/common/sys.cpp Normal file
View File

@ -0,0 +1,48 @@
/*
MIT License
Copyright (c) 2024 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/common/sys.hpp>
namespace PD::Sys {
TraceMap pd_sys_tm;
u64 GetTime() {
return std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.count();
}
u64 GetNanoTime() {
return std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.count();
}
TT::Res::Ref& GetTraceRef(const std::string& id) {
// Auto Generate a New if doesnt exist
if (pd_sys_tm.find(id) == pd_sys_tm.end()) {
pd_sys_tm[id] = TT::Res::New();
pd_sys_tm[id]->SetID(id);
}
return pd_sys_tm[id];
}
TraceMap& GetTraceMap() { return pd_sys_tm; }
} // namespace PD::Sys

View File

@ -0,0 +1,37 @@
/*
MIT License
Copyright (c) 2024 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/common/sys.hpp>
#include <pd/common/timetrace.hpp>
namespace PD::TT {
void Beg(const std::string& id) {
auto trace = Sys::GetTraceRef(id);
trace->SetStart(PD::Sys::GetNanoTime());
}
void End(const std::string& id) {
auto trace = Sys::GetTraceRef(id);
trace->SetEnd(PD::Sys::GetNanoTime());
}
} // namespace PD::TT