94 Commits

Author SHA1 Message Date
186fce803e Add missing sources 2026-03-18 11:37:44 +01:00
66412ca8e0 Full 3ds support and fix dx9 2026-03-18 11:34:36 +01:00
e04046720b Work at 3ds support and backend upgrades
- Track textures (not sure if this is done tbh)
- Add lithium formatters and move TextureID, TextureFormat and TextureFilter to lithium
- Only include gl-helper if any glDriver is included
- Add Li::Rect for UV stuff
- Add Li::Texture as Info holder (still thinking of making them to ptrs
- Add Check if textures are still loaded on exit
2026-03-18 09:31:47 +01:00
d4c59e5b61 Add backends
- Renamed GfxOpenGL to GfxOPenGL2
- Added GfxOpenGL3 backend for OpenGL 3.3+
- Added WIP DirectX9 backend
- Added structure for Citro3D
- Added linear Allocator
2026-03-17 16:47:19 +01:00
fe9194b907 More work to drivers
- Add gfx_test
- add texture loading to GfxOpenGL
- add full submit code
- add debug logging
- add construct and destroy functionality to Pool
- add command functionality
- add vertex and index pools to lithium (static and not threadsafe yet)
- Update GfxDriver Matrix with SetViewPort
- Add glfw (only dependency of gfx_test) maybe later required for input driver
2026-03-16 17:33:46 +01:00
4924d86bc0 # Work at gfx driver system
- Update pool to use template allocator directly instead of std::vector
- Add a GfxDriver config Template to be able to modify settings like allocators / Types for specific Drivers
- Add glad
2026-03-16 15:19:12 +01:00
41b612ec0a 0.7.0 rewrite dev
- remove everyting
- keep core
-rename bit_utils to bits
- add formatter for  color
- add float getters to color
- start with new drivers api
2026-03-16 06:37:51 +01:00
ff1b574276 [pd-ui7] add getters for ui7 menu pos and size 2026-03-13 20:55:40 +01:00
1b47ed843f [pd-drivers]: Ad more debug values
[pd-3ds]: Use new debug values
[pd-lithium]: Add functionality to DrawList::Optimize
[pd-ui7]: Add setters for Menu pos ans size
2026-03-12 20:18:27 +01:00
02d2200edd Fix Render discard issue [pd-3ds]
- Clip Rects do now not discard when they move out of screen (cause the maths ends in < 0 which is not working with u32)
- Fixing ui7 crash wehn im input was nullptr
2026-03-10 18:57:29 +01:00
97efca5173 Merge branch 'stable' of https://github.com/tobid7/palladium into stable 2026-03-09 20:47:53 +01:00
68cc809555 Fix Drawlist::Clear / Add HashID / FNV Type traits 2026-03-09 20:46:41 +01:00
ca490df915 Add U8Iterator and Pool base class 2026-03-05 20:24:47 +01:00
da0f7320c8 Add stuff for cmake find_package
- Add build* to gitignore
- Fix year in license file
- other changes are result of clang-format
2026-03-01 21:41:53 +01:00
8ee7006d2c Export OS correctly 2026-01-30 20:19:13 +01:00
683c226ce0 Fix MSVC dll building 2026-01-29 20:17:04 +01:00
1ec06a26cc Fix GL Scissor in Desktop Backend 2026-01-28 07:40:34 +01:00
21b45f5855 WIP: Add CLipRects to UI7 Layouts
- Added Scissor Support to Font Rendering
2026-01-28 07:11:56 +01:00
090656b30c Fix close sym input logic 2026-01-27 08:06:52 +01:00
e8072a064c WIP Backend System Redesign Step 1
- Created 1 Context for Backend Management and Sharing
- Made every class that used a static Backend require the Context or specific Backend
- Bring Back 3ds support
2026-01-26 20:46:27 +01:00
892f8ce0c4 Update License Header Text 2026-01-25 21:12:16 +01:00
c373b15bab remove drivers pd_p_api header 2026-01-25 21:00:50 +01:00
fb46f4d36a Let's just use 1 PD_API header 2026-01-25 20:57:14 +01:00
337c016824 Unfiy all sub projects back into 1 libpalladium 2026-01-25 20:44:52 +01:00
d2806b2061 Add Nee Backend Structure
Use TexAddress instead of Texture::Ref in Cmds
Add a .clang-format??
2026-01-25 00:04:40 +01:00
da79db223f Add MacOS support as well as OpenGL 3.3 support 2026-01-24 23:08:03 +01:00
b2c7c1fdbf UI7 Add Containers to Layout
- Hotfix in CommandPool
- Add UI7 ItemRowHeight (Universal Item Size/Height)
- Add Containers to Layout
- Add ColorEdit to Menu
- Switch Back to COlorEdit in UI7::StyleEditor
- Add DrawList Layer Sorting to UI7 (Not working as expected)
- STart Work at ColorEdit container
2026-01-24 11:58:41 +01:00
4a73e8c8da UI7 hotfix
- Fix Image has No Size
- Fix DragData PathRect Positioning
2026-01-24 09:27:21 +01:00
641fc27e55 Auto Menu Sizing 2026-01-23 16:11:09 +01:00
b8c25d6901 Add a Drag Slider to UI7 2026-01-23 15:45:25 +01:00
931e02aefb Move CmdPool code to a source file 2026-01-22 19:25:01 +01:00
0db4953125 Reimplement list sorting and Fix UI7 Layers 2026-01-22 16:34:46 +01:00
2b7d25cf06 Update
- Added DestroyTex to 3ds backend
- Added Size() -> ivec2 to PD::Image
- Added CmdPool Copy as well as DrawList Copy (Static rendering)
- Added == ooperator for Rect
- Added UI7 Frame Rounding
- Fix UI7 Image usage withour size or uv
- Added New way to use BeginMenu
2026-01-18 19:25:50 +01:00
0ef6d34435 Refactor the Command / DrawList System
Use Command Pool instead of always allocating.
This gives us e big performance diffrence on the 3ds
Fixed IDS of ui7 for now
2026-01-16 12:13:48 +01:00
eb5d5f9974 backend updates
pd-3ds:
Add support for RGB565 textures
pd-desktop:
Add support for A8 textures
Add glfw callback chain to not break other libs using the same callback
2026-01-05 14:37:57 +01:00
3575a6787d hotfix 2025-12-28 21:38:41 +01:00
7fc7a2ecb9 QoL Changes
fix timetrace last diff
2025-12-27 23:35:23 +01:00
03f65e069f Add TextMapSystem WIP 2025-12-24 18:17:58 +01:00
c618c616fe Fix UI7 Crash by safe deleting the elements 2025-12-24 15:05:05 +01:00
ac281dc7a9 Update
- Add data getter to DrawList
- Add NoOOS (Out Of screen Rendering) flag to text renderer (requires a textbox)
- UI7 Label Wrapping (optinal and beta)
2025-12-23 19:20:31 +01:00
0cb5de882f Fixes and function additions
- Fixed Text pos at NoCollapse flag
- Fix Button Input Api (HandleScrolling after layout Update)
- Add getter for IO and Current Menu
- Add AdObject func wrappers to Menu
2025-12-20 19:25:20 +01:00
b3d621a847 Add LayerOptimisation / QoL change 2025-12-19 21:08:32 +01:00
4ad00cd2be pd-3ds: Add sysfont loader
- add support for Alpha only textures in rendering
2025-12-19 21:07:57 +01:00
1e35dbd743 ReAdd text shorting 2025-12-18 21:51:48 +01:00
803fa5cdb5 Remove custom standard lib
Why?? cause it was russian roulette with pointer access stuff etc
2025-12-17 10:02:05 +01:00
66d3825481 bknd-3ds: implement libpicasso to load shader 2025-12-17 09:25:36 +01:00
6c38aa6f21 Adding and fixing stuff
- Fix HexChar2Int
- Remove some devisions in tween engine
- Add PathAdd function for x, y seperated instead of fvec2
- Readd text wrapping (rd7-palladium maybe)
2025-12-15 22:16:19 +01:00
f19c947fc3 Road to 0.6.0
- readd the c++ linear allocator for 3ds
- start switching from PD::Vec to std::vector
- Add Color::Hex as constexpr for compiletime color converts
- Add FNV Hasing functions
- Make UI7 ids be able to be generated at compile time
- Added a Throw Function (for whatever)
- Added HexCHar2Int (replaces the lookup table)
- Made u128 fully constexpr
2025-12-10 19:02:54 +01:00
91754558f7 Fix the floating color bug :) 2025-12-06 22:30:37 +01:00
8328181a2a Merge branch 'devel050' of https://dev.npid7.de/tobid7/palladium into devel050 2025-10-24 09:18:29 +02:00
be230bef6b lithium: Fix text Spacing 2025-10-22 20:58:02 +02:00
c2bff368d4 lithium: Fix text Spacing 2025-10-21 08:55:51 +02:00
0ecf559fbb # Small Update
- Start some work on scrolling
2025-10-18 17:00:35 +02:00
3823f08bab Update Font System
- Add support for splitting glyphs over multiple textures
- Fix some casts in wrong places (like casting a float to float?)
- Add a break if stb truetype fails
- Fix a typo in FontRenderer Shaddow part (used .x twice)
- Use L' ' for the wstring chars

- TODO: Fix the space of tabs / space chars (currently hardcoded)

- WARNING
  - Spaces are broken (idk why)
