Compare commits

..

No commits in common. "stable" and "rd7-palladium" have entirely different histories.

202 changed files with 30761 additions and 30549 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
build/

View File

@ -7,30 +7,12 @@
"C:/devkitpro/libctru/include/**", "C:/devkitpro/libctru/include/**",
"C:/devkitpro/devkitARM/include/**", "C:/devkitpro/devkitARM/include/**",
"C:/devkitpro/devkitARM/arm-none-eabi/include/**", "C:/devkitpro/devkitARM/arm-none-eabi/include/**",
"C:/devkitpro/portlibs/3ds/include/**" "C:/devkitpro/portlibs/3ds/include/**",
],
"defines": [
"BUILD_CTR"
],
"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/libctru/include/**",
"/opt/devkitpro/portlibs/3ds/include/**" "/opt/devkitpro/portlibs/**"
],
"defines": [ ]
"BUILD_CTR"
],
"cStandard": "c17",
"cppStandard": "gnu++20",
"intelliSenseMode": "gcc-arm"
} }
], ],
"version": 4 "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
}
]
}
]
}

View File

@ -113,8 +113,6 @@
"__threading_support": "cpp", "__threading_support": "cpp",
"__tree": "cpp", "__tree": "cpp",
"__verbose_abort": "cpp", "__verbose_abort": "cpp",
"complex": "cpp", "complex": "cpp"
"any": "cpp",
"text_encoding": "cpp"
} }
} }

127
CHANGELOG.md Normal file
View File

@ -0,0 +1,127 @@
# Palladium Changelog
## 1.0.0
- Rename Everyting to PD
- R7Vec -> NVec
- Switch from C2D to Lithium (LI7)
- For the Rest See RenderD7 Changelog below
- swr -> Rubidium
- LIFont (TTF Font Renderer)
- Implement shbin as c++ array
- Larger Mesaage Box
- Add Texture Loader
- Update Image/Error and other sytems to Lithium
- Remove Render2
- Add Deltatime to every moving object
- Restructure Project
# RenderD7 Changelog
## 0.9.5
- Remove Npi Intro and NVID Api
- Replace Toasts System with Message
- Added GetTime
- Move from Draw to Render2 Api
- Implement RD7Color and R7Vec2
- Add new Features to Color::RGBA
- Cleanup Code
- Added RenderD7 Keyboard (Overlay)
- Added Ftrace Overlay
- Moved MetrikOVL into an Overlay
- Removed Old Font/Text Handlers
- Added UI7 (New UI Api)
- Remove Old UI Api
- Rewrite of RenderD7::Image
- Internal Debugger/Database (IDB)
- Removed BitmapPrinter
- Added nimg and swr(render2nimg | SoftwareRender)
- Removed Old Error/Message Handler
- GetTextSize (extra buffer) + New TextShorter
- Require specific FLAG for MemTrack
- Replace all lodepng usage by stb_image
- Move Asset Generator into single python script
- Remove INI reader
- Python based clangformat script
- Move some Init code into functions to not use twice
- Added Font class
- Add LinearAllocator (for std)
- Fix Crash in FilsSystem
- Implement basic Theme System
- Remove 0.9.4 Security
- Tasks now based on std functional/thread
- Add Network Support (Download Files, APi Requests)
- Remove RD7TF
- Add Cia Installer
- Move from Init bool values to flags
## 0.9.4
- Implement new Security System To prevent from crashes
- Implement Functiontrace for better Timing Tests
- Implement MemAlloc Tracker (only size)
- Add some new Overlays (not functional yet)
- Complete Rewrite of Overlay System
- Fixed the FrameEnd Crash
- New System to get Hardware Info
- Removed RenderD7 Super Reselution (800px mode)
## 0.9.3
- Completly Documented Everything
- Fix typo in Sprite::getHeight
- Remove Deprecated/Useless Stuff
## 0.9.2
- Add Nvid Support(v0.0.1)
- Add Basic RenderD7 Splash
- Faster Graphics Init
- Fade Effects
- Fix Changelog Screen
## 0.9.1
- Fix Critical bug in Spritesheet animations
- Fix RenderD7::Color::Hex (Major performance tweak)
## 0.9.0
- Remove Stupid try of Console
- Add Services list
- Clean up Code
- Added Minimal Init for hax2.x
## 0.8.5
- Fix Deltatime
## 0.8.4
- A lot of Fixes
- New Features for BitmapPrinter
## 0.8.3
- Added Overlaycount to Info
- Addet ResultDecoder for errors
## 0.8.2
- Fix a lot of Stuff
- Use c++17 std::filesystem for RenderD7::Filesystem
## 0.8.1
- Add abillity to Get Stdout as string to render it to the screen.
## 0.8.0
- Implement BitmapPrinter
## 0.7.3
- Implement Over Render Overlay Framework
## 0.7.2
- Implement MT to csv file saving
- Add RGB2HEX
## 0.7.1
- Add the New Overlay Handler. Its Just in code and does nothing yet
## 0.7.0
- Made Big Progress In the MT Ovl but it still crashes On a 2nd C3D_FrameEnd \
- Implement 800px but doesn't work that good
## 0.6.2
- Fix Crash when exiting through Home Menu.
## 0.6.10
- Rewrite Threadsystem
- Improve framerate
## 0.6.02
- Fix Code in lang.hpp
- Add Draw Text Left Function (Right since 0.7.0)
- Add changelog
## 0.6.01
- Add Threading system
## 0.6.0
- Better Scene Management
## 0.5.0
- Fixed some Bugs!
## 0.4.0
- Trying to fix Filesystem and Bugs
## 0.3.0
- Recreate D7-Core into RenderD7
## 0.2.0
- Trying to create Animations of Images instead of Sheets
## 0.1.0
- Inital Release of D7-Core sprite animation plugin

View File

@ -1,210 +0,0 @@
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 "")
set(one_val_args "")
set(multi_val_args SRC_FILES DEPENDS)
cmake_parse_arguments(ARG "${opts}" "${one_val_args}" "${multi_val_args}" ${ARGN})
add_library(${TARGET_NAME} STATIC ${ARG_SRC_FILES})
target_include_directories(${TARGET_NAME} PUBLIC
include
${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()
# Setup Toolchain if not specified
# Could propably avoided by using arm-none-eabi-cmake
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()
## 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
)
# Set Project
project(palladium LANGUAGES C CXX VERSION 0.3.0)
option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)
# 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
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")
## 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/strings.cpp
source/core/sys.cpp
source/core/timer.cpp
source/core/timetrace.cpp)
## 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)
## Drivers Source Code
set(DRVS_SRC
source/drivers/hid.cpp)
## Lib3ds Source Code
set(L3DS_SRC
source/lib3ds/gamepad_icons.cpp
source/lib3ds/result_decoder.cpp
source/lib3ds/drv_hid.cpp
source/lib3ds/hwinfo.cpp
source/lib3ds/os.cpp)
## Lithium Source Code
set(LI_SRC
source/lithium/li7_shader.cpp
source/lithium/spritesheet.cpp
source/lithium/texture.cpp
source/lithium/font.cpp
source/lithium/objects.cpp
source/lithium/renderer.cpp)
## Sounbd Source Code
set(SOUND_SRC
source/sound/mp3.cpp)
## Overlay source Code
set(OVL_SRC
source/overlays/keyboard.cpp
source/overlays/message_mgr.cpp
source/overlays/overlay_mgr.cpp
source/overlays/performance.cpp
source/overlays/settings.cpp)
## App Source Code
set(APP_SRC
source/app/app.cpp
source/app/lang.cpp
source/app/error.cpp)
## UI7 Source Code
set(UI7_SRC
source/ui7/drawlist.cpp
source/ui7/io.cpp
source/ui7/menu.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/image.cpp
source/ui7/container/label.cpp)
#### Creating the Libraries (if activated) ####
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-drivers SRC_FILES ${DRVS_SRC} DEPENDS pd-core)
add_pd_lib(pd-lib3ds SRC_FILES ${L3DS_SRC} DEPENDS pd-drivers)
add_pd_lib(pd-lithium SRC_FILES ${LI_SRC} DEPENDS pd-core pd-image pd-external citro3d)
add_pd_lib(pd-sound SRC_FILES ${SOUND_SRC} DEPENDS pd-core mpg123)
add_pd_lib(pd-overlays SRC_FILES ${OVL_SRC} DEPENDS pd-lithium)
add_pd_lib(pd-app SRC_FILES ${APP_SRC} DEPENDS pd-overlays pd-drivers pd-lib3ds)
add_pd_lib(pd-ui7 SRC_FILES ${UI7_SRC} DEPENDS pd-drivers pd-lithium)
add_library(palladium INTERFACE)
target_link_libraries(palladium INTERFACE
pd-core pd-image pd-external pd-drivers pd-lib3ds
pd-lithium pd-overlays pd-app pd-ui7
)
add_dependencies(palladium
pd-core pd-image pd-external pd-drivers
pd-lib3ds pd-lithium pd-overlays pd-app pd-ui7
)
add_library(palladium-lite INTERFACE)
target_link_libraries(palladium-lite INTERFACE
pd-core pd-image pd-external pd-drivers pd-lib3ds
pd-lithium
)
add_dependencies(palladium-lite
pd-core pd-image pd-external pd-drivers
pd-lib3ds pd-lithium
)
if(PD_BUILD_TESTS)
add_executable(test test/app/main.cpp)
target_include_directories(test PUBLIC include test/app)
target_link_directories(test PUBLIC ${CMAKE_BINARY_DIR})
target_link_libraries(test PUBLIC palladium citro3d ctru m)
add_executable(testbench test/bench/main.cpp)
target_include_directories(testbench PUBLIC include test/bench)
target_link_directories(testbench PUBLIC ${CMAKE_BINARY_DIR})
target_link_libraries(testbench PUBLIC palladium citro3d ctru m)
# Generate 3DSX
ctr_generate_smdh(
${CMAKE_BINARY_DIR}/test.smdh
NAME "${APP_NAME}"
DESCRIPTION "Palladium test app"
AUTHOR "tobid7"
ICON "test/romfs/icon.png"
)
ctr_create_3dsx(
test
OUTPUT "${CMAKE_BINARY_DIR}/test.3dsx"
SMDH "${CMAKE_BINARY_DIR}/test.smdh"
ROMFS "${CMAKE_SOURCE_DIR}/test/romfs"
)
ctr_create_3dsx(
testbench
OUTPUT "${CMAKE_BINARY_DIR}/testbench.3dsx"
SMDH "${CMAKE_BINARY_DIR}/test.smdh"
ROMFS "${CMAKE_SOURCE_DIR}/test/romfs"
)
endif()
install(DIRECTORY include DESTINATION ".")

View File

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

152
Makefile Normal file
View File

@ -0,0 +1,152 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/3ds_rules
export PD_MAJOR := 1
export PD_MINOR := 0
export PD_PATCH := 0
VERSION := $(PD_MAJOR).$(PD_MINOR).$(PD_PATCH)
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#---------------------------------------------------------------------------------
TARGET := palladium
SOURCES := source source/base
DATA := data
INCLUDES := include
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
CFLAGS := -g -Wall -Wno-psabi -Werror -mword-relocations \
-ffunction-sections -fdata-sections \
-fomit-frame-pointer -ffast-math \
$(ARCH) $(BUILD_CFLAGS)
CFLAGS += $(INCLUDE) -D__3DS__ -D_GNU_SOURCE=1
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=c++20
ASFLAGS := -g $(ARCH) $(DEFINES)
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(CTRULIB)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I.
.PHONY: clean all doc
#---------------------------------------------------------------------------------
all: lib/libpalladium.a lib/libpalladiumd.a
dist-bin: all
@tar --exclude=*~ -cjf palladium-$(VERSION).tar.bz2 include lib
dist-src:
@tar --exclude=*~ -cjf palladium-src-$(VERSION).tar.bz2 include source Makefile
dist: dist-src dist-bin
install: dist-bin
mkdir -p $(DESTDIR)$(DEVKITPRO)/libctru
bzip2 -cd palladium-$(VERSION).tar.bz2 | tar -xf - -C $(DESTDIR)$(DEVKITPRO)/libctru
lib:
@[ -d $@ ] || mkdir -p $@
release:
@[ -d $@ ] || mkdir -p $@
debug:
@[ -d $@ ] || mkdir -p $@
lib/libpalladium.a : lib release $(SOURCES) $(INCLUDES)
@$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \
BUILD_CFLAGS="-DNDEBUG=1 -O3 -fomit-frame-pointer -fno-math-errno" \
DEPSDIR=$(CURDIR)/release \
--no-print-directory -C release \
-f $(CURDIR)/Makefile
lib/libpalladiumd.a : lib debug $(SOURCES) $(INCLUDES)
@$(MAKE) BUILD=debug OUTPUT=$(CURDIR)/$@ \
BUILD_CFLAGS="-DDEBUG=1 -Og" \
DEPSDIR=$(CURDIR)/debug \
--no-print-directory -C debug \
-f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr release debug lib
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT) : $(OFILES)
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@ -1,50 +1,62 @@
# Palladium # Palladium
Create README ?
# RenderD7 as Submodule (0.9.5+)
To use RenderD7 just use this command: `git submodule add https://github.com/NPI-D7/RenderD7` and add `-b v0.9.5` for example for a specific version.
**Framework / Engine to create Homebrew Apps / Games**
## Building And in Your Project Makefile add this
```
Install Dependencies: # Make Sure to Change this paths if your Submodule
# is located somewhere else
```bash RENDERD7_SRC := RenderD7/source RenderD7/external
# This Command will install everything RENDERD7_INC := RenderD7/include
(dkp-)pacman -S --noconfirm 3ds-dev 3ds-portlibs # Libraries used for RenderD7
# if you already use -lm, -lctru etc place a # before -lm
RENDERD7_LIBS := -lcurl -lmbedtls -lmbedx509 -lmbedcrypto -lz -lm -lcitro2dd -lcitro3d -lctru
```
Now you need to add it to your sources and includes
```
SOURCES := source $(RENDERD7_SRC)
INCLUDES := source $(RENDERD7_INC)
``` ```
Building: Example from rd7tf
### Installation (0.8.0-0.9.4) (OUTDATED)
If you want to have the lib in a projects `libs` dir or so you can simply add `-DCMAKE_INSTALL_PREFIX=./res` to the cmake command and copy the dirs from res to you libs folder Download a Package From Releses Page
`https://github.com/NPI-D7/RenderD7/releases/download/v0.9.4/renderd7.tar.bz2 -o renderd7.tar.bz2`
```bash Then Extract it to your Libraries Path
mkdir -p build `bzip2 -cd renderd7.tar.bz2 | tar -xf - -C path_to_your_libs`
cd build Finally put `-lrenderd7` to the First Place and add the path_to_your_libs
cmake .. -DCMAKE_BUILD_TYPE=Release # Make sure to build in Release Mode (exept you want to debug some issues)
make
make install
``` ```
LIBS := -lrenderd7 -lcurl -lstdc++ -lm -lcitro2d -lcitro3d -lctru
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(CTRULIB) ../path_to_your_libs
```
Make sure that `-lrenderd7` is before `-lcitro2d`, `-lcitro3d`, `-lctru`.
Here an example tree
```
Example-App
├── gfx
├── libs
│ ├── include
│ │ ├── rd7.hpp
│ │ └── renderd7
│ └── lib
│ ├── librenderd7.a
│ └── librenderd7d.a
├── Makefile
├── romfs
│ └── gfx
└── src
└── main.cpp
```
# Credits
- NPI-D7
- Tobi-D7 Main Dev
## Libraries Some Icons are From
https://icons8.de/
| Name | Last Updated | Platform | Depends | See Subfolder Readmes
|---|---|---|---|
| pd-core | 0.2.6 | multi | none |
| pd-external | 0.1.0 | multi | none |
| pd-image | 0.2.6 | multi | pd-core |
| pd-drivers | 0.2.4 | 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.2.9 | 3ds | pd-core, pd-image pd-lib3ds, citro3d |
| 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.2.9 | 3ds | pd-core, pd-image, pd-lib3ds, 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 |

View File

@ -7,33 +7,6 @@ from pathlib import Path
# WHY? Cause having this stupid .v.pica files in # WHY? Cause having this stupid .v.pica files in
# sourcecode is pain with some buildsystems # sourcecode is pain with some buildsystems
license_text = """
/*
MIT License
Copyright (c) 2024 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.
*/
"""
def file2array(path, custom_incluse_path): def file2array(path, custom_incluse_path):
print(path) print(path)
cip = len(custom_incluse_path) cip = len(custom_incluse_path)
@ -45,8 +18,7 @@ def file2array(path, custom_incluse_path):
buf = filei.read() buf = filei.read()
filei.close() filei.close()
fs = open(name + '.cpp', 'w') fs = open(name + '.cpp', 'w')
fs.write("// THIS FILE WAS GENERATED BY build_shaders.py!!!\n") fs.write("// THIS FILE WAS GENERATED BY build_shaders.py!!!\n\n")
fs.write(license_text)
fs.write('#include <'+ sip + name + '.hpp>\n\n') fs.write('#include <'+ sip + name + '.hpp>\n\n')
fs.write('// clang-format off\n') fs.write('// clang-format off\n')
fs.write('unsigned char ' + name + '[] = {\n') fs.write('unsigned char ' + name + '[] = {\n')
@ -57,9 +29,8 @@ def file2array(path, custom_incluse_path):
fs.write('size_t ' + name + '_size = ' + hex(len(buf)) + ';') fs.write('size_t ' + name + '_size = ' + hex(len(buf)) + ';')
fs.close() fs.close()
fh = open(name + '.hpp', 'w') fh = open(name + '.hpp', 'w')
fh.write("// THIS FILE WAS GENERATED BY build_shaders.py!!!\n") fh.write("// THIS FILE WAS GENERATED BY build_shaders.py!!!\n\n")
fh.write('#pragma once\n') fh.write('#pragma once\n\n')
fh.write(license_text)
fh.write('#include <cstddef>\n\n') fh.write('#include <cstddef>\n\n')
fh.write('extern unsigned char ' + name + '[];\n') fh.write('extern unsigned char ' + name + '[];\n')
fh.write('extern size_t ' + name + '_size;') fh.write('extern size_t ' + name + '_size;')
@ -86,9 +57,9 @@ for object in shaders:
name = Path(Path(object).stem).stem name = Path(Path(object).stem).stem
bp = os.path.dirname(object) bp = os.path.dirname(object)
build_shader(object) build_shader(object)
file2array(bp + '/' + name + '.shbin', 'pd/lithium/') file2array(bp + '/' + name + '.shbin', 'pd/')
install_code(name + '.cpp', 'source/lithium/') install_code(name + '.cpp', 'source/')
install_code(name + '.hpp', 'include/pd/lithium/') install_code(name + '.hpp', 'include/pd/')
cleanup() cleanup()
print("Done") print("Done")

View File

@ -1,28 +1,24 @@
import subprocess import subprocess
import glob import glob
from pathlib import Path from pathlib import Path
# Format script # Format script
def fmt_file(path): def fmt_file(path):
if Path(path).is_dir(): if Path(path).is_dir():
return # Skip return # Skip
try: try:
subprocess.run(['clang-format', '-i', path, '--style=Google'], check=True) subprocess.run(['clang-format', '-i', path, '--style=Google'], check=True)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print('Error for ' + Path(path).stem + ': ' + e) print('Error for ' + Path(path).stem + ': ' + e)
def fmt_dir(path): def fmt_dir(path):
sources = glob.glob(path+'/*') sources = glob.glob(path+'/*')
for file in sources: for file in sources:
fmt_file(file) fmt_file(file)
print('Formatting...') print('Formatting...')
fmt_dir('source/base') fmt_dir('source')
fmt_dir('source/drivers') fmt_dir('include')
fmt_dir('include') fmt_dir('include/pd')
fmt_dir('include/pd/base')
fmt_dir('include/pd/app')
fmt_dir('include/pd/drivers')
fmt_dir('include/pd/gfx')
print('Done') print('Done')

View File

@ -1,16 +1,18 @@
window.MathJax = { <div class="md-copyright">
tex: { {% if config.copyright %}
inlineMath: [["\\(", "\\)"]], <div class="md-copyright__highlight">
displayMath: [["\\[", "\\]"]], {{ config.copyright }}
processEscapes: true, </div>
processEnvironments: true {% endif %}
}, {% if not config.extra.generator == false %}
options: { Made with
ignoreHtmlClass: ".*|", <a href="https://doxide.org" target="_blank" rel="noopener">
processHtmlClass: "arithmatex" Doxide
} </a>
}; and
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
document$.subscribe(() => { Material for MkDocs
MathJax.typesetPromise() </a>
}) {% endif %}
</div>

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

View File

