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;
78 static Factory* FindFactory(
const char* className);
80 static NodePtr Construct(
const std::string& name);
82 static void Destruct(
Node* node);
87 virtual void Create();
89 void DestroyDeferred();
93 virtual void LoadStream(
Stream& stream,
Platform platform, uint32_t version);
95 virtual void Copy(
Node* srcNode,
bool recurse);
101 virtual void PrepareTick(std::vector<NodePtrWeak>& outTickNodes,
bool game,
bool recurse);
102 virtual void Tick(
float deltaTime);
103 virtual void EditorTick(
float deltaTime);
104 uint32_t GetLastTickedFrame()
const;
105 virtual void Render();
106 virtual void OnInstanced();
112 virtual void GatherReplicatedData(std::vector<NetDatum>& outData);
113 virtual void GatherNetFuncs(std::vector<NetFunc>& outFuncs);
115 void GatherPropertyOverrides(std::vector<Property>& outOverrides);
116 void ApplyPropertyOverrides(
const std::vector<Property>& overs);
120 virtual void OnCollision(
123 glm::vec3 impactPoint,
124 glm::vec3 impactNormal,
125 btPersistentManifold* manifold);
129 uint64_t GetPersistentUuid()
const;
130 void SetPersistentUuid(uint64_t uuid);
131 void EnsurePersistentUuid();
133 void EmitSignal(
const std::string& name,
const std::vector<Datum>& args);
135 void ConnectSignal(
const std::string& name,
Node* listener,
const ScriptFunc& func);
136 void DisconnectSignal(
const std::string& name,
Node* listener);
139 void RenderSelected(
bool renderChildren);
142 Node* CreateChild(
const char* typeName);
143 Node* CreateChildClone(
Node* srcNode,
bool recurse);
144 NodePtr Clone(
bool recurse,
bool instantiateLinkedScene =
true,
bool resolveNodePaths =
false);
145 void DestroyAllChildren();
148 bool IsWorldRoot()
const;
151 template<
class NodeClass>
154 return (NodeClass*)CreateChild(NodeClass::GetStaticType());
157 template<
class NodeClass>
160 return ResolvePtr<NodeClass>(CreateChild(NodeClass::GetStaticType()));
163 template<
class NodeClass>
166 NodeClass* ret = (NodeClass*)CreateChild(NodeClass::GetStaticType());
171 template<
class NodeClass>
174 NodeClass* ret = (NodeClass*)CreateChild(NodeClass::GetStaticType());
176 return ResolvePtr<NodeClass>(ret);
179 bool IsDestroyed()
const;
180 bool IsPendingDestroy()
const;
181 bool IsDoomed()
const;
183 bool HasStarted()
const;
184 bool HasAwoken()
const;
186 void EnableTick(
bool enable);
187 bool IsTickEnabled()
const;
189 virtual void SetWorld(
World* world,
bool subRoot);
192 void SetScene(
Scene* scene);
198 std::vector<NetDatum>& GetReplicatedData();
200 void SetNetId(
NetId id);
201 NetId GetNetId()
const;
204 void SetOwningHost(
NetHostId hostId,
bool setAsPawn =
false);
206 void SetReplicate(
bool replicate);
207 bool IsReplicated()
const;
208 void SetReplicateTransform(
bool repTransform);
209 bool IsTransformReplicated()
const;
211 void ForceReplication();
212 void ClearForcedReplication();
213 bool NeedsForcedReplication();
215 virtual bool CheckNetRelevance(
Node* playerNode);
216 bool IsAlwaysRelevant()
const;
217 void SetAlwaysRelevant(
bool alwaysRelevant);
219 bool HasTag(
const std::string& tag);
220 void AddTag(
const std::string& tag);
221 void RemoveTag(
const std::string& tag);
223 void SetName(
const std::string& newName);
224 const std::string& GetName()
const;
225 virtual void SetActive(
bool active);
226 bool IsActive(
bool recurse =
false)
const;
227 virtual void SetVisible(
bool visible);
228 bool IsVisible(
bool recurse =
false)
const;
229 void SetTransient(
bool transient);
230 virtual bool IsTransient()
const;
231 void SetPersistent(
bool persistent);
232 bool IsPersistent()
const;
234 void SetDefault(
bool isDefault);
235 bool IsDefault()
const;
237 void SetUserdataCreated(
bool created);
238 bool IsUserdataCreated()
const;
240 virtual const char* GetTypeName()
const;
243 virtual bool IsNode3D()
const;
244 virtual bool IsWidget()
const;
245 virtual bool IsPrimitive3D()
const;
246 virtual bool IsLight3D()
const;
249 const Node* GetParent()
const;
250 const std::vector<NodePtr>& GetChildren()
const;
252 virtual void Attach(
Node* parent,
bool keepWorldTransform =
false, int32_t index = -1);
253 void Detach(
bool keepWorldTransform =
false);
254 void AddChild(
Node* child, int32_t index = -1);
255 void RemoveChild(
Node* child);
256 void RemoveChild(int32_t index);
261 AddChild(child.
Get(), index);
267 RemoveChild(child.
Get());
270 int32_t FindChildIndex(
const std::string& name)
const;
271 int32_t FindChildIndex(
Node* child)
const;
272 Node* FindChild(
const std::string& name,
bool recurse)
const;
273 Node* FindChildWithTag(
const std::string& name,
bool recurse)
const;
274 Node* FindDescendant(
const std::string& name);
275 Node* FindAncestor(
const std::string& name);
276 bool HasAncestor(
Node* node);
277 Node* GetChild(int32_t index)
const;
279 uint32_t GetNumChildren()
const;
280 int32_t FindParentNodeIndex()
const;
282 void SetHitCheckId(uint32_t
id);
283 uint32_t GetHitCheckId()
const;
285 bool IsLateTickEnabled()
const;
286 void EnableLateTick(
bool enable);
289 void SetScriptFile(
const std::string& fileName);
291 bool DoChildrenHaveUniqueNames()
const;
292 void BreakSceneLink();
293 bool IsSceneLinked(
bool ignoreInPie =
true)
const;
294 bool IsSceneLinkedChild(
bool ignoreInPie =
true);
295 bool IsForeign()
const;
297 bool HasAuthority()
const;
298 bool IsOwned()
const;
299 bool IsLocallyControlled()
const;
301 Datum GetField(
const std::string& key);
302 void SetField(
const std::string& name,
const Datum& value);
303 Datum GetField(int32_t key);
304 void SetField(int32_t key,
const Datum& value);
305 Datum CallFunction(
const std::string& name,
const std::vector<Datum>& args = {});
307 NetFunc* FindNetFunc(
const char* name);
308 NetFunc* FindNetFunc(uint16_t index);
310 void InvokeNetFunc(
const char* name);
311 void InvokeNetFunc(
const char* name,
Datum param0);
312 void InvokeNetFunc(
const char* name,
Datum param0,
Datum param1);
313 void InvokeNetFunc(
const char* name,
Datum param0,
Datum param1,
Datum param2);
319 void InvokeNetFunc(
const char* name,
const std::vector<Datum>& params);
321 static void ProcessPendingDestroys();
323 static void RegisterNetFuncs(
Node* node);
325 static void Deleter(
Node* node);
333 Node* child = FindChild(name, recurse);
334 if (child !=
nullptr)
336 ret = child->
As<T>();
345 bool traverseChildren =
true;
349 traverseChildren = func(
this);
352 if (traverseChildren)
356 for (int32_t i = int32_t(mChildren.size()) - 1; i >= 0; --i)
358 mChildren[i]->Traverse(func, inverted);
363 for (uint32_t i = 0; i < mChildren.size(); ++i)
365 mChildren[i]->Traverse(func, inverted);
390 for (int32_t i = int32_t(mChildren.size()) - 1; i >= 0; --i)
392 cont = mChildren[i]->ForEach(func, inverted);
402 for (uint32_t i = 0; i < mChildren.size(); ++i)
404 cont = mChildren[i]->ForEach(func, inverted);
414 if (cont && inverted)
422 template<
class NodeClass>
426 NodeClass* newNode = (NodeClass*)Node::CreateInstance(NodeClass::GetStaticType());
429 if (newNode !=
nullptr)
431 newNodePtr.
Set(newNode,
nullptr);
433 newNodePtr->mSelf = PtrStaticCast<Node>(newNodePtr);
434 newNodePtr->Create();
442 static bool HandlePropChange(
Datum* datum, uint32_t index,
const void* newValue);
444 static bool OnRep_OwningHost(
Datum* datum, uint32_t index,
const void* newValue);
446 void TickCommon(
float deltaTime);
448 virtual void SetParent(
Node* parent);
449 void ValidateUniqueChildName(
Node* newChild);
451 void SendNetFunc(
NetFunc* func, uint32_t numParams,
const Datum** params);
466 uint32_t mLastTickedFrame = 0;
468 bool mVisible =
true;
469 bool mTransient =
false;
470 bool mPersistent =
false;
471 bool mDefault =
false;
472 bool mUserdataCreated =
false;
473 bool mHasStarted =
false;
474 bool mHasAwoken =
false;
475 bool mDestroyed =
false;
476 bool mTickEnabled =
true;
477 bool mLateTick =
false;
481 uint8_t mTargetScreen = 0;
484 uint64_t mPersistentUuid = 0;
493 bool mReplicate =
false;
494 bool mReplicateTransform =
false;
495 bool mForceReplicate =
false;
496 bool mAlwaysRelevant =
true;
505 bool ShouldExposeVariable()
const;
506 void SetExposeVariable(
bool expose);
507 bool AreAllChildrenHiddenInTree()
const;
509 uint32_t mHitCheckId = 0;
510 bool mExposeVariable =
false;
511 bool mHiddenInTree =
false;
540 return PtrStaticCast<T>(nodePtr);
557 return PtrStaticCast<T>(selfWeak);
#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:72
Platform
Definition EngineTypes.h:31
uint8_t NetHostId
Definition EngineTypes.h:502
uint32_t TypeId
Definition EngineTypes.h:71
uint32_t NodeId
Definition EngineTypes.h:73
World * GetWorld(int32_t index)
Definition Engine.cpp:1106
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:526
WeakPtr< T > ResolveWeakPtr(Node *node)
Definition Node.h:544
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:490
SceneRef mScene
Definition Node.h:480
DECLARE_FACTORY(Node, Node)
SharedPtr< NodeClass > CreateChildSp(const char *name)
Definition Node.h:172
std::string mScriptFile
Definition Node.h:465
void Traverse(T func, bool inverted=false)
Definition Node.h:343
NodePtrWeak mParent
Definition Node.h:460
NodeClass * CreateChild(const char *name)
Definition Node.h:164
std::vector< NodePtr > mChildren
Definition Node.h:462
std::string mName
Definition Node.h:457
static std::unordered_map< TypeId, NetFuncMap > sTypeNetFuncMap
Definition Node.h:453
static SharedPtr< NodeClass > Construct()
Definition Node.h:423
NodePtrWeak mSelf
Definition Node.h:461
void SetTargetScreen(uint8_t screen)
Definition Node.h:196
DECLARE_FACTORY_MANAGER(Node)
static std::unordered_set< NodePtrWeak > sPendingDestroySet
Definition Node.h:454
DECLARE_OBJECT(Node, Object)
static NodeId sNextNodeId
Definition Node.h:455
SharedPtr< NodeClass > CreateChildSp()
Definition Node.h:158
bool ForEach(T func, bool inverted=false)
Definition Node.h:377
static void Deleter(Node *node)
Definition Node.cpp:146
std::unordered_map< std::string, Node * > mChildNameMap
Definition Node.h:463
void AddChild(const SharedPtr< T > &child, int32_t index=-1)
Definition Node.h:259
std::unordered_map< std::string, Signal > mSignalMap
Definition Node.h:464
DECLARE_SCRIPT_LINK_BASE(Node)
uint8_t GetTargetScreen() const
Definition Node.h:195
T * FindChild(const std::string &name, bool recurse)
Definition Node.h:330
NodeClass * CreateChild()
Definition Node.h:152
const WeakPtr< Node > & GetSelfPtr() const
Definition Node.h:327
std::vector< std::string > mTags
Definition Node.h:482
void RemoveChild(const SharedPtr< Node > &child)
Definition Node.h:265
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
RefCount< T > * GetRefCount() const
Definition SmartPointer.h:531
SharedPtr< T > Lock() const
Definition SmartPointer.h:492
const T * GetPointerRaw() const
Definition SmartPointer.h:551
Definition EngineTypes.h:206