2025-08-28 21:06:19 +02:00
decae031ae Small Fix
- Make target compile definitions private (cause its only for them

this fixes errors when using in projects that have c source files
2025-08-23 20:02:33 +02:00
da87c0f7c2 # Hotfix
- 3ds backend
   -probably i forgot to apply the changes of moving Gfx backends to the PD namespace to the 3ds backend :/
2025-08-15 22:14:33 +02:00
310b44caf5 # Changes -> 0.5.1
- 3ds
  - Remove Gfx values that are present in Backend Tamplate
  - Move to default Palladium Namespace
  - Set the Input Flags
- Desktop
  - Move to PD Namespace
  - Comment out old keyboard stuff
  - HidDriver needs a rewrite but is functional enough
- Core
  - Add u128 class (only used in input driver so far
- Drivers (Core)
  - Move Gfx to PD namespace
  - Move Vertex/Index Pos and Projection Mtx to Gfx template
  - Add Keyboard support with u128 to Hid
  - Add a Update func if no hiddriver is specified (to prevent crashes when requestign inputs)
- Image
   - Add RGBA -> BGRA support (used in windows bitmaps iirc)
- Lithium
  - Add Vertex/Index counters to drawlist
  - Add a LoadTTF from Mem func and let the loadfile func use PD::IO::LoadFile2Mem (looks cleaner)
  - Add LoadDefaultFont (which loads one of the integrated fonts if the PD_LI_INCLUDE_FONTS flag was passed on palaldium build) !!! Note that there are no fonts integrated yet due to i dont know how to handle licensing...
- UI7
  - Add MouseLeft support to Input handler
  - Use xy coords of the Viewport to create Menus inside it
  - Get num of Vertices/Indices out of FinalDrawList
  - Add some Palladium Info to metrics Menu
  - Readd Compiler string
- pdfm
  - New tool that creates fonts.cpp/fonts.hpp
2025-08-14 20:37:55 +02:00
87910b57de # Changes
3ds Backend:
  - switch to shaderProgramUse
Desktop Backend
  - Add Pre Alpha Text Input and Keyboard Support
  - Move Shader Attrib Setup into a function and callit every time we need a set up vbo
  - Move to Mat4 api
Core:
  - Add fquat support
  - Add LoadFile2Str
  - Move Mat4 Lib from Project     n73 to Palladium
  - Add full supprot for vec cross types
  - Add Normalize, Distance and Dot to all
  - Add Cross to vec3
Drivers:
  - Add a SetViewPort func to GFX
  - Add Keyboard keys and Flasg to Hid
Image:
  - Add Vertical Flipping
  - Add Horizontal flipping
UI7:
  - Fix Critical Bug in IO Viewport handler
  - Fix library list (error on MinGW for some reason)
Lazyvec:
  - Split into multiple source files
  - Generate new functions (see core updates)
2025-07-23 23:21:34 +02:00
31a0c3656f # Changes
- Remove () from vec formatter
 -Add Merge function to DrawList to Move Data into the Current DrawList
- Fix stupid bug in Rect.hpp which caused some problems in line rendering
- Remove some unused UI7 Flags
- io: Allocate FinalDrawList and add GetViewPort func
- Readd TreeNodes to Menu
- Add ABout/Style and Metrics Menu to Context
- Add some Variables for cliprects in ui7 container.hpp
- Add InputHandler functionality to DynObj
- Fix Menu Layout Render Order
- Add Better Menu Sorting to Context
# ppam
- Use stringview instead of hardcoded const char*
# Todos
- Work on the Lithium 3D System
- Fix UI7 Menu Order to Pop new Menus into the front instead of the background
- Add Scrolling support to menu (or integrate it into layout maybe)
2025-07-01 21:43:35 +02:00
01fb149e71 Update glfw 2025-06-22 21:05:24 +02:00
57634cbf4b # Rewrite 5
- Move Libraries Source into pd directory and give them all their own CMakeLists.txt
- Partial rewrite core (color, autogenerated vec), lithium (now uses UNIQUE PTR for Commands), UI7
- Use MenuV2 as new standart in UI7
- Implementz ViewPort Pre alpha to UI7
- Add Line Drawing to DrawList (not Working)
- Implement a Complete new drievrs API (static Drivers)
- NO SUPPORT FOR SHARED LIBRARY BUILDS IN VERSION 5 YET
- Add Tools to Autogenerate Headers and Stuff
2025-06-22 21:05:09 +02:00
963fa72e41 # Changes
- Fix PD Image
- Add some beta RLE Compress Decompress variants
2025-06-16 20:50:56 +02:00
271defffca # Fix Color Code
- Fix extreme stupid bug in color.hpp (returing m_r for all...)
- Fix Collor::Hex  with int cast to make sure to have valid hex output (u8 gets interpreted as char)
2025-06-01 18:07:14 +02:00
ea76a304d4 Add GLFW as submodule in Repo 2025-05-08 20:46:01 +02:00
f75f7067ff # Fixes
- Fix LinearAlloc bug not using *sizeof(T)
- Add WaitForRead to net backend
- Add a Get func to Tween
- Skip \r in Text Rendering
- Add Citro3D Max Texsize check
2025-05-02 15:09:21 +02:00
13c2869ba8 Initial Cross Platform Work 2025-04-24 16:39:24 +02:00
dbffb7f316 # 0.3.2
Implement Path render API into drawlist
Add some new drawing functions (need to make Rectangle -> RectFilled
Add Menu Border
ReSetup the Menu Input and Rendering API to fix flickering when moving
2025-03-21 16:23:17 +01:00
6738fda55c # 0.3.1-1
- Add Deltatime usage for Overscroll as well as a config value for ids multiplier
- Add Function to Layout to remove all ID Objects
- Add step and precision to DragData as well as setting min and max to their type limits
- Use the Address for now for the id of the DragData (cause with tree nodes opened backwars all DragData will share the same data reference)
- Add a fix to MaxPosition in Layout to be actually the max Position on X axis
2025-03-16 20:03:08 +01:00
35272687f6 # Changes 0.3.1
- Add Layout API and let Menu use it
- Add DragData (for float, double, int, etc)
- Add IO Delta calculation to not require a users delta value
- Add Config Var for SLider drag min size
- Remove Hid::Ref input of Containers as IO DragApi is used
- Containers that accept input will require an ID to function
2025-03-14 15:14:45 +01:00
ba77dc9b42 # 0.3.0
- Fix minor issues
- Add Custom UV Support to Drawlist and Menu Image
- Add DoubleClick to IO Input API
- Add Flashbang Theme (Not completly done)
- Fix Menu glitch when scrolling was possible when not allowed
2025-03-12 21:09:45 +01:00
b94dfc0c53 # 0.2.9-1 HotFix
- Fix Bug where Input is locked for ever when removing a Menu by Changing its name / Not Process it anymore
2025-03-09 20:40:02 +01:00
edf5f387ae # Changes 0.2.9
- Litium Chenge Static Object to set instead of add layer
- Add UI7 Color Selector (Not done)
- Add NoClose flag as well as a is_shown address to set to close menus completly
- Add u32 input for nameless ui7 ids
- Add Debug Vertex/Index counters to DrawLists and IO
- Add an Anywhere Released bool to Input API to decide if object should always react or only if curser is inside its box
- Add Focused Menu System to Drag API to make sure to not care about the menu input process order
- Let Menus only have 1 Drawlist instead of 3
Put Close, Resize, Move, Collapse and Scroll into their own handlers
 - Add a DeadHeader color to make a visual diffrence between Menus and Focused Menu
 - Add a GetRef to Theme for Color edit
 - Fix DrawList Line not rendering if going out of screen
 - Clear All CLipRects after process DrawList
 - Fix SeparatorText glitch
 - Fix Typos
 - Add IO Input Support to Containers
2025-03-09 20:00:47 +01:00
09b1937a8d # Changes 0.2.8
- Fix Flickering problem in StaticText api
- Fix Lagacy and Container HandleScrolling InBox checks
- Add IO Flags define for future
- Implement Single Object Dragging API by IO Context
- Add TreeNodes
- Use ioMenuPadding and ItemSpace
- Add StyleEditorMenu
- Rework ContainerApi to take functions from IO and add an Update function template for Updating internal values if required
- Use new DragApi for MenuCollabse, MenuDragging, MenuResize, SliderDragging and TreeNodes Open/Close
- Add Helper Defines for Metrics Menu [INTERNAL]
- Add TimeTrace as Tree to Metrics as well as other new Data
- Add GetRawObject to StaticText for custom rendering like ui7
- Add DrawlistRegestry to correctly render Menus in their own layer ranges
2025-03-08 13:52:11 +01:00
e282d0ec7e # 0.2.7-2
- Start dev on UI7 IO
- Add NoRezize flag and rezising
- Fix Bug in DebugLabels
- Use view Area for Menu Pos and Size
- Only set Viewarea once in BeginMenu
2025-03-07 14:05:43 +01:00
85e12c45c0 # 0.2.7-1 **HOTFIX**
- Fix nullptr->value access issue in UI7::Context
- Add UI7MenuFlags_NoMove to disable window movement
- Fix testapp to support the new DebugLabels standard
2025-03-06 20:22:13 +01:00
e45598f9f6 # Changes 0.2.7
- Add UI7 32Bit Version Num
- Fix ClipRect Bug with Separators
- Fix Triangle/Rect Render order Bug (UI7 - Bug of Lithium)
- Add Position to Menus and Movement by dragging the Title bar
- Add Menu Collabse (+ Flag to disable)
- Add About and Metrics Menus to Context
2025-03-06 18:14:39 +01:00
5375d0f3a9 # 0.2.6-2
- Add Scissor (CLIP RECT) to lithium commands and UI7 Drawlist API
- Enable ClipRect to UI7::Menu (probably create a enable/disable flag)
2025-03-05 20:18:00 +01:00
229d54f088 # 0.2.6-1
- Fix TTF FOnt loader to support any size between 8 and 64
- Fix UI7 Image Custom SIze support
- Add new Syste mfor Image buffer modification to image lib
2025-03-05 12:06:40 +01:00
c9e14ad08f # 0.2.5
Add DrawLine to DrawList
Fix Text Separator Alignment
2025-03-04 10:22:28 +01:00
e6495d70b1 # Changes 0.2.4-2
- Document the rest of th elibs
- remove sound.hpp header
2025-03-03 10:55:24 +01:00
7d3f619169 # Changes 0.2.4-1
- Add GIT_BRANCH (for development and stable)
- Write  Documentation of
  - pd-core (exept of vec.hpp)
  - pd-app
  - pd-drivers
  - pd-lib3ds
  - pd-image
  - pd-image
  - pd-ui7
2025-03-02 21:11:58 +01:00
af3d3e0b5b # split pd-maths into pd-core and pd-image (0.2.3) 2025-02-28 21:14:20 +01:00
debedf59c6 # Stage 2.2
- Move Timer to core
- Use Timer for app_time
- Fix Deltatime Bug in App
- Add HwInfo to lib3ds (stolen from hbloader 2 pd-rewrite port)
- Add GetSystemLanguage to lib3ds
- Add Net Header for pd-net (still need to find a way to make this working)
- Add base Decoder and Player Headers for pd-sound
- Add Mp3 Decoder (useless and untested yet)
- Add GetDataDirectory to App
- Add InitFLag to App for HwInfo
- Actually write the Timer class
- Rework the UI7 Theme API to use SmartCtor
- UI7::Menu::JoinAlign: Use a loop to determinate max width for centering a group
- Add some Doctumentation around UI7::Menu
2025-02-28 19:49:24 +01:00
f9a1d8aefb # Stage 2.1
- Split palladium into diffrent libraries
- Fix a Logical bug in App class
- Add New Flag to Init App Data Directory
- Add Cmake Option for build tests
- Bump Version in cmake file
- Make Hid a Driver
- Start moving 3ds specific stuff into pd-lib3ds
- Split Lithium into more files
2025-02-22 00:23:48 +01:00
cbdb15e0de # Stage 2
- reAdd Text Shorting
- make SpriteSheet part of SmartCtor
- Add Some Gaussian Blur func (not functional for now)
-  Add Image Indexing functions and Reverse32 for (RGBA -> ABGR)
- Add Transparency flag to Keyboard and Fix its Render Prder
- Add UI7 Alignment API
  - Incldes PushAlignment (One way Alignment, JoinAlign, etc)
- Make Setter for Scroll Offset public
- Make Getter for ScrollMod Public
- Add a Check if Menu is duing an animated scroll
- Add FindMenu to Context for Modifications after Context::EndMenu
- Fix Major Issue in Lithium InBox Function
- Fix TextAlignRight and Add PerLine Text Shorting
- Fix Screen being unused in Performance Overlay
- Add Beta Slider Dragging
- Dont Handle Inputs for Objects when scrolling
- Add a MainArea to Not Handle Inputs outside of it
- Simplefied some logic

- TODO:
  - Write TextWrap Function
  - Add PerLine text Align
  - Track and Fix a lot of UI7 Bugs such as Alignment Issues etc
2025-02-17 22:20:30 +01:00
ca26189f52 # Stage 1.9
- Add AppInit Flags and AppFlags to COntrol some Individual Stuff (Not using default can run into a crash report if things get used that are disabled)
- Create a Test Settings Menu
- Make Some Menu functions Public
- Add ScrollTo Animation
- Make ContainerApi fully public
- Remove an else statement (now need to find a way to not set the pos twice)
-
2025-02-09 21:40:31 +01:00
fc8291555e # Stage 1.8.2
- Use Font in Static text for rerendering if the font changed
  ### TODO: Detect reloading the current font
- Updated License notice in all Files
2025-02-04 21:44:27 +01:00
f7d262b7b0 # Stage 1.8.1
- Add Removable to containers (Only used for ID Objs)
- Add Counts for specific Object types to have for example multiple buttons with same name
- Readd Background as accidently deleted it
2025-02-03 16:15:37 +01:00
f87c103d8d # Stage 1.8
- Renderer now vould use more screen Objects
- Register default Top and Bottom Screens (for Overlays and UI7)
- Make ToHex an Inline header func
- Add GetCompilerVersion
- Add Library Compile And Version Info to common
- Remove z of vertex object and shader in position
- Add Container base and SubContainers to UI7
- Add abillity to Join Multiple Objects in Same Line and Center them
- Fix LayerOrder Bug for updating texts in DrawList
2025-02-02 20:32:07 +01:00
055588ce8b # Stage 1.7.1
- Add Min and Max to timetrace
- Add TestBench
2025-01-30 15:06:27 +01:00
2914f2c8e5 # Stage 1.7
- Added File to Memory and FastHashMomory
- Add Protection that only one app can exist
- Add a Trace exist Variable as GetTraceRef automatically creates a trace
- Outsource the LI::Rect to its own header
- Add a CurrentScreen func
- Use Rect for uv (to manually set all corners)
- Rect still supports to use vec4 for uv
- Add tex3ds Spritesheet support
- Add T3X Loader to Texture (if single tex)
- Integrate an autounload into Texture as in case of spritesheet the Tex needs to be unloaded manually
- Safe some performance in texture loading by combining the Loops (best thing ive ever found)
- Use the Momory Hash to only render one error icon into the TTF Texture
- Also Try loading the whole 16-Bit range
- Use GPU_A8 format for TTF rendering to save 24Bits per pixel and use the same Rendermode as System Font
- Simplify Quad Command by using modern vec api
- Integrate Text aligning
- Fix FPS displayed twice in Performance overlay
- UI7 DrawList now has its own AST system
  - TODO: do the same layering for the objects as Text uses
- Map Drawcommands with a bool that declares either bottom or top screen was active
- Add first basic Manu functions
- Fix Typos in Theme
- Add a basic UI7 Context Handler

## Extra
- Added JetBrainsMono font in Test app
## Bugs:
- Performance Overlay Freezes 3ds hardware and crashes Citra with Vulkan when System Font is used
- UI7 Menu scrolling is as scruffed as back in RenderD7 0.9.5
2025-01-29 03:14:29 +01:00
d55f485b8d # Rewrite Stage 1.6
- Add static Text (Auto Static Text)
- Add a Text Flag that Renders Text if it is Out of Screen
- Shorter Keyboard animations and Fix Vertical Movement
- Make Keyboard keys transparent
- Make | to / in Performance Overlay as the symbol lokks biggy on System Font
- Add Ast and Tms to Performance OVL
2025-01-22 09:22:03 +01:00
b4a4b6a426 # Rewrite Stage 1.5
- Added Overlays (Performance / Keyboaed)
- Keyboard has Gamepad Movement WIP (kinda)
- Work on UI7 Started
- Added Input Manager
- Added Message Boxes (Animated)
- Added Signle Header Tween func for animated stuff (Keyboard Messages, etc)
- Add FastHash (Maybe useful later)
- Using const & for vec in lithium
- Add ability to copy a command by a Ref
- Make Lists in Commands OpenAccess for Modification (StaticObject)
- Add Static Object (System to PreRender Suff that never changes) but can still be recolored or moved
- Add Layer and Font change functions
- Make Renderer Tools (RotateCorner, CreateRect, CreateLine, InBox, OptiCommandList) static (OpenAccess)
- Add ReIndexing to PushCommand
- Add Ability to Init vec3 and vec4 with vec2 and add .xy and .zw to vec4
- Fully Animated Keyboard that currently has problem of Top Down GamePad movement
- Add Func to Get GamePad Icon Codepoints for TextRenderer
- Made deltatime a float
- Using filesystem::path().wstring for convertation (works)
- Add a New InBox to Renderer that only checks if a point is inside a boundingbox
- Disable Font loading on Renderer Init due to 3ds Freezes when using SystemFont
- Make SystemFont lineheight 10% larger than it is to be nearly the same size as the ttf fonts
- Fix Some SpaceOffsets between TTF and SystemFont Rendering
- Cleanup the Update Rendermode Func
- Use LayerRenderSystem by default now as it now runs faster even with ttf fonts
2025-01-19 20:16:43 +01:00
d815bb5674 # Rewrite Stage 1
- Switch to CMake build system
- delete everything for a new structure
- Add SmartCtor class and saperate New func
- New Faster and Open Lithium Command API
- Rewritten Text Renderer to ghet rid of all that janky code
- New TimeTrace System and use of NanoTime using GetTimeNano
- Overall going to a more Object oriented way
- Updated vec api to support vec2 input on vec3
## Todo
- Support vec2 and vec3 in vec4 as inputs
- Continue UI7
- Fix SystemFont on 3ds freezing the system
- Fix TTF Font UV Mapping
## Warning
Creating Apps for the 3ds is not possible yet as the 3ds is Freezing and this is only stage 1 of ?   Emulator works perfect
2025-01-09 20:22:49 +01:00
185 changed files with 32247 additions and 52034 deletions

334
.clang-format Normal file
View File

@@ -0,0 +1,334 @@
---
Language: Cpp
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: true
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveShortCaseStatements:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCaseArrows: false
AlignCaseColons: false
AlignConsecutiveTableGenBreakingDAGArgColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveTableGenCondOperatorColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveTableGenDefinitionColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Never
AllowShortBlocksOnASingleLine: Never
AllowShortCaseExpressionOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AllowShortNamespacesOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AttributeMacros:
- __capability
- absl_nonnull
- absl_nullable
- absl_nullability_unknown
BinPackArguments: true
BinPackLongBracedList: true
BinPackParameters: BinPack
BitFieldColonSpacing: Both
BracedInitializerIndentWidth: -1
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAdjacentStringLiterals: true
BreakAfterAttributes: Leave
BreakAfterJavaFieldAnnotations: false
BreakAfterReturnType: None
BreakArrays: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Attach
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTemplateCloser: false
BreakBeforeTernaryOperators: true
BreakBinaryOperations: Never
BreakConstructorInitializers: BeforeColon
BreakFunctionDefinitionParameters: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
BreakTemplateDeclarations: Yes
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
EnumTrailingComma: Leave
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 3
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExportBlock: true
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
BinaryMinDigits: 0
Decimal: 0
DecimalMinDigits: 0
Hex: 0
HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: false
AtStartOfFile: true
KeepFormFeed: false
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
MainIncludeChar: Quote
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
OneLineFormatOffRegex: ''
PackConstructorInitializers: NextLine
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakBeforeMemberAccess: 150
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakScopeResolution: 500
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
PPIndentWidth: -1
QualifierAlignment: Leave
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
- ParseTestProto
- ParsePartialTestProto
CanonicalDelimiter: pb
BasedOnStyle: google
ReferenceAlignment: Pointer
ReflowComments: Always
RemoveBracesLLVM: false
RemoveEmptyLinesInUnwrappedLines: false
RemoveParentheses: Leave
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SkipMacroDefinitionBody: false
SortIncludes:
Enabled: true
IgnoreCase: false
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterOperatorKeyword: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterNot: false
AfterOverloadedOperator: false
AfterPlacementOperator: true
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParens: Never
SpacesInParensOptions:
ExceptDoubleParentheses: false
InCStyleCasts: false
InConditionalStatements: false
InEmptyParentheses: false
Other: false
SpacesInSquareBrackets: false
Standard: Auto
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TableGenBreakInsideDAGArg: DontBreak
TabWidth: 8
UseTab: Never
VerilogBreakBetweenInstancePorts: true
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE
WrapNamespaceBodyWithEmptyLines: Leave
...

5
.clangd Normal file
View File

@@ -0,0 +1,5 @@
CompileFlags:
Add: []
Completion:
HeaderInsertion: Never

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
vendor/* linguist-vendored

3
.gitignore vendored Executable file
View File

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

9
.gitmodules vendored Normal file
View File

@@ -0,0 +1,9 @@
[submodule "vendor/stb"]
path = vendor/stb
url = https://github.com/nothings/stb.git
[submodule "vendor/glfw"]
path = vendor/glfw
url = https://github.com/glfw/glfw.git
[submodule "vendor/libpicasso"]
path = vendor/libpicasso
url = https://github.com/tobid7/libpicasso

View File

@@ -1,18 +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/**",
"/opt/devkitpro/libctru/include/**",
"/opt/devkitpro/portlibs/**"
]
}
],
"version": 4
}

118
.vscode/settings.json vendored
View File

@@ -1,118 +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"
}
}

View File

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

139
CMakeLists.txt Executable file
View File

@@ -0,0 +1,139 @@
cmake_minimum_required(VERSION 3.22)
include(GNUInstallDirs)
# Set Project
project(palladium LANGUAGES C CXX VERSION 0.7.0)
# Required to add this Variable
set(PD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
include(cmake/palladium.cmake)
option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)
option(PD_BUILD_SHARED "Build Shared Library" OFF)
option(PD_BUILD_TOOLS "Build Palladium Tools" OFF)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
add_compile_options(-Wno-psabi)
endif()
if(${PD_BUILD_TOOLS})
add_subdirectory(tools)
endif()
add_subdirectory(vendor)
# # Include Library Source
set(PD_SOURCES
# Common
source/common.cpp
# Core
source/core/bits.cpp
source/core/color.cpp
source/core/io.cpp
source/core/mat.cpp
source/core/strings.cpp
source/core/timer.cpp
source/core/timetrace.cpp
# Drivers
source/drivers/os.cpp
source/drivers/gfx.cpp
# Lithium
source/lithium/pools.cpp
)
if(${PD_BUILD_SHARED})
add_library(palladium SHARED ${PD_SOURCES})
target_compile_definitions(palladium PRIVATE PD_BUILD_SHARED)
else()
add_library(palladium STATIC ${PD_SOURCES})
target_compile_definitions(palladium PUBLIC PD_BUILD_STATIC)
endif()
target_compile_definitions(palladium PUBLIC PD_DEBUG)
target_compile_options(palladium
PUBLIC $<$<CXX_COMPILER_ID:GNU,Clang>:
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/source=source
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/include=include
>
)
add_library(palladium::palladium ALIAS palladium)
target_include_directories(palladium
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_options(palladium
PRIVATE
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:GNU,Clang>>:-O0 -g>
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:GNU,Clang>>:-O3>
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>>:/Od /Zi>
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:MSVC>>:/O2>
)
install(
TARGETS palladium
EXPORT palladiumTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(EXPORT palladiumTargets
FILE palladiumTargets.cmake
NAMESPACE palladium::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/palladium
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/palladiumConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfig.cmake
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/palladium
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfigVersion.cmake
VERSION
${PROJECT_VERSION}
COMPATIBILITY
SameMajorVersion
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/palladium
)
find_program(CLANG_FORMAT clang-format)
file(GLOB_RECURSE PD_FMTFILES
CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/backends/source/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/backends/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/core/source/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/gfx/source/*.cpp
)
add_custom_target(pd-clang-format
COMMAND ${CLANG_FORMAT} --style=file -i ${PD_FMTFILES}
COMMENT "Formatting Project Sources"
)
add_subdirectory(backends)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)

4
LICENSE Normal file → Executable file
View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2024 tobid7
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ 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.
SOFTWARE.

152
Makefile
View File

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

83
README.md Normal file → Executable file
View File

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

72
backends/CMakeLists.txt Normal file
View File

@@ -0,0 +1,72 @@
cmake_minimum_required(VERSION 3.22)
project(pd-system)
option(PD_ENABLE_OPENGL2 "Enable OpenGL 2.1 (On Supported Hardware)" ON)
option(PD_ENABLE_OPENGL3 "Enable OpenGL 3.3 (On Supported Hardware)" ON)
option(PD_ENABLE_DIRECTX9 "Enable DirectX9 Support" ON)
option(PD_ENABLE_CITRO3D "Enable Citro3D Support (3DS)" OFF)
option(PD_ENABLE_VULKAN "Not implemented yet" OFF)
if(NOT WIN32) # cause we are not on windows...
set(PD_ENABLE_DIRECTX9 OFF)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
set(PD_ENABLE_OPENGL2 OFF)
set(PD_ENABLE_OPENGL3 OFF)
set(PD_ENABLE_VULKAN OFF)
set(PD_ENABLE_CITRO3D ON)
endif()
add_library(pd-system STATIC
${CMAKE_CURRENT_SOURCE_DIR}/source/gl-helper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_directx9.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_citro3d.cpp
)
target_include_directories(pd-system
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_options(palladium
PUBLIC $<$<CXX_COMPILER_ID:GNU,Clang>:
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/source=source
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/include=include
>
)
target_compile_definitions(pd-system
PUBLIC
$<$<BOOL:${PD_ENABLE_OPENGL2}>:PD_ENABLE_OPENGL2>
$<$<BOOL:${PD_ENABLE_OPENGL3}>:PD_ENABLE_OPENGL3>
$<$<BOOL:${PD_ENABLE_VULKAN}>:PD_ENABLE_VULKAN>
$<$<BOOL:${PD_ENABLE_DIRECTX9}>:PD_ENABLE_DIRECTX9>
$<$<BOOL:${PD_ENABLE_CITRO3D}>:PD_ENABLE_CITRO3D>
)
# Palladium
target_link_libraries(pd-system PUBLIC palladium::palladium)
# glad (if we have any OpenGL version included)
if(PD_ENABLE_OPENGL2 OR PD_ENABLE_OPENGL3)
target_link_libraries(pd-system
PUBLIC glad
)
endif()
# DirectX9
if(PD_ENABLE_DIRECTX9)
target_link_libraries(pd-system
PUBLIC
d3d9
d3dcompiler
)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
target_link_libraries(pd-system PUBLIC pica::pica citro3d ctru)
endif()

View File

@@ -0,0 +1,67 @@
#pragma once
#ifdef __3DS__
#include <3ds.h>
#endif
#include <limits>
#include <memory>
#include <stdexcept>
// Custom C++ Allocator class to interface with libctru linear heap memory
// based on this guide:
// https://johnfarrier.com/custom-allocators-in-c-high-performance-memory-management/
namespace PD {
template <typename T>
class LinearAllocator {
public:
using value_type = T;
LinearAllocator() noexcept = default;
template <typename U>
constexpr LinearAllocator(const LinearAllocator<U>&) noexcept {}
T* allocate(std::size_t n) {
if (n > max_size()) {
throw std::runtime_error("[PD] LinearAllocator: Bad alloc!");
}
#ifdef __3DS__
return static_cast<T*>(linearAlloc(n * sizeof(T)));
#else
return static_cast<T*>(malloc(n * sizeof(T)));
#endif
}
#ifdef __3DS__
void deallocate(T* p, std::size_t) noexcept { linearFree(p); }
#else
void deallocate(T* p, std::size_t) noexcept { free(p); }
#endif
template <class U, class... Args>
void construct(U* p, Args&&... args) {
::new ((void*)p) U(std::forward<Args>(args)...);
}
template <class U>
void destroy(U* p) {
p->~U();
}
friend bool operator==(const LinearAllocator, const LinearAllocator) {
return true;
}
friend bool operator!=(const LinearAllocator, const LinearAllocator) {
return false;
}
#ifdef __3DS__
// Use linearSpace free as max_size to not allocate out of bounds
// or to b eable to see a crash report screen.
size_t max_size() const noexcept { return linearSpaceFree(); }
#else
size_t max_size() const noexcept {
return std::numeric_limits<size_t>::max();
}
#endif
};
} // namespace PD

View File

@@ -0,0 +1,39 @@
#pragma once
#include <pd/drivers/gfx.hpp>
#include <pd_system/ctr-linear-allocator.hpp>
namespace PD {
struct GfxCitro3DConfig {
// Vertex Allocator
template <typename T>
using VertexAlloc = LinearAllocator<T>;
// Index Allocator
template <typename T>
using IndexAlloc = LinearAllocator<T>;
static constexpr size_t NumVertices = 32768; // 8192*4
static constexpr size_t NumIndices = 49152; // 8192*6
};
class GfxCitro3D : public GfxDriverBase<GfxCitro3DConfig> {
public:
GfxCitro3D() : GfxDriverBase("Citro3D") {}
~GfxCitro3D() {}
void SysInit() override;
void SysDeinit() override;
void Submit(size_t count, size_t start) override;
void BindTexture(TextureID id) override;
void SysReset() override;
Li::Texture LoadTexture(
const std::vector<PD::u8>& pixels, int w, int h,
TextureFormat type = TextureFormat::RGBA32,
TextureFilter filter = TextureFilter::Linear) override;
void DeleteTexture(const Li::Texture& tex) override;
private:
struct Impl;
Impl* impl = nullptr;
};
} // namespace PD

View File

@@ -0,0 +1,40 @@
#pragma once
#include <pd/drivers/gfx.hpp>
namespace PD {
struct GfxDirectX9Config {
// Vertex Allocator
template <typename T>
using VertexAlloc = std::allocator<T>;
// Index Allocator
template <typename T>
using IndexAlloc = std::allocator<T>;
static constexpr size_t NumVertices = 32768; // 8192*4
static constexpr size_t NumIndices = 49152; // 8192*6
};
class GfxDirectX9 : public GfxDriverBase<GfxDirectX9Config> {
public:
GfxDirectX9(void* device = nullptr)
: GfxDriverBase("DirectX9"), pDevice(device) {}
~GfxDirectX9() {}
void SysInit() override;
void SysDeinit() override;
void Submit(size_t count, size_t start) override;
void BindTexture(TextureID id) override;
void SysReset() override;
Li::Texture LoadTexture(
const std::vector<PD::u8>& pixels, int w, int h,
TextureFormat type = TextureFormat::RGBA32,
TextureFilter filter = TextureFilter::Linear) override;
void DeleteTexture(const Li::Texture& tex) override;
private:
struct Impl;
Impl* impl = nullptr;
void* pDevice = nullptr;
};
} // namespace PD

View File

@@ -0,0 +1,45 @@
#pragma once
#include <pd/drivers/gfx.hpp>
namespace PD {
struct GfxOpenGL2Config {
// Vertex Allocator
template <typename T>
using VertexAlloc = std::allocator<T>;
// Index Allocator
template <typename T>
using IndexAlloc = std::allocator<T>;
static constexpr size_t NumVertices = 32768; // 8192*4
static constexpr size_t NumIndices = 49152; // 8192*6
};
class GfxOpenGL2 : public GfxDriverBase<GfxOpenGL2Config> {
public:
GfxOpenGL2() : GfxDriverBase("OpenGL2") {}
~GfxOpenGL2() {}
void SysInit() override;
void SysDeinit() override;
void Submit(size_t count, size_t start) override;
void BindTexture(TextureID id) override;
void SysReset() override;
Li::Texture LoadTexture(
const std::vector<PD::u8>& pixels, int w, int h,
TextureFormat type = TextureFormat::RGBA32,
TextureFilter filter = TextureFilter::Linear) override;
void DeleteTexture(const Li::Texture& tex) override;
private:
void pSetupShaderAttribs(u32 shader);
u32 pShader = 0;
u32 VBO = 0;
u32 IBO = 0;
int pLocTex = 0;
int pLocAlfa = 0;
int pLocProjection = 0;
static const char* pVertCode;
static const char* pFragCode;
};
} // namespace PD

View File

@@ -0,0 +1,45 @@
#pragma once
#include <pd/drivers/gfx.hpp>
namespace PD {
struct GfxOpenGL3Config {
// Vertex Allocator
template <typename T>
using VertexAlloc = std::allocator<T>;
// Index Allocator
template <typename T>
using IndexAlloc = std::allocator<T>;
static constexpr size_t NumVertices = 32768; // 8192*4
static constexpr size_t NumIndices = 49152; // 8192*6
};
class GfxOpenGL3 : public GfxDriverBase<GfxOpenGL3Config> {
public:
GfxOpenGL3() : GfxDriverBase("OpenGL3") {}
~GfxOpenGL3() {}
void SysInit() override;
void SysDeinit() override;
void Submit(size_t count, size_t start) override;
void BindTexture(TextureID id) override;
void SysReset() override;
Li::Texture LoadTexture(
const std::vector<PD::u8>& pixels, int w, int h,
TextureFormat type = TextureFormat::RGBA32,
TextureFilter filter = TextureFilter::Linear) override;
void DeleteTexture(const Li::Texture& tex) override;
private:
u32 pShader = 0;
u32 VBO = 0;
u32 IBO = 0;
u32 VAO = 0;
int pLocTex = 0;
int pLocAlfa = 0;
int pLocProjection = 0;
static const char* pVertCode;
static const char* pFragCode;
};
} // namespace PD

View File

@@ -0,0 +1,7 @@
#pragma once
#include <pd/common.hpp>
namespace PD {
u32 CreateShaderProgram(const char* vert, const char* frag);
}

View File

@@ -0,0 +1,6 @@
#pragma once
#include <pd_system/gfx_citro3d.hpp>
#include <pd_system/gfx_directx9.hpp>
#include <pd_system/gfx_opengl2.hpp>
#include <pd_system/gfx_opengl3.hpp>

View File

@@ -0,0 +1,254 @@
// Well yes, i finally try it
#include <pd/core/core.hpp>
#include <pd/lithium/formatters.hpp>
#include <pd_system/gfx_citro3d.hpp>
#if defined(PD_ENABLE_CITRO3D) && defined(__3DS__)
#include <3ds.h>
#include <citro3d.h>
#include <pd/drivers/drivers.hpp>
#include <pica.hpp>
namespace PD {
const char* LIShaderCTR = R"(
; LI7 Shader
; Constants
.constf myconst(0.0, 1.0, 0.00392156862745, 0.0)
.alias ones myconst.yyyy ; Vector full of ones
; Uniforms
.fvec projection[4]
; Outputs
.out out_position position
.out out_color color
.out out_uv texcoord0
; Inputs
.alias in_xy v0
.alias in_uvc v1
.alias in_col v2
.entry vmain
.proc vmain
mov r0.xy, in_xy.xy
mov r0.w, ones
dp4 out_position.x, projection[0], r0
dp4 out_position.y, projection[1], r0
dp4 out_position.z, projection[2], r0
dp4 out_position.w, projection[3], r0
mov out_uv, in_uvc.xy
mul r1, myconst.zzzz, in_col
mov out_color, r1
end
.end
)";
struct GfxCitro3D::Impl {
C3D_AttrInfo pAttr;
shaderProgram_s pShader;
DVLB_s* pCode;
int uLocProjection = 0;
C3D_Tex* CurrentTex = nullptr;
std::vector<u8> pShaderRaw;
GPU_TEXCOLOR TextureTranslateFormat(TextureFormat fmt) {
switch (fmt) {
case PD::TextureFormat::A8:
return GPU_A8;
case PD::TextureFormat::RGB24:
return GPU_RGB8;
case PD::TextureFormat::RGBA32:
return GPU_RGBA8;
default:
return GPU_RGBA8;
}
}
int TextureFormat2Bpp(TextureFormat fmt) {
switch (fmt) {
case PD::TextureFormat::A8:
return 1;
case PD::TextureFormat::RGB24:
return 3;
case PD::TextureFormat::RGBA32:
return 4;
default:
return 0;
}
}
void SetupPixelStage() {
shaderProgramUse(&pShader);
C3D_BindProgram(&pShader);
C3D_SetAttrInfo(&pAttr);
C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL);
if (!CurrentTex) return;
C3D_TexEnv* env = C3D_GetTexEnv(0);
C3D_TexEnvInit(env);
switch (CurrentTex->fmt) {
case GPU_A4:
case GPU_A8:
case GPU_L4:
case GPU_L8:
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0);
C3D_TexEnvFunc(env, C3D_RGB, GPU_REPLACE);
C3D_TexEnvFunc(env, C3D_Alpha, GPU_MODULATE);
break;
case GPU_RGB565:
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0);
C3D_TexEnvFunc(env, C3D_RGB, GPU_MODULATE);
C3D_TexEnvFunc(env, C3D_Alpha, GPU_REPLACE);
break;
default:
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0);
C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
break;
}
}
};
void GfxCitro3D::SysInit() {
if (impl) return;
PDLOG("GfxCitro3D::SysInit();");
impl = new Impl();
impl->pShaderRaw = Pica::AssembleCode(LIShaderCTR);
impl->pCode = DVLB_ParseFile((uint32_t*)impl->pShaderRaw.data(),
impl->pShaderRaw.size());
shaderProgramInit(&impl->pShader);
shaderProgramSetVsh(&impl->pShader, &impl->pCode->DVLE[0]);
impl->uLocProjection = shaderInstanceGetUniformLocation(
impl->pShader.vertexShader, "projection");
AttrInfo_Init(&impl->pAttr);
AttrInfo_AddLoader(&impl->pAttr, 0, GPU_FLOAT, 2);
AttrInfo_AddLoader(&impl->pAttr, 1, GPU_FLOAT, 2);
AttrInfo_AddLoader(&impl->pAttr, 2, GPU_UNSIGNED_BYTE, 4);
}
void GfxCitro3D::SysDeinit() {
if (!impl) return;
shaderProgramFree(&impl->pShader);
DVLB_Free(impl->pCode);
delete impl;
impl = nullptr;
PDLOG("GfxCitro3D::SysDeinit()");
}
void GfxCitro3D::Submit(size_t count, size_t start) {
if (!impl) return;
BindTexture(CurrentTex);
impl->SetupPixelStage(); // needs to be called after
C3D_Mtx proj;
Mtx_OrthoTilt(&proj, 0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f, false);
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, impl->uLocProjection, &proj);
// C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, impl->uLocProjection,
// (C3D_Mtx*)&Projection);
auto buf = C3D_GetBufInfo();
BufInfo_Init(buf);
BufInfo_Add(buf, GetVertexBufPtr(0), sizeof(Li::Vertex), 3, 0x210);
C3D_DrawElements(GPU_TRIANGLES, count, C3D_UNSIGNED_SHORT,
GetIndexBufPtr(start));
impl->CurrentTex = nullptr;
}
void GfxCitro3D::BindTexture(TextureID id) {
if (!impl || !id) return;
impl->CurrentTex = (C3D_Tex*)id;
C3D_TexBind(0, (C3D_Tex*)id);
}
void GfxCitro3D::SysReset() {
if (!impl) return;
C3D_CullFace(GPU_CULL_NONE);
}
Li::Texture GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
int h, TextureFormat type,
TextureFilter filter) {
if (!impl || w > 1024 || h > 1024) return Li::Texture();
// Don't check here as check done before
PD::Li::Texture res;
int bpp = impl->TextureFormat2Bpp(type);
ivec2 tex_size(w, h);
// Pow2
if (!PD::Bits::IsSingleBit(w)) {
tex_size.x = PD::Bits::GetPow2((unsigned int)w);
}
if (!PD::Bits::IsSingleBit(h)) {
tex_size.y = PD::Bits::GetPow2((unsigned int)h);
}
res.SetSize(w, h);
res.SetUV(0.f, 1.f, ((float)w / (float)tex_size.x),
1.0 - ((float)h / (float)tex_size.y));
// Texture Setup
auto fltr = (filter == TextureFilter::Linear ? GPU_NEAREST : GPU_LINEAR);
auto tex_fmt = impl->TextureTranslateFormat(type);
auto tex = new C3D_Tex;
C3D_TexInit(tex, (u16)tex_size.x, (u16)tex_size.y, tex_fmt);
C3D_TexSetFilter(tex, fltr, fltr);
std::memset((PD::u8*)tex->data, 0x0, tex->size);
/// Probably Remove this if statement in future
/// This are the things confirmed as working
if (bpp == 3 || bpp == 4 || bpp == 1) {
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
int dst_pos = ((((y >> 3) * ((int)tex_size.x >> 3) + (x >> 3)) << 6) +
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
bpp;
int src_pos = (y * w + x) * bpp;
/// Best idea i had
for (int i = 0; i < bpp; i++) {
((u8*)tex->data)[dst_pos + bpp - 1 - i] = pixels[src_pos + i];
}
}
}
C3D_TexFlush(tex);
}
tex->border = 0x00000000;
C3D_TexSetWrap(tex, GPU_REPEAT, GPU_REPEAT);
res.SetID((TextureID)tex);
RegisterTexture(res);
PDLOG("GfxCitro3D::LoadTexture -> {{ {} }}, [{}, {}]", res, type, filter);
return res;
}
void GfxCitro3D::DeleteTexture(const Li::Texture& tex) {
if (!tex.GetID()) return;
UnregisterTexture(tex);
C3D_Tex* t = reinterpret_cast<C3D_Tex*>(tex.GetID());
C3D_TexDelete(t);
delete t;
}
} // namespace PD
#else
namespace PD {
void GfxCitro3D::SysInit() {
PDLOG(
"GfxCitro3D::SysInit: Citro3D Driver is not included in "
"palladium-system");
}
void GfxCitro3D::SysDeinit() {}
void GfxCitro3D::Submit(size_t count, size_t start) {}
void GfxCitro3D::BindTexture(TextureID id) {}
void GfxCitro3D::SysReset() {}
Li::Texture GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
int h, TextureFormat type,
TextureFilter filter) {
return Li::Texture();
}
void GfxCitro3D::DeleteTexture(const Li::Texture& tex) {}
} // namespace PD
#endif

View File

@@ -0,0 +1,273 @@
// Well yes, i finally try it
#include <pd/lithium/formatters.hpp>
#include <pd_system/gfx_directx9.hpp>
// Sicher ist sicher
#if defined(PD_ENABLE_DIRECTX9) && defined(_WIN32)
#include <d3d9.h>
#include <d3dcompiler.h>
#include <pd/drivers/drivers.hpp>
namespace PD {
static const char* g_vsCode = R"(
float4x4 projection;
struct VS_IN {
float2 pos : POSITION0;
float2 uv : TEXCOORD0;
float4 col : COLOR0;
};
struct VS_OUT {
float4 pos : POSITION0;
float2 uv : TEXCOORD0;
float4 col : COLOR0;
};
VS_OUT main(VS_IN input) {
VS_OUT o;
o.pos = mul(projection, float4(input.pos, 0.0, 1.0));
o.uv = input.uv;
o.col = input.col;
return o;
}
)";
static const char* g_psCode = R"(
sampler2D tex : register(s0);
float alfa;
struct PS_IN {
float2 uv : TEXCOORD0;
float4 col : COLOR0;
};
float4 main(PS_IN input) : COLOR0 {
float4 tc = tex2D(tex, input.uv);
if (alfa > 0.5)
return float4(input.col.rgb, tc.a * input.col.a);
else
return tc * input.col;
}
)";
struct GfxDirectX9::Impl {
IDirect3DDevice9* Device = nullptr;
IDirect3DVertexBuffer9* VBO = nullptr;
IDirect3DIndexBuffer9* IBO = nullptr;
IDirect3DVertexDeclaration9* Decl = nullptr;
IDirect3DVertexShader9* VS = nullptr;
IDirect3DPixelShader9* FS = nullptr;
IDirect3DTexture9* CurrentTex = nullptr;
};
void GfxDirectX9::SysInit() {
if (impl) return;
PDLOG("GfxDirectX9::SysInit();");
impl = new Impl();
impl->Device = (IDirect3DDevice9*)pDevice;
if (impl->Device) {
D3DVERTEXELEMENT9 elements[]{
{0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,
0},
{0, 8, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,
0},
{0, 16, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR,
0},
D3DDECL_END()};
impl->Device->CreateVertexDeclaration(elements, &impl->Decl);
impl->Device->CreateVertexBuffer(
GfxDirectX9Config::NumVertices * sizeof(PD::Li::Vertex),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &impl->VBO,
nullptr);
impl->Device->CreateIndexBuffer(GfxDirectX9Config::NumIndices * sizeof(u16),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_DEFAULT, &impl->IBO,
nullptr);
ID3DBlob* vsBlob = nullptr;
ID3DBlob* errBlob = nullptr;
HRESULT hr = D3DCompile(g_vsCode, strlen(g_vsCode), nullptr, nullptr,
nullptr, "main", "vs_2_0", 0, 0, &vsBlob, &errBlob);
if (FAILED(hr)) {
PDLOG("Vertex Shader compile error: {}",
errBlob ? (char*)errBlob->GetBufferPointer() : "");
} else {
impl->Device->CreateVertexShader((DWORD*)vsBlob->GetBufferPointer(),
&impl->VS);
}
if (vsBlob) vsBlob->Release();
if (errBlob) errBlob->Release();
ID3DBlob* psBlob = nullptr;
errBlob = nullptr;
hr = D3DCompile(g_psCode, strlen(g_psCode), nullptr, nullptr, nullptr,
"main", "ps_2_0", 0, 0, &psBlob, &errBlob);
if (FAILED(hr)) {
PDLOG("Pixel Shader compile error: {}",
errBlob ? (char*)errBlob->GetBufferPointer() : "");
} else {
impl->Device->CreatePixelShader((DWORD*)psBlob->GetBufferPointer(),
&impl->FS);
}
if (psBlob) psBlob->Release();
if (errBlob) errBlob->Release();
} else {
PDLOG(
"GfxDirectX9::SysInit Error: pDevice is not set!\nYOu need to include "
"your D3D9 Device as "
"folowing:\nPD::Gfx::UseDriver<PD::GfxDirectX9>(D3D9Device);");
}
}
void GfxDirectX9::SysDeinit() {
if (!impl || !impl->Device) return;
if (impl->VBO) impl->VBO->Release();
if (impl->IBO) impl->IBO->Release();
if (impl->Decl) impl->Decl->Release();
if (impl->VS) impl->VS->Release();
if (impl->FS) impl->FS->Release();
delete impl;
impl = nullptr;
PDLOG("GfxDirectX9::SysDeinit()");
}
void GfxDirectX9::Submit(size_t count, size_t start) {
if (!impl || !impl->Device || !impl->VBO || !impl->IBO) return;
BindTexture(CurrentTex);
impl->Device->SetVertexShaderConstantF(
0, reinterpret_cast<const float*>(&Projection), 4);
void* vptr;
impl->VBO->Lock(0, 0, &vptr, D3DLOCK_DISCARD);
memcpy(vptr, GetVertexBufPtr(0), CurrentVertex * sizeof(PD::Li::Vertex));
impl->VBO->Unlock();
void* iptr;
impl->IBO->Lock(0, 0, &iptr, D3DLOCK_DISCARD);
memcpy(iptr, GetIndexBufPtr(0), CurrentIndex * sizeof(u16));
impl->IBO->Unlock();
impl->Device->SetStreamSource(0, impl->VBO, 0, sizeof(PD::Li::Vertex));
impl->Device->SetIndices(impl->IBO);
impl->Device->SetVertexDeclaration(impl->Decl);
impl->Device->SetVertexShader(impl->VS);
impl->Device->SetPixelShader(impl->FS);
impl->Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, CurrentVertex,
start, count / 3);
}
void GfxDirectX9::BindTexture(TextureID id) {
if (!impl || !impl->Device) return;
impl->CurrentTex = (IDirect3DTexture9*)id;
impl->Device->SetTexture(0, impl->CurrentTex);
bool a8 = false;
if (impl->CurrentTex) {
D3DSURFACE_DESC desc;
impl->CurrentTex->GetLevelDesc(0, &desc);
a8 = (desc.Format == D3DFMT_A8);
}
float v = a8 ? 1.0f : 0.0f;
impl->Device->SetPixelShaderConstantF(0, &v, 1);
}
void GfxDirectX9::SysReset() {
if (!impl || !impl->Device) return;
impl->Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
impl->Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
impl->Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
}
Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
int h, TextureFormat type,
TextureFilter filter) {
if (!impl || !impl->Device) return Li::Texture();
IDirect3DTexture9* tex = nullptr;
D3DFORMAT fmt = D3DFMT_A8R8G8B8;
if (type == TextureFormat::RGB24)
fmt = D3DFMT_X8R8G8B8;
else if (type == TextureFormat::A8)
fmt = D3DFMT_A8;
HRESULT hr = impl->Device->CreateTexture(w, h, 1, 0, fmt, D3DPOOL_MANAGED,
&tex, nullptr);
if (FAILED(hr) || !tex) return Li::Texture();
D3DLOCKED_RECT rect;
tex->LockRect(0, &rect, nullptr, 0);
if (type == TextureFormat::RGB24) {
u8* dstRow = reinterpret_cast<u8*>(rect.pBits);
for (int y = 0; y < h; ++y) {
u32* dst = reinterpret_cast<u32*>(dstRow);
for (int x = 0; x < w; ++x) {
u8 r = pixels[(y * w + x) * 3 + 0];
u8 g = pixels[(y * w + x) * 3 + 1];
u8 b = pixels[(y * w + x) * 3 + 2];
dst[x] = (0xFF << 24) | (r << 16) | (g << 8) | b;
}
dstRow += rect.Pitch;
}
} else if (type == TextureFormat::RGBA32) {
u8* dstRow = reinterpret_cast<u8*>(rect.pBits);
for (int y = 0; y < h; ++y) {
u32* dst = reinterpret_cast<u32*>(dstRow);
for (int x = 0; x < w; ++x) {
u8 r = pixels[(y * w + x) * 4 + 0];
u8 g = pixels[(y * w + x) * 4 + 1];
u8 b = pixels[(y * w + x) * 4 + 2];
u8 a = pixels[(y * w + x) * 4 + 3];
dst[x] = (a << 24) | (r << 16) | (g << 8) | b;
}
dstRow += rect.Pitch;
}
} else if (type == TextureFormat::A8) {
u8* dstRow = reinterpret_cast<u8*>(rect.pBits);
for (int y = 0; y < h; ++y) {
memcpy(dstRow, &pixels[y * w], w);
dstRow += rect.Pitch;
}
}
tex->UnlockRect(0);
Li::Texture res;
res.SetID((TextureID)tex);
res.SetSize(w, h);
res.SetUV(0.f, 0.f, 1.f, 1.f);
RegisterTexture(res);
PDLOG("GfxDirectX9::LoadTexture -> {{ {} }}, [{}, {}]", res, type, filter);
return res;
}
void GfxDirectX9::DeleteTexture(const Li::Texture& tex) {
if (!tex.GetID()) return;
UnregisterTexture(tex);
IDirect3DTexture9* t = (IDirect3DTexture9*)tex.GetID();
t->Release();
}
} // namespace PD
#else
namespace PD {
void GfxDirectX9::SysInit() {
PDLOG(
"GfxDirectX9::SysInit: DirectX9 Driver is not included in "
"palladium-system");
}
void GfxDirectX9::SysDeinit() {}
void GfxDirectX9::Submit(size_t count, size_t start) {}
void GfxDirectX9::BindTexture(TextureID id) {}
void GfxDirectX9::SysReset() {}
Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
int h, TextureFormat type,
TextureFilter filter) {
return Li::Texture();
}
void GfxDirectX9::DeleteTexture(const Li::Texture& tex) {}
} // namespace PD
#endif

View File

@@ -0,0 +1,190 @@
#include <pd/lithium/formatters.hpp>
#include <pd_system/gfx_opengl2.hpp>
#if defined(PD_ENABLE_OPENGL2)
#include <glad/glad.h>
#include <pd/drivers/drivers.hpp>
#include <pd_system/gl-helper.hpp>
namespace PD {
const char* GfxOpenGL2::pVertCode = R"(
#version 120
attribute vec2 pos;
attribute vec2 uv;
attribute vec4 color;
varying vec2 oUV;
varying vec4 oColor;
// Probably forgot about this matrix and
// searched hours for why the rendering isn't working :/
uniform mat4 projection;
void main() {
gl_Position = projection*vec4(pos, 0.0, 1.0);
oUV = uv;
oColor = color;
}
)";
const char* GfxOpenGL2::pFragCode = R"(
#version 120
varying vec2 oUV;
varying vec4 oColor;
uniform sampler2D tex;
uniform bool alfa;
void main() {
vec4 tc = texture2D(tex, oUV);
if (alfa) {
gl_FragColor = vec4(oColor.rgb, tc.a * oColor.a);
} else {
gl_FragColor = tc * oColor;
}
}
)";
void GfxOpenGL2::pSetupShaderAttribs(u32 shader) {
GLint _pos = glGetAttribLocation(shader, "pos");
GLint _uv = glGetAttribLocation(shader, "uv");
GLint _color = glGetAttribLocation(shader, "color");
glVertexAttribPointer(_pos, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, pos));
glEnableVertexAttribArray(_pos);
glVertexAttribPointer(_uv, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, uv));
glEnableVertexAttribArray(_uv);
glVertexAttribPointer(_color, 4, GL_UNSIGNED_BYTE, GL_TRUE,
sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, color));
glEnableVertexAttribArray(_color);
}
void GfxOpenGL2::SysInit() {
pShader = CreateShaderProgram(pVertCode, pFragCode);
glUseProgram(pShader);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glGenBuffers(1, &IBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
pSetupShaderAttribs(pShader);
pLocTex = glGetUniformLocation(pShader, "tex");
pLocAlfa = glGetUniformLocation(pShader, "alfa");
pLocProjection = glGetUniformLocation(pShader, "projection");
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
PDLOG(
"GfxOpenGL2::SysInit():\n pShader = {}\n pLocTex = {}\n pLocAlfa = "
"{}\n pLocProjection = {}\n VBO = {}\n IBO = {}",
pShader, pLocTex, pLocAlfa, pLocProjection, VBO, IBO);
}
void GfxOpenGL2::SysDeinit() {
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &IBO);
PDLOG("GfxOpenGL2::SysDeinit()");
}
void GfxOpenGL2::Submit(size_t count, size_t start) {
BindTexture(CurrentTex);
glUseProgram(pShader);
glUniformMatrix4fv(pLocProjection, 1, GL_FALSE, Projection.m.data());
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
GetVertexBufPtr(0), GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(PD::u16),
GetIndexBufPtr(0), GL_DYNAMIC_DRAW);
pSetupShaderAttribs(pShader);
GLint ibo = 0;
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &ibo);
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT,
reinterpret_cast<void*>(start * sizeof(u16)));
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
BindTexture(0);
}
void GfxOpenGL2::BindTexture(TextureID id) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, (GLuint)id);
glUniform1i(pLocTex, 0);
GLint fmt = 0;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
glUniform1i(pLocAlfa, fmt == GL_ALPHA);
}
void GfxOpenGL2::SysReset() {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
Li::Texture GfxOpenGL2::LoadTexture(const std::vector<PD::u8>& pixels, int w,
int h, TextureFormat type,
TextureFilter filter) {
GLuint texID;
glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);
// Set base format (Always using RGBA as base)
GLenum fmt = GL_RGBA;
if (type == TextureFormat::RGB24) {
fmt = GL_RGB;
} else if (type == TextureFormat::A8) {
fmt = GL_ALPHA;
}
glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
pixels.data());
if (filter == TextureFilter::Linear) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else if (filter == TextureFilter::Nearest) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
glBindTexture(GL_TEXTURE_2D, 0);
Li::Texture res;
res.SetID(texID);
res.SetSize(w, h);
res.SetUV(0.f, 0.f, 1.f, 1.f);
RegisterTexture(res);
PDLOG("GfxOpenGL2::LoadTexture -> {{ {} }}, [{}, {}]", res, type, filter);
return res;
}
void GfxOpenGL2::DeleteTexture(const Li::Texture& tex) {
UnregisterTexture(tex);
GLuint tex_ = tex.GetID();
glDeleteTextures(1, &tex_);
}
} // namespace PD
#else
namespace PD {
void GfxOpenGL2::SysInit() {
PDLOG(
"GfxOpenGL2::SysInit: OpenGL2 Driver is not included in "
"palladium-system");
}
void GfxOpenGL2::SysDeinit() {}
void GfxOpenGL2::Submit(size_t count, size_t start) {}
void GfxOpenGL2::BindTexture(TextureID id) {}
void GfxOpenGL2::SysReset() {}
Li::Texture GfxOpenGL2::LoadTexture(const std::vector<PD::u8>& pixels, int w,
int h, TextureFormat type,
TextureFilter filter) {
return Li::Texture();
}
void GfxOpenGL2::DeleteTexture(const Li::Texture& tex) {}
void GfxOpenGL2::pSetupShaderAttribs(u32 shader) {}
} // namespace PD
#endif

View File

@@ -0,0 +1,186 @@
#include <pd/lithium/formatters.hpp>
#include <pd_system/gfx_opengl3.hpp>
#if defined(PD_ENABLE_OPENGL3)
#include <glad/glad.h>
#include <pd/drivers/drivers.hpp>
#include <pd_system/gl-helper.hpp>
namespace PD {
const char* GfxOpenGL3::pVertCode = R"(
#version 330 core
layout(location = 0) in vec2 pos;
layout(location = 1) in vec2 uv;
layout(location = 2) in vec4 color;
out vec2 oUV;
out vec4 oColor;
// Probably forgot about this matrix and
// searched hours for why the rendering isn't working :/
uniform mat4 projection;
void main() {
gl_Position = projection*vec4(pos, 0.0, 1.0);
oUV = uv;
oColor = color;
}
)";
const char* GfxOpenGL3::pFragCode = R"(
#version 330 core
in vec2 oUV;
in vec4 oColor;
uniform sampler2D tex;
uniform bool alfa;
out vec4 FragColor;
void main() {
vec4 tc = texture(tex, oUV);
if (alfa) {
FragColor = vec4(oColor.rgb, tc.a * oColor.a);
} else {
FragColor = tc * oColor;
}
}
)";
void GfxOpenGL3::SysInit() {
pShader = CreateShaderProgram(pVertCode, pFragCode);
glUseProgram(pShader);
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, pos));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, uv));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, color));
glGenBuffers(1, &IBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
pLocTex = glGetUniformLocation(pShader, "tex");
pLocAlfa = glGetUniformLocation(pShader, "alfa");
pLocProjection = glGetUniformLocation(pShader, "projection");
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);
PDLOG(
"GfxOpenGL3::SysInit():\n pShader = {}\n pLocTex = {}\n pLocAlfa = "
"{}\n pLocProjection = {}\n VBO = {}\n IBO = {}, VAO = {}",
pShader, pLocTex, pLocAlfa, pLocProjection, VBO, IBO, VAO);
}
void GfxOpenGL3::SysDeinit() {
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &IBO);
glDeleteVertexArrays(1, &VAO);
PDLOG("GfxOpenGL3::SysDeinit()");
}
void GfxOpenGL3::Submit(size_t count, size_t start) {
BindTexture(CurrentTex);
glUseProgram(pShader);
glUniformMatrix4fv(pLocProjection, 1, GL_FALSE, Projection.m.data());
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
GetVertexBufPtr(0), GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(u16),
GetIndexBufPtr(0), GL_DYNAMIC_DRAW);
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT,
reinterpret_cast<void*>(start * sizeof(u16)));
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);
BindTexture(0);
}
void GfxOpenGL3::BindTexture(TextureID id) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, (GLuint)id);
glUniform1i(pLocTex, 0);
GLint fmt = 0;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
glUniform1i(pLocAlfa, fmt == GL_ALPHA);
}
void GfxOpenGL3::SysReset() {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
Li::Texture GfxOpenGL3::LoadTexture(const std::vector<PD::u8>& pixels, int w,
int h, TextureFormat type,
TextureFilter filter) {
GLuint texID;
glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);
// Set base format (Always using RGBA as base)
GLenum fmt = GL_RGBA;
if (type == TextureFormat::RGB24) {
fmt = GL_RGB;
} else if (type == TextureFormat::A8) {
fmt = GL_ALPHA;
}
glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
pixels.data());
if (filter == TextureFilter::Linear) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else if (filter == TextureFilter::Nearest) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
glBindTexture(GL_TEXTURE_2D, 0);
Li::Texture res;
res.SetID(texID);
res.SetSize(w, h);
res.SetUV(0.f, 0.f, 1.f, 1.f);
RegisterTexture(res);
PDLOG("GfxOpenGL3::LoadTexture -> {{ {} }}, [{}, {}]", res, type, filter);
return res;
}
void GfxOpenGL3::DeleteTexture(const Li::Texture& tex) {
UnregisterTexture(tex);
GLuint tex_ = tex.GetID();
glDeleteTextures(1, &tex_);
}
} // namespace PD
#else
namespace PD {
void GfxOpenGL3::SysInit() {
PDLOG(
"GfxOpenGL3::SysInit: OpenGL3 Driver is not included in "
"palladium-system");
}
void GfxOpenGL3::SysDeinit() {}
void GfxOpenGL3::Submit(size_t count, size_t start) {}
void GfxOpenGL3::BindTexture(TextureID id) {}
void GfxOpenGL3::SysReset() {}
Li::Texture GfxOpenGL3::LoadTexture(const std::vector<PD::u8>& pixels, int w,
int h, TextureFormat type,
TextureFilter filter) {
return Li::Texture();
}
void GfxOpenGL3::DeleteTexture(const Li::Texture& tex) {}
} // namespace PD
#endif

View File

@@ -0,0 +1,48 @@
#if defined(PD_ENABLE_OPENGL2) || defined(PD_ENABLE_OPENGL3)
#include <glad/glad.h>
#include <iostream>
#include <pd_system/gl-helper.hpp>
namespace PD {
GLuint compileShader(const char* src, GLenum type) {
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &src, nullptr);
glCompileShader(shader);
GLint success;
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
if (!success) {
char infoLog[512];
glGetShaderInfoLog(shader, 512, nullptr, infoLog);
std::cerr << "Shader Compilation Error: " << infoLog << std::endl;
}
return shader;
}
u32 CreateShaderProgram(const char* vert, const char* frag) {
GLuint vertexShader = compileShader(vert, GL_VERTEX_SHADER);
GLuint fragmentShader = compileShader(frag, GL_FRAGMENT_SHADER);
GLuint shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
GLint success;
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if (!success) {
char infoLog[512];
glGetProgramInfoLog(shaderProgram, 512, nullptr, infoLog);
std::cerr << "Shader Program Linking Error: " << infoLog << std::endl;
}
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
if (success) PDLOG("Shader [{}] compiled sucessfully", shaderProgram);
return shaderProgram;
}
} // namespace PD
#endif

View File

@@ -1,65 +0,0 @@
import os
import glob
import shutil
from pathlib import Path
# Simple Script to generate/update Shaders
# WHY? Cause having this stupid .v.pica files in
# sourcecode is pain with some buildsystems
def file2array(path, custom_incluse_path):
print(path)
cip = len(custom_incluse_path)
sip = ''
if cip > 0:
sip = custom_incluse_path
name = Path(path).stem
filei = open(path, 'rb')
buf = filei.read()
filei.close()
fs = open(name + '.cpp', 'w')
fs.write("// THIS FILE WAS GENERATED BY build_shaders.py!!!\n\n")
fs.write('#include <'+ sip + name + '.hpp>\n\n')
fs.write('// clang-format off\n')
fs.write('unsigned char ' + name + '[] = {\n')
for byte in buf:
fs.write(hex(byte) + ', ')
fs.write('\n};\n')
fs.write('// clang-format on\n')
fs.write('size_t ' + name + '_size = ' + hex(len(buf)) + ';')
fs.close()
fh = open(name + '.hpp', 'w')
fh.write("// THIS FILE WAS GENERATED BY build_shaders.py!!!\n\n")
fh.write('#pragma once\n\n')
fh.write('#include <cstddef>\n\n')
fh.write('extern unsigned char ' + name + '[];\n')
fh.write('extern size_t ' + name + '_size;')
fh.close()
def build_shader(path):
p = os.path.dirname(path)
n = Path(Path(path).stem).stem
os.system('picasso -o ' + p + '/' + n + '.shbin ' + path)
def cleanup():
t3x = glob.glob('shaders/*.shbin')
for f in t3x:
os.remove(f)
def install_code(what, where):
if Path(what).is_dir:
os.error('Must be a file!!!')
shutil.move(what, where + Path(what).name)
print("Generating...")
shaders = glob.glob('shaders/*v.pica')
for object in shaders:
name = Path(Path(object).stem).stem
bp = os.path.dirname(object)
build_shader(object)
file2array(bp + '/' + name + '.shbin', 'pd/')
install_code(name + '.cpp', 'source/')
install_code(name + '.hpp', 'include/pd/')
cleanup()
print("Done")

View File

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

34
cmake/palladium.cmake Executable file
View File

@@ -0,0 +1,34 @@
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)
### GIT HELPER ###
function(pd_git_get_hash ret)
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE _ret
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(${ret} "${_ret}" PARENT_SCOPE)
endfunction()
function(pd_git_get_branch ret)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE _ret
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(${ret} "${_ret}" PARENT_SCOPE)
endfunction()

View File

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

View File

@@ -1,18 +0,0 @@
<div class="md-copyright">
{% if config.copyright %}
<div class="md-copyright__highlight">
{{ config.copyright }}
</div>
{% endif %}
{% if not config.extra.generator == false %}
Made with
<a href="https://doxide.org" target="_blank" rel="noopener">
Doxide
</a>
and
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
{% endif %}
</div>

View File

@@ -1,18 +0,0 @@
<div class="md-copyright">
{% if config.copyright %}
<div class="md-copyright__highlight">
{{ config.copyright }}
</div>
{% endif %}
{% if not config.extra.generator == false %}
Made with
<a href="https://doxide.org" target="_blank" rel="noopener">
Doxide
</a>
and
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
{% endif %}
</div>

View File

@@ -1,49 +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--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.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 .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 .concept > .admonition-title::before,
.md-typeset .concept > summary::before {
background-color: var(--md-default-fg-color--light);
-webkit-mask-image: var(--md-admonition-icon--concept);
mask-image: var(--md-admonition-icon--concept);
}
.md-typeset .macro > .admonition-title::before,
.md-typeset .macro > summary::before {
background-color: var(--md-default-fg-color--light);
-webkit-mask-image: var(--md-admonition-icon--macro);
mask-image: var(--md-admonition-icon--macro);
}

View File

@@ -1,9 +0,0 @@
title: Palladium
description:
files:
- "include/*.hpp"
- "include/pd/*.hpp"
- "include/pd/base/*.hpp"
- "include/*.h"
- "include/pd/*.h"
- "include/pd/base/*.h"

28
include/palladium Executable file
View File

@@ -0,0 +1,28 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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/drivers/drivers.hpp>
#include <pd/lithium/lithium.hpp>

View File

@@ -1,27 +0,0 @@
#pragma once
#include <pd/Error.hpp>
#include <pd/Hid.hpp>
#include <pd/Image.hpp>
#include <pd/Installer.hpp>
#include <pd/Lithium.hpp>
#include <pd/Message.hpp>
#include <pd/Net.hpp>
#include <pd/Overlays.hpp>
#include <pd/Rubidium.hpp>
#include <pd/Sheet.hpp>
#include <pd/Sound.hpp>
#include <pd/Texture.hpp>
#include <pd/Timer.hpp>
#include <pd/UI7.hpp>
#include <pd/base/Allocator.hpp>
#include <pd/base/FileSystem.hpp>
#include <pd/global_db.hpp>
#include <pd/palladium.hpp>
namespace Palladium {
using Lithium = LI;
using RB = Rubidium;
} // namespace Palladium
namespace PD = Palladium;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,42 +0,0 @@
#pragma once
#include <pd/external/json.hpp>
#include <string>
namespace Palladium {
namespace Net {
// Define List of Errors
enum Error_ {
Error_None, // Function Executed Successfully
Error_Memory, // Memory Allocation Error
Error_Write, // Unable to Write File
Error_StatusCode, // Error with Status Code
Error_Git, // Git Error
Error_CtrStatus, // 3ds Result Code
Error_Curl, // Curl Error
Error_Busy, // Another Download Taskl is already running
Error_Invalid, // Invalid Json struct
Error_NoWifi, // Console not connected to wifi
};
// Set an typedefine for Error code
using Error = unsigned long long;
// Extract Error_ from Error code
inline Error_ ErrorCode(Error err) {
return static_cast<Error_>(static_cast<unsigned int>(err & 0xffffffff));
}
// Extract Http Status code, Curl Error Code or Ctr Result Code
inline int StatusCode(Error err) {
Error_ c = ErrorCode(err);
if (c != Error_StatusCode && c != Error_CtrStatus && c != Error_Curl)
return 0;
return static_cast<unsigned int>(err >> 32);
}
Error Download(const std::string& url, std::string& data);
Error Download2File(const std::string& url, const std::string& path);
Error GitDownloadRelease(const std::string& url, const std::string& asset_name,
const std::string& path, bool prerelease = false);
Error JsonApiRequest(const std::string& api_url, nlohmann::json& res);
unsigned long long GetProgressCurrent();
unsigned long long GetProgressTotal();
} // namespace Net
} // namespace Palladium

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

@@ -0,0 +1,63 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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 <array>
#include <chrono>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <exception>
#include <format>
#include <fstream>
#include <numbers>
#include <pd/pd_p_api.hpp>
#include <string>
#include <unordered_map>
#include <vector>
namespace PD {
[[noreturn]] inline void Throw(const std::string& msg) {
throw std::runtime_error(msg);
}
using u8 = unsigned char;
using u16 = unsigned short;
using u32 = unsigned int;
using u64 = unsigned long long;
using ptr = uintptr_t;
PD_API void Log(const std::string& txt);
template <typename... Args>
void Log(std::format_string<Args...> fmt, Args&&... args) {
std::string msg = std::format(fmt, std::forward<Args>(args)...);
Log(msg);
}
} // namespace PD
#ifdef PD_DEBUG
#define PDLOG(fmt, ...) \
PD::Log("[{}:{}]: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define PDLOG(fmt, ...)
#endif

43
include/pd/core/bits.hpp Normal file
View File

@@ -0,0 +1,43 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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/common.hpp>
namespace PD {
namespace Bits {
/**
* Check if a 32 Bit number only set a sigle bit to 1
* @param v 32 bit unsigned int
* @return true if its a single bit number
*/
PD_API bool IsSingleBit(u32 v);
/**
* Get the Next Power of two Number
* @param v Current Number
* @return Next Number thats a Pow of 2
*/
PD_API u32 GetPow2(u32 v);
} // namespace Bits
} // namespace PD

154
include/pd/core/color.hpp Executable file
View File

@@ -0,0 +1,154 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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/common.hpp>
#include <pd/core/strings.hpp>
namespace PD {
class PD_API Color {
public:
/**
* Default Constructor (all variables are set to 0)
*/
constexpr Color() : r(0), g(0), b(0), a(0) {}
constexpr ~Color() {}
/**
* Constructor for 32Bit Color Input
* @param color 32Bit Color value
*/
constexpr Color(u32 clr) {
a = (clr >> 24) & 0xff;
b = (clr >> 16) & 0xff;
g = (clr >> 8) & 0xff;
r = clr & 0xff;
}
/**
* Constructor for 8Bit Input
* @param r Red Value
* @param g Green Value
* @param b Blue Value
* @param a Optional Alpha Value (Defaults to 255)
*/
constexpr Color(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {}
/**
* Constructor for float Input
* @param r Red Value
* @param g Green Value
* @param b Blue Value
* @param a Optional Alpha Value (Defaults to 1.0f)
* @note There is no Check if the number is between 0.0 and 1.0
*/
constexpr Color(float r, float g, float b, float a = 1.f)
: r(static_cast<u8>(255.f * r)),
g(static_cast<u8>(255.f * g)),
b(static_cast<u8>(255.f * b)),
a(static_cast<u8>(255.f * a)) {}
/**
* Constructor for Hex Input (is abel to run at compile time xD)
* @param hex Hex String in `#ffffff` or `#ffffffff` format
*/
constexpr Color(const std::string_view& hex) { Hex(hex); }
/**
* Create Color Object by Hex String (at compile time btw)
* @param hex Hex String in `#ffffff` or `#ffffffff` format
* @return Color class itself
*/
constexpr Color& Hex(const std::string_view& hex) {
if (!(hex.length() == 7 || hex.length() == 9)) {
PD::Throw("[PD] Color: hex string is not rgb or rgba!");
}
r = PD::Strings::HexChar2Int(hex[1]) * 16 +
PD::Strings::HexChar2Int(hex[2]);
g = PD::Strings::HexChar2Int(hex[3]) * 16 +
PD::Strings::HexChar2Int(hex[4]);
b = PD::Strings::HexChar2Int(hex[5]) * 16 +
PD::Strings::HexChar2Int(hex[6]);
if (hex.length() == 9) {
a = PD::Strings::HexChar2Int(hex[7]) * 16 +
PD::Strings::HexChar2Int(hex[8]);
} else {
a = 255;
}
return *this;
}
/**
* Convert this Color Object to Hex string
* @param rgba [default false] sets if 8 or 6 digit color should be returned
* @return Color Hex String
*/
std::string Hex(bool rgba = false) const;
/**
* 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
*/
constexpr Color& Fade(const Color& color, float p) {
a = static_cast<u8>((color.a - a) * ((p + 1.f) / 2));
b = static_cast<u8>((color.b - b) * ((p + 1.f) / 2));
g = static_cast<u8>((color.g - g) * ((p + 1.f) / 2));
r = static_cast<u8>((color.r - r) * ((p + 1.f) / 2));
return *this;
}
/**
* Get 32Bit Color Value
* @return 32Bit Color Value (ABGR iirc)
*/
constexpr u32 Get() const { return (a << 24) | (b << 16) | (g << 8) | r; }
/**
* Get The Luminance of the Color
* @return luminance (from 0.0 to 1.0)
*/
constexpr float Luminance() const {
// For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
return (0.3 * (r / 255.f) + 0.59 * (g / 255.f) + 0.11 * (b / 255.f));
}
/**
* Check if the Color is Light or Dark
* @return true if light
*/
constexpr bool IsLight() const { return (Luminance() >= 0.5); }
/**
* Operator to cast Color to 32Bit Value
* @return 32Bit Color Value
*/
constexpr operator u32() const { return Get(); }
const float rf() const { return static_cast<float>(r) / 255.f; }
const float gf() const { return static_cast<float>(g) / 255.f; }
const float bf() const { return static_cast<float>(b) / 255.f; }
const float af() const { return static_cast<float>(a) / 255.f; }
/** Public Access Data section */
u8 r;
u8 g;
u8 b;
u8 a;
};
} // namespace PD

40
include/pd/core/core.hpp Executable file
View File

@@ -0,0 +1,40 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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/bits.hpp>
#include <pd/core/color.hpp>
#include <pd/core/fnv.hpp>
#include <pd/core/formatters.hpp>
#include <pd/core/fquat.hpp>
#include <pd/core/hashid.hpp>
#include <pd/core/io.hpp>
#include <pd/core/mat.hpp>
#include <pd/core/pool.hpp>
#include <pd/core/strings.hpp>
#include <pd/core/timer.hpp>
#include <pd/core/timetrace.hpp>
#include <pd/core/tween.hpp>
#include <pd/core/u128.hpp>
#include <pd/core/vec.hpp>

70
include/pd/core/fnv.hpp Normal file
View File

@@ -0,0 +1,70 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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/common.hpp>
namespace PD {
/**
* FNV-1a 32Bit hasing function
* https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
*/
constexpr u32 FNV1A32(std::string_view str) {
u32 ret = 0x811c9dc5; // Offset basis
for (auto& it : str) {
ret ^= it;
ret *= 0x01000193; // Prime
}
return ret;
}
/**
* FNV-1a 64Bit hasing function
* https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
*/
constexpr u64 FNV1A64(std::string_view str) {
u64 ret = 0xcbf29ce484222325; // Offset basis
for (auto& it : str) {
ret ^= it;
ret *= 0x00000100000001b3; // Prime
}
return ret;
}
namespace Detail {
template <typename T>
struct FNV1A {};
template <>
struct FNV1A<u32> {
static constexpr u32 Hash(std::string_view str) { return FNV1A32(str); }
static constexpr u32 Hash(const std::string& str) { return FNV1A32(str); }
};
template <>
struct FNV1A<u64> {
static constexpr u64 Hash(std::string_view str) { return FNV1A64(str); }
static constexpr u64 Hash(const std::string& str) { return FNV1A64(str); }
};
} // namespace Detail
} // namespace PD

View File

@@ -0,0 +1,98 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/color.hpp>
template <>
struct std::formatter<PD::Color> : std::formatter<std::string> {
enum class ColorFmt {
Hex,
Rgbf,
Rgb,
Rgba,
Rgbaf,
};
ColorFmt mode = ColorFmt::Hex;
constexpr auto parse(std::format_parse_context& ctx) {
auto it = ctx.begin();
auto end = ctx.end();
if (it == end || *it == '}') return it;
if (check(it, end, 5, "rgbaf")) {
mode = ColorFmt::Rgbaf;
it += 5;
} else if (check(it, end, 4, "rgba")) {
mode = ColorFmt::Rgba;
it += 4;
} else if (check(it, end, 4, "rgbf")) {
mode = ColorFmt::Rgbf;
it += 4;
} else if (check(it, end, 3, "rgb")) {
mode = ColorFmt::Rgb;
it += 3;
} else if (check(it, end, 3, "hex")) {
mode = ColorFmt::Hex;
it += 3;
} else {
throw std::format_error("invalid format for PD::Color");
}
if (it == end || *it != '}')
throw std::format_error("invalid format for PD::Color");
return it;
}
template <typename FormatContext>
auto format(const PD::Color& value, FormatContext& ctx) const {
switch (mode) {
case ColorFmt::Hex:
return std::format_to(ctx.out(), "#{:02X}{:02X}{:02X}{:02X}", value.r,
value.g, value.b, value.a);
case ColorFmt::Rgb:
return std::format_to(ctx.out(), "{}, {}, {}", value.r, value.g,
value.b);
case ColorFmt::Rgba:
return std::format_to(ctx.out(), "{}, {}, {}, {}", value.r, value.g,
value.b, value.a);
case ColorFmt::Rgbf:
return std::format_to(ctx.out(), "{}, {}, {}", value.rf(), value.gf(),
value.bf());
case ColorFmt::Rgbaf:
return std::format_to(ctx.out(), "{}, {}, {}, {}", value.rf(),
value.gf(), value.bf(), value.af());
default:
return ctx.out();
}
}
constexpr bool check(std::format_parse_context::const_iterator it,
std::format_parse_context::const_iterator end,
size_t len, const char* what) {
return (end - it >= static_cast<std::ptrdiff_t>(len) &&
std::string_view(&*it, len) == what); // msvc things...
}
};

55
include/pd/core/fquat.hpp Normal file
View File

@@ -0,0 +1,55 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This file is based on fvec4
#include <pd/common.hpp>
#include <pd/core/vec4.hpp>
namespace PD {
class fquat : public fvec4 {
constexpr fquat() : fvec4(0.f, 0.f, 0.f, 1.f) {}
constexpr fquat(float x, float y, float z, float w) : fvec4(x, y, z, w) {}
constexpr fquat(const fvec4& v) : fvec4(v) {}
static fquat Identity() { return fquat(0.f, 0.f, 0.f, 1.f); }
constexpr fquat Conjugate() const { return fquat(-x, -y, -z, w); }
fquat Inverse() const {
float len = SqLen();
if (len == 0.0f) {
return fquat();
}
return Conjugate() / len;
}
fquat operator*(const fquat& v) const {
return fquat(w * v.x + x * v.w + y * v.z - z * v.y,
w * v.y - x * v.z + y * v.w + z * v.x,
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 PD

View File

@@ -0,0 +1,50 @@
#pragma once
#include <pd/core/fnv.hpp>
#include <pd/core/strings.hpp>
namespace PD {
template <typename T>
class HashID {
public:
using __Type = T;
constexpr HashID() {};
constexpr HashID(T id) { pID = id; }
HashID(const std::string& name) {
pID = Detail::FNV1A<T>::Hash(name);
#ifdef PD_HASHID_KEEP_STR
pName = name;
#endif
}
constexpr HashID(const char* name) {
pID = Detail::FNV1A<T>::Hash(std::string_view(name));
#ifdef PD_HASHID_KEEP_STR
pName = name;
#endif
}
~HashID() {}
constexpr T Get() { return pID; }
std::string GetName() const {
#ifdef PD_HASHID_KEEP_STR
return pName;
#else
return std::format("hash({:#08x})", pID);
#endif
}
operator T() const { return pID; }
// operator std::string() const { return GetName(); }
private:
T pID;
#ifdef PD_HASHID_KEEP_STR
str pName;
#endif
};
using HashID32 = HashID<u32>;
using HashID64 = HashID<u64>;
} // namespace PD

62
include/pd/core/io.hpp Executable file
View File

@@ -0,0 +1,62 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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/common.hpp>
namespace PD {
/**
* Set of File Functions
*/
namespace IO {
/**
* Load a File into an 8Bit Memory Buffer
* @param path Path to the File
* @return 8Bit FileBuffer
*/
PD_API std::vector<u8> LoadFile2Mem(const std::string& path);
/**
* Load a File into a std::string
* @param path Path to the File
* @return std::string file content
*/
PD_API std::string LoadFile2Str(const std::string& path);
/**
* Hash a 8Bit Memory Buffer
* @param data 8Bit input Buffer
* @return 32Bit Hash
*/
PD_API u32 HashMemory(const std::vector<u8>& data);
/**
* Function to decrompress RLE buffer
* @param data Data buffer to decompress
*/
PD_API void DecompressRLE(std::vector<u8>& data);
/**
* Function to compress data with RLE Algorithm
* @param data Data buf
*/
PD_API void CompressRLE(std::vector<u8>& data);
} // namespace IO
} // namespace PD

141
include/pd/core/mat.hpp Executable file
View File

@@ -0,0 +1,141 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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/common.hpp>
#include <pd/core/vec3.hpp>
namespace PD {
namespace Numbers {
constexpr float Tau = std::numbers::pi * 2.f;
}
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
*/
struct PD_API Mat4 {
std::array<float, 16> m;
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); }
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

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

@@ -0,0 +1,81 @@
#pragma once
#include <memory>
#include <pd/common.hpp>
namespace PD {
template <typename T, typename Alloc = std::allocator<T>>
class Pool {
public:
using value_type = T;
using iterator = T*;
using const_iterator = const iterator*;
Pool() = default;
~Pool() {
if (pData) {
pAlloc.deallocate(pData, pCap);
pData = nullptr;
}
}
static Pool* Create(size_t size) { return new Pool(size); }
void Init(size_t size) {
pPos = 0;
pCap = size;
pData = pAlloc.allocate(size);
for (size_t i = 0; i < pCap; i++) {
std::allocator_traits<Alloc>::construct(pAlloc, &pData[i]);
}
PDLOG("Pool::Init({})", size);
}
Pool(const Pool&) = delete;
Pool(Pool&&) = delete;
Pool& operator=(const Pool&) = delete;
Pool& operator=(Pool&&) = delete;
T* Allocate(size_t num = 1) {
if (CheckLimits(num)) return nullptr;
T* ret = &pData[pPos];
pPos += num;
return ret;
}
bool CheckLimits(size_t num) {
if ((pPos + num) >= pCap) {
throw std::runtime_error(
std::format("[PD::Pool]: Trying to allocate {} elements but this is "
"going out of range ({}/{})",
num, pPos + num, pCap));
return true;
}
return false;
}
void Reset() {
for (size_t i = 0; i < pCap; i++) {
std::allocator_traits<Alloc>::destroy(pAlloc, &pData[i]);
}
pPos = 0;
for (size_t i = 0; i < pCap; i++) {
std::allocator_traits<Alloc>::construct(pAlloc, &pData[i]);
}
}
size_t size() const { return pPos; }
size_t capacity() const { return pCap; }
T& at(size_t idx) { return pData[idx]; }
const T& at(size_t idx) const { return pData[idx]; }
T& operator[](size_t idx) { return at(idx); }
const T& operator[](size_t idx) const { return at(idx); }
private:
Pool(size_t size) : pCap(size), pPos(0) { pData = pAlloc.allocate(size); }
size_t pCap = 0;
size_t pPos = 0;
Alloc pAlloc;
T* pData = nullptr;
};
} // namespace PD

170
include/pd/core/strings.hpp Normal file
View File

@@ -0,0 +1,170 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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/common.hpp>
namespace PD {
/**
* Set of String Utillity Functions
*/
namespace Strings {
constexpr int HexChar2Int(char c) {
/** Imagine man hat ne lookup table dafür verwendet :/ */
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return 10 + (c - 'a');
if (c >= 'A' && c <= 'F') return 10 + (c - 'A');
return -1; // Error
}
/**
* Check if a String ends with a specific extension
* @param str Input string
* @param exts List of Extensions to check for
* @return true if one of the extensions is found in the String
*/
PD_API bool StringEndsWith(const std::string& str,
const std::vector<std::string>& exts);
/**
* Function to Create a wstring of a string
* @param s Input String to Convert
* @return Result wstring
* @note Returns Empty if it has an error
*/
PD_API std::wstring MakeWstring(const std::string& s);
/**
* Generate a Formatted String by an Nanoseconds Input
* @param nanos Nanoseconds Input
* @return Result String
*/
PD_API const std::string FormatNanos(unsigned long long nanos);
/**
* Generate a Formatted String by an Milliseconds Input
* @param millis Milliseconds Input
* @return Result String
*/
PD_API const std::string FormatMillis(unsigned long long millis);
/**
* Create a formatted String by an input bytes value
* @param bytes value in bytes
* @result Formatted String for example `2.5MB`
*/
PD_API const std::string FormatBytes(unsigned long long bytes);
/**
* Extract the Filename out of a Path
* @param path Path to extract from
* @param saperators Path Split Chars
* @return extracted filename
*/
PD_API const std::string GetFileName(const std::string& path,
const std::string& saperators = "/\\");
/**
* Remove Extension from a Path / Filename
* @param path Input Path
* @return Path without Extension
*/
PD_API const std::string PathRemoveExtension(const std::string& path);
/**
* Function to Convert a Type to a hex value
* @tparam T Type
* @param v value
* @return hex string beginning with 0x
*/
template <typename T>
inline const std::string ToHex(const T& v) {
return std::format("{0:0{1}X}", v, sizeof(v) * 2);
}
/**
* Generate a Hash out of a string
* @param s String to hash
* @return 32Bit Hash
*/
PD_API u32 FastHash(const std::string& s);
/**
* Function to Generate a Compiler Name and Version String
* Based on their Macros
* @return CompilerName: Version
*/
inline const char* GetCompilerVersion() {
/// As the function looks like this Project is meant to
/// Be ported to other systems as well
#define __mks(x) #x
#define mkstring(x) __mks(x)
#ifdef __clang__ // Check clang first
return "Clang: " mkstring(__clang_major__) "." mkstring(
__clang_minor__) "." mkstring(__clang_patchlevel__);
#elif __GNUC__
return "GCC: " mkstring(__GNUC__) "." mkstring(__GNUC_MINOR__) "." mkstring(
__GNUC_PATCHLEVEL__);
#elif _MSC_VER
return "MSVC; " mkstring(_MSC_VER);
#else
return "Unknown Compiler";
#endif
}
} // namespace Strings
class U8Iterator {
public:
explicit U8Iterator(const char* s) : ptr(reinterpret_cast<const u8*>(s)) {}
~U8Iterator() = default;
bool Decode32(u32& ret) {
if (ptr == nullptr || *ptr == 0) return false;
u8 c = *ptr;
if (c < 0x80) {
ret = c;
ptr += 1;
} else if ((c >> 5) == 0x6) {
ret = ((c & 0x1F) << 6) | (ptr[1] & 0x3F);
ptr += 2;
} else if ((c >> 4) == 0xE) {
ret = ((c & 0x0F) << 12) | ((ptr[1] & 0x3F) << 6) | (ptr[2] & 0x3F);
ptr += 3;
} else {
ret = ((c & 0x07) << 18) | ((ptr[1] & 0x3F) << 12) |
((ptr[2] & 0x3F) << 6) | (ptr[3] & 0x3F);
ptr += 4;
}
return true;
}
bool PeekNext32(u32& ret) {
// if ((ptr + 1) == 0 || *(ptr + 1) == 0) return false;
u8 c = *ptr;
if (c < 0x80) {
ret = c;
} else if ((c >> 5) == 0x6) {
ret = ((c & 0x1F) << 6) | (ptr[1] & 0x3F);
} else if ((c >> 4) == 0xE) {
ret = ((c & 0x0F) << 12) | ((ptr[1] & 0x3F) << 6) | (ptr[2] & 0x3F);
} else {
ret = ((c & 0x07) << 18) | ((ptr[1] & 0x3F) << 12) |
((ptr[2] & 0x3F) << 6) | (ptr[3] & 0x3F);
}
return true;
}
private:
const u8* ptr = nullptr;
};
} // namespace PD

83
include/pd/core/timer.hpp Executable file
View File

@@ -0,0 +1,83 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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/common.hpp>
namespace PD {
/**
* Timer class
*/
class PD_API Timer {
public:
/**
* Constructor
* @param auto_start [default true] sets if timer should start after creation
*/
Timer(bool auto_start = true);
/**
* Unused Deconstructor
*/
~Timer() {}
/**
* Resume Timer if Paused
*/
void Rseume();
/**
* Pause Timer if not Paused
*/
void Pause();
/**
* Update Timer
*/
void Update();
/**
* Reset Timer
*/
void Reset();
/**
* Check if the Timer is Running
* @return true if its running
*/
bool IsRunning() const;
/**
* Get 64 Bit milliseconds value
* @return 64Bit millis
*/
u64 Get();
/**
* Get as Seconds
* @return seconds as floating number
*/
double GetSeconds();
/** Start of the Timer */
u64 pStart;
/** Current Time */
u64 pNow;
/** Is Running */
bool pIsRunning = false;
};
} // namespace PD

View File

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

228
include/pd/core/tween.hpp Executable file
View File

@@ -0,0 +1,228 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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/common.hpp>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
namespace PD {
/**
* D7 Tween Engine (or something like that)
* @tparam T Any Numeric value
*/
template <typename T>
class Tween {
public:
/**
* Effects Table
*/
enum Effect {
Linear, ///< Linear Movement [works]
EaseInQuad, ///< EaseInQuad Movement [works]
EaseOutQuad, ///< EaseOutQuad Movement [works]
EaseInOutQuad, ///< EaseInOutQuad Movement [works]
EaseInCubic, ///< EaseInCubic Movement [not tested]
EaseOutCubic, ///< EaseOutCubic Movement [not tested]
EaseInOutCubic, ///< EaseInOutCubic Movement [disabled]
EaseInSine, ///< EaseInSine Movement [works]
EaseOutSine, ///< EaseOutSine Movement [works]
EaseInOutSine, ///< EaseInOutSine Movement [not tested]
};
Tween() = default;
~Tween() = default;
/**
* Update Tween
* @param delta deltatime
*/
void Update(float delta) {
time += delta * 0.001f;
if (time > tend) {
finished = true;
time = tend;
}
}
/**
* Check if Tween is finished
* @return true if finished
*/
bool IsFinished() const { return finished; }
/**
* Force finish the animation
* @return Class reference
*/
Tween& Finish() {
time = tend;
finished = true;
return *this;
}
/**
* Set Start Value
* @tparam T datatype of the Tween
* @param start Start Value
* @return class Reference
*/
Tween& From(const T& start) {
Reset();
this->start = start;
return *this;
}
/**
* Set End Value
* @tparam T datatype of the Tween
* @param end End Value
* @return class Reference
*/
Tween& To(const T& end) {
Reset();
this->end = end;
return *this;
}
/**
* Set the Duration (in seconds)
* @param seconds Duration
* @return class Reference
*/
Tween& In(float seconds) {
Reset();
tend = seconds;
return *this;
}
/**
* Set Effect of the Tween
* @param e Effect
* @return class Reference
*/
Tween& As(const Effect& e) {
effect = e;
return *this;
}
/**
* Reset to time 0
* @return class Reference
*/
Tween& Reset() {
finished = false;
time = 0.f;
return *this;
}
/**
* Get the Prograss in percent (0.0 to 1.0) of the tween
* @return progress value
*/
float Progress() const { return time / tend; }
/**
* Swap Start and end Position of the Tween
* @return class reference
*/
Tween& Swap() {
T temp = start;
start = end;
end = temp;
return *this;
}
T Get() const {
float t = 0.f;
switch (effect) {
case EaseInQuad:
t = time / tend;
return (end - start) * t * t + start;
break;
case EaseOutQuad:
t = time / tend;
return -(end - start) * t * (t - 2) + start;
break;
case EaseInOutQuad:
t = time / (tend * 0.5f);
if (t < 1) return (end - start) * 0.5f * t * t + start;
t--;
return -(end - start) * 0.5f * (t * (t - 2) - 1) + start;
break;
case EaseInCubic:
t = time / tend;
return (end - start) * t * t * t + start;
break;
case EaseOutCubic:
t = time / tend;
t--;
return (end - start) * (t * t * t + 1) + start;
break;
// case EaseInOutCubic:
// t = time / (tend *0.5f);
// if (t < 1) return (end - start) *0.5f * t * t * t + start;
// t--;
// return (end - start) *0.5f * (t * t * t * 2) + start;
// break;
case EaseInSine:
return -(end - start) * cos(time / tend * (M_PI * 0.5f)) +
(end - start) + start;
break;
case EaseOutSine:
return (end - start) * sin(time / tend * (M_PI * 0.5f)) + start;
break;
case EaseInOutSine:
return -(end - start) * 0.5f * (cos(M_PI * time / tend) - 1) + start;
break;
default: // Linear
return (end - start) * (time / tend) + start;
break;
}
}
/**
* Operator that returns the current value calculated
* by time and effect
*/
operator T() const { return Get(); }
private:
/** Animation Effect */
Effect effect;
/** Time */
float time = 0.f;
/**
* End time
* Defaulting to one to prevent div zero
* without a safetey check
* not implementing one cause if the user is
* Writing a In(0.f) its their fault
*/
float tend = 1.f;
/** Start value */
T start;
/** end value */
T end;
/** is finished value */
bool finished = false;
};
} // namespace PD

127
include/pd/core/u128.hpp Normal file
View File

@@ -0,0 +1,127 @@
#pragma once
#include <pd/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();
}
constexpr u128 operator+(const u128& v) const {
u128 ret;
ret.pLow = pLow + v.pLow;
ret.pHigh = pHigh + v.pHigh + (ret.pLow < pLow);
return ret;
}
constexpr u128 operator&(const u128& v) const {
return u128(pLow & v.pLow, pHigh & v.pHigh);
}
constexpr 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)));
}
constexpr 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);
}
constexpr u128& operator|=(const u128& v) {
pLow |= v.pLow;
pHigh |= v.pHigh;
return *this;
}
constexpr u128 operator|(const u128& v) const {
return u128(pLow | v.pLow, pHigh | v.pHigh);
}
constexpr u128& operator&=(const u128& v) {
pLow &= v.pLow;
pHigh &= v.pHigh;
return *this;
}
constexpr 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;
// }
constexpr 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...
*/
constexpr explicit operator bool() const { return pLow != 0 || pHigh != 0; }
/** Deprecated way to handle `flag & SomeFlag` */
constexpr bool Has(const u128& v) const {
return pLow & v.pLow || pHigh & v.pHigh;
}
constexpr 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