@ -1,58 +1,49 @@
:root { :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--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--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--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-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.variable, .md-typeset details.variable, .md-typeset .admonition.function, .md-typeset details.function,
.md-typeset .admonition.function, .md-typeset details.function, .md-typeset .admonition.concept, .md-typeset details.concept,
.md-typeset .admonition.typedef, .md-typeset details.typedef, .md-typeset .admonition.macro, .md-typeset details.macro {
.md-typeset .admonition.concept, .md-typeset details.concept, border-color: var(--md-default-fg-color--lighter);
.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 .variable > .admonition-title, .md-typeset .variable > summary, .md-typeset .concept > .admonition-title, .md-typeset .concept > summary,
.md-typeset .function > .admonition-title, .md-typeset .function > summary, .md-typeset .macro > .admonition-title, .md-typeset .macro > summary {
.md-typeset .typedef > .admonition-title, .md-typeset .typedef > summary, background-color: var(--md-default-bg-color);
.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);
.md-typeset .variable > .admonition-title::before, -webkit-mask-image: var(--md-admonition-icon--variable);
.md-typeset .variable > summary::before { mask-image: var(--md-admonition-icon--variable);
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);
.md-typeset .function > .admonition-title::before, -webkit-mask-image: var(--md-admonition-icon--function);
.md-typeset .function > summary::before { mask-image: var(--md-admonition-icon--function);
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 .concept > .admonition-title::before,
} .md-typeset .concept > summary::before {
background-color: var(--md-default-fg-color--light);
.md-typeset .typedef > .admonition-title::before, -webkit-mask-image: var(--md-admonition-icon--concept);
.md-typeset .typedef > summary::before { mask-image: var(--md-admonition-icon--concept);
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 .macro > .admonition-title::before,
} .md-typeset .macro > summary::before {
background-color: var(--md-default-fg-color--light);
.md-typeset .concept > .admonition-title::before, -webkit-mask-image: var(--md-admonition-icon--macro);
.md-typeset .concept > summary::before { mask-image: var(--md-admonition-icon--macro);
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 +1,9 @@
title: Palladium title: Palladium
description: description:
files: files:
- "include/*.hpp" - "include/*.hpp"
- "include/pd/app/*.hpp" - "include/pd/*.hpp"
- "include/pd/core/*.hpp" - "include/pd/base/*.hpp"
- "include/pd/drivers/*.hpp" - "include/*.h"
- "include/pd/image/*.hpp" - "include/pd/*.h"
- "include/pd/lib3ds/*.hpp" - "include/pd/base/*.h"
- "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"

View File

@ -1,71 +1,27 @@
#pragma once #pragma once
/* #include <pd/Error.hpp>
MIT License #include <pd/Hid.hpp>
#include <pd/Image.hpp>
#include <pd/Installer.hpp>
#include <pd/Lithium.hpp>
#include <pd/Message.hpp>
#include <pd/Net.hpp>
#include <pd/Overlays.hpp>
#include <pd/Rubidium.hpp>
#include <pd/Sheet.hpp>
#include <pd/Sound.hpp>
#include <pd/Texture.hpp>
#include <pd/Timer.hpp>
#include <pd/UI7.hpp>
#include <pd/base/Allocator.hpp>
#include <pd/base/FileSystem.hpp>
#include <pd/global_db.hpp>
#include <pd/palladium.hpp>
Copyright (c) 2024 - 2025 tobid7 namespace Palladium {
using Lithium = LI;
using RB = Rubidium;
} // namespace Palladium
Permission is hereby granted, free of charge, to any person obtaining a copy namespace PD = Palladium;
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/bit_util.hpp>
#include <pd/core/color.hpp>
#include <pd/core/common.hpp>
#include <pd/core/io.hpp>
#include <pd/core/strings.hpp>
#include <pd/core/sys.hpp>
#include <pd/core/timer.hpp>
#include <pd/core/timetrace.hpp>
#include <pd/core/vec.hpp>
// Graphics
#include <pd/lithium/renderer.hpp>
#include <pd/lithium/spritesheet.hpp>
// Image
#include <pd/image/image.hpp>
#include <pd/image/img_blur.hpp>
#include <pd/image/img_convert.hpp>
// Drivers
#include <pd/drivers/hid.hpp>
// Overlays
#include <pd/overlays/keyboard.hpp>
#include <pd/overlays/message_mgr.hpp>
#include <pd/overlays/overlay_mgr.hpp>
#include <pd/overlays/performance.hpp>
#include <pd/overlays/settings.hpp>
// UI7
#include <pd/ui7/ui7.hpp>
// Lib3ds
#include <pd/lib3ds/hwinfo.hpp>
#include <pd/lib3ds/memory.hpp>
#include <pd/lib3ds/os.hpp>
#include <pd/lib3ds/result_decoder.hpp>
// App
#include <pd/app/app.hpp>
#include <pd/app/error.hpp>
#include <pd/app/lang.hpp>
/// Setup these as non Namespaced access by default
#ifndef PD_MATH_NAMESPACED
using vec2 = PD::vec2;
using vec3 = PD::vec3;
using vec4 = PD::vec4;
#endif
// namespace Palladium = PD;

18
include/pd/Error.hpp Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <string>
namespace Palladium {
void Error(const std::string& msg);
inline void InlineError(const std::string& msg) {
std::string location = __FILE__ + std::string(":") + std::to_string(__LINE__);
Error("Error: \n" + location + "\n" + msg);
}
inline void InlineAssert(bool v, const std::string& msg = "") {
if (v == false) {
std::string location =
__FILE__ + std::string(":") + std::to_string(__LINE__);
Error("Assert Failed:\n" + location + "\n" + msg);
}
}
} // namespace Palladium

26
include/pd/Hardware.hpp Normal file
View File

@ -0,0 +1,26 @@
#pragma once
namespace Palladium {
namespace Hardware {
/// @brief Initialisize required Services
void Initialisize();
/// @brief Check if Headphones are Plugged in
/// @return true if headphones plugged in
bool IsHeadphones();
/// @brief Check if the 3ds Is Charging
/// @return true if System gets Charged
bool IsCharging();
/// @brief Check the Battery Percentage
/// @return Persentage as int
int GetBatteryPercentage();
/// @brief Get current State of 3d Slider
/// @return current 3dslider poition
float Get3dSliderLevel();
/// @brief Get Current state of Sound Slider
/// @return current SoundSlider state
float GetSoundSliderLevel();
/// @brief Get Current Wifi Level
/// @return current wifi level
int GetWifiLevel();
} // namespace Hardware
} // namespace Palladium

42
include/pd/Hid.hpp Normal file
View File

@ -0,0 +1,42 @@
// WARNING
// THIS IS BETA STUFF
// ITS MAKE LIKE EXTERNAL BUT
// FOR Palladium ITS INTEGRATED
#pragma once
#include <pd/maths/NVec.hpp>
#include <string>
namespace Palladium {
namespace Hid {
enum Actions {
Down = 0,
Held = 1,
Up = 2,
DownRepeat = 3,
};
// Register Functions
// Register Current state values
void RegKeyDown(uint32_t &key_down);
void RegKeyHeld(uint32_t &key_held);
void RegKeyUp(uint32_t &key_up);
void RegKeyRepeat(uint32_t &repeat);
void RegTouchCoords(NVec2 &touch_pos);
// Not Corectly Implemented Yet
void RegAnalog1Movement(NVec2 &movement);
void RegAnalog2Movement(NVec2 &movement);
// Register Keys
void RegKeyEvent(const std::string &event, uint32_t key);
// KeyEvents
bool IsEvent(const std::string &event, Actions action);
NVec2 GetTouchPosition();
NVec2 GetLastTouchPosition();
NVec2 GetTouchDownPosition();
void Update();
// Lock/Unlock Input api for example for Keyboard
void Lock();
void Unlock();
void Clear();
} // namespace Hid
} // namespace Palladium

33
include/pd/Image.hpp Normal file
View File

@ -0,0 +1,33 @@
#pragma once
#include <3ds.h>
#include <pd/Texture.hpp>
#include <pd/maths/NVec.hpp>
#include <pd/nimg.hpp>
#include <pd/smart_ctor.hpp>
#include <string>
namespace Palladium {
class Image {
public:
Image() = default;
Image(const std::string& path) { this->Load(path); }
~Image() = default;
PD_SMART_CTOR(Image)
void Load(const std::string& path);
void From_NIMG(const nimg& image);
void Delete();
Texture::Ref Get();
void Set(Texture::Ref i, NVec4 uvs = NVec4(-1, -1, -1, -1));
NVec2 GetSize();
NVec4 GetUV() { return (custom_uvs.x() != -1) ? custom_uvs : img->GetUV(); }
bool Loadet();
private:
bool ext = false;
Texture::Ref img;
NVec4 custom_uvs = NVec4(-1, -1, -1, -1);
};
} // namespace Palladium

17
include/pd/Installer.hpp Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <3ds.h> // Result
#include <string>
namespace Palladium {
struct InstallerInfo {
unsigned long long total;
unsigned long long current;
unsigned int mem_size = 0x80000;
bool active = false;
};
Result InstallCia(const std::string& path, bool self);
void InstallSetBuffersSize(unsigned int bytes);
InstallerInfo InstallGetInfo();
} // namespace Palladium

238
include/pd/Lithium.hpp Normal file
View File

@ -0,0 +1,238 @@
#pragma once
#include <citro3d.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <pd/Texture.hpp>
#include <pd/base/Allocator.hpp>
#include <pd/maths/NVec.hpp>
#include <vector>
#define MAKEFLAG(x) (1 << x)
using PDTextFlags = unsigned int;
enum PDTextFlags_ {
PDTextFlags_None = 0, //< Align is Left and Other things are disabled
PDTextFlags_AlignRight = MAKEFLAG(0),
PDTextFlags_AlignMid = MAKEFLAG(1),
PDTextFlags_Shaddow = MAKEFLAG(2), // TextBuf Killer lol (doubled Text)
PDTextFlags_Wrap = MAKEFLAG(3),
PDTextFlags_Short = MAKEFLAG(4),
PDTextFlags_Scroll = MAKEFLAG(5),
};
using PDLithiumFlags = unsigned int;
enum PDLithiumFlags_ {
PDLithiumFlags_None = 0,
PDLithiumFlags_TMS = MAKEFLAG(0), // Text Map System
PDLithiumFlags_LRS = MAKEFLAG(1), // Layer Render System
PDLithiumFlags_FCS = MAKEFLAG(2), // Floor Coords System
PDLithiumFlags_Default = PDLithiumFlags_TMS,
};
namespace Palladium {
class LIFont {
public:
struct CPI {
CPI()
: codepoint(0),
uv(NVec4()),
tex(nullptr),
szs(NVec2()),
off(0.f),
invalid(false) {}
CPI(bool iv)
: codepoint(0),
uv(NVec4()),
tex(nullptr),
szs(NVec2()),
off(0.f),
invalid(iv) {}
unsigned int codepoint;
NVec4 uv;
Texture::Ref tex;
NVec2 szs;
float off;
bool invalid;
};
LIFont() = default;
~LIFont() = default;
PD_SMART_CTOR(LIFont)
void LoadTFF(const std::string path, int px_size = 32);
void LoadBitmapFont(const std::string& path);
void LoadSystemFont();
int GetPixelHeight();
CPI GetCodepoint(unsigned int c);
std::string GetName() { return name; };
bool IsSystemFont() { return sysfnt; }
void Dump();
private:
bool sysfnt = false;
std::string name;
int pixel_height;
std::map<unsigned int, CPI> cpmap;
std::vector<Texture::Ref> tex;
};
class LI {
public:
struct Vtx {
Vtx() {}
Vtx(NVec2 xy, float u, float v, unsigned int clr) {
// Coords
pos[0] = xy[0];
pos[1] = xy[1];
pos[2] = 0.f;
// UV
uv[0] = u;
uv[1] = v;
col = clr;
}
NVec3 pos;
NVec2 uv;
unsigned int col;
};
/// CMD TYPES ///
/// 0 = SKIP
/// 2 = TRIANGLE
/// 1 = RECT
/// 3 = Circle
/////////////////
struct Cmd {
NVec4 top;
NVec4 bot;
NVec4 uv;
int layer = 0;
int cmd_type = 0;
bool fcs = false; // Floor Coords System
unsigned int clr = 0;
bool sfr = false; // SysFontRender
Texture::Ref tex = nullptr;
int index = 0;
};
/// Text Box ///
/// System to Make GetTextDiemnsions
/// and Short/Wrap faster
struct TextBox {
NVec2 size;
float time_created;
// Optional
bool optinal = false;
std::string text;
};
LI() = default;
~LI() = default;
static void Init();
static void Exit();
// Settings
static void EnableFeature(PDLithiumFlags flag) { flags |= flag; }
static void DisableFeature(PDLithiumFlags flag) { flags &= ~flag; }
static PDLithiumFlags& GetFeatures() { return flags; }
static void OnScreen(bool bottom);
static void Render(C3D_RenderTarget* top, C3D_RenderTarget* bot);
static NVec2 GetScreenSize() { return screen_size; }
static LIFont::Ref GetFont() { return font; }
static void SetFont(LIFont::Ref i) {
font_update = true;
font = i;
}
static void UseTexture(Texture::Ref tex = nullptr) {
active_texture = tex ? tex : single_color;
}
static bool IsBottomScreen() { return bottom_screen; }
static float GetTextScale() { return text_scale; }
static void SetTextScale(float scale) {
font_update = true;
text_scale = scale;
}
static void DefaultTextScale() {
font_update = true;
text_scale = default_text_size;
}
static void Layer(int v) { layer = v; }
static int Layer() { return layer; }
static void NewLayer() { layer++; }
static NVec2 GetTextDimensions(const std::string& text);
static std::string ShortText(const std::string& in, int maxlen, NVec2& dim);
static std::string WrapText(const std::string& in, int maxlen, NVec2& dim);
// Drawing Functions
static void DrawRect(NVec2 pos, NVec2 size, unsigned int color, NVec4 uvs);
static void DrawLine(NVec2 a, NVec2 b, unsigned int clr, int t = 1);
static void DrawCircle(NVec2 pos, float r, unsigned int color, int segments);
static void DrawRect(NVec2 pos, NVec2 size, unsigned int color) {
UseTexture();
DrawRect(pos, size, color, NVec4(0, 1, 1, 0));
}
static void DrawTriangle(NVec2 a, NVec2 b, NVec2 c, unsigned int color);
static void DrawImage(NVec2 pos, Texture::Ref tex, NVec2 size, NVec4 uvs) {
UseTexture(tex);
DrawRect(pos, size, 0xffffffff, uvs);
}
static void DrawText(NVec2 pos, unsigned int color, const std::string& text,
PDTextFlags flags = 0, NVec2 ap = NVec2());
static int Vertices() { return num_vertices; }
static int Indices() { return num_indices; }
static int Drawcalls() { return num_drawcalls; }
static int DarwCommands() { return num_commands; }
static size_t GetMaxVerticesNum() { return vertex_buffer.size(); }
private:
static void RotateCorner(NVec2& v, float s, float c);
static void MakeRect(NVec4& top, NVec4& bot, NVec2 pos, NVec2 szs,
float angle = 0.f);
static bool CompareCommands(const Cmd& a, const Cmd& b);
static void RenderFrame(bool bottom);
/// CTX ///
static PDLithiumFlags flags;
// Font Stuff
// Default Font Size in (px)
static const float default_font_size;
static const float default_text_size;
static float text_scale;
// Renderer Stuff
static NVec2 screen_size;
static bool bottom_screen;
static int layer;
static std::vector<Cmd> draw_lists[2];
static Texture::Ref active_texture;
static Texture::Ref single_color;
static std::vector<Vtx, LinearAllocator<Vtx>> vertex_buffer;
static std::vector<unsigned short, LinearAllocator<unsigned short>>
idx_buffer;
static size_t vertex_index;
static size_t idx_index;
static LIFont::Ref font;
static bool font_update;
static bool sysfont_render;
static std::map<std::string, TextBox> text_sizes;
static int cmd_index;
// Debug
static int num_vertices;
static int num_drawcalls;
static int num_commands;
static int num_indices;
// Shader
static DVLB_s* li7_dvlb;
static shaderProgram_s li7_prog;
static C3D_AttrInfo li7_attr;
static int uLoc_proj;
};
} // namespace Palladium

27
include/pd/Message.hpp Normal file
View File

@ -0,0 +1,27 @@
#pragma once
#include <string>
namespace Palladium {
struct Message {
Message(std::string t, std::string m) {
title = t;
message = m;
animtime = 0.f;
}
std::string title;
std::string message;
float animtime;
};
void ProcessMessages();
void PushMessage(const Message& msg);
inline void PushMessage(const std::string& head, const std::string& msg) {
PushMessage(Message(head, msg));
}
// Config
void SetMessageIdleStartFrame(int frame);
void SetMessageTotalAnimationFrames(int total_frames);
void SetMessageFadeOutStartFrame(int frame);
} // namespace Palladium

42
include/pd/Net.hpp Normal file
View File

@ -0,0 +1,42 @@
#pragma once
#include <pd/external/json.hpp>
#include <string>
namespace Palladium {
namespace Net {
// Define List of Errors
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
};
// Set an typedefine for Error code
using Error = unsigned long long;
// Extract Error_ from Error code
inline Error_ ErrorCode(Error err) {
return static_cast<Error_>(static_cast<unsigned int>(err & 0xffffffff));
}
// Extract Http Status code, Curl Error Code or Ctr Result Code
inline int StatusCode(Error err) {
Error_ c = ErrorCode(err);
if (c != Error_StatusCode && c != Error_CtrStatus && c != Error_Curl)
return 0;
return static_cast<unsigned int>(err >> 32);
}
Error Download(const std::string& url, std::string& data);
Error Download2File(const std::string& url, const std::string& path);
Error GitDownloadRelease(const std::string& url, const std::string& asset_name,
const std::string& path, bool prerelease = false);
Error JsonApiRequest(const std::string& api_url, nlohmann::json& res);
unsigned long long GetProgressCurrent();
unsigned long long GetProgressTotal();
} // namespace Net
} // namespace Palladium

107
include/pd/Overlays.hpp Normal file
View File

@ -0,0 +1,107 @@
#pragma once
#include <pd/Ovl.hpp>
#include <pd/Timer.hpp>
#include <pd/base/FunctionTrace.hpp>
#include <pd/maths/NVec.hpp>
#include <string>
typedef int PDKeyboard;
enum PDKeyboard_ {
PDKeyboard_Default,
PDKeyboard_Numpad,
PDKeyboard_Password,
};
enum PDKeyboardState {
PDKeyboardState_None = 0,
PDKeyboardState_Cancel = 1,
PDKeyboardState_Confirm = 2,
};
using PDKeyboardFlags = unsigned int;
enum PDKeyboardFlags_ {
PDKeyboardFlags_None = 0,
PDKeyboardFlags_BlendTop = 1 << 0,
PDKeyboardFlags_BlendBottom = 1 << 1,
PDKeyboardFlags_LockControls = 1 << 2,
PDKeyboardFlags_Default = PDKeyboardFlags_BlendTop |
PDKeyboardFlags_BlendBottom |
PDKeyboardFlags_LockControls,
};
namespace Palladium {
class Ovl_Ftrace : public Palladium::Ovl {
public:
/// @brief Constructor
Ovl_Ftrace(bool* is_enabled);
/// @brief Override for Draw
void Draw(void) const override;
/// @brief Override for Logic
void Logic() override;
private:
bool* i_is_enabled;
};
class Ovl_Metrik : public Palladium::Ovl {
public:
/// @brief Constructor
Ovl_Metrik(bool* is_enabled, bool* screen, unsigned int* mt_color,
unsigned int* txt_color, float* txt_size);
/// @brief Override for Draw
void Draw(void) const override;
/// @brief Override for Logic
void Logic() override;
private:
// Mutable internal values
mutable std::string mt_fps;
mutable std::string mt_cpu;
mutable std::string mt_gpu;
mutable std::string mt_cmd;
mutable std::string mt_lfr;
mutable std::string mt_vtx;
mutable std::string mt_idx;
mutable std::string mt_drc;
mutable std::string mt_dmc;
mutable std::string mt_mem;
// Importand Adresses
bool* i_is_enabled;
bool* i_screen;
unsigned int* i_mt_color;
unsigned int* i_txt_color;
float* i_txt_size;
mutable Ftrace::TimeStats cpu_stats;
mutable Ftrace::TimeStats gpu_stats;
mutable Timer v_update;
};
class Ovl_Keyboard : public Palladium::Ovl {
public:
/// @brief Constructor
/// Keyboard Type not Supported for now
Ovl_Keyboard(std::string& ref, PDKeyboardState& state,
const std::string& hint = "", PDKeyboard type = 0,
PDKeyboardFlags flags = PDKeyboardFlags_Default);
/// @brief Deconstructor
~Ovl_Keyboard();
/// @brief Override for Draw
void Draw(void) const override;
/// @brief Override for Logic
void Logic() override;
private:
mutable std::map<unsigned char, char> shared_data;
// Pointer to useres String
std::string* typed_text = nullptr;
std::string str_bak;
PDKeyboardState* state;
PDKeyboard type;
int mode = 0;
int ft3 = 0;
PDKeyboardFlags flags;
};
} // namespace Palladium

28
include/pd/Ovl.hpp Normal file
View File

@ -0,0 +1,28 @@
#pragma once
#include <map>
#include <memory>
namespace Palladium {
/// @brief The Overlay Class (Used for Toasts for example)
class Ovl {
public:
/// @brief Deconstructor
virtual ~Ovl() {}
/// @brief Function Called to Draw this
virtual void Draw() const = 0;
/// @brief Logic of the Overlay
virtual void Logic() = 0;
/// @brief Should the overlay be killed
/// @return Killed or Not
inline bool IsKilled() { return this->iskilled; }
/// @brief Kill The Overlay
inline void Kill() { iskilled = true; }
private:
/// @param iskilled For IsKilled();
bool iskilled = false;
};
/// @brief Add an Overlay to the Screen
/// @param scene Overlay to push to Screen
void AddOvl(std::unique_ptr<Palladium::Ovl> scene);
} // namespace Palladium

View File

@ -0,0 +1,54 @@
#pragma once
#include <3ds.h>
#include <string>
namespace Palladium {
/// @brief Decoder for 3ds Result Codes
class ResultDecoder {
public:
/// @brief Constructor
ResultDecoder() {}
/// @brief Deconstructor
~ResultDecoder() {}
/// @brief Load a Result into Decoder
/// @param rescode Result Code
void Load(Result rescode);
/// @brief Load A Hex Converted Code into Decoder
/// @param rescode Result-Hex Code
void Load(std::string rescode);
/// @brief Get Hex Code
/// @return Hex-Code
std::string GetCode();
/// @brief Get Level Name
/// @return Level Name
std::string GetLevel();
/// @brief Get Level Value
/// @return Level Value
int GetLevelInt();
/// @brief Get The Mosule Name
/// @return Module Name
std::string GetModule();
/// @brief Get The Module Value
/// @return Module Value
int GetModuleInt();
/// @brief Get The Description
/// @return Description
std::string GetDescription();
/// @brief Get The Description Valur
/// @return Description Value
int GetDescriptionInt();
/// @brief Get the Summary
/// @return Summary
std::string GetSummary();
/// @brief Get the Summary Value
/// @return Summary Value
int GetSummaryInt();
/// @brief Write a Result log file to sd
void WriteLog(void);
private:
/// @param m_rescode Result code
Result m_rescode;
};
} // namespace Palladium

30
include/pd/Rubidium.hpp Normal file
View File

@ -0,0 +1,30 @@
#pragma once
#include <pd/nimg.hpp>
#include <pd/smart_ctor.hpp>
namespace Palladium {
class Rubidium {
public:
Rubidium(int w, int h);
Rubidium();
~Rubidium();
PD_SMART_CTOR(Rubidium)
nimg& GetNimg() { return image; }
void LoadFile(const std::string& path);
void LoadNimg(const std::string& path);
// Rendering
void DrawPixel(int x, int y, unsigned int color);
void DrawRect(int x, int y, int w, int h, unsigned int color, int t = 1);
void DrawRectSolid(int x, int y, int w, int h, unsigned int color);
void DrawLine(int x1, int y1, int x2, int y2, unsigned int color, int t = 1);
void Flip(bool h, bool v);
void EnableAA(bool enable) { enable_aa = enable; }
private:
// Leinwand (dont know english word for that)
nimg image;
bool enable_aa = true;
};
} // namespace Palladium

23
include/pd/Sheet.hpp Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include <tex3ds.h>
#include <pd/Image.hpp>
#include <pd/Texture.hpp>
#include <pd/smart_ctor.hpp>
namespace Palladium {
class Sheet {
public:
Sheet() = default;
~Sheet() = default;
PD_SMART_CTOR(Sheet)
void LoadT3X(const std::string& path);
Texture::Ref Get(int idx);
Image::Ref GetImage(int idx);
private:
std::vector<Texture::Ref> sprites;
Tex3DS_Texture sheet;
C3D_Tex* sheet_tex = nullptr;
};
} // namespace Palladium

35
include/pd/Sound.hpp Normal file
View File

@ -0,0 +1,35 @@
#pragma once
#include <3ds.h>
#include <pd/smart_ctor.hpp>
#include <string>
namespace Palladium {
/** Sound Class */
class Sound {
public:
/// \brief Construct new Soundeffect
/// \param path Path to the .wav file
/// \param channel the channel 1-23
/// \param toloop true:loop the sound, false: don't loop
Sound(const std::string &path, int channel = 1, bool toloop = false);
/// @brief Deconstructor
~Sound();
PD_SMART_CTOR(Sound)
/// @brief Play the sound
void Play();
/// @brief Stop the sound
void Stop();
private:
/// \param dataSize Size of the filedata
u32 dataSize;
/// \param waveBuf For ndsp
ndspWaveBuf waveBuf;
/// \param data Memmory data of the sound
uint8_t *data = NULL;
/// \param chnl Channel of the sound
int chnl;
};
} // namespace Palladium

63
include/pd/Sprite.hpp Normal file
View File

@ -0,0 +1,63 @@
#pragma once
#include <citro3d.h>
#include <pd/Image.hpp>
#include <pd/smart_ctor.hpp>
namespace Palladium {
/// @brief Sprite Class
class Sprite {
public:
/// \brief Construct Sprite
Sprite() = default;
/// \brief Deconstruct Sprite
~Sprite() = default;
PD_SMART_CTOR(Sprite)
/// \brief Load a Sprite From SpriteSheet
/// \param img the Image to load from.(Palladium::Image)
void FromImage(Palladium::Image::Ref img);
/// @brief Draw the Sprite
/// @return success ?
bool Draw();
/// @brief Set the Center Position
/// @param x X Pos
/// @param y Y Pos
void SetCenter(float x, float y);
/// @brief Set the Sprite's Position
/// @param x X Pos
/// @param y Y Pos
void SetPos(float x, float y);
/// @brief Set The Sprite's Scale
/// @param x Scale on X-Axis
/// @param y Scale on Y-Axis
void SetScale(float x, float y);
/// @brief Set the Sprite's Rotation
/// @param rotation ratation
void SetRotation(float rotation);
/// @brief Rotate the Sprite
/// @param speed Speed to Rotate
void Rotate(float speed);
/// @brief Get Tje Sprite's Width
/// @return Width
float GetWidth();
/// @brief Get the Sprite's Height
/// @return Height
float GetHeight();
/// @brief Get The Sprite's X Position
/// @return X Position
float GetPosX();
/// @brief Get the Sprite's Y Position
/// @return Y Position
float GetPosY();
NVec2 GetSize();
NVec2 GetPos();
void SetPos(NVec2 pos);
void SetScale(NVec2 scale);
void SetRotCenter(NVec2 percentage);
private:
///// @param sprite The Sprite
// C2D_Sprite sprite;
};
} // namespace Palladium

13
include/pd/Tasks.hpp Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include <functional>
namespace Palladium {
namespace Tasks {
/// @brief Push A Task
/// @param fun Function of Your Task
/// @return index
int Create(std::function<void()> fun);
/// @brief Destroy all Tasks
void DestroyAll();
} // namespace Tasks
} // namespace Palladium

77
include/pd/Texture.hpp Normal file
View File

@ -0,0 +1,77 @@
#pragma once
#include <citro3d.h>
#include <pd/maths/NVec.hpp>
#include <pd/smart_ctor.hpp>
#include <string>
#include <vector>
namespace Palladium {
class Texture {
public:
// Define Types supported by the texture loader
// For example usefull to waste not as much space
// in linear mem
enum Type {
RGBA32,
RGB24,
A8,
};
enum Filter {
NEAREST,
LINEAR,
};
Texture() {
// Set Default UV
this->uvs[0] = 0.0f;
this->uvs[1] = 1.0f;
this->uvs[2] = 1.0f;
this->uvs[3] = 0.0f;
};
~Texture() { Delete(); }
PD_SMART_CTOR(Texture)
void Delete();
/// @brief Loads an Image [png, jpg, bmp] as texture
/// by default it sets up the texture as RGBA32 and
/// only supports RGB24 and RGBA32 images
/// @param path Path to file
void LoadFile(const std::string& path);
/// @brief Loads an Image [png, jpg, bmp] as texture
/// by default it sets up the texture as RGBA32 and
/// only supports RGB24 and RGBA32 images
/// @param data Data of file
void LoadFromMemory(const std::vector<unsigned char>& data);
/// @brief Create Texture by pixel Data. This function supports
/// [RGBA32, RGB24, A8]
/// @param data Pixel Data
/// @param w Width of data
/// @param h Height of Data
/// @param type Type of Data (default is RGBA32)
void LoadPixels(const std::vector<unsigned char>& data, int w, int h,
Type type = RGBA32, Filter filter = NEAREST);
/// @brief This function sets up a texture Object based on the input
/// Data and a self setup C3D_Tex. You dont need to delete it as
/// This class does this automatically
void ExternalLoad(C3D_Tex* tex, NVec2 rszs, NVec4 uvs);
C3D_Tex* Get() { return this->tex; }
NVec2 GetTexSize();
NVec2 GetSize() { return img_size; }
// As the texture is a pow of 2 we need a uv
NVec4 GetUV() { return uvs; }
void AutoDelete(bool enable) { ad = enable; }
private:
void MakeTex(std::vector<unsigned char>& buf, int w, int h,
Type type = RGBA32, Filter filter = NEAREST);
C3D_Tex* tex = nullptr;
NVec2 img_size;
NVec4 uvs;
bool ad = true;
};
} // namespace Palladium

View File

@ -0,0 +1,28 @@
#pragma once
#include <pd/palladium.hpp>
namespace Palladium {
class ThemeEditor : public Palladium::Scene {
public:
ThemeEditor();
~ThemeEditor();
void Update() override;
private:
Theme::Ref edit_theme;
// Placeholder to save active one to
Theme::Ref temp_theme;
// temp vars for samples
bool cm;
std::string inpt;
int menu = 0;
// Keyboard
PDKeyboardState kbd_state;
std::string kbd_text;
std::vector<std::string> theme_list;
};
} // namespace Palladium

13
include/pd/Time.hpp Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include <string>
namespace Palladium {
/// @brief Format a String
/// @param fmt_str Format To
/// @param ... Additional Args
/// @return Formatted String
std::string FormatString(std::string fmt_str, ...);
/// @brief Get Current Time as String
/// @return Time-String
std::string GetTimeStr(void);
} // namespace Palladium

26
include/pd/Timer.hpp Normal file
View File

@ -0,0 +1,26 @@
#pragma once
#include <3ds.h>
#include <pd/smart_ctor.hpp>
namespace Palladium {
class Timer {
public:
Timer(bool autostart = true);
~Timer() {}
PD_SMART_CTOR(Timer)
void Reset();
void Tick();
void Pause();
void Resume();
float Get();
float GetLive();
bool Running();
private:
uint64_t last = 0;
uint64_t current = 0;
bool is_running = false;
};
} // namespace Palladium

134
include/pd/UI7.hpp Normal file
View File

@ -0,0 +1,134 @@
#pragma once
#include <pd/Image.hpp>
#include <pd/Lithium.hpp>
#include <pd/base/Color.hpp>
#include <pd/maths/NVec.hpp>
#include <pd/smart_ctor.hpp>
#define UI7MAKEFLAG(x) (1 << x)
using UI7MenuFlags = unsigned int;
enum UI7MenuFlags_ {
UI7MenuFlags_None = 0,
UI7MenuFlags_NoTitlebar = UI7MAKEFLAG(0),
UI7MenuFlags_TitleMid = UI7MAKEFLAG(1),
UI7MenuFlags_HzScrolling = MAKEFLAG(2),
UI7MenuFlags_VtScrolling = MAKEFLAG(3),
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
};
enum UI7Horizontal {
UI7Horizontal_Left = 0,
UI7Horizontal_Center = 1,
UI7Horizontal_Right = 2,
};
enum UI7Vertical {
UI7Vertical_Top = 0,
UI7Vertical_Center = 1,
UI7Vertical_Bot = 2,
};
class DrawCmd;
class UI7DrawList {
public:
UI7DrawList() = default;
~UI7DrawList() = default;
void AddRectangle(NVec2 pos, NVec2 szs, PDColor clr);
void AddRectangle(NVec2 pos, NVec2 szs, unsigned int clr);
void AddTriangle(NVec2 pos0, NVec2 pos1, NVec2 pos2, PDColor clr);
void AddTriangle(NVec2 pos0, NVec2 pos1, NVec2 pos2, unsigned int clr);
void AddText(NVec2 pos, const std::string &text, PDColor clr,
PDTextFlags flags = 0, NVec2 box = NVec2());
void AddText(NVec2 pos, const std::string &text, unsigned int clr,
PDTextFlags flags = 0, NVec2 box = NVec2());
void AddImage(NVec2 pos, Palladium::Image::Ref img);
void AddCall(std::shared_ptr<DrawCmd> cmd);
void Process(bool auto_clear = true);
void Clear();
int Layer() { return layer; }
void Layer(int v) { layer = v; }
int BaseLayer() { return bl; }
void BaseLayer(int v) { bl = v; }
PD_SMART_CTOR(UI7DrawList)
private:
int layer = 0;
int bl = 0;
void AddDebugCall(std::shared_ptr<DrawCmd> cmd);
std::vector<std::shared_ptr<DrawCmd>> list;
};
namespace UI7 {
// Key functions
void Init();
void Deinit();
void Update();
float GetTime();
float GetDeltaTime();
bool &IsDebugging();
// Internal Function
// Should not be used
void Debug();
bool &DebugMenu();
bool Button(const std::string &label, NVec2 size = NVec2(0, 0));
void Checkbox(const std::string &label, bool &c);
void Label(const std::string &label, PDTextFlags flags = 0);
void Progressbar(float value);
/// @brief Draw Image in Menu
/// @param img Pointer f.e to Palladium::Image2
void Image(Palladium::Image::Ref img);
void BrowserList(const std::vector<std::string> &entrys, int &selection,
PDTextFlags txtflags = 0, NVec2 size = NVec2(0, 0),
int max_entrys = 13);
void InputText(const std::string &label, std::string &text,
const std::string &hint = "");
bool BeginMenu(const std::string &title, NVec2 size = NVec2(0, 0),
UI7MenuFlags flags = 0);
void EndMenu();
void Grid(const std::string &name, const NVec2 &size, const NVec2 &entry_size,
void (*display_func)(void *, NVec2), void **data_array,
size_t num_entrys);
void ColorSelector(const std::string &label, unsigned int &color);
bool BeginTree(const std::string &text);
void EndTree();
void Prompt(const std::string &label, int &res,
// For Translations
const std::string &lcf = "Confirm",
const std::string &lcc = "Cancel");
void ClosePromts();
NVec2 GetCursorPos();
void SetCursorPos(NVec2 cp);
void RestoreCursor();
void SameLine();
void Separator();
// Internal API (For Creating Custom Objects)
bool InBox(NVec2 inpos, NVec2 boxpos, NVec2 boxsize);
void MoveCursor(NVec2 size);
bool HandleScrolling(NVec2 &pos, NVec2 size);
bool InMenu();
namespace Menu {
// All of them return the Main BG DrawList if Menu is null
UI7DrawList::Ref GetBackgroundList();
UI7DrawList::Ref GetList();
UI7DrawList::Ref GetForegroundList();
// Other Menu Specific Functions
float GetScrollingOffset();
void SetScrollingOffset(float off);
bool IsScrolling();
} // namespace Menu
namespace Next {
// Alignment in ScreenSpace
void Align(UI7Horizontal hz = UI7Horizontal_Left,
UI7Vertical vt = UI7Vertical_Top);
} // namespace Next
// DrawLists
UI7DrawList::Ref GetForegroundList();
UI7DrawList::Ref GetBackgroundList();
} // namespace UI7

View File

@ -1,231 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/timer.hpp>
#include <pd/core/timetrace.hpp>
#include <pd/lib3ds/drv_hid.hpp>
#include <pd/lithium/renderer.hpp>
#include <pd/overlays/message_mgr.hpp>
#include <pd/overlays/overlay_mgr.hpp>
namespace PD {
/**
* Template Class for a User Application on the 3ds
*/
class App {
public:
/**
* alias for AppFlags
*/
using AppFlags = u32;
/**
* App Flags
*
* - Probably only the default Setup should be used
*/
enum AppFlags_ {
AppFlags_None = 0, ///< Do Nothing
AppFLags_UserLoop = 1 << 0, ///< Handle User MainLoop
AppFlags_HandleOverlays = 1 << 1, ///< Process Overlays
AppFlags_HandleMessageMgr = 1 << 2, ///< Process Messages
AppFlags_HandleRendering = 1 << 3, ///< Handle Rendering
/// Default Flags
AppFlags_Default = AppFlags_HandleMessageMgr | AppFlags_HandleOverlays |
AppFlags_HandleRendering | AppFLags_UserLoop,
};
/**
* alias for AppInitFlags
*/
using AppInitFlags = u32;
/**
* App Init Flags
*/
enum AppInitFlags_ {
AppInitFlags_None = 0, ///< Do nothing (probably a useles ability)
AppInitFlags_MountRomfs = 1 << 0, ///< Mount Romfs on PreInit
AppInitFlags_InitGraphics = 1 << 1, ///< Default Init Graphics for GPU use
AppInitFlags_New3dsMode = 1 << 2, ///< Enable New3DS Speedup
AppInitFlags_InitGraphicsNoC3D = 1 << 3, ///< Init GFX for Buf Modification
AppInitFlags_InitLithium = 1 << 4, ///< Init 2D Rendering Engine
/// I dont have a name for this one yet
/// It Inits Internal Directory structure
AppInitFlags_UnnamedOption1 = 1 << 5,
AppInitFlags_InitHwInfo = 1 << 6, ///< Init HwInfo from lib3ds
/// Default App Init Flags
AppInitFlags_Default = AppInitFlags_MountRomfs | AppInitFlags_InitGraphics |
AppInitFlags_New3dsMode | AppInitFlags_InitLithium,
};
/**
* App Constructor that can Optionally set a name for the App
* @param name App Name Defaults to App
*/
App(const std::string& name = "App") {
if (too) {
Error("Only one App can be created at the same time!");
}
this->name = name;
too++;
}
/**
* App Deconstructor
*/
~App() { too--; }
/**
* Templete function where the user can Init his stuff
*/
virtual void Init() {}
/**
* Template function to deinit stuff (most is deinit automatically
* but it is still possible that some things need to be ordered manually)
*/
virtual void Deinit() {}
/**
* Template User MainLoop
* @param delta Delta time
* @param time App Run time
* @return false to exit the App
*/
virtual bool MainLoop(float delta, float time) { return false; }
/**
* Function to actually run the app
*
* Example:
* ```cpp
* int main() {
* UserApp app;
* app.Run();
* return 0;
* }
* ```
*/
void Run();
/**
* Get the Renderer Reference
* @return Renderer Reference
*/
LI::Renderer::Ref Renderer() { return renderer; }
/**
* Get Message Manager Reference
* @return Message Manager Reference
*/
MessageMgr::Ref Messages() { return msg_mgr; }
/**
* Get Overlay Manager Reference
* @return Overlay Manager Reference
*/
OverlayMgr::Ref Overlays() { return overlay_mgr; }
/**
* Get Input Driver Reference
* @return Input Driver Reference
*/
Hid::Ref Input() { return input_mgr; }
/**
* Get Framerate
* @return frames per second
*/
float GetFps() const { return fps; }
/**
* Enable Runtime Feature(s) (AppFlags)
* @param flags Flag(s) to enable
*/
void FeatureEnable(AppFlags flags) { runtimeflags |= flags; }
/**
* Disable Runtime Feature(s) (AppFlags)
* @param flags Flag(s) to disable
*/
void FeatureDisable(AppFlags flags) { runtimeflags &= ~flags; }
/**
* Get Reference Access to runtimeflags
* @return reference to runtimeflags
*/
AppFlags& GetFeatureSet() { return runtimeflags; }
/**
* Get App Datadirectory (if enabled in AppInitFlags)
* @return App Data Directory
*/
std::string GetDataDirectory();
protected:
/**
* Top Screen Reference
*/
Screen::Ref Top;
/**
* Bottom Screen Reference
*/
Screen::Ref Bottom;
/**
* AppInitFlags
*
* - Can only be edited in your App class Constructor
* - Editing them Later will not effect the Deinit Process
* Example:
* ```cpp
* class YourApp : public PD::App {
* public:
* YourApp(): App("YourApp") {
* AppInitFlags |= AppInitFlags_InitLithium;
* }
* }
* ```
*/
AppInitFlags InitFlags = AppInitFlags_Default;
private:
/** Runtime Flags (can be edited) */
AppFlags runtimeflags = AppFlags_Default;
/** Safe Copy to prevent from editing befor Deinit */
AppInitFlags SafeInitFlags = AppInitFlags_Default;
/** PreInit Handler */
void PreInit();
/** Post Deinit Handler */
void PostDeinit();
/** Renderer Reference */
LI::Renderer::Ref renderer;
/** Message Manager */
MessageMgr::Ref msg_mgr;
/** Overlay Manager */
OverlayMgr::Ref overlay_mgr;
/** Input Driver */
Hid::Ref input_mgr;
/** Timer to track the App Runtime */
Timer::Ref app_time;
/** Last Time (for delta time and fps calculation) */
u64 last_time;
/** Framerate */
float fps;
/** App Name */
std::string name;
/** A static variable to make sure only one App instance can exist */
static int too;
};
} // namespace PD

View File

@ -1,40 +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 {
/**
* Function to Throw an Error Screen
* @param error Error Message to Display
*/
void Error(const std::string& error);
/**
* Custom Assert Function that Shows an Error Screen if it fails
* @param v The bool var to check `(Throws error if it is false)`
* @param msg The Message that Should be displayed if the Assert fails
*/
void Assert(bool v, const std::string& msg);
} // 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/common.hpp>
namespace PD {
/**
* Language System
*
* - Translations are saved into json files
* - path should point to a directory containing the json files
* - example for filenames: `en.json`, `de.json`, `fr.json`
*/
class Lang : public SmartCtor<Lang> {
public:
Lang() = default;
~Lang() = default;
/**
* Function to set the path to search for Language files
* @param path Path to search the files
*/
void SetBasePath(const std::string &path) { langs_path = path; }
/**
* Load a language file by the language key
* @param lang_key Language key for example `de`
*/
void Load(const std::string &lang_key) {
LoadFile(langs_path + "/" + lang_key + ".json");
}
/**
* Directly load a Language file from a specific path
* @param path Path to load the file from
*/
void LoadFile(const std::string &path);
/**
* Get a String by a `Keyword`
* @param k Keyword to search for
* @return Returns the string or if none found it returns the Keyword
*/
const std::string &Get(const std::string &k);
/**
* Get the Language Name
* @return Returns the Language Name
*/
const std::string &GetName() { return lang_name; }
/**
* Get the Language ID / Key
* @return Returns the Language ID
*/
const std::string &GetID() { return lang_id; }
/**
* Get the Language Author(s)
* @return Returns the Author(s) of the Language file
*/
const std::string &GetAuthor() { return lang_author; }
/**
* Get the Language File Search Path
* @return Returns Path where the Files are searched for
*/
const std::string &GetPath() { return langs_path; }
private:
const int ver = 0;
/** Language Files Root path */
std::string langs_path = "romfs:/lang";
/** Language Name */
std::string lang_name;
/** Language ID / Key */
std::string lang_id;
/** Language Author */
std::string lang_author;
/** KEY - STRING Table for faster Key access */
std::map<std::string, std::string> ltable;
};
} // namespace PD

View File

@ -0,0 +1,40 @@
#pragma once
#include <3ds.h>
#include <memory>
#include <pd/Error.hpp>
// Write own LinearAllocator for learning
namespace Palladium {
template <typename T>
class LinearAllocator : public std::allocator<T> {
public:
typedef size_t size_type;
typedef T* pointer;
typedef const T* const_pointer;
template <typename T1>
struct rebind {
typedef LinearAllocator<T1> other;
};
pointer allocate(size_type n, const void* hint = nullptr) {
if (n > this->max_size()) {
Palladium::Error(
"Linear Allocator: \nBad Alloc -> size is larger than free space!");
return nullptr;
}
return (pointer)linearAlloc(n * sizeof(T));
}
void deallocate(pointer p, size_type) { linearFree((void*)p); }
size_type max_size() { return linearSpaceFree(); }
LinearAllocator() throw() {}
LinearAllocator(const LinearAllocator<T>& a) throw() : std::allocator<T>(a) {}
~LinearAllocator() throw() {}
};
} // namespace Palladium

204
include/pd/base/Color.hpp Normal file
View File

@ -0,0 +1,204 @@
#pragma once
#include <unistd.h>
#include <cstring>
#include <memory>
#include <pd/smart_ctor.hpp>
#include <string>
#include <vector>
#define UNPACK_RGBA(col) \
(unsigned char)(col >> 24), (col >> 16), (col >> 8), (col)
#define UNPACK_BGRA(col) \
(unsigned char)(col >> 8), (col >> 16), (col >> 24), (col)
inline unsigned int RGBA8(unsigned char r, unsigned char g, unsigned char b,
unsigned char a = 255) {
return (r | g << 8 | b << 16 | a << 24);
}
typedef int PDColor;
// MultiColor (Less FunctionNameLen)
struct Color2 {
unsigned int color0;
unsigned int color1;
};
struct Color3 {
unsigned int color0;
unsigned int color1;
unsigned int color2;
};
struct Color4 {
unsigned int color0;
unsigned int color1;
unsigned int color2;
unsigned int color3;
};
enum PDColor_ {
PDColor_Text, ///< This Color Should always be used for Light Backgrounds
PDColor_TextDisabled, /// Text Disabled Color
PDColor_Text2, ///< And This want for Texts on Dark Backgrounds
PDColor_Background, ///< Your Bg Color
PDColor_Header, ///< Header Color (if the header is dark text2 is used)
PDColor_Selector, ///< Selector Color
PDColor_SelectorFade, ///< Selector FadingTo Color
PDColor_List0, ///< List Color1
PDColor_List1, ///< List Color2
PDColor_MessageBackground, ///< Message Background
PDColor_Button, ///< Button Color
PDColor_ButtonHovered, ///< Button Color if Hovered
PDColor_ButtonDisabled, ///< Button Color if disabled
PDColor_ButtonActive, ///< Button Colkor if Clicked
PDColor_Checkmark, ///< Checkbox Checkmark Color
PDColor_FrameBg, ///< Frame Background Color
PDColor_FrameBgHovered, ///< Frame Background Color if hovered
PDColor_Progressbar, ///< Progressbar Color
/// NON COLOR ///
PDColor_Len, ///< Used to define the lengh of this list
};
namespace Palladium {
class Theme {
public:
Theme() = default;
~Theme() = default;
void Load(const std::string &path);
void Default();
void Save(const std::string &path);
unsigned int Get(PDColor clr);
void Set(PDColor clr, unsigned int v);
void Swap(PDColor a, PDColor b);
bool Undo();
void UndoAll();
void TextBy(PDColor bg);
PDColor AutoText(PDColor bg);
void ClearHistory() { changes.clear(); }
std::vector<unsigned int> &GetTableRef() { return clr_tab; }
// For Smart Pointer
PD_SMART_CTOR(Theme);
// Loader method
void CopyOther(Theme::Ref theme);
private:
struct change {
change(PDColor a, unsigned int f, unsigned int t)
: clr(a), from(f), to(t) {}
change(PDColor a, PDColor b, unsigned int f, unsigned int t)
: clr(a), clr2(b), from(f), to(t) {}
PDColor clr;
PDColor clr2 = 0; // Used if Swap
unsigned int from;
unsigned int to;
};
// Use a vector for faster access
std::vector<unsigned int> clr_tab;
std::vector<change> changes;
};
Theme::Ref ThemeActive();
/// @brief Change Theme Adress
/// @param theme your adress
void ThemeSet(Theme::Ref theme);
namespace Color {
/// @brief RGBA Class
class RGBA {
public:
/// @brief Construct
/// @param r
/// @param g
/// @param b
/// @param a
RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
: m_r(r), m_g(g), m_b(b), m_a(a) {}
/// @brief Construct
/// @param r
/// @param g
/// @param b
/// @param a
RGBA(float r, float g, float b, float a = 1.f)
: m_r(r * 255.f), m_g(g * 255.f), m_b(b * 255.f), m_a(a * 255.f) {}
RGBA(unsigned int in) {
#define ISIMPLEUNPAK(x, y) (((x) >> y) & 0xFF)
m_r = ISIMPLEUNPAK(in, 0);
m_g = ISIMPLEUNPAK(in, 8);
m_b = ISIMPLEUNPAK(in, 16);
m_a = ISIMPLEUNPAK(in, 24);
}
RGBA(PDColor in) {
if (!Palladium::ThemeActive()) return;
unsigned int col = Palladium::ThemeActive()->Get(in);
m_r = ISIMPLEUNPAK(col, 0);
m_g = ISIMPLEUNPAK(col, 8);
m_b = ISIMPLEUNPAK(col, 16);
m_a = ISIMPLEUNPAK(col, 24);
}
RGBA &changeR(unsigned char r) {
m_r = r;
return *this;
}
RGBA &changeG(unsigned char g) {
m_g = g;
return *this;
}
RGBA &changeB(unsigned char b) {
m_b = b;
return *this;
}
RGBA &changeA(unsigned char a) {
m_a = a;
return *this;
}
RGBA &fade_to(const RGBA &color, float p) {
m_a =
m_a + static_cast<unsigned char>((color.m_a - m_a) * ((p + 1.0f) / 2));
m_b =
m_b + static_cast<unsigned char>((color.m_b - m_b) * ((p + 1.0f) / 2));
m_g =
m_g + static_cast<unsigned char>((color.m_g - m_g) * ((p + 1.0f) / 2));
m_r =
m_r + static_cast<unsigned char>((color.m_r - m_r) * ((p + 1.0f) / 2));
return *this;
}
/// @brief Get as Uint32
/// @return color
unsigned int toRGBA() const { return RGBA8(m_r, m_g, m_b, m_a); }
// Just calculate the "lightness" f.e. to use Text or Text2
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));
}
bool is_light() {
// Gives us the light or dark to not
// always use the below "if" statement
return (luminance() >= 0.5);
}
unsigned char m_r = 0, m_g = 0, m_b = 0, m_a = 0;
};
std::string RGBA2Hex(unsigned int c32);
/// @brief Convert RGB to Hex
/// @param r
/// @param g
/// @param b
/// @return Hex-String
std::string RGB2Hex(int r, int g, int b);
/// @brief Hex to U32
/// @param color
/// @param a
/// @return Color32
unsigned int Hex(const std::string &color, unsigned char a = 255);
} // namespace Color
} // namespace Palladium

View File

@ -0,0 +1,24 @@
#pragma once
#include <string>
#include <vector>
namespace Palladium {
namespace FileSystem {
/// @brief A Directory Entry
struct Entry {
/// @brief Patf of The Entry
std::string path;
/// @brief Name of The Entry
std::string name;
/// @brief Directory or File
bool dir = false;
};
/// @brief Gets All Entrys of A Directory into a Vector
/// @param path The Path of the Directory
/// @return The Vector of found Entrys
std::vector<Palladium::FileSystem::Entry> GetDirContent(std::string path);
std::string GetParentPath(std::string path, std::string mount_point);
std::vector<Entry> GetDirContentsExt(
std::string &path, const std::vector<std::string> &extensions);
} // namespace FileSystem
} // namespace Palladium

View File

@ -0,0 +1,137 @@
#pragma once
// Base includes
#include <functional>
#include <map>
#include <string>
// 3ds does not support std::chrono
#include <3ds.h>
/// @brief 3ds System Ticks per milli second
#define TICKS_PER_MSEC 268111.856
#define f2s(x_) #x_
#define scomb(x1, x2) std::string(x1 + x2)
namespace Palladium {
namespace Ftrace {
class TimeStats {
public:
TimeStats(int len) : len(len), values(len, 0) {}
void Add(float v) {
values[idx] = v;
idx = next_index(idx);
num_values = std::min(num_values + 1, len);
}
float GetAverage() {
float res = 0.f;
if (!num_values) {
return res;
}
for (int i = 0; i < num_values; ++i) {
res += values[index(i)];
}
return res / num_values;
}
float GetMax() {
float res = 0.f;
if (!num_values) {
return res;
}
for (int i = 0; i < num_values; i++) {
res = std::max(res, values[index(i)]);
}
return res;
}
float GetMin() {
float res = 0.f;
if (!num_values) {
return res;
}
res = values[0];
for (int i = 0; i < num_values; i++) {
res = std::min(res, values[index(i)]);
}
return res;
}
const std::vector<float>& GetData() { return values; }
const float& operator[](int i) { return values[index(i)]; }
const size_t GetLen() { return len; }
const size_t GetNumValues() { return num_values; }
private:
// Indexing Functions for better overview
size_t next_index(size_t current) const { return (current + 1) % len; }
size_t index(size_t v) const { return (idx + len - num_values + v) % len; }
// Data
int len = 0;
std::vector<float> values;
int idx = 0;
int num_values = 0;
};
/// @brief Result of FTrace
struct FTRes {
FTRes() : time_start(0), time_end(0), time_of(0.f), is_ovl(false), ts(60) {}
std::string group; ///< Group of the Trace
std::string func_name; ///< Function Name
uint64_t time_start; ///< when started
uint64_t time_end; ///< when stopped
float time_of; ///< stop - start (how long)
bool is_ovl; ///< is displayed in overlay?
TimeStats ts; ///< Time Stats
};
/// @brief Map of Traces
extern std::map<std::string, Palladium::Ftrace::FTRes> pd_traces;
/// @brief Set a Start TracePoint
/// @param group Set a Group Name
/// @param func_name Set a Function Name
inline void Beg(const std::string& group, const std::string& func_name) {
std::string trace_id = scomb(group, func_name);
auto& trace = pd_traces[trace_id];
trace.group = group;
trace.func_name = func_name;
trace.time_start = svcGetSystemTick();
}
/// @brief Set an End TracePoint
/// @param group Set a Group Name
/// @param func_name Set a Function Name
inline void End(const std::string& group, const std::string& func_name) {
std::string trace_id = scomb(group, func_name);
auto& trace = pd_traces[trace_id];
trace.time_end = svcGetSystemTick();
trace.time_of =
static_cast<float>(trace.time_end - trace.time_start) / TICKS_PER_MSEC;
trace.ts.Add(trace.time_of);
}
/// @brief Trace a function execution
/// @param group Set a Group Name
/// @param name Set a Function Name
inline void Func(const std::string& group, const std::string& name,
std::function<void()> fun) {
if (!fun) return;
Beg(group, name);
fun();
End(group, name);
}
/// @brief This Starts an Ftrace and
/// end ist when going out of scope
struct ScopedTrace {
ScopedTrace(std::string g, std::string n) : group(g), name(n) {
Ftrace::Beg(g, n);
}
~ScopedTrace() { Ftrace::End(group, name); }
std::string group;
std::string name;
};
} // namespace Ftrace
} // namespace Palladium

24
include/pd/base/Lang.hpp Normal file
View File

@ -0,0 +1,24 @@
#pragma once
// clang-format off
#include <string>
#include <pd/external/json.hpp>
// clang-format on
namespace Palladium {
namespace Lang {
/// @brief Get 3ds System lang! [en] by default
/// @return Sytemlang as string
std::string GetSys();
/// @brief Get The Translation String
/// @param key Key of Translation
/// @return The Translated String
std::string Get(const std::string &key);
/// @brief Load A Language json
/// @param lang The Language Key [en], [de], etc, or getSys()
void Load(const std::string &lang);
// New funcs
std::string GetName();
std::string GetAuthor();
std::string GetShortcut();
} // namespace Lang
} // namespace Palladium

View File

@ -0,0 +1,26 @@
#pragma once
#include <cstddef>
namespace Palladium {
namespace Memory {
/// @brief Metriks struct For the Internal Tracker
struct memory_metrics {
unsigned int t_TotalAllocated = 0; ///< Total Allocated Memory
unsigned int t_TotalFreed = 0; ///< Total Deleted Memory
/// @brief Gets the Currently Allocated Memory
unsigned int t_CurrentlyAllocated() {
return t_TotalAllocated - t_TotalFreed;
}
};
/// @brief Get Total Allocated Memory
/// @return Total Allocated Memory
size_t GetTotalAllocated();
/// @brief Get Total Deleted Memory
/// @return Total Deleted Memory
size_t GetTotalFreed();
/// @brief Get Current Allocated Memory
/// @return Current Allocated Memory
size_t GetCurrent();
} // namespace Memory
} // namespace Palladium

View File

@ -0,0 +1,98 @@
#pragma once
#include <format>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
namespace Palladium {
/// @brief Check if A String ends with
/// @param name Input String
/// @param extensions Extensions to Check for
/// @return Ends with or not
inline bool NameIsEndingWith(const std::string &name,
const std::vector<std::string> &extensions) {
if (name.substr(0, 2) == "._") return false;
if (name.size() == 0) return false;
if (extensions.size() == 0) return true;
for (int i = 0; i < (int)extensions.size(); i++) {
const std::string ext = extensions.at(i);
if (strcasecmp(name.c_str() + name.size() - ext.size(), ext.c_str()) == 0)
return true;
}
return false;
}
/// @brief Format Milliseconds to clean string (Stolen from one of my Mc
/// Plugins)
/// @param t_time Time in ms
/// @return String
inline std::string MsTimeFmt(float t_time, bool dems = false) {
std::string res;
if (t_time < 0.000001f) {
res = std::format("{:.2f}ns", t_time * 1000000.f);
} else if (t_time < 0.001f) {
res = std::format("{:.2f}µs", t_time * 1000.f);
} else if (t_time < 1.0f) {
res = std::format("{:.2f}ms", t_time);
} else if (t_time < 60000.0f) {
int seconds = static_cast<int>(t_time / 1000.0f);
float milliseconds = t_time - (seconds * 1000.0f);
if (seconds) {
res = std::format("{}s {:.2f}ms", seconds, milliseconds);
}
res = std::format("{:.2f}ms", milliseconds);
} else {
int minutes = static_cast<int>(t_time / 60000.0f);
int seconds = static_cast<int>((t_time - (minutes * 60000.0f)) / 1000.0f);
float milliseconds = t_time - (minutes * 60000.0f) - (seconds * 1000.0f);
res = std::format("{}m {}s {:.2f}ms", minutes, seconds, milliseconds);
}
return res;
}
inline std::string FormatBytes(int bytes) {
char out[32];
if (bytes == 1)
snprintf(out, sizeof(out), "%d Byte", bytes);
else if (bytes < 1024)
snprintf(out, sizeof(out), "%d Bytes", bytes);
else if (bytes < 1024 * 1024)
snprintf(out, sizeof(out), "%.1f KB", (float)bytes / 1024);
else if (bytes < 1024 * 1024 * 1024)
snprintf(out, sizeof(out), "%.1f MB", (float)bytes / 1024 / 1024);
else
snprintf(out, sizeof(out), "%.1f GB", (float)bytes / 1024 / 1024 / 1024);
return out;
}
} // namespace Palladium
template <class T>
T GetFileName(T const &path, T const &delims = "/\\") {
return path.substr(path.find_last_of(delims) + 1);
}
template <class T>
T remove_ext(T const &filename) {
typename T::size_type const p(filename.find_last_of('.'));
return p > 0 && p != T::npos ? filename.substr(0, p) : filename;
}
template <typename T>
std::string Int_To_Hex(T i) {
std::stringstream stream;
stream << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex
<< i;
return stream.str();
}

View File

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

View File

@ -1,210 +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/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 Color {
public:
/**
* Default Constructor (all variables are set to 0)
*/
Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
/**
* Constructor for 32Bit Color Input
* @param color 32Bit Color value
*/
Color(u32 color) {
m_a = (color >> 24) & 0xff;
m_b = (color >> 16) & 0xff;
m_g = (color >> 8) & 0xff;
m_r = color & 0xff;
}
/**
* Constructor for 8Bit Input
* @param r Red Value
* @param g Green Value
* @param b Blue Value
* @param a Optional Alpha Value (Defaults to 255)
*/
Color(u8 r, u8 g, u8 b, u8 a = 255) {
m_r = r;
m_g = g;
m_b = b;
m_a = a;
}
/**
* Constructor for float Input
* @param r Red Value
* @param g Green Value
* @param b Blue Value
* @param a Optional Alpha Value (Defaults to 1.0f)
* @note There is no Check if the number is between 0.0 and 1.0
*/
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);
}
/**
* 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
* @param hex Hex String in `#ffffff` or `#ffffffff` format
* @return Color class itself
*/
Color& Hex(const std::string& hex);
/**
* Convert this Color Object to Hex string
* @param rgba [default false] sets if 8 or 6 digit color should be returned
* @return Color Hex String
*/
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_r; }
/**
* 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_r; }
/**
* 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_r; }
/**
* Fade from Current to another Color
* @param color Color to fade to
* @param p Amount (supports -1.0 to 1.0 for use of sine)
* @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));
return *this;
}
/**
* Get 32Bit Color Value
* @return 32Bit Color Value
*/
u32 Get() const { return (m_a << 24) | (m_b << 16) | (m_g << 8) | m_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));
}
/**
* Check if the Color is Light or Dark
* @return true if light
*/
bool IsLight() const { return (Luminance() >= 0.5); }
/**
* Operator to cast Color to 32Bit Value
* @return 32Bit Color Value
*/
operator u32() const { return Get(); }
private:
/** Red Value */
u8 m_r;
/** Green Value */
u8 m_g;
/** Blue Value */
u8 m_b;
/** Alpha Value */
u8 m_a;
};
} // namespace PD

