Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
SceneNode.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_NODE_H_
34#define DVD_SCENE_NODE_H_
35
36#include "SceneNodeFwd.h"
38
44
45namespace Divide {
46
47class Scene;
48class Camera;
49class Player;
50class SceneGraph;
51class SceneState;
52class WorldPacket;
53class SceneRenderState;
54class BoundsSystem;
55class BoundsComponent;
56class RenderingComponent;
57class NetworkingComponent;
58
59class Light;
60class SpotLightComponent;
61class PointLightComponent;
63
64struct RenderPackage;
65struct RenderStagePass;
66struct CameraSnapshot;
67
68namespace GFX
69{
70 struct DrawCommand;
71 struct MemoryBarrierCommand;
72};
73
74FWD_DECLARE_MANAGED_CLASS(SceneGraphNode);
76
77namespace Attorney
78{
79 class SceneNodePlayer;
80 class SceneNodeSceneGraph;
81 class SceneNodeLightComponent;
82 class SceneNodeBoundsSystem;
83 class SceneNodeNetworkComponent;
84};
85
87{
93
94 public:
95 explicit SceneNode( const ResourceDescriptorBase& descriptor, SceneNodeType type, U32 requiredComponentMask );
96
97 virtual ~SceneNode() override;
98
101 virtual void prepareRender(SceneGraphNode* sgn,
102 RenderingComponent& rComp,
103 RenderPackage& pkg,
104 GFX::MemoryBarrierCommand& postDrawMemCmd,
105 RenderStagePass renderStagePass,
106 const CameraSnapshot& cameraSnapshot,
107 bool refreshData);
108
110
111 bool load( PlatformContext& context ) override;
112 bool postLoad() override;
113 bool unload() override;
114 virtual void setMaterialTpl( Handle<Material> material);
116
117 [[nodiscard]] inline SceneNodeRenderState& renderState() noexcept { return _renderState; }
118 [[nodiscard]] inline const SceneNodeRenderState& renderState() const noexcept { return _renderState; }
119
120 [[nodiscard]] inline const BoundingBox& getBounds() const noexcept { return _boundingBox; }
121 [[nodiscard]] inline const vec3<F32>& getWorldOffset() const noexcept { return _worldOffset; }
122
123 [[nodiscard]] inline U32 requiredComponentMask() const noexcept { return _requiredComponentMask; }
124
125 virtual bool saveCache(ByteBuffer& outputBuffer) const;
126 virtual bool loadCache(ByteBuffer& inputBuffer);
127
128 virtual void saveToXML(boost::property_tree::ptree& pt) const;
129 virtual void loadFromXML(const boost::property_tree::ptree& pt);
130
131 EditorComponent* editorComponent() const noexcept { return _editorComponent.get(); }
132
133 protected:
135 virtual void sceneUpdate(U64 deltaTimeUS, SceneGraphNode* sgn, SceneState& sceneState);
136
137 // Post insertion calls (Use this to setup child objects during creation)
138 virtual void postLoad(SceneGraphNode* sgn);
139
140 void setBounds(const BoundingBox& aabb, const vec3<F32>& worldOffset = {});
141
142 void registerEditorComponent( PlatformContext& context );
143
145 PROPERTY_RW(bool, rebuildDrawCommands, false);
146
147 protected:
148 virtual void onNetworkSend(SceneGraphNode* sgn, WorldPacket& dataOut) const;
149 virtual void onNetworkReceive(SceneGraphNode* sgn, WorldPacket& dataIn) const;
150
151 protected:
152 std::unique_ptr<EditorComponent> _editorComponent;
153 Handle<Material> _materialTemplate = INVALID_HANDLE<Material>;
154
157
161 bool _boundsChanged = false;
162
163private:
165};
166
168
170{
171 public:
172 explicit TransformNode( const ResourceDescriptor<TransformNode>& descriptor );
173};
174
175namespace Attorney {
177 static void postLoad(SceneNode* node, SceneGraphNode* sgn)
178 {
179 node->postLoad(sgn);
180 }
181
182 static void sceneUpdate(SceneNode* node, const U64 deltaTimeUS,
183 SceneGraphNode* sgn, SceneState& sceneState)
184 {
186 node->sceneUpdate(deltaTimeUS, sgn, sceneState);
187 }
188
189 friend class Divide::SceneGraph;
191};
192
194 static void onNetworkSend(SceneGraphNode* sgn, const SceneNode& node, WorldPacket& dataOut) {
195 node.onNetworkSend(sgn, dataOut);
196 }
197
198 static void onNetworkReceive(SceneGraphNode* sgn, const SceneNode& node, WorldPacket& dataIn) {
199 node.onNetworkReceive(sgn, dataIn);
200 }
201
203};
204
206 static void setBounds(SceneNode& node, const BoundingBox& aabb, const vec3<F32>& worldOffset = {}) {
207 node.setBounds(aabb, worldOffset);
208 }
209
210 static bool boundsChanged(const SceneNode& node) noexcept {
211 return node._boundsChanged;
212 }
213
214 static void setBoundsChanged(SceneNode& node) noexcept {
215 node._boundsChanged = true;
216 }
217
218 static bool clearBoundsChanged(SceneNode& node) noexcept {
219 if (!node._boundsChanged) {
220 return false;
221 }
222
223 node._boundsChanged = false;
224 return true;
225 }
226
228};
229
231 static void setBounds(SceneNode& node, const BoundingBox& aabb, const vec3<F32>& worldOffset = {}) {
232 node.setBounds(aabb, worldOffset);
233 }
234
235 friend class Divide::Light;
239};
240
242 static void setBounds(SceneNode& node, const BoundingBox& aabb, const vec3<F32>& worldOffset = {}) {
243 node.setBounds(aabb, worldOffset);
244 }
245
246 friend class Divide::Player;
247};
248
249}; // namespace Attorney
250}; // namespace Divide
251
252#endif //DVD_SCENE_NODE_H_
253
#define TYPEDEF_SMART_POINTERS_FOR_TYPE(T)
#define FWD_DECLARE_MANAGED_CLASS(T)
#define PROFILE_SCOPE_AUTO(CATEGORY)
Definition: Profiler.h:87
#define DEFINE_NODE_TYPE(Name, Enum)
Definition: SceneNodeFwd.h:120
static void setBounds(SceneNode &node, const BoundingBox &aabb, const vec3< F32 > &worldOffset={})
Definition: SceneNode.h:206
static bool boundsChanged(const SceneNode &node) noexcept
Definition: SceneNode.h:210
static void setBoundsChanged(SceneNode &node) noexcept
Definition: SceneNode.h:214
static bool clearBoundsChanged(SceneNode &node) noexcept
Definition: SceneNode.h:218
friend class Divide::PointLightComponent
Definition: SceneNode.h:237
static void setBounds(SceneNode &node, const BoundingBox &aabb, const vec3< F32 > &worldOffset={})
Definition: SceneNode.h:231
friend class Divide::SpotLightComponent
Definition: SceneNode.h:236
static void onNetworkReceive(SceneGraphNode *sgn, const SceneNode &node, WorldPacket &dataIn)
Definition: SceneNode.h:198
static void onNetworkSend(SceneGraphNode *sgn, const SceneNode &node, WorldPacket &dataOut)
Definition: SceneNode.h:194
static void setBounds(SceneNode &node, const BoundingBox &aabb, const vec3< F32 > &worldOffset={})
Definition: SceneNode.h:242
static void postLoad(SceneNode *node, SceneGraphNode *sgn)
Definition: SceneNode.h:177
static void sceneUpdate(SceneNode *node, const U64 deltaTimeUS, SceneGraphNode *sgn, SceneState &sceneState)
Definition: SceneNode.h:182
A light object placed in the scene at a certain position.
Definition: Light.h:58
User controlled Unit.
Definition: Player.h:45
const SceneNodeRenderState & renderState() const noexcept
Definition: SceneNode.h:118
void setBounds(const BoundingBox &aabb, const vec3< F32 > &worldOffset={})
Definition: SceneNode.cpp:66
SceneNodeRenderState _renderState
The various states needed for rendering.
Definition: SceneNode.h:156
const BoundingBox & getBounds() const noexcept
Definition: SceneNode.h:120
virtual ~SceneNode() override
Definition: SceneNode.cpp:34
PROPERTY_R(SceneNodeType, type, SceneNodeType::COUNT)
bool unload() override
Definition: SceneNode.cpp:108
virtual void saveToXML(boost::property_tree::ptree &pt) const
Definition: SceneNode.cpp:156
virtual void sceneUpdate(U64 deltaTimeUS, SceneGraphNode *sgn, SceneState &sceneState)
Called from SceneGraph "sceneUpdate".
Definition: SceneNode.cpp:44
BoundingBox _boundingBox
The initial bounding box as it was at object's creation (i.e. no transforms applied)
Definition: SceneNode.h:159
Handle< Material > _materialTemplate
Definition: SceneNode.h:153
virtual void prepareRender(SceneGraphNode *sgn, RenderingComponent &rComp, RenderPackage &pkg, GFX::MemoryBarrierCommand &postDrawMemCmd, RenderStagePass renderStagePass, const CameraSnapshot &cameraSnapshot, bool refreshData)
Definition: SceneNode.cpp:50
PROPERTY_RW(bool, rebuildDrawCommands, false)
U32 requiredComponentMask() const noexcept
Definition: SceneNode.h:123
EditorComponent * editorComponent() const noexcept
Definition: SceneNode.h:131
Handle< Material > getMaterialTpl() const
Definition: SceneNode.cpp:73
std::unique_ptr< EditorComponent > _editorComponent
Definition: SceneNode.h:152
virtual void buildDrawCommands(SceneGraphNode *sgn, GenericDrawCommandContainer &cmdsOut)
Definition: SceneNode.cpp:115
virtual void onNetworkReceive(SceneGraphNode *sgn, WorldPacket &dataIn) const
Definition: SceneNode.cpp:124
virtual bool saveCache(ByteBuffer &outputBuffer) const
Definition: SceneNode.cpp:128
virtual bool loadCache(ByteBuffer &inputBuffer)
Definition: SceneNode.cpp:139
SceneNodeRenderState & renderState() noexcept
Definition: SceneNode.h:117
vec3< F32 > _worldOffset
Definition: SceneNode.h:160
const vec3< F32 > & getWorldOffset() const noexcept
Definition: SceneNode.h:121
bool postLoad() override
Definition: SceneNode.cpp:103
void registerEditorComponent(PlatformContext &context)
Definition: SceneNode.cpp:39
virtual void onNetworkSend(SceneGraphNode *sgn, WorldPacket &dataOut) const
Definition: SceneNode.cpp:120
virtual void setMaterialTpl(Handle< Material > material)
Definition: SceneNode.cpp:78
virtual void loadFromXML(const boost::property_tree::ptree &pt)
Definition: SceneNode.cpp:164
U32 _requiredComponentMask
Definition: SceneNode.h:164
constexpr Optick::Category::Type GameLogic
Definition: Profiler.h:63
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
bool load() override
constexpr U32 to_U32(const T value)
SceneNodeType
ToDo: Move particle emitter to components (it will make them way more dynamic) - Ionut.
Definition: SceneNodeFwd.h:47
DirectionalLightComponent(SceneGraphNode *sgn, PlatformContext &context)
eastl::fixed_vector< GenericDrawCommand, 1, true > GenericDrawCommandContainer
uint32_t U32
uint64_t U64