0.7.0 rewrite dev

- remove everyting
- keep core
-rename bit_utils to bits
- add formatter for  color
- add float getters to color
- start with new drivers api
This commit is contained in:
2026-03-16 06:37:51 +01:00
parent ff1b574276
commit 41b612ec0a
131 changed files with 499 additions and 55336 deletions

View File

@@ -1,46 +1,43 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 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 {
/**
* Binary Utillity Functions
*/
namespace BitUtil {
/**
* Check if a 32 Bit number only set a sigle bit to 1
* @param v 32 bit unsigned int
* @return true if its a single bit number
*/
PD_API bool IsSingleBit(u32 v);
/**
* Get the Next Power of two Number
* @param v Current Number
* @return Next Number thats a Pow of 2
*/
PD_API u32 GetPow2(u32 v);
} // namespace BitUtil
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 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.hpp>
namespace PD {
namespace Bits {
/**
* Check if a 32 Bit number only set a sigle bit to 1
* @param v 32 bit unsigned int
* @return true if its a single bit number
*/
PD_API bool IsSingleBit(u32 v);
/**
* Get the Next Power of two Number
* @param v Current Number
* @return Next Number thats a Pow of 2
*/
PD_API u32 GetPow2(u32 v);
} // namespace Bits
} // namespace PD

View File

@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/common.hpp>
#include <pd/core/strings.hpp>
namespace PD {
@@ -140,6 +140,11 @@ class PD_API Color {
*/
constexpr operator u32() const { return Get(); }
const float rf() const { return static_cast<float>(r) / 255.f; }
const float gf() const { return static_cast<float>(g) / 255.f; }
const float bf() const { return static_cast<float>(b) / 255.f; }
const float af() const { return static_cast<float>(a) / 255.f; }
/** Public Access Data section */
u8 r;
u8 g;

View File

@@ -1,89 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 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 <array>
#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 <list>
#include <map>
#include <memory>
#include <numbers>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/** Dynamic Lib loading */
#include <pd/pd_p_api.hpp>
/** Memory Management */
#define PD_SHARED(x) \
using Ref = std::shared_ptr<x>; \
template <typename... Args> \
static Ref New(Args&&... args) { \
return std::make_shared<x>(std::forward<Args>(args)...); \
}
#define PD_RAW(x) \
using Ref = x*; \
template <typename... Args> \
static Ref New(Args&&... args) { \
x* v = new x; \
new (v) x(std::forward<Args>(args)...); \
return v; \
} \
static void Delete(Ref ref) { delete ref; }
#define PD_UNIQUE(x) \
using Ref = std::unique_ptr<x>; \
template <typename... Args> \
static Ref New(Args&&... args) { \
return std::make_unique<x>(std::forward<Args>(args)...); \
}
#define PD_BIT(x) (1 << x)
namespace PD {
[[noreturn]] inline void Throw(const std::string& str) {
#ifdef _EXCEPTIONS
throw std::runtime_error("PD Error " + str);
#else
std::cout << "PD Error " << str << std::endl;
std::abort();
#endif
}
/** Types */
using u8 = unsigned char;
using u16 = unsigned short;
using u32 = unsigned int;
using u64 = unsigned long long;
} // namespace PD

View File

@@ -23,9 +23,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/bit_util.hpp>
#include <pd/core/bits.hpp>
#include <pd/core/color.hpp>
#include <pd/core/fnv.hpp>
#include <pd/core/formatters.hpp>
#include <pd/core/fquat.hpp>
#include <pd/core/hashid.hpp>
#include <pd/core/io.hpp>
#include <pd/core/mat.hpp>
@@ -35,4 +37,4 @@ SOFTWARE.
#include <pd/core/timetrace.hpp>
#include <pd/core/tween.hpp>
#include <pd/core/u128.hpp>
#include <pd/core/vec.hpp>
#include <pd/core/vec.hpp>

View File

@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/common.hpp>
namespace PD {
/**

View File

@@ -0,0 +1,98 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 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/color.hpp>
template <>
struct std::formatter<PD::Color> : std::formatter<std::string> {
enum class ColorFmt {
Hex,
Rgbf,
Rgb,
Rgba,
Rgbaf,
};
ColorFmt mode = ColorFmt::Hex;
constexpr auto parse(std::format_parse_context& ctx) {
auto it = ctx.begin();
auto end = ctx.end();
if (it == end || *it == '}') return it;
if (check(it, end, 5, "rgbaf")) {
mode = ColorFmt::Rgbaf;
it += 5;
} else if (check(it, end, 4, "rgba")) {
mode = ColorFmt::Rgba;
it += 4;
} else if (check(it, end, 4, "rgbf")) {
mode = ColorFmt::Rgbf;
it += 4;
} else if (check(it, end, 3, "rgb")) {
mode = ColorFmt::Rgb;
it += 3;
} else if (check(it, end, 3, "hex")) {
mode = ColorFmt::Hex;
it += 3;
} else {
throw std::format_error("invalid format for PD::Color");
}
if (it == end || *it != '}')
throw std::format_error("invalid format for PD::Color");
return it;
}
template <typename FormatContext>
auto format(const PD::Color& value, FormatContext& ctx) const {
switch (mode) {
case ColorFmt::Hex:
return std::format_to(ctx.out(), "#{:02X}{:02X}{:02X}{:02X}", value.r,
value.g, value.b, value.a);
case ColorFmt::Rgb:
return std::format_to(ctx.out(), "{}, {}, {}", value.r, value.g,
value.b);
case ColorFmt::Rgba:
return std::format_to(ctx.out(), "{}, {}, {}, {}", value.r, value.g,
value.b, value.a);
case ColorFmt::Rgbf:
return std::format_to(ctx.out(), "{}, {}, {}", value.rf(), value.gf(),
value.bf());
case ColorFmt::Rgbaf:
return std::format_to(ctx.out(), "{}, {}, {}, {}", value.rf(),
value.gf(), value.bf(), value.af());
default:
return ctx.out();
}
}
constexpr bool check(std::format_parse_context::const_iterator it,
std::format_parse_context::const_iterator end,
size_t len, const char* what) {
return (end - it >= static_cast<std::ptrdiff_t>(len) &&
std::string_view(it, len) == what);
}
};

View File

@@ -25,7 +25,7 @@ SOFTWARE.
// This file is based on fvec4
#include <pd/core/common.hpp>
#include <pd/common.hpp>
#include <pd/core/vec4.hpp>
namespace PD {

View File

@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/common.hpp>
namespace PD {
/**

View File

@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/common.hpp>
#include <pd/core/vec3.hpp>
namespace PD {

View File

@@ -1,6 +1,6 @@
#pragma once
#include <pd/core/common.hpp>
#include <pd/common.hpp>
namespace PD {
template <typename T, typename Alloc = std::allocator<T>>

View File

@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/common.hpp>
namespace PD {
/**
@@ -92,9 +92,7 @@ PD_API 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();
return std::format("{0:0{1}X}", v, sizeof(v) * 2);
}
/**
* Generate a Hash out of a string
@@ -107,24 +105,22 @@ PD_API u32 FastHash(const std::string& s);
* Based on their Macros
* @return CompilerName: Version
*/
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;
inline const char* GetCompilerVersion() {
/// As the function looks like this Project is meant to
/// Be ported to other systems as well
#define __mks(x) #x
#define mkstring(x) __mks(x)
#ifdef __clang__ // Check clang first
res << "Clang: " << __clang_major__ << ".";
res << __clang_minor__ << ".";
res << __clang_patchlevel__;
return "Clang: " mkstring(__clang_major__) "." mkstring(
__clang_minor__) "." mkstring(__clang_patchlevel__);
#elif __GNUC__
res << "GCC: " << __GNUC__;
res << "." << __GNUC_MINOR__ << ".";
res << __GNUC_PATCHLEVEL__;
return "GCC: " mkstring(__GNUC__) "." mkstring(__GNUC_MINOR__) "." mkstring(
__GNUC_PATCHLEVEL__);
#elif _MSC_VER
res << "MSVC: " << _MSC_VER;
return "MSVC; " mkstring(_MSC_VER);
#else
res << "Unknown Compiler";
return "Unknown Compiler";
#endif
return res.str();
}
} // namespace Strings
class U8Iterator {

View File

@@ -23,10 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/common.hpp>
namespace PD {
class OsDriver;
/**
* Timer class
*/
@@ -36,14 +35,12 @@ class PD_API Timer {
* Constructor
* @param auto_start [default true] sets if timer should start after creation
*/
Timer(OsDriver& os, bool auto_start = true);
Timer(bool auto_start = true);
/**
* Unused Deconstructor
*/
~Timer() {}
PD_SHARED(Timer);
/**
* Resume Timer if Paused
*/
@@ -82,7 +79,5 @@ class PD_API Timer {
u64 pNow;
/** Is Running */
bool pIsRunning = false;
/** Os Driver reference */
OsDriver& pOs;
};
} // namespace PD

View File

@@ -23,10 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/common.hpp>
namespace PD {
class OsDriver;
/**
* Class to calculate Maximum/Minimum and Average Timings
*/
@@ -39,8 +38,6 @@ class TimeStats {
TimeStats(int l) : len(l), val(l, 0) {}
~TimeStats() = default;
PD_SHARED(TimeStats);
/**
* Add a New Value to the list
* @param v value to add
@@ -152,11 +149,9 @@ namespace TT {
class Res {
public:
/** Constructore that Inits a protocol at size of 60 frames */
Res() : start(0), end(0) { protocol = TimeStats::New(60); }
Res() : start(0), end(0), protocol(60) {}
~Res() = default;
PD_SHARED(Res);
/**
* Setter for the ID (Name)
* @param v ID of the Trace
@@ -184,7 +179,7 @@ class Res {
void SetEnd(u64 v) {
end = v;
diff = end - start;
protocol->Add(GetLastDiff());
protocol.Add(GetLastDiff());
}
/**
* Getter for the End Time
@@ -201,7 +196,7 @@ class Res {
* Get Protcol Reference
* @return Protocol Ref
*/
TimeStats::Ref GetProtocol() { return protocol; }
TimeStats& GetProtocol() { return protocol; }
private:
/** Trace ID */
@@ -213,18 +208,18 @@ class Res {
/** Last Diff */
u64 diff;
/** Protocol */
TimeStats::Ref protocol;
TimeStats protocol;
};
/**
* Begin a Trace
* @param id Name of the Trace
*/
PD_API void Beg(OsDriver& os, const std::string& id);
PD_API void Beg(const std::string& id);
/**
* End a Trace
* @param id Name of the Trace
*/
PD_API void End(OsDriver& os, const std::string& id);
PD_API void End(const std::string& id);
/**
* Collect Start end end of the trace by tracking
* when the Scope object goes out of scope
@@ -246,20 +241,18 @@ class Scope {
* Constructor requiring a Name for the Trace
* @param id Name of the Trace
*/
Scope(OsDriver& os, const std::string& id) : pOs(os) {
Scope(const std::string& id) {
this->ID = id;
Beg(pOs, id);
Beg(id);
}
/**
* Deconstructor getting the end time when going out of scope
*/
~Scope() { End(pOs, ID); }
~Scope() { End(ID); }
private:
/** Trace Name/ID */
std::string ID;
/** Os Driver Reference */
OsDriver& pOs;
};
} // namespace TT
} // namespace PD

View File

@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/common.hpp>
#ifndef M_PI
#define M_PI 3.14159265358979323846

View File

@@ -1,6 +1,6 @@
#pragma once
#include <pd/core/common.hpp>
#include <pd/common.hpp>
namespace PD {
/**

View File

@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/common.hpp>
#include <pd/core/vec2.hpp>
#include <pd/core/vec3.hpp>
#include <pd/core/vec4.hpp>

View File

@@ -25,7 +25,7 @@ SOFTWARE.
// This file is generated by lazyvec 2.0.0
#include <pd/core/common.hpp>
#include <pd/common.hpp>
namespace PD {
template <typename T>

View File

@@ -25,7 +25,7 @@ SOFTWARE.
// This file is generated by lazyvec 2.0.0
#include <pd/core/common.hpp>
#include <pd/common.hpp>
// Extended includes (rename if you use other filenames/paths)
#include <pd/core/vec2.hpp>

View File

@@ -25,7 +25,7 @@ SOFTWARE.
// This file is generated by lazyvec 2.0.0
#include <pd/core/common.hpp>
#include <pd/common.hpp>
// Extended includes (rename if you use other filenames/paths)
#include <pd/core/vec2.hpp>
#include <pd/core/vec3.hpp>