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:
@@ -25,19 +25,19 @@ SOFTWARE.
|
||||
#include <pd/drivers/drivers.hpp>
|
||||
|
||||
namespace PD {
|
||||
PD_API Timer::Timer(bool autostart) {
|
||||
PD_API Timer::Timer(OsDriver& os, bool autostart) : pOs(os) {
|
||||
pIsRunning = autostart;
|
||||
Reset();
|
||||
}
|
||||
|
||||
PD_API void Timer::Reset() {
|
||||
pStart = OS::GetTime();
|
||||
pStart = pOs.GetTime();
|
||||
pNow = pStart;
|
||||
}
|
||||
|
||||
PD_API void Timer::Update() {
|
||||
if (pIsRunning) {
|
||||
pNow = OS::GetTime();
|
||||
pNow = pOs.GetTime();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,13 +25,13 @@ SOFTWARE.
|
||||
#include <pd/drivers/drivers.hpp>
|
||||
|
||||
namespace PD::TT {
|
||||
PD_API void Beg(const std::string& id) {
|
||||
auto trace = OS::GetTraceRef(id);
|
||||
trace->SetStart(PD::OS::GetNanoTime());
|
||||
PD_API void Beg(OsDriver& os, const std::string& id) {
|
||||
auto trace = os.GetTraceRef(id);
|
||||
trace->SetStart(os.GetNanoTime());
|
||||
}
|
||||
|
||||
PD_API void End(const std::string& id) {
|
||||
auto trace = OS::GetTraceRef(id);
|
||||
trace->SetEnd(PD::OS::GetNanoTime());
|
||||
PD_API void End(OsDriver& os, const std::string& id) {
|
||||
auto trace = os.GetTraceRef(id);
|
||||
trace->SetEnd(os.GetNanoTime());
|
||||
}
|
||||
} // namespace PD::TT
|
||||
42
source/drivers/context.cpp
Normal file
42
source/drivers/context.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
namespace PD {
|
||||
PD_API Context::Ref Context::Create() {
|
||||
Context::Ref ctx = Context::New();
|
||||
ctx->pGfx = GfxDriver::New();
|
||||
ctx->pOs = OsDriver::New();
|
||||
ctx->pHid = HidDriver::New();
|
||||
return ctx;
|
||||
}
|
||||
|
||||
PD_API PD::Li::Texture::Ref Context::GetSolidTex() {
|
||||
if (pSolidTex == nullptr) {
|
||||
std::vector<u8> data(16 * 16 * 4, 0xff);
|
||||
pSolidTex = pGfx->LoadTex(data, 16, 16);
|
||||
}
|
||||
return pSolidTex;
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -23,20 +23,4 @@ SOFTWARE.
|
||||
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
|
||||
namespace PD {
|
||||
GfxDriver::Ref Gfx::pGfx = nullptr;
|
||||
|
||||
void Gfx::Init(GfxDriver::Ref d) {
|
||||
if (!d) {
|
||||
return;
|
||||
}
|
||||
pGfx = d;
|
||||
pGfx->Init();
|
||||
pGfx->PostInit();
|
||||
}
|
||||
|
||||
void GfxDriver::PostInit() {
|
||||
std::vector<PD::u8> white(16 * 16 * 4, 0xff);
|
||||
pSolid = this->LoadTex(white, 16, 16);
|
||||
}
|
||||
} // namespace PD
|
||||
namespace PD {} // namespace PD
|
||||
@@ -24,9 +24,8 @@ SOFTWARE.
|
||||
#include <pd/drivers/hid.hpp>
|
||||
|
||||
namespace PD {
|
||||
HidDriver::Ref Hid::pHid = nullptr;
|
||||
|
||||
bool HidDriver::IsEvent(Event e, Key keys) { return KeyEvents[0][e] & keys; }
|
||||
|
||||
bool HidDriver::IsEvent(Event e, KbKey keys) {
|
||||
return KbKeyEvents[0][e].Has(keys);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,6 @@ SOFTWARE.
|
||||
#include <pd/drivers/os.hpp>
|
||||
|
||||
namespace PD {
|
||||
OsDriver::Ref OS::pOs = nullptr;
|
||||
|
||||
TT::Res::Ref& OsDriver::GetTraceRef(const std::string& id) {
|
||||
if (!pTraces.count(id)) {
|
||||
pTraces[id] = TT::Res::New();
|
||||
|
||||
@@ -30,7 +30,7 @@ SOFTWARE.
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
PD_API DrawList::DrawList(int initial_size) {
|
||||
PD_API DrawList::DrawList(Context& ctx, int initial_size) : pCtx(&ctx) {
|
||||
DrawSolid();
|
||||
pPool.Init(initial_size);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ PD_API DrawList::~DrawList() {
|
||||
pPool.Deinit();
|
||||
}
|
||||
|
||||
PD_API void DrawList::DrawSolid() { CurrentTex = Gfx::GetSolidTex(); }
|
||||
PD_API void DrawList::DrawSolid() { CurrentTex = pCtx->GetSolidTex(); }
|
||||
|
||||
PD_API void DrawList::Clear() {
|
||||
pNumIndices = 0;
|
||||
@@ -70,9 +70,6 @@ PD_API void DrawList::Merge(DrawList::Ref list) {
|
||||
PD_API void DrawList::Copy(DrawList::Ref list) { pPool.Copy(list->pPool); }
|
||||
|
||||
PD_API void DrawList::Optimize() {
|
||||
#ifndef NDEBUG
|
||||
PD::TT::Scope s("Optimize");
|
||||
#endif
|
||||
/*std::sort(pDrawList.begin(), pDrawList.end(),
|
||||
[](const PD::Li::Command::Ref &a, const PD::Li::Command::Ref &b) {
|
||||
if (a->Layer == b->Layer) { // Same layer
|
||||
|
||||
@@ -53,15 +53,15 @@ PD_API void Font::LoadTTF(const std::string& path, int height) {
|
||||
* and helps not having the font loading code twice
|
||||
* when adding LoadTTF with mem support
|
||||
*/
|
||||
TT::Scope st("LI_LoadTTF_" + path);
|
||||
TT::Scope st(*pCtx.Os().get(), "LI_LoadTTF_" + path);
|
||||
auto font = PD::IO::LoadFile2Mem(path);
|
||||
LoadTTF(font, height);
|
||||
}
|
||||
|
||||
PD_API void Font::pMakeAtlas(bool final, std::vector<u8>& font_tex, int texszs,
|
||||
PD::Li::Texture::Ref tex) {
|
||||
auto t =
|
||||
Gfx::LoadTex(font_tex, texszs, texszs, Texture::RGBA32, Texture::LINEAR);
|
||||
auto t = pCtx.Gfx()->LoadTex(font_tex, texszs, texszs, Texture::RGBA32,
|
||||
Texture::LINEAR);
|
||||
tex->CopyFrom(t);
|
||||
Textures.push_back(tex);
|
||||
}
|
||||
@@ -147,7 +147,7 @@ PD_API void Font::LoadTTF(const std::vector<u8>& data, int height) {
|
||||
uvs.z = (off.x + w) / static_cast<float>(texszs);
|
||||
uvs.w = (off.y + h) / static_cast<float>(texszs);
|
||||
// Flip if needed
|
||||
if (Gfx::Flags() & LiBackendFlags_FlipUV_Y) {
|
||||
if (pCtx.Gfx()->Flags & LiBackendFlags_FlipUV_Y) {
|
||||
uvs.y = 1.f - uvs.y;
|
||||
uvs.w = 1.f - uvs.w;
|
||||
}
|
||||
@@ -196,7 +196,7 @@ PD_API Font::Codepoint& Font::GetCodepoint(u32 cp) {
|
||||
PD_API fvec2 Font::GetTextBounds(const std::string& text, float scale) {
|
||||
u32 id = PD::FNV1A32(text);
|
||||
if (pTMS.find(id) != pTMS.end()) {
|
||||
pTMS[id].TimeStamp = PD::OS::GetTime();
|
||||
pTMS[id].TimeStamp = pCtx.Os()->GetTime();
|
||||
return pTMS[id].Size;
|
||||
}
|
||||
// Use wstring for exemple for german äöü
|
||||
@@ -242,7 +242,7 @@ PD_API fvec2 Font::GetTextBounds(const std::string& text, float scale) {
|
||||
res.y += lh;
|
||||
pTMS[id].ID = id;
|
||||
pTMS[id].Size = res;
|
||||
pTMS[id].TimeStamp = PD::OS::GetTime();
|
||||
pTMS[id].TimeStamp = pCtx.Os()->GetTime();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -341,7 +341,7 @@ PD_API std::string Font::pWrapText(const std::string& txt, float scale,
|
||||
if (pTMS.find(id) != pTMS.end()) {
|
||||
if (pTMS[id].Text.size()) {
|
||||
dim = pTMS[id].Size;
|
||||
pTMS[id].TimeStamp = PD::OS::GetTime();
|
||||
pTMS[id].TimeStamp = pCtx.Os()->GetTime();
|
||||
return pTMS[id].Text;
|
||||
}
|
||||
}
|
||||
@@ -367,7 +367,7 @@ PD_API std::string Font::pWrapText(const std::string& txt, float scale,
|
||||
pTMS[id].ID = id;
|
||||
pTMS[id].Size = dim;
|
||||
pTMS[id].Text = ret;
|
||||
pTMS[id].TimeStamp = PD::OS::GetTime();
|
||||
pTMS[id].TimeStamp = pCtx.Os()->GetTime();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ PD_API std::string Font::pShortText(const std::string& txt, float scale,
|
||||
if (pTMS.find(id) != pTMS.end()) {
|
||||
if (pTMS[id].Text.size()) {
|
||||
dim = pTMS[id].Size;
|
||||
pTMS[id].TimeStamp = PD::OS::GetTime();
|
||||
pTMS[id].TimeStamp = pCtx.Os()->GetTime();
|
||||
return pTMS[id].Text;
|
||||
}
|
||||
}
|
||||
@@ -410,12 +410,12 @@ PD_API std::string Font::pShortText(const std::string& txt, float scale,
|
||||
pTMS[id].ID = id;
|
||||
pTMS[id].Size = dim;
|
||||
pTMS[id].Text = ret;
|
||||
pTMS[id].TimeStamp = PD::OS::GetTime();
|
||||
pTMS[id].TimeStamp = pCtx.Os()->GetTime();
|
||||
return ret;
|
||||
}
|
||||
|
||||
PD_API void Font::CleanupTMS() {
|
||||
u64 t = PD::OS::GetTime();
|
||||
u64 t = pCtx.Os()->GetTime();
|
||||
for (auto it = pTMS.begin(); it != pTMS.end();) {
|
||||
if (t - it->second.TimeStamp > 1000) {
|
||||
it = pTMS.erase(it);
|
||||
|
||||
@@ -26,10 +26,10 @@ SOFTWARE.
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
PD_API void Container::HandleScrolling(fvec2 scrolling, fvec4 viewport) {
|
||||
if (last_use != 0 && OS::GetTime() - last_use > 5000) {
|
||||
if (last_use != 0 && io->pCtx.Os()->GetTime() - last_use > 5000) {
|
||||
rem = true;
|
||||
}
|
||||
last_use = OS::GetTime();
|
||||
last_use = io->pCtx.Os()->GetTime();
|
||||
pos -= fvec2(0, scrolling.y);
|
||||
skippable = !Li::Renderer::InBox(
|
||||
pos, size,
|
||||
|
||||
@@ -27,7 +27,7 @@ SOFTWARE.
|
||||
namespace PD {
|
||||
PD_API void UI7::IO::Update() {
|
||||
/** Todo: find out if we even still use the Drawlist regestry */
|
||||
u64 current = OS::GetNanoTime();
|
||||
u64 current = pCtx.Os()->GetNanoTime();
|
||||
Delta = static_cast<float>(current - LastTime) / 1000000.f;
|
||||
LastTime = current;
|
||||
DeltaStats->Add(Delta * 1000);
|
||||
|
||||
@@ -132,10 +132,10 @@ PD_API void Menu::HandleFocus() {
|
||||
if (!pIsOpen) {
|
||||
newarea = fvec4(pLayout->Pos, fvec2(pLayout->Size.x, TitleBarHeight));
|
||||
}
|
||||
if ((Hid::IsDown(Hid::Key::Touch) ||
|
||||
Hid::IsEvent(Hid::Event::Event_Down, HidKb::Kb_MouseLeft)) &&
|
||||
Li::Renderer::InBox(Hid::MousePos(), newarea) &&
|
||||
!Li::Renderer::InBox(Hid::MousePos(),
|
||||
if ((pIO->pCtx.Hid()->IsDown(Hid::Key::Touch) ||
|
||||
pIO->pCtx.Hid()->IsEvent(Hid::Event::Event_Down, HidKb::Kb_MouseLeft)) &&
|
||||
Li::Renderer::InBox(pIO->pCtx.Hid()->MousePos(), newarea) &&
|
||||
!Li::Renderer::InBox(pIO->pCtx.Hid()->MousePos(),
|
||||
pIO->InputHandler->FocusedMenuRect)) {
|
||||
pIO->InputHandler->FocusedMenu = pID;
|
||||
}
|
||||
@@ -150,7 +150,7 @@ PD_API void Menu::HandleScrolling() {
|
||||
bool allowed =
|
||||
pLayout->MaxPosition.y > (pLayout->WorkRect.w - pLayout->WorkRect.y);
|
||||
if (allowed) {
|
||||
if (PD::Hid::IsDown(PD::Hid::Key::Touch)) {
|
||||
if (pIO->pCtx.Hid()->IsDown(PD::Hid::Key::Touch)) {
|
||||
pLayout->ScrollStart = pLayout->ScrollOffset;
|
||||
}
|
||||
if (pIO->InputHandler->DragObject(
|
||||
|
||||
@@ -190,9 +190,10 @@ PD_API void Context::MetricsMenu(bool* show) {
|
||||
m->Label("Menus: " + std::to_string(pMenus.size()));
|
||||
/** Section TimeTrace */
|
||||
m->SeparatorText("TimeTrace");
|
||||
if (m->BeginTreeNode("Traces (" + std::to_string(OS::GetTraceMap().size()) +
|
||||
if (m->BeginTreeNode("Traces (" +
|
||||
std::to_string(pIO->pCtx.Os()->GetTraceMap().size()) +
|
||||
")")) {
|
||||
for (auto& it : OS::GetTraceMap()) {
|
||||
for (auto& it : pIO->pCtx.Os()->GetTraceMap()) {
|
||||
if (m->BeginTreeNode(it.second->GetID())) {
|
||||
m->Label("Diff: " + UI7DTF(it.second->GetLastDiff()));
|
||||
m->Label("Protocol Len: " +
|
||||
@@ -207,18 +208,18 @@ PD_API void Context::MetricsMenu(bool* show) {
|
||||
m->EndTreeNode();
|
||||
}
|
||||
m->SeparatorText("Palladium Info");
|
||||
m->Label("Renderer: " + PD::Gfx::pGfx->pName);
|
||||
if (m->BeginTreeNode(std::string("Input: " + PD::Hid::pHid->pName))) {
|
||||
if (PD::Hid::GetFlags() & PD::HidDriver::Flags_HasKeyboard) {
|
||||
m->Label("Renderer: " + pIO->pCtx.Gfx()->GetName());
|
||||
if (m->BeginTreeNode(std::string("Input: " + pIO->pCtx.Hid()->GetName()))) {
|
||||
if (pIO->pCtx.Hid()->Flags & PD::HidDriver::Flags_HasKeyboard) {
|
||||
m->Label("- Keyboard Supported");
|
||||
}
|
||||
if (PD::Hid::GetFlags() & PD::HidDriver::Flags_HasMouse) {
|
||||
if (pIO->pCtx.Hid()->Flags & PD::HidDriver::Flags_HasMouse) {
|
||||
m->Label("- Mouse Supported");
|
||||
}
|
||||
if (PD::Hid::GetFlags() & PD::HidDriver::Flags_HasTouch) {
|
||||
if (pIO->pCtx.Hid()->Flags & PD::HidDriver::Flags_HasTouch) {
|
||||
m->Label("- Touch Supported");
|
||||
}
|
||||
if (PD::Hid::GetFlags() & PD::HidDriver::FLags_HasGamepad) {
|
||||
if (pIO->pCtx.Hid()->Flags & PD::HidDriver::FLags_HasGamepad) {
|
||||
m->Label("- Gamepad Supported");
|
||||
}
|
||||
m->EndTreeNode();
|
||||
|
||||
Reference in New Issue
Block a user