View File

@ -1,120 +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 <chrono>
#include <cinttypes>
#include <cmath>
#include <filesystem> // Requires C++ 17 or later
#include <format> // Requires C++ 20 or later
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
namespace PD {
/**
* SmartCtor (std::shared_ptr) Template class for Smart Pointers
*
* - Just add : public PD::SmartCtor<YourClass> to your class
* @tparam T Your Class
*/
template <typename T>
class SmartCtor {
public:
/** Reference alias for std::shared_ptr<Type> */
using Ref = std::shared_ptr<T>;
/**
* static Function to Create a New Reference
* @param args Additional Arguments (Depends on your classes Constructors)
* @return New Reference Object
*/
template <typename... Args>
static Ref New(Args&&... args) {
return std::make_shared<T>(std::forward<Args>(args)...);
}
};
/**
* Wrapper for SmartCtor<Type>::New(Args)
* @tparam T Class Type
* @param args Arguments
* @return Type Reference (SmartPointer)
*/
template <typename T, typename... Args>
SmartCtor<T>::Ref New(Args&&... args) {
return SmartCtor<T>::New(std::forward<Args>(args)...);
}
// Defines
/** alias for 64 Bit unsigned integer */
using u64 = unsigned long long;
/** alias for 32 Bit unsigned integer */
using u32 = unsigned int;
/** alias for 16 Bit unsigned integer */
using u16 = unsigned short;
/** alias for 8 Bit unsigned integer */
using u8 = unsigned char;
/**
* LinInfo Compile Information
*/
namespace LibInfo {
/**
* Get the Compiler Name and Version the lib got Compiled with
* @return Compiler Name / Version
*/
const std::string CompiledWith();
/**
* Get the C++ Version used to compile the lib
* @return C++ Version (__cplusplus)
*/
const std::string CxxVersion();
/**
* Get the Buildtime of the Library
* @return Build Time
*/
const std::string BuildTime();
/**
* Get the Library Version
* @return Library Version String
*/
const std::string Version();
/**
* Get the Git Commit the Lib got compiled in
* @return Git Commit 7digit short hash
*/
const std::string Commit();
/**
* Get the Git Branch which was active when compiling the lib
* @return Git Branch
*/
const std::string Branch();
} // namespace LibInfo
} // namespace PD

