# 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
This commit is contained in:
28
include/pd/drivers/drivers.hpp
Executable file
28
include/pd/drivers/drivers.hpp
Executable file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/drivers/os.hpp>
|
111
include/pd/drivers/gfx.hpp
Executable file
111
include/pd/drivers/gfx.hpp
Executable file
@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
using LiBackendFlags = PD::u32;
|
||||
enum LiBackendFlags_ {
|
||||
LiBackendFlags_None = 0,
|
||||
LiBackendFlags_FlipUV_Y = PD_BIT(0), // Essential for font loading
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
class GfxDriver {
|
||||
public:
|
||||
GfxDriver(const std::string& name = "NullGfx") : pName(name) {};
|
||||
~GfxDriver() = default;
|
||||
|
||||
PD_SHARED(GfxDriver);
|
||||
|
||||
void PostInit();
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual void NewFrame() {}
|
||||
|
||||
virtual void BindTex(TexAddress addr) {}
|
||||
|
||||
virtual void RenderDrawData(const std::vector<Command::Ref>& Commands) {}
|
||||
|
||||
virtual Texture::Ref LoadTex(
|
||||
const std::vector<u8>& pixels, int w, int h,
|
||||
Texture::Type type = Texture::Type::RGBA32,
|
||||
Texture::Filter filter = Texture::Filter::LINEAR) {
|
||||
// Texture loading not supported (when this func not get override)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Texture::Ref GetSolidTex() { return pSolid; }
|
||||
|
||||
const std::string pName = "NullGfx";
|
||||
LiBackendFlags Flags = 0;
|
||||
ivec2 ViewPort;
|
||||
fvec4 ClearColor;
|
||||
Texture::Ref pSolid;
|
||||
|
||||
/** Debug Variables */
|
||||
|
||||
// Optional Index counter
|
||||
u32 IndexCounter;
|
||||
// Optional Vertex counter
|
||||
u32 VertexCounter;
|
||||
// Optional Frame Counter
|
||||
u64 FrameCounter;
|
||||
};
|
||||
|
||||
/** Static Gfx Controller */
|
||||
class Gfx {
|
||||
public:
|
||||
Gfx() = default;
|
||||
~Gfx() = default;
|
||||
|
||||
static void Init(GfxDriver::Ref d);
|
||||
|
||||
static void Deinit() { pGfx->Deinit(); }
|
||||
static void NewFrame() { pGfx->NewFrame(); }
|
||||
|
||||
static void BindTex(TexAddress addr) { pGfx->BindTex(addr); }
|
||||
|
||||
static void RenderDrawData(const std::vector<Command::Ref>& Commands) {
|
||||
pGfx->RenderDrawData(Commands);
|
||||
}
|
||||
|
||||
static LiBackendFlags Flags() { return pGfx->Flags; }
|
||||
static Texture::Ref LoadTex(
|
||||
const std::vector<u8>& pixels, int w, int h,
|
||||
Texture::Type type = Texture::Type::RGBA32,
|
||||
Texture::Filter filter = Texture::Filter::LINEAR) {
|
||||
return pGfx->LoadTex(pixels, w, h, type, filter);
|
||||
}
|
||||
|
||||
static Texture::Ref GetSolidTex() { return pGfx->GetSolidTex(); }
|
||||
|
||||
static GfxDriver::Ref pGfx;
|
||||
};
|
||||
} // namespace Li
|
||||
} // namespace PD
|
214
include/pd/drivers/hid.hpp
Executable file
214
include/pd/drivers/hid.hpp
Executable file
@ -0,0 +1,214 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPHidE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
|
||||
namespace PD {
|
||||
class HidDriver {
|
||||
public:
|
||||
/** Key [Controller] */
|
||||
enum Key : u32 {
|
||||
No = 0, ///< No Key
|
||||
A = 1 << 0, ///< A
|
||||
B = 1 << 1, ///< B
|
||||
X = 1 << 2, ///< X
|
||||
Y = 1 << 3, ///< Y
|
||||
Start = 1 << 4, ///< Start
|
||||
Select = 1 << 5, ///< Select
|
||||
L = 1 << 6, ///< L
|
||||
R = 1 << 7, ///< R
|
||||
DUp = 1 << 8, ///< Dpad Up
|
||||
DDown = 1 << 9, ///< Dpad down
|
||||
DLeft = 1 << 10, ///< Dpad left
|
||||
DRight = 1 << 11, ///< Dpad right
|
||||
CPUp = 1 << 12, ///< Cpad up
|
||||
CPDown = 1 << 13, ///< cpad down
|
||||
CPLeft = 1 << 14, ///< cpad left
|
||||
CPRight = 1 << 15, ///< Cpad right
|
||||
CSUp = 1 << 16, ///< Cstick up
|
||||
CSDown = 1 << 17, ///< cstick down
|
||||
CSLeft = 1 << 18, ///< cstick left
|
||||
CSRight = 1 << 19, ///< cstick right
|
||||
ZL = 1 << 20, ///< ZL
|
||||
ZR = 1 << 21, ///< ZR
|
||||
Touch = 1 << 22, ///< Touch
|
||||
Up = DUp | CPUp, ///< DPad or CPad Up
|
||||
Down = DDown | CPDown, ///< DPad or CPad Down
|
||||
Left = DLeft | CPLeft, ///< DPad or CPad Left
|
||||
Right = DRight | CPRight, ///< DPad or CPad Right
|
||||
};
|
||||
|
||||
/** Event */
|
||||
enum Event {
|
||||
Event_Down, ///< Key Pressed
|
||||
Event_Held, ///< Key Held
|
||||
Event_Up, ///< Key released
|
||||
};
|
||||
|
||||
HidDriver(const std::string& name = "NullHid") : pName(name) {};
|
||||
virtual ~HidDriver() = default;
|
||||
PD_SHARED(HidDriver);
|
||||
|
||||
/**
|
||||
* Get Mouse Position
|
||||
* @return Mouse pos
|
||||
*/
|
||||
fvec2 MousePos() const {
|
||||
return pMouse[0];
|
||||
} /**
|
||||
* Get Last Mouse Position (from last frame)
|
||||
* @return Mouse pos
|
||||
*/
|
||||
fvec2 MousePosLast() const { return pMouse[1]; }
|
||||
|
||||
/**
|
||||
* Check for a Button Event
|
||||
* @param e Event Type
|
||||
* @param keys Keys to check for
|
||||
* @return if key(s) doing the requiested event
|
||||
*/
|
||||
bool IsEvent(Event e, Key keys);
|
||||
/**
|
||||
* Check for Key Press Event
|
||||
* @param keys set of keys
|
||||
* @return true if key is pressed
|
||||
*/
|
||||
bool IsDown(Key keys) const { return KeyEvents[0].at(Event_Down) & keys; }
|
||||
/**
|
||||
* Check for Key Held Event
|
||||
* @param keys set of keys
|
||||
* @return true if key is held
|
||||
*/
|
||||
bool IsHeld(Key keys) const { return KeyEvents[0].at(Event_Held) & keys; }
|
||||
/**
|
||||
* Check for Key Release Event
|
||||
* @param keys set of keys
|
||||
* @return true if key is released
|
||||
*/
|
||||
bool IsUp(Key keys) const { return KeyEvents[0].at(Event_Up) & keys; }
|
||||
|
||||
/**
|
||||
* Sett all keyevents to 0
|
||||
*/
|
||||
void Clear() {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
KeyEvents[i][Event_Down] = 0;
|
||||
KeyEvents[i][Event_Up] = 0;
|
||||
KeyEvents[i][Event_Held] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock input driver
|
||||
* @param v lock or not lock
|
||||
*/
|
||||
void Lock(bool v) {
|
||||
if (v != pLocked) {
|
||||
SwapTab();
|
||||
}
|
||||
pLocked = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Driver is locked
|
||||
* @return true if locked
|
||||
*/
|
||||
bool Locked() const { return pLocked; }
|
||||
|
||||
/**
|
||||
* Lock Input Driver
|
||||
*/
|
||||
void Lock() {
|
||||
if (!pLocked) {
|
||||
SwapTab();
|
||||
}
|
||||
pLocked = true;
|
||||
}
|
||||
/**
|
||||
* Unlock Input Driver
|
||||
*/
|
||||
void Unlock() {
|
||||
if (pLocked) {
|
||||
SwapTab();
|
||||
}
|
||||
pLocked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template Update Function for a device specific driver
|
||||
*/
|
||||
virtual void Update() {}
|
||||
|
||||
/** Data Section */
|
||||
|
||||
/** Backend Identification Name */
|
||||
const std::string pName;
|
||||
|
||||
/** Key Binds Map */
|
||||
std::unordered_map<u32, u32> pBinds;
|
||||
/** Swap Tabe Function */
|
||||
void SwapTab();
|
||||
/** Using 2 Positions for Current and Last */
|
||||
fvec2 pMouse[2];
|
||||
/** Lock State */
|
||||
bool pLocked = false;
|
||||
/** Key Event Table Setup */
|
||||
std::unordered_map<Event, u32> KeyEvents[2];
|
||||
};
|
||||
|
||||
/** Static Hid Controller */
|
||||
class Hid {
|
||||
public:
|
||||
Hid() = default;
|
||||
~Hid() = default;
|
||||
|
||||
/** Referenec to Drivers enums */
|
||||
using Key = HidDriver::Key;
|
||||
using Event = HidDriver::Event;
|
||||
|
||||
static void Init(HidDriver::Ref v = nullptr) {
|
||||
if (v) {
|
||||
pHid = v;
|
||||
} else {
|
||||
pHid = HidDriver::New();
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsEvent(Event e, Key keys) { return pHid->IsEvent(e, keys); }
|
||||
static bool IsDown(Key keys) { return pHid->IsDown(keys); }
|
||||
static bool IsUp(Key keys) { return pHid->IsUp(keys); }
|
||||
static bool IsHeld(Key keys) { return pHid->IsHeld(keys); }
|
||||
static fvec2 MousePos() { return pHid->MousePos(); }
|
||||
static fvec2 MousePosLast() { return pHid->MousePosLast(); }
|
||||
static void Clear() { pHid->Clear(); }
|
||||
static void Lock() { pHid->Lock(); }
|
||||
static void Lock(bool v) { pHid->Lock(v); }
|
||||
static void Unlock() { pHid->Unlock(); }
|
||||
static bool Locked() { return pHid->Locked(); }
|
||||
static void Update() { pHid->Update(); }
|
||||
|
||||
static HidDriver::Ref pHid;
|
||||
};
|
||||
} // namespace PD
|
71
include/pd/drivers/os.hpp
Executable file
71
include/pd/drivers/os.hpp
Executable file
@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/core/timetrace.hpp>
|
||||
|
||||
namespace PD {
|
||||
using TraceMap = std::map<std::string, TT::Res::Ref>;
|
||||
|
||||
class OsDriver {
|
||||
public:
|
||||
OsDriver() = default;
|
||||
virtual ~OsDriver() = default;
|
||||
PD_SHARED(OsDriver);
|
||||
|
||||
virtual u64 GetTime();
|
||||
virtual u64 GetNanoTime();
|
||||
TraceMap& GetTraceMap();
|
||||
TT::Res::Ref& GetTraceRef(const std::string& id);
|
||||
bool TraceExist(const std::string& id);
|
||||
|
||||
TraceMap pTraces;
|
||||
};
|
||||
|
||||
/** Static Os Controller */
|
||||
class OS {
|
||||
public:
|
||||
OS() = default;
|
||||
~OS() = default;
|
||||
|
||||
static void Init(OsDriver::Ref v = nullptr) {
|
||||
if (v) {
|
||||
pOs = v;
|
||||
} else {
|
||||
pOs = OsDriver::New();
|
||||
}
|
||||
}
|
||||
|
||||
static u64 GetTime() { return pOs->GetTime(); }
|
||||
static u64 GetNanoTime() { return pOs->GetNanoTime(); }
|
||||
static TraceMap& GetTraceMap() { return pOs->GetTraceMap(); }
|
||||
static TT::Res::Ref& GetTraceRef(const std::string& id) {
|
||||
return pOs->GetTraceRef(id);
|
||||
}
|
||||
static bool TraceExist(const std::string& id) { return pOs->TraceExist(id); }
|
||||
|
||||
static OsDriver::Ref pOs;
|
||||
};
|
||||
} // namespace PD
|
26
include/pd/drivers/pd_p_api.hpp
Executable file
26
include/pd/drivers/pd_p_api.hpp
Executable file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#define PD_DEF_EXP(x, y) x y = nullptr
|
Reference in New Issue
Block a user