2015-08-20 02:52:07 +00:00
|
|
|
#include "CIOWinManager.hpp"
|
2015-08-22 01:58:41 +00:00
|
|
|
#include "CArchitectureMessage.hpp"
|
2015-08-29 01:30:47 +00:00
|
|
|
#include "CIOWin.hpp"
|
2015-08-20 02:52:07 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2015-08-20 02:52:07 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
bool CIOWinManager::OnIOWinMessage(const CArchitectureMessage& msg)
|
|
|
|
{
|
|
|
|
switch (msg.GetType())
|
|
|
|
{
|
2015-11-21 01:16:07 +00:00
|
|
|
case EArchMsgType::RemoveIOWin:
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
|
|
|
const CArchMsgParmVoidPtr& parm = MakeMsg::GetParmDeleteIOWin(msg);
|
2015-08-26 06:38:45 +00:00
|
|
|
CIOWin* iow = FindIOWin(*static_cast<const std::string*>(parm.x4_parm1));
|
2015-08-26 01:34:56 +00:00
|
|
|
if (iow)
|
|
|
|
RemoveIOWin(iow);
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-21 01:16:07 +00:00
|
|
|
case EArchMsgType::CreateIOWin:
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2017-01-17 01:23:19 +00:00
|
|
|
const CArchMsgParmInt32Int32IOWin& parm = MakeMsg::GetParmCreateIOWin(msg);
|
|
|
|
AddIOWin(parm.xc_parm3, parm.x4_parm1, parm.x8_parm2);
|
2015-08-26 01:34:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-11-21 01:16:07 +00:00
|
|
|
case EArchMsgType::ChangeIOWinPriority:
|
2015-08-20 02:52:07 +00:00
|
|
|
{
|
|
|
|
const CArchMsgParmInt32Int32VoidPtr& parm = MakeMsg::GetParmChangeIOWinPriority(msg);
|
2015-08-26 06:38:45 +00:00
|
|
|
CIOWin* iow = FindIOWin(*static_cast<const std::string*>(parm.xc_parm3));
|
2015-08-26 01:34:56 +00:00
|
|
|
if (iow)
|
|
|
|
ChangeIOWinPriority(iow, parm.x4_parm1, parm.x8_parm2);
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-21 01:16:07 +00:00
|
|
|
case EArchMsgType::RemoveAllIOWins:
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
|
|
|
RemoveAllIOWins();
|
|
|
|
return true;
|
2015-08-20 02:52:07 +00:00
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-26 01:34:56 +00:00
|
|
|
void CIOWinManager::Draw() const
|
|
|
|
{
|
2016-09-14 05:54:09 +00:00
|
|
|
for (IOWinPQNode* node = x0_drawRoot ; node ; node = node->x8_next)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2015-08-26 06:38:45 +00:00
|
|
|
CIOWin* iow = node->GetIOWin();
|
2015-08-26 01:34:56 +00:00
|
|
|
iow->PreDraw();
|
|
|
|
if (!iow->GetIsContinueDraw())
|
|
|
|
break;
|
|
|
|
}
|
2016-09-14 05:54:09 +00:00
|
|
|
for (IOWinPQNode* node = x0_drawRoot ; node ; node = node->x8_next)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2015-08-26 06:38:45 +00:00
|
|
|
CIOWin* iow = node->GetIOWin();
|
2015-08-26 01:34:56 +00:00
|
|
|
iow->Draw();
|
|
|
|
if (!iow->GetIsContinueDraw())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CIOWinManager::DistributeOneMessage(const CArchitectureMessage& msg,
|
|
|
|
CArchitectureQueue& queue)
|
|
|
|
{
|
2017-01-27 09:21:02 +00:00
|
|
|
CArchitectureMessage tmpMsg = msg;
|
2017-02-06 03:21:58 +00:00
|
|
|
for (IOWinPQNode* node = x4_pumpRoot ; node ;)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2017-02-06 03:21:58 +00:00
|
|
|
IOWinPQNode* next = node->x8_next;
|
2015-08-26 06:38:45 +00:00
|
|
|
CIOWin* iow = node->GetIOWin();
|
2017-01-27 09:21:02 +00:00
|
|
|
CIOWin::EMessageReturn mret = iow->OnMessage(tmpMsg, x8_localGatherQueue);
|
2015-08-26 01:34:56 +00:00
|
|
|
|
2015-08-27 00:23:46 +00:00
|
|
|
while (x8_localGatherQueue)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2017-01-27 09:21:02 +00:00
|
|
|
tmpMsg = x8_localGatherQueue.Pop();
|
|
|
|
if (tmpMsg.GetTarget() == EArchMsgTarget::IOWinManager)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2017-01-27 09:21:02 +00:00
|
|
|
if (OnIOWinMessage(tmpMsg))
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2015-08-27 00:23:46 +00:00
|
|
|
x8_localGatherQueue.Clear();
|
2015-08-26 01:34:56 +00:00
|
|
|
queue.Clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-01-27 09:21:02 +00:00
|
|
|
queue.Push(std::move(tmpMsg));
|
2015-08-26 01:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (mret)
|
|
|
|
{
|
2015-11-21 01:16:07 +00:00
|
|
|
case CIOWin::EMessageReturn::RemoveIOWinAndExit:
|
|
|
|
case CIOWin::EMessageReturn::RemoveIOWin:
|
2015-08-26 01:34:56 +00:00
|
|
|
RemoveIOWin(iow);
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mret)
|
|
|
|
{
|
2015-11-21 01:16:07 +00:00
|
|
|
case CIOWin::EMessageReturn::Exit:
|
|
|
|
case CIOWin::EMessageReturn::RemoveIOWinAndExit:
|
2015-08-26 01:34:56 +00:00
|
|
|
return false;
|
|
|
|
default: break;
|
|
|
|
}
|
2017-02-06 03:21:58 +00:00
|
|
|
|
|
|
|
node = next;
|
2015-08-26 01:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIOWinManager::PumpMessages(CArchitectureQueue& queue)
|
|
|
|
{
|
|
|
|
while (queue)
|
|
|
|
{
|
|
|
|
CArchitectureMessage msg = queue.Pop();
|
|
|
|
if (DistributeOneMessage(msg, queue))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CIOWin* CIOWinManager::FindIOWin(std::string_view name)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2017-11-13 06:19:18 +00:00
|
|
|
size_t findHash = std::hash<std::string_view>()(name);
|
2015-08-26 01:34:56 +00:00
|
|
|
|
2016-09-14 05:54:09 +00:00
|
|
|
for (IOWinPQNode* node = x4_pumpRoot ; node ; node = node->x8_next)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2015-08-26 06:38:45 +00:00
|
|
|
CIOWin* iow = node->GetIOWin();
|
2015-08-26 01:34:56 +00:00
|
|
|
if (iow->GetNameHash() == findHash)
|
|
|
|
return iow;
|
|
|
|
}
|
|
|
|
|
2016-09-14 05:54:09 +00:00
|
|
|
for (IOWinPQNode* node = x0_drawRoot ; node ; node = node->x8_next)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2015-08-26 06:38:45 +00:00
|
|
|
CIOWin* iow = node->GetIOWin();
|
|
|
|
if (iow->GetNameHash() == findHash)
|
|
|
|
return iow;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
std::shared_ptr<CIOWin> CIOWinManager::FindAndShareIOWin(std::string_view name)
|
2015-08-26 06:38:45 +00:00
|
|
|
{
|
2017-11-13 06:19:18 +00:00
|
|
|
size_t findHash = std::hash<std::string_view>()(name);
|
2015-08-26 06:38:45 +00:00
|
|
|
|
2016-09-14 05:54:09 +00:00
|
|
|
for (IOWinPQNode* node = x4_pumpRoot ; node ; node = node->x8_next)
|
2015-08-26 06:38:45 +00:00
|
|
|
{
|
2016-02-05 01:27:03 +00:00
|
|
|
std::shared_ptr<CIOWin> iow = node->ShareIOWin();
|
2015-08-26 06:38:45 +00:00
|
|
|
if (iow->GetNameHash() == findHash)
|
|
|
|
return iow;
|
|
|
|
}
|
|
|
|
|
2016-09-14 05:54:09 +00:00
|
|
|
for (IOWinPQNode* node = x0_drawRoot ; node ; node = node->x8_next)
|
2015-08-26 06:38:45 +00:00
|
|
|
{
|
2016-02-05 01:27:03 +00:00
|
|
|
std::shared_ptr<CIOWin> iow = node->ShareIOWin();
|
2015-08-26 01:34:56 +00:00
|
|
|
if (iow->GetNameHash() == findHash)
|
|
|
|
return iow;
|
|
|
|
}
|
|
|
|
|
2016-02-05 01:27:03 +00:00
|
|
|
return std::shared_ptr<CIOWin>();
|
2015-08-26 01:34:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-26 06:38:45 +00:00
|
|
|
void CIOWinManager::ChangeIOWinPriority(CIOWin* toChange, int pumpPrio, int drawPrio)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2015-08-26 06:38:45 +00:00
|
|
|
IOWinPQNode* prevNode = nullptr;
|
2016-09-14 05:54:09 +00:00
|
|
|
for (IOWinPQNode* node = x4_pumpRoot ; node ; node = node->x8_next)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2015-08-26 06:38:45 +00:00
|
|
|
CIOWin* iow = node->GetIOWin();
|
|
|
|
if (iow == toChange)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
|
|
|
if (prevNode)
|
|
|
|
prevNode->x8_next = node->x8_next;
|
|
|
|
node->x4_prio = pumpPrio;
|
2015-08-26 06:38:45 +00:00
|
|
|
IOWinPQNode* testNode = x4_pumpRoot;
|
|
|
|
IOWinPQNode* testPrevNode = nullptr;
|
2015-08-26 01:34:56 +00:00
|
|
|
while (testNode->x4_prio > pumpPrio)
|
|
|
|
{
|
|
|
|
testPrevNode = testNode;
|
|
|
|
testNode = testNode->x8_next;
|
|
|
|
}
|
|
|
|
node->x8_next = testNode;
|
|
|
|
if (testPrevNode)
|
|
|
|
testPrevNode->x8_next = node;
|
|
|
|
else
|
2015-08-26 06:38:45 +00:00
|
|
|
x4_pumpRoot = node;
|
2015-08-26 01:34:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
prevNode = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
prevNode = nullptr;
|
2016-09-14 05:54:09 +00:00
|
|
|
for (IOWinPQNode* node = x0_drawRoot ; node ; node = node->x8_next)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2015-08-26 06:38:45 +00:00
|
|
|
CIOWin* iow = node->GetIOWin();
|
|
|
|
if (iow == toChange)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
|
|
|
if (prevNode)
|
|
|
|
prevNode->x8_next = node->x8_next;
|
|
|
|
node->x4_prio = drawPrio;
|
2015-08-26 06:38:45 +00:00
|
|
|
IOWinPQNode* testNode = x0_drawRoot;
|
|
|
|
IOWinPQNode* testPrevNode = nullptr;
|
2015-08-26 01:34:56 +00:00
|
|
|
while (testNode->x4_prio > drawPrio)
|
|
|
|
{
|
|
|
|
testPrevNode = testNode;
|
|
|
|
testNode = testNode->x8_next;
|
|
|
|
}
|
|
|
|
node->x8_next = testNode;
|
|
|
|
if (testPrevNode)
|
|
|
|
testPrevNode->x8_next = node;
|
|
|
|
else
|
2015-08-26 06:38:45 +00:00
|
|
|
x0_drawRoot = node;
|
2015-08-26 01:34:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
prevNode = node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIOWinManager::RemoveAllIOWins()
|
|
|
|
{
|
2017-01-22 01:40:12 +00:00
|
|
|
for (IOWinPQNode* node = x0_drawRoot ; node ;)
|
|
|
|
{
|
|
|
|
IOWinPQNode* n = node;
|
|
|
|
node = n->x8_next;
|
|
|
|
delete n;
|
|
|
|
}
|
2015-08-27 00:23:46 +00:00
|
|
|
x0_drawRoot = nullptr;
|
2017-01-22 01:40:12 +00:00
|
|
|
for (IOWinPQNode* node = x4_pumpRoot ; node ;)
|
|
|
|
{
|
|
|
|
IOWinPQNode* n = node;
|
|
|
|
node = n->x8_next;
|
|
|
|
delete n;
|
|
|
|
}
|
2015-08-27 00:23:46 +00:00
|
|
|
x4_pumpRoot = nullptr;
|
2015-08-26 01:34:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-26 06:38:45 +00:00
|
|
|
void CIOWinManager::RemoveIOWin(CIOWin* chIow)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2015-08-26 06:38:45 +00:00
|
|
|
IOWinPQNode* prevNode = nullptr;
|
2016-09-14 05:54:09 +00:00
|
|
|
for (IOWinPQNode* node = x4_pumpRoot ; node ; node = node->x8_next)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2015-08-26 06:38:45 +00:00
|
|
|
CIOWin* iow = node->GetIOWin();
|
2015-08-26 01:34:56 +00:00
|
|
|
if (iow == chIow)
|
|
|
|
{
|
|
|
|
if (prevNode)
|
|
|
|
prevNode->x8_next = node->x8_next;
|
|
|
|
else
|
2015-08-26 06:38:45 +00:00
|
|
|
x4_pumpRoot = node->x8_next;
|
2015-08-26 01:34:56 +00:00
|
|
|
delete node;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prevNode = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
prevNode = nullptr;
|
2016-09-14 05:54:09 +00:00
|
|
|
for (IOWinPQNode* node = x0_drawRoot ; node ; node = node->x8_next)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2015-08-26 06:38:45 +00:00
|
|
|
CIOWin* iow = node->GetIOWin();
|
2015-08-26 01:34:56 +00:00
|
|
|
if (iow == chIow)
|
|
|
|
{
|
|
|
|
if (prevNode)
|
|
|
|
prevNode->x8_next = node->x8_next;
|
|
|
|
else
|
2015-08-26 06:38:45 +00:00
|
|
|
x0_drawRoot = node->x8_next;
|
2015-08-26 01:34:56 +00:00
|
|
|
delete node;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prevNode = node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-05 01:27:03 +00:00
|
|
|
void CIOWinManager::AddIOWin(std::weak_ptr<CIOWin> chIow, int pumpPrio, int drawPrio)
|
2015-08-26 01:34:56 +00:00
|
|
|
{
|
2016-09-14 05:54:09 +00:00
|
|
|
IOWinPQNode* node;
|
2015-08-26 06:38:45 +00:00
|
|
|
IOWinPQNode* prevNode = nullptr;
|
2016-09-14 05:54:09 +00:00
|
|
|
for (node = x4_pumpRoot ; node && pumpPrio < node->x4_prio ; node = node->x8_next)
|
2015-08-26 01:34:56 +00:00
|
|
|
prevNode = node;
|
2015-08-26 06:38:45 +00:00
|
|
|
IOWinPQNode* newNode = new IOWinPQNode(chIow, pumpPrio, node);
|
2015-08-26 01:34:56 +00:00
|
|
|
if (prevNode)
|
|
|
|
prevNode->x8_next = newNode;
|
|
|
|
else
|
2015-08-26 06:38:45 +00:00
|
|
|
x4_pumpRoot = newNode;
|
2015-08-26 01:34:56 +00:00
|
|
|
|
|
|
|
prevNode = nullptr;
|
2016-09-14 05:54:09 +00:00
|
|
|
for (node = x0_drawRoot ; node && drawPrio < node->x4_prio ; node = node->x8_next)
|
2015-08-26 01:34:56 +00:00
|
|
|
prevNode = node;
|
2015-08-26 06:38:45 +00:00
|
|
|
newNode = new IOWinPQNode(chIow, drawPrio, node);
|
2015-08-26 01:34:56 +00:00
|
|
|
if (prevNode)
|
|
|
|
prevNode->x8_next = newNode;
|
|
|
|
else
|
2015-08-26 06:38:45 +00:00
|
|
|
x0_drawRoot = newNode;
|
2015-08-26 01:34:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-20 02:52:07 +00:00
|
|
|
}
|