View File

@ -1,46 +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 {
/**
* Set of File Functions
*/
namespace IO {
/**
* Load a File into an 8Bit Memory Buffer
* @param path Path to the File
* @return 8Bit FileBuffer
*/
std::vector<u8> LoadFile2Mem(const std::string& path);
/**
* Hash a 8Bit Memory Buffer
* @param data 8Bit input Buffer
* @return 32Bit Hash
*/
u32 HashMemory(const std::vector<u8>& data);
} // namespace IO
} // namespace PD

View File

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

View File

@ -1,124 +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 {
/**
* Set of String Utillity Functions
*/
namespace Strings {
/**
* Check if a String ends with a specific extension
* @param str Input string
* @param exts List of Extensions to check for
* @return true if one of the extensions is found in the String
*/
bool StringEndsWith(const std::string& str,
const std::vector<std::string>& exts);
/**
* Function to Create a wstring of a string
* @param s Input String to Convert
* @return Result wstring
* @note Currently using std::filesystem::path for this as wstring_convert
* got removed in c++ 20
*/
std::wstring MakeWstring(const std::string& s);
/**
* Generate a Formatted String by an Nanoseconds Input
* @param nanos Nanoseconds Input
* @return Result String
*/
const std::string FormatNanos(unsigned long long nanos);
/**
* Generate a Formatted String by an Milliseconds Input
* @param millis Milliseconds Input
* @return Result String
*/
const std::string FormatMillis(unsigned long long millis);
/**
* Create a formatted String by an input bytes value
* @param bytes value in bytes
* @result Formatted String for example `2.5MB`
*/
const std::string FormatBytes(unsigned long long bytes);
/**
* Extract the Filename out of a Path
* @param path Path to extract from
* @param saperators Path Split Chars
* @return extracted filename
*/
const std::string GetFileName(const std::string& path,
const std::string& saperators = "/\\");
/**
* Remove Extension from a Path / Filename
* @param path Input Path
* @return Path without Extension
*/
const std::string PathRemoveExtension(const std::string& path);
/**
* Function to Convert a Type to a hex value
* @tparam T Type
* @param v value
* @return hex string beginning with 0x
*/
template <typename T>
inline const std::string ToHex(const T& v) {
std::stringstream s;
s << "0x" << std::setfill('0') << std::setw(sizeof(v) * 2) << std::hex << v;
return s.str();
}
/**
* Generate a Hash out of a string
* @param s String to hash
* @return 32Bit Hash
*/
u32 FastHash(const std::string& s);
/**
* Function to Generate a Compiler Name and Version String
* Based on their Macros
* @return CompilerName: Version
*/
inline const std::string GetCompilerVersion() {
/// As the function looks like this Project is meant to
/// Be ported to other systems as well
std::stringstream res;
#ifdef __GNUC__
res << "GCC: " << __GNUC__;
res << "." << __GNUC_MINOR__ << ".";
res << __GNUC_PATCHLEVEL__;
#elif __clang__
res << "Clang: " << __clang_major__ << ".";
res << __clang_minor__ << ".";
res << __clang_patchlevel__;
#elif _MSC_VER
res << "MSVC: " << _MSC_VER;
#else
res << "Unknown Compiler";
#endif
return res.str();
}
} // namespace Strings
} // namespace PD

View File

@ -1,66 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/timetrace.hpp>
namespace PD {
/**
* Namespace containing functions for get Millis and Get Nanos
*/
namespace Sys {
/**
* alias for the TimeTrace Traces Map
*/
using TraceMap = std::map<std::string, TT::Res::Ref>;
/**
* Get Current Time in Milliseconds
* @return 64Bit value of millis
*/
u64 GetTime();
/**
* Get Current Time in Nanoseconds
* @return 64Bit value of nanos
*/
u64 GetNanoTime();
/**
* Get a TimeTrace Reference by its string ID
* @param id trace name
* @return Trace reference or nullptr if not found
*/
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
*/
bool TraceExist(const std::string& id);
/**
* Get TraceMap Reference
* @return edidable Reference to the TraceMap
*/
TraceMap& GetTraceMap();
} // namespace Sys
} // 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/common.hpp>
#include <pd/core/sys.hpp>
namespace PD {
/**
* Timer class
*/
class Timer : public SmartCtor<Timer> {
public:
/**
* Constructor
* @param auto_start [default true] sets if timer should start after creation
*/
Timer(bool auto_start = true);
/**
* Unused Deconstructor
*/
~Timer() {}
/**
* Resume Timer if Paused
*/
void Rseume();
/**
* Pause Timer if not Paused
*/
void Pause();
/**
* Update Timer
*/
void Update();
/**
* Reset Timer
*/
void Reset();
/**
* Check if the Timer is Running
* @return true if its running
*/
bool IsRunning() const;
/**
* Get 64 Bit milliseconds value
* @return 64Bit millis
*/
u64 Get();
/**
* Get as Seconds
* @return seconds as floating number
*/
double GetSeconds();
private:
/** Start of the Timer */
u64 start;
/** Current Time */
u64 now;
/** Is Running */
bool is_running = false;
};
} // namespace PD

View File

