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
/*
   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_NODE_H_
#define _SCENE_NODE_H_

#include "SceneNodeRenderState.h"
#include "Rendering/Camera/Headers/Frustum.h"
#include "Core/Resources/Headers/Resource.h"
#include "Core/Math/BoundingVolumes/Headers/BoundingBox.h"
#include "Core/Math/BoundingVolumes/Headers/BoundingSphere.h"
#include "Platform/Video/Headers/RenderAPIWrapper.h"

namespace Divide {

class Scene;
class Camera;
class SceneGraph;
class SceneState;
class WorldPacket;
class RenderPackage;
class RenderStagePass;
class SceneRenderState;
class NetworkingComponent;

FWD_DECLARE_MANAGED_CLASS(SceneGraphNode);
FWD_DECLARE_MANAGED_CLASS(Material);

namespace Attorney {
    class SceneNodeSceneGraph;
    class SceneNodeNetworkComponent;
};

enum class SceneNodeType : U32 {
    TYPE_ROOT = toBit(1),       //< root node
    TYPE_OBJECT3D = toBit(2),   //< 3d objects in the scene
    TYPE_TRANSFORM = toBit(3),  //< dummy node to stack multiple transforms
    TYPE_WATER = toBit(4),      //< water node
    TYPE_LIGHT = toBit(5),      //< a scene light
    TYPE_TRIGGER = toBit(6),    //< a scene trigger (perform action on contact)
    TYPE_PARTICLE_EMITTER = toBit(7),   //< a particle emitter
    TYPE_SKY = toBit(8),                //< sky node
    TYPE_VEGETATION_GRASS = toBit(9),   //< grass node
    TYPE_VEGETATION_TREES = toBit(10),  //< trees node (to do later)
    COUNT                               //< Place types above
                                        
};

class NOINITVTABLE SceneNode : public CachedResource {
    friend class Attorney::SceneNodeSceneGraph;
    friend class Attorney::SceneNodeNetworkComponent;

    public:
    enum class UpdateFlag : U32 {
        BOUNDS_CHANGED = toBit(1),
        COUNT = 1
    };

    class SGNParentData {
        public:
        explicit SGNParentData(I64 sgnGUID) : _GUID(sgnGUID)
        {
            _updateFlags = 1;
        }

        inline I64 sgnGUID() const { return _GUID; }

        inline bool getFlag(UpdateFlag flag) const { return BitCompare(_updateFlags, to_base(flag)); }
        inline void clearFlag(UpdateFlag flag) { ClearBit(_updateFlags, to_base(flag)); }
        inline void setFlag(UpdateFlag flag) { SetBit(_updateFlags, to_base(flag)); }
        inline void toggleFlag(UpdateFlag flag) { ToggleBit(_updateFlags, to_base(flag)); }

        private:
        I64 _GUID;
        U32 _updateFlags;
    };

    public:
    explicit SceneNode(ResourceCache& parentCache, size_t descriptorHash, const stringImpl& name, const SceneNodeType& type);
    explicit SceneNode(ResourceCache& parentCache, size_t descriptorHash, const stringImpl& name, const stringImpl& resourceName, const stringImpl& resourceLocation, const SceneNodeType& type);
    virtual ~SceneNode();

    /// Perform any pre-draw operations (this is after sort and transform updates)
    /// If the node isn't ready for rendering and should be skipped this frame,
    /// the return value is false
    virtual bool onRender(SceneGraphNode& sgn,
                          const SceneRenderState& sceneRenderState,
                          const RenderStagePass& renderStagePass);
    virtual bool getDrawState() const { return _renderState.getDrawState(); }
    /// Some SceneNodes may need special case handling. I.E. water shouldn't
    /// render itself in REFLECTION
    virtual bool getDrawState(const RenderStagePass& renderStage);

    virtual void buildDrawCommands(SceneGraphNode& sgn,
                                   const RenderStagePass& renderStage,
                                   RenderPackage& pkgInOut);
    /*//Rendering/Processing*/

    virtual bool unload();
    virtual void setMaterialTpl(const Material_ptr& material);
    const Material_ptr& getMaterialTpl();

    inline void setType(const SceneNodeType& type) { _type = type; }
    inline const SceneNodeType& getType() const { return _type; }

    inline SceneNodeRenderState& renderState() { return _renderState; }

    inline void incLODcount() { _LODcount++; }
    inline void decLODcount() { _LODcount--; }
    inline U8   getLODcount() const { return _LODcount; }

    ResourceCache& parentResourceCache() { return _parentCache; }
    const ResourceCache& parentResourceCache() const { return _parentCache; }


    inline const BoundingBox& refBoundingBox() const { return _boundingBox; }
   protected:
    friend class BoundsSystem;
    /// Called from SceneGraph "sceneUpdate"
    virtual void sceneUpdate(const U64 deltaTimeUS, SceneGraphNode& sgn,
                             SceneState& sceneState);

    // Post insertion calls (Use this to setup child objects during creation)
    virtual void postLoad(SceneGraphNode& sgn);
    virtual void updateBoundsInternal(SceneGraphNode& sgn);

    inline void setFlag(UpdateFlag flag) {
        for (SGNParentData& data : _sgnParents) {
            data.setFlag(flag);
        }
    }

    inline vectorImpl<SceneNode::SGNParentData>::iterator getSGNData(I64 sgnGUID) {
        vectorImpl<SceneNode::SGNParentData>::iterator it;
        it = std::find_if(std::begin(_sgnParents), std::end(_sgnParents),
            [&sgnGUID](const SceneNode::SGNParentData& sgnIter) {
                return (sgnIter.sgnGUID() == sgnGUID);
            });
        return it;
    }

    inline vectorImpl<SceneNode::SGNParentData>::const_iterator getSGNData(I64 sgnGUID) const {
        return getSGNData(sgnGUID);
    }

    virtual void onCameraUpdate(SceneGraphNode& sgn,
                                const I64 cameraGUID,
                                const vec3<F32>& posOffset,
                                const mat4<F32>& rotationOffset);
    virtual void onCameraChange(SceneGraphNode& sgn,
                                const Camera& cam);

   protected:
     virtual void onNetworkSend(SceneGraphNode& sgn, WorldPacket& dataOut) const;
     virtual void onNetworkReceive(SceneGraphNode& sgn, WorldPacket& dataIn) const;

   protected:
    ResourceCache& _parentCache;
    /// The various states needed for rendering
    SceneNodeRenderState _renderState;
    /// Maximum available LOD levels
    U8 _LODcount;
    /// The initial bounding box as it was at object's creation (i.e. no transforms applied)
    BoundingBox _boundingBox;

   private:
    SceneNodeType _type;
    Material_ptr _materialTemplate;

    vectorImpl<SGNParentData> _sgnParents;
};

