Compare commits

...

2 Commits

Author SHA1 Message Date
01fb149e71 Update glfw 2025-06-22 21:05:24 +02:00
57634cbf4b # 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
2025-06-22 21:05:09 +02:00
185 changed files with 13968 additions and 18454 deletions

1
.gitignore vendored Normal file → Executable file
View File

@ -1 +1,2 @@
build/
.cache

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "backends/desktop/glfw"]
path = backends/desktop/glfw
url = https://github.com/glfw/glfw.git
url = https://github.com/glfw/glfw

View File

@ -1,37 +0,0 @@
{
"configurations": [
{
"name": "3DS | Windows",
"includePath": [
"${workspaceFolder}/**",
"C:/devkitpro/libctru/include/**",
"C:/devkitpro/devkitARM/include/**",
"C:/devkitpro/devkitARM/arm-none-eabi/include/**",
"C:/devkitpro/portlibs/3ds/include/**"
],
"defines": [
"BUILD_CTR",
"__3DS__"
],
"compilerPath": "C:/devkitPro/devkitARM/bin/arm-none-eabi-g++.exe",
"intelliSenseMode": "gcc-arm",
"cStandard": "c11",
"cppStandard": "c++20"
},
{
"name": "3DS | Linux",
"includePath": [
"${workspaceFolder}/**",
"/opt/devkitpro/libctru/include/**",
"/opt/devkitpro/portlibs/3ds/include/**"
],
"defines": [
"BUILD_CTR"
],
"cStandard": "c17",
"cppStandard": "gnu++20",
"intelliSenseMode": "gcc-arm"
}
],
"version": 4
}

21
.vscode/launch.json vendored
View File