@ -1,255 +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 {
/**
* Class to calculate Maximum/Minimum and Average Timings
*/
class TimeStats : public SmartCtor<TimeStats> {
public:
/**
* Constructor taking a lengh for the List
* @param l Lengh of the data list
*/
TimeStats(int l) : len(l), val(l, 0) {}
~TimeStats() = default;
/**
* Add a New Value to the list
* @param v value to add
*/
void Add(u64 v) {
val[idx] = v;
idx = next(idx);
num_val = std::min(num_val + 1, len);
}
/**
* Get Avarage Num
* @return Average
*/
u64 GetAverage() {
if (!num_val) return 0.f;
u64 res = 0;
for (int i = 0; i < num_val; i++) {
res += val[smart_idx(i)];
}
return res / num_val;
}
/**
* Get Minimum Num
* @return Minimum value
*/
u64 GetMin() {
if (!num_val) return 0.f;
u64 res = std::numeric_limits<u64>::max();
for (int i = 0; i < num_val; i++) {
res = std::min(val[smart_idx(i)], res);
}
return res;
}
/**
* Get Maximum Value
* @return Max Value
*/
u64 GetMax() {
if (!num_val) return 0.f;
u64 res = 0;
for (int i = 0; i < num_val; i++) {
res = std::max(val[smart_idx(i)], res);
}
return res;
}
/**
* Clear the List
*/
void Clear() {
val.assign(len, 0);
idx = 0;
num_val = 0;
}
/**
* Get Data Buffer
* @return data bufer (not edidable)
*/
const std::vector<u64> &GetData() { return val; }
/**
* Access an element in the list [not edidable]
* @return value to access
*/
const u64 &operator[](int i) { return val[smart_idx(i)]; }
/**
* Get List Lengh
* @return Lengh
*/
const size_t GetLen() { return len; }
/**
* Get Number of Values
* @return number of values
*/
const size_t GetNumValues() { return num_val; }
private:
/**
* Get the Next Position to write to
* @param c current position
* @return next position
*/
size_t next(size_t c) const { return (c + 1) % len; }
/**
* Smart Indexing in for loops to make sure to
* not index a value that was not set yet
* @param v pos in for loop
* @return indexing pos
*/
size_t smart_idx(size_t v) const { return (idx + len - num_val + v) % len; }
/** Lengh of the list */
int len = 0;
/** Value Storage */
std::vector<u64> val;
int idx = 0;
int num_val = 0;
};
/**
* Timatrace Functions
*/
namespace TT {
/**
* Data Structure for a TimeTrace Result
*/
class Res : public SmartCtor<Res> {
public:
/** Constructore that Inits a protocol at size of 60 frames */
Res() { protocol = TimeStats::New(60); }
~Res() = default;
/**
* Setter for the ID (Name)
* @param v ID of the Trace
*/
void SetID(const std::string &v) { id = v; }
/**
* Getter for the traces ID
* @return Trace ID
*/
const std::string GetID() { return id; }
/**
* Setter for the Start Value
* @param v start time
*/
void SetStart(u64 v) { start = v; }
/**
* Getter for the Start time
* @return start time
*/
u64 GetStart() { return start; }
/**
* Setter for the End Time
* @param v end time
*/
void SetEnd(u64 v) {
end = v;
protocol->Add(GetLastDiff());
}
/**
* Getter for the End Time
* @result end time
*/
u64 GetEnd() { return end; }
/**
* Get Last Diffrence between end and start
* @return end - start
*/
u64 GetLastDiff() { return end - start; }
/**
* Get Protcol Reference
* @return Protocol Ref
*/
TimeStats::Ref GetProtocol() { return protocol; }
private:
/** Trace ID */
std::string id;
/** Start time */
u64 start;
/** End Time */
u64 end;
/** Protocol */
TimeStats::Ref protocol;
};
/**
* Begin a Trace
* @param id Name of the Trace
*/
void Beg(const std::string &id);
/**
* End a Trace
* @param id Name of the Trace
*/
void End(const std::string &id);
/**
* Collect Start end end of the trace by tracking
* when the Scope object goes out of scope
*
* Example:
* ```cpp
* void SomeFunction() {
* // Create a Scoped Trace called "SomeFunc"
* PD::TT::Scope st("SomeFunc");
* // Do your functions stuff
* // End at the end it goes out of
* // scope which collects the end time
* }
* ```
*/
class Scope {
public:
/**
* Constructor requiring a Name for the Trace
* @param id Name of the Trace
*/
Scope(const std::string &id) {
this->id = id;
Beg(id);
}
/**
* Deconstructor getting the end time when going out of scope
*/
~Scope() { End(id); }
private:
/** Trace Name/ID */
std::string id;
};
} // namespace TT
} // namespace PD

View File

@ -1,222 +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/vec.hpp>
namespace PD {
/**
* D7 Tween Engine (or something like that)
* @tparam T Any Numeric value
*/
template <typename T>
class Tween {
public:
/**
* Effects Table
*/
enum Effect {
Linear, ///< Linear Movement [works]
EaseInQuad, ///< EaseInQuad Movement [works]
EaseOutQuad, ///< EaseOutQuad Movement [works]
EaseInOutQuad, ///< EaseInOutQuad Movement [works]
EaseInCubic, ///< EaseInCubic Movement [not tested]
EaseOutCubic, ///< EaseOutCubic Movement [not tested]
EaseInOutCubic, ///< EaseInOutCubic Movement [disabled]
EaseInSine, ///< EaseInSine Movement [works]
EaseOutSine, ///< EaseOutSine Movement [works]
EaseInOutSine, ///< EaseInOutSine Movement [not tested]
};
Tween() = default;
~Tween() = default;
/**
* Update Tween
* @param delta deltatime
*/
void Update(float delta) {
time += delta / 1000.f;
if (time > tend) {
finished = true;
time = tend;
}
}
/**
* Check if Tween is finished
* @return true if finished
*/
bool IsFinished() const { return finished; }
/**
* Force finish the animation
* @return Class reference
*/
Tween& Finish() {
time = tend;
finished = true;
return *this;
}
/**
* Set Start Value
* @tparam T datatype of the Tween
* @param start Start Value
* @return class Reference
*/
Tween& From(const T& start) {
Reset();
this->start = start;
return *this;
}
/**
* Set End Value
* @tparam T datatype of the Tween
* @param end End Value
* @return class Reference
*/
Tween& To(const T& end) {
Reset();
this->end = end;
return *this;
}
/**
* Set the Duration (in seconds)
* @param seconds Duration
* @return class Reference
*/
Tween& In(float seconds) {
Reset();
tend = seconds;
return *this;
}
/**
* Set Effect of the Tween
* @param e Effect
* @return class Reference
*/
Tween& As(const Effect& e) {
effect = e;
return *this;
}
/**
* Reset to time 0
* @return class Reference
*/
Tween& Reset() {
finished = false;
time = 0.f;
return *this;
}
/**
* Get the Prograss in percent (0.0 to 1.0) of the tween
* @return progress value
*/
float Progress() const { return time / tend; }
/**
* Swap Start and end Position of the Tween
* @return class reference
*/
Tween& Swap() {
T temp = start;
start = end;
end = temp;
return *this;
}
/**
* Operator that returns the current value calculated
* by time and effect
*/
operator T() {
float t = 0.f;
switch (effect) {
case EaseInQuad:
t = time / tend;
return (end - start) * t * t + start;
break;
case EaseOutQuad:
t = time / tend;
return -(end - start) * t * (t - 2) + start;
break;
case EaseInOutQuad:
t = time / (tend / 2);
if (t < 1) return (end - start) / 2 * t * t + start;
t--;
return -(end - start) / 2 * (t * (t - 2) - 1) + start;
break;
case EaseInCubic:
t = time / tend;
return (end - start) * t * t * t + start;
break;
case EaseOutCubic:
t = time / tend;
t--;
return (end - start) * (t * t * t + 1) + start;
break;
// case EaseInOutCubic:
// t = time / (tend / 2);
// if (t < 1) return (end - start) / 2 * t * t * t + start;
// t--;
// return (end - start) / 2 * (t * t * t * 2) + start;
// break;
case EaseInSine:
return -(end - start) * cos(time / tend * (M_PI / 2)) + (end - start) +
start;
break;
case EaseOutSine:
return (end - start) * sin(time / tend * (M_PI / 2)) + start;
break;
case EaseInOutSine:
return -(end - start) / 2 * (cos(M_PI * time / tend) - 1) + start;
break;
default: // Linear
return (end - start) * (time / tend) + start;
break;
}
}
private:
/** Animation Effect */
Effect effect;
/** Time */
float time = 0.f;
/**
* End time
* Defaulting to one to prevent div zero
* without a safetey check
* not implementing one cause if the user is
* Writing a In(0.f) its their fault
*/
float tend = 1.f;
/** Start value */
T start;
/** end value */
T end;
/** is finished value */
bool finished = false;
};
} // namespace PD

View File

@ -1,424 +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.
*/
// Why Creating this:
// Cause using makes coding much better structured
// and easy to use like in glsl or glm
#include <pd/core/common.hpp>
namespace PD {
struct vec2 {
// Init Funcs
vec2() {
v[0] = 0;
v[1] = 0;
}
vec2(float x, float y) {
v[0] = x;
v[1] = y;
}
vec2(const vec2 &i) {
v[0] = i[0];
v[1] = i[1];
}
vec2(float i) {
v[0] = i;
v[1] = i;
}
// Operations
// Add
vec2 &operator+=(const vec2 &i) {
v[0] += i[0];
v[1] += i[1];
return *this;
}
vec2 &operator+=(const float &i) {
v[0] += i;
v[1] += i;
return *this;
}
vec2 operator+(const vec2 &i) const { return vec2(v[0] + i[0], v[1] + i[1]); }
vec2 operator+(const float &i) const { return vec2(v[0] + i, v[1] + i); }
// Sub
vec2 &operator-=(const vec2 &i) {
v[0] -= i[0];
v[1] -= i[1];
return *this;
}
vec2 &operator-=(const float &i) {
v[0] -= i;
v[1] -= i;
return *this;
}
vec2 operator-(const vec2 &i) const { return vec2(v[0] - i[0], v[1] - i[1]); }
vec2 operator-(const float &i) const { return vec2(v[0] - i, v[1] - i); }
// Mul
vec2 &operator*=(const vec2 &i) {
v[0] *= i[0];
v[1] *= i[1];
return *this;
}
vec2 &operator*=(const float &i) {
v[0] *= i;
v[1] *= i;
return *this;
}
vec2 operator*(const vec2 &i) const { return vec2(v[0] * i[0], v[1] * i[1]); }
vec2 operator*(const float &i) const { return vec2(v[0] * i, v[1] * i); }
// Div
vec2 &operator/=(const vec2 &i) {
v[0] /= i[0];
v[1] /= i[1];
return *this;
}
vec2 &operator/=(const float &i) {
v[0] /= i;
v[1] /= i;
return *this;
}
vec2 operator/(const vec2 &i) const { return vec2(v[0] / i[0], v[1] / i[1]); }
vec2 operator/(const float &i) const { return vec2(v[0] / i, v[1] / i); }
// Compare
bool operator==(const vec2 &in) const {
return v[0] == in[0] && v[1] == in[1];
}
bool operator!=(const vec2 &in) const {
// use the first comparefuncs result
// and swap it lol
return !(*this == in);
}
vec2 operator-() const { return vec2(-v[0], -v[1]); }
float operator[](int i) const { return v[i]; }
float &operator[](int i) { return v[i]; }
float len() const { return sqrt(sqlen()); }
float sqlen() const { return v[0] * v[0] + v[1] * v[1]; }
float x() const { return v[0]; }
float &x() { return v[0]; }
float y() const { return v[1]; }
float &y() { return v[1]; }
// Internal Values
float v[2];
};
struct vec3 {
// Init Funcs
vec3() {
v[0] = 0.f;
v[1] = 0.f;
v[2] = 0.f;
}
vec3(float x, float y, float z) {
v[0] = x;
v[1] = y;
v[2] = z;
}
vec3(const vec3 &i) {
v[0] = i[0];
v[1] = i[1];
v[2] = i[2];
}
vec3(float i) {
v[0] = i;
v[1] = i;
v[2] = i;
}
//// PD REWRITE ADDITIONAL CONTENT ////
vec3(const vec2 &xy, float z) {
v[0] = xy[0];
v[1] = xy[1];
v[2] = z;
}
vec3(float x, const vec2 &yz) {
v[0] = x;
v[1] = yz[0];
v[2] = yz[1];
}
// Operations
// Add
vec3 &operator+=(const vec3 &i) {
v[0] += i[0];
v[1] += i[1];
v[2] += i[2];
return *this;
}
vec3 &operator+=(const float &i) {
v[0] += i;
v[1] += i;
v[2] += i;
return *this;
}
vec3 operator+(const vec3 &i) const {
return vec3(v[0] + i[0], v[1] + i[1], v[2] + i[2]);
}
vec3 operator+(const float &i) const {
return vec3(v[0] + i, v[1] + i, v[2] + i);
}
// Sub
vec3 &operator-=(const vec3 &i) {
v[0] -= i[0];
v[1] -= i[1];
v[2] -= i[2];
return *this;
}
vec3 &operator-=(const float &i) {
v[0] -= i;
v[1] -= i;
v[2] -= i;
return *this;
}
vec3 operator-(const vec3 &i) const {
return vec3(v[0] - i[0], v[1] - i[1], v[2] - i[2]);
}
vec3 operator-(const float &i) const {
return vec3(v[0] - i, v[1] - i, v[2] - i);
}
// Mul
vec3 &operator*=(const vec3 &i) {
v[0] *= i[0];
v[1] *= i[1];
v[2] *= i[2];
return *this;
}
vec3 &operator*=(const float &i) {
v[0] *= i;
v[1] *= i;
v[2] *= i;
return *this;
}
vec3 operator*(const vec3 &i) const {
return vec3(v[0] * i[0], v[1] * i[1], v[2] * i[2]);
}
vec3 operator*(const float &i) const {
return vec3(v[0] * i, v[1] * i, v[2] * i);
}
// Div
vec3 &operator/=(const vec3 &i) {
v[0] /= i[0];
v[1] /= i[1];
v[2] /= i[2];
return *this;
}
vec3 &operator/=(const float &i) {
v[0] /= i;
v[1] /= i;
v[2] /= i;
return *this;
}
vec3 operator/(const vec3 &i) const {
return vec3(v[0] / i[0], v[1] / i[1], v[2] / i[2]);
}
vec3 operator/(const float &i) const {
return vec3(v[0] / i, v[1] / i, v[2] / i);
}
// Compare
bool operator==(const vec3 &in) const {
return v[0] == in[0] && v[1] == in[1] && v[2] == v[2];
}
bool operator!=(const vec3 &in) const {
// use the first comparefuncs result
// and swap it lol
return !(*this == in);
}
// Base
vec3 operator-() const { return vec3(-v[0], -v[1], -v[2]); }
float operator[](int i) const { return v[i]; }
float &operator[](int i) { return v[i]; }
float len() const { return sqrt(sqlen()); }
float sqlen() const { return v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; }
float x() const { return v[0]; }
float &x() { return v[0]; }
float y() const { return v[1]; }
float &y() { return v[1]; }
float z() const { return v[2]; }
float &z() { return v[2]; }
//// PALLADIUM REWRITE ADDITIONAL CONTENT ////
vec2 xy() const { return vec2(v[0], v[1]); }
vec2 yz() const { return vec2(v[1], v[2]); }
float v[3];
};
struct vec4 {
// Init Funcs
vec4() {
v[0] = 0.f;
v[1] = 0.f;
v[2] = 0.f;
v[3] = 0.f;
}
vec4(float x, float y, float z, float w) {
v[0] = x;
v[1] = y;
v[2] = z;
v[3] = w;
}
vec4(const vec4 &i) {
v[0] = i[0];
v[1] = i[1];
v[2] = i[2];
v[3] = i[3];
}
vec4(const vec2 &i0, const vec2 &i1) {
v[0] = i0[0];
v[1] = i0[1];
v[2] = i1[0];
v[3] = i1[1];
}
vec4(float i) {
v[0] = i;
v[1] = i;
v[2] = i;
v[3] = i;
}
vec4(const vec3 &xyz, float w) {
v[0] = xyz[0];
v[1] = xyz[1];
v[2] = xyz[2];
v[3] = w;
}
vec4(float x, const vec3 &yzw) {
v[0] = x;
v[1] = yzw[1];
v[2] = yzw[2];
v[3] = yzw[3];
}
// Operators
// Add
vec4 &operator+=(const vec4 &i) {
v[0] += i[0];
v[1] += i[1];
v[2] += i[2];
v[3] += i[3];
return *this;
}
vec4 operator+(const vec4 &i) const {
return vec4(v[0] + i[0], v[1] + i[1], v[2] + i[2], v[3] + i[3]);
}
// Sub
vec4 &operator-=(const vec4 &i) {
v[0] -= i[0];
v[1] -= i[1];
v[2] -= i[2];
v[3] -= i[3];
return *this;
}
vec4 operator-(const vec4 &i) const {
return vec4(v[0] - i[0], v[1] - i[1], v[2] - i[2], v[3] - i[3]);
}
// Compare
bool operator==(const vec4 &in) const {
return v[0] == in[0] && v[1] == in[1] && v[2] == in[2] && v[3] == in[3];
}
bool operator!=(const vec4 &in) const {
// use the first comparefuncs result
// and swap it lol
return !(*this == in);
}
// Base
vec4 operator-() const { return vec4(-v[0], -v[1], -v[2], -v[3]); }
float operator[](int i) const { return v[i]; }
float &operator[](int i) { return v[i]; }
float len() const { return sqrt(sqlen()); }
float sqlen() const {
return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
}
// Vec Acess
float x() const { return v[0]; }
float &x() { return v[0]; }
float y() const { return v[1]; }
float &y() { return v[1]; }
float z() const { return v[2]; }
float &z() { return v[2]; }
float w() const { return v[3]; }
float &w() { return v[3]; }
vec2 xy() const { return vec2(v[0], v[1]); }
vec2 zw() const { return vec2(v[2], v[3]); }
vec3 xyz() const { return vec3(v[0], v[1], v[2]); }
vec3 yzw() const { return vec3(v[1], v[2], v[3]); }
// Quaternion Acess
float r() const { return v[0]; }
float &r() { return v[0]; }
float k() const { return v[1]; }
float &k() { return v[1]; }
float j() const { return v[2]; }
float &j() { return v[2]; }
float i() const { return v[3]; }
float &i() { return v[3]; }
vec2 rk() const { return vec2(v[0], v[1]); }
vec2 ji() const { return vec2(v[2], v[3]); }
vec3 rkj() const { return vec3(v[0], v[1], v[2]); }
vec3 kji() const { return vec3(v[1], v[2], v[3]); }
// Internal Values
float v[4];
};
} // namespace PD

View File

@ -1,172 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/vec.hpp>
namespace PD {
/** Input Driver Template class */
class Hid : public SmartCtor<Hid> {
public:
/** Key [Controller] */
enum Key : u32 {
No = 0, ///< No Key
A = 1 << 0, ///< A
B = 1 << 1, ///< B
X = 1 << 2, ///< X
Y = 1 << 3, ///< Y
Start = 1 << 4, ///< Start
Select = 1 << 5, ///< Select
L = 1 << 6, ///< L
R = 1 << 7, ///< R
DUp = 1 << 8, ///< Dpad Up
DDown = 1 << 9, ///< Dpad down
DLeft = 1 << 10, ///< Dpad left
DRight = 1 << 11, ///< Dpad right
CPUp = 1 << 12, ///< Cpad up
CPDown = 1 << 13, ///< cpad down
CPLeft = 1 << 14, ///< cpad left
CPRight = 1 << 15, ///< Cpad right
CSUp = 1 << 16, ///< Cstick up
CSDown = 1 << 17, ///< cstick down
CSLeft = 1 << 18, ///< cstick left
CSRight = 1 << 19, ///< cstick right
ZL = 1 << 20, ///< ZL
ZR = 1 << 21, ///< ZR
Touch = 1 << 22, ///< Touch
Up = DUp | CPUp, ///< DPad or CPad Up
Down = DDown | CPDown, ///< DPad or CPad Down
Left = DLeft | CPLeft, ///< DPad or CPad Left
Right = DRight | CPRight, ///< DPad or CPad Right
};
/** Event */
enum Event {
Event_Down, ///< Key Pressed
Event_Held, ///< Key Held
Event_Up, ///< Key released
};
Hid() = default;
~Hid() = default;
/**
* Get TOuch Position
* @return touch pos
*/
vec2 TouchPos() const { return touch[0]; }
/**
* Get Last Touch Position (from last frame)
* @return touch pos
*/
vec2 TouchPosLast() const { return touch[1]; }
/**
* Check for a Button Event
* @param e Event Type
* @param keys Keys to check for
* @return if key(s) doing the requiested event
*/
bool IsEvent(Event e, Key keys);
/**
* Check for Key Press Event
* @param keys set of keys
* @return true if key is pressed
*/
bool IsDown(Key keys) const { return key_events[0].at(Event_Down) & keys; }
/**
* Check for Key Held Event
* @param keys set of keys
* @return true if key is held
*/
bool IsHeld(Key keys) const { return key_events[0].at(Event_Held) & keys; }
/**
* Check for Key Release Event
* @param keys set of keys
* @return true if key is released
*/
bool IsUp(Key keys) const { return key_events[0].at(Event_Up) & keys; }
/**
* Sett all keyevents to 0
*/
void Clear() {
for (int i = 0; i < 2; i++) {
key_events[i][Event_Down] = 0;
key_events[i][Event_Up] = 0;
key_events[i][Event_Held] = 0;
}
}
/**
* Lock input driver
* @param v lock or not lock
*/
void Lock(bool v) {
if (v != locked) {
SwappyTable();
}
locked = v;
}
/**
* Check if Driver is locked
* @return true if locked
*/
bool Locked() const { return locked; }
/**
* Lock Input Driver
*/
void Lock() {
if (!locked) {
SwappyTable();
}
locked = true;
}
/**
* Unlock Input Driver
*/
void Unlock() {
if (locked) {
SwappyTable();
}
locked = false;
}
/**
* Template Update Function for a device specific driver
*/
virtual void Update() {}
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 */
vec2 touch[2];
/** locked state */
bool locked = false;
/** Key event tables */
std::unordered_map<Event, u32> key_events[2];
};
} // namespace PD

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

2054
include/pd/external/stb_image_write.h vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

78
include/pd/global_db.hpp Normal file
View File

