mirror of https://github.com/stella-emu/stella.git
Replace executor class with a template --- we've got closures, after all :)
This commit is contained in:
parent
208f630a3c
commit
b874269065
|
@ -51,17 +51,4 @@ namespace TIA6502tsCore {
|
|||
myIndices[address] = index;
|
||||
}
|
||||
|
||||
void DelayQueue::execute(Executor& executor) {
|
||||
DelayQueueMember& currentMember = myMembers.at(myIndex);
|
||||
|
||||
for (auto&& entry : currentMember) {
|
||||
executor(entry.address, entry.value);
|
||||
myIndices[entry.address] = 0xFF;
|
||||
}
|
||||
|
||||
currentMember.clear();
|
||||
|
||||
myIndex = (myIndex + 1) & myMembers.size();
|
||||
}
|
||||
|
||||
} // namespace TIA6502tsCore
|
|
@ -27,18 +27,6 @@ namespace TIA6502tsCore {
|
|||
|
||||
class DelayQueue {
|
||||
|
||||
public:
|
||||
|
||||
class Executor {
|
||||
|
||||
public:
|
||||
|
||||
virtual void operator()(uInt8 address, uInt8 value) = 0;
|
||||
|
||||
virtual ~Executor() = default;
|
||||
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
DelayQueue(uInt8 length, uInt8 size);
|
||||
|
@ -47,7 +35,7 @@ class DelayQueue {
|
|||
|
||||
void push(uInt8 address, uInt8 value, uInt8 delay);
|
||||
|
||||
void execute(Executor& executor);
|
||||
template<class T> void execute(T executor);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -67,6 +55,23 @@ class DelayQueue {
|
|||
|
||||
};
|
||||
|
||||
// ############################################################################
|
||||
// Implementation
|
||||
// ############################################################################
|
||||
|
||||
template<class T> void DelayQueue::execute(T executor) {
|
||||
DelayQueueMember& currentMember = myMembers.at(myIndex);
|
||||
|
||||
for (auto&& entry : currentMember) {
|
||||
executor(entry.address, entry.value);
|
||||
myIndices[entry.address] = 0xFF;
|
||||
}
|
||||
|
||||
currentMember.clear();
|
||||
|
||||
myIndex = (myIndex + 1) & myMembers.size();
|
||||
}
|
||||
|
||||
} // namespace TIA6502tsCore
|
||||
|
||||
#endif // TIA_6502TS_CORE_DELAY_QUEUE
|
|
@ -28,27 +28,7 @@ namespace TIA6502tsCore {
|
|||
mySound(sound),
|
||||
mySettings(settings),
|
||||
myDelayQueue(10, 20)
|
||||
{
|
||||
class DelayedWriteExecutor : public DelayQueue::Executor {
|
||||
|
||||
public:
|
||||
|
||||
DelayedWriteExecutor(TIA& tia) : myTia(tia)
|
||||
{}
|
||||
|
||||
void operator()(uInt8 address, uInt8 value) override
|
||||
{
|
||||
myTia.delayedWrite(address, value);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
TIA& myTia;
|
||||
|
||||
};
|
||||
|
||||
myDelayQueueExecutor.reset(new DelayedWriteExecutor(*this));
|
||||
}
|
||||
{}
|
||||
|
||||
// TODO: stub
|
||||
void TIA::reset()
|
||||
|
|
|
@ -128,7 +128,6 @@ class TIA : public AbstractTIA {
|
|||
Settings& mySettings;
|
||||
|
||||
DelayQueue myDelayQueue;
|
||||
unique_ptr<DelayQueue::Executor> myDelayQueueExecutor;
|
||||
|
||||
private:
|
||||
|
||||
|
|
Loading…
Reference in New Issue