Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/container/seadTreeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ inline TreeMapNode<Key>* TreeMapImpl<Key>::findMin(Node* node)
return node;
}

// NON_MATCHING: this version matches the LLRB tree implementation and is better optimized
template <typename Key>
inline TreeMapNode<Key>* TreeMapImpl<Key>::eraseMin(Node* node)
{
Expand All @@ -462,10 +461,11 @@ inline TreeMapNode<Key>* TreeMapImpl<Key>::eraseMin(Node* node)
if (!isRed(node->mLeft) && !isRed(node->mLeft->mLeft))
node = moveRedLeft(node);

node->mLeft = eraseMin(node->mLeft);
Node* newLeft = eraseMin(node->mLeft);
#ifdef MATCHING_HACK_NX_CLANG
asm("");
#endif
node->mLeft = newLeft;
return fixUp(node);
}

Expand Down
2 changes: 1 addition & 1 deletion include/controller/seadControllerMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ControllerMgr : public CalculateTask
class ConstructArg : public TaskConstructArg
{
public:
ConstructArg() : TaskConstructArg(), mHeapArray() { heap_array = &mHeapArray; }
ConstructArg() : TaskConstructArg() { heap_array = &mHeapArray; }

private:
HeapArray mHeapArray;
Expand Down
5 changes: 5 additions & 0 deletions include/filedevice/seadFileDeviceMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <filedevice/seadMainFileDevice.h>
#include <heap/seadDisposer.h>
#include <prim/seadSafeString.h>
#include <seadVersion.h>

namespace sead
{
Expand Down Expand Up @@ -72,8 +73,12 @@ class FileDeviceMgr
#elif defined(NNSDK)
u8* mRomCache = nullptr;
bool mMountedHost = false;
#if SEAD_VERSION == SEAD_VERSION_SMO
bool mMountedSd;
#else
bool mMountedSd = false;
#endif
#endif
};

} // namespace sead
Expand Down
4 changes: 3 additions & 1 deletion include/framework/seadGameFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace sead
{
class Thread;

class GameFramework : public Framework
{
SEAD_RTTI_OVERRIDE(GameFramework, Framework);
Expand Down Expand Up @@ -42,7 +44,7 @@ class GameFramework : public Framework
sead::SafeString mUnk1 = "";
sead::SafeString mUnk2 = "";
sead::SafeString mUnk3 = "";
[[maybe_unused]] void* mUnk4 = nullptr; // TODO: remove [[maybe_unused]] once mUnk4 is used
Thread* mUnk4 = nullptr;
void (*mUnk5)(bool) = nullptr;
void (*mUnk6)(bool);
};
Expand Down
8 changes: 4 additions & 4 deletions include/framework/seadMethodTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CriticalSection;
template <typename T, typename U>
class IDelegate2;

class MethodTreeNode : public IDisposer, public TTreeNode<MethodTreeNode*>, public INamable
class MethodTreeNode : public TTreeNode<MethodTreeNode*>, public INamable, public IDisposer
{
SEAD_RTTI_BASE(MethodTreeNode)

Expand All @@ -31,13 +31,13 @@ class MethodTreeNode : public IDisposer, public TTreeNode<MethodTreeNode*>, publ

using PauseEventDelegate = IDelegate2<MethodTreeNode*, PauseFlag>;

// NON_MATCHING: stores for mPauseFlag, mPauseEventDelegate, mUserID
explicit MethodTreeNode(CriticalSection* cs) : TTreeNode(this)
{
mCriticalSection = cs;
mPauseEventDelegate = nullptr;
mUserID = nullptr;
mCriticalSection = cs;
mDelegateHolder.construct(sead::Delegate<MethodTreeNode>());
mUserID = nullptr;
mPauseFlag = cPause_None;
setPauseFlag(cPause_Both);
}

Expand Down
11 changes: 9 additions & 2 deletions include/mc/seadJobQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "mc/seadJob.h"
#include "prim/seadEnum.h"
#include "prim/seadNamable.h"
#include "seadVersion.h"
#include "thread/seadAtomic.h"
#include "thread/seadEvent.h"

Expand Down Expand Up @@ -36,9 +37,15 @@ class PerfJobQueue
void detachProcessMeter();

private:
#ifdef SEAD_DEBUG
Buffer<MultiProcessMeterBar<512>> mBars;
Buffer<u32> mInts;
MultiProcessMeterBar<1> mProcessMeterBar;
#else
Buffer<SafeString> mBars;
Buffer<u32> mInts;
SafeString mProcessMeterBar;
#endif
};

class JobQueueLock
Expand Down Expand Up @@ -112,13 +119,13 @@ class JobQueue : public hostio::Node, public INamable
CoreIdMask mMask;
Event mFinishEvent{true};
SafeArray<u32, 3> mGranularity;
SafeArray<u32, 3> mCoreEnabled;
SafeArray<volatile u32, 3> mCoreEnabled; // volatile required for setCoreMaskAndWaitType
Atomic<u32> mNumDoneJobs = 0;

Atomic<Status> mStatus = Status::_0;
const char* mDescription = "NoName";

#ifdef SEAD_DEBUG
#if defined(SEAD_DEBUG) || SEAD_VERSION == SEAD_VERSION_SMO
PerfJobQueue mPerf;
#endif
};
Expand Down
2 changes: 2 additions & 0 deletions include/prim/seadDelegateEventSlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class DelegateEvent
bool mConnectedToDelegateEvent = false;
};