59
include/pd/core/vec.hpp Executable file
View File

@@ -0,0 +1,59 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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/common.hpp>
#include <pd/core/vec2.hpp>
#include <pd/core/vec3.hpp>
#include <pd/core/vec4.hpp>
/** Define Formatters for C++ 20 */
/**
* WHY DOES MSVC ALWAYS NEED THESE EXTRA THINGS
*/
template <typename T, typename CharT>
struct std::formatter<PD::vec2<T>, CharT> : std::formatter<T, CharT> {
template <typename FormatContext>
auto format(const PD::vec2<T>& v, FormatContext& ctx) const {
return std::format_to(ctx.out(), "{}, {}", v.x, v.y);
}
};
template <typename T, typename CharT>
struct std::formatter<PD::vec3<T>, CharT> : std::formatter<T, CharT> {
template <typename FormatContext>
auto format(const PD::vec3<T>& v, FormatContext& ctx) const {
return std::format_to(ctx.out(), "{}, {}, {}", v.x, v.y, v.z);
}
};
template <typename T, typename CharT>
struct std::formatter<PD::vec4<T>, CharT> : std::formatter<T, CharT> {
template <typename FormatContext>
auto format(const PD::vec4<T>& v, FormatContext& ctx) const {
return std::format_to(ctx.out(), "{}, {}, {}, {}", v.x, v.y, v.z, v.w);
}
};

