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
This commit is contained in:
2026-01-26 20:46:27 +01:00
parent 892f8ce0c4
commit e8072a064c
47 changed files with 350 additions and 242 deletions

View File

@@ -27,6 +27,6 @@ SOFTWARE.
#include <pd-3ds/bknd-hid.hpp>
namespace PD {
PD::Li::Font::Ref LoadSystemFont();
PD::Li::Font::Ref LoadSystemFont(Context& ctx);
void Init(void* data = nullptr);
} // namespace PD

View File

@@ -32,7 +32,7 @@ SOFTWARE.
namespace PD {
class GfxC3D : public GfxDriver {
public:
GfxC3D() : GfxDriver("Citro3D") {}
GfxC3D(PDDriverData data = nullptr) : GfxDriver("Citro3D") {}
~GfxC3D() = default;
PD_SHARED(GfxC3D);

View File

@@ -28,7 +28,7 @@ SOFTWARE.
namespace PD {
class Hid3DS : public HidDriver {
public:
Hid3DS();
Hid3DS(PDDriverData data = nullptr);
~Hid3DS() = default;
PD_SHARED(Hid3DS);

View File

@@ -42,7 +42,7 @@ class LinearAllocator {
T* allocate(std::size_t n) {
if (n > max_size()) {
throw std::runtime_error("[PD] LinearAllocator: Bad alloc!");
PD::Throw("[PD] LinearAllocator: Bad alloc!");
}
return static_cast<T*>(linearAlloc(n * sizeof(T)));
}

View File

@@ -156,7 +156,7 @@ void GfxC3D::RenderDrawData(const PD::Li::CmdPool& Commands) {
// C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, (C3D_Mtx*)&proj);
size_t index = 0;
while (index < Commands.Size()) {
PD::Li::Texture::Ref Tex = Commands.GetCmd(index)->Tex;
PD::Li::TexAddress Tex = Commands.GetCmd(index)->Tex;
if (!Tex) {
index++;
continue;
@@ -186,8 +186,8 @@ void GfxC3D::RenderDrawData(const PD::Li::CmdPool& Commands) {
} else {
C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0);
}
FragCfg(((C3D_Tex*)Tex->Address)->fmt);
BindTex(Tex->Address);
FragCfg(((C3D_Tex*)Tex)->fmt);
BindTex(Tex);
auto bufInfo = C3D_GetBufInfo();
BufInfo_Init(bufInfo);
BufInfo_Add(bufInfo, VertexBuffer.data(), sizeof(Li::Vertex), 3, 0x210);

View File

@@ -26,7 +26,7 @@ SOFTWARE.
#include <pd-3ds/bknd-hid.hpp>
namespace PD {
Hid3DS::Hid3DS() : HidDriver("Hid3DS") {
Hid3DS::Hid3DS(PDDriverData data) : HidDriver("Hid3DS") {
this->Flags |= Flags_HasTouch;
this->Flags |= FLags_HasGamepad;
pBinds[KEY_A] = A;
@@ -64,7 +64,7 @@ void Hid3DS::Update() {
u32 kd = hidKeysDown();
u32 kh = hidKeysHeld();
u32 ku = hidKeysUp();
for (auto &b : pBinds) {
for (auto& b : pBinds) {
if (b.first & kd) {
KeyEvents[0][Event_Down] |= b.second;
}

View File

@@ -27,9 +27,9 @@ SOFTWARE.
#include <pd-3ds.hpp>
namespace PD {
PD::Li::Font::Ref LoadSystemFont() {
TT::Scope st("LI_SystemFont"); // Trace loading time
Li::Font::Ref ret = Li::Font::New();
PD::Li::Font::Ref LoadSystemFont(Context& ctx) {
TT::Scope st(*ctx.Os(), "LI_SystemFont"); // Trace loading time
Li::Font::Ref ret = Li::Font::New(ctx);
fontEnsureMapped(); // Call this to be sure the font is mapped
// Get some const references for system font loading
const auto fnt = fontGetSystemFont();
@@ -124,8 +124,8 @@ PD::Li::Font::Ref LoadSystemFont() {
void Init(void* data) {
// Dekstop Init Stage
// First use default OS Driver
PD::OS::Init();
PD::Gfx::Init(PD::GfxC3D::New());
PD::Hid::Init(PD::Hid3DS::New());
// PD::OS::Init();
// PD::Gfx::Init(PD::GfxC3D::New());
// PD::Hid::Init(PD::Hid3DS::New());
}
} // namespace PD

View File

@@ -34,7 +34,7 @@ SOFTWARE.
namespace PD {
class GfxGL2 : public GfxDriver {
public:
GfxGL2() : GfxDriver("OpenGL2") {}
GfxGL2(PDDriverData data = nullptr) : GfxDriver("OpenGL2") {}
~GfxGL2() = default;
PD_SHARED(GfxGL2);

View File

@@ -30,7 +30,7 @@ SOFTWARE.
namespace PD {
class HidGLFW : public HidDriver {
public:
HidGLFW(GLFWwindow* win);
HidGLFW(PDDriverData data);
~HidGLFW() = default;
PD_SHARED(HidGLFW);
@@ -44,7 +44,7 @@ class HidGLFW : public HidDriver {
pTimings.erase(k);
return false;
}
return (PD::OS::GetTime() - pTimings[k]) > 50;
return 0; //(PD::OS::GetTime() - pTimings[k]) > 50;
}
if (!IsEvent(Event_Held, k)) {
if (pTimings.count(k)) {
@@ -53,7 +53,7 @@ class HidGLFW : public HidDriver {
}
}
if (IsEvent(Event_Held, k)) {
pTimings[k] = PD::OS::GetTime();
pTimings[k] = 0; // PD::OS::GetTime();
return true;
}
return false;

View File

@@ -337,6 +337,8 @@ PD::Li::Texture::Ref GfxGL2::LoadTex(const std::vector<PD::u8>& pixels, int w,
}
glBindTexture(GL_TEXTURE_2D, 0);
auto res = PD::Li::Texture::New(texID, PD::ivec2(w, h));
std::cout << std::format("Texture loaded: {} {}", texID, PD::ivec2(w, h))
<< std::endl;
return res;
}

View File

@@ -43,8 +43,11 @@ void TextCB(GLFWwindow* win, unsigned int c) {
}
*HidGLFW::pText += (char)c;
}
HidGLFW::HidGLFW(GLFWwindow* win) : HidDriver("HidGLFW") {
Window = win;
HidGLFW::HidGLFW(PDDriverData data) : HidDriver("HidGLFW") {
if (!data) {
std::cout << "[HidGLFW] Error: Data pointer was null" << std::endl;
}
Window = reinterpret_cast<GLFWwindow*>(data);
HidGLFW::pOldTextCB = glfwSetCharCallback(Window, NullTextCB);
Flags |= Flags_HasKeyboard;
Flags |= Flags_HasMouse;
@@ -148,10 +151,10 @@ void HidGLFW::Update() {
glfwGetCursorPos(Window, &x, &y);
pMouse[1] = pMouse[0]; // Cycle pMouse pos
pMouse[0] = fvec2(x, y);
if (pInTextMode && (PD::OS::GetTime() - pLastUpdate) > 50) {
pLastUpdate = PD::OS::GetTime();
HandleTextOps();
}
/*if (pInTextMode && (PD::OS::GetTime() - pLastUpdate) > 50) {
pLastUpdate = PD::OS::GetTime();
HandleTextOps();
}*/
}
void HidGLFW::GetInputStr(std::string& str) {

View File

@@ -26,7 +26,7 @@ SOFTWARE.
namespace PD {
void Init(void* data) {
if (!data) {
/*if (!data) {
std::cout << "[PD-DRIVERS] Error: pd-desktop requires GLFWwindow* "
"reference as data "
"input!"
@@ -37,6 +37,6 @@ void Init(void* data) {
// First use default OS Driver
PD::OS::Init();
PD::Gfx::Init(PD::GfxGL2::New());
PD::Hid::Init(PD::HidGLFW::New(reinterpret_cast<GLFWwindow*>(data)));
PD::Hid::Init(PD::HidGLFW::New(reinterpret_cast<GLFWwindow*>(data)));*/
}
} // namespace PD

View File

View File

View File

View File

View File