Reorganize sources and files (#414)

* Reorganize sources

* Refactor

* Remove relative paths

* Renames

* Fix gitignore

* Remove stuff

* Try fixing format script

* Fix format

* Fix format

* Fix naming script

* Test format

* Fix format
This commit is contained in:
Christian Semmler
2024-01-08 04:58:49 -05:00
committed by GitHub
parent 6a85e62406
commit c47206617d
447 changed files with 347 additions and 346 deletions

View File

@@ -0,0 +1,16 @@
#include "mxautolocker.h"
// FUNCTION: LEGO1 0x100b8ed0
MxAutoLocker::MxAutoLocker(MxCriticalSection* p_criticalSection)
{
this->m_criticalSection = p_criticalSection;
if (this->m_criticalSection != 0)
this->m_criticalSection->Enter();
}
// FUNCTION: LEGO1 0x100b8ef0
MxAutoLocker::~MxAutoLocker()
{
if (this->m_criticalSection != 0)
this->m_criticalSection->Leave();
}

View File

@@ -0,0 +1,76 @@
#include "mxcriticalsection.h"
#include "decomp.h"
#include <stdio.h>
DECOMP_SIZE_ASSERT(MxCriticalSection, 0x1c);
// GLOBAL: LEGO1 0x10101e78
int g_useMutex = 0;
// FUNCTION: LEGO1 0x100b6d20
MxCriticalSection::MxCriticalSection()
{
HANDLE mutex;
if (g_useMutex != 0) {
mutex = CreateMutexA(NULL, FALSE, NULL);
this->m_mutex = mutex;
return;
}
InitializeCriticalSection(&this->m_criticalSection);
this->m_mutex = NULL;
}
// FUNCTION: LEGO1 0x100b6d60
MxCriticalSection::~MxCriticalSection()
{
if (this->m_mutex != NULL) {
CloseHandle(this->m_mutex);
return;
}
DeleteCriticalSection(&this->m_criticalSection);
}
// FUNCTION: LEGO1 0x100b6d80
void MxCriticalSection::Enter()
{
DWORD result;
FILE* file;
if (this->m_mutex != NULL) {
result = WaitForSingleObject(this->m_mutex, 5000);
if (result == WAIT_FAILED) {
file = fopen("C:\\DEADLOCK.TXT", "a");
if (file != NULL) {
fprintf(file, "mutex timeout occurred!\n");
fclose(file);
}
abort();
}
}
else {
EnterCriticalSection(&this->m_criticalSection);
}
}
// FUNCTION: LEGO1 0x100b6de0
void MxCriticalSection::Leave()
{
if (this->m_mutex != NULL) {
ReleaseMutex(this->m_mutex);
return;
}
LeaveCriticalSection(&this->m_criticalSection);
}
// FUNCTION: LEGO1 0x100b6e00
void MxCriticalSection::SetDoMutex()
{
g_useMutex = 1;
}

View File

@@ -0,0 +1,14 @@
#include "mxscheduler.h"
// FUNCTION: LEGO1 0x100bf4f0
MxScheduler* MxScheduler::GetInstance()
{
// Intentionally empty
return 0;
}
// FUNCTION: LEGO1 0x100bf500
void MxScheduler::StartMultiTasking(MxULong)
{
// Intentionally empty
}

View File

@@ -0,0 +1,33 @@
#include "mxsemaphore.h"
#include "decomp.h"
DECOMP_SIZE_ASSERT(MxSemaphore, 0x08)
// FUNCTION: LEGO1 0x100c87d0
MxSemaphore::MxSemaphore()
{
m_hSemaphore = NULL;
}
// FUNCTION: LEGO1 0x100c8800
MxResult MxSemaphore::Init(MxU32 p_initialCount, MxU32 p_maxCount)
{
MxResult result = FAILURE;
if (m_hSemaphore = CreateSemaphoreA(NULL, p_initialCount, p_maxCount, NULL))
result = SUCCESS;
return result;
}
// FUNCTION: LEGO1 0x100c8830
void MxSemaphore::Wait(MxU32 p_timeoutMS)
{
WaitForSingleObject(m_hSemaphore, p_timeoutMS);
}
// FUNCTION: LEGO1 0x100c8850
void MxSemaphore::Release(MxU32 p_releaseCount)
{
ReleaseSemaphore(m_hSemaphore, p_releaseCount, NULL);
}

View File

@@ -0,0 +1,97 @@
#include "mxthread.h"
#include "decomp.h"
#include "mxomni.h"
#include "mxtimer.h"
#include <process.h>
DECOMP_SIZE_ASSERT(MxThread, 0x1c)
DECOMP_SIZE_ASSERT(MxTickleThread, 0x20)
// FUNCTION: LEGO1 0x100b8bb0
MxTickleThread::MxTickleThread(MxCore* p_target, MxS32 p_frequencyMS)
{
m_target = p_target;
m_frequencyMS = p_frequencyMS;
}
// Match except for register allocation
// FUNCTION: LEGO1 0x100b8c90
MxResult MxTickleThread::Run()
{
MxTimer* timer = Timer();
MxS32 lastTickled = -m_frequencyMS;
while (IsRunning()) {
MxLong currentTime = timer->GetTime();
if (currentTime < lastTickled) {
lastTickled = -m_frequencyMS;
}
MxS32 timeRemainingMS = (m_frequencyMS - currentTime) + lastTickled;
if (timeRemainingMS <= 0) {
m_target->Tickle();
timeRemainingMS = 0;
lastTickled = currentTime;
}
Sleep(timeRemainingMS);
}
return MxThread::Run();
}
// FUNCTION: LEGO1 0x100bf510
MxThread::MxThread()
{
m_hThread = NULL;
m_running = TRUE;
m_threadId = 0;
}
// FUNCTION: LEGO1 0x100bf5a0
MxThread::~MxThread()
{
if (m_hThread)
CloseHandle((HANDLE) m_hThread);
}
typedef unsigned(__stdcall* ThreadFunc)(void*);
// FUNCTION: LEGO1 0x100bf610
MxResult MxThread::Start(MxS32 p_stack, MxS32 p_flag)
{
MxResult result = FAILURE;
if (m_semaphore.Init(0, 1) == SUCCESS) {
if (m_hThread =
_beginthreadex(NULL, p_stack << 2, (ThreadFunc) &MxThread::ThreadProc, this, p_flag, &m_threadId))
result = SUCCESS;
}
return result;
}
// FUNCTION: LEGO1 0x100bf660
void MxThread::Sleep(MxS32 p_milliseconds)
{
::Sleep(p_milliseconds);
}
// FUNCTION: LEGO1 0x100bf670
void MxThread::Terminate()
{
m_running = FALSE;
m_semaphore.Wait(INFINITE);
}
// FUNCTION: LEGO1 0x100bf680
unsigned MxThread::ThreadProc(void* p_thread)
{
return static_cast<MxThread*>(p_thread)->Run();
}
// FUNCTION: LEGO1 0x100bf690
MxResult MxThread::Run()
{
m_semaphore.Release(1);
return SUCCESS;
}