NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_scene.hpp
1#pragma once
2#include <game/bases/d_base.hpp>
4#include <game/sLib/s_Phase.hpp>
5
6/**
7 * @brief The minimum required implementation for a scene base.
8 * @ingroup bases
9 * @details
10 * ## Overview
11 * Scene bases act as overall managers for specific parts of the game. As such, only one scene can be active at
12 * any given time. All bases are created as children of the @ref ::m_nowScene "currently active scene", which
13 * allows a scene switch to act as a garbage collection mechanism by deleting every other active base.
14 *
15 * Scene execution (and therefore every other base's) cannot begin until the scene has finished initializing.
16 *
17 * The game's initial scene is dScBoot_c (which performs various initialization tasks), while dScRestartCrsin_c
18 * is used for soft resets to return to the title screen.
19 *
20 * ## Switching Scenes
21 * To switch from the current scene to another, use the ::setNextScene function, providing the new scene's
22 * profile name and parameters. The creation of the next scene is handled automatically.
23 *
24 * @note
25 * - Scene switches during resets are typically disallowed. However, this restriction can be bypassed by setting
26 * the @p forceChange parameter to @p true in the ::setNextScene call.
27 * - A scene switch cannot occur until the existing scene has completed its initialization, regardless of the
28 * aforementioned parameter.
29 * - Consecutive calls to set the next scene will have no effect.
30 *
31 * ## Scene Initialization
32 * An @ref mpPhase "initialization phase" can be provided to set up the scene step by step. Typical actions
33 * include:
34 * - Loading additional resources (such as @ref dRes_c "archives", @ref LytBase_c "layouts" or effects) not
35 * linked to a specific base (e.g. the worldmap model in the @ref dScWMap_c "worldmap scene"). Checks must be
36 * added to ensure these resources have finished loading before initialization ends.
37 * - Loading additional sound objects (see [below](#audio-initialization)).
38 * - Creating specific bases necessary for the scene's functionality (e.g. the game interface for the scene).
39 * @note The LASTACTOR base is created automatically.
40 * - Setting the scene's paint function, which must always be the final step in initialization.
41 * - In earlier development stages, any base used by the scene was dynamically linked in the first
42 * initialization step.
43 *
44 * Failure to complete initialization (e.g. due to missing resources) will cause the game to softlock.
45 *
46 * @hint{Existing scene initialization phases are a good reference point for implementing custom scenes.}
47 *
48 * ### Audio Initialization
49 * The following sound objects are automatically created and deleted; other sound objects must be managed
50 * manually:
51 * - SndObjctCmnEmy_c
52 * - SndObjctCmnMap_c
53 * - NonPosSndObjctAmb_c
54 *
55 * @todo Expand this section when dAudio and the related classes are decompiled.
56 *
57 * ## Scene Fading
58 * The fader to be used for a scene transition can be set with dFader_c::setFader. The fade-in and fade-out
59 * durations can be set using ::setFadeInFrame and ::setFadeOutFrame respectively. Both can be set simultaneously
60 * with ::setFadeInOutFrame).
61 *
62 * The previous scene is automatically deleted once the fade-out completes. The next scene will fade in automatically
63 * unless ::m_isAutoFadeIn is set to @p false (in that case, the fade-in must be started manually by calling
64 * dFader_c::startFadeIn and audio must be reinitialized with dAudio::requestStartScene).
65 */
66class dScene_c : public dBase_c {
67public:
68 dScene_c(); ///< Creates a new scene.
69 ~dScene_c(); ///< Destroys the scene.
70
71 virtual int preCreate();
72
73 /// @copybrief fBase_c::postCreate
74 /// @details Appends a LASTACTOR child base to this scene.
75 virtual void postCreate(fBase_c::MAIN_STATE_e status);
76
77 virtual int preDelete();
78 virtual void postDelete(fBase_c::MAIN_STATE_e status);
79
80 /// @copybrief fBase_c::preExecute
81 /// @details If ::m_nextScene is set, prepares to transition to the next scene.
82 /// Once all initial child bases have been added, the execute and draw operations are enabled on this base
83 /// and its children.
84 virtual int preExecute();
85 virtual void postExecute(fBase_c::MAIN_STATE_e status);
86
87 virtual int preDraw();
88 virtual void postDraw(fBase_c::MAIN_STATE_e status);
89
90 static void setStartScene(); ///< Sets up the scene to be shown when the game boots up.
91 static void setResetScene(); ///< Sets up the scene to be shown after a game reset.
92 static dScene_c *createNextScene(); ///< Creates and returns a root base for the next scene.
93
94 /// @brief Attempts to prepare the transition to a new scene.
95 /// @details If the game is resetting, the transition is not performed unless forceChange is @p true.
96 /// @param nextScene The next scene's profile name.
97 /// @param param The next scene's parameters.
98 /// @param forceChange If the transition should always be performed.
99 static void setNextScene(ProfileName nextScene, unsigned long param, bool forceChange);
100
101 /// @brief Sets the duration of the next fade-in transition to @p length.
102 static void setFadeInFrame(unsigned short length);
103
104 /// @brief Sets the duration of the next fade-out transition to @p length.
105 static void setFadeOutFrame(unsigned short length);
106
107 /// @brief Sets the duration of the next fade-in and fade-out transitions to @p length.
108 static void setFadeInOutFrame(unsigned short length);
109
110 sPhase_c *mpPhase; ///< The phase used for scene initialization.
111
112 static u32 mPara; ///< The parameters for the next scene.
113 static ProfileName m_nextScene; ///< The profile name of the next scene.
114 static ProfileName m_nowScene; ///< The profile name of the current scene.
115 static ProfileName m_oldScene; ///< The profile name of the previous scene.
116 static bool m_otherSceneFlg; ///< Whether the next scene has already been created.
117
118 static u16 m_fadeInFrame; ///< The duration of the next fade-in.
119 static u16 m_fadeOutFrame; ///< The duration of the next fade-out.
120 static bool m_isAutoFadeIn; ///< If a fade-in should automatically be performed on scene load.
121};
dBase_c()
Constructs a new base.
Definition d_base.cpp:12
virtual int preExecute()
pre method for the execute operation.
Definition d_scene.cpp:77
static void setFadeInFrame(unsigned short length)
Sets the duration of the next fade-in transition to length.
Definition d_scene.cpp:184
static void setStartScene()
Sets up the scene to be shown when the game boots up.
Definition d_scene.cpp:133
~dScene_c()
Destroys the scene.
Definition d_scene.cpp:37
virtual void postExecute(fBase_c::MAIN_STATE_e status)
post method for the execute operation.
Definition d_scene.cpp:115
virtual void postDelete(fBase_c::MAIN_STATE_e status)
post method for the delete operation.
Definition d_scene.cpp:69
static dScene_c * createNextScene()
Creates and returns a root base for the next scene.
Definition d_scene.cpp:145
virtual int preDraw()
pre method for the draw operation.
Definition d_scene.cpp:122
static void setFadeOutFrame(unsigned short length)
Sets the duration of the next fade-out transition to length.
Definition d_scene.cpp:188
virtual void postDraw(fBase_c::MAIN_STATE_e status)
post method for the draw operation.
Definition d_scene.cpp:129
static bool m_isAutoFadeIn
If a fade-in should automatically be performed on scene load.
Definition d_scene.hpp:120
dScene_c()
Creates a new scene.
Definition d_scene.cpp:23
virtual void postCreate(fBase_c::MAIN_STATE_e status)
post method for the create operation.
Definition d_scene.cpp:53
sPhase_c * mpPhase
The phase used for scene initialization.
Definition d_scene.hpp:110
static ProfileName m_nextScene
The profile name of the next scene.
Definition d_scene.hpp:113
virtual int preDelete()
pre method for the delete operation.
Definition d_scene.cpp:62
static u16 m_fadeInFrame
The duration of the next fade-in.
Definition d_scene.hpp:118
static bool m_otherSceneFlg
Whether the next scene has already been created.
Definition d_scene.hpp:116
static void setResetScene()
Sets up the scene to be shown after a game reset.
Definition d_scene.cpp:141
static u32 mPara
The parameters for the next scene.
Definition d_scene.hpp:112
static ProfileName m_nowScene
The profile name of the current scene.
Definition d_scene.hpp:114
virtual int preCreate()
pre method for the create operation.
Definition d_scene.cpp:44
static u16 m_fadeOutFrame
The duration of the next fade-out.
Definition d_scene.hpp:119
static void setFadeInOutFrame(unsigned short length)
Sets the duration of the next fade-in and fade-out transitions to length.
Definition d_scene.cpp:192
static void setNextScene(ProfileName nextScene, unsigned long param, bool forceChange)
Attempts to prepare the transition to a new scene.
Definition d_scene.cpp:162
static ProfileName m_oldScene
The profile name of the previous scene.
Definition d_scene.hpp:115
MAIN_STATE_e
The possible operation results.
Definition f_base.hpp:137
A phase is a list of methods to be called in order.
Definition s_Phase.hpp:5
u16 ProfileName
The name of a profile. Value is a fProfile::PROFILE_NAME_e.
Definition f_profile.hpp:32