@ -0,0 +1,78 @@
#pragma once
#include <pd/external/json.hpp>
#include <pd/palladium.hpp>
namespace Palladium {
namespace IDB {
void Start();
void Stop();
void Restart();
} // namespace IDB
} // namespace Palladium
using PDFlags = unsigned int;
enum PDFlags_ {
PDFlags_None = 0,
PDFlags_MemTrack = 1 << 0,
PDFlags_SceneSystem = 1 << 1,
PDFlags_Default = PDFlags_SceneSystem,
};
using PDMetrikOverlayFlags = unsigned int;
enum PDMetrikOverlayFlags_ {
PDMetrikOverlayFlags_None = 0, // Displays Nothing
PDMetrikOverlayFlags_FPS = 1 << 0, // Display FPS
PDMetrikOverlayFlags_CPU = 1 << 1, // Display CPU Usage
PDMetrikOverlayFlags_GPU = 1 << 2, // Display GPU Usage
PDMetrikOverlayFlags_CMD = 1 << 3, // Display GPU CMD Usage
PDMetrikOverlayFlags_LMM = 1 << 4, // Display Linear Space Free
PDMetrikOverlayFlags_LVT = 1 << 5, // Display Lithium Vertex Usage
PDMetrikOverlayFlags_LID = 1 << 6, // Display Lithium Indices Usage
PDMetrikOverlayFlags_LDM = 1 << 7, // Display Lithium Draw Command Num
PDMetrikOverlayFlags_LDC = 1 << 8, // Display Lithium Drawcalls Count
PDMetrikOverlayFlags_PDO = 1 << 9, // Display Overlay Info String
PDMetrikOverlayFlags_MTD = 1 << 10, // Display Memory Usage (if enabled)
PDMetrikOverlayFlags_CGR = 1 << 11, // Display CPU Graph
PDMetrikOverlayFlags_GGR = 1 << 12, // Display GPU Graph
PDMetrikOverlayFlags_Default =
PDMetrikOverlayFlags_FPS | PDMetrikOverlayFlags_CPU |
PDMetrikOverlayFlags_GPU | PDMetrikOverlayFlags_CMD |
PDMetrikOverlayFlags_LMM | PDMetrikOverlayFlags_LVT |
PDMetrikOverlayFlags_LID | PDMetrikOverlayFlags_LDM |
PDMetrikOverlayFlags_LDC | PDMetrikOverlayFlags_PDO |
PDMetrikOverlayFlags_MTD, // Enable All of Them exept Graphs
};
using PDFTraceOverlayFlags = unsigned int;
enum PDFTraceOverlayFlags_ {
PDFTraceOverlayFlags_None = 0, // Displays Nothing
PDFTraceOverlayFlags_DisplayName = 1 << 0, // Display Tracename
PDFTraceOverlayFlags_DisplayAverage = 1 << 1, // Display Average Time
PDFTraceOverlayFlags_DisplayMin = 1 << 2, // Display Minimum Time
PDFTraceOverlayFlags_DisplayMax = 1 << 3, // Display Maximum Time
PDFTraceOverlayFlags_FillBg = 1 << 4, // Make Background Darker
PDFTraceOverlayFlags_DisplayHelp = 1 << 5, // Display Info for values
PDFTraceOverlayFlags_Default =
PDFTraceOverlayFlags_DisplayName | PDFTraceOverlayFlags_DisplayAverage |
PDFTraceOverlayFlags_DisplayMin | PDFTraceOverlayFlags_DisplayMax |
PDFTraceOverlayFlags_FillBg |
PDFTraceOverlayFlags_DisplayHelp, // Enable All of Them
};
// Outdated HidApi (HidV2Patched)
extern u32 d7_hDown;
extern u32 d7_hHeld;
extern u32 d7_hUp;
extern u32 d7_hRepeat; // Inofficial lol
extern touchPosition d7_touch;
// Modern Global Api
extern C3D_RenderTarget *pd_top;
extern C3D_RenderTarget *pd_top_right;
extern C3D_RenderTarget *pd_bottom;
extern PDFlags pd_flags;
extern PDMetrikOverlayFlags pd_ovl_flags;
extern PDFTraceOverlayFlags pd_ftrace_ovl_flags;
// Draw2
extern float pd_draw2_tsm;

View File

@ -1,64 +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/common.hpp>
namespace PD {
class Image {
public:
Image() = default;
Image(const std::string& path) { this->Load(path); }
Image(const std::vector<u8>& buf) { this->Load(buf); }
Image(const std::vector<u8>& buf, int w, int h, int fmt = 4) {
this->Copy(buf, w, h, fmt);
}
~Image() = default;
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 fmt = 4);
std::vector<u8>& GetBuffer() { return buffer; }
std::vector<u8> GetBuffer() const { return buffer; }
int Width() const { return w; }
int Height() const { return h; }
u8& operator[](int idx) { return buffer[idx]; }
u8 operator[](int idx) const { return buffer[idx]; }
// Probably these make th eabove ones useless
operator std::vector<u8>&() { return buffer; }
operator std::vector<u8>() const { return buffer; }
private:
std::vector<u8> buffer;
int w = 0;
int h = 0;
int fmt = 0;
};
} // namespace PD

View File

@ -1,72 +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/common.hpp>
#include <pd/core/vec.hpp>
namespace PD {
/**
* Namepace containing functions to blur images
*/
namespace ImgBlur {
/**
* Function to create Gaussian Kernel List
* @param radius Rasius to use
* @param si sigma value to use
* @return list of kernel values
*/
std::vector<float> GaussianKernel(int radius, float si);
/**
* Gaussian Blur for basic Image Buffer
* @param buf Image Buffer (unsigned char)
* @param w width of the image
* @param h width of the image
* @param radius Blur radius
* @param si Blur sigma
* @param idxfn Indexing function
*/
void GaussianBlur(
std::vector<u8> &buf, int w, int h, float radius, float si,
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
return y * w + x;
});
/**
* Advanced func to access memory directly
* @param buf Referenvce to the buffer
* @param w width of the image
* @param h width of the image
* @param bpp Bytes per Pixels (RGB[A], RGB565, etc)
* @param radius Blur radius
* @param si Blur sigma
* @param idxfn Indexing function
*/
void GaussianBlur(
void *buf, int w, int h, int bpp, float radius, float si,
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
return y * w + x;
});
} // namespace ImgBlur
} // 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.
*/
#include <pd/core/common.hpp>
namespace PD {
/**
* Namespace containing function to convert images
*/
namespace ImgConvert {
/**
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
* to every pixel
* @param out Result List
* @param in Input Buffer List (rgb24)
* @param w width of the image
* @param h height of the image
*/
void RGB24toRGBA32(std::vector<u8> &out, const std::vector<u8> &in,
const int &w, const int &h);
/**
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
* @param buf Buffer to convert
* @param w width
* @param h height
*/
void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
} // namespace ImgConvert
} // namespace PD

View File

@ -0,0 +1,64 @@
#pragma once
#include <pd/Net.hpp>
#include <pd/external/json.hpp>
#include <pd/global_db.hpp>
#include <pd/palladium.hpp>
#define CFGVER "2"
#define THEMEVER "0"
#ifndef V_PDBTIME
#define V_PDBTIME "SUBMODULE"
#endif
#ifndef V_PDCSTRING
#define V_PDCSTRING "SUBMODULE"
#endif
// Base
extern bool pdi_enable_scene_system;
extern bool pdi_debugging;
extern bool pdi_enable_memtrack;
extern std::string pdi_app_name;
extern std::string pdi_config_path;
extern nlohmann::json pdi_config;
extern u8 pdi_console_model;
extern u8 pdi_system_region;
extern bool pdi_is_citra;
extern bool pdi_settings;
extern NVec2 pdi_hid_touch_pos;
extern bool pdi_is_ndsp;
extern bool pdi_running;
extern std::unique_ptr<Palladium::Scene> pdi_fade_scene;
extern std::vector<std::unique_ptr<Palladium::Ovl>> pdi_overlays;
extern unsigned int pdi_frames;
extern u64 pdi_last_time;
extern float pdi_framerate;
extern unsigned int pdi_mt_color;
extern unsigned int pdi_mt_txtcolor;
extern bool pdi_mt_screen;
extern float pdi_mt_txtSize;
extern bool pdi_metrikd;
extern bool pdi_ftraced;
extern u64 pdi_delta_time;
extern u64 pdi_last_tm;
extern float pdi_dtm;
extern float pdi_time;
extern bool pdi_fadeout;
extern bool pdi_fadein;
extern bool pdi_fadeout2;
extern bool pdi_fadein2;
extern int pdi_fadealpha;
extern int pdi_fadecolor;
extern bool pdi_wait_fade;
extern bool pdi_fade_exit;
extern bool pdi_fade_scene_wait;
extern bool pdi_idb_running;
extern bool pdi_graphics_on;
extern bool pdi_amdt;
extern void* pdi_soc_buf;
extern bool pdi_is_am_init;
extern Palladium::Theme::Ref pdi_active_theme;
extern bool pdi_lggrf;
Palladium::Net::Error pdi_soc_init();
void pdi_soc_deinit();

View File

@ -0,0 +1,8 @@
// THIS FILE WAS GENERATED BY build_shaders.py!!!
#pragma once
#include <cstddef>
extern unsigned char li7_shader[];
extern size_t li7_shader_size;

View File

@ -1,45 +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/drivers/hid.hpp>
namespace PD {
/**
* Nintendo 3DS Input Driver
*/
class CtrHid : public Hid {
public:
/**
* Constructor to setup Key binds
*/
CtrHid();
~CtrHid() = default;
/**
* Overrideing the Update Function for Input Checking etc
*/
void Update() override;
};
} // namespace PD

View File

@ -1,73 +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/drivers/hid.hpp>
namespace PD {
/**
* Simple Table Containing the codepoint references
* for the Controller Icons on the 3ds
*/
namespace GamePadIcons {
/**
* Icon ID
*/
enum ID {
A,
B,
X,
Y,
L,
R,
Dpad,
Start,
Select,
Home,
Steps,
PlayCoin,
AnalogStick,
Power3DS,
DpadUp,
DpadDown,
DpadLeft,
DpadRight,
DpadHorizontal,
DpadVertical,
};
/**
* Get Icon by ID
* @param id ID to Get
* @return codepoint
*/
std::string GetIcon(ID id);
/**
* Get Icon By Input Driver Key
* @param key Key to find
* @return codepoint
*/
std::string GetIcon(Hid::Key key);
} // namespace GamePadIcons
} // namespace PD

View File

@ -1,57 +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 {
/**
* static Namespace containing Access to some 3ds Hardware Info
*/
namespace HwInfo {
/**
* Init connecttion to required sys modules
*/
void Init();
/**
* Deinit connection to sys modules
*/
void Deinit();
/**
* Check if the Console is Charging
* @return true if the console is charging
*/
bool IsCharging();
/**
* Get the Current Battery Percentage
* @return Battery Percentage (from 0 to 100)
*/
int GetBatteryPercentage();
/**
* Get Current Wifi Level
* @return wifi level (0 to 4)
*/
int GetWifiLevel();
} // namespace HwInfo
} // namespace PD

View File

@ -1,71 +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 <3ds.h>
#include <pd/app/error.hpp>
#include <pd/core/common.hpp>
namespace PD {
/**
* Custom C++ Allocator for 3DS linear Memory
* Used for Everything that has to do with Rendering or sound
* Dont going into that much detail here
*
* Example:
* ```cpp
* // Index Buffer for Rendering using Linear Allocator
* std::vector<u16, PD::LinearAllocator<u16>> index_buf;
* ```
*/
template <typename T>
class LinearAllocator : public std::allocator<T> {
public:
using size_type = size_t;
using pointer = T*;
using const_pointer = const T*;
template <typename T1>
struct rebind {
using other = LinearAllocator<T1>;
};
pointer allocate(size_type n, const void* hint = nullptr) {
if (n > this->max_size()) {
Error("Linear Alloc failed (no space left)");
return nullptr;
}
return (pointer)linearAlloc(n * sizeof(T));
}
void deallocate(pointer p, size_type) { linearFree((void*)p); }
size_type max_size() { return linearSpaceFree(); }
LinearAllocator() noexcept {}
LinearAllocator(const LinearAllocator<T>& a) noexcept
: std::allocator<T>(a) {}
~LinearAllocator() noexcept {}
};
} // namespace PD

View File

@ -1,40 +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 to Everything that has to
* do with the 3ds (very empty currently)
*/
namespace Ctr {
/**
* Get the System Language key (for lang system)
* @return language key
*/
std::string GetSystemLanguage();
} // namespace Ctr
} // namespace PD

View File

@ -1,36 +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 <pd/core/common.hpp>
#include <pd/core/markdown.hpp>
namespace PD {
class ResultDecoder {
public:
ResultDecoder(Result res);
};
} // namespace PD

View File

@ -1,215 +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/common.hpp>
#include <pd/core/vec.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> {
public:
Command() = default;
~Command() = default;
/**
* Copy Constructor [to Copy the Data of a Command Reference]
*/
Command(Command::Ref v) {
this->index = v->index;
this->index_buf = v->index_buf;
this->layer = v->layer;
this->mode = v->mode;
this->tex = v->tex;
this->vertex_buf = v->vertex_buf;
}
/**
* Setter for the Commands layer
* @param v layer value
* @return command reference
*/
Command& Layer(int v) {
layer = v;
return *this;
}
/**
* Getter for the Layer
* @return layer value
*/
int Layer() const { return layer; }
/**
* Setter for the Commands Index [used in sorting]
* @param v index value
* @return command reference
*/
Command& Index(int v) {
index = v;
return *this;
}
/**
* Getter for the Index
* @return index value
*/
int Index() const { return index; }
/**
* Setter for the Commands Texture
* @param v Texture reference
* @return command reference
*/
Command& Tex(Texture::Ref v) {
tex = v;
return *this;
}
/**
* Getter for the Texture reference
* @return Texture reference
*/
Texture::Ref Tex() const { return tex; }
/**
* Function to Push a Vertex to the vertexbuffer
* @param v Vertex to push
* @return command reference
*/
Command& PushVertex(const Vertex& v) {
vertex_buf.push_back(v);
return *this;
}
/**
* Access to the Index list [used to write index data
* to the real indexbuffer]
* @return const reference to commands idx buffer
*/
const std::vector<u16>& IndexList() const { return index_buf; }
/**
* Access to the Vertex list [used to write vertices
* data to the real vertexbuffer]
* @return const reference to commands vertex buffer
*/
const std::vector<Vertex>& VertexList() const { return vertex_buf; }
// ADVANCED
/**
* Advanced function to access index list
*
* - This function is UNSAFE to use cause it allows to modify index data
* @return reference to index list
*/
std::vector<u16>& IndexList() { return index_buf; }
/**
* Advanced function to access vertex list
*
* - This function is UNSAFE to use cause it allows to modify index data
* - Using this in StaticText to change Position color and stuff after it is
* rendered into commands
* @return reference to vertex list
*/
std::vector<Vertex>& VertexList() { return vertex_buf; }
/**
* Function to Push an index value to indexbuffer
* @param v Index value
* @return command reference
*/
Command& PushIndex(u16 v) {
index_buf.push_back(vertex_buf.size() + v);
return *this;
}
/**
* Setter for the Commands RenderMode
* @param v RenderMode
* @return command reference
*/
Command& Rendermode(const RenderMode& v) {
mode = v;
return *this;
}
/**
* Getter for the Commands RenderMode
* @return RenderMode
*/
RenderMode Rendermode() const { return mode; }
/** Setter for Scissor Mode */
Command& SetScissorMode(ScissorMode mode) {
scissor = mode;
return *this;
}
/** Getter for Scissor Mode */
ScissorMode GetScissorMode() const { return scissor; }
/** Setter for Scissor Area */
Command& ScissorRect(const vec4& v) {
scissor_area = v;
return *this;
}
/** Getter for Scissor Area */
vec4 ScissorRect() const { return scissor_area; }
private:
/**
* Vertex Buffer
*
* - Using default vector here as its data will be copied later
*/
std::vector<Vertex> vertex_buf;
/**
* Index Buffer
*
* - Using default vector here as its data will be copied later
*/
std::vector<u16> index_buf;
/** Layer */
int layer;
/** Texture Reference */
Texture::Ref tex;
/** Index */
int index;
/** RenderMode (Default to RenderMode_RGBA) */
RenderMode mode = RenderMode_RGBA;
/** Scissor Mode (for defined area to render) */
ScissorMode scissor = ScissorMode_None;
/** scissor box (top left and bottom right) */
vec4 scissor_area;
};
} // namespace LI
} // namespace PD

View File

@ -1,71 +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/common.hpp>
/** Alias for Lithium Text Flags */
using LITextFlags = PD::u32;
/** LITextFlags */
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]
LITextFlags_RenderOOS = 1 << 6 ///< Render Out of Screen
};
/** Aliad for Lithium Render Flags */
using LIRenderFlags = PD::u32;
/** LIRenderFlags */
enum LIRenderFlags_ {
LIRenderFlags_None = 0, ///< Nothing
LIRenderFlags_TMS = 1 << 0, ///< Text Map System
LIRenderFlags_LRS = 1 << 1, ///< Layer Render System
LIRenderFlags_AST = 1 << 2, ///< Auto Static Text
/** Default Enables all of them */
LIRenderFlags_Default =
LIRenderFlags_TMS | LIRenderFlags_LRS | LIRenderFlags_AST,
};
namespace PD {
namespace LI {
/** RenderMode [Required to modify TexENV] */
enum RenderMode {
RenderMode_RGBA, ///< RGBA [for textures or solid colors]
RenderMode_Font, ///< A8 [for textures only crated by 1 color channel]
};
/** Scissor Mode (for ClipRect related rendering) */
enum ScissorMode {
ScissorMode_None = 0, ///< No Scissor
ScissorMode_Inverted = 1, ///< Render Pixels outside the box
ScissorMode_Normal = 3, ///< Only render pixels inside the box
};
} // namespace LI
} // namespace PD

View File

@ -1,181 +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/common.hpp>
#include <pd/core/vec.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/texture.hpp>
namespace PD {
namespace LI {
/** Font Loader for Lithium */
class Font : public SmartCtor<Font> {
public:
/** Codepoint Data holder */
class Codepoint {
public:
Codepoint() = default;
~Codepoint() = default;
/**
* Codepoint ID Getter
* @return 32Bit codepoint value
*/
u32 cp() const { return m_cp; }
/**
* Codepoint ID Setter
* @param v codepoint id
* @return DataHolder reference
*/
Codepoint& cp(u32 v) {
m_cp = v;
return *this;
}
/**
* Getter for the UV Coords
* @return uv coords
*/
vec4 uv() const { return m_uv; }
/**
* Setter for the UV Coords
* @param v uv coords
* @return DataHolder Reference
*/
Codepoint& uv(const vec4& v) {
m_uv = v;
return *this;
}
/**
* Getter for the Texture reference
* @return Texture Reference
*/
Texture::Ref tex() const { return m_tex; }
/**
* Setter for the Texture Reference
* @param v Texture Reference
* @return DataHolder Reference
*/
Codepoint& tex(Texture::Ref v) {
m_tex = v;
return *this;
}
/**
* Getter for the size
* @return Size
*/
vec2 size() const { return m_size; }
/**
* Setter for the Size
* @param v size
* @return DataHolder Reference
*/
Codepoint& size(const vec2& v) {
m_size = v;
return *this;
}
/**
* Getter for the Position offset
* @return offset
*/
float off() const { return m_off; }
/**
* Setter for the Render Offset
* @param v offset
* @return DataHolder Reference
*/
Codepoint& off(float v) {
m_off = v;
return *this;
}
/**
* Getter to check if Codepoint is invalid
* @return true if invalid
*/
bool invalid() const { return m_invalid; }
/**
* Setter for invald state
* @param v true or false
* @return DataHolder Reference
*/
Codepoint& invalid(bool v) {
m_invalid = v;
return *this;
}
private:
/** 32Bit Codepoint ID */
u32 m_cp = 0;
/** UvMap */
vec4 m_uv;
/** Texture Reference */
Texture::Ref m_tex = nullptr;
/** Codepoint Size */
vec2 m_size;
/** Render Position Offset */
float m_off = 0;
/** Invalid check (for skip in renderer) */
bool m_invalid = false;
};
Font() = default;
~Font() = default;
/**
* Load a TTF File
* @param path Path to the TTF file
* @param px_height Pixelheight of the codepoints (limit by 64)
*/
void LoadTTF(const std::string& path, int px_height = 32);
/**
* Load 3DS System Font
*/
void LoadSystemFont();
/**
* Getter for PixelHeight
* @return pixelheigt
*/
int PixelHeight() const { return pixel_height; }
/**
* Getter for Codepoint reference
* @return codepoint dataholder reference
*/
Codepoint& GetCodepoint(u32 c);
/**
* Check if Systemfont is used
* @return true if is system font
*/
bool SystemFont() const { return sysfont; }
private:
/** sysfont set to true if LoadSystemFont got called */
bool sysfont;
/** Pixelheight */
int pixel_height;
/** List of textures (codepoints are using) */
std::vector<Texture::Ref> textures;
/** 32Bit Codepoint Dataholder Reference Map */
std::map<u32, Codepoint> cpmap;
};
} // namespace LI
} // namespace PD

View File

