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
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
#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/gfx.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/drivers/os.hpp>
|
||||
|
||||
namespace PD {
|
||||
class PD_API Context {
|
||||
public:
|
||||
Context()
|
||||
: pOs(OsDriver::New()), pGfx(GfxDriver::New()), pHid(HidDriver::New()) {}
|
||||
~Context() {}
|
||||
|
||||
PD_RAW(Context);
|
||||
|
||||
static Context::Ref Create();
|
||||
|
||||
template <typename Driver>
|
||||
void UseGfxDriver(PDDriverData data) {
|
||||
static_assert(std::is_base_of<GfxDriver, Driver>::value,
|
||||
"Driver must extend GfxDriver");
|
||||
pGfx.reset();
|
||||
pGfx = Driver::New(data);
|
||||
}
|
||||
|
||||
template <typename Driver>
|
||||
void UseHidDriver(PDDriverData data) {
|
||||
static_assert(std::is_base_of<HidDriver, Driver>::value,
|
||||
"Driver must extend HidDriver");
|
||||
pHid.reset();
|
||||
pHid = Driver::New(data);
|
||||
}
|
||||
|
||||
template <typename Driver>
|
||||
void UseOsDriver(PDDriverData data) {
|
||||
static_assert(std::is_base_of<OsDriver, Driver>::value,
|
||||
"Driver must extend OsDriver");
|
||||
pOs.reset();
|
||||
pOs = Driver::New(data);
|
||||
}
|
||||
|
||||
PD::Li::Texture::Ref GetSolidTex();
|
||||
|
||||
OsDriver::Ref Os() { return pOs; }
|
||||
GfxDriver::Ref Gfx() { return pGfx; }
|
||||
HidDriver::Ref Hid() { return pHid; }
|
||||
|
||||
private:
|
||||
OsDriver::Ref pOs = nullptr;
|
||||
GfxDriver::Ref pGfx = nullptr;
|
||||
HidDriver::Ref pHid = nullptr;
|
||||
|
||||
PD::Li::Texture::Ref pSolidTex = nullptr;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,29 +1,3 @@
|
||||
#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/drivers/context.hpp>
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/drivers/os.hpp>
|
||||
#include <pd/drivers/os.hpp>
|
||||
@@ -1,119 +1,82 @@
|
||||
#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/types.hpp>
|
||||
#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 = PD_BIT(0), // Essential for font loading
|
||||
LiBackendFlags_FlipUV_Y = 1 << 0, // Essential for font loading
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
// The backend api nobody asked for
|
||||
class GfxDriver2 {
|
||||
public:
|
||||
GfxDriver2(const std::string& name = "NullGfx") : pName(name) {};
|
||||
~GfxDriver2() = default;
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual void Draw(const PD::Li::CmdPool& pool) {}
|
||||
virtual void TexBind(PD::Li::TexAddress addr) {}
|
||||
virtual PD::Li::TexAddress TexLoad(
|
||||
const std::vector<PD::u8>& pixels, int w, int h,
|
||||
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
|
||||
PD::Li::Texture::Filter filter = PD::Li::Texture::Filter::LINEAR) {
|
||||
return 0;
|
||||
}
|
||||
virtual void TexDelete(PD::Li::TexAddress tex) {}
|
||||
|
||||
protected:
|
||||
const std::string pName;
|
||||
LiBackendFlags pFlags = 0;
|
||||
size_t CurrentIndex = 0;
|
||||
size_t CurrentVertex = 0;
|
||||
ivec2 ViewPort;
|
||||
using TextureID = ptr;
|
||||
enum class TextureFilter {
|
||||
Linear,
|
||||
Nearest,
|
||||
};
|
||||
class GfxDriver {
|
||||
|
||||
enum class TextureFormat {
|
||||
RGBA32,
|
||||
A8,
|
||||
};
|
||||
|
||||
class PD_API GfxDriver : public DriverInterface {
|
||||
public:
|
||||
GfxDriver(const std::string& name = "NullGfx") : pName(name) {}
|
||||
GfxDriver(PDDriverData data) : pName("NullGfx") {}
|
||||
~GfxDriver() = default;
|
||||
|
||||
PD_SHARED(GfxDriver);
|
||||
|
||||
void PostInit();
|
||||
GfxDriver(std::string_view name = "Default") : DriverInterface(name) {}
|
||||
virtual ~GfxDriver() {}
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual void NewFrame() {}
|
||||
|
||||
virtual void BindTex(Li::TexAddress addr) {}
|
||||
|
||||
virtual void RenderDrawData(const Li::CmdPool& Commands) {}
|
||||
|
||||
void SetViewPort(const ivec2& vp) { ViewPort = vp; }
|
||||
void SetViewPort(int w, int h) { ViewPort = PD::ivec2(w, h); }
|
||||
|
||||
virtual Li::Texture::Ref LoadTex(
|
||||
const std::vector<u8>& pixels, int w, int h,
|
||||
Li::Texture::Type type = Li::Texture::Type::RGBA32,
|
||||
Li::Texture::Filter filter = Li::Texture::Filter::LINEAR) {
|
||||
// Texture loading not supported (when this func not get override)
|
||||
return nullptr;
|
||||
virtual void Submit() {}
|
||||
virtual void BindTexture(TextureID id) {}
|
||||
virtual void Reset() {}
|
||||
virtual TextureID LoadTexture(const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) {}
|
||||
virtual void DeleteTexture(const TextureID& tex) {}
|
||||
void Draw(const std::vector<Li::Command>& commands) {
|
||||
CountCommands += commands.size();
|
||||
// Bind shader
|
||||
Projection = Mat4::Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f);
|
||||
// Shader Set Mtx
|
||||
size_t index = 0;
|
||||
while (index < commands.size()) {
|
||||
CurrentTex = commands[index].Tex;
|
||||
if (!CurrentTex) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void DestroyTex(PD::Li::Texture::Ref tex) {}
|
||||
|
||||
Li::Texture::Ref GetSolidTex() { return pSolid; }
|
||||
|
||||
const std::string& GetName() const { return pName; }
|
||||
|
||||
const std::string pName = "NullGfx";
|
||||
LiBackendFlags Flags = 0;
|
||||
ivec2 ViewPort;
|
||||
Mat4 Projection;
|
||||
Li::Texture::Ref pSolid;
|
||||
size_t CurrentVertex = 0;
|
||||
private:
|
||||
size_t CurrentIndex = 0;
|
||||
size_t CurrentVertex = 0;
|
||||
TextureID CurrentTex = 0;
|
||||
Mat4 Projection;
|
||||
ivec2 ViewPort;
|
||||
|
||||
/** Debug Variables */
|
||||
// Counters
|
||||
size_t CountDrawcalls = 0;
|
||||
size_t CountCommands = 0;
|
||||
size_t CountVertices = 0;
|
||||
size_t CountIndices = 0;
|
||||
};
|
||||
|
||||
// Optional Index counter
|
||||
u32 IndexCounter;
|
||||
// Optional Vertex counter
|
||||
u32 VertexCounter;
|
||||
// Optional Frame Counter
|
||||
u64 FrameCounter;
|
||||
// Draw calls counter
|
||||
u32 DrawCalls;
|
||||
// Command Counter
|
||||
u32 DrawCommands;
|
||||
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)...);
|
||||
}
|
||||
|
||||
private:
|
||||
static std::unique_ptr<GfxDriver> driver;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,267 +0,0 @@
|
||||
#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 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>
|
||||
#include <pd/drivers/types.hpp>
|
||||
|
||||
namespace PD {
|
||||
/** Did not found a better solution yet sadly */
|
||||
namespace HidKb {
|
||||
// Lets use u128 here
|
||||
using KbKey = u128;
|
||||
constexpr static KbKey Kb_No = 0;
|
||||
constexpr static KbKey Kb_Escape = KbKey::Flag(0);
|
||||
constexpr static KbKey Kb_Q = KbKey::Flag(1);
|
||||
constexpr static KbKey Kb_W = KbKey::Flag(2);
|
||||
constexpr static KbKey Kb_E = KbKey::Flag(3);
|
||||
constexpr static KbKey Kb_R = KbKey::Flag(4);
|
||||
constexpr static KbKey Kb_T = KbKey::Flag(5);
|
||||
constexpr static KbKey Kb_Z = KbKey::Flag(6);
|
||||
constexpr static KbKey Kb_U = KbKey::Flag(7);
|
||||
constexpr static KbKey Kb_I = KbKey::Flag(8);
|
||||
constexpr static KbKey Kb_O = KbKey::Flag(9);
|
||||
constexpr static KbKey Kb_P = KbKey::Flag(10);
|
||||
constexpr static KbKey Kb_A = KbKey::Flag(11);
|
||||
constexpr static KbKey Kb_S = KbKey::Flag(12);
|
||||
constexpr static KbKey Kb_D = KbKey::Flag(13);
|
||||
constexpr static KbKey Kb_F = KbKey::Flag(14);
|
||||
constexpr static KbKey Kb_G = KbKey::Flag(15);
|
||||
constexpr static KbKey Kb_H = KbKey::Flag(16);
|
||||
constexpr static KbKey Kb_J = KbKey::Flag(17);
|
||||
constexpr static KbKey Kb_K = KbKey::Flag(18);
|
||||
constexpr static KbKey Kb_L = KbKey::Flag(19);
|
||||
constexpr static KbKey Kb_Y = KbKey::Flag(20);
|
||||
constexpr static KbKey Kb_X = KbKey::Flag(21);
|
||||
constexpr static KbKey Kb_C = KbKey::Flag(22);
|
||||
constexpr static KbKey Kb_V = KbKey::Flag(23);
|
||||
constexpr static KbKey Kb_B = KbKey::Flag(24);
|
||||
constexpr static KbKey Kb_N = KbKey::Flag(25);
|
||||
constexpr static KbKey Kb_M = KbKey::Flag(26);
|
||||
constexpr static KbKey Kb_1 = KbKey::Flag(27);
|
||||
constexpr static KbKey Kb_2 = KbKey::Flag(28);
|
||||
constexpr static KbKey Kb_3 = KbKey::Flag(29);
|
||||
constexpr static KbKey Kb_4 = KbKey::Flag(30);
|
||||
constexpr static KbKey Kb_5 = KbKey::Flag(31);
|
||||
constexpr static KbKey Kb_6 = KbKey::Flag(32);
|
||||
constexpr static KbKey Kb_7 = KbKey::Flag(33);
|
||||
constexpr static KbKey Kb_8 = KbKey::Flag(34);
|
||||
constexpr static KbKey Kb_9 = KbKey::Flag(35);
|
||||
constexpr static KbKey Kb_0 = KbKey::Flag(36);
|
||||
constexpr static KbKey Kb_F1 = KbKey::Flag(37);
|
||||
constexpr static KbKey Kb_F2 = KbKey::Flag(38);
|
||||
constexpr static KbKey Kb_F3 = KbKey::Flag(39);
|
||||
constexpr static KbKey Kb_F4 = KbKey::Flag(40);
|
||||
constexpr static KbKey Kb_F5 = KbKey::Flag(41);
|
||||
constexpr static KbKey Kb_F6 = KbKey::Flag(42);
|
||||
constexpr static KbKey Kb_F7 = KbKey::Flag(43);
|
||||
constexpr static KbKey Kb_F8 = KbKey::Flag(44);
|
||||
constexpr static KbKey Kb_F9 = KbKey::Flag(45);
|
||||
constexpr static KbKey Kb_F10 = KbKey::Flag(46);
|
||||
constexpr static KbKey Kb_F11 = KbKey::Flag(47);
|
||||
constexpr static KbKey Kb_F12 = KbKey::Flag(48);
|
||||
constexpr static KbKey Kb_MouseLeft = KbKey::Flag(120);
|
||||
} // namespace HidKb
|
||||
|
||||
class PD_API HidDriver {
|
||||
public:
|
||||
enum Flags : u32 {
|
||||
Flags_None = 0,
|
||||
FLags_HasGamepad = 1 << 0,
|
||||
Flags_HasKeyboard = 1 << 1,
|
||||
Flags_HasTouch = 1 << 2,
|
||||
Flags_HasMouse = 1 << 3,
|
||||
};
|
||||
// Todo: Name to GpKey (GamepadKey)
|
||||
/** Key [Controller] */
|
||||
enum Key : u32 {
|
||||
No = 0, ///< No Key
|
||||
A = 1 << 0, ///< A
|
||||
B = 1 << 1, ///< B
|
||||
X = 1 << 2, ///< X
|
||||
Y = 1 << 3, ///< Y
|
||||
Start = 1 << 4, ///< Start
|
||||
Select = 1 << 5, ///< Select
|
||||
L = 1 << 6, ///< L
|
||||
R = 1 << 7, ///< R
|
||||
DUp = 1 << 8, ///< Dpad Up
|
||||
DDown = 1 << 9, ///< Dpad down
|
||||
DLeft = 1 << 10, ///< Dpad left
|
||||
DRight = 1 << 11, ///< Dpad right
|
||||
CPUp = 1 << 12, ///< Cpad up
|
||||
CPDown = 1 << 13, ///< cpad down
|
||||
CPLeft = 1 << 14, ///< cpad left
|
||||
CPRight = 1 << 15, ///< Cpad right
|
||||
CSUp = 1 << 16, ///< Cstick up
|
||||
CSDown = 1 << 17, ///< cstick down
|
||||
CSLeft = 1 << 18, ///< cstick left
|
||||
CSRight = 1 << 19, ///< cstick right
|
||||
ZL = 1 << 20, ///< ZL
|
||||
ZR = 1 << 21, ///< ZR
|
||||
Touch = 1 << 22, ///< Touch
|
||||
Up = DUp | CPUp, ///< DPad or CPad Up
|
||||
Down = DDown | CPDown, ///< DPad or CPad Down
|
||||
Left = DLeft | CPLeft, ///< DPad or CPad Left
|
||||
Right = DRight | CPRight, ///< DPad or CPad Right
|
||||
};
|
||||
|
||||
using KbKey = HidKb::KbKey;
|
||||
|
||||
/** Event */
|
||||
enum Event {
|
||||
Event_Null,
|
||||
Event_Down, ///< Key Pressed
|
||||
Event_Held, ///< Key Held
|
||||
Event_Up, ///< Key released
|
||||
};
|
||||
|
||||
HidDriver(const std::string& name = "NullHid") : pName(name) {}
|
||||
HidDriver(PDDriverData data) : pName("NullHid") {}
|
||||
virtual ~HidDriver() = default;
|
||||
PD_SHARED(HidDriver);
|
||||
|
||||
/**
|
||||
* Get Mouse Position
|
||||
* @return Mouse pos
|
||||
*/
|
||||
fvec2 MousePos() const {
|
||||
return pMouse[0];
|
||||
} /**
|
||||
* Get Last Mouse Position (from last frame)
|
||||
* @return Mouse pos
|
||||
*/
|
||||
fvec2 MousePosLast() const { return pMouse[1]; }
|
||||
|
||||
/**
|
||||
* Check for a Button Event
|
||||
* @param e Event Type
|
||||
* @param keys Keys to check for
|
||||
* @return if key(s) doing the requiested event
|
||||
*/
|
||||
bool IsEvent(Event e, Key keys);
|
||||
bool IsEvent(Event e, KbKey key);
|
||||
/**
|
||||
* Check for Key Press Event
|
||||
* @param keys set of keys
|
||||
* @return true if key is pressed
|
||||
*/
|
||||
bool IsDown(Key keys) const { return KeyEvents[0].at(Event_Down) & keys; }
|
||||
/**
|
||||
* Check for Key Held Event
|
||||
* @param keys set of keys
|
||||
* @return true if key is held
|
||||
*/
|
||||
bool IsHeld(Key keys) const { return KeyEvents[0].at(Event_Held) & keys; }
|
||||
/**
|
||||
* Check for Key Release Event
|
||||
* @param keys set of keys
|
||||
* @return true if key is released
|
||||
*/
|
||||
bool IsUp(Key keys) const { return KeyEvents[0].at(Event_Up) & keys; }
|
||||
|
||||
/**
|
||||
* Sett all keyevents to 0
|
||||
*/
|
||||
void Clear() {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
KeyEvents[i][Event_Down] = 0;
|
||||
KeyEvents[i][Event_Up] = 0;
|
||||
KeyEvents[i][Event_Held] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock input driver
|
||||
* @param v lock or not lock
|
||||
*/
|
||||
void Lock(bool v) {
|
||||
if (v != pLocked) {
|
||||
SwapTab();
|
||||
}
|
||||
pLocked = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Driver is locked
|
||||
* @return true if locked
|
||||
*/
|
||||
bool Locked() const { return pLocked; }
|
||||
|
||||
/**
|
||||
* Lock Input Driver
|
||||
*/
|
||||
void Lock() {
|
||||
if (!pLocked) {
|
||||
SwapTab();
|
||||
}
|
||||
pLocked = true;
|
||||
}
|
||||
/**
|
||||
* Unlock Input Driver
|
||||
*/
|
||||
void Unlock() {
|
||||
if (pLocked) {
|
||||
SwapTab();
|
||||
}
|
||||
pLocked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template Update Function for a device specific driver
|
||||
*/
|
||||
virtual void Update();
|
||||
/**
|
||||
* Get Text from Keyboard
|
||||
*/
|
||||
virtual void GetInputStr(std::string& str) {}
|
||||
|
||||
const std::string& GetName() const { return pName; }
|
||||
|
||||
/** Data Section */
|
||||
|
||||
/** Backend Identification Name */
|
||||
const std::string pName;
|
||||
|
||||
/** Flags */
|
||||
u32 Flags = 0;
|
||||
|
||||
/** Key Binds Map */
|
||||
std::unordered_map<u32, u32> pBinds;
|
||||
std::unordered_map<u128, u128> pKbBinds;
|
||||
/** Swap Tabe Function */
|
||||
void SwapTab();
|
||||
/** Using 2 Positions for Current and Last */
|
||||
fvec2 pMouse[2];
|
||||
/** Lock State */
|
||||
bool pLocked = false;
|
||||
/** Key Event Table Setup */
|
||||
std::unordered_map<Event, u32> KeyEvents[2];
|
||||
/** Keyboard Key Event Table Setup */
|
||||
std::unordered_map<Event, u128> KbKeyEvents[2];
|
||||
};
|
||||
namespace Hid {
|
||||
using Event = HidDriver::Event;
|
||||
using Key = HidDriver::Key;
|
||||
} // namespace Hid
|
||||
} // namespace PD
|
||||
16
include/pd/drivers/interface.hpp
Normal file
16
include/pd/drivers/interface.hpp
Normal 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
|
||||
@@ -1,53 +1,32 @@
|
||||
#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/common.hpp>
|
||||
#include <pd/core/timetrace.hpp>
|
||||
#include <pd/drivers/types.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
#include <pd/drivers/interface.hpp>
|
||||
|
||||
namespace PD {
|
||||
using TraceMap = std::map<std::string, TT::Res::Ref>;
|
||||
|
||||
class PD_API OsDriver {
|
||||
class PD_API OsDriver : public DriverInterface {
|
||||
public:
|
||||
OsDriver(const std::string& name = "StdPd") : pName(name) {}
|
||||
OsDriver(PDDriverData data) : pName("StdPd") {}
|
||||
virtual ~OsDriver() = default;
|
||||
PD_SHARED(OsDriver);
|
||||
OsDriver(std::string_view name = "Default") : DriverInterface(name) {}
|
||||
virtual ~OsDriver() {}
|
||||
|
||||
virtual u64 GetTime();
|
||||
virtual u64 GetNanoTime();
|
||||
TraceMap& GetTraceMap();
|
||||
TT::Res::Ref& GetTraceRef(const std::string& id);
|
||||
bool TraceExist(const std::string& id);
|
||||
const std::string& GetName() const { return pName; }
|
||||
virtual u64 GetTime() const;
|
||||
virtual u64 GetTimeNano() const;
|
||||
};
|
||||
|
||||
TraceMap pTraces;
|
||||
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:
|
||||
const std::string pName = "StdPd";
|
||||
static std::unique_ptr<OsDriver> driver;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,45 +0,0 @@
|
||||
#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 {
|
||||
class Snd {
|
||||
public:
|
||||
Snd(const std::string& name = "NullSnd") : pName(name) {};
|
||||
~Snd() = default;
|
||||
|
||||
PD_SHARED(Snd);
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual bool Done(int buf_idx) {}
|
||||
virtual void Update(int buf_idx, void* data) {}
|
||||
virtual bool IsChannelPlaying(int chn) {}
|
||||
virtual bool IsChannelPaused(int chn) {}
|
||||
|
||||
const std::string pName = "NullSnd";
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,3 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
using PDDriverData = void*;
|
||||
Reference in New Issue
Block a user