Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
01fb149e71 | |||
57634cbf4b | |||
963fa72e41 | |||
271defffca | |||
ea76a304d4 | |||
f75f7067ff | |||
13c2869ba8 | |||
dbffb7f316 | |||
6738fda55c | |||
35272687f6 |
3
.gitignore
vendored
Normal file → Executable file
3
.gitignore
vendored
Normal file → Executable file
@ -1 +1,2 @@
|
|||||||
build/
|
build/
|
||||||
|
.cache
|
||||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "backends/desktop/glfw"]
|
||||||
|
path = backends/desktop/glfw
|
||||||
|
url = https://github.com/glfw/glfw
|
36
.vscode/c_cpp_properties.json
vendored
36
.vscode/c_cpp_properties.json
vendored
@ -1,36 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "3DS | Windows",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"C:/devkitpro/libctru/include/**",
|
|
||||||
"C:/devkitpro/devkitARM/include/**",
|
|
||||||
"C:/devkitpro/devkitARM/arm-none-eabi/include/**",
|
|
||||||
"C:/devkitpro/portlibs/3ds/include/**"
|
|
||||||
],
|
|
||||||
"defines": [
|
|
||||||
"BUILD_CTR"
|
|
||||||
],
|
|
||||||
"compilerPath": "C:/devkitPro/devkitARM/bin/arm-none-eabi-g++.exe",
|
|
||||||
"intelliSenseMode": "gcc-arm",
|
|
||||||
"cStandard": "c11",
|
|
||||||
"cppStandard": "c++20"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "3DS | Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**",
|
|
||||||
"/opt/devkitpro/libctru/include/**",
|
|
||||||
"/opt/devkitpro/portlibs/3ds/include/**"
|
|
||||||
],
|
|
||||||
"defines": [
|
|
||||||
"BUILD_CTR"
|
|
||||||
],
|
|
||||||
"cStandard": "c17",
|
|
||||||
"cppStandard": "gnu++20",
|
|
||||||
"intelliSenseMode": "gcc-arm"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
21
.vscode/launch.json
vendored
21
.vscode/launch.json
vendored
@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "3DS GDB",
|
|
||||||
"type": "cppdbg",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/build/test.elf",
|
|
||||||
"miDebuggerServerAddress": "localhost:4003",
|
|
||||||
"miDebuggerPath": "C:\\devkitPro\\devkitARM\\bin\\arm-none-eabi-gdb.exe",
|
|
||||||
"cwd": "${workspaceFolder}",
|
|
||||||
"externalConsole": true,
|
|
||||||
"setupCommands": [
|
|
||||||
{
|
|
||||||
"description": "Enable pretty-printing for gdb",
|
|
||||||
"text": "-enable-pretty-printing",
|
|
||||||
"ignoreFailures": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
120
.vscode/settings.json
vendored
120
.vscode/settings.json
vendored
@ -1,120 +0,0 @@
|
|||||||
{
|
|
||||||
"files.associations": {
|
|
||||||
"array": "cpp",
|
|
||||||
"*.tcc": "cpp",
|
|
||||||
"cctype": "cpp",
|
|
||||||
"clocale": "cpp",
|
|
||||||
"cmath": "cpp",
|
|
||||||
"cstdarg": "cpp",
|
|
||||||
"cstddef": "cpp",
|
|
||||||
"cstdint": "cpp",
|
|
||||||
"cstdio": "cpp",
|
|
||||||
"cstdlib": "cpp",
|
|
||||||
"cwchar": "cpp",
|
|
||||||
"cwctype": "cpp",
|
|
||||||
"unordered_map": "cpp",
|
|
||||||
"vector": "cpp",
|
|
||||||
"exception": "cpp",
|
|
||||||
"algorithm": "cpp",
|
|
||||||
"functional": "cpp",
|
|
||||||
"iterator": "cpp",
|
|
||||||
"memory": "cpp",
|
|
||||||
"numeric": "cpp",
|
|
||||||
"type_traits": "cpp",
|
|
||||||
"fstream": "cpp",
|
|
||||||
"initializer_list": "cpp",
|
|
||||||
"iosfwd": "cpp",
|
|
||||||
"iostream": "cpp",
|
|
||||||
"istream": "cpp",
|
|
||||||
"limits": "cpp",
|
|
||||||
"new": "cpp",
|
|
||||||
"optional": "cpp",
|
|
||||||
"ostream": "cpp",
|
|
||||||
"sstream": "cpp",
|
|
||||||
"stdexcept": "cpp",
|
|
||||||
"streambuf": "cpp",
|
|
||||||
"string": "cpp",
|
|
||||||
"string_view": "cpp",
|
|
||||||
"system_error": "cpp",
|
|
||||||
"tuple": "cpp",
|
|
||||||
"typeinfo": "cpp",
|
|
||||||
"utility": "cpp",
|
|
||||||
"atomic": "cpp",
|
|
||||||
"bit": "cpp",
|
|
||||||
"bitset": "cpp",
|
|
||||||
"chrono": "cpp",
|
|
||||||
"codecvt": "cpp",
|
|
||||||
"condition_variable": "cpp",
|
|
||||||
"cstring": "cpp",
|
|
||||||
"ctime": "cpp",
|
|
||||||
"deque": "cpp",
|
|
||||||
"forward_list": "cpp",
|
|
||||||
"map": "cpp",
|
|
||||||
"iomanip": "cpp",
|
|
||||||
"memory_resource": "cpp",
|
|
||||||
"ratio": "cpp",
|
|
||||||
"regex": "cpp",
|
|
||||||
"shared_mutex": "cpp",
|
|
||||||
"valarray": "cpp",
|
|
||||||
"random": "cpp",
|
|
||||||
"cuchar": "cpp",
|
|
||||||
"compare": "cpp",
|
|
||||||
"concepts": "cpp",
|
|
||||||
"numbers": "cpp",
|
|
||||||
"filesystem": "cpp",
|
|
||||||
"xstring": "cpp",
|
|
||||||
"charconv": "cpp",
|
|
||||||
"format": "cpp",
|
|
||||||
"ios": "cpp",
|
|
||||||
"list": "cpp",
|
|
||||||
"locale": "cpp",
|
|
||||||
"mutex": "cpp",
|
|
||||||
"stack": "cpp",
|
|
||||||
"stop_token": "cpp",
|
|
||||||
"thread": "cpp",
|
|
||||||
"xfacet": "cpp",
|
|
||||||
"xhash": "cpp",
|
|
||||||
"xiosbase": "cpp",
|
|
||||||
"xlocale": "cpp",
|
|
||||||
"xlocbuf": "cpp",
|
|
||||||
"xlocinfo": "cpp",
|
|
||||||
"xlocmes": "cpp",
|
|
||||||
"xlocmon": "cpp",
|
|
||||||
"xlocnum": "cpp",
|
|
||||||
"xloctime": "cpp",
|
|
||||||
"xmemory": "cpp",
|
|
||||||
"xstddef": "cpp",
|
|
||||||
"xtr1common": "cpp",
|
|
||||||
"xtree": "cpp",
|
|
||||||
"xutility": "cpp",
|
|
||||||
"queue": "cpp",
|
|
||||||
"semaphore": "cpp",
|
|
||||||
"hash_map": "cpp",
|
|
||||||
"set": "cpp",
|
|
||||||
"unordered_set": "cpp",
|
|
||||||
"source_location": "cpp",
|
|
||||||
"future": "cpp",
|
|
||||||
"cfenv": "cpp",
|
|
||||||
"cinttypes": "cpp",
|
|
||||||
"typeindex": "cpp",
|
|
||||||
"variant": "cpp",
|
|
||||||
"ranges": "cpp",
|
|
||||||
"span": "cpp",
|
|
||||||
"coroutine": "cpp",
|
|
||||||
"__bit_reference": "cpp",
|
|
||||||
"__config": "cpp",
|
|
||||||
"__debug": "cpp",
|
|
||||||
"__errc": "cpp",
|
|
||||||
"__hash_table": "cpp",
|
|
||||||
"__locale": "cpp",
|
|
||||||
"__mutex_base": "cpp",
|
|
||||||
"__node_handle": "cpp",
|
|
||||||
"__split_buffer": "cpp",
|
|
||||||
"__threading_support": "cpp",
|
|
||||||
"__tree": "cpp",
|
|
||||||
"__verbose_abort": "cpp",
|
|
||||||
"complex": "cpp",
|
|
||||||
"any": "cpp",
|
|
||||||
"text_encoding": "cpp"
|
|
||||||
}
|
|
||||||
}
|
|
246
CMakeLists.txt
Normal file → Executable file
246
CMakeLists.txt
Normal file → Executable file
@ -1,210 +1,36 @@
|
|||||||
cmake_minimum_required(VERSION 3.18)
|
cmake_minimum_required(VERSION 3.22)
|
||||||
|
|
||||||
### Helper Function to Build Librarys without have always
|
# Set Project
|
||||||
### These includes and definition defines
|
project(palladium LANGUAGES C CXX VERSION 0.5.0)
|
||||||
function(add_pd_lib TARGET_NAME)
|
|
||||||
set(opts "")
|
# Required to add this Variable
|
||||||
set(one_val_args "")
|
set(PD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
set(multi_val_args SRC_FILES DEPENDS)
|
include(cmake/palladium.cmake)
|
||||||
cmake_parse_arguments(ARG "${opts}" "${one_val_args}" "${multi_val_args}" ${ARGN})
|
|
||||||
|
option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)
|
||||||
add_library(${TARGET_NAME} STATIC ${ARG_SRC_FILES})
|
option(PD_BUILD_SHARED "Build Shared Libraries" OFF)
|
||||||
target_include_directories(${TARGET_NAME} PUBLIC
|
option(PD_BUILD_TOOLS "Build Palladium Tools" OFF)
|
||||||
include
|
|
||||||
${DEVKITPRO}/portlibs/3ds/include)
|
if(${PD_BUILD_TOOLS})
|
||||||
target_compile_definitions(${TARGET_NAME} PUBLIC
|
add_subdirectory(tools)
|
||||||
-D_GNU_SOURCE=1
|
endif()
|
||||||
-DPALLADIUM_VERSION="${PROJECT_VERSION}"
|
|
||||||
-DPALLADIUM_GIT_COMMIT="${GIT_SHORT_HASH}"
|
## Include Library Source
|
||||||
-DPALLADIUM_GIT_BRANCH="${GIT_BRANCH}"
|
|
||||||
-DBUILD_CTR=1)
|
add_subdirectory(pd/drivers)
|
||||||
### For the libs that depend on another
|
add_subdirectory(pd/core)
|
||||||
if(ARG_DEPENDS)
|
add_subdirectory(pd/image)
|
||||||
target_link_libraries(${TARGET_NAME} PUBLIC ${ARG_DEPENDS})
|
add_subdirectory(pd/external)
|
||||||
endif()
|
add_subdirectory(pd/lithium)
|
||||||
install(TARGETS ${TARGET_NAME})
|
add_subdirectory(pd/ui7)
|
||||||
endfunction()
|
|
||||||
|
add_library(palladium INTERFACE)
|
||||||
# Setup Toolchain if not specified
|
target_link_libraries(palladium INTERFACE
|
||||||
# Could propably avoided by using arm-none-eabi-cmake
|
pd-core pd-image pd-external pd-lithium pd-ui7 #pd-net
|
||||||
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
)
|
||||||
if(DEFINED ENV{DEVKITPRO})
|
|
||||||
set(CMAKE_TOOLCHAIN_FILE "$ENV{DEVKITPRO}/cmake/3DS.cmake" CACHE PATH "toolchain file")
|
add_dependencies(palladium
|
||||||
else()
|
pd-drivers pd-core pd-image pd-external pd-lithium pd-ui7 #pd-net
|
||||||
message(FATAL_ERROR "Please define DEVKITPRO to point to your SDK path!")
|
)
|
||||||
endif()
|
|
||||||
endif()
|
install(DIRECTORY include DESTINATION ".")
|
||||||
|
|
||||||
## 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 ".")
|
|
||||||
|
17
README.md
Normal file → Executable file
17
README.md
Normal file → Executable file
@ -23,28 +23,11 @@ make
|
|||||||
make install
|
make install
|
||||||
```
|
```
|
||||||
|
|
||||||
## Libraries
|
|
||||||
|
|
||||||
| Name | Last Updated | Platform | Depends |
|
|
||||||
|---|---|---|---|
|
|
||||||
| 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
|
## Credits
|
||||||
|
|
||||||
| Icon | Username | Description |
|
| 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/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/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/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 |
|
| <img src="https://github.com/nlohmann.png" alt="https://github.com/nlohmann" width="48"/> | [nlohmann](https://github.com/nlohmann) | for json.hpp |
|
||||||
|
13
backends/3ds/CMakeLists.txt
Executable file
13
backends/3ds/CMakeLists.txt
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.22)
|
||||||
|
|
||||||
|
project(pd-3ds LANGUAGES CXX VERSION 0.5.0)
|
||||||
|
|
||||||
|
set(SRC
|
||||||
|
source/bknd-gfx.cpp
|
||||||
|
source/bknd-hid.cpp
|
||||||
|
source/pd-3ds.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
pd_add_lib(pd-3ds SRC_FILES ${SRC})
|
||||||
|
target_include_directories(pd-3ds PUBLIC include)
|
||||||
|
target_link_libraries(pd-3ds PUBLIC m palladium ctru citro3d)
|
32
backends/3ds/include/pd-3ds.hpp
Executable file
32
backends/3ds/include/pd-3ds.hpp
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pd-3ds/bknd-gfx.hpp>
|
||||||
|
#include <pd-3ds/bknd-hid.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
void Init(void* data = nullptr);
|
||||||
|
}
|
78
backends/3ds/include/pd-3ds/bknd-gfx.hpp
Executable file
78
backends/3ds/include/pd-3ds/bknd-gfx.hpp
Executable file
@ -0,0 +1,78 @@
|
|||||||
|
#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 <citro3d.h>
|
||||||
|
|
||||||
|
#include <pd/lithium/lithium.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
template <typename T>
|
||||||
|
class LinearAlloc : public Allocator<T> {
|
||||||
|
public:
|
||||||
|
LinearAlloc() = default;
|
||||||
|
~LinearAlloc() = default;
|
||||||
|
|
||||||
|
/** Never forget the sizeof(T) again (most painful bug i created) */
|
||||||
|
T* Allocate(size_t n) override { return (T*)linearAlloc(n * sizeof(T)); }
|
||||||
|
void Deallocate(T* ptr) { linearFree(ptr); }
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace Li {
|
||||||
|
class GfxC3D : public GfxDriver {
|
||||||
|
public:
|
||||||
|
GfxC3D() : GfxDriver("Citro3D") {}
|
||||||
|
~GfxC3D() = default;
|
||||||
|
|
||||||
|
PD_SHARED(GfxC3D);
|
||||||
|
|
||||||
|
void Init() override;
|
||||||
|
void Deinit() override;
|
||||||
|
void NewFrame() override;
|
||||||
|
void BindTex(PD::Li::TexAddress addr) override;
|
||||||
|
void RenderDrawData(
|
||||||
|
const std::vector<PD::Li::Command::Ref>& Commands) override;
|
||||||
|
PD::Li::Texture::Ref LoadTex(
|
||||||
|
const std::vector<PD::u8>& pixels, int w, int h,
|
||||||
|
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
|
||||||
|
PD::Li::Texture::Filter filter =
|
||||||
|
PD::Li::Texture::Filter::LINEAR) override;
|
||||||
|
|
||||||
|
Vec<Vertex, LinearAlloc<Vertex>> VertexBuffer;
|
||||||
|
Vec<u16, LinearAlloc<u16>> IndexBuffer;
|
||||||
|
size_t CurrentVertex = 0;
|
||||||
|
size_t CurrentIndex = 0;
|
||||||
|
Mat4 Projection;
|
||||||
|
int pLocProjection = 0;
|
||||||
|
DVLB_s* ShaderCode;
|
||||||
|
shaderProgram_s Shader;
|
||||||
|
C3D_AttrInfo ShaderInfo;
|
||||||
|
// Stats oder so IDNK zu lange her
|
||||||
|
PD::u32 NumVtx;
|
||||||
|
PD::u32 NumIdx;
|
||||||
|
};
|
||||||
|
} // namespace Li
|
||||||
|
} // namespace PD
|
82
include/pd/lib3ds/drv_hid.hpp → backends/3ds/include/pd-3ds/bknd-hid.hpp
Normal file → Executable file
82
include/pd/lib3ds/drv_hid.hpp → backends/3ds/include/pd-3ds/bknd-hid.hpp
Normal file → Executable file
@ -1,45 +1,39 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
in the Software without restriction, including without limitation the rights
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
in the Software without restriction, including without limitation the rights
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
furnished to do so, subject to the following conditions:
|
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 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,
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
SOFTWARE.
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
*/
|
SOFTWARE.
|
||||||
|
*/
|
||||||
#include <pd/drivers/hid.hpp>
|
|
||||||
|
#include <pd/drivers/drivers.hpp>
|
||||||
namespace PD {
|
|
||||||
/**
|
namespace PD {
|
||||||
* Nintendo 3DS Input Driver
|
class Hid3DS : public HidDriver {
|
||||||
*/
|
public:
|
||||||
class CtrHid : public Hid {
|
Hid3DS();
|
||||||
public:
|
~Hid3DS() = default;
|
||||||
/**
|
|
||||||
* Constructor to setup Key binds
|
PD_SHARED(Hid3DS);
|
||||||
*/
|
|
||||||
CtrHid();
|
void Update() override;
|
||||||
~CtrHid() = default;
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Overrideing the Update Function for Input Checking etc
|
|
||||||
*/
|
|
||||||
void Update() override;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
} // namespace PD
|
250
backends/3ds/source/bknd-gfx.cpp
Executable file
250
backends/3ds/source/bknd-gfx.cpp
Executable file
@ -0,0 +1,250 @@
|
|||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pd-3ds/bknd-gfx.hpp>
|
||||||
|
|
||||||
|
/// @brief Shader Code (Unused as i dont want to use libpicasso here (yet))
|
||||||
|
const char* LIShaderCTR = R"(
|
||||||
|
; LI7 Shader
|
||||||
|
; Constants
|
||||||
|
.constf myconst(0.0, 1.0, 0.00392156862745, 0.0)
|
||||||
|
.alias ones myconst.yyyy ; Vector full of ones
|
||||||
|
|
||||||
|
; Uniforms
|
||||||
|
.fvec projection[4]
|
||||||
|
|
||||||
|
; Outputs
|
||||||
|
.out out_position position
|
||||||
|
.out out_color color
|
||||||
|
.out out_uv texcoord0
|
||||||
|
|
||||||
|
; Inputs
|
||||||
|
.alias in_xy v0
|
||||||
|
.alias in_uvc v1
|
||||||
|
.alias in_col v2
|
||||||
|
|
||||||
|
.entry vmain
|
||||||
|
.proc vmain
|
||||||
|
mov r0.xy, in_xy.xy
|
||||||
|
mov r0.w, ones
|
||||||
|
|
||||||
|
dp4 out_position.x, projection[0], r0
|
||||||
|
dp4 out_position.y, projection[1], r0
|
||||||
|
dp4 out_position.z, projection[2], r0
|
||||||
|
dp4 out_position.w, projection[3], r0
|
||||||
|
|
||||||
|
mov out_uv, in_uvc.xy
|
||||||
|
|
||||||
|
mul r1, myconst.zzzz, in_col
|
||||||
|
mov out_color, r1
|
||||||
|
end
|
||||||
|
.end
|
||||||
|
)";
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
unsigned char li_shader[] = {
|
||||||
|
0x44, 0x56, 0x4c, 0x42, 0x1, 0x0, 0x0, 0x0, 0xa4, 0x0, 0x0, 0x0, 0x44, 0x56, 0x4c, 0x50, 0x0, 0x0, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x50, 0x0, 0x0, 0x0, 0x9, 0x0, 0x0, 0x0, 0x98, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4e, 0x1, 0xf0, 0x7, 0x4e, 0x2, 0x8, 0x2, 0x8, 0x3, 0x18, 0x2, 0x8, 0x4, 0x28, 0x2, 0x8, 0x5, 0x38, 0x2, 0x8, 0x6, 0x10, 0x40, 0x4c, 0x7, 0xf1, 0x27, 0x22, 0x8, 0x10, 0x21, 0x4c, 0x0, 0x0, 0x0, 0x88, 0xac, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa1, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x68, 0xc3, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x64, 0xc3, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x62, 0xc3, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x61, 0xc3, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0xaf, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4f, 0xd5, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6f, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x56, 0x4c, 0x45, 0x2, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x54, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x54, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x6c, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x74, 0x0, 0x0, 0x0, 0xb, 0x0, 0x0, 0x0, 0x2, 0x0, 0x5f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3f, 0x0, 0x1, 0x1, 0x37, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0x0, 0x0, 0x0, 0x2, 0x0, 0x1, 0x0, 0xf, 0x0, 0x0, 0x0, 0x3, 0x0, 0x2, 0x0, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x13, 0x0, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0, 0x0,
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
|
size_t li_shader_size = 0x124;
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
namespace Li {
|
||||||
|
GPU_TEXCOLOR GetTexFmt(Texture::Type type) {
|
||||||
|
if (type == Texture::RGBA32)
|
||||||
|
return GPU_RGBA8;
|
||||||
|
else if (type == Texture::RGB24)
|
||||||
|
return GPU_RGB8;
|
||||||
|
else if (type == Texture::A8)
|
||||||
|
return GPU_A8;
|
||||||
|
return GPU_RGBA8; // Default
|
||||||
|
}
|
||||||
|
int GetBPP(Texture::Type type) {
|
||||||
|
if (type == Texture::RGBA32)
|
||||||
|
return 4;
|
||||||
|
else if (type == Texture::RGB24)
|
||||||
|
return 3;
|
||||||
|
else if (type == Texture::A8)
|
||||||
|
return 1;
|
||||||
|
return 0; // Error
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxC3D::Init() {
|
||||||
|
VertexBuffer.Resize(4 * 8192);
|
||||||
|
IndexBuffer.Resize(6 * 8192);
|
||||||
|
|
||||||
|
Flags |= LiBackendFlags_FlipUV_Y;
|
||||||
|
|
||||||
|
ShaderCode = DVLB_ParseFile((uint32_t*)li_shader, li_shader_size);
|
||||||
|
shaderProgramInit(&Shader);
|
||||||
|
shaderProgramSetVsh(&Shader, &ShaderCode->DVLE[0]);
|
||||||
|
pLocProjection =
|
||||||
|
shaderInstanceGetUniformLocation(Shader.vertexShader, "projection");
|
||||||
|
|
||||||
|
AttrInfo_Init(&ShaderInfo);
|
||||||
|
AttrInfo_AddLoader(&ShaderInfo, 0, GPU_FLOAT, 2);
|
||||||
|
AttrInfo_AddLoader(&ShaderInfo, 1, GPU_FLOAT, 2);
|
||||||
|
AttrInfo_AddLoader(&ShaderInfo, 2, GPU_UNSIGNED_BYTE, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxC3D::Deinit() {
|
||||||
|
shaderProgramFree(&Shader);
|
||||||
|
DVLB_Free(ShaderCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxC3D::NewFrame() {
|
||||||
|
C3D_BindProgram(&Shader);
|
||||||
|
C3D_SetAttrInfo(&ShaderInfo);
|
||||||
|
CurrentIndex = 0;
|
||||||
|
CurrentVertex = 0;
|
||||||
|
FrameCounter++;
|
||||||
|
VertexCounter = NumVtx;
|
||||||
|
IndexCounter = NumIdx;
|
||||||
|
NumVtx = 0;
|
||||||
|
NumIdx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxC3D::BindTex(PD::Li::TexAddress addr) {
|
||||||
|
C3D_TexBind(0, reinterpret_cast<C3D_Tex*>(addr));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxC3D::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
|
||||||
|
C3D_BindProgram(&Shader);
|
||||||
|
C3D_SetAttrInfo(&ShaderInfo);
|
||||||
|
C3D_Mtx proj;
|
||||||
|
Mtx_OrthoTilt(&proj, 0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f, false);
|
||||||
|
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, &proj);
|
||||||
|
C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL);
|
||||||
|
C3D_TexEnv* env = C3D_GetTexEnv(0);
|
||||||
|
C3D_TexEnvInit(env);
|
||||||
|
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0);
|
||||||
|
C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
|
||||||
|
size_t index = 0;
|
||||||
|
while (index < Commands.size()) {
|
||||||
|
PD::Li::Texture::Ref Tex = Commands[index]->Tex;
|
||||||
|
if (!Tex) {
|
||||||
|
index++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
bool ScissorEnabled = Commands[index]->ScissorOn;
|
||||||
|
ivec4 ScissorRect = Commands[index]->ScissorRect;
|
||||||
|
size_t StartIndex = CurrentIndex;
|
||||||
|
|
||||||
|
while (index < Commands.size() && Commands[index]->Tex == Tex &&
|
||||||
|
Commands[index]->ScissorOn == ScissorEnabled &&
|
||||||
|
Commands[index]->ScissorRect == ScissorRect) {
|
||||||
|
auto c = Commands[index].get();
|
||||||
|
for (size_t i = 0; i < c->IndexBuffer.Size(); i++) {
|
||||||
|
NumIdx++;
|
||||||
|
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i);
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < c->VertexBuffer.Size(); i++) {
|
||||||
|
NumVtx++;
|
||||||
|
VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i);
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
if (ScissorEnabled) {
|
||||||
|
// Figure out this setup was pain
|
||||||
|
C3D_SetScissor(GPU_SCISSOR_NORMAL,
|
||||||
|
ViewPort.y - (ScissorRect.y + ScissorRect.w),
|
||||||
|
ViewPort.x - (ScissorRect.x + ScissorRect.z),
|
||||||
|
ViewPort.y - ScissorRect.y, ViewPort.x - ScissorRect.x);
|
||||||
|
} else {
|
||||||
|
C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
BindTex(Tex->Address);
|
||||||
|
auto bufInfo = C3D_GetBufInfo();
|
||||||
|
BufInfo_Init(bufInfo);
|
||||||
|
BufInfo_Add(bufInfo, VertexBuffer.Data(), sizeof(Vertex), 3, 0x210);
|
||||||
|
|
||||||
|
C3D_DrawElements(GPU_TRIANGLES, CurrentIndex - StartIndex,
|
||||||
|
C3D_UNSIGNED_SHORT, IndexBuffer.Data() + StartIndex);
|
||||||
|
}
|
||||||
|
C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
PD::Li::Texture::Ref GfxC3D::LoadTex(const std::vector<PD::u8>& pixels, int w,
|
||||||
|
int h, PD::Li::Texture::Type type,
|
||||||
|
PD::Li::Texture::Filter filter) {
|
||||||
|
if (w > 1024 || h > 1024) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
// Don't check here as check done before
|
||||||
|
PD::Li::Texture::Ref res = PD::Li::Texture::New();
|
||||||
|
int bpp = GetBPP(type);
|
||||||
|
ivec2 tex_size(w, h);
|
||||||
|
// Pow2
|
||||||
|
if (!PD::BitUtil::IsSingleBit(w)) {
|
||||||
|
tex_size.x = PD::BitUtil::GetPow2((unsigned int)w);
|
||||||
|
}
|
||||||
|
if (!PD::BitUtil::IsSingleBit(h)) {
|
||||||
|
tex_size.y = PD::BitUtil::GetPow2((unsigned int)h);
|
||||||
|
}
|
||||||
|
res->Size.x = w;
|
||||||
|
res->Size.y = h;
|
||||||
|
res->UV = fvec4(0.f, 1.f, ((float)w / (float)tex_size.x),
|
||||||
|
1.0 - ((float)h / (float)tex_size.y));
|
||||||
|
|
||||||
|
// Texture Setup
|
||||||
|
auto fltr = (filter == Texture::NEAREST ? GPU_NEAREST : GPU_LINEAR);
|
||||||
|
auto tex_fmt = GetTexFmt(type);
|
||||||
|
auto tex = new C3D_Tex;
|
||||||
|
C3D_TexInit(tex, (u16)tex_size.x, (u16)tex_size.y, tex_fmt);
|
||||||
|
C3D_TexSetFilter(tex, fltr, fltr);
|
||||||
|
|
||||||
|
// Using std::fill_n instead cause i hate this error lines
|
||||||
|
// under the memset func in my editor
|
||||||
|
std::fill_n((PD::u8*)tex->data, tex->size, 0);
|
||||||
|
// memset(tex->data, 0, tex->size);s
|
||||||
|
|
||||||
|
/// Probably Remove this if statement in future
|
||||||
|
/// This are the things confirmed as working
|
||||||
|
if (bpp == 3 || bpp == 4 || bpp == 1) {
|
||||||
|
for (int x = 0; x < w; x++) {
|
||||||
|
for (int y = 0; y < h; y++) {
|
||||||
|
int dst_pos = ((((y >> 3) * ((int)tex_size.x >> 3) + (x >> 3)) << 6) +
|
||||||
|
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
|
||||||
|
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
|
||||||
|
bpp;
|
||||||
|
int src_pos = (y * w + x) * bpp;
|
||||||
|
/// Best idea i had
|
||||||
|
for (int i = 0; i < bpp; i++) {
|
||||||
|
((u8*)tex->data)[dst_pos + bpp - 1 - i] = pixels[src_pos + i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
C3D_TexFlush(tex);
|
||||||
|
}
|
||||||
|
|
||||||
|
tex->border = 0x00000000;
|
||||||
|
C3D_TexSetWrap(tex, GPU_REPEAT, GPU_REPEAT);
|
||||||
|
res->Address = (TexAddress)tex;
|
||||||
|
std::cout << std::format("Tex {:#08x} Addr {:#08X}", (TexAddress)res.get(),
|
||||||
|
res->Address)
|
||||||
|
<< std::endl;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
} // namespace Li
|
||||||
|
} // namespace PD
|
170
source/lib3ds/drv_hid.cpp → backends/3ds/source/bknd-hid.cpp
Normal file → Executable file
170
source/lib3ds/drv_hid.cpp → backends/3ds/source/bknd-hid.cpp
Normal file → Executable file
@ -1,87 +1,85 @@
|
|||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
in the Software without restriction, including without limitation the rights
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
in the Software without restriction, including without limitation the rights
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
furnished to do so, subject to the following conditions:
|
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 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,
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
SOFTWARE.
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
*/
|
SOFTWARE.
|
||||||
|
*/
|
||||||
#include <3ds.h>
|
|
||||||
|
#include <3ds.h>
|
||||||
#include <pd/lib3ds/drv_hid.hpp>
|
|
||||||
|
#include <pd-3ds/bknd-hid.hpp>
|
||||||
/// Reform of the RenderD7 095 Hid Api
|
|
||||||
/// Using Custom Keybindings for future
|
namespace PD {
|
||||||
/// Porting of the library
|
Hid3DS::Hid3DS() : HidDriver("Hid3DS") {
|
||||||
|
pBinds[KEY_A] = A;
|
||||||
namespace PD {
|
pBinds[KEY_B] = B;
|
||||||
CtrHid::CtrHid() {
|
pBinds[KEY_X] = X;
|
||||||
binds[KEY_A] = A;
|
pBinds[KEY_Y] = Y;
|
||||||
binds[KEY_B] = B;
|
pBinds[KEY_START] = Start;
|
||||||
binds[KEY_X] = X;
|
pBinds[KEY_SELECT] = Select;
|
||||||
binds[KEY_Y] = Y;
|
pBinds[KEY_L] = L;
|
||||||
binds[KEY_START] = Start;
|
pBinds[KEY_R] = R;
|
||||||
binds[KEY_SELECT] = Select;
|
pBinds[KEY_DUP] = DUp;
|
||||||
binds[KEY_L] = L;
|
pBinds[KEY_DDOWN] = DDown;
|
||||||
binds[KEY_R] = R;
|
pBinds[KEY_DLEFT] = DLeft;
|
||||||
binds[KEY_DUP] = DUp;
|
pBinds[KEY_DRIGHT] = DRight;
|
||||||
binds[KEY_DDOWN] = DDown;
|
pBinds[KEY_CPAD_UP] = CPUp;
|
||||||
binds[KEY_DLEFT] = DLeft;
|
pBinds[KEY_CPAD_DOWN] = CPDown;
|
||||||
binds[KEY_DRIGHT] = DRight;
|
pBinds[KEY_CPAD_LEFT] = CPLeft;
|
||||||
binds[KEY_CPAD_UP] = CPUp;
|
pBinds[KEY_CPAD_RIGHT] = CPRight;
|
||||||
binds[KEY_CPAD_DOWN] = CPDown;
|
pBinds[KEY_CSTICK_UP] = CSUp;
|
||||||
binds[KEY_CPAD_LEFT] = CPLeft;
|
pBinds[KEY_CSTICK_DOWN] = CSDown;
|
||||||
binds[KEY_CPAD_RIGHT] = CPRight;
|
pBinds[KEY_CSTICK_LEFT] = CSLeft;
|
||||||
binds[KEY_CSTICK_UP] = CSUp;
|
pBinds[KEY_CSTICK_RIGHT] = CSRight;
|
||||||
binds[KEY_CSTICK_DOWN] = CSDown;
|
pBinds[KEY_ZL] = ZL;
|
||||||
binds[KEY_CSTICK_LEFT] = CSLeft;
|
pBinds[KEY_ZR] = ZR;
|
||||||
binds[KEY_CSTICK_RIGHT] = CSRight;
|
pBinds[KEY_TOUCH] = Touch;
|
||||||
binds[KEY_ZL] = ZL;
|
}
|
||||||
binds[KEY_ZR] = ZR;
|
|
||||||
binds[KEY_TOUCH] = Touch;
|
void Hid3DS::Update() {
|
||||||
}
|
hidScanInput();
|
||||||
void CtrHid::Update() {
|
for (int i = 0; i < 2; i++) {
|
||||||
hidScanInput();
|
KeyEvents[i][Event_Down] = 0;
|
||||||
for (int i = 0; i < 2; i++) {
|
KeyEvents[i][Event_Held] = 0;
|
||||||
key_events[i][Event_Down] = 0;
|
KeyEvents[i][Event_Up] = 0;
|
||||||
key_events[i][Event_Held] = 0;
|
}
|
||||||
key_events[i][Event_Up] = 0;
|
u32 kd = hidKeysDown();
|
||||||
}
|
u32 kh = hidKeysHeld();
|
||||||
u32 kd = hidKeysDown();
|
u32 ku = hidKeysUp();
|
||||||
u32 kh = hidKeysHeld();
|
for (auto &b : pBinds) {
|
||||||
u32 ku = hidKeysUp();
|
if (b.first & kd) {
|
||||||
for (auto &b : binds) {
|
KeyEvents[0][Event_Down] |= b.second;
|
||||||
if (b.first & kd) {
|
}
|
||||||
key_events[0][Event_Down] |= b.second;
|
if (b.first & kh) {
|
||||||
}
|
KeyEvents[0][Event_Held] |= b.second;
|
||||||
if (b.first & kh) {
|
}
|
||||||
key_events[0][Event_Held] |= b.second;
|
if (b.first & ku) {
|
||||||
}
|
KeyEvents[0][Event_Up] |= b.second;
|
||||||
if (b.first & ku) {
|
}
|
||||||
key_events[0][Event_Up] |= b.second;
|
}
|
||||||
}
|
if (pLocked) {
|
||||||
}
|
SwapTab();
|
||||||
if (locked) {
|
}
|
||||||
SwappyTable();
|
touchPosition t;
|
||||||
}
|
hidTouchRead(&t);
|
||||||
touchPosition t;
|
pMouse[1] = pMouse[0]; // Cycle pMouse pos
|
||||||
hidTouchRead(&t);
|
pMouse[0] = fvec2(t.px, t.py);
|
||||||
touch[1] = touch[0]; // Cycle touch pos
|
}
|
||||||
touch[0] = vec2(t.px, t.py);
|
|
||||||
}
|
|
||||||
} // namespace PD
|
} // namespace PD
|
36
backends/3ds/source/pd-3ds.cpp
Executable file
36
backends/3ds/source/pd-3ds.cpp
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <palladium>
|
||||||
|
#include <pd-3ds.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
void Init(void* data) {
|
||||||
|
// Dekstop Init Stage
|
||||||
|
// First use default OS Driver
|
||||||
|
PD::OS::Init();
|
||||||
|
PD::Li::Gfx::Init(PD::Li::GfxC3D::New());
|
||||||
|
PD::Hid::Init(PD::Hid3DS::New());
|
||||||
|
}
|
||||||
|
} // namespace PD
|
16
backends/desktop/CMakeLists.txt
Executable file
16
backends/desktop/CMakeLists.txt
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.22)
|
||||||
|
|
||||||
|
project(pd-desktop LANGUAGES CXX VERSION 0.5.0)
|
||||||
|
|
||||||
|
add_subdirectory(glad)
|
||||||
|
add_subdirectory(glfw)
|
||||||
|
|
||||||
|
set(SRC
|
||||||
|
source/bknd-gfx.cpp
|
||||||
|
source/bknd-hid.cpp
|
||||||
|
source/pd-desktop.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
pd_add_lib(pd-desktop SRC_FILES ${SRC})
|
||||||
|
target_include_directories(pd-desktop PUBLIC include)
|
||||||
|
target_link_libraries(pd-desktop PUBLIC palladium glad glfw)
|
4
backends/desktop/glad/CMakeLists.txt
Executable file
4
backends/desktop/glad/CMakeLists.txt
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.22)
|
||||||
|
|
||||||
|
add_library(glad source/glad.c)
|
||||||
|
target_include_directories(glad PUBLIC include)
|
311
backends/desktop/glad/include/KHR/khrplatform.h
Executable file
311
backends/desktop/glad/include/KHR/khrplatform.h
Executable file
@ -0,0 +1,311 @@
|
|||||||
|
#ifndef __khrplatform_h_
|
||||||
|
#define __khrplatform_h_
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||||
|
**
|
||||||
|
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
** copy of this software and/or associated documentation files (the
|
||||||
|
** "Materials"), to deal in the Materials without restriction, including
|
||||||
|
** without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||||
|
** permit persons to whom the Materials are 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 Materials.
|
||||||
|
**
|
||||||
|
** THE MATERIALS ARE 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
|
||||||
|
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Khronos platform-specific types and definitions.
|
||||||
|
*
|
||||||
|
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||||
|
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||||
|
* The last semantic modification to khrplatform.h was at commit ID:
|
||||||
|
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||||
|
*
|
||||||
|
* Adopters may modify this file to suit their platform. Adopters are
|
||||||
|
* encouraged to submit platform specific modifications to the Khronos
|
||||||
|
* group so that they can be included in future versions of this file.
|
||||||
|
* Please submit changes by filing pull requests or issues on
|
||||||
|
* the EGL Registry repository linked above.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* See the Implementer's Guidelines for information about where this file
|
||||||
|
* should be located on your system and for more details of its use:
|
||||||
|
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||||
|
*
|
||||||
|
* This file should be included as
|
||||||
|
* #include <KHR/khrplatform.h>
|
||||||
|
* by Khronos client API header files that use its types and defines.
|
||||||
|
*
|
||||||
|
* The types in khrplatform.h should only be used to define API-specific types.
|
||||||
|
*
|
||||||
|
* Types defined in khrplatform.h:
|
||||||
|
* khronos_int8_t signed 8 bit
|
||||||
|
* khronos_uint8_t unsigned 8 bit
|
||||||
|
* khronos_int16_t signed 16 bit
|
||||||
|
* khronos_uint16_t unsigned 16 bit
|
||||||
|
* khronos_int32_t signed 32 bit
|
||||||
|
* khronos_uint32_t unsigned 32 bit
|
||||||
|
* khronos_int64_t signed 64 bit
|
||||||
|
* khronos_uint64_t unsigned 64 bit
|
||||||
|
* khronos_intptr_t signed same number of bits as a pointer
|
||||||
|
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||||
|
* khronos_ssize_t signed size
|
||||||
|
* khronos_usize_t unsigned size
|
||||||
|
* khronos_float_t signed 32 bit floating point
|
||||||
|
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||||
|
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||||
|
* nanoseconds
|
||||||
|
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||||
|
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||||
|
* only be used as a base type when a client API's boolean type is
|
||||||
|
* an enum. Client APIs which use an integer or other type for
|
||||||
|
* booleans cannot use this as the base type for their boolean.
|
||||||
|
*
|
||||||
|
* Tokens defined in khrplatform.h:
|
||||||
|
*
|
||||||
|
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||||
|
*
|
||||||
|
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||||
|
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||||
|
*
|
||||||
|
* Calling convention macros defined in this file:
|
||||||
|
* KHRONOS_APICALL
|
||||||
|
* KHRONOS_APIENTRY
|
||||||
|
* KHRONOS_APIATTRIBUTES
|
||||||
|
*
|
||||||
|
* These may be used in function prototypes as:
|
||||||
|
*
|
||||||
|
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||||
|
* int arg1,
|
||||||
|
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||||
|
# define KHRONOS_STATIC 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APICALL
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This precedes the return type of the function in the function prototype.
|
||||||
|
*/
|
||||||
|
#if defined(KHRONOS_STATIC)
|
||||||
|
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||||
|
* header compatible with static linking. */
|
||||||
|
# define KHRONOS_APICALL
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
# define KHRONOS_APICALL __declspec(dllimport)
|
||||||
|
#elif defined (__SYMBIAN32__)
|
||||||
|
# define KHRONOS_APICALL IMPORT_C
|
||||||
|
#elif defined(__ANDROID__)
|
||||||
|
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
# define KHRONOS_APICALL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APIENTRY
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This follows the return type of the function and precedes the function
|
||||||
|
* name in the function prototype.
|
||||||
|
*/
|
||||||
|
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||||
|
/* Win32 but not WinCE */
|
||||||
|
# define KHRONOS_APIENTRY __stdcall
|
||||||
|
#else
|
||||||
|
# define KHRONOS_APIENTRY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APIATTRIBUTES
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This follows the closing parenthesis of the function prototype arguments.
|
||||||
|
*/
|
||||||
|
#if defined (__ARMCC_2__)
|
||||||
|
#define KHRONOS_APIATTRIBUTES __softfp
|
||||||
|
#else
|
||||||
|
#define KHRONOS_APIATTRIBUTES
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* basic type definitions
|
||||||
|
*-----------------------------------------------------------------------*/
|
||||||
|
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using <stdint.h>
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
/*
|
||||||
|
* To support platform where unsigned long cannot be used interchangeably with
|
||||||
|
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
||||||
|
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
||||||
|
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
||||||
|
* unsigned long long or similar (this results in different C++ name mangling).
|
||||||
|
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
||||||
|
* platforms where the size of a pointer is larger than the size of long.
|
||||||
|
*/
|
||||||
|
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
||||||
|
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
||||||
|
#define KHRONOS_USE_INTPTR_T
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(__VMS ) || defined(__sgi)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using <inttypes.h>
|
||||||
|
*/
|
||||||
|
#include <inttypes.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Win32
|
||||||
|
*/
|
||||||
|
typedef __int32 khronos_int32_t;
|
||||||
|
typedef unsigned __int32 khronos_uint32_t;
|
||||||
|
typedef __int64 khronos_int64_t;
|
||||||
|
typedef unsigned __int64 khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(__sun__) || defined(__digital__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sun or Digital
|
||||||
|
*/
|
||||||
|
typedef int khronos_int32_t;
|
||||||
|
typedef unsigned int khronos_uint32_t;
|
||||||
|
#if defined(__arch64__) || defined(_LP64)
|
||||||
|
typedef long int khronos_int64_t;
|
||||||
|
typedef unsigned long int khronos_uint64_t;
|
||||||
|
#else
|
||||||
|
typedef long long int khronos_int64_t;
|
||||||
|
typedef unsigned long long int khronos_uint64_t;
|
||||||
|
#endif /* __arch64__ */
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif 0
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hypothetical platform with no float or int64 support
|
||||||
|
*/
|
||||||
|
typedef int khronos_int32_t;
|
||||||
|
typedef unsigned int khronos_uint32_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 0
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 0
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic fallback
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types that are (so far) the same on all platforms
|
||||||
|
*/
|
||||||
|
typedef signed char khronos_int8_t;
|
||||||
|
typedef unsigned char khronos_uint8_t;
|
||||||
|
typedef signed short int khronos_int16_t;
|
||||||
|
typedef unsigned short int khronos_uint16_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||||
|
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||||
|
* to be the only LLP64 architecture in current use.
|
||||||
|
*/
|
||||||
|
#ifdef KHRONOS_USE_INTPTR_T
|
||||||
|
typedef intptr_t khronos_intptr_t;
|
||||||
|
typedef uintptr_t khronos_uintptr_t;
|
||||||
|
#elif defined(_WIN64)
|
||||||
|
typedef signed long long int khronos_intptr_t;
|
||||||
|
typedef unsigned long long int khronos_uintptr_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_intptr_t;
|
||||||
|
typedef unsigned long int khronos_uintptr_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN64)
|
||||||
|
typedef signed long long int khronos_ssize_t;
|
||||||
|
typedef unsigned long long int khronos_usize_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_ssize_t;
|
||||||
|
typedef unsigned long int khronos_usize_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KHRONOS_SUPPORT_FLOAT
|
||||||
|
/*
|
||||||
|
* Float type
|
||||||
|
*/
|
||||||
|
typedef float khronos_float_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KHRONOS_SUPPORT_INT64
|
||||||
|
/* Time types
|
||||||
|
*
|
||||||
|
* These types can be used to represent a time interval in nanoseconds or
|
||||||
|
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||||
|
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||||
|
* time the system booted). The Unadjusted System Time is an unsigned
|
||||||
|
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||||
|
* may be either signed or unsigned.
|
||||||
|
*/
|
||||||
|
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||||
|
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dummy value used to pad enum types to 32 bits.
|
||||||
|
*/
|
||||||
|
#ifndef KHRONOS_MAX_ENUM
|
||||||
|
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enumerated boolean type
|
||||||
|
*
|
||||||
|
* Values other than zero should be considered to be true. Therefore
|
||||||
|
* comparisons should not be made against KHRONOS_TRUE.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
KHRONOS_FALSE = 0,
|
||||||
|
KHRONOS_TRUE = 1,
|
||||||
|
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||||
|
} khronos_boolean_enum_t;
|
||||||
|
|
||||||
|
#endif /* __khrplatform_h_ */
|
5169
backends/desktop/glad/include/glad/glad.h
Executable file
5169
backends/desktop/glad/include/glad/glad.h
Executable file
File diff suppressed because it is too large
Load Diff
2532
backends/desktop/glad/source/glad.c
Executable file
2532
backends/desktop/glad/source/glad.c
Executable file
File diff suppressed because it is too large
Load Diff
1
backends/desktop/glfw
Submodule
1
backends/desktop/glfw
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit e7ea71be039836da3a98cea55ae5569cb5eb885c
|
32
backends/desktop/include/pd-desktop.hpp
Executable file
32
backends/desktop/include/pd-desktop.hpp
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pd-desktop/bknd-gfx.hpp>
|
||||||
|
#include <pd-desktop/bknd-hid.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
void Init(void* data = nullptr);
|
||||||
|
}
|
130
include/pd/sound/mp3.hpp → backends/desktop/include/pd-desktop/bknd-gfx.hpp
Normal file → Executable file
130
include/pd/sound/mp3.hpp → backends/desktop/include/pd-desktop/bknd-gfx.hpp
Normal file → Executable file
@ -1,62 +1,70 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
in the Software without restriction, including without limitation the rights
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
in the Software without restriction, including without limitation the rights
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
furnished to do so, subject to the following conditions:
|
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 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,
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
SOFTWARE.
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
*/
|
SOFTWARE.
|
||||||
|
*/
|
||||||
#include <mpg123.h>
|
|
||||||
|
#include <glad/glad.h>
|
||||||
#include <pd/sound/decoder.hpp>
|
|
||||||
|
/** SEPARATOR */
|
||||||
namespace PD {
|
#include <GLFW/glfw3.h>
|
||||||
namespace Music {
|
/** SEPARATOR */
|
||||||
/**
|
|
||||||
* MP3 Decoder
|
#include <pd/lithium/lithium.hpp>
|
||||||
*/
|
|
||||||
class Mp3Decoder : public Decoder {
|
namespace PD {
|
||||||
public:
|
namespace Li {
|
||||||
Mp3Decoder() = default;
|
class GfxGL2 : public GfxDriver {
|
||||||
~Mp3Decoder() = default;
|
public:
|
||||||
|
GfxGL2() : GfxDriver("OpenGL2") {}
|
||||||
/** Init Funciton to load file and Init decoder */
|
~GfxGL2() = default;
|
||||||
int Init(const std::string& path) override;
|
|
||||||
/** Unload Decoder */
|
PD_SHARED(GfxGL2);
|
||||||
void Deinit() override;
|
|
||||||
/** Get Sample Rate */
|
void Init() override;
|
||||||
u32 GetSampleRate() override;
|
void Deinit() override;
|
||||||
/** Get Channels */
|
void NewFrame() override;
|
||||||
u8 GetChannels() override;
|
void BindTex(PD::Li::TexAddress addr) override;
|
||||||
/** Get Buffer Size */
|
void RenderDrawData(
|
||||||
size_t GetBufSize() override;
|
const std::vector<PD::Li::Command::Ref>& Commands) override;
|
||||||
/** Decode next data */
|
PD::Li::Texture::Ref LoadTex(
|
||||||
u64 Decode(u16* buf_address) override;
|
const std::vector<PD::u8>& pixels, int w, int h,
|
||||||
/** Get File Samples if exist */
|
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
|
||||||
size_t GetFileSamples() override;
|
PD::Li::Texture::Filter filter =
|
||||||
|
PD::Li::Texture::Filter::LINEAR) override;
|
||||||
private:
|
|
||||||
mpg123_handle* handle = nullptr;
|
PD::Vec<Vertex> VertexBuffer;
|
||||||
size_t buf_size = 0;
|
PD::Vec<PD::u16> IndexBuffer;
|
||||||
u32 rate = 0;
|
size_t CurrentVertex = 0;
|
||||||
u8 channels = 0;
|
size_t CurrentIndex = 0;
|
||||||
};
|
GLuint Shader;
|
||||||
} // namespace Music
|
GLuint pLocProjection;
|
||||||
|
GLuint pLocTex;
|
||||||
|
Mat4 Projection;
|
||||||
|
GLuint VBO, IBO;
|
||||||
|
// Stats oder so IDNK zu lange her
|
||||||
|
PD::u32 NumVtx;
|
||||||
|
PD::u32 NumIdx;
|
||||||
|
};
|
||||||
|
} // namespace Li
|
||||||
} // namespace PD
|
} // namespace PD
|
45
backends/desktop/include/pd-desktop/bknd-hid.hpp
Executable file
45
backends/desktop/include/pd-desktop/bknd-hid.hpp
Executable file
@ -0,0 +1,45 @@
|
|||||||
|
#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 <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#include <pd/drivers/drivers.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
class HidGLFW : public HidDriver {
|
||||||
|
public:
|
||||||
|
HidGLFW(GLFWwindow* win);
|
||||||
|
~HidGLFW() = default;
|
||||||
|
|
||||||
|
PD_SHARED(HidGLFW);
|
||||||
|
|
||||||
|
void Update() override;
|
||||||
|
|
||||||
|
/** Data section */
|
||||||
|
GLFWwindow* Window;
|
||||||
|
int PrevState;
|
||||||
|
};
|
||||||
|
} // namespace PD
|
252
backends/desktop/source/bknd-gfx.cpp
Executable file
252
backends/desktop/source/bknd-gfx.cpp
Executable file
@ -0,0 +1,252 @@
|
|||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pd-desktop/bknd-gfx.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
namespace Li {
|
||||||
|
const char* vertex_shader = R"(
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
attribute vec2 pos;
|
||||||
|
attribute vec2 uv;
|
||||||
|
attribute vec4 color;
|
||||||
|
|
||||||
|
varying vec2 oUV;
|
||||||
|
varying vec4 oColor;
|
||||||
|
|
||||||
|
// Probably forgot about this matric and
|
||||||
|
// searched hours for why the rendering isn't working :/
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = projection*vec4(pos, 0.0, 1.0);
|
||||||
|
oUV = uv;
|
||||||
|
oColor = color;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
const char* frag_shader = R"(
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
varying vec2 oUV;
|
||||||
|
varying vec4 oColor;
|
||||||
|
|
||||||
|
uniform sampler2D tex;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 tc = texture2D(tex, oUV);
|
||||||
|
gl_FragColor = tc*oColor;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
GLuint compileShader(const std::string& source, GLenum type) {
|
||||||
|
GLuint shader = glCreateShader(type);
|
||||||
|
const char* src = source.c_str();
|
||||||
|
glShaderSource(shader, 1, &src, nullptr);
|
||||||
|
glCompileShader(shader);
|
||||||
|
|
||||||
|
GLint success;
|
||||||
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||||
|
if (!success) {
|
||||||
|
char infoLog[512];
|
||||||
|
glGetShaderInfoLog(shader, 512, nullptr, infoLog);
|
||||||
|
std::cerr << "Shader Compilation Error: " << infoLog << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint createShaderProgram(const std::string& vertexShaderSource,
|
||||||
|
const std::string& fragmentShaderSource) {
|
||||||
|
GLuint vertexShader = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
||||||
|
GLuint fragmentShader =
|
||||||
|
compileShader(fragmentShaderSource, GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
GLuint shaderProgram = glCreateProgram();
|
||||||
|
glAttachShader(shaderProgram, vertexShader);
|
||||||
|
glAttachShader(shaderProgram, fragmentShader);
|
||||||
|
glLinkProgram(shaderProgram);
|
||||||
|
|
||||||
|
GLint success;
|
||||||
|
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
|
||||||
|
if (!success) {
|
||||||
|
char infoLog[512];
|
||||||
|
glGetProgramInfoLog(shaderProgram, 512, nullptr, infoLog);
|
||||||
|
std::cerr << "Shader Program Linking Error: " << infoLog << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
glDeleteShader(vertexShader);
|
||||||
|
glDeleteShader(fragmentShader);
|
||||||
|
|
||||||
|
return shaderProgram;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Actual Backend */
|
||||||
|
|
||||||
|
void GfxGL2::Init() {
|
||||||
|
VertexBuffer.Resize(4 * 8192);
|
||||||
|
IndexBuffer.Resize(6 * 8192);
|
||||||
|
Shader = createShaderProgram(vertex_shader, frag_shader);
|
||||||
|
glUseProgram(Shader);
|
||||||
|
|
||||||
|
glGenBuffers(1, &VBO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
|
||||||
|
GLint _pos = glGetAttribLocation(Shader, "pos");
|
||||||
|
GLint _uv = glGetAttribLocation(Shader, "uv");
|
||||||
|
GLint _color = glGetAttribLocation(Shader, "color");
|
||||||
|
glVertexAttribPointer(_pos, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||||
|
(void*)offsetof(PD::Li::Vertex, Pos));
|
||||||
|
glEnableVertexAttribArray(_pos);
|
||||||
|
|
||||||
|
glVertexAttribPointer(_uv, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||||
|
(void*)offsetof(PD::Li::Vertex, UV));
|
||||||
|
glEnableVertexAttribArray(_uv);
|
||||||
|
|
||||||
|
glVertexAttribPointer(_color, 4, GL_UNSIGNED_BYTE, GL_TRUE,
|
||||||
|
sizeof(PD::Li::Vertex),
|
||||||
|
(void*)offsetof(PD::Li::Vertex, Color));
|
||||||
|
glEnableVertexAttribArray(_color);
|
||||||
|
|
||||||
|
glGenBuffers(1, &IBO);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||||
|
|
||||||
|
pLocTex = glGetUniformLocation(Shader, "tex");
|
||||||
|
pLocProjection = glGetUniformLocation(Shader, "projection");
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxGL2::Deinit() {
|
||||||
|
glDeleteBuffers(1, &VBO);
|
||||||
|
glDeleteBuffers(1, &IBO);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxGL2::NewFrame() {
|
||||||
|
glViewport(0, 0, ViewPort.x, ViewPort.y);
|
||||||
|
glClearColor(ClearColor.x, ClearColor.y, ClearColor.z, ClearColor.w);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
Projection.Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, -1.f, 1.f);
|
||||||
|
glUniformMatrix4fv(pLocProjection, 1, GL_TRUE, Projection.m);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
CurrentIndex = 0;
|
||||||
|
CurrentVertex = 0;
|
||||||
|
FrameCounter++;
|
||||||
|
VertexCounter = NumVtx;
|
||||||
|
IndexCounter = NumIdx;
|
||||||
|
NumVtx = 0;
|
||||||
|
NumIdx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxGL2::BindTex(PD::Li::TexAddress addr) {
|
||||||
|
// Actually not using the Address as Address
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, (GLuint)addr);
|
||||||
|
glUniform1i(pLocTex, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxGL2::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
|
||||||
|
glUseProgram(Shader);
|
||||||
|
size_t index = 0;
|
||||||
|
while (index < Commands.size()) {
|
||||||
|
PD::Li::Texture::Ref Tex = Commands[index]->Tex;
|
||||||
|
if (!Tex) {
|
||||||
|
index++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
size_t StartIndex = CurrentIndex;
|
||||||
|
bool ScissorOn = Commands[index]->ScissorOn;
|
||||||
|
ivec4 ScissorRect = Commands[index]->ScissorRect;
|
||||||
|
|
||||||
|
while (index < Commands.size() && Commands[index]->Tex == Tex &&
|
||||||
|
Commands[index]->ScissorOn == ScissorOn &&
|
||||||
|
Commands[index]->ScissorRect == ScissorRect) {
|
||||||
|
auto c = Commands[index].get();
|
||||||
|
for (size_t i = 0; i < c->IndexBuffer.Size(); i++) {
|
||||||
|
NumIdx++;
|
||||||
|
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i);
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < c->VertexBuffer.Size(); i++) {
|
||||||
|
NumVtx++;
|
||||||
|
VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i);
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
if (ScissorOn) {
|
||||||
|
glScissor(ScissorRect.x, ViewPort.y - (ScissorRect.y + ScissorRect.w),
|
||||||
|
ScissorRect.z, ScissorRect.w);
|
||||||
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
} else {
|
||||||
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
}
|
||||||
|
BindTex(Tex->Address);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
|
||||||
|
&VertexBuffer[0], GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(PD::u16),
|
||||||
|
&IndexBuffer[0], GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
glDrawElements(GL_TRIANGLES, CurrentIndex - StartIndex, GL_UNSIGNED_SHORT,
|
||||||
|
(void*)(StartIndex * sizeof(PD::u16)));
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
BindTex(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PD::Li::Texture::Ref GfxGL2::LoadTex(const std::vector<PD::u8>& pixels, int w,
|
||||||
|
int h, PD::Li::Texture::Type type,
|
||||||
|
PD::Li::Texture::Filter filter) {
|
||||||
|
GLuint texID;
|
||||||
|
glGenTextures(1, &texID);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texID);
|
||||||
|
|
||||||
|
// Set base format (Always using RGBA as base)
|
||||||
|
GLenum fmt = GL_RGBA;
|
||||||
|
if (type == PD::Li::Texture::Type::RGB24) {
|
||||||
|
fmt = GL_RGB;
|
||||||
|
} else if (type == PD::Li::Texture::Type::A8) {
|
||||||
|
fmt = GL_ALPHA;
|
||||||
|
}
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
|
||||||
|
pixels.data());
|
||||||
|
if (filter == PD::Li::Texture::Filter::LINEAR) {
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
} else if (filter == PD::Li::Texture::Filter::NEAREST) {
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
}
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
auto res = PD::Li::Texture::New(texID, PD::ivec2(w, h));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
} // namespace Li
|
||||||
|
} // namespace PD
|
58
backends/desktop/source/bknd-hid.cpp
Executable file
58
backends/desktop/source/bknd-hid.cpp
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pd-desktop/bknd-hid.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
HidGLFW::HidGLFW(GLFWwindow* win) : HidDriver("HidGLFW") {
|
||||||
|
Window = win;
|
||||||
|
pBinds[GLFW_MOUSE_BUTTON_LEFT] = Touch;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HidGLFW::Update() {
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
KeyEvents[i][Event_Down] = 0;
|
||||||
|
KeyEvents[i][Event_Held] = 0;
|
||||||
|
KeyEvents[i][Event_Up] = 0;
|
||||||
|
}
|
||||||
|
int state = glfwGetMouseButton(Window, GLFW_MOUSE_BUTTON_LEFT);
|
||||||
|
if (state == GLFW_PRESS) {
|
||||||
|
if (PrevState == GLFW_RELEASE) {
|
||||||
|
KeyEvents[0][Event_Down] |= Touch;
|
||||||
|
}
|
||||||
|
KeyEvents[0][Event_Held] |= Touch;
|
||||||
|
} else if (state == GLFW_RELEASE && PrevState == GLFW_PRESS) {
|
||||||
|
KeyEvents[0][Event_Up] |= Touch;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrevState = state;
|
||||||
|
if (pLocked) {
|
||||||
|
SwapTab();
|
||||||
|
}
|
||||||
|
double x, y;
|
||||||
|
glfwGetCursorPos(Window, &x, &y);
|
||||||
|
pMouse[1] = pMouse[0]; // Cycle pMouse pos
|
||||||
|
pMouse[0] = fvec2(x, y);
|
||||||
|
}
|
||||||
|
} // namespace PD
|
90
source/core/timer.cpp → backends/desktop/source/pd-desktop.cpp
Normal file → Executable file
90
source/core/timer.cpp → backends/desktop/source/pd-desktop.cpp
Normal file → Executable file
@ -1,49 +1,43 @@
|
|||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
Copyright (c) 2024 - 2025 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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/timer.hpp>
|
#include <palladium>
|
||||||
|
#include <pd-desktop.hpp>
|
||||||
namespace PD {
|
|
||||||
Timer::Timer(bool autostart) {
|
namespace PD {
|
||||||
is_running = autostart;
|
void Init(void* data) {
|
||||||
Reset();
|
if (!data) {
|
||||||
}
|
std::cout << "[PD-DRIVERS] Error: pd-desktop requires GLFWwindow* "
|
||||||
|
"reference as data "
|
||||||
void Timer::Reset() {
|
"input!"
|
||||||
start = Sys::GetTime();
|
<< std::endl;
|
||||||
now = start;
|
abort();
|
||||||
}
|
}
|
||||||
|
// Dekstop Init Stage
|
||||||
void Timer::Update() {
|
// First use default OS Driver
|
||||||
if (is_running) {
|
PD::OS::Init();
|
||||||
now = Sys::GetTime();
|
PD::Li::Gfx::Init(PD::Li::GfxGL2::New());
|
||||||
}
|
PD::Hid::Init(PD::HidGLFW::New(reinterpret_cast<GLFWwindow*>(data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::Pause() { is_running = false; }
|
|
||||||
void Timer::Rseume() { is_running = true; }
|
|
||||||
bool Timer::IsRunning() const { return is_running; }
|
|
||||||
u64 Timer::Get() { return now - start; }
|
|
||||||
double Timer::GetSeconds() { return double(Get()) / 1000.0; }
|
|
||||||
} // namespace PD
|
} // namespace PD
|
74
cmake/palladium.cmake
Executable file
74
cmake/palladium.cmake
Executable file
@ -0,0 +1,74 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.22)
|
||||||
|
|
||||||
|
## Utilitys of Palladium Library
|
||||||
|
|
||||||
|
### RULES ###
|
||||||
|
|
||||||
|
# Force C++ 20
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||||
|
|
||||||
|
# Enable Compile Command Export
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
option(PD_INCLUDE_DIR "")
|
||||||
|
|
||||||
|
### Helper Function to Build Librarys without have always
|
||||||
|
### These includes and definition defines
|
||||||
|
function(pd_add_lib TARGET_NAME)
|
||||||
|
set(opts "BUILD_SHARED")
|
||||||
|
set(one_val_args "")
|
||||||
|
set(multi_val_args SRC_FILES DEPENDS)
|
||||||
|
cmake_parse_arguments(ARG "${opts}" "${one_val_args}" "${multi_val_args}" ${ARGN})
|
||||||
|
|
||||||
|
string(REPLACE "-" "_" FLAG_NAME_T ${TARGET_NAME})
|
||||||
|
string(TOUPPER ${FLAG_NAME_T} FLAG_NAME_F)
|
||||||
|
|
||||||
|
if(ARG_BUILD_SHARED)
|
||||||
|
add_library(${TARGET_NAME} SHARED ${ARG_SRC_FILES})
|
||||||
|
target_compile_definitions(${TARGET_NAME} PUBLIC -D${FLAG_NAME_F}_BUILD_SHARED=1)
|
||||||
|
message("Building SHARED library: ${FLAG_NAME_F}_BUILD_SHARED=1")
|
||||||
|
else()
|
||||||
|
add_library(${TARGET_NAME} STATIC ${ARG_SRC_FILES})
|
||||||
|
target_compile_definitions(${TARGET_NAME} PUBLIC -D${FLAG_NAME_F}_BUILD_SHARED=0)
|
||||||
|
message("Building STATIC library: ${FLAG_NAME_F}_BUILD_SHARED=0")
|
||||||
|
endif()
|
||||||
|
target_include_directories(${TARGET_NAME} PUBLIC
|
||||||
|
${PD_INCLUDE_DIR}
|
||||||
|
${DEVKITPRO}/portlibs/3ds/include
|
||||||
|
)
|
||||||
|
target_compile_definitions(${TARGET_NAME} PUBLIC
|
||||||
|
-D_GNU_SOURCE=1
|
||||||
|
-DPALLADIUM_VERSION="${PROJECT_VERSION}"
|
||||||
|
-DPALLADIUM_GIT_COMMIT="${GIT_SHORT_HASH}"
|
||||||
|
-DPALLADIUM_GIT_BRANCH="${GIT_BRANCH}"
|
||||||
|
-DBUILD_CTR=1
|
||||||
|
)
|
||||||
|
### For the libs that depend on another
|
||||||
|
if(ARG_DEPENDS)
|
||||||
|
target_link_libraries(${TARGET_NAME} PUBLIC ${ARG_DEPENDS})
|
||||||
|
endif()
|
||||||
|
install(TARGETS ${TARGET_NAME})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
### GIT HELPER ###
|
||||||
|
|
||||||
|
function(pd_git_get_hash ret)
|
||||||
|
execute_process(
|
||||||
|
COMMAND git rev-parse --short HEAD
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE _ret
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
set(${ret} "${_ret}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(pd_git_get_branch ret)
|
||||||
|
execute_process(
|
||||||
|
COMMAND git rev-parse --abbrev-ref HEAD
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE _ret
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
set(${ret} "${_ret}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
@ -1,16 +0,0 @@
|
|||||||
window.MathJax = {
|
|
||||||
tex: {
|
|
||||||
inlineMath: [["\\(", "\\)"]],
|
|
||||||
displayMath: [["\\[", "\\]"]],
|
|
||||||
processEscapes: true,
|
|
||||||
processEnvironments: true
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
ignoreHtmlClass: ".*|",
|
|
||||||
processHtmlClass: "arithmatex"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
document$.subscribe(() => {
|
|
||||||
MathJax.typesetPromise()
|
|
||||||
})
|
|
@ -1,6 +0,0 @@
|
|||||||
document$.subscribe(function() {
|
|
||||||
var tables = document.querySelectorAll("article table:not([class])")
|
|
||||||
tables.forEach(function(table) {
|
|
||||||
new Tablesort(table)
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,22 +0,0 @@
|
|||||||
<div class="md-copyright">
|
|
||||||
{% if config.copyright %}
|
|
||||||
<div class="md-copyright__highlight">
|
|
||||||
{{ config.copyright }}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% if not config.extra.generator == false %}
|
|
||||||
© 2024 -
|
|
||||||
<script>document.write(new Date().getFullYear());</script>
|
|
||||||
<a href="https://github.com/tobid7">
|
|
||||||
tobid7
|
|
||||||
</a>
|
|
||||||
- Kassel, Germany | Made with
|
|
||||||
<a href="https://doxide.org" target="_blank" rel="noopener">
|
|
||||||
Doxide
|
|
||||||
</a>
|
|
||||||
and
|
|
||||||
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
|
|
||||||
Material for MkDocs
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
@ -1,58 +0,0 @@
|
|||||||
:root {
|
|
||||||
--md-admonition-icon--variable: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.41 3c1.39 2.71 1.94 5.84 1.59 9-.2 3.16-1.3 6.29-3.17 9l-1.53-1c1.61-2.43 2.55-5.2 2.7-8 .34-2.8-.11-5.57-1.3-8l1.71-1M5.17 3 6.7 4C5.09 6.43 4.15 9.2 4 12c-.34 2.8.12 5.57 1.3 8l-1.69 1c-1.4-2.71-1.96-5.83-1.61-9 .2-3.16 1.3-6.29 3.17-9m6.91 7.68 2.32-3.23h2.53l-3.78 5 2.2 4.92h-2.26L11.71 14l-2.43 3.33H6.76l3.9-5.12-2.13-4.76h2.27l1.28 3.23Z"/></svg>');
|
|
||||||
--md-admonition-icon--function: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.6 5.29c-1.1-.1-2.07.71-2.17 1.82L13.18 10H16v2h-3l-.44 5.07a3.986 3.986 0 0 1-4.33 3.63 4.007 4.007 0 0 1-3.06-1.87l1.5-1.5c.24.74.9 1.31 1.73 1.38 1.1.1 2.07-.71 2.17-1.82L11 12H8v-2h3.17l.27-3.07c.19-2.2 2.13-3.83 4.33-3.63 1.31.11 2.41.84 3.06 1.87l-1.5 1.5c-.24-.74-.9-1.31-1.73-1.38Z"/></svg>');
|
|
||||||
--md-admonition-icon--typedef: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M 13.43 7.11 L 13.18 10 H 17 V 12 H 13 L 12.56 17.07 A 1 1 0 0 0 15.287 17.261 L 17.028 17.48 A 1 1 0 0 1 10.57 16.89 L 11 12 H 8 V 10 H 11.17 L 11.44 6.93 Z"/></svg>');
|
|
||||||
--md-admonition-icon--concept: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3.75 3.5a.25.25 0 0 0-.25.25v2.062a.75.75 0 1 1-1.5 0V3.75C2 2.783 2.783 2 3.75 2h2.062a.75.75 0 1 1 0 1.5Zm13.688-.75a.75.75 0 0 1 .75-.75h2.062c.966 0 1.75.783 1.75 1.75v2.062a.75.75 0 1 1-1.5 0V3.75a.25.25 0 0 0-.25-.25h-2.062a.75.75 0 0 1-.75-.75ZM2.75 17.438a.75.75 0 0 1 .75.75v2.062c0 .138.112.25.25.25h2.062a.75.75 0 1 1 0 1.5H3.75A1.75 1.75 0 0 1 2 20.25v-2.062a.75.75 0 0 1 .75-.75Zm18.5 0a.75.75 0 0 1 .75.75v2.062A1.75 1.75 0 0 1 20.25 22h-2.062a.75.75 0 1 1 0-1.5h2.062a.25.25 0 0 0 .25-.25v-2.062a.75.75 0 0 1 .75-.75Zm-18.5-8.25a.75.75 0 0 1 .75.75v4.124a.75.75 0 1 1-1.5 0V9.938a.75.75 0 0 1 .75-.75ZM9.188 2.75a.75.75 0 0 1 .75-.75h4.124a.75.75 0 1 1 0 1.5H9.938a.75.75 0 0 1-.75-.75Zm0 18.5a.75.75 0 0 1 .75-.75h4.124a.75.75 0 1 1 0 1.5H9.938a.75.75 0 0 1-.75-.75ZM21.25 9.188a.75.75 0 0 1 .75.75v4.124a.75.75 0 1 1-1.5 0V9.938a.75.75 0 0 1 .75-.75ZM3.75 8.25a.75.75 0 0 1 .75-.75h2a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1-.75-.75Zm5.5 0A.75.75 0 0 1 10 7.5h2A.75.75 0 0 1 12 9h-2a.75.75 0 0 1-.75-.75Zm-1-4.5A.75.75 0 0 1 9 4.5v2a.75.75 0 0 1-1.5 0v-2a.75.75 0 0 1 .75-.75Zm0 5.5A.75.75 0 0 1 9 10v2a.75.75 0 0 1-1.5 0v-2a.75.75 0 0 1 .75-.75Zm0 4.75a.75.75 0 0 1 .75.75v4a.75.75 0 0 1-1.5 0v-4a.75.75 0 0 1 .75-.75ZM14 8.25a.75.75 0 0 1 .75-.75h4a.75.75 0 0 1 0 1.5h-4a.75.75 0 0 1-.75-.75Z"/></svg>');
|
|
||||||
--md-admonition-icon--macro: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m5.41 21 .71-4h-4l.35-2h4l1.06-6h-4l.35-2h4l.71-4h2l-.71 4h6l.71-4h2l-.71 4h4l-.35 2h-4l-1.06 6h4l-.35 2h-4l-.71 4h-2l.71-4h-6l-.71 4h-2M9.53 9l-1.06 6h6l1.06-6h-6Z"/></svg>');
|
|
||||||
}
|
|
||||||
|
|
||||||
.md-typeset .admonition.variable, .md-typeset details.variable,
|
|
||||||
.md-typeset .admonition.function, .md-typeset details.function,
|
|
||||||
.md-typeset .admonition.typedef, .md-typeset details.typedef,
|
|
||||||
.md-typeset .admonition.concept, .md-typeset details.concept,
|
|
||||||
.md-typeset .admonition.macro, .md-typeset details.macro {
|
|
||||||
border-color: var(--md-default-fg-color--lighter);
|
|
||||||
}
|
|
||||||
|
|
||||||
.md-typeset .variable > .admonition-title, .md-typeset .variable > summary,
|
|
||||||
.md-typeset .function > .admonition-title, .md-typeset .function > summary,
|
|
||||||
.md-typeset .typedef > .admonition-title, .md-typeset .typedef > summary,
|
|
||||||
.md-typeset .concept > .admonition-title, .md-typeset .concept > summary,
|
|
||||||
.md-typeset .macro > .admonition-title, .md-typeset .macro > summary {
|
|
||||||
background-color: var(--md-default-bg-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.md-typeset .variable > .admonition-title::before,
|
|
||||||
.md-typeset .variable > summary::before {
|
|
||||||
background-color: var(--md-default-fg-color--light);
|
|
||||||
-webkit-mask-image: var(--md-admonition-icon--variable);
|
|
||||||
mask-image: var(--md-admonition-icon--variable);
|
|
||||||
}
|
|
||||||
|
|
||||||
.md-typeset .function > .admonition-title::before,
|
|
||||||
.md-typeset .function > summary::before {
|
|
||||||
background-color: var(--md-default-fg-color--light);
|
|
||||||
-webkit-mask-image: var(--md-admonition-icon--function);
|
|
||||||
mask-image: var(--md-admonition-icon--function);
|
|
||||||
}
|
|
||||||
|
|
||||||
.md-typeset .typedef > .admonition-title::before,
|
|
||||||
.md-typeset .typedef > summary::before {
|
|
||||||
background-color: var(--md-default-fg-color--light);
|
|
||||||
-webkit-mask-image: var(--md-admonition-icon--typedef);
|
|
||||||
mask-image: var(--md-admonition-icon--typedef);
|
|
||||||
}
|
|
||||||
|
|
||||||
.md-typeset .concept > .admonition-title::before,
|
|
||||||
.md-typeset .concept > summary::before {
|
|
||||||
background-color: var(--md-default-fg-color--light);
|
|
||||||
-webkit-mask-image: var(--md-admonition-icon--concept);
|
|
||||||
mask-image: var(--md-admonition-icon--concept);
|
|
||||||
}
|
|
||||||
|
|
||||||
.md-typeset .macro > .admonition-title::before,
|
|
||||||
.md-typeset .macro > summary::before {
|
|
||||||
background-color: var(--md-default-fg-color--light);
|
|
||||||
-webkit-mask-image: var(--md-admonition-icon--macro);
|
|
||||||
mask-image: var(--md-admonition-icon--macro);
|
|
||||||
}
|
|
15
doxide.yaml
15
doxide.yaml
@ -1,15 +0,0 @@
|
|||||||
title: Palladium
|
|
||||||
description:
|
|
||||||
files:
|
|
||||||
- "include/*.hpp"
|
|
||||||
- "include/pd/app/*.hpp"
|
|
||||||
- "include/pd/core/*.hpp"
|
|
||||||
- "include/pd/drivers/*.hpp"
|
|
||||||
- "include/pd/image/*.hpp"
|
|
||||||
- "include/pd/lib3ds/*.hpp"
|
|
||||||
- "include/pd/lithium/*.hpp"
|
|
||||||
- "include/pd/net/*.hpp"
|
|
||||||
- "include/pd/overlays/*.hpp"
|
|
||||||
- "include/pd/sound/*.hpp"
|
|
||||||
- "include/pd/ui7/*.hpp"
|
|
||||||
- "include/pd/ui7/container/*.hpp"
|
|
8
include/palladium
Executable file
8
include/palladium
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/core/core.hpp>
|
||||||
|
#include <pd/drivers/drivers.hpp>
|
||||||
|
#include <pd/external/json.hpp>
|
||||||
|
#include <pd/image/image.hpp>
|
||||||
|
#include <pd/lithium/lithium.hpp>
|
||||||
|
#include <pd/ui7/ui7.hpp>
|
@ -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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// 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;
|
|
@ -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
|
|
@ -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
|
|
92
include/pd/core/bit_util.hpp
Normal file → Executable file
92
include/pd/core/bit_util.hpp
Normal file → Executable file
@ -1,47 +1,47 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
Copyright (c) 2024 - 2025 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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
* Binary Utillity Functions
|
* Binary Utillity Functions
|
||||||
*/
|
*/
|
||||||
namespace BitUtil {
|
namespace BitUtil {
|
||||||
/**
|
/**
|
||||||
* Check if a 32 Bit number only set a sigle bit to 1
|
* Check if a 32 Bit number only set a sigle bit to 1
|
||||||
* @param v 32 bit unsigned int
|
* @param v 32 bit unsigned int
|
||||||
* @return true if its a single bit number
|
* @return true if its a single bit number
|
||||||
*/
|
*/
|
||||||
bool IsSingleBit(u32 v);
|
PD_CORE_API bool IsSingleBit(u32 v);
|
||||||
/**
|
/**
|
||||||
* Get the Next Power of two Number
|
* Get the Next Power of two Number
|
||||||
* @param v Current Number
|
* @param v Current Number
|
||||||
* @return Next Number thats a Pow of 2
|
* @return Next Number thats a Pow of 2
|
||||||
*/
|
*/
|
||||||
u32 GetPow2(u32 v);
|
PD_CORE_API u32 GetPow2(u32 v);
|
||||||
} // namespace BitUtil
|
} // namespace BitUtil
|
||||||
} // namespace PD
|
} // namespace PD
|
340
include/pd/core/color.hpp
Normal file → Executable file
340
include/pd/core/color.hpp
Normal file → Executable file
@ -1,210 +1,132 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
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
|
in the Software without restriction, including without limitation the rights
|
||||||
in the Software without restriction, including without limitation the rights
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
furnished to do so, subject to the following conditions:
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
The above copyright notice and this permission notice shall be included in all
|
copies or substantial portions of the Software.
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
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
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
SOFTWARE.
|
||||||
SOFTWARE.
|
*/
|
||||||
*/
|
|
||||||
|
#include <pd/core/common.hpp>
|
||||||
#include <pd/core/common.hpp>
|
|
||||||
|
namespace PD {
|
||||||
namespace PD {
|
class PD_CORE_API Color {
|
||||||
/**
|
public:
|
||||||
* Color class
|
/**
|
||||||
*
|
* Default Constructor (all variables are set to 0)
|
||||||
* - Supports hex input starting with a # and 6 or 8 digits
|
*/
|
||||||
* - Supports rgb(a) 8Bit unsigned number input
|
constexpr Color() : r(0), g(0), b(0), a(0) {}
|
||||||
* - Supports rgb(a) float input from 0.0 to 1.0
|
constexpr ~Color() {}
|
||||||
* - Supports 32Bit input color
|
/**
|
||||||
* @note Safetey checks are disabled for maximum performance
|
* Constructor for 32Bit Color Input
|
||||||
*/
|
* @param color 32Bit Color value
|
||||||
class Color {
|
*/
|
||||||
public:
|
constexpr Color(u32 clr) {
|
||||||
/**
|
a = (clr >> 24) & 0xff;
|
||||||
* Default Constructor (all variables are set to 0)
|
b = (clr >> 16) & 0xff;
|
||||||
*/
|
g = (clr >> 8) & 0xff;
|
||||||
Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
|
r = clr & 0xff;
|
||||||
/**
|
}
|
||||||
* Constructor for 32Bit Color Input
|
/**
|
||||||
* @param color 32Bit Color value
|
* Constructor for 8Bit Input
|
||||||
*/
|
* @param r Red Value
|
||||||
Color(u32 color) {
|
* @param g Green Value
|
||||||
m_a = (color >> 24) & 0xff;
|
* @param b Blue Value
|
||||||
m_b = (color >> 16) & 0xff;
|
* @param a Optional Alpha Value (Defaults to 255)
|
||||||
m_g = (color >> 8) & 0xff;
|
*/
|
||||||
m_r = color & 0xff;
|
constexpr Color(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {}
|
||||||
}
|
/**
|
||||||
/**
|
* Constructor for float Input
|
||||||
* Constructor for 8Bit Input
|
* @param r Red Value
|
||||||
* @param r Red Value
|
* @param g Green Value
|
||||||
* @param g Green Value
|
* @param b Blue Value
|
||||||
* @param b Blue Value
|
* @param a Optional Alpha Value (Defaults to 1.0f)
|
||||||
* @param a Optional Alpha Value (Defaults to 255)
|
* @note There is no Check if the number is between 0.0 and 1.0
|
||||||
*/
|
*/
|
||||||
Color(u8 r, u8 g, u8 b, u8 a = 255) {
|
constexpr Color(float r, float g, float b, float a = 1.f) {
|
||||||
m_r = r;
|
r = static_cast<u8>(255.f * r);
|
||||||
m_g = g;
|
g = static_cast<u8>(255.f * g);
|
||||||
m_b = b;
|
b = static_cast<u8>(255.f * b);
|
||||||
m_a = a;
|
a = static_cast<u8>(255.f * a);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Constructor for float Input
|
* Constructor for Hex Input
|
||||||
* @param r Red Value
|
* @param hex Hex String in `#ffffff` or `#ffffffff` format
|
||||||
* @param g Green Value
|
*/
|
||||||
* @param b Blue Value
|
Color(const std::string& hex) { Hex(hex); }
|
||||||
* @param a Optional Alpha Value (Defaults to 1.0f)
|
|
||||||
* @note There is no Check if the number is between 0.0 and 1.0
|
/**
|
||||||
*/
|
* Create Color Object by Hex String
|
||||||
Color(float r, float g, float b, float a = 1.f) {
|
* @param hex Hex String in `#ffffff` or `#ffffffff` format
|
||||||
m_r = static_cast<u8>(255.f * r);
|
* @return Color class itself
|
||||||
m_g = static_cast<u8>(255.f * g);
|
*/
|
||||||
m_b = static_cast<u8>(255.f * b);
|
Color& Hex(const std::string& hex);
|
||||||
m_a = static_cast<u8>(255.f * a);
|
/**
|
||||||
}
|
* Convert this Color Object to Hex string
|
||||||
/**
|
* @param rgba [default false] sets if 8 or 6 digit color should be returned
|
||||||
* Constructor for Hex Input
|
* @return Color Hex String
|
||||||
* @param hex Hex String in `#ffffff` or `#ffffffff` format
|
*/
|
||||||
*/
|
std::string Hex(bool rgba = false) const;
|
||||||
Color(const std::string& hex) { Hex(hex); }
|
|
||||||
/**
|
/**
|
||||||
* Unused Deconstructor
|
* Fade from Current to another Color
|
||||||
*/
|
* @param color Color to fade to
|
||||||
~Color() {}
|
* @param p Amount (supports -1.0 to 1.0 for use of sine)
|
||||||
|
* @return Class Reference
|
||||||
/**
|
*/
|
||||||
* Create Color Object by Hex String
|
Color& Fade(const Color& color, float p) {
|
||||||
* @param hex Hex String in `#ffffff` or `#ffffffff` format
|
a = static_cast<u8>((color.a - a) * ((p + 1.f) / 2));
|
||||||
* @return Color class itself
|
b = static_cast<u8>((color.b - b) * ((p + 1.f) / 2));
|
||||||
*/
|
g = static_cast<u8>((color.g - g) * ((p + 1.f) / 2));
|
||||||
Color& Hex(const std::string& hex);
|
r = static_cast<u8>((color.r - r) * ((p + 1.f) / 2));
|
||||||
/**
|
return *this;
|
||||||
* 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
|
/**
|
||||||
*/
|
* Get 32Bit Color Value
|
||||||
std::string Hex(bool rgba = false) const;
|
* @return 32Bit Color Value (ABGR iirc)
|
||||||
|
*/
|
||||||
/**
|
u32 Get() const { return (a << 24) | (b << 16) | (g << 8) | r; }
|
||||||
* Setter for Red
|
/**
|
||||||
* @param v value
|
* Get The Luminance of the Color
|
||||||
* @return Color class reference
|
* @return luminance (from 0.0 to 1.0)
|
||||||
*/
|
*/
|
||||||
Color& r(u8 v) {
|
float Luminance() const {
|
||||||
m_r = v;
|
// For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
|
||||||
return *this;
|
return (0.3 * (r / 255.f) + 0.59 * (g / 255.f) + 0.11 * (b / 255.f));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Getter for Red
|
* Check if the Color is Light or Dark
|
||||||
* @return Red Value
|
* @return true if light
|
||||||
*/
|
*/
|
||||||
u8 r() const { return m_r; }
|
bool IsLight() const { return (Luminance() >= 0.5); }
|
||||||
/**
|
|
||||||
* Setter for Green
|
/**
|
||||||
* @param v value
|
* Operator to cast Color to 32Bit Value
|
||||||
* @return Color class reference
|
* @return 32Bit Color Value
|
||||||
*/
|
*/
|
||||||
Color& g(u8 v) {
|
operator u32() const { return Get(); }
|
||||||
m_g = v;
|
|
||||||
return *this;
|
/** Public Access Data section */
|
||||||
}
|
u8 r;
|
||||||
/**
|
u8 g;
|
||||||
* Getter for Green
|
u8 b;
|
||||||
* @return Green Value
|
u8 a;
|
||||||
*/
|
};
|
||||||
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
|
} // namespace PD
|
186
include/pd/core/common.hpp
Normal file → Executable file
186
include/pd/core/common.hpp
Normal file → Executable file
@ -1,120 +1,68 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <filesystem> // Requires C++ 17 or later
|
#include <filesystem> // Requires C++ 17 or later
|
||||||
#include <format> // Requires C++ 20 or later
|
#include <format> // Requires C++ 20 or later
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace PD {
|
/** Dynamic Lib loading */
|
||||||
/**
|
#include <pd/core/pd_p_api.hpp>
|
||||||
* SmartCtor (std::shared_ptr) Template class for Smart Pointers
|
|
||||||
*
|
/** Memory Management */
|
||||||
* - Just add : public PD::SmartCtor<YourClass> to your class
|
|
||||||
* @tparam T Your Class
|
#define PD_SHARED(x) \
|
||||||
*/
|
using Ref = std::shared_ptr<x>; \
|
||||||
template <typename T>
|
template <typename... Args> \
|
||||||
class SmartCtor {
|
static Ref New(Args&&... args) { \
|
||||||
public:
|
return std::make_shared<x>(std::forward<Args>(args)...); \
|
||||||
/** Reference alias for std::shared_ptr<Type> */
|
}
|
||||||
using Ref = std::shared_ptr<T>;
|
|
||||||
|
#define PD_UNIQUE(x) \
|
||||||
/**
|
using Ref = std::unique_ptr<x>; \
|
||||||
* static Function to Create a New Reference
|
template <typename... Args> \
|
||||||
* @param args Additional Arguments (Depends on your classes Constructors)
|
static Ref New(Args&&... args) { \
|
||||||
* @return New Reference Object
|
return std::make_unique<x>(std::forward<Args>(args)...); \
|
||||||
*/
|
}
|
||||||
template <typename... Args>
|
|
||||||
static Ref New(Args&&... args) {
|
#define PD_BIT(x) (1 << x)
|
||||||
return std::make_shared<T>(std::forward<Args>(args)...);
|
|
||||||
}
|
namespace PD {
|
||||||
};
|
/** Types */
|
||||||
/**
|
using u8 = unsigned char;
|
||||||
* Wrapper for SmartCtor<Type>::New(Args)
|
using u16 = unsigned short;
|
||||||
* @tparam T Class Type
|
using u32 = unsigned int;
|
||||||
* @param args Arguments
|
using u64 = unsigned long long;
|
||||||
* @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
|
} // namespace PD
|
73
source/ui7/io.cpp → include/pd/core/core.hpp
Normal file → Executable file
73
source/ui7/io.cpp → include/pd/core/core.hpp
Normal file → Executable file
@ -1,38 +1,35 @@
|
|||||||
/*
|
#pragma once
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
/*
|
||||||
|
MIT License
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
in the Software without restriction, including without limitation the rights
|
||||||
furnished to do so, subject to the following conditions:
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
The above copyright notice and this permission notice shall be included in all
|
furnished to do so, subject to the following conditions:
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
copies or substantial portions of the Software.
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
SOFTWARE.
|
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/timetrace.hpp>
|
*/
|
||||||
#include <pd/ui7/io.hpp>
|
|
||||||
|
#include <pd/core/bit_util.hpp>
|
||||||
namespace PD {
|
#include <pd/core/color.hpp>
|
||||||
void UI7::IO::Update() {
|
#include <pd/core/io.hpp>
|
||||||
Time->Update();
|
#include <pd/core/mat.hpp>
|
||||||
DragTime->Update();
|
#include <pd/core/sl/sl.hpp>
|
||||||
DragReleased = false;
|
#include <pd/core/strings.hpp>
|
||||||
DragReleasedAW = false;
|
#include <pd/core/timer.hpp>
|
||||||
DragDoubleRelease = false;
|
#include <pd/core/timetrace.hpp>
|
||||||
Framerate = 1000.f / Delta;
|
#include <pd/core/tween.hpp>
|
||||||
DrawListRegestry.clear();
|
#include <pd/core/vec.hpp>
|
||||||
RegisterDrawList("CtxBackList", Back);
|
|
||||||
}
|
|
||||||
} // namespace PD
|
|
100
include/pd/core/io.hpp
Normal file → Executable file
100
include/pd/core/io.hpp
Normal file → Executable file
@ -1,46 +1,56 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
* Set of File Functions
|
* Set of File Functions
|
||||||
*/
|
*/
|
||||||
namespace IO {
|
namespace IO {
|
||||||
/**
|
/**
|
||||||
* Load a File into an 8Bit Memory Buffer
|
* Load a File into an 8Bit Memory Buffer
|
||||||
* @param path Path to the File
|
* @param path Path to the File
|
||||||
* @return 8Bit FileBuffer
|
* @return 8Bit FileBuffer
|
||||||
*/
|
*/
|
||||||
std::vector<u8> LoadFile2Mem(const std::string& path);
|
PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path);
|
||||||
/**
|
/**
|
||||||
* Hash a 8Bit Memory Buffer
|
* Hash a 8Bit Memory Buffer
|
||||||
* @param data 8Bit input Buffer
|
* @param data 8Bit input Buffer
|
||||||
* @return 32Bit Hash
|
* @return 32Bit Hash
|
||||||
*/
|
*/
|
||||||
u32 HashMemory(const std::vector<u8>& data);
|
PD_CORE_API u32 HashMemory(const std::vector<u8>& data);
|
||||||
} // namespace IO
|
/**
|
||||||
|
* Function to decrompress RLE buffer
|
||||||
|
* @param data Data buffer to decompress
|
||||||
|
*/
|
||||||
|
PD_CORE_API void DecompressRLE(std::vector<u8>& data);
|
||||||
|
/**
|
||||||
|
* Function to compress data with RLE Algorithm
|
||||||
|
* @param data Data buf
|
||||||
|
*/
|
||||||
|
PD_CORE_API void CompressRLE(std::vector<u8>& data);
|
||||||
|
} // namespace IO
|
||||||
} // namespace PD
|
} // namespace PD
|
@ -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
|
|
79
include/pd/lib3ds/os.hpp → include/pd/core/mat.hpp
Normal file → Executable file
79
include/pd/lib3ds/os.hpp → include/pd/core/mat.hpp
Normal file → Executable file
@ -1,40 +1,41 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
in the Software without restriction, including without limitation the rights
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
in the Software without restriction, including without limitation the rights
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
furnished to do so, subject to the following conditions:
|
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 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,
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
SOFTWARE.
|
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/common.hpp>
|
||||||
namespace PD {
|
|
||||||
/**
|
namespace PD {
|
||||||
* Namespace to Everything that has to
|
class PD_CORE_API Mat4 {
|
||||||
* do with the 3ds (very empty currently)
|
public:
|
||||||
*/
|
Mat4() { Zeros(); }
|
||||||
namespace Ctr {
|
~Mat4() = default;
|
||||||
/**
|
|
||||||
* Get the System Language key (for lang system)
|
void Zeros();
|
||||||
* @return language key
|
void Ortho(float left, float right, float bottom, float top, float near,
|
||||||
*/
|
float far);
|
||||||
std::string GetSystemLanguage();
|
|
||||||
} // namespace Ctr
|
float m[16];
|
||||||
|
};
|
||||||
} // namespace PD
|
} // namespace PD
|
51
include/pd/core/pd_p_api.hpp
Executable file
51
include/pd/core/pd_p_api.hpp
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Generated with ppam */
|
||||||
|
|
||||||
|
#ifdef _WIN32 // Windows (MSVC Tested)
|
||||||
|
#ifdef PD_CORE_BUILD_SHARED
|
||||||
|
#define PD_CORE_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define PD_CORE_API __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#elif defined(__APPLE__) // macOS (untested yet)
|
||||||
|
#ifdef PD_CORE_BUILD_SHARED
|
||||||
|
#define PD_CORE_API __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
#define PD_CORE_API
|
||||||
|
#endif
|
||||||
|
#elif defined(__linux__) // Linux (untested yet)
|
||||||
|
#ifdef PD_CORE_BUILD_SHARED
|
||||||
|
#define PD_CORE_API __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
#define PD_CORE_API
|
||||||
|
#endif
|
||||||
|
#elif defined(__3DS__) // 3ds Specific
|
||||||
|
// Only Static supported
|
||||||
|
#define PD_CORE_API
|
||||||
|
#else
|
||||||
|
#define PD_CORE_API
|
||||||
|
#endif
|
122
include/pd/lib3ds/gamepad_icons.hpp → include/pd/core/sl/allocator.hpp
Normal file → Executable file
122
include/pd/lib3ds/gamepad_icons.hpp → include/pd/core/sl/allocator.hpp
Normal file → Executable file
@ -1,73 +1,51 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
in the Software without restriction, including without limitation the rights
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
in the Software without restriction, including without limitation the rights
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
furnished to do so, subject to the following conditions:
|
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 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,
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
SOFTWARE.
|
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/core/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
* Simple Table Containing the codepoint references
|
* Custom Allocator for Custom Vec and probably other stuff in future
|
||||||
* for the Controller Icons on the 3ds
|
*/
|
||||||
*/
|
template <typename T>
|
||||||
namespace GamePadIcons {
|
class Allocator {
|
||||||
/**
|
public:
|
||||||
* Icon ID
|
Allocator() = default;
|
||||||
*/
|
~Allocator() = default;
|
||||||
enum ID {
|
|
||||||
A,
|
virtual T* Allocate(size_t n) { return new T[n]; }
|
||||||
B,
|
virtual T* AllocateRaw(size_t n) {
|
||||||
X,
|
return reinterpret_cast<T*>(::operator new(sizeof(T) * n));
|
||||||
Y,
|
}
|
||||||
L,
|
virtual void DeallocateRaw(T* ptr) { operator delete(ptr); }
|
||||||
R,
|
virtual void Deallocate(T* ptr) { delete[] ptr; }
|
||||||
Dpad,
|
template <typename... Args>
|
||||||
Start,
|
void Construct(T* ptr, Args&&... args) {
|
||||||
Select,
|
new (ptr) T(std::forward<Args>(args)...);
|
||||||
Home,
|
}
|
||||||
Steps,
|
void Destroy(T* ptr) { ptr->~T(); }
|
||||||
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
|
} // namespace PD
|
135
include/pd/lithium/spritesheet.hpp → include/pd/core/sl/hashmap.hpp
Normal file → Executable file
135
include/pd/lithium/spritesheet.hpp → include/pd/core/sl/hashmap.hpp
Normal file → Executable file
@ -1,66 +1,71 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
in the Software without restriction, including without limitation the rights
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
in the Software without restriction, including without limitation the rights
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
furnished to do so, subject to the following conditions:
|
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 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,
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
SOFTWARE.
|
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/core/sl/list.hpp>
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/sl/pair.hpp>
|
||||||
#include <pd/lithium/texture.hpp>
|
|
||||||
|
namespace PD {
|
||||||
namespace PD {
|
template <typename K, typename V, size_t bucket_count = 10>
|
||||||
/**
|
class HashMap {
|
||||||
* Tex 3DS Spritesheet integration to Lithium
|
public:
|
||||||
*/
|
HashMap() {}
|
||||||
class SpriteSheet : public SmartCtor<SpriteSheet> {
|
~HashMap() {}
|
||||||
public:
|
|
||||||
SpriteSheet() = default;
|
void Insert(const K& k, const V& v) {
|
||||||
/**
|
size_t idx = Hash(k);
|
||||||
* Constructor to directly load a spritesheet
|
auto& bukket = pBuckets[idx];
|
||||||
* @param path Path to spritesheet
|
for (auto& it : bukket) {
|
||||||
*/
|
if (it.First == k) {
|
||||||
SpriteSheet(const std::string& path) { this->LoadFile(path); }
|
it.Second = v;
|
||||||
/**
|
return;
|
||||||
* Deconstructor to unload the Spritesheet
|
}
|
||||||
*/
|
}
|
||||||
~SpriteSheet();
|
bukket.PushBack(Pair(k, v));
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Function to load a Spritesheet
|
bool Contains(const K& k) const {
|
||||||
* @param path Path to the file
|
size_t idx = Hash(k);
|
||||||
*/
|
auto& bukket = pBuckets[idx];
|
||||||
void LoadFile(const std::string& path);
|
|
||||||
/** Get a Textures Reference */
|
for (auto& it : bukket) {
|
||||||
Texture::Ref Get(int idx);
|
if (it.First == k) {
|
||||||
/** Get Number of Textures in spritesheet */
|
return true;
|
||||||
int NumTextures() const;
|
}
|
||||||
|
}
|
||||||
/** Operator to get Texture reference */
|
return false;
|
||||||
Texture::Ref operator[](int idx) { return Get(idx); }
|
}
|
||||||
|
|
||||||
private:
|
void Clear() {
|
||||||
/** Storage of the Spritesheets textures */
|
for (size_t i = 0; i < bucket_count; i++) {
|
||||||
std::vector<Texture::Ref> textures;
|
pBuckets[i].Clear();
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Hash(const K& k) const { return std::hash<K>{}(k) % bucket_count; }
|
||||||
|
PD::List<PD::Pair<K, V>> pBuckets[bucket_count];
|
||||||
|
};
|
||||||
} // namespace PD
|
} // namespace PD
|
210
include/pd/core/sl/list.hpp
Executable file
210
include/pd/core/sl/list.hpp
Executable file
@ -0,0 +1,210 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pd/core/common.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
template <typename T>
|
||||||
|
class List {
|
||||||
|
public:
|
||||||
|
List() {}
|
||||||
|
~List() {}
|
||||||
|
|
||||||
|
struct Node {
|
||||||
|
Node(const T& v) : Data(v) {}
|
||||||
|
T Data;
|
||||||
|
Node* Prev = nullptr;
|
||||||
|
Node* Next = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Iterator {
|
||||||
|
public:
|
||||||
|
Iterator(Node* n) : pNode(n) {}
|
||||||
|
T& operator*() { return pNode->Data; }
|
||||||
|
Iterator& operator++() {
|
||||||
|
pNode = pNode->Next;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
bool operator!=(const Iterator& o) const { return pNode != o.pNode; }
|
||||||
|
|
||||||
|
Node* pNode = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
void PushFront(const T& val) {
|
||||||
|
Node* node = new Node(val);
|
||||||
|
// node->Data = val;
|
||||||
|
node->Prev = nullptr;
|
||||||
|
node->Next = pHead;
|
||||||
|
if (pHead) {
|
||||||
|
pHead->Prev = node;
|
||||||
|
}
|
||||||
|
pHead = node;
|
||||||
|
if (!pTail) {
|
||||||
|
pTail = node;
|
||||||
|
}
|
||||||
|
pSize++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PushBack(const T& val) {
|
||||||
|
Node* node = new Node(val);
|
||||||
|
// node->Data = val;
|
||||||
|
node->Prev = pTail;
|
||||||
|
node->Next = nullptr;
|
||||||
|
if (pTail) {
|
||||||
|
pTail->Next = node;
|
||||||
|
}
|
||||||
|
pTail = node;
|
||||||
|
if (!pHead) {
|
||||||
|
pHead = node;
|
||||||
|
}
|
||||||
|
pSize++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PopFront() {
|
||||||
|
if (!pHead) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Node* t = pHead;
|
||||||
|
pHead = pHead->Next;
|
||||||
|
if (pHead) {
|
||||||
|
pHead->Prev = nullptr;
|
||||||
|
} else {
|
||||||
|
pTail = nullptr;
|
||||||
|
}
|
||||||
|
delete t;
|
||||||
|
pSize--;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PopBack() {
|
||||||
|
if (!pTail) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Node* t = pTail;
|
||||||
|
pTail = pTail->Prev;
|
||||||
|
if (pTail) {
|
||||||
|
pTail->Next = nullptr;
|
||||||
|
} else {
|
||||||
|
pHead = nullptr;
|
||||||
|
}
|
||||||
|
delete t;
|
||||||
|
pSize--;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear() {
|
||||||
|
while (pHead) {
|
||||||
|
PopFront();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Remove(const T& v) {
|
||||||
|
Node* s = pHead;
|
||||||
|
while (s) {
|
||||||
|
if (s->Data == v) {
|
||||||
|
if (s->Prev) {
|
||||||
|
s->Prev->Next = s->Next;
|
||||||
|
} else {
|
||||||
|
pHead = s->Next;
|
||||||
|
}
|
||||||
|
if (s->Next) {
|
||||||
|
s->Next->Prev = s->Prev;
|
||||||
|
} else {
|
||||||
|
pTail = s->Prev;
|
||||||
|
}
|
||||||
|
delete s;
|
||||||
|
pSize--;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
s = s->Next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Reverse() {
|
||||||
|
Node* cur = pHead;
|
||||||
|
while (cur) {
|
||||||
|
Node* temp = cur->Prev;
|
||||||
|
cur->Prev = cur->Next;
|
||||||
|
cur->Next = temp;
|
||||||
|
cur = cur->Prev;
|
||||||
|
}
|
||||||
|
Node* temp = pHead;
|
||||||
|
pHead = pTail;
|
||||||
|
pTail = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
T& Front() {
|
||||||
|
if (pHead) {
|
||||||
|
return pHead->Data;
|
||||||
|
}
|
||||||
|
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const T& Front() const {
|
||||||
|
if (pHead) {
|
||||||
|
return pHead->Data;
|
||||||
|
}
|
||||||
|
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
T& Back() {
|
||||||
|
if (pTail) {
|
||||||
|
return pTail->Data;
|
||||||
|
}
|
||||||
|
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const T& Back() const {
|
||||||
|
if (pTail) {
|
||||||
|
return pTail->Data;
|
||||||
|
}
|
||||||
|
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Size() const { return pSize; }
|
||||||
|
|
||||||
|
Iterator begin() { return Iterator(pHead); }
|
||||||
|
Iterator end() { return Iterator(nullptr); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Node* Find(const T& v) const {
|
||||||
|
Node* t = pHead;
|
||||||
|
while (t) {
|
||||||
|
if (t->Data == v) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
t = t->Next;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node* pHead = nullptr;
|
||||||
|
Node* pTail = nullptr;
|
||||||
|
size_t pSize = 0;
|
||||||
|
};
|
||||||
|
} // namespace PD
|
41
include/pd/core/sl/pair.hpp
Executable file
41
include/pd/core/sl/pair.hpp
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pd/core/common.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
class Pair {
|
||||||
|
public:
|
||||||
|
Pair() = default;
|
||||||
|
Pair(const T1& f, const T2& s) : First(f), Second(s) {}
|
||||||
|
Pair(T1&& f, T2&& s) : First(std::move(f)), Second(std::move(s)) {}
|
||||||
|
~Pair() = default;
|
||||||
|
|
||||||
|
T1 First;
|
||||||
|
T2 Second;
|
||||||
|
};
|
||||||
|
} // namespace PD
|
33
include/pd/core/sl/sl.hpp
Executable file
33
include/pd/core/sl/sl.hpp
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pd/core/sl/allocator.hpp>
|
||||||
|
#include <pd/core/sl/hashmap.hpp>
|
||||||
|
#include <pd/core/sl/list.hpp>
|
||||||
|
#include <pd/core/sl/pair.hpp>
|
||||||
|
#include <pd/core/sl/stack.hpp>
|
||||||
|
#include <pd/core/sl/tools.hpp>
|
||||||
|
#include <pd/core/sl/vector.hpp>
|
125
include/pd/overlays/overlay.hpp → include/pd/core/sl/stack.hpp
Normal file → Executable file
125
include/pd/overlays/overlay.hpp → include/pd/core/sl/stack.hpp
Normal file → Executable file
@ -1,57 +1,70 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
in the Software without restriction, including without limitation the rights
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
in the Software without restriction, including without limitation the rights
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
furnished to do so, subject to the following conditions:
|
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 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,
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
SOFTWARE.
|
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/core/common.hpp>
|
||||||
#include <pd/lithium/renderer.hpp>
|
#include <pd/core/sl/vector.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
* Overlay Template class
|
* Custom Stack class (caus std::stack ofsten lead to memory coruption)
|
||||||
*/
|
*/
|
||||||
class Overlay : public SmartCtor<Overlay> {
|
template <typename T, typename Alloc = Allocator<T>>
|
||||||
public:
|
class Stack {
|
||||||
Overlay() = default;
|
public:
|
||||||
virtual ~Overlay() = default;
|
Stack() = default;
|
||||||
|
explicit Stack(size_t cap) : pVec(cap) {}
|
||||||
/**
|
|
||||||
* Update Function for Overlay input and rendering
|
void Push(const T& val) { pVec.Add(val); }
|
||||||
* @param delta Deltatime
|
|
||||||
* @param ren Renderer reference
|
void Pop() {
|
||||||
* @param inp Input Driver
|
if (pVec.Size() == 0) {
|
||||||
*/
|
exit(1);
|
||||||
virtual void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) = 0;
|
}
|
||||||
|
pVec.PopBack();
|
||||||
/** Check if killed to remove from Overlay Manager */
|
}
|
||||||
bool IsKilled() const { return kill; }
|
|
||||||
|
T& Top() {
|
||||||
protected:
|
if (pVec.Size() == 0) {
|
||||||
/** Internall Kill function to call from your Overlay */
|
exit(1);
|
||||||
void Kill() { kill = true; }
|
}
|
||||||
|
return pVec[pVec.Size() - 1];
|
||||||
private:
|
}
|
||||||
bool kill = false; ///< Should be killed or not
|
|
||||||
};
|
const T& Top() const {
|
||||||
|
if (pVec.Size() == 0) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return pVec[pVec.Size() - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsEmpty() const { return pVec.Size() == 0; }
|
||||||
|
size_t Size() const { return pVec.Size(); }
|
||||||
|
void Clear() { pVec.Clear(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Vec<T, Alloc> pVec;
|
||||||
|
};
|
||||||
} // namespace PD
|
} // namespace PD
|
81
include/pd/app/error.hpp → include/pd/core/sl/tools.hpp
Normal file → Executable file
81
include/pd/app/error.hpp → include/pd/core/sl/tools.hpp
Normal file → Executable file
@ -1,40 +1,43 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
in the Software without restriction, including without limitation the rights
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
in the Software without restriction, including without limitation the rights
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
furnished to do so, subject to the following conditions:
|
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 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,
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
SOFTWARE.
|
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/common.hpp>
|
||||||
namespace PD {
|
|
||||||
/**
|
namespace PD {
|
||||||
* Function to Throw an Error Screen
|
/**
|
||||||
* @param error Error Message to Display
|
* Function to get Arraysize for any type using modern c++ to
|
||||||
*/
|
* get the size at compiletime instead of runtime
|
||||||
void Error(const std::string& error);
|
* @note this function only works for Arrays declared as
|
||||||
/**
|
* type arr[size] and not for pointer references.
|
||||||
* Custom Assert Function that Shows an Error Screen if it fails
|
* This function will precalculate the size at compile time
|
||||||
* @param v The bool var to check `(Throws error if it is false)`
|
* while keeping the code clean to not hardcode arraysizes
|
||||||
* @param msg The Message that Should be displayed if the Assert fails
|
* into functions like std::fill_n
|
||||||
*/
|
*/
|
||||||
void Assert(bool v, const std::string& msg);
|
template <typename T, size_t N>
|
||||||
|
constexpr size_t ArraySize(T (&)[N]) noexcept {
|
||||||
|
return N;
|
||||||
|
}
|
||||||
} // namespace PD
|
} // namespace PD
|
165
include/pd/core/sl/vector.hpp
Executable file
165
include/pd/core/sl/vector.hpp
Executable file
@ -0,0 +1,165 @@
|
|||||||
|
#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/sl/allocator.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
/**
|
||||||
|
* Open Access Vector class (Alternative to std::vector)
|
||||||
|
*/
|
||||||
|
template <typename T, typename Alloc = Allocator<T>>
|
||||||
|
class Vec {
|
||||||
|
public:
|
||||||
|
Vec() {
|
||||||
|
pData = pAllocator.Allocate(2);
|
||||||
|
pCap = 2;
|
||||||
|
Clear();
|
||||||
|
pPos = 0;
|
||||||
|
};
|
||||||
|
Vec(const size_t& Size) {
|
||||||
|
pData = pAllocator.Allocate(Size + 2);
|
||||||
|
pCap = Size + 2;
|
||||||
|
Clear();
|
||||||
|
pPos = Size;
|
||||||
|
}
|
||||||
|
Vec(const size_t& Size, const T& v) {
|
||||||
|
pData = pAllocator.Allocate(Size + 2);
|
||||||
|
pCap = Size + 2;
|
||||||
|
Clear();
|
||||||
|
pPos = Size;
|
||||||
|
std::fill_n(pData, Size, v);
|
||||||
|
}
|
||||||
|
Vec(const T* s, const T* e) {
|
||||||
|
pData = pAllocator.Allocate(2);
|
||||||
|
pCap = 2;
|
||||||
|
Clear();
|
||||||
|
pPos = 0;
|
||||||
|
Resize(e - s);
|
||||||
|
std::copy_n(s, e - s, pData);
|
||||||
|
}
|
||||||
|
Vec(const Vec& v) {
|
||||||
|
pCap = v.pCap;
|
||||||
|
pPos = v.pPos;
|
||||||
|
pData = pAllocator.Allocate(pCap);
|
||||||
|
for (size_t i = 0; i < pPos; i++) {
|
||||||
|
pData[i] = v.pData[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
~Vec() { pAllocator.Deallocate(pData); }
|
||||||
|
|
||||||
|
void Add(const T& v) {
|
||||||
|
if (pPos >= pCap) {
|
||||||
|
Reserve(pCap * 2);
|
||||||
|
}
|
||||||
|
pData[pPos++] = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PopBack() {
|
||||||
|
if (pPos == 0) return;
|
||||||
|
pPos--;
|
||||||
|
}
|
||||||
|
|
||||||
|
T Pop() {
|
||||||
|
if (pPos == 0) {
|
||||||
|
// Todo: LOG
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return pData[pPos--];
|
||||||
|
}
|
||||||
|
|
||||||
|
T& At(const size_t& Idx) {
|
||||||
|
if (Idx >= pPos) {
|
||||||
|
// Log
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return pData[Idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
const T& At(const size_t& Idx) const {
|
||||||
|
if (Idx >= pPos) {
|
||||||
|
// Log
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return pData[Idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
T& operator[](const size_t& Idx) { return At(Idx); }
|
||||||
|
const T& operator[](const size_t& Idx) const { return At(Idx); }
|
||||||
|
void operator+=(T v) { Add(v); }
|
||||||
|
|
||||||
|
T* Begin() { return pData; }
|
||||||
|
const T* Begin() const { return pData; }
|
||||||
|
T* End() { return pData + pPos; }
|
||||||
|
const T* End() const { return pData + pPos; }
|
||||||
|
|
||||||
|
// Support: `for(auto& it : Vec)` //
|
||||||
|
T* begin() { return pData; }
|
||||||
|
const T* begin() const { return pData; }
|
||||||
|
T* end() { return pData + pPos; }
|
||||||
|
const T* end() const { return pData + pPos; }
|
||||||
|
|
||||||
|
T* Data() { return pData; }
|
||||||
|
T* Data() const { return pData; }
|
||||||
|
size_t Size() const { return pPos; }
|
||||||
|
size_t Capacity() const { return pCap; }
|
||||||
|
void Clear() {
|
||||||
|
// Avoid memset to support std::string for now
|
||||||
|
// probably revert this decision based if it lacks performance
|
||||||
|
// or make it a setting
|
||||||
|
std::fill(pData, pData + pCap, T());
|
||||||
|
pPos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Reserve(const size_t& Size) {
|
||||||
|
if (Size <= pCap) return;
|
||||||
|
T* tmp = pAllocator.Allocate(Size);
|
||||||
|
std::fill(tmp, tmp + Size, T());
|
||||||
|
std::copy(pData, pData + pCap, tmp);
|
||||||
|
pAllocator.Deallocate(pData);
|
||||||
|
pData = tmp;
|
||||||
|
pCap = Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Resize(size_t Size) {
|
||||||
|
if (Size < pPos) {
|
||||||
|
pPos = Size;
|
||||||
|
} else if (Size > pCap) {
|
||||||
|
Reserve(Size);
|
||||||
|
}
|
||||||
|
std::fill(pData + pPos, pData + Size, T());
|
||||||
|
pPos = Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocator
|
||||||
|
Alloc pAllocator;
|
||||||
|
// Data Reference Pointer
|
||||||
|
T* pData;
|
||||||
|
// Capacity
|
||||||
|
size_t pCap;
|
||||||
|
// Current Position (Size)
|
||||||
|
size_t pPos;
|
||||||
|
};
|
||||||
|
} // namespace PD
|
245
include/pd/core/strings.hpp
Normal file → Executable file
245
include/pd/core/strings.hpp
Normal file → Executable file
@ -1,124 +1,123 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
* Set of String Utillity Functions
|
* Set of String Utillity Functions
|
||||||
*/
|
*/
|
||||||
namespace Strings {
|
namespace Strings {
|
||||||
/**
|
/**
|
||||||
* Check if a String ends with a specific extension
|
* Check if a String ends with a specific extension
|
||||||
* @param str Input string
|
* @param str Input string
|
||||||
* @param exts List of Extensions to check for
|
* @param exts List of Extensions to check for
|
||||||
* @return true if one of the extensions is found in the String
|
* @return true if one of the extensions is found in the String
|
||||||
*/
|
*/
|
||||||
bool StringEndsWith(const std::string& str,
|
PD_CORE_API bool StringEndsWith(const std::string& str,
|
||||||
const std::vector<std::string>& exts);
|
const std::vector<std::string>& exts);
|
||||||
/**
|
/**
|
||||||
* Function to Create a wstring of a string
|
* Function to Create a wstring of a string
|
||||||
* @param s Input String to Convert
|
* @param s Input String to Convert
|
||||||
* @return Result wstring
|
* @return Result wstring
|
||||||
* @note Currently using std::filesystem::path for this as wstring_convert
|
* @note Returns Empty if it has an error
|
||||||
* got removed in c++ 20
|
*/
|
||||||
*/
|
PD_CORE_API std::wstring MakeWstring(const std::string& s);
|
||||||
std::wstring MakeWstring(const std::string& s);
|
/**
|
||||||
/**
|
* Generate a Formatted String by an Nanoseconds Input
|
||||||
* Generate a Formatted String by an Nanoseconds Input
|
* @param nanos Nanoseconds Input
|
||||||
* @param nanos Nanoseconds Input
|
* @return Result String
|
||||||
* @return Result String
|
*/
|
||||||
*/
|
PD_CORE_API const std::string FormatNanos(unsigned long long nanos);
|
||||||
const std::string FormatNanos(unsigned long long nanos);
|
/**
|
||||||
/**
|
* Generate a Formatted String by an Milliseconds Input
|
||||||
* Generate a Formatted String by an Milliseconds Input
|
* @param millis Milliseconds Input
|
||||||
* @param millis Milliseconds Input
|
* @return Result String
|
||||||
* @return Result String
|
*/
|
||||||
*/
|
PD_CORE_API const std::string FormatMillis(unsigned long long millis);
|
||||||
const std::string FormatMillis(unsigned long long millis);
|
/**
|
||||||
/**
|
* Create a formatted String by an input bytes value
|
||||||
* Create a formatted String by an input bytes value
|
* @param bytes value in bytes
|
||||||
* @param bytes value in bytes
|
* @result Formatted String for example `2.5MB`
|
||||||
* @result Formatted String for example `2.5MB`
|
*/
|
||||||
*/
|
PD_CORE_API const std::string FormatBytes(unsigned long long bytes);
|
||||||
const std::string FormatBytes(unsigned long long bytes);
|
/**
|
||||||
/**
|
* Extract the Filename out of a Path
|
||||||
* Extract the Filename out of a Path
|
* @param path Path to extract from
|
||||||
* @param path Path to extract from
|
* @param saperators Path Split Chars
|
||||||
* @param saperators Path Split Chars
|
* @return extracted filename
|
||||||
* @return extracted filename
|
*/
|
||||||
*/
|
PD_CORE_API const std::string GetFileName(
|
||||||
const std::string GetFileName(const std::string& path,
|
const std::string& path, const std::string& saperators = "/\\");
|
||||||
const std::string& saperators = "/\\");
|
/**
|
||||||
/**
|
* Remove Extension from a Path / Filename
|
||||||
* Remove Extension from a Path / Filename
|
* @param path Input Path
|
||||||
* @param path Input Path
|
* @return Path without Extension
|
||||||
* @return Path without Extension
|
*/
|
||||||
*/
|
PD_CORE_API const std::string PathRemoveExtension(const std::string& path);
|
||||||
const std::string PathRemoveExtension(const std::string& path);
|
/**
|
||||||
/**
|
* Function to Convert a Type to a hex value
|
||||||
* Function to Convert a Type to a hex value
|
* @tparam T Type
|
||||||
* @tparam T Type
|
* @param v value
|
||||||
* @param v value
|
* @return hex string beginning with 0x
|
||||||
* @return hex string beginning with 0x
|
*/
|
||||||
*/
|
template <typename T>
|
||||||
template <typename T>
|
inline const std::string ToHex(const T& v) {
|
||||||
inline const std::string ToHex(const T& v) {
|
std::stringstream s;
|
||||||
std::stringstream s;
|
s << "0x" << std::setfill('0') << std::setw(sizeof(v) * 2) << std::hex << v;
|
||||||
s << "0x" << std::setfill('0') << std::setw(sizeof(v) * 2) << std::hex << v;
|
return s.str();
|
||||||
return s.str();
|
}
|
||||||
}
|
/**
|
||||||
/**
|
* Generate a Hash out of a string
|
||||||
* Generate a Hash out of a string
|
* @param s String to hash
|
||||||
* @param s String to hash
|
* @return 32Bit Hash
|
||||||
* @return 32Bit Hash
|
*/
|
||||||
*/
|
PD_CORE_API u32 FastHash(const std::string& s);
|
||||||
u32 FastHash(const std::string& s);
|
/**
|
||||||
/**
|
* Function to Generate a Compiler Name and Version String
|
||||||
* Function to Generate a Compiler Name and Version String
|
* Based on their Macros
|
||||||
* Based on their Macros
|
* @return CompilerName: Version
|
||||||
* @return CompilerName: Version
|
*/
|
||||||
*/
|
inline const std::string GetCompilerVersion() {
|
||||||
inline const std::string GetCompilerVersion() {
|
/// As the function looks like this Project is meant to
|
||||||
/// As the function looks like this Project is meant to
|
/// Be ported to other systems as well
|
||||||
/// Be ported to other systems as well
|
std::stringstream res;
|
||||||
std::stringstream res;
|
#ifdef __clang__ // Check clang first
|
||||||
#ifdef __GNUC__
|
res << "Clang: " << __clang_major__ << ".";
|
||||||
res << "GCC: " << __GNUC__;
|
res << __clang_minor__ << ".";
|
||||||
res << "." << __GNUC_MINOR__ << ".";
|
res << __clang_patchlevel__;
|
||||||
res << __GNUC_PATCHLEVEL__;
|
#elif __GNUC__
|
||||||
#elif __clang__
|
res << "GCC: " << __GNUC__;
|
||||||
res << "Clang: " << __clang_major__ << ".";
|
res << "." << __GNUC_MINOR__ << ".";
|
||||||
res << __clang_minor__ << ".";
|
res << __GNUC_PATCHLEVEL__;
|
||||||
res << __clang_patchlevel__;
|
#elif _MSC_VER
|
||||||
#elif _MSC_VER
|
res << "MSVC: " << _MSC_VER;
|
||||||
res << "MSVC: " << _MSC_VER;
|
#else
|
||||||
#else
|
res << "Unknown Compiler";
|
||||||
res << "Unknown Compiler";
|
#endif
|
||||||
#endif
|
return res.str();
|
||||||
return res.str();
|
}
|
||||||
}
|
} // namespace Strings
|
||||||
} // namespace Strings
|
|
||||||
} // namespace PD
|
} // namespace PD
|
167
include/pd/core/timer.hpp
Normal file → Executable file
167
include/pd/core/timer.hpp
Normal file → Executable file
@ -1,84 +1,85 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/common.hpp>
|
||||||
#include <pd/core/sys.hpp>
|
|
||||||
|
namespace PD {
|
||||||
namespace PD {
|
/**
|
||||||
/**
|
* Timer class
|
||||||
* Timer class
|
*/
|
||||||
*/
|
class PD_CORE_API Timer {
|
||||||
class Timer : public SmartCtor<Timer> {
|
public:
|
||||||
public:
|
/**
|
||||||
/**
|
* Constructor
|
||||||
* Constructor
|
* @param auto_start [default true] sets if timer should start after creation
|
||||||
* @param auto_start [default true] sets if timer should start after creation
|
*/
|
||||||
*/
|
Timer(bool auto_start = true);
|
||||||
Timer(bool auto_start = true);
|
/**
|
||||||
/**
|
* Unused Deconstructor
|
||||||
* Unused Deconstructor
|
*/
|
||||||
*/
|
~Timer() {}
|
||||||
~Timer() {}
|
|
||||||
/**
|
PD_SHARED(Timer);
|
||||||
* Resume Timer if Paused
|
|
||||||
*/
|
/**
|
||||||
void Rseume();
|
* Resume Timer if Paused
|
||||||
/**
|
*/
|
||||||
* Pause Timer if not Paused
|
void Rseume();
|
||||||
*/
|
/**
|
||||||
void Pause();
|
* Pause Timer if not Paused
|
||||||
/**
|
*/
|
||||||
* Update Timer
|
void Pause();
|
||||||
*/
|
/**
|
||||||
void Update();
|
* Update Timer
|
||||||
/**
|
*/
|
||||||
* Reset Timer
|
void Update();
|
||||||
*/
|
/**
|
||||||
void Reset();
|
* Reset Timer
|
||||||
/**
|
*/
|
||||||
* Check if the Timer is Running
|
void Reset();
|
||||||
* @return true if its running
|
/**
|
||||||
*/
|
* Check if the Timer is Running
|
||||||
bool IsRunning() const;
|
* @return true if its running
|
||||||
/**
|
*/
|
||||||
* Get 64 Bit milliseconds value
|
bool IsRunning() const;
|
||||||
* @return 64Bit millis
|
/**
|
||||||
*/
|
* Get 64 Bit milliseconds value
|
||||||
u64 Get();
|
* @return 64Bit millis
|
||||||
/**
|
*/
|
||||||
* Get as Seconds
|
u64 Get();
|
||||||
* @return seconds as floating number
|
/**
|
||||||
*/
|
* Get as Seconds
|
||||||
double GetSeconds();
|
* @return seconds as floating number
|
||||||
|
*/
|
||||||
private:
|
double GetSeconds();
|
||||||
/** Start of the Timer */
|
|
||||||
u64 start;
|
/** Start of the Timer */
|
||||||
/** Current Time */
|
u64 pStart;
|
||||||
u64 now;
|
/** Current Time */
|
||||||
/** Is Running */
|
u64 pNow;
|
||||||
bool is_running = false;
|
/** Is Running */
|
||||||
};
|
bool pIsRunning = false;
|
||||||
|
};
|
||||||
} // namespace PD
|
} // namespace PD
|
512
include/pd/core/timetrace.hpp
Normal file → Executable file
512
include/pd/core/timetrace.hpp
Normal file → Executable file
@ -1,255 +1,259 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
* Class to calculate Maximum/Minimum and Average Timings
|
* Class to calculate Maximum/Minimum and Average Timings
|
||||||
*/
|
*/
|
||||||
class TimeStats : public SmartCtor<TimeStats> {
|
class TimeStats {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor taking a lengh for the List
|
* Constructor taking a lengh for the List
|
||||||
* @param l Lengh of the data list
|
* @param l Lengh of the data list
|
||||||
*/
|
*/
|
||||||
TimeStats(int l) : len(l), val(l, 0) {}
|
TimeStats(int l) : len(l), val(l, 0) {}
|
||||||
~TimeStats() = default;
|
~TimeStats() = default;
|
||||||
|
|
||||||
/**
|
PD_SHARED(TimeStats);
|
||||||
* Add a New Value to the list
|
|
||||||
* @param v value to add
|
/**
|
||||||
*/
|
* Add a New Value to the list
|
||||||
void Add(u64 v) {
|
* @param v value to add
|
||||||
val[idx] = v;
|
*/
|
||||||
idx = next(idx);
|
void Add(u64 v) {
|
||||||
num_val = std::min(num_val + 1, len);
|
val[idx] = v;
|
||||||
}
|
idx = next(idx);
|
||||||
|
num_val = std::min(num_val + 1, len);
|
||||||
/**
|
}
|
||||||
* Get Avarage Num
|
|
||||||
* @return Average
|
/**
|
||||||
*/
|
* Get Avarage Num
|
||||||
u64 GetAverage() {
|
* @return Average
|
||||||
if (!num_val) return 0.f;
|
*/
|
||||||
u64 res = 0;
|
u64 GetAverage() {
|
||||||
for (int i = 0; i < num_val; i++) {
|
if (!num_val) return 0.f;
|
||||||
res += val[smart_idx(i)];
|
u64 res = 0;
|
||||||
}
|
for (int i = 0; i < num_val; i++) {
|
||||||
return res / num_val;
|
res += val[smart_idx(i)];
|
||||||
}
|
}
|
||||||
|
return res / num_val;
|
||||||
/**
|
}
|
||||||
* Get Minimum Num
|
|
||||||
* @return Minimum value
|
/**
|
||||||
*/
|
* Get Minimum Num
|
||||||
u64 GetMin() {
|
* @return Minimum value
|
||||||
if (!num_val) return 0.f;
|
*/
|
||||||
u64 res = std::numeric_limits<u64>::max();
|
u64 GetMin() {
|
||||||
for (int i = 0; i < num_val; i++) {
|
if (!num_val) return 0.f;
|
||||||
res = std::min(val[smart_idx(i)], res);
|
u64 res = std::numeric_limits<u64>::max();
|
||||||
}
|
for (int i = 0; i < num_val; i++) {
|
||||||
return res;
|
res = std::min(val[smart_idx(i)], res);
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
/**
|
}
|
||||||
* Get Maximum Value
|
|
||||||
* @return Max Value
|
/**
|
||||||
*/
|
* Get Maximum Value
|
||||||
u64 GetMax() {
|
* @return Max Value
|
||||||
if (!num_val) return 0.f;
|
*/
|
||||||
u64 res = 0;
|
u64 GetMax() {
|
||||||
for (int i = 0; i < num_val; i++) {
|
if (!num_val) return 0.f;
|
||||||
res = std::max(val[smart_idx(i)], res);
|
u64 res = 0;
|
||||||
}
|
for (int i = 0; i < num_val; i++) {
|
||||||
return res;
|
res = std::max(val[smart_idx(i)], res);
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
/**
|
}
|
||||||
* Clear the List
|
|
||||||
*/
|
/**
|
||||||
void Clear() {
|
* Clear the List
|
||||||
val.assign(len, 0);
|
*/
|
||||||
idx = 0;
|
void Clear() {
|
||||||
num_val = 0;
|
val.assign(len, 0);
|
||||||
}
|
idx = 0;
|
||||||
|
num_val = 0;
|
||||||
/**
|
}
|
||||||
* Get Data Buffer
|
|
||||||
* @return data bufer (not edidable)
|
/**
|
||||||
*/
|
* Get Data Buffer
|
||||||
const std::vector<u64> &GetData() { return val; }
|
* @return data bufer (not edidable)
|
||||||
/**
|
*/
|
||||||
* Access an element in the list [not edidable]
|
const std::vector<u64> &GetData() { return val; }
|
||||||
* @return value to access
|
/**
|
||||||
*/
|
* Access an element in the list [not edidable]
|
||||||
const u64 &operator[](int i) { return val[smart_idx(i)]; }
|
* @return value to access
|
||||||
/**
|
*/
|
||||||
* Get List Lengh
|
const u64 &operator[](int i) { return val[smart_idx(i)]; }
|
||||||
* @return Lengh
|
/**
|
||||||
*/
|
* Get List Lengh
|
||||||
const size_t GetLen() { return len; }
|
* @return Lengh
|
||||||
/**
|
*/
|
||||||
* Get Number of Values
|
const size_t GetLen() { return len; }
|
||||||
* @return number of values
|
/**
|
||||||
*/
|
* Get Number of Values
|
||||||
const size_t GetNumValues() { return num_val; }
|
* @return number of values
|
||||||
|
*/
|
||||||
private:
|
const size_t GetNumValues() { return num_val; }
|
||||||
/**
|
|
||||||
* Get the Next Position to write to
|
private:
|
||||||
* @param c current position
|
/**
|
||||||
* @return next position
|
* Get the Next Position to write to
|
||||||
*/
|
* @param c current position
|
||||||
size_t next(size_t c) const { return (c + 1) % len; }
|
* @return next position
|
||||||
/**
|
*/
|
||||||
* Smart Indexing in for loops to make sure to
|
size_t next(size_t c) const { return (c + 1) % len; }
|
||||||
* not index a value that was not set yet
|
/**
|
||||||
* @param v pos in for loop
|
* Smart Indexing in for loops to make sure to
|
||||||
* @return indexing pos
|
* not index a value that was not set yet
|
||||||
*/
|
* @param v pos in for loop
|
||||||
size_t smart_idx(size_t v) const { return (idx + len - num_val + v) % len; }
|
* @return indexing pos
|
||||||
|
*/
|
||||||
/** Lengh of the list */
|
size_t smart_idx(size_t v) const { return (idx + len - num_val + v) % len; }
|
||||||
int len = 0;
|
|
||||||
/** Value Storage */
|
/** Lengh of the list */
|
||||||
std::vector<u64> val;
|
int len = 0;
|
||||||
int idx = 0;
|
/** Value Storage */
|
||||||
int num_val = 0;
|
std::vector<u64> val;
|
||||||
};
|
int idx = 0;
|
||||||
/**
|
int num_val = 0;
|
||||||
* Timatrace Functions
|
};
|
||||||
*/
|
/**
|
||||||
namespace TT {
|
* Timatrace Functions
|
||||||
/**
|
*/
|
||||||
* Data Structure for a TimeTrace Result
|
namespace TT {
|
||||||
*/
|
/**
|
||||||
class Res : public SmartCtor<Res> {
|
* Data Structure for a TimeTrace Result
|
||||||
public:
|
*/
|
||||||
/** Constructore that Inits a protocol at size of 60 frames */
|
class Res {
|
||||||
Res() { protocol = TimeStats::New(60); }
|
public:
|
||||||
~Res() = default;
|
/** Constructore that Inits a protocol at size of 60 frames */
|
||||||
|
Res(): start(0), end(0) { protocol = TimeStats::New(60); }
|
||||||
/**
|
~Res() = default;
|
||||||
* Setter for the ID (Name)
|
|
||||||
* @param v ID of the Trace
|
PD_SHARED(Res);
|
||||||
*/
|
|
||||||
void SetID(const std::string &v) { id = v; }
|
/**
|
||||||
/**
|
* Setter for the ID (Name)
|
||||||
* Getter for the traces ID
|
* @param v ID of the Trace
|
||||||
* @return Trace ID
|
*/
|
||||||
*/
|
void SetID(const std::string &v) { id = v; }
|
||||||
const std::string GetID() { return id; }
|
/**
|
||||||
/**
|
* Getter for the traces ID
|
||||||
* Setter for the Start Value
|
* @return Trace ID
|
||||||
* @param v start time
|
*/
|
||||||
*/
|
const std::string GetID() { return id; }
|
||||||
void SetStart(u64 v) { start = v; }
|
/**
|
||||||
/**
|
* Setter for the Start Value
|
||||||
* Getter for the Start time
|
* @param v start time
|
||||||
* @return start time
|
*/
|
||||||
*/
|
void SetStart(u64 v) { start = v; }
|
||||||
u64 GetStart() { return start; }
|
/**
|
||||||
/**
|
* Getter for the Start time
|
||||||
* Setter for the End Time
|
* @return start time
|
||||||
* @param v end time
|
*/
|
||||||
*/
|
u64 GetStart() { return start; }
|
||||||
void SetEnd(u64 v) {
|
/**
|
||||||
end = v;
|
* Setter for the End Time
|
||||||
protocol->Add(GetLastDiff());
|
* @param v end time
|
||||||
}
|
*/
|
||||||
/**
|
void SetEnd(u64 v) {
|
||||||
* Getter for the End Time
|
end = v;
|
||||||
* @result end time
|
protocol->Add(GetLastDiff());
|
||||||
*/
|
}
|
||||||
u64 GetEnd() { return end; }
|
/**
|
||||||
|
* Getter for the End Time
|
||||||
/**
|
* @result end time
|
||||||
* Get Last Diffrence between end and start
|
*/
|
||||||
* @return end - start
|
u64 GetEnd() { return end; }
|
||||||
*/
|
|
||||||
u64 GetLastDiff() { return end - start; }
|
/**
|
||||||
/**
|
* Get Last Diffrence between end and start
|
||||||
* Get Protcol Reference
|
* @return end - start
|
||||||
* @return Protocol Ref
|
*/
|
||||||
*/
|
u64 GetLastDiff() { return end - start; }
|
||||||
TimeStats::Ref GetProtocol() { return protocol; }
|
/**
|
||||||
|
* Get Protcol Reference
|
||||||
private:
|
* @return Protocol Ref
|
||||||
/** Trace ID */
|
*/
|
||||||
std::string id;
|
TimeStats::Ref GetProtocol() { return protocol; }
|
||||||
/** Start time */
|
|
||||||
u64 start;
|
private:
|
||||||
/** End Time */
|
/** Trace ID */
|
||||||
u64 end;
|
std::string id;
|
||||||
/** Protocol */
|
/** Start time */
|
||||||
TimeStats::Ref protocol;
|
u64 start;
|
||||||
};
|
/** End Time */
|
||||||
/**
|
u64 end;
|
||||||
* Begin a Trace
|
/** Protocol */
|
||||||
* @param id Name of the Trace
|
TimeStats::Ref protocol;
|
||||||
*/
|
};
|
||||||
void Beg(const std::string &id);
|
/**
|
||||||
/**
|
* Begin a Trace
|
||||||
* End a Trace
|
* @param id Name of the Trace
|
||||||
* @param id Name of the Trace
|
*/
|
||||||
*/
|
PD_CORE_API void Beg(const std::string &id);
|
||||||
void End(const std::string &id);
|
/**
|
||||||
/**
|
* End a Trace
|
||||||
* Collect Start end end of the trace by tracking
|
* @param id Name of the Trace
|
||||||
* when the Scope object goes out of scope
|
*/
|
||||||
*
|
PD_CORE_API void End(const std::string &id);
|
||||||
* Example:
|
/**
|
||||||
* ```cpp
|
* Collect Start end end of the trace by tracking
|
||||||
* void SomeFunction() {
|
* when the Scope object goes out of scope
|
||||||
* // Create a Scoped Trace called "SomeFunc"
|
*
|
||||||
* PD::TT::Scope st("SomeFunc");
|
* Example:
|
||||||
* // Do your functions stuff
|
* ```cpp
|
||||||
* // End at the end it goes out of
|
* void SomeFunction() {
|
||||||
* // scope which collects the end time
|
* // Create a Scoped Trace called "SomeFunc"
|
||||||
* }
|
* PD::TT::Scope st("SomeFunc");
|
||||||
* ```
|
* // Do your functions stuff
|
||||||
*/
|
* // End at the end it goes out of
|
||||||
class Scope {
|
* // scope which collects the end time
|
||||||
public:
|
* }
|
||||||
/**
|
* ```
|
||||||
* Constructor requiring a Name for the Trace
|
*/
|
||||||
* @param id Name of the Trace
|
class Scope {
|
||||||
*/
|
public:
|
||||||
Scope(const std::string &id) {
|
/**
|
||||||
this->id = id;
|
* Constructor requiring a Name for the Trace
|
||||||
Beg(id);
|
* @param id Name of the Trace
|
||||||
}
|
*/
|
||||||
/**
|
Scope(const std::string &id) {
|
||||||
* Deconstructor getting the end time when going out of scope
|
this->ID = id;
|
||||||
*/
|
Beg(id);
|
||||||
~Scope() { End(id); }
|
}
|
||||||
|
/**
|
||||||
private:
|
* Deconstructor getting the end time when going out of scope
|
||||||
/** Trace Name/ID */
|
*/
|
||||||
std::string id;
|
~Scope() { End(ID); }
|
||||||
};
|
|
||||||
} // namespace TT
|
private:
|
||||||
|
/** Trace Name/ID */
|
||||||
|
std::string ID;
|
||||||
|
};
|
||||||
|
} // namespace TT
|
||||||
} // namespace PD
|
} // namespace PD
|
448
include/pd/core/tween.hpp
Normal file → Executable file
448
include/pd/core/tween.hpp
Normal file → Executable file
@ -1,222 +1,228 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/vec.hpp>
|
#include <pd/core/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
#ifndef M_PI
|
||||||
/**
|
#define M_PI 3.14159265358979323846
|
||||||
* D7 Tween Engine (or something like that)
|
#endif
|
||||||
* @tparam T Any Numeric value
|
|
||||||
*/
|
namespace PD {
|
||||||
template <typename T>
|
/**
|
||||||
class Tween {
|
* D7 Tween Engine (or something like that)
|
||||||
public:
|
* @tparam T Any Numeric value
|
||||||
/**
|
*/
|
||||||
* Effects Table
|
template <typename T>
|
||||||
*/
|
class Tween {
|
||||||
enum Effect {
|
public:
|
||||||
Linear, ///< Linear Movement [works]
|
/**
|
||||||
EaseInQuad, ///< EaseInQuad Movement [works]
|
* Effects Table
|
||||||
EaseOutQuad, ///< EaseOutQuad Movement [works]
|
*/
|
||||||
EaseInOutQuad, ///< EaseInOutQuad Movement [works]
|
enum Effect {
|
||||||
EaseInCubic, ///< EaseInCubic Movement [not tested]
|
Linear, ///< Linear Movement [works]
|
||||||
EaseOutCubic, ///< EaseOutCubic Movement [not tested]
|
EaseInQuad, ///< EaseInQuad Movement [works]
|
||||||
EaseInOutCubic, ///< EaseInOutCubic Movement [disabled]
|
EaseOutQuad, ///< EaseOutQuad Movement [works]
|
||||||
EaseInSine, ///< EaseInSine Movement [works]
|
EaseInOutQuad, ///< EaseInOutQuad Movement [works]
|
||||||
EaseOutSine, ///< EaseOutSine Movement [works]
|
EaseInCubic, ///< EaseInCubic Movement [not tested]
|
||||||
EaseInOutSine, ///< EaseInOutSine Movement [not tested]
|
EaseOutCubic, ///< EaseOutCubic Movement [not tested]
|
||||||
};
|
EaseInOutCubic, ///< EaseInOutCubic Movement [disabled]
|
||||||
Tween() = default;
|
EaseInSine, ///< EaseInSine Movement [works]
|
||||||
~Tween() = default;
|
EaseOutSine, ///< EaseOutSine Movement [works]
|
||||||
|
EaseInOutSine, ///< EaseInOutSine Movement [not tested]
|
||||||
/**
|
};
|
||||||
* Update Tween
|
Tween() = default;
|
||||||
* @param delta deltatime
|
~Tween() = default;
|
||||||
*/
|
|
||||||
void Update(float delta) {
|
/**
|
||||||
time += delta / 1000.f;
|
* Update Tween
|
||||||
if (time > tend) {
|
* @param delta deltatime
|
||||||
finished = true;
|
*/
|
||||||
time = tend;
|
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; }
|
/**
|
||||||
|
* Check if Tween is finished
|
||||||
/**
|
* @return true if finished
|
||||||
* Force finish the animation
|
*/
|
||||||
* @return Class reference
|
bool IsFinished() const { return finished; }
|
||||||
*/
|
|
||||||
Tween& Finish() {
|
/**
|
||||||
time = tend;
|
* Force finish the animation
|
||||||
finished = true;
|
* @return Class reference
|
||||||
return *this;
|
*/
|
||||||
}
|
Tween& Finish() {
|
||||||
|
time = tend;
|
||||||
/**
|
finished = true;
|
||||||
* Set Start Value
|
return *this;
|
||||||
* @tparam T datatype of the Tween
|
}
|
||||||
* @param start Start Value
|
|
||||||
* @return class Reference
|
/**
|
||||||
*/
|
* Set Start Value
|
||||||
Tween& From(const T& start) {
|
* @tparam T datatype of the Tween
|
||||||
Reset();
|
* @param start Start Value
|
||||||
this->start = start;
|
* @return class Reference
|
||||||
return *this;
|
*/
|
||||||
}
|
Tween& From(const T& start) {
|
||||||
/**
|
Reset();
|
||||||
* Set End Value
|
this->start = start;
|
||||||
* @tparam T datatype of the Tween
|
return *this;
|
||||||
* @param end End Value
|
}
|
||||||
* @return class Reference
|
/**
|
||||||
*/
|
* Set End Value
|
||||||
Tween& To(const T& end) {
|
* @tparam T datatype of the Tween
|
||||||
Reset();
|
* @param end End Value
|
||||||
this->end = end;
|
* @return class Reference
|
||||||
return *this;
|
*/
|
||||||
}
|
Tween& To(const T& end) {
|
||||||
/**
|
Reset();
|
||||||
* Set the Duration (in seconds)
|
this->end = end;
|
||||||
* @param seconds Duration
|
return *this;
|
||||||
* @return class Reference
|
}
|
||||||
*/
|
/**
|
||||||
Tween& In(float seconds) {
|
* Set the Duration (in seconds)
|
||||||
Reset();
|
* @param seconds Duration
|
||||||
tend = seconds;
|
* @return class Reference
|
||||||
return *this;
|
*/
|
||||||
}
|
Tween& In(float seconds) {
|
||||||
/**
|
Reset();
|
||||||
* Set Effect of the Tween
|
tend = seconds;
|
||||||
* @param e Effect
|
return *this;
|
||||||
* @return class Reference
|
}
|
||||||
*/
|
/**
|
||||||
Tween& As(const Effect& e) {
|
* Set Effect of the Tween
|
||||||
effect = e;
|
* @param e Effect
|
||||||
return *this;
|
* @return class Reference
|
||||||
}
|
*/
|
||||||
/**
|
Tween& As(const Effect& e) {
|
||||||
* Reset to time 0
|
effect = e;
|
||||||
* @return class Reference
|
return *this;
|
||||||
*/
|
}
|
||||||
Tween& Reset() {
|
/**
|
||||||
finished = false;
|
* Reset to time 0
|
||||||
time = 0.f;
|
* @return class Reference
|
||||||
return *this;
|
*/
|
||||||
}
|
Tween& Reset() {
|
||||||
/**
|
finished = false;
|
||||||
* Get the Prograss in percent (0.0 to 1.0) of the tween
|
time = 0.f;
|
||||||
* @return progress value
|
return *this;
|
||||||
*/
|
}
|
||||||
float Progress() const { return time / tend; }
|
/**
|
||||||
|
* Get the Prograss in percent (0.0 to 1.0) of the tween
|
||||||
/**
|
* @return progress value
|
||||||
* Swap Start and end Position of the Tween
|
*/
|
||||||
* @return class reference
|
float Progress() const { return time / tend; }
|
||||||
*/
|
|
||||||
Tween& Swap() {
|
/**
|
||||||
T temp = start;
|
* Swap Start and end Position of the Tween
|
||||||
start = end;
|
* @return class reference
|
||||||
end = temp;
|
*/
|
||||||
return *this;
|
Tween& Swap() {
|
||||||
}
|
T temp = start;
|
||||||
|
start = end;
|
||||||
/**
|
end = temp;
|
||||||
* Operator that returns the current value calculated
|
return *this;
|
||||||
* by time and effect
|
}
|
||||||
*/
|
|
||||||
operator T() {
|
T Get() const {
|
||||||
float t = 0.f;
|
float t = 0.f;
|
||||||
switch (effect) {
|
switch (effect) {
|
||||||
case EaseInQuad:
|
case EaseInQuad:
|
||||||
t = time / tend;
|
t = time / tend;
|
||||||
return (end - start) * t * t + start;
|
return (end - start) * t * t + start;
|
||||||
break;
|
break;
|
||||||
case EaseOutQuad:
|
case EaseOutQuad:
|
||||||
t = time / tend;
|
t = time / tend;
|
||||||
return -(end - start) * t * (t - 2) + start;
|
return -(end - start) * t * (t - 2) + start;
|
||||||
break;
|
break;
|
||||||
case EaseInOutQuad:
|
case EaseInOutQuad:
|
||||||
t = time / (tend / 2);
|
t = time / (tend / 2);
|
||||||
if (t < 1) return (end - start) / 2 * t * t + start;
|
if (t < 1) return (end - start) / 2 * t * t + start;
|
||||||
t--;
|
t--;
|
||||||
return -(end - start) / 2 * (t * (t - 2) - 1) + start;
|
return -(end - start) / 2 * (t * (t - 2) - 1) + start;
|
||||||
break;
|
break;
|
||||||
case EaseInCubic:
|
case EaseInCubic:
|
||||||
t = time / tend;
|
t = time / tend;
|
||||||
return (end - start) * t * t * t + start;
|
return (end - start) * t * t * t + start;
|
||||||
break;
|
break;
|
||||||
case EaseOutCubic:
|
case EaseOutCubic:
|
||||||
t = time / tend;
|
t = time / tend;
|
||||||
t--;
|
t--;
|
||||||
return (end - start) * (t * t * t + 1) + start;
|
return (end - start) * (t * t * t + 1) + start;
|
||||||
break;
|
break;
|
||||||
// case EaseInOutCubic:
|
// case EaseInOutCubic:
|
||||||
// t = time / (tend / 2);
|
// t = time / (tend / 2);
|
||||||
// if (t < 1) return (end - start) / 2 * t * t * t + start;
|
// if (t < 1) return (end - start) / 2 * t * t * t + start;
|
||||||
// t--;
|
// t--;
|
||||||
// return (end - start) / 2 * (t * t * t * 2) + start;
|
// return (end - start) / 2 * (t * t * t * 2) + start;
|
||||||
// break;
|
// break;
|
||||||
case EaseInSine:
|
case EaseInSine:
|
||||||
return -(end - start) * cos(time / tend * (M_PI / 2)) + (end - start) +
|
return -(end - start) * cos(time / tend * (M_PI / 2)) + (end - start) +
|
||||||
start;
|
start;
|
||||||
break;
|
break;
|
||||||
case EaseOutSine:
|
case EaseOutSine:
|
||||||
return (end - start) * sin(time / tend * (M_PI / 2)) + start;
|
return (end - start) * sin(time / tend * (M_PI / 2)) + start;
|
||||||
break;
|
break;
|
||||||
case EaseInOutSine:
|
case EaseInOutSine:
|
||||||
return -(end - start) / 2 * (cos(M_PI * time / tend) - 1) + start;
|
return -(end - start) / 2 * (cos(M_PI * time / tend) - 1) + start;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // Linear
|
default: // Linear
|
||||||
return (end - start) * (time / tend) + start;
|
return (end - start) * (time / tend) + start;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
/**
|
||||||
/** Animation Effect */
|
* Operator that returns the current value calculated
|
||||||
Effect effect;
|
* by time and effect
|
||||||
/** Time */
|
*/
|
||||||
float time = 0.f;
|
operator T() const { return Get(); }
|
||||||
/**
|
|
||||||
* End time
|
private:
|
||||||
* Defaulting to one to prevent div zero
|
/** Animation Effect */
|
||||||
* without a safetey check
|
Effect effect;
|
||||||
* not implementing one cause if the user is
|
/** Time */
|
||||||
* Writing a In(0.f) its their fault
|
float time = 0.f;
|
||||||
*/
|
/**
|
||||||
float tend = 1.f;
|
* End time
|
||||||
/** Start value */
|
* Defaulting to one to prevent div zero
|
||||||
T start;
|
* without a safetey check
|
||||||
/** end value */
|
* not implementing one cause if the user is
|
||||||
T end;
|
* Writing a In(0.f) its their fault
|
||||||
/** is finished value */
|
*/
|
||||||
bool finished = false;
|
float tend = 1.f;
|
||||||
};
|
/** Start value */
|
||||||
|
T start;
|
||||||
|
/** end value */
|
||||||
|
T end;
|
||||||
|
/** is finished value */
|
||||||
|
bool finished = false;
|
||||||
|
};
|
||||||
} // namespace PD
|
} // namespace PD
|
484
include/pd/core/vec.hpp
Normal file → Executable file
484
include/pd/core/vec.hpp
Normal file → Executable file
@ -1,424 +1,60 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
in the Software without restriction, including without limitation the rights
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
in the Software without restriction, including without limitation the rights
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
furnished to do so, subject to the following conditions:
|
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 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,
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
SOFTWARE.
|
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
|
#include <pd/core/common.hpp>
|
||||||
// and easy to use like in glsl or glm
|
#include <pd/core/vec2.hpp>
|
||||||
|
#include <pd/core/vec3.hpp>
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/vec4.hpp>
|
||||||
|
|
||||||
namespace PD {
|
/** Define Formatters for C++ 20 */
|
||||||
struct vec2 {
|
|
||||||
// Init Funcs
|
/**
|
||||||
vec2() {
|
* WHY DOES MSVC ALWAYS NEED THESE EXTRA THINGS
|
||||||
v[0] = 0;
|
*/
|
||||||
v[1] = 0;
|
|
||||||
}
|
template <typename T, typename CharT>
|
||||||
vec2(float x, float y) {
|
struct std::formatter<PD::vec2<T>, CharT> : std::formatter<T, CharT> {
|
||||||
v[0] = x;
|
template <typename FormatContext>
|
||||||
v[1] = y;
|
auto format(const PD::vec2<T>& v, FormatContext& ctx) const {
|
||||||
}
|
return std::format_to(ctx.out(), "({}, {})", v.x, v.y);
|
||||||
vec2(const vec2 &i) {
|
}
|
||||||
v[0] = i[0];
|
};
|
||||||
v[1] = i[1];
|
|
||||||
}
|
template <typename T, typename CharT>
|
||||||
vec2(float i) {
|
struct std::formatter<PD::vec3<T>, CharT> : std::formatter<T, CharT> {
|
||||||
v[0] = i;
|
template <typename FormatContext>
|
||||||
v[1] = i;
|
auto format(const PD::vec3<T>& v, FormatContext& ctx) const {
|
||||||
}
|
return std::format_to(ctx.out(), "({}, {}, {})", v.x, v.y, v.z);
|
||||||
|
}
|
||||||
// Operations
|
};
|
||||||
// Add
|
|
||||||
vec2 &operator+=(const vec2 &i) {
|
template <typename T, typename CharT>
|
||||||
v[0] += i[0];
|
struct std::formatter<PD::vec4<T>, CharT> : std::formatter<T, CharT> {
|
||||||
v[1] += i[1];
|
template <typename FormatContext>
|
||||||
return *this;
|
auto format(const PD::vec4<T>& v, FormatContext& ctx) const {
|
||||||
}
|
return std::format_to(ctx.out(), "({}, {}, {}, {})", v.x, v.y, v.z, v.w);
|
||||||
|
}
|
||||||
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
|
|
164
include/pd/core/vec2.hpp
Executable file
164
include/pd/core/vec2.hpp
Executable file
@ -0,0 +1,164 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This file is generated by lazyvec
|
||||||
|
#include <pd/core/common.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
template <typename T>
|
||||||
|
class vec2 {
|
||||||
|
public:
|
||||||
|
T x;
|
||||||
|
T y;
|
||||||
|
|
||||||
|
vec2() : x(0), y(0) {}
|
||||||
|
template <typename T1>
|
||||||
|
vec2(T1 v) {
|
||||||
|
x = (T)v;
|
||||||
|
y = (T)v;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2(vec2<T1> v) {
|
||||||
|
x = (T)v.x;
|
||||||
|
y = (T)v.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2(T x, T y) : x(x), y(y) {}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T>& operator+=(T1 v) {
|
||||||
|
x += (T)v;
|
||||||
|
y += (T)v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T>& operator+=(const vec2<T1>& v) {
|
||||||
|
x += (T)v.x;
|
||||||
|
y += (T)v.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T> operator+(T1 v) const {
|
||||||
|
return vec2<T>(x + (T)v, y + (T)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T> operator+(const vec2<T1>& v) const {
|
||||||
|
return vec2<T>(x + (T)v.x, y + (T)v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T>& operator-=(T1 v) {
|
||||||
|
x -= (T)v;
|
||||||
|
y -= (T)v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T>& operator-=(const vec2<T1>& v) {
|
||||||
|
x -= (T)v.x;
|
||||||
|
y -= (T)v.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T> operator-(T1 v) const {
|
||||||
|
return vec2<T>(x - (T)v, y - (T)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T> operator-(const vec2<T1>& v) const {
|
||||||
|
return vec2<T>(x - (T)v.x, y - (T)v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T>& operator*=(T1 v) {
|
||||||
|
x *= (T)v;
|
||||||
|
y *= (T)v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T>& operator*=(const vec2<T1>& v) {
|
||||||
|
x *= (T)v.x;
|
||||||
|
y *= (T)v.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T> operator*(T1 v) const {
|
||||||
|
return vec2<T>(x * (T)v, y * (T)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T> operator*(const vec2<T1>& v) const {
|
||||||
|
return vec2<T>(x * (T)v.x, y * (T)v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T>& operator/=(T1 v) {
|
||||||
|
x /= (T)v;
|
||||||
|
y /= (T)v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T>& operator/=(const vec2<T1>& v) {
|
||||||
|
x /= (T)v.x;
|
||||||
|
y /= (T)v.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T> operator/(T1 v) const {
|
||||||
|
return vec2<T>(x / (T)v, y / (T)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec2<T> operator/(const vec2<T1>& v) const {
|
||||||
|
return vec2<T>(x / (T)v.x, y / (T)v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 operator-() const { return vec2(-x, -y); }
|
||||||
|
|
||||||
|
bool operator==(const vec2& v) const { return x == v.x && y == v.y; }
|
||||||
|
bool operator!=(const vec2& v) const { return !(*this == v); }
|
||||||
|
|
||||||
|
double Len() const { return std::sqrt(SqLen()); }
|
||||||
|
double SqLen() const { return x * x + y * y; }
|
||||||
|
|
||||||
|
void SwapXY() {
|
||||||
|
T t = x;
|
||||||
|
x = y;
|
||||||
|
y = t;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
using fvec2 = vec2<float>;
|
||||||
|
using dvec2 = vec2<double>;
|
||||||
|
using ivec2 = vec2<int>;
|
||||||
|
} // namespace PD
|
187
include/pd/core/vec3.hpp
Executable file
187
include/pd/core/vec3.hpp
Executable file
@ -0,0 +1,187 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This file is generated by lazyvec
|
||||||
|
#include <pd/core/common.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
template <typename T>
|
||||||
|
class vec3 {
|
||||||
|
public:
|
||||||
|
T x;
|
||||||
|
T y;
|
||||||
|
T z;
|
||||||
|
|
||||||
|
vec3() : x(0), y(0), z(0) {}
|
||||||
|
template <typename T1>
|
||||||
|
explicit vec3(T1 v) {
|
||||||
|
x = (T)v;
|
||||||
|
y = (T)v;
|
||||||
|
z = (T)v;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
explicit vec3(vec3<T1> v) {
|
||||||
|
x = (T)v.x;
|
||||||
|
y = (T)v.y;
|
||||||
|
z = (T)v.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3(T x, T y, T z) : x(x), y(y), z(z) {}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T>& operator+=(T1 v) {
|
||||||
|
x += (T)v;
|
||||||
|
y += (T)v;
|
||||||
|
z += (T)v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T>& operator+=(const vec3<T1>& v) {
|
||||||
|
x += (T)v.x;
|
||||||
|
y += (T)v.y;
|
||||||
|
z += (T)v.z;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T> operator+(T1 v) const {
|
||||||
|
return vec3<T>(x + (T)v, y + (T)v, z + (T)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T> operator+(const vec3<T1>& v) const {
|
||||||
|
return vec3<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T>& operator-=(T1 v) {
|
||||||
|
x -= (T)v;
|
||||||
|
y -= (T)v;
|
||||||
|
z -= (T)v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T>& operator-=(const vec3<T1>& v) {
|
||||||
|
x -= (T)v.x;
|
||||||
|
y -= (T)v.y;
|
||||||
|
z -= (T)v.z;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T> operator-(T1 v) const {
|
||||||
|
return vec3<T>(x - (T)v, y - (T)v, z - (T)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T> operator-(const vec3<T1>& v) const {
|
||||||
|
return vec3<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T>& operator*=(T1 v) {
|
||||||
|
x *= (T)v;
|
||||||
|
y *= (T)v;
|
||||||
|
z *= (T)v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T>& operator*=(const vec3<T1>& v) {
|
||||||
|
x *= (T)v.x;
|
||||||
|
y *= (T)v.y;
|
||||||
|
z *= (T)v.z;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T> operator*(T1 v) const {
|
||||||
|
return vec3<T>(x * (T)v, y * (T)v, z * (T)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T> operator*(const vec3<T1>& v) const {
|
||||||
|
return vec3<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T>& operator/=(T1 v) {
|
||||||
|
x /= (T)v;
|
||||||
|
y /= (T)v;
|
||||||
|
z /= (T)v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T>& operator/=(const vec3<T1>& v) {
|
||||||
|
x /= (T)v.x;
|
||||||
|
y /= (T)v.y;
|
||||||
|
z /= (T)v.z;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T> operator/(T1 v) const {
|
||||||
|
return vec3<T>(x / (T)v, y / (T)v, z / (T)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec3<T> operator/(const vec3<T1>& v) const {
|
||||||
|
return vec3<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 operator-() const { return vec3(-x, -y, -z); }
|
||||||
|
|
||||||
|
bool operator==(const vec3& v) const {
|
||||||
|
return x == v.x && y == v.y && z == v.z;
|
||||||
|
}
|
||||||
|
bool operator!=(const vec3& v) const { return !(*this == v); }
|
||||||
|
|
||||||
|
double Len() const { return std::sqrt(SqLen()); }
|
||||||
|
double SqLen() const { return x * x + y * y + z * z; }
|
||||||
|
|
||||||
|
void SwapXY() {
|
||||||
|
T t = x;
|
||||||
|
x = y;
|
||||||
|
y = t;
|
||||||
|
}
|
||||||
|
void SwapXZ() {
|
||||||
|
T t = x;
|
||||||
|
x = z;
|
||||||
|
z = t;
|
||||||
|
}
|
||||||
|
void SwapYZ() {
|
||||||
|
T t = y;
|
||||||
|
y = z;
|
||||||
|
z = t;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
using fvec3 = vec3<float>;
|
||||||
|
using dvec3 = vec3<double>;
|
||||||
|
using ivec3 = vec3<int>;
|
||||||
|
} // namespace PD
|
223
include/pd/core/vec4.hpp
Executable file
223
include/pd/core/vec4.hpp
Executable file
@ -0,0 +1,223 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This file is generated by lazyvec
|
||||||
|
#include <pd/core/common.hpp>
|
||||||
|
#include <pd/core/vec2.hpp> // Extended
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
template <typename T>
|
||||||
|
class vec4 {
|
||||||
|
public:
|
||||||
|
T x;
|
||||||
|
T y;
|
||||||
|
T z;
|
||||||
|
T w;
|
||||||
|
|
||||||
|
vec4() : x(0), y(0), z(0), w(0) {}
|
||||||
|
template <typename T1>
|
||||||
|
explicit vec4(T1 v) {
|
||||||
|
x = (T)v;
|
||||||
|
y = (T)v;
|
||||||
|
z = (T)v;
|
||||||
|
w = (T)v;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
explicit vec4(vec4<T1> v) {
|
||||||
|
x = (T)v.x;
|
||||||
|
y = (T)v.y;
|
||||||
|
z = (T)v.z;
|
||||||
|
w = (T)v.w;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Extended Constructor */
|
||||||
|
template <typename T1>
|
||||||
|
explicit vec4(vec2<T1> a, vec2<T1> b) {
|
||||||
|
x = (T)a.x;
|
||||||
|
y = (T)a.y;
|
||||||
|
z = (T)b.x;
|
||||||
|
w = (T)b.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T>& operator+=(T1 v) {
|
||||||
|
x += (T)v;
|
||||||
|
y += (T)v;
|
||||||
|
z += (T)v;
|
||||||
|
w += (T)v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T>& operator+=(const vec4<T1>& v) {
|
||||||
|
x += (T)v.x;
|
||||||
|
y += (T)v.y;
|
||||||
|
z += (T)v.z;
|
||||||
|
w += (T)v.w;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T> operator+(T1 v) const {
|
||||||
|
return vec4<T>(x + (T)v, y + (T)v, z + (T)v, w + (T)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T> operator+(const vec4<T1>& v) const {
|
||||||
|
return vec4<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z, w + (T)v.w);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T>& operator-=(T1 v) {
|
||||||
|
x -= (T)v;
|
||||||
|
y -= (T)v;
|
||||||
|
z -= (T)v;
|
||||||
|
w -= (T)v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T>& operator-=(const vec4<T1>& v) {
|
||||||
|
x -= (T)v.x;
|
||||||
|
y -= (T)v.y;
|
||||||
|
z -= (T)v.z;
|
||||||
|
w -= (T)v.w;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T> operator-(T1 v) const {
|
||||||
|
return vec4<T>(x - (T)v, y - (T)v, z - (T)v, w - (T)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T> operator-(const vec4<T1>& v) const {
|
||||||
|
return vec4<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z, w - (T)v.w);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T>& operator*=(T1 v) {
|
||||||
|
x *= (T)v;
|
||||||
|
y *= (T)v;
|
||||||
|
z *= (T)v;
|
||||||
|
w *= (T)v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T>& operator*=(const vec4<T1>& v) {
|
||||||
|
x *= (T)v.x;
|
||||||
|
y *= (T)v.y;
|
||||||
|
z *= (T)v.z;
|
||||||
|
w *= (T)v.w;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T> operator*(T1 v) const {
|
||||||
|
return vec4<T>(x * (T)v, y * (T)v, z * (T)v, w * (T)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T> operator*(const vec4<T1>& v) const {
|
||||||
|
return vec4<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z, w * (T)v.w);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T>& operator/=(T1 v) {
|
||||||
|
x /= (T)v;
|
||||||
|
y /= (T)v;
|
||||||
|
z /= (T)v;
|
||||||
|
w /= (T)v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T>& operator/=(const vec4<T1>& v) {
|
||||||
|
x /= (T)v.x;
|
||||||
|
y /= (T)v.y;
|
||||||
|
z /= (T)v.z;
|
||||||
|
w /= (T)v.w;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T> operator/(T1 v) const {
|
||||||
|
return vec4<T>(x / (T)v, y / (T)v, z / (T)v, w / (T)v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1>
|
||||||
|
vec4<T> operator/(const vec4<T1>& v) const {
|
||||||
|
return vec4<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z, w / (T)v.w);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 operator-() const { return vec4(-x, -y, -z, -w); }
|
||||||
|
|
||||||
|
bool operator==(const vec4& v) const {
|
||||||
|
return x == v.x && y == v.y && z == v.z && w == v.w;
|
||||||
|
}
|
||||||
|
bool operator!=(const vec4& v) const { return !(*this == v); }
|
||||||
|
|
||||||
|
double Len() const { return std::sqrt(SqLen()); }
|
||||||
|
double SqLen() const { return x * x + y * y + z * z + w * w; }
|
||||||
|
|
||||||
|
void SwapXY() {
|
||||||
|
T t = x;
|
||||||
|
x = y;
|
||||||
|
y = t;
|
||||||
|
}
|
||||||
|
void SwapXZ() {
|
||||||
|
T t = x;
|
||||||
|
x = z;
|
||||||
|
z = t;
|
||||||
|
}
|
||||||
|
void SwapXW() {
|
||||||
|
T t = x;
|
||||||
|
x = w;
|
||||||
|
w = t;
|
||||||
|
}
|
||||||
|
void SwapYZ() {
|
||||||
|
T t = y;
|
||||||
|
y = z;
|
||||||
|
z = t;
|
||||||
|
}
|
||||||
|
void SwapYW() {
|
||||||
|
T t = y;
|
||||||
|
y = w;
|
||||||
|
w = t;
|
||||||
|
}
|
||||||
|
void SwapZW() {
|
||||||
|
T t = z;
|
||||||
|
z = w;
|
||||||
|
w = t;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
using fvec4 = vec4<float>;
|
||||||
|
using dvec4 = vec4<double>;
|
||||||
|
using ivec4 = vec4<int>;
|
||||||
|
} // namespace PD
|
64
include/pd/lib3ds/result_decoder.hpp → include/pd/drivers/drivers.hpp
Normal file → Executable file
64
include/pd/lib3ds/result_decoder.hpp → include/pd/drivers/drivers.hpp
Normal file → Executable file
@ -1,36 +1,28 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <3ds.h>
|
#include <pd/drivers/gfx.hpp>
|
||||||
|
#include <pd/drivers/hid.hpp>
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/drivers/os.hpp>
|
||||||
#include <pd/core/markdown.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
class ResultDecoder {
|
|
||||||
public:
|
|
||||||
ResultDecoder(Result res);
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
111
include/pd/drivers/gfx.hpp
Executable file
111
include/pd/drivers/gfx.hpp
Executable file
@ -0,0 +1,111 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pd/core/core.hpp>
|
||||||
|
#include <pd/lithium/command.hpp>
|
||||||
|
#include <pd/lithium/texture.hpp>
|
||||||
|
|
||||||
|
using LiBackendFlags = PD::u32;
|
||||||
|
enum LiBackendFlags_ {
|
||||||
|
LiBackendFlags_None = 0,
|
||||||
|
LiBackendFlags_FlipUV_Y = PD_BIT(0), // Essential for font loading
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
namespace Li {
|
||||||
|
class GfxDriver {
|
||||||
|
public:
|
||||||
|
GfxDriver(const std::string& name = "NullGfx") : pName(name) {};
|
||||||
|
~GfxDriver() = default;
|
||||||
|
|
||||||
|
PD_SHARED(GfxDriver);
|
||||||
|
|
||||||
|
void PostInit();
|
||||||
|
|
||||||
|
virtual void Init() {}
|
||||||
|
virtual void Deinit() {}
|
||||||
|
virtual void NewFrame() {}
|
||||||
|
|
||||||
|
virtual void BindTex(TexAddress addr) {}
|
||||||
|
|
||||||
|
virtual void RenderDrawData(const std::vector<Command::Ref>& Commands) {}
|
||||||
|
|
||||||
|
virtual Texture::Ref LoadTex(
|
||||||
|
const std::vector<u8>& pixels, int w, int h,
|
||||||
|
Texture::Type type = Texture::Type::RGBA32,
|
||||||
|
Texture::Filter filter = Texture::Filter::LINEAR) {
|
||||||
|
// Texture loading not supported (when this func not get override)
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture::Ref GetSolidTex() { return pSolid; }
|
||||||
|
|
||||||
|
const std::string pName = "NullGfx";
|
||||||
|
LiBackendFlags Flags = 0;
|
||||||
|
ivec2 ViewPort;
|
||||||
|
fvec4 ClearColor;
|
||||||
|
Texture::Ref pSolid;
|
||||||
|
|
||||||
|
/** Debug Variables */
|
||||||
|
|
||||||
|
// Optional Index counter
|
||||||
|
u32 IndexCounter;
|
||||||
|
// Optional Vertex counter
|
||||||
|
u32 VertexCounter;
|
||||||
|
// Optional Frame Counter
|
||||||
|
u64 FrameCounter;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Static Gfx Controller */
|
||||||
|
class Gfx {
|
||||||
|
public:
|
||||||
|
Gfx() = default;
|
||||||
|
~Gfx() = default;
|
||||||
|
|
||||||
|
static void Init(GfxDriver::Ref d);
|
||||||
|
|
||||||
|
static void Deinit() { pGfx->Deinit(); }
|
||||||
|
static void NewFrame() { pGfx->NewFrame(); }
|
||||||
|
|
||||||
|
static void BindTex(TexAddress addr) { pGfx->BindTex(addr); }
|
||||||
|
|
||||||
|
static void RenderDrawData(const std::vector<Command::Ref>& Commands) {
|
||||||
|
pGfx->RenderDrawData(Commands);
|
||||||
|
}
|
||||||
|
|
||||||
|
static LiBackendFlags Flags() { return pGfx->Flags; }
|
||||||
|
static Texture::Ref LoadTex(
|
||||||
|
const std::vector<u8>& pixels, int w, int h,
|
||||||
|
Texture::Type type = Texture::Type::RGBA32,
|
||||||
|
Texture::Filter filter = Texture::Filter::LINEAR) {
|
||||||
|
return pGfx->LoadTex(pixels, w, h, type, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Texture::Ref GetSolidTex() { return pGfx->GetSolidTex(); }
|
||||||
|
|
||||||
|
static GfxDriver::Ref pGfx;
|
||||||
|
};
|
||||||
|
} // namespace Li
|
||||||
|
} // namespace PD
|
384
include/pd/drivers/hid.hpp
Normal file → Executable file
384
include/pd/drivers/hid.hpp
Normal file → Executable file
@ -1,172 +1,214 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPHidE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/core.hpp>
|
||||||
#include <pd/core/vec.hpp>
|
|
||||||
|
namespace PD {
|
||||||
namespace PD {
|
class HidDriver {
|
||||||
/** Input Driver Template class */
|
public:
|
||||||
class Hid : public SmartCtor<Hid> {
|
/** Key [Controller] */
|
||||||
public:
|
enum Key : u32 {
|
||||||
/** Key [Controller] */
|
No = 0, ///< No Key
|
||||||
enum Key : u32 {
|
A = 1 << 0, ///< A
|
||||||
No = 0, ///< No Key
|
B = 1 << 1, ///< B
|
||||||
A = 1 << 0, ///< A
|
X = 1 << 2, ///< X
|
||||||
B = 1 << 1, ///< B
|
Y = 1 << 3, ///< Y
|
||||||
X = 1 << 2, ///< X
|
Start = 1 << 4, ///< Start
|
||||||
Y = 1 << 3, ///< Y
|
Select = 1 << 5, ///< Select
|
||||||
Start = 1 << 4, ///< Start
|
L = 1 << 6, ///< L
|
||||||
Select = 1 << 5, ///< Select
|
R = 1 << 7, ///< R
|
||||||
L = 1 << 6, ///< L
|
DUp = 1 << 8, ///< Dpad Up
|
||||||
R = 1 << 7, ///< R
|
DDown = 1 << 9, ///< Dpad down
|
||||||
DUp = 1 << 8, ///< Dpad Up
|
DLeft = 1 << 10, ///< Dpad left
|
||||||
DDown = 1 << 9, ///< Dpad down
|
DRight = 1 << 11, ///< Dpad right
|
||||||
DLeft = 1 << 10, ///< Dpad left
|
CPUp = 1 << 12, ///< Cpad up
|
||||||
DRight = 1 << 11, ///< Dpad right
|
CPDown = 1 << 13, ///< cpad down
|
||||||
CPUp = 1 << 12, ///< Cpad up
|
CPLeft = 1 << 14, ///< cpad left
|
||||||
CPDown = 1 << 13, ///< cpad down
|
CPRight = 1 << 15, ///< Cpad right
|
||||||
CPLeft = 1 << 14, ///< cpad left
|
CSUp = 1 << 16, ///< Cstick up
|
||||||
CPRight = 1 << 15, ///< Cpad right
|
CSDown = 1 << 17, ///< cstick down
|
||||||
CSUp = 1 << 16, ///< Cstick up
|
CSLeft = 1 << 18, ///< cstick left
|
||||||
CSDown = 1 << 17, ///< cstick down
|
CSRight = 1 << 19, ///< cstick right
|
||||||
CSLeft = 1 << 18, ///< cstick left
|
ZL = 1 << 20, ///< ZL
|
||||||
CSRight = 1 << 19, ///< cstick right
|
ZR = 1 << 21, ///< ZR
|
||||||
ZL = 1 << 20, ///< ZL
|
Touch = 1 << 22, ///< Touch
|
||||||
ZR = 1 << 21, ///< ZR
|
Up = DUp | CPUp, ///< DPad or CPad Up
|
||||||
Touch = 1 << 22, ///< Touch
|
Down = DDown | CPDown, ///< DPad or CPad Down
|
||||||
Up = DUp | CPUp, ///< DPad or CPad Up
|
Left = DLeft | CPLeft, ///< DPad or CPad Left
|
||||||
Down = DDown | CPDown, ///< DPad or CPad Down
|
Right = DRight | CPRight, ///< DPad or CPad Right
|
||||||
Left = DLeft | CPLeft, ///< DPad or CPad Left
|
};
|
||||||
Right = DRight | CPRight, ///< DPad or CPad Right
|
|
||||||
};
|
/** Event */
|
||||||
/** Event */
|
enum Event {
|
||||||
enum Event {
|
Event_Down, ///< Key Pressed
|
||||||
Event_Down, ///< Key Pressed
|
Event_Held, ///< Key Held
|
||||||
Event_Held, ///< Key Held
|
Event_Up, ///< Key released
|
||||||
Event_Up, ///< Key released
|
};
|
||||||
};
|
|
||||||
Hid() = default;
|
HidDriver(const std::string& name = "NullHid") : pName(name) {};
|
||||||
~Hid() = default;
|
virtual ~HidDriver() = default;
|
||||||
|
PD_SHARED(HidDriver);
|
||||||
/**
|
|
||||||
* Get TOuch Position
|
/**
|
||||||
* @return touch pos
|
* Get Mouse Position
|
||||||
*/
|
* @return Mouse pos
|
||||||
vec2 TouchPos() const { return touch[0]; }
|
*/
|
||||||
/**
|
fvec2 MousePos() const {
|
||||||
* Get Last Touch Position (from last frame)
|
return pMouse[0];
|
||||||
* @return touch pos
|
} /**
|
||||||
*/
|
* Get Last Mouse Position (from last frame)
|
||||||
vec2 TouchPosLast() const { return touch[1]; }
|
* @return Mouse pos
|
||||||
|
*/
|
||||||
/**
|
fvec2 MousePosLast() const { return pMouse[1]; }
|
||||||
* Check for a Button Event
|
|
||||||
* @param e Event Type
|
/**
|
||||||
* @param keys Keys to check for
|
* Check for a Button Event
|
||||||
* @return if key(s) doing the requiested event
|
* @param e Event Type
|
||||||
*/
|
* @param keys Keys to check for
|
||||||
bool IsEvent(Event e, Key keys);
|
* @return if key(s) doing the requiested event
|
||||||
/**
|
*/
|
||||||
* Check for Key Press Event
|
bool IsEvent(Event e, Key keys);
|
||||||
* @param keys set of keys
|
/**
|
||||||
* @return true if key is pressed
|
* Check for Key Press Event
|
||||||
*/
|
* @param keys set of keys
|
||||||
bool IsDown(Key keys) const { return key_events[0].at(Event_Down) & keys; }
|
* @return true if key is pressed
|
||||||
/**
|
*/
|
||||||
* Check for Key Held Event
|
bool IsDown(Key keys) const { return KeyEvents[0].at(Event_Down) & keys; }
|
||||||
* @param keys set of keys
|
/**
|
||||||
* @return true if key is held
|
* Check for Key Held Event
|
||||||
*/
|
* @param keys set of keys
|
||||||
bool IsHeld(Key keys) const { return key_events[0].at(Event_Held) & keys; }
|
* @return true if key is held
|
||||||
/**
|
*/
|
||||||
* Check for Key Release Event
|
bool IsHeld(Key keys) const { return KeyEvents[0].at(Event_Held) & keys; }
|
||||||
* @param keys set of keys
|
/**
|
||||||
* @return true if key is released
|
* Check for Key Release Event
|
||||||
*/
|
* @param keys set of keys
|
||||||
bool IsUp(Key keys) const { return key_events[0].at(Event_Up) & keys; }
|
* @return true if key is released
|
||||||
|
*/
|
||||||
/**
|
bool IsUp(Key keys) const { return KeyEvents[0].at(Event_Up) & keys; }
|
||||||
* Sett all keyevents to 0
|
|
||||||
*/
|
/**
|
||||||
void Clear() {
|
* Sett all keyevents to 0
|
||||||
for (int i = 0; i < 2; i++) {
|
*/
|
||||||
key_events[i][Event_Down] = 0;
|
void Clear() {
|
||||||
key_events[i][Event_Up] = 0;
|
for (int i = 0; i < 2; i++) {
|
||||||
key_events[i][Event_Held] = 0;
|
KeyEvents[i][Event_Down] = 0;
|
||||||
}
|
KeyEvents[i][Event_Up] = 0;
|
||||||
}
|
KeyEvents[i][Event_Held] = 0;
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Lock input driver
|
|
||||||
* @param v lock or not lock
|
/**
|
||||||
*/
|
* Lock input driver
|
||||||
void Lock(bool v) {
|
* @param v lock or not lock
|
||||||
if (v != locked) {
|
*/
|
||||||
SwappyTable();
|
void Lock(bool v) {
|
||||||
}
|
if (v != pLocked) {
|
||||||
locked = v;
|
SwapTab();
|
||||||
}
|
}
|
||||||
/**
|
pLocked = v;
|
||||||
* Check if Driver is locked
|
}
|
||||||
* @return true if locked
|
|
||||||
*/
|
/**
|
||||||
bool Locked() const { return locked; }
|
* Check if Driver is locked
|
||||||
/**
|
* @return true if locked
|
||||||
* Lock Input Driver
|
*/
|
||||||
*/
|
bool Locked() const { return pLocked; }
|
||||||
void Lock() {
|
|
||||||
if (!locked) {
|
/**
|
||||||
SwappyTable();
|
* Lock Input Driver
|
||||||
}
|
*/
|
||||||
locked = true;
|
void Lock() {
|
||||||
}
|
if (!pLocked) {
|
||||||
/**
|
SwapTab();
|
||||||
* Unlock Input Driver
|
}
|
||||||
*/
|
pLocked = true;
|
||||||
void Unlock() {
|
}
|
||||||
if (locked) {
|
/**
|
||||||
SwappyTable();
|
* Unlock Input Driver
|
||||||
}
|
*/
|
||||||
locked = false;
|
void Unlock() {
|
||||||
}
|
if (pLocked) {
|
||||||
|
SwapTab();
|
||||||
/**
|
}
|
||||||
* Template Update Function for a device specific driver
|
pLocked = false;
|
||||||
*/
|
}
|
||||||
virtual void Update() {}
|
|
||||||
|
/**
|
||||||
protected:
|
* Template Update Function for a device specific driver
|
||||||
/** Key binds map */
|
*/
|
||||||
std::unordered_map<u32, u32> binds;
|
virtual void Update() {}
|
||||||
/** Function to swap around the Table */
|
|
||||||
void SwappyTable();
|
/** Data Section */
|
||||||
/** Using 2 Touch positions for current and last frame */
|
|
||||||
vec2 touch[2];
|
/** Backend Identification Name */
|
||||||
/** locked state */
|
const std::string pName;
|
||||||
bool locked = false;
|
|
||||||
/** Key event tables */
|
/** Key Binds Map */
|
||||||
std::unordered_map<Event, u32> key_events[2];
|
std::unordered_map<u32, u32> pBinds;
|
||||||
};
|
/** Swap Tabe Function */
|
||||||
|
void SwapTab();
|
||||||
|
/** Using 2 Positions for Current and Last */
|
||||||
|
fvec2 pMouse[2];
|
||||||
|
/** Lock State */
|
||||||
|
bool pLocked = false;
|
||||||
|
/** Key Event Table Setup */
|
||||||
|
std::unordered_map<Event, u32> KeyEvents[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Static Hid Controller */
|
||||||
|
class Hid {
|
||||||
|
public:
|
||||||
|
Hid() = default;
|
||||||
|
~Hid() = default;
|
||||||
|
|
||||||
|
/** Referenec to Drivers enums */
|
||||||
|
using Key = HidDriver::Key;
|
||||||
|
using Event = HidDriver::Event;
|
||||||
|
|
||||||
|
static void Init(HidDriver::Ref v = nullptr) {
|
||||||
|
if (v) {
|
||||||
|
pHid = v;
|
||||||
|
} else {
|
||||||
|
pHid = HidDriver::New();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IsEvent(Event e, Key keys) { return pHid->IsEvent(e, keys); }
|
||||||
|
static bool IsDown(Key keys) { return pHid->IsDown(keys); }
|
||||||
|
static bool IsUp(Key keys) { return pHid->IsUp(keys); }
|
||||||
|
static bool IsHeld(Key keys) { return pHid->IsHeld(keys); }
|
||||||
|
static fvec2 MousePos() { return pHid->MousePos(); }
|
||||||
|
static fvec2 MousePosLast() { return pHid->MousePosLast(); }
|
||||||
|
static void Clear() { pHid->Clear(); }
|
||||||
|
static void Lock() { pHid->Lock(); }
|
||||||
|
static void Lock(bool v) { pHid->Lock(v); }
|
||||||
|
static void Unlock() { pHid->Unlock(); }
|
||||||
|
static bool Locked() { return pHid->Locked(); }
|
||||||
|
static void Update() { pHid->Update(); }
|
||||||
|
|
||||||
|
static HidDriver::Ref pHid;
|
||||||
|
};
|
||||||
} // namespace PD
|
} // namespace PD
|
137
include/pd/core/sys.hpp → include/pd/drivers/os.hpp
Normal file → Executable file
137
include/pd/core/sys.hpp → include/pd/drivers/os.hpp
Normal file → Executable file
@ -1,66 +1,71 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/common.hpp>
|
||||||
#include <pd/core/timetrace.hpp>
|
#include <pd/core/timetrace.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
using TraceMap = std::map<std::string, TT::Res::Ref>;
|
||||||
* Namespace containing functions for get Millis and Get Nanos
|
|
||||||
*/
|
class OsDriver {
|
||||||
namespace Sys {
|
public:
|
||||||
/**
|
OsDriver() = default;
|
||||||
* alias for the TimeTrace Traces Map
|
virtual ~OsDriver() = default;
|
||||||
*/
|
PD_SHARED(OsDriver);
|
||||||
using TraceMap = std::map<std::string, TT::Res::Ref>;
|
|
||||||
/**
|
virtual u64 GetTime();
|
||||||
* Get Current Time in Milliseconds
|
virtual u64 GetNanoTime();
|
||||||
* @return 64Bit value of millis
|
TraceMap& GetTraceMap();
|
||||||
*/
|
TT::Res::Ref& GetTraceRef(const std::string& id);
|
||||||
u64 GetTime();
|
bool TraceExist(const std::string& id);
|
||||||
/**
|
|
||||||
* Get Current Time in Nanoseconds
|
TraceMap pTraces;
|
||||||
* @return 64Bit value of nanos
|
};
|
||||||
*/
|
|
||||||
u64 GetNanoTime();
|
/** Static Os Controller */
|
||||||
/**
|
class OS {
|
||||||
* Get a TimeTrace Reference by its string ID
|
public:
|
||||||
* @param id trace name
|
OS() = default;
|
||||||
* @return Trace reference or nullptr if not found
|
~OS() = default;
|
||||||
*/
|
|
||||||
TT::Res::Ref& GetTraceRef(const std::string& id);
|
static void Init(OsDriver::Ref v = nullptr) {
|
||||||
/**
|
if (v) {
|
||||||
* Check if a Trace with the name exists
|
pOs = v;
|
||||||
* @param id tracename to search
|
} else {
|
||||||
* @return true if exist
|
pOs = OsDriver::New();
|
||||||
*/
|
}
|
||||||
bool TraceExist(const std::string& id);
|
}
|
||||||
/**
|
|
||||||
* Get TraceMap Reference
|
static u64 GetTime() { return pOs->GetTime(); }
|
||||||
* @return edidable Reference to the TraceMap
|
static u64 GetNanoTime() { return pOs->GetNanoTime(); }
|
||||||
*/
|
static TraceMap& GetTraceMap() { return pOs->GetTraceMap(); }
|
||||||
TraceMap& GetTraceMap();
|
static TT::Res::Ref& GetTraceRef(const std::string& id) {
|
||||||
} // namespace Sys
|
return pOs->GetTraceRef(id);
|
||||||
} // namespace PD
|
}
|
||||||
|
static bool TraceExist(const std::string& id) { return pOs->TraceExist(id); }
|
||||||
|
|
||||||
|
static OsDriver::Ref pOs;
|
||||||
|
};
|
||||||
|
} // namespace PD
|
57
include/pd/lithium/li7_shader.hpp → include/pd/drivers/pd_p_api.hpp
Normal file → Executable file
57
include/pd/lithium/li7_shader.hpp → include/pd/drivers/pd_p_api.hpp
Normal file → Executable file
@ -1,31 +1,26 @@
|
|||||||
// THIS FILE WAS GENERATED BY build_shaders.py!!!
|
#pragma once
|
||||||
#pragma once
|
|
||||||
|
/*
|
||||||
/*
|
MIT License
|
||||||
MIT License
|
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||||
|
|
||||||
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
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
in the Software without restriction, including without limitation the rights
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
in the Software without restriction, including without limitation the rights
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
furnished to do so, subject to the following conditions:
|
||||||
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 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,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
SOFTWARE.
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
*/
|
||||||
SOFTWARE.
|
|
||||||
*/
|
#define PD_DEF_EXP(x, y) x y = nullptr
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
extern unsigned char li7_shader[];
|
|
||||||
extern size_t li7_shader_size;
|
|
0
include/pd/external/json.hpp
vendored
Normal file → Executable file
0
include/pd/external/json.hpp
vendored
Normal file → Executable file
0
include/pd/external/stb_image.h
vendored
Normal file → Executable file
0
include/pd/external/stb_image.h
vendored
Normal file → Executable file
0
include/pd/external/stb_truetype.h
vendored
Normal file → Executable file
0
include/pd/external/stb_truetype.h
vendored
Normal file → Executable file
146
include/pd/image/image.hpp
Normal file → Executable file
146
include/pd/image/image.hpp
Normal file → Executable file
@ -1,64 +1,84 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
Copyright (c) 2024 - 2025 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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/core.hpp>
|
||||||
|
#include <pd/image/pd_p_api.hpp>
|
||||||
namespace PD {
|
|
||||||
class Image {
|
namespace PD {
|
||||||
public:
|
class PD_IMAGE_API Image {
|
||||||
Image() = default;
|
public:
|
||||||
Image(const std::string& path) { this->Load(path); }
|
enum Format {
|
||||||
Image(const std::vector<u8>& buf) { this->Load(buf); }
|
RGBA, // bpp == 4
|
||||||
Image(const std::vector<u8>& buf, int w, int h, int fmt = 4) {
|
RGB, // bpp == 3
|
||||||
this->Copy(buf, w, h, fmt);
|
RGB565, // bpp == 2 (not supported in laoding)
|
||||||
}
|
BGR, // bpp == 3
|
||||||
~Image() = default;
|
ABGR // bpp == 4
|
||||||
|
};
|
||||||
void Load(const std::string& path);
|
Image() = default;
|
||||||
void Load(const std::vector<u8>& buf);
|
Image(const std::string& path) { this->Load(path); }
|
||||||
void Copy(const std::vector<u8>& buf, int w, int h, int fmt = 4);
|
Image(const std::vector<u8>& buf) { this->Load(buf); }
|
||||||
|
Image(const std::vector<u8>& buf, int w, int h, int bpp = 4) {
|
||||||
std::vector<u8>& GetBuffer() { return buffer; }
|
this->Copy(buf, w, h, bpp);
|
||||||
std::vector<u8> GetBuffer() const { return buffer; }
|
}
|
||||||
|
~Image() = default;
|
||||||
int Width() const { return w; }
|
|
||||||
int Height() const { return h; }
|
PD_SHARED(Image)
|
||||||
|
|
||||||
u8& operator[](int idx) { return buffer[idx]; }
|
void Load(const std::string& path);
|
||||||
u8 operator[](int idx) const { return buffer[idx]; }
|
void Load(const std::vector<u8>& buf);
|
||||||
|
void Copy(const std::vector<u8>& buf, int w, int h, int bpp = 4);
|
||||||
// Probably these make th eabove ones useless
|
|
||||||
|
std::vector<PD::u8>& GetBuffer() { return pBuffer; }
|
||||||
operator std::vector<u8>&() { return buffer; }
|
std::vector<PD::u8> GetBuffer() const { return pBuffer; }
|
||||||
operator std::vector<u8>() const { return buffer; }
|
|
||||||
|
int Width() const { return pWidth; }
|
||||||
private:
|
int Height() const { return pHeight; }
|
||||||
std::vector<u8> buffer;
|
Format Fmt() const { return pFmt; }
|
||||||
int w = 0;
|
|
||||||
int h = 0;
|
u8& operator[](int idx) { return pBuffer[idx]; }
|
||||||
int fmt = 0;
|
u8 operator[](int idx) const { return pBuffer[idx]; }
|
||||||
};
|
|
||||||
|
// Probably these make th eabove ones useless
|
||||||
|
|
||||||
|
operator std::vector<PD::u8>&() { return pBuffer; }
|
||||||
|
operator std::vector<PD::u8>() const { return pBuffer; }
|
||||||
|
|
||||||
|
static void Convert(Image::Ref img, Image::Format dst);
|
||||||
|
static void ReTile(Image::Ref img,
|
||||||
|
std::function<u32(int x, int y, int w)> src,
|
||||||
|
std::function<u32(int x, int y, int w)> dst);
|
||||||
|
static int Fmt2Bpp(Format fmt);
|
||||||
|
|
||||||
|
std::vector<PD::u8> pBuffer;
|
||||||
|
int pWidth;
|
||||||
|
int pHeight;
|
||||||
|
Format pFmt = Format::RGBA;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** Leftover variable used for stbi_load */
|
||||||
|
int fmt = 0;
|
||||||
|
};
|
||||||
} // namespace PD
|
} // namespace PD
|
142
include/pd/image/img_blur.hpp
Normal file → Executable file
142
include/pd/image/img_blur.hpp
Normal file → Executable file
@ -1,72 +1,72 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
Copyright (c) 2024 - 2025 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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/core.hpp>
|
||||||
#include <pd/core/vec.hpp>
|
#include <pd/image/pd_p_api.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
* Namepace containing functions to blur images
|
* Namepace containing functions to blur images
|
||||||
*/
|
*/
|
||||||
namespace ImgBlur {
|
namespace ImgBlur {
|
||||||
/**
|
/**
|
||||||
* Function to create Gaussian Kernel List
|
* Function to create Gaussian Kernel List
|
||||||
* @param radius Rasius to use
|
* @param radius Rasius to use
|
||||||
* @param si sigma value to use
|
* @param si sigma value to use
|
||||||
* @return list of kernel values
|
* @return list of kernel values
|
||||||
*/
|
*/
|
||||||
std::vector<float> GaussianKernel(int radius, float si);
|
PD_IMAGE_API std::vector<float> GaussianKernel(int radius, float si);
|
||||||
/**
|
/**
|
||||||
* Gaussian Blur for basic Image Buffer
|
* Gaussian Blur for basic Image Buffer
|
||||||
* @param buf Image Buffer (unsigned char)
|
* @param buf Image Buffer (unsigned char)
|
||||||
* @param w width of the image
|
* @param w width of the image
|
||||||
* @param h width of the image
|
* @param h width of the image
|
||||||
* @param radius Blur radius
|
* @param radius Blur radius
|
||||||
* @param si Blur sigma
|
* @param si Blur sigma
|
||||||
* @param idxfn Indexing function
|
* @param idxfn Indexing function
|
||||||
*/
|
*/
|
||||||
void GaussianBlur(
|
PD_IMAGE_API void GaussianBlur(
|
||||||
std::vector<u8> &buf, int w, int h, float radius, float si,
|
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 {
|
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
|
||||||
return y * w + x;
|
return y * w + x;
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
* Advanced func to access memory directly
|
* Advanced func to access memory directly
|
||||||
* @param buf Referenvce to the buffer
|
* @param buf Referenvce to the buffer
|
||||||
* @param w width of the image
|
* @param w width of the image
|
||||||
* @param h width of the image
|
* @param h width of the image
|
||||||
* @param bpp Bytes per Pixels (RGB[A], RGB565, etc)
|
* @param bpp Bytes per Pixels (RGB[A], RGB565, etc)
|
||||||
* @param radius Blur radius
|
* @param radius Blur radius
|
||||||
* @param si Blur sigma
|
* @param si Blur sigma
|
||||||
* @param idxfn Indexing function
|
* @param idxfn Indexing function
|
||||||
*/
|
*/
|
||||||
void GaussianBlur(
|
PD_IMAGE_API void GaussianBlur(
|
||||||
void *buf, int w, int h, int bpp, float radius, float si,
|
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 {
|
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
|
||||||
return y * w + x;
|
return y * w + x;
|
||||||
});
|
});
|
||||||
} // namespace ImgBlur
|
} // namespace ImgBlur
|
||||||
} // namespace PD
|
} // namespace PD
|
132
include/pd/image/img_convert.hpp
Normal file → Executable file
132
include/pd/image/img_convert.hpp
Normal file → Executable file
@ -1,52 +1,82 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
Copyright (c) 2024 - 2025 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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/core.hpp>
|
||||||
|
#include <pd/image/image.hpp>
|
||||||
namespace PD {
|
#include <pd/image/pd_p_api.hpp>
|
||||||
/**
|
|
||||||
* Namespace containing function to convert images
|
namespace PD {
|
||||||
*/
|
/**
|
||||||
namespace ImgConvert {
|
* Namespace containing function to convert images
|
||||||
/**
|
*/
|
||||||
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
|
namespace ImgConvert {
|
||||||
* to every pixel
|
/**
|
||||||
* @param out Result List
|
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
|
||||||
* @param in Input Buffer List (rgb24)
|
* to every pixel
|
||||||
* @param w width of the image
|
* @param out Result List
|
||||||
* @param h height of the image
|
* @param in Input Buffer List (rgb24)
|
||||||
*/
|
* @param w width of the image
|
||||||
void RGB24toRGBA32(std::vector<u8> &out, const std::vector<u8> &in,
|
* @param h height of the image
|
||||||
const int &w, const int &h);
|
*/
|
||||||
/**
|
PD_IMAGE_API
|
||||||
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
|
void RGB24toRGBA32(std::vector<PD::u8> &out, const std::vector<u8> &in,
|
||||||
* @param buf Buffer to convert
|
const int &w, const int &h);
|
||||||
* @param w width
|
PD_IMAGE_API
|
||||||
* @param h height
|
void RGB32toRGBA24(std::vector<u8> &out, const std::vector<u8> &in,
|
||||||
*/
|
const int &w, const int &h);
|
||||||
void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
|
/**
|
||||||
} // namespace ImgConvert
|
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
|
||||||
|
* @param buf Buffer to convert
|
||||||
|
* @param w width
|
||||||
|
* @param h height
|
||||||
|
*/
|
||||||
|
PD_IMAGE_API void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
|
||||||
|
PD_IMAGE_API void ReverseBuf(std::vector<u8> &buf, size_t bpp, int w, int h);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
PD_IMAGE_API
|
||||||
|
void RGB24toRGBA32(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w,
|
||||||
|
const int &h);
|
||||||
|
PD_IMAGE_API
|
||||||
|
void RGB32toRGBA24(PD::Vec<u8> &out, const PD::Vec<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
|
||||||
|
*/
|
||||||
|
PD_IMAGE_API void Reverse32(PD::Vec<u8> &buf, const int &w, const int &h);
|
||||||
|
PD_IMAGE_API void ReverseBuf(PD::Vec<u8> &buf, size_t bpp, int w, int h);
|
||||||
|
} // namespace ImgConvert
|
||||||
} // namespace PD
|
} // namespace PD
|
51
include/pd/image/pd_p_api.hpp
Executable file
51
include/pd/image/pd_p_api.hpp
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Generated with ppam */
|
||||||
|
|
||||||
|
#ifdef _WIN32 // Windows (MSVC Tested)
|
||||||
|
#ifdef PD_IMAGE_BUILD_SHARED
|
||||||
|
#define PD_IMAGE_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define PD_IMAGE_API __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#elif defined(__APPLE__) // macOS (untested yet)
|
||||||
|
#ifdef PD_IMAGE_BUILD_SHARED
|
||||||
|
#define PD_IMAGE_API __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
#define PD_IMAGE_API
|
||||||
|
#endif
|
||||||
|
#elif defined(__linux__) // Linux (untested yet)
|
||||||
|
#ifdef PD_IMAGE_BUILD_SHARED
|
||||||
|
#define PD_IMAGE_API __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
#define PD_IMAGE_API
|
||||||
|
#endif
|
||||||
|
#elif defined(__3DS__) // 3ds Specific
|
||||||
|
// Only Static supported
|
||||||
|
#define PD_IMAGE_API
|
||||||
|
#else
|
||||||
|
#define PD_IMAGE_API
|
||||||
|
#endif
|
@ -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
|
|
271
include/pd/lithium/command.hpp
Normal file → Executable file
271
include/pd/lithium/command.hpp
Normal file → Executable file
@ -1,215 +1,58 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
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
|
in the Software without restriction, including without limitation the rights
|
||||||
in the Software without restriction, including without limitation the rights
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
furnished to do so, subject to the following conditions:
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
The above copyright notice and this permission notice shall be included in all
|
copies or substantial portions of the Software.
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
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
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
SOFTWARE.
|
||||||
SOFTWARE.
|
*/
|
||||||
*/
|
|
||||||
|
#include <pd/core/core.hpp>
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/lithium/texture.hpp>
|
||||||
#include <pd/core/vec.hpp>
|
#include <pd/lithium/vertex.hpp>
|
||||||
#include <pd/lithium/flags.hpp>
|
|
||||||
#include <pd/lithium/texture.hpp>
|
namespace PD {
|
||||||
#include <pd/lithium/vertex.hpp>
|
namespace Li {
|
||||||
|
class Command {
|
||||||
namespace PD {
|
public:
|
||||||
namespace LI {
|
Command() = default;
|
||||||
/**
|
~Command() = default;
|
||||||
* Lithium Draw Command (containing a list of vertex and index data
|
|
||||||
* only for this specific command itself)
|
PD_UNIQUE(Command);
|
||||||
*/
|
|
||||||
class Command : public SmartCtor<Command> {
|
Command& AddIdx(const u16& idx) {
|
||||||
public:
|
IndexBuffer.Add(VertexBuffer.Size() + idx);
|
||||||
Command() = default;
|
return *this;
|
||||||
~Command() = default;
|
}
|
||||||
|
|
||||||
/**
|
Command& AddVtx(const Vertex& v) {
|
||||||
* Copy Constructor [to Copy the Data of a Command Reference]
|
VertexBuffer.Add(std::move(v));
|
||||||
*/
|
return *this;
|
||||||
Command(Command::Ref v) {
|
}
|
||||||
this->index = v->index;
|
|
||||||
this->index_buf = v->index_buf;
|
PD::Vec<Vertex> VertexBuffer;
|
||||||
this->layer = v->layer;
|
PD::Vec<u16> IndexBuffer;
|
||||||
this->mode = v->mode;
|
ivec4 ScissorRect;
|
||||||
this->tex = v->tex;
|
bool ScissorOn = false;
|
||||||
this->vertex_buf = v->vertex_buf;
|
int Layer;
|
||||||
}
|
int Index;
|
||||||
|
Texture::Ref Tex;
|
||||||
/**
|
};
|
||||||
* Setter for the Commands layer
|
} // namespace Li
|
||||||
* @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
|
} // namespace PD
|
191
include/pd/lithium/drawlist.hpp
Executable file
191
include/pd/lithium/drawlist.hpp
Executable file
@ -0,0 +1,191 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pd/lithium/command.hpp>
|
||||||
|
#include <pd/lithium/font.hpp>
|
||||||
|
#include <pd/lithium/pd_p_api.hpp>
|
||||||
|
|
||||||
|
/** Path Rect Flags */
|
||||||
|
using LiPathRectFlags = PD::u32;
|
||||||
|
|
||||||
|
/** Setup for everything (oder so) */
|
||||||
|
enum LiPathRectFlags_ : PD::u32 {
|
||||||
|
LiPathRectFlags_None = 0,
|
||||||
|
LiPathRectFlags_KeepTopLeft = PD_BIT(0),
|
||||||
|
LiPathRectFlags_KeepTopRight = PD_BIT(1),
|
||||||
|
LiPathRectFlags_KeepBotRight = PD_BIT(2),
|
||||||
|
LiPathRectFlags_KeepBotLeft = PD_BIT(3),
|
||||||
|
LiPathRectFlags_KeepTop = PD_BIT(0) | PD_BIT(1),
|
||||||
|
LiPathRectFlags_KeepBot = PD_BIT(2) | PD_BIT(3),
|
||||||
|
LiPathRectFlags_KeepLeft = PD_BIT(0) | PD_BIT(3),
|
||||||
|
LiPathRectFlags_KeepRight = PD_BIT(1) | PD_BIT(2),
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
namespace Li {
|
||||||
|
class PD_LITHIUM_API DrawList {
|
||||||
|
public:
|
||||||
|
DrawList() { DrawSolid(); }
|
||||||
|
~DrawList() { pDrawList.clear(); }
|
||||||
|
|
||||||
|
/** Require Copy and Move Constructors */
|
||||||
|
|
||||||
|
DrawList(const DrawList&) = delete;
|
||||||
|
DrawList& operator=(const DrawList&) = delete;
|
||||||
|
|
||||||
|
DrawList(DrawList&&) noexcept = default;
|
||||||
|
DrawList& operator=(DrawList&&) noexcept = default;
|
||||||
|
|
||||||
|
PD_SHARED(DrawList);
|
||||||
|
|
||||||
|
Command::Ref PreGenerateCmd();
|
||||||
|
void AddCommand(Command::Ref v) { pDrawList.push_back(std::move(v)); }
|
||||||
|
void Clear() { pDrawList.clear(); }
|
||||||
|
|
||||||
|
void SetFont(Font::Ref font) { pCurrentFont = font; }
|
||||||
|
void SetFontScale(float scale) { pFontScale = scale; }
|
||||||
|
|
||||||
|
void DrawSolid();
|
||||||
|
void DrawTexture(Texture::Ref tex) { CurrentTex = tex; }
|
||||||
|
|
||||||
|
// SECTION: Draw API //
|
||||||
|
|
||||||
|
void DrawRect(const fvec2& pos, const fvec2& size, u32 color,
|
||||||
|
int thickness = 1);
|
||||||
|
void DrawRectFilled(const fvec2& pos, const fvec2& size, u32 color);
|
||||||
|
void DrawTriangle(const fvec2& a, const fvec2& b, const fvec2& c, u32 color,
|
||||||
|
int thickness = 1);
|
||||||
|
void DrawTriangleFilled(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||||
|
u32 color);
|
||||||
|
void DrawCircle(const fvec2& center, float rad, u32 color, int num_segments,
|
||||||
|
int thickness = 1);
|
||||||
|
void DrawCircleFilled(const fvec2& center, float rad, u32 color,
|
||||||
|
int num_segments);
|
||||||
|
void DrawText(const fvec2& p, const std::string& text, u32 color);
|
||||||
|
/**
|
||||||
|
* Extended Draw Text Function
|
||||||
|
*/
|
||||||
|
void DrawTextEx(const fvec2& p, const std::string& text, u32 color,
|
||||||
|
LiTextFlags flags, fvec2 box = fvec2(0.f));
|
||||||
|
void DrawLine(const fvec2& a, const fvec2& b, u32 color, int t = 1);
|
||||||
|
/**
|
||||||
|
* Take list of points and display it as a line on screen
|
||||||
|
* @param points List of Positions
|
||||||
|
* @param clr Color of the Line
|
||||||
|
* @param flags Additional Flags (Close for go back to starting point)
|
||||||
|
* @param thickness Thickness of the Line
|
||||||
|
*/
|
||||||
|
void DrawPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0,
|
||||||
|
int thickness = 1);
|
||||||
|
/**
|
||||||
|
* Take a List ofpoints and display it as Filled Shape
|
||||||
|
* @note Keep in mind to setup the list of points clockwise
|
||||||
|
* @param points List of Points
|
||||||
|
* @param clr Color of the shape
|
||||||
|
*/
|
||||||
|
void DrawConvexPolyFilled(const Vec<fvec2>& points, u32 clr);
|
||||||
|
|
||||||
|
// SECTION: PATH API //
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to reserve Memory to prevent overhead on
|
||||||
|
* pusing a lot of points with PathNext
|
||||||
|
* @param num_points Number of Positions you want to add
|
||||||
|
*/
|
||||||
|
void PathReserve(size_t num_points) {
|
||||||
|
pPath.Reserve(pPath.Size() + num_points);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Clear current Path
|
||||||
|
* @note PathStroke and PathFill will automatically clear
|
||||||
|
*/
|
||||||
|
void PathClear() { pPath.Clear(); }
|
||||||
|
/**
|
||||||
|
* Add a Point to the Path
|
||||||
|
* @note Keep in mind that this function is used for
|
||||||
|
* setting the starting point
|
||||||
|
* @param v Position to add
|
||||||
|
*/
|
||||||
|
void PathAdd(const fvec2& v) { pPath.Add(v); }
|
||||||
|
/**
|
||||||
|
* Path Stroke Create Line from point to point
|
||||||
|
* @note For Primitives like Rect or Triangle mak sure to use
|
||||||
|
* UI7DrawFlags_Close to add a line back to the starting point
|
||||||
|
* @param clr Color od the line
|
||||||
|
* @param thickness Thickness of the line
|
||||||
|
* @param flags Additional Drawflags
|
||||||
|
*/
|
||||||
|
void PathStroke(u32 clr, int thickness = 1, u32 flags = 0) {
|
||||||
|
DrawPolyLine(pPath, clr, flags, thickness);
|
||||||
|
pPath.Clear();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Fill a Path with a Color
|
||||||
|
* @note **IMPORTANT: ** Paths need to be setup clockwise
|
||||||
|
* to be rendered correctly
|
||||||
|
* @param clr Fill Color
|
||||||
|
*/
|
||||||
|
void PathFill(u32 clr) {
|
||||||
|
DrawConvexPolyFilled(pPath, clr);
|
||||||
|
pPath.Clear();
|
||||||
|
}
|
||||||
|
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
|
||||||
|
int segments);
|
||||||
|
void PathFastArcToN(const fvec2& c, float r, float amin, float amax, int s);
|
||||||
|
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
|
||||||
|
/// @param a Top Left Position
|
||||||
|
/// @param b Bottom Right Position
|
||||||
|
/// @param rounding rounding
|
||||||
|
void PathRect(fvec2 a, fvec2 b, float rounding = 0.f);
|
||||||
|
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
|
||||||
|
/// @param a Top Left Position
|
||||||
|
/// @param b Bottom Right Position
|
||||||
|
/// @param rounding rounding
|
||||||
|
/// @param flags DrawFlags (for special rounding rules)
|
||||||
|
void PathRectEx(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0);
|
||||||
|
|
||||||
|
void PushClipRect(const fvec4& cr) { pClipRects.Push(cr); }
|
||||||
|
void PopClipRect() {
|
||||||
|
if (pClipRects.IsEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pClipRects.Pop();
|
||||||
|
}
|
||||||
|
/** One linear Clip rect Setup */
|
||||||
|
void pClipCmd(Command* cmd);
|
||||||
|
|
||||||
|
/** Data Section */
|
||||||
|
|
||||||
|
Stack<fvec4> pClipRects;
|
||||||
|
int Layer;
|
||||||
|
float pFontScale = 0.7f;
|
||||||
|
Font::Ref pCurrentFont;
|
||||||
|
Texture::Ref CurrentTex;
|
||||||
|
std::vector<Command::Ref> pDrawList;
|
||||||
|
PD::Vec<fvec2> pPath;
|
||||||
|
};
|
||||||
|
} // namespace Li
|
||||||
|
} // namespace PD
|
@ -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
|
|
277
include/pd/lithium/font.hpp
Normal file → Executable file
277
include/pd/lithium/font.hpp
Normal file → Executable file
@ -1,181 +1,98 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
Copyright (c) 2024 - 2025 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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/core.hpp>
|
||||||
#include <pd/core/vec.hpp>
|
#include <pd/lithium/command.hpp>
|
||||||
#include <pd/lithium/rect.hpp>
|
#include <pd/lithium/pd_p_api.hpp>
|
||||||
#include <pd/lithium/texture.hpp>
|
#include <pd/lithium/rect.hpp>
|
||||||
|
#include <pd/lithium/texture.hpp>
|
||||||
namespace PD {
|
|
||||||
namespace LI {
|
using LiTextFlags = PD::u32;
|
||||||
/** Font Loader for Lithium */
|
enum LiTextFlags_ {
|
||||||
class Font : public SmartCtor<Font> {
|
LiTextFlags_None = 0, ///< Do nothing
|
||||||
public:
|
LiTextFlags_AlignRight = 1 << 0, ///< Align Right of position
|
||||||
/** Codepoint Data holder */
|
LiTextFlags_AlignMid = 1 << 1, ///< Align in the middle of pos and box
|
||||||
class Codepoint {
|
LiTextFlags_Shaddow = 1 << 2, ///< Draws the text twice to create shaddow
|
||||||
public:
|
LiTextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
|
||||||
Codepoint() = default;
|
LiTextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
|
||||||
~Codepoint() = default;
|
LiTextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
|
||||||
|
};
|
||||||
/**
|
|
||||||
* Codepoint ID Getter
|
namespace PD {
|
||||||
* @return 32Bit codepoint value
|
namespace Li {
|
||||||
*/
|
class PD_LITHIUM_API Font {
|
||||||
u32 cp() const { return m_cp; }
|
public:
|
||||||
/**
|
/** Codepoint Data holder */
|
||||||
* Codepoint ID Setter
|
struct Codepoint {
|
||||||
* @param v codepoint id
|
u32 pCodepoint = 0;
|
||||||
* @return DataHolder reference
|
fvec4 SimpleUV;
|
||||||
*/
|
Texture::Ref Tex;
|
||||||
Codepoint& cp(u32 v) {
|
fvec2 Size;
|
||||||
m_cp = v;
|
float Offset = 0.f;
|
||||||
return *this;
|
bool pInvalid = false;
|
||||||
}
|
};
|
||||||
/**
|
|
||||||
* Getter for the UV Coords
|
/** Constructore doesnt need Backand anymore */
|
||||||
* @return uv coords
|
Font() = default;
|
||||||
*/
|
~Font() = default;
|
||||||
vec4 uv() const { return m_uv; }
|
|
||||||
/**
|
PD_SHARED(Font);
|
||||||
* Setter for the UV Coords
|
|
||||||
* @param v uv coords
|
/**
|
||||||
* @return DataHolder Reference
|
* Load a TTF File
|
||||||
*/
|
* @param path Path to the TTF file
|
||||||
Codepoint& uv(const vec4& v) {
|
* @param px_height Pixelheight of the codepoints (limit by 64)
|
||||||
m_uv = v;
|
*/
|
||||||
return *this;
|
void LoadTTF(const std::string& path, int px_height = 32);
|
||||||
}
|
/**
|
||||||
/**
|
* Getter for Codepoint reference
|
||||||
* Getter for the Texture reference
|
* @return codepoint dataholder reference
|
||||||
* @return Texture Reference
|
*/
|
||||||
*/
|
Codepoint& GetCodepoint(u32 c);
|
||||||
Texture::Ref tex() const { return m_tex; }
|
|
||||||
/**
|
/**
|
||||||
* Setter for the Texture Reference
|
* Get Text Bounding Box
|
||||||
* @param v Texture Reference
|
*/
|
||||||
* @return DataHolder Reference
|
fvec2 GetTextBounds(const std::string& text, float scale);
|
||||||
*/
|
/**
|
||||||
Codepoint& tex(Texture::Ref v) {
|
* Extended Draw Text Function that vreates a Command List
|
||||||
m_tex = v;
|
*/
|
||||||
return *this;
|
void CmdTextEx(std::vector<Command::Ref>& cmds, const fvec2& pos, u32 color,
|
||||||
}
|
float scale, const std::string& text, LiTextFlags flags = 0,
|
||||||
/**
|
const fvec2& box = 0);
|
||||||
* Getter for the size
|
|
||||||
* @return Size
|
/** Data Section */
|
||||||
*/
|
int PixelHeight;
|
||||||
vec2 size() const { return m_size; }
|
int DefaultPixelHeight = 24;
|
||||||
/**
|
std::vector<Texture::Ref> Textures;
|
||||||
* Setter for the Size
|
/**
|
||||||
* @param v size
|
* 32Bit Codepoint Dataholder reference map
|
||||||
* @return DataHolder Reference
|
* **Now using unordered map**
|
||||||
*/
|
*/
|
||||||
Codepoint& size(const vec2& v) {
|
std::unordered_map<u32, Codepoint> CodeMap;
|
||||||
m_size = v;
|
};
|
||||||
return *this;
|
} // namespace Li
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 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
|
} // namespace PD
|
32
include/pd/lithium/lithium.hpp
Executable file
32
include/pd/lithium/lithium.hpp
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 - 2025 tobid7
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pd/lithium/command.hpp>
|
||||||
|
#include <pd/lithium/drawlist.hpp>
|
||||||
|
#include <pd/lithium/font.hpp>
|
||||||
|
#include <pd/lithium/rect.hpp>
|
||||||
|
#include <pd/lithium/renderer.hpp>
|
||||||
|
#include <pd/lithium/texture.hpp>
|
@ -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
|
|
51
include/pd/lithium/pd_p_api.hpp
Executable file
51
include/pd/lithium/pd_p_api.hpp
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Generated with ppam */
|
||||||
|
|
||||||
|
#ifdef _WIN32 // Windows (MSVC Tested)
|
||||||
|
#ifdef PD_LITHIUM_BUILD_SHARED
|
||||||
|
#define PD_LITHIUM_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define PD_LITHIUM_API __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#elif defined(__APPLE__) // macOS (untested yet)
|
||||||
|
#ifdef PD_LITHIUM_BUILD_SHARED
|
||||||
|
#define PD_LITHIUM_API __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
#define PD_LITHIUM_API
|
||||||
|
#endif
|
||||||
|
#elif defined(__linux__) // Linux (untested yet)
|
||||||
|
#ifdef PD_LITHIUM_BUILD_SHARED
|
||||||
|
#define PD_LITHIUM_API __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
#define PD_LITHIUM_API
|
||||||
|
#endif
|
||||||
|
#elif defined(__3DS__) // 3ds Specific
|
||||||
|
// Only Static supported
|
||||||
|
#define PD_LITHIUM_API
|
||||||
|
#else
|
||||||
|
#define PD_LITHIUM_API
|
||||||
|
#endif
|
342
include/pd/lithium/rect.hpp
Normal file → Executable file
342
include/pd/lithium/rect.hpp
Normal file → Executable file
@ -1,197 +1,147 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/core.hpp>
|
||||||
#include <pd/core/vec.hpp>
|
|
||||||
|
namespace PD {
|
||||||
namespace PD {
|
namespace Li {
|
||||||
namespace LI {
|
class Rect {
|
||||||
/**
|
public:
|
||||||
* Container that holds position of a rectangle's corners.
|
Rect() : Top(0), Bot(0) {}
|
||||||
*/
|
~Rect() = default;
|
||||||
class Rect {
|
/**
|
||||||
public:
|
* Constructor that initializes the rectangle using top and bottom positions.
|
||||||
Rect() = default;
|
* @param t Top left and right corner positions.
|
||||||
|
* @param b Bottom left and right corner positions.
|
||||||
/**
|
*/
|
||||||
* Constructor that initializes the rectangle using top and bottom positions.
|
Rect(const fvec4& t, const fvec4& b) {
|
||||||
* @param t Top left and right corner positions.
|
Top = t;
|
||||||
* @param b Bottom left and right corner positions.
|
Bot = b;
|
||||||
*/
|
}
|
||||||
Rect(const vec4& t, const vec4& b) {
|
/**
|
||||||
top = t;
|
* Constructor that initializes the rectangle using individual corner
|
||||||
bot = b;
|
* positions.
|
||||||
}
|
* @param tl Top left corner position.
|
||||||
|
* @param tr Top right corner position.
|
||||||
/**
|
* @param bl Bottom left corner position.
|
||||||
* Constructor that initializes the rectangle using individual corner
|
* @param br Bottom right corner position.
|
||||||
* positions.
|
*/
|
||||||
* @param tl Top left corner position.
|
Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br) {
|
||||||
* @param tr Top right corner position.
|
Top = fvec4(tl, tr);
|
||||||
* @param bl Bottom left corner position.
|
Bot = fvec4(bl, br);
|
||||||
* @param br Bottom right corner position.
|
}
|
||||||
*/
|
|
||||||
Rect(const vec2& tl, const vec2& tr, const vec2& bl, const vec2& br) {
|
/**
|
||||||
top = vec4(tl, tr);
|
* Constructor that initializes the rectangle using a UV mapping vector.
|
||||||
bot = vec4(bl, br);
|
*
|
||||||
}
|
* - The old API used vec4 for UV mapping.
|
||||||
|
* - Spritesheets have rotated images, so this was updated to use Rect for UV.
|
||||||
/**
|
*
|
||||||
* Constructor that initializes the rectangle using a UV mapping vector.
|
* @param uv Vec4 UV map.
|
||||||
*
|
*/
|
||||||
* - The old API used vec4 for UV mapping.
|
Rect(const fvec4& uv) {
|
||||||
* - Spritesheets have rotated images, so this was updated to use Rect for UV.
|
Top = vec4(uv.x, uv.y, uv.z, uv.y);
|
||||||
*
|
Bot = vec4(uv.x, uv.w, uv.z, uv.w);
|
||||||
* @param uv Vec4 UV map.
|
}
|
||||||
*/
|
|
||||||
Rect(const vec4& uv) {
|
/**
|
||||||
top = vec4(uv.x(), uv.y(), uv.z(), uv.y());
|
* Get the top-left corner position.
|
||||||
bot = vec4(uv.x(), uv.w(), uv.z(), uv.w());
|
* @return Top-left position as vec2.
|
||||||
}
|
*/
|
||||||
|
fvec2 TopLeft() const { return fvec2(Top.x, Top.y); }
|
||||||
~Rect() = default;
|
/**
|
||||||
|
* Get the top-right corner position.
|
||||||
/**
|
* @return Top-right position as vec2.
|
||||||
* Get the top left and right corner positions.
|
*/
|
||||||
* @return Top positions.
|
fvec2 TopRight() const { return fvec2(Top.z, Top.w); }
|
||||||
*/
|
/**
|
||||||
vec4 Top() const { return top; }
|
* Get the bottom-left corner position.
|
||||||
|
* @return Bottom-left position as vec2.
|
||||||
/**
|
*/
|
||||||
* Get the bottom left and right corner positions.
|
fvec2 BotLeft() const { return fvec2(Bot.x, Bot.y); }
|
||||||
* @return Bottom positions.
|
/**
|
||||||
*/
|
* Get the bottom-right corner position.
|
||||||
vec4 Bot() const { return bot; }
|
* @return Bottom-right position as vec2.
|
||||||
|
*/
|
||||||
/**
|
fvec2 BotRight() const { return fvec2(Bot.z, Bot.y); }
|
||||||
* Set the top left and right corner positions.
|
|
||||||
* @param v New top positions.
|
/**
|
||||||
* @return Reference to the updated Rect.
|
* Set the top-left corner position.
|
||||||
*/
|
* @param v New top-left position.
|
||||||
Rect& Top(const vec4& v) {
|
* @return Reference to the updated Rect.
|
||||||
top = v;
|
*/
|
||||||
return *this;
|
Rect& TopLeft(const fvec2& v) {
|
||||||
}
|
Top.x = v.x;
|
||||||
|
Top.y = v.y;
|
||||||
/**
|
return *this;
|
||||||
* Set the bottom left and right corner positions.
|
}
|
||||||
* @param v New bottom positions.
|
|
||||||
* @return Reference to the updated Rect.
|
/**
|
||||||
*/
|
* Set the top-right corner position.
|
||||||
Rect& Bot(const vec4& v) {
|
* @param v New top-right position.
|
||||||
bot = v;
|
* @return Reference to the updated Rect.
|
||||||
return *this;
|
*/
|
||||||
}
|
Rect& TopRight(const fvec2& v) {
|
||||||
|
Top.z = v.x;
|
||||||
/**
|
Top.w = v.y;
|
||||||
* Get the top-left corner position.
|
return *this;
|
||||||
* @return Top-left position as vec2.
|
}
|
||||||
*/
|
|
||||||
vec2 TopLeft() const { return vec2(top[0], top[1]); }
|
/**
|
||||||
|
* Set the bottom-left corner position.
|
||||||
/**
|
* @param v New bottom-left position.
|
||||||
* Get the top-right corner position.
|
* @return Reference to the updated Rect.
|
||||||
* @return Top-right position as vec2.
|
*/
|
||||||
*/
|
Rect& BotLeft(const fvec2& v) {
|
||||||
vec2 TopRight() const { return vec2(top[2], top[3]); }
|
Bot.x = v.x;
|
||||||
|
Bot.y = v.y;
|
||||||
/**
|
return *this;
|
||||||
* Get the bottom-left corner position.
|
}
|
||||||
* @return Bottom-left position as vec2.
|
|
||||||
*/
|
/**
|
||||||
vec2 BotLeft() const { return vec2(bot[0], bot[1]); }
|
* Set the bottom-right corner position.
|
||||||
|
* @param v New bottom-right position.
|
||||||
/**
|
* @return Reference to the updated Rect.
|
||||||
* Get the bottom-right corner position.
|
*/
|
||||||
* @return Bottom-right position as vec2.
|
Rect& BotRight(const fvec2& v) {
|
||||||
*/
|
Bot.z = v.x;
|
||||||
vec2 BotRight() const { return vec2(bot[2], bot[3]); }
|
Bot.w = v.y;
|
||||||
|
return *this;
|
||||||
/**
|
}
|
||||||
* Set the top-left corner position.
|
|
||||||
* @param v New top-left position.
|
void SwapVec2XY() {
|
||||||
* @return Reference to the updated Rect.
|
Top.SwapXY();
|
||||||
*/
|
Top.SwapZW();
|
||||||
Rect& TopLeft(const vec2& v) {
|
Bot.SwapXY();
|
||||||
top[0] = v[0];
|
Bot.SwapZW();
|
||||||
top[1] = v[1];
|
}
|
||||||
return *this;
|
|
||||||
}
|
/** Data Section */
|
||||||
|
|
||||||
/**
|
fvec4 Top;
|
||||||
* Set the top-right corner position.
|
fvec4 Bot;
|
||||||
* @param v New top-right position.
|
};
|
||||||
* @return Reference to the updated Rect.
|
} // namespace Li
|
||||||
*/
|
|
||||||
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
|
} // namespace PD
|
442
include/pd/lithium/renderer.hpp
Normal file → Executable file
442
include/pd/lithium/renderer.hpp
Normal file → Executable file
@ -1,382 +1,62 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
Copyright (c) 2024 - 2025 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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/drivers/drivers.hpp>
|
||||||
#include <pd/core/vec.hpp>
|
#include <pd/lithium/pd_p_api.hpp>
|
||||||
#include <pd/lib3ds/memory.hpp>
|
#include <pd/lithium/rect.hpp>
|
||||||
#include <pd/lithium/command.hpp>
|
|
||||||
#include <pd/lithium/flags.hpp>
|
namespace PD {
|
||||||
#include <pd/lithium/font.hpp>
|
namespace Li {
|
||||||
#include <pd/lithium/objects.hpp>
|
/**
|
||||||
#include <pd/lithium/screen.hpp>
|
* Static Class Render Setup Functions
|
||||||
#include <pd/lithium/texture.hpp>
|
*/
|
||||||
#include <pd/lithium/vertex.hpp>
|
class PD_LITHIUM_API Renderer {
|
||||||
|
public:
|
||||||
namespace PD {
|
Renderer() = default;
|
||||||
namespace LI {
|
~Renderer() = default;
|
||||||
/**
|
|
||||||
* Lithium base renderer Class.
|
// SECTION: Open Command and Object creation API
|
||||||
*/
|
static void RotateCorner(fvec2& pos, float s, float c);
|
||||||
class Renderer : public SmartCtor<Renderer> {
|
static Rect PrimRect(const fvec2& pos, const fvec2& size, float angle = 0.f);
|
||||||
public:
|
static Rect PrimLine(const fvec2& a, const fvec2& b, int thickness = 1);
|
||||||
/**
|
static void CmdQuad(Command* cmd, const Rect& quad, const Rect& uv,
|
||||||
* Constructor setting up the 2d Rendering Engine
|
u32 color);
|
||||||
* @param flags Flags to use [can be changed at runtime].
|
static void CmdTriangle(Command* cmd, const fvec2 a, const fvec2 b,
|
||||||
*/
|
const fvec2 c, u32 clr);
|
||||||
Renderer(LIRenderFlags flags = LIRenderFlags_Default);
|
static void CmdPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0,
|
||||||
/**
|
int thickness = 1);
|
||||||
* Deconstructor that unloads all the renderer data
|
static void CmdConvexPolyFilled(Command* cmd, const Vec<fvec2>& points,
|
||||||
*/
|
u32 clr, Texture::Ref tex);
|
||||||
~Renderer();
|
|
||||||
|
// SECTION: InBounds Checks
|
||||||
/**
|
|
||||||
* Prepare render stage for rendering.
|
static bool InBox(const fvec2& pos, const fvec2& size, const fvec4& area);
|
||||||
*/
|
static bool InBox(const fvec2& pos, const fvec4& area);
|
||||||
void PrepareRender();
|
static bool InBox(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||||
/**
|
const fvec4& area);
|
||||||
* Render a screens Command list.
|
};
|
||||||
* @param s Screen to Draw its list on.
|
} // namespace Li
|
||||||
*/
|
|
||||||
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
|
} // namespace PD
|
@ -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
|
|
226
include/pd/lithium/texture.hpp
Normal file → Executable file
226
include/pd/lithium/texture.hpp
Normal file → Executable file
@ -1,153 +1,75 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
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
|
in the Software without restriction, including without limitation the rights
|
||||||
in the Software without restriction, including without limitation the rights
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
furnished to do so, subject to the following conditions:
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
The above copyright notice and this permission notice shall be included in all
|
copies or substantial portions of the Software.
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
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
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
SOFTWARE.
|
||||||
SOFTWARE.
|
*/
|
||||||
*/
|
|
||||||
|
#include <pd/core/core.hpp>
|
||||||
#include <citro3d.h>
|
#include <pd/lithium/rect.hpp>
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
namespace PD {
|
||||||
#include <pd/core/vec.hpp>
|
namespace Li {
|
||||||
#include <pd/lithium/rect.hpp>
|
/** Use so address type for TexAddress */
|
||||||
|
using TexAddress = uintptr_t;
|
||||||
namespace PD {
|
class Texture {
|
||||||
/**
|
public:
|
||||||
* Lithium Texture Loader / DataHolder
|
/** Texture Types */
|
||||||
*/
|
enum Type {
|
||||||
class Texture : public SmartCtor<Texture> {
|
RGBA32, ///< Rgba 32Bit
|
||||||
public:
|
RGB24, ///< Rgb 24 Bit
|
||||||
/** Texture Type */
|
A8, ///< A8 8Bit alpha
|
||||||
enum Type {
|
};
|
||||||
RGBA32, ///< RGBA 32
|
/** Texture Filters */
|
||||||
RGB24, ///< RGB24
|
enum Filter {
|
||||||
A8, ///< A8
|
NEAREST, ///< Nearest
|
||||||
};
|
LINEAR, ///< Linear
|
||||||
/** Texture Filters */
|
};
|
||||||
enum Filter {
|
/** Constructor */
|
||||||
NEAREST, ///< Nearest
|
Texture() : Address(0), Size(0), UV(fvec4(0.f, 0.f, 1.f, 1.f)) {}
|
||||||
LINEAR, ///< Linear
|
Texture(TexAddress addr, ivec2 size,
|
||||||
};
|
Li::Rect uv = fvec4(0.f, 0.f, 1.f, 1.f)) {
|
||||||
/** Default constructor */
|
Address = addr;
|
||||||
Texture() : uv(0.f, 1.f, 1.f, 0.f) {}
|
Size = size;
|
||||||
/**
|
UV = uv;
|
||||||
* Load file Constructor
|
}
|
||||||
* @param path path to file
|
|
||||||
* @param t3x set true if file is a t3x file
|
PD_SHARED(Texture);
|
||||||
*/
|
|
||||||
Texture(const std::string& path, bool t3x = false) : uv(0.f, 1.f, 1.f, 0.f) {
|
void CopyFrom(Texture::Ref tex) {
|
||||||
if (t3x) {
|
Address = tex->Address;
|
||||||
this->LoadT3X(path);
|
Size = tex->Size;
|
||||||
} else {
|
UV = tex->UV;
|
||||||
this->LoadFile(path);
|
}
|
||||||
}
|
|
||||||
}
|
/** Left in Code getter (should be remoevd) */
|
||||||
/**
|
ivec2 GetSize() const { return Size; }
|
||||||
* Load Memory constructor
|
Li::Rect GetUV() const { return UV; }
|
||||||
* @param data File Data reference
|
|
||||||
*/
|
operator ivec2() const { return Size; }
|
||||||
Texture(const std::vector<u8>& data) : uv(0.f, 1.f, 1.f, 0.f) {
|
operator Li::Rect() const { return UV; }
|
||||||
this->LoadMemory(data);
|
|
||||||
}
|
TexAddress Address;
|
||||||
/**
|
ivec2 Size;
|
||||||
* Load Pixels constructor
|
Li::Rect UV;
|
||||||
* @param data Pixel Buffer reference
|
};
|
||||||
* @param w width
|
} // namespace Li
|
||||||
* @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
|
} // namespace PD
|
110
include/pd/lithium/vertex.hpp
Normal file → Executable file
110
include/pd/lithium/vertex.hpp
Normal file → Executable file
@ -1,62 +1,50 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
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
|
in the Software without restriction, including without limitation the rights
|
||||||
in the Software without restriction, including without limitation the rights
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
furnished to do so, subject to the following conditions:
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
The above copyright notice and this permission notice shall be included in all
|
copies or substantial portions of the Software.
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
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
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
SOFTWARE.
|
||||||
SOFTWARE.
|
*/
|
||||||
*/
|
|
||||||
|
#include <pd/core/core.hpp>
|
||||||
#include <pd/core/common.hpp>
|
|
||||||
#include <pd/core/vec.hpp>
|
namespace PD {
|
||||||
|
namespace Li {
|
||||||
namespace PD {
|
class Vertex {
|
||||||
namespace LI {
|
public:
|
||||||
class Vertex {
|
Vertex() {}
|
||||||
public:
|
Vertex(const fvec2& p, const fvec2& u, u32 c) {
|
||||||
Vertex() {}
|
Pos.x = p.x;
|
||||||
Vertex(const vec2& p, const vec2& u, u32 c) {
|
Pos.y = p.y;
|
||||||
pos[0] = p[0];
|
UV = u;
|
||||||
pos[1] = p[1];
|
Color = c;
|
||||||
uv = u;
|
}
|
||||||
color = c;
|
~Vertex() {}
|
||||||
}
|
|
||||||
~Vertex() {}
|
// private:
|
||||||
|
|
||||||
Vertex& Pos(const vec2& v) {
|
/** Open Access Data Section */
|
||||||
pos = v;
|
|
||||||
return *this;
|
fvec2 Pos;
|
||||||
}
|
fvec2 UV;
|
||||||
Vertex& Uv(const vec2& v) {
|
u32 Color;
|
||||||
uv = v;
|
};
|
||||||
return *this;
|
} // namespace Li
|
||||||
}
|
|
||||||
Vertex& Color(u32 v) {
|
|
||||||
color = v;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// private:
|
|
||||||
vec2 pos;
|
|
||||||
vec2 uv;
|
|
||||||
u32 color;
|
|
||||||
};
|
|
||||||
} // namespace LI
|
|
||||||
} // namespace PD
|
} // namespace PD
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -1,54 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
namespace Music {
|
|
||||||
/**
|
|
||||||
* Decoder Template class
|
|
||||||
*/
|
|
||||||
class Decoder : public SmartCtor<Decoder> {
|
|
||||||
public:
|
|
||||||
Decoder() = default;
|
|
||||||
virtual ~Decoder() = default;
|
|
||||||
|
|
||||||
/** Template Init function */
|
|
||||||
virtual int Init(const std::string& path) = 0;
|
|
||||||
/** Template deinit function */
|
|
||||||
virtual void Deinit() = 0;
|
|
||||||
/** Template function to get sample rate */
|
|
||||||
virtual u32 GetSampleRate() = 0;
|
|
||||||
/** template function to get number of channels */
|
|
||||||
virtual u8 GetChannels() = 0;
|
|
||||||
/** template function to get buffer size */
|
|
||||||
virtual size_t GetBufSize() = 0;
|
|
||||||
/** template decode function */
|
|
||||||
virtual u64 Decode(u16* buf_address) = 0;
|
|
||||||
/** template function to get file sanples if exist */
|
|
||||||
virtual size_t GetFileSamples() = 0;
|
|
||||||
};
|
|
||||||
} // namespace Music
|
|
||||||
} // namespace PD
|
|
@ -1,79 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
namespace Music {
|
|
||||||
/**
|
|
||||||
* Music Metadata Data Holder
|
|
||||||
*/
|
|
||||||
class MetaData {
|
|
||||||
public:
|
|
||||||
MetaData() = default;
|
|
||||||
~MetaData() = default;
|
|
||||||
|
|
||||||
/** Getter for name */
|
|
||||||
std::string Name() const { return name; }
|
|
||||||
/** Getter for album */
|
|
||||||
std::string Album() const { return album; }
|
|
||||||
/** Getter for year */
|
|
||||||
std::string Year() const { return year; }
|
|
||||||
/** Getter for Title */
|
|
||||||
std::string Title() const { return title; }
|
|
||||||
/** Getter for Artist */
|
|
||||||
std::string Artist() const { return artist; }
|
|
||||||
/** Getter for [what is this] */
|
|
||||||
std::string Mdt() const { return mdt; }
|
|
||||||
/** Gettr for file path */
|
|
||||||
std::string Path() const { return path; }
|
|
||||||
|
|
||||||
/** Setter for Name */
|
|
||||||
void Name(const std::string &v) { name = v; }
|
|
||||||
/** Setter for Album */
|
|
||||||
void Album(const std::string &v) { album = v; }
|
|
||||||
/** Settr for Year */
|
|
||||||
void Year(const std::string &v) { year = v; }
|
|
||||||
/** Settr for Title */
|
|
||||||
void Title(const std::string &v) { title = v; }
|
|
||||||
/** Settr for Artist */
|
|
||||||
void Artist(const std::string &v) { artist = v; }
|
|
||||||
/** Settr for [what is this] */
|
|
||||||
void Mdt(const std::string &v) { mdt = v; }
|
|
||||||
/** Settr for Path */
|
|
||||||
void Path(const std::string &v) { path = v; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::string unk = "Unknown";
|
|
||||||
std::string title = unk;
|
|
||||||
std::string album = unk;
|
|
||||||
std::string year = unk;
|
|
||||||
std::string name = unk;
|
|
||||||
std::string path = unk;
|
|
||||||
std::string artist = unk;
|
|
||||||
std::string mdt = unk;
|
|
||||||
};
|
|
||||||
} // namespace Music
|
|
||||||
} // namespace PD
|
|
@ -1,55 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/lib3ds/memory.hpp>
|
|
||||||
#include <pd/sound/decoder.hpp>
|
|
||||||
#include <pd/sound/metadata.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
namespace Music {
|
|
||||||
/**
|
|
||||||
* Music Player
|
|
||||||
*/
|
|
||||||
class Player : public SmartCtor<Player> {
|
|
||||||
public:
|
|
||||||
Player() {}
|
|
||||||
~Player() {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
MetaData meta;
|
|
||||||
size_t samples_total = 0;
|
|
||||||
size_t samples_played = 0;
|
|
||||||
size_t samples_per_sec = 0;
|
|
||||||
std::string file;
|
|
||||||
std::vector<signed short, LinearAllocator<signed short>> buffers[2];
|
|
||||||
ndspWaveBuf wave_buf[2] = {0};
|
|
||||||
bool last_buf = false;
|
|
||||||
int ret = -1;
|
|
||||||
bool done = false;
|
|
||||||
bool playing = false;
|
|
||||||
bool stop = false;
|
|
||||||
};
|
|
||||||
} // namespace Music
|
|
||||||
} // namespace PD
|
|
150
include/pd/ui7/container/button.hpp
Normal file → Executable file
150
include/pd/ui7/container/button.hpp
Normal file → Executable file
@ -1,76 +1,76 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/ui7/container/container.hpp>
|
#include <pd/ui7/container/container.hpp>
|
||||||
#include <pd/ui7/io.hpp>
|
#include <pd/ui7/io.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
namespace UI7 {
|
namespace UI7 {
|
||||||
/**
|
/**
|
||||||
* Button Object
|
* Button Object
|
||||||
* @note Button Press is delayed by 1 frame
|
* @note Button Press is delayed by 1 frame
|
||||||
* (but the visual reaction is done in the same frame)
|
* (but the visual reaction is done in the same frame)
|
||||||
* This only means that InPressed is responding the info in
|
* This only means that InPressed is responding the info in
|
||||||
* the next frame
|
* the next frame
|
||||||
*/
|
*/
|
||||||
class Button : public Container {
|
class PD_UI7_API Button : public Container {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Button Object constructor
|
* Button Object constructor
|
||||||
* @param label Label of the Button
|
* @param label Label of the Button
|
||||||
* @param pos Base Position
|
* @param pos Base Position
|
||||||
* @param lr Reference to the Renderer
|
* @param lr Reference to the Renderer
|
||||||
*/
|
*/
|
||||||
Button(const std::string& label, UI7::IO::Ref io) {
|
Button(const std::string& label, UI7::IO::Ref io) {
|
||||||
this->label = label;
|
this->label = label;
|
||||||
this->tdim = io->Ren->GetTextDimensions(label);
|
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||||
}
|
}
|
||||||
~Button() = default;
|
~Button() = default;
|
||||||
|
PD_SHARED(Button);
|
||||||
/** Return true if butten is pressed*/
|
|
||||||
bool IsPressed() { return pressed; }
|
/** Return true if butten is pressed*/
|
||||||
/**
|
bool IsPressed() { return pressed; }
|
||||||
* Override for the Input Handler
|
/**
|
||||||
* @note This function is usally called by Menu::Update
|
* Override for the Input Handler
|
||||||
* @param inp Reference to the Input Handler
|
* @note This function is usally called by Menu::Update
|
||||||
*/
|
*/
|
||||||
void HandleInput(Hid::Ref inp) override;
|
void HandleInput() override;
|
||||||
/**
|
/**
|
||||||
* Override for the Rendering Handler
|
* Override for the Rendering Handler
|
||||||
* @note This function is usally called by Menu::Update
|
* @note This function is usally called by Menu::Update
|
||||||
* */
|
* */
|
||||||
void Draw() override;
|
void Draw() override;
|
||||||
|
|
||||||
/** Function to Update Size if framepadding changes */
|
/** Function to Update Size if framepadding changes */
|
||||||
void Update() override;
|
void Update() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vec2 tdim; ///< Text size
|
fvec2 tdim; ///< Text size
|
||||||
UI7Color color = UI7Color_Button; ///< current button color
|
UI7Color color = UI7Color_Button; ///< current button color
|
||||||
std::string label; ///< Label of the Button
|
std::string label; ///< Label of the Button
|
||||||
bool pressed = false; ///< ispressed value
|
bool pressed = false; ///< ispressed value
|
||||||
};
|
};
|
||||||
} // namespace UI7
|
} // namespace UI7
|
||||||
} // namespace PD
|
} // namespace PD
|
144
include/pd/ui7/container/checkbox.hpp
Normal file → Executable file
144
include/pd/ui7/container/checkbox.hpp
Normal file → Executable file
@ -1,73 +1,73 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/ui7/container/container.hpp>
|
#include <pd/ui7/container/container.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
namespace UI7 {
|
namespace UI7 {
|
||||||
/**
|
/**
|
||||||
* Checkbox Object
|
* Checkbox Object
|
||||||
* @note The Updated input is available after
|
* @note The Updated input is available after
|
||||||
* Context::Update while the visual update is done
|
* Context::Update while the visual update is done
|
||||||
* during the Update
|
* during the Update
|
||||||
*/
|
*/
|
||||||
class Checkbox : public Container {
|
class PD_UI7_API Checkbox : public Container {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor for Checkbox Object
|
* Constructor for Checkbox Object
|
||||||
* @param label Label of the Checkbox
|
* @param label Label of the Checkbox
|
||||||
* @param usr_ref Reference to the bool value to update
|
* @param usr_ref Reference to the bool value to update
|
||||||
* @param io IO Reference
|
* @param io IO Reference
|
||||||
*/
|
*/
|
||||||
Checkbox(const std::string& label, bool& usr_ref, UI7::IO::Ref io)
|
Checkbox(const std::string& label, bool& usr_ref, UI7::IO::Ref io)
|
||||||
: usr_ref(usr_ref) {
|
: usr_ref(usr_ref) {
|
||||||
this->label = label;
|
this->label = label;
|
||||||
this->tdim = io->Ren->GetTextDimensions(label);
|
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||||
}
|
}
|
||||||
~Checkbox() = default;
|
~Checkbox() = default;
|
||||||
/**
|
PD_SHARED(Checkbox);
|
||||||
* Override for the Input Handler
|
/**
|
||||||
* @note This function is usally called by Menu::Update
|
* Override for the Input Handler
|
||||||
* @param inp Reference to the Input Handler
|
* @note This function is usally called by Menu::Update
|
||||||
*/
|
*/
|
||||||
void HandleInput(Hid::Ref inp) override;
|
void HandleInput() override;
|
||||||
/**
|
/**
|
||||||
* Override for the Rendering Handler
|
* Override for the Rendering Handler
|
||||||
* @note This function is usally called by Menu::Update
|
* @note This function is usally called by Menu::Update
|
||||||
* */
|
* */
|
||||||
void Draw() override;
|
void Draw() override;
|
||||||
|
|
||||||
/** Update Size if framepadding changed */
|
/** Update Size if framepadding changed */
|
||||||
void Update() override;
|
void Update() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vec2 tdim; ///< Text Size
|
fvec2 tdim; ///< Text Size
|
||||||
vec2 cbs = vec2(18); ///< Checkbox size
|
fvec2 cbs = fvec2(18); ///< Checkbox size
|
||||||
UI7Color color = UI7Color_FrameBackground; ///< Checkbox background Color
|
UI7Color color = UI7Color_FrameBackground; ///< Checkbox background Color
|
||||||
std::string label; ///< Checkbox Label
|
std::string label; ///< Checkbox Label
|
||||||
bool& usr_ref; ///< User bool reference
|
bool& usr_ref; ///< User bool reference
|
||||||
};
|
};
|
||||||
} // namespace UI7
|
} // namespace UI7
|
||||||
} // namespace PD
|
} // namespace PD
|
147
include/pd/ui7/container/coloredit.hpp
Normal file → Executable file
147
include/pd/ui7/container/coloredit.hpp
Normal file → Executable file
@ -1,73 +1,76 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/ui7/container/container.hpp>
|
#include <pd/ui7/container/container.hpp>
|
||||||
#include <pd/ui7/io.hpp>
|
#include <pd/ui7/io.hpp>
|
||||||
|
#include <pd/ui7/layout.hpp>
|
||||||
namespace PD {
|
|
||||||
namespace UI7 {
|
namespace PD {
|
||||||
/**
|
namespace UI7 {
|
||||||
* Color Editor (Creating a PopUP when clicking)
|
/**
|
||||||
*/
|
* Color Editor (Creating a PopUP when clicking)
|
||||||
class ColorEdit : public Container {
|
*/
|
||||||
public:
|
class PD_UI7_API ColorEdit : public Container {
|
||||||
/**
|
public:
|
||||||
* Constructor
|
/**
|
||||||
* @param label Label of the Button
|
* Constructor
|
||||||
* @param pos Base Position
|
* @param label Label of the Button
|
||||||
* @param lr Reference to the Renderer
|
* @param pos Base Position
|
||||||
*/
|
* @param lr Reference to the Renderer
|
||||||
ColorEdit(const std::string& label, u32* color, UI7::IO::Ref io) {
|
*/
|
||||||
PD::Assert(color != nullptr, "Input Color Address is null!");
|
ColorEdit(const std::string& label, u32* color, UI7::IO::Ref io) {
|
||||||
this->label = label;
|
// PD::Assert(color != nullptr, "Input Color Address is null!");
|
||||||
this->color_ref = color;
|
this->label = label;
|
||||||
this->initial_color = *color;
|
this->color_ref = color;
|
||||||
this->tdim = io->Ren->GetTextDimensions(label);
|
this->initial_color = *color;
|
||||||
}
|
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||||
~ColorEdit() = default;
|
}
|
||||||
|
~ColorEdit() = default;
|
||||||
/**
|
PD_SHARED(ColorEdit);
|
||||||
* Override for the Input Handler
|
|
||||||
* @note This function is usally called by Menu::Update
|
/**
|
||||||
* @param inp Reference to the Input Handler
|
* Override for the Input Handler
|
||||||
*/
|
* @note This function is usally called by Menu::Update
|
||||||
void HandleInput(Hid::Ref inp) override;
|
*/
|
||||||
/**
|
void HandleInput() override;
|
||||||
* Override for the Rendering Handler
|
/**
|
||||||
* @note This function is usally called by Menu::Update
|
* Override for the Rendering Handler
|
||||||
* */
|
* @note This function is usally called by Menu::Update
|
||||||
void Draw() override;
|
* */
|
||||||
|
void Draw() override;
|
||||||
/** Function to Update Size if framepadding changes */
|
|
||||||
void Update() override;
|
/** Function to Update Size if framepadding changes */
|
||||||
|
void Update() override;
|
||||||
private:
|
|
||||||
vec2 tdim; ///< Text size
|
private:
|
||||||
u32* color_ref = nullptr; ///< Color Reference
|
fvec2 tdim; ///< Text size
|
||||||
u32 initial_color; ///< Initial Color
|
u32* color_ref = nullptr; ///< Color Reference
|
||||||
std::string label; ///< Label of the Button
|
u32 initial_color; ///< Initial Color
|
||||||
};
|
std::string label; ///< Label of the Button
|
||||||
} // namespace UI7
|
Layout::Ref layout; ///< Layout to open
|
||||||
|
bool is_shown = false; ///< AHow Layout Editor
|
||||||
|
};
|
||||||
|
} // namespace UI7
|
||||||
} // namespace PD
|
} // namespace PD
|
319
include/pd/ui7/container/container.hpp
Normal file → Executable file
319
include/pd/ui7/container/container.hpp
Normal file → Executable file
@ -1,153 +1,166 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2025 René Amthor (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
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/core/core.hpp>
|
||||||
#include <pd/core/strings.hpp>
|
#include <pd/ui7/io.hpp>
|
||||||
#include <pd/core/vec.hpp>
|
#include <pd/ui7/pd_p_api.hpp>
|
||||||
#include <pd/drivers/hid.hpp>
|
|
||||||
#include <pd/ui7/drawlist.hpp>
|
namespace PD {
|
||||||
#include <pd/ui7/io.hpp>
|
namespace UI7 {
|
||||||
|
/**
|
||||||
namespace PD {
|
* Container base class all Objects are based on
|
||||||
namespace UI7 {
|
* @note this class can be used to create custom Objects as well
|
||||||
/**
|
*/
|
||||||
* Container base class all Objects are based on
|
class PD_UI7_API Container {
|
||||||
* @note this class can be used to create custom Objects as well
|
public:
|
||||||
*/
|
Container() = default;
|
||||||
class Container : public SmartCtor<Container> {
|
/**
|
||||||
public:
|
* Constructor with pos and Size
|
||||||
Container() = default;
|
* @param pos Container Position
|
||||||
/**
|
* @param size Container Size
|
||||||
* Constructor with pos and Size
|
*/
|
||||||
* @param pos Container Position
|
Container(const fvec2& pos, const fvec2& size) : pos(pos), size(size) {}
|
||||||
* @param size Container Size
|
/**
|
||||||
*/
|
* Constructor by a vec4 box
|
||||||
Container(const vec2& pos, const vec2& size) : pos(pos), size(size) {}
|
* @param box Box containing top left and bottom right coords
|
||||||
/**
|
*/
|
||||||
* Constructor by a vec4 box
|
Container(const fvec4& box)
|
||||||
* @param box Box containing top left and bottom right coords
|
: pos(fvec2(box.x, box.y)), size(fvec2(box.z - box.x, box.w - box.y)) {}
|
||||||
*/
|
~Container() = default;
|
||||||
Container(const vec4& box) : pos(box.xy()), size(box.zw() - box.xy()) {}
|
|
||||||
~Container() = default;
|
PD_SHARED(Container);
|
||||||
|
/**
|
||||||
/**
|
* Init Function Required by every Object that uses
|
||||||
* Init Function Required by every Object that uses
|
* Render or Input functions
|
||||||
* Render or Input functions
|
* @param io IO Reference
|
||||||
* @param io IO Reference
|
* @param l DrawList Reference
|
||||||
* @param l DrawList Reference
|
*/
|
||||||
*/
|
void Init(UI7::IO::Ref io, Li::DrawList::Ref l) {
|
||||||
void Init(UI7::IO::Ref io, UI7::DrawList::Ref l) {
|
list = l;
|
||||||
list = l;
|
this->io = io;
|
||||||
this->io = io;
|
// this->screen = io->Ren->CurrentScreen();
|
||||||
this->screen = io->Ren->CurrentScreen();
|
}
|
||||||
}
|
|
||||||
|
/** Setter for Position */
|
||||||
/** Setter for Position */
|
void SetPos(const fvec2& pos) { this->pos = pos; }
|
||||||
void SetPos(const vec2& pos) { this->pos = pos; }
|
/** Setter for Size */
|
||||||
/** Setter for Size */
|
void SetSize(const fvec2& size) { this->size = size; }
|
||||||
void SetSize(const vec2& size) { this->size = size; }
|
/** Getter for Position */
|
||||||
/** Getter for Position */
|
fvec2 GetPos() { return pos; }
|
||||||
vec2 GetPos() { return pos; }
|
/** Getter for Size */
|
||||||
/** Getter for Size */
|
fvec2 GetSize() { return size; }
|
||||||
vec2 GetSize() { return size; }
|
/**
|
||||||
/**
|
* Get the Containers Final Position
|
||||||
* Get the Containers Final Position
|
* for Rendering and Input (if it has a parent Object)
|
||||||
* for Rendering and Input (if it has a parent Object)
|
*/
|
||||||
*/
|
fvec2 FinalPos() {
|
||||||
vec2 FinalPos() {
|
vec2 res = pos;
|
||||||
vec2 res = pos;
|
if (parent) {
|
||||||
if (parent) {
|
/// Probably should use parant->FinalPos here
|
||||||
/// Probably should use parant->FinalPos here
|
res += parent->GetPos();
|
||||||
res += parent->GetPos();
|
}
|
||||||
}
|
return res;
|
||||||
return res;
|
}
|
||||||
}
|
|
||||||
|
/** Setter for Parent Container */
|
||||||
/** Setter for Parent Container */
|
void SetParent(Container::Ref v) { parent = v; }
|
||||||
void SetParent(Container::Ref v) { parent = v; }
|
/** Getter for Parent Container */
|
||||||
/** Getter for Parent Container */
|
Container::Ref GetParent() { return parent; }
|
||||||
Container::Ref GetParent() { return parent; }
|
|
||||||
|
/** Check if Rendering can be skipped */
|
||||||
/** Check if Rendering can be skipped */
|
bool Skippable() const { return skippable; }
|
||||||
bool Skippable() const { return skippable; }
|
/** Check if the Object got a timeout (ID OBJ Relevant) */
|
||||||
/** Check if the Object got a timeout (ID OBJ Relevant) */
|
bool Removable() const { return rem; }
|
||||||
bool Removable() const { return rem; }
|
|
||||||
|
/**
|
||||||
/**
|
* Handles Scrolling by scrolling pos as well as
|
||||||
* Handles Scrolling by scrolling pos as well as
|
* Time for Remove for ID Objects
|
||||||
* Time for Remove for ID Objects
|
* @param scrolling Scrolling Position
|
||||||
* @param scrolling Scrolling Position
|
* @param viewport Viewport to check if the Object is skippable
|
||||||
* @param viewport Viewport to check if the Object is skippable
|
*/
|
||||||
*/
|
void HandleScrolling(fvec2 scrolling, fvec4 viewport);
|
||||||
void HandleScrolling(vec2 scrolling, vec4 viewport);
|
/** Template function for Input Handling */
|
||||||
/** Template function for Input Handling */
|
virtual void HandleInput() {}
|
||||||
virtual void HandleInput(Hid::Ref inp) {}
|
/** Tamplate function for Object rendering */
|
||||||
/** Tamplate function for Object rendering */
|
virtual void Draw() {}
|
||||||
virtual void Draw() {}
|
/** Template function to update internal data (if needed) */
|
||||||
/** Template function to update internal data (if needed) */
|
virtual void Update() {}
|
||||||
virtual void Update() {}
|
|
||||||
|
/** Internal Input Handler */
|
||||||
/**
|
void HandleInternalInput();
|
||||||
* Function to unlock Input after Rendering is done in
|
|
||||||
* Menu::Update
|
/**
|
||||||
* @note This is used if the Object got Input Handled directly after creation
|
* Function to unlock Input after Rendering is done in
|
||||||
* to not check for Inputs twice
|
* Menu::Update
|
||||||
*/
|
* @note This is used if the Object got Input Handled directly after creation
|
||||||
void UnlockInput() { inp_done = false; }
|
* to not check for Inputs twice
|
||||||
|
*/
|
||||||
/** Get the Objects ID (if it is an ID object)*/
|
void UnlockInput() { inp_done = false; }
|
||||||
u32 GetID() const { return id; }
|
|
||||||
/**
|
/** Get the Objects ID (if it is an ID object)*/
|
||||||
* Set ID for ID Objects
|
u32 GetID() const { return id; }
|
||||||
* @param id Object ID (hashed prefix+objname+prefixed_counter)
|
/**
|
||||||
*/
|
* Set ID for ID Objects
|
||||||
void SetID(u32 id) { this->id = id; }
|
* @param id Object ID (hashed prefix+objname+prefixed_counter)
|
||||||
|
*/
|
||||||
protected:
|
void SetID(u32 id) { this->id = id; }
|
||||||
/** used to skip Input/Render preocessing ot not*/
|
|
||||||
bool skippable = false;
|
/** Get a reference to IO */
|
||||||
/** value to check if an ID Object goes out of lifetime*/
|
UI7::IO::Ref GetIO() { return io; }
|
||||||
bool rem = false;
|
|
||||||
/** Time of the last use (set by HandleScrolling)*/
|
protected:
|
||||||
u64 last_use = 0;
|
/** used to skip Input/Render preocessing ot not*/
|
||||||
/** Input done or not for current frame*/
|
bool skippable = false;
|
||||||
bool inp_done = false;
|
/** value to check if an ID Object goes out of lifetime*/
|
||||||
/** Reference to the Screen to draw the Object on*/
|
bool rem = false;
|
||||||
Screen::Ref screen;
|
/** Time of the last use (set by HandleScrolling)*/
|
||||||
/** Container Position*/
|
u64 last_use = 0;
|
||||||
vec2 pos;
|
/** Input done or not for current frame*/
|
||||||
/** Container Size*/
|
bool inp_done = false;
|
||||||
vec2 size;
|
/** Reference to the Screen to draw the Object on*/
|
||||||
/** Reference to the Drawlist to Draw to*/
|
// Screen::Ref screen;
|
||||||
UI7::DrawList::Ref list;
|
/** Container Position*/
|
||||||
/** IO Reference for Renderer and Theme */
|
fvec2 pos;
|
||||||
UI7::IO::Ref io;
|
/** Container Size*/
|
||||||
/** Reference to the parent container*/
|
fvec2 size;
|
||||||
Container::Ref parent;
|
/** Reference to the Drawlist to Draw to*/
|
||||||
/** Object ID (0 if unused)*/
|
Li::DrawList::Ref list;
|
||||||
u32 id = 0;
|
/** IO Reference for Renderer and Theme */
|
||||||
};
|
UI7::IO::Ref io;
|
||||||
} // namespace UI7
|
/** Reference to the parent container*/
|
||||||
} // namespace PD
|
Container::Ref parent;
|
||||||
|
/** Object ID (0 if unused)*/
|
||||||
|
u32 id = 0;
|
||||||
|
/** Internal Flags */
|
||||||
|
u32 pFlags = 0;
|
||||||
|
/** Is Selected? */
|
||||||
|
bool pSelected = false;
|
||||||
|
/** Was Pressed */
|
||||||
|
bool pPressed = false;
|
||||||
|
/** Was Pressed Twice */
|
||||||
|
bool pPressedTwice = false;
|
||||||
|
};
|
||||||
|
} // namespace UI7
|
||||||
|
} // namespace PD
|
||||||
|
92
include/pd/ui7/container/dragdata.hpp
Executable file
92
include/pd/ui7/container/dragdata.hpp
Executable file
@ -0,0 +1,92 @@
|
|||||||
|
#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/ui7/container/container.hpp>
|
||||||
|
#include <pd/ui7/io.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
namespace UI7 {
|
||||||
|
/**
|
||||||
|
* DragData Object can take a datatype or a list
|
||||||
|
* and modifys these by moving left or right when dragging
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
class PD_UI7_API DragData : public Container {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param label Label of the Button
|
||||||
|
* @param data Data reference (Supported types can be seen in dragdata.cpp)
|
||||||
|
* @param num_elms Number of Array elements (for exaple with use ofvec4)
|
||||||
|
* @param io IO Reference
|
||||||
|
* @param min minimum number using Minimum limit
|
||||||
|
* @param max Maximum number set by max limit by default
|
||||||
|
* @param step To set the modifier for drag movement
|
||||||
|
* @param precision for float and double to set precision
|
||||||
|
*/
|
||||||
|
DragData(const std::string& label, T* data, size_t num_elms, UI7::IO::Ref io,
|
||||||
|
T min = std::numeric_limits<T>::min(),
|
||||||
|
T max = std::numeric_limits<T>::max(), T step = 1,
|
||||||
|
int precision = 1) {
|
||||||
|
// PD::Assert(data != nullptr, "Input Data Address is null!");
|
||||||
|
this->label = label;
|
||||||
|
this->data = data;
|
||||||
|
this->elm_count = num_elms;
|
||||||
|
this->min = min;
|
||||||
|
this->max = max;
|
||||||
|
this->step = step;
|
||||||
|
this->precision = precision;
|
||||||
|
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
|
||||||
|
}
|
||||||
|
~DragData() = default;
|
||||||
|
|
||||||
|
/** Als ob das funktioniert... */
|
||||||
|
PD_SHARED(DragData<T>);
|
||||||
|
/**
|
||||||
|
* Override for the Input Handler
|
||||||
|
* @note This function is usally called by Menu::Update
|
||||||
|
*/
|
||||||
|
void HandleInput() override;
|
||||||
|
/**
|
||||||
|
* Override for the Rendering Handler
|
||||||
|
* @note This function is usally called by Menu::Update
|
||||||
|
* */
|
||||||
|
void Draw() override;
|
||||||
|
|
||||||
|
/** Function to Update Size if framepadding changes */
|
||||||
|
void Update() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
fvec2 tdim; ///< Text size
|
||||||
|
std::string label; ///< Label of the Button
|
||||||
|
T* data;
|
||||||
|
size_t elm_count = 0;
|
||||||
|
T min;
|
||||||
|
T max;
|
||||||
|
T step;
|
||||||
|
int precision = 1;
|
||||||
|
};
|
||||||
|
} // namespace UI7
|
||||||
|
} // namespace PD
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user