Road to 0.6.0
- readd the c++ linear allocator for 3ds - start switching from PD::Vec to std::vector - Add Color::Hex as constexpr for compiletime color converts - Add FNV Hasing functions - Make UI7 ids be able to be generated at compile time - Added a Throw Function (for whatever) - Added HexCHar2Int (replaces the lookup table) - Made u128 fully constexpr
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(pd-3ds LANGUAGES CXX VERSION 0.5.0)
|
||||
project(pd-3ds LANGUAGES CXX VERSION 0.6.0)
|
||||
|
||||
set(SRC
|
||||
source/bknd-gfx.cpp
|
||||
|
||||
@@ -27,19 +27,10 @@ SOFTWARE.
|
||||
#include <3ds.h>
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <pd-3ds/linearAllocator.hpp>
|
||||
#include <pd/lithium/lithium.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
class LinearAlloc : public Allocator<T> {
|
||||
public:
|
||||
LinearAlloc() = default;
|
||||
~LinearAlloc() = default;
|
||||
|
||||
/** Never forget the sizeof(T) again (most painful bug i created) */
|
||||
T* Allocate(size_t n) override { return (T*)linearAlloc(n * sizeof(T)); }
|
||||
void Deallocate(T* ptr) { linearFree(ptr); }
|
||||
};
|
||||
class GfxC3D : public GfxDriver {
|
||||
public:
|
||||
GfxC3D() : GfxDriver("Citro3D") {}
|
||||
@@ -59,8 +50,8 @@ class GfxC3D : public GfxDriver {
|
||||
PD::Li::Texture::Filter filter =
|
||||
PD::Li::Texture::Filter::LINEAR) override;
|
||||
|
||||
Vec<Li::Vertex, LinearAlloc<Li::Vertex>> VertexBuffer;
|
||||
Vec<u16, LinearAlloc<u16>> IndexBuffer;
|
||||
std::vector<Li::Vertex, LinearAllocator<Li::Vertex>> VertexBuffer;
|
||||
std::vector<u16, LinearAllocator<u16>> IndexBuffer;
|
||||
int pLocProjection = 0;
|
||||
DVLB_s* ShaderCode;
|
||||
shaderProgram_s Shader;
|
||||
|
||||
49
backends/3ds/include/pd-3ds/linearAllocator.hpp
Normal file
49
backends/3ds/include/pd-3ds/linearAllocator.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
|
||||
// Custom C++ Allocator class to interface with libctru linear heap memory
|
||||
// based on this guide:
|
||||
// https://johnfarrier.com/custom-allocators-in-c-high-performance-memory-management/
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
class LinearAllocator {
|
||||
public:
|
||||
using value_type = T;
|
||||
LinearAllocator() noexcept = default;
|
||||
template <typename U>
|
||||
constexpr LinearAllocator(const LinearAllocator<U>&) noexcept {}
|
||||
|
||||
T* allocate(std::size_t n) {
|
||||
if (n > max_size()) {
|
||||
throw std::runtime_error("[PD] LinearAllocator: Bad alloc!");
|
||||
}
|
||||
return static_cast<T*>(linearAlloc(n * sizeof(T)));
|
||||
}
|
||||
void deallocate(T* p, std::size_t) noexcept { linearFree(p); }
|
||||
|
||||
template <class U, class... Args>
|
||||
void construct(U* p, Args&&... args) {
|
||||
::new ((void*)p) U(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <class U>
|
||||
void destroy(U* p) {
|
||||
p->~U();
|
||||
}
|
||||
|
||||
friend bool operator==(const LinearAllocator, const LinearAllocator) {
|
||||
return true;
|
||||
}
|
||||
friend bool operator!=(const LinearAllocator, const LinearAllocator) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use linearSpace free as max_size to not allocate out of bounds
|
||||
// or to b eable to see a crash report screen.
|
||||
size_t max_size() const noexcept { return linearSpaceFree(); }
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -93,8 +93,8 @@ int GetBPP(Li::Texture::Type type) {
|
||||
}
|
||||
|
||||
void GfxC3D::Init() {
|
||||
VertexBuffer.Resize(4 * 8192);
|
||||
IndexBuffer.Resize(6 * 8192);
|
||||
VertexBuffer.resize(4 * 8192);
|
||||
IndexBuffer.resize(6 * 8192);
|
||||
|
||||
Flags |= LiBackendFlags_FlipUV_Y;
|
||||
|
||||
@@ -179,10 +179,10 @@ void GfxC3D::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
|
||||
BindTex(Tex->Address);
|
||||
auto bufInfo = C3D_GetBufInfo();
|
||||
BufInfo_Init(bufInfo);
|
||||
BufInfo_Add(bufInfo, VertexBuffer.Data(), sizeof(Li::Vertex), 3, 0x210);
|
||||
BufInfo_Add(bufInfo, VertexBuffer.data(), sizeof(Li::Vertex), 3, 0x210);
|
||||
|
||||
C3D_DrawElements(GPU_TRIANGLES, CurrentIndex - StartIndex,
|
||||
C3D_UNSIGNED_SHORT, IndexBuffer.Data() + StartIndex);
|
||||
C3D_UNSIGNED_SHORT, IndexBuffer.data() + StartIndex);
|
||||
}
|
||||
C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user