197
include/pd/core/vec2.hpp Executable file
View File

@@ -0,0 +1,197 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This file is generated by lazyvec 2.0.0
#include <pd/common.hpp>
namespace PD {
template <typename T>
class vec2 {
public:
T x;
T y;
// Constructors
constexpr vec2() : x(0), y(0) {}
template <typename T1>
constexpr vec2(T1 v) {
x = (T)v;
y = (T)v;
}
template <typename T1>
constexpr vec2(const vec2<T1>& v) {
x = (T)v.x;
y = (T)v.y;
}
constexpr explicit vec2(T x, T y) : x(x), y(y) {}
// Operations
template <typename T1>
vec2<T>& operator+=(T1 v) {
x += (T)v;
y += (T)v;
return *this;
}
template <typename T1>
vec2<T>& operator+=(const vec2<T1>& v) {
x += (T)v.x;
y += (T)v.y;
return *this;
}
template <typename T1>
vec2<T> operator+(T1 v) const {
return vec2<T>(x + (T)v, y + (T)v);
}
template <typename T1>
vec2<T> operator+(const vec2<T1>& v) const {
return vec2<T>(x + (T)v.x, y + (T)v.y);
}
template <typename T1>
vec2<T>& operator-=(T1 v) {
x -= (T)v;
y -= (T)v;
return *this;
}
template <typename T1>
vec2<T>& operator-=(const vec2<T1>& v) {
x -= (T)v.x;
y -= (T)v.y;
return *this;
}
template <typename T1>
vec2<T> operator-(T1 v) const {
return vec2<T>(x - (T)v, y - (T)v);
}
template <typename T1>
vec2<T> operator-(const vec2<T1>& v) const {
return vec2<T>(x - (T)v.x, y - (T)v.y);
}
template <typename T1>
vec2<T>& operator*=(T1 v) {
x *= (T)v;
y *= (T)v;
return *this;
}
template <typename T1>
vec2<T>& operator*=(const vec2<T1>& v) {
x *= (T)v.x;
y *= (T)v.y;
return *this;
}
template <typename T1>
vec2<T> operator*(T1 v) const {
return vec2<T>(x * (T)v, y * (T)v);
}
template <typename T1>
vec2<T> operator*(const vec2<T1>& v) const {
return vec2<T>(x * (T)v.x, y * (T)v.y);
}
template <typename T1>
vec2<T>& operator/=(T1 v) {
x /= (T)v;
y /= (T)v;
return *this;
}
template <typename T1>
vec2<T>& operator/=(const vec2<T1>& v) {
x /= (T)v.x;
y /= (T)v.y;
return *this;
}
template <typename T1>
vec2<T> operator/(T1 v) const {
return vec2<T>(x / (T)v, y / (T)v);
}
template <typename T1>
vec2<T> operator/(const vec2<T1>& v) const {
return vec2<T>(x / (T)v.x, y / (T)v.y);
}
// 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

235
include/pd/core/vec3.hpp Executable file
View File

@@ -0,0 +1,235 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This file is generated by lazyvec 2.0.0
#include <pd/common.hpp>
// Extended includes (rename if you use other filenames/paths)
#include <pd/core/vec2.hpp>
namespace PD {
template <typename T>
class vec3 {
public:
T x;
T y;
T z;
// Constructors
constexpr vec3() : x(0), y(0), z(0) {}
template <typename T1>
constexpr vec3(T1 v) {
x = (T)v;
y = (T)v;
z = (T)v;
}
template <typename T1>
constexpr vec3(const vec3<T1>& v) {
x = (T)v.x;
y = (T)v.y;
z = (T)v.z;
}
constexpr explicit vec3(T x, T y, T z) : x(x), y(y), z(z) {}
// Extended Constructors
template <typename T1>
constexpr explicit vec3(const vec2<T1>& xy, T1 z) {
{
x = (T)xy.x;
y = (T)xy.y;
this->z = (T)z;
}
}
// Operations
template <typename T1>
vec3<T>& operator+=(T1 v) {
x += (T)v;
y += (T)v;
z += (T)v;
return *this;
}
template <typename T1>
vec3<T>& operator+=(const vec3<T1>& v) {
x += (T)v.x;
y += (T)v.y;
z += (T)v.z;
return *this;
}
template <typename T1>
vec3<T> operator+(T1 v) const {
return vec3<T>(x + (T)v, y + (T)v, z + (T)v);
}
template <typename T1>
vec3<T> operator+(const vec3<T1>& v) const {
return vec3<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z);
}
template <typename T1>
vec3<T>& operator-=(T1 v) {
x -= (T)v;
y -= (T)v;
z -= (T)v;
return *this;
}
template <typename T1>
vec3<T>& operator-=(const vec3<T1>& v) {
x -= (T)v.x;
y -= (T)v.y;
z -= (T)v.z;
return *this;
}
template <typename T1>
vec3<T> operator-(T1 v) const {
return vec3<T>(x - (T)v, y - (T)v, z - (T)v);
}
template <typename T1>
vec3<T> operator-(const vec3<T1>& v) const {
return vec3<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z);
}
template <typename T1>
vec3<T>& operator*=(T1 v) {
x *= (T)v;
y *= (T)v;
z *= (T)v;
return *this;
}
template <typename T1>
vec3<T>& operator*=(const vec3<T1>& v) {
x *= (T)v.x;
y *= (T)v.y;
z *= (T)v.z;
return *this;
}
template <typename T1>
vec3<T> operator*(T1 v) const {
return vec3<T>(x * (T)v, y * (T)v, z * (T)v);
}
template <typename T1>
vec3<T> operator*(const vec3<T1>& v) const {
return vec3<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z);
}
template <typename T1>
vec3<T>& operator/=(T1 v) {
x /= (T)v;
y /= (T)v;
z /= (T)v;
return *this;
}
template <typename T1>
vec3<T>& operator/=(const vec3<T1>& v) {
x /= (T)v.x;
y /= (T)v.y;
z /= (T)v.z;
return *this;
}
template <typename T1>
vec3<T> operator/(T1 v) const {
return vec3<T>(x / (T)v, y / (T)v, z / (T)v);
}
template <typename T1>
vec3<T> operator/(const vec3<T1>& v) const {
return vec3<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z);
}
// 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

