mirror of
https://github.com/zeldaret/st
synced 2026-06-18 07:25:26 -04:00
5e934a8c9b
* name func_01ffd3d8 and func_01ffd400 * name func_01ffd3b0 * match func_ov024_020cf9d4 + improve the Random struct * UnkStruct_027e0cf8_00_0C_024 45% * match PassengerManager::GetRandomIndex * UnkStruct_027e0cf8_00_0C_024 OK * UnkStruct_027e0cf8_00_0C_024: do other sections * UnkStruct_027e0cf8_08_024 55% * cleanup: remplace delete into null by the delete macro * UnkStruct_027e0cf8_08_024 OK * fix build issues * UnkStruct_ov024_020d86a0_024 OK * PlayerActor_A0_38_024 .text OK, CreditsEndingType OK * tools: create courselist.py to convert .CLB data to yaml * UnkDataStruct4_14 OK * UnkDataStruct4 17% * UnkDataStruct4 OK * MiscAdvManager OK * PassengerManager OK * fix build issues * ZeldaTrainBinary OK * mark PassengerManager as complete and adjust delinks * UnkStruct_027e0cf8_08_00_024 OK * document more of UnkStruct_027e0ce0 * savefile hotfixes * UnkStruct_027e0ce0_34_024 OK * code_020d46b4_024 OK * UnkStruct_027e0d00 & UnkStruct_027e0d00_20 OK * code_020d51dc_024 OK * fix weird formatting * UnkTrainSystem1 OK * fix jp broken match * UnkTrainSystem2 OK * UnkStruct_027e0d08_024 31% * fix build issues * UnkStruct_027e0d08 OK!!! * remove useless parenthesis * ActorUnk_ov000_020a8bb0_EC OK * move ActorUnk_ov000_020a8bb0_EC to MainGame/Actor/ * ActorUnkOBPC OK * add sjiswrap support * solve remaining gaps and fix build issues * reorganise files + counter docs * tools: remove format command execution from defaults
112 lines
2.3 KiB
C++
112 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include "System/SysNew.hpp"
|
|
#include "types.h"
|
|
|
|
// link list?
|
|
struct stack_struct1 {
|
|
void *param1;
|
|
|
|
union {
|
|
void *param2;
|
|
unk32 arg2;
|
|
};
|
|
};
|
|
|
|
template <typename T> class Iterator {
|
|
public:
|
|
/* 00 */ void *begin;
|
|
/* 04 */ void *end;
|
|
/* 08 */
|
|
|
|
Iterator() {
|
|
this->Clear();
|
|
}
|
|
|
|
~Iterator() {
|
|
this->Destroy();
|
|
}
|
|
|
|
// allocate the list and run the constructors for each element
|
|
void Init(size_t arrayLength) {
|
|
this->Destroy();
|
|
this->Set(arrayLength * 4);
|
|
|
|
if (this->begin != this->end) {
|
|
T *it = (T *) this->begin;
|
|
|
|
do {
|
|
new(it) T(); // using placement new to run the ctor
|
|
|
|
it++;
|
|
} while (it != (T *) this->end);
|
|
}
|
|
}
|
|
|
|
// same as the other `Init` except this takes a node list
|
|
void Init(size_t arrayLength, void *params) {
|
|
this->Destroy();
|
|
this->Set(arrayLength);
|
|
|
|
if (this->begin != this->end) {
|
|
T *it = (T *) this->begin;
|
|
stack_struct1 *p = (stack_struct1 *) params;
|
|
|
|
do {
|
|
new(it) T(*p);
|
|
|
|
it++;
|
|
p++;
|
|
} while (it != (T *) this->end);
|
|
}
|
|
}
|
|
|
|
// iterate the array and run the destructors for each element
|
|
void Destroy() {
|
|
if (this->begin != this->end) {
|
|
T *it = (T *) this->end;
|
|
|
|
do {
|
|
(--it)->~T();
|
|
} while (it != (T *) this->begin);
|
|
|
|
delete this->begin;
|
|
}
|
|
}
|
|
|
|
// allocate and set pointers
|
|
void Set(size_t arrayLength) {
|
|
void *ptr = ::operator new(arrayLength, HeapIndex_1, 4);
|
|
this->begin = ptr;
|
|
this->end = (void *) ((u8 *) ptr + arrayLength);
|
|
}
|
|
|
|
// clear pointers
|
|
void Clear() {
|
|
this->begin = NULL;
|
|
this->end = NULL;
|
|
}
|
|
|
|
// destroy and clear
|
|
void Reset() {
|
|
this->Destroy();
|
|
this->Clear();
|
|
}
|
|
|
|
T &Get(int index) {
|
|
return ((T *) this->begin)[index];
|
|
}
|
|
|
|
T *GetPtr(int index) {
|
|
return ((T *) this->begin) + index;
|
|
}
|
|
|
|
const int GetAllocSize() const {
|
|
return (int) this->end - (int) this->begin;
|
|
}
|
|
|
|
const int GetLastIndex() const {
|
|
return (this->GetAllocSize() / (int) sizeof(T)) - 1;
|
|
}
|
|
};
|