Remove custom standard lib
Why?? cause it was russian roulette with pointer access stuff etc
This commit is contained in:
@@ -149,11 +149,11 @@ void GfxC3D::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
|
|||||||
Commands[index]->ScissorOn == ScissorEnabled &&
|
Commands[index]->ScissorOn == ScissorEnabled &&
|
||||||
Commands[index]->ScissorRect == ScissorRect) {
|
Commands[index]->ScissorRect == ScissorRect) {
|
||||||
auto c = Commands[index].get();
|
auto c = Commands[index].get();
|
||||||
for (size_t i = 0; i < c->IndexBuffer.Size(); i++) {
|
for (size_t i = 0; i < c->IndexBuffer.size(); i++) {
|
||||||
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i);
|
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.at(i);
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < c->VertexBuffer.Size(); i++) {
|
for (size_t i = 0; i < c->VertexBuffer.size(); i++) {
|
||||||
VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i);
|
VertexBuffer[CurrentVertex++] = c->VertexBuffer.at(i);
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ class GfxGL2 : public GfxDriver {
|
|||||||
PD::Li::Texture::Filter filter =
|
PD::Li::Texture::Filter filter =
|
||||||
PD::Li::Texture::Filter::LINEAR) override;
|
PD::Li::Texture::Filter::LINEAR) override;
|
||||||
|
|
||||||
PD::Vec<Li::Vertex> VertexBuffer;
|
std::vector<Li::Vertex> VertexBuffer;
|
||||||
PD::Vec<PD::u16> IndexBuffer;
|
std::vector<PD::u16> IndexBuffer;
|
||||||
GLuint Shader;
|
GLuint Shader;
|
||||||
GLuint pLocProjection;
|
GLuint pLocProjection;
|
||||||
GLuint pLocTex;
|
GLuint pLocTex;
|
||||||
|
|||||||
@@ -123,8 +123,8 @@ void SetupShaderAttribs(GLuint Shader) {
|
|||||||
/** Actual Backend */
|
/** Actual Backend */
|
||||||
|
|
||||||
void GfxGL2::Init() {
|
void GfxGL2::Init() {
|
||||||
VertexBuffer.Resize(4 * 8192);
|
VertexBuffer.resize(4 * 8192);
|
||||||
IndexBuffer.Resize(6 * 8192);
|
IndexBuffer.resize(6 * 8192);
|
||||||
Shader = createShaderProgram(vertex_shader, frag_shader);
|
Shader = createShaderProgram(vertex_shader, frag_shader);
|
||||||
glUseProgram(Shader);
|
glUseProgram(Shader);
|
||||||
|
|
||||||
@@ -190,11 +190,11 @@ void GfxGL2::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
|
|||||||
Commands[index]->ScissorOn == ScissorOn &&
|
Commands[index]->ScissorOn == ScissorOn &&
|
||||||
Commands[index]->ScissorRect == ScissorRect) {
|
Commands[index]->ScissorRect == ScissorRect) {
|
||||||
auto c = Commands[index].get();
|
auto c = Commands[index].get();
|
||||||
for (size_t i = 0; i < c->IndexBuffer.Size(); i++) {
|
for (size_t i = 0; i < c->IndexBuffer.size(); i++) {
|
||||||
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i);
|
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.at(i);
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < c->VertexBuffer.Size(); i++) {
|
for (size_t i = 0; i < c->VertexBuffer.size(); i++) {
|
||||||
VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i);
|
VertexBuffer[CurrentVertex++] = c->VertexBuffer.at(i);
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ SOFTWARE.
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <numbers>
|
#include <numbers>
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ SOFTWARE.
|
|||||||
#include <pd/core/fnv.hpp>
|
#include <pd/core/fnv.hpp>
|
||||||
#include <pd/core/io.hpp>
|
#include <pd/core/io.hpp>
|
||||||
#include <pd/core/mat.hpp>
|
#include <pd/core/mat.hpp>
|
||||||
#include <pd/core/sl/sl.hpp>
|
|
||||||
#include <pd/core/strings.hpp>
|
#include <pd/core/strings.hpp>
|
||||||
#include <pd/core/timer.hpp>
|
#include <pd/core/timer.hpp>
|
||||||
#include <pd/core/timetrace.hpp>
|
#include <pd/core/timetrace.hpp>
|
||||||
#include <pd/core/tween.hpp>
|
#include <pd/core/tween.hpp>
|
||||||
|
#include <pd/core/u128.hpp>
|
||||||
#include <pd/core/vec.hpp>
|
#include <pd/core/vec.hpp>
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 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>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
/**
|
|
||||||
* Custom Allocator for Custom Vec and probably other stuff in future
|
|
||||||
*/
|
|
||||||
template <typename T>
|
|
||||||
class Allocator {
|
|
||||||
public:
|
|
||||||
Allocator() = default;
|
|
||||||
~Allocator() = default;
|
|
||||||
|
|
||||||
virtual T* Allocate(size_t n) { return new T[n]; }
|
|
||||||
virtual T* AllocateRaw(size_t n) {
|
|
||||||
return reinterpret_cast<T*>(::operator new(sizeof(T) * n));
|
|
||||||
}
|
|
||||||
virtual void DeallocateRaw(T* ptr) { operator delete(ptr); }
|
|
||||||
virtual void Deallocate(T* ptr) { delete[] ptr; }
|
|
||||||
template <typename... Args>
|
|
||||||
void Construct(T* ptr, Args&&... args) {
|
|
||||||
new (ptr) T(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
void Destroy(T* ptr) { ptr->~T(); }
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 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/sl/list.hpp>
|
|
||||||
#include <pd/core/sl/pair.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
template <typename K, typename V, size_t bucket_count = 10>
|
|
||||||
class HashMap {
|
|
||||||
public:
|
|
||||||
HashMap() {}
|
|
||||||
~HashMap() {}
|
|
||||||
|
|
||||||
void Insert(const K& k, const V& v) {
|
|
||||||
size_t idx = Hash(k);
|
|
||||||
auto& bukket = pBuckets[idx];
|
|
||||||
for (auto& it : bukket) {
|
|
||||||
if (it.First == k) {
|
|
||||||
it.Second = v;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bukket.PushBack(Pair(k, v));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Contains(const K& k) const {
|
|
||||||
size_t idx = Hash(k);
|
|
||||||
auto& bukket = pBuckets[idx];
|
|
||||||
|
|
||||||
for (auto& it : bukket) {
|
|
||||||
if (it.First == k) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clear() {
|
|
||||||
for (size_t i = 0; i < bucket_count; i++) {
|
|
||||||
pBuckets[i].Clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Hash(const K& k) const { return std::hash<K>{}(k) % bucket_count; }
|
|
||||||
PD::List<PD::Pair<K, V>> pBuckets[bucket_count];
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,210 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 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>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
template <typename T>
|
|
||||||
class List {
|
|
||||||
public:
|
|
||||||
List() {}
|
|
||||||
~List() {}
|
|
||||||
|
|
||||||
struct Node {
|
|
||||||
Node(const T& v) : Data(v) {}
|
|
||||||
T Data;
|
|
||||||
Node* Prev = nullptr;
|
|
||||||
Node* Next = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Iterator {
|
|
||||||
public:
|
|
||||||
Iterator(Node* n) : pNode(n) {}
|
|
||||||
T& operator*() { return pNode->Data; }
|
|
||||||
Iterator& operator++() {
|
|
||||||
pNode = pNode->Next;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
bool operator!=(const Iterator& o) const { return pNode != o.pNode; }
|
|
||||||
|
|
||||||
Node* pNode = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
void PushFront(const T& val) {
|
|
||||||
Node* node = new Node(val);
|
|
||||||
// node->Data = val;
|
|
||||||
node->Prev = nullptr;
|
|
||||||
node->Next = pHead;
|
|
||||||
if (pHead) {
|
|
||||||
pHead->Prev = node;
|
|
||||||
}
|
|
||||||
pHead = node;
|
|
||||||
if (!pTail) {
|
|
||||||
pTail = node;
|
|
||||||
}
|
|
||||||
pSize++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PushBack(const T& val) {
|
|
||||||
Node* node = new Node(val);
|
|
||||||
// node->Data = val;
|
|
||||||
node->Prev = pTail;
|
|
||||||
node->Next = nullptr;
|
|
||||||
if (pTail) {
|
|
||||||
pTail->Next = node;
|
|
||||||
}
|
|
||||||
pTail = node;
|
|
||||||
if (!pHead) {
|
|
||||||
pHead = node;
|
|
||||||
}
|
|
||||||
pSize++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PopFront() {
|
|
||||||
if (!pHead) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Node* t = pHead;
|
|
||||||
pHead = pHead->Next;
|
|
||||||
if (pHead) {
|
|
||||||
pHead->Prev = nullptr;
|
|
||||||
} else {
|
|
||||||
pTail = nullptr;
|
|
||||||
}
|
|
||||||
delete t;
|
|
||||||
pSize--;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PopBack() {
|
|
||||||
if (!pTail) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Node* t = pTail;
|
|
||||||
pTail = pTail->Prev;
|
|
||||||
if (pTail) {
|
|
||||||
pTail->Next = nullptr;
|
|
||||||
} else {
|
|
||||||
pHead = nullptr;
|
|
||||||
}
|
|
||||||
delete t;
|
|
||||||
pSize--;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clear() {
|
|
||||||
while (pHead) {
|
|
||||||
PopFront();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Remove(const T& v) {
|
|
||||||
Node* s = pHead;
|
|
||||||
while (s) {
|
|
||||||
if (s->Data == v) {
|
|
||||||
if (s->Prev) {
|
|
||||||
s->Prev->Next = s->Next;
|
|
||||||
} else {
|
|
||||||
pHead = s->Next;
|
|
||||||
}
|
|
||||||
if (s->Next) {
|
|
||||||
s->Next->Prev = s->Prev;
|
|
||||||
} else {
|
|
||||||
pTail = s->Prev;
|
|
||||||
}
|
|
||||||
delete s;
|
|
||||||
pSize--;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
s = s->Next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Reverse() {
|
|
||||||
Node* cur = pHead;
|
|
||||||
while (cur) {
|
|
||||||
Node* temp = cur->Prev;
|
|
||||||
cur->Prev = cur->Next;
|
|
||||||
cur->Next = temp;
|
|
||||||
cur = cur->Prev;
|
|
||||||
}
|
|
||||||
Node* temp = pHead;
|
|
||||||
pHead = pTail;
|
|
||||||
pTail = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
T& Front() {
|
|
||||||
if (pHead) {
|
|
||||||
return pHead->Data;
|
|
||||||
}
|
|
||||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& Front() const {
|
|
||||||
if (pHead) {
|
|
||||||
return pHead->Data;
|
|
||||||
}
|
|
||||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
T& Back() {
|
|
||||||
if (pTail) {
|
|
||||||
return pTail->Data;
|
|
||||||
}
|
|
||||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& Back() const {
|
|
||||||
if (pTail) {
|
|
||||||
return pTail->Data;
|
|
||||||
}
|
|
||||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Size() const { return pSize; }
|
|
||||||
|
|
||||||
Iterator begin() { return Iterator(pHead); }
|
|
||||||
Iterator end() { return Iterator(nullptr); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Node* Find(const T& v) const {
|
|
||||||
Node* t = pHead;
|
|
||||||
while (t) {
|
|
||||||
if (t->Data == v) {
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
t = t->Next;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Node* pHead = nullptr;
|
|
||||||
Node* pTail = nullptr;
|
|
||||||
size_t pSize = 0;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 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>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
template <typename T1, typename T2>
|
|
||||||
class Pair {
|
|
||||||
public:
|
|
||||||
Pair() = default;
|
|
||||||
Pair(const T1& f, const T2& s) : First(f), Second(s) {}
|
|
||||||
Pair(T1&& f, T2&& s) : First(std::move(f)), Second(std::move(s)) {}
|
|
||||||
~Pair() = default;
|
|
||||||
|
|
||||||
T1 First;
|
|
||||||
T2 Second;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 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/sl/allocator.hpp>
|
|
||||||
#include <pd/core/sl/hashmap.hpp>
|
|
||||||
#include <pd/core/sl/list.hpp>
|
|
||||||
#include <pd/core/sl/pair.hpp>
|
|
||||||
#include <pd/core/sl/stack.hpp>
|
|
||||||
#include <pd/core/sl/tools.hpp>
|
|
||||||
#include <pd/core/sl/u128.hpp>
|
|
||||||
#include <pd/core/sl/vector.hpp>
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 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/sl/vector.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
/**
|
|
||||||
* Custom Stack class (caus std::stack ofsten lead to memory coruption)
|
|
||||||
*/
|
|
||||||
template <typename T, typename Alloc = Allocator<T>>
|
|
||||||
class Stack {
|
|
||||||
public:
|
|
||||||
Stack() = default;
|
|
||||||
explicit Stack(size_t cap) : pVec(cap) {}
|
|
||||||
|
|
||||||
void Push(const T& val) { pVec.Add(val); }
|
|
||||||
|
|
||||||
void Pop() {
|
|
||||||
if (pVec.Size() == 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
pVec.PopBack();
|
|
||||||
}
|
|
||||||
|
|
||||||
T& Top() {
|
|
||||||
if (pVec.Size() == 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return pVec[pVec.Size() - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& Top() const {
|
|
||||||
if (pVec.Size() == 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return pVec[pVec.Size() - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsEmpty() const { return pVec.Size() == 0; }
|
|
||||||
size_t Size() const { return pVec.Size(); }
|
|
||||||
void Clear() { pVec.Clear(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Vec<T, Alloc> pVec;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 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>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
/**
|
|
||||||
* Function to get Arraysize for any type using modern c++ to
|
|
||||||
* get the size at compiletime instead of runtime
|
|
||||||
* @note this function only works for Arrays declared as
|
|
||||||
* type arr[size] and not for pointer references.
|
|
||||||
* This function will precalculate the size at compile time
|
|
||||||
* while keeping the code clean to not hardcode arraysizes
|
|
||||||
* into functions like std::fill_n
|
|
||||||
*/
|
|
||||||
template <typename T, size_t N>
|
|
||||||
constexpr size_t ArraySize(T (&)[N]) noexcept {
|
|
||||||
return N;
|
|
||||||
}
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
#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/sl/allocator.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
/**
|
|
||||||
* Open Access Vector class (Alternative to std::vector)
|
|
||||||
*/
|
|
||||||
template <typename T, typename Alloc = Allocator<T>>
|
|
||||||
class Vec {
|
|
||||||
public:
|
|
||||||
Vec() {
|
|
||||||
pData = pAllocator.Allocate(2);
|
|
||||||
pCap = 2;
|
|
||||||
Clear();
|
|
||||||
pPos = 0;
|
|
||||||
};
|
|
||||||
Vec(const size_t& Size) {
|
|
||||||
pData = pAllocator.Allocate(Size + 2);
|
|
||||||
pCap = Size + 2;
|
|
||||||
Clear();
|
|
||||||
pPos = Size;
|
|
||||||
}
|
|
||||||
Vec(const size_t& Size, const T& v) {
|
|
||||||
pData = pAllocator.Allocate(Size + 2);
|
|
||||||
pCap = Size + 2;
|
|
||||||
Clear();
|
|
||||||
pPos = Size;
|
|
||||||
std::fill_n(pData, Size, v);
|
|
||||||
}
|
|
||||||
Vec(const T* s, const T* e) {
|
|
||||||
pData = pAllocator.Allocate(2);
|
|
||||||
pCap = 2;
|
|
||||||
Clear();
|
|
||||||
pPos = 0;
|
|
||||||
Resize(e - s);
|
|
||||||
std::copy_n(s, e - s, pData);
|
|
||||||
}
|
|
||||||
Vec(const Vec& v) {
|
|
||||||
pCap = v.pCap;
|
|
||||||
pPos = v.pPos;
|
|
||||||
pData = pAllocator.Allocate(pCap);
|
|
||||||
for (size_t i = 0; i < pPos; i++) {
|
|
||||||
pData[i] = v.pData[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
~Vec() { pAllocator.Deallocate(pData); }
|
|
||||||
|
|
||||||
void Add(const T& v) {
|
|
||||||
if (pPos >= pCap) {
|
|
||||||
Reserve(pCap * 2);
|
|
||||||
}
|
|
||||||
pData[pPos++] = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PopBack() {
|
|
||||||
if (pPos == 0) return;
|
|
||||||
pPos--;
|
|
||||||
}
|
|
||||||
|
|
||||||
T Pop() {
|
|
||||||
if (pPos == 0) {
|
|
||||||
// Todo: LOG
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return pData[pPos--];
|
|
||||||
}
|
|
||||||
|
|
||||||
T& At(const size_t& Idx) {
|
|
||||||
if (Idx >= pPos) {
|
|
||||||
// Log
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return pData[Idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& At(const size_t& Idx) const {
|
|
||||||
if (Idx >= pPos) {
|
|
||||||
// Log
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return pData[Idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
T& operator[](const size_t& Idx) { return At(Idx); }
|
|
||||||
const T& operator[](const size_t& Idx) const { return At(Idx); }
|
|
||||||
void operator+=(T v) { Add(v); }
|
|
||||||
|
|
||||||
T* Begin() { return pData; }
|
|
||||||
const T* Begin() const { return pData; }
|
|
||||||
T* End() { return pData + pPos; }
|
|
||||||
const T* End() const { return pData + pPos; }
|
|
||||||
|
|
||||||
// Support: `for(auto& it : Vec)` //
|
|
||||||
T* begin() { return pData; }
|
|
||||||
const T* begin() const { return pData; }
|
|
||||||
T* end() { return pData + pPos; }
|
|
||||||
const T* end() const { return pData + pPos; }
|
|
||||||
|
|
||||||
T* Data() { return pData; }
|
|
||||||
T* Data() const { return pData; }
|
|
||||||
size_t Size() const { return pPos; }
|
|
||||||
size_t Capacity() const { return pCap; }
|
|
||||||
void Clear() {
|
|
||||||
// Avoid memset to support std::string for now
|
|
||||||
// probably revert this decision based if it lacks performance
|
|
||||||
// or make it a setting
|
|
||||||
std::fill(pData, pData + pCap, T());
|
|
||||||
pPos = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Reserve(const size_t& Size) {
|
|
||||||
if (Size <= pCap) return;
|
|
||||||
T* tmp = pAllocator.Allocate(Size);
|
|
||||||
std::fill(tmp, tmp + Size, T());
|
|
||||||
std::copy(pData, pData + pCap, tmp);
|
|
||||||
pAllocator.Deallocate(pData);
|
|
||||||
pData = tmp;
|
|
||||||
pCap = Size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Resize(size_t Size) {
|
|
||||||
if (Size < pPos) {
|
|
||||||
pPos = Size;
|
|
||||||
} else if (Size > pCap) {
|
|
||||||
Reserve(Size);
|
|
||||||
}
|
|
||||||
std::fill(pData + pPos, pData + Size, T());
|
|
||||||
pPos = Size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocator
|
|
||||||
Alloc pAllocator;
|
|
||||||
// Data Reference Pointer
|
|
||||||
T* pData;
|
|
||||||
// Capacity
|
|
||||||
size_t pCap;
|
|
||||||
// Current Position (Size)
|
|
||||||
size_t pPos;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -55,28 +55,5 @@ void RGB32toRGBA24(std::vector<u8> &out, const std::vector<u8> &in,
|
|||||||
*/
|
*/
|
||||||
PD_IMAGE_API void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
|
PD_IMAGE_API void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
|
||||||
PD_IMAGE_API void ReverseBuf(std::vector<u8> &buf, size_t bpp, int w, int h);
|
PD_IMAGE_API void ReverseBuf(std::vector<u8> &buf, size_t bpp, int w, int h);
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
|
|
||||||
* to every pixel
|
|
||||||
* @param out Result List
|
|
||||||
* @param in Input Buffer List (rgb24)
|
|
||||||
* @param w width of the image
|
|
||||||
* @param h height of the image
|
|
||||||
*/
|
|
||||||
PD_IMAGE_API
|
|
||||||
void RGB24toRGBA32(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w,
|
|
||||||
const int &h);
|
|
||||||
PD_IMAGE_API
|
|
||||||
void RGB32toRGBA24(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w,
|
|
||||||
const int &h);
|
|
||||||
/**
|
|
||||||
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
|
|
||||||
* @param buf Buffer to convert
|
|
||||||
* @param w width
|
|
||||||
* @param h height
|
|
||||||
*/
|
|
||||||
PD_IMAGE_API void Reverse32(PD::Vec<u8> &buf, const int &w, const int &h);
|
|
||||||
PD_IMAGE_API void ReverseBuf(PD::Vec<u8> &buf, size_t bpp, int w, int h);
|
|
||||||
} // namespace ImgConvert
|
} // namespace ImgConvert
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -37,17 +37,17 @@ class Command {
|
|||||||
PD_UNIQUE(Command);
|
PD_UNIQUE(Command);
|
||||||
|
|
||||||
Command& AddIdx(const u16& idx) {
|
Command& AddIdx(const u16& idx) {
|
||||||
IndexBuffer.Add(VertexBuffer.Size() + idx);
|
IndexBuffer.push_back(VertexBuffer.size() + idx);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command& AddVtx(const Vertex& v) {
|
Command& AddVtx(const Vertex& v) {
|
||||||
VertexBuffer.Add(std::move(v));
|
VertexBuffer.push_back(std::move(v));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PD::Vec<Vertex> VertexBuffer;
|
std::vector<Vertex> VertexBuffer;
|
||||||
PD::Vec<u16> IndexBuffer;
|
std::vector<u16> IndexBuffer;
|
||||||
ivec4 ScissorRect;
|
ivec4 ScissorRect;
|
||||||
bool ScissorOn = false;
|
bool ScissorOn = false;
|
||||||
int Layer;
|
int Layer;
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class PD_LITHIUM_API DrawList {
|
|||||||
* @param flags Additional Flags (Close for go back to starting point)
|
* @param flags Additional Flags (Close for go back to starting point)
|
||||||
* @param thickness Thickness of the Line
|
* @param thickness Thickness of the Line
|
||||||
*/
|
*/
|
||||||
void DrawPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0,
|
void DrawPolyLine(const std::vector<fvec2>& points, u32 clr, u32 flags = 0,
|
||||||
int thickness = 1);
|
int thickness = 1);
|
||||||
/**
|
/**
|
||||||
* Take a List ofpoints and display it as Filled Shape
|
* Take a List ofpoints and display it as Filled Shape
|
||||||
@@ -114,7 +114,7 @@ class PD_LITHIUM_API DrawList {
|
|||||||
* @param points List of Points
|
* @param points List of Points
|
||||||
* @param clr Color of the shape
|
* @param clr Color of the shape
|
||||||
*/
|
*/
|
||||||
void DrawConvexPolyFilled(const Vec<fvec2>& points, u32 clr);
|
void DrawConvexPolyFilled(const std::vector<fvec2>& points, u32 clr);
|
||||||
|
|
||||||
// SECTION: PATH API //
|
// SECTION: PATH API //
|
||||||
|
|
||||||
@@ -124,20 +124,20 @@ class PD_LITHIUM_API DrawList {
|
|||||||
* @param num_points Number of Positions you want to add
|
* @param num_points Number of Positions you want to add
|
||||||
*/
|
*/
|
||||||
void PathReserve(size_t num_points) {
|
void PathReserve(size_t num_points) {
|
||||||
pPath.Reserve(pPath.Size() + num_points);
|
pPath.reserve(pPath.size() + num_points);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Clear current Path
|
* Clear current Path
|
||||||
* @note PathStroke and PathFill will automatically clear
|
* @note PathStroke and PathFill will automatically clear
|
||||||
*/
|
*/
|
||||||
void PathClear() { pPath.Clear(); }
|
void PathClear() { pPath.clear(); }
|
||||||
/**
|
/**
|
||||||
* Add a Point to the Path
|
* Add a Point to the Path
|
||||||
* @note Keep in mind that this function is used for
|
* @note Keep in mind that this function is used for
|
||||||
* setting the starting point
|
* setting the starting point
|
||||||
* @param v Position to add
|
* @param v Position to add
|
||||||
*/
|
*/
|
||||||
void PathAdd(const fvec2& v) { pPath.Add(v); }
|
void PathAdd(const fvec2& v) { pPath.push_back(v); }
|
||||||
/**
|
/**
|
||||||
* Add a Point to the Path
|
* Add a Point to the Path
|
||||||
* @note Keep in mind that this function is used for
|
* @note Keep in mind that this function is used for
|
||||||
@@ -145,7 +145,7 @@ class PD_LITHIUM_API DrawList {
|
|||||||
* @param x X Position to add
|
* @param x X Position to add
|
||||||
* @param y Y Position to add
|
* @param y Y Position to add
|
||||||
*/
|
*/
|
||||||
void PathAdd(float x, float y) { pPath.Add(fvec2(x, y)); }
|
void PathAdd(float x, float y) { pPath.push_back(fvec2(x, y)); }
|
||||||
/**
|
/**
|
||||||
* Path Stroke Create Line from point to point
|
* Path Stroke Create Line from point to point
|
||||||
* @note For Primitives like Rect or Triangle mak sure to use
|
* @note For Primitives like Rect or Triangle mak sure to use
|
||||||
@@ -156,7 +156,7 @@ class PD_LITHIUM_API DrawList {
|
|||||||
*/
|
*/
|
||||||
void PathStroke(u32 clr, int thickness = 1, u32 flags = 0) {
|
void PathStroke(u32 clr, int thickness = 1, u32 flags = 0) {
|
||||||
DrawPolyLine(pPath, clr, flags, thickness);
|
DrawPolyLine(pPath, clr, flags, thickness);
|
||||||
pPath.Clear();
|
pPath.clear();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Fill a Path with a Color
|
* Fill a Path with a Color
|
||||||
@@ -166,7 +166,7 @@ class PD_LITHIUM_API DrawList {
|
|||||||
*/
|
*/
|
||||||
void PathFill(u32 clr) {
|
void PathFill(u32 clr) {
|
||||||
DrawConvexPolyFilled(pPath, clr);
|
DrawConvexPolyFilled(pPath, clr);
|
||||||
pPath.Clear();
|
pPath.clear();
|
||||||
}
|
}
|
||||||
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
|
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
|
||||||
int segments);
|
int segments);
|
||||||
@@ -183,25 +183,25 @@ class PD_LITHIUM_API DrawList {
|
|||||||
/// @param flags DrawFlags (for special rounding rules)
|
/// @param flags DrawFlags (for special rounding rules)
|
||||||
void PathRectEx(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0);
|
void PathRectEx(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0);
|
||||||
|
|
||||||
void PushClipRect(const fvec4& cr) { pClipRects.Push(cr); }
|
void PushClipRect(const fvec4& cr) { pClipRects.push(cr); }
|
||||||
void PopClipRect() {
|
void PopClipRect() {
|
||||||
if (pClipRects.IsEmpty()) {
|
if (pClipRects.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pClipRects.Pop();
|
pClipRects.pop();
|
||||||
}
|
}
|
||||||
/** One linear Clip rect Setup */
|
/** One linear Clip rect Setup */
|
||||||
void pClipCmd(Command* cmd);
|
void pClipCmd(Command* cmd);
|
||||||
|
|
||||||
/** Data Section */
|
/** Data Section */
|
||||||
|
|
||||||
Stack<fvec4> pClipRects;
|
std::stack<fvec4> pClipRects;
|
||||||
int Layer;
|
int Layer;
|
||||||
float pFontScale = 0.7f;
|
float pFontScale = 0.7f;
|
||||||
Font::Ref pCurrentFont;
|
Font::Ref pCurrentFont;
|
||||||
Texture::Ref CurrentTex;
|
Texture::Ref CurrentTex;
|
||||||
std::vector<Command::Ref> pDrawList;
|
std::vector<Command::Ref> pDrawList;
|
||||||
PD::Vec<fvec2> pPath;
|
std::vector<fvec2> pPath;
|
||||||
u32 pNumIndices = 0;
|
u32 pNumIndices = 0;
|
||||||
u32 pNumVertices = 0;
|
u32 pNumVertices = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -46,10 +46,11 @@ class PD_LITHIUM_API Renderer {
|
|||||||
u32 color);
|
u32 color);
|
||||||
static void CmdTriangle(Command* cmd, const fvec2 a, const fvec2 b,
|
static void CmdTriangle(Command* cmd, const fvec2 a, const fvec2 b,
|
||||||
const fvec2 c, u32 clr);
|
const fvec2 c, u32 clr);
|
||||||
static void CmdPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0,
|
static void CmdPolyLine(const std::vector<fvec2>& points, u32 clr,
|
||||||
int thickness = 1);
|
u32 flags = 0, int thickness = 1);
|
||||||
static void CmdConvexPolyFilled(Command* cmd, const Vec<fvec2>& points,
|
static void CmdConvexPolyFilled(Command* cmd,
|
||||||
u32 clr, Texture::Ref tex);
|
const std::vector<fvec2>& points, u32 clr,
|
||||||
|
Texture::Ref tex);
|
||||||
|
|
||||||
// SECTION: InBounds Checks
|
// SECTION: InBounds Checks
|
||||||
|
|
||||||
|
|||||||
@@ -79,19 +79,18 @@ class PD_UI7_API IO {
|
|||||||
bool ShowFrameBorder = false; // not implemented yet
|
bool ShowFrameBorder = false; // not implemented yet
|
||||||
float OverScrollMod = 0.15f;
|
float OverScrollMod = 0.15f;
|
||||||
u64 DoubleClickTime = 500; // Milliseconds
|
u64 DoubleClickTime = 500; // Milliseconds
|
||||||
PD::List<Pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry;
|
std::list<std::pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry;
|
||||||
// Short define for DrawKistRegestryLast
|
// Short define for DrawKistRegestryLast
|
||||||
PD::List<Pair<UI7::ID, Li::DrawList::Ref>> pDLRL;
|
std::list<std::pair<UI7::ID, Li::DrawList::Ref>> pDLRL;
|
||||||
// std::vector<std::pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry;
|
|
||||||
Li::DrawList::Ref Back;
|
Li::DrawList::Ref Back;
|
||||||
Li::DrawList::Ref Front;
|
Li::DrawList::Ref Front;
|
||||||
u32 NumVertices = 0; ///< Debug Vertices Num
|
u32 NumVertices = 0; ///< Debug Vertices Num
|
||||||
u32 NumIndices = 0; ///< Debug Indices Num
|
u32 NumIndices = 0; ///< Debug Indices Num
|
||||||
Vec<u32> MenuOrder;
|
std::vector<u32> MenuOrder;
|
||||||
|
|
||||||
// DrawListApi
|
// DrawListApi
|
||||||
void RegisterDrawList(const UI7::ID& id, Li::DrawList::Ref v) {
|
void RegisterDrawList(const UI7::ID& id, Li::DrawList::Ref v) {
|
||||||
DrawListRegestry.PushBack(Pair(id, v));
|
DrawListRegestry.push_back(std::make_pair(id, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddViewPort(const ID& id, const ivec4& size) {
|
void AddViewPort(const ID& id, const ivec4& size) {
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ class PD_UI7_API Layout {
|
|||||||
bool Scrolling[2];
|
bool Scrolling[2];
|
||||||
|
|
||||||
// Objects
|
// Objects
|
||||||
PD::List<Container::Ref> Objects;
|
std::list<Container::Ref> Objects;
|
||||||
std::vector<Container::Ref> IDObjects;
|
std::vector<Container::Ref> IDObjects;
|
||||||
};
|
};
|
||||||
} // namespace UI7
|
} // namespace UI7
|
||||||
|
|||||||
@@ -79,59 +79,4 @@ PD_IMAGE_API void ReverseBuf(std::vector<u8> &buf, size_t bpp, int w, int h) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_IMAGE_API void RGB24toRGBA32(PD::Vec<u8> &out, const PD::Vec<u8> &in,
|
|
||||||
const int &w, const int &h) {
|
|
||||||
// Converts RGB24 to RGBA32
|
|
||||||
for (int y = 0; y < h; y++) {
|
|
||||||
for (int x = 0; x < w; x++) {
|
|
||||||
int src = (y * w + x) * 3;
|
|
||||||
int dst = (y * w + x) * 4;
|
|
||||||
out[dst + 0] = in[src + 0];
|
|
||||||
out[dst + 1] = in[src + 1];
|
|
||||||
out[dst + 2] = in[src + 2];
|
|
||||||
out[dst + 3] = 255;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PD_IMAGE_API void RGB32toRGBA24(PD::Vec<u8> &out, const PD::Vec<u8> &in,
|
|
||||||
const int &w, const int &h) {
|
|
||||||
// Converts RGB24 to RGBA32
|
|
||||||
for (int y = 0; y < h; y++) {
|
|
||||||
for (int x = 0; x < w; x++) {
|
|
||||||
int src = (y * w + x) * 4;
|
|
||||||
int dst = (y * w + x) * 3;
|
|
||||||
out[dst + 0] = in[src + 0];
|
|
||||||
out[dst + 1] = in[src + 1];
|
|
||||||
out[dst + 2] = in[src + 2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PD_IMAGE_API void Reverse32(PD::Vec<u8> &buf, const int &w, const int &h) {
|
|
||||||
for (int x = 0; x < w; x++) {
|
|
||||||
for (int y = 0; y < h; y++) {
|
|
||||||
int i = y * w + x;
|
|
||||||
u8 t0 = buf[i + 0];
|
|
||||||
u8 t1 = buf[i + 1];
|
|
||||||
buf[i + 0] = buf[i + 3];
|
|
||||||
buf[i + 1] = buf[i + 2];
|
|
||||||
buf[i + 3] = t0;
|
|
||||||
buf[i + 2] = t1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PD_IMAGE_API void ReverseBuf(PD::Vec<u8> &buf, size_t bpp, int w, int h) {
|
|
||||||
PD::Vec<u8> cpy = buf;
|
|
||||||
for (int x = 0; x < w; x++) {
|
|
||||||
for (int y = 0; y < h; y++) {
|
|
||||||
int pos = (y * w + x) * bpp;
|
|
||||||
for (size_t i = 0; i < bpp; i++) {
|
|
||||||
buf[pos + bpp - 1 - i] = cpy[pos + i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace PD::ImgConvert
|
} // namespace PD::ImgConvert
|
||||||
@@ -37,20 +37,22 @@ PD_LITHIUM_API void DrawList::Clear() {
|
|||||||
pNumIndices = 0;
|
pNumIndices = 0;
|
||||||
pNumVertices = 0;
|
pNumVertices = 0;
|
||||||
pDrawList.clear();
|
pDrawList.clear();
|
||||||
pPath.Clear();
|
pPath.clear();
|
||||||
pClipRects.Clear();
|
while (!pClipRects.empty()) {
|
||||||
|
pClipRects.pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_LITHIUM_API void DrawList::AddCommand(Command::Ref v) {
|
PD_LITHIUM_API void DrawList::AddCommand(Command::Ref v) {
|
||||||
pNumIndices += v->IndexBuffer.Size();
|
pNumIndices += v->IndexBuffer.size();
|
||||||
pNumVertices += v->VertexBuffer.Size();
|
pNumVertices += v->VertexBuffer.size();
|
||||||
pDrawList.push_back(std::move(v));
|
pDrawList.push_back(std::move(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_LITHIUM_API void DrawList::Merge(DrawList::Ref list) {
|
PD_LITHIUM_API void DrawList::Merge(DrawList::Ref list) {
|
||||||
for (size_t i = 0; i < list->pDrawList.size(); i++) {
|
for (size_t i = 0; i < list->pDrawList.size(); i++) {
|
||||||
pNumIndices += list->pDrawList[i]->IndexBuffer.Size();
|
pNumIndices += list->pDrawList[i]->IndexBuffer.size();
|
||||||
pNumVertices += list->pDrawList[i]->VertexBuffer.Size();
|
pNumVertices += list->pDrawList[i]->VertexBuffer.size();
|
||||||
pDrawList.push_back(std::move(list->pDrawList[i]));
|
pDrawList.push_back(std::move(list->pDrawList[i]));
|
||||||
}
|
}
|
||||||
/** Make sure The list gets cleared */
|
/** Make sure The list gets cleared */
|
||||||
@@ -67,9 +69,9 @@ PD_LITHIUM_API Command::Ref DrawList::PreGenerateCmd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PD_LITHIUM_API void DrawList::pClipCmd(Command *cmd) {
|
PD_LITHIUM_API void DrawList::pClipCmd(Command *cmd) {
|
||||||
if (!pClipRects.IsEmpty()) {
|
if (!pClipRects.empty()) {
|
||||||
cmd->ScissorOn = true;
|
cmd->ScissorOn = true;
|
||||||
cmd->ScissorRect = ivec4(pClipRects.Top());
|
cmd->ScissorRect = ivec4(pClipRects.top());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,21 +235,21 @@ PD_LITHIUM_API void DrawList::DrawCircleFilled(const fvec2 ¢er, float rad,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Don't render OOS
|
// TODO: Don't render OOS
|
||||||
PD_LITHIUM_API void DrawList::DrawPolyLine(const Vec<fvec2> &points, u32 clr,
|
PD_LITHIUM_API void DrawList::DrawPolyLine(const std::vector<fvec2> &points,
|
||||||
u32 flags, int thickness) {
|
u32 clr, u32 flags, int thickness) {
|
||||||
if (points.Size() < 2) {
|
if (points.size() < 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DrawSolid();
|
DrawSolid();
|
||||||
auto cmd = PreGenerateCmd();
|
auto cmd = PreGenerateCmd();
|
||||||
bool close = (flags & (1 << 0));
|
bool close = (flags & (1 << 0));
|
||||||
int num_points = close ? (int)points.Size() : (int)points.Size() - 1;
|
int num_points = close ? (int)points.size() : (int)points.size() - 1;
|
||||||
if (flags & (1 << 1)) {
|
if (flags & (1 << 1)) {
|
||||||
// TODO: Find a way to draw less garbage looking lines
|
// TODO: Find a way to draw less garbage looking lines
|
||||||
} else {
|
} else {
|
||||||
// Non antialiased lines look awful when rendering with thickness != 1
|
// Non antialiased lines look awful when rendering with thickness != 1
|
||||||
for (int i = 0; i < num_points; i++) {
|
for (int i = 0; i < num_points; i++) {
|
||||||
int j = (i + 1) == (int)points.Size() ? 0 : (i + 1);
|
int j = (i + 1) == (int)points.size() ? 0 : (i + 1);
|
||||||
auto line = Renderer::PrimLine(points[i], points[j], thickness);
|
auto line = Renderer::PrimLine(points[i], points[j], thickness);
|
||||||
Renderer::CmdQuad(cmd.get(), line, vec4(0.f, 1.f, 1.f, 0.f), clr);
|
Renderer::CmdQuad(cmd.get(), line, vec4(0.f, 1.f, 1.f, 0.f), clr);
|
||||||
}
|
}
|
||||||
@@ -255,9 +257,9 @@ PD_LITHIUM_API void DrawList::DrawPolyLine(const Vec<fvec2> &points, u32 clr,
|
|||||||
AddCommand(std::move(cmd));
|
AddCommand(std::move(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_LITHIUM_API void DrawList::DrawConvexPolyFilled(const Vec<fvec2> &points,
|
PD_LITHIUM_API void DrawList::DrawConvexPolyFilled(
|
||||||
u32 clr) {
|
const std::vector<fvec2> &points, u32 clr) {
|
||||||
if (points.Size() < 3) {
|
if (points.size() < 3) {
|
||||||
return; // Need at least three points
|
return; // Need at least three points
|
||||||
}
|
}
|
||||||
auto cmd = PreGenerateCmd();
|
auto cmd = PreGenerateCmd();
|
||||||
|
|||||||
@@ -110,10 +110,9 @@ PD_LITHIUM_API void Renderer::CmdTriangle(Command* cmd, const fvec2 a,
|
|||||||
// TODO: Don't render OOS (Probably make it with a define as it
|
// TODO: Don't render OOS (Probably make it with a define as it
|
||||||
// would probably be faster to render out of screen than checking if
|
// would probably be faster to render out of screen than checking if
|
||||||
// it could be skipped)
|
// it could be skipped)
|
||||||
PD_LITHIUM_API void Renderer::CmdConvexPolyFilled(Command* cmd,
|
PD_LITHIUM_API void Renderer::CmdConvexPolyFilled(
|
||||||
const Vec<fvec2>& points,
|
Command* cmd, const std::vector<fvec2>& points, u32 clr, Texture::Ref tex) {
|
||||||
u32 clr, Texture::Ref tex) {
|
if (points.size() < 3 || tex == nullptr) {
|
||||||
if (points.Size() < 3 || tex == nullptr) {
|
|
||||||
return; // Need at least three points
|
return; // Need at least three points
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,11 +120,11 @@ PD_LITHIUM_API void Renderer::CmdConvexPolyFilled(Command* cmd,
|
|||||||
float minX = points[0].x, minY = points[0].y;
|
float minX = points[0].x, minY = points[0].y;
|
||||||
float maxX = minX, maxY = minY;
|
float maxX = minX, maxY = minY;
|
||||||
// Check for the max and min Positions
|
// Check for the max and min Positions
|
||||||
for (auto it = points.Begin(); it != points.End(); it++) {
|
for (const auto& it : points) {
|
||||||
if ((*it).x < minX) minX = (*it).x;
|
if (it.x < minX) minX = it.x;
|
||||||
if ((*it).y < minY) minY = (*it).y;
|
if (it.y < minY) minY = it.y;
|
||||||
if ((*it).x > maxX) maxX = (*it).x;
|
if (it.x > maxX) maxX = it.x;
|
||||||
if ((*it).y > maxY) maxY = (*it).y;
|
if (it.y > maxY) maxY = it.y;
|
||||||
}
|
}
|
||||||
// Get Short defines for UV
|
// Get Short defines for UV
|
||||||
// (Bottom Right is not required)
|
// (Bottom Right is not required)
|
||||||
@@ -134,10 +133,10 @@ PD_LITHIUM_API void Renderer::CmdConvexPolyFilled(Command* cmd,
|
|||||||
auto uv_bl = tex->UV.BotLeft();
|
auto uv_bl = tex->UV.BotLeft();
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
for (int i = 2; i < (int)points.Size(); i++) {
|
for (int i = 2; i < (int)points.size(); i++) {
|
||||||
cmd->AddIdx(0).AddIdx(i).AddIdx(i - 1);
|
cmd->AddIdx(0).AddIdx(i).AddIdx(i - 1);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < (int)points.Size(); i++) {
|
for (int i = 0; i < (int)points.size(); i++) {
|
||||||
// Calculate U and V coords
|
// Calculate U and V coords
|
||||||
float u =
|
float u =
|
||||||
uv_tl.x + ((points[i].x - minX) / (maxX - minX)) * (uv_tr.x - uv_tl.x);
|
uv_tl.x + ((points[i].x - minX) / (maxX - minX)) * (uv_tr.x - uv_tl.x);
|
||||||
|
|||||||
@@ -34,9 +34,8 @@ PD_UI7_API void UI7::IO::Update() {
|
|||||||
Time->Update();
|
Time->Update();
|
||||||
InputHandler->Update();
|
InputHandler->Update();
|
||||||
Framerate = 1000.f / Delta;
|
Framerate = 1000.f / Delta;
|
||||||
DrawListRegestry.Clear();
|
DrawListRegestry.clear();
|
||||||
DrawListRegestry.PushFront(
|
DrawListRegestry.push_front(std::make_pair("CtxBackList", Back));
|
||||||
Pair<UI7::ID, Li::DrawList::Ref>("CtxBackList", Back));
|
|
||||||
// RegisterDrawList("CtxBackList", Back);
|
// RegisterDrawList("CtxBackList", Back);
|
||||||
NumIndices = FDL->pNumIndices;
|
NumIndices = FDL->pNumIndices;
|
||||||
NumVertices = FDL->pNumVertices;
|
NumVertices = FDL->pNumVertices;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ PD_UI7_API void Layout::AddObject(Container::Ref obj) {
|
|||||||
obj->Update();
|
obj->Update();
|
||||||
CursorMove(obj->GetSize());
|
CursorMove(obj->GetSize());
|
||||||
obj->HandleScrolling(ScrollOffset, WorkRect);
|
obj->HandleScrolling(ScrollOffset, WorkRect);
|
||||||
Objects.PushBack(obj);
|
Objects.push_back(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_UI7_API void Layout::AddObjectEx(Container::Ref obj, u32 flags) {
|
PD_UI7_API void Layout::AddObjectEx(Container::Ref obj, u32 flags) {
|
||||||
@@ -83,9 +83,9 @@ PD_UI7_API void Layout::AddObjectEx(Container::Ref obj, u32 flags) {
|
|||||||
obj->HandleScrolling(ScrollOffset, WorkRect);
|
obj->HandleScrolling(ScrollOffset, WorkRect);
|
||||||
}
|
}
|
||||||
if (flags & UI7LytAdd_Front) {
|
if (flags & UI7LytAdd_Front) {
|
||||||
Objects.PushFront(obj);
|
Objects.push_front(obj);
|
||||||
} else {
|
} else {
|
||||||
Objects.PushBack(obj);
|
Objects.push_back(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ PD_UI7_API void Layout::Update() {
|
|||||||
for (auto& it : tbr) {
|
for (auto& it : tbr) {
|
||||||
IDObjects.erase(IDObjects.begin() + it);
|
IDObjects.erase(IDObjects.begin() + it);
|
||||||
}
|
}
|
||||||
Objects.Clear();
|
Objects.clear();
|
||||||
WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO->MenuPadding);
|
WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO->MenuPadding);
|
||||||
CursorInit();
|
CursorInit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ PD_UI7_API void Menu::Label(const std::string& label) {
|
|||||||
PD_UI7_API bool Menu::Button(const std::string& label) {
|
PD_UI7_API bool Menu::Button(const std::string& label) {
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
u32 id = Strings::FastHash("btn" + label +
|
u32 id = Strings::FastHash("btn" + label +
|
||||||
std::to_string(pLayout->Objects.Size()));
|
std::to_string(pLayout->Objects.size()));
|
||||||
Container::Ref r = pLayout->FindObject(id);
|
Container::Ref r = pLayout->FindObject(id);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
r = Button::New(label, pIO);
|
r = Button::New(label, pIO);
|
||||||
@@ -59,7 +59,7 @@ PD_UI7_API bool Menu::Button(const std::string& label) {
|
|||||||
|
|
||||||
PD_UI7_API void Menu::Checkbox(const std::string& label, bool& v) {
|
PD_UI7_API void Menu::Checkbox(const std::string& label, bool& v) {
|
||||||
u32 id = Strings::FastHash("cbx" + label +
|
u32 id = Strings::FastHash("cbx" + label +
|
||||||
std::to_string(pLayout->Objects.Size()));
|
std::to_string(pLayout->Objects.size()));
|
||||||
Container::Ref r = pLayout->FindObject(id);
|
Container::Ref r = pLayout->FindObject(id);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
r = Checkbox::New(label, v, pIO);
|
r = Checkbox::New(label, v, pIO);
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ PD_UI7_API void Context::MetricsMenu(bool *show) {
|
|||||||
}
|
}
|
||||||
// Well this are Li Drawlists now and they do not count their stats (yet)
|
// Well this are Li Drawlists now and they do not count their stats (yet)
|
||||||
/*if (m->BeginTreeNode("DrawLists (" +
|
/*if (m->BeginTreeNode("DrawLists (" +
|
||||||
std::to_string(pIO->DrawListRegestry.Size()) + ")")) {
|
std::to_string(pIO->DrawListRegestry.size()) + ")")) {
|
||||||
for (auto &it : pIO->DrawListRegestry) {
|
for (auto &it : pIO->DrawListRegestry) {
|
||||||
if (m->BeginTreeNode(it.First.GetName())) {
|
if (m->BeginTreeNode(it.First.GetName())) {
|
||||||
m->Label("Vertices: " + std::to_string(it.Second->NumVertices));
|
m->Label("Vertices: " + std::to_string(it.Second->NumVertices));
|
||||||
|
|||||||
Reference in New Issue
Block a user