268
include/pd/core/vec4.hpp Executable file
View File

@@ -0,0 +1,268 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This file is generated by lazyvec 2.0.0
#include <pd/common.hpp>
// Extended includes (rename if you use other filenames/paths)
#include <pd/core/vec2.hpp>
#include <pd/core/vec3.hpp>
namespace PD {
template <typename T>
class vec4 {
public:
T x;
T y;
T z;
T w;
// Constructors
constexpr vec4() : x(0), y(0), z(0), w(0) {}
template <typename T1>
constexpr vec4(T1 v) {
x = (T)v;
y = (T)v;
z = (T)v;
w = (T)v;
}
template <typename T1>
constexpr vec4(const vec4<T1>& v) {
x = (T)v.x;
y = (T)v.y;
z = (T)v.z;
w = (T)v.w;
}
constexpr explicit vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {}
// Extended Constructors
template <typename T1>
constexpr explicit vec4(const vec2<T1>& xy, const vec2<T1>& zw) {
{
x = (T)xy.x;
y = (T)xy.y;
z = (T)zw.x;
w = (T)zw.y;
}
}
template <typename T1>
constexpr explicit vec4(const vec3<T1>& xyz, T1 w) {
{
x = (T)xyz.x;
y = (T)xyz.y;
z = (T)xyz.z;
this->w = (T)w;
}
}
// Operations
template <typename T1>
vec4<T>& operator+=(T1 v) {
x += (T)v;
y += (T)v;
z += (T)v;
w += (T)v;
return *this;
}
template <typename T1>
vec4<T>& operator+=(const vec4<T1>& v) {
x += (T)v.x;
y += (T)v.y;
z += (T)v.z;
w += (T)v.w;
return *this;
}
template <typename T1>
vec4<T> operator+(T1 v) const {
return vec4<T>(x + (T)v, y + (T)v, z + (T)v, w + (T)v);
}
template <typename T1>
vec4<T> operator+(const vec4<T1>& v) const {
return vec4<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z, w + (T)v.w);
}
template <typename T1>
vec4<T>& operator-=(T1 v) {
x -= (T)v;
y -= (T)v;
z -= (T)v;
w -= (T)v;
return *this;
}
template <typename T1>
vec4<T>& operator-=(const vec4<T1>& v) {
x -= (T)v.x;
y -= (T)v.y;
z -= (T)v.z;
w -= (T)v.w;
return *this;
}
template <typename T1>
vec4<T> operator-(T1 v) const {
return vec4<T>(x - (T)v, y - (T)v, z - (T)v, w - (T)v);
}
template <typename T1>
vec4<T> operator-(const vec4<T1>& v) const {
return vec4<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z, w - (T)v.w);
}
template <typename T1>
vec4<T>& operator*=(T1 v) {
x *= (T)v;
y *= (T)v;
z *= (T)v;
w *= (T)v;
return *this;
}
template <typename T1>
vec4<T>& operator*=(const vec4<T1>& v) {
x *= (T)v.x;
y *= (T)v.y;
z *= (T)v.z;
w *= (T)v.w;
return *this;
}
template <typename T1>
vec4<T> operator*(T1 v) const {
return vec4<T>(x * (T)v, y * (T)v, z * (T)v, w * (T)v);
}
template <typename T1>
vec4<T> operator*(const vec4<T1>& v) const {
return vec4<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z, w * (T)v.w);
}
template <typename T1>
vec4<T>& operator/=(T1 v) {
x /= (T)v;
y /= (T)v;
z /= (T)v;
w /= (T)v;
return *this;
}
template <typename T1>
vec4<T>& operator/=(const vec4<T1>& v) {
x /= (T)v.x;
y /= (T)v.y;
z /= (T)v.z;
w /= (T)v.w;
return *this;
}
template <typename T1>
vec4<T> operator/(T1 v) const {
return vec4<T>(x / (T)v, y / (T)v, z / (T)v, w / (T)v);
}
template <typename T1>
vec4<T> operator/(const vec4<T1>& v) const {
return vec4<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z, w / (T)v.w);
}
// 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

