Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
   Copyright (c) 2018 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _SCENE_STATE_H_
#define _SCENE_STATE_H_

#include "Platform/Audio/Headers/SFXDevice.h"
#include "Platform/Video/Headers/RenderAPIEnums.h"
#include "Platform/Audio/Headers/AudioDescriptor.h"
#include "Core/Resources/Headers/ResourceCache.h"
#include "Core/Headers/Console.h"
#include "Scenes/Headers/SceneComponent.h"
#include "Utility/Headers/Localization.h"

/// This class contains all the variables that define each scene's
/// "unique"-ness:
/// background music, wind information, visibility settings, camera movement,
/// BB and Skeleton visibility, fog info, etc

/// Fog information (fog is so game specific, that it belongs in SceneState not
/// SceneRenderState

namespace Divide {

enum class MusicType : U32 {
    TYPE_BACKGROUND = 0,
    TYPE_COMBAT,
    COUNT
};


struct FogDescriptor {
  public:
    FogDescriptor();

    inline bool dirty() const { return _dirty; }
    inline F32 density() const { return _density; }
    inline const vec3<F32>& colour() const { return _colour; }

    inline void set(const vec3<F32>& colour, F32 density) {
        _colour.set(colour);
        _density = density;
        _dirty = true;
    }


  protected:
    friend class SceneManager;
    inline void clean() {
        _dirty = false;
    }
    inline void active(const bool state) {
        _active = state;
    }
    inline bool active() const {
        return _active;
    }
  private:
    bool _dirty;
    bool _active;
    F32 _density;
    vec3<F32> _colour;
};

class Scene;
class LightPool;
class RenderPass;
namespace Attorney {
    class SceneRenderStateScene;
};

/// Contains all the information needed to render the scene: camera position,
/// render state, etc
class SceneRenderState : public SceneComponent {
    friend class Attorney::SceneRenderStateScene;

   public:
    enum class GizmoState : U32 {
        NO_GIZMO = toBit(1),
        SCENE_GIZMO = toBit(2),
        SELECTED_GIZMO = toBit(3),
        ALL_GIZMO = SCENE_GIZMO | SELECTED_GIZMO,
        COUNT = 4
    };

    enum class RenderOptions : U32 {
        /// Show/hide bounding boxes and/or objects
        RENDER_AABB = toBit(1),
        /// Show/hide debug lines
        RENDER_DEBUG_LINES = toBit(2),
        RENDER_DEBUG_TARGET_LINES = toBit(3),
        /// Show/hide geometry
        RENDER_GEOMETRY = toBit(4),
        /// Render skeletons for animated geometry
        RENDER_SKELETONS = toBit(5),
        /// Render wireframe for all scene geometry
        RENDER_WIREFRAME = toBit(6),
        RENDER_OCTREE_REGIONS = toBit(7),
        PLAY_ANIMATIONS = toBit(8),
        COUNT = 8
    };

    explicit SceneRenderState(Scene& parentScene);

    void renderMask(U32 mask);
    bool isEnabledOption(RenderOptions option) const;
    void enableOption(RenderOptions option);
    void disableOption(RenderOptions option);
    void toggleOption(RenderOptions option);
    void toggleOption(RenderOptions option, const bool state);

    /// Show/hide axis gizmos
    void toggleAxisLines();
    
    inline void gizmoState(GizmoState newState) {
        _gizmoState = newState;
    }
    
    inline GizmoState gizmoState() const {
        return _gizmoState;
    }

    inline void generalVisibility(F32 distance) { _generalVisibility = distance; }
    inline F32  generalVisibility()       const { return _generalVisibility; }

    inline void grassVisibility(F32 distance) { _grassVisibility = distance; }
    inline F32  grassVisibility()       const { return _grassVisibility; }

    inline void treeVisibility(F32 distance) { _treeVisibility = distance; }
    inline F32  treeVisibility()       const { return _treeVisibility; }

    inline void playerPass(U8 pass) { _playerPass = pass; }
    inline U8   playerPass()  const { return _playerPass; }

   protected:
    U8  _playerPass;
    U32 _stateMask;
    GizmoState _gizmoState;
    F32 _grassVisibility;
    F32 _treeVisibility;
    F32 _generalVisibility;
};

class Camera;

enum class MoveDirection : I32 {
    NONE = 0,
    NEGATIVE = -1,
    POSITIVE = 1
};

class SceneStatePerPlayer {
  public:
    SceneStatePerPlayer()
        : _cameraLockedToMouse(false),
          _cameraUnderwater(false),
          _cameraUpdated(false),
          _overrideCamera(nullptr)
    {
         resetMovement();
    }

