wavelength 1.0.0
Loading...
Searching...
No Matches
world.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5
6#include "app/msgsink.h"
7#include "game/btnevent.h"
10#include "game/rotateevent.h"
11#include "game/song.h"
12#include "game/stickevent.h"
13#include "game/worldlogic.h"
14#include "msg/gameendedmsg.h"
15#include "msg/message.h"
17#include "msg/startgamemsg.h"
18#include "os/file.h"
19#include "script/dataarray.h"
20
31class World : public MsgSink {
32public:
42
53
61
68 ~World() override;
69
78 bool DispatchPriv(Message *pMsg) override;
79
87 virtual int GetRuleSet() const = 0;
88
96 virtual bool IsFinished() = 0;
97
107 virtual float GetDisplayTime();
108
116 virtual void Handle(const RotateEvent &event) = 0;
117
125 virtual void Handle(const PlayNoteEvent &event) = 0;
126
134 virtual void Handle(const BtnEvent<8> &event) = 0;
135
143 virtual void Handle(const StickEvent<2> &event) = 0;
144
152 virtual void Handle(const StickEvent<6> &event) = 0;
153
161 virtual void Handle(const BtnEvent<3> &event) = 0;
162
170 virtual void Handle(const BtnEvent<4> &event) = 0;
171
179 virtual void Handle(const BtnEvent<5> &event) = 0;
180
188 virtual void Handle(const ChangeSectionEvent &event) = 0;
189
197 virtual void Handle(const BtnEvent<9> &event) = 0;
198
206 virtual void Handle(const BtnEvent<10> &event) = 0;
207
213 virtual void BeginAssetLoad() = 0;
214
220 virtual void PollAssetLoad() = 0;
221
229 virtual bool IsAssetLoadDone() = 0;
230
236 virtual void BeginSongLoad() = 0;
237
243 virtual void PollSongLoad() = 0;
244
252 virtual bool IsSongLoadDone() = 0;
253
262 virtual void BeginEnding() {
263 }
264
273 virtual void PollEnding() {
274 }
275
285 virtual bool IsEndingDone() {
286 return true;
287 }
288
294 virtual void CreateLogic() = 0;
295
303 virtual void Record(const RotateEvent &event);
304
312 virtual void Record(const PlayNoteEvent &event);
313
321 virtual void Record(const BtnEvent<8> &event);
322
330 virtual void Record(const StickEvent<2> &event);
331
339 virtual void Record(const StickEvent<6> &event);
340
348 virtual void Record(const BtnEvent<3> &event);
349
357 virtual void Record(const BtnEvent<4> &event);
358
366 virtual void Record(const BtnEvent<5> &event);
367
375 virtual void Record(const ChangeSectionEvent &event);
376
384 virtual void Record(const BtnEvent<9> &event);
385
393 virtual void Record(const BtnEvent<10> &event);
394
403 virtual void OnStart() {
404 }
405
413 virtual void BuildTracks(int nStartTick) = 0;
414
423 void Start();
424
433 void Stop();
434
445
454 bool IsFreestyling(int nPlayer);
455
464 void Poll();
465
475 bool IsLoaded() const;
476
486
496 int GetTick();
497
507 float GetTime();
508
518 void SetLogic(WorldLogic *pLogic);
519
520protected:
521 std::unique_ptr<Song> mSong;
523 int mSeed;
524
525private:
534 void DeleteLogic();
535
545 void OnSongStart();
546
555 void PollLoad();
556
565 void FinishLoad();
566
575 void PollQuitEnding();
576
585 void PollPlaying();
586
595 void Restart();
596
605 void BeginQuitEnding();
606
617 void StartClock(int nTick);
618
627 int OnStartGame(StartGameMsg *pMsg);
628
637 int OnGameEnded(GameEndedMsg *pMsg);
638
647 int OnPlayerAborted(PlayerAbortedMsg *pMsg);
648
649 int mState;
650 int mLoadStep;
651 std::vector<std::unique_ptr<GameEndedMsg>> mGameEndedMsgs;
652 std::vector<std::unique_ptr<PlayerAbortedMsg>> mPlayerAbortedMsgs;
653 std::unique_ptr<File> mDemoFile;
654 int mDemoSize;
655 char *mDemoBuffer;
656 int mLeadTicks;
657 std::unique_ptr<WorldLogic> mLogic;
658};
659
Input event of a button press that names only the player.
Definition btnevent.h:15
Input event that changes the section a player is on.
Definition changesectionevent.h:10
Reference-counted array of script data nodes.
Definition dataarray.h:20
Message that reports the end of an online session, with the final scores.
Definition gameendedmsg.h:23
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:40
Receiver of engine messages.
Definition msgsink.h:21
Input event that plays a note on one of the three gem buttons.
Definition playnoteevent.h:10
Message that reports a player leaving an online session.
Definition playerabortedmsg.h:20
Input event that rotates a player's view of the tracks by one track.
Definition rotateevent.h:11
Message that starts the song of an online session on every console.
Definition startgamemsg.h:20
Input event of an analog stick position.
Definition stickevent.h:15
Rules of one World, the base of the game, remix, and duel logic.
Definition worldlogic.h:28
virtual void Record(const BtnEvent< 3 > &event)
Record a button event of command 3.
virtual void Handle(const BtnEvent< 3 > &event)=0
Act on a button event of command 3 from the input router.
virtual void Handle(const PlayNoteEvent &event)=0
Act on a gem button from the input router.
virtual void Handle(const ChangeSectionEvent &event)=0
Act on a section change from the input router.
bool IsFreestyling(int nPlayer)
Report whether a player is in a freestyle while the song plays.
virtual bool IsSongLoadDone()=0
Report whether the first loading stage finished.
virtual void Handle(const RotateEvent &event)=0
Act on a rotation from the input router.
int mSeed
Definition world.h:523
virtual void Record(const BtnEvent< 8 > &event)
Record a button event of command 8.
LoadStep
Values of mLoadStep.
Definition world.h:44
@ kLoadStepSong
Definition world.h:46
@ kLoadStepDemo
Definition world.h:45
@ kLoadStepTracks
Definition world.h:47
@ kLoadStepSession
Definition world.h:50
@ kLoadStepMusic
Definition world.h:48
@ kLoadStepComplete
Definition world.h:51
@ kLoadStepAssets
Definition world.h:49
virtual void Handle(const StickEvent< 2 > &event)=0
Act on a stick event of command 2 from the input router.
virtual bool IsAssetLoadDone()=0
Report whether the second loading stage finished.
virtual void PollSongLoad()=0
Advance the first loading stage by one frame.
int GetTick()
Report the song position in ticks.
int IsRestartRequested()
Report whether the world that ended requested a restart.
virtual void Record(const StickEvent< 2 > &event)
Record a stick event of command 2.
float GetTime()
Report the song position on the song clock.
virtual void Handle(const BtnEvent< 10 > &event)=0
Act on a button event of command 10 from the input router.
virtual void Record(const BtnEvent< 4 > &event)
Record a button event of command 4.
virtual void Record(const BtnEvent< 9 > &event)
Record a button event of command 9.
virtual bool IsFinished()=0
Report whether the running world has ended.
virtual void Record(const ChangeSectionEvent &event)
Record a section change.
virtual int GetRuleSet() const =0
Report the rule set the world plays under.
virtual void BeginEnding()
Start the sequence that follows the end of the game.
Definition world.h:262
void LoadAssets()
Start loading the song and the assets of the world.
virtual void OnStart()
Finish starting the song, after Start() created the logic.
Definition world.h:403
void SetLogic(WorldLogic *pLogic)
Destroy the installed logic and install another.
virtual void Handle(const BtnEvent< 9 > &event)=0
Act on a button event of command 9 from the input router.
virtual void Record(const BtnEvent< 10 > &event)
Record a button event of command 10.
virtual void BeginSongLoad()=0
Start loading the song, the first loading stage.
virtual void BuildTracks(int nStartTick)=0
Build the track display for the song.
virtual void BeginAssetLoad()=0
Start loading the assets of the second loading stage.
bool DispatchPriv(Message *pMsg) override
Act on a message sent to the world.
virtual void Record(const StickEvent< 6 > &event)
Record a stick event of command 6.
virtual void Record(const BtnEvent< 5 > &event)
Record a button event of command 5.
std::unique_ptr< Song > mSong
Definition world.h:521
State
Values of mState.
Definition world.h:34
@ kStateLoaded
Definition world.h:37
@ kStatePlaying
Definition world.h:38
@ kStateEnding
Definition world.h:39
@ kStateLoading
Definition world.h:36
@ kStateIdle
Definition world.h:35
@ kStateRestarting
Definition world.h:40
void Start()
Start the song of a world that finished loading.
virtual void CreateLogic()=0
Build the WorldLogic of the rule set and install it with SetLogic().
bool IsLoaded() const
Report whether the assets LoadAssets() started are loaded.
DataArray * mSongConfig
Definition world.h:522
void Poll()
Advance the world by one frame.
virtual void Handle(const StickEvent< 6 > &event)=0
Act on a stick event of command 6 from the input router.
virtual float GetDisplayTime()
Report how far the running world has played, from WorldLogic::GetProgress().
virtual void Record(const RotateEvent &event)
Record a rotation as a serializable input command.
void Stop()
Stop the song and release what Start() and LoadAssets() created.
virtual void Handle(const BtnEvent< 4 > &event)=0
Act on a button event of command 4 from the input router.
~World() override
Release the world.
virtual bool IsEndingDone()
Report whether the sequence that follows the end of the game finished.
Definition world.h:285
virtual void Record(const PlayNoteEvent &event)
Record a gem button as a serializable input command.
virtual void PollEnding()
Advance the sequence that follows the end of the game by one frame.
Definition world.h:273
virtual void Handle(const BtnEvent< 5 > &event)=0
Act on a button event of command 5 from the input router.
World()
Construct a world with no game state.
virtual void Handle(const BtnEvent< 8 > &event)=0
Act on a button event of command 8 from the input router.
virtual void PollAssetLoad()=0
Advance the second loading stage by one frame.
WorldLogic * TheWorldLogic
The logic of the running world, which World::SetLogic() installs, or null.