wavelength 1.0.0
Loading...
Searching...
No Matches
playscriptcmd.h
Go to the documentation of this file.
1#pragma once
2
4#include "os/command.h"
5#include "os/scheduler.h"
6#include "os/task.h"
9
18class PlayScriptCmd : public Command {
19public:
26 PlayScriptCmd(ScriptTrackData *pTrack, float *pTickDuration)
27 : mTrack(pTrack), mTickDuration(pTickDuration), mNextCommand(0), mStartTick(0),
28 mWaitingTask(nullptr) {
29 }
30
37 ~PlayScriptCmd() override {
38 }
39
46 void Execute() override {
47 // Yes, the binary discards the result.
48 (void)ScriptFunction::Dispatch(mTrack->GetCommand(mNextCommand)->mValue);
49 ++mNextCommand;
51 }
52
62 void ScheduleNext() {
63 if (mNextCommand < mTrack->NumCommands()) {
64 TheSongScheduler.PostAt(
65 this, mStartTick + mTrack->GetCommand(mNextCommand)->mPosition, false);
66 } else if (mWaitingTask != nullptr) {
67 TaskDoneNotifier::ReportDone(mWaitingTask);
68 }
69 }
70
72 int GetStartTick() const {
73 return mStartTick;
74 }
75
77 void SetStartTick(int nStartTick) {
78 mStartTick = nStartTick;
79 }
80
82 int GetNextCommand() const {
83 return mNextCommand;
84 }
85
87 void SetNextCommand(int nNextCommand) {
88 mNextCommand = nNextCommand;
89 }
90
93 return mTrack;
94 }
95
97 void SetWaitingTask(Task *pWaitingTask) {
98 mWaitingTask = pWaitingTask;
99 }
100
101private:
102 ScriptTrackData *mTrack;
103 float *mTickDuration;
104 int mNextCommand;
105 int mStartTick;
106 Task *mWaitingTask;
107};
Unit of work a Scheduler runs at a set time.
Definition command.h:13
void SetWaitingTask(Task *pWaitingTask)
Definition playscriptcmd.h:97
PlayScriptCmd(ScriptTrackData *pTrack, float *pTickDuration)
Construct a command at the first command of a track.
Definition playscriptcmd.h:26
void SetStartTick(int nStartTick)
Definition playscriptcmd.h:77
ScriptTrackData * GetTrack() const
Definition playscriptcmd.h:92
void SetNextCommand(int nNextCommand)
Definition playscriptcmd.h:87
void ScheduleNext()
Post the command at the tick of the next command of the track, or report the end of the track to the ...
Definition playscriptcmd.h:62
void Execute() override
Run the next command of the track and post the one after it.
Definition playscriptcmd.h:46
~PlayScriptCmd() override
Release the command.
Definition playscriptcmd.h:37
int GetStartTick() const
Definition playscriptcmd.h:72
int GetNextCommand() const
Definition playscriptcmd.h:82
static bool Dispatch(DataArray *pCommand)
Run a script command through the routine registered for its name.
The script commands of a song's SCRIPT track, each at its tick.
Definition scripttrackdata.h:14
static void ReportDone(Task *pTask)
Tell a waiting task that its work is done.
Definition taskdonenotifier.h:38
Unit of work an owner starts, polls until it reports that it is done, and stops.
Definition task.h:9
Scheduler TheSongScheduler
The scheduler of the song clock.