Etterna 0.74.4
Loading...
Searching...
No Matches
GameState.h
1#ifndef GAMESTATE_H
2#define GAMESTATE_H
3
4#include "Etterna/Models/Misc/Difficulty.h"
5#include "Etterna/Models/Misc/GameConstantsAndTypes.h"
6#include "MessageManager.h"
7#include "Etterna/Models/Misc/ModsGroup.h"
8#include "Etterna/Models/Songs/SongPosition.h"
9#include "Etterna/Singletons/PrefsManager.h"
10#include "Etterna/Models/Misc/PlayerNumber.h"
11
12struct Game;
13struct lua_State;
14class LuaTable;
15class PlayerState;
16class PlayerOptions;
17class Profile;
18class Song;
19class Steps;
20class StageStats;
21class Style;
22class TimingData;
23class SongOptions;
24
25auto
26GetDefaultSort() -> SortOrder;
27
28extern int mina_calc_version;
29
32{
35 PlayerNumber masterPlayerNumber;
37 TimingData* processedTiming;
38
39 public:
41 GameState();
42 ~GameState();
44 void Reset();
45 void ResetPlayer(PlayerNumber pn);
46 void ResetPlayerOptions(PlayerNumber pn);
47 void ApplyCmdline(); // called by Reset
48 void ApplyGameCommand(const std::string& sCommand,
49 PlayerNumber pn = PLAYER_INVALID);
51 void BeginGame();
52 void JoinPlayer(PlayerNumber pn);
53 void UnjoinPlayer(PlayerNumber pn);
54 auto JoinInput(PlayerNumber pn) -> bool;
55 auto JoinPlayers() -> bool;
56 void LoadProfiles(bool bLoadEdits = true);
57 void SavePlayerProfile();
58 auto HaveProfileToLoad() -> bool;
59 auto HaveProfileToSave() -> bool;
60 void AddStageToPlayer(PlayerNumber pn);
61 void LoadCurrentSettingsFromProfile(PlayerNumber pn);
67 void SaveCurrentSettingsToProfile(PlayerNumber pn);
68 [[nodiscard]] auto GetDefaultSong() const -> Song*;
69
70 auto CanSafelyEnterGameplay(std::string& reason) -> bool;
71 void SetCompatibleStylesForPlayers();
72 void ForceOtherPlayersToCompatibleSteps(PlayerNumber main);
73
74 void Update(float fDelta);
75
76 // Main state info
77
84 void SetCurGame(const Game* pGame);
86
87 private: // DO NOT access directly. Use Get/SetCurrentStyle.
89 // Only used if the Game specifies that styles are separate.
90 Style const* m_SeparatedStyles[NUM_PlayerNumber];
91
92 public:
96 bool m_bSideIsJoined; // left side, right side
97 MultiPlayerStatus m_MultiPlayerStatus[NUM_MultiPlayer];
98
99 bool m_bPlayingMulti = false;
100 int m_iNumMultiplayerNoteFields;
101 auto ChangePreferredDifficultyAndStepsType(PlayerNumber pn,
102 Difficulty dc,
103 StepsType st) -> bool;
104 auto ChangePreferredDifficulty(PlayerNumber pn, int dir) -> bool;
105 [[nodiscard]] auto GetClosestShownDifficulty(PlayerNumber pn) const
106 -> Difficulty;
107 [[nodiscard]] auto GetEasiestStepsDifficulty() const -> Difficulty;
108 [[nodiscard]] auto GetHardestStepsDifficulty() const -> Difficulty;
109 RageTimer m_timeGameStarted; // from the moment the first
110 // player pressed Start
111 LuaTable* m_Environment;
112
113 // This is set to a random number per-game/round; it can be used for a
114 // random seed.
115 int m_iGameSeed, m_iStageSeed;
116
117 void SetNewStageSeed();
118
122 [[nodiscard]] auto PlayersCanJoin() const -> bool;
123
124 [[nodiscard]] auto GetCurrentGame() const -> const Game*;
125 [[nodiscard]] auto GetCurrentStyle(PlayerNumber pn) const -> const Style*;
126 void SetCurrentStyle(const Style* style, PlayerNumber pn);
127 auto SetCompatibleStyle(StepsType stype, PlayerNumber pn) -> bool;
128
129 [[nodiscard]] auto IsPlayerEnabled(PlayerNumber pn) const -> bool;
130 [[nodiscard]] auto IsMultiPlayerEnabled(MultiPlayer mp) const -> bool;
131 auto IsPlayerEnabled(const PlayerState* pPlayerState) const -> bool;
132 [[nodiscard]] auto GetNumPlayersEnabled() const -> int;
133
138 [[nodiscard]] auto IsHumanPlayer(PlayerNumber pn) const -> bool;
139 [[nodiscard]] auto GetNumHumanPlayers() const -> int;
140 [[nodiscard]] auto GetFirstHumanPlayer() const -> PlayerNumber;
141 [[nodiscard]] auto GetFirstDisabledPlayer() const -> PlayerNumber;
142 [[nodiscard]] auto IsCpuPlayer(PlayerNumber pn) const -> bool;
143 [[nodiscard]] auto AnyPlayersAreCpu() const -> bool;
144
148 [[nodiscard]] auto GetMasterPlayerNumber() const -> PlayerNumber;
149
153 void SetMasterPlayerNumber(PlayerNumber p);
154
158 [[nodiscard]] auto GetProcessedTimingData() const -> TimingData*;
159
164
165 BroadcastOnChange<std::string>
166 m_sPreferredSongGroup; // GROUP_ALL denotes no preferred group
167 bool m_bFailTypeWasExplicitlySet; // true if FailType was changed in the
168 // song options screen
169 BroadcastOnChange<StepsType> m_PreferredStepsType;
170 BroadcastOnChange<Difficulty> m_PreferredDifficulty;
171 BroadcastOnChange<SortOrder> m_SortOrder; // set by MusicWheel
172 SortOrder m_PreferredSortOrder; // used by MusicWheel
173
174 int m_iNumStagesOfThisSong;
175 // Used by GameplayScreen to know if it needs to call NSMAN
176 bool m_bInNetGameplay = false;
177
188
189 std::string sExpandedSectionName;
190 std::string m_sLastSongGroup;
191
192 static auto GetNumStagesMultiplierForSong(const Song* pSong) -> int;
193 [[nodiscard]] auto GetNumStagesForCurrentSongAndStepsOrCourse() const
194 -> int;
195
196 void BeginStage();
197 void CancelStage();
198 void CommitStageStats();
199 void FinishStage();
200 [[nodiscard]] auto GetCourseSongIndex() const -> int;
201 [[nodiscard]] auto GetPlayerDisplayName(PlayerNumber pn) const
202 -> std::string;
203
204 bool m_bLoadingNextSong;
205 [[nodiscard]] auto GetLoadingCourseSongIndex() const -> int;
206
207 static auto GetEtternaVersion() -> std::string { return "0.74.4"; }
208
209 /* is this the best place for this? it's not exactly a pref, and we
210 * shouldn't be copying and pasting these values everywhere as needed j1-j4
211 * are now all 1.f to remove j1-3 without having to mess with expected array
212 * sizes in other areas yes i know this is lazy */
213 std::vector<float> timingscales = { 1.00F, 1.00F, 1.00F, 1.00F, 0.84F,
214 0.66F, 0.50F, 0.33F, 0.20F };
215 bool isplaylistcourse = false;
216 [[nodiscard]] auto IsPlaylistCourse() const -> bool
217 {
218 return isplaylistcourse;
219 }
220 auto CountNotesSeparately() -> bool;
221
222 // State Info used during gameplay
223
224 // NULL on ScreenSelectMusic if the currently selected wheel item isn't a
225 // Song.
227 // The last Song that the user manually changed to.
228 Song* m_pPreferredSong;
230
231 // Music statistics:
232 SongPosition m_Position;
233
234 BroadcastOnChange<bool> m_bGameplayLeadIn;
235
236 // if re-adding noteskin changes in courses, add functions and such here -aj
237 void GetAllUsedNoteSkins(std::vector<std::string>& out) const;
238
239 static const float MUSIC_SECONDS_INVALID;
240
241 void ResetMusicStatistics(); // Call this when it's time to play a new song.
242 // Clears the values above.
243 void SetPaused(bool p) { m_paused = p; }
244 [[nodiscard]] auto GetPaused() const -> bool { return m_paused; }
245 void UpdateSongPosition(float fPositionSeconds,
246 const TimingData& timing,
247 const RageTimer& timestamp = RageZeroTimer);
248 [[nodiscard]] auto GetSongPercent(float beat) const -> float;
249
250 [[nodiscard]] auto AllAreInDangerOrWorse() const -> bool;
251 [[nodiscard]] auto OneIsHot() const -> bool;
252
253 // used by themes that support heart rate entry.
254 RageTimer m_DanceStartTime;
255 float m_DanceDuration;
256
259
260 // Options stuff
261 ModsGroup<SongOptions> m_SongOptions;
262
269
270 void GetDefaultPlayerOptions(PlayerOptions& po);
271 void GetDefaultSongOptions(SongOptions& so);
272 void ResetToDefaultSongOptions(ModsLevel l);
273 void ApplyPreferredModifiers(PlayerNumber pn,
274 const std::string& sModifiers);
275 void ApplyStageModifiers(PlayerNumber pn, const std::string& sModifiers);
276
277 auto CurrentOptionsDisqualifyPlayer(PlayerNumber pn) -> bool;
278 auto PlayerIsUsingModifier(PlayerNumber pn, const std::string& sModifier)
279 -> bool;
280
281 auto GetPlayerFailType(const PlayerState* pPlayerState) const -> FailType;
282
283 [[nodiscard]] auto GetNumSidesJoined() const -> int;
284 // PlayerState
287 PlayerState* m_pMultiPlayerState[NUM_MultiPlayer];
288
289 auto GetNumCols(int pn) -> int;
290
291 // Preferences
292 static Preference<bool> m_bAutoJoin;
293 static Preference<bool> DisableChordCohesion;
294
295 // These options have weird interactions depending on m_bEventMode,
296 // so wrap them.
297 bool m_bTemporaryEventMode;
298 [[nodiscard]] auto IsEventMode() const -> bool;
299
300 // Edit stuff
301
307 BroadcastOnChange<std::string> m_sEditLocalProfileID;
308 auto GetEditLocalProfile() -> Profile*;
309
310 // Current mode of Gameplay
311 BroadcastOnChange<GameplayMode> m_gameplayMode;
312 [[nodiscard]] auto GetGameplayMode() const -> GameplayMode
313 {
314 return m_gameplayMode;
315 }
316 void TogglePracticeModeSafe(bool set);
317 void TogglePracticeMode(bool set);
318 auto IsPracticeMode() -> bool;
319
320 // A "persistent" way to know if we restarted gameplay (hack)
321 bool m_bRestartedGameplay;
322
323 std::string ProgramHash{};
324
325 // Discord Rich Presence
326 void discordInit();
327 void updateDiscordPresence(const std::string& largeImageText,
328 const std::string& details,
329 const std::string& state,
330 int64_t endTime);
331 void updateDiscordPresenceMenu(const std::string& largeImageText);
332
333 // Lua
334 void PushSelf(lua_State* L);
335
336 // Keep extra stage logic internal to GameState.
337 private:
338 // Timing position corrections
339 RageTimer m_LastPositionTimer;
340 float m_LastPositionSeconds;
341 bool m_paused;
342
343 GameState(const GameState& rhs);
344};
345
346extern GameState*
347 GAMESTATE; // global and accessible from anywhere in our program
348
349#endif
Definition MessageManager.h:296
Definition MessageManager.h:267
Definition MessageManager.h:234
Holds game data that is not saved between sessions.
Definition GameState.h:32
void BeginGame()
Start the game when the first player joins in.
Definition GameState.cpp:415
bool m_bSideIsJoined
Determine which side is joined.
Definition GameState.h:96
void SetProcessedTimingData(TimingData *t)
Set the timing data to be used with processing.
Definition GameState.cpp:195
void SetMasterPlayerNumber(PlayerNumber p)
Set the master player number.
Definition GameState.cpp:183
void Reset()
Reset the GameState back to initial values.
Definition GameState.cpp:260
GameState()
Set up the GameState with initial values.
Definition GameState.cpp:86
bool m_bIsUsingStepTiming
Is the game right now using Song timing or Steps timing?
Definition GameState.h:306
PlayerState * m_pPlayerState
Allow access to each player's PlayerState.
Definition GameState.h:286
void ResetStageStatistics()
Call this function when it's time to play a new stage.
Definition GameState.cpp:737
bool m_bDidModeChangeNoteSkin
Did the current game mode change the default Noteskin?
Definition GameState.h:268
auto PlayersCanJoin() const -> bool
Determine if a second player can join in at this time.
Definition GameState.cpp:822
void SaveCurrentSettingsToProfile(PlayerNumber pn)
Save the specified player's settings to his/her profile.
Definition GameState.cpp:604
int m_iPlayerStageTokens
The number of stages available for the players.
Definition GameState.h:187
auto IsHumanPlayer(PlayerNumber pn) const -> bool
Is the specified Player a human Player?
Definition GameState.cpp:919
int m_iCurrentStageIndex
Increase this every stage while not resetting on a continue.
Definition GameState.h:182
auto GetProcessedTimingData() const -> TimingData *
Retrieve the present timing data being processed.
Definition GameState.cpp:189
void SetCurGame(const Game *pGame)
State what the current game is.
Definition GameState.cpp:715
auto GetMasterPlayerNumber() const -> PlayerNumber
Retrieve the present master player number.
Definition GameState.cpp:177
Definition LuaReference.h:105
Definition ModsGroup.h:44
Per-player options that are not saved between sessions.
Definition PlayerOptions.h:48
The player's indivdual state.
Definition PlayerState.h:30
Definition Preference.h:53
Player data that persists between sessions.
Definition Profile.h:130
Definition RageTimer.h:9
Definition SongOptions.h:37
Definition SongPosition.h:10
Holds all music metadata and steps for one song.
Definition Song.h:65
Contains statistics for one stage of play.
Definition StageStats.h:15
Holds note information for a Song.
Definition Steps.h:42
Definition Style.h:22
Holds data for translating beats<->seconds.
Definition TimingData.h:54
Holds information about a particular style of a game (e.g. "single", "double").
Definition Game.h:33