@ -1,21 +0,0 @@
{
"configurations": [
{
"name": "3DS GDB",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/test.elf",
"miDebuggerServerAddress": "localhost:4003",
"miDebuggerPath": "C:\\devkitPro\\devkitARM\\bin\\arm-none-eabi-gdb.exe",
"cwd": "${workspaceFolder}",
"externalConsole": true,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

120
.vscode/settings.json vendored
View File

@ -1,120 +0,0 @@
{
"files.associations": {
"array": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"numeric": "cpp",
"type_traits": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"condition_variable": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"map": "cpp",
"iomanip": "cpp",
"memory_resource": "cpp",
"ratio": "cpp",
"regex": "cpp",
"shared_mutex": "cpp",
"valarray": "cpp",
"random": "cpp",
"cuchar": "cpp",
"compare": "cpp",
"concepts": "cpp",
"numbers": "cpp",
"filesystem": "cpp",
"xstring": "cpp",
"charconv": "cpp",
"format": "cpp",
"ios": "cpp",
"list": "cpp",
"locale": "cpp",
"mutex": "cpp",
"stack": "cpp",
"stop_token": "cpp",
"thread": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"queue": "cpp",
"semaphore": "cpp",
"hash_map": "cpp",
"set": "cpp",
"unordered_set": "cpp",
"source_location": "cpp",
"future": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"variant": "cpp",
"ranges": "cpp",
"span": "cpp",
"coroutine": "cpp",
"__bit_reference": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__verbose_abort": "cpp",
"complex": "cpp",
"any": "cpp",
"text_encoding": "cpp"
}
}

158
CMakeLists.txt Normal file → Executable file
View File

@ -1,158 +1,36 @@
cmake_minimum_required(VERSION 3.18)
### Helper Function to Build Librarys without have always
### These includes and definition defines
function(add_pd_lib TARGET_NAME)
set(opts "BUILD_SHARED")
set(one_val_args "")
set(multi_val_args SRC_FILES DEPENDS)
cmake_parse_arguments(ARG "${opts}" "${one_val_args}" "${multi_val_args}" ${ARGN})
string(REPLACE "-" "_" FLAG_NAME_T ${TARGET_NAME})
string(TOUPPER ${FLAG_NAME_T} FLAG_NAME_F)
if(ARG_BUILD_SHARED)
add_library(${TARGET_NAME} SHARED ${ARG_SRC_FILES})
target_compile_definitions(${TARGET_NAME} PUBLIC -D${FLAG_NAME_F}_BUILD_SHARED=1)
message("Building SHARED library: ${FLAG_NAME_F}_BUILD_SHARED=1")
else()
add_library(${TARGET_NAME} STATIC ${ARG_SRC_FILES})
target_compile_definitions(${TARGET_NAME} PUBLIC -D${FLAG_NAME_F}_BUILD_SHARED=0)
message("Building STATIC library: ${FLAG_NAME_F}_BUILD_SHARED=0")
endif()
target_include_directories(${TARGET_NAME} PUBLIC
include
${DEVKITPRO}/portlibs/3ds/include
backends)
target_compile_definitions(${TARGET_NAME} PUBLIC
-D_GNU_SOURCE=1
-DPALLADIUM_VERSION="${PROJECT_VERSION}"
-DPALLADIUM_GIT_COMMIT="${GIT_SHORT_HASH}"
-DPALLADIUM_GIT_BRANCH="${GIT_BRANCH}"
-DBUILD_CTR=1)
### For the libs that depend on another
if(ARG_DEPENDS)
target_link_libraries(${TARGET_NAME} PUBLIC ${ARG_DEPENDS})
endif()
install(TARGETS ${TARGET_NAME})
endfunction()
## Get Current Git Commit Value
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_SHORT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
## Get Current Git Branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
cmake_minimum_required(VERSION 3.22)
# Set Project
project(palladium LANGUAGES C CXX VERSION 0.4.0)
project(palladium LANGUAGES C CXX VERSION 0.5.0)
# Required to add this Variable
set(PD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
include(cmake/palladium.cmake)
option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)
option(PD_BUILD_SHARED "Build Shared Libraries" OFF)
option(PD_BUILD_TOOLS "Build Palladium Tools" OFF)
message("Var: ${PD_BUILD_SHARED}")
# Enable Compile Command Export
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Force C++ 20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# Set Special C and CXX flags for 3ds
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
if(${PD_BUILD_SHARED})
message(ERROR "3DS Only supports Static libraries")
if(${PD_BUILD_TOOLS})
add_subdirectory(tools)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-psabi -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions")
endif()
#include_directories(include)
## Core Source Code
set(CORE_SRC
source/core/common.cpp
source/core/bit_util.cpp
source/core/color.cpp
source/core/io.cpp
source/core/hid_driver.cpp
source/core/mat.cpp
source/core/strings.cpp
source/core/sys.cpp
source/core/timer.cpp
source/core/timetrace.cpp)
## Include Library Source
## Image Source Code
set(IMAGE_SRC
source/image/image.cpp
source/image/img_blur.cpp
source/image/img_convert.cpp)
## External Source Code
set(EXTERNAL_SRC
source/external/stb.cpp)
## Lithiu, Source Code
set(LI_SRC
source/lithium/font.cpp
source/lithium/drawlist.cpp
source/lithium/renderer.cpp)
## Net Source Code
set(NET_SRC
source/net/socket.cpp)
## UI7 Source Code
set(UI7_SRC
source/ui7/drawlist.cpp
source/ui7/io.cpp
source/ui7/layout.cpp
source/ui7/menu.cpp
source/ui7/remenu.cpp
source/ui7/theme.cpp
source/ui7/ui7.cpp
source/ui7/container/container.cpp
source/ui7/container/button.cpp
source/ui7/container/checkbox.cpp
source/ui7/container/coloredit.cpp
source/ui7/container/dragdata.cpp
source/ui7/container/dynobj.cpp
source/ui7/container/image.cpp
source/ui7/container/label.cpp)
#### Creating the Libraries ####
if(PD_BUILD_SHARED)
add_pd_lib(pd-core BUILD_SHARED TRUE SRC_FILES ${CORE_SRC})
add_pd_lib(pd-image BUILD_SHARED TRUE SRC_FILES ${IMAGE_SRC} DEPENDS pd-core)
add_pd_lib(pd-external SRC_FILES ${EXTERNAL_SRC})
add_pd_lib(pd-lithium BUILD_SHARED TRUE SRC_FILES ${LI_SRC} DEPENDS pd-core)
add_pd_lib(pd-net BUILD_SHARED TRUE SRC_FILES ${NET_SRC} DEPENDS pd-core)
add_pd_lib(pd-ui7 BUILD_SHARED TRUE SRC_FILES ${UI7_SRC} DEPENDS pd-core pd-lithium)
else()
add_pd_lib(pd-core SRC_FILES ${CORE_SRC})
add_pd_lib(pd-image SRC_FILES ${IMAGE_SRC} DEPENDS pd-core)
add_pd_lib(pd-external SRC_FILES ${EXTERNAL_SRC})
add_pd_lib(pd-lithium SRC_FILES ${LI_SRC} DEPENDS pd-core)
add_pd_lib(pd-net SRC_FILES ${NET_SRC} DEPENDS pd-core)
add_pd_lib(pd-ui7 SRC_FILES ${UI7_SRC} DEPENDS pd-core pd-lithium)
endif()
add_subdirectory(pd/drivers)
add_subdirectory(pd/core)
add_subdirectory(pd/image)
add_subdirectory(pd/external)
add_subdirectory(pd/lithium)
add_subdirectory(pd/ui7)
add_library(palladium INTERFACE)
target_link_libraries(palladium INTERFACE
pd-core pd-image pd-external pd-lithium pd-net pd-ui7
pd-core pd-image pd-external pd-lithium pd-ui7 #pd-net
)
add_dependencies(palladium
pd-core pd-image pd-external pd-lithium pd-net pd-ui7
pd-drivers pd-core pd-image pd-external pd-lithium pd-ui7 #pd-net
)
install(DIRECTORY include DESTINATION ".")

0
LICENSE Normal file → Executable file
View File

16
README.md Normal file → Executable file
View File

@ -23,27 +23,11 @@ make
make install
```
## Libraries
| Name | Last Updated | Platform | Depends |
|---|---|---|---|
| pd-core | 0.3.3 | multi | none |
| pd-external | 0.1.0 | multi | none |
| pd-image | 0.3.3 | multi | pd-core |
| pd-lib3ds | 0.2.4 | 3ds | pd-core, pd-drivers |
| pd-net | 0.2.4 | 3ds | pd-core, pd-lib3ds |
| pd-lithium | 0.3.3 | multi | pd-core |
| pd-sound | 0.2.4 | 3ds | pd-core, mpg123 |
| pd-overlays | 0.2.4 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium, pd-ui7 |
| pd-ui7 | 0.3.3 | multi | pd-core, pd-lithium |
| pd-app | 0.2.4 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium |
## Credits
| Icon | Username | Description |
|---|---|---|
| <img src="https://github.com/tobid7.png" alt="https://github.com/tobid7" width="48"/> | [tobid7](https://github.com/tobid7) | main dev of RenderD7, Palladium |
| <img src="https://github.com/devkitpro.png" alt="https://github.com/devkitpro" width="48"/> | [devkitpro](https://github.com/devkitpro) | devkitarm, picasso, libctru and citro3d |
| <img src="https://github.com/Universal-Team.png" alt="https://github.com/Universal-Team" width="48"/> | [Universal-Team](https://github.com/Universal-Team) | Inspiration for Lang System, Cia Installer Code |
| <img src="https://github.com/nothings.png" alt="https://github.com/nothings" width="48"/> | [nothings](https://github.com/nothings) | stb_image(_write) and stb_truetype |
| <img src="https://github.com/nlohmann.png" alt="https://github.com/nlohmann" width="48"/> | [nlohmann](https://github.com/nlohmann) | for json.hpp |

25
backends/3ds/CMakeLists.txt Normal file → Executable file
View File

@ -1,18 +1,13 @@
cmake_minimum_required(VERSION 3.22)
# Make sure to use 3ds toolschain for 3ds build :)
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(DEFINED ENV{DEVKITPRO})
set(CMAKE_TOOLCHAIN_FILE "$ENV{DEVKITPRO}/cmake/3DS.cmake" CACHE PATH "toolchain file")
else()
message(FATAL_ERROR "Please define DEVKITPRO to point to your SDK path!")
endif()
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-psabi -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions")
project(pd-3ds LANGUAGES CXX VERSION 0.5.0)
add_library(pd-backend-3ds STATIC
source/li_backend_c3d.cpp
source/pd_hid_3ds.cpp)
target_include_directories(pd-backend-3ds PUBLIC include)
target_link_libraries(pd-backend-3ds PUBLIC palladium)
set(SRC
source/bknd-gfx.cpp
source/bknd-hid.cpp
source/pd-3ds.cpp
)
pd_add_lib(pd-3ds SRC_FILES ${SRC})
target_include_directories(pd-3ds PUBLIC include)
target_link_libraries(pd-3ds PUBLIC m palladium ctru citro3d)

32
backends/3ds/include/pd-3ds.hpp Executable file
View File

@ -0,0 +1,32 @@
#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-3ds/bknd-gfx.hpp>
#include <pd-3ds/bknd-hid.hpp>
namespace PD {
void Init(void* data = nullptr);
}

View File

@ -24,13 +24,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <3ds.h>
#include <citro3d.h>
#include <pd/core/core.hpp>
#include <pd/lithium/backend.hpp>
#include <pd/lithium/lithium.hpp>
namespace PD {
template <typename T>
@ -43,30 +40,27 @@ class LinearAlloc : public Allocator<T> {
T* Allocate(size_t n) override { return (T*)linearAlloc(n * sizeof(T)); }
void Deallocate(T* ptr) { linearFree(ptr); }
};
namespace LI {
class Backend_C3D : public PD::LI::Backend {
namespace Li {
class GfxC3D : public GfxDriver {
public:
Backend_C3D() : LI::Backend("Citro3D") {}
~Backend_C3D() {}
PD_SMART_CTOR(Backend_C3D)
GfxC3D() : GfxDriver("Citro3D") {}
~GfxC3D() = default;
PD_SHARED(GfxC3D);
void Init() override;
void Deinit() override;
void NewFrame() override;
void BindTexture(PD::LI::TexAddress addr) override;
void RenderDrawData(const PD::Vec<PD::LI::Command::Ref>& Commands) override;
PD::LI::Texture::Ref LoadTexture(
void BindTex(PD::Li::TexAddress addr) override;
void RenderDrawData(
const std::vector<PD::Li::Command::Ref>& Commands) override;
PD::Li::Texture::Ref LoadTex(
const std::vector<PD::u8>& pixels, int w, int h,
PD::LI::Texture::Type type = PD::LI::Texture::Type::RGBA32,
PD::LI::Texture::Filter filter =
PD::LI::Texture::Filter::LINEAR) override;
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
PD::Li::Texture::Filter filter =
PD::Li::Texture::Filter::LINEAR) override;
private:
Vec<Vertex, LinearAlloc<Vertex>> VertexBuffer;
Vec<u16, LinearAlloc<u16>> IndexBuffer;
size_t CurrentVertex = 0;
@ -76,9 +70,9 @@ class Backend_C3D : public PD::LI::Backend {
DVLB_s* ShaderCode;
shaderProgram_s Shader;
C3D_AttrInfo ShaderInfo;
// For Stats
PD::u32 num_vtx = 0;
PD::u32 num_idx = 0;
// Stats oder so IDNK zu lange her
PD::u32 NumVtx;
PD::u32 NumIdx;
};
} // namespace LI
} // namespace Li
} // namespace PD

View 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,21 +24,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/hid_driver.hpp>
#include <pd/drivers/drivers.hpp>
namespace PD {
class Hid3DS : public Hid {
class Hid3DS : public HidDriver {
public:
/**
* Constructor to setup Key binds
*/
Hid3DS();
~Hid3DS() = default;
PD_SMART_CTOR(Hid3DS)
/**
* Overrideing the Update Function for Input Checking etc
*/
PD_SHARED(Hid3DS);
void Update() override;
};
} // namespace PD

View File

@ -1,117 +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 <3ds.h>
#include <arpa/inet.h>
#include <malloc.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <pd/net/backend.hpp>
namespace PD {
class NetBackend3DS : public Net::Backend {
public:
NetBackend3DS() : Net::Backend("3DS") {}
~NetBackend3DS() = default;
PD_SMART_CTOR(NetBackend3DS)
bool Init() override {
pSocBuffer = (uint32_t*)memalign(pSocAlign, pSocBufferSize);
Result ret = 0;
if (pSocBuffer == NULL) {
return false;
}
if ((ret = socInit(pSocBuffer, pSocBufferSize)) != 0) {
return false;
}
return true;
}
void Deinit() override { socExit(); }
int NewSocket() override { return socket(AF_INET, SOCK_STREAM, 0); }
void Close(int sock_id) override { close(sock_id); }
int GetInvalidRef() const override { return -1; }
bool Bind(int sock_id, u16 port) {
sockaddr_in addr{};
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = INADDR_ANY;
return bind(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
}
bool Listen(int sock_id, int backlog = 5) {
return listen(sock_id, backlog) != -1;
}
bool WaitForRead(int sock_id, int timeout_ms) override {
fd_set set;
FD_ZERO(&set);
FD_SET(sock_id, &set);
timeval timeout{};
timeout.tv_sec = timeout_ms / 1000;
timeout.tv_usec = (timeout_ms % 1000) * 1000;
int result = select(sock_id + 1, &set, nullptr, nullptr, &timeout);
return (result > 0 && FD_ISSET(sock_id, &set));
}
bool Accept(int sock_id, Net::Socket::Ref client) {
int client_soc = accept(sock_id, nullptr, nullptr);
if (client_soc == -1) {
return false;
}
client->pSocket = client_soc;
return true;
}
bool Connect(int sock_id, const std::string& ip, u16 port) {
sockaddr_in addr{};
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
inet_pton(AF_INET, ip.c_str(), &addr.sin_addr);
return connect(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
}
int Send(int sock_id, const std::string& data) {
return send(sock_id, data.c_str(), static_cast<int>(data.size()), 0);
}
int Receive(int sock_id, std::string& data, int size = 1024) {
char* tmp = new char[size];
int res = recv(sock_id, tmp, size, 0);
if (res > 0) {
data.assign(tmp, res);
}
delete[] tmp;
return res;
}
private:
/** using libctru u32 here */
const uint32_t pSocAlign = 0x1000;
const uint32_t pSocBufferSize = 0x100000;
uint32_t* pSocBuffer = nullptr;
};
} // namespace PD

View File

@ -1,4 +1,28 @@
#include <li_backend_c3d.hpp>
/*
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-3ds/bknd-gfx.hpp>
/// @brief Shader Code (Unused as i dont want to use libpicasso here (yet))
const char* LIShaderCTR = R"(
@ -44,8 +68,9 @@ unsigned char li_shader[] = {
};
// clang-format on
size_t li_shader_size = 0x124;
namespace PD {
namespace LI {
namespace Li {
GPU_TEXCOLOR GetTexFmt(Texture::Type type) {
if (type == Texture::RGBA32)
return GPU_RGBA8;
@ -64,51 +89,47 @@ int GetBPP(Texture::Type type) {
return 1;
return 0; // Error
}
void Backend_C3D::Init() {
std::cout << "[BACKEND_C3D]: Setting up Buffers" << std::endl;
void GfxC3D::Init() {
VertexBuffer.Resize(4 * 8192);
IndexBuffer.Resize(6 * 8192);
Flags |= LIBackendFlags_FlipUV_Y;
Flags |= LiBackendFlags_FlipUV_Y;
std::cout << "[BACKEND_C3D]: Loading shader..." << std::endl;
ShaderCode = DVLB_ParseFile((uint32_t*)li_shader, li_shader_size);
shaderProgramInit(&Shader);
shaderProgramSetVsh(&Shader, &ShaderCode->DVLE[0]);
pLocProjection =
shaderInstanceGetUniformLocation(Shader.vertexShader, "projection");
std::cout << "[BACKEND_C3D]: Setting up Attr Info" << std::endl;
AttrInfo_Init(&ShaderInfo);
AttrInfo_AddLoader(&ShaderInfo, 0, GPU_FLOAT, 2);
AttrInfo_AddLoader(&ShaderInfo, 1, GPU_FLOAT, 2);
AttrInfo_AddLoader(&ShaderInfo, 2, GPU_UNSIGNED_BYTE, 4);
std::cout << "[BACKEND_C3D]: Backend init done!" << std::endl;
}
void Backend_C3D::Deinit() {
void GfxC3D::Deinit() {
shaderProgramFree(&Shader);
DVLB_Free(ShaderCode);
}
void Backend_C3D::NewFrame() {
void GfxC3D::NewFrame() {
C3D_BindProgram(&Shader);
C3D_SetAttrInfo(&ShaderInfo);
CurrentIndex = 0;
CurrentVertex = 0;
FrameCounter++;
VertexCounter = num_vtx;
IndexCounter = num_idx;
num_vtx = 0;
num_idx = 0;
VertexCounter = NumVtx;
IndexCounter = NumIdx;
NumVtx = 0;
NumIdx = 0;
}
void Backend_C3D::BindTexture(PD::LI::TexAddress addr) {
void GfxC3D::BindTex(PD::Li::TexAddress addr) {
C3D_TexBind(0, reinterpret_cast<C3D_Tex*>(addr));
}
void Backend_C3D::RenderDrawData(
const PD::Vec<PD::LI::Command::Ref>& Commands) {
void GfxC3D::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
C3D_BindProgram(&Shader);
C3D_SetAttrInfo(&ShaderInfo);
C3D_Mtx proj;
@ -120,26 +141,26 @@ void Backend_C3D::RenderDrawData(
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0);
C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
size_t index = 0;
while (index < Commands.Size()) {
PD::LI::Texture::Ref Tex = Commands[index]->Tex;
while (index < Commands.size()) {
PD::Li::Texture::Ref Tex = Commands[index]->Tex;
if (!Tex) {
index++;
continue;
}
bool ScissorEnabled = Commands[index]->ScissorEnabled;
bool ScissorEnabled = Commands[index]->ScissorOn;
ivec4 ScissorRect = Commands[index]->ScissorRect;
size_t StartIndex = CurrentIndex;
while (index < Commands.Size() && Commands[index]->Tex == Tex &&
Commands[index]->ScissorEnabled == ScissorEnabled &&
while (index < Commands.size() && Commands[index]->Tex == Tex &&
Commands[index]->ScissorOn == ScissorEnabled &&
Commands[index]->ScissorRect == ScissorRect) {
auto c = Commands[index];
auto c = Commands[index].get();
for (size_t i = 0; i < c->IndexBuffer.Size(); i++) {
num_idx++;
NumIdx++;
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i);
}
for (size_t i = 0; i < c->VertexBuffer.Size(); i++) {
num_vtx++;
NumVtx++;
VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i);
}
index++;
@ -153,7 +174,7 @@ void Backend_C3D::RenderDrawData(
} else {
C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0);
}
BindTexture(Tex->Address);
BindTex(Tex->Address);
auto bufInfo = C3D_GetBufInfo();
BufInfo_Init(bufInfo);
BufInfo_Add(bufInfo, VertexBuffer.Data(), sizeof(Vertex), 3, 0x210);
@ -164,16 +185,14 @@ void Backend_C3D::RenderDrawData(
C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL);
}
PD::LI::Texture::Ref Backend_C3D::LoadTexture(const std::vector<PD::u8>& pixels,
int w, int h,
PD::LI::Texture::Type type,
PD::LI::Texture::Filter filter) {
std::cout << "Loading Tex " << std::format("[{}, {}]", w, h) << std::endl;
PD::Li::Texture::Ref GfxC3D::LoadTex(const std::vector<PD::u8>& pixels, int w,
int h, PD::Li::Texture::Type type,
PD::Li::Texture::Filter filter) {
if (w > 1024 || h > 1024) {
return nullptr;
}
// Don't check here as check done before
PD::LI::Texture::Ref res = PD::LI::Texture::New();
PD::Li::Texture::Ref res = PD::Li::Texture::New();
int bpp = GetBPP(type);
ivec2 tex_size(w, h);
// Pow2
@ -227,5 +246,5 @@ PD::LI::Texture::Ref Backend_C3D::LoadTexture(const std::vector<PD::u8>& pixels,
<< std::endl;
return res;
}
} // namespace LI
} // namespace Li
} // namespace PD

View File

@ -0,0 +1,85 @@
/*
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 <3ds.h>
#include <pd-3ds/bknd-hid.hpp>
namespace PD {
Hid3DS::Hid3DS() : HidDriver("Hid3DS") {
pBinds[KEY_A] = A;
pBinds[KEY_B] = B;
pBinds[KEY_X] = X;
pBinds[KEY_Y] = Y;
pBinds[KEY_START] = Start;
pBinds[KEY_SELECT] = Select;
pBinds[KEY_L] = L;
pBinds[KEY_R] = R;
pBinds[KEY_DUP] = DUp;
pBinds[KEY_DDOWN] = DDown;
pBinds[KEY_DLEFT] = DLeft;
pBinds[KEY_DRIGHT] = DRight;
pBinds[KEY_CPAD_UP] = CPUp;
pBinds[KEY_CPAD_DOWN] = CPDown;
pBinds[KEY_CPAD_LEFT] = CPLeft;
pBinds[KEY_CPAD_RIGHT] = CPRight;
pBinds[KEY_CSTICK_UP] = CSUp;
pBinds[KEY_CSTICK_DOWN] = CSDown;
pBinds[KEY_CSTICK_LEFT] = CSLeft;
pBinds[KEY_CSTICK_RIGHT] = CSRight;
pBinds[KEY_ZL] = ZL;
pBinds[KEY_ZR] = ZR;
pBinds[KEY_TOUCH] = Touch;
}
void Hid3DS::Update() {
hidScanInput();
for (int i = 0; i < 2; i++) {
KeyEvents[i][Event_Down] = 0;
KeyEvents[i][Event_Held] = 0;
KeyEvents[i][Event_Up] = 0;
}
u32 kd = hidKeysDown();
u32 kh = hidKeysHeld();
u32 ku = hidKeysUp();
for (auto &b : pBinds) {
if (b.first & kd) {
KeyEvents[0][Event_Down] |= b.second;
}
if (b.first & kh) {
KeyEvents[0][Event_Held] |= b.second;
}
if (b.first & ku) {
KeyEvents[0][Event_Up] |= b.second;
}
}
if (pLocked) {
SwapTab();
}
touchPosition t;
hidTouchRead(&t);
pMouse[1] = pMouse[0]; // Cycle pMouse pos
pMouse[0] = fvec2(t.px, t.py);
}
} // namespace PD

36
backends/3ds/source/pd-3ds.cpp Executable file
View File

@ -0,0 +1,36 @@
/*
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 <palladium>
#include <pd-3ds.hpp>
namespace PD {
void Init(void* data) {
// Dekstop Init Stage
// First use default OS Driver
PD::OS::Init();
PD::Li::Gfx::Init(PD::Li::GfxC3D::New());
PD::Hid::Init(PD::Hid3DS::New());
}
} // namespace PD

View File

@ -1,60 +0,0 @@
#include <3ds.h>
#include <pd_hid_3ds.hpp>
namespace PD {
Hid3DS::Hid3DS() : Hid("3DS") {
binds[KEY_A] = A;
binds[KEY_B] = B;
binds[KEY_X] = X;
binds[KEY_Y] = Y;
binds[KEY_START] = Start;
binds[KEY_SELECT] = Select;
binds[KEY_L] = L;
binds[KEY_R] = R;
binds[KEY_DUP] = DUp;
binds[KEY_DDOWN] = DDown;
binds[KEY_DLEFT] = DLeft;
binds[KEY_DRIGHT] = DRight;
binds[KEY_CPAD_UP] = CPUp;
binds[KEY_CPAD_DOWN] = CPDown;
binds[KEY_CPAD_LEFT] = CPLeft;
binds[KEY_CPAD_RIGHT] = CPRight;
binds[KEY_CSTICK_UP] = CSUp;
binds[KEY_CSTICK_DOWN] = CSDown;
binds[KEY_CSTICK_LEFT] = CSLeft;
binds[KEY_CSTICK_RIGHT] = CSRight;
binds[KEY_ZL] = ZL;
binds[KEY_ZR] = ZR;
binds[KEY_TOUCH] = Touch;
}
void Hid3DS::Update() {
hidScanInput();
for (int i = 0; i < 2; i++) {
key_events[i][Event_Down] = 0;
key_events[i][Event_Held] = 0;
key_events[i][Event_Up] = 0;
}
u32 kd = hidKeysDown();
u32 kh = hidKeysHeld();
u32 ku = hidKeysUp();
for (auto &b : binds) {
if (b.first & kd) {
key_events[0][Event_Down] |= b.second;
}
if (b.first & kh) {
key_events[0][Event_Held] |= b.second;
}
if (b.first & ku) {
key_events[0][Event_Up] |= b.second;
}
}
if (locked) {
SwappyTable();
}
touchPosition t;
hidTouchRead(&t);
touch[1] = touch[0]; // Cycle touch pos
touch[0] = fvec2(t.px, t.py);
}
} // namespace PD

31
backends/desktop/CMakeLists.txt Normal file → Executable file
View File

@ -1,27 +1,16 @@
cmake_minimum_required(VERSION 3.22)
if(WIN32)
set(EXTRA_LIBS ws2_32)
else()
set(EXTRA_LIBS)
endif()
project(pd-desktop LANGUAGES CXX VERSION 0.5.0)
add_subdirectory(glfw)
add_subdirectory(glad)
add_subdirectory(glfw)
# if(PD_BUILD_SHARED)
# add_library(pd-backend-desktop SHARED
# source/li_backend_gl2.cpp
# source/pd_hid_glfw.cpp)
# target_compile_definitions(pd-backend-desktop PUBLIC
# -DPD_BKND_DESKTOP_BUILD_SHARED=1)
# else()
add_library(pd-backend-desktop STATIC
source/li_backend_gl2.cpp
source/pd_hid_glfw.cpp)
#endif()
set(SRC
source/bknd-gfx.cpp
source/bknd-hid.cpp
source/pd-desktop.cpp
)
target_compile_definitions(pd-backend-desktop PUBLIC
-DPD_BKND_DESKTOP_STATIC=1)
target_include_directories(pd-backend-desktop PUBLIC include)
target_link_libraries(pd-backend-desktop PUBLIC glad glfw palladium ${EXTRA_LIBS})
pd_add_lib(pd-desktop SRC_FILES ${SRC})
target_include_directories(pd-desktop PUBLIC include)
target_link_libraries(pd-desktop PUBLIC palladium glad glfw)

0
backends/desktop/glad/CMakeLists.txt Normal file → Executable file
View File

0
backends/desktop/glad/include/KHR/khrplatform.h Normal file → Executable file
View File

0
backends/desktop/glad/include/glad/glad.h Normal file → Executable file
View File

0
backends/desktop/glad/source/glad.c Normal file → Executable file
View File

@ -1 +1 @@
Subproject commit 7b6aead9fb88b3623e3b3725ebb42670cbe4c579
Subproject commit e7ea71be039836da3a98cea55ae5569cb5eb885c

View File

@ -1,46 +0,0 @@
#include <glad/glad.h>
/** SEPARATOR */
#include <GLFW/glfw3.h>
/** SEPARATOR */
#include <pd/core/core.hpp>
#include <pd/lithium/backend.hpp>
#include <pd_p_bknd_api.hpp>
namespace PD {
namespace LI {
class PD_BKND_DESKTOP_API Backend_GL2 : public PD::LI::Backend {
public:
Backend_GL2() : LI::Backend("OpenGL2") {}
~Backend_GL2() {}
PD_SMART_CTOR(Backend_GL2)
void Init() override;
void Deinit() override;
void NewFrame() override;
void BindTexture(PD::LI::TexAddress addr) override;
void RenderDrawData(const PD::Vec<PD::LI::Command::Ref>& Commands) override;
PD::LI::Texture::Ref LoadTexture(
const std::vector<PD::u8>& pixels, int w, int h,
PD::LI::Texture::Type type = PD::LI::Texture::Type::RGBA32,
PD::LI::Texture::Filter filter =
PD::LI::Texture::Filter::LINEAR) override;
private:
PD::Vec<PD::LI::Vertex> VertexBuffer;
PD::Vec<PD::u16> IndexBuffer;
size_t CurrentVertex = 0;
size_t CurrentIndex = 0;
GLuint Shader;
GLuint pLocProjection;
GLuint pLocTex;
Mat4 Projection;
GLuint VBO, IBO;
// For Stats
PD::u32 num_vtx = 0;
PD::u32 num_idx = 0;
};
} // namespace LI
} // namespace PD

View File

@ -0,0 +1,32 @@
#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-desktop/bknd-gfx.hpp>
#include <pd-desktop/bknd-hid.hpp>
namespace PD {
void Init(void* data = nullptr);
}

View 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,40 +24,47 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <mpg123.h>
#include <glad/glad.h>
#include <pd/sound/decoder.hpp>
/** SEPARATOR */
#include <GLFW/glfw3.h>
/** SEPARATOR */
#include <pd/lithium/lithium.hpp>
namespace PD {
namespace Music {
/**
* MP3 Decoder
*/
class Mp3Decoder : public Decoder {
namespace Li {
class GfxGL2 : public GfxDriver {
public:
Mp3Decoder() = default;
~Mp3Decoder() = default;
GfxGL2() : GfxDriver("OpenGL2") {}
~GfxGL2() = default;
/** Init Funciton to load file and Init decoder */
int Init(const std::string& path) override;
/** Unload Decoder */
PD_SHARED(GfxGL2);
void Init() override;
void Deinit() override;
/** Get Sample Rate */
u32 GetSampleRate() override;
/** Get Channels */
u8 GetChannels() override;
/** Get Buffer Size */
size_t GetBufSize() override;
/** Decode next data */
u64 Decode(u16* buf_address) override;
/** Get File Samples if exist */
size_t GetFileSamples() override;
void NewFrame() override;
void BindTex(PD::Li::TexAddress addr) override;
void RenderDrawData(
const std::vector<PD::Li::Command::Ref>& Commands) override;
PD::Li::Texture::Ref LoadTex(
const std::vector<PD::u8>& pixels, int w, int h,
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
PD::Li::Texture::Filter filter =
PD::Li::Texture::Filter::LINEAR) override;
private:
mpg123_handle* handle = nullptr;
size_t buf_size = 0;
u32 rate = 0;
u8 channels = 0;
PD::Vec<Vertex> VertexBuffer;
PD::Vec<PD::u16> IndexBuffer;
size_t CurrentVertex = 0;
size_t CurrentIndex = 0;
GLuint Shader;
GLuint pLocProjection;
GLuint pLocTex;
Mat4 Projection;
GLuint VBO, IBO;
// Stats oder so IDNK zu lange her
PD::u32 NumVtx;
PD::u32 NumIdx;
};
} // namespace Music
} // namespace Li
} // namespace PD

View 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
@ -25,25 +26,19 @@ SOFTWARE.
#include <GLFW/glfw3.h>
#include <pd/core/hid_driver.hpp>
#include <pd_p_bknd_api.hpp>
#include <pd/drivers/drivers.hpp>
namespace PD {
class PD_BKND_DESKTOP_API HidGLFW : public Hid {
class HidGLFW : public HidDriver {
public:
/**
* Constructor to setup Key binds
*/
HidGLFW(GLFWwindow* win);
~HidGLFW() = default;
PD_SMART_CTOR(HidGLFW)
/**
* Overrideing the Update Function for Input Checking etc
*/
PD_SHARED(HidGLFW);
void Update() override;
private:
/** Data section */
GLFWwindow* Window;
int PrevState;
};

View File

@ -1,132 +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.
*/
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#ifdef _MSVC
#pragma comment(lib, "ws2_32.lib")
#endif
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#endif
#include <pd/net/backend.hpp>
namespace PD {
class NetBackendDesktop : public PD::Net::Backend {
public:
#ifdef _WIN32
NetBackendDesktop() : Net::Backend("Desktop (Windows)") {
#else
NetBackendDesktop() : Net::Backend("Desktop (Unix)") {
#endif
}
~NetBackendDesktop() = default;
PD_SMART_CTOR(NetBackendDesktop)
bool Init() override {
#ifdef _WIN32
WSADATA wsa_data;
return (WSAStartup(MAKEWORD(2, 2), &wsa_data) == 0);
#else
return true;
#endif
}
void Deinit() override {
#ifdef _WIN32
WSACleanup();
#endif
}
int NewSocket() override { return socket(AF_INET, SOCK_STREAM, 0); }
void Close(int sock_id) override {
#ifdef _WIN32
closesocket(sock_id);
#else
close(sock_id);
#endif
}
int GetInvalidRef() const override {
#ifdef _WIN32
return INVALID_SOCKET;
#else
return -1;
#endif
}
bool Bind(int sock_id, u16 port) override {
sockaddr_in addr{};
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = INADDR_ANY;
return bind(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
}
bool Listen(int sock_id, int backlog = 5) override {
return listen(sock_id, backlog) != -1;
}
bool WaitForRead(int sock_id, int timeout_ms) override {
fd_set set;
FD_ZERO(&set);
FD_SET(sock_id, &set);
timeval timeout{};
timeout.tv_sec = timeout_ms / 1000;
timeout.tv_usec = (timeout_ms % 1000) * 1000;
int result = select(sock_id + 1, &set, nullptr, nullptr, &timeout);
return (result > 0 && FD_ISSET(sock_id, &set));
}
bool Accept(int sock_id, Net::Socket::Ref client) override {
int client_soc = accept(sock_id, nullptr, nullptr);
if (client_soc == GetInvalidRef()) {
return false;
}
client->pSocket = client_soc;
return true;
}
bool Connect(int sock_id, const std::string& ip, u16 port) override {
sockaddr_in addr{};
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
inet_pton(AF_INET, ip.c_str(), &addr.sin_addr);
return connect(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
}
int Send(int sock_id, const std::string& data) override {
return send(sock_id, data.c_str(), static_cast<int>(data.size()), 0);
}
int Receive(int sock_id, std::string& data, int size = 1024) override {
char* tmp = new char[size];
int res = recv(sock_id, tmp, size, 0);
if (res > 0) {
data.assign(tmp, res);
}
delete[] tmp;
return res;
}
};
} // namespace PD

View File

@ -1,58 +0,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.
*/
#pragma once
#ifdef PD_BKND_DESKTOP_STATIC
#if defined(__3DS__) // 3ds Specific
#error "Desktop backend is not supported on the 3ds!"
#endif
#define PD_BKND_DESKTOP_API
#else
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_BKND_DESKTOP_BUILD_SHARED
#define PD_BKND_DESKTOP_API __declspec(dllexport)
#else
#define PD_BKND_DESKTOP_API __declspec(dllimport)
#endif
#elif defined(__APPLE__) // macOS (untested yet)
#ifdef PD_BKND_DESKTOP_BUILD_SHARED
#define PD_BKND_DESKTOP_API __attribute__((visibility("default")))
#else
#define PD_BKND_DESKTOP_API
#endif
#elif defined(__linux__) // Linux (untested yet)
#ifdef PD_BKND_DESKTOP_BUILD_SHARED
#define PD_BKND_DESKTOP_API __attribute__((visibility("default")))
#else
#define PD_BKND_DESKTOP_API
#endif
#elif defined(__3DS__) // 3ds Specific
#error "Desktop backend is not supported on the 3ds!"
#else
#define PD_BKND_DESKTOP_API
#endif
#endif

View File

@ -1,5 +1,31 @@
#include <li_backend_gl2.hpp>
/*
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-desktop/bknd-gfx.hpp>
namespace PD {
namespace Li {
const char* vertex_shader = R"(
#version 120
@ -35,8 +61,7 @@ const char* frag_shader = R"(
}
)";
GLuint compileShader(const std::string& source,
GLenum type) {
GLuint compileShader(const std::string& source, GLenum type) {
GLuint shader = glCreateShader(type);
const char* src = source.c_str();
glShaderSource(shader, 1, &src, nullptr);
@ -53,8 +78,7 @@ GLuint compileShader(const std::string& source,
return shader;
}
GLuint
createShaderProgram(const std::string& vertexShaderSource,
GLuint createShaderProgram(const std::string& vertexShaderSource,
const std::string& fragmentShaderSource) {
GLuint vertexShader = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
GLuint fragmentShader =
@ -79,9 +103,9 @@ createShaderProgram(const std::string& vertexShaderSource,
return shaderProgram;
}
namespace PD {
namespace LI {
PD_BKND_DESKTOP_API void Backend_GL2::Init() {
/** Actual Backend */
void GfxGL2::Init() {
VertexBuffer.Resize(4 * 8192);
IndexBuffer.Resize(6 * 8192);
Shader = createShaderProgram(vertex_shader, frag_shader);
@ -93,17 +117,17 @@ PD_BKND_DESKTOP_API void Backend_GL2::Init() {
GLint _pos = glGetAttribLocation(Shader, "pos");
GLint _uv = glGetAttribLocation(Shader, "uv");
GLint _color = glGetAttribLocation(Shader, "color");
glVertexAttribPointer(_pos, 2, GL_FLOAT, GL_FALSE, sizeof(PD::LI::Vertex),
(void*)offsetof(PD::LI::Vertex, Pos));
glVertexAttribPointer(_pos, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, Pos));
glEnableVertexAttribArray(_pos);
glVertexAttribPointer(_uv, 2, GL_FLOAT, GL_FALSE, sizeof(PD::LI::Vertex),
(void*)offsetof(PD::LI::Vertex, UV));
glVertexAttribPointer(_uv, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, UV));
glEnableVertexAttribArray(_uv);
glVertexAttribPointer(_color, 4, GL_UNSIGNED_BYTE, GL_TRUE,
sizeof(PD::LI::Vertex),
(void*)offsetof(PD::LI::Vertex, Color));
sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, Color));
glEnableVertexAttribArray(_color);
glGenBuffers(1, &IBO);
@ -116,12 +140,12 @@ PD_BKND_DESKTOP_API void Backend_GL2::Init() {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
PD_BKND_DESKTOP_API void Backend_GL2::Deinit() {
void GfxGL2::Deinit() {
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &IBO);
}
PD_BKND_DESKTOP_API void Backend_GL2::NewFrame() {
void GfxGL2::NewFrame() {
glViewport(0, 0, ViewPort.x, ViewPort.y);
glClearColor(ClearColor.x, ClearColor.y, ClearColor.z, ClearColor.w);
glClear(GL_COLOR_BUFFER_BIT);
@ -132,57 +156,56 @@ PD_BKND_DESKTOP_API void Backend_GL2::NewFrame() {
CurrentIndex = 0;
CurrentVertex = 0;
FrameCounter++;
VertexCounter = num_vtx;
IndexCounter = num_idx;
num_vtx = 0;
num_idx = 0;
VertexCounter = NumVtx;
IndexCounter = NumIdx;
NumVtx = 0;
NumIdx = 0;
}
PD_BKND_DESKTOP_API void Backend_GL2::BindTexture(PD::LI::TexAddress addr) {
void GfxGL2::BindTex(PD::Li::TexAddress addr) {
// Actually not using the Address as Address
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, (GLuint)addr);
glUniform1i(pLocTex, 0);
}
PD_BKND_DESKTOP_API void Backend_GL2::RenderDrawData(
const PD::Vec<PD::LI::Command::Ref>& Commands) {
void GfxGL2::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
glUseProgram(Shader);
size_t index = 0;
while (index < Commands.Size()) {
PD::LI::Texture::Ref Tex = Commands[index]->Tex;
while (index < Commands.size()) {
PD::Li::Texture::Ref Tex = Commands[index]->Tex;
if (!Tex) {
index++;
continue;
}
size_t StartIndex = CurrentIndex;
bool ScissorEnabled = Commands[index]->ScissorEnabled;
bool ScissorOn = Commands[index]->ScissorOn;
ivec4 ScissorRect = Commands[index]->ScissorRect;
while (index < Commands.Size() && Commands[index]->Tex == Tex &&
Commands[index]->ScissorEnabled == ScissorEnabled &&
while (index < Commands.size() && Commands[index]->Tex == Tex &&
Commands[index]->ScissorOn == ScissorOn &&
Commands[index]->ScissorRect == ScissorRect) {
auto c = Commands[index];
auto c = Commands[index].get();
for (size_t i = 0; i < c->IndexBuffer.Size(); i++) {
num_idx++;
NumIdx++;
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i);
}
for (size_t i = 0; i < c->VertexBuffer.Size(); i++) {
num_vtx++;
NumVtx++;
VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i);
}
index++;
}
if (ScissorEnabled) {
if (ScissorOn) {
glScissor(ScissorRect.x, ViewPort.y - (ScissorRect.y + ScissorRect.w),
ScissorRect.z, ScissorRect.w);
glEnable(GL_SCISSOR_TEST);
} else {
glDisable(GL_SCISSOR_TEST);
}
BindTexture(Tex->Address);
BindTex(Tex->Address);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::LI::Vertex),
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
&VertexBuffer[0], GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
@ -194,37 +217,36 @@ PD_BKND_DESKTOP_API void Backend_GL2::RenderDrawData(
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
BindTexture(0);
BindTex(0);
}
}
PD_BKND_DESKTOP_API PD::LI::Texture::Ref Backend_GL2::LoadTexture(
const std::vector<PD::u8>& pixels, int w, int h, PD::LI::Texture::Type type,
PD::LI::Texture::Filter filter) {
PD::Li::Texture::Ref GfxGL2::LoadTex(const std::vector<PD::u8>& pixels, int w,
int h, PD::Li::Texture::Type type,
PD::Li::Texture::Filter filter) {
GLuint texID;
glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);
// Set base format (Always using RGBA as base)
GLenum fmt = GL_RGBA;
if (type == PD::LI::Texture::Type::RGB24) {
if (type == PD::Li::Texture::Type::RGB24) {
fmt = GL_RGB;
} else if (type == PD::LI::Texture::Type::A8) {
} else if (type == PD::Li::Texture::Type::A8) {
fmt = GL_ALPHA;
}
glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
pixels.data());
if (filter == PD::LI::Texture::Filter::LINEAR) {
if (filter == PD::Li::Texture::Filter::LINEAR) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else if (filter == PD::LI::Texture::Filter::NEAREST) {
} else if (filter == PD::Li::Texture::Filter::NEAREST) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
glBindTexture(GL_TEXTURE_2D, 0);
auto res = PD::LI::Texture::New(texID, PD::ivec2(w, h));
auto res = PD::Li::Texture::New(texID, PD::ivec2(w, h));
return res;
}
} // namespace LI
} // namespace Li
} // namespace PD

View File

@ -1,8 +1,7 @@
#pragma once
/*
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,42 +22,37 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/lithium/renderer.hpp>
#include <pd/overlays/overlay.hpp>
#include <pd-desktop/bknd-hid.hpp>
namespace PD {
/**
* Overlay Manager Class
*/
class OverlayMgr : public SmartCtor<OverlayMgr> {
public:
/**
* Constructor
* @param ren Renderer
* @param inp Input Driver reference
*/
OverlayMgr(LI::Renderer::Ref ren, Hid::Ref inp) {
this->ren = ren;
this->inp = inp;
HidGLFW::HidGLFW(GLFWwindow* win) : HidDriver("HidGLFW") {
Window = win;
pBinds[GLFW_MOUSE_BUTTON_LEFT] = Touch;
}
/** Deconstructor */
~OverlayMgr() { overlays.clear(); }
/**
* Append a New Overlay
* @param overlay Overlay reference to push
*/
void Push(Overlay::Ref overlay);
/**
* Update Overlays
* @paran delta Deltatime
*/
void Update(float delta);
void HidGLFW::Update() {
for (int i = 0; i < 2; i++) {
KeyEvents[i][Event_Down] = 0;
KeyEvents[i][Event_Held] = 0;
KeyEvents[i][Event_Up] = 0;
}
int state = glfwGetMouseButton(Window, GLFW_MOUSE_BUTTON_LEFT);
if (state == GLFW_PRESS) {
if (PrevState == GLFW_RELEASE) {
KeyEvents[0][Event_Down] |= Touch;
}
KeyEvents[0][Event_Held] |= Touch;
} else if (state == GLFW_RELEASE && PrevState == GLFW_PRESS) {
KeyEvents[0][Event_Up] |= Touch;
}
private:
std::vector<Overlay::Ref> overlays; ///< Overlay List
LI::Renderer::Ref ren; ///< Renderer reference
Hid::Ref inp; ///< Input Driver reference
};
PrevState = state;
if (pLocked) {
SwapTab();
}
double x, y;
glfwGetCursorPos(Window, &x, &y);
pMouse[1] = pMouse[0]; // Cycle pMouse pos
pMouse[0] = fvec2(x, y);
}
} // namespace PD

View File

@ -0,0 +1,43 @@
/*
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 <palladium>
#include <pd-desktop.hpp>
namespace PD {
void Init(void* data) {
if (!data) {
std::cout << "[PD-DRIVERS] Error: pd-desktop requires GLFWwindow* "
"reference as data "
"input!"
<< std::endl;
abort();
}
// Dekstop Init Stage
// First use default OS Driver
PD::OS::Init();
PD::Li::Gfx::Init(PD::Li::GfxGL2::New());
PD::Hid::Init(PD::HidGLFW::New(reinterpret_cast<GLFWwindow*>(data)));
}
} // namespace PD

View File

@ -1,33 +0,0 @@
#include <pd_hid_glfw.hpp>
namespace PD {
PD_BKND_DESKTOP_API HidGLFW::HidGLFW(GLFWwindow* win) : Hid("GLFW") {
Window = win;
binds[GLFW_MOUSE_BUTTON_LEFT] = Touch;
}
PD_BKND_DESKTOP_API void HidGLFW::Update() {
for (int i = 0; i < 2; i++) {
key_events[i][Event_Down] = 0;
key_events[i][Event_Held] = 0;
key_events[i][Event_Up] = 0;
}
int state = glfwGetMouseButton(Window, GLFW_MOUSE_BUTTON_LEFT);
if (state == GLFW_PRESS) {
if (PrevState == GLFW_RELEASE) {
key_events[0][Event_Down] |= Touch;
}
key_events[0][Event_Held] |= Touch;
} else if (state == GLFW_RELEASE && PrevState == GLFW_PRESS) {
key_events[0][Event_Up] |= Touch;
}
PrevState = state;
if (locked) {
SwappyTable();
}
double x, y;
glfwGetCursorPos(Window, &x, &y);
touch[1] = touch[0]; // Cycle touch pos
touch[0] = fvec2(x, y);
}
} // namespace PD

74
cmake/palladium.cmake Executable file
View File

@ -0,0 +1,74 @@
cmake_minimum_required(VERSION 3.22)
## Utilitys of Palladium Library
### RULES ###
# Force C++ 20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# Enable Compile Command Export
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(PD_INCLUDE_DIR "")
### Helper Function to Build Librarys without have always
### These includes and definition defines
function(pd_add_lib TARGET_NAME)
set(opts "BUILD_SHARED")
set(one_val_args "")
set(multi_val_args SRC_FILES DEPENDS)
cmake_parse_arguments(ARG "${opts}" "${one_val_args}" "${multi_val_args}" ${ARGN})
string(REPLACE "-" "_" FLAG_NAME_T ${TARGET_NAME})
string(TOUPPER ${FLAG_NAME_T} FLAG_NAME_F)
if(ARG_BUILD_SHARED)
add_library(${TARGET_NAME} SHARED ${ARG_SRC_FILES})
target_compile_definitions(${TARGET_NAME} PUBLIC -D${FLAG_NAME_F}_BUILD_SHARED=1)
message("Building SHARED library: ${FLAG_NAME_F}_BUILD_SHARED=1")
else()
add_library(${TARGET_NAME} STATIC ${ARG_SRC_FILES})
target_compile_definitions(${TARGET_NAME} PUBLIC -D${FLAG_NAME_F}_BUILD_SHARED=0)
message("Building STATIC library: ${FLAG_NAME_F}_BUILD_SHARED=0")
endif()
target_include_directories(${TARGET_NAME} PUBLIC
${PD_INCLUDE_DIR}
${DEVKITPRO}/portlibs/3ds/include
)
target_compile_definitions(${TARGET_NAME} PUBLIC
-D_GNU_SOURCE=1
-DPALLADIUM_VERSION="${PROJECT_VERSION}"
-DPALLADIUM_GIT_COMMIT="${GIT_SHORT_HASH}"
-DPALLADIUM_GIT_BRANCH="${GIT_BRANCH}"
-DBUILD_CTR=1
)
### For the libs that depend on another
if(ARG_DEPENDS)
target_link_libraries(${TARGET_NAME} PUBLIC ${ARG_DEPENDS})
endif()
install(TARGETS ${TARGET_NAME})
endfunction()
### GIT HELPER ###
function(pd_git_get_hash ret)
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE _ret
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(${ret} "${_ret}" PARENT_SCOPE)
endfunction()
function(pd_git_get_branch ret)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE _ret
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(${ret} "${_ret}" PARENT_SCOPE)
endfunction()

View File

@ -1,16 +0,0 @@
window.MathJax = {
tex: {
inlineMath: [["\\(", "\\)"]],
displayMath: [["\\[", "\\]"]],
processEscapes: true,
processEnvironments: true
},
options: {
ignoreHtmlClass: ".*|",
processHtmlClass: "arithmatex"
}
};
document$.subscribe(() => {
MathJax.typesetPromise()
})

View File

@ -1,6 +0,0 @@
document$.subscribe(function() {
var tables = document.querySelectorAll("article table:not([class])")
tables.forEach(function(table) {
new Tablesort(table)
})
})

View File

@ -1,22 +0,0 @@
<div class="md-copyright">
{% if config.copyright %}
<div class="md-copyright__highlight">
{{ config.copyright }}
</div>
{% endif %}
{% if not config.extra.generator == false %}
&copy; 2024 -
<script>document.write(new Date().getFullYear());</script>
<a href="https://github.com/tobid7">
tobid7
</a>
- Kassel, Germany | Made with
<a href="https://doxide.org" target="_blank" rel="noopener">
Doxide
</a>
and
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
{% endif %}
</div>

View File

@ -1,58 +0,0 @@
:root {
--md-admonition-icon--variable: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.41 3c1.39 2.71 1.94 5.84 1.59 9-.2 3.16-1.3 6.29-3.17 9l-1.53-1c1.61-2.43 2.55-5.2 2.7-8 .34-2.8-.11-5.57-1.3-8l1.71-1M5.17 3 6.7 4C5.09 6.43 4.15 9.2 4 12c-.34 2.8.12 5.57 1.3 8l-1.69 1c-1.4-2.71-1.96-5.83-1.61-9 .2-3.16 1.3-6.29 3.17-9m6.91 7.68 2.32-3.23h2.53l-3.78 5 2.2 4.92h-2.26L11.71 14l-2.43 3.33H6.76l3.9-5.12-2.13-4.76h2.27l1.28 3.23Z"/></svg>');
--md-admonition-icon--function: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.6 5.29c-1.1-.1-2.07.71-2.17 1.82L13.18 10H16v2h-3l-.44 5.07a3.986 3.986 0 0 1-4.33 3.63 4.007 4.007 0 0 1-3.06-1.87l1.5-1.5c.24.74.9 1.31 1.73 1.38 1.1.1 2.07-.71 2.17-1.82L11 12H8v-2h3.17l.27-3.07c.19-2.2 2.13-3.83 4.33-3.63 1.31.11 2.41.84 3.06 1.87l-1.5 1.5c-.24-.74-.9-1.31-1.73-1.38Z"/></svg>');
--md-admonition-icon--typedef: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M 13.43 7.11 L 13.18 10 H 17 V 12 H 13 L 12.56 17.07 A 1 1 0 0 0 15.287 17.261 L 17.028 17.48 A 1 1 0 0 1 10.57 16.89 L 11 12 H 8 V 10 H 11.17 L 11.44 6.93 Z"/></svg>');
--md-admonition-icon--concept: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3.75 3.5a.25.25 0 0 0-.25.25v2.062a.75.75 0 1 1-1.5 0V3.75C2 2.783 2.783 2 3.75 2h2.062a.75.75 0 1 1 0 1.5Zm13.688-.75a.75.75 0 0 1 .75-.75h2.062c.966 0 1.75.783 1.75 1.75v2.062a.75.75 0 1 1-1.5 0V3.75a.25.25 0 0 0-.25-.25h-2.062a.75.75 0 0 1-.75-.75ZM2.75 17.438a.75.75 0 0 1 .75.75v2.062c0 .138.112.25.25.25h2.062a.75.75 0 1 1 0 1.5H3.75A1.75 1.75 0 0 1 2 20.25v-2.062a.75.75 0 0 1 .75-.75Zm18.5 0a.75.75 0 0 1 .75.75v2.062A1.75 1.75 0 0 1 20.25 22h-2.062a.75.75 0 1 1 0-1.5h2.062a.25.25 0 0 0 .25-.25v-2.062a.75.75 0 0 1 .75-.75Zm-18.5-8.25a.75.75 0 0 1 .75.75v4.124a.75.75 0 1 1-1.5 0V9.938a.75.75 0 0 1 .75-.75ZM9.188 2.75a.75.75 0 0 1 .75-.75h4.124a.75.75 0 1 1 0 1.5H9.938a.75.75 0 0 1-.75-.75Zm0 18.5a.75.75 0 0 1 .75-.75h4.124a.75.75 0 1 1 0 1.5H9.938a.75.75 0 0 1-.75-.75ZM21.25 9.188a.75.75 0 0 1 .75.75v4.124a.75.75 0 1 1-1.5 0V9.938a.75.75 0 0 1 .75-.75ZM3.75 8.25a.75.75 0 0 1 .75-.75h2a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1-.75-.75Zm5.5 0A.75.75 0 0 1 10 7.5h2A.75.75 0 0 1 12 9h-2a.75.75 0 0 1-.75-.75Zm-1-4.5A.75.75 0 0 1 9 4.5v2a.75.75 0 0 1-1.5 0v-2a.75.75 0 0 1 .75-.75Zm0 5.5A.75.75 0 0 1 9 10v2a.75.75 0 0 1-1.5 0v-2a.75.75 0 0 1 .75-.75Zm0 4.75a.75.75 0 0 1 .75.75v4a.75.75 0 0 1-1.5 0v-4a.75.75 0 0 1 .75-.75ZM14 8.25a.75.75 0 0 1 .75-.75h4a.75.75 0 0 1 0 1.5h-4a.75.75 0 0 1-.75-.75Z"/></svg>');
--md-admonition-icon--macro: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m5.41 21 .71-4h-4l.35-2h4l1.06-6h-4l.35-2h4l.71-4h2l-.71 4h6l.71-4h2l-.71 4h4l-.35 2h-4l-1.06 6h4l-.35 2h-4l-.71 4h-2l.71-4h-6l-.71 4h-2M9.53 9l-1.06 6h6l1.06-6h-6Z"/></svg>');
}
.md-typeset .admonition.variable, .md-typeset details.variable,
.md-typeset .admonition.function, .md-typeset details.function,
.md-typeset .admonition.typedef, .md-typeset details.typedef,
.md-typeset .admonition.concept, .md-typeset details.concept,
.md-typeset .admonition.macro, .md-typeset details.macro {
border-color: var(--md-default-fg-color--lighter);
}
.md-typeset .variable > .admonition-title, .md-typeset .variable > summary,
.md-typeset .function > .admonition-title, .md-typeset .function > summary,
.md-typeset .typedef > .admonition-title, .md-typeset .typedef > summary,
.md-typeset .concept > .admonition-title, .md-typeset .concept > summary,
.md-typeset .macro > .admonition-title, .md-typeset .macro > summary {
background-color: var(--md-default-bg-color);
}
.md-typeset .variable > .admonition-title::before,
.md-typeset .variable > summary::before {
background-color: var(--md-default-fg-color--light);
-webkit-mask-image: var(--md-admonition-icon--variable);
mask-image: var(--md-admonition-icon--variable);
}
.md-typeset .function > .admonition-title::before,
.md-typeset .function > summary::before {
background-color: var(--md-default-fg-color--light);
-webkit-mask-image: var(--md-admonition-icon--function);
mask-image: var(--md-admonition-icon--function);
}
.md-typeset .typedef > .admonition-title::before,
.md-typeset .typedef > summary::before {
background-color: var(--md-default-fg-color--light);
-webkit-mask-image: var(--md-admonition-icon--typedef);
mask-image: var(--md-admonition-icon--typedef);
}
.md-typeset .concept > .admonition-title::before,
.md-typeset .concept > summary::before {
background-color: var(--md-default-fg-color--light);
-webkit-mask-image: var(--md-admonition-icon--concept);
mask-image: var(--md-admonition-icon--concept);
}
.md-typeset .macro > .admonition-title::before,
.md-typeset .macro > summary::before {
background-color: var(--md-default-fg-color--light);
-webkit-mask-image: var(--md-admonition-icon--macro);
mask-image: var(--md-admonition-icon--macro);
}

View File

@ -1,15 +0,0 @@
title: Palladium
description:
files:
- "include/*.hpp"
- "include/pd/app/*.hpp"
- "include/pd/core/*.hpp"
- "include/pd/drivers/*.hpp"
- "include/pd/image/*.hpp"
- "include/pd/lib3ds/*.hpp"
- "include/pd/lithium/*.hpp"
- "include/pd/net/*.hpp"
- "include/pd/overlays/*.hpp"
- "include/pd/sound/*.hpp"
- "include/pd/ui7/*.hpp"
- "include/pd/ui7/container/*.hpp"

8
include/palladium Executable file
View File

@ -0,0 +1,8 @@
#pragma once
#include <pd/core/core.hpp>
#include <pd/drivers/drivers.hpp>
#include <pd/external/json.hpp>
#include <pd/image/image.hpp>
#include <pd/lithium/lithium.hpp>
#include <pd/ui7/ui7.hpp>

View File

@ -1,51 +0,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.
*/
// Core
#include <pd/core/core.hpp>
// Image
#include <pd/image/image.hpp>
#include <pd/image/img_blur.hpp>
#include <pd/image/img_convert.hpp>
#include <pd/ui7/ui7.hpp>
// Net
#include <pd/net/backend.hpp>
#include <pd/net/socket.hpp>
/// Setup these as non Namespaced access by default
#ifndef PD_MATH_NAMESPACED
using fvec2 = PD::fvec2;
using fvec3 = PD::fvec3;
using fvec4 = PD::fvec4;
using dvec2 = PD::dvec2;
using dvec3 = PD::dvec3;
using dvec4 = PD::dvec4;
using ivec2 = PD::ivec2;
using ivec3 = PD::ivec3;
using ivec4 = PD::ivec4;
#endif
// namespace Palladium = PD;

0
include/pd/core/bit_util.hpp Normal file → Executable file
View File

151
include/pd/core/color.hpp Normal file → Executable file
View 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

103
include/pd/core/common.hpp Normal file → Executable file
View File

@ -38,94 +38,31 @@ SOFTWARE.
#include <string>
#include <vector>
// Platform API
/** Dynamic Lib loading */
#include <pd/core/pd_p_api.hpp>
// Legacy Smart Pointer
#define PD_SMART_CTOR(x) \
/** Memory Management */
#define PD_SHARED(x) \
using Ref = std::shared_ptr<x>; \
template <typename... args> \
static Ref New(args&&... cargs) { \
return std::make_shared<x>(std::forward<args>(cargs)...); \
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 {
/**
* 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 */
/** Types */
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
using u16 = unsigned short;
using u32 = unsigned int;
using u64 = unsigned long long;
} // namespace PD

6
include/pd/core/core.hpp Normal file → Executable file
View 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
@ -26,13 +25,10 @@ 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>

16
include/pd/core/io.hpp Normal file → Executable file
View File

@ -30,12 +30,6 @@ 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
@ -53,20 +47,10 @@ PD_CORE_API u32 HashMemory(const std::vector<u8>& data);
* @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
} // namespace PD

0
include/pd/core/mat.hpp Normal file → Executable file
View File

5
include/pd/core/pd_p_api.hpp Normal file → Executable file
View 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
@ -24,6 +23,8 @@ 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
#define PD_CORE_API __declspec(dllexport)

0
include/pd/core/sl/allocator.hpp Normal file → Executable file
View File

0
include/pd/core/sl/hashmap.hpp Normal file → Executable file
View File

0
include/pd/core/sl/list.hpp Normal file → Executable file
View File

0
include/pd/core/sl/pair.hpp Normal file → Executable file
View File

0
include/pd/core/sl/sl.hpp Normal file → Executable file
View File

0
include/pd/core/sl/stack.hpp Normal file → Executable file
View File

0
include/pd/core/sl/tools.hpp Normal file → Executable file
View File

0
include/pd/core/sl/vector.hpp Normal file → Executable file
View File

0
include/pd/core/strings.hpp Normal file → Executable file
View File

13
include/pd/core/timer.hpp Normal file → Executable file
View File

@ -24,13 +24,12 @@ SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/sys.hpp>
namespace PD {
/**
* Timer class
*/
class PD_CORE_API Timer : public SmartCtor<Timer> {
class PD_CORE_API Timer {
public:
/**
* Constructor
@ -41,6 +40,9 @@ class PD_CORE_API Timer : public SmartCtor<Timer> {
* Unused Deconstructor
*/
~Timer() {}
PD_SHARED(Timer);
/**
* Resume Timer if Paused
*/
@ -73,12 +75,11 @@ class PD_CORE_API Timer : public SmartCtor<Timer> {
*/
double GetSeconds();
private:
/** Start of the Timer */
u64 start;
u64 pStart;
/** Current Time */
u64 now;
u64 pNow;
/** Is Running */
bool is_running = false;
bool pIsRunning = false;
};
} // namespace PD

16
include/pd/core/timetrace.hpp Normal file → Executable file
View File

@ -29,7 +29,7 @@ namespace PD {
/**
* Class to calculate Maximum/Minimum and Average Timings
*/
class TimeStats : public SmartCtor<TimeStats> {
class TimeStats {
public:
/**
* Constructor taking a lengh for the List
@ -38,6 +38,8 @@ class TimeStats : public SmartCtor<TimeStats> {
TimeStats(int l) : len(l), val(l, 0) {}
~TimeStats() = default;
PD_SHARED(TimeStats);
/**
* Add a New Value to the list
* @param v value to add
@ -146,12 +148,14 @@ namespace TT {
/**
* Data Structure for a TimeTrace Result
*/
class Res : public SmartCtor<Res> {
class Res {
public:
/** Constructore that Inits a protocol at size of 60 frames */
Res() { protocol = TimeStats::New(60); }
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
@ -239,17 +243,17 @@ class Scope {
* @param id Name of the Trace
*/
Scope(const std::string &id) {
this->id = id;
this->ID = id;
Beg(id);
}
/**
* Deconstructor getting the end time when going out of scope
*/
~Scope() { End(id); }
~Scope() { End(ID); }
private:
/** Trace Name/ID */
std::string id;
std::string ID;
};
} // namespace TT
} // namespace PD

0
include/pd/core/tween.hpp Normal file → Executable file
View File

34
include/pd/core/vec.hpp Normal file → Executable file
View 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>
/** 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);
}
};

151
include/pd/core/vec2.hpp Normal file → Executable file
View File

@ -23,113 +23,142 @@ 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:
// SECTION: Constructors //
T x;
T y;
vec2() = default;
vec2(T v) {
x = v;
y = v;
}
vec2(T x, T y) {
this->x = x;
this->y = y;
vec2() : x(0), y(0) {}
template <typename T1>
vec2(T1 v) {
x = (T)v;
y = (T)v;
}
vec2(const vec2<T> &v) {
x = v.x;
y = v.y;
template <typename T1>
vec2(vec2<T1> v) {
x = (T)v.x;
y = (T)v.y;
}
// SECTION: Operators //
vec2(T x, T y) : x(x), y(y) {}
// ADD //
vec2 &operator+=(T v) {
x += v;
y += v;
template <typename T1>
vec2<T>& operator+=(T1 v) {
x += (T)v;
y += (T)v;
return *this;
}
vec2 &operator+=(const vec2 &v) {
x += v.x;
y += v.y;
template <typename T1>
vec2<T>& operator+=(const vec2<T1>& v) {
x += (T)v.x;
y += (T)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 //
template <typename T1>
vec2<T> operator+(T1 v) const {
return vec2<T>(x + (T)v, y + (T)v);
}
vec2 &operator-=(T v) {
x -= v;
y -= 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;
}
vec2 &operator-=(const vec2 &v) {
x -= v.x;
y -= v.y;
template <typename T1>
vec2<T>& operator-=(const vec2<T1>& v) {
x -= (T)v.x;
y -= (T)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 //
template <typename T1>
vec2<T> operator-(T1 v) const {
return vec2<T>(x - (T)v, y - (T)v);
}
vec2 &operator*=(T v) {
x *= v;
y *= 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;
}
vec2 &operator*=(const vec2 &v) {
x *= v.x;
y *= v.y;
template <typename T1>
vec2<T>& operator*=(const vec2<T1>& v) {
x *= (T)v.x;
y *= (T)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 //
template <typename T1>
vec2<T> operator*(T1 v) const {
return vec2<T>(x * (T)v, y * (T)v);
}
vec2 &operator/=(T v) {
x /= v;
y /= 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;
}
vec2 &operator/=(const vec2 &v) {
x /= v.x;
y /= v.y;
template <typename T1>
vec2<T>& operator/=(const vec2<T1>& v) {
x /= (T)v.x;
y /= (T)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 //
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); }
// SECTION: Additional Functions //
double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y; }
float Len() const { return sqrt(SqLen()); }
float SqLen() const { return x * x + y * y; }
void Swap() {
void SwapXY() {
T t = x;
x = y;
y = t;
}
// SECTION: DATA //
T x = 0;
T y = 0;
};
using dvec2 = vec2<double>;
using fvec2 = vec2<float>;
using dvec2 = vec2<double>;
using ivec2 = vec2<int>;
} // namespace PD

189
include/pd/core/vec3.hpp Normal file → Executable file
View File

@ -23,104 +23,138 @@ 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>
namespace PD {
template <typename T>
class vec3 {
public:
// SECTION: Constructors //
T x;
T y;
T z;
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() : x(0), y(0), z(0) {}
template <typename T1>
explicit vec3(T1 v) {
x = (T)v;
y = (T)v;
z = (T)v;
}
vec3(const vec3 &v) {
x = v.x;
y = v.y;
z = v.z;
template <typename T1>
explicit vec3(vec3<T1> v) {
x = (T)v.x;
y = (T)v.y;
z = (T)v.z;
}
// SECTION: Operators //
vec3(T x, T y, T z) : x(x), y(y), z(z) {}
// ADD //
vec3 &operator+=(T v) {
x += v;
y += v;
z += v;
template <typename T1>
vec3<T>& operator+=(T1 v) {
x += (T)v;
y += (T)v;
z += (T)v;
return *this;
}
vec3 &operator+=(const vec3 &v) {
x += v.x;
y += v.y;
z += v.z;
template <typename T1>
vec3<T>& operator+=(const vec3<T1>& v) {
x += (T)v.x;
y += (T)v.y;
z += (T)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 //
template <typename T1>
vec3<T> operator+(T1 v) const {
return vec3<T>(x + (T)v, y + (T)v, z + (T)v);
}
vec3 &operator-=(T v) {
x -= v;
y -= v;
z -= 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;
}
vec3 &operator-=(const vec3 &v) {
x -= v.x;
y -= v.y;
z -= v.z;
template <typename T1>
vec3<T>& operator-=(const vec3<T1>& v) {
x -= (T)v.x;
y -= (T)v.y;
z -= (T)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 //
template <typename T1>
vec3<T> operator-(T1 v) const {
return vec3<T>(x - (T)v, y - (T)v, z - (T)v);
}
vec3 &operator*=(T v) {
x *= v;
y *= v;
z *= 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;
}
vec3 &operator*=(const vec3 &v) {
x *= v.x;
y *= v.y;
z *= v.z;
template <typename T1>
vec3<T>& operator*=(const vec3<T1>& v) {
x *= (T)v.x;
y *= (T)v.y;
z *= (T)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 //
template <typename T1>
vec3<T> operator*(T1 v) const {
return vec3<T>(x * (T)v, y * (T)v, z * (T)v);
}
vec3 &operator/=(T v) {
x /= v;
y /= v;
z /= 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;
}
vec3 &operator/=(const vec3 &v) {
x /= v.x;
y /= v.y;
z /= v.z;
template <typename T1>
vec3<T>& operator/=(const vec3<T1>& v) {
x /= (T)v.x;
y /= (T)v.y;
z /= (T)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 //
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 {
@ -128,33 +162,26 @@ class vec3 {
}
bool operator!=(const vec3& v) const { return !(*this == v); }
// SECTION: Additional Functions //
double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y + z * z; }
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;
T t = x;
x = z;
z = t;
}
void SwapYZ() {
T t = y;
y = z;
z = t;
}
// SECTION: DATA //
T x = 0;
T y = 0;
T z = 0;
};
using dvec3 = vec3<double>;
using fvec3 = vec3<float>;
using dvec3 = vec3<double>;
using ivec3 = vec3<int>;
} // namespace PD

244
include/pd/core/vec4.hpp Normal file → Executable file
View File

@ -23,130 +23,159 @@ 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/vec3.hpp>
#include <pd/core/vec2.hpp> // Extended
namespace PD {
template <typename T>
class vec4 {
public:
// SECTION: Constructors //
T x;
T y;
T z;
T w;
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() : 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;
}
vec4(const vec4 &v) {
x = v.x;
y = v.y;
z = v.z;
w = v.w;
template <typename T1>
explicit vec4(vec4<T1> v) {
x = (T)v.x;
y = (T)v.y;
z = (T)v.z;
w = (T)v.w;
}
vec4(const vec2<T> &xy, const vec2<T> &zw) {
x = xy.x;
y = xy.y;
z = zw.x;
w = zw.y;
/** 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;
}
// SECTION: Operators //
vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {}
// ADD //
vec4 &operator+=(T v) {
x += v;
y += v;
z += v;
w += v;
template <typename T1>
vec4<T>& operator+=(T1 v) {
x += (T)v;
y += (T)v;
z += (T)v;
w += (T)v;
return *this;
}
vec4 &operator+=(const vec4<T> &v) {
x += v.x;
y += v.y;
z += v.z;
w += v.w;
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;
}
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);
template <typename T1>
vec4<T> operator+(T1 v) const {
return vec4<T>(x + (T)v, y + (T)v, z + (T)v, w + (T)v);
}
// SUB //
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-=(T v) {
x -= v;
y -= v;
z -= v;
w -= v;
template <typename T1>
vec4<T>& operator-=(T1 v) {
x -= (T)v;
y -= (T)v;
z -= (T)v;
w -= (T)v;
return *this;
}
vec4 &operator-=(const vec4 &v) {
x -= v.x;
y -= v.y;
z -= v.z;
w -= v.w;
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;
}
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);
template <typename T1>
vec4<T> operator-(T1 v) const {
return vec4<T>(x - (T)v, y - (T)v, z - (T)v, w - (T)v);
}
// MUL //
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*=(T v) {
x *= v;
y *= v;
z *= v;
w *= v;
template <typename T1>
vec4<T>& operator*=(T1 v) {
x *= (T)v;
y *= (T)v;
z *= (T)v;
w *= (T)v;
return *this;
}
vec4 &operator*=(const vec4 &v) {
x *= v.x;
y *= v.y;
z *= v.z;
w *= v.w;
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;
}
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);
template <typename T1>
vec4<T> operator*(T1 v) const {
return vec4<T>(x * (T)v, y * (T)v, z * (T)v, w * (T)v);
}
// DIV //
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/=(T v) {
x /= v;
y /= v;
z /= v;
w /= v;
template <typename T1>
vec4<T>& operator/=(T1 v) {
x /= (T)v;
y /= (T)v;
z /= (T)v;
w /= (T)v;
return *this;
}
vec4 &operator/=(const vec4 &v) {
x /= v.x;
y /= v.y;
z /= v.z;
w /= v.w;
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;
}
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);
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);
}
// Make Negative //
vec4 operator-() const { return vec4(-x, -y, -z, -w); }
bool operator==(const vec4& v) const {
@ -154,40 +183,41 @@ class vec4 {
}
bool operator!=(const vec4& v) const { return !(*this == v); }
// SECTION: Additional Functions //
double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y + z * z + w * w; }
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;
T t = x;
x = z;
z = t;
}
// SECTION: DATA //
T x = 0;
T y = 0;
T z = 0;
T w = 0;
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 dvec4 = vec4<double>;
using fvec4 = vec4<float>;
using dvec4 = vec4<double>;
using ivec4 = vec4<int>;
} // namespace PD

View File

@ -1,3 +1,5 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
@ -21,17 +23,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/overlays/overlay_mgr.hpp>
namespace PD {
void OverlayMgr::Push(Overlay::Ref overlay) { overlays.push_back(overlay); }
void OverlayMgr::Update(float delta) {
for (size_t i = 0; i < overlays.size(); i++) {
if (overlays[i]->IsKilled()) {
overlays.erase(overlays.begin() + i);
continue;
}
overlays[i]->Update(delta, ren, inp);
}
}
} // namespace PD
#include <pd/drivers/gfx.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/drivers/os.hpp>

111
include/pd/drivers/gfx.hpp Executable file
View File

@ -0,0 +1,111 @@
#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/core.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/texture.hpp>
using LiBackendFlags = PD::u32;
enum LiBackendFlags_ {
LiBackendFlags_None = 0,
LiBackendFlags_FlipUV_Y = PD_BIT(0), // Essential for font loading
};
namespace PD {
namespace Li {
class GfxDriver {
public:
GfxDriver(const std::string& name = "NullGfx") : pName(name) {};
~GfxDriver() = default;
PD_SHARED(GfxDriver);
void PostInit();
virtual void Init() {}
virtual void Deinit() {}
virtual void NewFrame() {}
virtual void BindTex(TexAddress addr) {}
virtual void RenderDrawData(const std::vector<Command::Ref>& Commands) {}
virtual Texture::Ref LoadTex(
const std::vector<u8>& pixels, int w, int h,
Texture::Type type = Texture::Type::RGBA32,
Texture::Filter filter = Texture::Filter::LINEAR) {
// Texture loading not supported (when this func not get override)
return nullptr;
}
Texture::Ref GetSolidTex() { return pSolid; }
const std::string pName = "NullGfx";
LiBackendFlags Flags = 0;
ivec2 ViewPort;
fvec4 ClearColor;
Texture::Ref pSolid;
/** Debug Variables */
// Optional Index counter
u32 IndexCounter;
// Optional Vertex counter
u32 VertexCounter;
// Optional Frame Counter
u64 FrameCounter;
};
/** Static Gfx Controller */
class Gfx {
public:
Gfx() = default;
~Gfx() = default;
static void Init(GfxDriver::Ref d);
static void Deinit() { pGfx->Deinit(); }
static void NewFrame() { pGfx->NewFrame(); }
static void BindTex(TexAddress addr) { pGfx->BindTex(addr); }
static void RenderDrawData(const std::vector<Command::Ref>& Commands) {
pGfx->RenderDrawData(Commands);
}
static LiBackendFlags Flags() { return pGfx->Flags; }
static Texture::Ref LoadTex(
const std::vector<u8>& pixels, int w, int h,
Texture::Type type = Texture::Type::RGBA32,
Texture::Filter filter = Texture::Filter::LINEAR) {
return pGfx->LoadTex(pixels, w, h, type, filter);
}
static Texture::Ref GetSolidTex() { return pGfx->GetSolidTex(); }
static GfxDriver::Ref pGfx;
};
} // namespace Li
} // namespace PD

View File

@ -16,19 +16,17 @@ 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
FITNESS FOR A PARTICULAR PURPHidE 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>
#include <pd/core/core.hpp>
namespace PD {
/** Input Driver Template class */
class PD_CORE_API Hid : public SmartCtor<Hid> {
class HidDriver {
public:
/** Key [Controller] */
enum Key : u32 {
@ -61,25 +59,29 @@ class PD_CORE_API Hid : public SmartCtor<Hid> {
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;
HidDriver(const std::string& name = "NullHid") : pName(name) {};
virtual ~HidDriver() = default;
PD_SHARED(HidDriver);
/**
* Get TOuch Position
* @return touch pos
* Get Mouse Position
* @return Mouse pos
*/
fvec2 TouchPos() const { return touch[0]; }
/**
* Get Last Touch Position (from last frame)
* @return touch pos
fvec2 MousePos() const {
return pMouse[0];
} /**
* Get Last Mouse Position (from last frame)
* @return Mouse pos
*/
fvec2 TouchPosLast() const { return touch[1]; }
fvec2 MousePosLast() const { return pMouse[1]; }
/**
* Check for a Button Event
@ -93,28 +95,28 @@ class PD_CORE_API Hid : public SmartCtor<Hid> {
* @param keys set of keys
* @return true if key is pressed
*/
bool IsDown(Key keys) const { return key_events[0].at(Event_Down) & keys; }
bool IsDown(Key keys) const { return KeyEvents[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; }
bool IsHeld(Key keys) const { return KeyEvents[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; }
bool IsUp(Key keys) const { return KeyEvents[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;
KeyEvents[i][Event_Down] = 0;
KeyEvents[i][Event_Up] = 0;
KeyEvents[i][Event_Held] = 0;
}
}
@ -123,33 +125,35 @@ class PD_CORE_API Hid : public SmartCtor<Hid> {
* @param v lock or not lock
*/
void Lock(bool v) {
if (v != locked) {
SwappyTable();
if (v != pLocked) {
SwapTab();
}
locked = v;
pLocked = v;
}
/**
* Check if Driver is locked
* @return true if locked
*/
bool Locked() const { return locked; }
bool Locked() const { return pLocked; }
/**
* Lock Input Driver
*/
void Lock() {
if (!locked) {
SwappyTable();
if (!pLocked) {
SwapTab();
}
locked = true;
pLocked = true;
}
/**
* Unlock Input Driver
*/
void Unlock() {
if (locked) {
SwappyTable();
if (pLocked) {
SwapTab();
}
locked = false;
pLocked = false;
}
/**
@ -157,19 +161,54 @@ class PD_CORE_API Hid : public SmartCtor<Hid> {
*/
virtual void Update() {}
/** Data Section */
/** 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];
/** Key Binds Map */
std::unordered_map<u32, u32> pBinds;
/** Swap Tabe Function */
void SwapTab();
/** Using 2 Positions for Current and Last */
fvec2 pMouse[2];
/** Lock State */
bool pLocked = false;
/** Key Event Table Setup */
std::unordered_map<Event, u32> KeyEvents[2];
};
/** Static Hid Controller */
class Hid {
public:
Hid() = default;
~Hid() = default;
/** Referenec to Drivers enums */
using Key = HidDriver::Key;
using Event = HidDriver::Event;
static void Init(HidDriver::Ref v = nullptr) {
if (v) {
pHid = v;
} else {
pHid = HidDriver::New();
}
}
static bool IsEvent(Event e, Key keys) { return pHid->IsEvent(e, keys); }
static bool IsDown(Key keys) { return pHid->IsDown(keys); }
static bool IsUp(Key keys) { return pHid->IsUp(keys); }
static bool IsHeld(Key keys) { return pHid->IsHeld(keys); }
static fvec2 MousePos() { return pHid->MousePos(); }
static fvec2 MousePosLast() { return pHid->MousePosLast(); }
static void Clear() { pHid->Clear(); }
static void Lock() { pHid->Lock(); }
static void Lock(bool v) { pHid->Lock(v); }
static void Unlock() { pHid->Unlock(); }
static bool Locked() { return pHid->Locked(); }
static void Update() { pHid->Update(); }
static HidDriver::Ref pHid;
};
} // namespace PD

75
include/pd/core/sys.hpp → include/pd/drivers/os.hpp Normal file → Executable file
View File

@ -27,40 +27,45 @@ SOFTWARE.
#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
class OsDriver {
public:
OsDriver() = default;
virtual ~OsDriver() = default;
PD_SHARED(OsDriver);
virtual u64 GetTime();
virtual u64 GetNanoTime();
TraceMap& GetTraceMap();
TT::Res::Ref& GetTraceRef(const std::string& id);
bool TraceExist(const std::string& id);
TraceMap pTraces;
};
/** Static Os Controller */
class OS {
public:
OS() = default;
~OS() = default;
static void Init(OsDriver::Ref v = nullptr) {
if (v) {
pOs = v;
} else {
pOs = OsDriver::New();
}
}
static u64 GetTime() { return pOs->GetTime(); }
static u64 GetNanoTime() { return pOs->GetNanoTime(); }
static TraceMap& GetTraceMap() { return pOs->GetTraceMap(); }
static TT::Res::Ref& GetTraceRef(const std::string& id) {
return pOs->GetTraceRef(id);
}
static bool TraceExist(const std::string& id) { return pOs->TraceExist(id); }
static OsDriver::Ref pOs;
};
} // namespace PD

26
include/pd/drivers/pd_p_api.hpp Executable file
View File

@ -0,0 +1,26 @@
#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.
*/
#define PD_DEF_EXP(x, y) x y = nullptr

0
include/pd/external/json.hpp vendored Normal file → Executable file
View File

0
include/pd/external/stb_image.h vendored Normal file → Executable file
View File

0
include/pd/external/stb_truetype.h vendored Normal file → Executable file
View File

4
include/pd/image/image.hpp Normal file → Executable file
View File

@ -28,7 +28,7 @@ SOFTWARE.
#include <pd/image/pd_p_api.hpp>
namespace PD {
class PD_IMAGE_API Image : public SmartCtor<Image> {
class PD_IMAGE_API Image {
public:
enum Format {
RGBA, // bpp == 4
@ -45,6 +45,8 @@ class PD_IMAGE_API Image : public SmartCtor<Image> {
}
~Image() = default;
PD_SHARED(Image)
void Load(const std::string& path);
void Load(const std::vector<u8>& buf);
void Copy(const std::vector<u8>& buf, int w, int h, int bpp = 4);

0
include/pd/image/img_blur.hpp Normal file → Executable file
View File

0
include/pd/image/img_convert.hpp Normal file → Executable file
View File

5
include/pd/image/pd_p_api.hpp Normal file → Executable file
View 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
@ -24,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
/** Generated with ppam */
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_IMAGE_BUILD_SHARED

View File

@ -1,76 +0,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/core.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/texture.hpp>
using LIBackendFlags = PD::u32;
enum LIBackendFlags_ {
LIBackendFlags_None = 0,
LIBackendFlags_FlipUV_Y = 1 << 0, // Essential for Font Loading
};
namespace PD {
namespace LI {
class Backend {
public:
Backend(const std::string& name = "NullBackend") : pName(name) {}
~Backend() = default;
// Using Legacy SmartCTOR API here
PD_SMART_CTOR(Backend)
virtual void Init() {}
virtual void Deinit() {}
virtual void NewFrame() {}
virtual void BindTexture(TexAddress addr) {}
virtual void RenderDrawData(const Vec<Command::Ref>& Commands) {}
virtual Texture::Ref LoadTexture(
const std::vector<PD::u8>& pixels, int w, int h,
Texture::Type type = Texture::Type::RGBA32,
Texture::Filter filter = Texture::Filter::LINEAR) {
// Texture loading not supported (when this func not get override)
return nullptr;
}
/** Backend identification name */
const std::string pName = "NullBackend";
LIBackendFlags Flags = 0;
ivec2 ViewPort;
fvec4 ClearColor;
// Optional Index Counter
int IndexCounter = 0;
// Optional Vertex Counter
int VertexCounter = 0;
// Optional Frame Counter
int FrameCounter = 0;
};
} // namespace LI
} // namespace PD

28
include/pd/lithium/command.hpp Normal file → Executable file
View 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
@ -25,38 +24,35 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
// #include <pd/lithium/flags.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/lithium/vertex.hpp>
namespace PD {
namespace LI {
/**
* Lithium Draw Command (containing a list of vertex and index data
* only for this specific command itself)
*/
class Command : public SmartCtor<Command> {
namespace Li {
class Command {
public:
Command() = default;
~Command() = default;
Command& AppendIndex(u16 idx) {
PD_UNIQUE(Command);
Command& AddIdx(const u16& idx) {
IndexBuffer.Add(VertexBuffer.Size() + idx);
return *this;
}
Command& AppendVertex(const Vertex& v) {
VertexBuffer.Add(v);
Command& AddVtx(const Vertex& v) {
VertexBuffer.Add(std::move(v));
return *this;
}
Vec<Vertex> VertexBuffer;
Vec<u16> IndexBuffer;
PD::Vec<Vertex> VertexBuffer;
PD::Vec<u16> IndexBuffer;
ivec4 ScissorRect;
bool ScissorEnabled = false;
bool ScissorOn = false;
int Layer;
int Index;
Texture::Ref Tex;
};
} // namespace LI
} // namespace Li
} // namespace PD

82
include/pd/lithium/drawlist.hpp Normal file → Executable file
View File

@ -28,24 +28,47 @@ SOFTWARE.
#include <pd/lithium/font.hpp>
#include <pd/lithium/pd_p_api.hpp>
/** Path Rect Flags */
using LiPathRectFlags = PD::u32;
/** Setup for everything (oder so) */
enum LiPathRectFlags_ : PD::u32 {
LiPathRectFlags_None = 0,
LiPathRectFlags_KeepTopLeft = PD_BIT(0),
LiPathRectFlags_KeepTopRight = PD_BIT(1),
LiPathRectFlags_KeepBotRight = PD_BIT(2),
LiPathRectFlags_KeepBotLeft = PD_BIT(3),
LiPathRectFlags_KeepTop = PD_BIT(0) | PD_BIT(1),
LiPathRectFlags_KeepBot = PD_BIT(2) | PD_BIT(3),
LiPathRectFlags_KeepLeft = PD_BIT(0) | PD_BIT(3),
LiPathRectFlags_KeepRight = PD_BIT(1) | PD_BIT(2),
};
namespace PD {
namespace LI {
class PD_LITHIUM_API DrawList : public SmartCtor<DrawList> {
namespace Li {
class PD_LITHIUM_API DrawList {
public:
DrawList(Texture::Ref solid) {
WhitePixel = solid;
CurrentTex = solid;
}
~DrawList() {}
DrawList() { DrawSolid(); }
~DrawList() { pDrawList.clear(); }
/** Require Copy and Move Constructors */
DrawList(const DrawList&) = delete;
DrawList& operator=(const DrawList&) = delete;
DrawList(DrawList&&) noexcept = default;
DrawList& operator=(DrawList&&) noexcept = default;
PD_SHARED(DrawList);
Command::Ref PreGenerateCmd();
void AddCommand(Command::Ref v) { pDrawList.Add(v); }
void Clear() { pDrawList.Clear(); }
void AddCommand(Command::Ref v) { pDrawList.push_back(std::move(v)); }
void Clear() { pDrawList.clear(); }
void SetFont(Font::Ref font) { pCurrentFont = font; }
void SetFontScale(float scale) { pFontScale = scale; }
void DrawSolid() { CurrentTex = WhitePixel; }
void DrawSolid();
void DrawTexture(Texture::Ref tex) { CurrentTex = tex; }
// SECTION: Draw API //
@ -62,7 +85,12 @@ class PD_LITHIUM_API DrawList : public SmartCtor<DrawList> {
void DrawCircleFilled(const fvec2& center, float rad, u32 color,
int num_segments);
void DrawText(const fvec2& p, const std::string& text, u32 color);
/**
* Extended Draw Text Function
*/
void DrawTextEx(const fvec2& p, const std::string& text, u32 color,
LiTextFlags flags, fvec2 box = fvec2(0.f));
void DrawLine(const fvec2& a, const fvec2& b, u32 color, int t = 1);
/**
* Take list of points and display it as a line on screen
* @param points List of Positions
@ -126,20 +154,38 @@ class PD_LITHIUM_API DrawList : public SmartCtor<DrawList> {
}
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
int segments);
void PathFastArcToN(const fvec2& c, float r, float amin, float amax, int s);
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
/// @param a Top Left Position
/// @param b Bottom Right Position
/// @param rounding rounding
void PathRect(fvec2 a, fvec2 b, float rounding = 0.f);
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
/// @param a Top Left Position
/// @param b Bottom Right Position
/// @param rounding rounding
/// @param flags DrawFlags (for special rounding rules)
void PathRect(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0);
void PathRectEx(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0);
int Layer = 0;
void PushClipRect(const fvec4& cr) { pClipRects.Push(cr); }
void PopClipRect() {
if (pClipRects.IsEmpty()) {
return;
}
pClipRects.Pop();
}
/** One linear Clip rect Setup */
void pClipCmd(Command* cmd);
/** Data Section */
Stack<fvec4> pClipRects;
int Layer;
float pFontScale = 0.7f;
Font::Ref pCurrentFont = nullptr;
Texture::Ref CurrentTex = nullptr;
Texture::Ref WhitePixel = nullptr;
PD::Vec<Command::Ref> pDrawList;
Font::Ref pCurrentFont;
Texture::Ref CurrentTex;
std::vector<Command::Ref> pDrawList;
PD::Vec<fvec2> pPath;
};
} // namespace LI
} // namespace Li
} // namespace PD

51
include/pd/lithium/font.hpp Normal file → Executable file
View File

@ -25,26 +25,25 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/lithium/backend.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/pd_p_api.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/texture.hpp>
using LITextFlags = PD::u32;
enum LITextFlags_ {
LITextFlags_None = 0, ///< Do nothing
LITextFlags_AlignRight = 1 << 0, ///< Align Right of position
LITextFlags_AlignMid = 1 << 1, ///< Align in the middle of pos and box
LITextFlags_Shaddow = 1 << 2, ///< Draws the text twice to create shaddow
LITextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
LITextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
LITextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
using LiTextFlags = PD::u32;
enum LiTextFlags_ {
LiTextFlags_None = 0, ///< Do nothing
LiTextFlags_AlignRight = 1 << 0, ///< Align Right of position
LiTextFlags_AlignMid = 1 << 1, ///< Align in the middle of pos and box
LiTextFlags_Shaddow = 1 << 2, ///< Draws the text twice to create shaddow
LiTextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
LiTextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
LiTextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
};
namespace PD {
namespace LI {
/** Font Loader for Lithium */
class PD_LITHIUM_API Font : public SmartCtor<Font> {
namespace Li {
class PD_LITHIUM_API Font {
public:
/** Codepoint Data holder */
struct Codepoint {
@ -55,8 +54,13 @@ class PD_LITHIUM_API Font : public SmartCtor<Font> {
float Offset = 0.f;
bool pInvalid = false;
};
Font(Backend::Ref backend) { pBackend = backend; };
/** Constructore doesnt need Backand anymore */
Font() = default;
~Font() = default;
PD_SHARED(Font);
/**
* Load a TTF File
* @param path Path to the TTF file
@ -76,20 +80,19 @@ class PD_LITHIUM_API Font : public SmartCtor<Font> {
/**
* Extended Draw Text Function that vreates a Command List
*/
void CmdTextEx(Vec<Command::Ref>& cmds, const fvec2& pos, u32 color,
float scale, const std::string& text, LITextFlags flags = 0,
void CmdTextEx(std::vector<Command::Ref>& cmds, const fvec2& pos, u32 color,
float scale, const std::string& text, LiTextFlags flags = 0,
const fvec2& box = 0);
/** Pixelheight */
/** Data Section */
int PixelHeight;
int DefaultPixelHeight = 24;
private:
/** List of textures (codepoints are using) */
std::vector<Texture::Ref> Textures;
/** 32Bit Codepoint Dataholder Reference Map */
std::map<u32, Codepoint> CodeMap;
Backend::Ref pBackend = nullptr;
/**
* 32Bit Codepoint Dataholder reference map
* **Now using unordered map**
*/
std::unordered_map<u32, Codepoint> CodeMap;
};
} // namespace LI
} // namespace Li
} // namespace PD

32
include/pd/lithium/lithium.hpp Executable file
View File

@ -0,0 +1,32 @@
#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/lithium/command.hpp>
#include <pd/lithium/drawlist.hpp>
#include <pd/lithium/font.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/renderer.hpp>
#include <pd/lithium/texture.hpp>

5
include/pd/lithium/pd_p_api.hpp Normal file → Executable file
View 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
@ -24,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
/** Generated with ppam */
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_LITHIUM_BUILD_SHARED

105
include/pd/lithium/rect.hpp Normal file → Executable file
View File

@ -26,24 +26,20 @@ SOFTWARE.
#include <pd/core/core.hpp>
namespace PD {
namespace LI {
/**
* Container that holds position of a rectangle's corners.
*/
namespace Li {
class Rect {
public:
Rect() = default;
Rect() : Top(0), Bot(0) {}
~Rect() = default;
/**
* Constructor that initializes the rectangle using top and bottom positions.
* @param t Top left and right corner positions.
* @param b Bottom left and right corner positions.
*/
Rect(const fvec4& t, const fvec4& b) {
top = t;
bot = b;
Top = t;
Bot = b;
}
/**
* Constructor that initializes the rectangle using individual corner
* positions.
@ -53,8 +49,8 @@ class Rect {
* @param br Bottom right corner position.
*/
Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br) {
top = fvec4(tl, tr);
bot = fvec4(bl, br);
Top = fvec4(tl, tr);
Bot = fvec4(bl, br);
}
/**
@ -66,67 +62,30 @@ class Rect {
* @param uv Vec4 UV map.
*/
Rect(const fvec4& uv) {
top = vec4(uv.x, uv.y, uv.z, uv.y);
bot = vec4(uv.x, uv.w, uv.z, uv.w);
}
~Rect() = default;
/**
* Get the top left and right corner positions.
* @return Top positions.
*/
fvec4 Top() const { return top; }
/**
* Get the bottom left and right corner positions.
* @return Bottom positions.
*/
fvec4 Bot() const { return bot; }
/**
* Set the top left and right corner positions.
* @param v New top positions.
* @return Reference to the updated Rect.
*/
Rect& Top(const fvec4& v) {
top = v;
return *this;
}
/**
* Set the bottom left and right corner positions.
* @param v New bottom positions.
* @return Reference to the updated Rect.
*/
Rect& Bot(const fvec4& v) {
bot = v;
return *this;
Top = vec4(uv.x, uv.y, uv.z, uv.y);
Bot = vec4(uv.x, uv.w, uv.z, uv.w);
}
/**
* Get the top-left corner position.
* @return Top-left position as vec2.
*/
fvec2 TopLeft() const { return vec2(top.x, top.y); }
fvec2 TopLeft() const { return fvec2(Top.x, Top.y); }
/**
* Get the top-right corner position.
* @return Top-right position as vec2.
*/
fvec2 TopRight() const { return vec2(top.z, top.w); }
fvec2 TopRight() const { return fvec2(Top.z, Top.w); }
/**
* Get the bottom-left corner position.
* @return Bottom-left position as vec2.
*/
fvec2 BotLeft() const { return vec2(bot.x, bot.y); }
fvec2 BotLeft() const { return fvec2(Bot.x, Bot.y); }
/**
* Get the bottom-right corner position.
* @return Bottom-right position as vec2.
*/
fvec2 BotRight() const { return vec2(bot.z, bot.w); }
fvec2 BotRight() const { return fvec2(Bot.z, Bot.y); }
/**
* Set the top-left corner position.
@ -134,8 +93,8 @@ class Rect {
* @return Reference to the updated Rect.
*/
Rect& TopLeft(const fvec2& v) {
top.x = v.x;
top.y = v.y;
Top.x = v.x;
Top.y = v.y;
return *this;
}
@ -145,8 +104,8 @@ class Rect {
* @return Reference to the updated Rect.
*/
Rect& TopRight(const fvec2& v) {
top.z = v.x;
top.w = v.y;
Top.z = v.x;
Top.w = v.y;
return *this;
}
@ -156,8 +115,8 @@ class Rect {
* @return Reference to the updated Rect.
*/
Rect& BotLeft(const fvec2& v) {
bot.x = v.x;
bot.y = v.y;
Bot.x = v.x;
Bot.y = v.y;
return *this;
}
@ -167,26 +126,22 @@ class Rect {
* @return Reference to the updated Rect.
*/
Rect& BotRight(const fvec2& v) {
bot.z = v.x;
bot.w = v.y;
Bot.z = v.x;
Bot.w = v.y;
return *this;
}
/**
* Swap X and Y coordinates for all corners.
*
* - Used in SpiteSheet for the rotated images.
*/
void SwapVec2XY() {
top.SwapXY();
top.SwapZW();
bot.SwapXY();
bot.SwapZW();
Top.SwapXY();
Top.SwapZW();
Bot.SwapXY();
Bot.SwapZW();
}
private:
fvec4 top; ///< Top left and right corner positions.
fvec4 bot; ///< Bottom left and right corner positions.
/** Data Section */
fvec4 Top;
fvec4 Bot;
};
} // namespace LI
} // namespace Li
} // namespace PD

43
include/pd/lithium/renderer.hpp Normal file → Executable file
View File

@ -24,37 +24,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/lithium/backend.hpp>
#include <pd/lithium/drawlist.hpp>
#include <pd/lithium/font.hpp>
#include <pd/drivers/drivers.hpp>
#include <pd/lithium/pd_p_api.hpp>
#include <pd/lithium/rect.hpp>
namespace PD {
namespace LI {
class PD_LITHIUM_API Renderer : public SmartCtor<Renderer> {
namespace Li {
/**
* Static Class Render Setup Functions
*/
class PD_LITHIUM_API Renderer {
public:
Renderer(Backend::Ref backend);
Renderer() = default;
~Renderer() = default;
void Render();
// SECTION: ADVANCED API
void AddCommand(Command::Ref v) { DrawList.Add(v); }
void RegisterDrawList(DrawList::Ref list) { pDrawLists.Add(list); }
Command::Ref PreGenerateCmd();
// SECTION: Open Command and Object creation API
static void RotateCorner(fvec2& pos, float sinus, float cosinus);
static void RotateCorner(fvec2& pos, float s, float c);
static Rect PrimRect(const fvec2& pos, const fvec2& size, float angle = 0.f);
static Rect PrimLine(const fvec2& a, const fvec2& b, int thickness = 1);
static void CmdQuad(Command::Ref cmd, const Rect& quad, const Rect& uv,
static void CmdQuad(Command* cmd, const Rect& quad, const Rect& uv,
u32 color);
static void CmdTriangle(Command::Ref cmd, const fvec2 a, const fvec2 b,
static void CmdTriangle(Command* cmd, const fvec2 a, const fvec2 b,
const fvec2 c, u32 clr);
static void CmdPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0,
int thickness = 1);
static void CmdConvexPolyFilled(Command::Ref cmd, const Vec<fvec2>& points,
static void CmdConvexPolyFilled(Command* cmd, const Vec<fvec2>& points,
u32 clr, Texture::Ref tex);
// SECTION: InBounds Checks
@ -63,17 +57,6 @@ class PD_LITHIUM_API Renderer : public SmartCtor<Renderer> {
static bool InBox(const fvec2& pos, const fvec4& area);
static bool InBox(const fvec2& a, const fvec2& b, const fvec2& c,
const fvec4& area);
// SECTION: Data //
Texture::Ref WhitePixel = nullptr;
Backend::Ref pBackend = nullptr;
Texture::Ref CurrentTex = nullptr;
int Layer = 0;
private:
PD::Vec<Command::Ref> DrawList;
PD::Vec<DrawList::Ref> pDrawLists;
};
} // namespace LI
} // namespace Li
} // namespace PD

39
include/pd/lithium/texture.hpp Normal file → Executable file
View 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
@ -28,49 +27,49 @@ SOFTWARE.
#include <pd/lithium/rect.hpp>
namespace PD {
namespace LI {
namespace Li {
/** Use so address type for TexAddress */
using TexAddress = uintptr_t;
/**
* Lithium Texture Data Holder
* Memory management is handled by backend
*/
class Texture : public SmartCtor<Texture> {
class Texture {
public:
/** Texture Type */
/** Texture Types */
enum Type {
RGBA32, ///< RGBA 32
RGB24, ///< RGB24
A8, ///< A8
RGBA32, ///< Rgba 32Bit
RGB24, ///< Rgb 24 Bit
A8, ///< A8 8Bit alpha
};
/** Texture Filters */
enum Filter {
NEAREST, ///< Nearest
LINEAR, ///< Linear
};
/** Default constructor */
Texture() : UV(0.f, 0.f, 1.f, 1.f) {}
/** Constructor */
Texture() : Address(0), Size(0), UV(fvec4(0.f, 0.f, 1.f, 1.f)) {}
Texture(TexAddress addr, ivec2 size,
LI::Rect uv = fvec4(0.f, 0.f, 1.f, 1.f)) {
Li::Rect uv = fvec4(0.f, 0.f, 1.f, 1.f)) {
Address = addr;
Size = size;
UV = uv;
}
void CopyOther(Texture::Ref tex) {
PD_SHARED(Texture);
void CopyFrom(Texture::Ref tex) {
Address = tex->Address;
Size = tex->Size;
UV = tex->UV;
}
/** Left in Code getter (should be remoevd) */
ivec2 GetSize() const { return Size; }
LI::Rect GetUV() const { return UV; }
Li::Rect GetUV() const { return UV; }
operator ivec2() const { return Size; }
operator LI::Rect() const { return UV; }
operator Li::Rect() const { return UV; }
TexAddress Address;
ivec2 Size;
LI::Rect UV;
Li::Rect UV;
};
} // namespace LI
} // namespace Li
} // namespace PD

10
include/pd/lithium/vertex.hpp Normal file → Executable file
View 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,7 +26,7 @@ SOFTWARE.
#include <pd/core/core.hpp>
namespace PD {
namespace LI {
namespace Li {
class Vertex {
public:
Vertex() {}
@ -40,9 +39,12 @@ class Vertex {
~Vertex() {}
// private:
/** Open Access Data Section */
fvec2 Pos;
fvec2 UV;
u32 Color;
};
} // namespace LI
} // namespace Li
} // namespace PD

View File

@ -1,53 +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/core.hpp>
#include <pd/net/socket.hpp>
namespace PD {
namespace Net {
class Backend {
public:
Backend(const std::string& name = "NullBackend") : pName(name) {}
~Backend() = default;
PD_SMART_CTOR(Backend)
virtual bool Init() = 0;
virtual void Deinit() = 0;
virtual int NewSocket() = 0;
virtual void Close(int sock_id) = 0;
virtual int GetInvalidRef() const = 0;
virtual bool Bind(int sock_id, u16 port) = 0;
virtual bool Listen(int sock_id, int backlog = 5) = 0;
virtual bool WaitForRead(int sock_id, int timeout_ms) = 0;
virtual bool Accept(int sock_id, Socket::Ref client) = 0;
virtual bool Connect(int sock_id, const std::string& ip, u16 port) = 0;
virtual int Send(int sock_id, const std::string& data) = 0;
virtual int Receive(int sock_id, std::string& data, int size = 1024) = 0;
/** Backend identification name */
const std::string pName;
};
} // namespace Net
} // namespace PD

View File

@ -1,115 +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/external/json.hpp>
namespace PD {
/**
* Download manager class
*/
class DownloadManager : public SmartCtor<DownloadManager> {
public:
/** Alias to contain Error Cdoe and for some Errors a Status Code */
using Error = u64;
/** Error Codes of DL Manager */
enum Error_ {
Error_None, ///< Function Executed Successfully
Error_Memory, ///< Memory Allocation Error
Error_Write, ///< Unable to Write File
Error_StatusCode, ///< Error with Status Code
Error_Git, ///< Git Error
Error_CtrStatus, ///< 3ds Result Code
Error_Curl, ///< Curl Error
Error_Busy, ///< Another Download Taskl is already running
Error_Invalid, ///< Invalid Json struct
Error_NoWifi, ///< Console not connected to wifi
};
DownloadManager() = default;
~DownloadManager() = default;
/**
* Extract the DL Manager Error code of a Error
* @param err Error
* @return Downloadmanager Error code
*/
static Error_ GetErrorCode(Error err) {
return (Error_)u32(err & 0xffffffff);
}
/**
* Extract the DL Manager Status code of a Error
* @param err Error
* @return Status code
*/
static int GetStatusCode(Error err) {
Error_ c = GetErrorCode(err);
if (c != Error_StatusCode && c != Error_CtrStatus && c != Error_Curl) {
return 0;
}
return u32(err >> 32);
}
/**
* Download from URL inro a String Buffer
* @param url URL to download from
* @param res result buffer
* @return Error Code
*/
Error Get(const std::string& url, std::string& res);
/**
* Download from URL into a File
* @param url URL to download from
* @param res_path Path to write file to
* @return Error Code
*/
Error GetFile(const std::string& url, const std::string& res_path);
/**
* Download a File from a Git Release
* @param url URL of the repo
* @param asset Asset to download
* @param path Path to write file into
* @param pre download from Prerelease
* @return Error Code
*/
Error GetGitRelease(const std::string& url, const std::string& asset,
const std::string& path, bool pre);
/**
* Get a json API request as nlohmann json object
* @param url URL to request
* @param res result json object
* @return Error Code
*/
Error GetAsJson(const std::string& url, nlohmann::json& res);
/** Get Current Progress in Bytes */
u64 ProgressCurrent() const { return current; }
/** Get Total number in bytes */
u64 ProgressTotal() const { return total; }
private:
u64 current; ///< Current Progress
u64 total; ///< Total Bytes tp Download
};
} // namespace PD

View File

@ -1,52 +0,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.
*/
#pragma once
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_NET_BUILD_SHARED
#define PD_NET_API __declspec(dllexport)
#else
#define PD_NET_API __declspec(dllimport)
#endif
#elif defined(__APPLE__) // macOS (untested yet)
#ifdef PD_NET_BUILD_SHARED
#define PD_NET_API __attribute__((visibility("default")))
#else
#define PD_NET_API
#endif
#elif defined(__linux__) // Linux (untested yet)
#ifdef PD_NET_BUILD_SHARED
#define PD_NET_API __attribute__((visibility("default")))
#else
#define PD_NET_API
#endif
#elif defined(__3DS__) // 3ds Specific
// Only Static supported
#define PD_NET_API
#else
#define PD_NET_API
#endif

View File

@ -1,61 +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/core.hpp>
#include <pd/net/pd_p_api.hpp>
namespace PD {
namespace Net {
class Backend;
/**
* Wrapper class around the functionality of Net::Backend
*/
class PD_NET_API Socket {
public:
Socket(PD::SmartCtor<Backend>::Ref bknd) { backend = bknd; };
Socket(PD::SmartCtor<Backend>::Ref bknd, u16 port) {
backend = bknd;
this->Create();
this->Bind(port);
}
~Socket() { Close(); };
PD_SMART_CTOR(Socket);
bool Create();
bool Bind(u16 port);
bool Listen(int backlog = 5);
bool WaitForRead(int timeout_ms);
bool Accept(Socket::Ref client);
bool Connect(const std::string& ip, u16 port);
int Send(const std::string& data);
int Receive(std::string& data, int size = 1024);
void Close();
bool IsValid() const;
int pSocket;
PD::SmartCtor<Net::Backend>::Ref backend;
};
} // namespace Net
} // namespace PD

View File

@ -1,177 +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/core.hpp>
#include <pd/overlays/overlay.hpp>
namespace PD {
/**
* Development Function to dump Keyboard Layout into a Json File
* @param path Path to write into
*/
void DumpLayout(const std::string& path);
/**
* Keyboard class
*
* - needs to be pushed with text and State reference as Overlay
* to communicate with it
* @note Hardcoded Rendering to get maximum Rendering Performance
*/
class Keyboard : public Overlay {
public:
/** Key Operations */
enum KeyOperation {
AppendSelf = 0, ///< Append Keyname to res string
Shift = 1, ///< Shift
Backspace = 2, ///< Backspace
Enter = 3, ///< Enter
OpCancel = 4, ///< Cancel
OpConfirm = 5, ///< Confirm
Tab = 6, ///< Tab
Caps = 7, ///< Caps
Space = 8, ///< Space
Op1 = 9, ///< Unnset Op 1
Op2 = 10, ///< Unset Op 2
};
/** Keyboard Type */
enum Type {
Default, ///< Default Keyboard
Numpad, ///< Numpad
Password, ///< Password Input
};
/** State */
enum State {
None, ///< Doing nothing
Cancel, ///< Cancelled
Confirm, ///< Confirmed
};
/** Alias for Keyboard Flags */
using Flags = u32;
/** Flags */
enum Flags_ {
Flags_None = 0, ///< Nothing
Flags_BlendTop = 1 << 0, ///< Blend Top Screen
Flags_BlendBottom = 1 << 1, ///< Blend Bottom
Flags_LockControls = 1 << 2, ///< Lock Contols (Input Driver)
Flags_Transparency = 1 << 3, ///< Transparant Keyboard Colors
// Default Flags
Flags_Default = Flags_BlendBottom | Flags_BlendTop | Flags_LockControls,
};
/**
* Keyboard Constructor
* @param text Result Text
* @param state Result State
* @param hint Hint to display if result is empty
* @param type Keyboard type
* @param flags Keyboard flags to use
*/
Keyboard(std::string& text, State& state, const std::string& hint = "",
Type type = Default, Flags flags = Flags_Default) {
too++;
if (too > 1) {
Kill();
return;
}
this->text = &text;
this->copy = text;
this->state = &state;
this->hint = hint;
this->type = type;
this->flags = flags;
this->raw_sel = -1;
flymgr.From(vec2(0, 240)).To(vec2(0, 115)).In(0.3f).As(flymgr.EaseInQuad);
chflymgr.From(vec2(-320, 0)).To(vec2(-320, 0)).In(0.1f).As(chflymgr.Linear);
}
/** Deconstructor */
~Keyboard() { too--; }
/**
* Rendering and Input Handler
* @param delta Deltatime for Animations
* @param ren Renderer Reference
* @param inp Input Driver reference
*/
void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) override;
/** Remove Keyboard */
void Rem() {
rem = true;
flymgr.From(vec2(0, 115)).To(vec2(0, 240)).In(0.2f).As(flymgr.EaseOutQuad);
}
private:
/** Prerender Keys */
void LoadTheKeys(LI::Renderer::Ref ren);
/** Controller Movement */
void Movement(Hid::Ref inp);
/** Trigger Move from to Animation */
void MoveSelector();
/** Execute a Key operation */
void DoOperation(KeyOperation op, const std::string& kname);
/** Recolor all Keys with the same operation */
void RecolorBy(KeyOperation op, u32 color, int cm);
/** Bind an operation */
void InputOpBind(Hid::Key k, KeyOperation op, Hid::Ref inp, int cm);
// Result Text reference
std::string* text;
// Copy of the Text
std::string copy;
// Hint
std::string hint;
// Result State reference
State* state;
// Keyboard Type
Type type;
// Keyboard flags
Flags flags;
// def, caps, shift
int mode = 0;
// Stands for The Only One
static int too;
// Tween for selector Movement
Tween<fvec2> selector;
// Tween for Selector Size
Tween<fvec2> sel_szs;
// Current Cell size
fvec2 cselszs;
// selector index
int raw_sel;
// Prerendered Keytables
LI::StaticObject::Ref keys[3];
// Value to check if table is loadet
bool keys_loadet = false;
// Remove Animation
bool rem = false;
/// Probably a float would've done the job as well ;)
Tween<fvec2> flymgr;
// Secode Flymanager
Tween<fvec2> chflymgr;
// Show Help
bool show_help = true;
};
} // namespace PD

View File

@ -1,98 +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/core.hpp>
#include <pd/lithium/renderer.hpp>
namespace PD {
/**
* Message Manager
*/
class MessageMgr : public PD::SmartCtor<MessageMgr> {
public:
/**
* Message Container
*/
class Container : public PD::SmartCtor<Container> {
public:
/**
* Message Constructor
* @param title Title
* @param msg Message
*/
Container(const std::string& title, const std::string& msg);
~Container() = default;
/** Render the Container */
void Render(PD::LI::Renderer::Ref ren);
/**
* Update Animations by slot and delta
* @param slot Slot
* @param delta Deltatime
*/
void Update(int slot, float delta);
/** Trigger Fly in Animation */
void FlyIn();
/** Trigger Change Position Animation */
void ToBeMoved(int slot);
/** Trigger Removed Animation */
void ToBeRemoved();
/** Check if Message can be removed from list */
bool ShouldBeRemoved() const { return (tbr && pos.IsFinished()) || kill; }
private:
PD::Color col_bg; // Background Color
PD::Color col_text; // Text Color
float lifetime = 0.f; // LifeTime
PD::Tween<fvec2> pos; // Position effect
std::string title; // Title
std::string msg; // Message
fvec2 size; // Size of the Background
bool tbr = false; // To be Removed ?
bool kill = false; // Instant Kill
int s = 0; // Slot
};
/** Constructor to Link a Renderer reference */
MessageMgr(PD::LI::Renderer::Ref r) { ren = r; }
~MessageMgr() = default;
/**
* Add a New Message
* @param title Message Title
* @param text Message Text
*/
void Push(const std::string& title, const std::string& text);
/**
* Update Messages
* @param delta Deltatime
*/
void Update(float delta);
private:
std::vector<Container::Ref> msgs; // List of Messages
PD::LI::Renderer::Ref ren; // Renderer Reference
};
} // namespace PD

View File

@ -1,56 +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/core.hpp>
#include <pd/lithium/renderer.hpp>
namespace PD {
/**
* Overlay Template class
*/
class Overlay : public SmartCtor<Overlay> {
public:
Overlay() = default;
virtual ~Overlay() = default;
/**
* Update Function for Overlay input and rendering
* @param delta Deltatime
* @param ren Renderer reference
* @param inp Input Driver
*/
virtual void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) = 0;
/** Check if killed to remove from Overlay Manager */
bool IsKilled() const { return kill; }
protected:
/** Internall Kill function to call from your Overlay */
void Kill() { kill = true; }
private:
bool kill = false; ///< Should be killed or not
};
} // namespace PD

View File

@ -1,84 +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/core.hpp>
#include <pd/overlays/overlay.hpp>
namespace PD {
/**
* Performance Overlay
*
* - Framerate / Frametime
* - Renderer Avarage Time
* - Overlays Avarage Time
* - UserApp Average Time
* - **V**ertices and **I**ndices
* - **D**Draw Commands and Draw **C**alls
* - Text Map System Texts
* - Auto static Text Texts
*/
class Performance : public Overlay {
public:
/**
* Constructor
* @param skill (if set to true the Overlay self kills)
* @param screen Bottom or Top Screen
*/
Performance(bool& skill, bool& screen) {
too++;
if (too > 1) {
Kill();
return;
}
this->skill = &skill;
*this->skill = false; // Make sure its false
this->screen = &screen;
}
/** Deconstructor */
~Performance() { too--; }
/**
* Rendering Function
* @param delta Deltatime
* @param ren Renderer Reference
* @param inp Input Driver Reference
*/
void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) override;
private:
/**
* Render an Info line
* @param pos Position reference (gets updated for next line)
* @param text Text to Show
* @param ren Renderer Reference
*/
void Line(fvec2& pos, const std::string& text, LI::Renderer::Ref ren);
// Trace String Average
std::string TSA(const std::string& id);
// Described in Keyboard
static int too;
bool *skill, *screen;
};
} // namespace PD

View File

@ -1,75 +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/core.hpp>
#include <pd/overlays/overlay.hpp>
#include <pd/ui7/ui7.hpp>
namespace PD {
/**
* Settings Menu Overlay
*/
class SettingsMenu : public Overlay {
public:
/**
* Constructor to setup Overlay
*/
SettingsMenu() {
too++;
if (too > 1) {
Kill();
return;
}
flymgr.From(vec2(0, 240)).To(vec2(0, 115)).In(0.3f).As(flymgr.EaseInQuad);
}
/** Deconstructor */
~SettingsMenu() { too--; }
/** Rendering and Input Handler */
void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) override;
/**
* Function to Trigger remove animation
*/
void Rem() {
rem = true;
flymgr.From(vec2(0, 115)).To(vec2(0, 240)).In(0.2f).As(flymgr.EaseOutQuad);
}
private:
/// Section is used to determinate what
/// should be displayed on the top screen
int section = 0;
// Stands for The Only One
static int too;
// Some Animation
bool rem = false;
Tween<fvec2> flymgr;
// Custom UI7 Context
UI7::Context::Ref ctx;
};
} // namespace PD

View File

@ -1,54 +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>
namespace PD {
namespace Music {
/**
* Decoder Template class
*/
class Decoder : public SmartCtor<Decoder> {
public:
Decoder() = default;
virtual ~Decoder() = default;
/** Template Init function */
virtual int Init(const std::string& path) = 0;
/** Template deinit function */
virtual void Deinit() = 0;
/** Template function to get sample rate */
virtual u32 GetSampleRate() = 0;
/** template function to get number of channels */
virtual u8 GetChannels() = 0;
/** template function to get buffer size */
virtual size_t GetBufSize() = 0;
/** template decode function */
virtual u64 Decode(u16* buf_address) = 0;
/** template function to get file sanples if exist */
virtual size_t GetFileSamples() = 0;
};
} // namespace Music
} // namespace PD

View File

@ -1,79 +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>
namespace PD {
namespace Music {
/**
* Music Metadata Data Holder
*/
class MetaData {
public:
MetaData() = default;
~MetaData() = default;
/** Getter for name */
std::string Name() const { return name; }
/** Getter for album */
std::string Album() const { return album; }
/** Getter for year */
std::string Year() const { return year; }
/** Getter for Title */
std::string Title() const { return title; }
/** Getter for Artist */
std::string Artist() const { return artist; }
/** Getter for [what is this] */
std::string Mdt() const { return mdt; }
/** Gettr for file path */
std::string Path() const { return path; }
/** Setter for Name */
void Name(const std::string &v) { name = v; }
/** Setter for Album */
void Album(const std::string &v) { album = v; }
/** Settr for Year */
void Year(const std::string &v) { year = v; }
/** Settr for Title */
void Title(const std::string &v) { title = v; }
/** Settr for Artist */
void Artist(const std::string &v) { artist = v; }
/** Settr for [what is this] */
void Mdt(const std::string &v) { mdt = v; }
/** Settr for Path */
void Path(const std::string &v) { path = v; }
private:
const std::string unk = "Unknown";
std::string title = unk;
std::string album = unk;
std::string year = unk;
std::string name = unk;
std::string path = unk;
std::string artist = unk;
std::string mdt = unk;
};
} // namespace Music
} // namespace PD

View File

@ -1,55 +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/lib3ds/memory.hpp>
#include <pd/sound/decoder.hpp>
#include <pd/sound/metadata.hpp>
namespace PD {
namespace Music {
/**
* Music Player
*/
class Player : public SmartCtor<Player> {
public:
Player() {}
~Player() {}
private:
MetaData meta;
size_t samples_total = 0;
size_t samples_played = 0;
size_t samples_per_sec = 0;
std::string file;
std::vector<signed short, LinearAllocator<signed short>> buffers[2];
ndspWaveBuf wave_buf[2] = {0};
bool last_buf = false;
int ret = -1;
bool done = false;
bool playing = false;
bool stop = false;
};
} // namespace Music
} // namespace PD

1
include/pd/ui7/container/button.hpp Normal file → Executable file
View File

@ -48,6 +48,7 @@ class PD_UI7_API Button : public Container {
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~Button() = default;
PD_SHARED(Button);
/** Return true if butten is pressed*/
bool IsPressed() { return pressed; }

1
include/pd/ui7/container/checkbox.hpp Normal file → Executable file
View File

@ -47,6 +47,7 @@ class PD_UI7_API Checkbox : public Container {
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~Checkbox() = default;
PD_SHARED(Checkbox);
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update

Some files were not shown because too many files have changed in this diff Show More