// Copyright (c) 2008-2022 the Urho3D project // License: MIT #pragma once #include "../Graphics/Skeleton.h" #include "../Scene/Scene.h" #include "../Graphics/Octree.h" #include "../Graphics/DebugRenderer.h" #include "../IO/PackageFile.h" namespace Urho3D { #ifdef URHO3D_NETWORK static const bool URHO3D_NETWORK_DEFINED = true; #else static const bool URHO3D_NETWORK_DEFINED = false; #endif static const AttributeInfo noAttributeInfo; template const AttributeInfo& Serializable_GetAttributeInfo(unsigned index, T* ptr) { const Vector* attributes = ptr->GetAttributes(); if (!attributes || index >= attributes->Size()) { GetActiveASContext()->SetException("Index out of bounds"); return noAttributeInfo; } else return attributes->At(index); } #define REGISTER_MEMBERS_MANUAL_PART_Serializable() \ engine->RegisterObjectMethod(className, "const AttributeInfo& get_attributeInfos(uint) const", AS_FUNCTION_OBJLAST(Serializable_GetAttributeInfo), AS_CALL_CDECL_OBJLAST); // ======================================================================================== // bool Node::SaveXML(Serializer& dest, const String& indentation = "\t") const | File: ../Scene/Node.h template bool Node_SaveXML_File(File* file, const String& indentation, T* ptr) { return file && ptr->SaveXML(*file, indentation); } // bool Node::SaveXML(Serializer& dest, const String& indentation = "\t") const | File: ../Scene/Node.h template bool Node_SaveXML_VectorBuffer(VectorBuffer& buffer, const String& indentation, T* ptr) { return ptr->SaveXML(buffer, indentation); } // bool Node::SaveJSON(Serializer& dest, const String& indentation = "\t") const | File: ../Scene/Node.h template bool Node_SaveJSON_File(File* file, T* ptr) { return file && ptr->SaveJSON(*file); } // bool Node::SaveJSON(Serializer& dest, const String& indentation = "\t") const | File: ../Scene/Node.h template bool Node_SaveJSON_VectorBuffer(VectorBuffer& buffer, T* ptr) { return ptr->SaveJSON(buffer); } // template void Node::GetChildrenWithComponent(PODVector& dest, bool recursive = false) const | File: ../Scene/Node.h template CScriptArray* Node_GetChildren_Script(bool recursive, T* ptr) { PODVector nodes; ptr->template GetChildrenWithComponent(nodes, recursive); return VectorToHandleArray(nodes, "Array"); } // template void Node::GetChildrenWithComponent(PODVector& dest, bool recursive = false) const | File: ../Scene/Node.h template CScriptArray* Node_GetChildren_Script_ClassName(const String& className, bool recursive, T* ptr) { PODVector nodes; ptr->template GetChildrenWithComponent(nodes, recursive); PODVector result; for (PODVector::Iterator i = nodes.Begin(); i != nodes.End(); ++i) { Node* node = *i; const Vector>& components = node->GetComponents(); for (Vector>::ConstIterator j = components.Begin(); j != components.End(); ++j) { if (auto* instance = (*j)->Cast()) { if (instance->IsA(className)) result.Push(node); } } } return VectorToHandleArray(result, "Array"); } // void Node::GetComponents(PODVector& dest, StringHash type, bool recursive = false) const | File: ../Scene/Node.h template CScriptArray* Node_GetComponents_Type(const String& typeName, bool recursive, T* ptr) { PODVector components; ptr->GetComponents(components, typeName, recursive); return VectorToHandleArray(components, "Array"); } // unsigned Node::GetNumChildren(bool recursive = false) const | File: ../Scene/Node.h template unsigned Node_GetNumChildren_NonRecursive(T* ptr) { return ptr->GetNumChildren(false); } // unsigned Node::GetNumChildren(bool recursive = false) const | File: ../Scene/Node.h template unsigned Node_GetNumChildren_Recursive(T* ptr) { return ptr->GetNumChildren(true); } // Node* Node::GetChild(unsigned index) const | File: ../Scene/Node.h template Node* Node_GetChild(unsigned index, T* ptr) { const Vector>& children = ptr->GetChildren(); if (index >= children.Size()) { GetActiveASContext()->SetException("Index out of bounds"); return nullptr; } else return children[index].Get(); } // Node* Node::GetChild(const String& name, bool recursive = false) const | File: ../Scene/Node.h template Node* Node_GetChild_Name_NonRecursive(const String& name, T* ptr) { return ptr->GetChild(name, false); } // Node* Node::GetChild(const String& name, bool recursive = false) const | File: ../Scene/Node.h template Node* Node_GetChild_Name_Recursive(const String& name, T* ptr) { return ptr->GetChild(name, true); } // const Vector>& Node::GetComponents() const | File: ../Scene/Node.h template Component* Node_GetComponent(unsigned index, T* ptr) { const Vector>& components = ptr->GetComponents(); if (index >= components.Size()) { GetActiveASContext()->SetException("Index out of bounds"); return nullptr; } else return components[index]; } // const VariantMap& Node::GetVars() const | File: ../Scene/Node.h template VariantMap& Node_GetVars(T* ptr) { // Assume that the vars will be modified and queue a network update attribute check ptr->MarkNetworkUpdate(); return const_cast(ptr->GetVars()); } #define REGISTER_MEMBERS_MANUAL_PART_Node() \ RegisterNamedObjectConstructor(engine, className); \ \ /* bool Node::SaveXML(Serializer& dest, const String& indentation = "\t") const | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "bool SaveXML(File@+, const String&in = \"\t\")", AS_FUNCTION_OBJLAST(Node_SaveXML_File), AS_CALL_CDECL_OBJLAST); \ engine->RegisterObjectMethod(className, "bool SaveXML(VectorBuffer&, const String&in = \"\t\")", AS_FUNCTION_OBJLAST(Node_SaveXML_VectorBuffer), AS_CALL_CDECL_OBJLAST); \ \ /* bool Node::SaveJSON(Serializer& dest, const String& indentation = "\t") const | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "bool SaveJSON(File@+)", AS_FUNCTION_OBJLAST(Node_SaveJSON_File), AS_CALL_CDECL_OBJLAST); \ engine->RegisterObjectMethod(className, "bool SaveJSON(VectorBuffer&)", AS_FUNCTION_OBJLAST(Node_SaveJSON_VectorBuffer), AS_CALL_CDECL_OBJLAST); \ \ /* template void Node::GetChildrenWithComponent(PODVector& dest, bool recursive = false) const | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "Array@ GetChildrenWithScript(bool = false) const", AS_FUNCTION_OBJLAST(Node_GetChildren_Script), AS_CALL_CDECL_OBJLAST); \ engine->RegisterObjectMethod(className, "Array@ GetChildrenWithScript(const String&in, bool = false) const", AS_FUNCTION_OBJLAST(Node_GetChildren_Script_ClassName), AS_CALL_CDECL_OBJLAST); \ \ /* void Node::GetComponents(PODVector& dest, StringHash type, bool recursive = false) const | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "Array@ GetComponents(const String&in, bool = false) const", AS_FUNCTION_OBJLAST(Node_GetComponents_Type), AS_CALL_CDECL_OBJLAST); \ \ /* unsigned Node::GetNumChildren(bool recursive = false) const | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "uint get_numChildren() const", AS_FUNCTION_OBJLAST(Node_GetNumChildren_NonRecursive), AS_CALL_CDECL_OBJLAST); \ engine->RegisterObjectMethod(className, "uint get_numAllChildren() const", AS_FUNCTION_OBJLAST(Node_GetNumChildren_Recursive), AS_CALL_CDECL_OBJLAST); \ \ /* Node* Node::GetChild(unsigned index) const | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "Node@+ get_children(uint) const", AS_FUNCTION_OBJLAST(Node_GetChild), AS_CALL_CDECL_OBJLAST); \ \ /* Node* Node::GetChild(const String& name, bool recursive = false) const | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "Node@+ get_childrenByName(const String&in) const", AS_FUNCTION_OBJLAST(Node_GetChild_Name_NonRecursive), AS_CALL_CDECL_OBJLAST); \ engine->RegisterObjectMethod(className, "Node@+ get_allChildrenByName(const String&in) const", AS_FUNCTION_OBJLAST(Node_GetChild_Name_Recursive), AS_CALL_CDECL_OBJLAST); \ \ /* const Vector>& Node::GetComponents() const | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "Component@+ get_components(uint) const", AS_FUNCTION_OBJLAST(Node_GetComponent), AS_CALL_CDECL_OBJLAST); \ \ /* const VariantMap& Node::GetVars() const | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "VariantMap& get_vars()", AS_FUNCTION_OBJLAST(Node_GetVars), AS_CALL_CDECL_OBJLAST); \ \ /* Workarounds for Connection that used outside URHO3D_NETWORK define */ \ if (URHO3D_NETWORK_DEFINED) \ { \ /* void Node::SetOwner(Connection* owner) | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "void SetOwner(Connection@+)", AS_METHOD(T, SetOwner), AS_CALL_THISCALL); \ engine->RegisterObjectMethod(className, "void set_owner(Connection@+)", AS_METHOD(T, SetOwner), AS_CALL_THISCALL); \ \ /* Connection* Node::GetOwner() const | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "Connection@+ GetOwner() const", AS_METHOD(T, GetOwner), AS_CALL_THISCALL); \ engine->RegisterObjectMethod(className, "Connection@+ get_owner() const", AS_METHOD(T, GetOwner), AS_CALL_THISCALL); \ \ /* void Node::CleanupConnection(Connection* connection) | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "void CleanupConnection(Connection@+)", AS_METHOD(T, CleanupConnection), AS_CALL_THISCALL); \ } // ======================================================================================== // bool Scene::LoadXML(Deserializer& source) | File: ../Scene/Scene.h template bool Scene_LoadXML_File(File* file, T* ptr) { return file && ptr->LoadXML(*file); } // bool Scene::LoadXML(Deserializer& source) | File: ../Scene/Scene.h template bool Scene_LoadXML_VectorBuffer(VectorBuffer& buffer, T* ptr) { return ptr->LoadXML(buffer); } // bool Scene::LoadJSON(Deserializer& source) | File: ../Scene/Scene.h template bool Scene_LoadJSON_File(File* file, T* ptr) { return file && ptr->LoadJSON(*file); } // bool Scene::LoadJSON(Deserializer& source) | File: ../Scene/Scene.h template bool Scene_LoadJSON_VectorBuffer(VectorBuffer& buffer, T* ptr) { return ptr->LoadJSON(buffer); } // Node* Scene::Instantiate(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h template Node* Scene_Instantiate_File(File* file, const Vector3& position, const Quaternion& rotation, CreateMode mode, T* ptr) { return file ? ptr->Instantiate(*file, position, rotation, mode) : nullptr; } // Node* Scene::Instantiate(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h template Node* Scene_Instantiate_VectorBuffer(VectorBuffer& buffer, const Vector3& position, const Quaternion& rotation, CreateMode mode, T* ptr) { return ptr->Instantiate(buffer, position, rotation, mode); } // Node* Scene::InstantiateXML(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h template Node* Scene_InstantiateXML_File(File* file, const Vector3& position, const Quaternion& rotation, CreateMode mode, T* ptr) { return file ? ptr->InstantiateXML(*file, position, rotation, mode) : nullptr; } // Node* Scene::InstantiateXML(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h template Node* Scene_InstantiateXML_VectorBuffer(VectorBuffer& buffer, const Vector3& position, const Quaternion& rotation, CreateMode mode, T* ptr) { return ptr->InstantiateXML(buffer, position, rotation, mode); } // Node* Scene::InstantiateJSON(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h template Node* Scene_InstantiateJSON_File(File* file, const Vector3& position, const Quaternion& rotation, CreateMode mode, T* ptr) { return file ? ptr->InstantiateJSON(*file, position, rotation, mode) : nullptr; } // Node* Scene::InstantiateJSON(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h template Node* Scene_InstantiateJSON_VectorBuffer(VectorBuffer& buffer, const Vector3& position, const Quaternion& rotation, CreateMode mode, T* ptr) { return ptr->InstantiateJSON(buffer, position, rotation, mode); } // Node* Scene::InstantiateXML(const XMLElement& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h template Node* Scene_InstantiateXML_XMLFile(XMLFile* xml, const Vector3& position, const Quaternion& rotation, CreateMode mode, T* ptr) { return xml ? ptr->InstantiateXML(xml->GetRoot(), position, rotation, mode) : nullptr; } // Node* Scene::InstantiateJSON(const JSONValue& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h template Node* Scene_InstantiateJSON_JSONFile(JSONFile* json, const Vector3& position, const Quaternion& rotation, CreateMode mode, T* ptr) { return json ? ptr->InstantiateJSON(json->GetRoot(), position, rotation, mode) : nullptr; } // bool Scene::GetNodesWithTag(PODVector& dest, const String& tag) const | File: ../Scene/Scene.h template CScriptArray* Scene_GetNodesWithTag(const String& tag, T* ptr) { PODVector nodes; ptr->GetNodesWithTag(nodes, tag); return VectorToHandleArray(nodes, "Array"); } // template T* Scene::GetComponent(bool recursive = false) const | File: ../Scene/Node.h template DebugRenderer* Scene_GetDebugRenderer(T* ptr) { return ptr->template GetComponent(); } // template T* Scene::GetComponent(bool recursive = false) const | File: ../Scene/Node.h template Octree* Scene_GetOctree(T* ptr) { return ptr->template GetComponent(); } #define REGISTER_MEMBERS_MANUAL_PART_Scene() \ /* bool Scene::LoadXML(Deserializer& source) | File: ../Scene/Scene.h */ \ engine->RegisterObjectMethod(className, "bool LoadXML(File@+)", AS_FUNCTION_OBJLAST(Scene_LoadXML_File), AS_CALL_CDECL_OBJLAST); \ engine->RegisterObjectMethod(className, "bool LoadXML(VectorBuffer&)", AS_FUNCTION_OBJLAST(Scene_LoadXML_VectorBuffer), AS_CALL_CDECL_OBJLAST); \ \ /* bool Scene::LoadJSON(Deserializer& source) | File: ../Scene/Scene.h */ \ engine->RegisterObjectMethod(className, "bool LoadJSON(File@+)", AS_FUNCTION_OBJLAST(Scene_LoadJSON_File), AS_CALL_CDECL_OBJLAST); \ engine->RegisterObjectMethod(className, "bool LoadJSON(VectorBuffer&)", AS_FUNCTION_OBJLAST(Scene_LoadJSON_VectorBuffer), AS_CALL_CDECL_OBJLAST); \ \ /* Node* Scene::Instantiate(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h */ \ engine->RegisterObjectMethod(className, "Node@+ Instantiate(File@+, const Vector3&in, const Quaternion&in, CreateMode = REPLICATED)", AS_FUNCTION_OBJLAST(Scene_Instantiate_File), AS_CALL_CDECL_OBJLAST); \ engine->RegisterObjectMethod(className, "Node@+ Instantiate(VectorBuffer&, const Vector3&in, const Quaternion&in, CreateMode = REPLICATED)", AS_FUNCTION_OBJLAST(Scene_Instantiate_VectorBuffer), AS_CALL_CDECL_OBJLAST); \ \ /* Node* Scene::InstantiateXML(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h */ \ engine->RegisterObjectMethod(className, "Node@+ InstantiateXML(File@+, const Vector3&in, const Quaternion&in, CreateMode = REPLICATED)", AS_FUNCTION_OBJLAST(Scene_InstantiateXML_File), AS_CALL_CDECL_OBJLAST); \ engine->RegisterObjectMethod(className, "Node@+ InstantiateXML(VectorBuffer&, const Vector3&in, const Quaternion&in, CreateMode = REPLICATED)", AS_FUNCTION_OBJLAST(Scene_InstantiateXML_VectorBuffer), AS_CALL_CDECL_OBJLAST); \ \ /*Node* Scene::InstantiateJSON(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h */ \ engine->RegisterObjectMethod(className, "Node@+ InstantiateJSON(File@+, const Vector3&in, const Quaternion&in, CreateMode = REPLICATED)", AS_FUNCTION_OBJLAST(Scene_InstantiateJSON_File), AS_CALL_CDECL_OBJLAST); \ engine->RegisterObjectMethod(className, "Node@+ InstantiateJSON(VectorBuffer&, const Vector3&in, const Quaternion&in, CreateMode = REPLICATED)", AS_FUNCTION_OBJLAST(Scene_InstantiateJSON_VectorBuffer), AS_CALL_CDECL_OBJLAST); \ \ /* Node* Scene::InstantiateXML(const XMLElement& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h */ \ engine->RegisterObjectMethod(className, "Node@+ InstantiateXML(XMLFile@+, const Vector3&in, const Quaternion&in, CreateMode = REPLICATED)", AS_FUNCTION_OBJLAST(Scene_InstantiateXML_XMLFile), AS_CALL_CDECL_OBJLAST); \ \ /* Node* Scene::InstantiateJSON(const JSONValue& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED) | File: ../Scene/Scene.h */ \ engine->RegisterObjectMethod(className, "Node@+ InstantiateJSON(JSONFile@+, const Vector3&in, const Quaternion&in, CreateMode = REPLICATED)", AS_FUNCTION_OBJLAST(Scene_InstantiateJSON_JSONFile), AS_CALL_CDECL_OBJLAST); \ \ /* bool Scene::GetNodesWithTag(PODVector& dest, const String& tag) const | File: ../Scene/Scene.h */ \ engine->RegisterObjectMethod(className, "Array@ GetNodesWithTag(const String&in) const", AS_FUNCTION_OBJLAST(Scene_GetNodesWithTag), AS_CALL_CDECL_OBJLAST); \ \ /* template T* Scene::GetComponent(bool recursive = false) const | File: ../Scene/Node.h */ \ engine->RegisterObjectMethod(className, "DebugRenderer@+ get_debugRenderer() const", AS_FUNCTION_OBJLAST(Scene_GetDebugRenderer), AS_CALL_CDECL_OBJLAST); \ engine->RegisterObjectMethod(className, "Octree@+ get_octree() const", AS_FUNCTION_OBJLAST(Scene_GetOctree), AS_CALL_CDECL_OBJLAST); \ \ /* Workaround Doxygen bug: have no const flag in xml (but already registered in template because string GetSignature(const MethodAnalyzer& method) ignores const) */ \ /* Component* Node::GetComponent(StringHash type, bool recursive=false) const | File: ../Scene/Scene.h */ \ /*engine->RegisterObjectMethod(className, "Component@+ GetComponent(StringHash, bool = false) const", AS_METHODPR(Scene, GetComponent, (StringHash, bool) const, Component*), AS_CALL_THISCALL);*/ \ /* bool Node::SaveXML(XMLElement &dest) const override | File: ../Scene/Scene.h */ \ /*engine->RegisterObjectMethod(className, "bool SaveXML(XMLElement&) const", AS_METHODPR(Scene, SaveXML, (XMLElement &) const, bool), AS_CALL_THISCALL);*/ \ /* bool Node::SaveJSON(JSONValue &dest) const override | File: ../Scene/Scene.h */ \ /*engine->RegisterObjectMethod(className, "bool SaveJSON(JSONValue&) const", AS_METHODPR(Scene, SaveJSON, (JSONValue &) const, bool), AS_CALL_THISCALL);*/ // ======================================================================================== // WeakPtr Bone::node_ | File: ../Graphics/Skeleton.h template Node* Bone_GetNode(T* ptr) { return ptr->node_; } // WeakPtr Bone::node_ | File: ../Graphics/Skeleton.h template void Bone_SetNode(Node* node, T* ptr) { ptr->node_ = node; } #define REGISTER_MEMBERS_MANUAL_PART_Bone() \ /* WeakPtr Bone::node_ | File: ../Graphics/Skeleton.h */ \ engine->RegisterObjectMethod(className, "void set_node(Node@+)", AS_FUNCTION_OBJLAST(Bone_SetNode), AS_CALL_CDECL_OBJLAST); \ engine->RegisterObjectMethod(className, "Node@+ get_node() const", AS_FUNCTION_OBJLAST(Bone_GetNode), AS_CALL_CDECL_OBJLAST); // ======================================================================================== #define REGISTER_MEMBERS_MANUAL_PART_Component() \ /* Workarounds for Connection that used outside URHO3D_NETWORK define */ \ if (URHO3D_NETWORK_DEFINED) \ { \ /* void Component::CleanupConnection(Connection* connection) | File: ../Scene/Component.h */ \ engine->RegisterObjectMethod(className, "void CleanupConnection(Connection@+)", AS_METHODPR(T, CleanupConnection, (Connection*), void), AS_CALL_THISCALL); \ } }