    inline void resetMovement() {
        _moveFB = _moveLR = _angleUD = _angleLR = _roll = MoveDirection::NONE;
        _aimPos.reset();
        _aimDelta.reset();
    }

    inline void cameraUnderwater(bool state) { _cameraUnderwater = state; }
    inline bool cameraUnderwater()     const { return _cameraUnderwater; }

    inline void cameraUpdated(bool state) { _cameraUpdated = state; }
    inline bool cameraUpdated()     const { return _cameraUpdated; }

    inline void moveFB(MoveDirection factor) { _moveFB = factor; }
    inline MoveDirection  moveFB()     const { return _moveFB; }

    inline void moveLR(MoveDirection factor) { _moveLR = factor; }
    inline MoveDirection  moveLR()     const { return _moveLR; }

    inline void angleUD(MoveDirection factor) { _angleUD = factor; }
    inline MoveDirection  angleUD()     const { return _angleUD; }

    inline void angleLR(MoveDirection factor) { _angleLR = factor; }
    inline MoveDirection  angleLR()     const { return _angleLR; }

    inline void roll(MoveDirection factor) { _roll = factor; }
    inline MoveDirection  roll()     const { return _roll; }

    inline void cameraLockedToMouse(bool state) { _cameraLockedToMouse = state; }
    inline bool cameraLockedToMouse()     const { return _cameraLockedToMouse; }

    inline void aimPos(const vec2<I32>& position) { _aimDelta.set(_aimPos - position); _aimPos.set(position); }
    inline const vec2<I32>&  aimPos()       const { return _aimPos; }

    inline const vec2<I32>&  aimDelta()     const { return _aimDelta; }

    inline void    overrideCamera(Camera* camera) { _overrideCamera = camera; }
    inline Camera* overrideCamera()         const { return _overrideCamera; }

private:
    vec2<I32> _aimPos;
    vec2<I32> _aimDelta;

    bool _cameraLockedToMouse;
    MoveDirection _moveFB;   ///< forward-back move change detected
    MoveDirection _moveLR;   ///< left-right move change detected
    MoveDirection _angleUD;  ///< up-down angle change detected
    MoveDirection _angleLR;  ///< left-right angle change detected
    MoveDirection _roll;     ///< roll left or right change detected
    bool _cameraUnderwater;
    // was the camera moved or rotated this frame
    bool _cameraUpdated;
    Camera* _overrideCamera;
};

class SceneState : public SceneComponent {
   public:
    /// Background music map : trackName - track
    typedef hashMapImpl<U64, AudioDescriptor_ptr> MusicPlaylist;

    SceneState(Scene& parentScene)
        : SceneComponent(parentScene),
          _renderState(parentScene),
          _saveLoadDisabled(false),
          _waterHeight(0.0f),
          _waterDepth(0.0f),
          _windSpeed(1.0f),
          _windDirX(0.0f),
          _windDirZ(1.0f)
    {
        _fog.set(vec3<F32>(0.2f, 0.2f, 0.2f), 0.01f);
    }

    virtual ~SceneState()
    {
        for (MusicPlaylist& playlist : _music) {
            playlist.clear();
        }
    }

    inline void onPlayerAdd(U8 index) {
        _playerState.insert(std::make_pair(index, SceneStatePerPlayer()));
    }

    inline void onPlayerRemove(U8 index) {
        playerState(index).resetMovement();
    }

    inline SceneStatePerPlayer& playerState(U8 index) { return _playerState.find(index)->second; }
    inline const SceneStatePerPlayer& playerState(U8 index) const { return _playerState.find(index)->second; }

    inline FogDescriptor& fogDescriptor()   { return _fog; }
    inline SceneRenderState& renderState()  { return _renderState; }
    inline MusicPlaylist& music(MusicType type) { return _music[to_U32(type)]; }

    inline const FogDescriptor& fogDescriptor() const { return _fog; }
    inline const SceneRenderState& renderState() const { return _renderState; }
    inline const MusicPlaylist& music(MusicType type) const { return _music[to_U32(type)]; }