DelegateEvent() {}

virtual ~DelegateEvent()
{
auto it = mList.begin();
Expand Down
4 changes: 3 additions & 1 deletion modules/src/basis/seadNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace sead
{
namespace system
{
void* NewImpl(Heap* heap, size_t size, s32 alignment, bool abortOnFailure)
void* NewImpl(Heap* heap, size_t size, s32 alignment, bool abortOnFailure [[maybe_unused]])
{
if (!HeapMgr::sInstancePtr)
{
Expand All @@ -27,13 +27,15 @@ void* NewImpl(Heap* heap, size_t size, s32 alignment, bool abortOnFailure)
}

void* result = heap->tryAlloc(size, alignment);
#ifdef SEAD_DEBUG
if (!result && abortOnFailure)
{
SEAD_ASSERT_MSG(
false, "alloc failed. size: %zu, allocatable size: %zu, alignment: %d, heap: %s", size,
heap->getMaxAllocatableSize(alignment), alignment, heap->getName().cstr());
return nullptr;
}
#endif
return result;
}

Expand Down
43 changes: 39 additions & 4 deletions modules/src/container/seadPtrArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ void PtrArrayImpl::erase(s32 pos, s32 count)
mPtrNum -= count;
}

// NON_MATCHING: semantically equivalent
void PtrArrayImpl::reverse()
{
for (s32 i = 0; i < mPtrNum / 2; ++i)
const s32 half = mPtrNum / 2;
for (s32 i = 0; i < half; ++i)
swap(mPtrNum - i - 1, i);
}

Expand Down Expand Up @@ -145,8 +145,43 @@ bool PtrArrayImpl::checkInsert(s32 pos, s32 num)

void PtrArrayImpl::sort(CompareCallbackImpl cmp)
{
// Note: Nintendo did not use <algorithm>
std::sort(mPtrs, mPtrs + size(), [&](const void* a, const void* b) { return cmp(a, b) < 0; });
if (mPtrNum < 2)
return;

void** ptrs = mPtrs;
s32 begin = 0;
s32 end = mPtrNum - 1;
do
{
s32 last = begin;
for (s32 i = begin; i < end; ++i)
{
if (cmp(ptrs[i], ptrs[i + 1]) > 0)
{
void* tmp = ptrs[i + 1];
ptrs[i + 1] = ptrs[i];
ptrs[i] = tmp;
last = i;
}
}

end = last;
if (begin == end)
break;

last = end;
for (s32 i = end; i > begin; --i)
{
if (cmp(ptrs[i], ptrs[i - 1]) < 0)
{
void* tmp = ptrs[i - 1];
ptrs[i - 1] = ptrs[i];
ptrs[i] = tmp;
last = i;
}
}
begin = last;
} while (begin != end);
}

// TODO: PtrArrayImpl::heapSort
Expand Down
32 changes: 8 additions & 24 deletions modules/src/container/seadTreeNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,34 +78,18 @@ void TreeNode::detachSubTree()

TreeNode* TreeNode::findRoot()
{
if (!mParent)
return this;

TreeNode* p = mParent;
TreeNode* root;
do
{
root = p;
SEAD_ASSERT(p != this);
p = p->mParent;
} while (p);
return root;
TreeNode* node = this;
while (node->mParent)
node = node->mParent;
return node;
}

const TreeNode* TreeNode::findRoot() const
{
if (!mParent)
return this;

TreeNode* p = mParent;
TreeNode* root;
do
{
root = p;
SEAD_ASSERT(p != this);
p = p->mParent;
} while (p);
return root;
const TreeNode* node = this;
while (node->mParent)
node = node->mParent;
return node;
}

void TreeNode::insertAfterSelf(TreeNode* node)
Expand Down
13 changes: 4 additions & 9 deletions modules/src/controller/seadControllerMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace sead
{
SEAD_TASK_SINGLETON_IMPL(ControllerMgr)

// NON_MATCHING: storing too much 00s into stack (for ConstructArg)
ControllerMgr::ControllerMgr() : CalculateTask(ConstructArg(), "sead::ControllerMgr")
{
mDevices.initOffset(offsetof(ControlDevice, mListNode));
Expand Down Expand Up @@ -67,15 +66,11 @@ void ControllerMgr::initializeDefault(Heap* heap)
void ControllerMgr::finalizeDefault()
{
#ifdef NNSDK
// NON_MATCHING: missing cbz instruction within loop
for (auto& device : mDevices)
ControlDevice* device = getControlDevice(ControllerDefine::DeviceId::cDevice_NinJoyNpad);
if (device)
{
if (device.getId() == 13)
{
mDevices.erase(&device);
delete &device;
break;
}
mDevices.erase(device);
delete device;
}
#endif // cafe

Expand Down
25 changes: 20 additions & 5 deletions modules/src/filedevice/nin/seadNinFileDeviceBaseNin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ NinFileDeviceBase::NinFileDeviceBase(const SafeString& name, const SafeString& m
{
}

// NON_MATCHING: inverted branching for should_set_size
FileDevice* NinFileDeviceBase::doOpen_(FileHandle* handle, const SafeString& path,
FileDevice::FileOpenFlag flag)
{
Expand All @@ -47,7 +46,7 @@ FileDevice* NinFileDeviceBase::doOpen_(FileHandle* handle, const SafeString& pat
bool should_set_size = true;
if ((flag | cFileOpenFlag_ReadWrite) == cFileOpenFlag_Create)
{
bool is_file = false;
u32 is_file = false;
nn::fs::DirectoryEntryType type;
const auto result = nn::fs::GetEntryType(&type, fs_path.cstr());
if (result.IsSuccess())
Expand All @@ -64,14 +63,14 @@ FileDevice* NinFileDeviceBase::doOpen_(FileHandle* handle, const SafeString& pat
return nullptr;
}

should_set_size = flag == cFileOpenFlag_Create || !is_file;
if (flag == cFileOpenFlag_Create || !is_file)
if (flag == cFileOpenFlag_Create)
{
if (is_file)
if (is_file != 0)
{
mLastError = nn::fs::ResultPathAlreadyExists();
return nullptr;
}

const auto create_result = nn::fs::CreateFile(fs_path.cstr(), 0);
if (create_result.IsFailure())
{
Expand All @@ -83,6 +82,22 @@ FileDevice* NinFileDeviceBase::doOpen_(FileHandle* handle, const SafeString& pat
return nullptr;
}
}
else
{
if (is_file == 1)
{
should_set_size = false;
}
else
{
const auto create_result = nn::fs::CreateFile(fs_path.cstr(), 0);
if (create_result.IsFailure())
{
mLastError = create_result;
return nullptr;
}
}
}
}

auto* handle_inner = getFileHandleInner_(handle, true);
Expand Down
4 changes: 2 additions & 2 deletions modules/src/filedevice/seadArchiveFileDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ u8* ArchiveFileDevice::doLoadWithEntryID_(s32 entry_id, LoadArg& arg)
if (!buffer)
{
const s32 aligment_sign = Mathi::sign(arg.alignment);
const s32 alignment = std::max(Mathi::abs(arg.alignment), 32);
const s32 alignment = Mathi::abs(arg.alignment) > 32 ? Mathi::abs(arg.alignment) : 32;
buffer = new (arg.heap, alignment * aligment_sign) u8[buffer_size];
buffer_allocated = true;
}
Expand All @@ -199,8 +199,8 @@ u8* ArchiveFileDevice::doLoadWithEntryID_(s32 entry_id, LoadArg& arg)
}

arg.read_size = bytes_read;
arg.need_unload = buffer_allocated;
arg.roundup_size = buffer_size;
arg.need_unload = buffer_allocated;
return buffer;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/src/filedevice/seadFileDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ u8* FileDevice::doLoad_(LoadArg& arg)
{
const s32 sign = (arg.alignment < 0) ? -1 : 1;
s32 alignment = Mathi::abs(arg.alignment);
alignment = sign * ((alignment < cBufferMinAlignment) ? cBufferMinAlignment : alignment);
alignment = sign * ((alignment > cBufferMinAlignment) ? alignment : cBufferMinAlignment);

Heap* heap = arg.heap;
if (!heap)
Expand Down
Loading