mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-04-19 03:20:11 +03:00
feat(model): properly handle IsDrawable and WaitForLoad calls
This commit is contained in:
parent
5e3d08bf32
commit
961c722825
@ -2,6 +2,7 @@
|
|||||||
#include "util/SFile.hpp"
|
#include "util/SFile.hpp"
|
||||||
#include <common/Prop.hpp>
|
#include <common/Prop.hpp>
|
||||||
#include <common/Time.hpp>
|
#include <common/Time.hpp>
|
||||||
|
#include <storm/Error.hpp>
|
||||||
|
|
||||||
uint32_t AsyncFileRead::s_threadSleep;
|
uint32_t AsyncFileRead::s_threadSleep;
|
||||||
uint32_t AsyncFileRead::s_handlerTimeout = 100;
|
uint32_t AsyncFileRead::s_handlerTimeout = 100;
|
||||||
@ -25,6 +26,7 @@ TSList<CAsyncQueue, TSGetLink<CAsyncQueue>> AsyncFileRead::s_asyncQueueList;
|
|||||||
TSList<CAsyncThread, TSGetLink<CAsyncThread>> AsyncFileRead::s_asyncThreadList;
|
TSList<CAsyncThread, TSGetLink<CAsyncThread>> AsyncFileRead::s_asyncThreadList;
|
||||||
STORM_EXPLICIT_LIST(CAsyncObject, link) AsyncFileRead::s_asyncFileReadPostList;
|
STORM_EXPLICIT_LIST(CAsyncObject, link) AsyncFileRead::s_asyncFileReadPostList;
|
||||||
STORM_EXPLICIT_LIST(CAsyncObject, link) AsyncFileRead::s_asyncFileReadFreeList;
|
STORM_EXPLICIT_LIST(CAsyncObject, link) AsyncFileRead::s_asyncFileReadFreeList;
|
||||||
|
int32_t AsyncFileRead::s_waiting;
|
||||||
|
|
||||||
CAsyncQueue* AsyncFileReadCreateQueue() {
|
CAsyncQueue* AsyncFileReadCreateQueue() {
|
||||||
CAsyncQueue* queue = AsyncFileRead::s_asyncQueueList.NewNode(0, 2, 0x8);
|
CAsyncQueue* queue = AsyncFileRead::s_asyncQueueList.NewNode(0, 2, 0x8);
|
||||||
@ -194,3 +196,51 @@ uint32_t AsyncFileReadThread(void* param) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AsyncFileReadWait(CAsyncObject* object) {
|
||||||
|
STORM_ASSERT(object);
|
||||||
|
|
||||||
|
AsyncFileRead::s_waiting++;
|
||||||
|
|
||||||
|
AsyncFileRead::s_queueLock.Enter();
|
||||||
|
|
||||||
|
if (object->isProcessed) {
|
||||||
|
AsyncFileRead::s_queueLock.Leave();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncFileRead::s_asyncWaitObject = object;
|
||||||
|
|
||||||
|
if (!object->isCurrent && !object->isRead) {
|
||||||
|
object->link.Unlink();
|
||||||
|
object->queue->readList.LinkToHead(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncFileRead::s_queueLock.Leave();
|
||||||
|
|
||||||
|
if (SFile::IsStreamingMode()) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
if (AsyncFileRead::s_ingameStartCallback) {
|
||||||
|
// TODO AsyncFileRead::s_ingameStartCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (AsyncFileRead::s_ingameProgressCallback) {
|
||||||
|
// TODO AsyncFileRead::s_ingameProgressCallback(0.0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncFileReadPollHandler(nullptr, nullptr);
|
||||||
|
|
||||||
|
if (!AsyncFileRead::s_asyncWaitObject) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
OsSleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncFileRead::s_waiting--;
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@ class AsyncFileRead {
|
|||||||
static TSList<CAsyncThread, TSGetLink<CAsyncThread>> s_asyncThreadList;
|
static TSList<CAsyncThread, TSGetLink<CAsyncThread>> s_asyncThreadList;
|
||||||
static STORM_EXPLICIT_LIST(CAsyncObject, link) s_asyncFileReadPostList;
|
static STORM_EXPLICIT_LIST(CAsyncObject, link) s_asyncFileReadPostList;
|
||||||
static STORM_EXPLICIT_LIST(CAsyncObject, link) s_asyncFileReadFreeList;
|
static STORM_EXPLICIT_LIST(CAsyncObject, link) s_asyncFileReadFreeList;
|
||||||
|
static int32_t s_waiting;
|
||||||
};
|
};
|
||||||
|
|
||||||
CAsyncQueue* AsyncFileReadCreateQueue();
|
CAsyncQueue* AsyncFileReadCreateQueue();
|
||||||
@ -43,4 +44,6 @@ int32_t AsyncFileReadPollHandler(const void* a1, void* a2);
|
|||||||
|
|
||||||
uint32_t AsyncFileReadThread(void* thread);
|
uint32_t AsyncFileReadThread(void* thread);
|
||||||
|
|
||||||
|
void AsyncFileReadWait(CAsyncObject* object);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "model/CM2Model.hpp"
|
#include "model/CM2Model.hpp"
|
||||||
|
#include "async/AsyncFileRead.hpp"
|
||||||
#include "math/Types.hpp"
|
#include "math/Types.hpp"
|
||||||
#include "model/CM2Scene.hpp"
|
#include "model/CM2Scene.hpp"
|
||||||
#include "model/CM2Shared.hpp"
|
#include "model/CM2Shared.hpp"
|
||||||
@ -1020,7 +1021,33 @@ int32_t CM2Model::IsBatchDoodadCompatible(M2Batch* batch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t CM2Model::IsDrawable(int32_t a2, int32_t a3) {
|
int32_t CM2Model::IsDrawable(int32_t a2, int32_t a3) {
|
||||||
|
if (!this->m_loaded && a2) {
|
||||||
|
this->WaitForLoad(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this->m_flag2) {
|
||||||
|
if (!this->m_loaded) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < this->m_shared->m_data->textures.Count(); i++) {
|
||||||
|
auto texture = this->m_textures[i];
|
||||||
|
|
||||||
|
if (!texture) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TextureGetGxTex(texture, a2, nullptr)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->m_flag2 = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this->m_flag200 && a3) {
|
||||||
// TODO
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1501,5 +1528,15 @@ void CM2Model::UpdateLoaded() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CM2Model::WaitForLoad(const char* a2) {
|
void CM2Model::WaitForLoad(const char* a2) {
|
||||||
// TODO
|
if (this->m_shared->asyncObject) {
|
||||||
|
AsyncFileReadWait(this->m_shared->asyncObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->m_shared->asyncObject) {
|
||||||
|
AsyncFileReadWait(this->m_shared->asyncObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->m_flags & 0x20) {
|
||||||
|
this->InitializeLoaded();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user