# Stage 2.1

- Split palladium into diffrent libraries
- Fix a Logical bug in App class
- Add New Flag to Init App Data Directory
- Add Cmake Option for build tests
- Bump Version in cmake file
- Make Hid a Driver
- Start moving 3ds specific stuff into pd-lib3ds
- Split Lithium into more files
This commit is contained in:
2025-02-22 00:23:48 +01:00
parent cbdb15e0de
commit f9a1d8aefb
73 changed files with 1705 additions and 508 deletions

View File

@ -0,0 +1,80 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 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 <chrono>
#include <cinttypes>
#include <cmath>
#include <filesystem> // Requires C++ 17 or later
#include <format> // Requires C++ 20 or later
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
namespace PD {
// New Version of Smart CTOR
// Using as Template class
template <typename T>
class SmartCtor {
public:
/// @brief Type Reference
using Ref = std::shared_ptr<T>;
/// @brief Creates a New Shared Pointer
/// @param ...args Arguments to forward
/// @return Shared Pointer (Reference)
template <typename... Args>
static Ref New(Args&&... args) {
return std::make_shared<T>(std::forward<Args>(args)...);
}
};
/// @brief Wrapper for SmartCtor<Type>::New
/// @tparam T class type
/// @param ...args Arguments
/// @return SmartCtor<T>::Ref type reference
/// @note Not sure if this is solving the problem or
/// if I schould switch back to the macro
template <typename T, typename... Args>
SmartCtor<T>::Ref New(Args&&... args) {
return SmartCtor<T>::New(std::forward<Args>(args)...);
}
// Defines
using u64 = unsigned long long;
using u32 = unsigned int;
using u16 = unsigned short;
using u8 = unsigned char;
namespace LibInfo {
const std::string CompiledWith();
const std::string CxxVersion();
const std::string BuildTime();
const std::string Version();
const std::string Commit();
} // namespace LibInfo
} // namespace PD

33
include/pd/core/io.hpp Normal file
View File

@ -0,0 +1,33 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 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/core/common.hpp>
namespace PD {
namespace IO {
std::vector<u8> LoadFile2Mem(const std::string& path);
u32 HashMemory(const std::vector<u8>& data);
} // namespace IO
} // namespace PD

View File

@ -0,0 +1,103 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 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/core/common.hpp>
namespace PD {
class Markdown {
public:
Markdown() = default;
~Markdown() = default;
void Header(const std::string& hdr, int lvl = 2) {
if (task != 0 || lvl < 1 || lvl > 10) {
return;
}
/// Directly create the string with its amount of #
std::string str(lvl, '#');
str += " ";
str += hdr;
s << str << std::endl << std::endl;
}
void BeginTable(const std::vector<std::string>& head) {
if (task != 0) {
return;
}
ctc = head.size();
for (auto& it : head) {
s << "| " << it << " ";
}
s << "|\n";
for (int i = 0; i < ctc; i++) {
s << "|---";
}
s << "|\n";
task = 1;
}
Markdown& TableAddEntry(const std::string& e) {
if (task != 1) {
return *this;
}
ctci++;
s << "| " << e << " ";
if (ctci == ctc) {
s << "|\n";
ctci = 0;
}
return *this;
}
void EndTable() {
if (task != 1) {
return;
}
s << std::endl;
task = 0;
}
void Write(const std::string& path) {
std::ofstream f(path);
if (!f) {
return;
}
f << s.str();
f.close();
}
private:
/// @brief Tasks
/// 0 = free
/// 1 = table
/// 2 = text
int task = 0;
/// @brief Current Table Columns
int ctc = 0;
/// @brief Current Table Column Index
int ctci = 0;
std::stringstream s;
};
} // namespace PD

View File

