Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some cleanup of f_pc/f_op files #2254

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def MatchingFor(*versions):
Object(Matching, "f_op/f_op_kankyo.cpp"),
Object(Matching, "f_op/f_op_msg.cpp"),
Object(Matching, "f_op/f_op_kankyo_mng.cpp"),
Object(NonMatching, "f_op/f_op_msg_mng.cpp"),
Object(Matching, "f_op/f_op_msg_mng.cpp", extra_cflags=['-pragma "nosyminline on"']),
Object(Matching, "f_op/f_op_draw_iter.cpp"),
Object(Matching, "f_op/f_op_draw_tag.cpp"),
Object(Matching, "f_op/f_op_scene_pause.cpp"),
Expand Down Expand Up @@ -927,7 +927,7 @@ def MatchingFor(*versions):
[
Object(NonMatching, "JSystem/JGadget/binary.cpp"),
Object(NonMatching, "JSystem/JGadget/linklist.cpp"),
Object(NonMatching, "JSystem/JGadget/std-vector.cpp"),
Object(Equivalent, "JSystem/JGadget/std-vector.cpp"), # just weak order
],
),
JSystemLib(
Expand Down Expand Up @@ -984,7 +984,7 @@ def MatchingFor(*versions):
Object(Matching, "JSystem/J3DGraphBase/J3DGD.cpp"),
Object(Matching, "JSystem/J3DGraphBase/J3DSys.cpp"),
Object(Matching, "JSystem/J3DGraphBase/J3DVertex.cpp"),
Object(NonMatching, "JSystem/J3DGraphBase/J3DTransform.cpp"),
Object(Matching, "JSystem/J3DGraphBase/J3DTransform.cpp"),
Object(Matching, "JSystem/J3DGraphBase/J3DTexture.cpp"),
Object(Matching, "JSystem/J3DGraphBase/J3DPacket.cpp"),
Object(NonMatching, "JSystem/J3DGraphBase/J3DShapeMtx.cpp"),
Expand Down
2 changes: 1 addition & 1 deletion include/JSystem/J3DGraphBase/J3DTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
33 changes: 33 additions & 0 deletions include/JSystem/JGadget/std-memory.h
Original file line number Diff line number Diff line change
@@ -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 */
172 changes: 172 additions & 0 deletions include/JSystem/JGadget/std-vector.h
Original file line number Diff line number Diff line change
@@ -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 */
7 changes: 7 additions & 0 deletions include/JSystem/JMessage/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions include/JSystem/JMessage/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
};

/**
Expand Down
Loading