# Rewrite 5
- Move Libraries Source into pd directory and give them all their own CMakeLists.txt - Partial rewrite core (color, autogenerated vec), lithium (now uses UNIQUE PTR for Commands), UI7 - Use MenuV2 as new standart in UI7 - Implementz ViewPort Pre alpha to UI7 - Add Line Drawing to DrawList (not Working) - Implement a Complete new drievrs API (static Drivers) - NO SUPPORT FOR SHARED LIBRARY BUILDS IN VERSION 5 YET - Add Tools to Autogenerate Headers and Stuff
This commit is contained in:
92
include/pd/core/bit_util.hpp
Normal file → Executable file
92
include/pd/core/bit_util.hpp
Normal file → Executable file
@ -1,47 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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_CORE_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_CORE_API u32 GetPow2(u32 v);
|
||||
} // namespace BitUtil
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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_CORE_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_CORE_API u32 GetPow2(u32 v);
|
||||
} // namespace BitUtil
|
||||
} // namespace PD
|
151
include/pd/core/color.hpp
Normal file → Executable file
151
include/pd/core/color.hpp
Normal file → Executable file
@ -2,8 +2,7 @@
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 tobid7
|
||||
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
|
||||
@ -27,42 +26,22 @@ SOFTWARE.
|
||||
#include <pd/core/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Color class
|
||||
*
|
||||
* - Supports hex input starting with a # and 6 or 8 digits
|
||||
* - Supports rgb(a) 8Bit unsigned number input
|
||||
* - Supports rgb(a) float input from 0.0 to 1.0
|
||||
* - Supports 32Bit input color
|
||||
* @note Safetey checks are disabled for maximum performance
|
||||
*/
|
||||
class PD_CORE_API Color {
|
||||
private:
|
||||
/** Red Value */
|
||||
u8 m_r;
|
||||
/** Green Value */
|
||||
u8 m_g;
|
||||
/** Blue Value */
|
||||
u8 m_b;
|
||||
/** Alpha Value */
|
||||
u8 m_a;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default Constructor (all variables are set to 0)
|
||||
*/
|
||||
// Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
|
||||
constexpr Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
|
||||
constexpr Color() : r(0), g(0), b(0), a(0) {}
|
||||
constexpr ~Color() {}
|
||||
/**
|
||||
* Constructor for 32Bit Color Input
|
||||
* @param color 32Bit Color value
|
||||
*/
|
||||
constexpr Color(u32 color) {
|
||||
m_a = (color >> 24) & 0xff;
|
||||
m_b = (color >> 16) & 0xff;
|
||||
m_g = (color >> 8) & 0xff;
|
||||
m_r = color & 0xff;
|
||||
constexpr Color(u32 clr) {
|
||||
a = (clr >> 24) & 0xff;
|
||||
b = (clr >> 16) & 0xff;
|
||||
g = (clr >> 8) & 0xff;
|
||||
r = clr & 0xff;
|
||||
}
|
||||
/**
|
||||
* Constructor for 8Bit Input
|
||||
@ -71,12 +50,7 @@ class PD_CORE_API Color {
|
||||
* @param b Blue Value
|
||||
* @param a Optional Alpha Value (Defaults to 255)
|
||||
*/
|
||||
constexpr Color(int r, int g, int b, int a = 255) {
|
||||
m_r = r;
|
||||
m_g = g;
|
||||
m_b = b;
|
||||
m_a = a;
|
||||
}
|
||||
constexpr Color(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {}
|
||||
/**
|
||||
* Constructor for float Input
|
||||
* @param r Red Value
|
||||
@ -86,20 +60,16 @@ class PD_CORE_API Color {
|
||||
* @note There is no Check if the number is between 0.0 and 1.0
|
||||
*/
|
||||
constexpr Color(float r, float g, float b, float a = 1.f) {
|
||||
m_r = static_cast<u8>(255.f * r);
|
||||
m_g = static_cast<u8>(255.f * g);
|
||||
m_b = static_cast<u8>(255.f * b);
|
||||
m_a = static_cast<u8>(255.f * a);
|
||||
r = static_cast<u8>(255.f * r);
|
||||
g = static_cast<u8>(255.f * g);
|
||||
b = static_cast<u8>(255.f * b);
|
||||
a = static_cast<u8>(255.f * a);
|
||||
}
|
||||
/**
|
||||
* Constructor for Hex Input
|
||||
* @param hex Hex String in `#ffffff` or `#ffffffff` format
|
||||
*/
|
||||
Color(const std::string& hex) { Hex(hex); }
|
||||
/**
|
||||
* Unused Deconstructor
|
||||
*/
|
||||
// ~Color() {}
|
||||
|
||||
/**
|
||||
* Create Color Object by Hex String
|
||||
@ -114,63 +84,6 @@ class PD_CORE_API Color {
|
||||
*/
|
||||
std::string Hex(bool rgba = false) const;
|
||||
|
||||
/**
|
||||
* Setter for Red
|
||||
* @param v value
|
||||
* @return Color class reference
|
||||
*/
|
||||
Color& r(u8 v) {
|
||||
m_r = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for Red
|
||||
* @return Red Value
|
||||
*/
|
||||
u8 r() const { return m_r; }
|
||||
/**
|
||||
* Setter for Green
|
||||
* @param v value
|
||||
* @return Color class reference
|
||||
*/
|
||||
Color& g(u8 v) {
|
||||
m_g = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for Green
|
||||
* @return Green Value
|
||||
*/
|
||||
u8 g() const { return m_g; }
|
||||
/**
|
||||
* Setter for Blue
|
||||
* @param v value
|
||||
* @return Color class reference
|
||||
*/
|
||||
Color& b(u8 v) {
|
||||
m_b = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for Blue
|
||||
* @return Blue Value
|
||||
*/
|
||||
u8 b() const { return m_b; }
|
||||
/**
|
||||
* Setter for Alpha
|
||||
* @param v value
|
||||
* @return Color class reference
|
||||
*/
|
||||
Color& a(u8 v) {
|
||||
m_a = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for Alpha
|
||||
* @return Alpha Value
|
||||
*/
|
||||
u8 a() const { return m_a; }
|
||||
|
||||
/**
|
||||
* Fade from Current to another Color
|
||||
* @param color Color to fade to
|
||||
@ -178,24 +91,25 @@ class PD_CORE_API Color {
|
||||
* @return Class Reference
|
||||
*/
|
||||
Color& Fade(const Color& color, float p) {
|
||||
m_a = static_cast<u8>((color.a() - m_a) * ((p + 1.f) / 2));
|
||||
m_b = static_cast<u8>((color.b() - m_b) * ((p + 1.f) / 2));
|
||||
m_g = static_cast<u8>((color.g() - m_g) * ((p + 1.f) / 2));
|
||||
m_r = static_cast<u8>((color.r() - m_r) * ((p + 1.f) / 2));
|
||||
a = static_cast<u8>((color.a - a) * ((p + 1.f) / 2));
|
||||
b = static_cast<u8>((color.b - b) * ((p + 1.f) / 2));
|
||||
g = static_cast<u8>((color.g - g) * ((p + 1.f) / 2));
|
||||
r = static_cast<u8>((color.r - r) * ((p + 1.f) / 2));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get 32Bit Color Value
|
||||
* @return 32Bit Color Value
|
||||
* @return 32Bit Color Value (ABGR iirc)
|
||||
*/
|
||||
u32 Get() const { return (m_a << 24) | (m_b << 16) | (m_g << 8) | m_r; }
|
||||
u32 Get() const { return (a << 24) | (b << 16) | (g << 8) | r; }
|
||||
/**
|
||||
* Get The Luminance of the Color
|
||||
* @return luminance (from 0.0 to 1.0)
|
||||
*/
|
||||
float Luminance() const {
|
||||
// For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
|
||||
return (0.3 * (m_r / 255.f) + 0.59 * (m_g / 255.f) + 0.11 * (m_b / 255.f));
|
||||
return (0.3 * (r / 255.f) + 0.59 * (g / 255.f) + 0.11 * (b / 255.f));
|
||||
}
|
||||
/**
|
||||
* Check if the Color is Light or Dark
|
||||
@ -208,24 +122,11 @@ class PD_CORE_API Color {
|
||||
* @return 32Bit Color Value
|
||||
*/
|
||||
operator u32() const { return Get(); }
|
||||
|
||||
/** Public Access Data section */
|
||||
u8 r;
|
||||
u8 g;
|
||||
u8 b;
|
||||
u8 a;
|
||||
};
|
||||
namespace Colors {
|
||||
constexpr Color White = Color(1.f, 1.f, 1.f, 1.f);
|
||||
constexpr Color Black = Color(0.f, 0.f, 0.f, 1.f);
|
||||
constexpr Color Red = Color(1.f, 0.f, 0.f, 1.f);
|
||||
constexpr Color Green = Color(0.f, 1.f, 0.f, 1.f);
|
||||
constexpr Color Blue = Color(0.f, 0.f, 1.f, 1.f);
|
||||
constexpr Color Yellow = Color(1.f, 1.f, 0.f, 1.f);
|
||||
constexpr Color Cyan = Color(0.f, 1.f, 1.f, 1.f);
|
||||
constexpr Color Magenta = Color(1.f, 0.f, 1.f, 1.f);
|
||||
constexpr Color Gray = Color(0.5f, 0.5f, 0.5f, 1.f);
|
||||
constexpr Color LightGray = Color(0.75f, 0.75f, 0.75f, 1.f);
|
||||
constexpr Color DarkGray = Color(0.25f, 0.25f, 0.25f, 1.f);
|
||||
constexpr Color Orange = Color(1.f, 0.65f, 0.f, 1.f);
|
||||
constexpr Color Pink = Color(1.f, 0.75f, 0.8f, 1.f);
|
||||
constexpr Color Brown = Color(0.6f, 0.4f, 0.2f, 1.f);
|
||||
constexpr Color Purple = Color(0.5f, 0.f, 0.5f, 1.f);
|
||||
constexpr Color Teal = Color(0.f, 0.5f, 0.5f, 1.f);
|
||||
constexpr Color Transparent = Color(0.f, 0.f, 0.f, 0.f);
|
||||
} // namespace Colors
|
||||
} // namespace PD
|
197
include/pd/core/common.hpp
Normal file → Executable file
197
include/pd/core/common.hpp
Normal file → Executable file
@ -1,131 +1,68 @@
|
||||
#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 <stack>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Platform API
|
||||
#include <pd/core/pd_p_api.hpp>
|
||||
|
||||
// Legacy Smart Pointer
|
||||
#define PD_SMART_CTOR(x) \
|
||||
using Ref = std::shared_ptr<x>; \
|
||||
template <typename... args> \
|
||||
static Ref New(args&&... cargs) { \
|
||||
return std::make_shared<x>(std::forward<args>(cargs)...); \
|
||||
}
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* SmartCtor (std::shared_ptr) Template class for Smart Pointers
|
||||
*
|
||||
* - Just add : public PD::SmartCtor<YourClass> to your class
|
||||
* @tparam T Your Class
|
||||
*/
|
||||
template <typename T>
|
||||
class SmartCtor {
|
||||
public:
|
||||
/** Reference alias for std::shared_ptr<Type> */
|
||||
using Ref = std::shared_ptr<T>;
|
||||
|
||||
/**
|
||||
* static Function to Create a New Reference
|
||||
* @param args Additional Arguments (Depends on your classes Constructors)
|
||||
* @return New Reference Object
|
||||
*/
|
||||
template <typename... Args>
|
||||
static Ref New(Args&&... args) {
|
||||
return std::make_shared<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Wrapper for SmartCtor<Type>::New(Args)
|
||||
* @tparam T Class Type
|
||||
* @param args Arguments
|
||||
* @return Type Reference (SmartPointer)
|
||||
*/
|
||||
template <typename T, typename... Args>
|
||||
SmartCtor<T>::Ref New(Args&&... args) {
|
||||
return SmartCtor<T>::New(std::forward<Args>(args)...);
|
||||
}
|
||||
// Defines
|
||||
|
||||
/** alias for 64 Bit unsigned integer */
|
||||
using u64 = unsigned long long;
|
||||
/** alias for 32 Bit unsigned integer */
|
||||
using u32 = unsigned int;
|
||||
/** alias for 16 Bit unsigned integer */
|
||||
using u16 = unsigned short;
|
||||
/** alias for 8 Bit unsigned integer */
|
||||
using u8 = unsigned char;
|
||||
|
||||
/**
|
||||
* LinInfo Compile Information
|
||||
*/
|
||||
namespace LibInfo {
|
||||
/**
|
||||
* Get the Compiler Name and Version the lib got Compiled with
|
||||
* @return Compiler Name / Version
|
||||
*/
|
||||
PD_CORE_API const std::string CompiledWith();
|
||||
/**
|
||||
* Get the C++ Version used to compile the lib
|
||||
* @return C++ Version (__cplusplus)
|
||||
*/
|
||||
PD_CORE_API const std::string CxxVersion();
|
||||
/**
|
||||
* Get the Buildtime of the Library
|
||||
* @return Build Time
|
||||
*/
|
||||
PD_CORE_API const std::string BuildTime();
|
||||
/**
|
||||
* Get the Library Version
|
||||
* @return Library Version String
|
||||
*/
|
||||
PD_CORE_API const std::string Version();
|
||||
/**
|
||||
* Get the Git Commit the Lib got compiled in
|
||||
* @return Git Commit 7digit short hash
|
||||
*/
|
||||
PD_CORE_API const std::string Commit();
|
||||
/**
|
||||
* Get the Git Branch which was active when compiling the lib
|
||||
* @return Git Branch
|
||||
*/
|
||||
PD_CORE_API const std::string Branch();
|
||||
} // namespace LibInfo
|
||||
#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 <stack>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/** Dynamic Lib loading */
|
||||
#include <pd/core/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_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 {
|
||||
/** Types */
|
||||
using u8 = unsigned char;
|
||||
using u16 = unsigned short;
|
||||
using u32 = unsigned int;
|
||||
using u64 = unsigned long long;
|
||||
} // namespace PD
|
8
include/pd/core/core.hpp
Normal file → Executable file
8
include/pd/core/core.hpp
Normal file → Executable file
@ -2,8 +2,7 @@
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 tobid7
|
||||
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
|
||||
@ -22,17 +21,14 @@ 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/bit_util.hpp>
|
||||
#include <pd/core/color.hpp>
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/core/hid_driver.hpp>
|
||||
#include <pd/core/io.hpp>
|
||||
#include <pd/core/mat.hpp>
|
||||
#include <pd/core/sl/sl.hpp>
|
||||
#include <pd/core/strings.hpp>
|
||||
#include <pd/core/sys.hpp>
|
||||
#include <pd/core/timer.hpp>
|
||||
#include <pd/core/timetrace.hpp>
|
||||
#include <pd/core/tween.hpp>
|
||||
|
@ -1,175 +0,0 @@
|
||||
#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/vec.hpp>
|
||||
|
||||
namespace PD {
|
||||
/** Input Driver Template class */
|
||||
class PD_CORE_API Hid : public SmartCtor<Hid> {
|
||||
public:
|
||||
/** Key [Controller] */
|
||||
enum Key : u32 {
|
||||
No = 0, ///< No Key
|
||||
A = 1 << 0, ///< A
|
||||
B = 1 << 1, ///< B
|
||||
X = 1 << 2, ///< X
|
||||
Y = 1 << 3, ///< Y
|
||||
Start = 1 << 4, ///< Start
|
||||
Select = 1 << 5, ///< Select
|
||||
L = 1 << 6, ///< L
|
||||
R = 1 << 7, ///< R
|
||||
DUp = 1 << 8, ///< Dpad Up
|
||||
DDown = 1 << 9, ///< Dpad down
|
||||
DLeft = 1 << 10, ///< Dpad left
|
||||
DRight = 1 << 11, ///< Dpad right
|
||||
CPUp = 1 << 12, ///< Cpad up
|
||||
CPDown = 1 << 13, ///< cpad down
|
||||
CPLeft = 1 << 14, ///< cpad left
|
||||
CPRight = 1 << 15, ///< Cpad right
|
||||
CSUp = 1 << 16, ///< Cstick up
|
||||
CSDown = 1 << 17, ///< cstick down
|
||||
CSLeft = 1 << 18, ///< cstick left
|
||||
CSRight = 1 << 19, ///< cstick right
|
||||
ZL = 1 << 20, ///< ZL
|
||||
ZR = 1 << 21, ///< ZR
|
||||
Touch = 1 << 22, ///< Touch
|
||||
Up = DUp | CPUp, ///< DPad or CPad Up
|
||||
Down = DDown | CPDown, ///< DPad or CPad Down
|
||||
Left = DLeft | CPLeft, ///< DPad or CPad Left
|
||||
Right = DRight | CPRight, ///< DPad or CPad Right
|
||||
};
|
||||
/** Event */
|
||||
enum Event {
|
||||
Event_Down, ///< Key Pressed
|
||||
Event_Held, ///< Key Held
|
||||
Event_Up, ///< Key released
|
||||
};
|
||||
Hid(const std::string& name = "NullBackend") : pName(name) {}
|
||||
~Hid() = default;
|
||||
|
||||
/**
|
||||
* Get TOuch Position
|
||||
* @return touch pos
|
||||
*/
|
||||
fvec2 TouchPos() const { return touch[0]; }
|
||||
/**
|
||||
* Get Last Touch Position (from last frame)
|
||||
* @return touch pos
|
||||
*/
|
||||
fvec2 TouchPosLast() const { return touch[1]; }
|
||||
|
||||
/**
|
||||
* Check for a Button Event
|
||||
* @param e Event Type
|
||||
* @param keys Keys to check for
|
||||
* @return if key(s) doing the requiested event
|
||||
*/
|
||||
bool IsEvent(Event e, Key keys);
|
||||
/**
|
||||
* Check for Key Press Event
|
||||
* @param keys set of keys
|
||||
* @return true if key is pressed
|
||||
*/
|
||||
bool IsDown(Key keys) const { return key_events[0].at(Event_Down) & keys; }
|
||||
/**
|
||||
* Check for Key Held Event
|
||||
* @param keys set of keys
|
||||
* @return true if key is held
|
||||
*/
|
||||
bool IsHeld(Key keys) const { return key_events[0].at(Event_Held) & keys; }
|
||||
/**
|
||||
* Check for Key Release Event
|
||||
* @param keys set of keys
|
||||
* @return true if key is released
|
||||
*/
|
||||
bool IsUp(Key keys) const { return key_events[0].at(Event_Up) & keys; }
|
||||
|
||||
/**
|
||||
* Sett all keyevents to 0
|
||||
*/
|
||||
void Clear() {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
key_events[i][Event_Down] = 0;
|
||||
key_events[i][Event_Up] = 0;
|
||||
key_events[i][Event_Held] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock input driver
|
||||
* @param v lock or not lock
|
||||
*/
|
||||
void Lock(bool v) {
|
||||
if (v != locked) {
|
||||
SwappyTable();
|
||||
}
|
||||
locked = v;
|
||||
}
|
||||
/**
|
||||
* Check if Driver is locked
|
||||
* @return true if locked
|
||||
*/
|
||||
bool Locked() const { return locked; }
|
||||
/**
|
||||
* Lock Input Driver
|
||||
*/
|
||||
void Lock() {
|
||||
if (!locked) {
|
||||
SwappyTable();
|
||||
}
|
||||
locked = true;
|
||||
}
|
||||
/**
|
||||
* Unlock Input Driver
|
||||
*/
|
||||
void Unlock() {
|
||||
if (locked) {
|
||||
SwappyTable();
|
||||
}
|
||||
locked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template Update Function for a device specific driver
|
||||
*/
|
||||
virtual void Update() {}
|
||||
|
||||
/** Backend Identification Name */
|
||||
const std::string pName;
|
||||
|
||||
protected:
|
||||
/** Key binds map */
|
||||
std::unordered_map<u32, u32> binds;
|
||||
/** Function to swap around the Table */
|
||||
void SwappyTable();
|
||||
/** Using 2 Touch positions for current and last frame */
|
||||
fvec2 touch[2];
|
||||
/** locked state */
|
||||
bool locked = false;
|
||||
/** Key event tables */
|
||||
std::unordered_map<Event, u32> key_events[2];
|
||||
};
|
||||
} // namespace PD
|
126
include/pd/core/io.hpp
Normal file → Executable file
126
include/pd/core/io.hpp
Normal file → Executable file
@ -1,72 +1,56 @@
|
||||
#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 {
|
||||
/**
|
||||
* Set of File Functions
|
||||
*/
|
||||
namespace IO {
|
||||
enum RleFmt {
|
||||
Default = 0,
|
||||
_16 = 1 << 0,
|
||||
_32 = 1 << 1,
|
||||
_64 = 1 << 2,
|
||||
};
|
||||
/**
|
||||
* Load a File into an 8Bit Memory Buffer
|
||||
* @param path Path to the File
|
||||
* @return 8Bit FileBuffer
|
||||
*/
|
||||
PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path);
|
||||
/**
|
||||
* Hash a 8Bit Memory Buffer
|
||||
* @param data 8Bit input Buffer
|
||||
* @return 32Bit Hash
|
||||
*/
|
||||
PD_CORE_API u32 HashMemory(const std::vector<u8>& data);
|
||||
/**
|
||||
* Function to decrompress RLE buffer
|
||||
* @param data Data buffer to decompress
|
||||
*/
|
||||
PD_CORE_API void DecompressRLE(std::vector<u8>& data);
|
||||
/**
|
||||
* Function to decrompress Extended RLE Buffer
|
||||
* @param data Data buffer to decompress
|
||||
*/
|
||||
PD_CORE_API void DecompressRLE_Ex(std::vector<u8>& data);
|
||||
/**
|
||||
* Function to compress data with RLE Algorithm
|
||||
* @param data Data buf
|
||||
*/
|
||||
PD_CORE_API void CompressRLE(std::vector<u8>& data);
|
||||
/**
|
||||
* Extended RLE Compress function (slower cause searches best format)
|
||||
* @param data Data buf
|
||||
*/
|
||||
PD_CORE_API void CompressRLE_Ex(std::vector<u8>& data);
|
||||
} // namespace IO
|
||||
#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 {
|
||||
/**
|
||||
* Set of File Functions
|
||||
*/
|
||||
namespace IO {
|
||||
/**
|
||||
* Load a File into an 8Bit Memory Buffer
|
||||
* @param path Path to the File
|
||||
* @return 8Bit FileBuffer
|
||||
*/
|
||||
PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path);
|
||||
/**
|
||||
* Hash a 8Bit Memory Buffer
|
||||
* @param data 8Bit input Buffer
|
||||
* @return 32Bit Hash
|
||||
*/
|
||||
PD_CORE_API u32 HashMemory(const std::vector<u8>& data);
|
||||
/**
|
||||
* Function to decrompress RLE buffer
|
||||
* @param data Data buffer to decompress
|
||||
*/
|
||||
PD_CORE_API void DecompressRLE(std::vector<u8>& data);
|
||||
/**
|
||||
* Function to compress data with RLE Algorithm
|
||||
* @param data Data buf
|
||||
*/
|
||||
PD_CORE_API void CompressRLE(std::vector<u8>& data);
|
||||
} // namespace IO
|
||||
} // namespace PD
|
0
include/pd/core/mat.hpp
Normal file → Executable file
0
include/pd/core/mat.hpp
Normal file → Executable file
9
include/pd/core/pd_p_api.hpp
Normal file → Executable file
9
include/pd/core/pd_p_api.hpp
Normal file → Executable file
@ -2,8 +2,7 @@
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 tobid7
|
||||
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
|
||||
@ -22,7 +21,9 @@ 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.
|
||||
*/
|
||||
*/
|
||||
|
||||
/** Generated with ppam */
|
||||
|
||||
#ifdef _WIN32 // Windows (MSVC Tested)
|
||||
#ifdef PD_CORE_BUILD_SHARED
|
||||
@ -47,4 +48,4 @@ SOFTWARE.
|
||||
#define PD_CORE_API
|
||||
#else
|
||||
#define PD_CORE_API
|
||||
#endif
|
||||
#endif
|
||||
|
0
include/pd/core/sl/allocator.hpp
Normal file → Executable file
0
include/pd/core/sl/allocator.hpp
Normal file → Executable file
140
include/pd/core/sl/hashmap.hpp
Normal file → Executable file
140
include/pd/core/sl/hashmap.hpp
Normal file → Executable file
@ -1,71 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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/sl/list.hpp>
|
||||
#include <pd/core/sl/pair.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename K, typename V, size_t bucket_count = 10>
|
||||
class HashMap {
|
||||
public:
|
||||
HashMap() {}
|
||||
~HashMap() {}
|
||||
|
||||
void Insert(const K& k, const V& v) {
|
||||
size_t idx = Hash(k);
|
||||
auto& bukket = pBuckets[idx];
|
||||
for (auto& it : bukket) {
|
||||
if (it.First == k) {
|
||||
it.Second = v;
|
||||
return;
|
||||
}
|
||||
}
|
||||
bukket.PushBack(Pair(k, v));
|
||||
}
|
||||
|
||||
bool Contains(const K& k) const {
|
||||
size_t idx = Hash(k);
|
||||
auto& bukket = pBuckets[idx];
|
||||
|
||||
for (auto& it : bukket) {
|
||||
if (it.First == k) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
for (size_t i = 0; i < bucket_count; i++) {
|
||||
pBuckets[i].Clear();
|
||||
}
|
||||
}
|
||||
|
||||
size_t Hash(const K& k) const { return std::hash<K>{}(k) % bucket_count; }
|
||||
PD::List<PD::Pair<K, V>> pBuckets[bucket_count];
|
||||
};
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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/sl/list.hpp>
|
||||
#include <pd/core/sl/pair.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename K, typename V, size_t bucket_count = 10>
|
||||
class HashMap {
|
||||
public:
|
||||
HashMap() {}
|
||||
~HashMap() {}
|
||||
|
||||
void Insert(const K& k, const V& v) {
|
||||
size_t idx = Hash(k);
|
||||
auto& bukket = pBuckets[idx];
|
||||
for (auto& it : bukket) {
|
||||
if (it.First == k) {
|
||||
it.Second = v;
|
||||
return;
|
||||
}
|
||||
}
|
||||
bukket.PushBack(Pair(k, v));
|
||||
}
|
||||
|
||||
bool Contains(const K& k) const {
|
||||
size_t idx = Hash(k);
|
||||
auto& bukket = pBuckets[idx];
|
||||
|
||||
for (auto& it : bukket) {
|
||||
if (it.First == k) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
for (size_t i = 0; i < bucket_count; i++) {
|
||||
pBuckets[i].Clear();
|
||||
}
|
||||
}
|
||||
|
||||
size_t Hash(const K& k) const { return std::hash<K>{}(k) % bucket_count; }
|
||||
PD::List<PD::Pair<K, V>> pBuckets[bucket_count];
|
||||
};
|
||||
} // namespace PD
|
418
include/pd/core/sl/list.hpp
Normal file → Executable file
418
include/pd/core/sl/list.hpp
Normal file → Executable file
@ -1,210 +1,210 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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 {
|
||||
template <typename T>
|
||||
class List {
|
||||
public:
|
||||
List() {}
|
||||
~List() {}
|
||||
|
||||
struct Node {
|
||||
Node(const T& v) : Data(v) {}
|
||||
T Data;
|
||||
Node* Prev = nullptr;
|
||||
Node* Next = nullptr;
|
||||
};
|
||||
|
||||
class Iterator {
|
||||
public:
|
||||
Iterator(Node* n) : pNode(n) {}
|
||||
T& operator*() { return pNode->Data; }
|
||||
Iterator& operator++() {
|
||||
pNode = pNode->Next;
|
||||
return *this;
|
||||
}
|
||||
bool operator!=(const Iterator& o) const { return pNode != o.pNode; }
|
||||
|
||||
Node* pNode = nullptr;
|
||||
};
|
||||
|
||||
void PushFront(const T& val) {
|
||||
Node* node = new Node(val);
|
||||
// node->Data = val;
|
||||
node->Prev = nullptr;
|
||||
node->Next = pHead;
|
||||
if (pHead) {
|
||||
pHead->Prev = node;
|
||||
}
|
||||
pHead = node;
|
||||
if (!pTail) {
|
||||
pTail = node;
|
||||
}
|
||||
pSize++;
|
||||
}
|
||||
|
||||
void PushBack(const T& val) {
|
||||
Node* node = new Node(val);
|
||||
// node->Data = val;
|
||||
node->Prev = pTail;
|
||||
node->Next = nullptr;
|
||||
if (pTail) {
|
||||
pTail->Next = node;
|
||||
}
|
||||
pTail = node;
|
||||
if (!pHead) {
|
||||
pHead = node;
|
||||
}
|
||||
pSize++;
|
||||
}
|
||||
|
||||
void PopFront() {
|
||||
if (!pHead) {
|
||||
return;
|
||||
}
|
||||
Node* t = pHead;
|
||||
pHead = pHead->Next;
|
||||
if (pHead) {
|
||||
pHead->Prev = nullptr;
|
||||
} else {
|
||||
pTail = nullptr;
|
||||
}
|
||||
delete t;
|
||||
pSize--;
|
||||
}
|
||||
|
||||
void PopBack() {
|
||||
if (!pTail) {
|
||||
return;
|
||||
}
|
||||
Node* t = pTail;
|
||||
pTail = pTail->Prev;
|
||||
if (pTail) {
|
||||
pTail->Next = nullptr;
|
||||
} else {
|
||||
pHead = nullptr;
|
||||
}
|
||||
delete t;
|
||||
pSize--;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
while (pHead) {
|
||||
PopFront();
|
||||
}
|
||||
}
|
||||
|
||||
void Remove(const T& v) {
|
||||
Node* s = pHead;
|
||||
while (s) {
|
||||
if (s->Data == v) {
|
||||
if (s->Prev) {
|
||||
s->Prev->Next = s->Next;
|
||||
} else {
|
||||
pHead = s->Next;
|
||||
}
|
||||
if (s->Next) {
|
||||
s->Next->Prev = s->Prev;
|
||||
} else {
|
||||
pTail = s->Prev;
|
||||
}
|
||||
delete s;
|
||||
pSize--;
|
||||
return;
|
||||
}
|
||||
s = s->Next;
|
||||
}
|
||||
}
|
||||
|
||||
void Reverse() {
|
||||
Node* cur = pHead;
|
||||
while (cur) {
|
||||
Node* temp = cur->Prev;
|
||||
cur->Prev = cur->Next;
|
||||
cur->Next = temp;
|
||||
cur = cur->Prev;
|
||||
}
|
||||
Node* temp = pHead;
|
||||
pHead = pTail;
|
||||
pTail = temp;
|
||||
}
|
||||
|
||||
T& Front() {
|
||||
if (pHead) {
|
||||
return pHead->Data;
|
||||
}
|
||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const T& Front() const {
|
||||
if (pHead) {
|
||||
return pHead->Data;
|
||||
}
|
||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
T& Back() {
|
||||
if (pTail) {
|
||||
return pTail->Data;
|
||||
}
|
||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const T& Back() const {
|
||||
if (pTail) {
|
||||
return pTail->Data;
|
||||
}
|
||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
size_t Size() const { return pSize; }
|
||||
|
||||
Iterator begin() { return Iterator(pHead); }
|
||||
Iterator end() { return Iterator(nullptr); }
|
||||
|
||||
private:
|
||||
Node* Find(const T& v) const {
|
||||
Node* t = pHead;
|
||||
while (t) {
|
||||
if (t->Data == v) {
|
||||
return t;
|
||||
}
|
||||
t = t->Next;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Node* pHead = nullptr;
|
||||
Node* pTail = nullptr;
|
||||
size_t pSize = 0;
|
||||
};
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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 {
|
||||
template <typename T>
|
||||
class List {
|
||||
public:
|
||||
List() {}
|
||||
~List() {}
|
||||
|
||||
struct Node {
|
||||
Node(const T& v) : Data(v) {}
|
||||
T Data;
|
||||
Node* Prev = nullptr;
|
||||
Node* Next = nullptr;
|
||||
};
|
||||
|
||||
class Iterator {
|
||||
public:
|
||||
Iterator(Node* n) : pNode(n) {}
|
||||
T& operator*() { return pNode->Data; }
|
||||
Iterator& operator++() {
|
||||
pNode = pNode->Next;
|
||||
return *this;
|
||||
}
|
||||
bool operator!=(const Iterator& o) const { return pNode != o.pNode; }
|
||||
|
||||
Node* pNode = nullptr;
|
||||
};
|
||||
|
||||
void PushFront(const T& val) {
|
||||
Node* node = new Node(val);
|
||||
// node->Data = val;
|
||||
node->Prev = nullptr;
|
||||
node->Next = pHead;
|
||||
if (pHead) {
|
||||
pHead->Prev = node;
|
||||
}
|
||||
pHead = node;
|
||||
if (!pTail) {
|
||||
pTail = node;
|
||||
}
|
||||
pSize++;
|
||||
}
|
||||
|
||||
void PushBack(const T& val) {
|
||||
Node* node = new Node(val);
|
||||
// node->Data = val;
|
||||
node->Prev = pTail;
|
||||
node->Next = nullptr;
|
||||
if (pTail) {
|
||||
pTail->Next = node;
|
||||
}
|
||||
pTail = node;
|
||||
if (!pHead) {
|
||||
pHead = node;
|
||||
}
|
||||
pSize++;
|
||||
}
|
||||
|
||||
void PopFront() {
|
||||
if (!pHead) {
|
||||
return;
|
||||
}
|
||||
Node* t = pHead;
|
||||
pHead = pHead->Next;
|
||||
if (pHead) {
|
||||
pHead->Prev = nullptr;
|
||||
} else {
|
||||
pTail = nullptr;
|
||||
}
|
||||
delete t;
|
||||
pSize--;
|
||||
}
|
||||
|
||||
void PopBack() {
|
||||
if (!pTail) {
|
||||
return;
|
||||
}
|
||||
Node* t = pTail;
|
||||
pTail = pTail->Prev;
|
||||
if (pTail) {
|
||||
pTail->Next = nullptr;
|
||||
} else {
|
||||
pHead = nullptr;
|
||||
}
|
||||
delete t;
|
||||
pSize--;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
while (pHead) {
|
||||
PopFront();
|
||||
}
|
||||
}
|
||||
|
||||
void Remove(const T& v) {
|
||||
Node* s = pHead;
|
||||
while (s) {
|
||||
if (s->Data == v) {
|
||||
if (s->Prev) {
|
||||
s->Prev->Next = s->Next;
|
||||
} else {
|
||||
pHead = s->Next;
|
||||
}
|
||||
if (s->Next) {
|
||||
s->Next->Prev = s->Prev;
|
||||
} else {
|
||||
pTail = s->Prev;
|
||||
}
|
||||
delete s;
|
||||
pSize--;
|
||||
return;
|
||||
}
|
||||
s = s->Next;
|
||||
}
|
||||
}
|
||||
|
||||
void Reverse() {
|
||||
Node* cur = pHead;
|
||||
while (cur) {
|
||||
Node* temp = cur->Prev;
|
||||
cur->Prev = cur->Next;
|
||||
cur->Next = temp;
|
||||
cur = cur->Prev;
|
||||
}
|
||||
Node* temp = pHead;
|
||||
pHead = pTail;
|
||||
pTail = temp;
|
||||
}
|
||||
|
||||
T& Front() {
|
||||
if (pHead) {
|
||||
return pHead->Data;
|
||||
}
|
||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const T& Front() const {
|
||||
if (pHead) {
|
||||
return pHead->Data;
|
||||
}
|
||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
T& Back() {
|
||||
if (pTail) {
|
||||
return pTail->Data;
|
||||
}
|
||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const T& Back() const {
|
||||
if (pTail) {
|
||||
return pTail->Data;
|
||||
}
|
||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
size_t Size() const { return pSize; }
|
||||
|
||||
Iterator begin() { return Iterator(pHead); }
|
||||
Iterator end() { return Iterator(nullptr); }
|
||||
|
||||
private:
|
||||
Node* Find(const T& v) const {
|
||||
Node* t = pHead;
|
||||
while (t) {
|
||||
if (t->Data == v) {
|
||||
return t;
|
||||
}
|
||||
t = t->Next;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Node* pHead = nullptr;
|
||||
Node* pTail = nullptr;
|
||||
size_t pSize = 0;
|
||||
};
|
||||
} // namespace PD
|
80
include/pd/core/sl/pair.hpp
Normal file → Executable file
80
include/pd/core/sl/pair.hpp
Normal file → Executable file
@ -1,41 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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 {
|
||||
template <typename T1, typename T2>
|
||||
class Pair {
|
||||
public:
|
||||
Pair() = default;
|
||||
Pair(const T1& f, const T2& s) : First(f), Second(s) {}
|
||||
Pair(T1&& f, T2&& s) : First(std::move(f)), Second(std::move(s)) {}
|
||||
~Pair() = default;
|
||||
|
||||
T1 First;
|
||||
T2 Second;
|
||||
};
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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 {
|
||||
template <typename T1, typename T2>
|
||||
class Pair {
|
||||
public:
|
||||
Pair() = default;
|
||||
Pair(const T1& f, const T2& s) : First(f), Second(s) {}
|
||||
Pair(T1&& f, T2&& s) : First(std::move(f)), Second(std::move(s)) {}
|
||||
~Pair() = default;
|
||||
|
||||
T1 First;
|
||||
T2 Second;
|
||||
};
|
||||
} // namespace PD
|
64
include/pd/core/sl/sl.hpp
Normal file → Executable file
64
include/pd/core/sl/sl.hpp
Normal file → Executable file
@ -1,33 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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/sl/allocator.hpp>
|
||||
#include <pd/core/sl/hashmap.hpp>
|
||||
#include <pd/core/sl/list.hpp>
|
||||
#include <pd/core/sl/pair.hpp>
|
||||
#include <pd/core/sl/stack.hpp>
|
||||
#include <pd/core/sl/tools.hpp>
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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/sl/allocator.hpp>
|
||||
#include <pd/core/sl/hashmap.hpp>
|
||||
#include <pd/core/sl/list.hpp>
|
||||
#include <pd/core/sl/pair.hpp>
|
||||
#include <pd/core/sl/stack.hpp>
|
||||
#include <pd/core/sl/tools.hpp>
|
||||
#include <pd/core/sl/vector.hpp>
|
0
include/pd/core/sl/stack.hpp
Normal file → Executable file
0
include/pd/core/sl/stack.hpp
Normal file → Executable file
0
include/pd/core/sl/tools.hpp
Normal file → Executable file
0
include/pd/core/sl/tools.hpp
Normal file → Executable file
0
include/pd/core/sl/vector.hpp
Normal file → Executable file
0
include/pd/core/sl/vector.hpp
Normal file → Executable file
244
include/pd/core/strings.hpp
Normal file → Executable file
244
include/pd/core/strings.hpp
Normal file → Executable file
@ -1,123 +1,123 @@
|
||||
#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 {
|
||||
/**
|
||||
* Set of String Utillity Functions
|
||||
*/
|
||||
namespace Strings {
|
||||
/**
|
||||
* Check if a String ends with a specific extension
|
||||
* @param str Input string
|
||||
* @param exts List of Extensions to check for
|
||||
* @return true if one of the extensions is found in the String
|
||||
*/
|
||||
PD_CORE_API bool StringEndsWith(const std::string& str,
|
||||
const std::vector<std::string>& exts);
|
||||
/**
|
||||
* Function to Create a wstring of a string
|
||||
* @param s Input String to Convert
|
||||
* @return Result wstring
|
||||
* @note Returns Empty if it has an error
|
||||
*/
|
||||
PD_CORE_API std::wstring MakeWstring(const std::string& s);
|
||||
/**
|
||||
* Generate a Formatted String by an Nanoseconds Input
|
||||
* @param nanos Nanoseconds Input
|
||||
* @return Result String
|
||||
*/
|
||||
PD_CORE_API const std::string FormatNanos(unsigned long long nanos);
|
||||
/**
|
||||
* Generate a Formatted String by an Milliseconds Input
|
||||
* @param millis Milliseconds Input
|
||||
* @return Result String
|
||||
*/
|
||||
PD_CORE_API const std::string FormatMillis(unsigned long long millis);
|
||||
/**
|
||||
* Create a formatted String by an input bytes value
|
||||
* @param bytes value in bytes
|
||||
* @result Formatted String for example `2.5MB`
|
||||
*/
|
||||
PD_CORE_API const std::string FormatBytes(unsigned long long bytes);
|
||||
/**
|
||||
* Extract the Filename out of a Path
|
||||
* @param path Path to extract from
|
||||
* @param saperators Path Split Chars
|
||||
* @return extracted filename
|
||||
*/
|
||||
PD_CORE_API const std::string GetFileName(
|
||||
const std::string& path, const std::string& saperators = "/\\");
|
||||
/**
|
||||
* Remove Extension from a Path / Filename
|
||||
* @param path Input Path
|
||||
* @return Path without Extension
|
||||
*/
|
||||
PD_CORE_API const std::string PathRemoveExtension(const std::string& path);
|
||||
/**
|
||||
* Function to Convert a Type to a hex value
|
||||
* @tparam T Type
|
||||
* @param v value
|
||||
* @return hex string beginning with 0x
|
||||
*/
|
||||
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();
|
||||
}
|
||||
/**
|
||||
* Generate a Hash out of a string
|
||||
* @param s String to hash
|
||||
* @return 32Bit Hash
|
||||
*/
|
||||
PD_CORE_API u32 FastHash(const std::string& s);
|
||||
/**
|
||||
* Function to Generate a Compiler Name and Version String
|
||||
* 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;
|
||||
#ifdef __clang__ // Check clang first
|
||||
res << "Clang: " << __clang_major__ << ".";
|
||||
res << __clang_minor__ << ".";
|
||||
res << __clang_patchlevel__;
|
||||
#elif __GNUC__
|
||||
res << "GCC: " << __GNUC__;
|
||||
res << "." << __GNUC_MINOR__ << ".";
|
||||
res << __GNUC_PATCHLEVEL__;
|
||||
#elif _MSC_VER
|
||||
res << "MSVC: " << _MSC_VER;
|
||||
#else
|
||||
res << "Unknown Compiler";
|
||||
#endif
|
||||
return res.str();
|
||||
}
|
||||
} // namespace Strings
|
||||
#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 {
|
||||
/**
|
||||
* Set of String Utillity Functions
|
||||
*/
|
||||
namespace Strings {
|
||||
/**
|
||||
* Check if a String ends with a specific extension
|
||||
* @param str Input string
|
||||
* @param exts List of Extensions to check for
|
||||
* @return true if one of the extensions is found in the String
|
||||
*/
|
||||
PD_CORE_API bool StringEndsWith(const std::string& str,
|
||||
const std::vector<std::string>& exts);
|
||||
/**
|
||||
* Function to Create a wstring of a string
|
||||
* @param s Input String to Convert
|
||||
* @return Result wstring
|
||||
* @note Returns Empty if it has an error
|
||||
*/
|
||||
PD_CORE_API std::wstring MakeWstring(const std::string& s);
|
||||
/**
|
||||
* Generate a Formatted String by an Nanoseconds Input
|
||||
* @param nanos Nanoseconds Input
|
||||
* @return Result String
|
||||
*/
|
||||
PD_CORE_API const std::string FormatNanos(unsigned long long nanos);
|
||||
/**
|
||||
* Generate a Formatted String by an Milliseconds Input
|
||||
* @param millis Milliseconds Input
|
||||
* @return Result String
|
||||
*/
|
||||
PD_CORE_API const std::string FormatMillis(unsigned long long millis);
|
||||
/**
|
||||
* Create a formatted String by an input bytes value
|
||||
* @param bytes value in bytes
|
||||
* @result Formatted String for example `2.5MB`
|
||||
*/
|
||||
PD_CORE_API const std::string FormatBytes(unsigned long long bytes);
|
||||
/**
|
||||
* Extract the Filename out of a Path
|
||||
* @param path Path to extract from
|
||||
* @param saperators Path Split Chars
|
||||
* @return extracted filename
|
||||
*/
|
||||
PD_CORE_API const std::string GetFileName(
|
||||
const std::string& path, const std::string& saperators = "/\\");
|
||||
/**
|
||||
* Remove Extension from a Path / Filename
|
||||
* @param path Input Path
|
||||
* @return Path without Extension
|
||||
*/
|
||||
PD_CORE_API const std::string PathRemoveExtension(const std::string& path);
|
||||
/**
|
||||
* Function to Convert a Type to a hex value
|
||||
* @tparam T Type
|
||||
* @param v value
|
||||
* @return hex string beginning with 0x
|
||||
*/
|
||||
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();
|
||||
}
|
||||
/**
|
||||
* Generate a Hash out of a string
|
||||
* @param s String to hash
|
||||
* @return 32Bit Hash
|
||||
*/
|
||||
PD_CORE_API u32 FastHash(const std::string& s);
|
||||
/**
|
||||
* Function to Generate a Compiler Name and Version String
|
||||
* 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;
|
||||
#ifdef __clang__ // Check clang first
|
||||
res << "Clang: " << __clang_major__ << ".";
|
||||
res << __clang_minor__ << ".";
|
||||
res << __clang_patchlevel__;
|
||||
#elif __GNUC__
|
||||
res << "GCC: " << __GNUC__;
|
||||
res << "." << __GNUC_MINOR__ << ".";
|
||||
res << __GNUC_PATCHLEVEL__;
|
||||
#elif _MSC_VER
|
||||
res << "MSVC: " << _MSC_VER;
|
||||
#else
|
||||
res << "Unknown Compiler";
|
||||
#endif
|
||||
return res.str();
|
||||
}
|
||||
} // namespace Strings
|
||||
} // namespace PD
|
@ -1,66 +0,0 @@
|
||||
#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 containing functions for get Millis and Get Nanos
|
||||
*/
|
||||
namespace Sys {
|
||||
/**
|
||||
* alias for the TimeTrace Traces Map
|
||||
*/
|
||||
using TraceMap = std::map<std::string, TT::Res::Ref>;
|
||||
/**
|
||||
* Get Current Time in Milliseconds
|
||||
* @return 64Bit value of millis
|
||||
*/
|
||||
PD_CORE_API u64 GetTime();
|
||||
/**
|
||||
* Get Current Time in Nanoseconds
|
||||
* @return 64Bit value of nanos
|
||||
*/
|
||||
PD_CORE_API u64 GetNanoTime();
|
||||
/**
|
||||
* Get a TimeTrace Reference by its string ID
|
||||
* @param id trace name
|
||||
* @return Trace reference or nullptr if not found
|
||||
*/
|
||||
PD_CORE_API TT::Res::Ref& GetTraceRef(const std::string& id);
|
||||
/**
|
||||
* Check if a Trace with the name exists
|
||||
* @param id tracename to search
|
||||
* @return true if exist
|
||||
*/
|
||||
PD_CORE_API bool TraceExist(const std::string& id);
|
||||
/**
|
||||
* Get TraceMap Reference
|
||||
* @return edidable Reference to the TraceMap
|
||||
*/
|
||||
PD_CORE_API TraceMap& GetTraceMap();
|
||||
} // namespace Sys
|
||||
} // namespace PD
|
167
include/pd/core/timer.hpp
Normal file → Executable file
167
include/pd/core/timer.hpp
Normal file → Executable file
@ -1,84 +1,85 @@
|
||||
#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/sys.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Timer class
|
||||
*/
|
||||
class PD_CORE_API Timer : public SmartCtor<Timer> {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param auto_start [default true] sets if timer should start after creation
|
||||
*/
|
||||
Timer(bool auto_start = true);
|
||||
/**
|
||||
* Unused Deconstructor
|
||||
*/
|
||||
~Timer() {}
|
||||
/**
|
||||
* Resume Timer if Paused
|
||||
*/
|
||||
void Rseume();
|
||||
/**
|
||||
* Pause Timer if not Paused
|
||||
*/
|
||||
void Pause();
|
||||
/**
|
||||
* Update Timer
|
||||
*/
|
||||
void Update();
|
||||
/**
|
||||
* Reset Timer
|
||||
*/
|
||||
void Reset();
|
||||
/**
|
||||
* Check if the Timer is Running
|
||||
* @return true if its running
|
||||
*/
|
||||
bool IsRunning() const;
|
||||
/**
|
||||
* Get 64 Bit milliseconds value
|
||||
* @return 64Bit millis
|
||||
*/
|
||||
u64 Get();
|
||||
/**
|
||||
* Get as Seconds
|
||||
* @return seconds as floating number
|
||||
*/
|
||||
double GetSeconds();
|
||||
|
||||
private:
|
||||
/** Start of the Timer */
|
||||
u64 start;
|
||||
/** Current Time */
|
||||
u64 now;
|
||||
/** Is Running */
|
||||
bool is_running = false;
|
||||
};
|
||||
#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 {
|
||||
/**
|
||||
* Timer class
|
||||
*/
|
||||
class PD_CORE_API Timer {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param auto_start [default true] sets if timer should start after creation
|
||||
*/
|
||||
Timer(bool auto_start = true);
|
||||
/**
|
||||
* Unused Deconstructor
|
||||
*/
|
||||
~Timer() {}
|
||||
|
||||
PD_SHARED(Timer);
|
||||
|
||||
/**
|
||||
* Resume Timer if Paused
|
||||
*/
|
||||
void Rseume();
|
||||
/**
|
||||
* Pause Timer if not Paused
|
||||
*/
|
||||
void Pause();
|
||||
/**
|
||||
* Update Timer
|
||||
*/
|
||||
void Update();
|
||||
/**
|
||||
* Reset Timer
|
||||
*/
|
||||
void Reset();
|
||||
/**
|
||||
* Check if the Timer is Running
|
||||
* @return true if its running
|
||||
*/
|
||||
bool IsRunning() const;
|
||||
/**
|
||||
* Get 64 Bit milliseconds value
|
||||
* @return 64Bit millis
|
||||
*/
|
||||
u64 Get();
|
||||
/**
|
||||
* Get as Seconds
|
||||
* @return seconds as floating number
|
||||
*/
|
||||
double GetSeconds();
|
||||
|
||||
/** Start of the Timer */
|
||||
u64 pStart;
|
||||
/** Current Time */
|
||||
u64 pNow;
|
||||
/** Is Running */
|
||||
bool pIsRunning = false;
|
||||
};
|
||||
} // namespace PD
|
512
include/pd/core/timetrace.hpp
Normal file → Executable file
512
include/pd/core/timetrace.hpp
Normal file → Executable file
@ -1,255 +1,259 @@
|
||||
#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 to calculate Maximum/Minimum and Average Timings
|
||||
*/
|
||||
class TimeStats : public SmartCtor<TimeStats> {
|
||||
public:
|
||||
/**
|
||||
* Constructor taking a lengh for the List
|
||||
* @param l Lengh of the data list
|
||||
*/
|
||||
TimeStats(int l) : len(l), val(l, 0) {}
|
||||
~TimeStats() = default;
|
||||
|
||||
/**
|
||||
* Add a New Value to the list
|
||||
* @param v value to add
|
||||
*/
|
||||
void Add(u64 v) {
|
||||
val[idx] = v;
|
||||
idx = next(idx);
|
||||
num_val = std::min(num_val + 1, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Avarage Num
|
||||
* @return Average
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Minimum Num
|
||||
* @return Minimum value
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Maximum Value
|
||||
* @return Max Value
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the List
|
||||
*/
|
||||
void Clear() {
|
||||
val.assign(len, 0);
|
||||
idx = 0;
|
||||
num_val = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Data Buffer
|
||||
* @return data bufer (not edidable)
|
||||
*/
|
||||
const std::vector<u64> &GetData() { return val; }
|
||||
/**
|
||||
* Access an element in the list [not edidable]
|
||||
* @return value to access
|
||||
*/
|
||||
const u64 &operator[](int i) { return val[smart_idx(i)]; }
|
||||
/**
|
||||
* Get List Lengh
|
||||
* @return Lengh
|
||||
*/
|
||||
const size_t GetLen() { return len; }
|
||||
/**
|
||||
* Get Number of Values
|
||||
* @return number of values
|
||||
*/
|
||||
const size_t GetNumValues() { return num_val; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* Get the Next Position to write to
|
||||
* @param c current position
|
||||
* @return next position
|
||||
*/
|
||||
size_t next(size_t c) const { return (c + 1) % len; }
|
||||
/**
|
||||
* Smart Indexing in for loops to make sure to
|
||||
* not index a value that was not set yet
|
||||
* @param v pos in for loop
|
||||
* @return indexing pos
|
||||
*/
|
||||
size_t smart_idx(size_t v) const { return (idx + len - num_val + v) % len; }
|
||||
|
||||
/** Lengh of the list */
|
||||
int len = 0;
|
||||
/** Value Storage */
|
||||
std::vector<u64> val;
|
||||
int idx = 0;
|
||||
int num_val = 0;
|
||||
};
|
||||
/**
|
||||
* Timatrace Functions
|
||||
*/
|
||||
namespace TT {
|
||||
/**
|
||||
* Data Structure for a TimeTrace Result
|
||||
*/
|
||||
class Res : public SmartCtor<Res> {
|
||||
public:
|
||||
/** Constructore that Inits a protocol at size of 60 frames */
|
||||
Res() { protocol = TimeStats::New(60); }
|
||||
~Res() = default;
|
||||
|
||||
/**
|
||||
* Setter for the ID (Name)
|
||||
* @param v ID of the Trace
|
||||
*/
|
||||
void SetID(const std::string &v) { id = v; }
|
||||
/**
|
||||
* Getter for the traces ID
|
||||
* @return Trace ID
|
||||
*/
|
||||
const std::string GetID() { return id; }
|
||||
/**
|
||||
* Setter for the Start Value
|
||||
* @param v start time
|
||||
*/
|
||||
void SetStart(u64 v) { start = v; }
|
||||
/**
|
||||
* Getter for the Start time
|
||||
* @return start time
|
||||
*/
|
||||
u64 GetStart() { return start; }
|
||||
/**
|
||||
* Setter for the End Time
|
||||
* @param v end time
|
||||
*/
|
||||
void SetEnd(u64 v) {
|
||||
end = v;
|
||||
protocol->Add(GetLastDiff());
|
||||
}
|
||||
/**
|
||||
* Getter for the End Time
|
||||
* @result end time
|
||||
*/
|
||||
u64 GetEnd() { return end; }
|
||||
|
||||
/**
|
||||
* Get Last Diffrence between end and start
|
||||
* @return end - start
|
||||
*/
|
||||
u64 GetLastDiff() { return end - start; }
|
||||
/**
|
||||
* Get Protcol Reference
|
||||
* @return Protocol Ref
|
||||
*/
|
||||
TimeStats::Ref GetProtocol() { return protocol; }
|
||||
|
||||
private:
|
||||
/** Trace ID */
|
||||
std::string id;
|
||||
/** Start time */
|
||||
u64 start;
|
||||
/** End Time */
|
||||
u64 end;
|
||||
/** Protocol */
|
||||
TimeStats::Ref protocol;
|
||||
};
|
||||
/**
|
||||
* Begin a Trace
|
||||
* @param id Name of the Trace
|
||||
*/
|
||||
PD_CORE_API void Beg(const std::string &id);
|
||||
/**
|
||||
* End a Trace
|
||||
* @param id Name of the Trace
|
||||
*/
|
||||
PD_CORE_API void End(const std::string &id);
|
||||
/**
|
||||
* Collect Start end end of the trace by tracking
|
||||
* when the Scope object goes out of scope
|
||||
*
|
||||
* Example:
|
||||
* ```cpp
|
||||
* void SomeFunction() {
|
||||
* // Create a Scoped Trace called "SomeFunc"
|
||||
* PD::TT::Scope st("SomeFunc");
|
||||
* // Do your functions stuff
|
||||
* // End at the end it goes out of
|
||||
* // scope which collects the end time
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
class Scope {
|
||||
public:
|
||||
/**
|
||||
* Constructor requiring a Name for the Trace
|
||||
* @param id Name of the Trace
|
||||
*/
|
||||
Scope(const std::string &id) {
|
||||
this->id = id;
|
||||
Beg(id);
|
||||
}
|
||||
/**
|
||||
* Deconstructor getting the end time when going out of scope
|
||||
*/
|
||||
~Scope() { End(id); }
|
||||
|
||||
private:
|
||||
/** Trace Name/ID */
|
||||
std::string id;
|
||||
};
|
||||
} // namespace TT
|
||||
#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 to calculate Maximum/Minimum and Average Timings
|
||||
*/
|
||||
class TimeStats {
|
||||
public:
|
||||
/**
|
||||
* Constructor taking a lengh for the List
|
||||
* @param l Lengh of the data list
|
||||
*/
|
||||
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
|
||||
*/
|
||||
void Add(u64 v) {
|
||||
val[idx] = v;
|
||||
idx = next(idx);
|
||||
num_val = std::min(num_val + 1, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Avarage Num
|
||||
* @return Average
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Minimum Num
|
||||
* @return Minimum value
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Maximum Value
|
||||
* @return Max Value
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the List
|
||||
*/
|
||||
void Clear() {
|
||||
val.assign(len, 0);
|
||||
idx = 0;
|
||||
num_val = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Data Buffer
|
||||
* @return data bufer (not edidable)
|
||||
*/
|
||||
const std::vector<u64> &GetData() { return val; }
|
||||
/**
|
||||
* Access an element in the list [not edidable]
|
||||
* @return value to access
|
||||
*/
|
||||
const u64 &operator[](int i) { return val[smart_idx(i)]; }
|
||||
/**
|
||||
* Get List Lengh
|
||||
* @return Lengh
|
||||
*/
|
||||
const size_t GetLen() { return len; }
|
||||
/**
|
||||
* Get Number of Values
|
||||
* @return number of values
|
||||
*/
|
||||
const size_t GetNumValues() { return num_val; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* Get the Next Position to write to
|
||||
* @param c current position
|
||||
* @return next position
|
||||
*/
|
||||
size_t next(size_t c) const { return (c + 1) % len; }
|
||||
/**
|
||||
* Smart Indexing in for loops to make sure to
|
||||
* not index a value that was not set yet
|
||||
* @param v pos in for loop
|
||||
* @return indexing pos
|
||||
*/
|
||||
size_t smart_idx(size_t v) const { return (idx + len - num_val + v) % len; }
|
||||
|
||||
/** Lengh of the list */
|
||||
int len = 0;
|
||||
/** Value Storage */
|
||||
std::vector<u64> val;
|
||||
int idx = 0;
|
||||
int num_val = 0;
|
||||
};
|
||||
/**
|
||||
* Timatrace Functions
|
||||
*/
|
||||
namespace TT {
|
||||
/**
|
||||
* Data Structure for a TimeTrace Result
|
||||
*/
|
||||
class Res {
|
||||
public:
|
||||
/** Constructore that Inits a protocol at size of 60 frames */
|
||||
Res(): start(0), end(0) { protocol = TimeStats::New(60); }
|
||||
~Res() = default;
|
||||
|
||||
PD_SHARED(Res);
|
||||
|
||||
/**
|
||||
* Setter for the ID (Name)
|
||||
* @param v ID of the Trace
|
||||
*/
|
||||
void SetID(const std::string &v) { id = v; }
|
||||
/**
|
||||
* Getter for the traces ID
|
||||
* @return Trace ID
|
||||
*/
|
||||
const std::string GetID() { return id; }
|
||||
/**
|
||||
* Setter for the Start Value
|
||||
* @param v start time
|
||||
*/
|
||||
void SetStart(u64 v) { start = v; }
|
||||
/**
|
||||
* Getter for the Start time
|
||||
* @return start time
|
||||
*/
|
||||
u64 GetStart() { return start; }
|
||||
/**
|
||||
* Setter for the End Time
|
||||
* @param v end time
|
||||
*/
|
||||
void SetEnd(u64 v) {
|
||||
end = v;
|
||||
protocol->Add(GetLastDiff());
|
||||
}
|
||||
/**
|
||||
* Getter for the End Time
|
||||
* @result end time
|
||||
*/
|
||||
u64 GetEnd() { return end; }
|
||||
|
||||
/**
|
||||
* Get Last Diffrence between end and start
|
||||
* @return end - start
|
||||
*/
|
||||
u64 GetLastDiff() { return end - start; }
|
||||
/**
|
||||
* Get Protcol Reference
|
||||
* @return Protocol Ref
|
||||
*/
|
||||
TimeStats::Ref GetProtocol() { return protocol; }
|
||||
|
||||
private:
|
||||
/** Trace ID */
|
||||
std::string id;
|
||||
/** Start time */
|
||||
u64 start;
|
||||
/** End Time */
|
||||
u64 end;
|
||||
/** Protocol */
|
||||
TimeStats::Ref protocol;
|
||||
};
|
||||
/**
|
||||
* Begin a Trace
|
||||
* @param id Name of the Trace
|
||||
*/
|
||||
PD_CORE_API void Beg(const std::string &id);
|
||||
/**
|
||||
* End a Trace
|
||||
* @param id Name of the Trace
|
||||
*/
|
||||
PD_CORE_API void End(const std::string &id);
|
||||
/**
|
||||
* Collect Start end end of the trace by tracking
|
||||
* when the Scope object goes out of scope
|
||||
*
|
||||
* Example:
|
||||
* ```cpp
|
||||
* void SomeFunction() {
|
||||
* // Create a Scoped Trace called "SomeFunc"
|
||||
* PD::TT::Scope st("SomeFunc");
|
||||
* // Do your functions stuff
|
||||
* // End at the end it goes out of
|
||||
* // scope which collects the end time
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
class Scope {
|
||||
public:
|
||||
/**
|
||||
* Constructor requiring a Name for the Trace
|
||||
* @param id Name of the Trace
|
||||
*/
|
||||
Scope(const std::string &id) {
|
||||
this->ID = id;
|
||||
Beg(id);
|
||||
}
|
||||
/**
|
||||
* Deconstructor getting the end time when going out of scope
|
||||
*/
|
||||
~Scope() { End(ID); }
|
||||
|
||||
private:
|
||||
/** Trace Name/ID */
|
||||
std::string ID;
|
||||
};
|
||||
} // namespace TT
|
||||
} // namespace PD
|
454
include/pd/core/tween.hpp
Normal file → Executable file
454
include/pd/core/tween.hpp
Normal file → Executable file
@ -1,228 +1,228 @@
|
||||
#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>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* D7 Tween Engine (or something like that)
|
||||
* @tparam T Any Numeric value
|
||||
*/
|
||||
template <typename T>
|
||||
class Tween {
|
||||
public:
|
||||
/**
|
||||
* Effects Table
|
||||
*/
|
||||
enum Effect {
|
||||
Linear, ///< Linear Movement [works]
|
||||
EaseInQuad, ///< EaseInQuad Movement [works]
|
||||
EaseOutQuad, ///< EaseOutQuad Movement [works]
|
||||
EaseInOutQuad, ///< EaseInOutQuad Movement [works]
|
||||
EaseInCubic, ///< EaseInCubic Movement [not tested]
|
||||
EaseOutCubic, ///< EaseOutCubic Movement [not tested]
|
||||
EaseInOutCubic, ///< EaseInOutCubic Movement [disabled]
|
||||
EaseInSine, ///< EaseInSine Movement [works]
|
||||
EaseOutSine, ///< EaseOutSine Movement [works]
|
||||
EaseInOutSine, ///< EaseInOutSine Movement [not tested]
|
||||
};
|
||||
Tween() = default;
|
||||
~Tween() = default;
|
||||
|
||||
/**
|
||||
* Update Tween
|
||||
* @param delta deltatime
|
||||
*/
|
||||
void Update(float delta) {
|
||||
time += delta / 1000.f;
|
||||
if (time > tend) {
|
||||
finished = true;
|
||||
time = tend;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Tween is finished
|
||||
* @return true if finished
|
||||
*/
|
||||
bool IsFinished() const { return finished; }
|
||||
|
||||
/**
|
||||
* Force finish the animation
|
||||
* @return Class reference
|
||||
*/
|
||||
Tween& Finish() {
|
||||
time = tend;
|
||||
finished = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Start Value
|
||||
* @tparam T datatype of the Tween
|
||||
* @param start Start Value
|
||||
* @return class Reference
|
||||
*/
|
||||
Tween& From(const T& start) {
|
||||
Reset();
|
||||
this->start = start;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Set End Value
|
||||
* @tparam T datatype of the Tween
|
||||
* @param end End Value
|
||||
* @return class Reference
|
||||
*/
|
||||
Tween& To(const T& end) {
|
||||
Reset();
|
||||
this->end = end;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Set the Duration (in seconds)
|
||||
* @param seconds Duration
|
||||
* @return class Reference
|
||||
*/
|
||||
Tween& In(float seconds) {
|
||||
Reset();
|
||||
tend = seconds;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Set Effect of the Tween
|
||||
* @param e Effect
|
||||
* @return class Reference
|
||||
*/
|
||||
Tween& As(const Effect& e) {
|
||||
effect = e;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Reset to time 0
|
||||
* @return class Reference
|
||||
*/
|
||||
Tween& Reset() {
|
||||
finished = false;
|
||||
time = 0.f;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Get the Prograss in percent (0.0 to 1.0) of the tween
|
||||
* @return progress value
|
||||
*/
|
||||
float Progress() const { return time / tend; }
|
||||
|
||||
/**
|
||||
* Swap Start and end Position of the Tween
|
||||
* @return class reference
|
||||
*/
|
||||
Tween& Swap() {
|
||||
T temp = start;
|
||||
start = end;
|
||||
end = temp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
T Get() const {
|
||||
float t = 0.f;
|
||||
switch (effect) {
|
||||
case EaseInQuad:
|
||||
t = time / tend;
|
||||
return (end - start) * t * t + start;
|
||||
break;
|
||||
case EaseOutQuad:
|
||||
t = time / tend;
|
||||
return -(end - start) * t * (t - 2) + start;
|
||||
break;
|
||||
case EaseInOutQuad:
|
||||
t = time / (tend / 2);
|
||||
if (t < 1) return (end - start) / 2 * t * t + start;
|
||||
t--;
|
||||
return -(end - start) / 2 * (t * (t - 2) - 1) + start;
|
||||
break;
|
||||
case EaseInCubic:
|
||||
t = time / tend;
|
||||
return (end - start) * t * t * t + start;
|
||||
break;
|
||||
case EaseOutCubic:
|
||||
t = time / tend;
|
||||
t--;
|
||||
return (end - start) * (t * t * t + 1) + start;
|
||||
break;
|
||||
// case EaseInOutCubic:
|
||||
// t = time / (tend / 2);
|
||||
// if (t < 1) return (end - start) / 2 * t * t * t + start;
|
||||
// t--;
|
||||
// return (end - start) / 2 * (t * t * t * 2) + start;
|
||||
// break;
|
||||
case EaseInSine:
|
||||
return -(end - start) * cos(time / tend * (M_PI / 2)) + (end - start) +
|
||||
start;
|
||||
break;
|
||||
case EaseOutSine:
|
||||
return (end - start) * sin(time / tend * (M_PI / 2)) + start;
|
||||
break;
|
||||
case EaseInOutSine:
|
||||
return -(end - start) / 2 * (cos(M_PI * time / tend) - 1) + start;
|
||||
break;
|
||||
|
||||
default: // Linear
|
||||
return (end - start) * (time / tend) + start;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator that returns the current value calculated
|
||||
* by time and effect
|
||||
*/
|
||||
operator T() const { return Get(); }
|
||||
|
||||
private:
|
||||
/** Animation Effect */
|
||||
Effect effect;
|
||||
/** Time */
|
||||
float time = 0.f;
|
||||
/**
|
||||
* End time
|
||||
* Defaulting to one to prevent div zero
|
||||
* without a safetey check
|
||||
* not implementing one cause if the user is
|
||||
* Writing a In(0.f) its their fault
|
||||
*/
|
||||
float tend = 1.f;
|
||||
/** Start value */
|
||||
T start;
|
||||
/** end value */
|
||||
T end;
|
||||
/** is finished value */
|
||||
bool finished = false;
|
||||
};
|
||||
#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>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* D7 Tween Engine (or something like that)
|
||||
* @tparam T Any Numeric value
|
||||
*/
|
||||
template <typename T>
|
||||
class Tween {
|
||||
public:
|
||||
/**
|
||||
* Effects Table
|
||||
*/
|
||||
enum Effect {
|
||||
Linear, ///< Linear Movement [works]
|
||||
EaseInQuad, ///< EaseInQuad Movement [works]
|
||||
EaseOutQuad, ///< EaseOutQuad Movement [works]
|
||||
EaseInOutQuad, ///< EaseInOutQuad Movement [works]
|
||||
EaseInCubic, ///< EaseInCubic Movement [not tested]
|
||||
EaseOutCubic, ///< EaseOutCubic Movement [not tested]
|
||||
EaseInOutCubic, ///< EaseInOutCubic Movement [disabled]
|
||||
EaseInSine, ///< EaseInSine Movement [works]
|
||||
EaseOutSine, ///< EaseOutSine Movement [works]
|
||||
EaseInOutSine, ///< EaseInOutSine Movement [not tested]
|
||||
};
|
||||
Tween() = default;
|
||||
~Tween() = default;
|
||||
|
||||
/**
|
||||
* Update Tween
|
||||
* @param delta deltatime
|
||||
*/
|
||||
void Update(float delta) {
|
||||
time += delta / 1000.f;
|
||||
if (time > tend) {
|
||||
finished = true;
|
||||
time = tend;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Tween is finished
|
||||
* @return true if finished
|
||||
*/
|
||||
bool IsFinished() const { return finished; }
|
||||
|
||||
/**
|
||||
* Force finish the animation
|
||||
* @return Class reference
|
||||
*/
|
||||
Tween& Finish() {
|
||||
time = tend;
|
||||
finished = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Start Value
|
||||
* @tparam T datatype of the Tween
|
||||
* @param start Start Value
|
||||
* @return class Reference
|
||||
*/
|
||||
Tween& From(const T& start) {
|
||||
Reset();
|
||||
this->start = start;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Set End Value
|
||||
* @tparam T datatype of the Tween
|
||||
* @param end End Value
|
||||
* @return class Reference
|
||||
*/
|
||||
Tween& To(const T& end) {
|
||||
Reset();
|
||||
this->end = end;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Set the Duration (in seconds)
|
||||
* @param seconds Duration
|
||||
* @return class Reference
|
||||
*/
|
||||
Tween& In(float seconds) {
|
||||
Reset();
|
||||
tend = seconds;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Set Effect of the Tween
|
||||
* @param e Effect
|
||||
* @return class Reference
|
||||
*/
|
||||
Tween& As(const Effect& e) {
|
||||
effect = e;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Reset to time 0
|
||||
* @return class Reference
|
||||
*/
|
||||
Tween& Reset() {
|
||||
finished = false;
|
||||
time = 0.f;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Get the Prograss in percent (0.0 to 1.0) of the tween
|
||||
* @return progress value
|
||||
*/
|
||||
float Progress() const { return time / tend; }
|
||||
|
||||
/**
|
||||
* Swap Start and end Position of the Tween
|
||||
* @return class reference
|
||||
*/
|
||||
Tween& Swap() {
|
||||
T temp = start;
|
||||
start = end;
|
||||
end = temp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
T Get() const {
|
||||
float t = 0.f;
|
||||
switch (effect) {
|
||||
case EaseInQuad:
|
||||
t = time / tend;
|
||||
return (end - start) * t * t + start;
|
||||
break;
|
||||
case EaseOutQuad:
|
||||
t = time / tend;
|
||||
return -(end - start) * t * (t - 2) + start;
|
||||
break;
|
||||
case EaseInOutQuad:
|
||||
t = time / (tend / 2);
|
||||
if (t < 1) return (end - start) / 2 * t * t + start;
|
||||
t--;
|
||||
return -(end - start) / 2 * (t * (t - 2) - 1) + start;
|
||||
break;
|
||||
case EaseInCubic:
|
||||
t = time / tend;
|
||||
return (end - start) * t * t * t + start;
|
||||
break;
|
||||
case EaseOutCubic:
|
||||
t = time / tend;
|
||||
t--;
|
||||
return (end - start) * (t * t * t + 1) + start;
|
||||
break;
|
||||
// case EaseInOutCubic:
|
||||
// t = time / (tend / 2);
|
||||
// if (t < 1) return (end - start) / 2 * t * t * t + start;
|
||||
// t--;
|
||||
// return (end - start) / 2 * (t * t * t * 2) + start;
|
||||
// break;
|
||||
case EaseInSine:
|
||||
return -(end - start) * cos(time / tend * (M_PI / 2)) + (end - start) +
|
||||
start;
|
||||
break;
|
||||
case EaseOutSine:
|
||||
return (end - start) * sin(time / tend * (M_PI / 2)) + start;
|
||||
break;
|
||||
case EaseInOutSine:
|
||||
return -(end - start) / 2 * (cos(M_PI * time / tend) - 1) + start;
|
||||
break;
|
||||
|
||||
default: // Linear
|
||||
return (end - start) * (time / tend) + start;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator that returns the current value calculated
|
||||
* by time and effect
|
||||
*/
|
||||
operator T() const { return Get(); }
|
||||
|
||||
private:
|
||||
/** Animation Effect */
|
||||
Effect effect;
|
||||
/** Time */
|
||||
float time = 0.f;
|
||||
/**
|
||||
* End time
|
||||
* Defaulting to one to prevent div zero
|
||||
* without a safetey check
|
||||
* not implementing one cause if the user is
|
||||
* Writing a In(0.f) its their fault
|
||||
*/
|
||||
float tend = 1.f;
|
||||
/** Start value */
|
||||
T start;
|
||||
/** end value */
|
||||
T end;
|
||||
/** is finished value */
|
||||
bool finished = false;
|
||||
};
|
||||
} // namespace PD
|
36
include/pd/core/vec.hpp
Normal file → Executable file
36
include/pd/core/vec.hpp
Normal file → Executable file
@ -2,7 +2,8 @@
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||
|
||||
Copyright (c) 2024 - 2025 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
|
||||
@ -23,6 +24,37 @@ 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/vec2.hpp>
|
||||
#include <pd/core/vec3.hpp>
|
||||
#include <pd/core/vec4.hpp>
|
||||
#include <pd/core/vec4.hpp>
|
||||
|
||||
/** Define Formatters for C++ 20 */
|
||||
|
||||
/**
|
||||
* WHY DOES MSVC ALWAYS NEED THESE EXTRA THINGS
|
||||
*/
|
||||
|
||||
template <typename T, typename CharT>
|
||||
struct std::formatter<PD::vec2<T>, CharT> : std::formatter<T, CharT> {
|
||||
template <typename FormatContext>
|
||||
auto format(const PD::vec2<T>& v, FormatContext& ctx) const {
|
||||
return std::format_to(ctx.out(), "({}, {})", v.x, v.y);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename CharT>
|
||||
struct std::formatter<PD::vec3<T>, CharT> : std::formatter<T, CharT> {
|
||||
template <typename FormatContext>
|
||||
auto format(const PD::vec3<T>& v, FormatContext& ctx) const {
|
||||
return std::format_to(ctx.out(), "({}, {}, {})", v.x, v.y, v.z);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename CharT>
|
||||
struct std::formatter<PD::vec4<T>, CharT> : std::formatter<T, CharT> {
|
||||
template <typename FormatContext>
|
||||
auto format(const PD::vec4<T>& v, FormatContext& ctx) const {
|
||||
return std::format_to(ctx.out(), "({}, {}, {}, {})", v.x, v.y, v.z, v.w);
|
||||
}
|
||||
};
|
299
include/pd/core/vec2.hpp
Normal file → Executable file
299
include/pd/core/vec2.hpp
Normal file → Executable file
@ -1,135 +1,164 @@
|
||||
#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 {
|
||||
template <typename T>
|
||||
class vec2 {
|
||||
public:
|
||||
// SECTION: Constructors //
|
||||
|
||||
vec2() = default;
|
||||
vec2(T v) {
|
||||
x = v;
|
||||
y = v;
|
||||
}
|
||||
vec2(T x, T y) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
vec2(const vec2<T> &v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
}
|
||||
|
||||
// SECTION: Operators //
|
||||
|
||||
// ADD //
|
||||
|
||||
vec2 &operator+=(T v) {
|
||||
x += v;
|
||||
y += v;
|
||||
return *this;
|
||||
}
|
||||
vec2 &operator+=(const vec2 &v) {
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
return *this;
|
||||
}
|
||||
vec2 operator+(T v) const { return vec2(x + v, y + v); }
|
||||
vec2 operator+(vec2 v) const { return vec2(x + v.x, y + v.y); }
|
||||
|
||||
// SUB //
|
||||
|
||||
vec2 &operator-=(T v) {
|
||||
x -= v;
|
||||
y -= v;
|
||||
return *this;
|
||||
}
|
||||
vec2 &operator-=(const vec2 &v) {
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
return *this;
|
||||
}
|
||||
vec2 operator-(T v) const { return vec2(x - v, y - v); }
|
||||
vec2 operator-(vec2 v) const { return vec2(x - v.x, y - v.y); }
|
||||
|
||||
// MUL //
|
||||
|
||||
vec2 &operator*=(T v) {
|
||||
x *= v;
|
||||
y *= v;
|
||||
return *this;
|
||||
}
|
||||
vec2 &operator*=(const vec2 &v) {
|
||||
x *= v.x;
|
||||
y *= v.y;
|
||||
return *this;
|
||||
}
|
||||
vec2 operator*(T v) const { return vec2(x * v, y * v); }
|
||||
vec2 operator*(vec2 v) const { return vec2(x * v.x, y * v.y); }
|
||||
|
||||
// DIV //
|
||||
|
||||
vec2 &operator/=(T v) {
|
||||
x /= v;
|
||||
y /= v;
|
||||
return *this;
|
||||
}
|
||||
vec2 &operator/=(const vec2 &v) {
|
||||
x /= v.x;
|
||||
y /= v.y;
|
||||
return *this;
|
||||
}
|
||||
vec2 operator/(T v) const { return vec2(x / v, y / v); }
|
||||
vec2 operator/(vec2 v) const { return vec2(x / v.x, y / v.y); }
|
||||
|
||||
// Make Negative //
|
||||
vec2 operator-() const { return vec2(-x, -y); }
|
||||
|
||||
bool operator==(const vec2 &v) const { return x == v.x && y == v.y; }
|
||||
bool operator!=(const vec2 &v) const { return !(*this == v); }
|
||||
|
||||
// SECTION: Additional Functions //
|
||||
|
||||
float Len() const { return sqrt(SqLen()); }
|
||||
float SqLen() const { return x * x + y * y; }
|
||||
void Swap() {
|
||||
T t = x;
|
||||
x = y;
|
||||
y = t;
|
||||
}
|
||||
|
||||
// SECTION: DATA //
|
||||
T x = 0;
|
||||
T y = 0;
|
||||
};
|
||||
|
||||
using dvec2 = vec2<double>;
|
||||
using fvec2 = vec2<float>;
|
||||
using ivec2 = vec2<int>;
|
||||
} // namespace PD
|
||||
#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.
|
||||
*/
|
||||
|
||||
// This file is generated by lazyvec
|
||||
#include <pd/core/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
class vec2 {
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
|
||||
vec2() : x(0), y(0) {}
|
||||
template <typename T1>
|
||||
vec2(T1 v) {
|
||||
x = (T)v;
|
||||
y = (T)v;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2(vec2<T1> v) {
|
||||
x = (T)v.x;
|
||||
y = (T)v.y;
|
||||
}
|
||||
|
||||
vec2(T x, T y) : x(x), y(y) {}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T>& operator+=(T1 v) {
|
||||
x += (T)v;
|
||||
y += (T)v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T>& operator+=(const vec2<T1>& v) {
|
||||
x += (T)v.x;
|
||||
y += (T)v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T> operator+(T1 v) const {
|
||||
return vec2<T>(x + (T)v, y + (T)v);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T> operator+(const vec2<T1>& v) const {
|
||||
return vec2<T>(x + (T)v.x, y + (T)v.y);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T>& operator-=(T1 v) {
|
||||
x -= (T)v;
|
||||
y -= (T)v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T>& operator-=(const vec2<T1>& v) {
|
||||
x -= (T)v.x;
|
||||
y -= (T)v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T> operator-(T1 v) const {
|
||||
return vec2<T>(x - (T)v, y - (T)v);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T> operator-(const vec2<T1>& v) const {
|
||||
return vec2<T>(x - (T)v.x, y - (T)v.y);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T>& operator*=(T1 v) {
|
||||
x *= (T)v;
|
||||
y *= (T)v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T>& operator*=(const vec2<T1>& v) {
|
||||
x *= (T)v.x;
|
||||
y *= (T)v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T> operator*(T1 v) const {
|
||||
return vec2<T>(x * (T)v, y * (T)v);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T> operator*(const vec2<T1>& v) const {
|
||||
return vec2<T>(x * (T)v.x, y * (T)v.y);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T>& operator/=(T1 v) {
|
||||
x /= (T)v;
|
||||
y /= (T)v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T>& operator/=(const vec2<T1>& v) {
|
||||
x /= (T)v.x;
|
||||
y /= (T)v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T> operator/(T1 v) const {
|
||||
return vec2<T>(x / (T)v, y / (T)v);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec2<T> operator/(const vec2<T1>& v) const {
|
||||
return vec2<T>(x / (T)v.x, y / (T)v.y);
|
||||
}
|
||||
|
||||
vec2 operator-() const { return vec2(-x, -y); }
|
||||
|
||||
bool operator==(const vec2& v) const { return x == v.x && y == v.y; }
|
||||
bool operator!=(const vec2& v) const { return !(*this == v); }
|
||||
|
||||
double Len() const { return std::sqrt(SqLen()); }
|
||||
double SqLen() const { return x * x + y * y; }
|
||||
|
||||
void SwapXY() {
|
||||
T t = x;
|
||||
x = y;
|
||||
y = t;
|
||||
}
|
||||
};
|
||||
using fvec2 = vec2<float>;
|
||||
using dvec2 = vec2<double>;
|
||||
using ivec2 = vec2<int>;
|
||||
} // namespace PD
|
||||
|
347
include/pd/core/vec3.hpp
Normal file → Executable file
347
include/pd/core/vec3.hpp
Normal file → Executable file
@ -1,160 +1,187 @@
|
||||
#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/vec2.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
class vec3 {
|
||||
public:
|
||||
// SECTION: Constructors //
|
||||
|
||||
vec3() = default;
|
||||
vec3(T v) {
|
||||
x = v;
|
||||
y = v;
|
||||
z = v;
|
||||
}
|
||||
vec3(T x, T y, T z) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
vec3(const vec3 &v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
}
|
||||
|
||||
// SECTION: Operators //
|
||||
|
||||
// ADD //
|
||||
|
||||
vec3 &operator+=(T v) {
|
||||
x += v;
|
||||
y += v;
|
||||
z += v;
|
||||
return *this;
|
||||
}
|
||||
vec3 &operator+=(const vec3 &v) {
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
z += v.z;
|
||||
return *this;
|
||||
}
|
||||
vec3 operator+(T v) const { return vec3(x + v, y + v, z + v); }
|
||||
vec3 operator+(vec3 v) const { return vec3(x + v.x, y + v.y, z + v.z); }
|
||||
|
||||
// SUB //
|
||||
|
||||
vec3 &operator-=(T v) {
|
||||
x -= v;
|
||||
y -= v;
|
||||
z -= v;
|
||||
return *this;
|
||||
}
|
||||
vec3 &operator-=(const vec3 &v) {
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
z -= v.z;
|
||||
return *this;
|
||||
}
|
||||
vec3 operator-(T v) const { return vec3(x - v, y - v, z - v); }
|
||||
vec3 operator-(vec3 v) const { return vec3(x - v.x, y - v.y, z - v.z); }
|
||||
|
||||
// MUL //
|
||||
|
||||
vec3 &operator*=(T v) {
|
||||
x *= v;
|
||||
y *= v;
|
||||
z *= v;
|
||||
return *this;
|
||||
}
|
||||
vec3 &operator*=(const vec3 &v) {
|
||||
x *= v.x;
|
||||
y *= v.y;
|
||||
z *= v.z;
|
||||
return *this;
|
||||
}
|
||||
vec3 operator*(T v) const { return vec3(x * v, y * v, z * v); }
|
||||
vec3 operator*(vec3 v) const { return vec3(x * v.x, y * v.y, z * v.z); }
|
||||
|
||||
// DIV //
|
||||
|
||||
vec3 &operator/=(T v) {
|
||||
x /= v;
|
||||
y /= v;
|
||||
z /= v;
|
||||
return *this;
|
||||
}
|
||||
vec3 &operator/=(const vec3 &v) {
|
||||
x /= v.x;
|
||||
y /= v.y;
|
||||
z /= v.z;
|
||||
return *this;
|
||||
}
|
||||
vec3 operator/(T v) const { return vec3(x / v, y / v, z / v); }
|
||||
vec3 operator/(vec3 v) const { return vec3(x / v.x, y / v.y, z / v.z); }
|
||||
|
||||
// Make Negative //
|
||||
vec3 operator-() const { return vec3(-x, -y, -z); }
|
||||
|
||||
bool operator==(const vec3 &v) const {
|
||||
return x == v.x && y == v.y && z == v.z;
|
||||
}
|
||||
bool operator!=(const vec3 &v) const { return !(*this == v); }
|
||||
|
||||
// SECTION: Additional Functions //
|
||||
|
||||
float Len() const { return sqrt(SqLen()); }
|
||||
float SqLen() const { return x * x + y * y + z * z; }
|
||||
void SwapXY() {
|
||||
T t = x;
|
||||
x = y;
|
||||
y = t;
|
||||
}
|
||||
void SwapYZ() {
|
||||
T t = z;
|
||||
z = y;
|
||||
y = t;
|
||||
}
|
||||
void SwapXZ() {
|
||||
T t = z;
|
||||
z = x;
|
||||
x = t;
|
||||
}
|
||||
|
||||
// SECTION: DATA //
|
||||
T x = 0;
|
||||
T y = 0;
|
||||
T z = 0;
|
||||
};
|
||||
|
||||
using dvec3 = vec3<double>;
|
||||
using fvec3 = vec3<float>;
|
||||
using ivec3 = vec3<int>;
|
||||
} // namespace PD
|
||||
#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.
|
||||
*/
|
||||
|
||||
// This file is generated by lazyvec
|
||||
#include <pd/core/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
class vec3 {
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
|
||||
vec3() : x(0), y(0), z(0) {}
|
||||
template <typename T1>
|
||||
explicit vec3(T1 v) {
|
||||
x = (T)v;
|
||||
y = (T)v;
|
||||
z = (T)v;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
explicit vec3(vec3<T1> v) {
|
||||
x = (T)v.x;
|
||||
y = (T)v.y;
|
||||
z = (T)v.z;
|
||||
}
|
||||
|
||||
vec3(T x, T y, T z) : x(x), y(y), z(z) {}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T>& operator+=(T1 v) {
|
||||
x += (T)v;
|
||||
y += (T)v;
|
||||
z += (T)v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T>& operator+=(const vec3<T1>& v) {
|
||||
x += (T)v.x;
|
||||
y += (T)v.y;
|
||||
z += (T)v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T> operator+(T1 v) const {
|
||||
return vec3<T>(x + (T)v, y + (T)v, z + (T)v);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T> operator+(const vec3<T1>& v) const {
|
||||
return vec3<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T>& operator-=(T1 v) {
|
||||
x -= (T)v;
|
||||
y -= (T)v;
|
||||
z -= (T)v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T>& operator-=(const vec3<T1>& v) {
|
||||
x -= (T)v.x;
|
||||
y -= (T)v.y;
|
||||
z -= (T)v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T> operator-(T1 v) const {
|
||||
return vec3<T>(x - (T)v, y - (T)v, z - (T)v);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T> operator-(const vec3<T1>& v) const {
|
||||
return vec3<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T>& operator*=(T1 v) {
|
||||
x *= (T)v;
|
||||
y *= (T)v;
|
||||
z *= (T)v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T>& operator*=(const vec3<T1>& v) {
|
||||
x *= (T)v.x;
|
||||
y *= (T)v.y;
|
||||
z *= (T)v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T> operator*(T1 v) const {
|
||||
return vec3<T>(x * (T)v, y * (T)v, z * (T)v);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T> operator*(const vec3<T1>& v) const {
|
||||
return vec3<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T>& operator/=(T1 v) {
|
||||
x /= (T)v;
|
||||
y /= (T)v;
|
||||
z /= (T)v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T>& operator/=(const vec3<T1>& v) {
|
||||
x /= (T)v.x;
|
||||
y /= (T)v.y;
|
||||
z /= (T)v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T> operator/(T1 v) const {
|
||||
return vec3<T>(x / (T)v, y / (T)v, z / (T)v);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec3<T> operator/(const vec3<T1>& v) const {
|
||||
return vec3<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z);
|
||||
}
|
||||
|
||||
vec3 operator-() const { return vec3(-x, -y, -z); }
|
||||
|
||||
bool operator==(const vec3& v) const {
|
||||
return x == v.x && y == v.y && z == v.z;
|
||||
}
|
||||
bool operator!=(const vec3& v) const { return !(*this == v); }
|
||||
|
||||
double Len() const { return std::sqrt(SqLen()); }
|
||||
double SqLen() const { return x * x + y * y + z * z; }
|
||||
|
||||
void SwapXY() {
|
||||
T t = x;
|
||||
x = y;
|
||||
y = t;
|
||||
}
|
||||
void SwapXZ() {
|
||||
T t = x;
|
||||
x = z;
|
||||
z = t;
|
||||
}
|
||||
void SwapYZ() {
|
||||
T t = y;
|
||||
y = z;
|
||||
z = t;
|
||||
}
|
||||
};
|
||||
using fvec3 = vec3<float>;
|
||||
using dvec3 = vec3<double>;
|
||||
using ivec3 = vec3<int>;
|
||||
} // namespace PD
|
||||
|
416
include/pd/core/vec4.hpp
Normal file → Executable file
416
include/pd/core/vec4.hpp
Normal file → Executable file
@ -1,193 +1,223 @@
|
||||
#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/vec3.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
class vec4 {
|
||||
public:
|
||||
// SECTION: Constructors //
|
||||
|
||||
vec4() = default;
|
||||
vec4(T v) {
|
||||
x = v;
|
||||
y = v;
|
||||
z = v;
|
||||
w = v;
|
||||
}
|
||||
vec4(T x, T y, T z, T w) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
this->w = w;
|
||||
}
|
||||
|
||||
vec4(const vec4 &v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
w = v.w;
|
||||
}
|
||||
|
||||
vec4(const vec2<T> &xy, const vec2<T> &zw) {
|
||||
x = xy.x;
|
||||
y = xy.y;
|
||||
z = zw.x;
|
||||
w = zw.y;
|
||||
}
|
||||
|
||||
// SECTION: Operators //
|
||||
|
||||
// ADD //
|
||||
|
||||
vec4 &operator+=(T v) {
|
||||
x += v;
|
||||
y += v;
|
||||
z += v;
|
||||
w += v;
|
||||
return *this;
|
||||
}
|
||||
vec4 &operator+=(const vec4<T> &v) {
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
z += v.z;
|
||||
w += v.w;
|
||||
return *this;
|
||||
}
|
||||
vec4 operator+(T v) const { return vec4<T>(x + v, y + v, z + v, w + v); }
|
||||
vec4 operator+(vec4 v) const {
|
||||
return vec4(x + v.x, y + v.y, z + v.z, w + v.w);
|
||||
}
|
||||
|
||||
// SUB //
|
||||
|
||||
vec4 &operator-=(T v) {
|
||||
x -= v;
|
||||
y -= v;
|
||||
z -= v;
|
||||
w -= v;
|
||||
return *this;
|
||||
}
|
||||
vec4 &operator-=(const vec4 &v) {
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
z -= v.z;
|
||||
w -= v.w;
|
||||
return *this;
|
||||
}
|
||||
vec4 operator-(T v) const { return vec4(x - v, y - v, z - v, w - v); }
|
||||
vec4 operator-(vec4 v) const {
|
||||
return vec4(x - v.x, y - v.y, z - v.z, w - v.w);
|
||||
}
|
||||
|
||||
// MUL //
|
||||
|
||||
vec4 &operator*=(T v) {
|
||||
x *= v;
|
||||
y *= v;
|
||||
z *= v;
|
||||
w *= v;
|
||||
return *this;
|
||||
}
|
||||
vec4 &operator*=(const vec4 &v) {
|
||||
x *= v.x;
|
||||
y *= v.y;
|
||||
z *= v.z;
|
||||
w *= v.w;
|
||||
return *this;
|
||||
}
|
||||
vec4 operator*(T v) const { return vec4(x * v, y * v, z * v, w * v); }
|
||||
vec4 operator*(vec4 v) const {
|
||||
return vec4(x * v.x, y * v.y, z * v.z, w * v.w);
|
||||
}
|
||||
|
||||
// DIV //
|
||||
|
||||
vec4 &operator/=(T v) {
|
||||
x /= v;
|
||||
y /= v;
|
||||
z /= v;
|
||||
w /= v;
|
||||
return *this;
|
||||
}
|
||||
vec4 &operator/=(const vec4 &v) {
|
||||
x /= v.x;
|
||||
y /= v.y;
|
||||
z /= v.z;
|
||||
w /= v.w;
|
||||
return *this;
|
||||
}
|
||||
vec4 operator/(T v) const { return vec4(x / v, y / v, z / v, w / v); }
|
||||
vec4 operator/(vec4 v) const {
|
||||
return vec4(x / v.x, y / v.y, z / v.z, w / v.w);
|
||||
}
|
||||
|
||||
// Make Negative //
|
||||
vec4 operator-() const { return vec4(-x, -y, -z, -w); }
|
||||
|
||||
bool operator==(const vec4 &v) const {
|
||||
return x == v.x && y == v.y && z == v.z && w == v.w;
|
||||
}
|
||||
bool operator!=(const vec4 &v) const { return !(*this == v); }
|
||||
|
||||
// SECTION: Additional Functions //
|
||||
|
||||
float Len() const { return sqrt(SqLen()); }
|
||||
float SqLen() const { return x * x + y * y + z * z + w * w; }
|
||||
void SwapXY() {
|
||||
T t = x;
|
||||
x = y;
|
||||
y = t;
|
||||
}
|
||||
void SwapYZ() {
|
||||
T t = z;
|
||||
z = y;
|
||||
y = t;
|
||||
}
|
||||
void SwapXZ() {
|
||||
T t = z;
|
||||
z = x;
|
||||
x = t;
|
||||
}
|
||||
// Adding ZW (to lazy to add all of those yet)
|
||||
void SwapZW() {
|
||||
T t = w;
|
||||
w = z;
|
||||
z = t;
|
||||
}
|
||||
|
||||
// SECTION: DATA //
|
||||
T x = 0;
|
||||
T y = 0;
|
||||
T z = 0;
|
||||
T w = 0;
|
||||
};
|
||||
|
||||
using dvec4 = vec4<double>;
|
||||
using fvec4 = vec4<float>;
|
||||
using ivec4 = vec4<int>;
|
||||
} // namespace PD
|
||||
#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.
|
||||
*/
|
||||
|
||||
// This file is generated by lazyvec
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/core/vec2.hpp> // Extended
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
class vec4 {
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
T w;
|
||||
|
||||
vec4() : x(0), y(0), z(0), w(0) {}
|
||||
template <typename T1>
|
||||
explicit vec4(T1 v) {
|
||||
x = (T)v;
|
||||
y = (T)v;
|
||||
z = (T)v;
|
||||
w = (T)v;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
explicit vec4(vec4<T1> v) {
|
||||
x = (T)v.x;
|
||||
y = (T)v.y;
|
||||
z = (T)v.z;
|
||||
w = (T)v.w;
|
||||
}
|
||||
|
||||
/** Extended Constructor */
|
||||
template <typename T1>
|
||||
explicit vec4(vec2<T1> a, vec2<T1> b) {
|
||||
x = (T)a.x;
|
||||
y = (T)a.y;
|
||||
z = (T)b.x;
|
||||
w = (T)b.y;
|
||||
}
|
||||
|
||||
vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T>& operator+=(T1 v) {
|
||||
x += (T)v;
|
||||
y += (T)v;
|
||||
z += (T)v;
|
||||
w += (T)v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T>& operator+=(const vec4<T1>& v) {
|
||||
x += (T)v.x;
|
||||
y += (T)v.y;
|
||||
z += (T)v.z;
|
||||
w += (T)v.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T> operator+(T1 v) const {
|
||||
return vec4<T>(x + (T)v, y + (T)v, z + (T)v, w + (T)v);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T> operator+(const vec4<T1>& v) const {
|
||||
return vec4<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z, w + (T)v.w);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T>& operator-=(T1 v) {
|
||||
x -= (T)v;
|
||||
y -= (T)v;
|
||||
z -= (T)v;
|
||||
w -= (T)v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T>& operator-=(const vec4<T1>& v) {
|
||||
x -= (T)v.x;
|
||||
y -= (T)v.y;
|
||||
z -= (T)v.z;
|
||||
w -= (T)v.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T> operator-(T1 v) const {
|
||||
return vec4<T>(x - (T)v, y - (T)v, z - (T)v, w - (T)v);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T> operator-(const vec4<T1>& v) const {
|
||||
return vec4<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z, w - (T)v.w);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T>& operator*=(T1 v) {
|
||||
x *= (T)v;
|
||||
y *= (T)v;
|
||||
z *= (T)v;
|
||||
w *= (T)v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T>& operator*=(const vec4<T1>& v) {
|
||||
x *= (T)v.x;
|
||||
y *= (T)v.y;
|
||||
z *= (T)v.z;
|
||||
w *= (T)v.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T> operator*(T1 v) const {
|
||||
return vec4<T>(x * (T)v, y * (T)v, z * (T)v, w * (T)v);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T> operator*(const vec4<T1>& v) const {
|
||||
return vec4<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z, w * (T)v.w);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T>& operator/=(T1 v) {
|
||||
x /= (T)v;
|
||||
y /= (T)v;
|
||||
z /= (T)v;
|
||||
w /= (T)v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T>& operator/=(const vec4<T1>& v) {
|
||||
x /= (T)v.x;
|
||||
y /= (T)v.y;
|
||||
z /= (T)v.z;
|
||||
w /= (T)v.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T> operator/(T1 v) const {
|
||||
return vec4<T>(x / (T)v, y / (T)v, z / (T)v, w / (T)v);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
vec4<T> operator/(const vec4<T1>& v) const {
|
||||
return vec4<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z, w / (T)v.w);
|
||||
}
|
||||
|
||||
vec4 operator-() const { return vec4(-x, -y, -z, -w); }
|
||||
|
||||
bool operator==(const vec4& v) const {
|
||||
return x == v.x && y == v.y && z == v.z && w == v.w;
|
||||
}
|
||||
bool operator!=(const vec4& v) const { return !(*this == v); }
|
||||
|
||||
double Len() const { return std::sqrt(SqLen()); }
|
||||
double SqLen() const { return x * x + y * y + z * z + w * w; }
|
||||
|
||||
void SwapXY() {
|
||||
T t = x;
|
||||
x = y;
|
||||
y = t;
|
||||
}
|
||||
void SwapXZ() {
|
||||
T t = x;
|
||||
x = z;
|
||||
z = t;
|
||||
}
|
||||
void SwapXW() {
|
||||
T t = x;
|
||||
x = w;
|
||||
w = t;
|
||||
}
|
||||
void SwapYZ() {
|
||||
T t = y;
|
||||
y = z;
|
||||
z = t;
|
||||
}
|
||||
void SwapYW() {
|
||||
T t = y;
|
||||
y = w;
|
||||
w = t;
|
||||
}
|
||||
void SwapZW() {
|
||||
T t = z;
|
||||
z = w;
|
||||
w = t;
|
||||
}
|
||||
};
|
||||
using fvec4 = vec4<float>;
|
||||
using dvec4 = vec4<double>;
|
||||
using ivec4 = vec4<int>;
|
||||
} // namespace PD
|
||||
|
Reference in New Issue
Block a user