4
include/pd/drivers/drivers.hpp Executable file
View File

@@ -0,0 +1,4 @@
#pragma once
#include <pd/drivers/gfx.hpp>
#include <pd/drivers/os.hpp>

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

@@ -0,0 +1,164 @@
#pragma once
#include <pd/core/mat.hpp>
#include <pd/drivers/interface.hpp>
#include <pd/lithium/command.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 {
// Pre interface class
class PD_API GfxDriver : public DriverInterface {
public:
GfxDriver(std::string_view name);
virtual ~GfxDriver();
virtual void Init() {}
virtual void Deinit() { SysDeinit(); }
void SetViewPort(const ivec2& size);
void SetViewPort(int x, int y);
virtual void BindTexture(TextureID id) {}
void Reset();
virtual Li::Texture LoadTexture(
const std::vector<PD::u8>& pixels, int w, int h,
TextureFormat type = TextureFormat::RGBA32,
TextureFilter filter = TextureFilter::Linear) {
return Li::Texture();
}
virtual void DeleteTexture(const Li::Texture& tex) {}
virtual void Draw(const Pool<Li::Command>& commands) {}
protected:
virtual void SysDeinit() {}
virtual void SysInit() {}
virtual void SysReset() {}
virtual void Submit(size_t count, size_t start) {}
virtual void ResetPools() = 0;
void RegisterTexture(const Li::Texture& tex);
void UnregisterTexture(const Li::Texture& tex);
// Counters
size_t CountDrawcalls = 0;
size_t CountCommands = 0;
size_t CountVertices = 0;
size_t CountIndices = 0;
size_t CurrentIndex = 0;
size_t CurrentVertex = 0;
TextureID CurrentTex = 0;
Mat4 Projection;
ivec2 ViewPort;
std::unordered_map<TextureID, Li::Texture> pTextureRegestry;
};
struct DefaultGfxConfig {
// Vertex Allocator
template <typename T>
using VertexAlloc = std::allocator<T>;
// Index Allocator
template <typename T>
using IndexAlloc = std::allocator<T>;
static constexpr size_t NumVertices = 32768; // 8192*4
static constexpr size_t NumIndices = 49152; // 8192*6
};
template <typename Config = DefaultGfxConfig>
class GfxDriverBase : public GfxDriver {
public:
using VtxPool =
Pool<Li::Vertex, typename Config::template VertexAlloc<Li::Vertex>>;
using IdxPool = Pool<u16, typename Config::template VertexAlloc<u16>>;
GfxDriverBase(std::string_view name = "Default") : GfxDriver(name) {}
virtual ~GfxDriverBase() {}
void Init() override {
pVtxPool.Init(Config::NumVertices);
pIdxPool.Init(Config::NumIndices);
SysInit();
}
void Draw(const Pool<Li::Command>& commands) override {
CountCommands += commands.size();
size_t index = 0;
while (index < commands.size()) {
CurrentTex = commands[index].Tex;
if (!CurrentTex) {
index++;
continue;
}
size_t startidx = CurrentIndex;
while (index < commands.size() && CurrentTex == commands[index].Tex) {
const auto& c = commands[index];
CountVertices += c.VertexCount;
CountIndices += c.IndexCount;
auto pIdx = pIdxPool.Allocate(c.IndexCount);
auto pVtx = pVtxPool.Allocate(c.VertexCount);
for (size_t i = 0; i < c.IndexCount; i++) {
pIdx[i] = CurrentVertex + c.FirstIndex[i];
}
CurrentIndex += c.IndexCount;
CurrentVertex += c.VertexCount;
for (size_t i = 0; i < c.VertexCount; i++) {
pVtx[i] = c.FirstVertex[i];
}
index++;
}
Submit(CurrentIndex - startidx, startidx);
}
}
protected:
u16* GetIndexBufPtr(size_t start) { return &pIdxPool[start]; }
Li::Vertex* GetVertexBufPtr(size_t start) { return &pVtxPool[start]; }
void ResetPools() override {
pVtxPool.Reset();
pIdxPool.Reset();
}
private:
VtxPool pVtxPool;
IdxPool pIdxPool;
};
class PD_API Gfx {
public:
Gfx() = default;
~Gfx() = default;
template <typename T, typename... Args>
static void UseDriver(Args&&... args) {
// assert(driver == nullptr && "OS Driver already set");
driver = std::make_unique<T>(std::forward<Args>(args)...);
}
static void Init() { driver->Init(); }
static void Deinit() { driver->Deinit(); }
static void SetViewPort(const ivec2& vp) { driver->SetViewPort(vp); }
static void SetViewPort(int w, int h) { driver->SetViewPort(w, h); }
static void Reset() { driver->Reset(); }
static void Draw(const Pool<Li::Command>& commands) {
driver->Draw(commands);
}
static Li::Texture LoadTexture(const std::vector<PD::u8>& pixels, int w,
int h,
TextureFormat type = TextureFormat::RGBA32,
TextureFilter filter = TextureFilter::Linear) {
return driver->LoadTexture(pixels, w, h, type, filter);
}
static void DeleteTexture(const Li::Texture& tex) {
driver->DeleteTexture(tex);
}
static const char* GetDriverName() { return driver->GetName(); }
private:
static std::unique_ptr<GfxDriver> driver;
};
} // namespace PD

