Pad stuff

This commit is contained in:
elijah-thomas774
2025-06-15 14:40:59 -04:00
parent 2707f74d70
commit e4b1c30f47
40 changed files with 2258 additions and 874 deletions
+6 -6
View File
@@ -2,8 +2,8 @@
#define EGG_AUDIO_REMOTE_SPEAKER_MANAGER_H
#include "common.h"
#include "rvl/WPAD.h" // IWYU pragma: export
#include "rvl/WPAD.h" // IWYU pragma: export
namespace EGG {
@@ -19,8 +19,8 @@ class AudioRmtSpeakerMgr {
public:
static void calc();
static void fn_804B6D80(s32 i, WPADCallback *pCallback);
static void fn_804B6DE0(s32 i, WPADCallback *pCallback);
static void setup(s32 i, WPADCallback *pCallback);
static void shutdown(s32 i, WPADCallback *pCallback);
static void connectAllByForce();
static void disconnectAllByForce();
@@ -30,9 +30,9 @@ public:
private:
static void setupCallback(s32, s32);
static void shutdownCallback(s32, s32);
static void fn_804B6AF0(s32 i, WPADCallback *pCallback, bool);
static void fn_804B6B80(s32 i, WPADCallback *pCallback);
static void fn_804B6C00(s32 i, WPADCallback *pCallback);
static void add_task(s32 i, WPADCallback *pCallback, bool);
static void doSetup(s32 i, WPADCallback *pCallback);
static void doShutdown(s32 i, WPADCallback *pCallback);
static void setupCallbackDirect(s32, s32);
static void shutdownCallbackDirect(s32, s32);
static bool sAudioRmtSpeakerConnectCanncelSw;
+334 -165
View File
@@ -2,107 +2,168 @@
#define EGG_CONTROLLER_H
#include "common.h"
#include "egg/core/eggSingleton.h"
#include "egg/math/eggMatrix.h"
#include "egg/math/eggVector.h"
#include "egg/prim/eggBitFlag.h"
#include "egg/prim/eggBuffer.h"
#include "rvl/KPAD/KPAD.h"
#include "rvl/KPAD.h" // IWYU pragma: exports
#include "rvl/PAD.h" // IWYU pragma: exports
#include "rvl/WPAD.h" // IWYU pragma: exports
namespace EGG {
class ControllerRumbleMgr;
class CoreController;
// To Be Filled out
enum eCoreDevType {
cDEV_CORE = WPAD_DEV_CORE,
cDEV_FREESTYLE = WPAD_DEV_FREESTYLE,
cDEV_CLASSIC = WPAD_DEV_CLASSIC,
cDEV_MPLS_PT_FS = WPAD_DEV_MPLS_PT_FS,
cDEV_FUTURE = WPAD_DEV_FUTURE,
cDEV_NOT_SUPPORTED = WPAD_DEV_NOT_SUPPORTED,
cDEV_NOT_FOUND = WPAD_DEV_NOT_FOUND,
cDEV_NULL = WPAD_DEV_NULL,
cDEV_UNKNOWN = WPAD_DEV_UNKNOWN,
};
typedef void (*ConnectCallback)(int args[]);
typedef class CoreController *(*ControllerFactory)();
enum eCoreButton {
cCORE_BUTTON_UP = 1 << 3,
cCORE_BUTTON_DOWN = 1 << 2,
cCORE_BUTTON_LEFT = 1 << 0,
cCORE_BUTTON_RIGHT = 1 << 1,
class CoreStatus {
cCORE_BUTTON_PLUS = 1 << 4,
cCORE_BUTTON_MINUS = 1 << 12,
cCORE_BUTTON_1 = 1 << 9,
cCORE_BUTTON_2 = 1 << 8,
cCORE_BUTTON_A = 1 << 11,
cCORE_BUTTON_B = 1 << 10,
cCORE_BUTTON_HOME = 1 << 15,
cCORE_FSSTICK_UP = 1 << 16,
cCORE_FSSTICK_DOWN = 1 << 17,
cCORE_FSSTICK_LEFT = 1 << 18,
cCORE_FSSTICK_RIGHT = 1 << 19,
cCORE_FSSTICK_BUTTONS = cCORE_FSSTICK_UP | cCORE_FSSTICK_DOWN | cCORE_FSSTICK_LEFT | cCORE_FSSTICK_RIGHT
};
typedef CoreController *(*CoreControllerFactory)();
struct CoreControllerConnectArg {
s32 chan; // at 0x0
s32 result; // at 0x4
};
typedef void (*CoreControllerConnectCallback)(const CoreControllerConnectArg &rArg);
struct CoreControllerExtensionArg {
eCoreDevType newDevType; // at 0x0
eCoreDevType oldDevType; // at 0x4
s32 chan; // at 0x8
};
class CoreControllerExtensionCallback {
public:
/* 0x00 */ u32 mHold;
/* 0x04 */ u32 mTrig;
/* 0x08 */ u32 mRelease;
/* 0x0C */ Vector3f mAccel;
/* 0x18 */ u8 field_0x01[0x20 - 0x18];
/* 0x20 */ f32 mDpdRawX;
/* 0x24 */ f32 mDpdRawY;
/* 0x28 */ u8 field_0x02[0x48 - 0x28];
/* 0x48 */ f32 mDpdDistance;
/* 0x4C */ f32 float_0x4C;
/* 0x50 */ f32 float_0x50;
/* 0x54 */ f32 float_0x54;
/* 0x58 */ f32 float_0x58;
/* 0x5C */ u8 mDevType;
/* 0x5D */ u8 field_0x5D;
/* 0x5E */ s8 mDpdValid;
/* 0x5F */ s8 unknown;
/* 0x60 */ f32 mFSStickX;
/* 0x64 */ f32 mFSStickY;
/* 0x68 */ u8 field_0x03[0x88];
virtual void onConnect(const CoreControllerExtensionArg &rArg); // at 0x8
};
/******************************************************************************
*
* CoreStatus
*
******************************************************************************/
class CoreStatus : public KPADStatus {
friend class CoreController;
public:
CoreStatus() {}
public:
void init();
u32 getFSStickButton() const;
f32 getFSStickX() const {
return mFSStickX;
}
f32 getFSStickY() const {
return mFSStickY;
}
bool down(u32 mask) const {
return (mask & mHold);
}
bool up(u32 mask) const {
return (mask & mHold) != mask;
}
bool downTrigger(u32 mask) const {
return (mask & mTrig);
}
bool upTrigger(u32 mask) const {
return (mask & mRelease);
}
bool downAll(u32 mask) const {
return (mask & mHold) == mask;
}
bool upAll(u32 mask) const {
return (mask & mHold) == 0;
}
s32 getDevType() const {
return mDevType;
}
bool isCore() const {
return getDevType() == WPAD_DEV_CORE;
}
bool isFreestyle() const {
return getDevType() == WPAD_DEV_FS;
}
u32 getHold() const {
return mHold;
return hold;
}
u32 getRelease() const {
return release;
}
u32 getTrigger() const {
return trig;
}
s8 getDpdValidFlag() const {
return mDpdValid;
};
bool down(u32 buttons) const {
return buttons & hold;
}
bool up(u32 buttons) const {
return (buttons & hold) != buttons;
}
Vector2f getUnk() {
return Vector2f(float_0x54, float_0x58);
bool downAll(u32 buttons) const {
return (buttons & hold) == buttons;
}
bool upAll(u32 buttons) const {
return (buttons & hold) == 0;
}
bool downTrigger(u32 buttons) const {
return buttons & trig;
}
bool upTrigger(u32 buttons) const {
return buttons & release;
}
const Vector3f &getAccel() const {
return mAccel;
return *reinterpret_cast<const Vector3f *>(&acc);
}
};
Vector2f getAccelVertical() {
return Vector2f(acc_vertical.x, acc_vertical.y);
}
eCoreDevType getDevType() const {
return static_cast<eCoreDevType>(dev_type);
}
bool isCore() const {
return getDevType() == cDEV_CORE || isFreestyle();
}
bool isFreestyle() const {
return getDevType() == cDEV_FREESTYLE;
}
s8 getDPDValidFlag() const {
return dpd_valid_fg;
}
f32 getFSStickX() const {
return ex_status.fs.stick.x;
}
f32 getFSStickY() const {
return ex_status.fs.stick.y;
}
u32 getFSStickButton();
};
/******************************************************************************
*
* CoreController
*
******************************************************************************/
class CoreController {
friend class CoreControllerMgr;
public:
CoreController();
// vtable 0x0000
/* vt 0x08 */ virtual void setPosParam(f32 f1, f32 f2) {
KPADSetPosParam(mChannelID, f1, f2);
@@ -116,86 +177,145 @@ public:
/* vt 0x14 */ virtual void setAccParam(f32 f1, f32 f2) {
KPADSetAccParam(mChannelID, f1, f2);
}
/* vt 0x18 */ virtual bool down(u32 mask) const {
return mCoreStatus[0].down(mask);
/* vt 0x18 */ virtual bool down(u32 buttons) const {
return mCoreStatus[0].down(buttons);
}
/* vt 0x1C */ virtual bool up(u32 mask) const {
return mCoreStatus[0].up(mask);
/* vt 0x1C */ virtual bool up(u32 buttons) const {
return mCoreStatus[0].up(buttons);
}
/* vt 0x20 */ virtual bool downTrigger(u32 mask) const {
return mCoreStatus[0].downTrigger(mask);
/* vt 0x20 */ virtual bool downTrigger(u32 buttons) const {
return mCoreStatus[0].downTrigger(buttons);
}
/* vt 0x24 */ virtual bool upTrigger(u32 mask) const {
return mCoreStatus[0].upTrigger(mask);
/* vt 0x24 */ virtual bool upTrigger(u32 buttons) const {
return mCoreStatus[0].upTrigger(buttons);
}
/* vt 0x28 */ virtual bool downAll(u32 mask) const {
return mCoreStatus[0].downAll(mask);
/* vt 0x28 */ virtual bool downAll(u32 buttons) const {
return mCoreStatus[0].downAll(buttons);
}
/* vt 0x2C */ virtual bool upAll(u32 mask) const {
return mCoreStatus[0].upAll(mask);
/* vt 0x2C */ virtual bool upAll(u32 buttons) const {
return mCoreStatus[0].upAll(buttons);
}
/* vt 0x30 */ virtual void beginFrame(PADStatus *padStatus);
/* vt 0x34 */ virtual void endFrame();
public:
/* 0x004 */ s32 mChannelID;
/* 0x008 */ u32 mButtonHeld;
/* 0x00C */ u32 mButtonTriggered;
/* 0x010 */ u32 mButtonReleased;
/* 0x014 */ u32 field_0x14;
/* 0x018 */ CoreStatus mCoreStatus[16];
/* 0xf18 */ int mReadStatusIdx;
/* 0xf1c */ TBitFlag<u8> mFlag;
/* 0xf20 */ Vector3f mAccel;
/* 0xf2c */ Vector2f mDpdPos;
/* 0xf34 */ u32 mIdleTime;
/* 0xf38 */ u32 mMotorPattern;
/* 0xf3c */ bool mEnableMotor;
/* 0xf40 */ s32 mMotorFrameDuration;
/* 0xf44 */ u8 mMotorPatternLength;
/* 0xf45 */ u8 mMotorPatternPos;
/* 0xf48 */ ControllerRumbleMgr *mRumbleMgr;
/* 0xf4c */ Matrix34f mPostureMatrix;
/* 0xf7c */ Matrix34f mPostureMatrixPrev;
/* 0xfac */ TBitFlag<u8> mAccelFlags; // May not be TBitFlag?
/* 0xfb0 */ s32 mMaxAccelFrameTime;
/* 0xfb4 */ s32 mAccelFrameTime[3];
/* 0xfc0 */ f32 mMaxAccelDiff;
/* 0xfc4 */ Vector3f mPrevAccel;
public:
CoreController();
void sceneReset();
Vector2f getDpdRawPos();
f32 getDpdDistance();
s32 getDpdValidFlag(); // Name Assumed. BBA hints at variable
void startMotor();
void stopMotor();
void createRumbleMgr(u8);
void startPatternRumble(const char *, int, bool);
void stopRumbleMgr();
CoreStatus *getCoreStatus(int idx);
void calc_posture_matrix(Matrix34f &mat, bool);
s32 getDpdValidFlag();
f32 getFreeStickX() const;
f32 getFreeStickY() const;
s32 getChannelID() const {
return mChannelID;
}
const Vector3f &getAccel() const {
return mCoreStatus[0].getAccel();
}
// Guess ?
bool isStable(u8 p1) const {
return (mAccelFlags.getDirect() & p1) == p1;
eCoreDevType getDevType() const {
return mCoreStatus[0].getDevType();
}
bool isCore() const {
return mCoreStatus[0].isCore();
}
bool isFreestyle() const {
return mCoreStatus[0].isFreestyle();
}
s32 getReadLength() const {
return mKPADReadLength;
}
bool isStable(u8 bits) const {
return (mStableFlags & bits) == bits;
}
void setStableFrame(int frame) {
mStableFrame = frame;
}
void setStableMag(f32 mag) {
mStableMag = mag;
}
void sceneReset();
void startMotor();
void stopMotor();
void createRumbleMgr(u8 overlap_num);
void startPatternRumble(const char *pPattern, int frame, bool force);
void startPowerFrameRumble(f32 power, int frame, bool force);
void stopRumbleMgr();
bool isConnected() const {
return mFlag.onBit(0);
}
CoreStatus *getCoreStatus(int idx);
CoreStatus *getCoreStatus() {
return mCoreStatus;
}
private:
enum StableAxis {
STABLE_AXIS_X,
STABLE_AXIS_Y,
STABLE_AXIS_Z,
STABLE_AXIS_MAX
};
enum StableFlag {
STABLE_FLAG_X = 1 << STABLE_AXIS_X,
STABLE_FLAG_Y = 1 << STABLE_AXIS_Y,
STABLE_FLAG_Z = 1 << STABLE_AXIS_Z,
STABLE_FLAG_XYZ = STABLE_FLAG_X | STABLE_FLAG_Y | STABLE_FLAG_Z
};
private:
void calc_posture_matrix(Matrix34f &rPostureMtx, bool checkStable);
private:
/* 0x004 */ s32 mChannelID;
/* 0x008 */ u32 mFSStickHold;
/* 0x00C */ u32 mFSStickTrig;
/* 0x010 */ u32 mFSStickRelease;
/* 0x014 */ u32 field_0x14;
/* 0x018 */ CoreStatus mCoreStatus[16];
/* 0xf18 */ int mKPADReadLength;
/* 0xf1c */ TBitFlag<u8> mFlag;
/* 0xf20 */ Vector3f mAccelPrev;
/* 0xf2c */ Vector2f mDpdPosPrev;
/* 0xf34 */ u32 mIdleTime;
/* 0xf38 */ u32 mSimpleRumblePattern;
/* 0xf3c */ bool mEnableSimpleRumble;
/* 0xf40 */ s32 mSimpleRumbleFrame;
/* 0xf44 */ u8 mSimpleRumbleSize;
/* 0xf45 */ u8 mSimpleRumbleIndex;
/* 0xf48 */ ControllerRumbleMgr *mRumbleMgr;
/* 0xf4c */ Matrix34f mPostureMatrix;
/* 0xf7c */ Matrix34f mPostureMatrixPrev;
/* 0xfac */ u8 mStableFlags; // May not be TBitFlag?
/* 0xfb0 */ s32 mStableFrame;
/* 0xfb4 */ s32 mStableTimer[3];
/* 0xfc0 */ f32 mStableMag;
/* 0xfc4 */ Vector3f mStableAccel;
};
/******************************************************************************
*
* CoreControllerMgr
*
******************************************************************************/
class CoreControllerMgr {
public:
struct T__Disposer : Disposer {
/* vt 0x08 */ virtual ~T__Disposer();
static T__Disposer *sStaticDisposer;
};
/* 0x0000 */ T__Disposer mDisposer;
EGG_SINGLETON_DECL(CoreControllerMgr);
struct UnkField0x10A0 {
virtual void v_08(UNKTYPE *);
@@ -206,81 +326,130 @@ public:
/* vt 0x08 */ virtual void beginFrame();
/* vt 0x0C */ virtual void endFrame();
public:
CoreController *getNthController(int index);
eCoreDevType getDevType(const int i) const {
return mDevTypes(i);
}
static void setConnectCallback(CoreControllerConnectCallback cb) {
sConnectCallback = cb;
}
private:
CoreControllerMgr();
static void *allocThunk(size_t size);
static int deleteThunk(void *ptr);
static void connectCallback(s32, s32);
private:
/* 0x0014 */ TBuffer<CoreController *> mControllers;
/* 0x0020 */ u8 field_0x20[0x10a0 - 0x0020];
/* 0x10A0 */ UnkField0x10A0 *field_0x10A0;
/* 0x10A4 */ TBuffer<eCoreDevType> mDevTypes;
/* 0x10b0 */ u8 field_0x10B0[0x10e0 - 0x10b0];
public:
static CoreControllerMgr *createInstance();
static void deleteInstance();
CoreController *getNthController(int);
static void *allocThunk(size_t size);
static int deleteThunk(void *ptr);
static void connectCallback(s32, s32);
CoreControllerMgr();
public:
static CoreControllerMgr *sInstance;
static CoreController *(*sCoreControllerFactory)();
static ConnectCallback sConnectCallback;
static CoreControllerFactory sCoreControllerFactory;
static CoreControllerConnectCallback sConnectCallback;
static bool sUseBuiltinWpadAllocator;
static s32 sWPADWorkSize;
};
/******************************************************************************
*
* NullController
*
******************************************************************************/
class NullController : public CoreController {
public:
NullController() {
unk[92] = 0xfe;
}
private:
// idk this has NO effect on anything
u8 unk[0x80674c00 - 0x80674b10];
};
/******************************************************************************
*
* ControllerRumbleUnit
*
******************************************************************************/
class ControllerRumbleUnit {
friend class ControllerRumbleMgr;
public:
// 0x00 vtable
inline ControllerRumbleUnit() : mFlag(0) {
ControllerRumbleUnit() : mFlags(0) {
init();
}
/* vt 0x08 */ virtual ~ControllerRumbleUnit() {}
public:
/* 0x04 */ const char *mPattern;
/* 0x08 */ const char *mPatternPos;
/* 0x0C */ s32 mTimer; // guess
/* 0x10 */ f32 mRampUp; // guess
/* 0x14 */ f32 mIntensity; // guess
/* 0x18 */ TBitFlag<u8> mFlag;
/* 0x1C */ nw4r::ut::Node mNode;
/* 0x24 */ u32 field_0x24; // could just be part of the node (List)
public:
void init();
void startPattern(const char *patter, int);
void startPattern(const char *pPattern, int frame);
f32 calc();
private:
enum {
BIT_USE_PATTERN,
BIT_USE_POWER,
BIT_POWER_LOOP,
BIT_ENABLED,
BIT_PATTERN_LOOP,
BIT_PATTERN_TIMER,
};
private:
void init();
void setFlags(u8 bit) {
mFlags.setBit(bit);
}
void clrFlags(u8 bit) {
mFlags.resetBit(bit);
}
bool tstFlags(u8 bit) {
return mFlags.onBit(bit);
}
private:
/* 0x04 */ const char *mRumblePattern;
/* 0x08 */ const char *mRumblePatternPtr;
/* 0x0C */ s32 mRumbleFrame;
/* 0x10 */ f32 mRumblePower;
/* 0x14 */ f32 mRumbleValue;
/* 0x18 */ TBitFlag<u8> mFlags;
/* 0x1C */ nw4r::ut::Node mNode;
/* 0x24 */ u32 field_0x24;
};
/******************************************************************************
*
* ControllerRumbleMgr
*
******************************************************************************/
class ControllerRumbleMgr {
public:
// 0x00 vtable
/* vt 0x08 */ virtual ~ControllerRumbleMgr() {}
public:
/* 0x04 */ nw4r::ut::List mActiveUnitList;
/* 0x10 */ nw4r::ut::List mInactiveUnitList;
/* 0x1C */ CoreController *mController;
public:
ControllerRumbleMgr();
void createUnit(u8 numUnits, CoreController *controller);
virtual ~ControllerRumbleMgr() {} // at 0x8
void createUnit(u8 overlap_num, CoreController *pController);
void stop();
void calc();
void startPattern(const char *pattern, int, bool);
private:
ControllerRumbleUnit *getUnitFromList(bool bGrabActive);
private:
/* 0x04 */ nw4r::ut::List mActiveUnitList;
/* 0x10 */ nw4r::ut::List mStoppedUnitList;
/* 0x1C */ CoreController *mController;
};
} // namespace EGG
+55
View File
@@ -0,0 +1,55 @@
#ifndef EGG_CORE_SINGLETON_H
#define EGG_CORE_SINGLETON_H
#include "egg/core/eggDisposer.h"
#include "egg/prim/eggAssert.h"
/**
* @brief Declares functions and data for a disposable singleton class
*/
#define EGG_SINGLETON_DECL(T) \
protected: \
class T__Disposer : public EGG::Disposer { \
public: \
virtual ~T__Disposer(); /* at 0x8 */ \
static T__Disposer *sStaticDisposer; \
}; \
\
T__Disposer mDisposer; \
\
public: \
static T *createInstance(); \
static void deleteInstance(); \
\
static T *instance() { \
return sInstance; \
} \
\
protected: \
static T *sInstance;
/**
* @brief Defines functions and data for a disposable singleton class
*/
#define EGG_SINGLETON_IMPL(T) \
T::T__Disposer::~T__Disposer() { \
T::deleteInstance(); \
} \
\
T *T::createInstance() { \
if (sInstance == NULL) { \
sInstance = new T(); \
} else { \
EGG_ASSERT_MSG(false, "Create Singleton Twice (%s) : addr %x\n", #T, sInstance); \
} \
\
return sInstance; \
} \
\
void T::deleteInstance() { \
sInstance = NULL; \
} \
\
T *T::sInstance = NULL;
#endif
+16 -1
View File
@@ -9,8 +9,23 @@ namespace EGG {
// TODO: Fixup funtions
namespace Assert {
typedef void (*AssertCallback)();
#if 1
#define EGG_ASSERT(EXP)
#define EGG_ASSERT_MSG(EXP, ...)
#define EGG_PRINT(...)
#else
#define EGG_ASSERT(EXP) \
if (!(EXP)) \
system_halt(__FILE__, __LINE__, #EXP)
#define EGG_ASSERT_MSG(EXP, ...) \
if (!(EXP)) \
system_halt(__FILE__, __LINE__, __VA_ARGS__)
#define EGG_PRINT(...) system_print(true, __FILE__, __VA_ARGS__)
#endif
typedef void (*AssertCallback)();
void wait(u32 time);
void system_vreport(const char *str, va_list list);
void system_report(const char *str, ...);
+98 -38
View File
@@ -4,67 +4,127 @@
#include "common.h"
#include "egg/core/eggHeap.h"
namespace EGG {
template <typename T>
class TBuffer {
public:
// vtable 0x00
/* vt 0x08 */ virtual ~TBuffer() {
if (mBuffer != nullptr) {
delete[] mBuffer;
mBuffer = nullptr;
class iterator {
public:
iterator(TBuffer *pBuffer, int index) : mBuffer(pBuffer), mIndex(index) {}
int get_index() const {
return mIndex;
}
}
/* vt 0x0C */ virtual void allocate(int n, int);
/* vt 0x10 */ virtual void allocate(int n, Heap *heap, int);
/* vt 0x14 */ virtual void onAllocate(Heap *) {
return;
}
/* vt 0x18 */ virtual void errRangeOver() {
return;
}
iterator &operator++() {
mIndex++;
return *this;
}
T &operator*() {
return (*mBuffer)(mIndex);
}
friend bool operator==(const iterator &rLhs, const iterator &rRhs) {
return rLhs.mBuffer == rRhs.mBuffer && rLhs.mIndex == rRhs.mIndex;
}
friend bool operator!=(const iterator &rLhs, const iterator &rRhs) {
return !(rLhs == rRhs);
}
private:
TBuffer *mBuffer; // at 0x0
int mIndex; // at 0x4
};
public:
/* 0x08 */ s32 mSize;
/* 0x0C */ T *mBuffer;
TBuffer() : mSize(0), mBuffer(NULL) {}
public:
inline TBuffer() : mSize(0), mBuffer(nullptr) {}
virtual ~TBuffer() {
if (mBuffer == NULL) {
return;
}
inline bool isRangeValid(int i) {
return (i >= 0 && i < mSize);
delete[] mBuffer;
mBuffer = NULL;
} // at 0x8
virtual void allocate(int size, int align = 0); // at 0xC
virtual void allocate(int size, Heap *pHeap, int align = 0); // at 0x10
virtual void onAllocate(Heap * /* pHeap */) {} // at 0x14
virtual void errRangeOver() const {} // at 0x18
T &operator()(int i) {
checkRange(i);
return mBuffer[i];
}
inline void checkRange(int i) {
const T &operator()(int i) const {
checkRange(i);
return mBuffer[i];
}
T &get(int i) {
checkRange(i);
return mBuffer[i];
}
const T &get(int i) const {
checkRange(i);
return mBuffer[i];
}
int getSize() const {
return mSize;
}
int size() const {
return mSize;
}
iterator begin() {
return iterator(this, 0);
}
iterator end() {
return iterator(this, getSize());
}
private:
void flush() {}
void checkRange(int i) const {
if (!isRangeValid(i)) {
errRangeOver();
}
}
inline T &operator()(int i) {
checkRange(i);
return mBuffer[i];
}
inline s32 getSize() {
return mSize;
bool isRangeValid(int i) const {
return i >= 0 && i < mSize;
}
private:
int mSize; // at 0x4
T *mBuffer; // at 0x8
};
template <typename T>
void TBuffer<T>::allocate(int n, int) {
mSize = n;
mBuffer = new T[n];
void TBuffer<T>::allocate(int size, int) {
mSize = size;
mBuffer = new T[size];
onAllocate(nullptr);
}
template <typename T>
void TBuffer<T>::allocate(int n, Heap *heap, int) {
mSize = n;
if (heap == nullptr) {
heap = Heap::sCurrentHeap;
void TBuffer<T>::allocate(int size, Heap *pHeap, int) {
mSize = size;
if (pHeap == NULL) {
pHeap = Heap::getCurrentHeap();
}
mBuffer = new (heap, 4) T[mSize];
onAllocate(heap);
mBuffer = new (pHeap) T[mSize];
flush();
onAllocate(pHeap);
}
} // namespace EGG