@ -0,0 +1,66 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 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/core/common.hpp>
namespace PD {
namespace Strings {
bool StringEndsWith(const std::string& str,
const std::vector<std::string>& exts);
std::wstring MakeWstring(const std::string& s);
const std::string FormatNanos(unsigned long long nanos);
const std::string FormatMillis(unsigned long long millis);
const std::string FormatBytes(unsigned long long bytes);
const std::string GetFileName(const std::string& path,
const std::string& saperators = "/\\");
const std::string PathRemoveExtension(const std::string& path);
template <typename T>
inline 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();
}
u32 FastHash(const std::string& s);
inline const std::string GetCompilerVersion() {
/// As the function looks like this Project is meant to
/// Be ported to other systems as well
std::stringstream res;
#ifdef __GNUC__
res << "GCC: " << __GNUC__;
res << "." << __GNUC_MINOR__ << ".";
res << __GNUC_PATCHLEVEL__;
#elif __clang__
res << "Clang: " << __clang_major__ << ".";
res << __clang_minor__ << ".";
res << __clang_patchlevel__;
#elif _MSC_VER
res << "MSVC: " << _MSC_VER;
#else
res << "Unknown Compiler";
#endif
return res.str();
}
} // namespace Strings
} // namespace PD

38
include/pd/core/sys.hpp Normal file
View File

@ -0,0 +1,38 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 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/core/common.hpp>
#include <pd/core/timetrace.hpp>
namespace PD {
namespace Sys {
using TraceMap = std::map<std::string, TT::Res::Ref>;
u64 GetTime();
u64 GetNanoTime();
TT::Res::Ref& GetTraceRef(const std::string& id);
bool TraceExist(const std::string& id);
TraceMap& GetTraceMap();
} // namespace Sys
} // namespace PD

View File

@ -0,0 +1,126 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 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/core/common.hpp>
namespace PD {
class TimeStats : public SmartCtor<TimeStats> {
public:
TimeStats(int l) : len(l), val(l, 0) {}
~TimeStats() = default;
void Add(u64 v) {
val[idx] = v;
idx = next(idx);
num_val = std::min(num_val + 1, len);
}
u64 GetAverage() {
if (!num_val) return 0.f;
u64 res = 0;
for (int i = 0; i < num_val; i++) {
res += val[smart_idx(i)];
}
return res / num_val;
}
u64 GetMin() {
if (!num_val) return 0.f;
u64 res = std::numeric_limits<u64>::max();
for (int i = 0; i < num_val; i++) {
res = std::min(val[smart_idx(i)], res);
}
return res;
}
u64 GetMax() {
if (!num_val) return 0.f;
u64 res = 0;
for (int i = 0; i < num_val; i++) {
res = std::max(val[smart_idx(i)], res);
}
return res;
}
void Clear() {
val.assign(len, 0);
idx = 0;
num_val = 0;
}
const std::vector<u64> &GetData() { return val; }
const u64 &operator[](int i) { return val[smart_idx(i)]; }
const size_t GetLen() { return len; }
const size_t GetNumValues() { return num_val; }
private:
size_t next(size_t c) const { return (c + 1) % len; }
size_t smart_idx(size_t v) const { return (idx + len - num_val + v) % len; }
int len = 0;
std::vector<u64> val;
int idx = 0;
int num_val = 0;
};
namespace TT {
class Res : public SmartCtor<Res> {
public:
Res() { protocol = TimeStats::New(60); }
~Res() = default;
void SetID(const std::string &v) { id = v; }
const std::string GetID() { return id; }
void SetStart(u64 v) { start = v; }
u64 GetStart() { return start; }
void SetEnd(u64 v) {
end = v;
protocol->Add(GetLastDiff());
}
u64 GetEnd() { return end; }
u64 GetLastDiff() { return end - start; }
TimeStats::Ref GetProtocol() { return protocol; }
private:
std::string id;
u64 start;
u64 end;
TimeStats::Ref protocol;
};
void Beg(const std::string &id);
void End(const std::string &id);
class Scope {
public:
Scope(const std::string &id) {
this->id = id;
Beg(id);
}
~Scope() { End(id); }
private:
std::string id;
};
} // namespace TT
} // namespace PD