21#include "Bullet/btBulletCollisionCommon.h"
23#include <unordered_map>
24#include <unordered_set>
31#define DECLARE_NODE(Class, Parent) \
32 DECLARE_FACTORY(Class, Node); \
33 DECLARE_OBJECT(Class, Parent); \
34 DECLARE_SCRIPT_LINK(Class, Parent, Node) \
37#define DEFINE_NODE(Class, Parent) \
38 DEFINE_FACTORY(Class, Node); \
39 DEFINE_OBJECT(Class); \
40 DEFINE_SCRIPT_LINK(Class, Parent, Node);
42typedef std::unordered_map<std::string, NetFunc>
NetFuncMap;
48template<
typename T = Node>
51template<
typename T = Node>
57 std::vector<NetDatum> mReplicatedData;
60 bool mReplicate =
false;
61 bool mReplicateTransform =
false;
62 bool mForceReplicate =
false;
75 static NodePtr Construct(
const std::string& name);
77 static void Destruct(
Node* node);
82 virtual void Create();
84 void DestroyDeferred();
88 virtual void LoadStream(
Stream& stream,
Platform platform, uint32_t version);
90 virtual void Copy(
Node* srcNode,
bool recurse);
96 virtual void PrepareTick(std::vector<NodePtrWeak>& outTickNodes,
bool game,
bool recurse);
97 virtual void Tick(
float deltaTime);
98 virtual void EditorTick(
float deltaTime);
99 uint32_t GetLastTickedFrame()
const;
100 virtual void Render();
101 virtual void OnInstanced();
107 virtual void GatherReplicatedData(std::vector<NetDatum>& outData);
108 virtual void GatherNetFuncs(std::vector<NetFunc>& outFuncs);
110 void GatherPropertyOverrides(std::vector<Property>& outOverrides);
111 void ApplyPropertyOverrides(
const std::vector<Property>& overs);
115 virtual void OnCollision(
118 glm::vec3 impactPoint,
119 glm::vec3 impactNormal,
120 btPersistentManifold* manifold);
124 uint64_t GetPersistentUuid()
const;
125 void SetPersistentUuid(uint64_t uuid);
126 void EnsurePersistentUuid();
128 void EmitSignal(
const std::string& name,
const std::vector<Datum>& args);
130 void ConnectSignal(
const std::string& name,
Node* listener,
const ScriptFunc& func);
131 void DisconnectSignal(
const std::string& name,
Node* listener);
134 void RenderSelected(
bool renderChildren);
137 Node* CreateChild(
const char* typeName);
138 Node* CreateChildClone(
Node* srcNode,
bool recurse);
139 NodePtr Clone(
bool recurse,
bool instantiateLinkedScene =
true,
bool resolveNodePaths =
false);
140 void DestroyAllChildren();
143 bool IsWorldRoot()
const;
146 template<
class NodeClass>
149 return (NodeClass*)CreateChild(NodeClass::GetStaticType());
152 template<
class NodeClass>
155 return ResolvePtr<NodeClass>(CreateChild(NodeClass::GetStaticType()));
158 template<
class NodeClass>
161 NodeClass* ret = (NodeClass*)CreateChild(NodeClass::GetStaticType());
166 template<
class NodeClass>
169 NodeClass* ret = (NodeClass*)CreateChild(NodeClass::GetStaticType());
171 return ResolvePtr<NodeClass>(ret);
174 bool IsDestroyed()
const;
175 bool IsPendingDestroy()
const;
176 bool IsDoomed()
const;
178 bool HasStarted()
const;
179 bool HasAwoken()
const;
181 void EnableTick(
bool enable);
182 bool IsTickEnabled()
const;
184 virtual void SetWorld(
World* world,
bool subRoot);
187 void SetScene(
Scene* scene);
193 std::vector<NetDatum>& GetReplicatedData();
195 void SetNetId(
NetId id);
196 NetId GetNetId()
const;
199 void SetOwningHost(
NetHostId hostId,
bool setAsPawn =
false);
201 void SetReplicate(
bool replicate);
202 bool IsReplicated()
const;
203 void SetReplicateTransform(
bool repTransform);
204 bool IsTransformReplicated()
const;
206 void ForceReplication();
207 void ClearForcedReplication();
208 bool NeedsForcedReplication();
210 virtual bool CheckNetRelevance(
Node* playerNode);
211 bool IsAlwaysRelevant()
const;
212 void SetAlwaysRelevant(
bool alwaysRelevant);
214 bool HasTag(
const std::string& tag);
215 void AddTag(
const std::string& tag);
216 void RemoveTag(
const std::string& tag);
218 void SetName(
const std::string& newName);
219 const std::string& GetName()
const;
220 virtual void SetActive(
bool active);
221 bool IsActive(
bool recurse =
false)
const;
222 virtual void SetVisible(
bool visible);
223 bool IsVisible(
bool recurse =
false)
const;
224 void SetTransient(
bool transient);
225 virtual bool IsTransient()
const;
226 void SetPersistent(
bool persistent);
227 bool IsPersistent()
const;
229 void SetDefault(
bool isDefault);
230 bool IsDefault()
const;
232 void SetUserdataCreated(
bool created);
233 bool IsUserdataCreated()
const;
235 virtual const char* GetTypeName()
const;
238 virtual bool IsNode3D()
const;
239 virtual bool IsWidget()
const;
240 virtual bool IsPrimitive3D()
const;
241 virtual bool IsLight3D()
const;
244 const Node* GetParent()
const;
245 const std::vector<NodePtr>& GetChildren()
const;
247 virtual void Attach(
Node* parent,
bool keepWorldTransform =
false, int32_t index = -1);
248 void Detach(
bool keepWorldTransform =
false);
249 void AddChild(
Node* child, int32_t index = -1);
250 void RemoveChild(
Node* child);
251 void RemoveChild(int32_t index);
256 AddChild(child.
Get(), index);
262 RemoveChild(child.
Get());
265 int32_t FindChildIndex(
const std::string& name)
const;
266 int32_t FindChildIndex(
Node* child)
const;
267 Node* FindChild(
const std::string& name,
bool recurse)
const;
268 Node* FindChildWithTag(
const std::string& name,
bool recurse)
const;
269 Node* FindDescendant(
const std::string& name);
270 Node* FindAncestor(
const std::string& name);
271 bool HasAncestor(
Node* node);
272 Node* GetChild(int32_t index)
const;
274 uint32_t GetNumChildren()
const;
275 int32_t FindParentNodeIndex()
const;
277 void SetHitCheckId(uint32_t
id);
278 uint32_t GetHitCheckId()
const;
280 bool IsLateTickEnabled()
const;
281 void EnableLateTick(
bool enable);
284 void SetScriptFile(
const std::string& fileName);
286 bool DoChildrenHaveUniqueNames()
const;
287 void BreakSceneLink();
288 bool IsSceneLinked(
bool ignoreInPie =
true)
const;
289 bool IsSceneLinkedChild(
bool ignoreInPie =
true);
290 bool IsForeign()
const;
292 bool HasAuthority()
const;
293 bool IsOwned()
const;
294 bool IsLocallyControlled()
const;
296 Datum GetField(
const std::string& key);
297 void SetField(
const std::string& name,
const Datum& value);
298 Datum GetField(int32_t key);
299 void SetField(int32_t key,
const Datum& value);
300 Datum CallFunction(
const std::string& name,
const std::vector<Datum>& args = {});
302 NetFunc* FindNetFunc(
const char* name);
303 NetFunc* FindNetFunc(uint16_t index);
305 void InvokeNetFunc(
const char* name);
306 void InvokeNetFunc(
const char* name,
Datum param0);
307 void InvokeNetFunc(
const char* name,
Datum param0,
Datum param1);
308 void InvokeNetFunc(
const char* name,
Datum param0,
Datum param1,
Datum param2);
314 void InvokeNetFunc(
const char* name,
const std::vector<Datum>& params);
316 static void ProcessPendingDestroys();
318 static void RegisterNetFuncs(
Node* node);
320 static void Deleter(
Node* node);
328 Node* child = FindChild(name, recurse);
329 if (child !=
nullptr)
331 ret = child->
As<T>();
340 bool traverseChildren =
true;
344 traverseChildren = func(
this);
347 if (traverseChildren)
351 for (int32_t i = int32_t(mChildren.size()) - 1; i >= 0; --i)
353 mChildren[i]->Traverse(func, inverted);
358 for (uint32_t i = 0; i < mChildren.size(); ++i)
360 mChildren[i]->Traverse(func, inverted);
385 for (int32_t i = int32_t(mChildren.size()) - 1; i >= 0; --i)
387 cont = mChildren[i]->ForEach(func, inverted);
397 for (uint32_t i = 0; i < mChildren.size(); ++i)
399 cont = mChildren[i]->ForEach(func, inverted);
409 if (cont && inverted)
417 template<
class NodeClass>
421 NodeClass* newNode = (NodeClass*)Node::CreateInstance(NodeClass::GetStaticType());
424 if (newNode !=
nullptr)
426 newNodePtr.
Set(newNode,
nullptr);
428 newNodePtr->mSelf = PtrStaticCast<Node>(newNodePtr);
429 newNodePtr->Create();
437 static bool HandlePropChange(
Datum* datum, uint32_t index,
const void* newValue);
439 static bool OnRep_OwningHost(
Datum* datum, uint32_t index,
const void* newValue);
441 void TickCommon(
float deltaTime);
443 virtual void SetParent(
Node* parent);
444 void ValidateUniqueChildName(
Node* newChild);
446 void SendNetFunc(
NetFunc* func, uint32_t numParams,
const Datum** params);
461 uint32_t mLastTickedFrame = 0;
463 bool mVisible =
true;
464 bool mTransient =
false;
465 bool mPersistent =
false;
466 bool mDefault =
false;
467 bool mUserdataCreated =
false;
468 bool mHasStarted =
false;
469 bool mHasAwoken =
false;
470 bool mDestroyed =
false;
471 bool mTickEnabled =
true;
472 bool mLateTick =
false;
476 uint8_t mTargetScreen = 0;
479 uint64_t mPersistentUuid = 0;
488 bool mReplicate =
false;
489 bool mReplicateTransform =
false;
490 bool mForceReplicate =
false;
491 bool mAlwaysRelevant =
true;
500 bool ShouldExposeVariable()
const;
501 void SetExposeVariable(
bool expose);
502 bool AreAllChildrenHiddenInTree()
const;
504 uint32_t mHitCheckId = 0;
505 bool mExposeVariable =
false;
506 bool mHiddenInTree =
false;
516 return PtrStaticCast<T>(nodePtr);
522 return PtrStaticCast<T>(node ? node->
GetSelfPtr() :
nullptr);
#define INVALID_HOST_ID
Definition Constants.h:44
#define INVALID_NODE_ID
Definition Constants.h:42
#define INVALID_NET_ID
Definition Constants.h:41
uint32_t NetId
Definition EngineTypes.h:65
Platform
Definition EngineTypes.h:31
uint8_t NetHostId
Definition EngineTypes.h:486
uint32_t TypeId
Definition EngineTypes.h:64
uint32_t NodeId
Definition EngineTypes.h:66
World * GetWorld(int32_t index)
Definition Engine.cpp:994
PipelineConfig
Definition GraphicsTypes.h:66
std::unordered_map< std::string, NetFunc > NetFuncMap
Definition Node.h:42
bool(* NodeTraversalFP)(Node *)
Definition Node.h:45
SharedPtr< T > ResolvePtr(Node *node)
Definition Node.h:513
WeakPtr< T > ResolveWeakPtr(Node *node)
Definition Node.h:520
Export macros for Polyphase Engine symbols.
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
void(* SignalHandlerFP)(Node *, const std::vector< Datum > &)
Definition Signals.h:11
VertexType
Definition Vertex.h:7
std::vector< NetDatum > mReplicatedData
Definition Node.h:485
SceneRef mScene
Definition Node.h:475
DECLARE_FACTORY(Node, Node)
SharedPtr< NodeClass > CreateChildSp(const char *name)
Definition Node.h:167
std::string mScriptFile
Definition Node.h:460
void Traverse(T func, bool inverted=false)
Definition Node.h:338
NodePtrWeak mParent
Definition Node.h:455
NodeClass * CreateChild(const char *name)
Definition Node.h:159
std::vector< NodePtr > mChildren
Definition Node.h:457
std::string mName
Definition Node.h:452
static std::unordered_map< TypeId, NetFuncMap > sTypeNetFuncMap
Definition Node.h:448
static SharedPtr< NodeClass > Construct()
Definition Node.h:418
NodePtrWeak mSelf
Definition Node.h:456
void SetTargetScreen(uint8_t screen)
Definition Node.h:191
DECLARE_FACTORY_MANAGER(Node)
static std::unordered_set< NodePtrWeak > sPendingDestroySet
Definition Node.h:449
DECLARE_OBJECT(Node, Object)
static NodeId sNextNodeId
Definition Node.h:450
SharedPtr< NodeClass > CreateChildSp()
Definition Node.h:153
bool ForEach(T func, bool inverted=false)
Definition Node.h:372
static void Deleter(Node *node)
Definition Node.cpp:131
std::unordered_map< std::string, Node * > mChildNameMap
Definition Node.h:458
void AddChild(const SharedPtr< T > &child, int32_t index=-1)
Definition Node.h:254
std::unordered_map< std::string, Signal > mSignalMap
Definition Node.h:459
DECLARE_SCRIPT_LINK_BASE(Node)
uint8_t GetTargetScreen() const
Definition Node.h:190
T * FindChild(const std::string &name, bool recurse)
Definition Node.h:325
NodeClass * CreateChild()
Definition Node.h:147
const WeakPtr< Node > & GetSelfPtr() const
Definition Node.h:322
std::vector< std::string > mTags
Definition Node.h:477
void RemoveChild(const SharedPtr< Node > &child)
Definition Node.h:260
virtual void GatherProperties(std::vector< Property > &props)
Definition Object.h:41
T * As() const
Definition Object.h:52
Definition Primitive3d.h:46
Definition ScriptFunc.h:10
Definition SmartPointer.h:33
void SetDeleter(typename RefCount< T >::DeleterFP deleteFunc)
Definition SmartPointer.h:234
void Set(T *pointer, RefCount< T > *refCount)
Definition SmartPointer.h:156
T * Get() const
Definition SmartPointer.h:247
Definition SmartPointer.h:312
SharedPtr< T > Lock() const
Definition SmartPointer.h:492
Definition EngineTypes.h:199