Skip to content

Commit

Permalink
Merge pull request #1569 from paulsapps/master
Browse files Browse the repository at this point in the history
prevent LoadingFiles being undeterminstic
  • Loading branch information
Paul committed Sep 17, 2022
2 parents ee1738a + 700538a commit 0a02018
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 44 deletions.
27 changes: 27 additions & 0 deletions Source/AliveLibAO/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

namespace AO {

DynamicArrayT<BaseGameObject>* gLoadingFiles = nullptr;

// TODO: Move these few funcs to correct location
#ifdef _WIN32
Expand Down Expand Up @@ -331,6 +332,9 @@ EXPORT void CC Init_Sound_DynamicArrays_And_Others_41CD20()
gBaseAliveGameObjects_4FC8A0 = ao_new<DynamicArrayT<BaseAliveGameObject>>();
gBaseAliveGameObjects_4FC8A0->ctor_4043E0(20);

gLoadingFiles = ao_new<DynamicArrayT<BaseGameObject>>();
gLoadingFiles->ctor_4043E0(20); // TODO: Leaked on purpose for now

ResourceManager::Init_454DA0();
SND_Init_476E40();
SND_Init_Ambiance_4765C0();
Expand Down Expand Up @@ -433,6 +437,29 @@ EXPORT void CC Game_Loop_437630()
}
}
}

for (s32 i = 0; i < gLoadingFiles->Size(); i++)
{
BaseGameObject* pObjIter = gLoadingFiles->ItemAt(i);
if (pObjIter->field_6_flags.Get(BaseGameObject::eUpdatable_Bit2) && !pObjIter->field_6_flags.Get(BaseGameObject::eDead_Bit3) && (sNumCamSwappers_507668 == 0 || pObjIter->field_6_flags.Get(BaseGameObject::eUpdateDuringCamSwap_Bit10)))
{
if (pObjIter->field_8_update_delay > 0)
{
pObjIter->field_8_update_delay--;
}
else
{
pObjIter->VUpdate();
}
}

if (pObjIter->field_6_flags.Get(BaseGameObject::eDead_Bit3) && pObjIter->field_C_refCount == 0)
{
i = gLoadingFiles->RemoveAt(i);
pObjIter->VDestructor(1);
}
}

GetGameAutoPlayer().SyncPoint(SyncPoints::EndGameObjectUpdate);

// Animate everything
Expand Down
1 change: 1 addition & 0 deletions Source/AliveLibAO/Game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ALIVE_VAR_EXTERN(u32, gnFrameCount_507670);
ALIVE_VAR_EXTERN(s16, gAttract_507698);
ALIVE_VAR_EXTERN(DynamicArrayT<BaseGameObject>*, gObjList_drawables_504618);
ALIVE_VAR_EXTERN(DynamicArrayT<AnimationBase>*, gObjList_animations_505564);
extern DynamicArrayT<BaseGameObject>* gLoadingFiles;
ALIVE_VAR_EXTERN(s16, sBreakGameLoop_507B78);
ALIVE_VAR_EXTERN(s8, gDDCheatMode_508BF8);

Expand Down
27 changes: 9 additions & 18 deletions Source/AliveLibAO/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,33 +1332,24 @@ void Menu::WaitForAbeSayHello_47B770()
void Menu::ProgressInProgressFilesLoading()
{
TRACE_ENTRYEXIT;
bool loadingFileExists = false;
do
{
LOG_INFO("Start iteration");
for (s32 i = 0; i < gBaseGameObject_list_9F2DF0->Size(); i++)
for (s32 i = 0; i < gLoadingFiles->Size(); i++)
{
BaseGameObject* pObjIter = gBaseGameObject_list_9F2DF0->ItemAt(i);
if (!pObjIter)
auto pObj = gLoadingFiles->ItemAt(i);

if (pObj->field_6_flags.Get(BaseGameObject::eDead_Bit3) && pObj->field_C_refCount == 0)
{
break;
i = gLoadingFiles->RemoveAt(i);
pObj->VDestructor(1);
}

if (pObjIter->field_4_typeId == Types::eLoadingFile_39)
else
{
pObjIter->VUpdate();
if (pObjIter->field_6_flags.Get(BaseGameObject::eDead_Bit3))
{
LOG_INFO("Removing dead loading file idx " << i);
i = gBaseGameObject_list_9F2DF0->RemoveAt(i);
pObjIter->VDestructor(1);
LOG_INFO("Idx is now " << i);
}
loadingFileExists = true;
pObj->VUpdate();
}
}
}
while (loadingFileExists);
while (!gLoadingFiles->Empty());
}

