Merge branch 'stable' of https://github.com/tobid7/palladium into stable

This commit is contained in:
2026-03-09 20:47:53 +01:00
13 changed files with 233 additions and 15 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,3 @@
build/
build*/
.cache
.vscode

View File

@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.22)
include(GNUInstallDirs)
# Set Project
project(palladium LANGUAGES C CXX VERSION 0.6.0)
@@ -10,6 +12,9 @@ include(cmake/palladium.cmake)
option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)
option(PD_BUILD_SHARED "Build Shared Library" OFF)
option(PD_BUILD_TOOLS "Build Palladium Tools" OFF)
option(PD_BUILD_DESKTOP "Build Desktop Backend" OFF)
option(PD_BUILD_3DS "Build 3ds Backend" OFF)
option(PD_BUNDLE_GLFW "Bundle GLFW in install" OFF)
if(${PD_BUILD_TOOLS})
add_subdirectory(tools)
@@ -73,7 +78,13 @@ else()
target_compile_definitions(palladium PUBLIC -DPD_BUILD_STATIC)
endif()
target_include_directories(palladium PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_library(palladium::palladium ALIAS palladium)
target_include_directories(palladium
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
target_compile_options(palladium PRIVATE
@@ -88,8 +99,47 @@ target_compile_options(palladium PRIVATE
$<$<CONFIG:Release>:-O3>
)
install(DIRECTORY include DESTINATION ".")
install(TARGETS palladium)
if(PD_BUILD_DESKTOP AND NOT PD_BUILD_3DS)
add_subdirectory(backends/desktop)
endif()
if(PD_BUILD_3DS AND NOT PD_BUILD_DESKTOP)
add_subdirectory(backends/3ds)
endif()
install(TARGETS palladium
EXPORT palladiumTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(EXPORT palladiumTargets
FILE palladiumTargets.cmake
NAMESPACE palladium::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/palladium
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/palladiumConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/palladium
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/palladium
)
find_program(CLANG_FORMAT clang-format)

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2024 - 2025 René Amthor tobid7
Copyright (c) 2024 - 2026 René Amthor tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -8,6 +8,30 @@ set(SRC
source/pd-3ds.cpp
)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libpicasso)
pd_add_lib(pd-3ds SRC_FILES ${SRC})
target_include_directories(pd-3ds PUBLIC include)
add_library(pd-3ds STATIC ${SRC})
target_include_directories(pd-3ds PUBLIC
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(pd-3ds PUBLIC m palladium ctru citro3d pica::pica)
add_library(palladium::pd-3ds ALIAS pd-3ds)
install(TARGETS pd-3ds
EXPORT palladiumTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(TARGETS pica
EXPORT palladiumTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

View File

@@ -19,10 +19,44 @@ set(SRC
source/pd-desktop.cpp
)
pd_add_lib(pd-desktop SRC_FILES ${SRC})
target_include_directories(pd-desktop PUBLIC include)
add_library(pd-desktop STATIC ${SRC})
target_include_directories(pd-desktop
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(pd-desktop PUBLIC palladium glad glfw)
target_compile_definitions(pd-desktop
PRIVATE PD_OPENGL=${PD_GL_VERSION}
)
add_library(palladium::pd-desktop ALIAS pd-desktop)
install(TARGETS pd-desktop
EXPORT palladiumTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(TARGETS glad
EXPORT palladiumTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if(PD_BUNDLE_GLFW)
install(TARGETS glfw
EXPORT palladiumTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()

View File

@@ -1,4 +1,8 @@
cmake_minimum_required(VERSION 3.22)
add_library(glad source/glad.c)
target_include_directories(glad PUBLIC include)
target_include_directories(glad
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

View File

@@ -0,0 +1,6 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/palladiumTargets.cmake")
if(NOT TARGET palladium::pd-desktop AND PALLADIUM_FIND_DESKTOP)
find_dependency(palladium::pd-desktop OPTIONAL)
endif()

View File

@@ -29,6 +29,7 @@ SOFTWARE.
#include <pd/core/hashid.hpp>
#include <pd/core/io.hpp>
#include <pd/core/mat.hpp>
#include <pd/core/pool.hpp>
#include <pd/core/strings.hpp>
#include <pd/core/timer.hpp>
#include <pd/core/timetrace.hpp>

51
include/pd/core/pool.hpp Normal file
View File

@@ -0,0 +1,51 @@
#pragma once
#include <pd/core/common.hpp>
namespace PD {
template <typename T, typename Alloc = std::allocator<T>>
class Pool {
public:
Pool() = default;
~Pool() = default;
static Pool* Create(size_t size) { return new Pool(size); }
void Init(size_t size) {
pPos = 0;
pCap = size;
pPool.resize(size);
}
Pool(const Pool&) = delete;
Pool(Pool&&) = delete;
Pool& operator=(const Pool&) = delete;
Pool& operator=(Pool&&) = delete;
T* Allocate(size_t num = 1) {
if (CheckLimits(num)) return nullptr;
T* ret = &pPool[pPos];
pPos += num;
return ret;
}
bool CheckLimits(size_t num) {
if ((pPos + num) >= pCap) {
throw std::runtime_error(
std::format("[PD::Pool]: Trying to allocate {} elements but this is "
"going out of range ({}/{})",
num, pPos + num, pCap));
return true;
}
return false;
}
void Reset() { pPos = 0; }
private:
Pool(size_t size) : pCap(size), pPos(0) { pPool.resize(size); }
size_t pCap = 0;
size_t pPos = 0;
std::vector<T, Alloc> pPool;
};
} // namespace PD

View File

@@ -127,4 +127,48 @@ inline const std::string GetCompilerVersion() {
return res.str();
}
} // namespace Strings
class U8Iterator {
public:
explicit U8Iterator(const char* s) : ptr(reinterpret_cast<const u8*>(s)) {}
~U8Iterator() = default;
bool Decode32(u32& ret) {
if (ptr == nullptr || *ptr == 0) return false;
u8 c = *ptr;
if (c < 0x80) {
ret = c;
ptr += 1;
} else if ((c >> 5) == 0x6) {
ret = ((c & 0x1F) << 6) | (ptr[1] & 0x3F);
ptr += 2;
} else if ((c >> 4) == 0xE) {
ret = ((c & 0x0F) << 12) | ((ptr[1] & 0x3F) << 6) | (ptr[2] & 0x3F);
ptr += 3;
} else {
ret = ((c & 0x07) << 18) | ((ptr[1] & 0x3F) << 12) |
((ptr[2] & 0x3F) << 6) | (ptr[3] & 0x3F);
ptr += 4;
}
return true;
}
bool PeekNext32(u32& ret) {
if (ptr + 1 == nullptr || *ptr + 1 == 0) return false;
u8 c = *ptr;
if (c < 0x80) {
ret = c;
} else if ((c >> 5) == 0x6) {
ret = ((c & 0x1F) << 6) | (ptr[1] & 0x3F);
} else if ((c >> 4) == 0xE) {
ret = ((c & 0x0F) << 12) | ((ptr[1] & 0x3F) << 6) | (ptr[2] & 0x3F);
} else {
ret = ((c & 0x07) << 18) | ((ptr[1] & 0x3F) << 12) |
((ptr[2] & 0x3F) << 6) | (ptr[3] & 0x3F);
}
return true;
}
private:
const u8* ptr = nullptr;
};
} // namespace PD

View File

@@ -24,7 +24,9 @@ SOFTWARE.
#include <pd/drivers/hid.hpp>
namespace PD {
PD_API bool HidDriver::IsEvent(Event e, Key keys) { return KeyEvents[0][e] & keys; }
PD_API bool HidDriver::IsEvent(Event e, Key keys) {
return KeyEvents[0][e] & keys;
}
PD_API bool HidDriver::IsEvent(Event e, KbKey keys) {
return KbKeyEvents[0][e].Has(keys);

View File

@@ -34,7 +34,9 @@ PD_API TT::Res::Ref& OsDriver::GetTraceRef(const std::string& id) {
PD_API TraceMap& OsDriver::GetTraceMap() { return pTraces; }
PD_API bool OsDriver::TraceExist(const std::string& id) { return pTraces.count(id); }
PD_API bool OsDriver::TraceExist(const std::string& id) {
return pTraces.count(id);
}
/** Standart Driver */
PD_API u64 OsDriver::GetTime() {