TYPEDEF_SMART_POINTERS_FOR_CLASS(SceneNode);

namespace Attorney {
class SceneNodeSceneGraph {
   private:
    static void postLoad(SceneNode& node, SceneGraphNode& sgn) {
        node.postLoad(sgn);
    }
    
    static void sceneUpdate(SceneNode& node, const U64 deltaTimeUS,
                            SceneGraphNode& sgn, SceneState& sceneState) {
        node.sceneUpdate(deltaTimeUS, sgn, sceneState);
    }

    static void registerSGNParent(SceneNode& node, I64 sgnGUID) {
        // prevent double add
        vectorImpl<SceneNode::SGNParentData>::const_iterator it;
        it = node.getSGNData(sgnGUID);
        assert(it == std::cend(node._sgnParents));

        node._sgnParents.push_back(SceneNode::SGNParentData(sgnGUID));
    }

    static void unregisterSGNParent(SceneNode& node, I64 sgnGUID) {
        // prevent double remove
        vectorImpl<SceneNode::SGNParentData>::const_iterator it;
        it = node.getSGNData(sgnGUID);
        assert(it != std::cend(node._sgnParents));

        node._sgnParents.erase(it);
    }

    static size_t parentCount(const SceneNode& node) {
        return node._sgnParents.size();
    }


    static void onCameraUpdate(SceneGraphNode& sgn,
                               SceneNode& node,
                               const I64 cameraGUID,
                               const vec3<F32>& posOffset,
                               const mat4<F32>& rotationOffset) {
        node.onCameraUpdate(sgn, cameraGUID, posOffset, rotationOffset);
    }

    static void onCameraChange(SceneGraphNode& sgn,
                               SceneNode& node,
                               const Camera& cam) {
        node.onCameraChange(sgn, cam);
    }

    friend class Divide::SceneGraph;
    friend class Divide::SceneGraphNode;
};

class SceneNodeNetworkComponent {
  private:
    static void onNetworkSend(SceneGraphNode& sgn, SceneNode& node, WorldPacket& dataOut) {
        node.onNetworkSend(sgn, dataOut);
    }

    static void onNetworkReceive(SceneGraphNode& sgn, SceneNode& node, WorldPacket& dataIn) {
        node.onNetworkReceive(sgn, dataIn);
    }

    friend class Divide::NetworkingComponent;
};

};  // namespace Attorney
};  // namespace Divide
#endif

Commits for Divide-Framework/trunk/Source Code/Graphs/Headers/SceneNode.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

1011 Diff Diff IonutCava picture IonutCava Fri 12 Jan, 2018 17:21:29 +0000

[Ionut]
- Performance improvements

994 Diff Diff IonutCava picture IonutCava Mon 11 Dec, 2017 18:01:11 +0000

[Ionut]
- Moved remaining components to new ECS system
- Started cleaning up code that was made redundant by the ECS system

968 Diff Diff IonutCava picture IonutCava Tue 07 Nov, 2017 17:32:31 +0000

[Ionut]
- Consistent naming between timing variables

957 Diff Diff IonutCava picture IonutCava Tue 31 Oct, 2017 17:15:51 +0000

[Ionut]
- Some SGN node search refactoring
- typedef PlayerIndex

948 Diff Diff IonutCava picture IonutCava Tue 17 Oct, 2017 22:41:09 +0000

[Ionut]
- Move rendering data caching outside of CommandBuffer and into RenderPackage for better control.

929 Diff Diff IonutCava picture IonutCava Sat 12 Aug, 2017 17:34:44 +0000

[Ionut]
- More work on finishing up new PushConstant / Command buffer rendering system:
— Everything compiles and runs but with graphical and performance issues

895 Diff Diff IonutCava picture IonutCava Wed 21 Jun, 2017 21:10:26 +0000

[IonutCava]
- Reorder and cleanup OpenGL backend a bit.
- Small code cleanup
- Some small profile-guided optimizations

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

[IonutCava]
- Optimise static casts

867 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.