@ -1,31 +0,0 @@
// THIS FILE WAS GENERATED BY build_shaders.py!!!
#pragma once
/*
MIT License
Copyright (c) 2024 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 <cstddef>
extern unsigned char li7_shader[];
extern size_t li7_shader_size;

View File

@ -1,349 +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/common.hpp>
#include <pd/core/vec.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/flags.hpp>
#include <pd/lithium/font.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/lithium/vertex.hpp>
namespace PD {
namespace LI {
class Renderer;
/**
* Prerendered Object that can be edidet at runtime
* and supports diffrent textures as well
*/
class StaticObject : public SmartCtor<StaticObject> {
public:
StaticObject() = default;
~StaticObject() = default;
/**
* Push a Draw Command to the Static Object
* @param v Command to add
*/
void PushCommand(Command::Ref v) { cmds.push_back(v); }
/**
* Copy the root Object to a copy buffer for modification
*/
void ReCopy() {
cpy.clear();
for (auto it : cmds) {
cpy.push_back(Command::New(it));
}
}
/**
* Modify the Color of a specific Command in the List
* @param idx Index of the Command
* @param col new COlor to replace with
*/
void ReColorQuad(int idx, u32 col) {
if (idx > (int)cpy.size()) {
return;
}
for (auto& it : cpy[idx]->VertexList()) {
it.Color(col);
}
}
/**
* Move the every Command in the Object by a specific offset
* @param off offset position to apply
*/
void MoveIt(vec2 off) {
for (auto& it : cpy) {
for (auto& jt : it->VertexList()) {
jt.pos += off;
}
}
}
/**
* Change Color of all Commands in the List
* @param col new Color to use
*/
void ReColor(u32 col) {
for (auto& it : cpy) {
for (auto& jt : it->VertexList()) {
jt.Color(col);
}
}
}
/**
* Assign a New Layer to all Objects
* @param layer new layer to set to all its commands
*/
void ReLayer(int layer) {
for (auto& it : cpy) {
it->Layer(layer);
}
}
/**
* Change the Commands Index by setting a start index
* @param start Start index position
*/
void ReIndex(int start) {
for (int i = 0; i < (int)cpy.size(); i++) {
cpy[i]->Index(start + i);
}
}
/**
* Set a Custom Scissor Mode for Object Copy List
* @param m New Mode to Set
*/
void ReSetScissorMode(ScissorMode m) {
for (auto& i : cpy) {
i->SetScissorMode(m);
}
}
/**
* Set Custom Scissor Rect to All Objects
* @param v Scissor Rect to set
*/
void ReScissorRect(const vec4& v) {
for (auto& i : cpy) {
i->ScissorRect(v);
}
}
/**
* Get a Reference to the Copy Commands List
* @return command list reference
*/
std::vector<Command::Ref>& List() {
if (cpy.size() != 0) {
return cpy;
}
return cmds;
}
private:
/** Copy Buffer */
std::vector<Command::Ref> cpy;
/** Source Buffer */
std::vector<Command::Ref> cmds;
};
/**
* Text Box container for TMS and AST
*/
class TextBox {
public:
TextBox() = default;
/**
* Baisc Constructor
* @param s Size of the text
* @param time creation time
*/
TextBox(const vec2& s, float time) {
size = s;
time_created = time;
optional = false;
}
~TextBox() = default;
/**
* Setter for Time created
* @param v time
*/
void TimeCreated(float v) { time_created = v; }
/**
* Setter for Size
* @param v size
*/
void Size(const vec2& v) { size = v; }
/**
* Setter for is optional
*
* - optional text contains the result string of wrap/short
* @param v optional
*/
void Optional(bool v) { optional = v; }
/**
* set Result of Short Text or Wrap Text
* @param v text
*/
void Text(const std::string& v) { text = v; }
/**
* Get Size
* @return size
*/
vec2 Size() const { return size; }
/**
* Get Time Created / Updated
* @param time created/updated
*/
float TimeCreated() const { return time_created; }
/**
* Check if Optional or not
* @return is optional
*/
bool Optional() const { return optional; }
/**
* Get Optional Text
* @return text
*/
std::string Text() const { return text; }
private:
/** Text Size */
vec2 size;
/** Time Created / Updated */
float time_created;
/** Is Optional */
bool optional;
/** Text Wrap / Short */
std::string text;
};
/**
* Static Text [abillity to Prerender Texts into a list of Commands]
*/
class StaticText : public SmartCtor<StaticText> {
public:
StaticText() = default;
/**
* Wrap Constructor to Setup
* @param ren Renderer direct pointer reference
* @param pos Position
* @param clr Color
* @param text Text to Render
* @param flags Text Flags
* @param box Additional textbox for specific flags
*/
StaticText(Renderer* ren, const vec2& pos, u32 clr, const std::string& text,
LITextFlags flags = 0, const vec2& box = 0) {
Setup(ren, pos, clr, text, flags, box);
}
~StaticText() = default;
/**
* Function that Sets Up the Rendering
* @param ren Renderer direct pointer reference
* @param pos Position
* @param clr Color
* @param text Text to Render
* @param flags Text Flags
* @param box Additional textbox for specific flags
*/
void Setup(Renderer* ren, const vec2& pos, u32 clr, const std::string& text,
LITextFlags flags = 0, const vec2& box = 0);
/**
* Get Text Size
* @return size
*/
vec2 GetDim() const { return tdim; }
/**
* Get Text Posiotion
* @return position
*/
vec2 GetPos() const { return pos; }
/**
* Setter to Update Color
* @param col color
*/
void SetColor(u32 col);
/**
* Setter to raplace the texts Commands Position
* @param pos new position
*/
void SetPos(const vec2& pos);
/**
* Set Layer of the Text
* @param l layer
*/
void SetLayer(int l);
/**
* Function to unset the used variable
*/
void SetUnused() { used = false; }
/**
* Function to check if the text got rendered
* @return is used
*/
bool Used() const { return used; }
/**
* Function to check if the text got setup
* @return is setup
*/
bool IsSetup() { return text != nullptr; }
/**
* Draw the Text
*/
void Draw();
/** Get the Raw Object for Custom API's */
StaticObject::Ref GetRawObject() { return text; }
/**
* Set Font used by the static Text
* @param fnt Font used
*/
void Font(Font::Ref fnt) { font = fnt; }
/**
* Get Font used by the Text
* @return Font Reference
*/
Font::Ref Font() { return font; }
/**
* Set a Custom Scissor Mode Static Text
* @param m New Mode to Set
*/
void SetScissorMode(ScissorMode m) { text->ReSetScissorMode(m); }
/**
* Set Custom Scissor Rect to Static Text
* @param v Scissor Rect to set
*/
void ScissorRect(const vec4& v) { text->ReScissorRect(v); }
private:
/** Font */
Font::Ref font;
/** Text got Rendered */
bool used;
/** Renderer pointer Reference */
Renderer* ren;
/** Text Size */
vec2 tdim;
/** Text Position */
vec2 pos;
/** Static Text Object */
StaticObject::Ref text;
};
} // namespace LI
} // namespace PD

View File

@ -1,197 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/vec.hpp>
namespace PD {
namespace LI {
/**
* Container that holds position of a rectangle's corners.
*/
class Rect {
public:
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 vec4& t, const vec4& b) {
top = t;
bot = b;
}
/**
* Constructor that initializes the rectangle using individual corner
* positions.
* @param tl Top left corner position.
* @param tr Top right corner position.
* @param bl Bottom left corner position.
* @param br Bottom right corner position.
*/
Rect(const vec2& tl, const vec2& tr, const vec2& bl, const vec2& br) {
top = vec4(tl, tr);
bot = vec4(bl, br);
}
/**
* Constructor that initializes the rectangle using a UV mapping vector.
*
* - The old API used vec4 for UV mapping.
* - Spritesheets have rotated images, so this was updated to use Rect for UV.
*
* @param uv Vec4 UV map.
*/
Rect(const vec4& 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.
*/
vec4 Top() const { return top; }
/**
* Get the bottom left and right corner positions.
* @return Bottom positions.
*/
vec4 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 vec4& 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 vec4& v) {
bot = v;
return *this;
}
/**
* Get the top-left corner position.
* @return Top-left position as vec2.
*/
vec2 TopLeft() const { return vec2(top[0], top[1]); }
/**
* Get the top-right corner position.
* @return Top-right position as vec2.
*/
vec2 TopRight() const { return vec2(top[2], top[3]); }
/**
* Get the bottom-left corner position.
* @return Bottom-left position as vec2.
*/
vec2 BotLeft() const { return vec2(bot[0], bot[1]); }
/**
* Get the bottom-right corner position.
* @return Bottom-right position as vec2.
*/
vec2 BotRight() const { return vec2(bot[2], bot[3]); }
/**
* Set the top-left corner position.
* @param v New top-left position.
* @return Reference to the updated Rect.
*/
Rect& TopLeft(const vec2& v) {
top[0] = v[0];
top[1] = v[1];
return *this;
}
/**
* Set the top-right corner position.
* @param v New top-right position.
* @return Reference to the updated Rect.
*/
Rect& TopRight(const vec2& v) {
top[2] = v[0];
top[3] = v[1];
return *this;
}
/**
* Set the bottom-left corner position.
* @param v New bottom-left position.
* @return Reference to the updated Rect.
*/
Rect& BotLeft(const vec2& v) {
bot[0] = v[0];
bot[1] = v[1];
return *this;
}
/**
* Set the bottom-right corner position.
* @param v New bottom-right position.
* @return Reference to the updated Rect.
*/
Rect& BotRight(const vec2& v) {
bot[2] = v[0];
bot[3] = v[1];
return *this;
}
/**
* Swap X and Y coordinates for all corners.
*
* - Used in SpiteSheet for the rotated images.
*/
void SwapVec2XY() {
for (int i = 0; i < 4; i += 2) {
float t = top[i];
top[i] = top[i + 1];
top[i + 1] = t;
t = bot[i];
bot[i] = bot[i + 1];
bot[i + 1] = t;
}
}
private:
vec4 top; ///< Top left and right corner positions.
vec4 bot; ///< Bottom left and right corner positions.
};
} // namespace LI
} // namespace PD

View File

@ -1,382 +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/common.hpp>
#include <pd/core/vec.hpp>
#include <pd/lib3ds/memory.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/flags.hpp>
#include <pd/lithium/font.hpp>
#include <pd/lithium/objects.hpp>
#include <pd/lithium/screen.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/lithium/vertex.hpp>
namespace PD {
namespace LI {
/**
* Lithium base renderer Class.
*/
class Renderer : public SmartCtor<Renderer> {
public:
/**
* Constructor setting up the 2d Rendering Engine
* @param flags Flags to use [can be changed at runtime].
*/
Renderer(LIRenderFlags flags = LIRenderFlags_Default);
/**
* Deconstructor that unloads all the renderer data
*/
~Renderer();
/**
* Prepare render stage for rendering.
*/
void PrepareRender();
/**
* Render a screens Command list.
* @param s Screen to Draw its list on.
*/
void Render(Screen::Ref s);
/**
* Finalize rendering stage.
*/
void FinalizeRender();
/**
* Register Screens (For UI7, probably move this).
* @param bottom set if you register bottom ot top screen.
* @param s Screen to register.
*/
void RegisterScreen(bool bottom, Screen::Ref s) { screens[bottom] = s; }
/**
* Set the Screen next commands will be add to
* @param s Screen of choice
*/
void OnScreen(Screen::Ref s) {
if (!s) {
return;
}
this->screen = s;
area_size = screen->GetSize();
}
/**
* Get cobst reference to active screen.
* @return current screen.
*/
Screen::Ref CurrentScreen() const { return screen; }
/**
* Get Screen of screen regestry.
* @param bottom bottom ot top screen.
* @return screen reference
*/
Screen::Ref GetScreen(bool bottom) {
auto res = screens[bottom];
Assert(res.get(), "Screen is not registered!");
return res;
}
void Rotation(float v) { rot = v; }
float Rotation() const { return rot; }
void TextScale(float v) { text_size = v; }
void DefaultTextScale() { text_size = default_text_size; }
float TextScale() const { return text_size; }
void Layer(int v) { current_layer = v; }
int Layer() const { return current_layer; }
LIRenderFlags& GetFlags() { return flags; }
void Font(Font::Ref v) {
font = v;
font_update = true;
}
Font::Ref Font() const { return font; }
/**
* Use a specific Texture for Next Rectangle.
* @param v texture reference to use.
*/
void UseTex(Texture::Ref v = nullptr) {
if (v == nullptr) {
current_tex = white;
return;
}
current_tex = v;
}
/**
* Draws a Rect based on current Texture
* @param pos Position of the Rect
* @param size Size of the Rect
* @param color Color of the Rect [0xffffffff]
* for full visible texture
* @param uv UV Map (if texture needs a custom uv)
* @note This function is part of Simple Draw API.
*/
void DrawRect(const vec2& pos, const vec2& size, u32 color,
const Rect& uv = vec4(0.f, 1.f, 1.f, 0.f));
/**
* Draw a Solid Rect (uses white tex)
* @note
* - acts as a simplified Draw rect Wrapper
* - This function is part of Simple Draw API.
* @param pos Position of the rect
* @param size Size of the rect
* @param color Color of the rect
*/
void DrawRectSolid(const vec2& pos, const vec2& size, u32 color);
/**
* Render a Triangle
* @param a Position A
* @param b Position B
* @param c Position C
* @param color Color of the triangle
* @note
* - Uses Solid color [white tex]
* - This function is part of Simple Draw API.
*/
void DrawTriangle(const vec2& a, const vec2& b, const vec2& c, u32 color);
/**
* Draw a Circle (Supports Textures)
* @param center_pos Center Position
* @param r Radius of the circle
* @param color Color of the circle
* @param segments Segments to use
* @note
* - Textures could look a bit janky due to uv mapping
* - This function is part of Simple Draw API.
*/
void DrawCircle(const vec2& center_pos, float r, u32 color, int segments);
/**
* Draw a Line between to Positions
* @param a Position A
* @param b Position B
* @param color Color of the line
* @param t Thickness
* @note This function is part of Simple Draw API.
*/
void DrawLine(const vec2& a, const vec2& b, u32 color, int t);
/**
* Render a Text
* @param pos Position of the text
* @param color Color of the Text
* @param text Text to Render
* @param flags flags to use
* @param ap optional size for specific flags
* @note This function is part of Simple Draw API.
*/
void DrawText(const vec2& pos, u32 color, const std::string& text,
u32 flags = 0, const vec2& ap = vec2());
/**
* Draw a Texture as 2D Image
* @param pos Position
* @param tex Texture reference
* @param scale Scale (cause maybe wants to be resized)
* @note
* - Acts as a Simplified wrapper to DrawRect
* - This function is part of Simple Draw API.
*/
void DrawImage(const vec2& pos, Texture::Ref tex,
const vec2& scale = vec2(1.f));
// Debug STUFF
/** DEBUG Get the Number of Vertices of last Frame */
u32 Vertices() const { return vertices; }
/** DEBUG Get the Number of Indices of last frame */
u32 Indices() const { return indices; }
/** DEBUG Get the Number of Commands of last frame */
u32 Commands() const { return commands; }
/** DEBUG Get the Number of Drawcalls of last frame */
u32 DrawCalls() const { return drawcalls; }
/** Auto Static Text Number of Texts */
u32 AstUsage() const { return ast.size(); }
/** Text Map System number of texts */
u32 TmsUsage() const { return tms.size(); }
// TOOLS
/** Rotate a rect corner position by sine and cosine value */
static void RotateCorner(vec2& v, float s, float c);
/** Create a Rect by Position, Size and rotation angle */
static Rect CreateRect(const vec2& pos, const vec2& size, float angle);
/** Create a Line Rect by 2 Position and a thickness value */
static Rect CreateLine(const vec2& a, const vec2& b, int t);
/** Check if a pos and size are inside a vec4 rect */
static bool InBox(const vec2& pos, const vec2& size, const vec4& rect);
/** Check if a pos is inside a vec4 rect */
static bool InBox(const vec2& pos, const vec4& rect);
/** Check if one or all of three positions are somehow inside a vec4 rect */
static bool InBox(const vec2& alpha, const vec2& bravo, const vec2& charlie,
const vec4& rect);
/**
* Get The Address of a Screen
* @note **IMPORTANT** THIS IS FOR 32Bit System
*
* Should find a better way to do this for porting this lib
*/
static u32 Screen32(Screen::Ref s) { return (u32)s.get(); }
/** Function to optimize command order for rendering */
static void OptiCommandList(std::vector<Command::Ref>& list);
/** Returns Viewport with xy */
vec4 GetViewport();
/** Push a Self Created command */
void PushCommand(Command::Ref cmd) {
cmd->Index(cmd_idx++); // Indexing
draw_list[Screen32(screen)].push_back(cmd);
}
/** Automatically sets up a command */
void SetupCommand(Command::Ref cmd);
/** Creates a default Quad Render Command */
void QuadCommand(Command::Ref cmd, const Rect& quad, const Rect& uv, u32 col);
/** Create a Default Triangle */
void TriangleCommand(Command::Ref cmd, const vec2& a, const vec2& b,
const vec2& c, u32 col);
/**
* Create List of a Text Commands
* @param cmds Link to a command List
* @param pos Position
* @param color Color
* @param text Text
* @param flags Flags
* @param box (Size for wrapping / Offset for Centered Text)
*/
void TextCommand(std::vector<Command::Ref>& cmds, const vec2& pos, u32 color,
const std::string& text, LITextFlags flags, const vec2& box);
vec2 GetTextDimensions(const std::string& text);
/**
* Function to short a text and replace the rest by ...
* @param text Text to short
* @param maxlen Maximum width
* @param newsize New Textbox size
* @return shorted text
*/
std::string ShortText(const std::string& text, int maxlen, vec2& newsize);
/**
* Function to Wrap Text by specific width
*
* **NOT IMPLEMENTED YET**
* @param text text to wrap
* @param maxlen maximum width per line
* @param newsize new textbox size
* @return wrapped text
*/
std::string WrapText(const std::string& text, int maxlen, vec2& newsize);
private:
// Helper Funcitons
/**
* Update the 3DS citro3d texenv for specific RenderMode
* @param mode RenderMode to use.
*/
void UpdateRenderMode(const RenderMode& mode);
/** Current Screen */
Screen::Ref screen;
/** Screen Regestry */
Screen::Ref screens[2];
// Context Related
/** Renderer flags */
LIRenderFlags flags = LIRenderFlags_Default;
/** Area Size */
vec2 area_size;
/** Current Layer */
int current_layer = 0;
/** Current Texture */
Texture::Ref current_tex = nullptr;
/** Single Color Texture (for solid color objs) */
Texture::Ref white = nullptr;
/** Current Font Reference */
Font::Ref font = nullptr;
/** Font updated */
bool font_update;
/** Current Rendermode */
RenderMode mode = RenderMode_RGBA;
/** Text Map System */
std::map<std::string, TextBox> tms;
/** (Auto) Static Text */
std::unordered_map<u32, StaticText::Ref> ast;
// Text Rendering
/** Default FOnt height */
const float default_font_h = 24.f;
/** Default Text Scale */
const float default_text_size = 0.7f;
/** Current Text Scale */
float text_size = 0.7f;
// Special
/** Current Rotation (RECTS) */
float rot = 0.f;
// Rendering
/** Map of drawlist by 32Bit memory Address of their Screen */
std::unordered_map<u32, std::vector<Command::Ref>> draw_list;
/** Vertex Buffer in linear Ram */
std::vector<Vertex, LinearAllocator<Vertex>> vertex_buf;
/** 16Bit index buffer in linear Ram */
std::vector<u16, LinearAllocator<u16>> index_buf;
/** vertex index (render stage) */
u32 vertex_idx = 0;
/** index buf index (render stage) */
u32 index_idx = 0;
/** command index (used for debug count) */
u32 cmd_idx = 0;
// Debug
/** Num of Vertices */
u32 vertices = 0;
/** Num of indices */
u32 indices = 0;
/** Num of Commands */
u32 commands = 0;
/** Num of Drawcalls */
u32 drawcalls = 0;
// Shader
/** Shader code */
DVLB_s* dvlb = nullptr;
/** Shader program */
shaderProgram_s shader;
/** Shader Attribute info */
C3D_AttrInfo attr;
/** projection matrix location */
int uLoc_projection = 0;
// Matrix
/** Precalculated Projectrion Matrix for top screen */
C3D_Mtx top_proj;
/** Precalculated Projectrion Matrix for bottom screen */
C3D_Mtx bot_proj;
};
} // namespace LI
} // 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 <3ds.h>
#include <citro3d.h>
#include <pd/core/common.hpp>
#include <pd/core/vec.hpp>
namespace PD {
/**
* 3DS Screen (RenderTarget)
*/
class Screen : public SmartCtor<Screen> {
public:
/** Screens */
enum Screen_ {
Top, ///< Top Screen
Bottom, ///< Bottom Screen
TopRight ///< Top Right Screen area
};
/**
* Constructor to create Screen by Screen Type
* @param screen Screen to grab default init values for
*/
Screen(Screen_ screen) : type(screen) {
if (screen == Top) {
target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8,
GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT,
DisplayTransferFlags);
} else if (screen == Bottom) {
target = C3D_RenderTargetCreate(240, 320, GPU_RB_RGBA8,
GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetOutput(target, GFX_BOTTOM, GFX_LEFT,
DisplayTransferFlags);
} else if (screen == TopRight) {
target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8,
GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_RIGHT,
DisplayTransferFlags);
}
}
~Screen() = default;
/** Clear the Screen */
void Clear() { C3D_RenderTargetClear(target, C3D_CLEAR_ALL, 0x00000000, 0); }
/** Set the Screen active for Rendering */
void Use() { C3D_FrameDrawOn(target); }
/** Get the Screens Size */
vec2 GetSize() const {
return vec2(target->frameBuf.height, target->frameBuf.width);
}
/** Get the Screen Type */
Screen_ ScreenType() const { return type; }
/** Get the Raw Rendertarget object */
C3D_RenderTarget* Get() const { return target; }
/** Operartor to get the raw RenderTarget */
operator C3D_RenderTarget*() const { return target; }
private:
/** Screen Type */
Screen_ type;
/** Default Init Flags */
const u32 DisplayTransferFlags =
(GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) |
GX_TRANSFER_RAW_COPY(0) | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) |
GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) |
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO));
/** RenderTarget */
C3D_RenderTarget* target;
};
} // namespace PD

View File

@ -1,66 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <citro3d.h>
#include <tex3ds.h>
#include <pd/core/common.hpp>
#include <pd/lithium/texture.hpp>
namespace PD {
/**
* Tex 3DS Spritesheet integration to Lithium
*/
class SpriteSheet : public SmartCtor<SpriteSheet> {
public:
SpriteSheet() = default;
/**
* Constructor to directly load a spritesheet
* @param path Path to spritesheet
*/
SpriteSheet(const std::string& path) { this->LoadFile(path); }
/**
* Deconstructor to unload the Spritesheet
*/
~SpriteSheet();
/**
* Function to load a Spritesheet
* @param path Path to the file
*/
void LoadFile(const std::string& path);
/** Get a Textures Reference */
Texture::Ref Get(int idx);
/** Get Number of Textures in spritesheet */
int NumTextures() const;
/** Operator to get Texture reference */
Texture::Ref operator[](int idx) { return Get(idx); }
private:
/** Storage of the Spritesheets textures */
std::vector<Texture::Ref> textures;
};
} // namespace PD

View File

@ -1,153 +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 <citro3d.h>
#include <pd/core/common.hpp>
#include <pd/core/vec.hpp>
#include <pd/lithium/rect.hpp>
namespace PD {
/**
* Lithium Texture Loader / DataHolder
*/
class Texture : public SmartCtor<Texture> {
public:
/** Texture Type */
enum Type {
RGBA32, ///< RGBA 32
RGB24, ///< RGB24
A8, ///< A8
};
/** Texture Filters */
enum Filter {
NEAREST, ///< Nearest
LINEAR, ///< Linear
};
/** Default constructor */
Texture() : uv(0.f, 1.f, 1.f, 0.f) {}
/**
* Load file Constructor
* @param path path to file
* @param t3x set true if file is a t3x file
*/
Texture(const std::string& path, bool t3x = false) : uv(0.f, 1.f, 1.f, 0.f) {
if (t3x) {
this->LoadT3X(path);
} else {
this->LoadFile(path);
}
}
/**
* Load Memory constructor
* @param data File Data reference
*/
Texture(const std::vector<u8>& data) : uv(0.f, 1.f, 1.f, 0.f) {
this->LoadMemory(data);
}
/**
* Load Pixels constructor
* @param data Pixel Buffer reference
* @param w width
* @param h height
* @param type Buffer Type [Default RGBA32]
* @param filter Filter [DEFAULT NEAREST]
*/
Texture(const std::vector<u8>& data, int w, int h, Type type = RGBA32,
Filter filter = NEAREST)
: uv(0.f, 1.f, 1.f, 0.f) {
this->LoadPixels(data, w, h, type, filter);
}
/** Deconstructor (aka auto delete) */
~Texture() {
if (autounload) {
Delete();
}
}
/// @brief Deletes image (if not already unloaded)
void Delete();
/// @brief Load a png/jpg/bmp from fs into a gpu tex
/// @param path path to image file
void LoadFile(const std::string& path);
/// @brief Load a png/jpg/bmp from memory
/// @param data reference to data buffer of the file
void LoadMemory(const std::vector<u8>& data);
/// @brief Create Texture out of Pixel Data
/// @param data Data reference
/// @param w width
/// @param h heigt
/// @param type Type of the databuffer
/// @param filter Filter (NEAREST OR LINEAR)
void LoadPixels(const std::vector<u8>& data, int w, int h, Type type = RGBA32,
Filter filter = NEAREST);
/// @brief Load a texture of a T3X File
/// @note This is used for single texture T3X
/// Not for SpriteSheets
/// @param path path to .t3x file
void LoadT3X(const std::string& path);
/// @brief Input a Texture that you had set up on your own
/// @param tex Texture reference (deletes itself)
/// @param rszs The size of the source image
/// @param uvs Your uv Setup
void LoadExternal(C3D_Tex* tex, vec2 rszs, LI::Rect uvs) {
this->Delete();
this->tex = tex;
this->size = rszs;
this->uv = uvs;
}
vec2 GetRealSize() {
if (!tex) {
return vec2();
}
return vec2(tex->width, tex->height);
}
vec2 GetSize() const { return size; }
C3D_Tex* GetTex() const { return tex; }
LI::Rect GetUV() const { return uv; }
bool IsValid() const { return tex != 0; }
bool AutoUnLoad() const { return autounload; }
void AutoUnLoad(bool v) { autounload = v; }
operator C3D_Tex*() const { return tex; }
operator vec2() const { return size; }
operator LI::Rect() const { return uv; }
operator bool() const { return tex != 0; }
private:
void MakeTex(std::vector<u8>& buf, int w, int h, Type type = RGBA32,
Filter filter = NEAREST);
vec2 size;
LI::Rect uv;
C3D_Tex* tex = nullptr;
bool autounload = true;
};
} // namespace PD

