Upload all my tests

- Add Count<> to AssetManager
- Initialize pCode in Shader
- Rename linearAllocator to LinearAllocator
- Add Construct and destroy to linear allocator
- Add Shader unloader (fixes atexit crash i guess)
-
This commit is contained in:
2025-11-30 21:57:01 +01:00
parent febf506a5e
commit 078af99ae5
16 changed files with 389 additions and 151 deletions

View File

@@ -5,6 +5,7 @@
#include <amethyst/c3d.hpp>
#include <amethyst/ctru.hpp>
#include <amethyst/image.hpp>
#include <amethyst/iron.hpp>
#include <amethyst/renderer.hpp>
#include <amethyst/texture.hpp>

View File

@@ -49,6 +49,17 @@ class AssetMgr {
return dynamic_cast<T*>(r->second) != nullptr;
}
template <typename T>
size_t Count() const {
size_t ret = 0;
for (auto& it : pAssets) {
if (dynamic_cast<T*>(it.second)) {
ret++;
}
}
return ret;
}
private:
std::map<ID, Asset*> pAssets;
};

View File

@@ -56,7 +56,7 @@ class C3D {
// private:
C3D_AttrInfo pInfo;
shaderProgram_s pProgram;
DVLB_s* pCode;
DVLB_s* pCode = nullptr;
int pReg = 0;
};

View File

@@ -158,8 +158,8 @@ class Iron {
static void pInitSolidTex();
static bool pCheckSize(size_t idx, size_t vtx);
static std::vector<Vertex, linearAllocator<Vertex>> m_vbuf;
static std::vector<u16, linearAllocator<u16>> m_ibuf;
static std::vector<Vertex, LinearAllocator<Vertex>> m_vbuf;
static std::vector<u16, LinearAllocator<u16>> m_ibuf;
static int uLocProj;
static C3D::Shader* m_shader;
static mat4 m_mtx;

View File

@@ -11,25 +11,35 @@
namespace Amy {
template <typename T>
class linearAllocator {
class LinearAllocator {
public:
using value_type = T;
linearAllocator() = default;
LinearAllocator() noexcept = default;
template <typename U>
constexpr linearAllocator(const linearAllocator<U>&) noexcept {}
constexpr LinearAllocator(const LinearAllocator<U>&) noexcept {}
T* allocate(std::size_t n) {
if (n > std::allocator_traits<linearAllocator>::max_size(*this)) {
if (n > max_size()) {
throw std::bad_alloc();
}
return static_cast<T*>(linearAlloc(n * sizeof(T)));
}
void deallocate(T* p, std::size_t) noexcept { linearFree(p); }
friend bool operator==(const linearAllocator, const linearAllocator) {
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) {
friend bool operator!=(const LinearAllocator, const LinearAllocator) {
return false;
}