View File

@@ -0,0 +1,16 @@
#pragma once
#include <pd/common.hpp>
namespace PD {
class DriverInterface {
public:
DriverInterface(const std::string_view& name) : pName(name) {}
virtual ~DriverInterface() {}
const char* GetName() const { return pName.data(); }
private:
std::string_view pName;
};
} // namespace PD

32
include/pd/drivers/os.hpp Executable file
View File

@@ -0,0 +1,32 @@
#pragma once
#include <pd/drivers/interface.hpp>
namespace PD {
class PD_API OsDriver : public DriverInterface {
public:
OsDriver(std::string_view name = "Default") : DriverInterface(name) {}
virtual ~OsDriver() {}
virtual u64 GetTime() const;
virtual u64 GetTimeNano() const;
};
class PD_API Os {
public:
Os() = default;
~Os() = default;
template <typename T, typename... Args>
static void UseDriver(Args&&... args) {
// assert(driver == nullptr && "OS Driver already set");
driver = std::make_unique<T>(std::forward<Args>(args)...);
}
static u64 GetTime() { return driver->GetTime(); }
static u64 GetTimeNano() { return driver->GetTimeNano(); }
private:
static std::unique_ptr<OsDriver> driver;
};
} // namespace PD

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,25 @@
#pragma once
#include <pd/core/core.hpp>
#include <pd/lithium/texture.hpp>
namespace PD {
namespace Li {
enum class AtlasState {
Invalid,
ReqCreate,
ReqUpdate,
ReqDestroy,
};
class Atlas {
public:
Atlas() {}
~Atlas() {}
private:
AtlasState pState = AtlasState::Invalid;
TextureID pID;
};
} // namespace Li
} // namespace PD