void Menu::MainScreen_Render_47BED0(PrimHeader** ppOt)
Expand Down
52 changes: 26 additions & 26 deletions Source/AliveLibAO/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ EXPORT void CC Odd_Sleep_48DD90(u32 /*dwMilliseconds*/)
ALIVE_VAR(1, 0x507714, s32, gFilesPending_507714, 0);
ALIVE_VAR(1, 0x50768C, s16, bLoadingAFile_50768C, 0);

class LoadingFile final : public BaseGameObject
class LoadingFile final : public BaseGameObject
{
public:
EXPORT LoadingFile* ctor_41E8A0(s32 pos, s32 size, TLoaderFn pFn, void* fnArg, Camera* pArray)
{
ctor_487E10(1);
ctor_487E10(0); // DON'T add to BGE list

SetVTable(this, 0x4BB088);

Expand All @@ -72,13 +72,18 @@ class LoadingFile final : public BaseGameObject
PSX_Pos_To_CdLoc_49B340(pos, &field_2A_cdLoc);

field_28_state = 0;

gLoadingFiles->Push_Back(this);

return this;
}

EXPORT BaseGameObject* dtor_41E870()
{
SetVTable(this, 0x4BB088);

gLoadingFiles->Remove_Item(this);

gFilesPending_507714--;

if (field_28_state != 0)
Expand Down Expand Up @@ -508,29 +513,26 @@ void CC ResourceManager::LoadResourcesFromList_446E80(const char_type* pFileName

void CC ResourceManager::WaitForPendingResources_41EA60(BaseGameObject* pObj)
{
for (s32 i = 0; i < gBaseGameObject_list_9F2DF0->Size(); i++)
for (s32 i = 0; i < gLoadingFiles->Size(); i++)
{
BaseGameObject* pObjIter = gBaseGameObject_list_9F2DF0->ItemAt(i);
BaseGameObject* pObjIter = gLoadingFiles->ItemAt(i);
if (!pObjIter)
{
break;
}

if (pObjIter->field_4_typeId == Types::eLoadingFile_39)
auto pLoadingFile = static_cast<LoadingFile*>(pObjIter);
if (!pObj || pObj == pLoadingFile->field_18_fn_arg)
{
auto pLoadingFile = static_cast<LoadingFile*>(pObjIter);
if (!pObj || pObj == pLoadingFile->field_18_fn_arg)
while (pLoadingFile->field_28_state != 0)
{
while (pLoadingFile->field_28_state != 0)
if (pLoadingFile->field_6_flags.Get(BaseGameObject::eDead_Bit3))
{
if (pLoadingFile->field_6_flags.Get(BaseGameObject::eDead_Bit3))
{
break;
}
pLoadingFile->VUpdate();
break;
}
pLoadingFile->field_6_flags.Set(BaseGameObject::eDead_Bit3);
pLoadingFile->VUpdate();
}
pLoadingFile->field_6_flags.Set(BaseGameObject::eDead_Bit3);
}
}
}
Expand All @@ -539,30 +541,28 @@ EXPORT void CC ResourceManager::LoadingLoop_41EAD0(s16 bShowLoadingIcon)
{
GetGameAutoPlayer().DisableRecorder();


while (gFilesPending_507714 > 0)
{
SYS_EventsPump_44FF90();

for (s32 i = 0; i < gBaseGameObject_list_9F2DF0->Size(); i++)
for (s32 i = 0; i < gLoadingFiles->Size(); i++)
{
BaseGameObject* pObjIter = gBaseGameObject_list_9F2DF0->ItemAt(i);
BaseGameObject* pObjIter = gLoadingFiles->ItemAt(i);
if (!pObjIter)
{
break;
}

if (pObjIter->field_4_typeId == Types::eLoadingFile_39)
if (!pObjIter->field_6_flags.Get(BaseGameObject::eDead_Bit3))
{
if (!pObjIter->field_6_flags.Get(BaseGameObject::eDead_Bit3))
{
pObjIter->VUpdate();
}
pObjIter->VUpdate();
}

if (pObjIter->field_6_flags.Get(BaseGameObject::eDead_Bit3))
{
i = gBaseGameObject_list_9F2DF0->RemoveAt(i);
pObjIter->VDestructor(1);
}
if (pObjIter->field_6_flags.Get(BaseGameObject::eDead_Bit3))
{
i = gLoadingFiles->RemoveAt(i);
pObjIter->VDestructor(1);
}
}

Expand Down

0 comments on commit 0a02018

Please sign in to comment.