99#include < span>
1010#include < spdlog/spdlog.h>
1111
12- struct TetrisApplication : public Application {
12+ /* *
13+ * @brief This struct inherits from Application and implements the game's functionality. Instantiate this struct
14+ * and call run() on it to start the main game loop.
15+ */
16+ struct TetrisApplication final : public Application {
1317private:
1418 using TetrionHeaders = std::vector<Recording::TetrionHeader>;
1519
@@ -25,43 +29,133 @@ struct TetrisApplication : public Application {
2529 static constexpr int width = 800 ;
2630 static constexpr int height = 600 ;
2731
32+ /* *
33+ * @brief Constructs a TetrisApplication instance.
34+ * @param command_line_arguments The command line arguments passed to the executable.
35+ */
2836 explicit TetrisApplication (CommandLineArguments command_line_arguments);
2937
3038protected:
39+ /* *
40+ * @brief Calls the update() functions on all elements of m_inputs.
41+ */
3142 void update_inputs ();
43+
44+ /* *
45+ * @brief Calls the update() functions on all elements of m_tetrions.
46+ */
3247 void update_tetrions ();
48+
49+ /* *
50+ * @brief Updates all inputs and all tetrions.
51+ */
3352 void update () override ;
53+
54+ /* *
55+ * @brief Renders the contents of the window.
56+ */
3457 void render () const override ;
3558
3659private:
60+ /* *
61+ * @brief Creates an input from given controls.
62+ * @param controls The controls (e.g. keyboard bindings) to apply for this control.
63+ * @param associated_tetrion The tetrion that is targeted by this input.
64+ * @param on_event_callback Callback that is invoked when an input event happens.
65+ * @return The input.
66+ */
3767 [[nodiscard]] std::unique_ptr<Input>
3868 create_input (Controls controls, Tetrion* associated_tetrion, Input::OnEventCallback on_event_callback);
3969
70+ /* *
71+ * @brief Creates an input that replays a recorded game.
72+ * @param tetrion_index The index of the tetrion that is targeted by this input.
73+ * @param recording_reader A pointer to the RecordingReader that holds the recorded game.
74+ * @param associated_tetrion The tetrion that is targeted by this input.
75+ * @param on_event_callback Callback that is invoked when an input event happens.
76+ * @return The input.
77+ */
4078 [[nodiscard]] static std::unique_ptr<Input> create_recording_input (
4179 u8 tetrion_index,
4280 RecordingReader* recording_reader,
4381 Tetrion* associated_tetrion,
4482 Input::OnEventCallback on_event_callback
4583 );
4684
85+ /* *
86+ * @brief Creates a callback that can be passed to create_input() or create_recording_input(). If a game is being
87+ * recorded, the returned callback stores all events in the associated RecordingWriter (m_recording_writer).
88+ * Otherwise, a callback that does nothing is returned.
89+ * @param tetrion_index The index of the tetrion that shall be recorded.
90+ * @return The callback.
91+ */
4792 [[nodiscard]] Input::OnEventCallback create_on_event_callback (int tetrion_index);
4893
94+ /* *
95+ * @brief Tries to load the settings from settings.json and stores them into m_settings. Applies default
96+ * values upon failure.
97+ */
4998 void try_load_settings ();
5099
100+ /* *
101+ * @brief Returns true if the path to a recorded game was specified as command line argument, false otherwise.
102+ * @return Whether a replay shall be replayed.
103+ */
51104 [[nodiscard]] bool is_replay_mode () const ;
52105
106+ /* *
107+ * @brief Returns true if the current game shall be recorded, false otherwise. The game shall be recorded if it's
108+ * not replaying a recorded game.
109+ * @return Whether the game shall be recorded.
110+ */
53111 [[nodiscard]] bool game_is_recorded () const ;
54112
113+ /* *
114+ * @brief Returns the random seed to be used for a given tetrion. The choice is based on whether a recorded
115+ * game is being replayed (then the seed of the recording is used) or not (then the passed common_seed is used).
116+ * @param tetrion_index The index of the tetrion this seed shall be used for.
117+ * @param common_seed The common random seed to be used if the application is not replaying a recorded game.
118+ * @return The seed for the tetrion.
119+ */
55120 [[nodiscard]] Random::Seed seed_for_tetrion (u8 tetrion_index, Random::Seed common_seed) const ;
56121
122+ /* *
123+ * @brief Returns the starting level for a given tetrion. The choice is based on whether a recorded game is
124+ * being replayed (then the starting level of the recording is used) or not (then the starting level is taken
125+ * from the command line arguments (maybe its default value).
126+ * @param tetrion_index The index of the tetrion this starting level shall be used for.
127+ * @return The starting level.
128+ */
57129 [[nodiscard]] auto starting_level_for_tetrion (u8 tetrion_index) const
58130 -> decltype(CommandLineArguments::starting_level);
59131
132+ /* *
133+ * @brief Creates the TetrionHeader instances to be used when a game shall be recorded. This data is part of the
134+ * header of the recording.
135+ * @param seeds The seeds of all tetrions.
136+ * @return The tetrion headers for all tetrions.
137+ */
60138 [[nodiscard]] TetrionHeaders create_tetrion_headers (std::span<const Random::Seed> seeds) const ;
61139
140+ /* *
141+ * @brief Creates the subdirectory for recorded games (if necessary) and instantiates a RecordingWriter to start
142+ * recording the game. The output filename is based on the current date and time.
143+ * @param tetrion_headers The tetrion headers of all tetrions.
144+ * @return The RecordingWriter.
145+ */
62146 [[nodiscard]] static std::unique_ptr<RecordingWriter> create_recording_writer (TetrionHeaders tetrion_headers);
63147
148+ /* *
149+ * @brief Creates seeds for a given number of tetrions.
150+ * @param num_tetrions The number of tetrions.
151+ * @return The seeds for all tetrions.
152+ */
64153 [[nodiscard]] std::vector<Random::Seed> create_seeds (u8 num_tetrions) const ;
65154
155+ /* *
156+ * @brief Returns an tl::optional containing a pointer to the object managed by m_recording_writer if present.
157+ * Otherwise returns an empty tl::optional.
158+ * @return The pointer to the RecordingWriter as an tl::optional.
159+ */
66160 [[nodiscard]] tl::optional<RecordingWriter*> recording_writer_optional ();
67161};
0 commit comments