Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
SceneState.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_SCENE_STATE_H_
34#define DVD_SCENE_STATE_H_
35
37
42
45
46namespace Divide {
47
49
50enum class MusicType : U8 {
53 COUNT
54};
55
57{
61
62 bool operator==(const WaterBodyData& other) const = default;
63};
64
66{
67 // (w == 1) - enabled
70};
71
73{
76
77 bool operator==(const FogDetails& other) const = default;
78};
79
80class Scene;
81class LightPool;
82class RenderPass;
83
87 public:
88 enum class RenderOptions : U16 {
90 RENDER_AABB = toBit(1),
92 RENDER_OBB = toBit(2),
104 ALL_GIZMOS = toBit(9),
105 COUNT = 9
106 };
107
108 explicit SceneRenderState(Scene& parentScene) noexcept;
109
110 void renderMask(U16 mask);
111 void enableOption(RenderOptions option) noexcept;
112 void disableOption(RenderOptions option) noexcept;
113 void toggleOption(RenderOptions option) noexcept;
114 void toggleOption(RenderOptions option, bool state) noexcept;
115 [[nodiscard]] bool isEnabledOption(RenderOptions option) const noexcept;
116
117 PROPERTY_RW(F32, generalVisibility, 1000.0f);
118 PROPERTY_RW(F32, grassVisibility, 1000.0f);
119 PROPERTY_RW(F32, treeVisibility, 1000.0f);
120 PROPERTY_RW(U8, renderPass, 0u);
122 PROPERTY_RW(I64, singleNodeRenderGUID, -1);
123 [[nodiscard]] vec4<U16>& lodThresholds() noexcept { return _lodThresholds; }
124 [[nodiscard]] vec4<U16> lodThresholds(RenderStage stage = RenderStage::DISPLAY) const noexcept;
125
126 protected:
129};
130
131class Camera;
132
133enum class MoveDirection : I8
134{
135 NONE = 0,
136 NEGATIVE = -1,
137 POSITIVE = 1
138};
139
140constexpr F32 DEFAULT_PLAYER_HEIGHT = 1.82f;
141
143{
146};
147
149{
150 std::array<MoveDirectionRequest, 2> _directions;
151
152 [[nodiscard]] inline MoveDirectionRequest top() const noexcept
153 {
154 return _directions[0];
155 }
156
157 [[nodiscard]] inline F32 topValue() const noexcept
158 {
159 const MoveDirectionRequest& direction = top();
160 if (direction._direction == MoveDirection::NONE)
161 {
162 return 0.f;
163 }
164
165 return (direction._speedPercentage / 255.f) * (direction._direction == MoveDirection::NEGATIVE ? -1.f : 1.f);
166 }
167
168 void push( const MoveDirectionRequest direction ) noexcept
169 {
170 _directions[1] = _directions[0];
171 _directions[0] = direction;
172 }
173
174 void pop() noexcept
175 {
176 _directions[0] = _directions[1];
177 _directions[1] = {};
178 }
179
180 void reset() noexcept
181 {
182 _directions.fill({});
183 }
184};
185
187 void resetMoveDirections() noexcept;
188 void resetAll() noexcept;
189
190 PROPERTY_RW(bool, cameraUnderwater, false);
191 PROPERTY_RW(bool, cameraUpdated, false);
192 PROPERTY_RW(bool, cameraLockedToMouse, false);
193
201
202 POINTER_RW(Camera, overrideCamera, nullptr);
203
205};
206
207using WaterBodyDataContainer = eastl::fixed_vector<WaterBodyData, 5, true>;
208
210 public:
213
214 explicit SceneState(Scene& parentScene);
215
216 void onPlayerAdd(const U8 index) noexcept { onPlayerRemove(index); }
217
218 inline void onPlayerRemove(const U8 index) noexcept { _playerState[index].resetAll(); }
219
220 [[nodiscard]] inline SceneStatePerPlayer& playerState() noexcept { return _playerState[playerPass()]; }
221 [[nodiscard]] inline const SceneStatePerPlayer& playerState() const noexcept { return _playerState[playerPass()]; }
222
223 [[nodiscard]] inline SceneStatePerPlayer& playerState(const U8 index) noexcept { return _playerState[index]; }
224 [[nodiscard]] inline const SceneStatePerPlayer& playerState(const U8 index) const noexcept { return _playerState[index]; }
225
226 [[nodiscard]] inline SceneRenderState& renderState() noexcept { return _renderState; }
227 [[nodiscard]] inline const SceneRenderState& renderState() const noexcept { return _renderState; }
228
229 [[nodiscard]] inline MusicPlaylist& music(const MusicType type) noexcept { return _music[to_U32(type)]; }
230 [[nodiscard]] inline const MusicPlaylist& music(const MusicType type) const noexcept { return _music[to_U32(type)]; }
231
232 [[nodiscard]] inline WaterBodyDataContainer& waterBodies() noexcept { return _waterBodies; }
233 [[nodiscard]] inline const WaterBodyDataContainer& waterBodies() const noexcept { return _waterBodies; }
234
235 PROPERTY_RW(U8, playerPass, 0u);
236 PROPERTY_RW(bool, saveLoadDisabled, false);
237 PROPERTY_RW(F32, windSpeed, 1.0f);
238 PROPERTY_RW(F32, windDirX, 0.1f);
239 PROPERTY_RW(F32, windDirZ, 0.7f);
240 PROPERTY_RW(F32, lightBleedBias, 0.2f);
241 PROPERTY_RW(F32, minShadowVariance, 0.00001f);
242 PROPERTY_RW(bool, screenshotRequestQueued, false);
243
244protected:
247 std::array<SceneStatePerPlayer, Config::MAX_LOCAL_PLAYER_COUNT> _playerState;
249};
250
252
253} // namespace Divide
254
255#endif //DVD_SCENE_STATE_H_
#define FWD_DECLARE_MANAGED_CLASS(T)
Scene & parentScene() noexcept
void disableOption(RenderOptions option) noexcept
Definition: SceneState.cpp:84
@ RENDER_WIREFRAME
Render wireframe for all scene geometry.
@ RENDER_OBB
Show/hide oriented bounding boxes.
@ RENDER_SKELETONS
Render skeletons for animated geometry.
@ RENDER_CUSTOM_PRIMITIVES
Show/hide custom IMPrimitive elements.
@ RENDER_AABB
Show/hide axis aligned bounding boxes.
@ RENDER_BSPHERES
Show/hide bounding spheres.
PROPERTY_RW(I64, singleNodeRenderGUID, -1)
PROPERTY_RW(F32, grassVisibility, 1000.0f)
bool isEnabledOption(RenderOptions option) const noexcept
Definition: SceneState.cpp:74
PROPERTY_RW(F32, generalVisibility, 1000.0f)
void enableOption(RenderOptions option) noexcept
Definition: SceneState.cpp:79
void renderMask(U16 mask)
Definition: SceneState.cpp:42
vec4< U16 > _lodThresholds
Definition: SceneState.h:127
vec4< U16 > & lodThresholds() noexcept
Definition: SceneState.h:123
void toggleOption(RenderOptions option) noexcept
Definition: SceneState.cpp:89
PROPERTY_RW(FogDetails, fogDetails)
PROPERTY_RW(U8, renderPass, 0u)
PROPERTY_RW(F32, treeVisibility, 1000.0f)
SceneRenderState _renderState
Definition: SceneState.h:245
WaterBodyDataContainer _waterBodies
Definition: SceneState.h:248
std::array< MusicPlaylist, to_base(MusicType::COUNT)> _music
Definition: SceneState.h:246
std::array< SceneStatePerPlayer, Config::MAX_LOCAL_PLAYER_COUNT > _playerState
Definition: SceneState.h:247
const SceneStatePerPlayer & playerState() const noexcept
Definition: SceneState.h:221
PROPERTY_RW(F32, windSpeed, 1.0f)
void onPlayerAdd(const U8 index) noexcept
Definition: SceneState.h:216
hashMap< U64, Handle< AudioDescriptor > > MusicPlaylist
Background music map : trackName - track.
Definition: SceneState.h:212
PROPERTY_RW(bool, screenshotRequestQueued, false)
SceneStatePerPlayer & playerState(const U8 index) noexcept
Definition: SceneState.h:223
PROPERTY_RW(F32, windDirX, 0.1f)
void onPlayerRemove(const U8 index) noexcept
Definition: SceneState.h:218
PROPERTY_RW(F32, windDirZ, 0.7f)
PROPERTY_RW(F32, minShadowVariance, 0.00001f)
PROPERTY_RW(F32, lightBleedBias, 0.2f)
SceneStatePerPlayer & playerState() noexcept
Definition: SceneState.h:220
SceneRenderState & renderState() noexcept
Definition: SceneState.h:226
const WaterBodyDataContainer & waterBodies() const noexcept
Definition: SceneState.h:233
WaterBodyDataContainer & waterBodies() noexcept
Definition: SceneState.h:232
const SceneRenderState & renderState() const noexcept
Definition: SceneState.h:227
MusicPlaylist & music(const MusicType type) noexcept
Definition: SceneState.h:229
const SceneStatePerPlayer & playerState(const U8 index) const noexcept
Definition: SceneState.h:224
const MusicPlaylist & music(const MusicType type) const noexcept
Definition: SceneState.h:230
PROPERTY_RW(bool, saveLoadDisabled, false)
PROPERTY_RW(U8, playerPass, 0u)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
constexpr U32 to_U32(const T value)
eastl::fixed_vector< WaterBodyData, 5, true > WaterBodyDataContainer
Definition: SceneState.h:207
uint8_t U8
hashAlg::unordered_map< K, V, HashFun, Predicate > hashMap
Definition: HashMap.h:55
constexpr F32 DEFAULT_PLAYER_HEIGHT
Definition: SceneState.h:140
uint16_t U16
MoveDirection
Definition: SceneState.h:134
int64_t I64
static const vec4< F32 > VECTOR4_ZERO
Definition: MathVectors.h:1435
constexpr T toBit(const T X)
Converts an arbitrary positive integer value to a bitwise value used for masks.
constexpr auto to_base(const Type value) -> Type
vec4< F32 > _colourAndDensity
Definition: SceneState.h:74
vec4< F32 > _colourSunScatter
Definition: SceneState.h:75
bool operator==(const FogDetails &other) const =default
U8 _speedPercentage
0...255 maps to 0...100%
Definition: SceneState.h:144
void reset() noexcept
Definition: SceneState.h:180
void pop() noexcept
Definition: SceneState.h:174
MoveDirectionRequest top() const noexcept
Definition: SceneState.h:152
void push(const MoveDirectionRequest direction) noexcept
Definition: SceneState.h:168
std::array< MoveDirectionRequest, 2 > _directions
Definition: SceneState.h:150
F32 topValue() const noexcept
Definition: SceneState.h:157
vec4< F32 > _positionW
Definition: SceneState.h:68
vec4< F32 > _halfExtents
Definition: SceneState.h:69
PROPERTY_RW(bool, cameraUnderwater, false)
PROPERTY_RW(bool, cameraUpdated, false)
PROPERTY_RW(bool, cameraLockedToMouse, false)
POINTER_RW(Camera, overrideCamera, nullptr)
void resetMoveDirections() noexcept
Definition: SceneState.cpp:8
void resetAll() noexcept
Definition: SceneState.cpp:19
vec4< F32 > _positionW
Definition: SceneState.h:58
bool operator==(const WaterBodyData &other) const =default
vec4< F32 > _extents
length, depth, width
Definition: SceneState.h:60