resonance 1.0.1
Loading...
Searching...
No Matches
msgqueue.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "app/msgsink.h"
6#include "app/msgsource.h"
7
8class Message;
9
34class MsgQueue : public MsgSource, public MsgSink {
35public:
43
50 virtual ~MsgQueue();
51
61 void Store(Message *pMsg);
62
77 void Poll();
78
79protected:
87 virtual void DispatchPriv(Message *pMsg);
88
89private:
90 std::vector<Message *> mFirst;
91 std::vector<Message *> mSecond;
92 // The vector that accepts a stored message. The constructor points it at mFirst and Poll()
93 // swaps it.
94 std::vector<Message *> *mTarget;
95 // The vector Poll() is iterating. Poll() is the only writer, and it reloads the member on
96 // every iteration rather than retaining it in a register.
97 std::vector<Message *> *mDraining;
98 // Non-zero while Poll() runs. Nothing recovered reads it.
99 int mInPoll;
100};
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:41
MsgQueue()
Start with both vectors empty and mFirst accepting.
virtual ~MsgQueue()
Delete every stored message and release both vectors.
void Store(Message *pMsg)
Store a copy of a message without reading its identity first.
virtual void DispatchPriv(Message *pMsg)
Store a copy of a message.
void Poll()
Deliver and discard every stored message.
Receiver of engine messages.
Definition msgsink.h:37
Sender of engine messages, which stores the list of sinks that receive them.
Definition msgsource.h:26