    inline void windSpeed(F32 speed) { _windSpeed = speed; }
    inline F32  windSpeed()    const { return _windSpeed; }

    inline void windDirX(F32 factor) { _windDirX = factor; }
    inline F32  windDirX()     const { return _windDirX; }

    inline void windDirZ(F32 factor) { _windDirZ = factor; }
    inline F32  windDirZ()     const { return _windDirZ; }

    inline void waterLevel(F32 level) { _waterHeight = level; }
    inline F32  waterLevel()    const { return _waterHeight; }

    inline void waterDepth(F32 depth) { _waterDepth = depth; }
    inline F32  waterDepth()    const { return _waterDepth; }

    inline void saveLoadDisabled(const bool state) { _saveLoadDisabled = state; }
    inline bool saveLoadDisabled()           const { return _saveLoadDisabled; }

protected:

    std::array<MusicPlaylist, to_base(MusicType::COUNT)> _music;
    hashMapImpl<U8, SceneStatePerPlayer> _playerState;

    bool _saveLoadDisabled;

    F32 _waterHeight;
    F32 _waterDepth;

    FogDescriptor _fog;
    /// saves all the rendering information for the scene
    /// (camera position, light info, draw states)
    SceneRenderState _renderState;
    F32 _windSpeed;
    F32 _windDirX;
    F32 _windDirZ;
};

namespace Attorney {
class SceneRenderStateScene {
   private:
    static void playAnimations(SceneRenderState& sceneRenderState,
                               bool playAnimations) {
        if (playAnimations) {
            SetBit(sceneRenderState._stateMask, to_base(SceneRenderState::RenderOptions::PLAY_ANIMATIONS));
        } else {
            ClearBit(sceneRenderState._stateMask, to_base(SceneRenderState::RenderOptions::PLAY_ANIMATIONS));
        }
    }
    friend class Divide::Scene;
};

};  // namespace Attorney

};  // namespace Divide
#endif

Commits for Divide-Framework/trunk/Source Code/Scenes/Headers/SceneState.h

Diff revisions: vs.
Revision Author Commited Message
1029 Diff Diff IonutCava picture IonutCava Tue 30 Jan, 2018 17:28:39 +0000

[Ionut]
- Update copyright notices

902 Diff Diff IonutCava picture IonutCava Sun 25 Jun, 2017 16:56:57 +0000

[Ionut]
- Rework input system a bit for easier maintenance and readability
- Toggle AntTweakBar display using CTRL+F11

872 Diff Diff IonutCava picture IonutCava Mon 06 Mar, 2017 23:23:20 +0000

[IonutCava]
- Optimise static casts

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

827 Diff Diff IonutCava picture IonutCava Sun 22 Jan, 2017 21:59:36 +0000

[IonutCava]
- ShaderBuffers now decide heuristically if they get persistently mapped or not (depends on size. Current limit is 512Kb for subData calls.
- Separate visible node command generation into 2 steps: onRender and getDrawPackage. onRender allows the creation of parallel tasks that should finish by the time the second call, getDrawPackage reaches the same node
- Update ParticleEmitter to take into account multiple players and increase parallelism at the cost of memory consumption and complexity.
- Add a default bounding box for Players (add extents to SceneTransform nodes)
- All buffers (ShaderBuffer, d3dConstantBuffer, glUniformBuffer, glBufferImpl, glGenericBuffer, etc) use BufferParams for creation.
— Constructor and create calls have been merged together

817 Diff Diff IonutCava picture IonutCava Sun 15 Jan, 2017 21:29:59 +0000

[IonutCava]
- Add a new Unit component to SGNs that holds NPC/Player/etc. objects
- Add support for multiple keyboard+mouse combos and joysticks and add mapping between these and players

816 Diff Diff IonutCava picture IonutCava Fri 13 Jan, 2017 17:05:20 +0000

[IonutCava]
- Allow per player scene state and input source
— Add SceneStatePerPlayer class
— Add device index to InputParams objects.
— ToDo: map players to devide indices

795 Diff Diff IonutCava picture IonutCava Wed 23 Nov, 2016 17:14:33 +0000

[IonutCava]
- Remove ULL. Use U64 instead
- Various small bug fixes and typos.

786 IonutCava picture IonutCava Tue 18 Oct, 2016 19:42:56 +0000

[IonutCava]
- Initial code for overriding the default camera. Added as part of the scene state.