Compare commits
	
		
			14 Commits
		
	
	
		
			ea76a304d4
			...
			devel050
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 8328181a2a | |||
| be230bef6b | |||
| c2bff368d4 | |||
| 0ecf559fbb | |||
| 3823f08bab | |||
| decae031ae | |||
| da87c0f7c2 | |||
| 310b44caf5 | |||
| 87910b57de | |||
| 31a0c3656f | |||
| 01fb149e71 | |||
| 57634cbf4b | |||
| 963fa72e41 | |||
| 271defffca | 
							
								
								
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1 +1,3 @@ | |||||||
| build/ | build/ | ||||||
|  | .cache | ||||||
|  | .vscode | ||||||
							
								
								
									
										2
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							| @@ -1,3 +1,3 @@ | |||||||
| [submodule "backends/desktop/glfw"] | [submodule "backends/desktop/glfw"] | ||||||
| 	path = backends/desktop/glfw | 	path = backends/desktop/glfw | ||||||
| 	url = https://github.com/glfw/glfw.git | 	url = https://github.com/glfw/glfw | ||||||
|   | |||||||
							
								
								
									
										37
									
								
								.vscode/c_cpp_properties.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										37
									
								
								.vscode/c_cpp_properties.json
									
									
									
									
										vendored
									
									
								
							| @@ -1,37 +0,0 @@ | |||||||
| { |  | ||||||
|     "configurations": [ |  | ||||||
|         { |  | ||||||
|             "name": "3DS | Windows", |  | ||||||
|             "includePath": [ |  | ||||||
|                 "${workspaceFolder}/**", |  | ||||||
|                 "C:/devkitpro/libctru/include/**", |  | ||||||
|                 "C:/devkitpro/devkitARM/include/**", |  | ||||||
|                 "C:/devkitpro/devkitARM/arm-none-eabi/include/**", |  | ||||||
|                 "C:/devkitpro/portlibs/3ds/include/**" |  | ||||||
|             ], |  | ||||||
|             "defines": [ |  | ||||||
|                 "BUILD_CTR", |  | ||||||
|                 "__3DS__" |  | ||||||
|             ], |  | ||||||
|             "compilerPath": "C:/devkitPro/devkitARM/bin/arm-none-eabi-g++.exe", |  | ||||||
|             "intelliSenseMode": "gcc-arm", |  | ||||||
|             "cStandard": "c11", |  | ||||||
|             "cppStandard": "c++20" |  | ||||||
|         }, |  | ||||||
|         { |  | ||||||
|             "name": "3DS | Linux", |  | ||||||
|             "includePath": [ |  | ||||||
|                 "${workspaceFolder}/**", |  | ||||||
|                 "/opt/devkitpro/libctru/include/**", |  | ||||||
|                 "/opt/devkitpro/portlibs/3ds/include/**" |  | ||||||
|             ], |  | ||||||
|             "defines": [ |  | ||||||
|                 "BUILD_CTR" |  | ||||||
|             ], |  | ||||||
|             "cStandard": "c17", |  | ||||||
|             "cppStandard": "gnu++20", |  | ||||||
|             "intelliSenseMode": "gcc-arm" |  | ||||||
|         } |  | ||||||
|     ], |  | ||||||
|     "version": 4 |  | ||||||
| } |  | ||||||
							
								
								
									
										21
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										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" |  | ||||||
|     } |  | ||||||
| } |  | ||||||
							
								
								
									
										160
									
								
								CMakeLists.txt
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										160
									
								
								CMakeLists.txt
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,158 +1,36 @@ | |||||||
| cmake_minimum_required(VERSION 3.18) | cmake_minimum_required(VERSION 3.22) | ||||||
|  |  | ||||||
| ### Helper Function to Build Librarys without have always |  | ||||||
| ### These includes and definition defines |  | ||||||
| function(add_pd_lib TARGET_NAME) |  | ||||||
| set(opts "BUILD_SHARED") |  | ||||||
| set(one_val_args "") |  | ||||||
| set(multi_val_args SRC_FILES DEPENDS) |  | ||||||
| cmake_parse_arguments(ARG "${opts}" "${one_val_args}" "${multi_val_args}" ${ARGN}) |  | ||||||
|  |  | ||||||
| string(REPLACE "-" "_" FLAG_NAME_T ${TARGET_NAME}) |  | ||||||
| string(TOUPPER ${FLAG_NAME_T} FLAG_NAME_F) |  | ||||||
|  |  | ||||||
| if(ARG_BUILD_SHARED) |  | ||||||
|     add_library(${TARGET_NAME} SHARED ${ARG_SRC_FILES}) |  | ||||||
|     target_compile_definitions(${TARGET_NAME} PUBLIC -D${FLAG_NAME_F}_BUILD_SHARED=1) |  | ||||||
|     message("Building SHARED library: ${FLAG_NAME_F}_BUILD_SHARED=1") |  | ||||||
| else() |  | ||||||
|     add_library(${TARGET_NAME} STATIC ${ARG_SRC_FILES}) |  | ||||||
|     target_compile_definitions(${TARGET_NAME} PUBLIC -D${FLAG_NAME_F}_BUILD_SHARED=0) |  | ||||||
|     message("Building STATIC library: ${FLAG_NAME_F}_BUILD_SHARED=0") |  | ||||||
| endif() |  | ||||||
| target_include_directories(${TARGET_NAME} PUBLIC |  | ||||||
|     include |  | ||||||
|     ${DEVKITPRO}/portlibs/3ds/include |  | ||||||
|     backends) |  | ||||||
| target_compile_definitions(${TARGET_NAME} PUBLIC |  | ||||||
|     -D_GNU_SOURCE=1 |  | ||||||
|     -DPALLADIUM_VERSION="${PROJECT_VERSION}" |  | ||||||
|     -DPALLADIUM_GIT_COMMIT="${GIT_SHORT_HASH}" |  | ||||||
|     -DPALLADIUM_GIT_BRANCH="${GIT_BRANCH}" |  | ||||||
|     -DBUILD_CTR=1) |  | ||||||
| ### For the libs that depend on another |  | ||||||
| if(ARG_DEPENDS) |  | ||||||
| target_link_libraries(${TARGET_NAME} PUBLIC ${ARG_DEPENDS}) |  | ||||||
| endif() |  | ||||||
| install(TARGETS ${TARGET_NAME}) |  | ||||||
| endfunction() |  | ||||||
|  |  | ||||||
| ## Get Current Git Commit Value |  | ||||||
| execute_process( |  | ||||||
|     COMMAND git rev-parse --short HEAD |  | ||||||
|     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |  | ||||||
|     OUTPUT_VARIABLE GIT_SHORT_HASH |  | ||||||
|     OUTPUT_STRIP_TRAILING_WHITESPACE |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| ## Get Current Git Branch |  | ||||||
| execute_process( |  | ||||||
|     COMMAND git rev-parse --abbrev-ref HEAD |  | ||||||
|     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |  | ||||||
|     OUTPUT_VARIABLE GIT_BRANCH |  | ||||||
|     OUTPUT_STRIP_TRAILING_WHITESPACE |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| # Set Project | # Set Project | ||||||
| project(palladium LANGUAGES C CXX VERSION 0.4.0) | project(palladium LANGUAGES C CXX VERSION 0.5.1) | ||||||
|  |  | ||||||
|  | # Required to add this Variable | ||||||
|  | set(PD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||||||
|  | include(cmake/palladium.cmake) | ||||||
|  |  | ||||||
| option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF) | option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF) | ||||||
| option(PD_BUILD_SHARED "Build Shared Libraries" OFF) | option(PD_BUILD_SHARED "Build Shared Libraries" OFF) | ||||||
|  | option(PD_BUILD_TOOLS "Build Palladium Tools" OFF) | ||||||
|  |  | ||||||
| message("Var: ${PD_BUILD_SHARED}") | if(${PD_BUILD_TOOLS}) | ||||||
|  |     add_subdirectory(tools) | ||||||
| # Enable Compile Command Export |  | ||||||
| set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |  | ||||||
|  |  | ||||||
| # Force C++ 20 |  | ||||||
| set(CMAKE_CXX_STANDARD 20) |  | ||||||
| set(CMAKE_CXX_STANDARD_REQUIRED TRUE) |  | ||||||
|  |  | ||||||
| # Set Special C and CXX flags for 3ds |  | ||||||
| if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS") |  | ||||||
| if(${PD_BUILD_SHARED}) |  | ||||||
| message(ERROR "3DS Only supports Static libraries") |  | ||||||
| endif() | endif() | ||||||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-psabi -O2") |  | ||||||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions") |  | ||||||
| endif() |  | ||||||
| #include_directories(include) |  | ||||||
|  |  | ||||||
| ## Core Source Code | ## Include Library Source | ||||||
| set(CORE_SRC |  | ||||||
| source/core/common.cpp |  | ||||||
| source/core/bit_util.cpp |  | ||||||
| source/core/color.cpp |  | ||||||
| source/core/io.cpp |  | ||||||
| source/core/hid_driver.cpp |  | ||||||
| source/core/mat.cpp |  | ||||||
| source/core/strings.cpp |  | ||||||
| source/core/sys.cpp |  | ||||||
| source/core/timer.cpp |  | ||||||
| source/core/timetrace.cpp) |  | ||||||
|  |  | ||||||
| ## Image Source Code | add_subdirectory(pd/drivers) | ||||||
| set(IMAGE_SRC | add_subdirectory(pd/core) | ||||||
| source/image/image.cpp | add_subdirectory(pd/image) | ||||||
| source/image/img_blur.cpp | add_subdirectory(pd/external) | ||||||
| source/image/img_convert.cpp) | add_subdirectory(pd/lithium) | ||||||
|  | add_subdirectory(pd/ui7) | ||||||
| ## External Source Code |  | ||||||
| set(EXTERNAL_SRC |  | ||||||
| source/external/stb.cpp) |  | ||||||
|  |  | ||||||
| ## Lithiu, Source Code |  | ||||||
| set(LI_SRC |  | ||||||
| source/lithium/font.cpp |  | ||||||
| source/lithium/drawlist.cpp |  | ||||||
| source/lithium/renderer.cpp) |  | ||||||
|  |  | ||||||
| ## Net Source Code |  | ||||||
| set(NET_SRC |  | ||||||
| source/net/socket.cpp) |  | ||||||
|  |  | ||||||
| ## UI7 Source Code |  | ||||||
| set(UI7_SRC |  | ||||||
| source/ui7/drawlist.cpp |  | ||||||
| source/ui7/io.cpp |  | ||||||
| source/ui7/layout.cpp |  | ||||||
| source/ui7/menu.cpp |  | ||||||
| source/ui7/remenu.cpp |  | ||||||
| source/ui7/theme.cpp |  | ||||||
| source/ui7/ui7.cpp |  | ||||||
| source/ui7/container/container.cpp |  | ||||||
| source/ui7/container/button.cpp |  | ||||||
| source/ui7/container/checkbox.cpp |  | ||||||
| source/ui7/container/coloredit.cpp |  | ||||||
| source/ui7/container/dragdata.cpp |  | ||||||
| source/ui7/container/dynobj.cpp |  | ||||||
| source/ui7/container/image.cpp |  | ||||||
| source/ui7/container/label.cpp) |  | ||||||
|  |  | ||||||
| #### Creating the Libraries #### |  | ||||||
| if(PD_BUILD_SHARED) |  | ||||||
| add_pd_lib(pd-core BUILD_SHARED TRUE SRC_FILES ${CORE_SRC}) |  | ||||||
| add_pd_lib(pd-image BUILD_SHARED TRUE SRC_FILES ${IMAGE_SRC} DEPENDS pd-core) |  | ||||||
| add_pd_lib(pd-external SRC_FILES ${EXTERNAL_SRC}) |  | ||||||
| add_pd_lib(pd-lithium BUILD_SHARED TRUE SRC_FILES ${LI_SRC} DEPENDS pd-core) |  | ||||||
| add_pd_lib(pd-net BUILD_SHARED TRUE SRC_FILES ${NET_SRC} DEPENDS pd-core) |  | ||||||
| add_pd_lib(pd-ui7 BUILD_SHARED TRUE SRC_FILES ${UI7_SRC} DEPENDS pd-core pd-lithium) |  | ||||||
| else() |  | ||||||
| add_pd_lib(pd-core SRC_FILES ${CORE_SRC}) |  | ||||||
| add_pd_lib(pd-image SRC_FILES ${IMAGE_SRC} DEPENDS pd-core) |  | ||||||
| add_pd_lib(pd-external SRC_FILES ${EXTERNAL_SRC}) |  | ||||||
| add_pd_lib(pd-lithium SRC_FILES ${LI_SRC} DEPENDS pd-core) |  | ||||||
| add_pd_lib(pd-net SRC_FILES ${NET_SRC} DEPENDS pd-core) |  | ||||||
| add_pd_lib(pd-ui7 SRC_FILES ${UI7_SRC} DEPENDS pd-core pd-lithium) |  | ||||||
| endif() |  | ||||||
|  |  | ||||||
| add_library(palladium INTERFACE) | add_library(palladium INTERFACE) | ||||||
| target_link_libraries(palladium INTERFACE | target_link_libraries(palladium INTERFACE | ||||||
| pd-core pd-image pd-external pd-lithium pd-net pd-ui7 |     pd-core pd-image pd-external pd-lithium pd-ui7 #pd-net | ||||||
| ) | ) | ||||||
|  |  | ||||||
| add_dependencies(palladium | add_dependencies(palladium | ||||||
| pd-core pd-image pd-external pd-lithium pd-net pd-ui7 |     pd-drivers pd-core pd-image pd-external pd-lithium pd-ui7 #pd-net | ||||||
| ) | ) | ||||||
|  |  | ||||||
| install(DIRECTORY include DESTINATION ".") | install(DIRECTORY include DESTINATION ".") | ||||||
|   | |||||||
							
								
								
									
										16
									
								
								README.md
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										16
									
								
								README.md
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -23,27 +23,11 @@ make | |||||||
| make install | make install | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| ## Libraries |  | ||||||
|  |  | ||||||
| | Name | Last Updated | Platform | Depends | |  | ||||||
| |---|---|---|---| |  | ||||||
| | pd-core | 0.3.3 | multi | none | |  | ||||||
| | pd-external | 0.1.0 | multi | none | |  | ||||||
| | pd-image | 0.3.3 | multi | pd-core | |  | ||||||
| | pd-lib3ds | 0.2.4 | 3ds | pd-core, pd-drivers | |  | ||||||
| | pd-net | 0.2.4 | 3ds | pd-core, pd-lib3ds | |  | ||||||
| | pd-lithium | 0.3.3 | multi | pd-core | |  | ||||||
| | pd-sound | 0.2.4 | 3ds | pd-core, mpg123 | |  | ||||||
| | pd-overlays | 0.2.4 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium, pd-ui7 | |  | ||||||
| | pd-ui7 | 0.3.3 | multi | pd-core, pd-lithium | |  | ||||||
| | pd-app | 0.2.4 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium | |  | ||||||
|  |  | ||||||
| ## Credits | ## 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                                                  | | ||||||
|   | |||||||
							
								
								
									
										25
									
								
								backends/3ds/CMakeLists.txt
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										25
									
								
								backends/3ds/CMakeLists.txt
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,18 +1,13 @@ | |||||||
| cmake_minimum_required(VERSION 3.22) | cmake_minimum_required(VERSION 3.22) | ||||||
|  |  | ||||||
| # Make sure to use 3ds toolschain for 3ds build :) | project(pd-3ds LANGUAGES CXX VERSION 0.5.0) | ||||||
| if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) |  | ||||||
|     if(DEFINED ENV{DEVKITPRO}) |  | ||||||
|         set(CMAKE_TOOLCHAIN_FILE "$ENV{DEVKITPRO}/cmake/3DS.cmake" CACHE PATH "toolchain file") |  | ||||||
|     else() |  | ||||||
|         message(FATAL_ERROR "Please define DEVKITPRO to point to your SDK path!") |  | ||||||
|     endif() |  | ||||||
| endif() |  | ||||||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-psabi -O3") |  | ||||||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions") |  | ||||||
|  |  | ||||||
| add_library(pd-backend-3ds STATIC | set(SRC | ||||||
| source/li_backend_c3d.cpp |     source/bknd-gfx.cpp | ||||||
| source/pd_hid_3ds.cpp) |     source/bknd-hid.cpp | ||||||
| target_include_directories(pd-backend-3ds PUBLIC include) |     source/pd-3ds.cpp | ||||||
| target_link_libraries(pd-backend-3ds PUBLIC palladium) | ) | ||||||
|  |  | ||||||
|  | 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); | ||||||
|  | } | ||||||
							
								
								
									
										45
									
								
								backends/3ds/include/li_backend_c3d.hpp → backends/3ds/include/pd-3ds/bknd-gfx.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										45
									
								
								backends/3ds/include/li_backend_c3d.hpp → backends/3ds/include/pd-3ds/bknd-gfx.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -22,15 +22,12 @@ 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. | ||||||
| */ |  */ | ||||||
| 
 |  | ||||||
| #pragma once |  | ||||||
| 
 | 
 | ||||||
| #include <3ds.h> | #include <3ds.h> | ||||||
| #include <citro3d.h> | #include <citro3d.h> | ||||||
| 
 | 
 | ||||||
| #include <pd/core/core.hpp> | #include <pd/lithium/lithium.hpp> | ||||||
| #include <pd/lithium/backend.hpp> |  | ||||||
| 
 | 
 | ||||||
| namespace PD { | namespace PD { | ||||||
| template <typename T> | template <typename T> | ||||||
| @@ -43,42 +40,30 @@ class LinearAlloc : public Allocator<T> { | |||||||
|   T* Allocate(size_t n) override { return (T*)linearAlloc(n * sizeof(T)); } |   T* Allocate(size_t n) override { return (T*)linearAlloc(n * sizeof(T)); } | ||||||
|   void Deallocate(T* ptr) { linearFree(ptr); } |   void Deallocate(T* ptr) { linearFree(ptr); } | ||||||
| }; | }; | ||||||
| namespace LI { | class GfxC3D : public GfxDriver { | ||||||
| class Backend_C3D : public PD::LI::Backend { |  | ||||||
|  public: |  public: | ||||||
|   Backend_C3D() : LI::Backend("Citro3D") {} |   GfxC3D() : GfxDriver("Citro3D") {} | ||||||
|   ~Backend_C3D() {} |   ~GfxC3D() = default; | ||||||
|   PD_SMART_CTOR(Backend_C3D) | 
 | ||||||
|  |   PD_SHARED(GfxC3D); | ||||||
| 
 | 
 | ||||||
|   void Init() override; |   void Init() override; | ||||||
| 
 |  | ||||||
|   void Deinit() override; |   void Deinit() override; | ||||||
| 
 |  | ||||||
|   void NewFrame() override; |   void NewFrame() override; | ||||||
| 
 |   void BindTex(PD::Li::TexAddress addr) override; | ||||||
|   void BindTexture(PD::LI::TexAddress addr) override; |   void RenderDrawData( | ||||||
| 
 |       const std::vector<PD::Li::Command::Ref>& Commands) override; | ||||||
|   void RenderDrawData(const PD::Vec<PD::LI::Command::Ref>& Commands) override; |   PD::Li::Texture::Ref LoadTex( | ||||||
| 
 |  | ||||||
|   PD::LI::Texture::Ref LoadTexture( |  | ||||||
|       const std::vector<PD::u8>& pixels, int w, int h, |       const std::vector<PD::u8>& pixels, int w, int h, | ||||||
|       PD::LI::Texture::Type type = PD::LI::Texture::Type::RGBA32, |       PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32, | ||||||
|       PD::LI::Texture::Filter filter = |       PD::Li::Texture::Filter filter = | ||||||
|           PD::LI::Texture::Filter::LINEAR) override; |           PD::Li::Texture::Filter::LINEAR) override; | ||||||
| 
 | 
 | ||||||
|  private: |   Vec<Li::Vertex, LinearAlloc<Li::Vertex>> VertexBuffer; | ||||||
|   Vec<Vertex, LinearAlloc<Vertex>> VertexBuffer; |  | ||||||
|   Vec<u16, LinearAlloc<u16>> IndexBuffer; |   Vec<u16, LinearAlloc<u16>> IndexBuffer; | ||||||
|   size_t CurrentVertex = 0; |  | ||||||
|   size_t CurrentIndex = 0; |  | ||||||
|   Mat4 Projection; |  | ||||||
|   int pLocProjection = 0; |   int pLocProjection = 0; | ||||||
|   DVLB_s* ShaderCode; |   DVLB_s* ShaderCode; | ||||||
|   shaderProgram_s Shader; |   shaderProgram_s Shader; | ||||||
|   C3D_AttrInfo ShaderInfo; |   C3D_AttrInfo ShaderInfo; | ||||||
|   // For Stats
 |  | ||||||
|   PD::u32 num_vtx = 0; |  | ||||||
|   PD::u32 num_idx = 0; |  | ||||||
| }; | }; | ||||||
| }  // namespace LI
 |  | ||||||
| }  // namespace PD
 | }  // namespace PD
 | ||||||
							
								
								
									
										16
									
								
								backends/3ds/include/pd_hid_3ds.hpp → backends/3ds/include/pd-3ds/bknd-hid.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										16
									
								
								backends/3ds/include/pd_hid_3ds.hpp → backends/3ds/include/pd-3ds/bknd-hid.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -2,7 +2,8 @@ | |||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
| 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 | ||||||
| @@ -23,21 +24,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||||||
| SOFTWARE. | SOFTWARE. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <pd/core/hid_driver.hpp> | #include <pd/drivers/drivers.hpp> | ||||||
| 
 | 
 | ||||||
| namespace PD { | namespace PD { | ||||||
| class Hid3DS : public Hid { | class Hid3DS : public HidDriver { | ||||||
|  public: |  public: | ||||||
|   /**
 |  | ||||||
|    * Constructor to setup Key binds |  | ||||||
|    */ |  | ||||||
|   Hid3DS(); |   Hid3DS(); | ||||||
|   ~Hid3DS() = default; |   ~Hid3DS() = default; | ||||||
|   PD_SMART_CTOR(Hid3DS) |  | ||||||
| 
 | 
 | ||||||
|   /**
 |   PD_SHARED(Hid3DS); | ||||||
|    * Overrideing the Update Function for Input Checking etc | 
 | ||||||
|    */ |  | ||||||
|   void Update() override; |   void Update() override; | ||||||
| }; | }; | ||||||
| }  // namespace PD
 | }  // namespace PD
 | ||||||