View File

@ -1,62 +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/common.hpp>
#include <pd/core/vec.hpp>
namespace PD {
namespace LI {
class Vertex {
public:
Vertex() {}
Vertex(const vec2& p, const vec2& u, u32 c) {
pos[0] = p[0];
pos[1] = p[1];
uv = u;
color = c;
}
~Vertex() {}
Vertex& Pos(const vec2& v) {
pos = v;
return *this;
}
Vertex& Uv(const vec2& v) {
uv = v;
return *this;
}
Vertex& Color(u32 v) {
color = v;
return *this;
}
// private:
vec2 pos;
vec2 uv;
u32 color;
};
} // namespace LI
} // namespace PD

45
include/pd/maths/NMat.hpp Normal file
View File

@ -0,0 +1,45 @@
#pragma once
#include <pd/maths/NVec.hpp>
class NMat4 {
public:
NMat4() { Zeros(); }
~NMat4() {}
void Zeros() { memset(this, 0, sizeof(*this)); }
void Identity() { Diagonal(NVec4(1.f, 1.f, 1.f, 1.f)); }
void Diagonal(NVec4 xyzw) {
Zeros();
r[0][0] = xyzw[0];
r[1][1] = xyzw[1];
r[2][2] = xyzw[2];
r[3][3] = xyzw[3];
}
NMat4& Get() { return *this; }
void Add(const NMat4& in) {
for (int i = 0; i < 0x10; i++) {
m[i] += in[i];
}
}
void Sub(const NMat4& in) {
for (int i = 0; i < 0x10; i++) {
m[i] -= in[i];
}
}
void Mul(const NMat4& in) {
}
void Transpose();
float Inverse();
// Operators
float operator[](int i) const { return m[i]; }
float& operator[](int i) { return m[i]; }
union {
NVec4 r[4];
float m[0x10];
};
};

366
include/pd/maths/NVec.hpp Normal file
View File

@ -0,0 +1,366 @@
#pragma once
#include <cmath>
struct NVec2 {
// Init Funcs
NVec2() {
v[0] = 0;
v[1] = 0;
}
NVec2(float x, float y) {
v[0] = x;
v[1] = y;
}
NVec2(const NVec2 &i) {
v[0] = i[0];
v[1] = i[1];
}
NVec2(float i) {
v[0] = i;
v[1] = i;
}
// Operations
// Add
NVec2 &operator+=(const NVec2 &i) {
v[0] += i[0];
v[1] += i[1];
return *this;
}
NVec2 &operator+=(const float &i) {
v[0] += i;
v[1] += i;
return *this;
}
NVec2 operator+(const NVec2 &i) const {
return NVec2(v[0] + i[0], v[1] + i[1]);
}
NVec2 operator+(const float &i) const { return NVec2(v[0] + i, v[1] + i); }
// Sub
NVec2 &operator-=(const NVec2 &i) {
v[0] -= i[0];
v[1] -= i[1];
return *this;
}
NVec2 &operator-=(const float &i) {
v[0] -= i;
v[1] -= i;
return *this;
}
NVec2 operator-(const NVec2 &i) const {
return NVec2(v[0] - i[0], v[1] - i[1]);
}
NVec2 operator-(const float &i) const { return NVec2(v[0] - i, v[1] - i); }
// Mul
NVec2 &operator*=(const NVec2 &i) {
v[0] *= i[0];
v[1] *= i[1];
return *this;
}
NVec2 &operator*=(const float &i) {
v[0] *= i;
v[1] *= i;
return *this;
}
NVec2 operator*(const NVec2 &i) const {
return NVec2(v[0] * i[0], v[1] * i[1]);
}
NVec2 operator*(const float &i) const { return NVec2(v[0] * i, v[1] * i); }
// Div
NVec2 &operator/=(const NVec2 &i) {
v[0] /= i[0];
v[1] /= i[1];
return *this;
}
NVec2 &operator/=(const float &i) {
v[0] /= i;
v[1] /= i;
return *this;
}
NVec2 operator/(const NVec2 &i) const {
return NVec2(v[0] / i[0], v[1] / i[1]);
}
NVec2 operator/(const float &i) const { return NVec2(v[0] / i, v[1] / i); }
// Compare
bool operator==(const NVec2 &in) const {
return v[0] == in[0] && v[1] == in[1];
}
bool operator!=(const NVec2 &in) const {
// use the first comparefuncs result
// and swap it lol
return !(*this == in);
}
NVec2 operator-() const { return NVec2(-v[0], -v[1]); }
float operator[](int i) const { return v[i]; }
float &operator[](int i) { return v[i]; }
float len() const { return sqrt(sqlen()); }
float sqlen() const { return v[0] * v[0] + v[1] * v[1]; }
float x() const { return v[0]; }
float &x() { return v[0]; }
float y() const { return v[1]; }
float &y() { return v[1]; }
// Internal Values
float v[2];
};
struct NVec3 {
// Init Funcs
NVec3() {
v[0] = 0.f;
v[1] = 0.f;
v[2] = 0.f;
}
NVec3(float x, float y, float z) {
v[0] = x;
v[1] = y;
v[2] = z;
}
NVec3(const NVec3 &i) {
v[0] = i[0];
v[1] = i[1];
v[2] = i[2];
}
NVec3(float i) {
v[0] = i;
v[1] = i;
v[2] = i;
}
// Operations
// Add
NVec3 &operator+=(const NVec3 &i) {
v[0] += i[0];
v[1] += i[1];
v[2] += i[2];
return *this;
}
NVec3 &operator+=(const float &i) {
v[0] += i;
v[1] += i;
v[2] += i;
return *this;
}
NVec3 operator+(const NVec3 &i) const {
return NVec3(v[0] + i[0], v[1] + i[1], v[2] + i[2]);
}
NVec3 operator+(const float &i) const {
return NVec3(v[0] + i, v[1] + i, v[2] + i);
}
// Sub
NVec3 &operator-=(const NVec3 &i) {
v[0] -= i[0];
v[1] -= i[1];
v[2] -= i[2];
return *this;
}
NVec3 &operator-=(const float &i) {
v[0] -= i;
v[1] -= i;
v[2] -= i;
return *this;
}
NVec3 operator-(const NVec3 &i) const {
return NVec3(v[0] - i[0], v[1] - i[1], v[2] - i[2]);
}
NVec3 operator-(const float &i) const {
return NVec3(v[0] - i, v[1] - i, v[2] - i);
}
// Mul
NVec3 &operator*=(const NVec3 &i) {
v[0] *= i[0];
v[1] *= i[1];
v[2] *= i[2];
return *this;
}
NVec3 &operator*=(const float &i) {
v[0] *= i;
v[1] *= i;
v[2] *= i;
return *this;
}
NVec3 operator*(const NVec3 &i) const {
return NVec3(v[0] * i[0], v[1] * i[1], v[2] * i[2]);
}
NVec3 operator*(const float &i) const {
return NVec3(v[0] * i, v[1] * i, v[2] * i);
}
// Div
NVec3 &operator/=(const NVec3 &i) {
v[0] /= i[0];
v[1] /= i[1];
v[2] /= i[2];
return *this;
}
NVec3 &operator/=(const float &i) {
v[0] /= i;
v[1] /= i;
v[2] /= i;
return *this;
}
NVec3 operator/(const NVec3 &i) const {
return NVec3(v[0] / i[0], v[1] / i[1], v[2] / i[2]);
}
NVec3 operator/(const float &i) const {
return NVec3(v[0] / i, v[1] / i, v[2] / i);
}
// Compare
bool operator==(const NVec3 &in) const {
return v[0] == in[0] && v[1] == in[1] && v[2] == v[2];
}
bool operator!=(const NVec3 &in) const {
// use the first comparefuncs result
// and swap it lol
return !(*this == in);
}
// Base
NVec3 operator-() const { return NVec3(-v[0], -v[1], -v[2]); }
float operator[](int i) const { return v[i]; }
float &operator[](int i) { return v[i]; }
float len() const { return sqrt(sqlen()); }
float sqlen() const { return v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; }
float x() const { return v[0]; }
float &x() { return v[0]; }
float y() const { return v[1]; }
float &y() { return v[1]; }
float z() const { return v[2]; }
float &z() { return v[2]; }
float v[3];
};
struct NVec4 {
// Init Funcs
NVec4() {
v[0] = 0.f;
v[1] = 0.f;
v[2] = 0.f;
v[3] = 0.f;
}
NVec4(float x, float y, float z, float w) {
v[0] = x;
v[1] = y;
v[2] = z;
v[3] = w;
}
NVec4(const NVec4 &i) {
v[0] = i[0];
v[1] = i[1];
v[2] = i[2];
v[3] = i[3];
}
NVec4(const NVec2 &i0, const NVec2 &i1) {
v[0] = i0[0];
v[1] = i0[1];
v[2] = i1[0];
v[3] = i1[1];
}
NVec4(float i) {
v[0] = i;
v[1] = i;
v[2] = i;
v[3] = i;
}
// Operators
// Add
NVec4 &operator+=(const NVec4 &i) {
v[0] += i[0];
v[1] += i[1];
v[2] += i[2];
v[3] += i[3];
return *this;
}
NVec4 operator+(const NVec4 &i) const {
return NVec4(v[0] + i[0], v[1] + i[1], v[2] + i[2], v[3] + i[3]);
}
// Sub
NVec4 &operator-=(const NVec4 &i) {
v[0] -= i[0];
v[1] -= i[1];
v[2] -= i[2];
v[3] -= i[3];
return *this;
}
NVec4 operator-(const NVec4 &i) const {
return NVec4(v[0] - i[0], v[1] - i[1], v[2] - i[2], v[3] - i[3]);
}
// Compare
bool operator==(const NVec4 &in) const {
return v[0] == in[0] && v[1] == in[1] && v[2] == in[2] && v[3] == in[3];
}
bool operator!=(const NVec4 &in) const {
// use the first comparefuncs result
// and swap it lol
return !(*this == in);
}
// Base
NVec3 operator-() const { return NVec3(-v[0], -v[1], -v[2]); }
float operator[](int i) const { return v[i]; }
float &operator[](int i) { return v[i]; }
float len() const { return sqrt(sqlen()); }
float sqlen() const {
return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
}
// Vec Acess
float x() const { return v[0]; }
float &x() { return v[0]; }
float y() const { return v[1]; }
float &y() { return v[1]; }
float z() const { return v[2]; }
float &z() { return v[2]; }
float w() const { return v[3]; }
float &w() { return v[3]; }
// Quaternion Acess
float r() const { return v[0]; }
float &r() { return v[0]; }
float k() const { return v[1]; }
float &k() { return v[1]; }
float j() const { return v[2]; }
float &j() { return v[2]; }
float i() const { return v[3]; }
float &i() { return v[3]; }
// Internal Values
float v[4];
};

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

30
include/pd/nimg.hpp Normal file
View File

@ -0,0 +1,30 @@
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#define NPI_NIMG_ (uint32_t)0x4e494d47 // Magic: NIMG
namespace Palladium {
struct nimg {
unsigned int magic; // Magic number defaults do NPI_NIMG_
int width;
int height;
int format;
int compression;
std::vector<unsigned char> pixel_buffer;
nimg(int w = 0, int h = 0, int fmt = 0, int cmp = 0) {
magic = NPI_NIMG_;
width = w;
height = h;
format = fmt;
compression = cmp;
pixel_buffer.resize((w * h) * (format ? 3 : 4));
}
};
nimg NIMG_Load(std::string path);
nimg NIMG_LoadFromMem(unsigned char* buffer, size_t bf_size);
void NIMG_Save(nimg image, std::string path);
} // namespace Palladium

View File

@ -1,178 +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/tween.hpp>
#include <pd/drivers/hid.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<vec2> selector;
// Tween for Selector Size
Tween<vec2> sel_szs;
// Current Cell size
vec2 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<vec2> flymgr;
// Secode Flymanager
Tween<vec2> chflymgr;
// Show Help
bool show_help = true;
};
} // namespace PD

View File

@ -1,99 +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/color.hpp>
#include <pd/core/tween.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<vec2> pos; // Position effect
std::string title; // Title
std::string msg; // Message
vec2 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,57 +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/drivers/hid.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,64 +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/drivers/hid.hpp>
#include <pd/lithium/renderer.hpp>
#include <pd/overlays/overlay.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;
}
/** 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);
private:
std::vector<Overlay::Ref> overlays; ///< Overlay List
LI::Renderer::Ref ren; ///< Renderer reference
Hid::Ref inp; ///< Input Driver reference
};
} // 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/drivers/hid.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(vec2& 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,76 +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/tween.hpp>
#include <pd/drivers/hid.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<vec2> flymgr;
// Custom UI7 Context
UI7::Context::Ref ctx;
};
} // namespace PD

183
include/pd/palladium.hpp Normal file
View File

@ -0,0 +1,183 @@
#pragma once
/// c++ Includes
#include <cstring>
#include <map>
#include <memory>
#include <stack>
#include <string>
/// c includes
#include <dirent.h>
#include <stdio.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
/// 3ds Includes
#include <3ds.h>
#include <citro3d.h>
/// Palladium Includes
#include <pd/Hardware.hpp>
#include <pd/Overlays.hpp>
#include <pd/Ovl.hpp>
#include <pd/ResultDecoder.hpp>
#include <pd/Sprite.hpp>
#include <pd/Tasks.hpp>
#include <pd/Time.hpp>
#include <pd/base/Color.hpp>
#include <pd/base/FunctionTrace.hpp>
#include <pd/base/Lang.hpp>
#include <pd/base/Memory.hpp>
#include <pd/base/stringtool.hpp>
#include <pd/parameter.hpp>
#include <pd/thread.hpp>
#define PDVSTRING "1.0.0"
#define DEFAULT_CENTER 0.5f
/// @param pd_max_objects Config Param for C2D Mac objects
extern int pd_max_objects;
namespace Palladium {
/// @brief Get Deltatime
/// @return Deltatime
float GetDeltaTime();
/// @brief Scene Class
class Scene {
public:
/// @brief Stack of the Scenes
static std::stack<std::unique_ptr<Scene>> scenes;
/// @brief Deconstructor
virtual ~Scene() {}
virtual void Update() = 0;
/// @brief Push a Scene to Stack
/// @param scene Scene to Push
/// @param fade FadeEffect (Not Correctly Implementet yet)
static void Load(std::unique_ptr<Scene> scene, bool fade = false);
/// @brief Go Back a Scene
static void Back();
/// @brief do the Draw (Called in Palladium::MainLoop())
static void doUpdate();
};
/// @brief Integrated Setting Menu of Palladium
class RSettings : public Palladium::Scene {
private:
/// @brief State (Define for Menus)
enum RState {
RSETTINGS, // Main Settings Menu
RIDB, // Internal Debugger
ROVERLAYS, // Overlay Settings
RFTRACE, // FTRace Menu
RUI7, // UI7 Menu
RLOGS, // Logs
RFV, // Font Viewer
};
/// @param shared_request Defines requests from Draw to Logic
/// As it is not planned to make Draw non const you'll need
/// A map of data or bool values that are mutable ake
/// editable by const functions
mutable std::map<unsigned int, unsigned int> shared_request;
/// @param m_state Current menu State (Default=MainMenu aka RSETTINGS)
Palladium::RSettings::RState m_state =
Palladium::RSettings::RState::RSETTINGS;
/// @brief Position in FTrace Menu
int ftrace_index = 0;
/// @param mtovlstate State of Metricks Overlay
std::string mtovlstate = "false";
/// @param mtscreenstate Screen the Overlay is Set to
std::string mtscreenstate = "Top";
std::string kbd_test;
PDKeyboardState kbd_state;
bool statemtold = false;
bool stateftold = false;
float tmp_txt;
public:
/// @brief Constructor
RSettings();
/// @brief Deconstructor
~RSettings();
void Update() override;
};
/// @brief Show Up the Palladium-Settings Menu
void LoadSettings();
/// @brief Show Up The Theme Editor
void LoadThemeEditor();
/// @brief Get's The Programs Time running
/// @return Time Running
float GetTime();
/// @brief Get Framerate as Number
/// @return FPS
int GetFps();
/// @brief Get A Rendom Int
/// @param b From
/// @param e To
/// @return Random Int
int GetRandomInt(int b, int e);
/// @brief Fade In
/// @param duration Duration in Frames
void FadeIn();
/// @brief Fade Out
/// @param duration Duration in Frames
void FadeOut();
/// @brief Display Fade Effects
void FadeDisplay();
namespace Init {
/// @brief Init Default Palladium
/// @param app_name Name of Your App
/// @return ResCode
Result Main(std::string app_name = "pdGame");
/// @brief Init Minimal Palladium (For better Hax2.x support)
/// @param app_name Name of Your App
/// @return ResCode
Result Minimal(std::string app_name = "pdGame");
/// @brief Reload the Graphics Engine
/// @return ResCode
Result Reload();
/// @brief Init Graphics Only (NOT SUPPORTET use Reload)
void Graphics();
/// @brief Init Ndsp for Sounds
void NdspFirm();
} // namespace Init
namespace FS {
/// @brief Check if File exists
/// @param path Path to the File
/// @return exists or not
bool FileExist(const std::string &path);
} // namespace FS
/// @brief Check if Ndsp is Init
/// @return is or not
bool IsNdspInit();
/// @brief Get Current Framerate as String
/// @return Framerate String
std::string GetFramerate();
/// @brief MainLoop of Palladiums
/// @return Is Still Running or not
bool MainLoop();
/// @brief Exit App (brak the MainLoop)
void ExitApp();
/// @brief Clear the Citro2D TextBuffers
/// @param
void ClearTextBufs(void);
/// @brief Draw Overlays And end the Frame. DO NEVER USE C3D_FRAMEEND cause it
/// breaks Overlay crash Security
void FrameEnd();
/// @brief Returns App Working Directory path
/// @return AppDir Path
std::string GetAppDirectory();
/// @brief returns path to the Data Directory
/// @return data dir path
std::string GetDataDirectory();
} // namespace Palladium

134
include/pd/parameter.hpp Normal file
View File

@ -0,0 +1,134 @@
#pragma once
#include <tuple>
namespace Palladium {
class Parameter {
private:
using id = size_t;
template <typename T>
struct type {
static void id() {}
};
template <typename T>
static id type_id() {
return reinterpret_cast<id>(&type<T>::id);
}
template <typename T>
using decay = typename std::decay<T>::type;
template <typename T>
using none =
typename std::enable_if<!std::is_same<Parameter, T>::value>::type;
struct base {
virtual ~base() {}
virtual bool is(id) const = 0;
virtual base *copy() const = 0;
} *p = nullptr;
template <typename T>
struct data : base, std::tuple<T> {
using std::tuple<T>::tuple;
T &get() & { return std::get<0>(*this); }
T const &get() const & { return std::get<0>(*this); }
bool is(id i) const override { return i == type_id<T>(); }
base *copy() const override { return new data{get()}; }
};
template <typename T>
T &stat() {
return static_cast<data<T> &>(*p).get();
}
template <typename T>
T const &stat() const {
return static_cast<data<T> const &>(*p).get();
}
template <typename T>
T &dyn() {
return dynamic_cast<data<T> &>(*p).get();
}
template <typename T>
T const &dyn() const {
return dynamic_cast<data<T> const &>(*p).get();
}
public:
/**
* @brief Default constructor
*/
Parameter() {}
/**
* @brief Destructs the Parameter
*/
~Parameter() { delete p; }
/**
* @brief Copy constructor
* @param s The Parameter to copy
*/
Parameter(Parameter &&s) : p{s.p} { s.p = nullptr; }
/**
* @brief Const copy constructor
* @param s The Parameter to copy
*/
Parameter(Parameter const &s) : p{s.p->copy()} {}
/**
* @brief Initializes the Parameter with the given value
* @param x The value to initialize the Parameter with
*/
template <typename T, typename U = decay<T>, typename = none<U>>
Parameter(T &&x) : p{new data<U>{std::forward<T>(x)}} {}
/**
* @brief Overloads the assignment operator
* @param s The value to set the Parameter to
*/
Parameter &operator=(Parameter s) {
swap(*this, s);
return *this;
}
friend void swap(Parameter &s, Parameter &r) { std::swap(s.p, r.p); }
/**
* @brief Clears the Parameter
*/
void clear() {
delete p;
p = nullptr;
}
/**
* @brief Checks whether the Parameter is the given type
* @tparam T The type to check
* @return Whether the Parameter has the given type or not
*/
template <typename T>
bool is() const {
return p ? p->is(type_id<T>()) : false;
}
/**
* @brief Returns the value of the Parameter
* @tparam T The type of the Parameter
* @return The value of the Parameter
* @warning If the type of the Parameter doesn't match the type of it's stored
* value, it will result in undefined behaviour.
*/
template <typename T>
T &get() & {
return stat<T>();
}
};
} // namespace Palladium

10
include/pd/smart_ctor.hpp Normal file
View File

@ -0,0 +1,10 @@
#pragma once
#include <memory>
#define PD_SMART_CTOR(type) \
using Ref = std::shared_ptr<type>; \
template <typename... args> \
static Ref New(args&&... cargs) { \
return std::make_shared<type>(std::forward<args>(cargs)...); \
}

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