mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-09 04:30:49 -04:00
some cleanup of f_pc/f_op files (#2254)
* cleanup f_pc files * cleanup f_op files * fix a couple f_op_actor_mng functions * minor JSystem work
This commit is contained in:
@@ -53,7 +53,7 @@ struct J3DTransformInfo {
|
||||
extern J3DTransformInfo const j3dDefaultTransformInfo;
|
||||
extern Vec const j3dDefaultScale;
|
||||
extern Mtx const j3dDefaultMtx;
|
||||
extern f32 PSMulUnit01[2];
|
||||
extern f32 PSMulUnit01[];
|
||||
|
||||
void J3DGQRSetup7(u32 param_0, u32 param_1, u32 param_2, u32 param_3);
|
||||
void J3DCalcBBoardMtx(f32 (*)[4]);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef STD_MEMORY_H
|
||||
#define STD_MEMORY_H
|
||||
|
||||
#include "JSystem/JUtility/JUTAssert.h"
|
||||
|
||||
namespace JGadget {
|
||||
template <typename T>
|
||||
struct TAllocator {
|
||||
T* allocate(u32 count, void *param_2) {
|
||||
return AllocateRaw(count * sizeof(T));
|
||||
}
|
||||
|
||||
T* AllocateRaw(u32 size) {
|
||||
return (T*)operator new(size);
|
||||
}
|
||||
|
||||
void deallocate(T* mem, u32 size) {
|
||||
DeallocateRaw(mem);
|
||||
}
|
||||
|
||||
void DeallocateRaw(T* mem) {
|
||||
delete mem;
|
||||
}
|
||||
|
||||
void destroy(T* p) {
|
||||
JUT_ASSERT(68, p!=0);
|
||||
}
|
||||
|
||||
/* 0x0 */ u8 mAllocator;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* STD_MEMORY_H */
|
||||
@@ -1,4 +1,176 @@
|
||||
#ifndef STD_VECTOR_H
|
||||
#define STD_VECTOR_H
|
||||
|
||||
#include "JSystem/JGadget/std-memory.h"
|
||||
#include "algorithm.h"
|
||||
#include "msl_memory.h"
|
||||
|
||||
namespace JGadget {
|
||||
namespace vector {
|
||||
/* 802DCCC8 */ u32 extend_default(u32, u32, u32);
|
||||
};
|
||||
|
||||
typedef u32 (*extendFunc)(u32, u32, u32);
|
||||
|
||||
template <typename T, typename Allocator = JGadget::TAllocator<T> >
|
||||
struct TVector {
|
||||
struct TDestructed_deallocate_ {
|
||||
TDestructed_deallocate_(JGadget::TAllocator<T>& allocator, T* ptr) {
|
||||
mAllocator = &allocator;
|
||||
mPtr = ptr;
|
||||
}
|
||||
|
||||
~TDestructed_deallocate_() { mAllocator->deallocate(mPtr, 0); }
|
||||
|
||||
void set(T* ptr) { mPtr = ptr; }
|
||||
|
||||
Allocator* mAllocator;
|
||||
T* mPtr;
|
||||
};
|
||||
|
||||
TVector(Allocator const& allocator) {
|
||||
mAllocator = allocator;
|
||||
pBegin_ = NULL;
|
||||
pEnd_ = pBegin_;
|
||||
mCapacity = 0;
|
||||
pfnExtend_ = JGadget::vector::extend_default;
|
||||
}
|
||||
|
||||
~TVector() {
|
||||
clear();
|
||||
mAllocator.deallocate(pBegin_, 0);
|
||||
}
|
||||
|
||||
T* insert(T* pos, const T& val) {
|
||||
u32 diff = (int)((u32)pos - (u32)begin()) / 4;
|
||||
insert(pos, 1, val);
|
||||
return pBegin_ + diff;
|
||||
}
|
||||
|
||||
void insert(T* pos, u32 count, const T& val) {
|
||||
if (count != 0) {
|
||||
T* ptr = Insert_raw(pos, count);
|
||||
if (ptr == end()) {
|
||||
/* JGadget_outMessage sp120(JGadget_outMessage::warning, __FILE__, 0x141);
|
||||
sp120 << "can't allocate memory"; */
|
||||
} else {
|
||||
std::uninitialized_fill_n(ptr, count, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T* Insert_raw(T* pIt, u32 pCount) {
|
||||
JUT_ASSERT(446, (pBegin_ <= pIt) && (pIt <= pEnd_));
|
||||
|
||||
T* const pFirst = pIt;
|
||||
|
||||
if (pCount == 0) {
|
||||
return pIt;
|
||||
}
|
||||
|
||||
if (pCount + size() <= mCapacity) {
|
||||
void** newEnd = pFirst + pCount;
|
||||
|
||||
if (newEnd < pEnd_) {
|
||||
void** pOverwrittenValues = pEnd_ - pCount;
|
||||
std::uninitialized_copy(pOverwrittenValues, pEnd_, pEnd_);
|
||||
std::copy_backward(pFirst, pOverwrittenValues, pEnd_);
|
||||
DestroyElement_(pFirst, newEnd);
|
||||
|
||||
pEnd_ += pCount;
|
||||
return pIt;
|
||||
} else {
|
||||
std::uninitialized_copy(pFirst, pEnd_, newEnd);
|
||||
DestroyElement_(pFirst, pEnd_);
|
||||
|
||||
pEnd_ += pCount;
|
||||
return pIt;
|
||||
}
|
||||
}
|
||||
|
||||
u32 newSize = GetSize_extend_(pCount);
|
||||
|
||||
void** newDataPointer = mAllocator.allocate(newSize, 0);
|
||||
if (!newDataPointer) {
|
||||
return end();
|
||||
}
|
||||
|
||||
TDestructed_deallocate_ destructionDeallocator(mAllocator, newDataPointer);
|
||||
|
||||
void** const endOfCopy = std::uninitialized_copy(pBegin_, pFirst, newDataPointer);
|
||||
std::uninitialized_copy(pFirst, pEnd_, endOfCopy + pCount);
|
||||
|
||||
DestroyElement_all_();
|
||||
destructionDeallocator.set(pBegin_);
|
||||
|
||||
pEnd_ = newDataPointer + (pEnd_ - pBegin_ + pCount);
|
||||
pBegin_ = newDataPointer;
|
||||
mCapacity = newSize;
|
||||
|
||||
return endOfCopy;
|
||||
}
|
||||
|
||||
T* begin() { return pBegin_; }
|
||||
|
||||
T* end() { return pEnd_; }
|
||||
|
||||
u32 size() {
|
||||
if (pBegin_ == 0) {
|
||||
return 0;
|
||||
}
|
||||
return (int)((u32)pEnd_ - (u32)pBegin_) / 4;
|
||||
}
|
||||
|
||||
u32 capacity() { return mCapacity; }
|
||||
|
||||
u32 GetSize_extend_(u32 count) {
|
||||
JUT_ASSERT(0x22B, pfnExtend_!=0);
|
||||
|
||||
u32 oldSize = size();
|
||||
u32 neededNewSpace = oldSize + count;
|
||||
u32 extendedSize = pfnExtend_(capacity(), oldSize, count);
|
||||
|
||||
return neededNewSpace > extendedSize ? neededNewSpace : extendedSize;
|
||||
}
|
||||
|
||||
void DestroyElement_(T* start, T* end) {
|
||||
for (; start != end; start++) {
|
||||
mAllocator.destroy(start);
|
||||
}
|
||||
}
|
||||
|
||||
void DestroyElement_all_() { DestroyElement_(pBegin_, pEnd_); }
|
||||
|
||||
T* erase(T* start, T* end) {
|
||||
T* vectorEnd = pEnd_;
|
||||
T* ppvVar3 = std::copy(end, vectorEnd, start);
|
||||
DestroyElement_(ppvVar3, pEnd_);
|
||||
pEnd_ = ppvVar3;
|
||||
return start;
|
||||
}
|
||||
|
||||
void clear() { erase(begin(), end()); }
|
||||
|
||||
/* 0x00 */ Allocator mAllocator;
|
||||
/* 0x04 */ T* pBegin_;
|
||||
/* 0x08 */ T* pEnd_;
|
||||
/* 0x0C */ u32 mCapacity;
|
||||
/* 0x10 */ extendFunc pfnExtend_;
|
||||
};
|
||||
|
||||
struct TVector_pointer_void : public TVector<void*, TAllocator<void*> > {
|
||||
TVector_pointer_void(const JGadget::TAllocator<void*>& allocator);
|
||||
TVector_pointer_void(u32, void* const&,
|
||||
const JGadget::TAllocator<void*>& allocator);
|
||||
|
||||
~TVector_pointer_void();
|
||||
|
||||
void insert(void**, void* const&);
|
||||
void** erase(void**, void**);
|
||||
|
||||
void clear() { erase(begin(), end()); }
|
||||
void push_back(const void*& value) { insert(end(), (void* const&)value); }
|
||||
};
|
||||
} // namespace JGadget
|
||||
|
||||
#endif /* STD_VECTOR_H */
|
||||
|
||||
@@ -42,6 +42,13 @@ struct data {
|
||||
|
||||
struct TParse_TBlock_messageID : public TParse_TBlock {
|
||||
TParse_TBlock_messageID(const void* data) : TParse_TBlock(data) {}
|
||||
|
||||
char* get() const { return (char*)getRaw(); }
|
||||
u8 get_formSupplement() const { return *(u8*)(get() + 0xB); }
|
||||
u16 get_number() const { return *(u16*)(get() + 0x8); }
|
||||
char* getContent() const { return (char*)get() + 0x10; }
|
||||
u8 get_form() const { return *(u8*)(get() + 0xA) & 0xF; }
|
||||
bool get_isOrdered() const { return *(u8*)(get() + 0xA) & 0xF0; }
|
||||
};
|
||||
|
||||
struct TParse_TBlock_color : public TParse_TBlock {
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace JMessage {
|
||||
*/
|
||||
struct TResource {
|
||||
TResource()
|
||||
: field_0x8(NULL), field_0xc(NULL), field_0x10(NULL), field_0x14(0), field_0x18(NULL) {}
|
||||
: field_0x8(NULL), field_0xc(NULL), field_0x10(NULL), field_0x14(0), mMessageID(NULL) {}
|
||||
|
||||
/* 802A8CDC */ u16 toMessageIndex_messageID(u32, u32, bool*) const;
|
||||
|
||||
@@ -56,7 +56,7 @@ struct TResource {
|
||||
/* 0x0C */ data::TParse_TBlock_info field_0xc;
|
||||
/* 0x10 */ char* field_0x10;
|
||||
/* 0x14 */ int field_0x14;
|
||||
/* 0x18 */ data::TParse_TBlock_messageID field_0x18;
|
||||
/* 0x18 */ data::TParse_TBlock_messageID mMessageID;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user