View File

@@ -0,0 +1,61 @@
#pragma once
#include <cstddef>
#include <pd/core/pool.hpp>
#include <pd/lithium/pools.hpp>
#include <pd/lithium/vertex.hpp>
namespace PD {
namespace Li {
class Command {
public:
Command() { Reset(); }
~Command() {}
void Reserve(size_t vtx, size_t idx) {
if (!FirstVertex)
FirstVertex = AllocateVertices(vtx);
else
AllocateVertices(vtx);
if (!FirstIndex)
FirstIndex = AllocateIndices(idx);
else
AllocateIndices(idx);
}
void Reset() {
Layer = 0;
Tex = 0;
FirstIndex = nullptr;
FirstVertex = nullptr;
IndexCount = 0;
VertexCount = 0;
}
Command& Add(const Vertex& vtx) {
FirstVertex[VertexCount++] = vtx;
return *this;
}
Command& Add(u16 idx) {
FirstIndex[IndexCount++] = VertexCount + idx;
return *this;
}
Command& Add(u16 a, u16 b, u16 c) {
FirstIndex[IndexCount++] = VertexCount + a;
FirstIndex[IndexCount++] = VertexCount + b;
FirstIndex[IndexCount++] = VertexCount + c;
return *this;
}
int Layer = 0;
ptr Tex = 0;
Vertex* FirstVertex = nullptr;
u16* FirstIndex = nullptr;
size_t VertexCount = 0;
size_t IndexCount = 0;
// Todo: implement
size_t VertexCountMax = 0;
size_t IndexCountMax = 0;
};
} // namespace Li
} // namespace PD

View File

@@ -0,0 +1,109 @@
#pragma once
#include <pd/lithium/atlas.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/lithium/vertex.hpp>
template <>
struct std::formatter<PD::TextureFilter> {
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const PD::TextureFilter& value, FormatContext& ctx) const {
std::string_view ret = "Unknown";
switch (value) {
case PD::TextureFilter::Linear:
ret = "Linear";
break;
case PD::TextureFilter::Nearest:
ret = "Nearest";
break;
}
return std::format_to(ctx.out(), "{}", ret);
}
};
template <>
struct std::formatter<PD::TextureFormat> {
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const PD::TextureFormat& value, FormatContext& ctx) const {
std::string_view ret = "Unknown";
switch (value) {
case PD::TextureFormat::RGBA32:
ret = "RGBA32";
break;
case PD::TextureFormat::RGB24:
ret = "RGB24";
break;
case PD::TextureFormat::A8:
ret = "A8";
break;
}
return std::format_to(ctx.out(), "{}", ret);
}
};
template <>
struct std::formatter<PD::Li::Rect> : std::formatter<std::string> {
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const PD::Li::Rect& value, FormatContext& ctx) const {
// {l, t, r, t, l, b, r, b}
return std::format_to(ctx.out(), "{}, {}, {}, {}, {}, {}, {}, {}",
value.Top.x, value.Top.y, value.Top.z, value.Top.w,
value.Bot.x, value.Bot.y, value.Bot.z, value.Bot.w);
}
};
template <>
struct std::formatter<PD::Li::Texture> : std::formatter<std::string> {
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const PD::Li::Texture& value, FormatContext& ctx) const {
// {ID, [w, h], [l, t, r, t, l, b, r, b]}
return std::format_to(ctx.out(), "{}, [{}], [{}]", value.GetID(),
value.GetSize(), value.GetUV());
}
};
template <>
struct std::formatter<PD::Li::Vertex> : std::formatter<std::string> {
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const PD::Li::Vertex& value, FormatContext& ctx) const {
// { [x, y], [u, v], colorhex }
return std::format_to(ctx.out(), "[{}], [{}], #{:08X}", value.pos, value.uv,
value.color);
}
};
template <>
struct std::formatter<PD::Li::AtlasState> : std::formatter<std::string> {
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const PD::Li::AtlasState& value, FormatContext& ctx) const {
std::string_view ret = "Unknown";
switch (value) {
case PD::Li::AtlasState::Invalid:
ret = "Invalid";
break;
case PD::Li::AtlasState::ReqCreate:
ret = "RequestCreate";
break;
case PD::Li::AtlasState::ReqUpdate:
ret = "RequestUpdate";
break;
case PD::Li::AtlasState::ReqDestroy:
ret = "RequestDestroy";
break;
}
return std::format_to(ctx.out(), "{}", ret);
}
};

View File

@@ -0,0 +1,5 @@
#pragma once
#include <pd/lithium/command.hpp>
#include <pd/lithium/pools.hpp>
#include <pd/lithium/vertex.hpp>

View File

@@ -0,0 +1,12 @@
#pragma once
#include <cstddef>
#include <pd/lithium/vertex.hpp>
namespace PD {
namespace Li {
PD_API void InitPools(size_t max_vertices = 32768);
PD_API Vertex* AllocateVertices(size_t count);
PD_API u16* AllocateIndices(size_t count);
} // namespace Li
} // namespace PD

149
include/pd/lithium/rect.hpp Normal file
View File

@@ -0,0 +1,149 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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>
namespace PD {
namespace Li {
class Rect {
public:
Rect() : Top(0), Bot(0) {}
~Rect() = default;
/**
* Constructor that initializes the rectangle using top and bottom positions.
* @param t Top left and right corner positions.
* @param b Bottom left and right corner positions.
*/
Rect(const fvec4& t, const fvec4& b) {
Top = t;
Bot = b;
}
/**
* Constructor that initializes the rectangle using individual corner
* positions.
* @param tl Top left corner position.
* @param tr Top right corner position.
* @param bl Bottom left corner position.
* @param br Bottom right corner position.
*/
Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br) {
Top = fvec4(tl, tr);
Bot = fvec4(bl, br);
}
/**
* Constructor that initializes the rectangle using a UV mapping vector.
*
* - The old API used vec4 for UV mapping.
* - Spritesheets have rotated images, so this was updated to use Rect for UV.
*
* @param uv Vec4 UV map.
*/
Rect(const fvec4& uv) {
Top = vec4(uv.x, uv.y, uv.z, uv.y);
Bot = vec4(uv.x, uv.w, uv.z, uv.w);
}
/**
* Get the top-left corner position.
* @return Top-left position as vec2.
*/
fvec2 TopLeft() const { return fvec2(Top.x, Top.y); }
/**
* Get the top-right corner position.
* @return Top-right position as vec2.
*/
fvec2 TopRight() const { return fvec2(Top.z, Top.w); }
/**
* Get the bottom-left corner position.
* @return Bottom-left position as vec2.
*/
fvec2 BotLeft() const { return fvec2(Bot.x, Bot.y); }
/**
* Get the bottom-right corner position.
* @return Bottom-right position as vec2.
*/
fvec2 BotRight() const { return fvec2(Bot.z, Bot.w); }
/**
* Set the top-left corner position.
* @param v New top-left position.
* @return Reference to the updated Rect.
*/
Rect& TopLeft(const fvec2& v) {
Top.x = v.x;
Top.y = v.y;
return *this;
}
/**
* Set the top-right corner position.
* @param v New top-right position.
* @return Reference to the updated Rect.
*/
Rect& TopRight(const fvec2& v) {
Top.z = v.x;
Top.w = v.y;
return *this;
}
/**
* Set the bottom-left corner position.
* @param v New bottom-left position.
* @return Reference to the updated Rect.
*/
Rect& BotLeft(const fvec2& v) {
Bot.x = v.x;
Bot.y = v.y;
return *this;
}
/**
* Set the bottom-right corner position.
* @param v New bottom-right position.
* @return Reference to the updated Rect.
*/
Rect& BotRight(const fvec2& v) {
Bot.z = v.x;
Bot.w = v.y;
return *this;
}
bool operator==(const Rect& r) const { return Top == r.Top && Bot == r.Bot; }
void SwapVec2XY() {
Top.SwapXY();
Top.SwapZW();
Bot.SwapXY();
Bot.SwapZW();
}
/** Data Section */
fvec4 Top;
fvec4 Bot;
};
} // namespace Li
} // namespace PD

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