wavelength 1.0.0
Loading...
Searching...
No Matches
trackcapturer.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
6#include "game/gemcatcher.h"
7#include "game/gemcursor.h"
8#include "game/netfaker.h"
9#include "game/player.h"
10#include "game/playmap.h"
12#include "game/trackreactor.h"
13#include "gs/muse.h"
14#include "os/command.h"
15#include "os/ptr.h"
16
27public:
33 class Receiver {
34 public:
41 virtual ~Receiver() {
42 }
43
49 virtual void OnCapture(const GemCursor &cursor) = 0;
50
52 virtual void OnRunLost() = 0;
53
60 virtual void OnRunStart(const GemCursor &cursor, int nEndBar) = 0;
61 };
62
70 public:
77 ~CatchReceiver() override = default;
78
84 explicit CatchReceiver(TrackCapturer *pCapturer) : mCapturer(pCapturer) {
85 }
86
95 void OnHit(int nTick, const GemCursor &cursor) override {
96 mCapturer->HitGem(nTick, cursor, false);
97 }
98
107 void OnPass(int nTick, const GemCursor &cursor) override {
108 mCapturer->MissGem(nTick, cursor, false);
109 }
110
119 void OnMiss(int nTick, int nLane) override {
120 mCapturer->MissPress(nTick, nLane);
121 }
122
123 private:
124 TrackCapturer *mCapturer;
125 };
126
134 public:
141 ~SetCaptureStartCmd() override = default;
142
148 explicit SetCaptureStartCmd(TrackCapturer *pCapturer) : mBar(0), mCapturer(pCapturer) {
149 }
150
157 void Execute() override {
158 mCapturer->UpdateRun(mBar);
159 }
160
166 void SetBar(int nBar) {
167 mBar = nBar;
168 }
169
170 private:
171 int mBar;
172 TrackCapturer *mCapturer;
173 };
174
181 class Faker {
182 public:
188 explicit Faker(TrackCapturer *pCapturer);
189
195 void Start();
196
203 void Stop();
204
211 void Update();
212
218 void SetEnabled(int nEnabled) {
219 mEnabled = nEnabled;
220 }
221
222 private:
223 TrackCapturer *mCapturer;
224 GemCursor mCursor;
225 Ptr<Command> mUpdateCmd;
226 int mEnabled;
227 };
228
245 CatchTrackState *pState,
246 const float *pMsPerTick,
247 PlayMap *pPlayMap,
248 const SectionBoundaries *pSections,
249 int nNumBars,
250 int nTrack,
251 int nTicksPerBar,
252 int nStopPreviousNote);
253
260 ~TrackCapturer() override;
261
268 void Start();
269
276 void Stop();
277
284 void Restart();
285
295 void SetPlayer(Player *pPlayer);
296
304 void Press(int nLane);
305
313 void SetFakeInput(int nEnabled);
314
322 void SetRunHidden(int nHidden);
323
333
344 bool GetRunStart(int nBar, int *pTick, int *pLane);
345
353 int GetTicksPerBar() const override {
354 return mTicksPerBar;
355 }
356
364 Player *GetPlayer() const override {
365 return mPlayer;
366 }
367
376 bool IsBarActive(int nBar) override;
377
390 void HitGem(int nTick, const GemCursor &cursor, bool bRemote) override;
391
401 void MissGem(int nTick, const GemCursor &cursor, bool bRemote) override;
402
411
412private:
421 bool IsLastGemOfBar(const GemCursor &cursor);
422
434 int FindActiveBar(int nFrom, int nTo);
435
445 int FindRunEnd(int nStart, int nMaxBars);
446
458 bool FindRun(int nFrom, int nTo, int *pStart, int *pEnd);
459
467 void UpdateRun(int nBar);
468
477 void EndRunIfStarted(int nTick, int nQuiet);
478
487 void EndRun(int nTick, int nQuiet);
488
498 void CompleteBar(const GemCursor &cursor, int nQuiet);
499
508 void Capture(const GemCursor &cursor, int nQuiet);
509
516 void UpdateMeter();
517
524 void HideRun();
525
533 void ShowRun(int nStyle);
534
542 void ShowPressHint(int nTick);
543
552 void MissPress(int nTick, int nLane);
553
554 std::unique_ptr<CatchReceiver> mCatchReceiver;
555 CatchTrackState *mState;
556 const SectionBoundaries *mSections;
557 GemCatcher mCatcher;
558 std::unique_ptr<NetFaker> mNetFaker;
559 std::unique_ptr<Faker> mFaker;
560 Receiver *mReceiver;
561 Player *mPlayer;
562 Muse *mLastMuse;
563 int mTrack;
564 int mTicksPerBar;
565 int mStopPreviousNote;
566 int mEndBar;
567 int mStarted;
568 Ptr<SetCaptureStartCmd> mCaptureStartCmd;
569 int mGemsCaught;
570 int mRunGems;
571 int mRunStart;
572 int mRunEnd;
573 int mRunHidden;
574};
Per-bar state of one catch track during a song.
Definition catchtrackstate.h:17
Unit of work a Scheduler runs at a set time.
Definition command.h:13
Object told of each judged gem and press.
Definition gemcatcher.h:25
Judge of the presses on the lanes of one catch track.
Definition gemcatcher.h:15
Position at one gem of a catch track, walked in the order the song plays the gems.
Definition gemcursor.h:14
Piece of MIDI performance that a Scheduler plays.
Definition muse.h:12
Map from the bars a song plays to the bars of the song as written, with the loops that repeat stretch...
Definition playmap.h:11
One participant in a song: the track the participant plays, the score, and the streak.
Definition player.h:19
Owner of one reference to an Attachment.
Definition ptr.h:16
Ascending list of the measures at which the sections of a song end.
Definition sectionboundaries.h:12
~CatchReceiver() override=default
Destroy the object.
void OnHit(int nTick, const GemCursor &cursor) override
Pass a caught gem on as a local hit.
Definition trackcapturer.h:95
void OnMiss(int nTick, int nLane) override
Pass a press that caught no gem on.
Definition trackcapturer.h:119
CatchReceiver(TrackCapturer *pCapturer)
Construct the receiver of a capturer.
Definition trackcapturer.h:84
void OnPass(int nTick, const GemCursor &cursor) override
Pass a gem that passed without a press on as a local miss.
Definition trackcapturer.h:107
void Update()
Press the gem of the current tick when the autopilot is on and schedule the next gem.
Faker(TrackCapturer *pCapturer)
Construct a stand-in at the first gem of the track.
void Start()
Move to the first gem at or after the current tick and schedule it.
void Stop()
Withdraw the scheduled gem.
void SetEnabled(int nEnabled)
Set whether the autopilot presses the gems.
Definition trackcapturer.h:218
Interface told when a run is started, lost, or captured.
Definition trackcapturer.h:33
virtual void OnRunLost()=0
Handle a lost run.
virtual void OnRunStart(const GemCursor &cursor, int nEndBar)=0
Handle the first gem caught in a run.
virtual ~Receiver()
Release the receiver.
Definition trackcapturer.h:41
virtual void OnCapture(const GemCursor &cursor)=0
Handle a captured run.
void Execute() override
Look for the next run from mBar.
Definition trackcapturer.h:157
SetCaptureStartCmd(TrackCapturer *pCapturer)
Construct the command of a capturer.
Definition trackcapturer.h:148
~SetCaptureStartCmd() override=default
Destroy the object.
void SetBar(int nBar)
Set the bar to look from.
Definition trackcapturer.h:166
void Restart()
Stop and start again when started.
void SetPlayer(Player *pPlayer)
Give the track to a player, ending the run of the previous player when it was catching.
void MissGem(int nTick, const GemCursor &cursor, bool bRemote) override
Act on a gem the player let pass.
void Press(int nLane)
Judge a press on a lane, or explain the controls when the capturer is stopped.
void SetFakeInput(int nEnabled)
Turn the autopilot on or off.
void RefreshRun()
Look for the run again from the current bar.
Player * GetPlayer() const override
Report the player who plays the track.
Definition trackcapturer.h:364
GemCursor GetCursor() override
Report a cursor at the first gem of the track.
void Stop()
Stop judging the presses and hide the run.
~TrackCapturer() override
Stop and release the helpers.
void SetRunHidden(int nHidden)
Hide or show the run and the catch meter.
TrackCapturer(Receiver *pReceiver, CatchTrackState *pState, const float *pMsPerTick, PlayMap *pPlayMap, const SectionBoundaries *pSections, int nNumBars, int nTrack, int nTicksPerBar, int nStopPreviousNote)
Construct the rules of a track and look for the first run.
int GetTicksPerBar() const override
Report the song ticks in one bar.
Definition trackcapturer.h:353
void HitGem(int nTick, const GemCursor &cursor, bool bRemote) override
Act on a gem the player hit.
bool IsBarActive(int nBar) override
Report whether a bar can be caught and is not yet captured.
bool GetRunStart(int nBar, int *pTick, int *pLane)
Find the first gem of the next run from a bar.
void Start()
Look for the run from the current bar and start judging the presses.
Interface through which the rules react to the phrases of a player's track.
Definition trackreactor.h:12