| @@ -1,117 +0,0 @@ | |||||||
| #pragma once |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| MIT License |  | ||||||
| Copyright (c) 2024 - 2025 René Amthor (tobid7) |  | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
| of this software and associated documentation files (the "Software"), to deal |  | ||||||
| in the Software without restriction, including without limitation the rights |  | ||||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
| copies of the Software, and to permit persons to whom the Software is |  | ||||||
| furnished to do so, subject to the following conditions: |  | ||||||
|  |  | ||||||
| The above copyright notice and this permission notice shall be included in all |  | ||||||
| copies or substantial portions of the Software. |  | ||||||
|  |  | ||||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
| SOFTWARE. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| #include <3ds.h> |  | ||||||
| #include <arpa/inet.h> |  | ||||||
| #include <malloc.h> |  | ||||||
| #include <netinet/in.h> |  | ||||||
| #include <sys/socket.h> |  | ||||||
|  |  | ||||||
| #include <pd/net/backend.hpp> |  | ||||||
|  |  | ||||||
| namespace PD { |  | ||||||
| class NetBackend3DS : public Net::Backend { |  | ||||||
|  public: |  | ||||||
|   NetBackend3DS() : Net::Backend("3DS") {} |  | ||||||
|   ~NetBackend3DS() = default; |  | ||||||
|   PD_SMART_CTOR(NetBackend3DS) |  | ||||||
|  |  | ||||||
|   bool Init() override { |  | ||||||
|     pSocBuffer = (uint32_t*)memalign(pSocAlign, pSocBufferSize); |  | ||||||
|     Result ret = 0; |  | ||||||
|     if (pSocBuffer == NULL) { |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     if ((ret = socInit(pSocBuffer, pSocBufferSize)) != 0) { |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|     return true; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   void Deinit() override { socExit(); } |  | ||||||
|   int NewSocket() override { return socket(AF_INET, SOCK_STREAM, 0); } |  | ||||||
|   void Close(int sock_id) override { close(sock_id); } |  | ||||||
|   int GetInvalidRef() const override { return -1; } |  | ||||||
|  |  | ||||||
|   bool Bind(int sock_id, u16 port) { |  | ||||||
|     sockaddr_in addr{}; |  | ||||||
|     addr.sin_family = AF_INET; |  | ||||||
|     addr.sin_port = htons(port); |  | ||||||
|     addr.sin_addr.s_addr = INADDR_ANY; |  | ||||||
|     return bind(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1; |  | ||||||
|   } |  | ||||||
|   bool Listen(int sock_id, int backlog = 5) { |  | ||||||
|     return listen(sock_id, backlog) != -1; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   bool WaitForRead(int sock_id, int timeout_ms) override { |  | ||||||
|     fd_set set; |  | ||||||
|     FD_ZERO(&set); |  | ||||||
|     FD_SET(sock_id, &set); |  | ||||||
|  |  | ||||||
|     timeval timeout{}; |  | ||||||
|     timeout.tv_sec = timeout_ms / 1000; |  | ||||||
|     timeout.tv_usec = (timeout_ms % 1000) * 1000; |  | ||||||
|  |  | ||||||
|     int result = select(sock_id + 1, &set, nullptr, nullptr, &timeout); |  | ||||||
|     return (result > 0 && FD_ISSET(sock_id, &set)); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   bool Accept(int sock_id, Net::Socket::Ref client) { |  | ||||||
|     int client_soc = accept(sock_id, nullptr, nullptr); |  | ||||||
|     if (client_soc == -1) { |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|     client->pSocket = client_soc; |  | ||||||
|     return true; |  | ||||||
|   } |  | ||||||
|   bool Connect(int sock_id, const std::string& ip, u16 port) { |  | ||||||
|     sockaddr_in addr{}; |  | ||||||
|     addr.sin_family = AF_INET; |  | ||||||
|     addr.sin_port = htons(port); |  | ||||||
|     inet_pton(AF_INET, ip.c_str(), &addr.sin_addr); |  | ||||||
|     return connect(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1; |  | ||||||
|   } |  | ||||||
|   int Send(int sock_id, const std::string& data) { |  | ||||||
|     return send(sock_id, data.c_str(), static_cast<int>(data.size()), 0); |  | ||||||
|   } |  | ||||||
|   int Receive(int sock_id, std::string& data, int size = 1024) { |  | ||||||
|     char* tmp = new char[size]; |  | ||||||
|     int res = recv(sock_id, tmp, size, 0); |  | ||||||
|     if (res > 0) { |  | ||||||
|       data.assign(tmp, res); |  | ||||||
|     } |  | ||||||
|     delete[] tmp; |  | ||||||
|     return res; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|  private: |  | ||||||
|   /** using libctru u32 here */ |  | ||||||
|   const uint32_t pSocAlign = 0x1000; |  | ||||||
|   const uint32_t pSocBufferSize = 0x100000; |  | ||||||
|   uint32_t* pSocBuffer = nullptr; |  | ||||||
| }; |  | ||||||
| }  // namespace PD |  | ||||||
							
								
								
									
										116
									
								
								backends/3ds/source/li_backend_c3d.cpp → backends/3ds/source/bknd-gfx.cpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										116
									
								
								backends/3ds/source/li_backend_c3d.cpp → backends/3ds/source/bknd-gfx.cpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,6 +1,33 @@ | |||||||
| #include <li_backend_c3d.hpp> | /*
 | ||||||
|  | MIT License | ||||||
|  | 
 | ||||||
|  | Copyright (c) 2024 - 2025 tobid7 | ||||||
|  | 
 | ||||||
|  | Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
|  | of this software and associated documentation files (the "Software"), to deal | ||||||
|  | in the Software without restriction, including without limitation the rights | ||||||
|  | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||
|  | copies of the Software, and to permit persons to whom the Software is | ||||||
|  | furnished to do so, subject to the following conditions: | ||||||
|  | 
 | ||||||
|  | The above copyright notice and this permission notice shall be included in all | ||||||
|  | copies or substantial portions of the Software. | ||||||
|  | 
 | ||||||
|  | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||
|  | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||
|  | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||
|  | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||
|  | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||
|  | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||
|  | SOFTWARE. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | #include <pd-3ds/bknd-gfx.hpp> | ||||||
| 
 | 
 | ||||||
| /// @brief Shader Code (Unused as i dont want to use libpicasso here (yet))
 | /// @brief Shader Code (Unused as i dont want to use libpicasso here (yet))
 | ||||||
|  | /// Update: Picasso breaks the linearRam or ram for somereason
 | ||||||
|  | /// as far as i found out loading anything into linear ram after
 | ||||||
|  | /// using libpicasso to compile a shader leads into a system freeze
 | ||||||
| const char* LIShaderCTR = R"( | const char* LIShaderCTR = R"( | ||||||
| ; LI7 Shader | ; LI7 Shader | ||||||
| ; Constants | ; Constants | ||||||
| @@ -44,102 +71,98 @@ unsigned char li_shader[] = { | |||||||
|   }; |   }; | ||||||
| // clang-format on
 | // clang-format on
 | ||||||
| size_t li_shader_size = 0x124; | size_t li_shader_size = 0x124; | ||||||
|  | 
 | ||||||
| namespace PD { | namespace PD { | ||||||
| namespace LI { | GPU_TEXCOLOR GetTexFmt(Li::Texture::Type type) { | ||||||
| GPU_TEXCOLOR GetTexFmt(Texture::Type type) { |   if (type == Li::Texture::RGBA32) | ||||||
|   if (type == Texture::RGBA32) |  | ||||||
|     return GPU_RGBA8; |     return GPU_RGBA8; | ||||||
|   else if (type == Texture::RGB24) |   else if (type == Li::Texture::RGB24) | ||||||
|     return GPU_RGB8; |     return GPU_RGB8; | ||||||
|   else if (type == Texture::A8) |   else if (type == Li::Texture::A8) | ||||||
|     return GPU_A8; |     return GPU_A8; | ||||||
|   return GPU_RGBA8;  // Default
 |   return GPU_RGBA8;  // Default
 | ||||||
| } | } | ||||||
| int GetBPP(Texture::Type type) { | int GetBPP(Li::Texture::Type type) { | ||||||
|   if (type == Texture::RGBA32) |   if (type == Li::Texture::RGBA32) | ||||||
|     return 4; |     return 4; | ||||||
|   else if (type == Texture::RGB24) |   else if (type == Li::Texture::RGB24) | ||||||
|     return 3; |     return 3; | ||||||
|   else if (type == Texture::A8) |   else if (type == Li::Texture::A8) | ||||||
|     return 1; |     return 1; | ||||||
|   return 0;  // Error
 |   return 0;  // Error
 | ||||||
| } | } | ||||||
| void Backend_C3D::Init() { | 
 | ||||||
|   std::cout << "[BACKEND_C3D]: Setting up Buffers" << std::endl; | void GfxC3D::Init() { | ||||||
|   VertexBuffer.Resize(4 * 8192); |   VertexBuffer.Resize(4 * 8192); | ||||||
|   IndexBuffer.Resize(6 * 8192); |   IndexBuffer.Resize(6 * 8192); | ||||||
| 
 | 
 | ||||||
|   Flags |= LIBackendFlags_FlipUV_Y; |   Flags |= LiBackendFlags_FlipUV_Y; | ||||||
| 
 | 
 | ||||||
|   std::cout << "[BACKEND_C3D]: Loading shader..." << std::endl; |  | ||||||
|   ShaderCode = DVLB_ParseFile((uint32_t*)li_shader, li_shader_size); |   ShaderCode = DVLB_ParseFile((uint32_t*)li_shader, li_shader_size); | ||||||
|   shaderProgramInit(&Shader); |   shaderProgramInit(&Shader); | ||||||
|   shaderProgramSetVsh(&Shader, &ShaderCode->DVLE[0]); |   shaderProgramSetVsh(&Shader, &ShaderCode->DVLE[0]); | ||||||
|   pLocProjection = |   pLocProjection = | ||||||
|       shaderInstanceGetUniformLocation(Shader.vertexShader, "projection"); |       shaderInstanceGetUniformLocation(Shader.vertexShader, "projection"); | ||||||
| 
 | 
 | ||||||
|   std::cout << "[BACKEND_C3D]: Setting up Attr Info" << std::endl; |  | ||||||
|   AttrInfo_Init(&ShaderInfo); |   AttrInfo_Init(&ShaderInfo); | ||||||
|   AttrInfo_AddLoader(&ShaderInfo, 0, GPU_FLOAT, 2); |   AttrInfo_AddLoader(&ShaderInfo, 0, GPU_FLOAT, 2); | ||||||
|   AttrInfo_AddLoader(&ShaderInfo, 1, GPU_FLOAT, 2); |   AttrInfo_AddLoader(&ShaderInfo, 1, GPU_FLOAT, 2); | ||||||
|   AttrInfo_AddLoader(&ShaderInfo, 2, GPU_UNSIGNED_BYTE, 4); |   AttrInfo_AddLoader(&ShaderInfo, 2, GPU_UNSIGNED_BYTE, 4); | ||||||
|   std::cout << "[BACKEND_C3D]: Backend init done!" << std::endl; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Backend_C3D::Deinit() { | void GfxC3D::Deinit() { | ||||||
|   shaderProgramFree(&Shader); |   shaderProgramFree(&Shader); | ||||||
|   DVLB_Free(ShaderCode); |   DVLB_Free(ShaderCode); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Backend_C3D::NewFrame() { | void GfxC3D::NewFrame() { | ||||||
|   C3D_BindProgram(&Shader); |   C3D_BindProgram(&Shader); | ||||||
|   C3D_SetAttrInfo(&ShaderInfo); |   C3D_SetAttrInfo(&ShaderInfo); | ||||||
|   CurrentIndex = 0; |   CurrentIndex = 0; | ||||||
|   CurrentVertex = 0; |   CurrentVertex = 0; | ||||||
|   FrameCounter++; |   FrameCounter++; | ||||||
|   VertexCounter = num_vtx; |   /** Probably completly incorrect but just do it like that */ | ||||||
|   IndexCounter = num_idx; |   VertexCounter = CurrentVertex; | ||||||
|   num_vtx = 0; |   IndexCounter = CurrentIndex; | ||||||
|   num_idx = 0; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Backend_C3D::BindTexture(PD::LI::TexAddress addr) { | void GfxC3D::BindTex(PD::Li::TexAddress addr) { | ||||||
|   C3D_TexBind(0, reinterpret_cast<C3D_Tex*>(addr)); |   C3D_TexBind(0, reinterpret_cast<C3D_Tex*>(addr)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Backend_C3D::RenderDrawData( | void GfxC3D::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) { | ||||||
|     const PD::Vec<PD::LI::Command::Ref>& Commands) { |   // C3D_BindProgram(&Shader);
 | ||||||
|   C3D_BindProgram(&Shader); |   shaderProgramUse(&Shader); | ||||||
|   C3D_SetAttrInfo(&ShaderInfo); |   C3D_SetAttrInfo(&ShaderInfo); | ||||||
|   C3D_Mtx proj; |   C3D_Mtx proj; | ||||||
|   Mtx_OrthoTilt(&proj, 0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f, false); |   Mtx_OrthoTilt(&proj, 0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f, false); | ||||||
|   C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, &proj); |   C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, &proj); | ||||||
|  |   // Mat4 proj = Mat4::Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f);
 | ||||||
|  |   // C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, (C3D_Mtx*)&proj);
 | ||||||
|   C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL); |   C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL); | ||||||
|   C3D_TexEnv* env = C3D_GetTexEnv(0); |   C3D_TexEnv* env = C3D_GetTexEnv(0); | ||||||
|   C3D_TexEnvInit(env); |   C3D_TexEnvInit(env); | ||||||
|   C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0); |   C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0); | ||||||
|   C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE); |   C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE); | ||||||
|   size_t index = 0; |   size_t index = 0; | ||||||
|   while (index < Commands.Size()) { |   while (index < Commands.size()) { | ||||||
|     PD::LI::Texture::Ref Tex = Commands[index]->Tex; |     PD::Li::Texture::Ref Tex = Commands[index]->Tex; | ||||||
|     if (!Tex) { |     if (!Tex) { | ||||||
|       index++; |       index++; | ||||||
|       continue; |       continue; | ||||||
|     } |     } | ||||||
|     bool ScissorEnabled = Commands[index]->ScissorEnabled; |     bool ScissorEnabled = Commands[index]->ScissorOn; | ||||||
|     ivec4 ScissorRect = Commands[index]->ScissorRect; |     ivec4 ScissorRect = Commands[index]->ScissorRect; | ||||||
|     size_t StartIndex = CurrentIndex; |     size_t StartIndex = CurrentIndex; | ||||||
| 
 | 
 | ||||||
|     while (index < Commands.Size() && Commands[index]->Tex == Tex && |     while (index < Commands.size() && Commands[index]->Tex == Tex && | ||||||
|            Commands[index]->ScissorEnabled == ScissorEnabled && |            Commands[index]->ScissorOn == ScissorEnabled && | ||||||
|            Commands[index]->ScissorRect == ScissorRect) { |            Commands[index]->ScissorRect == ScissorRect) { | ||||||
|       auto c = Commands[index]; |       auto c = Commands[index].get(); | ||||||
|       for (size_t i = 0; i < c->IndexBuffer.Size(); i++) { |       for (size_t i = 0; i < c->IndexBuffer.Size(); i++) { | ||||||
|         num_idx++; |  | ||||||
|         IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i); |         IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i); | ||||||
|       } |       } | ||||||
|       for (size_t i = 0; i < c->VertexBuffer.Size(); i++) { |       for (size_t i = 0; i < c->VertexBuffer.Size(); i++) { | ||||||
|         num_vtx++; |  | ||||||
|         VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i); |         VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i); | ||||||
|       } |       } | ||||||
|       index++; |       index++; | ||||||
| @@ -153,10 +176,10 @@ void Backend_C3D::RenderDrawData( | |||||||
|     } else { |     } else { | ||||||
|       C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0); |       C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0); | ||||||
|     } |     } | ||||||
|     BindTexture(Tex->Address); |     BindTex(Tex->Address); | ||||||
|     auto bufInfo = C3D_GetBufInfo(); |     auto bufInfo = C3D_GetBufInfo(); | ||||||
|     BufInfo_Init(bufInfo); |     BufInfo_Init(bufInfo); | ||||||
|     BufInfo_Add(bufInfo, VertexBuffer.Data(), sizeof(Vertex), 3, 0x210); |     BufInfo_Add(bufInfo, VertexBuffer.Data(), sizeof(Li::Vertex), 3, 0x210); | ||||||
| 
 | 
 | ||||||
|     C3D_DrawElements(GPU_TRIANGLES, CurrentIndex - StartIndex, |     C3D_DrawElements(GPU_TRIANGLES, CurrentIndex - StartIndex, | ||||||
|                      C3D_UNSIGNED_SHORT, IndexBuffer.Data() + StartIndex); |                      C3D_UNSIGNED_SHORT, IndexBuffer.Data() + StartIndex); | ||||||
| @@ -164,16 +187,14 @@ void Backend_C3D::RenderDrawData( | |||||||
|   C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL); |   C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| PD::LI::Texture::Ref Backend_C3D::LoadTexture(const std::vector<PD::u8>& pixels, | PD::Li::Texture::Ref GfxC3D::LoadTex(const std::vector<PD::u8>& pixels, int w, | ||||||
|                                               int w, int h, |                                      int h, PD::Li::Texture::Type type, | ||||||
|                                               PD::LI::Texture::Type type, |                                      PD::Li::Texture::Filter filter) { | ||||||
|                                               PD::LI::Texture::Filter filter) { |  | ||||||
|   std::cout << "Loading Tex " << std::format("[{}, {}]", w, h) << std::endl; |  | ||||||
|   if (w > 1024 || h > 1024) { |   if (w > 1024 || h > 1024) { | ||||||
|     return nullptr; |     return nullptr; | ||||||
|   } |   } | ||||||
|   // Don't check here as check done before
 |   // Don't check here as check done before
 | ||||||
|   PD::LI::Texture::Ref res = PD::LI::Texture::New(); |   PD::Li::Texture::Ref res = PD::Li::Texture::New(); | ||||||
|   int bpp = GetBPP(type); |   int bpp = GetBPP(type); | ||||||
|   ivec2 tex_size(w, h); |   ivec2 tex_size(w, h); | ||||||
|   // Pow2
 |   // Pow2
 | ||||||
| @@ -189,7 +210,7 @@ PD::LI::Texture::Ref Backend_C3D::LoadTexture(const std::vector<PD::u8>& pixels, | |||||||
|                   1.0 - ((float)h / (float)tex_size.y)); |                   1.0 - ((float)h / (float)tex_size.y)); | ||||||
| 
 | 
 | ||||||
|   // Texture Setup
 |   // Texture Setup
 | ||||||
|   auto fltr = (filter == Texture::NEAREST ? GPU_NEAREST : GPU_LINEAR); |   auto fltr = (filter == Li::Texture::NEAREST ? GPU_NEAREST : GPU_LINEAR); | ||||||
|   auto tex_fmt = GetTexFmt(type); |   auto tex_fmt = GetTexFmt(type); | ||||||
|   auto tex = new C3D_Tex; |   auto tex = new C3D_Tex; | ||||||
|   C3D_TexInit(tex, (u16)tex_size.x, (u16)tex_size.y, tex_fmt); |   C3D_TexInit(tex, (u16)tex_size.x, (u16)tex_size.y, tex_fmt); | ||||||
| @@ -221,11 +242,10 @@ PD::LI::Texture::Ref Backend_C3D::LoadTexture(const std::vector<PD::u8>& pixels, | |||||||
| 
 | 
 | ||||||
|   tex->border = 0x00000000; |   tex->border = 0x00000000; | ||||||
|   C3D_TexSetWrap(tex, GPU_REPEAT, GPU_REPEAT); |   C3D_TexSetWrap(tex, GPU_REPEAT, GPU_REPEAT); | ||||||
|   res->Address = (TexAddress)tex; |   res->Address = (Li::TexAddress)tex; | ||||||
|   std::cout << std::format("Tex {:#08x} Addr {:#08X}", (TexAddress)res.get(), |   std::cout << std::format("Tex {:#08x} Addr {:#08X}", | ||||||
|                            res->Address) |                            (Li::TexAddress)res.get(), res->Address) | ||||||
|             << std::endl; |             << std::endl; | ||||||
|   return res; |   return res; | ||||||
| } | } | ||||||
| }  // namespace LI
 | }  // namespace PD
 | ||||||
| }  // namespace PD
 |  | ||||||
							
								
								
									
										87
									
								
								backends/3ds/source/bknd-hid.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										87
									
								
								backends/3ds/source/bknd-hid.cpp
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,87 @@ | |||||||
|  | /* | ||||||
|  | MIT License | ||||||
|  |  | ||||||
|  | Copyright (c) 2024 - 2025 tobid7 | ||||||
|  |  | ||||||
|  | Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
|  | of this software and associated documentation files (the "Software"), to deal | ||||||
|  | in the Software without restriction, including without limitation the rights | ||||||
|  | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||
|  | copies of the Software, and to permit persons to whom the Software is | ||||||
|  | furnished to do so, subject to the following conditions: | ||||||
|  |  | ||||||
|  | The above copyright notice and this permission notice shall be included in all | ||||||
|  | copies or substantial portions of the Software. | ||||||
|  |  | ||||||
|  | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||
|  | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||
|  | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||
|  | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||
|  | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||
|  | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||
|  | SOFTWARE. | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | #include <3ds.h> | ||||||
|  |  | ||||||
|  | #include <pd-3ds/bknd-hid.hpp> | ||||||
|  |  | ||||||
|  | namespace PD { | ||||||
|  | Hid3DS::Hid3DS() : HidDriver("Hid3DS") { | ||||||
|  |   this->Flags |= Flags_HasTouch; | ||||||
|  |   this->Flags |= FLags_HasGamepad; | ||||||
|  |   pBinds[KEY_A] = A; | ||||||
|  |   pBinds[KEY_B] = B; | ||||||
|  |   pBinds[KEY_X] = X; | ||||||
|  |   pBinds[KEY_Y] = Y; | ||||||
|  |   pBinds[KEY_START] = Start; | ||||||
|  |   pBinds[KEY_SELECT] = Select; | ||||||
|  |   pBinds[KEY_L] = L; | ||||||
|  |   pBinds[KEY_R] = R; | ||||||
|  |   pBinds[KEY_DUP] = DUp; | ||||||
|  |   pBinds[KEY_DDOWN] = DDown; | ||||||
|  |   pBinds[KEY_DLEFT] = DLeft; | ||||||
|  |   pBinds[KEY_DRIGHT] = DRight; | ||||||
|  |   pBinds[KEY_CPAD_UP] = CPUp; | ||||||
|  |   pBinds[KEY_CPAD_DOWN] = CPDown; | ||||||
|  |   pBinds[KEY_CPAD_LEFT] = CPLeft; | ||||||
|  |   pBinds[KEY_CPAD_RIGHT] = CPRight; | ||||||
|  |   pBinds[KEY_CSTICK_UP] = CSUp; | ||||||
|  |   pBinds[KEY_CSTICK_DOWN] = CSDown; | ||||||
|  |   pBinds[KEY_CSTICK_LEFT] = CSLeft; | ||||||
|  |   pBinds[KEY_CSTICK_RIGHT] = CSRight; | ||||||
|  |   pBinds[KEY_ZL] = ZL; | ||||||
|  |   pBinds[KEY_ZR] = ZR; | ||||||
|  |   pBinds[KEY_TOUCH] = Touch; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Hid3DS::Update() { | ||||||
|  |   hidScanInput(); | ||||||
|  |   for (int i = 0; i < 2; i++) { | ||||||
|  |     KeyEvents[i][Event_Down] = 0; | ||||||
|  |     KeyEvents[i][Event_Held] = 0; | ||||||
|  |     KeyEvents[i][Event_Up] = 0; | ||||||
|  |   } | ||||||
|  |   u32 kd = hidKeysDown(); | ||||||
|  |   u32 kh = hidKeysHeld(); | ||||||
|  |   u32 ku = hidKeysUp(); | ||||||
|  |   for (auto &b : pBinds) { | ||||||
|  |     if (b.first & kd) { | ||||||
|  |       KeyEvents[0][Event_Down] |= b.second; | ||||||
|  |     } | ||||||
|  |     if (b.first & kh) { | ||||||
|  |       KeyEvents[0][Event_Held] |= b.second; | ||||||
|  |     } | ||||||
|  |     if (b.first & ku) { | ||||||
|  |       KeyEvents[0][Event_Up] |= b.second; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   if (pLocked) { | ||||||
|  |     SwapTab(); | ||||||
|  |   } | ||||||
|  |   touchPosition t; | ||||||
|  |   hidTouchRead(&t); | ||||||
|  |   pMouse[1] = pMouse[0];  // Cycle pMouse pos | ||||||
|  |   pMouse[0] = fvec2(t.px, t.py); | ||||||
|  | } | ||||||
|  | }  // namespace PD | ||||||
							
								
								
									
										36
									
								
								backends/3ds/source/pd-3ds.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										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::Gfx::Init(PD::GfxC3D::New()); | ||||||
|  |   PD::Hid::Init(PD::Hid3DS::New()); | ||||||
|  | } | ||||||
|  | }  // namespace PD | ||||||
| @@ -1,60 +0,0 @@ | |||||||
| #include <3ds.h> |  | ||||||
|  |  | ||||||
| #include <pd_hid_3ds.hpp> |  | ||||||
|  |  | ||||||
| namespace PD { |  | ||||||
| Hid3DS::Hid3DS() : Hid("3DS") { |  | ||||||
|   binds[KEY_A] = A; |  | ||||||
|   binds[KEY_B] = B; |  | ||||||
|   binds[KEY_X] = X; |  | ||||||
|   binds[KEY_Y] = Y; |  | ||||||
|   binds[KEY_START] = Start; |  | ||||||
|   binds[KEY_SELECT] = Select; |  | ||||||
|   binds[KEY_L] = L; |  | ||||||
|   binds[KEY_R] = R; |  | ||||||
|   binds[KEY_DUP] = DUp; |  | ||||||
|   binds[KEY_DDOWN] = DDown; |  | ||||||
|   binds[KEY_DLEFT] = DLeft; |  | ||||||
|   binds[KEY_DRIGHT] = DRight; |  | ||||||
|   binds[KEY_CPAD_UP] = CPUp; |  | ||||||
|   binds[KEY_CPAD_DOWN] = CPDown; |  | ||||||
|   binds[KEY_CPAD_LEFT] = CPLeft; |  | ||||||
|   binds[KEY_CPAD_RIGHT] = CPRight; |  | ||||||
|   binds[KEY_CSTICK_UP] = CSUp; |  | ||||||
|   binds[KEY_CSTICK_DOWN] = CSDown; |  | ||||||
|   binds[KEY_CSTICK_LEFT] = CSLeft; |  | ||||||
|   binds[KEY_CSTICK_RIGHT] = CSRight; |  | ||||||
|   binds[KEY_ZL] = ZL; |  | ||||||
|   binds[KEY_ZR] = ZR; |  | ||||||
|   binds[KEY_TOUCH] = Touch; |  | ||||||
| } |  | ||||||
| void Hid3DS::Update() { |  | ||||||
|   hidScanInput(); |  | ||||||
|   for (int i = 0; i < 2; i++) { |  | ||||||
|     key_events[i][Event_Down] = 0; |  | ||||||
|     key_events[i][Event_Held] = 0; |  | ||||||
|     key_events[i][Event_Up] = 0; |  | ||||||
|   } |  | ||||||
|   u32 kd = hidKeysDown(); |  | ||||||
|   u32 kh = hidKeysHeld(); |  | ||||||
|   u32 ku = hidKeysUp(); |  | ||||||
|   for (auto &b : binds) { |  | ||||||
|     if (b.first & kd) { |  | ||||||
|       key_events[0][Event_Down] |= b.second; |  | ||||||
|     } |  | ||||||
|     if (b.first & kh) { |  | ||||||
|       key_events[0][Event_Held] |= b.second; |  | ||||||
|     } |  | ||||||
|     if (b.first & ku) { |  | ||||||
|       key_events[0][Event_Up] |= b.second; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|   if (locked) { |  | ||||||
|     SwappyTable(); |  | ||||||
|   } |  | ||||||
|   touchPosition t; |  | ||||||
|   hidTouchRead(&t); |  | ||||||
|   touch[1] = touch[0];  // Cycle touch pos |  | ||||||
|   touch[0] = fvec2(t.px, t.py); |  | ||||||
| } |  | ||||||
| }  // namespace PD |  | ||||||
							
								
								
									
										31
									
								
								backends/desktop/CMakeLists.txt
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										31
									
								
								backends/desktop/CMakeLists.txt
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,27 +1,16 @@ | |||||||
| cmake_minimum_required(VERSION 3.22) | cmake_minimum_required(VERSION 3.22) | ||||||
|  |  | ||||||
| if(WIN32) | project(pd-desktop LANGUAGES CXX VERSION 0.5.0) | ||||||
| set(EXTRA_LIBS ws2_32) |  | ||||||
| else() |  | ||||||
| set(EXTRA_LIBS) |  | ||||||
| endif() |  | ||||||
|  |  | ||||||
| add_subdirectory(glfw) |  | ||||||
| add_subdirectory(glad) | add_subdirectory(glad) | ||||||
|  | add_subdirectory(glfw) | ||||||
|  |  | ||||||
| # if(PD_BUILD_SHARED) | set(SRC | ||||||
| # add_library(pd-backend-desktop SHARED |     source/bknd-gfx.cpp | ||||||
| # source/li_backend_gl2.cpp |     source/bknd-hid.cpp | ||||||
| # source/pd_hid_glfw.cpp) |     source/pd-desktop.cpp | ||||||
| # target_compile_definitions(pd-backend-desktop PUBLIC | ) | ||||||
| #     -DPD_BKND_DESKTOP_BUILD_SHARED=1) |  | ||||||
| # else() |  | ||||||
| add_library(pd-backend-desktop STATIC |  | ||||||
| source/li_backend_gl2.cpp |  | ||||||
| source/pd_hid_glfw.cpp) |  | ||||||
| #endif() |  | ||||||
|  |  | ||||||
| target_compile_definitions(pd-backend-desktop PUBLIC | pd_add_lib(pd-desktop SRC_FILES ${SRC}) | ||||||
|      -DPD_BKND_DESKTOP_STATIC=1) | target_include_directories(pd-desktop PUBLIC include) | ||||||
| target_include_directories(pd-backend-desktop PUBLIC include) | target_link_libraries(pd-desktop PUBLIC palladium glad glfw) | ||||||
| target_link_libraries(pd-backend-desktop PUBLIC glad glfw palladium ${EXTRA_LIBS}) |  | ||||||
|   | |||||||
							
								
								
									
										0
									
								
								backends/desktop/glad/CMakeLists.txt
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								backends/desktop/glad/CMakeLists.txt
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
								
								
									
										622
									
								
								backends/desktop/glad/include/KHR/khrplatform.h
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										622
									
								
								backends/desktop/glad/include/KHR/khrplatform.h
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,311 +1,311 @@ | |||||||
| #ifndef __khrplatform_h_ | #ifndef __khrplatform_h_ | ||||||
| #define __khrplatform_h_ | #define __khrplatform_h_ | ||||||
|  |  | ||||||
| /* | /* | ||||||
| ** Copyright (c) 2008-2018 The Khronos Group Inc. | ** Copyright (c) 2008-2018 The Khronos Group Inc. | ||||||
| ** | ** | ||||||
| ** Permission is hereby granted, free of charge, to any person obtaining a | ** Permission is hereby granted, free of charge, to any person obtaining a | ||||||
| ** copy of this software and/or associated documentation files (the | ** copy of this software and/or associated documentation files (the | ||||||
| ** "Materials"), to deal in the Materials without restriction, including | ** "Materials"), to deal in the Materials without restriction, including | ||||||
| ** without limitation the rights to use, copy, modify, merge, publish, | ** without limitation the rights to use, copy, modify, merge, publish, | ||||||
| ** distribute, sublicense, and/or sell copies of the Materials, and to | ** distribute, sublicense, and/or sell copies of the Materials, and to | ||||||
| ** permit persons to whom the Materials are furnished to do so, subject to | ** permit persons to whom the Materials are furnished to do so, subject to | ||||||
| ** the following conditions: | ** the following conditions: | ||||||
| ** | ** | ||||||
| ** The above copyright notice and this permission notice shall be included | ** The above copyright notice and this permission notice shall be included | ||||||
| ** in all copies or substantial portions of the Materials. | ** in all copies or substantial portions of the Materials. | ||||||
| ** | ** | ||||||
| ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||||||
| ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||||||
| ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||||||
| ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||||||
| ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||||||
| ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||||||
| ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. | ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. | ||||||
| */ | */ | ||||||
|  |  | ||||||
| /* Khronos platform-specific types and definitions. | /* Khronos platform-specific types and definitions. | ||||||
|  * |  * | ||||||
|  * The master copy of khrplatform.h is maintained in the Khronos EGL |  * The master copy of khrplatform.h is maintained in the Khronos EGL | ||||||
|  * Registry repository at https://github.com/KhronosGroup/EGL-Registry |  * Registry repository at https://github.com/KhronosGroup/EGL-Registry | ||||||
|  * The last semantic modification to khrplatform.h was at commit ID: |  * The last semantic modification to khrplatform.h was at commit ID: | ||||||
|  *      67a3e0864c2d75ea5287b9f3d2eb74a745936692 |  *      67a3e0864c2d75ea5287b9f3d2eb74a745936692 | ||||||
|  * |  * | ||||||
|  * Adopters may modify this file to suit their platform. Adopters are |  * Adopters may modify this file to suit their platform. Adopters are | ||||||
|  * encouraged to submit platform specific modifications to the Khronos |  * encouraged to submit platform specific modifications to the Khronos | ||||||
|  * group so that they can be included in future versions of this file. |  * group so that they can be included in future versions of this file. | ||||||
|  * Please submit changes by filing pull requests or issues on |  * Please submit changes by filing pull requests or issues on | ||||||
|  * the EGL Registry repository linked above. |  * the EGL Registry repository linked above. | ||||||
|  * |  * | ||||||
|  * |  * | ||||||
|  * See the Implementer's Guidelines for information about where this file |  * See the Implementer's Guidelines for information about where this file | ||||||
|  * should be located on your system and for more details of its use: |  * should be located on your system and for more details of its use: | ||||||
|  *    http://www.khronos.org/registry/implementers_guide.pdf |  *    http://www.khronos.org/registry/implementers_guide.pdf | ||||||
|  * |  * | ||||||
|  * This file should be included as |  * This file should be included as | ||||||
|  *        #include <KHR/khrplatform.h> |  *        #include <KHR/khrplatform.h> | ||||||
|  * by Khronos client API header files that use its types and defines. |  * 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. |  * The types in khrplatform.h should only be used to define API-specific types. | ||||||
|  * |  * | ||||||
|  * Types defined in khrplatform.h: |  * Types defined in khrplatform.h: | ||||||
|  *    khronos_int8_t              signed   8  bit |  *    khronos_int8_t              signed   8  bit | ||||||
|  *    khronos_uint8_t             unsigned 8  bit |  *    khronos_uint8_t             unsigned 8  bit | ||||||
|  *    khronos_int16_t             signed   16 bit |  *    khronos_int16_t             signed   16 bit | ||||||
|  *    khronos_uint16_t            unsigned 16 bit |  *    khronos_uint16_t            unsigned 16 bit | ||||||
|  *    khronos_int32_t             signed   32 bit |  *    khronos_int32_t             signed   32 bit | ||||||
|  *    khronos_uint32_t            unsigned 32 bit |  *    khronos_uint32_t            unsigned 32 bit | ||||||
|  *    khronos_int64_t             signed   64 bit |  *    khronos_int64_t             signed   64 bit | ||||||
|  *    khronos_uint64_t            unsigned 64 bit |  *    khronos_uint64_t            unsigned 64 bit | ||||||
|  *    khronos_intptr_t            signed   same number of bits as a pointer |  *    khronos_intptr_t            signed   same number of bits as a pointer | ||||||
|  *    khronos_uintptr_t           unsigned same number of bits as a pointer |  *    khronos_uintptr_t           unsigned same number of bits as a pointer | ||||||
|  *    khronos_ssize_t             signed   size |  *    khronos_ssize_t             signed   size | ||||||
|  *    khronos_usize_t             unsigned size |  *    khronos_usize_t             unsigned size | ||||||
|  *    khronos_float_t             signed   32 bit floating point |  *    khronos_float_t             signed   32 bit floating point | ||||||
|  *    khronos_time_ns_t           unsigned 64 bit time in nanoseconds |  *    khronos_time_ns_t           unsigned 64 bit time in nanoseconds | ||||||
|  *    khronos_utime_nanoseconds_t unsigned time interval or absolute time in |  *    khronos_utime_nanoseconds_t unsigned time interval or absolute time in | ||||||
|  *                                         nanoseconds |  *                                         nanoseconds | ||||||
|  *    khronos_stime_nanoseconds_t signed time interval in nanoseconds |  *    khronos_stime_nanoseconds_t signed time interval in nanoseconds | ||||||
|  *    khronos_boolean_enum_t      enumerated boolean type. This should |  *    khronos_boolean_enum_t      enumerated boolean type. This should | ||||||
|  *      only be used as a base type when a client API's boolean type is |  *      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 |  *      an enum. Client APIs which use an integer or other type for | ||||||
|  *      booleans cannot use this as the base type for their boolean. |  *      booleans cannot use this as the base type for their boolean. | ||||||
|  * |  * | ||||||
|  * Tokens defined in khrplatform.h: |  * Tokens defined in khrplatform.h: | ||||||
|  * |  * | ||||||
|  *    KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. |  *    KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. | ||||||
|  * |  * | ||||||
|  *    KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. |  *    KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. | ||||||
|  *    KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. |  *    KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. | ||||||
|  * |  * | ||||||
|  * Calling convention macros defined in this file: |  * Calling convention macros defined in this file: | ||||||
|  *    KHRONOS_APICALL |  *    KHRONOS_APICALL | ||||||
|  *    KHRONOS_APIENTRY |  *    KHRONOS_APIENTRY | ||||||
|  *    KHRONOS_APIATTRIBUTES |  *    KHRONOS_APIATTRIBUTES | ||||||
|  * |  * | ||||||
|  * These may be used in function prototypes as: |  * These may be used in function prototypes as: | ||||||
|  * |  * | ||||||
|  *      KHRONOS_APICALL void KHRONOS_APIENTRY funcname( |  *      KHRONOS_APICALL void KHRONOS_APIENTRY funcname( | ||||||
|  *                                  int arg1, |  *                                  int arg1, | ||||||
|  *                                  int arg2) KHRONOS_APIATTRIBUTES; |  *                                  int arg2) KHRONOS_APIATTRIBUTES; | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| #if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC) | #if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC) | ||||||
| #   define KHRONOS_STATIC 1 | #   define KHRONOS_STATIC 1 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| /*------------------------------------------------------------------------- | /*------------------------------------------------------------------------- | ||||||
|  * Definition of KHRONOS_APICALL |  * Definition of KHRONOS_APICALL | ||||||
|  *------------------------------------------------------------------------- |  *------------------------------------------------------------------------- | ||||||
|  * This precedes the return type of the function in the function prototype. |  * This precedes the return type of the function in the function prototype. | ||||||
|  */ |  */ | ||||||
| #if defined(KHRONOS_STATIC) | #if defined(KHRONOS_STATIC) | ||||||
|     /* If the preprocessor constant KHRONOS_STATIC is defined, make the |     /* If the preprocessor constant KHRONOS_STATIC is defined, make the | ||||||
|      * header compatible with static linking. */ |      * header compatible with static linking. */ | ||||||
| #   define KHRONOS_APICALL | #   define KHRONOS_APICALL | ||||||
| #elif defined(_WIN32) | #elif defined(_WIN32) | ||||||
| #   define KHRONOS_APICALL __declspec(dllimport) | #   define KHRONOS_APICALL __declspec(dllimport) | ||||||
| #elif defined (__SYMBIAN32__) | #elif defined (__SYMBIAN32__) | ||||||
| #   define KHRONOS_APICALL IMPORT_C | #   define KHRONOS_APICALL IMPORT_C | ||||||
| #elif defined(__ANDROID__) | #elif defined(__ANDROID__) | ||||||
| #   define KHRONOS_APICALL __attribute__((visibility("default"))) | #   define KHRONOS_APICALL __attribute__((visibility("default"))) | ||||||
| #else | #else | ||||||
| #   define KHRONOS_APICALL | #   define KHRONOS_APICALL | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| /*------------------------------------------------------------------------- | /*------------------------------------------------------------------------- | ||||||
|  * Definition of KHRONOS_APIENTRY |  * Definition of KHRONOS_APIENTRY | ||||||
|  *------------------------------------------------------------------------- |  *------------------------------------------------------------------------- | ||||||
|  * This follows the return type of the function  and precedes the function |  * This follows the return type of the function  and precedes the function | ||||||
|  * name in the function prototype. |  * name in the function prototype. | ||||||
|  */ |  */ | ||||||
| #if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) | #if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) | ||||||
|     /* Win32 but not WinCE */ |     /* Win32 but not WinCE */ | ||||||
| #   define KHRONOS_APIENTRY __stdcall | #   define KHRONOS_APIENTRY __stdcall | ||||||
| #else | #else | ||||||
| #   define KHRONOS_APIENTRY | #   define KHRONOS_APIENTRY | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| /*------------------------------------------------------------------------- | /*------------------------------------------------------------------------- | ||||||
|  * Definition of KHRONOS_APIATTRIBUTES |  * Definition of KHRONOS_APIATTRIBUTES | ||||||
|  *------------------------------------------------------------------------- |  *------------------------------------------------------------------------- | ||||||
|  * This follows the closing parenthesis of the function prototype arguments. |  * This follows the closing parenthesis of the function prototype arguments. | ||||||
|  */ |  */ | ||||||
| #if defined (__ARMCC_2__) | #if defined (__ARMCC_2__) | ||||||
| #define KHRONOS_APIATTRIBUTES __softfp | #define KHRONOS_APIATTRIBUTES __softfp | ||||||
| #else | #else | ||||||
| #define KHRONOS_APIATTRIBUTES | #define KHRONOS_APIATTRIBUTES | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| /*------------------------------------------------------------------------- | /*------------------------------------------------------------------------- | ||||||
|  * basic type definitions |  * basic type definitions | ||||||
|  *-----------------------------------------------------------------------*/ |  *-----------------------------------------------------------------------*/ | ||||||
| #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) | ||||||
|  |  | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Using <stdint.h> |  * Using <stdint.h> | ||||||
|  */ |  */ | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| typedef int32_t                 khronos_int32_t; | typedef int32_t                 khronos_int32_t; | ||||||
| typedef uint32_t                khronos_uint32_t; | typedef uint32_t                khronos_uint32_t; | ||||||
| typedef int64_t                 khronos_int64_t; | typedef int64_t                 khronos_int64_t; | ||||||
| typedef uint64_t                khronos_uint64_t; | typedef uint64_t                khronos_uint64_t; | ||||||
| #define KHRONOS_SUPPORT_INT64   1 | #define KHRONOS_SUPPORT_INT64   1 | ||||||
| #define KHRONOS_SUPPORT_FLOAT   1 | #define KHRONOS_SUPPORT_FLOAT   1 | ||||||
| /* | /* | ||||||
|  * To support platform where unsigned long cannot be used interchangeably with |  * 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. |  * 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 |  * 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 |  * ABI breakage if khronos_uintptr_t is changed from unsigned long to | ||||||
|  * unsigned long long or similar (this results in different C++ name mangling). |  * 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 |  * 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. |  * platforms where the size of a pointer is larger than the size of long. | ||||||
|  */ |  */ | ||||||
| #if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__) | #if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__) | ||||||
| #if __SIZEOF_POINTER__ > __SIZEOF_LONG__ | #if __SIZEOF_POINTER__ > __SIZEOF_LONG__ | ||||||
| #define KHRONOS_USE_INTPTR_T | #define KHRONOS_USE_INTPTR_T | ||||||
| #endif | #endif | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #elif defined(__VMS ) || defined(__sgi) | #elif defined(__VMS ) || defined(__sgi) | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Using <inttypes.h> |  * Using <inttypes.h> | ||||||
|  */ |  */ | ||||||
| #include <inttypes.h> | #include <inttypes.h> | ||||||
| typedef int32_t                 khronos_int32_t; | typedef int32_t                 khronos_int32_t; | ||||||
| typedef uint32_t                khronos_uint32_t; | typedef uint32_t                khronos_uint32_t; | ||||||
| typedef int64_t                 khronos_int64_t; | typedef int64_t                 khronos_int64_t; | ||||||
| typedef uint64_t                khronos_uint64_t; | typedef uint64_t                khronos_uint64_t; | ||||||
| #define KHRONOS_SUPPORT_INT64   1 | #define KHRONOS_SUPPORT_INT64   1 | ||||||
| #define KHRONOS_SUPPORT_FLOAT   1 | #define KHRONOS_SUPPORT_FLOAT   1 | ||||||
|  |  | ||||||
| #elif defined(_WIN32) && !defined(__SCITECH_SNAP__) | #elif defined(_WIN32) && !defined(__SCITECH_SNAP__) | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Win32 |  * Win32 | ||||||
|  */ |  */ | ||||||
| typedef __int32                 khronos_int32_t; | typedef __int32                 khronos_int32_t; | ||||||
| typedef unsigned __int32        khronos_uint32_t; | typedef unsigned __int32        khronos_uint32_t; | ||||||
| typedef __int64                 khronos_int64_t; | typedef __int64                 khronos_int64_t; | ||||||
| typedef unsigned __int64        khronos_uint64_t; | typedef unsigned __int64        khronos_uint64_t; | ||||||
| #define KHRONOS_SUPPORT_INT64   1 | #define KHRONOS_SUPPORT_INT64   1 | ||||||
| #define KHRONOS_SUPPORT_FLOAT   1 | #define KHRONOS_SUPPORT_FLOAT   1 | ||||||
|  |  | ||||||
| #elif defined(__sun__) || defined(__digital__) | #elif defined(__sun__) || defined(__digital__) | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Sun or Digital |  * Sun or Digital | ||||||
|  */ |  */ | ||||||
| typedef int                     khronos_int32_t; | typedef int                     khronos_int32_t; | ||||||
| typedef unsigned int            khronos_uint32_t; | typedef unsigned int            khronos_uint32_t; | ||||||
| #if defined(__arch64__) || defined(_LP64) | #if defined(__arch64__) || defined(_LP64) | ||||||
| typedef long int                khronos_int64_t; | typedef long int                khronos_int64_t; | ||||||
| typedef unsigned long int       khronos_uint64_t; | typedef unsigned long int       khronos_uint64_t; | ||||||
| #else | #else | ||||||
| typedef long long int           khronos_int64_t; | typedef long long int           khronos_int64_t; | ||||||
| typedef unsigned long long int  khronos_uint64_t; | typedef unsigned long long int  khronos_uint64_t; | ||||||
| #endif /* __arch64__ */ | #endif /* __arch64__ */ | ||||||
| #define KHRONOS_SUPPORT_INT64   1 | #define KHRONOS_SUPPORT_INT64   1 | ||||||
| #define KHRONOS_SUPPORT_FLOAT   1 | #define KHRONOS_SUPPORT_FLOAT   1 | ||||||
|  |  | ||||||
| #elif 0 | #elif 0 | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Hypothetical platform with no float or int64 support |  * Hypothetical platform with no float or int64 support | ||||||
|  */ |  */ | ||||||
| typedef int                     khronos_int32_t; | typedef int                     khronos_int32_t; | ||||||
| typedef unsigned int            khronos_uint32_t; | typedef unsigned int            khronos_uint32_t; | ||||||
| #define KHRONOS_SUPPORT_INT64   0 | #define KHRONOS_SUPPORT_INT64   0 | ||||||
| #define KHRONOS_SUPPORT_FLOAT   0 | #define KHRONOS_SUPPORT_FLOAT   0 | ||||||
|  |  | ||||||
| #else | #else | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Generic fallback |  * Generic fallback | ||||||
|  */ |  */ | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| typedef int32_t                 khronos_int32_t; | typedef int32_t                 khronos_int32_t; | ||||||
| typedef uint32_t                khronos_uint32_t; | typedef uint32_t                khronos_uint32_t; | ||||||
| typedef int64_t                 khronos_int64_t; | typedef int64_t                 khronos_int64_t; | ||||||
| typedef uint64_t                khronos_uint64_t; | typedef uint64_t                khronos_uint64_t; | ||||||
| #define KHRONOS_SUPPORT_INT64   1 | #define KHRONOS_SUPPORT_INT64   1 | ||||||
| #define KHRONOS_SUPPORT_FLOAT   1 | #define KHRONOS_SUPPORT_FLOAT   1 | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Types that are (so far) the same on all platforms |  * Types that are (so far) the same on all platforms | ||||||
|  */ |  */ | ||||||
| typedef signed   char          khronos_int8_t; | typedef signed   char          khronos_int8_t; | ||||||
| typedef unsigned char          khronos_uint8_t; | typedef unsigned char          khronos_uint8_t; | ||||||
| typedef signed   short int     khronos_int16_t; | typedef signed   short int     khronos_int16_t; | ||||||
| typedef unsigned short int     khronos_uint16_t; | typedef unsigned short int     khronos_uint16_t; | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Types that differ between LLP64 and LP64 architectures - in LLP64, |  * Types that differ between LLP64 and LP64 architectures - in LLP64, | ||||||
|  * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears |  * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears | ||||||
|  * to be the only LLP64 architecture in current use. |  * to be the only LLP64 architecture in current use. | ||||||
|  */ |  */ | ||||||
| #ifdef KHRONOS_USE_INTPTR_T | #ifdef KHRONOS_USE_INTPTR_T | ||||||
| typedef intptr_t               khronos_intptr_t; | typedef intptr_t               khronos_intptr_t; | ||||||
| typedef uintptr_t              khronos_uintptr_t; | typedef uintptr_t              khronos_uintptr_t; | ||||||
| #elif defined(_WIN64) | #elif defined(_WIN64) | ||||||
| typedef signed   long long int khronos_intptr_t; | typedef signed   long long int khronos_intptr_t; | ||||||
| typedef unsigned long long int khronos_uintptr_t; | typedef unsigned long long int khronos_uintptr_t; | ||||||
| #else | #else | ||||||
| typedef signed   long  int     khronos_intptr_t; | typedef signed   long  int     khronos_intptr_t; | ||||||
| typedef unsigned long  int     khronos_uintptr_t; | typedef unsigned long  int     khronos_uintptr_t; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if defined(_WIN64) | #if defined(_WIN64) | ||||||
| typedef signed   long long int khronos_ssize_t; | typedef signed   long long int khronos_ssize_t; | ||||||
| typedef unsigned long long int khronos_usize_t; | typedef unsigned long long int khronos_usize_t; | ||||||
| #else | #else | ||||||
| typedef signed   long  int     khronos_ssize_t; | typedef signed   long  int     khronos_ssize_t; | ||||||
| typedef unsigned long  int     khronos_usize_t; | typedef unsigned long  int     khronos_usize_t; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if KHRONOS_SUPPORT_FLOAT | #if KHRONOS_SUPPORT_FLOAT | ||||||
| /* | /* | ||||||
|  * Float type |  * Float type | ||||||
|  */ |  */ | ||||||
| typedef          float         khronos_float_t; | typedef          float         khronos_float_t; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if KHRONOS_SUPPORT_INT64 | #if KHRONOS_SUPPORT_INT64 | ||||||
| /* Time types | /* Time types | ||||||
|  * |  * | ||||||
|  * These types can be used to represent a time interval in nanoseconds or |  * These types can be used to represent a time interval in nanoseconds or | ||||||
|  * an absolute Unadjusted System Time.  Unadjusted System Time is the number |  * an absolute Unadjusted System Time.  Unadjusted System Time is the number | ||||||
|  * of nanoseconds since some arbitrary system event (e.g. since the last |  * of nanoseconds since some arbitrary system event (e.g. since the last | ||||||
|  * time the system booted).  The Unadjusted System Time is an unsigned |  * time the system booted).  The Unadjusted System Time is an unsigned | ||||||
|  * 64 bit value that wraps back to 0 every 584 years.  Time intervals |  * 64 bit value that wraps back to 0 every 584 years.  Time intervals | ||||||
|  * may be either signed or unsigned. |  * may be either signed or unsigned. | ||||||
|  */ |  */ | ||||||
| typedef khronos_uint64_t       khronos_utime_nanoseconds_t; | typedef khronos_uint64_t       khronos_utime_nanoseconds_t; | ||||||
| typedef khronos_int64_t        khronos_stime_nanoseconds_t; | typedef khronos_int64_t        khronos_stime_nanoseconds_t; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Dummy value used to pad enum types to 32 bits. |  * Dummy value used to pad enum types to 32 bits. | ||||||
|  */ |  */ | ||||||
| #ifndef KHRONOS_MAX_ENUM | #ifndef KHRONOS_MAX_ENUM | ||||||
| #define KHRONOS_MAX_ENUM 0x7FFFFFFF | #define KHRONOS_MAX_ENUM 0x7FFFFFFF | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Enumerated boolean type |  * Enumerated boolean type | ||||||
|  * |  * | ||||||
|  * Values other than zero should be considered to be true.  Therefore |  * Values other than zero should be considered to be true.  Therefore | ||||||
|  * comparisons should not be made against KHRONOS_TRUE. |  * comparisons should not be made against KHRONOS_TRUE. | ||||||
|  */ |  */ | ||||||
| typedef enum { | typedef enum { | ||||||
|     KHRONOS_FALSE = 0, |     KHRONOS_FALSE = 0, | ||||||
|     KHRONOS_TRUE  = 1, |     KHRONOS_TRUE  = 1, | ||||||
|     KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM |     KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM | ||||||
| } khronos_boolean_enum_t; | } khronos_boolean_enum_t; | ||||||
|  |  | ||||||
| #endif /* __khrplatform_h_ */ | #endif /* __khrplatform_h_ */ | ||||||
|   | |||||||
							
								
								
									
										10338
									
								
								backends/desktop/glad/include/glad/glad.h
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										10338
									
								
								backends/desktop/glad/include/glad/glad.h
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										5064
									
								
								backends/desktop/glad/source/glad.c
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										5064
									
								
								backends/desktop/glad/source/glad.c
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							 Submodule backends/desktop/glfw updated: 7b6aead9fb...e7ea71be03
									
								
							| @@ -1,46 +0,0 @@ | |||||||
| #include <glad/glad.h> |  | ||||||
|  |  | ||||||
| /** SEPARATOR */ |  | ||||||
| #include <GLFW/glfw3.h> |  | ||||||
| /** SEPARATOR */ |  | ||||||
| #include <pd/core/core.hpp> |  | ||||||
| #include <pd/lithium/backend.hpp> |  | ||||||
| #include <pd_p_bknd_api.hpp> |  | ||||||
|  |  | ||||||
| namespace PD { |  | ||||||
| namespace LI { |  | ||||||
| class PD_BKND_DESKTOP_API Backend_GL2 : public PD::LI::Backend { |  | ||||||
|  public: |  | ||||||
|   Backend_GL2() : LI::Backend("OpenGL2") {} |  | ||||||
|   ~Backend_GL2() {} |  | ||||||
|  |  | ||||||
|   PD_SMART_CTOR(Backend_GL2) |  | ||||||
|  |  | ||||||
|   void Init() override; |  | ||||||
|   void Deinit() override; |  | ||||||
|   void NewFrame() override; |  | ||||||
|   void BindTexture(PD::LI::TexAddress addr) override; |  | ||||||
|   void RenderDrawData(const PD::Vec<PD::LI::Command::Ref>& Commands) override; |  | ||||||
|   PD::LI::Texture::Ref LoadTexture( |  | ||||||
|       const std::vector<PD::u8>& pixels, int w, int h, |  | ||||||
|       PD::LI::Texture::Type type = PD::LI::Texture::Type::RGBA32, |  | ||||||
|       PD::LI::Texture::Filter filter = |  | ||||||
|           PD::LI::Texture::Filter::LINEAR) override; |  | ||||||
|  |  | ||||||
|  private: |  | ||||||
|   PD::Vec<PD::LI::Vertex> VertexBuffer; |  | ||||||
|   PD::Vec<PD::u16> IndexBuffer; |  | ||||||
|   size_t CurrentVertex = 0; |  | ||||||
|   size_t CurrentIndex = 0; |  | ||||||
|   GLuint Shader; |  | ||||||
|   GLuint pLocProjection; |  | ||||||
|   GLuint pLocTex; |  | ||||||
|   Mat4 Projection; |  | ||||||
|   GLuint VBO, IBO; |  | ||||||
|   // For Stats |  | ||||||
|   PD::u32 num_vtx = 0; |  | ||||||
|   PD::u32 num_idx = 0; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| }  // namespace LI |  | ||||||
| }  // namespace PD |  | ||||||
							
								
								
									
										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); | ||||||
|  | } | ||||||
							
								
								
									
										58
									
								
								include/pd/sound/mp3.hpp → backends/desktop/include/pd-desktop/bknd-gfx.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										58
									
								
								include/pd/sound/mp3.hpp → backends/desktop/include/pd-desktop/bknd-gfx.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -2,7 +2,8 @@ | |||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
| 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 | ||||||
| @@ -23,40 +24,39 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||||||
| SOFTWARE. | SOFTWARE. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <mpg123.h> | #include <glad/glad.h> | ||||||
| 
 | 
 | ||||||
| #include <pd/sound/decoder.hpp> | /** SEPARATOR */ | ||||||
|  | #include <GLFW/glfw3.h> | ||||||
|  | /** SEPARATOR */ | ||||||
|  | 
 | ||||||
|  | #include <pd/lithium/lithium.hpp> | ||||||
| 
 | 
 | ||||||
| namespace PD { | namespace PD { | ||||||
| namespace Music { | class GfxGL2 : public GfxDriver { | ||||||
|   /**
 |  | ||||||
|    * MP3 Decoder |  | ||||||
|    */ |  | ||||||
| class Mp3Decoder : public Decoder { |  | ||||||
|  public: |  public: | ||||||
|   Mp3Decoder() = default; |   GfxGL2() : GfxDriver("OpenGL2") {} | ||||||
|   ~Mp3Decoder() = default; |   ~GfxGL2() = default; | ||||||
| 
 | 
 | ||||||
|   /** Init Funciton to load file and Init decoder */ |   PD_SHARED(GfxGL2); | ||||||
|   int Init(const std::string& path) override; | 
 | ||||||
|   /** Unload Decoder */ |   void Init() override; | ||||||
|   void Deinit() override; |   void Deinit() override; | ||||||
|   /** Get Sample Rate */ |   void NewFrame() override; | ||||||
|   u32 GetSampleRate() override; |   void BindTex(PD::Li::TexAddress addr) override; | ||||||
|   /** Get Channels */ |   void RenderDrawData( | ||||||
|   u8 GetChannels() override; |       const std::vector<PD::Li::Command::Ref>& Commands) override; | ||||||
|   /** Get Buffer Size */ |   PD::Li::Texture::Ref LoadTex( | ||||||
|   size_t GetBufSize() override; |       const std::vector<PD::u8>& pixels, int w, int h, | ||||||
|   /** Decode next data */ |       PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32, | ||||||
|   u64 Decode(u16* buf_address) override; |       PD::Li::Texture::Filter filter = | ||||||
|   /** Get File Samples if exist */ |           PD::Li::Texture::Filter::LINEAR) override; | ||||||
|   size_t GetFileSamples() override; |  | ||||||
| 
 | 
 | ||||||
|  private: |   PD::Vec<Li::Vertex> VertexBuffer; | ||||||
|   mpg123_handle* handle = nullptr; |   PD::Vec<PD::u16> IndexBuffer; | ||||||
|   size_t buf_size = 0; |   GLuint Shader; | ||||||
|   u32 rate = 0; |   GLuint pLocProjection; | ||||||
|   u8 channels = 0; |   GLuint pLocTex; | ||||||
|  |   GLuint VBO, IBO; | ||||||
| }; | }; | ||||||
| }  // namespace Music
 |  | ||||||
| }  // namespace PD
 | }  // namespace PD
 | ||||||
							
								
								
									
										145
									
								
								include/pd/overlays/settings.hpp → backends/desktop/include/pd-desktop/bknd-hid.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										145
									
								
								include/pd/overlays/settings.hpp → backends/desktop/include/pd-desktop/bknd-hid.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,75 +1,72 @@ | |||||||
| #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/core.hpp> | 
 | ||||||
| #include <pd/overlays/overlay.hpp> | #include <GLFW/glfw3.h> | ||||||
| #include <pd/ui7/ui7.hpp> | 
 | ||||||
| 
 | #include <pd/drivers/drivers.hpp> | ||||||
| namespace PD { | 
 | ||||||
| /**
 | namespace PD { | ||||||
|  * Settings Menu Overlay | class HidGLFW : public HidDriver { | ||||||
|  */ |  public: | ||||||
| class SettingsMenu : public Overlay { |   HidGLFW(GLFWwindow* win); | ||||||
|  public: |   ~HidGLFW() = default; | ||||||
|   /**
 | 
 | ||||||
|    * Constructor to setup Overlay |   PD_SHARED(HidGLFW); | ||||||
|    */ | 
 | ||||||
|   SettingsMenu() { |   void Update() override; | ||||||
|     too++; |   void GetInputStr(std::string& str) override; | ||||||
|     if (too > 1) { |   void HandleTextOps(); | ||||||
|       Kill(); |   bool pTimedHeld(KbKey k) { | ||||||
|       return; |     if (pTimings.count(k)) { | ||||||
|     } |       if (IsEvent(Event_Up, k)) { | ||||||
|     flymgr.From(vec2(0, 240)).To(vec2(0, 115)).In(0.3f).As(flymgr.EaseInQuad); |         pTimings.erase(k); | ||||||
|   } |         return false; | ||||||
|   /** Deconstructor */ |       } | ||||||
|   ~SettingsMenu() { too--; } |       return (PD::OS::GetTime() - pTimings[k]) > 50; | ||||||
| 
 |     } | ||||||
|   /** Rendering and Input Handler */ |     if (!IsEvent(Event_Held, k)) { | ||||||
|   void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) override; |       if (pTimings.count(k)) { | ||||||
| 
 |         pTimings.erase(k); | ||||||
|   /**
 |         return false; | ||||||
|    * Function to Trigger remove animation |       } | ||||||
|    */ |     } | ||||||
|   void Rem() { |     if (IsEvent(Event_Held, k)) { | ||||||
|     rem = true; |       pTimings[k] = PD::OS::GetTime(); | ||||||
|     flymgr.From(vec2(0, 115)).To(vec2(0, 240)).In(0.2f).As(flymgr.EaseOutQuad); |       return true; | ||||||
|   } |     } | ||||||
| 
 |     return false; | ||||||
|  private: |   } | ||||||
|   /// Section is used to determinate what
 | 
 | ||||||
|   /// should be displayed on the top screen
 |   /** Data section */ | ||||||
|   int section = 0; |   GLFWwindow* Window; | ||||||
|   // Stands for The Only One
 |   int PrevState; | ||||||
|   static int too; |   std::unordered_map<int, int> PrevStates; | ||||||
| 
 |   static std::string* pText; | ||||||
|   // Some Animation
 |   bool pInTextMode = false; | ||||||
|   bool rem = false; |   PD::u64 pLastUpdate = 0; | ||||||
|   Tween<fvec2> flymgr; |   std::unordered_map<KbKey, u64> pTimings; | ||||||
| 
 | }; | ||||||
|   // Custom UI7 Context
 |  | ||||||
|   UI7::Context::Ref ctx; |  | ||||||
| }; |  | ||||||
| }  // namespace PD
 | }  // namespace PD
 | ||||||
| @@ -1,132 +0,0 @@ | |||||||
| #pragma once |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| MIT License |  | ||||||
| Copyright (c) 2024 - 2025 René Amthor (tobid7) |  | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
| of this software and associated documentation files (the "Software"), to deal |  | ||||||
| in the Software without restriction, including without limitation the rights |  | ||||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
| copies of the Software, and to permit persons to whom the Software is |  | ||||||
| furnished to do so, subject to the following conditions: |  | ||||||
|  |  | ||||||
| The above copyright notice and this permission notice shall be included in all |  | ||||||
| copies or substantial portions of the Software. |  | ||||||
|  |  | ||||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
| SOFTWARE. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| #ifdef _WIN32 |  | ||||||
| #include <winsock2.h> |  | ||||||
| #include <ws2tcpip.h> |  | ||||||
| #ifdef _MSVC |  | ||||||
| #pragma comment(lib, "ws2_32.lib") |  | ||||||
| #endif |  | ||||||
| #else |  | ||||||
| #include <arpa/inet.h> |  | ||||||
| #include <netinet/in.h> |  | ||||||
| #include <sys/socket.h> |  | ||||||
| #include <unistd.h> |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #include <pd/net/backend.hpp> |  | ||||||
| namespace PD { |  | ||||||
| class NetBackendDesktop : public PD::Net::Backend { |  | ||||||
|  public: |  | ||||||
| #ifdef _WIN32 |  | ||||||
|   NetBackendDesktop() : Net::Backend("Desktop (Windows)") { |  | ||||||
| #else |  | ||||||
|   NetBackendDesktop() : Net::Backend("Desktop (Unix)") { |  | ||||||
| #endif |  | ||||||
|   } |  | ||||||
|   ~NetBackendDesktop() = default; |  | ||||||
|   PD_SMART_CTOR(NetBackendDesktop) |  | ||||||
|   bool Init() override { |  | ||||||
| #ifdef _WIN32 |  | ||||||
|     WSADATA wsa_data; |  | ||||||
|     return (WSAStartup(MAKEWORD(2, 2), &wsa_data) == 0); |  | ||||||
| #else |  | ||||||
|     return true; |  | ||||||
| #endif |  | ||||||
|   } |  | ||||||
|   void Deinit() override { |  | ||||||
| #ifdef _WIN32 |  | ||||||
|     WSACleanup(); |  | ||||||
| #endif |  | ||||||
|   } |  | ||||||
|   int NewSocket() override { return socket(AF_INET, SOCK_STREAM, 0); } |  | ||||||
|   void Close(int sock_id) override { |  | ||||||
| #ifdef _WIN32 |  | ||||||
|     closesocket(sock_id); |  | ||||||
| #else |  | ||||||
|     close(sock_id); |  | ||||||
| #endif |  | ||||||
|   } |  | ||||||
|   int GetInvalidRef() const override { |  | ||||||
| #ifdef _WIN32 |  | ||||||
|     return INVALID_SOCKET; |  | ||||||
| #else |  | ||||||
|     return -1; |  | ||||||
| #endif |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   bool Bind(int sock_id, u16 port) override { |  | ||||||
|     sockaddr_in addr{}; |  | ||||||
|     addr.sin_family = AF_INET; |  | ||||||
|     addr.sin_port = htons(port); |  | ||||||
|     addr.sin_addr.s_addr = INADDR_ANY; |  | ||||||
|     return bind(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1; |  | ||||||
|   } |  | ||||||
|   bool Listen(int sock_id, int backlog = 5) override { |  | ||||||
|     return listen(sock_id, backlog) != -1; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   bool WaitForRead(int sock_id, int timeout_ms) override { |  | ||||||
|     fd_set set; |  | ||||||
|     FD_ZERO(&set); |  | ||||||
|     FD_SET(sock_id, &set); |  | ||||||
|  |  | ||||||
|     timeval timeout{}; |  | ||||||
|     timeout.tv_sec = timeout_ms / 1000; |  | ||||||
|     timeout.tv_usec = (timeout_ms % 1000) * 1000; |  | ||||||
|  |  | ||||||
|     int result = select(sock_id + 1, &set, nullptr, nullptr, &timeout); |  | ||||||
|     return (result > 0 && FD_ISSET(sock_id, &set)); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   bool Accept(int sock_id, Net::Socket::Ref client) override { |  | ||||||
|     int client_soc = accept(sock_id, nullptr, nullptr); |  | ||||||
|     if (client_soc == GetInvalidRef()) { |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|     client->pSocket = client_soc; |  | ||||||
|     return true; |  | ||||||
|   } |  | ||||||
|   bool Connect(int sock_id, const std::string& ip, u16 port) override { |  | ||||||
|     sockaddr_in addr{}; |  | ||||||
|     addr.sin_family = AF_INET; |  | ||||||
|     addr.sin_port = htons(port); |  | ||||||
|     inet_pton(AF_INET, ip.c_str(), &addr.sin_addr); |  | ||||||
|     return connect(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1; |  | ||||||
|   } |  | ||||||
|   int Send(int sock_id, const std::string& data) override { |  | ||||||
|     return send(sock_id, data.c_str(), static_cast<int>(data.size()), 0); |  | ||||||
|   } |  | ||||||
|   int Receive(int sock_id, std::string& data, int size = 1024) override { |  | ||||||
|     char* tmp = new char[size]; |  | ||||||
|     int res = recv(sock_id, tmp, size, 0); |  | ||||||
|     if (res > 0) { |  | ||||||
|       data.assign(tmp, res); |  | ||||||
|     } |  | ||||||
|     delete[] tmp; |  | ||||||
|     return res; |  | ||||||
|   } |  | ||||||
| }; |  | ||||||
| }  // namespace PD |  | ||||||
| @@ -1,58 +0,0 @@ | |||||||
| #pragma once |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| MIT License |  | ||||||
|  |  | ||||||
| Copyright (c) 2024 - 2025 tobid7 |  | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
| of this software and associated documentation files (the "Software"), to deal |  | ||||||
| in the Software without restriction, including without limitation the rights |  | ||||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
| copies of the Software, and to permit persons to whom the Software is |  | ||||||
| furnished to do so, subject to the following conditions: |  | ||||||
|  |  | ||||||
| The above copyright notice and this permission notice shall be included in all |  | ||||||
| copies or substantial portions of the Software. |  | ||||||
|  |  | ||||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
| SOFTWARE. |  | ||||||
| */ |  | ||||||
|  |  | ||||||
| #pragma once |  | ||||||
|  |  | ||||||
| #ifdef PD_BKND_DESKTOP_STATIC |  | ||||||
| #if defined(__3DS__)  // 3ds Specific |  | ||||||
| #error "Desktop backend is not supported on the 3ds!" |  | ||||||
| #endif |  | ||||||
| #define PD_BKND_DESKTOP_API |  | ||||||
| #else |  | ||||||
| #ifdef _WIN32  // Windows (MSVC Tested) |  | ||||||
| #ifdef PD_BKND_DESKTOP_BUILD_SHARED |  | ||||||
| #define PD_BKND_DESKTOP_API __declspec(dllexport) |  | ||||||
| #else |  | ||||||
| #define PD_BKND_DESKTOP_API __declspec(dllimport) |  | ||||||
| #endif |  | ||||||
| #elif defined(__APPLE__)  // macOS (untested yet) |  | ||||||
| #ifdef PD_BKND_DESKTOP_BUILD_SHARED |  | ||||||
| #define PD_BKND_DESKTOP_API __attribute__((visibility("default"))) |  | ||||||
| #else |  | ||||||
| #define PD_BKND_DESKTOP_API |  | ||||||
| #endif |  | ||||||
| #elif defined(__linux__)  // Linux (untested yet) |  | ||||||
| #ifdef PD_BKND_DESKTOP_BUILD_SHARED |  | ||||||
| #define PD_BKND_DESKTOP_API __attribute__((visibility("default"))) |  | ||||||
| #else |  | ||||||
| #define PD_BKND_DESKTOP_API |  | ||||||
| #endif |  | ||||||
| #elif defined(__3DS__)  // 3ds Specific |  | ||||||
| #error "Desktop backend is not supported on the 3ds!" |  | ||||||
| #else |  | ||||||
| #define PD_BKND_DESKTOP_API |  | ||||||
| #endif |  | ||||||
| #endif |  | ||||||
							
								
								
									
										148
									
								
								backends/desktop/source/li_backend_gl2.cpp → backends/desktop/source/bknd-gfx.cpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										148
									
								
								backends/desktop/source/li_backend_gl2.cpp → backends/desktop/source/bknd-gfx.cpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,5 +1,30 @@ | |||||||
| #include <li_backend_gl2.hpp> | /*
 | ||||||
|  | MIT License | ||||||
| 
 | 
 | ||||||
|  | Copyright (c) 2024 - 2025 tobid7 | ||||||
|  | 
 | ||||||
|  | Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
|  | of this software and associated documentation files (the "Software"), to deal | ||||||
|  | in the Software without restriction, including without limitation the rights | ||||||
|  | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||
|  | copies of the Software, and to permit persons to whom the Software is | ||||||
|  | furnished to do so, subject to the following conditions: | ||||||
|  | 
 | ||||||
|  | The above copyright notice and this permission notice shall be included in all | ||||||
|  | copies or substantial portions of the Software. | ||||||
|  | 
 | ||||||
|  | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||
|  | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||
|  | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||
|  | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||
|  | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||
|  | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||
|  | SOFTWARE. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | #include <pd-desktop/bknd-gfx.hpp> | ||||||
|  | 
 | ||||||
|  | namespace PD { | ||||||
| const char* vertex_shader = R"( | const char* vertex_shader = R"( | ||||||
|   #version 120 |   #version 120 | ||||||
|    |    | ||||||
| @@ -10,7 +35,7 @@ const char* vertex_shader = R"( | |||||||
|   varying vec2 oUV; |   varying vec2 oUV; | ||||||
|   varying vec4 oColor; |   varying vec4 oColor; | ||||||
|    |    | ||||||
|   // Probably forgot about this matric and
 |   // Probably forgot about this matrix and
 | ||||||
|   // searched hours for why the rendering isn't working :/
 |   // searched hours for why the rendering isn't working :/
 | ||||||
|   uniform mat4 projection; |   uniform mat4 projection; | ||||||
|    |    | ||||||
| @@ -35,8 +60,7 @@ const char* frag_shader = R"( | |||||||
|   } |   } | ||||||
|   )"; |   )"; | ||||||
| 
 | 
 | ||||||
| GLuint compileShader(const std::string& source, | GLuint compileShader(const std::string& source, GLenum type) { | ||||||
|                                          GLenum type) { |  | ||||||
|   GLuint shader = glCreateShader(type); |   GLuint shader = glCreateShader(type); | ||||||
|   const char* src = source.c_str(); |   const char* src = source.c_str(); | ||||||
|   glShaderSource(shader, 1, &src, nullptr); |   glShaderSource(shader, 1, &src, nullptr); | ||||||
| @@ -53,9 +77,8 @@ GLuint compileShader(const std::string& source, | |||||||
|   return shader; |   return shader; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| GLuint | GLuint createShaderProgram(const std::string& vertexShaderSource, | ||||||
| createShaderProgram(const std::string& vertexShaderSource, |                            const std::string& fragmentShaderSource) { | ||||||
|                     const std::string& fragmentShaderSource) { |  | ||||||
|   GLuint vertexShader = compileShader(vertexShaderSource, GL_VERTEX_SHADER); |   GLuint vertexShader = compileShader(vertexShaderSource, GL_VERTEX_SHADER); | ||||||
|   GLuint fragmentShader = |   GLuint fragmentShader = | ||||||
|       compileShader(fragmentShaderSource, GL_FRAGMENT_SHADER); |       compileShader(fragmentShaderSource, GL_FRAGMENT_SHADER); | ||||||
| @@ -79,9 +102,27 @@ createShaderProgram(const std::string& vertexShaderSource, | |||||||
|   return shaderProgram; |   return shaderProgram; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| namespace PD { | void SetupShaderAttribs(GLuint Shader) { | ||||||
| namespace LI { |   GLint _pos = glGetAttribLocation(Shader, "pos"); | ||||||
| PD_BKND_DESKTOP_API void Backend_GL2::Init() { |   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); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** Actual Backend */ | ||||||
|  | 
 | ||||||
|  | void GfxGL2::Init() { | ||||||
|   VertexBuffer.Resize(4 * 8192); |   VertexBuffer.Resize(4 * 8192); | ||||||
|   IndexBuffer.Resize(6 * 8192); |   IndexBuffer.Resize(6 * 8192); | ||||||
|   Shader = createShaderProgram(vertex_shader, frag_shader); |   Shader = createShaderProgram(vertex_shader, frag_shader); | ||||||
| @@ -90,21 +131,8 @@ PD_BKND_DESKTOP_API void Backend_GL2::Init() { | |||||||
|   glGenBuffers(1, &VBO); |   glGenBuffers(1, &VBO); | ||||||
|   glBindBuffer(GL_ARRAY_BUFFER, VBO); |   glBindBuffer(GL_ARRAY_BUFFER, VBO); | ||||||
| 
 | 
 | ||||||
|   GLint _pos = glGetAttribLocation(Shader, "pos"); |   // Attribs Setup
 | ||||||
|   GLint _uv = glGetAttribLocation(Shader, "uv"); |   SetupShaderAttribs(Shader); | ||||||
|   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); |   glGenBuffers(1, &IBO); | ||||||
|   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); |   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); | ||||||
| @@ -116,74 +144,74 @@ PD_BKND_DESKTOP_API void Backend_GL2::Init() { | |||||||
|   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| PD_BKND_DESKTOP_API void Backend_GL2::Deinit() { | void GfxGL2::Deinit() { | ||||||
|   glDeleteBuffers(1, &VBO); |   glDeleteBuffers(1, &VBO); | ||||||
|   glDeleteBuffers(1, &IBO); |   glDeleteBuffers(1, &IBO); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| PD_BKND_DESKTOP_API void Backend_GL2::NewFrame() { | void GfxGL2::NewFrame() { | ||||||
|  |   /*
 | ||||||
|   glViewport(0, 0, ViewPort.x, ViewPort.y); |   glViewport(0, 0, ViewPort.x, ViewPort.y); | ||||||
|   glClearColor(ClearColor.x, ClearColor.y, ClearColor.z, ClearColor.w); |   glClearColor(ClearColor.x, ClearColor.y, ClearColor.z, ClearColor.w); | ||||||
|   glClear(GL_COLOR_BUFFER_BIT); |   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); |   Projection = Mat4::Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, -1.f, 1.f); | ||||||
|  |   glUseProgram(Shader); | ||||||
|  |   glUniformMatrix4fv(pLocProjection, 1, GL_FALSE, Projection.m.data()); | ||||||
|   glEnable(GL_BLEND); |   glEnable(GL_BLEND); | ||||||
|   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||||||
|   CurrentIndex = 0; |  | ||||||
|   CurrentVertex = 0; |  | ||||||
|   FrameCounter++; |   FrameCounter++; | ||||||
|   VertexCounter = num_vtx; |   VertexCounter = CurrentVertex; | ||||||
|   IndexCounter = num_idx; |   IndexCounter = CurrentIndex; | ||||||
|   num_vtx = 0; |   CurrentVertex = 0; | ||||||
|   num_idx = 0; |   CurrentIndex = 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| PD_BKND_DESKTOP_API void Backend_GL2::BindTexture(PD::LI::TexAddress addr) { | void GfxGL2::BindTex(PD::Li::TexAddress addr) { | ||||||
|   // Actually not using the Address as Address
 |   // Actually not using the Address as Address
 | ||||||
|   glActiveTexture(GL_TEXTURE0); |   glActiveTexture(GL_TEXTURE0); | ||||||
|   glBindTexture(GL_TEXTURE_2D, (GLuint)addr); |   glBindTexture(GL_TEXTURE_2D, (GLuint)addr); | ||||||
|   glUniform1i(pLocTex, 0); |   glUniform1i(pLocTex, 0); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| PD_BKND_DESKTOP_API void Backend_GL2::RenderDrawData( | void GfxGL2::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) { | ||||||
|     const PD::Vec<PD::LI::Command::Ref>& Commands) { |  | ||||||
|   glUseProgram(Shader); |  | ||||||
|   size_t index = 0; |   size_t index = 0; | ||||||
|   while (index < Commands.Size()) { |   while (index < Commands.size()) { | ||||||
|     PD::LI::Texture::Ref Tex = Commands[index]->Tex; |     PD::Li::Texture::Ref Tex = Commands[index]->Tex; | ||||||
|     if (!Tex) { |     if (!Tex) { | ||||||
|       index++; |       index++; | ||||||
|       continue; |       continue; | ||||||
|     } |     } | ||||||
|     size_t StartIndex = CurrentIndex; |     size_t StartIndex = CurrentIndex; | ||||||
|     bool ScissorEnabled = Commands[index]->ScissorEnabled; |     bool ScissorOn = Commands[index]->ScissorOn; | ||||||
|     ivec4 ScissorRect = Commands[index]->ScissorRect; |     ivec4 ScissorRect = Commands[index]->ScissorRect; | ||||||
| 
 | 
 | ||||||
|     while (index < Commands.Size() && Commands[index]->Tex == Tex && |     while (index < Commands.size() && Commands[index]->Tex == Tex && | ||||||
|            Commands[index]->ScissorEnabled == ScissorEnabled && |            Commands[index]->ScissorOn == ScissorOn && | ||||||
|            Commands[index]->ScissorRect == ScissorRect) { |            Commands[index]->ScissorRect == ScissorRect) { | ||||||
|       auto c = Commands[index]; |       auto c = Commands[index].get(); | ||||||
|       for (size_t i = 0; i < c->IndexBuffer.Size(); i++) { |       for (size_t i = 0; i < c->IndexBuffer.Size(); i++) { | ||||||
|         num_idx++; |  | ||||||
|         IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i); |         IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i); | ||||||
|       } |       } | ||||||
|       for (size_t i = 0; i < c->VertexBuffer.Size(); i++) { |       for (size_t i = 0; i < c->VertexBuffer.Size(); i++) { | ||||||
|         num_vtx++; |  | ||||||
|         VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i); |         VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i); | ||||||
|       } |       } | ||||||
|       index++; |       index++; | ||||||
|     } |     } | ||||||
|     if (ScissorEnabled) { |     if (ScissorOn) { | ||||||
|       glScissor(ScissorRect.x, ViewPort.y - (ScissorRect.y + ScissorRect.w), |       glScissor(ScissorRect.x, ViewPort.y - (ScissorRect.y + ScissorRect.w), | ||||||
|                 ScissorRect.z, ScissorRect.w); |                 ScissorRect.z, ScissorRect.w); | ||||||
|       glEnable(GL_SCISSOR_TEST); |       glEnable(GL_SCISSOR_TEST); | ||||||
|     } else { |     } else { | ||||||
|       glDisable(GL_SCISSOR_TEST); |       glDisable(GL_SCISSOR_TEST); | ||||||
|     } |     } | ||||||
|     BindTexture(Tex->Address); |     BindTex(Tex->Address); | ||||||
|     glBindBuffer(GL_ARRAY_BUFFER, VBO); |     glBindBuffer(GL_ARRAY_BUFFER, VBO); | ||||||
|     glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::LI::Vertex), |     glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex), | ||||||
|                  &VertexBuffer[0], GL_DYNAMIC_DRAW); |                  &VertexBuffer[0], GL_DYNAMIC_DRAW); | ||||||
|  |     // For some reason we need to set these every frame for every buffer
 | ||||||
|  |     // Found that out when creating My 3d Engine
 | ||||||
|  |     SetupShaderAttribs(Shader); | ||||||
| 
 | 
 | ||||||
|     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); |     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); | ||||||
|     glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(PD::u16), |     glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(PD::u16), | ||||||
| @@ -194,37 +222,35 @@ PD_BKND_DESKTOP_API void Backend_GL2::RenderDrawData( | |||||||
| 
 | 
 | ||||||
|     glBindBuffer(GL_ARRAY_BUFFER, 0); |     glBindBuffer(GL_ARRAY_BUFFER, 0); | ||||||
|     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | ||||||
|     BindTexture(0); |     BindTex(0); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| PD_BKND_DESKTOP_API PD::LI::Texture::Ref Backend_GL2::LoadTexture( | PD::Li::Texture::Ref GfxGL2::LoadTex(const std::vector<PD::u8>& pixels, int w, | ||||||
|     const std::vector<PD::u8>& pixels, int w, int h, PD::LI::Texture::Type type, |                                      int h, PD::Li::Texture::Type type, | ||||||
|     PD::LI::Texture::Filter filter) { |                                      PD::Li::Texture::Filter filter) { | ||||||
|   GLuint texID; |   GLuint texID; | ||||||
|   glGenTextures(1, &texID); |   glGenTextures(1, &texID); | ||||||
|   glBindTexture(GL_TEXTURE_2D, texID); |   glBindTexture(GL_TEXTURE_2D, texID); | ||||||
| 
 | 
 | ||||||
|   // Set base format (Always using RGBA as base)
 |   // Set base format (Always using RGBA as base)
 | ||||||
|   GLenum fmt = GL_RGBA; |   GLenum fmt = GL_RGBA; | ||||||
|   if (type == PD::LI::Texture::Type::RGB24) { |   if (type == PD::Li::Texture::Type::RGB24) { | ||||||
|     fmt = GL_RGB; |     fmt = GL_RGB; | ||||||
|   } else if (type == PD::LI::Texture::Type::A8) { |   } else if (type == PD::Li::Texture::Type::A8) { | ||||||
|     fmt = GL_ALPHA; |     fmt = GL_ALPHA; | ||||||
|   } |   } | ||||||
|   glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE, |   glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE, | ||||||
|                pixels.data()); |                pixels.data()); | ||||||
|   if (filter == PD::LI::Texture::Filter::LINEAR) { |   if (filter == PD::Li::Texture::Filter::LINEAR) { | ||||||
|     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||||||
|     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||||||
|   } else if (filter == PD::LI::Texture::Filter::NEAREST) { |   } else if (filter == PD::Li::Texture::Filter::NEAREST) { | ||||||
|     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||||||
|     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||||||
|   } |   } | ||||||
|   glBindTexture(GL_TEXTURE_2D, 0); |   glBindTexture(GL_TEXTURE_2D, 0); | ||||||
|   auto res = PD::LI::Texture::New(texID, PD::ivec2(w, h)); |   auto res = PD::Li::Texture::New(texID, PD::ivec2(w, h)); | ||||||
|   return res; |   return res; | ||||||
| } | } | ||||||
| 
 |  | ||||||
| }  // namespace LI
 |  | ||||||
| }  // namespace PD
 | }  // namespace PD
 | ||||||
							
								
								
									
										166
									
								
								backends/desktop/source/bknd-hid.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										166
									
								
								backends/desktop/source/bknd-hid.cpp
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,166 @@ | |||||||
|  | /* | ||||||
|  | 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 { | ||||||
|  | std::string* HidGLFW::pText; | ||||||
|  | // Default Call back (If no Text input is requsted) | ||||||
|  | void NullTextCB(GLFWwindow* win, unsigned int c) {} | ||||||
|  | // Text callback if requested | ||||||
|  | void TextCB(GLFWwindow* win, unsigned int c) { | ||||||
|  |   if (!HidGLFW::pText) { | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |   *HidGLFW::pText += (char)c; | ||||||
|  | } | ||||||
|  | HidGLFW::HidGLFW(GLFWwindow* win) : HidDriver("HidGLFW") { | ||||||
|  |   Window = win; | ||||||
|  |   glfwSetCharCallback(Window, NullTextCB); | ||||||
|  |   Flags |= Flags_HasKeyboard; | ||||||
|  |   Flags |= Flags_HasMouse; | ||||||
|  |   pBinds[GLFW_MOUSE_BUTTON_LEFT] = Touch; | ||||||
|  |   /*pBinds[GLFW_KEY_F3] = Kb_3; | ||||||
|  |   pBinds[GLFW_KEY_ESCAPE] = Kb_Escape; | ||||||
|  |   pBinds[GLFW_KEY_F11] = Kb_F11; | ||||||
|  |   pBinds[GLFW_KEY_ESCAPE] = Kb_Escape; | ||||||
|  |   pBinds[GLFW_KEY_Q] = Kb_Q; | ||||||
|  |   pBinds[GLFW_KEY_W] = Kb_W; | ||||||
|  |   pBinds[GLFW_KEY_E] = Kb_E; | ||||||
|  |   pBinds[GLFW_KEY_R] = Kb_R; | ||||||
|  |   pBinds[GLFW_KEY_T] = Kb_T; | ||||||
|  |   pBinds[GLFW_KEY_Z] = Kb_Z; | ||||||
|  |   pBinds[GLFW_KEY_U] = Kb_U; | ||||||
|  |   pBinds[GLFW_KEY_I] = Kb_I; | ||||||
|  |   pBinds[GLFW_KEY_O] = Kb_O; | ||||||
|  |   pBinds[GLFW_KEY_P] = Kb_P; | ||||||
|  |   pBinds[GLFW_KEY_A] = Kb_A; | ||||||
|  |   pBinds[GLFW_KEY_S] = Kb_S; | ||||||
|  |   pBinds[GLFW_KEY_D] = Kb_D; | ||||||
|  |   pBinds[GLFW_KEY_F] = Kb_F; | ||||||
|  |   pBinds[GLFW_KEY_G] = Kb_G; | ||||||
|  |   pBinds[GLFW_KEY_H] = Kb_H; | ||||||
|  |   pBinds[GLFW_KEY_J] = Kb_J; | ||||||
|  |   pBinds[GLFW_KEY_K] = Kb_K; | ||||||
|  |   pBinds[GLFW_KEY_L] = Kb_L; | ||||||
|  |   pBinds[GLFW_KEY_Y] = Kb_Y; | ||||||
|  |   pBinds[GLFW_KEY_X] = Kb_X; | ||||||
|  |   pBinds[GLFW_KEY_C] = Kb_C; | ||||||
|  |   pBinds[GLFW_KEY_V] = Kb_V; | ||||||
|  |   pBinds[GLFW_KEY_B] = Kb_B; | ||||||
|  |   pBinds[GLFW_KEY_N] = Kb_N; | ||||||
|  |   pBinds[GLFW_KEY_M] = Kb_M; | ||||||
|  |   pBinds[GLFW_KEY_LEFT_SHIFT] = Kb_LShift; | ||||||
|  |   pBinds[GLFW_KEY_F1] = Kb_F1; | ||||||
|  |   pBinds[GLFW_KEY_F2] = Kb_F2; | ||||||
|  |   pBinds[GLFW_KEY_F3] = Kb_F3; | ||||||
|  |   pBinds[GLFW_KEY_F4] = Kb_F4; | ||||||
|  |   pBinds[GLFW_KEY_F5] = Kb_F5; | ||||||
|  |   pBinds[GLFW_KEY_F6] = Kb_F6; | ||||||
|  |   pBinds[GLFW_KEY_F7] = Kb_F7; | ||||||
|  |   pBinds[GLFW_KEY_F8] = Kb_F8; | ||||||
|  |   pBinds[GLFW_KEY_F9] = Kb_F9; | ||||||
|  |   pBinds[GLFW_KEY_F10] = Kb_F10; | ||||||
|  |   pBinds[GLFW_KEY_F11] = Kb_F11; | ||||||
|  |   pBinds[GLFW_KEY_F12] = Kb_F12; | ||||||
|  |   pBinds[GLFW_KEY_1] = Kb_1; | ||||||
|  |   pBinds[GLFW_KEY_2] = Kb_2; | ||||||
|  |   pBinds[GLFW_KEY_3] = Kb_3; | ||||||
|  |   pBinds[GLFW_KEY_4] = Kb_4; | ||||||
|  |   pBinds[GLFW_KEY_5] = Kb_5; | ||||||
|  |   pBinds[GLFW_KEY_6] = Kb_6; | ||||||
|  |   pBinds[GLFW_KEY_7] = Kb_7; | ||||||
|  |   pBinds[GLFW_KEY_8] = Kb_8; | ||||||
|  |   pBinds[GLFW_KEY_9] = Kb_9; | ||||||
|  |   pBinds[GLFW_KEY_0] = Kb_0; | ||||||
|  |   pBinds[GLFW_KEY_BACKSPACE] = Kb_Backspace; | ||||||
|  |   pBinds[GLFW_KEY_ENTER] = Kb_Enter;*/ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void HidGLFW::Update() { | ||||||
|  |   // Clear States | ||||||
|  |   for (int i = 0; i < 2; i++) { | ||||||
|  |     KeyEvents[i][Event_Down] = 0; | ||||||
|  |     KeyEvents[i][Event_Held] = 0; | ||||||
|  |     KeyEvents[i][Event_Up] = 0; | ||||||
|  |     for (auto& it : KbKeyEvents[i]) { | ||||||
|  |       it.second = Event_Null; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   // Keyboard Logic | ||||||
|  |   /*for (auto& it : pBinds) { | ||||||
|  |     int kbstate = glfwGetKey(Window, it.first); | ||||||
|  |     if (kbstate == GLFW_PRESS) { | ||||||
|  |       if (PrevStates[it.first] == GLFW_RELEASE) { | ||||||
|  |         KbKeyEvents[0][it.second] = Event_Down; | ||||||
|  |       } | ||||||
|  |       KbKeyEvents[0][it.second] = Event_Held; | ||||||
|  |     } else if (kbstate == GLFW_RELEASE && PrevStates[it.first] == GLFW_PRESS) { | ||||||
|  |       KbKeyEvents[0][it.second] = Event_Up; | ||||||
|  |     } | ||||||
|  |     PrevStates[it.first] = kbstate; | ||||||
|  |   }*/ | ||||||
|  |   // Mouse Logic (Todo: Support all mouse buttons) | ||||||
|  |   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); | ||||||
|  |   if (pInTextMode && (PD::OS::GetTime() - pLastUpdate) > 50) { | ||||||
|  |     pLastUpdate = PD::OS::GetTime(); | ||||||
|  |     HandleTextOps(); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void HidGLFW::GetInputStr(std::string& str) { | ||||||
|  |   pText = &str; | ||||||
|  |   glfwSetCharCallback(Window, TextCB); | ||||||
|  |   pInTextMode = true; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void HidGLFW::HandleTextOps() { | ||||||
|  |   if (!pText) { | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |   /*if (pTimedHeld(Kb_Backspace)) { | ||||||
|  |     if (!pText->empty()) { | ||||||
|  |       pText->pop_back(); | ||||||
|  |     } | ||||||
|  |   } else if (pTimedHeld(Kb_Enter)) { | ||||||
|  |     *pText += '\n'; | ||||||
|  |   }*/ | ||||||
|  | } | ||||||
|  | }  // namespace PD | ||||||
							
								
								
									
										43
									
								
								backends/desktop/source/pd-desktop.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										43
									
								
								backends/desktop/source/pd-desktop.cpp
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,43 @@ | |||||||
|  | /* | ||||||
|  | MIT License | ||||||
|  |  | ||||||
|  | Copyright (c) 2024 - 2025 tobid7 | ||||||
|  |  | ||||||
|  | Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
|  | of this software and associated documentation files (the "Software"), to deal | ||||||
|  | in the Software without restriction, including without limitation the rights | ||||||
|  | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||
|  | copies of the Software, and to permit persons to whom the Software is | ||||||
|  | furnished to do so, subject to the following conditions: | ||||||
|  |  | ||||||
|  | The above copyright notice and this permission notice shall be included in all | ||||||
|  | copies or substantial portions of the Software. | ||||||
|  |  | ||||||
|  | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||
|  | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||
|  | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||
|  | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||
|  | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||
|  | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||
|  | SOFTWARE. | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | #include <palladium> | ||||||
|  | #include <pd-desktop.hpp> | ||||||
|  |  | ||||||
|  | namespace PD { | ||||||
|  | void Init(void* data) { | ||||||
|  |   if (!data) { | ||||||
|  |     std::cout << "[PD-DRIVERS] Error: pd-desktop requires GLFWwindow* " | ||||||
|  |                  "reference as data " | ||||||
|  |                  "input!" | ||||||
|  |               << std::endl; | ||||||
|  |     abort(); | ||||||
|  |   } | ||||||
|  |   // Dekstop Init Stage | ||||||
|  |   // First use default OS Driver | ||||||
|  |   PD::OS::Init(); | ||||||
|  |   PD::Gfx::Init(PD::GfxGL2::New()); | ||||||
|  |   PD::Hid::Init(PD::HidGLFW::New(reinterpret_cast<GLFWwindow*>(data))); | ||||||
|  | } | ||||||
|  | }  // namespace PD | ||||||
| @@ -1,33 +0,0 @@ | |||||||
| #include <pd_hid_glfw.hpp> |  | ||||||
|  |  | ||||||
| namespace PD { |  | ||||||
| PD_BKND_DESKTOP_API HidGLFW::HidGLFW(GLFWwindow* win) : Hid("GLFW") { |  | ||||||
|   Window = win; |  | ||||||
|   binds[GLFW_MOUSE_BUTTON_LEFT] = Touch; |  | ||||||
| } |  | ||||||
| PD_BKND_DESKTOP_API void HidGLFW::Update() { |  | ||||||
|   for (int i = 0; i < 2; i++) { |  | ||||||
|     key_events[i][Event_Down] = 0; |  | ||||||
|     key_events[i][Event_Held] = 0; |  | ||||||
|     key_events[i][Event_Up] = 0; |  | ||||||
|   } |  | ||||||
|   int state = glfwGetMouseButton(Window, GLFW_MOUSE_BUTTON_LEFT); |  | ||||||
|   if (state == GLFW_PRESS) { |  | ||||||
|     if (PrevState == GLFW_RELEASE) { |  | ||||||
|       key_events[0][Event_Down] |= Touch; |  | ||||||
|     } |  | ||||||
|     key_events[0][Event_Held] |= Touch; |  | ||||||
|   } else if (state == GLFW_RELEASE && PrevState == GLFW_PRESS) { |  | ||||||
|     key_events[0][Event_Up] |= Touch; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   PrevState = state; |  | ||||||
|   if (locked) { |  | ||||||
|     SwappyTable(); |  | ||||||
|   } |  | ||||||
|   double x, y; |  | ||||||
|   glfwGetCursorPos(Window, &x, &y); |  | ||||||
|   touch[1] = touch[0];  // Cycle touch pos |  | ||||||
|   touch[0] = fvec2(x, y); |  | ||||||
| } |  | ||||||
| }  // namespace PD |  | ||||||
							
								
								
									
										79
									
								
								cmake/palladium.cmake
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										79
									
								
								cmake/palladium.cmake
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,79 @@ | |||||||
|  | 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} PRIVATE | ||||||
|  |         -D_GNU_SOURCE=1 | ||||||
|  |         -DPALLADIUM_VERSION="${PROJECT_VERSION}" | ||||||
|  |         -DPALLADIUM_GIT_COMMIT="${GIT_SHORT_HASH}" | ||||||
|  |         -DPALLADIUM_GIT_BRANCH="${GIT_BRANCH}" | ||||||
|  |         -DBUILD_CTR=1 | ||||||
|  |     ) | ||||||
|  |     if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS") | ||||||
|  |         target_compile_options(${TARGET_NAME} PRIVATE | ||||||
|  |             -Wno-abi | ||||||
|  |         ) | ||||||
|  |     endif() | ||||||
|  |     ### 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,51 +0,0 @@ | |||||||
| #pragma once |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| MIT License |  | ||||||
|  |  | ||||||
| Copyright (c) 2024 - 2025 tobid7 |  | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
| of this software and associated documentation files (the "Software"), to deal |  | ||||||
| in the Software without restriction, including without limitation the rights |  | ||||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
| copies of the Software, and to permit persons to whom the Software is |  | ||||||
| furnished to do so, subject to the following conditions: |  | ||||||
|  |  | ||||||
| The above copyright notice and this permission notice shall be included in all |  | ||||||
| copies or substantial portions of the Software. |  | ||||||
|  |  | ||||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
| SOFTWARE. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| // Core |  | ||||||
| #include <pd/core/core.hpp> |  | ||||||
| // Image |  | ||||||
| #include <pd/image/image.hpp> |  | ||||||
| #include <pd/image/img_blur.hpp> |  | ||||||
| #include <pd/image/img_convert.hpp> |  | ||||||
| #include <pd/ui7/ui7.hpp> |  | ||||||
| // Net |  | ||||||
| #include <pd/net/backend.hpp> |  | ||||||
| #include <pd/net/socket.hpp> |  | ||||||
|  |  | ||||||
| /// Setup these as non Namespaced access by default |  | ||||||
| #ifndef PD_MATH_NAMESPACED |  | ||||||
| using fvec2 = PD::fvec2; |  | ||||||
| using fvec3 = PD::fvec3; |  | ||||||
| using fvec4 = PD::fvec4; |  | ||||||
| using dvec2 = PD::dvec2; |  | ||||||
| using dvec3 = PD::dvec3; |  | ||||||
| using dvec4 = PD::dvec4; |  | ||||||
| using ivec2 = PD::ivec2; |  | ||||||
| using ivec3 = PD::ivec3; |  | ||||||
| using ivec4 = PD::ivec4; |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| // namespace Palladium = PD; |  | ||||||
							
								
								
									
										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 | ||||||
|  */ |  */ | ||||||
| PD_CORE_API 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 | ||||||
|  */ |  */ | ||||||
| PD_CORE_API u32 GetPow2(u32 v); | PD_CORE_API u32 GetPow2(u32 v); | ||||||
| }  // namespace BitUtil | }  // namespace BitUtil | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										361
									
								
								include/pd/core/color.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										361
									
								
								include/pd/core/color.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,231 +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 PD_CORE_API Color { |    */ | ||||||
|  private: |   constexpr Color(u32 clr) { | ||||||
|   /** Red Value */ |     a = (clr >> 24) & 0xff; | ||||||
|   u8 m_r; |     b = (clr >> 16) & 0xff; | ||||||
|   /** Green Value */ |     g = (clr >> 8) & 0xff; | ||||||
|   u8 m_g; |     r = clr & 0xff; | ||||||
|   /** Blue Value */ |   } | ||||||
|   u8 m_b; |   /** | ||||||
|   /** Alpha Value */ |    * Constructor for 8Bit Input | ||||||
|   u8 m_a; |    * @param r Red Value | ||||||
|  |    * @param g Green Value | ||||||
|  public: |    * @param b Blue Value | ||||||
|   /** |    * @param a Optional Alpha Value (Defaults to 255) | ||||||
|    * Default Constructor (all variables are set to 0) |    */ | ||||||
|    */ |   constexpr Color(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {} | ||||||
|   // Color() : m_r(0), m_g(0), m_b(0), m_a(0) {} |   /** | ||||||
|   constexpr Color() : m_r(0), m_g(0), m_b(0), m_a(0) {} |    * Constructor for float Input | ||||||
|   constexpr ~Color() {} |    * @param r Red Value | ||||||
|   /** |    * @param g Green Value | ||||||
|    * Constructor for 32Bit Color Input |    * @param b Blue Value | ||||||
|    * @param color 32Bit Color value |    * @param a Optional Alpha Value (Defaults to 1.0f) | ||||||
|    */ |    * @note There is no Check if the number is between 0.0 and 1.0 | ||||||
|   constexpr Color(u32 color) { |    */ | ||||||
|     m_a = (color >> 24) & 0xff; |   constexpr Color(float r, float g, float b, float a = 1.f) { | ||||||
|     m_b = (color >> 16) & 0xff; |     r = static_cast<u8>(255.f * r); | ||||||
|     m_g = (color >> 8) & 0xff; |     g = static_cast<u8>(255.f * g); | ||||||
|     m_r = color & 0xff; |     b = static_cast<u8>(255.f * b); | ||||||
|   } |     a = static_cast<u8>(255.f * a); | ||||||
|   /** |   } | ||||||
|    * Constructor for 8Bit Input |   /** | ||||||
|    * @param r Red Value |    * Constructor for Hex Input | ||||||
|    * @param g Green Value |    * @param hex Hex String in `#ffffff` or `#ffffffff` format | ||||||
|    * @param b Blue Value |    */ | ||||||
|    * @param a Optional Alpha Value (Defaults to 255) |   Color(const std::string& hex) { Hex(hex); } | ||||||
|    */ |  | ||||||
|   constexpr Color(int r, int g, int b, int a = 255) { |   /** | ||||||
|     m_r = r; |    * Create Color Object by Hex String | ||||||
|     m_g = g; |    * @param hex Hex String in `#ffffff` or `#ffffffff` format | ||||||
|     m_b = b; |    * @return Color class itself | ||||||
|     m_a = a; |    */ | ||||||
|   } |   Color& Hex(const std::string& hex); | ||||||
|   /** |   /** | ||||||
|    * Constructor for float Input |    * Convert this Color Object to Hex string | ||||||
|    * @param r Red Value |    * @param rgba [default false] sets if 8 or 6 digit color should be returned | ||||||
|    * @param g Green Value |    * @return Color Hex String | ||||||
|    * @param b Blue Value |    */ | ||||||
|    * @param a Optional Alpha Value (Defaults to 1.0f) |   std::string Hex(bool rgba = false) const; | ||||||
|    * @note There is no Check if the number is between 0.0 and 1.0 |  | ||||||
|    */ |   /** | ||||||
|   constexpr Color(float r, float g, float b, float a = 1.f) { |    * Fade from Current to another Color | ||||||
|     m_r = static_cast<u8>(255.f * r); |    * @param color Color to fade to | ||||||
|     m_g = static_cast<u8>(255.f * g); |    * @param p Amount (supports -1.0 to 1.0 for use of sine) | ||||||
|     m_b = static_cast<u8>(255.f * b); |    * @return Class Reference | ||||||
|     m_a = static_cast<u8>(255.f * a); |    */ | ||||||
|   } |   Color& Fade(const Color& color, float p) { | ||||||
|   /** |     a = static_cast<u8>((color.a - a) * ((p + 1.f) / 2)); | ||||||
|    * Constructor for Hex Input |     b = static_cast<u8>((color.b - b) * ((p + 1.f) / 2)); | ||||||
|    * @param hex Hex String in `#ffffff` or `#ffffffff` format |     g = static_cast<u8>((color.g - g) * ((p + 1.f) / 2)); | ||||||
|    */ |     r = static_cast<u8>((color.r - r) * ((p + 1.f) / 2)); | ||||||
|   Color(const std::string& hex) { Hex(hex); } |     return *this; | ||||||
|   /** |   } | ||||||
|    * Unused Deconstructor |  | ||||||
|    */ |   /** | ||||||
|   // ~Color() {} |    * Get 32Bit Color Value | ||||||
|  |    * @return 32Bit Color Value (ABGR iirc) | ||||||
|   /** |    */ | ||||||
|    * Create Color Object by Hex String |   u32 Get() const { return (a << 24) | (b << 16) | (g << 8) | r; } | ||||||
|    * @param hex Hex String in `#ffffff` or `#ffffffff` format |   /** | ||||||
|    * @return Color class itself |    * Get The Luminance of the Color | ||||||
|    */ |    * @return luminance (from 0.0 to 1.0) | ||||||
|   Color& Hex(const std::string& hex); |    */ | ||||||
|   /** |   float Luminance() const { | ||||||
|    * Convert this Color Object to Hex string |     // For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness | ||||||
|    * @param rgba [default false] sets if 8 or 6 digit color should be returned |     return (0.3 * (r / 255.f) + 0.59 * (g / 255.f) + 0.11 * (b / 255.f)); | ||||||
|    * @return Color Hex String |   } | ||||||
|    */ |   /** | ||||||
|   std::string Hex(bool rgba = false) const; |    * Check if the Color is Light or Dark | ||||||
|  |    * @return true if light | ||||||
|   /** |    */ | ||||||
|    * Setter for Red |   bool IsLight() const { return (Luminance() >= 0.5); } | ||||||
|    * @param v value |  | ||||||
|    * @return Color class reference |   /** | ||||||
|    */ |    * Operator to cast Color to 32Bit Value | ||||||
|   Color& r(u8 v) { |    * @return 32Bit Color Value | ||||||
|     m_r = v; |    */ | ||||||
|     return *this; |   operator u32() const { return Get(); } | ||||||
|   } |  | ||||||
|   /** |   /** Public Access Data section */ | ||||||
|    * Getter for Red |   u8 r; | ||||||
|    * @return Red Value |   u8 g; | ||||||
|    */ |   u8 b; | ||||||
|   u8 r() const { return m_r; } |   u8 a; | ||||||
|   /** | }; | ||||||
|    * Setter for Green |  | ||||||
|    * @param v value |  | ||||||
|    * @return Color class reference |  | ||||||
|    */ |  | ||||||
|   Color& g(u8 v) { |  | ||||||
|     m_g = v; |  | ||||||
|     return *this; |  | ||||||
|   } |  | ||||||
|   /** |  | ||||||
|    * Getter for Green |  | ||||||
|    * @return Green Value |  | ||||||
|    */ |  | ||||||
|   u8 g() const { return m_r; } |  | ||||||
|   /** |  | ||||||
|    * Setter for Blue |  | ||||||
|    * @param v value |  | ||||||
|    * @return Color class reference |  | ||||||
|    */ |  | ||||||
|   Color& b(u8 v) { |  | ||||||
|     m_b = v; |  | ||||||
|     return *this; |  | ||||||
|   } |  | ||||||
|   /** |  | ||||||
|    * Getter for Blue |  | ||||||
|    * @return Blue Value |  | ||||||
|    */ |  | ||||||
|   u8 b() const { return m_r; } |  | ||||||
|   /** |  | ||||||
|    * Setter for Alpha |  | ||||||
|    * @param v value |  | ||||||
|    * @return Color class reference |  | ||||||
|    */ |  | ||||||
|   Color& a(u8 v) { |  | ||||||
|     m_a = v; |  | ||||||
|     return *this; |  | ||||||
|   } |  | ||||||
|   /** |  | ||||||
|    * Getter for Alpha |  | ||||||
|    * @return Alpha Value |  | ||||||
|    */ |  | ||||||
|   u8 a() const { return m_r; } |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Fade from Current to another Color |  | ||||||
|    * @param color Color to fade to |  | ||||||
|    * @param p Amount (supports -1.0 to 1.0 for use of sine) |  | ||||||
|    * @return Class Reference |  | ||||||
|    */ |  | ||||||
|   Color& Fade(const Color& color, float p) { |  | ||||||
|     m_a = static_cast<u8>((color.a() - m_a) * ((p + 1.f) / 2)); |  | ||||||
|     m_b = static_cast<u8>((color.b() - m_b) * ((p + 1.f) / 2)); |  | ||||||
|     m_g = static_cast<u8>((color.g() - m_g) * ((p + 1.f) / 2)); |  | ||||||
|     m_r = static_cast<u8>((color.r() - m_r) * ((p + 1.f) / 2)); |  | ||||||
|     return *this; |  | ||||||
|   } |  | ||||||
|   /** |  | ||||||
|    * Get 32Bit Color Value |  | ||||||
|    * @return 32Bit Color Value |  | ||||||
|    */ |  | ||||||
|   u32 Get() const { return (m_a << 24) | (m_b << 16) | (m_g << 8) | m_r; } |  | ||||||
|   /** |  | ||||||
|    * Get The Luminance of the Color |  | ||||||
|    * @return luminance (from 0.0 to 1.0) |  | ||||||
|    */ |  | ||||||
|   float Luminance() const { |  | ||||||
|     // For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness |  | ||||||
|     return (0.3 * (m_r / 255.f) + 0.59 * (m_g / 255.f) + 0.11 * (m_b / 255.f)); |  | ||||||
|   } |  | ||||||
|   /** |  | ||||||
|    * Check if the Color is Light or Dark |  | ||||||
|    * @return true if light |  | ||||||
|    */ |  | ||||||
|   bool IsLight() const { return (Luminance() >= 0.5); } |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Operator to cast Color to 32Bit Value |  | ||||||
|    * @return 32Bit Color Value |  | ||||||
|    */ |  | ||||||
|   operator u32() const { return Get(); } |  | ||||||
| }; |  | ||||||
| namespace Colors { |  | ||||||
| constexpr Color White = Color(1.f, 1.f, 1.f, 1.f); |  | ||||||
| constexpr Color Black = Color(0.f, 0.f, 0.f, 1.f); |  | ||||||
| constexpr Color Red = Color(1.f, 0.f, 0.f, 1.f); |  | ||||||
| constexpr Color Green = Color(0.f, 1.f, 0.f, 1.f); |  | ||||||
| constexpr Color Blue = Color(0.f, 0.f, 1.f, 1.f); |  | ||||||
| constexpr Color Yellow = Color(1.f, 1.f, 0.f, 1.f); |  | ||||||
| constexpr Color Cyan = Color(0.f, 1.f, 1.f, 1.f); |  | ||||||
| constexpr Color Magenta = Color(1.f, 0.f, 1.f, 1.f); |  | ||||||
| constexpr Color Gray = Color(0.5f, 0.5f, 0.5f, 1.f); |  | ||||||
| constexpr Color LightGray = Color(0.75f, 0.75f, 0.75f, 1.f); |  | ||||||
| constexpr Color DarkGray = Color(0.25f, 0.25f, 0.25f, 1.f); |  | ||||||
| constexpr Color Orange = Color(1.f, 0.65f, 0.f, 1.f); |  | ||||||
| constexpr Color Pink = Color(1.f, 0.75f, 0.8f, 1.f); |  | ||||||
| constexpr Color Brown = Color(0.6f, 0.4f, 0.2f, 1.f); |  | ||||||
| constexpr Color Purple = Color(0.5f, 0.f, 0.5f, 1.f); |  | ||||||
| constexpr Color Teal = Color(0.f, 0.5f, 0.5f, 1.f); |  | ||||||
| constexpr Color Transparent = Color(0.f, 0.f, 0.f, 0.f); |  | ||||||
| }  // namespace Colors |  | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										199
									
								
								include/pd/core/common.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										199
									
								
								include/pd/core/common.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,131 +1,70 @@ | |||||||
| #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 <array> | ||||||
| #include <cinttypes> | #include <chrono> | ||||||
| #include <cmath> | #include <cinttypes> | ||||||
| #include <filesystem>  // Requires C++ 17 or later | #include <cmath> | ||||||
| #include <format>      // Requires C++ 20 or later | #include <filesystem>  // Requires C++ 17 or later | ||||||
| #include <fstream> | #include <format>      // Requires C++ 20 or later | ||||||
| #include <functional> | #include <fstream> | ||||||
| #include <iostream> | #include <functional> | ||||||
| #include <map> | #include <iostream> | ||||||
| #include <memory> | #include <map> | ||||||
| #include <sstream> | #include <memory> | ||||||
| #include <stack> | #include <numbers> | ||||||
| #include <string> | #include <sstream> | ||||||
| #include <vector> | #include <stack> | ||||||
|  | #include <string> | ||||||
| // Platform API | #include <vector> | ||||||
| #include <pd/core/pd_p_api.hpp> |  | ||||||
|  | /** Dynamic Lib loading */ | ||||||
| // Legacy Smart Pointer | #include <pd/core/pd_p_api.hpp> | ||||||
| #define PD_SMART_CTOR(x)                                      \ |  | ||||||
|   using Ref = std::shared_ptr<x>;                             \ | /** Memory Management */ | ||||||
|   template <typename... args>                                 \ |  | ||||||
|   static Ref New(args&&... cargs) {                           \ | #define PD_SHARED(x)                                         \ | ||||||
|     return std::make_shared<x>(std::forward<args>(cargs)...); \ |   using Ref = std::shared_ptr<x>;                            \ | ||||||
|   } |   template <typename... Args>                                \ | ||||||
|  |   static Ref New(Args&&... args) {                           \ | ||||||
| namespace PD { |     return std::make_shared<x>(std::forward<Args>(args)...); \ | ||||||
| /** |   } | ||||||
|  * SmartCtor (std::shared_ptr) Template class for Smart Pointers |  | ||||||
|  * | #define PD_UNIQUE(x)                                         \ | ||||||
|  * - Just add : public PD::SmartCtor<YourClass> to your class |   using Ref = std::unique_ptr<x>;                            \ | ||||||
|  * @tparam T Your Class |   template <typename... Args>                                \ | ||||||
|  */ |   static Ref New(Args&&... args) {                           \ | ||||||
| template <typename T> |     return std::make_unique<x>(std::forward<Args>(args)...); \ | ||||||
| class SmartCtor { |   } | ||||||
|  public: |  | ||||||
|   /** Reference alias for std::shared_ptr<Type> */ | #define PD_BIT(x) (1 << x) | ||||||
|   using Ref = std::shared_ptr<T>; |  | ||||||
|  | namespace PD { | ||||||
|   /** | /** Types */ | ||||||
|    * static Function to Create a New Reference | using u8 = unsigned char; | ||||||
|    * @param args Additional Arguments (Depends on your classes Constructors) | using u16 = unsigned short; | ||||||
|    * @return New Reference Object | using u32 = unsigned int; | ||||||
|    */ | using u64 = unsigned long long; | ||||||
|   template <typename... Args> |  | ||||||
|   static Ref New(Args&&... args) { |  | ||||||
|     return std::make_shared<T>(std::forward<Args>(args)...); |  | ||||||
|   } |  | ||||||
| }; |  | ||||||
| /** |  | ||||||
|  * Wrapper for SmartCtor<Type>::New(Args) |  | ||||||
|  * @tparam T Class Type |  | ||||||
|  * @param args Arguments |  | ||||||
|  * @return Type Reference (SmartPointer) |  | ||||||
|  */ |  | ||||||
| template <typename T, typename... Args> |  | ||||||
| SmartCtor<T>::Ref New(Args&&... args) { |  | ||||||
|   return SmartCtor<T>::New(std::forward<Args>(args)...); |  | ||||||
| } |  | ||||||
| // Defines |  | ||||||
|  |  | ||||||
| /** alias for 64 Bit unsigned integer */ |  | ||||||
| using u64 = unsigned long long; |  | ||||||
| /** alias for 32 Bit unsigned integer */ |  | ||||||
| using u32 = unsigned int; |  | ||||||
| /** alias for 16 Bit unsigned integer */ |  | ||||||
| using u16 = unsigned short; |  | ||||||
| /** alias for 8 Bit unsigned integer */ |  | ||||||
| using u8 = unsigned char; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * LinInfo Compile Information |  | ||||||
|  */ |  | ||||||
| namespace LibInfo { |  | ||||||
| /** |  | ||||||
|  * Get the Compiler Name and Version the lib got Compiled with |  | ||||||
|  * @return Compiler Name / Version |  | ||||||
|  */ |  | ||||||
| PD_CORE_API const std::string CompiledWith(); |  | ||||||
| /** |  | ||||||
|  * Get the C++ Version used to compile the lib |  | ||||||
|  * @return C++ Version (__cplusplus) |  | ||||||
|  */ |  | ||||||
| PD_CORE_API const std::string CxxVersion(); |  | ||||||
| /** |  | ||||||
|  * Get the Buildtime of the Library |  | ||||||
|  * @return Build Time |  | ||||||
|  */ |  | ||||||
| PD_CORE_API const std::string BuildTime(); |  | ||||||
| /** |  | ||||||
|  * Get the Library Version |  | ||||||
|  * @return Library Version String |  | ||||||
|  */ |  | ||||||
| PD_CORE_API const std::string Version(); |  | ||||||
| /** |  | ||||||
|  * Get the Git Commit the Lib got compiled in |  | ||||||
|  * @return Git Commit 7digit short hash |  | ||||||
|  */ |  | ||||||
| PD_CORE_API const std::string Commit(); |  | ||||||
| /** |  | ||||||
|  * Get the Git Branch which was active when compiling the lib |  | ||||||
|  * @return Git Branch |  | ||||||
|  */ |  | ||||||
| PD_CORE_API const std::string Branch(); |  | ||||||
| }  // namespace LibInfo |  | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										8
									
								
								include/pd/core/core.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										8
									
								
								include/pd/core/core.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -2,8 +2,7 @@ | |||||||
|  |  | ||||||
| /* | /* | ||||||
| MIT License | 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 | ||||||
| @@ -22,17 +21,14 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 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/bit_util.hpp> | #include <pd/core/bit_util.hpp> | ||||||
| #include <pd/core/color.hpp> | #include <pd/core/color.hpp> | ||||||
| #include <pd/core/common.hpp> |  | ||||||
| #include <pd/core/hid_driver.hpp> |  | ||||||
| #include <pd/core/io.hpp> | #include <pd/core/io.hpp> | ||||||
| #include <pd/core/mat.hpp> | #include <pd/core/mat.hpp> | ||||||
| #include <pd/core/sl/sl.hpp> | #include <pd/core/sl/sl.hpp> | ||||||
| #include <pd/core/strings.hpp> | #include <pd/core/strings.hpp> | ||||||
| #include <pd/core/sys.hpp> |  | ||||||
| #include <pd/core/timer.hpp> | #include <pd/core/timer.hpp> | ||||||
| #include <pd/core/timetrace.hpp> | #include <pd/core/timetrace.hpp> | ||||||
| #include <pd/core/tween.hpp> | #include <pd/core/tween.hpp> | ||||||
|   | |||||||
| @@ -1,54 +1,55 @@ | |||||||
| #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> | // This file is based on fvec4
 | ||||||
| 
 | 
 | ||||||
| namespace PD { | #include <pd/core/common.hpp> | ||||||
| namespace Music { | #include <pd/core/vec4.hpp> | ||||||
| /**
 | 
 | ||||||
|  * Decoder Template class | namespace PD { | ||||||
|  */ | class fquat : public fvec4 { | ||||||
| class Decoder : public SmartCtor<Decoder> { |   constexpr fquat() : fvec4(0.f, 0.f, 0.f, 1.f) {} | ||||||
|  public: |   constexpr fquat(float x, float y, float z, float w) : fvec4(x, y, z, w) {} | ||||||
|   Decoder() = default; |   constexpr fquat(const fvec4& v) : fvec4(v) {} | ||||||
|   virtual ~Decoder() = default; | 
 | ||||||
| 
 |   static fquat Identity() { return fquat(0.f, 0.f, 0.f, 1.f); } | ||||||
|   /** Template Init function */ | 
 | ||||||
|   virtual int Init(const std::string& path) = 0; |   constexpr fquat Conjugate() const { return fquat(-x, -y, -z, w); } | ||||||
|   /** Template deinit function */ |   fquat Inverse() const { | ||||||
|   virtual void Deinit() = 0; |     float len = SqLen(); | ||||||
|   /** Template function to get sample rate */ |     if (len == 0.0f) { | ||||||
|   virtual u32 GetSampleRate() = 0; |       return fquat(); | ||||||
|   /** template function to get number of channels */ |     } | ||||||
|   virtual u8 GetChannels() = 0; |     return Conjugate() / len; | ||||||
|   /** template function to get buffer size */ |   } | ||||||
|   virtual size_t GetBufSize() = 0; | 
 | ||||||
|   /** template decode function */ |   fquat operator*(const fquat& v) const { | ||||||
|   virtual u64 Decode(u16* buf_address) = 0; |     return fquat(w * v.x + x * v.w + y * v.z - z * v.y, | ||||||
|   /** template function to get file sanples if exist */ |                  w * v.y - x * v.z + y * v.w + z * v.x, | ||||||
|   virtual size_t GetFileSamples() = 0; |                  w * v.z + x * v.y - y * v.x + z * v.w, | ||||||
| }; |                  w * v.w - x * v.x - y * v.y - z * v.z); | ||||||
| }  // namespace Music
 |   } | ||||||
|  | }; | ||||||
| }  // namespace PD
 | }  // namespace PD
 | ||||||
| @@ -1,175 +0,0 @@ | |||||||
| #pragma once |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| MIT License |  | ||||||
| Copyright (c) 2024 - 2025 René Amthor (tobid7) |  | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
| of this software and associated documentation files (the "Software"), to deal |  | ||||||
| in the Software without restriction, including without limitation the rights |  | ||||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
| copies of the Software, and to permit persons to whom the Software is |  | ||||||
| furnished to do so, subject to the following conditions: |  | ||||||
|  |  | ||||||
| The above copyright notice and this permission notice shall be included in all |  | ||||||
| copies or substantial portions of the Software. |  | ||||||
|  |  | ||||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
| SOFTWARE. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| #include <pd/core/common.hpp> |  | ||||||
| #include <pd/core/vec.hpp> |  | ||||||
|  |  | ||||||
| namespace PD { |  | ||||||
| /** Input Driver Template class */ |  | ||||||
| class PD_CORE_API Hid : public SmartCtor<Hid> { |  | ||||||
|  public: |  | ||||||
|   /** Key [Controller] */ |  | ||||||
|   enum Key : u32 { |  | ||||||
|     No = 0,                    ///< No Key |  | ||||||
|     A = 1 << 0,                ///< A |  | ||||||
|     B = 1 << 1,                ///< B |  | ||||||
|     X = 1 << 2,                ///< X |  | ||||||
|     Y = 1 << 3,                ///< Y |  | ||||||
|     Start = 1 << 4,            ///< Start |  | ||||||
|     Select = 1 << 5,           ///< Select |  | ||||||
|     L = 1 << 6,                ///< L |  | ||||||
|     R = 1 << 7,                ///< R |  | ||||||
|     DUp = 1 << 8,              ///< Dpad Up |  | ||||||
|     DDown = 1 << 9,            ///< Dpad down |  | ||||||
|     DLeft = 1 << 10,           ///< Dpad left |  | ||||||
|     DRight = 1 << 11,          ///< Dpad right |  | ||||||
|     CPUp = 1 << 12,            ///< Cpad up |  | ||||||
|     CPDown = 1 << 13,          ///< cpad down |  | ||||||
|     CPLeft = 1 << 14,          ///< cpad left |  | ||||||
|     CPRight = 1 << 15,         ///< Cpad right |  | ||||||
|     CSUp = 1 << 16,            ///< Cstick up |  | ||||||
|     CSDown = 1 << 17,          ///< cstick down |  | ||||||
|     CSLeft = 1 << 18,          ///< cstick left |  | ||||||
|     CSRight = 1 << 19,         ///< cstick right |  | ||||||
|     ZL = 1 << 20,              ///< ZL |  | ||||||
|     ZR = 1 << 21,              ///< ZR |  | ||||||
|     Touch = 1 << 22,           ///< Touch |  | ||||||
|     Up = DUp | CPUp,           ///< DPad or CPad Up |  | ||||||
|     Down = DDown | CPDown,     ///< DPad or CPad Down |  | ||||||
|     Left = DLeft | CPLeft,     ///< DPad or CPad Left |  | ||||||
|     Right = DRight | CPRight,  ///< DPad or CPad Right |  | ||||||
|   }; |  | ||||||
|   /** Event */ |  | ||||||
|   enum Event { |  | ||||||
|     Event_Down,  ///< Key Pressed |  | ||||||
|     Event_Held,  ///< Key Held |  | ||||||
|     Event_Up,    ///< Key released |  | ||||||
|   }; |  | ||||||
|   Hid(const std::string& name = "NullBackend") : pName(name) {} |  | ||||||
|   ~Hid() = default; |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Get TOuch Position |  | ||||||
|    * @return touch pos |  | ||||||
|    */ |  | ||||||
|   fvec2 TouchPos() const { return touch[0]; } |  | ||||||
|   /** |  | ||||||
|    * Get Last Touch Position (from last frame) |  | ||||||
|    * @return touch pos |  | ||||||
|    */ |  | ||||||
|   fvec2 TouchPosLast() const { return touch[1]; } |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Check for a Button Event |  | ||||||
|    * @param e Event Type |  | ||||||
|    * @param keys Keys to check for |  | ||||||
|    * @return if key(s) doing the requiested event |  | ||||||
|    */ |  | ||||||
|   bool IsEvent(Event e, Key keys); |  | ||||||
|   /** |  | ||||||
|    * Check for Key Press Event |  | ||||||
|    * @param keys set of keys |  | ||||||
|    * @return true if key is pressed |  | ||||||
|    */ |  | ||||||
|   bool IsDown(Key keys) const { return key_events[0].at(Event_Down) & keys; } |  | ||||||
|   /** |  | ||||||
|    * Check for Key Held Event |  | ||||||
|    * @param keys set of keys |  | ||||||
|    * @return true if key is held |  | ||||||
|    */ |  | ||||||
|   bool IsHeld(Key keys) const { return key_events[0].at(Event_Held) & keys; } |  | ||||||
|   /** |  | ||||||
|    * Check for Key Release Event |  | ||||||
|    * @param keys set of keys |  | ||||||
|    * @return true if key is released |  | ||||||
|    */ |  | ||||||
|   bool IsUp(Key keys) const { return key_events[0].at(Event_Up) & keys; } |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Sett all keyevents to 0 |  | ||||||
|    */ |  | ||||||
|   void Clear() { |  | ||||||
|     for (int i = 0; i < 2; i++) { |  | ||||||
|       key_events[i][Event_Down] = 0; |  | ||||||
|       key_events[i][Event_Up] = 0; |  | ||||||
|       key_events[i][Event_Held] = 0; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Lock input driver |  | ||||||
|    * @param v lock or not lock |  | ||||||
|    */ |  | ||||||
|   void Lock(bool v) { |  | ||||||
|     if (v != locked) { |  | ||||||
|       SwappyTable(); |  | ||||||
|     } |  | ||||||
|     locked = v; |  | ||||||
|   } |  | ||||||
|   /** |  | ||||||
|    * Check if Driver is locked |  | ||||||
|    * @return true if locked |  | ||||||
|    */ |  | ||||||
|   bool Locked() const { return locked; } |  | ||||||
|   /** |  | ||||||
|    * Lock Input Driver |  | ||||||
|    */ |  | ||||||
|   void Lock() { |  | ||||||
|     if (!locked) { |  | ||||||
|       SwappyTable(); |  | ||||||
|     } |  | ||||||
|     locked = true; |  | ||||||
|   } |  | ||||||
|   /** |  | ||||||
|    * Unlock Input Driver |  | ||||||
|    */ |  | ||||||
|   void Unlock() { |  | ||||||
|     if (locked) { |  | ||||||
|       SwappyTable(); |  | ||||||
|     } |  | ||||||
|     locked = false; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Template Update Function for a device specific driver |  | ||||||
|    */ |  | ||||||
|   virtual void Update() {} |  | ||||||
|  |  | ||||||
|   /** Backend Identification Name */ |  | ||||||
|   const std::string pName; |  | ||||||
|  |  | ||||||
|  protected: |  | ||||||
|   /** Key binds map */ |  | ||||||
|   std::unordered_map<u32, u32> binds; |  | ||||||
|   /** Function to swap around the Table */ |  | ||||||
|   void SwappyTable(); |  | ||||||
|   /** Using 2 Touch positions for current and last frame */ |  | ||||||
|   fvec2 touch[2]; |  | ||||||
|   /** locked state */ |  | ||||||
|   bool locked = false; |  | ||||||
|   /** Key event tables */ |  | ||||||
|   std::unordered_map<Event, u32> key_events[2]; |  | ||||||
| }; |  | ||||||
| }  // namespace PD |  | ||||||
							
								
								
									
										106
									
								
								include/pd/core/io.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										106
									
								
								include/pd/core/io.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,46 +1,62 @@ | |||||||
| #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 | ||||||
|  */ |  */ | ||||||
| PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path); | PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path); | ||||||
| /** | /** | ||||||
|  * Hash a 8Bit Memory Buffer |  * Load a File into a std::string | ||||||
|  * @param data 8Bit input Buffer |  * @param path Path to the File | ||||||
|  * @return 32Bit Hash |  * @return std::string file content | ||||||
|  */ |  */ | ||||||
| PD_CORE_API u32 HashMemory(const std::vector<u8>& data); | PD_CORE_API std::string LoadFile2Str(const std::string& path); | ||||||
| }  // namespace IO | /** | ||||||
|  |  * Hash a 8Bit Memory Buffer | ||||||
|  |  * @param data 8Bit input Buffer | ||||||
|  |  * @return 32Bit Hash | ||||||
|  |  */ | ||||||
|  | PD_CORE_API u32 HashMemory(const std::vector<u8>& data); | ||||||
|  | /** | ||||||
|  |  * Function to decrompress RLE buffer | ||||||
|  |  * @param data Data buffer to decompress | ||||||
|  |  */ | ||||||
|  | PD_CORE_API void DecompressRLE(std::vector<u8>& data); | ||||||
|  | /** | ||||||
|  |  * Function to compress data with RLE Algorithm | ||||||
|  |  * @param data Data buf | ||||||
|  |  */ | ||||||
|  | PD_CORE_API void CompressRLE(std::vector<u8>& data); | ||||||
|  | }  // namespace IO | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										117
									
								
								include/pd/core/mat.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										117
									
								
								include/pd/core/mat.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -25,17 +25,118 @@ SOFTWARE. | |||||||
| */ | */ | ||||||
|  |  | ||||||
| #include <pd/core/common.hpp> | #include <pd/core/common.hpp> | ||||||
|  | #include <pd/core/vec3.hpp> | ||||||
|  |  | ||||||
| namespace PD { | namespace PD { | ||||||
| class PD_CORE_API Mat4 { | namespace Numbers { | ||||||
|  public: | constexpr float Tau = std::numbers::pi * 2.f; | ||||||
|   Mat4() { Zeros(); } | } | ||||||
|   ~Mat4() = default; | constexpr float Radians(float v) { return v * (Numbers::Tau / 360.0f); } | ||||||
|  | /** | ||||||
|  |  * Minimal Mtx4 Lib that precomputes | ||||||
|  |  * basic stuff stuff at compiletime | ||||||
|  |  * | ||||||
|  |  * This Lib includes Patches for work with Citro3D as well | ||||||
|  |  * | ||||||
|  |  * @note That this is not a full Matrix Library | ||||||
|  |  */ | ||||||
|  |  | ||||||
|   void Zeros(); | struct PD_CORE_API Mat4 { | ||||||
|   void Ortho(float left, float right, float bottom, float top, float near, |   std::array<float, 16> m; | ||||||
|              float far); |   constexpr Mat4() : m{} {} | ||||||
|  |   constexpr static Mat4 Diagonal(float x, float y, float z, float w) { | ||||||
|  |     Mat4 ret; | ||||||
|  |     ret(0, 0) = x; | ||||||
|  |     ret(1, 1) = y; | ||||||
|  |     ret(2, 2) = z; | ||||||
|  |     ret(3, 3) = w; | ||||||
|  |     return ret; | ||||||
|  |   } | ||||||
|  |   constexpr static Mat4 Identity() { return Diagonal(1, 1, 1, 1); } | ||||||
|  |  | ||||||
|   float m[16]; |   constexpr float* Ptr() { return m.data(); } | ||||||
|  |   constexpr const float* Ptr() const { return m.data(); } | ||||||
|  |  | ||||||
|  |   constexpr float& operator()(int row, int col) { | ||||||
|  | #ifdef __3DS__ | ||||||
|  |     // 3ds is full reverse order iirc | ||||||
|  |     return m[row * 4 + (3 - col)]; | ||||||
|  | #else | ||||||
|  |     return m[col * 4 + row]; | ||||||
|  | #endif | ||||||
|  |   } | ||||||
|  |   constexpr float operator()(int row, int col) const { | ||||||
|  | #ifdef __3DS__ | ||||||
|  |     // 3ds is full reverse order iirc | ||||||
|  |     return m[row * 4 + (3 - col)]; | ||||||
|  | #else | ||||||
|  |     return m[col * 4 + row]; | ||||||
|  | #endif | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   constexpr Mat4 operator*(const Mat4& v) const { | ||||||
|  |     Mat4 ret; | ||||||
|  |     for (int i = 0; i < 4; i++) { | ||||||
|  |       for (int j = 0; j < 4; j++) { | ||||||
|  |         float t = 0.f; | ||||||
|  |         for (int k = 0; k < 4; k++) { | ||||||
|  |           t += (*this)(i, k) * v(k, j); | ||||||
|  |         } | ||||||
|  |         ret(i, j) = t; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     return ret; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   constexpr Mat4& operator*=(const Mat4& v) { | ||||||
|  |     *this = *this * v; | ||||||
|  |     return *this; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   constexpr static Mat4 Translate(float x, float y, float z) { | ||||||
|  |     Mat4 ret = Identity(); | ||||||
|  |     ret(0, 3) = x; | ||||||
|  |     ret(1, 3) = y; | ||||||
|  |     ret(2, 3) = z; | ||||||
|  |     return ret; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   constexpr static Mat4 Scale(float x, float y, float z) { | ||||||
|  |     Mat4 ret; | ||||||
|  |     ret(0, 0) = x; | ||||||
|  |     ret(1, 1) = y; | ||||||
|  |     ret(2, 2) = z; | ||||||
|  |     ret(3, 3) = 1.f; | ||||||
|  |     return ret; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   constexpr static Mat4 Ortho(float l, float r, float b, float t, float n, | ||||||
|  |                               float f) { | ||||||
|  |     Mat4 ret; | ||||||
|  | #ifdef __3DS__  // Patch to rotate the Matrix correctly | ||||||
|  |     ret(0, 1) = 2.f / (t - b); | ||||||
|  |     ret(0, 3) = (b + t) / (b - t); | ||||||
|  |     ret(1, 0) = 2.f / (l - r); | ||||||
|  |     ret(1, 3) = (l + r) / (r - l); | ||||||
|  |     ret(2, 2) = 1.f / (n - f); | ||||||
|  |     ret(2, 3) = 0.5f * (n + f) / (n - f) - 0.5f; | ||||||
|  | #else | ||||||
|  |     ret(0, 0) = 2.0f / (r - l); | ||||||
|  |     ret(0, 3) = -(r + l) / (r - l); | ||||||
|  |     ret(1, 1) = 2.0f / (t - b); | ||||||
|  |     ret(1, 3) = -(t + b) / (t - b); | ||||||
|  |     ret(2, 2) = -2.0f / (f - n); | ||||||
|  |     ret(2, 3) = -(f + n) / (f - n); | ||||||
|  | #endif | ||||||
|  |     ret(3, 3) = 1.f; | ||||||
|  |     return ret; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   static Mat4 Rotate(fvec3 axis, float a); | ||||||
|  |   static Mat4 RotateX(float a); | ||||||
|  |   static Mat4 RotateY(float a); | ||||||
|  |   static Mat4 RotateZ(float a); | ||||||
|  |   static Mat4 Perspective(float fov, float aspect, float n, float f); | ||||||
|  |   static Mat4 LookAt(const fvec3& pos, const fvec3& center, const fvec3& up); | ||||||
| }; | }; | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										9
									
								
								include/pd/core/pd_p_api.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										9
									
								
								include/pd/core/pd_p_api.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -2,8 +2,7 @@ | |||||||
|  |  | ||||||
| /* | /* | ||||||
| MIT License | 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 | ||||||
| @@ -22,7 +21,9 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 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. | ||||||
| */ |  */ | ||||||
|  |  | ||||||
|  | /** Generated with ppam */ | ||||||
|  |  | ||||||
| #ifdef _WIN32  // Windows (MSVC Tested) | #ifdef _WIN32  // Windows (MSVC Tested) | ||||||
| #ifdef PD_CORE_BUILD_SHARED | #ifdef PD_CORE_BUILD_SHARED | ||||||
| @@ -47,4 +48,4 @@ SOFTWARE. | |||||||
| #define PD_CORE_API | #define PD_CORE_API | ||||||
| #else | #else | ||||||
| #define PD_CORE_API | #define PD_CORE_API | ||||||
| #endif | #endif | ||||||
|   | |||||||
							
								
								
									
										0
									
								
								include/pd/core/sl/allocator.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								include/pd/core/sl/allocator.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
								
								
									
										140
									
								
								include/pd/core/sl/hashmap.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										140
									
								
								include/pd/core/sl/hashmap.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,71 +1,71 @@ | |||||||
| #pragma once | #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> | ||||||
| #include <pd/core/sl/list.hpp> | #include <pd/core/sl/list.hpp> | ||||||
| #include <pd/core/sl/pair.hpp> | #include <pd/core/sl/pair.hpp> | ||||||
|  |  | ||||||
| namespace PD { | namespace PD { | ||||||
| template <typename K, typename V, size_t bucket_count = 10> | template <typename K, typename V, size_t bucket_count = 10> | ||||||
| class HashMap { | class HashMap { | ||||||
|  public: |  public: | ||||||
|   HashMap() {} |   HashMap() {} | ||||||
|   ~HashMap() {} |   ~HashMap() {} | ||||||
|  |  | ||||||
|   void Insert(const K& k, const V& v) { |   void Insert(const K& k, const V& v) { | ||||||
|     size_t idx = Hash(k); |     size_t idx = Hash(k); | ||||||
|     auto& bukket = pBuckets[idx]; |     auto& bukket = pBuckets[idx]; | ||||||
|     for (auto& it : bukket) { |     for (auto& it : bukket) { | ||||||
|       if (it.First == k) { |       if (it.First == k) { | ||||||
|         it.Second = v; |         it.Second = v; | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     bukket.PushBack(Pair(k, v)); |     bukket.PushBack(Pair(k, v)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   bool Contains(const K& k) const { |   bool Contains(const K& k) const { | ||||||
|     size_t idx = Hash(k); |     size_t idx = Hash(k); | ||||||
|     auto& bukket = pBuckets[idx]; |     auto& bukket = pBuckets[idx]; | ||||||
|  |  | ||||||
|     for (auto& it : bukket) { |     for (auto& it : bukket) { | ||||||
|       if (it.First == k) { |       if (it.First == k) { | ||||||
|         return true; |         return true; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   void Clear() { |   void Clear() { | ||||||
|     for (size_t i = 0; i < bucket_count; i++) { |     for (size_t i = 0; i < bucket_count; i++) { | ||||||
|       pBuckets[i].Clear(); |       pBuckets[i].Clear(); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   size_t Hash(const K& k) const { return std::hash<K>{}(k) % bucket_count; } |   size_t Hash(const K& k) const { return std::hash<K>{}(k) % bucket_count; } | ||||||
|   PD::List<PD::Pair<K, V>> pBuckets[bucket_count]; |   PD::List<PD::Pair<K, V>> pBuckets[bucket_count]; | ||||||
| }; | }; | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										418
									
								
								include/pd/core/sl/list.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										418
									
								
								include/pd/core/sl/list.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,210 +1,210 @@ | |||||||
| #pragma once | #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 { | ||||||
| template <typename T> | template <typename T> | ||||||
| class List { | class List { | ||||||
|  public: |  public: | ||||||
|   List() {} |   List() {} | ||||||
|   ~List() {} |   ~List() {} | ||||||
|  |  | ||||||
|   struct Node { |   struct Node { | ||||||
|     Node(const T& v) : Data(v) {} |     Node(const T& v) : Data(v) {} | ||||||
|     T Data; |     T Data; | ||||||
|     Node* Prev = nullptr; |     Node* Prev = nullptr; | ||||||
|     Node* Next = nullptr; |     Node* Next = nullptr; | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   class Iterator { |   class Iterator { | ||||||
|    public: |    public: | ||||||
|     Iterator(Node* n) : pNode(n) {} |     Iterator(Node* n) : pNode(n) {} | ||||||
|     T& operator*() { return pNode->Data; } |     T& operator*() { return pNode->Data; } | ||||||
|     Iterator& operator++() { |     Iterator& operator++() { | ||||||
|       pNode = pNode->Next; |       pNode = pNode->Next; | ||||||
|       return *this; |       return *this; | ||||||
|     } |     } | ||||||
|     bool operator!=(const Iterator& o) const { return pNode != o.pNode; } |     bool operator!=(const Iterator& o) const { return pNode != o.pNode; } | ||||||
|  |  | ||||||
|     Node* pNode = nullptr; |     Node* pNode = nullptr; | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   void PushFront(const T& val) { |   void PushFront(const T& val) { | ||||||
|     Node* node = new Node(val); |     Node* node = new Node(val); | ||||||
|     // node->Data = val; |     // node->Data = val; | ||||||
|     node->Prev = nullptr; |     node->Prev = nullptr; | ||||||
|     node->Next = pHead; |     node->Next = pHead; | ||||||
|     if (pHead) { |     if (pHead) { | ||||||
|       pHead->Prev = node; |       pHead->Prev = node; | ||||||
|     } |     } | ||||||
|     pHead = node; |     pHead = node; | ||||||
|     if (!pTail) { |     if (!pTail) { | ||||||
|       pTail = node; |       pTail = node; | ||||||
|     } |     } | ||||||
|     pSize++; |     pSize++; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   void PushBack(const T& val) { |   void PushBack(const T& val) { | ||||||
|     Node* node = new Node(val); |     Node* node = new Node(val); | ||||||
|     // node->Data = val; |     // node->Data = val; | ||||||
|     node->Prev = pTail; |     node->Prev = pTail; | ||||||
|     node->Next = nullptr; |     node->Next = nullptr; | ||||||
|     if (pTail) { |     if (pTail) { | ||||||
|       pTail->Next = node; |       pTail->Next = node; | ||||||
|     } |     } | ||||||
|     pTail = node; |     pTail = node; | ||||||
|     if (!pHead) { |     if (!pHead) { | ||||||
|       pHead = node; |       pHead = node; | ||||||
|     } |     } | ||||||
|     pSize++; |     pSize++; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   void PopFront() { |   void PopFront() { | ||||||
|     if (!pHead) { |     if (!pHead) { | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     Node* t = pHead; |     Node* t = pHead; | ||||||
|     pHead = pHead->Next; |     pHead = pHead->Next; | ||||||
|     if (pHead) { |     if (pHead) { | ||||||
|       pHead->Prev = nullptr; |       pHead->Prev = nullptr; | ||||||
|     } else { |     } else { | ||||||
|       pTail = nullptr; |       pTail = nullptr; | ||||||
|     } |     } | ||||||
|     delete t; |     delete t; | ||||||
|     pSize--; |     pSize--; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   void PopBack() { |   void PopBack() { | ||||||
|     if (!pTail) { |     if (!pTail) { | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     Node* t = pTail; |     Node* t = pTail; | ||||||
|     pTail = pTail->Prev; |     pTail = pTail->Prev; | ||||||
|     if (pTail) { |     if (pTail) { | ||||||
|       pTail->Next = nullptr; |       pTail->Next = nullptr; | ||||||
|     } else { |     } else { | ||||||
|       pHead = nullptr; |       pHead = nullptr; | ||||||
|     } |     } | ||||||
|     delete t; |     delete t; | ||||||
|     pSize--; |     pSize--; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   void Clear() { |   void Clear() { | ||||||
|     while (pHead) { |     while (pHead) { | ||||||
|       PopFront(); |       PopFront(); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   void Remove(const T& v) { |   void Remove(const T& v) { | ||||||
|     Node* s = pHead; |     Node* s = pHead; | ||||||
|     while (s) { |     while (s) { | ||||||
|       if (s->Data == v) { |       if (s->Data == v) { | ||||||
|         if (s->Prev) { |         if (s->Prev) { | ||||||
|           s->Prev->Next = s->Next; |           s->Prev->Next = s->Next; | ||||||
|         } else { |         } else { | ||||||
|           pHead = s->Next; |           pHead = s->Next; | ||||||
|         } |         } | ||||||
|         if (s->Next) { |         if (s->Next) { | ||||||
|           s->Next->Prev = s->Prev; |           s->Next->Prev = s->Prev; | ||||||
|         } else { |         } else { | ||||||
|           pTail = s->Prev; |           pTail = s->Prev; | ||||||
|         } |         } | ||||||
|         delete s; |         delete s; | ||||||
|         pSize--; |         pSize--; | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|       s = s->Next; |       s = s->Next; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   void Reverse() { |   void Reverse() { | ||||||
|     Node* cur = pHead; |     Node* cur = pHead; | ||||||
|     while (cur) { |     while (cur) { | ||||||
|       Node* temp = cur->Prev; |       Node* temp = cur->Prev; | ||||||
|       cur->Prev = cur->Next; |       cur->Prev = cur->Next; | ||||||
|       cur->Next = temp; |       cur->Next = temp; | ||||||
|       cur = cur->Prev; |       cur = cur->Prev; | ||||||
|     } |     } | ||||||
|     Node* temp = pHead; |     Node* temp = pHead; | ||||||
|     pHead = pTail; |     pHead = pTail; | ||||||
|     pTail = temp; |     pTail = temp; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   T& Front() { |   T& Front() { | ||||||
|     if (pHead) { |     if (pHead) { | ||||||
|       return pHead->Data; |       return pHead->Data; | ||||||
|     } |     } | ||||||
|     // Need a List Empty Error Here (exceptions are disabled on 3ds) |     // Need a List Empty Error Here (exceptions are disabled on 3ds) | ||||||
|     exit(1); |     exit(1); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   const T& Front() const { |   const T& Front() const { | ||||||
|     if (pHead) { |     if (pHead) { | ||||||
|       return pHead->Data; |       return pHead->Data; | ||||||
|     } |     } | ||||||
|     // Need a List Empty Error Here (exceptions are disabled on 3ds) |     // Need a List Empty Error Here (exceptions are disabled on 3ds) | ||||||
|     exit(1); |     exit(1); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   T& Back() { |   T& Back() { | ||||||
|     if (pTail) { |     if (pTail) { | ||||||
|       return pTail->Data; |       return pTail->Data; | ||||||
|     } |     } | ||||||
|     // Need a List Empty Error Here (exceptions are disabled on 3ds) |     // Need a List Empty Error Here (exceptions are disabled on 3ds) | ||||||
|     exit(1); |     exit(1); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   const T& Back() const { |   const T& Back() const { | ||||||
|     if (pTail) { |     if (pTail) { | ||||||
|       return pTail->Data; |       return pTail->Data; | ||||||
|     } |     } | ||||||
|     // Need a List Empty Error Here (exceptions are disabled on 3ds) |     // Need a List Empty Error Here (exceptions are disabled on 3ds) | ||||||
|     exit(1); |     exit(1); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   size_t Size() const { return pSize; } |   size_t Size() const { return pSize; } | ||||||
|  |  | ||||||
|   Iterator begin() { return Iterator(pHead); } |   Iterator begin() { return Iterator(pHead); } | ||||||
|   Iterator end() { return Iterator(nullptr); } |   Iterator end() { return Iterator(nullptr); } | ||||||
|  |  | ||||||
|  private: |  private: | ||||||
|   Node* Find(const T& v) const { |   Node* Find(const T& v) const { | ||||||
|     Node* t = pHead; |     Node* t = pHead; | ||||||
|     while (t) { |     while (t) { | ||||||
|       if (t->Data == v) { |       if (t->Data == v) { | ||||||
|         return t; |         return t; | ||||||
|       } |       } | ||||||
|       t = t->Next; |       t = t->Next; | ||||||
|     } |     } | ||||||
|     return nullptr; |     return nullptr; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   Node* pHead = nullptr; |   Node* pHead = nullptr; | ||||||
|   Node* pTail = nullptr; |   Node* pTail = nullptr; | ||||||
|   size_t pSize = 0; |   size_t pSize = 0; | ||||||
| }; | }; | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										80
									
								
								include/pd/core/sl/pair.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										80
									
								
								include/pd/core/sl/pair.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,41 +1,41 @@ | |||||||
| #pragma once | #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 { | ||||||
| template <typename T1, typename T2> | template <typename T1, typename T2> | ||||||
| class Pair { | class Pair { | ||||||
|  public: |  public: | ||||||
|   Pair() = default; |   Pair() = default; | ||||||
|   Pair(const T1& f, const T2& s) : First(f), Second(s) {} |   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(T1&& f, T2&& s) : First(std::move(f)), Second(std::move(s)) {} | ||||||
|   ~Pair() = default; |   ~Pair() = default; | ||||||
|  |  | ||||||
|   T1 First; |   T1 First; | ||||||
|   T2 Second; |   T2 Second; | ||||||
| }; | }; | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										67
									
								
								include/pd/core/sl/sl.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										67
									
								
								include/pd/core/sl/sl.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,33 +1,34 @@ | |||||||
| #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/sl/allocator.hpp> | #include <pd/core/sl/allocator.hpp> | ||||||
| #include <pd/core/sl/hashmap.hpp> | #include <pd/core/sl/hashmap.hpp> | ||||||
| #include <pd/core/sl/list.hpp> | #include <pd/core/sl/list.hpp> | ||||||
| #include <pd/core/sl/pair.hpp> | #include <pd/core/sl/pair.hpp> | ||||||
| #include <pd/core/sl/stack.hpp> | #include <pd/core/sl/stack.hpp> | ||||||
| #include <pd/core/sl/tools.hpp> | #include <pd/core/sl/tools.hpp> | ||||||
| #include <pd/core/sl/vector.hpp> | #include <pd/core/sl/u128.hpp> | ||||||
|  | #include <pd/core/sl/vector.hpp> | ||||||
|   | |||||||
							
								
								
									
										0
									
								
								include/pd/core/sl/stack.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								include/pd/core/sl/stack.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
								
								
									
										0
									
								
								include/pd/core/sl/tools.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								include/pd/core/sl/tools.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
								
								
									
										125
									
								
								include/pd/core/sl/u128.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								include/pd/core/sl/u128.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,125 @@ | |||||||
|  | #pragma once | ||||||
|  |  | ||||||
|  | #include <pd/core/common.hpp> | ||||||
|  |  | ||||||
|  | namespace PD { | ||||||
|  | /** | ||||||
|  |  * 128 Bit support for all platforms probably | ||||||
|  |  * only used for flag checks in Keyboard/Mouse Input driver | ||||||
|  |  */ | ||||||
|  | class u128 { | ||||||
|  |  public: | ||||||
|  |   u64 pLow = 0; | ||||||
|  |   u64 pHigh = 0; | ||||||
|  |  | ||||||
|  |   constexpr u128() : pLow(0), pHigh(0) {} | ||||||
|  |   constexpr u128(u64 l, u64 h = 0) : pLow(l), pHigh(h) {} | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Best way so far to create flags that go over 63 | ||||||
|  |    * like `1 << 65` is just `u128::Flag(65)` | ||||||
|  |    */ | ||||||
|  |   constexpr static u128 Flag(u32 i) { | ||||||
|  |     if (i < 64) { | ||||||
|  |       return u128(1ULL << i, 0); | ||||||
|  |     } else if (i < 128) { | ||||||
|  |       return u128(0, 1ULL << (i - 64)); | ||||||
|  |     } | ||||||
|  |     return u128(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   u128 operator+(const u128& v) const { | ||||||
|  |     u128 ret; | ||||||
|  |     ret.pLow = pLow + v.pLow; | ||||||
|  |     ret.pHigh = pHigh + v.pHigh + (ret.pLow < pLow); | ||||||
|  |     return ret; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   u128 operator&(const u128& v) const { | ||||||
|  |     return u128(pLow & v.pLow, pHigh & v.pHigh); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   u128 operator<<(u32 s) const { | ||||||
|  |     if (s == 0) { | ||||||
|  |       return *this; | ||||||
|  |     } | ||||||
|  |     if (s >= 128) { | ||||||
|  |       return u128(); | ||||||
|  |     } | ||||||
|  |     if (s >= 64) { | ||||||
|  |       return u128(0, pLow << (s - 64)); | ||||||
|  |     } | ||||||
|  |     return u128(pLow << s, (pHigh << s) | (pLow >> (64 - s))); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   u128 operator>>(u32 s) const { | ||||||
|  |     if (s == 0) { | ||||||
|  |       return *this; | ||||||
|  |     } | ||||||
|  |     if (s >= 128) { | ||||||
|  |       return u128(); | ||||||
|  |     } | ||||||
|  |     if (s >= 64) { | ||||||
|  |       return u128(pHigh >> (s - 64), 0); | ||||||
|  |     } | ||||||
|  |     return u128((pLow >> s) | (pHigh << (64 - s)), pHigh >> s); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   u128& operator|=(const u128& v) { | ||||||
|  |     pLow |= v.pLow; | ||||||
|  |     pHigh |= v.pHigh; | ||||||
|  |     return *this; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   u128 operator|(const u128& v) const { | ||||||
|  |     return u128(pLow | v.pLow, pHigh | v.pHigh); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   u128& operator&=(const u128& v) { | ||||||
|  |     pLow &= v.pLow; | ||||||
|  |     pHigh &= v.pHigh; | ||||||
|  |     return *this; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   u128 operator~() const { return u128(~pLow, ~pHigh); } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Old why to make if checks possible | ||||||
|  |    * Problem was that a operator& is required | ||||||
|  |    * with u128 as result | ||||||
|  |    */ | ||||||
|  |   // bool operator&(const u128& v) const { | ||||||
|  |   //   return pLow & v.pLow || pHigh & v.pHigh; | ||||||
|  |   // } | ||||||
|  |  | ||||||
|  |   bool operator==(const u128& v) const { | ||||||
|  |     return pLow == v.pLow && pHigh == v.pHigh; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Use explicit here to make sure it is only for checking and not for | ||||||
|  |    * some error leading implicit bool assignments... | ||||||
|  |    */ | ||||||
|  |   explicit operator bool() const { return pLow != 0 || pHigh != 0; } | ||||||
|  |  | ||||||
|  |   /** Deprecated way to handle `flag & SomeFlag` */ | ||||||
|  |   bool Has(const u128& v) const { return pLow & v.pLow || pHigh & v.pHigh; } | ||||||
|  |  | ||||||
|  |   bool operator!=(const u128& v) const { return !(*this == v); } | ||||||
|  | }; | ||||||
|  | }  // namespace PD | ||||||
|  |  | ||||||
|  | namespace std { | ||||||
|  | /** | ||||||
|  |  * Provide c++ STL support for unordered map to u128 | ||||||
|  |  */ | ||||||
|  | template <> | ||||||
|  | struct hash<PD::u128> { | ||||||
|  |   size_t operator()(const PD::u128& k) const { | ||||||
|  |     // just combine hashes of the parts usign simple xor op | ||||||
|  |     size_t h0 = std::hash<PD::u64>{}(k.pLow); | ||||||
|  |     size_t h1 = std::hash<PD::u64>{}(k.pHigh); | ||||||
|  |     return h0 ^ (h1 << 1); | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  | }  // namespace std | ||||||
							
								
								
									
										0
									
								
								include/pd/core/sl/vector.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								include/pd/core/sl/vector.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
								
								
									
										244
									
								
								include/pd/core/strings.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										244
									
								
								include/pd/core/strings.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,123 +1,123 @@ | |||||||
| #pragma once | #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 | ||||||
|  */ |  */ | ||||||
| PD_CORE_API 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 Returns Empty if it has an error |  * @note Returns Empty if it has an error | ||||||
|  */ |  */ | ||||||
| PD_CORE_API std::wstring MakeWstring(const std::string& s); | PD_CORE_API 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); | PD_CORE_API 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); | PD_CORE_API 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); | PD_CORE_API 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( | PD_CORE_API const std::string GetFileName( | ||||||
|     const std::string& path, const std::string& saperators = "/\\"); |     const std::string& path, 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); | PD_CORE_API 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); | PD_CORE_API 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 __clang__  // Check clang first | ||||||
|   res << "Clang: " << __clang_major__ << "."; |   res << "Clang: " << __clang_major__ << "."; | ||||||
|   res << __clang_minor__ << "."; |   res << __clang_minor__ << "."; | ||||||
|   res << __clang_patchlevel__; |   res << __clang_patchlevel__; | ||||||
| #elif __GNUC__ | #elif __GNUC__ | ||||||
|   res << "GCC: " << __GNUC__; |   res << "GCC: " << __GNUC__; | ||||||
|   res << "." << __GNUC_MINOR__ << "."; |   res << "." << __GNUC_MINOR__ << "."; | ||||||
|   res << __GNUC_PATCHLEVEL__; |   res << __GNUC_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 PD_CORE_API 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; | ||||||
|  */ | }; | ||||||
| PD_CORE_API 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); | ||||||
| PD_CORE_API 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 | ||||||
							
								
								
									
										454
									
								
								include/pd/core/tween.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										454
									
								
								include/pd/core/tween.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,228 +1,228 @@ | |||||||
| #pragma once | #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> | ||||||
|  |  | ||||||
| #ifndef M_PI | #ifndef M_PI | ||||||
| #define M_PI 3.14159265358979323846 | #define M_PI 3.14159265358979323846 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| namespace PD { | namespace PD { | ||||||
| /** | /** | ||||||
|  * D7 Tween Engine (or something like that) |  * D7 Tween Engine (or something like that) | ||||||
|  * @tparam T Any Numeric value |  * @tparam T Any Numeric value | ||||||
|  */ |  */ | ||||||
| template <typename T> | template <typename T> | ||||||
| class Tween { | class Tween { | ||||||
|  public: |  public: | ||||||
|   /** |   /** | ||||||
|    * Effects Table |    * Effects Table | ||||||
|    */ |    */ | ||||||
|   enum Effect { |   enum Effect { | ||||||
|     Linear,          ///< Linear Movement [works] |     Linear,          ///< Linear Movement [works] | ||||||
|     EaseInQuad,      ///< EaseInQuad Movement [works] |     EaseInQuad,      ///< EaseInQuad Movement [works] | ||||||
|     EaseOutQuad,     ///< EaseOutQuad Movement [works] |     EaseOutQuad,     ///< EaseOutQuad Movement [works] | ||||||
|     EaseInOutQuad,   ///< EaseInOutQuad Movement [works] |     EaseInOutQuad,   ///< EaseInOutQuad Movement [works] | ||||||
|     EaseInCubic,     ///< EaseInCubic Movement [not tested] |     EaseInCubic,     ///< EaseInCubic Movement [not tested] | ||||||
|     EaseOutCubic,    ///< EaseOutCubic Movement [not tested] |     EaseOutCubic,    ///< EaseOutCubic Movement [not tested] | ||||||
|     EaseInOutCubic,  ///< EaseInOutCubic Movement [disabled] |     EaseInOutCubic,  ///< EaseInOutCubic Movement [disabled] | ||||||
|     EaseInSine,      ///< EaseInSine Movement [works] |     EaseInSine,      ///< EaseInSine Movement [works] | ||||||
|     EaseOutSine,     ///< EaseOutSine Movement [works] |     EaseOutSine,     ///< EaseOutSine Movement [works] | ||||||
|     EaseInOutSine,   ///< EaseInOutSine Movement [not tested] |     EaseInOutSine,   ///< EaseInOutSine Movement [not tested] | ||||||
|   }; |   }; | ||||||
|   Tween() = default; |   Tween() = default; | ||||||
|   ~Tween() = default; |   ~Tween() = default; | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Update Tween |    * Update Tween | ||||||
|    * @param delta deltatime |    * @param delta deltatime | ||||||
|    */ |    */ | ||||||
|   void Update(float delta) { |   void Update(float delta) { | ||||||
|     time += delta / 1000.f; |     time += delta / 1000.f; | ||||||
|     if (time > tend) { |     if (time > tend) { | ||||||
|       finished = true; |       finished = true; | ||||||
|       time = tend; |       time = tend; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Check if Tween is finished |    * Check if Tween is finished | ||||||
|    * @return true if finished |    * @return true if finished | ||||||
|    */ |    */ | ||||||
|   bool IsFinished() const { return finished; } |   bool IsFinished() const { return finished; } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Force finish the animation |    * Force finish the animation | ||||||
|    * @return Class reference |    * @return Class reference | ||||||
|    */ |    */ | ||||||
|   Tween& Finish() { |   Tween& Finish() { | ||||||
|     time = tend; |     time = tend; | ||||||
|     finished = true; |     finished = true; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Set Start Value |    * Set Start Value | ||||||
|    * @tparam T datatype of the Tween |    * @tparam T datatype of the Tween | ||||||
|    * @param start Start Value |    * @param start Start Value | ||||||
|    * @return class Reference |    * @return class Reference | ||||||
|    */ |    */ | ||||||
|   Tween& From(const T& start) { |   Tween& From(const T& start) { | ||||||
|     Reset(); |     Reset(); | ||||||
|     this->start = start; |     this->start = start; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|   /** |   /** | ||||||
|    * Set End Value |    * Set End Value | ||||||
|    * @tparam T datatype of the Tween |    * @tparam T datatype of the Tween | ||||||
|    * @param end End Value |    * @param end End Value | ||||||
|    * @return class Reference |    * @return class Reference | ||||||
|    */ |    */ | ||||||
|   Tween& To(const T& end) { |   Tween& To(const T& end) { | ||||||
|     Reset(); |     Reset(); | ||||||
|     this->end = end; |     this->end = end; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|   /** |   /** | ||||||
|    * Set the Duration (in seconds) |    * Set the Duration (in seconds) | ||||||
|    * @param seconds Duration |    * @param seconds Duration | ||||||
|    * @return class Reference |    * @return class Reference | ||||||
|    */ |    */ | ||||||
|   Tween& In(float seconds) { |   Tween& In(float seconds) { | ||||||
|     Reset(); |     Reset(); | ||||||
|     tend = seconds; |     tend = seconds; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|   /** |   /** | ||||||
|    * Set Effect of the Tween |    * Set Effect of the Tween | ||||||
|    * @param e Effect |    * @param e Effect | ||||||
|    * @return class Reference |    * @return class Reference | ||||||
|    */ |    */ | ||||||
|   Tween& As(const Effect& e) { |   Tween& As(const Effect& e) { | ||||||
|     effect = e; |     effect = e; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|   /** |   /** | ||||||
|    * Reset to time 0 |    * Reset to time 0 | ||||||
|    * @return class Reference |    * @return class Reference | ||||||
|    */ |    */ | ||||||
|   Tween& Reset() { |   Tween& Reset() { | ||||||
|     finished = false; |     finished = false; | ||||||
|     time = 0.f; |     time = 0.f; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|   /** |   /** | ||||||
|    * Get the Prograss in percent (0.0 to 1.0) of the tween |    * Get the Prograss in percent (0.0 to 1.0) of the tween | ||||||
|    * @return progress value |    * @return progress value | ||||||
|    */ |    */ | ||||||
|   float Progress() const { return time / tend; } |   float Progress() const { return time / tend; } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Swap Start and end Position of the Tween |    * Swap Start and end Position of the Tween | ||||||
|    * @return class reference |    * @return class reference | ||||||
|    */ |    */ | ||||||
|   Tween& Swap() { |   Tween& Swap() { | ||||||
|     T temp = start; |     T temp = start; | ||||||
|     start = end; |     start = end; | ||||||
|     end = temp; |     end = temp; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   T Get() const { |   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; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Operator that returns the current value calculated |    * Operator that returns the current value calculated | ||||||
|    * by time and effect |    * by time and effect | ||||||
|    */ |    */ | ||||||
|   operator T() const { return Get(); } |   operator T() const { return Get(); } | ||||||
|  |  | ||||||
|  private: |  private: | ||||||
|   /** Animation Effect */ |   /** Animation Effect */ | ||||||
|   Effect effect; |   Effect effect; | ||||||
|   /** Time */ |   /** Time */ | ||||||
|   float time = 0.f; |   float time = 0.f; | ||||||
|   /** |   /** | ||||||
|    * End time |    * End time | ||||||
|    * Defaulting to one to prevent div zero |    * Defaulting to one to prevent div zero | ||||||
|    * without a safetey check |    * without a safetey check | ||||||
|    * not implementing one cause if the user is |    * not implementing one cause if the user is | ||||||
|    * Writing a In(0.f) its their fault |    * Writing a In(0.f) its their fault | ||||||
|    */ |    */ | ||||||
|   float tend = 1.f; |   float tend = 1.f; | ||||||
|   /** Start value */ |   /** Start value */ | ||||||
|   T start; |   T start; | ||||||
|   /** end value */ |   /** end value */ | ||||||
|   T end; |   T end; | ||||||
|   /** is finished value */ |   /** is finished value */ | ||||||
|   bool finished = false; |   bool finished = false; | ||||||
| }; | }; | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										36
									
								
								include/pd/core/vec.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										36
									
								
								include/pd/core/vec.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -2,7 +2,8 @@ | |||||||
|  |  | ||||||
| /* | /* | ||||||
| MIT License | 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 | ||||||
| @@ -23,6 +24,37 @@ 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/vec2.hpp> | #include <pd/core/vec2.hpp> | ||||||
| #include <pd/core/vec3.hpp> | #include <pd/core/vec3.hpp> | ||||||
| #include <pd/core/vec4.hpp> | #include <pd/core/vec4.hpp> | ||||||
|  |  | ||||||
|  | /** Define Formatters for C++ 20 */ | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * WHY DOES MSVC ALWAYS NEED THESE EXTRA THINGS | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | template <typename T, typename CharT> | ||||||
|  | struct std::formatter<PD::vec2<T>, CharT> : std::formatter<T, CharT> { | ||||||
|  |   template <typename FormatContext> | ||||||
|  |   auto format(const PD::vec2<T>& v, FormatContext& ctx) const { | ||||||
|  |     return std::format_to(ctx.out(), "{}, {}", v.x, v.y); | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename T, typename CharT> | ||||||
|  | struct std::formatter<PD::vec3<T>, CharT> : std::formatter<T, CharT> { | ||||||
|  |   template <typename FormatContext> | ||||||
|  |   auto format(const PD::vec3<T>& v, FormatContext& ctx) const { | ||||||
|  |     return std::format_to(ctx.out(), "{}, {}, {}", v.x, v.y, v.z); | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename T, typename CharT> | ||||||
|  | struct std::formatter<PD::vec4<T>, CharT> : std::formatter<T, CharT> { | ||||||
|  |   template <typename FormatContext> | ||||||
|  |   auto format(const PD::vec4<T>& v, FormatContext& ctx) const { | ||||||
|  |     return std::format_to(ctx.out(), "{}, {}, {}, {}", v.x, v.y, v.z, v.w); | ||||||
|  |   } | ||||||
|  | }; | ||||||
							
								
								
									
										332
									
								
								include/pd/core/vec2.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										332
									
								
								include/pd/core/vec2.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,135 +1,197 @@ | |||||||
| #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> | // This file is generated by lazyvec 2.0.0 | ||||||
|  |  | ||||||
| namespace PD { | #include <pd/core/common.hpp> | ||||||
| template <typename T> |  | ||||||
| class vec2 { | namespace PD { | ||||||
|  public: | template <typename T> | ||||||
|   // SECTION: Constructors // | class vec2 { | ||||||
|  |  public: | ||||||
|   vec2() = default; |   T x; | ||||||
|   vec2(T v) { |   T y; | ||||||
|     x = v; |  | ||||||
|     y = v; |   // Constructors | ||||||
|   } |  | ||||||
|   vec2(T x, T y) { |   constexpr vec2() : x(0), y(0) {} | ||||||
|     this->x = x; |   template <typename T1> | ||||||
|     this->y = y; |   constexpr vec2(T1 v) { | ||||||
|   } |     x = (T)v; | ||||||
|  |     y = (T)v; | ||||||
|   vec2(const vec2<T> &v) { |   } | ||||||
|     x = v.x; |  | ||||||
|     y = v.y; |   template <typename T1> | ||||||
|   } |   constexpr vec2(const vec2<T1>& v) { | ||||||
|  |     x = (T)v.x; | ||||||
|   // SECTION: Operators // |     y = (T)v.y; | ||||||
|  |   } | ||||||
|   // ADD // |  | ||||||
|  |   constexpr explicit vec2(T x, T y) : x(x), y(y) {} | ||||||
|   vec2 &operator+=(T v) { |  | ||||||
|     x += v; |   // Operations | ||||||
|     y += v; |  | ||||||
|     return *this; |   template <typename T1> | ||||||
|   } |   vec2<T>& operator+=(T1 v) { | ||||||
|   vec2 &operator+=(const vec2 &v) { |     x += (T)v; | ||||||
|     x += v.x; |     y += (T)v; | ||||||
|     y += v.y; |     return *this; | ||||||
|     return *this; |   } | ||||||
|   } |  | ||||||
|   vec2 operator+(T v) const { return vec2(x + v, y + v); } |   template <typename T1> | ||||||
|   vec2 operator+(vec2 v) const { return vec2(x + v.x, y + v.y); } |   vec2<T>& operator+=(const vec2<T1>& v) { | ||||||
|  |     x += (T)v.x; | ||||||
|   // SUB // |     y += (T)v.y; | ||||||
|  |     return *this; | ||||||
|   vec2 &operator-=(T v) { |   } | ||||||
|     x -= v; |  | ||||||
|     y -= v; |   template <typename T1> | ||||||
|     return *this; |   vec2<T> operator+(T1 v) const { | ||||||
|   } |     return vec2<T>(x + (T)v, y + (T)v); | ||||||
|   vec2 &operator-=(const vec2 &v) { |   } | ||||||
|     x -= v.x; |  | ||||||
|     y -= v.y; |   template <typename T1> | ||||||
|     return *this; |   vec2<T> operator+(const vec2<T1>& v) const { | ||||||
|   } |     return vec2<T>(x + (T)v.x, y + (T)v.y); | ||||||
|   vec2 operator-(T v) const { return vec2(x - v, y - v); } |   } | ||||||
|   vec2 operator-(vec2 v) const { return vec2(x - v.x, y - v.y); } |  | ||||||
|  |   template <typename T1> | ||||||
|   // MUL // |   vec2<T>& operator-=(T1 v) { | ||||||
|  |     x -= (T)v; | ||||||
|   vec2 &operator*=(T v) { |     y -= (T)v; | ||||||
|     x *= v; |     return *this; | ||||||
|     y *= v; |   } | ||||||
|     return *this; |  | ||||||
|   } |   template <typename T1> | ||||||
|   vec2 &operator*=(const vec2 &v) { |   vec2<T>& operator-=(const vec2<T1>& v) { | ||||||
|     x *= v.x; |     x -= (T)v.x; | ||||||
|     y *= v.y; |     y -= (T)v.y; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|   vec2 operator*(T v) const { return vec2(x * v, y * v); } |  | ||||||
|   vec2 operator*(vec2 v) const { return vec2(x * v.x, y * v.y); } |   template <typename T1> | ||||||
|  |   vec2<T> operator-(T1 v) const { | ||||||
|   // DIV // |     return vec2<T>(x - (T)v, y - (T)v); | ||||||
|  |   } | ||||||
|   vec2 &operator/=(T v) { |  | ||||||
|     x /= v; |   template <typename T1> | ||||||
|     y /= v; |   vec2<T> operator-(const vec2<T1>& v) const { | ||||||
|     return *this; |     return vec2<T>(x - (T)v.x, y - (T)v.y); | ||||||
|   } |   } | ||||||
|   vec2 &operator/=(const vec2 &v) { |  | ||||||
|     x /= v.x; |   template <typename T1> | ||||||
|     y /= v.y; |   vec2<T>& operator*=(T1 v) { | ||||||
|     return *this; |     x *= (T)v; | ||||||
|   } |     y *= (T)v; | ||||||
|   vec2 operator/(T v) const { return vec2(x / v, y / v); } |     return *this; | ||||||
|   vec2 operator/(vec2 v) const { return vec2(x / v.x, y / v.y); } |   } | ||||||
|  |  | ||||||
|   // Make Negative // |   template <typename T1> | ||||||
|   vec2 operator-() const { return vec2(-x, -y); } |   vec2<T>& operator*=(const vec2<T1>& v) { | ||||||
|  |     x *= (T)v.x; | ||||||
|   bool operator==(const vec2 &v) const { return x == v.x && y == v.y; } |     y *= (T)v.y; | ||||||
|   bool operator!=(const vec2 &v) const { return !(*this == v); } |     return *this; | ||||||
|  |   } | ||||||
|   // SECTION: Additional Functions // |  | ||||||
|  |   template <typename T1> | ||||||
|   float Len() const { return sqrt(SqLen()); } |   vec2<T> operator*(T1 v) const { | ||||||
|   float SqLen() const { return x * x + y * y; } |     return vec2<T>(x * (T)v, y * (T)v); | ||||||
|   void Swap() { |   } | ||||||
|     T t = x; |  | ||||||
|     x = y; |   template <typename T1> | ||||||
|     y = t; |   vec2<T> operator*(const vec2<T1>& v) const { | ||||||
|   } |     return vec2<T>(x * (T)v.x, y * (T)v.y); | ||||||
|  |   } | ||||||
|   // SECTION: DATA // |  | ||||||
|   T x = 0; |   template <typename T1> | ||||||
|   T y = 0; |   vec2<T>& operator/=(T1 v) { | ||||||
| }; |     x /= (T)v; | ||||||
|  |     y /= (T)v; | ||||||
| using dvec2 = vec2<double>; |     return *this; | ||||||
| using fvec2 = vec2<float>; |   } | ||||||
| using ivec2 = vec2<int>; |  | ||||||
| }  // namespace PD |   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); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Generic Operations | ||||||
|  |  | ||||||
|  |   vec2 operator-() const { return vec2(-x, -y); } | ||||||
|  |   template <typename T1> | ||||||
|  |   bool operator==(const vec2<T1>& v) const { | ||||||
|  |     return x == (T)v.x && y == (T)v.y; | ||||||
|  |   } | ||||||
|  |   template <typename T1> | ||||||
|  |   bool operator!=(const vec2<T1>& v) const { | ||||||
|  |     return !(*this == v); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Functions | ||||||
|  |  | ||||||
|  |   double Len() const { return std::sqrt(SqLen()); } | ||||||
|  |   double SqLen() const { return x * x + y * y; } | ||||||
|  |  | ||||||
|  |   template <typename T1> | ||||||
|  |   double Distance(const vec2<T1>& v) const { | ||||||
|  |     return (*this - v).Len(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   vec2<T> Normalize() const { | ||||||
|  |     double l = Len(); | ||||||
|  |     if (l == 0) { | ||||||
|  |       return *this; | ||||||
|  |     } | ||||||
|  |     return *this / (T)l; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   template <typename T1> | ||||||
|  |   T Dot(const vec2<T1>& v) const { | ||||||
|  |     return x * (T)v.x + y * (T)v.y; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Swap Functions | ||||||
|  |   void SwapXY() { | ||||||
|  |     T t = x; | ||||||
|  |     x = y; | ||||||
|  |     y = t; | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  | using fvec2 = vec2<float>; | ||||||
|  | using ivec2 = vec2<int>; | ||||||
|  | using dvec2 = vec2<double>; | ||||||
|  | }  // namespace PD | ||||||
|   | |||||||
							
								
								
									
										395
									
								
								include/pd/core/vec3.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										395
									
								
								include/pd/core/vec3.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,160 +1,235 @@ | |||||||
| #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> | // This file is generated by lazyvec 2.0.0 | ||||||
| #include <pd/core/vec2.hpp> |  | ||||||
|  | #include <pd/core/common.hpp> | ||||||
| namespace PD { | // Extended includes (rename if you use other filenames/paths) | ||||||
| template <typename T> | #include <pd/core/vec2.hpp> | ||||||
| class vec3 { |  | ||||||
|  public: | namespace PD { | ||||||
|   // SECTION: Constructors // | template <typename T> | ||||||
|  | class vec3 { | ||||||
|   vec3() = default; |  public: | ||||||
|   vec3(T v) { |   T x; | ||||||
|     x = v; |   T y; | ||||||
|     y = v; |   T z; | ||||||
|     z = v; |  | ||||||
|   } |   // Constructors | ||||||
|   vec3(T x, T y, T z) { |  | ||||||
|     this->x = x; |   constexpr vec3() : x(0), y(0), z(0) {} | ||||||
|     this->y = y; |   template <typename T1> | ||||||
|     this->z = z; |   constexpr vec3(T1 v) { | ||||||
|   } |     x = (T)v; | ||||||
|  |     y = (T)v; | ||||||
|   vec3(const vec3 &v) { |     z = (T)v; | ||||||
|     x = v.x; |   } | ||||||
|     y = v.y; |  | ||||||
|     z = v.z; |   template <typename T1> | ||||||
|   } |   constexpr vec3(const vec3<T1>& v) { | ||||||
|  |     x = (T)v.x; | ||||||
|   // SECTION: Operators // |     y = (T)v.y; | ||||||
|  |     z = (T)v.z; | ||||||
|   // ADD // |   } | ||||||
|  |  | ||||||
|   vec3 &operator+=(T v) { |   constexpr explicit vec3(T x, T y, T z) : x(x), y(y), z(z) {} | ||||||
|     x += v; |  | ||||||
|     y += v; |   // Extended Constructors | ||||||
|     z += v; |   template <typename T1> | ||||||
|     return *this; |   constexpr explicit vec3(const vec2<T1>& xy, T1 z) { | ||||||
|   } |     { | ||||||
|   vec3 &operator+=(const vec3 &v) { |       x = (T)xy.x; | ||||||
|     x += v.x; |       y = (T)xy.y; | ||||||
|     y += v.y; |       this->z = (T)z; | ||||||
|     z += v.z; |     } | ||||||
|     return *this; |   } | ||||||
|   } |  | ||||||
|   vec3 operator+(T v) const { return vec3(x + v, y + v, z + v); } |   // Operations | ||||||
|   vec3 operator+(vec3 v) const { return vec3(x + v.x, y + v.y, z + v.z); } |  | ||||||
|  |   template <typename T1> | ||||||
|   // SUB // |   vec3<T>& operator+=(T1 v) { | ||||||
|  |     x += (T)v; | ||||||
|   vec3 &operator-=(T v) { |     y += (T)v; | ||||||
|     x -= v; |     z += (T)v; | ||||||
|     y -= v; |     return *this; | ||||||
|     z -= v; |   } | ||||||
|     return *this; |  | ||||||
|   } |   template <typename T1> | ||||||
|   vec3 &operator-=(const vec3 &v) { |   vec3<T>& operator+=(const vec3<T1>& v) { | ||||||
|     x -= v.x; |     x += (T)v.x; | ||||||
|     y -= v.y; |     y += (T)v.y; | ||||||
|     z -= v.z; |     z += (T)v.z; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|   vec3 operator-(T v) const { return vec3(x - v, y - v, z - v); } |  | ||||||
|   vec3 operator-(vec3 v) const { return vec3(x - v.x, y - v.y, z - v.z); } |   template <typename T1> | ||||||
|  |   vec3<T> operator+(T1 v) const { | ||||||
|   // MUL // |     return vec3<T>(x + (T)v, y + (T)v, z + (T)v); | ||||||
|  |   } | ||||||
|   vec3 &operator*=(T v) { |  | ||||||
|     x *= v; |   template <typename T1> | ||||||
|     y *= v; |   vec3<T> operator+(const vec3<T1>& v) const { | ||||||
|     z *= v; |     return vec3<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z); | ||||||
|     return *this; |   } | ||||||
|   } |  | ||||||
|   vec3 &operator*=(const vec3 &v) { |   template <typename T1> | ||||||
|     x *= v.x; |   vec3<T>& operator-=(T1 v) { | ||||||
|     y *= v.y; |     x -= (T)v; | ||||||
|     z *= v.z; |     y -= (T)v; | ||||||
|     return *this; |     z -= (T)v; | ||||||
|   } |     return *this; | ||||||
|   vec3 operator*(T v) const { return vec3(x * v, y * v, z * v); } |   } | ||||||
|   vec3 operator*(vec3 v) const { return vec3(x * v.x, y * v.y, z * v.z); } |  | ||||||
|  |   template <typename T1> | ||||||
|   // DIV // |   vec3<T>& operator-=(const vec3<T1>& v) { | ||||||
|  |     x -= (T)v.x; | ||||||
|   vec3 &operator/=(T v) { |     y -= (T)v.y; | ||||||
|     x /= v; |     z -= (T)v.z; | ||||||
|     y /= v; |     return *this; | ||||||
|     z /= v; |   } | ||||||
|     return *this; |  | ||||||
|   } |   template <typename T1> | ||||||
|   vec3 &operator/=(const vec3 &v) { |   vec3<T> operator-(T1 v) const { | ||||||
|     x /= v.x; |     return vec3<T>(x - (T)v, y - (T)v, z - (T)v); | ||||||
|     y /= v.y; |   } | ||||||
|     z /= v.z; |  | ||||||
|     return *this; |   template <typename T1> | ||||||
|   } |   vec3<T> operator-(const vec3<T1>& v) const { | ||||||
|   vec3 operator/(T v) const { return vec3(x / v, y / v, z / v); } |     return vec3<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z); | ||||||
|   vec3 operator/(vec3 v) const { return vec3(x / v.x, y / v.y, z / v.z); } |   } | ||||||
|  |  | ||||||
|   // Make Negative // |   template <typename T1> | ||||||
|   vec3 operator-() const { return vec3(-x, -y, -z); } |   vec3<T>& operator*=(T1 v) { | ||||||
|  |     x *= (T)v; | ||||||
|   bool operator==(const vec3 &v) const { |     y *= (T)v; | ||||||
|     return x == v.x && y == v.y && z == v.z; |     z *= (T)v; | ||||||
|   } |     return *this; | ||||||
|   bool operator!=(const vec3 &v) const { return !(*this == v); } |   } | ||||||
|  |  | ||||||
|   // SECTION: Additional Functions // |   template <typename T1> | ||||||
|  |   vec3<T>& operator*=(const vec3<T1>& v) { | ||||||
|   float Len() const { return sqrt(SqLen()); } |     x *= (T)v.x; | ||||||
|   float SqLen() const { return x * x + y * y + z * z; } |     y *= (T)v.y; | ||||||
|   void SwapXY() { |     z *= (T)v.z; | ||||||
|     T t = x; |     return *this; | ||||||
|     x = y; |   } | ||||||
|     y = t; |  | ||||||
|   } |   template <typename T1> | ||||||
|   void SwapYZ() { |   vec3<T> operator*(T1 v) const { | ||||||
|     T t = z; |     return vec3<T>(x * (T)v, y * (T)v, z * (T)v); | ||||||
|     z = y; |   } | ||||||
|     y = t; |  | ||||||
|   } |   template <typename T1> | ||||||
|   void SwapXZ() { |   vec3<T> operator*(const vec3<T1>& v) const { | ||||||
|     T t = z; |     return vec3<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z); | ||||||
|     z = x; |   } | ||||||
|     x = t; |  | ||||||
|   } |   template <typename T1> | ||||||
|  |   vec3<T>& operator/=(T1 v) { | ||||||
|   // SECTION: DATA // |     x /= (T)v; | ||||||
|   T x = 0; |     y /= (T)v; | ||||||
|   T y = 0; |     z /= (T)v; | ||||||
|   T z = 0; |     return *this; | ||||||
| }; |   } | ||||||
|  |  | ||||||
| using dvec3 = vec3<double>; |   template <typename T1> | ||||||
| using fvec3 = vec3<float>; |   vec3<T>& operator/=(const vec3<T1>& v) { | ||||||
| using ivec3 = vec3<int>; |     x /= (T)v.x; | ||||||
| }  // namespace PD |     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); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Generic Operations | ||||||
|  |  | ||||||
|  |   vec3 operator-() const { return vec3(-x, -y, -z); } | ||||||
|  |   template <typename T1> | ||||||
|  |   bool operator==(const vec3<T1>& v) const { | ||||||
|  |     return x == (T)v.x && y == (T)v.y && z == (T)v.z; | ||||||
|  |   } | ||||||
|  |   template <typename T1> | ||||||
|  |   bool operator!=(const vec3<T1>& v) const { | ||||||
|  |     return !(*this == v); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Functions | ||||||
|  |  | ||||||
|  |   double Len() const { return std::sqrt(SqLen()); } | ||||||
|  |   double SqLen() const { return x * x + y * y + z * z; } | ||||||
|  |  | ||||||
|  |   template <typename T1> | ||||||
|  |   double Distance(const vec3<T1>& v) const { | ||||||
|  |     return (*this - v).Len(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   vec3<T> Normalize() const { | ||||||
|  |     double l = Len(); | ||||||
|  |     if (l == 0) { | ||||||
|  |       return *this; | ||||||
|  |     } | ||||||
|  |     return *this / (T)l; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   template <typename T1> | ||||||
|  |   T Dot(const vec3<T1>& v) const { | ||||||
|  |     return x * (T)v.x + y * (T)v.y + z * (T)v.z; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   template <typename T1> | ||||||
|  |   vec3<T> Cross(const vec3<T1>& v) const { | ||||||
|  |     return vec3<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Swap Functions | ||||||
|  |   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 ivec3 = vec3<int>; | ||||||
|  | using dvec3 = vec3<double>; | ||||||
|  | }  // namespace PD | ||||||
|   | |||||||
							
								
								
									
										461
									
								
								include/pd/core/vec4.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										461
									
								
								include/pd/core/vec4.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,193 +1,268 @@ | |||||||
| #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> | // This file is generated by lazyvec 2.0.0 | ||||||
| #include <pd/core/vec3.hpp> |  | ||||||
|  | #include <pd/core/common.hpp> | ||||||
| namespace PD { | // Extended includes (rename if you use other filenames/paths) | ||||||
| template <typename T> | #include <pd/core/vec2.hpp> | ||||||
| class vec4 { | #include <pd/core/vec3.hpp> | ||||||
|  public: |  | ||||||
|   // SECTION: Constructors // | namespace PD { | ||||||
|  | template <typename T> | ||||||
|   vec4() = default; | class vec4 { | ||||||
|   vec4(T v) { |  public: | ||||||
|     x = v; |   T x; | ||||||
|     y = v; |   T y; | ||||||
|     z = v; |   T z; | ||||||
|     w = v; |   T w; | ||||||
|   } |  | ||||||
|   vec4(T x, T y, T z, T w) { |   // Constructors | ||||||
|     this->x = x; |  | ||||||
|     this->y = y; |   constexpr vec4() : x(0), y(0), z(0), w(0) {} | ||||||
|     this->z = z; |   template <typename T1> | ||||||
|     this->w = w; |   constexpr vec4(T1 v) { | ||||||
|   } |     x = (T)v; | ||||||
|  |     y = (T)v; | ||||||
|   vec4(const vec4 &v) { |     z = (T)v; | ||||||
|     x = v.x; |     w = (T)v; | ||||||
|     y = v.y; |   } | ||||||
|     z = v.z; |  | ||||||
|     w = v.w; |   template <typename T1> | ||||||
|   } |   constexpr vec4(const vec4<T1>& v) { | ||||||
|  |     x = (T)v.x; | ||||||
|   vec4(const vec2<T> &xy, const vec2<T> &zw) { |     y = (T)v.y; | ||||||
|     x = xy.x; |     z = (T)v.z; | ||||||
|     y = xy.y; |     w = (T)v.w; | ||||||
|     z = zw.x; |   } | ||||||
|     w = zw.y; |  | ||||||
|   } |   constexpr explicit vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {} | ||||||
|  |  | ||||||
|   // SECTION: Operators // |   // Extended Constructors | ||||||
|  |   template <typename T1> | ||||||
|   // ADD // |   constexpr explicit vec4(const vec2<T1>& xy, const vec2<T1>& zw) { | ||||||
|  |     { | ||||||
|   vec4 &operator+=(T v) { |       x = (T)xy.x; | ||||||
|     x += v; |       y = (T)xy.y; | ||||||
|     y += v; |       z = (T)zw.x; | ||||||
|     z += v; |       w = (T)zw.y; | ||||||
|     w += v; |     } | ||||||
|     return *this; |   } | ||||||
|   } |  | ||||||
|   vec4 &operator+=(const vec4<T> &v) { |   template <typename T1> | ||||||
|     x += v.x; |   constexpr explicit vec4(const vec3<T1>& xyz, T1 w) { | ||||||
|     y += v.y; |     { | ||||||
|     z += v.z; |       x = (T)xyz.x; | ||||||
|     w += v.w; |       y = (T)xyz.y; | ||||||
|     return *this; |       z = (T)xyz.z; | ||||||
|   } |       this->w = (T)w; | ||||||
|   vec4 operator+(T v) const { return vec4<T>(x + v, y + v, z + v, w + v); } |     } | ||||||
|   vec4 operator+(vec4 v) const { |   } | ||||||
|     return vec4(x + v.x, y + v.y, z + v.z, w + v.w); |  | ||||||
|   } |   // Operations | ||||||
|  |  | ||||||
|   // SUB // |   template <typename T1> | ||||||
|  |   vec4<T>& operator+=(T1 v) { | ||||||
|   vec4 &operator-=(T v) { |     x += (T)v; | ||||||
|     x -= v; |     y += (T)v; | ||||||
|     y -= v; |     z += (T)v; | ||||||
|     z -= v; |     w += (T)v; | ||||||
|     w -= v; |     return *this; | ||||||
|     return *this; |   } | ||||||
|   } |  | ||||||
|   vec4 &operator-=(const vec4 &v) { |   template <typename T1> | ||||||
|     x -= v.x; |   vec4<T>& operator+=(const vec4<T1>& v) { | ||||||
|     y -= v.y; |     x += (T)v.x; | ||||||
|     z -= v.z; |     y += (T)v.y; | ||||||
|     w -= v.w; |     z += (T)v.z; | ||||||
|     return *this; |     w += (T)v.w; | ||||||
|   } |     return *this; | ||||||
|   vec4 operator-(T v) const { return vec4(x - v, y - v, z - v, w - v); } |   } | ||||||
|   vec4 operator-(vec4 v) const { |  | ||||||
|     return vec4(x - v.x, y - v.y, z - v.z, w - v.w); |   template <typename T1> | ||||||
|   } |   vec4<T> operator+(T1 v) const { | ||||||
|  |     return vec4<T>(x + (T)v, y + (T)v, z + (T)v, w + (T)v); | ||||||
|   // MUL // |   } | ||||||
|  |  | ||||||
|   vec4 &operator*=(T v) { |   template <typename T1> | ||||||
|     x *= v; |   vec4<T> operator+(const vec4<T1>& v) const { | ||||||
|     y *= v; |     return vec4<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z, w + (T)v.w); | ||||||
|     z *= v; |   } | ||||||
|     w *= v; |  | ||||||
|     return *this; |   template <typename T1> | ||||||
|   } |   vec4<T>& operator-=(T1 v) { | ||||||
|   vec4 &operator*=(const vec4 &v) { |     x -= (T)v; | ||||||
|     x *= v.x; |     y -= (T)v; | ||||||
|     y *= v.y; |     z -= (T)v; | ||||||
|     z *= v.z; |     w -= (T)v; | ||||||
|     w *= v.w; |     return *this; | ||||||
|     return *this; |   } | ||||||
|   } |  | ||||||
|   vec4 operator*(T v) const { return vec4(x * v, y * v, z * v, w * v); } |   template <typename T1> | ||||||
|   vec4 operator*(vec4 v) const { |   vec4<T>& operator-=(const vec4<T1>& v) { | ||||||
|     return vec4(x * v.x, y * v.y, z * v.z, w * v.w); |     x -= (T)v.x; | ||||||
|   } |     y -= (T)v.y; | ||||||
|  |     z -= (T)v.z; | ||||||
|   // DIV // |     w -= (T)v.w; | ||||||
|  |     return *this; | ||||||
|   vec4 &operator/=(T v) { |   } | ||||||
|     x /= v; |  | ||||||
|     y /= v; |   template <typename T1> | ||||||
|     z /= v; |   vec4<T> operator-(T1 v) const { | ||||||
|     w /= v; |     return vec4<T>(x - (T)v, y - (T)v, z - (T)v, w - (T)v); | ||||||
|     return *this; |   } | ||||||
|   } |  | ||||||
|   vec4 &operator/=(const vec4 &v) { |   template <typename T1> | ||||||
|     x /= v.x; |   vec4<T> operator-(const vec4<T1>& v) const { | ||||||
|     y /= v.y; |     return vec4<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z, w - (T)v.w); | ||||||
|     z /= v.z; |   } | ||||||
|     w /= v.w; |  | ||||||
|     return *this; |   template <typename T1> | ||||||
|   } |   vec4<T>& operator*=(T1 v) { | ||||||
|   vec4 operator/(T v) const { return vec4(x / v, y / v, z / v, w / v); } |     x *= (T)v; | ||||||
|   vec4 operator/(vec4 v) const { |     y *= (T)v; | ||||||
|     return vec4(x / v.x, y / v.y, z / v.z, w / v.w); |     z *= (T)v; | ||||||
|   } |     w *= (T)v; | ||||||
|  |     return *this; | ||||||
|   // Make Negative // |   } | ||||||
|   vec4 operator-() const { return vec4(-x, -y, -z, -w); } |  | ||||||
|  |   template <typename T1> | ||||||
|   bool operator==(const vec4 &v) const { |   vec4<T>& operator*=(const vec4<T1>& v) { | ||||||
|     return x == v.x && y == v.y && z == v.z && w == v.w; |     x *= (T)v.x; | ||||||
|   } |     y *= (T)v.y; | ||||||
|   bool operator!=(const vec4 &v) const { return !(*this == v); } |     z *= (T)v.z; | ||||||
|  |     w *= (T)v.w; | ||||||
|   // SECTION: Additional Functions // |     return *this; | ||||||
|  |   } | ||||||
|   float Len() const { return sqrt(SqLen()); } |  | ||||||
|   float SqLen() const { return x * x + y * y + z * z + w * w; } |   template <typename T1> | ||||||
|   void SwapXY() { |   vec4<T> operator*(T1 v) const { | ||||||
|     T t = x; |     return vec4<T>(x * (T)v, y * (T)v, z * (T)v, w * (T)v); | ||||||
|     x = y; |   } | ||||||
|     y = t; |  | ||||||
|   } |   template <typename T1> | ||||||
|   void SwapYZ() { |   vec4<T> operator*(const vec4<T1>& v) const { | ||||||
|     T t = z; |     return vec4<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z, w * (T)v.w); | ||||||
|     z = y; |   } | ||||||
|     y = t; |  | ||||||
|   } |   template <typename T1> | ||||||
|   void SwapXZ() { |   vec4<T>& operator/=(T1 v) { | ||||||
|     T t = z; |     x /= (T)v; | ||||||
|     z = x; |     y /= (T)v; | ||||||
|     x = t; |     z /= (T)v; | ||||||
|   } |     w /= (T)v; | ||||||
|   // Adding ZW (to lazy to add all of those yet) |     return *this; | ||||||
|   void SwapZW() { |   } | ||||||
|     T t = w; |  | ||||||
|     w = z; |   template <typename T1> | ||||||
|     z = t; |   vec4<T>& operator/=(const vec4<T1>& v) { | ||||||
|   } |     x /= (T)v.x; | ||||||
|  |     y /= (T)v.y; | ||||||
|   // SECTION: DATA // |     z /= (T)v.z; | ||||||
|   T x = 0; |     w /= (T)v.w; | ||||||
|   T y = 0; |     return *this; | ||||||
|   T z = 0; |   } | ||||||
|   T w = 0; |  | ||||||
| }; |   template <typename T1> | ||||||
|  |   vec4<T> operator/(T1 v) const { | ||||||
| using dvec4 = vec4<double>; |     return vec4<T>(x / (T)v, y / (T)v, z / (T)v, w / (T)v); | ||||||
| using fvec4 = vec4<float>; |   } | ||||||
| using ivec4 = vec4<int>; |  | ||||||
| }  // namespace PD |   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); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Generic Operations | ||||||
|  |  | ||||||
|  |   vec4 operator-() const { return vec4(-x, -y, -z, -w); } | ||||||
|  |   template <typename T1> | ||||||
|  |   bool operator==(const vec4<T1>& v) const { | ||||||
|  |     return x == (T)v.x && y == (T)v.y && z == (T)v.z && w == (T)v.w; | ||||||
|  |   } | ||||||
|  |   template <typename T1> | ||||||
|  |   bool operator!=(const vec4<T1>& v) const { | ||||||
|  |     return !(*this == v); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Functions | ||||||
|  |  | ||||||
|  |   double Len() const { return std::sqrt(SqLen()); } | ||||||
|  |   double SqLen() const { return x * x + y * y + z * z + w * w; } | ||||||
|  |  | ||||||
|  |   template <typename T1> | ||||||
|  |   double Distance(const vec4<T1>& v) const { | ||||||
|  |     return (*this - v).Len(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   vec4<T> Normalize() const { | ||||||
|  |     double l = Len(); | ||||||
|  |     if (l == 0) { | ||||||
|  |       return *this; | ||||||
|  |     } | ||||||
|  |     return *this / (T)l; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   template <typename T1> | ||||||
|  |   T Dot(const vec4<T1>& v) const { | ||||||
|  |     return x * (T)v.x + y * (T)v.y + z * (T)v.z + w * (T)v.w; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Swap Functions | ||||||
|  |   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 ivec4 = vec4<int>; | ||||||
|  | using dvec4 = vec4<double>; | ||||||
|  | }  // namespace PD | ||||||
|   | |||||||
							
								
								
									
										28
									
								
								include/pd/drivers/drivers.hpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										28
									
								
								include/pd/drivers/drivers.hpp
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,28 @@ | |||||||
|  | #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/gfx.hpp> | ||||||
|  | #include <pd/drivers/hid.hpp> | ||||||
|  | #include <pd/drivers/os.hpp> | ||||||
							
								
								
									
										114
									
								
								include/pd/drivers/gfx.hpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										114
									
								
								include/pd/drivers/gfx.hpp
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,114 @@ | |||||||
|  | #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 { | ||||||
|  | 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(Li::TexAddress addr) {} | ||||||
|  |  | ||||||
|  |   virtual void RenderDrawData(const std::vector<Li::Command::Ref>& Commands) {} | ||||||
|  |  | ||||||
|  |   void SetViewPort(const ivec2& vp) { ViewPort = vp; } | ||||||
|  |  | ||||||
|  |   virtual Li::Texture::Ref LoadTex( | ||||||
|  |       const std::vector<u8>& pixels, int w, int h, | ||||||
|  |       Li::Texture::Type type = Li::Texture::Type::RGBA32, | ||||||
|  |       Li::Texture::Filter filter = Li::Texture::Filter::LINEAR) { | ||||||
|  |     // Texture loading not supported (when this func not get override) | ||||||
|  |     return nullptr; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   Li::Texture::Ref GetSolidTex() { return pSolid; } | ||||||
|  |  | ||||||
|  |   const std::string pName = "NullGfx"; | ||||||
|  |   LiBackendFlags Flags = 0; | ||||||
|  |   ivec2 ViewPort; | ||||||
|  |   Mat4 Projection; | ||||||
|  |   Li::Texture::Ref pSolid; | ||||||
|  |   size_t CurrentVertex = 0; | ||||||
|  |   size_t CurrentIndex = 0; | ||||||
|  |  | ||||||
|  |   /** 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(Li::TexAddress addr) { pGfx->BindTex(addr); } | ||||||
|  |   static void SetViewPort(const ivec2& vp) { pGfx->SetViewPort(vp); } | ||||||
|  |  | ||||||
|  |   static void RenderDrawData(const std::vector<Li::Command::Ref>& Commands) { | ||||||
|  |     pGfx->RenderDrawData(Commands); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   static LiBackendFlags Flags() { return pGfx->Flags; } | ||||||
|  |   static Li::Texture::Ref LoadTex( | ||||||
|  |       const std::vector<u8>& pixels, int w, int h, | ||||||
|  |       Li::Texture::Type type = Li::Texture::Type::RGBA32, | ||||||
|  |       Li::Texture::Filter filter = Li::Texture::Filter::LINEAR) { | ||||||
|  |     return pGfx->LoadTex(pixels, w, h, type, filter); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   static Li::Texture::Ref GetSolidTex() { return pGfx->GetSolidTex(); } | ||||||
|  |  | ||||||
|  |   static GfxDriver::Ref pGfx; | ||||||
|  | }; | ||||||
|  | }  // namespace PD | ||||||
							
								
								
									
										296
									
								
								include/pd/drivers/hid.hpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										296
									
								
								include/pd/drivers/hid.hpp
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,296 @@ | |||||||
|  | #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 PURPHidE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||
|  | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||
|  | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||
|  | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||
|  | SOFTWARE. | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | #include <pd/core/core.hpp> | ||||||
|  |  | ||||||
|  | namespace PD { | ||||||
|  | /** Did not found a better solution yet sadly */ | ||||||
|  | namespace HidKb { | ||||||
|  | // Lets use u128 here | ||||||
|  | using KbKey = u128; | ||||||
|  | constexpr static KbKey Kb_No = 0; | ||||||
|  | constexpr static KbKey Kb_Escape = KbKey::Flag(0); | ||||||
|  | constexpr static KbKey Kb_Q = KbKey::Flag(1); | ||||||
|  | constexpr static KbKey Kb_W = KbKey::Flag(2); | ||||||
|  | constexpr static KbKey Kb_E = KbKey::Flag(3); | ||||||
|  | constexpr static KbKey Kb_R = KbKey::Flag(4); | ||||||
|  | constexpr static KbKey Kb_T = KbKey::Flag(5); | ||||||
|  | constexpr static KbKey Kb_Z = KbKey::Flag(6); | ||||||
|  | constexpr static KbKey Kb_U = KbKey::Flag(7); | ||||||
|  | constexpr static KbKey Kb_I = KbKey::Flag(8); | ||||||
|  | constexpr static KbKey Kb_O = KbKey::Flag(9); | ||||||
|  | constexpr static KbKey Kb_P = KbKey::Flag(10); | ||||||
|  | constexpr static KbKey Kb_A = KbKey::Flag(11); | ||||||
|  | constexpr static KbKey Kb_S = KbKey::Flag(12); | ||||||
|  | constexpr static KbKey Kb_D = KbKey::Flag(13); | ||||||
|  | constexpr static KbKey Kb_F = KbKey::Flag(14); | ||||||
|  | constexpr static KbKey Kb_G = KbKey::Flag(15); | ||||||
|  | constexpr static KbKey Kb_H = KbKey::Flag(16); | ||||||
|  | constexpr static KbKey Kb_J = KbKey::Flag(17); | ||||||
|  | constexpr static KbKey Kb_K = KbKey::Flag(18); | ||||||
|  | constexpr static KbKey Kb_L = KbKey::Flag(19); | ||||||
|  | constexpr static KbKey Kb_Y = KbKey::Flag(20); | ||||||
|  | constexpr static KbKey Kb_X = KbKey::Flag(21); | ||||||
|  | constexpr static KbKey Kb_C = KbKey::Flag(22); | ||||||
|  | constexpr static KbKey Kb_V = KbKey::Flag(23); | ||||||
|  | constexpr static KbKey Kb_B = KbKey::Flag(24); | ||||||
|  | constexpr static KbKey Kb_N = KbKey::Flag(25); | ||||||
|  | constexpr static KbKey Kb_M = KbKey::Flag(26); | ||||||
|  | constexpr static KbKey Kb_1 = KbKey::Flag(27); | ||||||
|  | constexpr static KbKey Kb_2 = KbKey::Flag(28); | ||||||
|  | constexpr static KbKey Kb_3 = KbKey::Flag(29); | ||||||
|  | constexpr static KbKey Kb_4 = KbKey::Flag(30); | ||||||
|  | constexpr static KbKey Kb_5 = KbKey::Flag(31); | ||||||
|  | constexpr static KbKey Kb_6 = KbKey::Flag(32); | ||||||
|  | constexpr static KbKey Kb_7 = KbKey::Flag(33); | ||||||
|  | constexpr static KbKey Kb_8 = KbKey::Flag(34); | ||||||
|  | constexpr static KbKey Kb_9 = KbKey::Flag(35); | ||||||
|  | constexpr static KbKey Kb_0 = KbKey::Flag(36); | ||||||
|  | constexpr static KbKey Kb_F1 = KbKey::Flag(37); | ||||||
|  | constexpr static KbKey Kb_F2 = KbKey::Flag(38); | ||||||
|  | constexpr static KbKey Kb_F3 = KbKey::Flag(39); | ||||||
|  | constexpr static KbKey Kb_F4 = KbKey::Flag(40); | ||||||
|  | constexpr static KbKey Kb_F5 = KbKey::Flag(41); | ||||||
|  | constexpr static KbKey Kb_F6 = KbKey::Flag(42); | ||||||
|  | constexpr static KbKey Kb_F7 = KbKey::Flag(43); | ||||||
|  | constexpr static KbKey Kb_F8 = KbKey::Flag(44); | ||||||
|  | constexpr static KbKey Kb_F9 = KbKey::Flag(45); | ||||||
|  | constexpr static KbKey Kb_F10 = KbKey::Flag(46); | ||||||
|  | constexpr static KbKey Kb_F11 = KbKey::Flag(47); | ||||||
|  | constexpr static KbKey Kb_F12 = KbKey::Flag(48); | ||||||
|  | constexpr static KbKey Kb_MouseLeft = KbKey::Flag(120); | ||||||
|  | }  // namespace HidKb | ||||||
|  | class HidDriver { | ||||||
|  |  public: | ||||||
|  |   enum Flags : u32 { | ||||||
|  |     Flags_None = 0, | ||||||
|  |     FLags_HasGamepad = 1 << 0, | ||||||
|  |     Flags_HasKeyboard = 1 << 1, | ||||||
|  |     Flags_HasTouch = 1 << 2, | ||||||
|  |     Flags_HasMouse = 1 << 3, | ||||||
|  |   }; | ||||||
|  |   // Todo: Name to GpKey (GamepadKey) | ||||||
|  |   /** Key [Controller] */ | ||||||
|  |   enum Key : u32 { | ||||||
|  |     No = 0,                    ///< No Key | ||||||
|  |     A = 1 << 0,                ///< A | ||||||
|  |     B = 1 << 1,                ///< B | ||||||
|  |     X = 1 << 2,                ///< X | ||||||
|  |     Y = 1 << 3,                ///< Y | ||||||
|  |     Start = 1 << 4,            ///< Start | ||||||
|  |     Select = 1 << 5,           ///< Select | ||||||
|  |     L = 1 << 6,                ///< L | ||||||
|  |     R = 1 << 7,                ///< R | ||||||
|  |     DUp = 1 << 8,              ///< Dpad Up | ||||||
|  |     DDown = 1 << 9,            ///< Dpad down | ||||||
|  |     DLeft = 1 << 10,           ///< Dpad left | ||||||
|  |     DRight = 1 << 11,          ///< Dpad right | ||||||
|  |     CPUp = 1 << 12,            ///< Cpad up | ||||||
|  |     CPDown = 1 << 13,          ///< cpad down | ||||||
|  |     CPLeft = 1 << 14,          ///< cpad left | ||||||
|  |     CPRight = 1 << 15,         ///< Cpad right | ||||||
|  |     CSUp = 1 << 16,            ///< Cstick up | ||||||
|  |     CSDown = 1 << 17,          ///< cstick down | ||||||
|  |     CSLeft = 1 << 18,          ///< cstick left | ||||||
|  |     CSRight = 1 << 19,         ///< cstick right | ||||||
|  |     ZL = 1 << 20,              ///< ZL | ||||||
|  |     ZR = 1 << 21,              ///< ZR | ||||||
|  |     Touch = 1 << 22,           ///< Touch | ||||||
|  |     Up = DUp | CPUp,           ///< DPad or CPad Up | ||||||
|  |     Down = DDown | CPDown,     ///< DPad or CPad Down | ||||||
|  |     Left = DLeft | CPLeft,     ///< DPad or CPad Left | ||||||
|  |     Right = DRight | CPRight,  ///< DPad or CPad Right | ||||||
|  |   }; | ||||||
|  |  | ||||||
|  |   using KbKey = HidKb::KbKey; | ||||||
|  |  | ||||||
|  |   /** Event */ | ||||||
|  |   enum Event { | ||||||
|  |     Event_Null, | ||||||
|  |     Event_Down,  ///< Key Pressed | ||||||
|  |     Event_Held,  ///< Key Held | ||||||
|  |     Event_Up,    ///< Key released | ||||||
|  |   }; | ||||||
|  |  | ||||||
|  |   HidDriver(const std::string& name = "NullHid") : pName(name) {}; | ||||||
|  |   virtual ~HidDriver() = default; | ||||||
|  |   PD_SHARED(HidDriver); | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Get Mouse Position | ||||||
|  |    * @return Mouse pos | ||||||
|  |    */ | ||||||
|  |   fvec2 MousePos() const { | ||||||
|  |     return pMouse[0]; | ||||||
|  |   } /** | ||||||
|  |      * Get Last Mouse Position (from last frame) | ||||||
|  |      * @return Mouse pos | ||||||
|  |      */ | ||||||
|  |   fvec2 MousePosLast() const { return pMouse[1]; } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Check for a Button Event | ||||||
|  |    * @param e Event Type | ||||||
|  |    * @param keys Keys to check for | ||||||
|  |    * @return if key(s) doing the requiested event | ||||||
|  |    */ | ||||||
|  |   bool IsEvent(Event e, Key keys); | ||||||
|  |   bool IsEvent(Event e, KbKey key); | ||||||
|  |   /** | ||||||
|  |    * Check for Key Press Event | ||||||
|  |    * @param keys set of keys | ||||||
|  |    * @return true if key is pressed | ||||||
|  |    */ | ||||||
|  |   bool IsDown(Key keys) const { return KeyEvents[0].at(Event_Down) & keys; } | ||||||
|  |   /** | ||||||
|  |    * Check for Key Held Event | ||||||
|  |    * @param keys set of keys | ||||||
|  |    * @return true if key is held | ||||||
|  |    */ | ||||||
|  |   bool IsHeld(Key keys) const { return KeyEvents[0].at(Event_Held) & keys; } | ||||||
|  |   /** | ||||||
|  |    * Check for Key Release Event | ||||||
|  |    * @param keys set of keys | ||||||
|  |    * @return true if key is released | ||||||
|  |    */ | ||||||
|  |   bool IsUp(Key keys) const { return KeyEvents[0].at(Event_Up) & keys; } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Sett all keyevents to 0 | ||||||
|  |    */ | ||||||
|  |   void Clear() { | ||||||
|  |     for (int i = 0; i < 2; i++) { | ||||||
|  |       KeyEvents[i][Event_Down] = 0; | ||||||
|  |       KeyEvents[i][Event_Up] = 0; | ||||||
|  |       KeyEvents[i][Event_Held] = 0; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Lock input driver | ||||||
|  |    * @param v lock or not lock | ||||||
|  |    */ | ||||||
|  |   void Lock(bool v) { | ||||||
|  |     if (v != pLocked) { | ||||||
|  |       SwapTab(); | ||||||
|  |     } | ||||||
|  |     pLocked = v; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Check if Driver is locked | ||||||
|  |    * @return true if locked | ||||||
|  |    */ | ||||||
|  |   bool Locked() const { return pLocked; } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Lock Input Driver | ||||||
|  |    */ | ||||||
|  |   void Lock() { | ||||||
|  |     if (!pLocked) { | ||||||
|  |       SwapTab(); | ||||||
|  |     } | ||||||
|  |     pLocked = true; | ||||||
|  |   } | ||||||
|  |   /** | ||||||
|  |    * Unlock Input Driver | ||||||
|  |    */ | ||||||
|  |   void Unlock() { | ||||||
|  |     if (pLocked) { | ||||||
|  |       SwapTab(); | ||||||
|  |     } | ||||||
|  |     pLocked = false; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Template Update Function for a device specific driver | ||||||
|  |    */ | ||||||
|  |   virtual void Update(); | ||||||
|  |   /** | ||||||
|  |    * Get Text from Keyboard | ||||||
|  |    */ | ||||||
|  |   virtual void GetInputStr(std::string& str) {} | ||||||
|  |  | ||||||
|  |   /** Data Section */ | ||||||
|  |  | ||||||
|  |   /** Backend Identification Name */ | ||||||
|  |   const std::string pName; | ||||||
|  |  | ||||||
|  |   /** Flags */ | ||||||
|  |   u32 Flags = 0; | ||||||
|  |  | ||||||
|  |   /** Key Binds Map */ | ||||||
|  |   std::unordered_map<u32, u32> pBinds; | ||||||
|  |   std::unordered_map<u128, u128> pKbBinds; | ||||||
|  |   /** 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]; | ||||||
|  |   /** Keyboard Key Event Table Setup */ | ||||||
|  |   std::unordered_map<Event, u128> KbKeyEvents[2]; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | /** Static Hid Controller */ | ||||||
|  | class Hid { | ||||||
|  |  public: | ||||||
|  |   Hid() = default; | ||||||
|  |   ~Hid() = default; | ||||||
|  |  | ||||||
|  |   /** Referenec to Drivers enums */ | ||||||
|  |   using Key = HidDriver::Key; | ||||||
|  |   using KbKey = HidKb::KbKey; | ||||||
|  |   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 IsEvent(Event e, KbKey key) { return pHid->IsEvent(e, key); } | ||||||
|  |   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 u32 GetFlags() { return pHid->Flags; } | ||||||
|  |   static void GetStrInput(std::string& str) { pHid->GetInputStr(str); } | ||||||
|  |  | ||||||
|  |   static HidDriver::Ref pHid; | ||||||
|  | }; | ||||||
|  | }  // 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); | ||||||
| PD_CORE_API u64 GetTime(); |   bool TraceExist(const std::string& id); | ||||||
| /**
 | 
 | ||||||
|  * Get Current Time in Nanoseconds |   TraceMap pTraces; | ||||||
|  * @return 64Bit value of nanos | }; | ||||||
|  */ | 
 | ||||||
| PD_CORE_API 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; | ||||||
|  */ | 
 | ||||||
| PD_CORE_API 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(); | ||||||
|  */ |     } | ||||||
| PD_CORE_API 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(); } | ||||||
| PD_CORE_API 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
 | ||||||
							
								
								
									
										26
									
								
								include/pd/drivers/pd_p_api.hpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										26
									
								
								include/pd/drivers/pd_p_api.hpp
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | #pragma once | ||||||
|  |  | ||||||
|  | /* | ||||||
|  | MIT License | ||||||
|  | Copyright (c) 2024 - 2025 René Amthor (tobid7) | ||||||
|  |  | ||||||
|  | Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
|  | of this software and associated documentation files (the "Software"), to deal | ||||||
|  | in the Software without restriction, including without limitation the rights | ||||||
|  | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||
|  | copies of the Software, and to permit persons to whom the Software is | ||||||
|  | furnished to do so, subject to the following conditions: | ||||||
|  |  | ||||||
|  | The above copyright notice and this permission notice shall be included in all | ||||||
|  | copies or substantial portions of the Software. | ||||||
|  |  | ||||||
|  | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||
|  | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||
|  | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||
|  | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||
|  | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||
|  | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||
|  | SOFTWARE. | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | #define PD_DEF_EXP(x, y) x y = nullptr | ||||||
							
								
								
									
										0
									
								
								include/pd/external/json.hpp
									
									
									
									
										vendored
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										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
									
								
							
							
								
								
									
										168
									
								
								include/pd/image/image.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										168
									
								
								include/pd/image/image.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,82 +1,88 @@ | |||||||
| #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/core.hpp> | #include <pd/core/core.hpp> | ||||||
| #include <pd/image/pd_p_api.hpp> | #include <pd/image/pd_p_api.hpp> | ||||||
|  |  | ||||||
| namespace PD { | namespace PD { | ||||||
| class PD_IMAGE_API Image : public SmartCtor<Image> { | class PD_IMAGE_API Image { | ||||||
|  public: |  public: | ||||||
|   enum Format { |   enum Format { | ||||||
|     RGBA,    // bpp == 4 |     RGBA,    // bpp == 4 | ||||||
|     RGB,     // bpp == 3 |     RGB,     // bpp == 3 | ||||||
|     RGB565,  // bpp == 2 (not supported in laoding) |     RGB565,  // bpp == 2 (not supported in laoding) | ||||||
|     BGR,     // bpp == 3 |     BGR,     // bpp == 3 | ||||||
|     ABGR     // bpp == 4 |     ABGR,    // bpp == 4 | ||||||
|   }; |     BGRA,    // bpp == 4 | ||||||
|   Image() = default; |   }; | ||||||
|   Image(const std::string& path) { this->Load(path); } |   Image() = default; | ||||||
|   Image(const std::vector<u8>& buf) { this->Load(buf); } |   Image(const std::string& path) { this->Load(path); } | ||||||
|   Image(const std::vector<u8>& buf, int w, int h, int bpp = 4) { |   Image(const std::vector<u8>& buf) { this->Load(buf); } | ||||||
|     this->Copy(buf, w, h, bpp); |   Image(const std::vector<u8>& buf, int w, int h, int bpp = 4) { | ||||||
|   } |     this->Copy(buf, w, h, bpp); | ||||||
|   ~Image() = default; |   } | ||||||
|  |   ~Image() = default; | ||||||
|   void Load(const std::string& path); |  | ||||||
|   void Load(const std::vector<u8>& buf); |   PD_SHARED(Image) | ||||||
|   void Copy(const std::vector<u8>& buf, int w, int h, int bpp = 4); |  | ||||||
|  |   void Load(const std::string& path); | ||||||
|   std::vector<PD::u8>& GetBuffer() { return pBuffer; } |   void Load(const std::vector<u8>& buf); | ||||||
|   std::vector<PD::u8> GetBuffer() const { return pBuffer; } |   void Copy(const std::vector<u8>& buf, int w, int h, int bpp = 4); | ||||||
|  |  | ||||||
|   int Width() const { return pWidth; } |   std::vector<PD::u8>& GetBuffer() { return pBuffer; } | ||||||
|   int Height() const { return pHeight; } |   std::vector<PD::u8> GetBuffer() const { return pBuffer; } | ||||||
|   Format Fmt() const { return pFmt; } |  | ||||||
|  |   int Width() const { return pWidth; } | ||||||
|   u8& operator[](int idx) { return pBuffer[idx]; } |   int Height() const { return pHeight; } | ||||||
|   u8 operator[](int idx) const { return pBuffer[idx]; } |   Format Fmt() const { return pFmt; } | ||||||
|  |  | ||||||
|   // Probably these make th eabove ones useless |   void FlipVertical(); | ||||||
|  |   void FlipHorizontal(); | ||||||
|   operator std::vector<PD::u8>&() { return pBuffer; } |  | ||||||
|   operator std::vector<PD::u8>() const { return pBuffer; } |   u8& operator[](int idx) { return pBuffer[idx]; } | ||||||
|  |   u8 operator[](int idx) const { return pBuffer[idx]; } | ||||||
|   static void Convert(Image::Ref img, Image::Format dst); |  | ||||||
|   static void ReTile(Image::Ref img, |   // Probably these make th eabove ones useless | ||||||
|                      std::function<u32(int x, int y, int w)> src, |  | ||||||
|                      std::function<u32(int x, int y, int w)> dst); |   operator std::vector<PD::u8>&() { return pBuffer; } | ||||||
|   static int Fmt2Bpp(Format fmt); |   operator std::vector<PD::u8>() const { return pBuffer; } | ||||||
|  |  | ||||||
|   std::vector<PD::u8> pBuffer; |   static void Convert(Image::Ref img, Image::Format dst); | ||||||
|   int pWidth; |   static void ReTile(Image::Ref img, | ||||||
|   int pHeight; |                      std::function<u32(int x, int y, int w)> src, | ||||||
|   Format pFmt = Format::RGBA; |                      std::function<u32(int x, int y, int w)> dst); | ||||||
|  |   static int Fmt2Bpp(Format fmt); | ||||||
|  private: |  | ||||||
|   /** Leftover variable used for stbi_load */ |   std::vector<PD::u8> pBuffer; | ||||||
|   int fmt = 0; |   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/core.hpp> | #include <pd/core/core.hpp> | ||||||
| #include <pd/image/pd_p_api.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 | ||||||
|  */ |  */ | ||||||
| PD_IMAGE_API 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 | ||||||
|  */ |  */ | ||||||
| PD_IMAGE_API 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 | ||||||
|  */ |  */ | ||||||
| PD_IMAGE_API 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 | ||||||
							
								
								
									
										162
									
								
								include/pd/image/img_convert.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										162
									
								
								include/pd/image/img_convert.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,82 +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/core.hpp> | #include <pd/core/core.hpp> | ||||||
| #include <pd/image/image.hpp> | #include <pd/image/image.hpp> | ||||||
| #include <pd/image/pd_p_api.hpp> | #include <pd/image/pd_p_api.hpp> | ||||||
|  |  | ||||||
| namespace PD { | namespace PD { | ||||||
| /** | /** | ||||||
|  * Namespace containing function to convert images |  * Namespace containing function to convert images | ||||||
|  */ |  */ | ||||||
| namespace ImgConvert { | namespace ImgConvert { | ||||||
| /** | /** | ||||||
|  * Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255 |  * Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255 | ||||||
|  * to every pixel |  * to every pixel | ||||||
|  * @param out Result List |  * @param out Result List | ||||||
|  * @param in Input Buffer List (rgb24) |  * @param in Input Buffer List (rgb24) | ||||||
|  * @param w width of the image |  * @param w width of the image | ||||||
|  * @param h height of the image |  * @param h height of the image | ||||||
|  */ |  */ | ||||||
| PD_IMAGE_API | PD_IMAGE_API | ||||||
| void RGB24toRGBA32(std::vector<PD::u8> &out, const std::vector<u8> &in, | void RGB24toRGBA32(std::vector<PD::u8> &out, const std::vector<u8> &in, | ||||||
|                    const int &w, const int &h); |                    const int &w, const int &h); | ||||||
| PD_IMAGE_API | PD_IMAGE_API | ||||||
| void RGB32toRGBA24(std::vector<u8> &out, const std::vector<u8> &in, | void RGB32toRGBA24(std::vector<u8> &out, const std::vector<u8> &in, | ||||||
|                    const int &w, const int &h); |                    const int &w, const int &h); | ||||||
| /** | /** | ||||||
|  * Reverse 32 (RGBA -> ABGR || ABGR -> RGBA) |  * Reverse 32 (RGBA -> ABGR || ABGR -> RGBA) | ||||||
|  * @param buf Buffer to convert |  * @param buf Buffer to convert | ||||||
|  * @param w width |  * @param w width | ||||||
|  * @param h height |  * @param h height | ||||||
|  */ |  */ | ||||||
| PD_IMAGE_API void Reverse32(std::vector<u8> &buf, const int &w, const int &h); | 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); | 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 |  * Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255 | ||||||
|  * to every pixel |  * to every pixel | ||||||
|  * @param out Result List |  * @param out Result List | ||||||
|  * @param in Input Buffer List (rgb24) |  * @param in Input Buffer List (rgb24) | ||||||
|  * @param w width of the image |  * @param w width of the image | ||||||
|  * @param h height of the image |  * @param h height of the image | ||||||
|  */ |  */ | ||||||
| PD_IMAGE_API | PD_IMAGE_API | ||||||
| void RGB24toRGBA32(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w, | void RGB24toRGBA32(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w, | ||||||
|                    const int &h); |                    const int &h); | ||||||
| PD_IMAGE_API | PD_IMAGE_API | ||||||
| void RGB32toRGBA24(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w, | void RGB32toRGBA24(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w, | ||||||
|                    const int &h); |                    const int &h); | ||||||
| /** | /** | ||||||
|  * Reverse 32 (RGBA -> ABGR || ABGR -> RGBA) |  * Reverse 32 (RGBA -> ABGR || ABGR -> RGBA) | ||||||
|  * @param buf Buffer to convert |  * @param buf Buffer to convert | ||||||
|  * @param w width |  * @param w width | ||||||
|  * @param h height |  * @param h height | ||||||
|  */ |  */ | ||||||
| PD_IMAGE_API void Reverse32(PD::Vec<u8> &buf, const int &w, const int &h); | 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); | PD_IMAGE_API void ReverseBuf(PD::Vec<u8> &buf, size_t bpp, int w, int h); | ||||||
| }  // namespace ImgConvert | }  // namespace ImgConvert | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										9
									
								
								include/pd/image/pd_p_api.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										9
									
								
								include/pd/image/pd_p_api.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -2,8 +2,7 @@ | |||||||
|  |  | ||||||
| /* | /* | ||||||
| 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 | ||||||
| @@ -22,9 +21,9 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 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. | ||||||
| */ |  */ | ||||||
|  |  | ||||||
| #pragma once | /** Generated with ppam */ | ||||||
|  |  | ||||||
| #ifdef _WIN32  // Windows (MSVC Tested) | #ifdef _WIN32  // Windows (MSVC Tested) | ||||||
| #ifdef PD_IMAGE_BUILD_SHARED | #ifdef PD_IMAGE_BUILD_SHARED | ||||||
| @@ -49,4 +48,4 @@ SOFTWARE. | |||||||
| #define PD_IMAGE_API | #define PD_IMAGE_API | ||||||
| #else | #else | ||||||
| #define PD_IMAGE_API | #define PD_IMAGE_API | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -1,76 +0,0 @@ | |||||||
| #pragma once |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| MIT License |  | ||||||
|  |  | ||||||
| Copyright (c) 2024 - 2025 tobid7 |  | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
| of this software and associated documentation files (the "Software"), to deal |  | ||||||
| in the Software without restriction, including without limitation the rights |  | ||||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
| copies of the Software, and to permit persons to whom the Software is |  | ||||||
| furnished to do so, subject to the following conditions: |  | ||||||
|  |  | ||||||
| The above copyright notice and this permission notice shall be included in all |  | ||||||
| copies or substantial portions of the Software. |  | ||||||
|  |  | ||||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
| SOFTWARE. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| #include <pd/core/core.hpp> |  | ||||||
| #include <pd/lithium/command.hpp> |  | ||||||
| #include <pd/lithium/rect.hpp> |  | ||||||
| #include <pd/lithium/texture.hpp> |  | ||||||
|  |  | ||||||
| using LIBackendFlags = PD::u32; |  | ||||||
| enum LIBackendFlags_ { |  | ||||||
|   LIBackendFlags_None = 0, |  | ||||||
|   LIBackendFlags_FlipUV_Y = 1 << 0,  // Essential for Font Loading |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| namespace PD { |  | ||||||
| namespace LI { |  | ||||||
| class Backend { |  | ||||||
|  public: |  | ||||||
|   Backend(const std::string& name = "NullBackend") : pName(name) {} |  | ||||||
|   ~Backend() = default; |  | ||||||
|   // Using Legacy SmartCTOR API here |  | ||||||
|   PD_SMART_CTOR(Backend) |  | ||||||
|  |  | ||||||
|   virtual void Init() {} |  | ||||||
|   virtual void Deinit() {} |  | ||||||
|   virtual void NewFrame() {} |  | ||||||
|  |  | ||||||
|   virtual void BindTexture(TexAddress addr) {} |  | ||||||
|  |  | ||||||
|   virtual void RenderDrawData(const Vec<Command::Ref>& Commands) {} |  | ||||||
|  |  | ||||||
|   virtual Texture::Ref LoadTexture( |  | ||||||
|       const std::vector<PD::u8>& pixels, int w, int h, |  | ||||||
|       Texture::Type type = Texture::Type::RGBA32, |  | ||||||
|       Texture::Filter filter = Texture::Filter::LINEAR) { |  | ||||||
|     // Texture loading not supported (when this func not get override) |  | ||||||
|     return nullptr; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   /** Backend identification name */ |  | ||||||
|   const std::string pName = "NullBackend"; |  | ||||||
|   LIBackendFlags Flags = 0; |  | ||||||
|   ivec2 ViewPort; |  | ||||||
|   fvec4 ClearColor; |  | ||||||
|   // Optional Index Counter |  | ||||||
|   int IndexCounter = 0; |  | ||||||
|   // Optional Vertex Counter |  | ||||||
|   int VertexCounter = 0; |  | ||||||
|   // Optional Frame Counter |  | ||||||
|   int FrameCounter = 0; |  | ||||||
| }; |  | ||||||
| }  // namespace LI |  | ||||||
| }  // namespace PD |  | ||||||
							
								
								
									
										28
									
								
								include/pd/lithium/command.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										28
									
								
								include/pd/lithium/command.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -2,8 +2,7 @@ | |||||||
|  |  | ||||||
| /* | /* | ||||||
| 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 | ||||||
| @@ -25,38 +24,35 @@ SOFTWARE. | |||||||
|  */ |  */ | ||||||
|  |  | ||||||
| #include <pd/core/core.hpp> | #include <pd/core/core.hpp> | ||||||
| // #include <pd/lithium/flags.hpp> |  | ||||||
| #include <pd/lithium/texture.hpp> | #include <pd/lithium/texture.hpp> | ||||||
| #include <pd/lithium/vertex.hpp> | #include <pd/lithium/vertex.hpp> | ||||||
|  |  | ||||||
| namespace PD { | namespace PD { | ||||||
| namespace LI { | namespace Li { | ||||||
| /** | class Command { | ||||||
|  * Lithium Draw Command (containing a list of vertex and index data |  | ||||||
|  * only for this specific command itself) |  | ||||||
|  */ |  | ||||||
| class Command : public SmartCtor<Command> { |  | ||||||
|  public: |  public: | ||||||
|   Command() = default; |   Command() = default; | ||||||
|   ~Command() = default; |   ~Command() = default; | ||||||
|  |  | ||||||
|   Command& AppendIndex(u16 idx) { |   PD_UNIQUE(Command); | ||||||
|  |  | ||||||
|  |   Command& AddIdx(const u16& idx) { | ||||||
|     IndexBuffer.Add(VertexBuffer.Size() + idx); |     IndexBuffer.Add(VertexBuffer.Size() + idx); | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   Command& AppendVertex(const Vertex& v) { |   Command& AddVtx(const Vertex& v) { | ||||||
|     VertexBuffer.Add(v); |     VertexBuffer.Add(std::move(v)); | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   Vec<Vertex> VertexBuffer; |   PD::Vec<Vertex> VertexBuffer; | ||||||
|   Vec<u16> IndexBuffer; |   PD::Vec<u16> IndexBuffer; | ||||||
|   ivec4 ScissorRect; |   ivec4 ScissorRect; | ||||||
|   bool ScissorEnabled = false; |   bool ScissorOn = false; | ||||||
|   int Layer; |   int Layer; | ||||||
|   int Index; |   int Index; | ||||||
|   Texture::Ref Tex; |   Texture::Ref Tex; | ||||||
| }; | }; | ||||||
| }  // namespace LI | }  // namespace Li | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										94
									
								
								include/pd/lithium/drawlist.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										94
									
								
								include/pd/lithium/drawlist.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -28,24 +28,55 @@ SOFTWARE. | |||||||
| #include <pd/lithium/font.hpp> | #include <pd/lithium/font.hpp> | ||||||
| #include <pd/lithium/pd_p_api.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 PD { | ||||||
| namespace LI { | namespace Li { | ||||||
| class PD_LITHIUM_API DrawList : public SmartCtor<DrawList> { | class PD_LITHIUM_API DrawList { | ||||||
|  public: |  public: | ||||||
|   DrawList(Texture::Ref solid) { |   DrawList() { DrawSolid(); } | ||||||
|     WhitePixel = solid; |   ~DrawList() { pDrawList.clear(); } | ||||||
|     CurrentTex = solid; |  | ||||||
|   } |   /** Require Copy and Move Constructors */ | ||||||
|   ~DrawList() {} |  | ||||||
|  |   DrawList(const DrawList&) = delete; | ||||||
|  |   DrawList& operator=(const DrawList&) = delete; | ||||||
|  |  | ||||||
|  |   DrawList(DrawList&&) noexcept = default; | ||||||
|  |   DrawList& operator=(DrawList&&) noexcept = default; | ||||||
|  |  | ||||||
|  |   PD_SHARED(DrawList); | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Append an input drawlist on top of this one | ||||||
|  |    * This Function will clear the Input list to make sure | ||||||
|  |    * THat the moved memory blocks don't get used | ||||||
|  |    * @param list DrawList to move into current | ||||||
|  |    */ | ||||||
|  |   void Merge(DrawList::Ref list); | ||||||
|  |  | ||||||
|   Command::Ref PreGenerateCmd(); |   Command::Ref PreGenerateCmd(); | ||||||
|   void AddCommand(Command::Ref v) { pDrawList.Add(v); } |   void AddCommand(Command::Ref v); | ||||||
|   void Clear() { pDrawList.Clear(); } |   void Clear(); | ||||||
|  |  | ||||||
|   void SetFont(Font::Ref font) { pCurrentFont = font; } |   void SetFont(Font::Ref font) { pCurrentFont = font; } | ||||||
|   void SetFontScale(float scale) { pFontScale = scale; } |   void SetFontScale(float scale) { pFontScale = scale; } | ||||||
|  |  | ||||||
|   void DrawSolid() { CurrentTex = WhitePixel; } |   void DrawSolid(); | ||||||
|   void DrawTexture(Texture::Ref tex) { CurrentTex = tex; } |   void DrawTexture(Texture::Ref tex) { CurrentTex = tex; } | ||||||
|  |  | ||||||
|   // SECTION: Draw API // |   // SECTION: Draw API // | ||||||
| @@ -62,7 +93,12 @@ class PD_LITHIUM_API DrawList : public SmartCtor<DrawList> { | |||||||
|   void DrawCircleFilled(const fvec2& center, float rad, u32 color, |   void DrawCircleFilled(const fvec2& center, float rad, u32 color, | ||||||
|                         int num_segments); |                         int num_segments); | ||||||
|   void DrawText(const fvec2& p, const std::string& text, u32 color); |   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 |    * Take list of points and display it as a line on screen | ||||||
|    * @param points List of Positions |    * @param points List of Positions | ||||||
| @@ -126,20 +162,40 @@ class PD_LITHIUM_API DrawList : public SmartCtor<DrawList> { | |||||||
|   } |   } | ||||||
|   void PathArcToN(const fvec2& c, float radius, float a_min, float a_max, |   void PathArcToN(const fvec2& c, float radius, float a_min, float a_max, | ||||||
|                   int segments); |                   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) |   /// @brief Create a Path Rect (uses to Positions instead of Pos/Size) | ||||||
|   /// @param a Top Left Position |   /// @param a Top Left Position | ||||||
|   /// @param b Bottom Right Position |   /// @param b Bottom Right Position | ||||||
|   /// @param rounding rounding |   /// @param rounding rounding | ||||||
|   /// @param flags DrawFlags (for special rounding rules) |   /// @param flags DrawFlags (for special rounding rules) | ||||||
|   void PathRect(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0); |   void PathRectEx(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0); | ||||||
|  |  | ||||||
|   int Layer = 0; |   void PushClipRect(const fvec4& cr) { pClipRects.Push(cr); } | ||||||
|  |   void PopClipRect() { | ||||||
|  |     if (pClipRects.IsEmpty()) { | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |     pClipRects.Pop(); | ||||||
|  |   } | ||||||
|  |   /** One linear Clip rect Setup */ | ||||||
|  |   void pClipCmd(Command* cmd); | ||||||
|  |  | ||||||
|  |   /** Data Section */ | ||||||
|  |  | ||||||
|  |   Stack<fvec4> pClipRects; | ||||||
|  |   int Layer; | ||||||
|   float pFontScale = 0.7f; |   float pFontScale = 0.7f; | ||||||
|   Font::Ref pCurrentFont = nullptr; |   Font::Ref pCurrentFont; | ||||||
|   Texture::Ref CurrentTex = nullptr; |   Texture::Ref CurrentTex; | ||||||
|   Texture::Ref WhitePixel = nullptr; |   std::vector<Command::Ref> pDrawList; | ||||||
|   PD::Vec<Command::Ref> pDrawList; |  | ||||||
|   PD::Vec<fvec2> pPath; |   PD::Vec<fvec2> pPath; | ||||||
|  |   u32 pNumIndices = 0; | ||||||
|  |   u32 pNumVertices = 0; | ||||||
| }; | }; | ||||||
| }  // namespace LI | }  // namespace Li | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
|   | |||||||
							
								
								
									
										69
									
								
								include/pd/lithium/font.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										69
									
								
								include/pd/lithium/font.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -25,26 +25,25 @@ SOFTWARE. | |||||||
|  */ |  */ | ||||||
|  |  | ||||||
| #include <pd/core/core.hpp> | #include <pd/core/core.hpp> | ||||||
| #include <pd/lithium/backend.hpp> | #include <pd/lithium/command.hpp> | ||||||
| #include <pd/lithium/pd_p_api.hpp> | #include <pd/lithium/pd_p_api.hpp> | ||||||
| #include <pd/lithium/rect.hpp> | #include <pd/lithium/rect.hpp> | ||||||
| #include <pd/lithium/texture.hpp> | #include <pd/lithium/texture.hpp> | ||||||
|  |  | ||||||
| using LITextFlags = PD::u32; | using LiTextFlags = PD::u32; | ||||||
| enum LITextFlags_ { | enum LiTextFlags_ { | ||||||
|   LITextFlags_None = 0,             ///< Do nothing |   LiTextFlags_None = 0,             ///< Do nothing | ||||||
|   LITextFlags_AlignRight = 1 << 0,  ///< Align Right of position |   LiTextFlags_AlignRight = 1 << 0,  ///< Align Right of position | ||||||
|   LITextFlags_AlignMid = 1 << 1,    ///< Align in the middle of pos and box |   LiTextFlags_AlignMid = 1 << 1,    ///< Align in the middle of pos and box | ||||||
|   LITextFlags_Shaddow = 1 << 2,     ///< Draws the text twice to create shaddow |   LiTextFlags_Shaddow = 1 << 2,     ///< Draws the text twice to create shaddow | ||||||
|   LITextFlags_Wrap = 1 << 3,        ///< Wrap Text: May be runs better with TMS |   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_Short = 1 << 4,       ///< Short Text: May be runs better with TMS | ||||||
|   LITextFlags_Scroll = 1 << 5,      ///< Not implemented [scoll text if to long] |   LiTextFlags_Scroll = 1 << 5,      ///< Not implemented [scoll text if to long] | ||||||
| }; | }; | ||||||
|  |  | ||||||
| namespace PD { | namespace PD { | ||||||
| namespace LI { | namespace Li { | ||||||
| /** Font Loader for Lithium */ | class PD_LITHIUM_API Font { | ||||||
| class PD_LITHIUM_API Font : public SmartCtor<Font> { |  | ||||||
|  public: |  public: | ||||||
|   /** Codepoint Data holder */ |   /** Codepoint Data holder */ | ||||||
|   struct Codepoint { |   struct Codepoint { | ||||||
| @@ -55,14 +54,31 @@ class PD_LITHIUM_API Font : public SmartCtor<Font> { | |||||||
|     float Offset = 0.f; |     float Offset = 0.f; | ||||||
|     bool pInvalid = false; |     bool pInvalid = false; | ||||||
|   }; |   }; | ||||||
|   Font(Backend::Ref backend) { pBackend = backend; }; |  | ||||||
|  |   /** Constructore doesnt need Backand anymore */ | ||||||
|  |   Font() = default; | ||||||
|   ~Font() = default; |   ~Font() = default; | ||||||
|  |  | ||||||
|  |   PD_SHARED(Font); | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Load a TTF File |    * Load a TTF File | ||||||
|    * @param path Path to the TTF file |    * @param path Path to the TTF file | ||||||
|    * @param px_height Pixelheight of the codepoints (limit by 64) |    * @param px_height Pixelheight of the codepoints (limit by 64) | ||||||
|    */ |    */ | ||||||
|   void LoadTTF(const std::string& path, int px_height = 32); |   void LoadTTF(const std::string& path, int px_height = 32); | ||||||
|  |   /** | ||||||
|  |    * Load a TTF File from Memory | ||||||
|  |    * @param data File data | ||||||
|  |    * @param px_height Pixelheight of the codepoints (limit by 64) | ||||||
|  |    */ | ||||||
|  |   void LoadTTF(const std::vector<u8>& data, int px_height = 32); | ||||||
|  |   /** | ||||||
|  |    * Function that loads a default integrated font... | ||||||
|  |    * This will only work if PD_LI_INCLUDE_FONTS was set | ||||||
|  |    * on lithium build cause otherwise the font data is not included | ||||||
|  |    */ | ||||||
|  |   void LoadDefaultFont(int id = 0, int pixel_height = 32); | ||||||
|   /** |   /** | ||||||
|    * Getter for Codepoint reference |    * Getter for Codepoint reference | ||||||
|    * @return codepoint dataholder reference |    * @return codepoint dataholder reference | ||||||
| @@ -76,20 +92,25 @@ class PD_LITHIUM_API Font : public SmartCtor<Font> { | |||||||
|   /** |   /** | ||||||
|    * Extended Draw Text Function that vreates a Command List |    * Extended Draw Text Function that vreates a Command List | ||||||
|    */ |    */ | ||||||
|   void CmdTextEx(Vec<Command::Ref>& cmds, const fvec2& pos, u32 color, |   void CmdTextEx(std::vector<Command::Ref>& cmds, const fvec2& pos, u32 color, | ||||||
|                  float scale, const std::string& text, LITextFlags flags = 0, |                  float scale, const std::string& text, LiTextFlags flags = 0, | ||||||
|                  const fvec2& box = 0); |                  const fvec2& box = 0); | ||||||
|  |   /** | ||||||
|  |    * Utility function to create a font atlas | ||||||
|  |    * During TTF loading (Internal and should not be called) | ||||||
|  |    */ | ||||||
|  |   void pMakeAtlas(bool final, std::vector<u8>& font_tex, int texszs, | ||||||
|  |                   PD::Li::Texture::Ref tex); | ||||||
|  |  | ||||||
|   /** Pixelheight */ |   /** Data Section */ | ||||||
|   int PixelHeight; |   int PixelHeight; | ||||||
|   int DefaultPixelHeight = 24; |   int DefaultPixelHeight = 24; | ||||||
|  |  | ||||||
|  private: |  | ||||||
|   /** List of textures (codepoints are using) */ |  | ||||||
|   std::vector<Texture::Ref> Textures; |   std::vector<Texture::Ref> Textures; | ||||||
|   /** 32Bit Codepoint Dataholder Reference Map */ |   /** | ||||||
|   std::map<u32, Codepoint> CodeMap; |    * 32Bit Codepoint Dataholder reference map | ||||||
|   Backend::Ref pBackend = nullptr; |    * **Now using unordered map** | ||||||
|  |    */ | ||||||
|  |   std::unordered_map<u32, Codepoint> CodeMap; | ||||||
| }; | }; | ||||||
| }  // namespace LI | }  // namespace Li | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
| @@ -1,3 +1,5 @@ | |||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
| /*
 | /*
 | ||||||
| MIT License | MIT License | ||||||
| Copyright (c) 2024 - 2025 René Amthor (tobid7) | Copyright (c) 2024 - 2025 René Amthor (tobid7) | ||||||
| @@ -21,17 +23,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||||||
| SOFTWARE. | SOFTWARE. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <pd/overlays/overlay_mgr.hpp> | #ifdef PD_LI_INCLUDE_FONTS | ||||||
| 
 | 
 | ||||||
|  | #include <pd/core/common.hpp> | ||||||
|  | 
 | ||||||
|  | /** Generated with pdfm */ | ||||||
| namespace PD { | namespace PD { | ||||||
| void OverlayMgr::Push(Overlay::Ref overlay) { overlays.push_back(overlay); } | struct FontFileData { | ||||||
| void OverlayMgr::Update(float delta) { |   std::string Name; | ||||||
|   for (size_t i = 0; i < overlays.size(); i++) { |   u32 StartOff; | ||||||
|     if (overlays[i]->IsKilled()) { |   u32 Size; | ||||||
|       overlays.erase(overlays.begin() + i); | }; | ||||||
|       continue; | extern FontFileData pFontData[]; | ||||||
|     } | extern size_t pNumFonts; | ||||||
|     overlays[i]->Update(delta, ren, inp); | extern PD::u8 pFontsDataRaw[]; | ||||||
|   } | }   // namespace PD
 | ||||||
| } | #endif | ||||||
| }  // 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> | ||||||
							
								
								
									
										9
									
								
								include/pd/lithium/pd_p_api.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										9
									
								
								include/pd/lithium/pd_p_api.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -2,8 +2,7 @@ | |||||||
|  |  | ||||||
| /* | /* | ||||||
| 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 | ||||||
| @@ -22,9 +21,9 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 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. | ||||||
| */ |  */ | ||||||
|  |  | ||||||
| #pragma once | /** Generated with ppam */ | ||||||
|  |  | ||||||
| #ifdef _WIN32  // Windows (MSVC Tested) | #ifdef _WIN32  // Windows (MSVC Tested) | ||||||
| #ifdef PD_LITHIUM_BUILD_SHARED | #ifdef PD_LITHIUM_BUILD_SHARED | ||||||
| @@ -49,4 +48,4 @@ SOFTWARE. | |||||||
| #define PD_LITHIUM_API | #define PD_LITHIUM_API | ||||||
| #else | #else | ||||||
| #define PD_LITHIUM_API | #define PD_LITHIUM_API | ||||||
| #endif | #endif | ||||||
|   | |||||||
							
								
								
									
										105
									
								
								include/pd/lithium/rect.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										105
									
								
								include/pd/lithium/rect.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -26,24 +26,20 @@ SOFTWARE. | |||||||
| #include <pd/core/core.hpp> | #include <pd/core/core.hpp> | ||||||
|  |  | ||||||
| namespace PD { | namespace PD { | ||||||
| namespace LI { | namespace Li { | ||||||
| /** |  | ||||||
|  * Container that holds position of a rectangle's corners. |  | ||||||
|  */ |  | ||||||
| class Rect { | class Rect { | ||||||
|  public: |  public: | ||||||
|   Rect() = default; |   Rect() : Top(0), Bot(0) {} | ||||||
|  |   ~Rect() = default; | ||||||
|   /** |   /** | ||||||
|    * Constructor that initializes the rectangle using top and bottom positions. |    * Constructor that initializes the rectangle using top and bottom positions. | ||||||
|    * @param t Top left and right corner positions. |    * @param t Top left and right corner positions. | ||||||
|    * @param b Bottom left and right corner positions. |    * @param b Bottom left and right corner positions. | ||||||
|    */ |    */ | ||||||
|   Rect(const fvec4& t, const fvec4& b) { |   Rect(const fvec4& t, const fvec4& b) { | ||||||
|     top = t; |     Top = t; | ||||||
|     bot = b; |     Bot = b; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Constructor that initializes the rectangle using individual corner |    * Constructor that initializes the rectangle using individual corner | ||||||
|    * positions. |    * positions. | ||||||
| @@ -53,8 +49,8 @@ class Rect { | |||||||
|    * @param br Bottom right corner position. |    * @param br Bottom right corner position. | ||||||
|    */ |    */ | ||||||
|   Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br) { |   Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br) { | ||||||
|     top = fvec4(tl, tr); |     Top = fvec4(tl, tr); | ||||||
|     bot = fvec4(bl, br); |     Bot = fvec4(bl, br); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -66,67 +62,30 @@ class Rect { | |||||||
|    * @param uv Vec4 UV map. |    * @param uv Vec4 UV map. | ||||||
|    */ |    */ | ||||||
|   Rect(const fvec4& uv) { |   Rect(const fvec4& uv) { | ||||||
|     top = vec4(uv.x, uv.y, uv.z, uv.y); |     Top = vec4(uv.x, uv.y, uv.z, uv.y); | ||||||
|     bot = vec4(uv.x, uv.w, uv.z, uv.w); |     Bot = vec4(uv.x, uv.w, uv.z, uv.w); | ||||||
|   } |  | ||||||
|  |  | ||||||
|   ~Rect() = default; |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Get the top left and right corner positions. |  | ||||||
|    * @return Top positions. |  | ||||||
|    */ |  | ||||||
|   fvec4 Top() const { return top; } |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Get the bottom left and right corner positions. |  | ||||||
|    * @return Bottom positions. |  | ||||||
|    */ |  | ||||||
|   fvec4 Bot() const { return bot; } |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Set the top left and right corner positions. |  | ||||||
|    * @param v New top positions. |  | ||||||
|    * @return Reference to the updated Rect. |  | ||||||
|    */ |  | ||||||
|   Rect& Top(const fvec4& v) { |  | ||||||
|     top = v; |  | ||||||
|     return *this; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Set the bottom left and right corner positions. |  | ||||||
|    * @param v New bottom positions. |  | ||||||
|    * @return Reference to the updated Rect. |  | ||||||
|    */ |  | ||||||
|   Rect& Bot(const fvec4& v) { |  | ||||||
|     bot = v; |  | ||||||
|     return *this; |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Get the top-left corner position. |    * Get the top-left corner position. | ||||||
|    * @return Top-left position as vec2. |    * @return Top-left position as vec2. | ||||||
|    */ |    */ | ||||||
|   fvec2 TopLeft() const { return vec2(top.x, top.y); } |   fvec2 TopLeft() const { return fvec2(Top.x, Top.y); } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Get the top-right corner position. |    * Get the top-right corner position. | ||||||
|    * @return Top-right position as vec2. |    * @return Top-right position as vec2. | ||||||
|    */ |    */ | ||||||
|   fvec2 TopRight() const { return vec2(top.z, top.w); } |   fvec2 TopRight() const { return fvec2(Top.z, Top.w); } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Get the bottom-left corner position. |    * Get the bottom-left corner position. | ||||||
|    * @return Bottom-left position as vec2. |    * @return Bottom-left position as vec2. | ||||||
|    */ |    */ | ||||||
|   fvec2 BotLeft() const { return vec2(bot.x, bot.y); } |   fvec2 BotLeft() const { return fvec2(Bot.x, Bot.y); } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Get the bottom-right corner position. |    * Get the bottom-right corner position. | ||||||
|    * @return Bottom-right position as vec2. |    * @return Bottom-right position as vec2. | ||||||
|    */ |    */ | ||||||
|   fvec2 BotRight() const { return vec2(bot.z, bot.w); } |   fvec2 BotRight() const { return fvec2(Bot.z, Bot.w); } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Set the top-left corner position. |    * Set the top-left corner position. | ||||||
| @@ -134,8 +93,8 @@ class Rect { | |||||||
|    * @return Reference to the updated Rect. |    * @return Reference to the updated Rect. | ||||||
|    */ |    */ | ||||||
|   Rect& TopLeft(const fvec2& v) { |   Rect& TopLeft(const fvec2& v) { | ||||||
|     top.x = v.x; |     Top.x = v.x; | ||||||
|     top.y = v.y; |     Top.y = v.y; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -145,8 +104,8 @@ class Rect { | |||||||
|    * @return Reference to the updated Rect. |    * @return Reference to the updated Rect. | ||||||
|    */ |    */ | ||||||
|   Rect& TopRight(const fvec2& v) { |   Rect& TopRight(const fvec2& v) { | ||||||
|     top.z = v.x; |     Top.z = v.x; | ||||||
|     top.w = v.y; |     Top.w = v.y; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -156,8 +115,8 @@ class Rect { | |||||||
|    * @return Reference to the updated Rect. |    * @return Reference to the updated Rect. | ||||||
|    */ |    */ | ||||||
|   Rect& BotLeft(const fvec2& v) { |   Rect& BotLeft(const fvec2& v) { | ||||||
|     bot.x = v.x; |     Bot.x = v.x; | ||||||
|     bot.y = v.y; |     Bot.y = v.y; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -167,26 +126,22 @@ class Rect { | |||||||
|    * @return Reference to the updated Rect. |    * @return Reference to the updated Rect. | ||||||
|    */ |    */ | ||||||
|   Rect& BotRight(const fvec2& v) { |   Rect& BotRight(const fvec2& v) { | ||||||
|     bot.z = v.x; |     Bot.z = v.x; | ||||||
|     bot.w = v.y; |     Bot.w = v.y; | ||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Swap X and Y coordinates for all corners. |  | ||||||
|    * |  | ||||||
|    * - Used in SpiteSheet for the rotated images. |  | ||||||
|    */ |  | ||||||
|   void SwapVec2XY() { |   void SwapVec2XY() { | ||||||
|     top.SwapXY(); |     Top.SwapXY(); | ||||||
|     top.SwapZW(); |     Top.SwapZW(); | ||||||
|     bot.SwapXY(); |     Bot.SwapXY(); | ||||||
|     bot.SwapZW(); |     Bot.SwapZW(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  private: |   /** Data Section */ | ||||||
|   fvec4 top;  ///< Top left and right corner positions. |  | ||||||
|   fvec4 bot;  ///< Bottom left and right corner positions. |   fvec4 Top; | ||||||
|  |   fvec4 Bot; | ||||||
| }; | }; | ||||||
| }  // namespace LI | }  // namespace Li | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										43
									
								
								include/pd/lithium/renderer.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										43
									
								
								include/pd/lithium/renderer.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -24,37 +24,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||||||
| SOFTWARE. | SOFTWARE. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| #include <pd/lithium/backend.hpp> | #include <pd/drivers/drivers.hpp> | ||||||
| #include <pd/lithium/drawlist.hpp> |  | ||||||
| #include <pd/lithium/font.hpp> |  | ||||||
| #include <pd/lithium/pd_p_api.hpp> | #include <pd/lithium/pd_p_api.hpp> | ||||||
|  | #include <pd/lithium/rect.hpp> | ||||||
|  |  | ||||||
| namespace PD { | namespace PD { | ||||||
| namespace LI { | namespace Li { | ||||||
| class PD_LITHIUM_API Renderer : public SmartCtor<Renderer> { | /** | ||||||
|  |  * Static Class Render Setup Functions | ||||||
|  |  */ | ||||||
|  | class PD_LITHIUM_API Renderer { | ||||||
|  public: |  public: | ||||||
|   Renderer(Backend::Ref backend); |   Renderer() = default; | ||||||
|   ~Renderer() = default; |   ~Renderer() = default; | ||||||
|  |  | ||||||
|   void Render(); |  | ||||||
|  |  | ||||||
|   // SECTION: ADVANCED API |  | ||||||
|  |  | ||||||
|   void AddCommand(Command::Ref v) { DrawList.Add(v); } |  | ||||||
|   void RegisterDrawList(DrawList::Ref list) { pDrawLists.Add(list); } |  | ||||||
|   Command::Ref PreGenerateCmd(); |  | ||||||
|  |  | ||||||
|   // SECTION: Open Command and Object creation API |   // SECTION: Open Command and Object creation API | ||||||
|   static void RotateCorner(fvec2& pos, float sinus, float cosinus); |   static void RotateCorner(fvec2& pos, float s, float c); | ||||||
|   static Rect PrimRect(const fvec2& pos, const fvec2& size, float angle = 0.f); |   static Rect PrimRect(const fvec2& pos, const fvec2& size, float angle = 0.f); | ||||||
|   static Rect PrimLine(const fvec2& a, const fvec2& b, int thickness = 1); |   static Rect PrimLine(const fvec2& a, const fvec2& b, int thickness = 1); | ||||||
|   static void CmdQuad(Command::Ref cmd, const Rect& quad, const Rect& uv, |   static void CmdQuad(Command* cmd, const Rect& quad, const Rect& uv, | ||||||
|                       u32 color); |                       u32 color); | ||||||
|   static void CmdTriangle(Command::Ref cmd, const fvec2 a, const fvec2 b, |   static void CmdTriangle(Command* cmd, const fvec2 a, const fvec2 b, | ||||||
|                           const fvec2 c, u32 clr); |                           const fvec2 c, u32 clr); | ||||||
|   static void CmdPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0, |   static void CmdPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0, | ||||||
|                           int thickness = 1); |                           int thickness = 1); | ||||||
|   static void CmdConvexPolyFilled(Command::Ref cmd, const Vec<fvec2>& points, |   static void CmdConvexPolyFilled(Command* cmd, const Vec<fvec2>& points, | ||||||
|                                   u32 clr, Texture::Ref tex); |                                   u32 clr, Texture::Ref tex); | ||||||
|  |  | ||||||
|   // SECTION: InBounds Checks |   // SECTION: InBounds Checks | ||||||
| @@ -63,17 +57,6 @@ class PD_LITHIUM_API Renderer : public SmartCtor<Renderer> { | |||||||
|   static bool InBox(const fvec2& pos, const fvec4& area); |   static bool InBox(const fvec2& pos, const fvec4& area); | ||||||
|   static bool InBox(const fvec2& a, const fvec2& b, const fvec2& c, |   static bool InBox(const fvec2& a, const fvec2& b, const fvec2& c, | ||||||
|                     const fvec4& area); |                     const fvec4& area); | ||||||
|  |  | ||||||
|   // SECTION: Data // |  | ||||||
|  |  | ||||||
|   Texture::Ref WhitePixel = nullptr; |  | ||||||
|   Backend::Ref pBackend = nullptr; |  | ||||||
|   Texture::Ref CurrentTex = nullptr; |  | ||||||
|   int Layer = 0; |  | ||||||
|  |  | ||||||
|  private: |  | ||||||
|   PD::Vec<Command::Ref> DrawList; |  | ||||||
|   PD::Vec<DrawList::Ref> pDrawLists; |  | ||||||
| }; | }; | ||||||
| }  // namespace LI | }  // namespace Li | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										39
									
								
								include/pd/lithium/texture.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										39
									
								
								include/pd/lithium/texture.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -2,8 +2,7 @@ | |||||||
|  |  | ||||||
| /* | /* | ||||||
| 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 | ||||||
| @@ -28,49 +27,49 @@ SOFTWARE. | |||||||
| #include <pd/lithium/rect.hpp> | #include <pd/lithium/rect.hpp> | ||||||
|  |  | ||||||
| namespace PD { | namespace PD { | ||||||
| namespace LI { | namespace Li { | ||||||
|  | /** Use so address type for TexAddress */ | ||||||
| using TexAddress = uintptr_t; | using TexAddress = uintptr_t; | ||||||
| /** | class Texture { | ||||||
|  * Lithium Texture Data Holder |  | ||||||
|  * Memory management is handled by backend |  | ||||||
|  */ |  | ||||||
| class Texture : public SmartCtor<Texture> { |  | ||||||
|  public: |  public: | ||||||
|   /** Texture Type */ |   /** Texture Types */ | ||||||
|   enum Type { |   enum Type { | ||||||
|     RGBA32,  ///< RGBA 32 |     RGBA32,  ///< Rgba 32Bit | ||||||
|     RGB24,   ///< RGB24 |     RGB24,   ///< Rgb 24 Bit | ||||||
|     A8,      ///< A8 |     A8,      ///< A8 8Bit alpha | ||||||
|   }; |   }; | ||||||
|   /** Texture Filters */ |   /** Texture Filters */ | ||||||
|   enum Filter { |   enum Filter { | ||||||
|     NEAREST,  ///< Nearest |     NEAREST,  ///< Nearest | ||||||
|     LINEAR,   ///< Linear |     LINEAR,   ///< Linear | ||||||
|   }; |   }; | ||||||
|   /** Default constructor */ |   /** Constructor */ | ||||||
|   Texture() : UV(0.f, 0.f, 1.f, 1.f) {} |   Texture() : Address(0), Size(0), UV(fvec4(0.f, 0.f, 1.f, 1.f)) {} | ||||||
|   Texture(TexAddress addr, ivec2 size, |   Texture(TexAddress addr, ivec2 size, | ||||||
|           LI::Rect uv = fvec4(0.f, 0.f, 1.f, 1.f)) { |           Li::Rect uv = fvec4(0.f, 0.f, 1.f, 1.f)) { | ||||||
|     Address = addr; |     Address = addr; | ||||||
|     Size = size; |     Size = size; | ||||||
|     UV = uv; |     UV = uv; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   void CopyOther(Texture::Ref tex) { |   PD_SHARED(Texture); | ||||||
|  |  | ||||||
|  |   void CopyFrom(Texture::Ref tex) { | ||||||
|     Address = tex->Address; |     Address = tex->Address; | ||||||
|     Size = tex->Size; |     Size = tex->Size; | ||||||
|     UV = tex->UV; |     UV = tex->UV; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /** Left in Code getter (should be remoevd) */ | ||||||
|   ivec2 GetSize() const { return Size; } |   ivec2 GetSize() const { return Size; } | ||||||
|   LI::Rect GetUV() const { return UV; } |   Li::Rect GetUV() const { return UV; } | ||||||
|  |  | ||||||
|   operator ivec2() const { return Size; } |   operator ivec2() const { return Size; } | ||||||
|   operator LI::Rect() const { return UV; } |   operator Li::Rect() const { return UV; } | ||||||
|  |  | ||||||
|   TexAddress Address; |   TexAddress Address; | ||||||
|   ivec2 Size; |   ivec2 Size; | ||||||
|   LI::Rect UV; |   Li::Rect UV; | ||||||
| }; | }; | ||||||
| }  // namespace LI | }  // namespace Li | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
							
								
								
									
										10
									
								
								include/pd/lithium/vertex.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										10
									
								
								include/pd/lithium/vertex.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -2,8 +2,7 @@ | |||||||
|  |  | ||||||
| /* | /* | ||||||
| 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 | ||||||
| @@ -27,7 +26,7 @@ SOFTWARE. | |||||||
| #include <pd/core/core.hpp> | #include <pd/core/core.hpp> | ||||||
|  |  | ||||||
| namespace PD { | namespace PD { | ||||||
| namespace LI { | namespace Li { | ||||||
| class Vertex { | class Vertex { | ||||||
|  public: |  public: | ||||||
|   Vertex() {} |   Vertex() {} | ||||||
| @@ -40,9 +39,12 @@ class Vertex { | |||||||
|   ~Vertex() {} |   ~Vertex() {} | ||||||
|  |  | ||||||
|   // private: |   // private: | ||||||
|  |  | ||||||
|  |   /** Open Access Data Section */ | ||||||
|  |  | ||||||
|   fvec2 Pos; |   fvec2 Pos; | ||||||
|   fvec2 UV; |   fvec2 UV; | ||||||
|   u32 Color; |   u32 Color; | ||||||
| }; | }; | ||||||
| }  // namespace LI | }  // namespace Li | ||||||
| }  // namespace PD | }  // namespace PD | ||||||
| @@ -1,53 +0,0 @@ | |||||||
| #pragma once |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| MIT License |  | ||||||
| Copyright (c) 2024 - 2025 René Amthor (tobid7) |  | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
| of this software and associated documentation files (the "Software"), to deal |  | ||||||
| in the Software without restriction, including without limitation the rights |  | ||||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
| copies of the Software, and to permit persons to whom the Software is |  | ||||||
| furnished to do so, subject to the following conditions: |  | ||||||
|  |  | ||||||
| The above copyright notice and this permission notice shall be included in all |  | ||||||
| copies or substantial portions of the Software. |  | ||||||
|  |  | ||||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
| SOFTWARE. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| #include <pd/core/core.hpp> |  | ||||||
| #include <pd/net/socket.hpp> |  | ||||||
|  |  | ||||||
| namespace PD { |  | ||||||
| namespace Net { |  | ||||||
| class Backend { |  | ||||||
|  public: |  | ||||||
|   Backend(const std::string& name = "NullBackend") : pName(name) {} |  | ||||||
|   ~Backend() = default; |  | ||||||
|   PD_SMART_CTOR(Backend) |  | ||||||
|   virtual bool Init() = 0; |  | ||||||
|   virtual void Deinit() = 0; |  | ||||||
|   virtual int NewSocket() = 0; |  | ||||||
|   virtual void Close(int sock_id) = 0; |  | ||||||
|   virtual int GetInvalidRef() const = 0; |  | ||||||
|   virtual bool Bind(int sock_id, u16 port) = 0; |  | ||||||
|   virtual bool Listen(int sock_id, int backlog = 5) = 0; |  | ||||||
|   virtual bool WaitForRead(int sock_id, int timeout_ms) = 0; |  | ||||||
|   virtual bool Accept(int sock_id, Socket::Ref client) = 0; |  | ||||||
|   virtual bool Connect(int sock_id, const std::string& ip, u16 port) = 0; |  | ||||||
|   virtual int Send(int sock_id, const std::string& data) = 0; |  | ||||||
|   virtual int Receive(int sock_id, std::string& data, int size = 1024) = 0; |  | ||||||
|  |  | ||||||
|   /** Backend identification name */ |  | ||||||
|   const std::string pName; |  | ||||||
| }; |  | ||||||
| }  // namespace Net |  | ||||||
| }  // namespace PD |  | ||||||
| @@ -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,52 +0,0 @@ | |||||||
| #pragma once |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| MIT License |  | ||||||
|  |  | ||||||
| Copyright (c) 2024 - 2025 tobid7 |  | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
| of this software and associated documentation files (the "Software"), to deal |  | ||||||
| in the Software without restriction, including without limitation the rights |  | ||||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
| copies of the Software, and to permit persons to whom the Software is |  | ||||||
| furnished to do so, subject to the following conditions: |  | ||||||
|  |  | ||||||
| The above copyright notice and this permission notice shall be included in all |  | ||||||
| copies or substantial portions of the Software. |  | ||||||
|  |  | ||||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
| SOFTWARE. |  | ||||||
| */ |  | ||||||
|  |  | ||||||
| #pragma once |  | ||||||
|  |  | ||||||
| #ifdef _WIN32  // Windows (MSVC Tested) |  | ||||||
| #ifdef PD_NET_BUILD_SHARED |  | ||||||
| #define PD_NET_API __declspec(dllexport) |  | ||||||
| #else |  | ||||||
| #define PD_NET_API __declspec(dllimport) |  | ||||||
| #endif |  | ||||||
| #elif defined(__APPLE__)  // macOS (untested yet) |  | ||||||
| #ifdef PD_NET_BUILD_SHARED |  | ||||||
| #define PD_NET_API __attribute__((visibility("default"))) |  | ||||||
| #else |  | ||||||
| #define PD_NET_API |  | ||||||
| #endif |  | ||||||
| #elif defined(__linux__)  // Linux (untested yet) |  | ||||||
| #ifdef PD_NET_BUILD_SHARED |  | ||||||
| #define PD_NET_API __attribute__((visibility("default"))) |  | ||||||
| #else |  | ||||||
| #define PD_NET_API |  | ||||||
| #endif |  | ||||||
| #elif defined(__3DS__)  // 3ds Specific |  | ||||||
| // Only Static supported |  | ||||||
| #define PD_NET_API |  | ||||||
| #else |  | ||||||
| #define PD_NET_API |  | ||||||
| #endif |  | ||||||
| @@ -1,61 +0,0 @@ | |||||||
| #pragma once |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| MIT License |  | ||||||
| Copyright (c) 2024 - 2025 René Amthor (tobid7) |  | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
| of this software and associated documentation files (the "Software"), to deal |  | ||||||
| in the Software without restriction, including without limitation the rights |  | ||||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
| copies of the Software, and to permit persons to whom the Software is |  | ||||||
| furnished to do so, subject to the following conditions: |  | ||||||
|  |  | ||||||
| The above copyright notice and this permission notice shall be included in all |  | ||||||
| copies or substantial portions of the Software. |  | ||||||
|  |  | ||||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
| SOFTWARE. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| #include <pd/core/core.hpp> |  | ||||||
| #include <pd/net/pd_p_api.hpp> |  | ||||||
|  |  | ||||||
| namespace PD { |  | ||||||
| namespace Net { |  | ||||||
| class Backend; |  | ||||||
| /** |  | ||||||
|  * Wrapper class around the functionality of Net::Backend |  | ||||||
|  */ |  | ||||||
| class PD_NET_API Socket { |  | ||||||
|  public: |  | ||||||
|   Socket(PD::SmartCtor<Backend>::Ref bknd) { backend = bknd; }; |  | ||||||
|   Socket(PD::SmartCtor<Backend>::Ref bknd, u16 port) { |  | ||||||
|     backend = bknd; |  | ||||||
|     this->Create(); |  | ||||||
|     this->Bind(port); |  | ||||||
|   } |  | ||||||
|   ~Socket() { Close(); }; |  | ||||||
|   PD_SMART_CTOR(Socket); |  | ||||||
|  |  | ||||||
|   bool Create(); |  | ||||||
|   bool Bind(u16 port); |  | ||||||
|   bool Listen(int backlog = 5); |  | ||||||
|   bool WaitForRead(int timeout_ms); |  | ||||||
|   bool Accept(Socket::Ref client); |  | ||||||
|   bool Connect(const std::string& ip, u16 port); |  | ||||||
|   int Send(const std::string& data); |  | ||||||
|   int Receive(std::string& data, int size = 1024); |  | ||||||
|   void Close(); |  | ||||||
|   bool IsValid() const; |  | ||||||
|  |  | ||||||
|   int pSocket; |  | ||||||
|   PD::SmartCtor<Net::Backend>::Ref backend; |  | ||||||
| }; |  | ||||||
| }  // namespace Net |  | ||||||
| }  // namespace PD |  | ||||||
| @@ -1,177 +0,0 @@ | |||||||
| #pragma once |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| MIT License |  | ||||||
| Copyright (c) 2024 - 2025 René Amthor (tobid7) |  | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
| of this software and associated documentation files (the "Software"), to deal |  | ||||||
| in the Software without restriction, including without limitation the rights |  | ||||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
| copies of the Software, and to permit persons to whom the Software is |  | ||||||
| furnished to do so, subject to the following conditions: |  | ||||||
|  |  | ||||||
| The above copyright notice and this permission notice shall be included in all |  | ||||||
| copies or substantial portions of the Software. |  | ||||||
|  |  | ||||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
| SOFTWARE. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| #include <pd/core/core.hpp> |  | ||||||
| #include <pd/overlays/overlay.hpp> |  | ||||||
|  |  | ||||||
| namespace PD { |  | ||||||
| /** |  | ||||||
|  * Development Function to dump Keyboard Layout into a Json File |  | ||||||
|  * @param path Path to write into |  | ||||||
|  */ |  | ||||||
| void DumpLayout(const std::string& path); |  | ||||||
| /** |  | ||||||
|  * Keyboard class |  | ||||||
|  * |  | ||||||
|  * - needs to be pushed with text and State reference as Overlay |  | ||||||
|  * to communicate with it |  | ||||||
|  * @note Hardcoded Rendering to get maximum Rendering Performance |  | ||||||
|  */ |  | ||||||
| class Keyboard : public Overlay { |  | ||||||
|  public: |  | ||||||
|   /** Key Operations */ |  | ||||||
|   enum KeyOperation { |  | ||||||
|     AppendSelf = 0,  ///< Append Keyname to res string |  | ||||||
|     Shift = 1,       ///< Shift |  | ||||||
|     Backspace = 2,   ///< Backspace |  | ||||||
|     Enter = 3,       ///< Enter |  | ||||||
|     OpCancel = 4,    ///< Cancel |  | ||||||
|     OpConfirm = 5,   ///< Confirm |  | ||||||
|     Tab = 6,         ///< Tab |  | ||||||
|     Caps = 7,        ///< Caps |  | ||||||
|     Space = 8,       ///< Space |  | ||||||
|     Op1 = 9,         ///< Unnset Op 1 |  | ||||||
|     Op2 = 10,        ///< Unset Op 2 |  | ||||||
|   }; |  | ||||||
|   /** Keyboard Type */ |  | ||||||
|   enum Type { |  | ||||||
|     Default,   ///< Default Keyboard |  | ||||||
|     Numpad,    ///< Numpad |  | ||||||
|     Password,  ///< Password Input |  | ||||||
|   }; |  | ||||||
|   /** State */ |  | ||||||
|   enum State { |  | ||||||
|     None,     ///< Doing nothing |  | ||||||
|     Cancel,   ///< Cancelled |  | ||||||
|     Confirm,  ///< Confirmed |  | ||||||
|   }; |  | ||||||
|   /** Alias for Keyboard Flags */ |  | ||||||
|   using Flags = u32; |  | ||||||
|   /** Flags */ |  | ||||||
|   enum Flags_ { |  | ||||||
|     Flags_None = 0,               ///< Nothing |  | ||||||
|     Flags_BlendTop = 1 << 0,      ///< Blend Top Screen |  | ||||||
|     Flags_BlendBottom = 1 << 1,   ///< Blend Bottom |  | ||||||
|     Flags_LockControls = 1 << 2,  ///< Lock Contols (Input Driver) |  | ||||||
|     Flags_Transparency = 1 << 3,  ///< Transparant Keyboard Colors |  | ||||||
|     // Default Flags |  | ||||||
|     Flags_Default = Flags_BlendBottom | Flags_BlendTop | Flags_LockControls, |  | ||||||
|   }; |  | ||||||
|   /** |  | ||||||
|    * Keyboard Constructor |  | ||||||
|    * @param text Result Text |  | ||||||
|    * @param state Result State |  | ||||||
|    * @param hint Hint to display if result is empty |  | ||||||
|    * @param type Keyboard type |  | ||||||
|    * @param flags Keyboard flags to use |  | ||||||
|    */ |  | ||||||
|   Keyboard(std::string& text, State& state, const std::string& hint = "", |  | ||||||
|            Type type = Default, Flags flags = Flags_Default) { |  | ||||||
|     too++; |  | ||||||
|     if (too > 1) { |  | ||||||
|       Kill(); |  | ||||||
|       return; |  | ||||||
|     } |  | ||||||
|     this->text = &text; |  | ||||||
|     this->copy = text; |  | ||||||
|     this->state = &state; |  | ||||||
|     this->hint = hint; |  | ||||||
|     this->type = type; |  | ||||||
|     this->flags = flags; |  | ||||||
|     this->raw_sel = -1; |  | ||||||
|     flymgr.From(vec2(0, 240)).To(vec2(0, 115)).In(0.3f).As(flymgr.EaseInQuad); |  | ||||||
|     chflymgr.From(vec2(-320, 0)).To(vec2(-320, 0)).In(0.1f).As(chflymgr.Linear); |  | ||||||
|   } |  | ||||||
|   /** Deconstructor */ |  | ||||||
|   ~Keyboard() { too--; } |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Rendering and Input Handler |  | ||||||
|    * @param delta Deltatime for Animations |  | ||||||
|    * @param ren Renderer Reference |  | ||||||
|    * @param inp Input Driver reference |  | ||||||
|    */ |  | ||||||
|   void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) override; |  | ||||||
|  |  | ||||||
|   /** Remove Keyboard */ |  | ||||||
|   void Rem() { |  | ||||||
|     rem = true; |  | ||||||
|     flymgr.From(vec2(0, 115)).To(vec2(0, 240)).In(0.2f).As(flymgr.EaseOutQuad); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|  private: |  | ||||||
|   /** Prerender Keys */ |  | ||||||
|   void LoadTheKeys(LI::Renderer::Ref ren); |  | ||||||
|   /** Controller Movement */ |  | ||||||
|   void Movement(Hid::Ref inp); |  | ||||||
|   /** Trigger Move from to Animation */ |  | ||||||
|   void MoveSelector(); |  | ||||||
|   /** Execute a Key operation */ |  | ||||||
|   void DoOperation(KeyOperation op, const std::string& kname); |  | ||||||
|   /** Recolor all Keys with the same operation */ |  | ||||||
|   void RecolorBy(KeyOperation op, u32 color, int cm); |  | ||||||
|   /** Bind an operation */ |  | ||||||
|   void InputOpBind(Hid::Key k, KeyOperation op, Hid::Ref inp, int cm); |  | ||||||
|   // Result Text reference |  | ||||||
|   std::string* text; |  | ||||||
|   // Copy of the Text |  | ||||||
|   std::string copy; |  | ||||||
|   // Hint |  | ||||||
|   std::string hint; |  | ||||||
|   // Result State reference |  | ||||||
|   State* state; |  | ||||||
|   // Keyboard Type |  | ||||||
|   Type type; |  | ||||||
|   // Keyboard flags |  | ||||||
|   Flags flags; |  | ||||||
|   // def, caps, shift |  | ||||||
|   int mode = 0; |  | ||||||
|   // Stands for The Only One |  | ||||||
|   static int too; |  | ||||||
|  |  | ||||||
|   // Tween for selector Movement |  | ||||||
|   Tween<fvec2> selector; |  | ||||||
|   // Tween for Selector Size |  | ||||||
|   Tween<fvec2> sel_szs; |  | ||||||
|   // Current Cell size |  | ||||||
|   fvec2 cselszs; |  | ||||||
|   // selector index |  | ||||||
|   int raw_sel; |  | ||||||
|  |  | ||||||
|   // Prerendered Keytables |  | ||||||
|   LI::StaticObject::Ref keys[3]; |  | ||||||
|   // Value to check if table is loadet |  | ||||||
|   bool keys_loadet = false; |  | ||||||
|  |  | ||||||
|   // Remove Animation |  | ||||||
|   bool rem = false; |  | ||||||
|   /// Probably a float would've done the job as well ;) |  | ||||||
|   Tween<fvec2> flymgr; |  | ||||||
|   // Secode Flymanager |  | ||||||
|   Tween<fvec2> chflymgr; |  | ||||||
|   // Show Help |  | ||||||
|   bool show_help = true; |  | ||||||
| }; |  | ||||||
| }  // namespace PD |  | ||||||
| @@ -1,98 +0,0 @@ | |||||||
| #pragma once |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| MIT License |  | ||||||
| Copyright (c) 2024 - 2025 René Amthor (tobid7) |  | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
| of this software and associated documentation files (the "Software"), to deal |  | ||||||
| in the Software without restriction, including without limitation the rights |  | ||||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
| copies of the Software, and to permit persons to whom the Software is |  | ||||||
| furnished to do so, subject to the following conditions: |  | ||||||
|  |  | ||||||
| The above copyright notice and this permission notice shall be included in all |  | ||||||
| copies or substantial portions of the Software. |  | ||||||
|  |  | ||||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
| SOFTWARE. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| #include <pd/core/core.hpp> |  | ||||||
| #include <pd/lithium/renderer.hpp> |  | ||||||
|  |  | ||||||
| namespace PD { |  | ||||||
| /** |  | ||||||
|  * Message Manager |  | ||||||
|  */ |  | ||||||
| class MessageMgr : public PD::SmartCtor<MessageMgr> { |  | ||||||
|  public: |  | ||||||
|   /** |  | ||||||
|    * Message Container |  | ||||||
|    */ |  | ||||||
|   class Container : public PD::SmartCtor<Container> { |  | ||||||
|    public: |  | ||||||
|     /** |  | ||||||
|      * Message Constructor |  | ||||||
|      * @param title Title |  | ||||||
|      * @param msg Message |  | ||||||
|      */ |  | ||||||
|     Container(const std::string& title, const std::string& msg); |  | ||||||
|     ~Container() = default; |  | ||||||
|  |  | ||||||
|     /** Render the Container */ |  | ||||||
|     void Render(PD::LI::Renderer::Ref ren); |  | ||||||
|     /** |  | ||||||
|      * Update Animations by slot and delta |  | ||||||
|      * @param slot Slot |  | ||||||
|      * @param delta Deltatime |  | ||||||
|      */ |  | ||||||
|     void Update(int slot, float delta); |  | ||||||
|     /** Trigger Fly in Animation */ |  | ||||||
|     void FlyIn(); |  | ||||||
|     /** Trigger Change Position Animation */ |  | ||||||
|     void ToBeMoved(int slot); |  | ||||||
|     /** Trigger Removed Animation */ |  | ||||||
|     void ToBeRemoved(); |  | ||||||
|  |  | ||||||
|     /** Check if Message can be removed from list */ |  | ||||||
|     bool ShouldBeRemoved() const { return (tbr && pos.IsFinished()) || kill; } |  | ||||||
|  |  | ||||||
|    private: |  | ||||||
|     PD::Color col_bg;      // Background Color |  | ||||||
|     PD::Color col_text;    // Text Color |  | ||||||
|     float lifetime = 0.f;  // LifeTime |  | ||||||
|     PD::Tween<fvec2> pos;  // Position effect |  | ||||||
|     std::string title;     // Title |  | ||||||
|     std::string msg;       // Message |  | ||||||
|     fvec2 size;            // Size of the Background |  | ||||||
|     bool tbr = false;      // To be Removed ? |  | ||||||
|     bool kill = false;     // Instant Kill |  | ||||||
|     int s = 0;             // Slot |  | ||||||
|   }; |  | ||||||
|   /** Constructor to Link a Renderer reference */ |  | ||||||
|   MessageMgr(PD::LI::Renderer::Ref r) { ren = r; } |  | ||||||
|   ~MessageMgr() = default; |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Add a New Message |  | ||||||
|    * @param title Message Title |  | ||||||
|    * @param text Message Text |  | ||||||
|    */ |  | ||||||
|   void Push(const std::string& title, const std::string& text); |  | ||||||
|   /** |  | ||||||
|    * Update Messages |  | ||||||
|    * @param delta Deltatime |  | ||||||
|    */ |  | ||||||
|   void Update(float delta); |  | ||||||
|  |  | ||||||
|  private: |  | ||||||
|   std::vector<Container::Ref> msgs;  // List of Messages |  | ||||||
|   PD::LI::Renderer::Ref ren;         // Renderer Reference |  | ||||||
| }; |  | ||||||
| }  // namespace PD |  | ||||||
| @@ -1,56 +0,0 @@ | |||||||
| #pragma once |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| MIT License |  | ||||||
| Copyright (c) 2024 - 2025 René Amthor (tobid7) |  | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
| of this software and associated documentation files (the "Software"), to deal |  | ||||||
| in the Software without restriction, including without limitation the rights |  | ||||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
| copies of the Software, and to permit persons to whom the Software is |  | ||||||
| furnished to do so, subject to the following conditions: |  | ||||||
|  |  | ||||||
| The above copyright notice and this permission notice shall be included in all |  | ||||||
| copies or substantial portions of the Software. |  | ||||||
|  |  | ||||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
| SOFTWARE. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| #include <pd/core/core.hpp> |  | ||||||
| #include <pd/lithium/renderer.hpp> |  | ||||||
|  |  | ||||||
| namespace PD { |  | ||||||
| /** |  | ||||||
|  * Overlay Template class |  | ||||||
|  */ |  | ||||||
| class Overlay : public SmartCtor<Overlay> { |  | ||||||
|  public: |  | ||||||
|   Overlay() = default; |  | ||||||
|   virtual ~Overlay() = default; |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Update Function for Overlay input and rendering |  | ||||||
|    * @param delta Deltatime |  | ||||||
|    * @param ren Renderer reference |  | ||||||
|    * @param inp Input Driver |  | ||||||
|    */ |  | ||||||
|   virtual void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) = 0; |  | ||||||
|  |  | ||||||
|   /** Check if killed to remove from Overlay Manager */ |  | ||||||
|   bool IsKilled() const { return kill; } |  | ||||||
|  |  | ||||||
|  protected: |  | ||||||
|   /** Internall Kill function to call from your Overlay */ |  | ||||||
|   void Kill() { kill = true; } |  | ||||||
|  |  | ||||||
|  private: |  | ||||||
|   bool kill = false;  ///< Should be killed or not |  | ||||||
| }; |  | ||||||
| }  // namespace PD |  | ||||||
| @@ -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/core/core.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/core/core.hpp> |  | ||||||
| #include <pd/overlays/overlay.hpp> |  | ||||||
|  |  | ||||||
| namespace PD { |  | ||||||
| /** |  | ||||||
|  * Performance Overlay |  | ||||||
|  * |  | ||||||
|  * - Framerate / Frametime |  | ||||||
|  * - Renderer Avarage Time |  | ||||||
|  * - Overlays Avarage Time |  | ||||||
|  * - UserApp Average Time |  | ||||||
|  * - **V**ertices and **I**ndices |  | ||||||
|  * - **D**Draw Commands and Draw **C**alls |  | ||||||
|  * - Text Map System Texts |  | ||||||
|  * - Auto static Text Texts |  | ||||||
|  */ |  | ||||||
| class Performance : public Overlay { |  | ||||||
|  public: |  | ||||||
|   /** |  | ||||||
|    * Constructor |  | ||||||
|    * @param skill (if set to true the Overlay self kills) |  | ||||||
|    * @param screen Bottom or Top Screen |  | ||||||
|    */ |  | ||||||
|   Performance(bool& skill, bool& screen) { |  | ||||||
|     too++; |  | ||||||
|     if (too > 1) { |  | ||||||
|       Kill(); |  | ||||||
|       return; |  | ||||||
|     } |  | ||||||
|     this->skill = &skill; |  | ||||||
|     *this->skill = false;  // Make sure its false |  | ||||||
|     this->screen = &screen; |  | ||||||
|   } |  | ||||||
|   /** Deconstructor */ |  | ||||||
|   ~Performance() { too--; } |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * Rendering Function |  | ||||||
|    * @param delta Deltatime |  | ||||||
|    * @param ren Renderer Reference |  | ||||||
|    * @param inp Input Driver Reference |  | ||||||
|    */ |  | ||||||
|   void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) override; |  | ||||||
|  |  | ||||||
|  private: |  | ||||||
|   /** |  | ||||||
|    * Render an Info line |  | ||||||
|    * @param pos Position reference (gets updated for next line) |  | ||||||
|    * @param text Text to Show |  | ||||||
|    * @param ren Renderer Reference |  | ||||||
|    */ |  | ||||||
|   void Line(fvec2& pos, const std::string& text, LI::Renderer::Ref ren); |  | ||||||
|   // Trace String Average |  | ||||||
|   std::string TSA(const std::string& id); |  | ||||||
|   // Described in Keyboard |  | ||||||
|   static int too; |  | ||||||
|   bool *skill, *screen; |  | ||||||
| }; |  | ||||||
| }  // namespace PD |  | ||||||
| @@ -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 |  | ||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user