新增:实现 EventQueue 类,单线程事件队列

This commit is contained in:
2025-09-01 18:46:27 +08:00
commit 7b0d4fd2c3
9 changed files with 255 additions and 0 deletions

46
code/EventQueue.cpp Normal file
View File

@ -0,0 +1,46 @@
#include "EventQueue.h"
bool EventQueue::EventQueue_AddEvent(int tInputCmd, void *pInputParam)
{
cmdParam.push_back(pInputParam);
cmdList.push_back(tInputCmd);
return true;
}
bool EventQueue::EventQueue_AddEventToFront(int tInputCmd, void *pInputParam)
{
cmdParam.push_front(pInputParam);
cmdList.push_front(tInputCmd);
return true;
}
bool EventQueue::EventQueue_PeekEvent(int *pOutputCmd, void **ppOutputParam)
{
if (cmdList.empty())
return false;
(*pOutputCmd) = cmdList.front();
(*ppOutputParam) = cmdParam.front();
return true;
}
void EventQueue::EventQueue_PopEvent(void)
{
if (!cmdList.empty())
{
cmdList.pop_front();
cmdParam.pop_front();
}
}
bool EventQueue::EventQueue_GetEvent(int *pOutputCmd, void **ppOutputParam)
{
if (cmdList.empty())
return false;
(*pOutputCmd) = cmdList.front();
(*ppOutputParam) = cmdParam.front();
cmdList.pop_front();
cmdParam.pop_front();
return true;
}