IOWinManager implementation optimizations

This commit is contained in:
Jack Andersen 2015-08-25 20:38:45 -10:00
parent a9cfd21ebc
commit acb3c549f5
6 changed files with 102 additions and 68 deletions

View File

@ -11,7 +11,7 @@ bool CIOWinManager::OnIOWinMessage(const CArchitectureMessage& msg)
case MsgRemoveIOWin:
{
const CArchMsgParmVoidPtr& parm = MakeMsg::GetParmDeleteIOWin(msg);
rstl::rc_ptr<CIOWin> iow = FindIOWin(*static_cast<const std::string*>(parm.x4_parm1));
CIOWin* iow = FindIOWin(*static_cast<const std::string*>(parm.x4_parm1));
if (iow)
RemoveIOWin(iow);
return false;
@ -26,7 +26,7 @@ bool CIOWinManager::OnIOWinMessage(const CArchitectureMessage& msg)
case MsgChangeIOWinPriority:
{
const CArchMsgParmInt32Int32VoidPtr& parm = MakeMsg::GetParmChangeIOWinPriority(msg);
rstl::rc_ptr<CIOWin> iow = FindIOWin(*static_cast<const std::string*>(parm.xc_parm3));
CIOWin* iow = FindIOWin(*static_cast<const std::string*>(parm.xc_parm3));
if (iow)
ChangeIOWinPriority(iow, parm.x4_parm1, parm.x8_parm2);
return false;
@ -43,19 +43,19 @@ bool CIOWinManager::OnIOWinMessage(const CArchitectureMessage& msg)
void CIOWinManager::Draw() const
{
IOWinPQNode* node = x0_rootDraw;
IOWinPQNode* node = x0_drawRoot;
while (node)
{
rstl::rc_ptr<CIOWin> iow = node->GetIOWin();
CIOWin* iow = node->GetIOWin();
iow->PreDraw();
if (!iow->GetIsContinueDraw())
break;
node = node->x8_next;
}
node = x0_rootDraw;
node = x0_drawRoot;
while (node)
{
rstl::rc_ptr<CIOWin> iow = node->GetIOWin();
CIOWin* iow = node->GetIOWin();
iow->Draw();
if (!iow->GetIsContinueDraw())
break;
@ -66,10 +66,10 @@ void CIOWinManager::Draw() const
bool CIOWinManager::DistributeOneMessage(const CArchitectureMessage& msg,
CArchitectureQueue& queue)
{
CIOWinManager::IOWinPQNode* node = x4_rootPump;
IOWinPQNode* node = x4_pumpRoot;
while (node)
{
rstl::rc_ptr<CIOWin> iow = node->GetIOWin();
CIOWin* iow = node->GetIOWin();
CIOWin::EMessageReturn mret = iow->OnMessage(msg, x8_internalQueue);
while (x8_internalQueue)
@ -120,23 +120,48 @@ void CIOWinManager::PumpMessages(CArchitectureQueue& queue)
}
}
rstl::rc_ptr<CIOWin> CIOWinManager::FindIOWin(const std::string& name)
CIOWin* CIOWinManager::FindIOWin(const std::string& name)
{
size_t findHash = std::hash<std::string>()(name);
CIOWinManager::IOWinPQNode* node = x4_rootPump;
IOWinPQNode* node = x4_pumpRoot;
while (node)
{
rstl::rc_ptr<CIOWin> iow = node->GetIOWin();
CIOWin* iow = node->GetIOWin();
if (iow->GetNameHash() == findHash)
return iow;
node = node->x8_next;
}
node = x0_rootDraw;
node = x0_drawRoot;
while (node)
{
rstl::rc_ptr<CIOWin> iow = node->GetIOWin();
CIOWin* iow = node->GetIOWin();
if (iow->GetNameHash() == findHash)
return iow;
node = node->x8_next;
}
return nullptr;
}
rstl::rc_ptr<CIOWin> CIOWinManager::FindAndShareIOWin(const std::string& name)
{
size_t findHash = std::hash<std::string>()(name);
IOWinPQNode* node = x4_pumpRoot;
while (node)
{
rstl::rc_ptr<CIOWin> iow = node->ShareIOWin();
if (iow->GetNameHash() == findHash)
return iow;
node = node->x8_next;
}
node = x0_drawRoot;
while (node)
{
rstl::rc_ptr<CIOWin> iow = node->ShareIOWin();
if (iow->GetNameHash() == findHash)
return iow;
node = node->x8_next;
@ -145,20 +170,20 @@ rstl::rc_ptr<CIOWin> CIOWinManager::FindIOWin(const std::string& name)
return rstl::rc_ptr<CIOWin>();
}
void CIOWinManager::ChangeIOWinPriority(rstl::ncrc_ptr<CIOWin> chIow, int pumpPrio, int drawPrio)
void CIOWinManager::ChangeIOWinPriority(CIOWin* toChange, int pumpPrio, int drawPrio)
{
CIOWinManager::IOWinPQNode* node = x4_rootPump;
CIOWinManager::IOWinPQNode* prevNode = nullptr;
IOWinPQNode* node = x4_pumpRoot;
IOWinPQNode* prevNode = nullptr;
while (node)
{
rstl::rc_ptr<CIOWin> iow = node->GetIOWin();
if (iow == chIow)
CIOWin* iow = node->GetIOWin();
if (iow == toChange)
{
if (prevNode)
prevNode->x8_next = node->x8_next;
node->x4_prio = pumpPrio;
CIOWinManager::IOWinPQNode* testNode = x4_rootPump;
CIOWinManager::IOWinPQNode* testPrevNode = nullptr;
IOWinPQNode* testNode = x4_pumpRoot;
IOWinPQNode* testPrevNode = nullptr;
while (testNode->x4_prio > pumpPrio)
{
testPrevNode = testNode;
@ -168,25 +193,25 @@ void CIOWinManager::ChangeIOWinPriority(rstl::ncrc_ptr<CIOWin> chIow, int pumpPr
if (testPrevNode)
testPrevNode->x8_next = node;
else
x4_rootPump = node;
x4_pumpRoot = node;
break;
}
prevNode = node;
node = node->x8_next;
}
node = x0_rootDraw;
node = x0_drawRoot;
prevNode = nullptr;
while (node)
{
rstl::rc_ptr<CIOWin> iow = node->GetIOWin();
if (iow == chIow)
CIOWin* iow = node->GetIOWin();
if (iow == toChange)
{
if (prevNode)
prevNode->x8_next = node->x8_next;
node->x4_prio = drawPrio;
CIOWinManager::IOWinPQNode* testNode = x0_rootDraw;
CIOWinManager::IOWinPQNode* testPrevNode = nullptr;
IOWinPQNode* testNode = x0_drawRoot;
IOWinPQNode* testPrevNode = nullptr;
while (testNode->x4_prio > drawPrio)
{
testPrevNode = testNode;
@ -196,7 +221,7 @@ void CIOWinManager::ChangeIOWinPriority(rstl::ncrc_ptr<CIOWin> chIow, int pumpPr
if (testPrevNode)
testPrevNode->x8_next = node;
else
x0_rootDraw = node;
x0_drawRoot = node;
break;
}
prevNode = node;
@ -206,25 +231,35 @@ void CIOWinManager::ChangeIOWinPriority(rstl::ncrc_ptr<CIOWin> chIow, int pumpPr
void CIOWinManager::RemoveAllIOWins()
{
while (x0_rootDraw)
RemoveIOWin(x0_rootDraw->GetIOWin());
while (x4_rootPump)
RemoveIOWin(x4_rootPump->GetIOWin());
}
void CIOWinManager::RemoveIOWin(rstl::ncrc_ptr<CIOWin> chIow)
{
CIOWinManager::IOWinPQNode* node = x4_rootPump;
CIOWinManager::IOWinPQNode* prevNode = nullptr;
IOWinPQNode* node = x0_drawRoot;
while (node)
{
rstl::rc_ptr<CIOWin> iow = node->GetIOWin();
IOWinPQNode* delNode = node;
node = node->x8_next;
delete delNode;
}
node = x4_pumpRoot;
while (node)
{
IOWinPQNode* delNode = node;
node = node->x8_next;
delete delNode;
}
}
void CIOWinManager::RemoveIOWin(CIOWin* chIow)
{
IOWinPQNode* node = x4_pumpRoot;
IOWinPQNode* prevNode = nullptr;
while (node)
{
CIOWin* iow = node->GetIOWin();
if (iow == chIow)
{
if (prevNode)
prevNode->x8_next = node->x8_next;
else
x4_rootPump = node->x8_next;
x4_pumpRoot = node->x8_next;
delete node;
break;
}
@ -232,17 +267,17 @@ void CIOWinManager::RemoveIOWin(rstl::ncrc_ptr<CIOWin> chIow)
node = node->x8_next;
}
node = x0_rootDraw;
node = x0_drawRoot;
prevNode = nullptr;
while (node)
{
rstl::rc_ptr<CIOWin> iow = node->GetIOWin();
CIOWin* iow = node->GetIOWin();
if (iow == chIow)
{
if (prevNode)
prevNode->x8_next = node->x8_next;
else
x0_rootDraw = node->x8_next;
x0_drawRoot = node->x8_next;
delete node;
break;
}
@ -253,31 +288,31 @@ void CIOWinManager::RemoveIOWin(rstl::ncrc_ptr<CIOWin> chIow)
void CIOWinManager::AddIOWin(rstl::ncrc_ptr<CIOWin> chIow, int pumpPrio, int drawPrio)
{
CIOWinManager::IOWinPQNode* node = x4_rootPump;
CIOWinManager::IOWinPQNode* prevNode = nullptr;
IOWinPQNode* node = x4_pumpRoot;
IOWinPQNode* prevNode = nullptr;
while (node && pumpPrio > node->x4_prio)
{
prevNode = node;
node = node->x8_next;
}
CIOWinManager::IOWinPQNode* newNode = new CIOWinManager::IOWinPQNode(chIow, pumpPrio, node);
IOWinPQNode* newNode = new IOWinPQNode(chIow, pumpPrio, node);
if (prevNode)
prevNode->x8_next = newNode;
else
x4_rootPump = newNode;
x4_pumpRoot = newNode;
node = x0_rootDraw;
node = x0_drawRoot;
prevNode = nullptr;
while (node && drawPrio > node->x4_prio)
{
prevNode = node;
node = node->x8_next;
}
newNode = new CIOWinManager::IOWinPQNode(chIow, drawPrio, node);
newNode = new IOWinPQNode(chIow, drawPrio, node);
if (prevNode)
prevNode->x8_next = newNode;
else
x0_rootDraw = newNode;
x0_drawRoot = newNode;
}
}

View File

@ -20,21 +20,23 @@ class CIOWinManager
IOWinPQNode(rstl::ncrc_ptr<CIOWin> iowin, int prio,
CIOWinManager::IOWinPQNode* next)
: x0_iowin(iowin), x4_prio(prio), x8_next(next) {}
rstl::rc_ptr<CIOWin> GetIOWin() const {return rstl::rc_ptr<CIOWin>(x0_iowin);}
rstl::rc_ptr<CIOWin> ShareIOWin() const {return rstl::rc_ptr<CIOWin>(x0_iowin);}
CIOWin* GetIOWin() const {return x0_iowin.get();}
};
IOWinPQNode* x0_rootDraw = nullptr;
IOWinPQNode* x4_rootPump = nullptr;
IOWinPQNode* x0_drawRoot = nullptr;
IOWinPQNode* x4_pumpRoot = nullptr;
CArchitectureQueue x8_internalQueue;
public:
bool OnIOWinMessage(const CArchitectureMessage& msg);
void Draw() const;
bool DistributeOneMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue);
void PumpMessages(CArchitectureQueue& queue);
rstl::rc_ptr<CIOWin> FindIOWin(const std::string& name);
void ChangeIOWinPriority(rstl::ncrc_ptr<CIOWin>, int pumpPrio, int drawPrio);
CIOWin* FindIOWin(const std::string& name);
rstl::rc_ptr<CIOWin> FindAndShareIOWin(const std::string& name);
void ChangeIOWinPriority(CIOWin* toChange, int pumpPrio, int drawPrio);
void RemoveAllIOWins();
void RemoveIOWin(rstl::ncrc_ptr<CIOWin>);
void AddIOWin(rstl::ncrc_ptr<CIOWin>, int pumpPrio, int drawPrio);
void RemoveIOWin(CIOWin* toRemove);
void AddIOWin(rstl::ncrc_ptr<CIOWin> toAdd, int pumpPrio, int drawPrio);
};

View File

@ -33,8 +33,4 @@ public:
void* operator new(std::size_t sz, const char* funcName, const char* typeName);
void* operator new[](std::size_t sz, const char* funcName, const char* typeName);
/* Macro to perform custom with debug strings */
#define NEW(T) new (AT_PRETTY_FUNCTION, typeid(T).name()) T
#define NEWA(T, N) new (AT_PRETTY_FUNCTION, typeid(T).name()) T[N]
#endif // __RETRO_CMEMORY_HPP__

View File

@ -20,7 +20,7 @@ void CResLoader::AddPakFileAsync(const std::string& name, bool flag)
std::string namePak = name + ".pak";
if (CDvdFile::FileExists(namePak.c_str()))
{
x34_pakLoadingList.emplace_back(NEW(CPakFile)(namePak, flag));
x34_pakLoadingList.emplace_back(new CPakFile(namePak, flag));
++x44_pakLoadingCount;
}
}
@ -46,7 +46,7 @@ CInputStream* CResLoader::LoadNewResourcePartSync(const SObjectTag& tag, int off
cs);
}
file->SyncSeekRead(buf, length, OriginBegin, x50_cachedResInfo->x4_offset + offset);
return NEW(CMemoryInStream)((atUint8*)buf, length, !extBuf);
return new CMemoryInStream((atUint8*)buf, length, !extBuf);
}
void CResLoader::LoadMemResourceSync(const SObjectTag& tag, void** bufOut, int* sizeOut)
@ -67,11 +67,11 @@ void CResLoader::LoadMemResourceSync(const SObjectTag& tag, void** bufOut, int*
CInputStream* CResLoader::LoadResourceFromMemorySync(const SObjectTag& tag, const void* buf)
{
FindResourceForLoad(tag);
CInputStream* newStrm = NEW(CMemoryInStream)((atUint8*)buf, x50_cachedResInfo->x8_size);
CInputStream* newStrm = new CMemoryInStream((atUint8*)buf, x50_cachedResInfo->x8_size);
if (x50_cachedResInfo->xb_compressed)
{
newStrm->readUint32Big();
newStrm = NEW(CZipInputStream)(std::move(std::unique_ptr<CInputStream>(newStrm)));
newStrm = new CZipInputStream(std::move(std::unique_ptr<CInputStream>(newStrm)));
}
return newStrm;
}
@ -91,11 +91,11 @@ CInputStream* CResLoader::LoadNewResourceSync(const SObjectTag& tag, void* extBu
cs);
}
file->SyncSeekRead(buf, resSz, OriginBegin, x50_cachedResInfo->x4_offset);
CInputStream* newStrm = NEW(CMemoryInStream)((atUint8*)buf, resSz, !extBuf);
CInputStream* newStrm = new CMemoryInStream((atUint8*)buf, resSz, !extBuf);
if (x50_cachedResInfo->xb_compressed)
{
newStrm->readUint32Big();
newStrm = NEW(CZipInputStream)(std::move(std::unique_ptr<CInputStream>(newStrm)));
newStrm = new CZipInputStream(std::move(std::unique_ptr<CInputStream>(newStrm)));
}
return newStrm;
}

View File

@ -9,7 +9,7 @@ class CZipSupport
public:
static void* Alloc(void*, u32 c, u32 n)
{
return NEWA(u8, c*n);
return new u8[c*n];
}
static void Free(void*, void* buf)
{
@ -18,7 +18,7 @@ public:
};
CZipInputStream::CZipInputStream(std::unique_ptr<CInputStream>&& strm)
: x24_compBuf(NEWA(u8, 4096)), x28_strm(std::move(strm))
: x24_compBuf(new u8[4096]), x28_strm(std::move(strm))
{
x30_zstrm.next_in = x24_compBuf.get();
x30_zstrm.avail_in = 0;

View File

@ -77,6 +77,7 @@ class ncrc_ptr
friend class rc_ptr<T>;
public:
ncrc_ptr(const rc_ptr<T>& other) : m_aux(other.m_aux) {}
T* get() const {return static_cast<T*>(m_aux->GetPtr());}
};
}