Preliminary controller support

This commit is contained in:
SimoneN64
2024-05-17 23:19:15 +02:00
parent 87f9546ed3
commit 2ebda70a8c
4 changed files with 122 additions and 15 deletions

View File

@@ -3,8 +3,43 @@
#include <cstring>
#include <portable_endian_bswap.h>
#include <log.hpp>
#include <functional>
namespace Util {
template <class T, typename... Args>
struct AutoRelease {
AutoRelease(void (*dtor)(T*)) : dtor(dtor) { }
AutoRelease(T* (*ctor)(Args...), void (*dtor)(T*), Args... args) : dtor(dtor) {
thing = ctor(args...);
}
T* get() { return thing; }
void Construct(T* (*ctor)(Args...), Args... args) {
if(thing) {
dtor(thing);
}
thing = ctor(args...);
}
void Destroy() {
if(thing) {
dtor(thing);
}
}
~AutoRelease() {
if(thing) {
dtor(thing);
}
}
private:
T* thing = nullptr;
void (*dtor)(T*) = nullptr;
};
template<typename T>
static FORCE_INLINE T ReadAccess(const u8* data, u32 index) {
if constexpr (sizeof(T) == 8) {