Manual_Scene.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../Precompiled.h"
  23. #include "../AngelScript/APITemplates.h"
  24. #include "../AngelScript/Manual_Scene.h"
  25. #ifdef URHO3D_PHYSICS
  26. #include "../Physics/PhysicsWorld.h"
  27. #endif
  28. #ifdef URHO3D_URHO2D
  29. #include "../Urho2D/PhysicsWorld2D.h"
  30. #endif
  31. namespace Urho3D
  32. {
  33. // This function is called before ASRegisterGenerated()
  34. void ASRegisterManualFirst_Scene(asIScriptEngine* engine)
  35. {
  36. }
  37. // ========================================================================================
  38. #ifdef URHO3D_PHYSICS
  39. // template<class T> T * Node::GetComponent(bool recursive=false) const | File: ../Scene/Node.h
  40. static PhysicsWorld* SceneGetPhysicsWorld(Scene* ptr)
  41. {
  42. return ptr->GetComponent<PhysicsWorld>();
  43. }
  44. #endif
  45. #ifdef URHO3D_URHO2D
  46. // template<class T> T * Node::GetComponent(bool recursive=false) const | File: ../Scene/Node.h
  47. static PhysicsWorld2D* SceneGetPhysicsWorld2D(Scene* ptr)
  48. {
  49. return ptr->GetComponent<PhysicsWorld2D>();
  50. }
  51. #endif
  52. // This function is called after ASRegisterGenerated()
  53. void ASRegisterManualLast_Scene(asIScriptEngine* engine)
  54. {
  55. #ifdef URHO3D_PHYSICS
  56. // template<class T> T * Node::GetComponent(bool recursive=false) const | File: ../Scene/Node.h
  57. engine->RegisterObjectMethod("Scene", "PhysicsWorld@+ get_physicsWorld() const", asFUNCTION(SceneGetPhysicsWorld), asCALL_CDECL_OBJLAST);
  58. #endif
  59. #ifdef URHO3D_URHO2D
  60. // template<class T> T * Node::GetComponent(bool recursive=false) const | File: ../Scene/Node.h
  61. engine->RegisterObjectMethod("Scene", "PhysicsWorld2D@+ get_physicsWorld2D() const", asFUNCTION(SceneGetPhysicsWorld2D), asCALL_CDECL_OBJLAST);
  62. #endif
  63. }
  64. // ========================================================================================
  65. static const AttributeInfo noAttributeInfo{};
  66. const AttributeInfo& SerializableGetAttributeInfo(unsigned index, Serializable* ptr)
  67. {
  68. const Vector<AttributeInfo>* attributes = ptr->GetAttributes();
  69. if (!attributes || index >= attributes->Size())
  70. {
  71. GetActiveASContext()->SetException("Index out of bounds");
  72. return noAttributeInfo;
  73. }
  74. else
  75. return attributes->At(index);
  76. }
  77. // ========================================================================================
  78. // bool Node::SaveXML(Serializer &dest, const String &indentation="\t") const | File: ../Scene/Node.h
  79. bool NodeSaveXML(File* file, const String& indentation, Node* ptr)
  80. {
  81. return file && ptr->SaveXML(*file, indentation);
  82. }
  83. // bool Node::SaveXML(Serializer &dest, const String &indentation="\t") const | File: ../Scene/Node.h
  84. bool NodeSaveXMLVectorBuffer(VectorBuffer& buffer, const String& indentation, Node* ptr)
  85. {
  86. return ptr->SaveXML(buffer, indentation);
  87. }
  88. // bool Node::SaveJSON(Serializer &dest, const String &indentation="\t") const | File: ../Scene/Node.h
  89. bool NodeSaveJSON(File* file, Node* ptr)
  90. {
  91. return file && ptr->SaveJSON(*file);
  92. }
  93. // bool Node::SaveJSON(Serializer &dest, const String &indentation="\t") const | File: ../Scene/Node.h
  94. bool NodeSaveJSONVectorBuffer(VectorBuffer& buffer, Node* ptr)
  95. {
  96. return ptr->SaveJSON(buffer);
  97. }
  98. // template<class T> void Node::GetChildrenWithComponent(PODVector< Node * > &dest, bool recursive=false) const | File: ../Scene/Node.h
  99. CScriptArray* NodeGetChildrenWithScript(bool recursive, Node* ptr)
  100. {
  101. PODVector<Node*> nodes;
  102. ptr->GetChildrenWithComponent<ScriptInstance>(nodes, recursive);
  103. return VectorToHandleArray<Node>(nodes, "Array<Node@>");
  104. }
  105. // template<class T> void Node::GetChildrenWithComponent(PODVector< Node * > &dest, bool recursive=false) const | File: ../Scene/Node.h
  106. CScriptArray* NodeGetChildrenWithClassName(const String& className, bool recursive, Node* ptr)
  107. {
  108. PODVector<Node*> nodes;
  109. PODVector<Node*> result;
  110. ptr->GetChildrenWithComponent<ScriptInstance>(nodes, recursive);
  111. for (PODVector<Node*>::Iterator i = nodes.Begin(); i != nodes.End(); ++i)
  112. {
  113. Node* node = *i;
  114. const Vector<SharedPtr<Component> >& components = node->GetComponents();
  115. for (Vector<SharedPtr<Component> >::ConstIterator j = components.Begin(); j != components.End(); ++j)
  116. {
  117. if (auto* instance = (*j)->Cast<ScriptInstance>())
  118. {
  119. if (instance->IsA(className))
  120. result.Push(node);
  121. }
  122. }
  123. }
  124. return VectorToHandleArray<Node>(result, "Array<Node@>");
  125. }
  126. // void Node::GetComponents(PODVector< Component * > &dest, StringHash type, bool recursive=false) const | File: ../Scene/Node.h
  127. CScriptArray* NodeGetComponentsWithType(const String& typeName, bool recursive, Node* ptr)
  128. {
  129. PODVector<Component*> components;
  130. ptr->GetComponents(components, typeName, recursive);
  131. return VectorToHandleArray<Component>(components, "Array<Component@>");
  132. }
  133. // unsigned Node::GetNumChildren(bool recursive=false) const | File: ../Scene/Node.h
  134. unsigned NodeGetNumChildrenNonRecursive(Node* ptr)
  135. {
  136. return ptr->GetNumChildren(false);
  137. }
  138. // unsigned Node::GetNumChildren(bool recursive=false) const | File: ../Scene/Node.h
  139. unsigned NodeGetNumChildrenRecursive(Node* ptr)
  140. {
  141. return ptr->GetNumChildren(true);
  142. }
  143. // Node* Node::GetChild(unsigned index) const | File: ../Scene/Node.h
  144. Node* NodeGetChild(unsigned index, Node* ptr)
  145. {
  146. const Vector<SharedPtr<Node> >& children = ptr->GetChildren();
  147. if (index >= children.Size())
  148. {
  149. GetActiveASContext()->SetException("Index out of bounds");
  150. return nullptr;
  151. }
  152. else
  153. return children[index].Get();
  154. }
  155. // Node* Node::GetChild(const String &name, bool recursive=false) const | File: ../Scene/Node.h
  156. Node* NodeGetChildByName(const String& name, Node* ptr)
  157. {
  158. return ptr->GetChild(name);
  159. }
  160. // Node* Node::GetChild(const String &name, bool recursive=false) const | File: ../Scene/Node.h
  161. Node* NodeGetChildByNameRecursive(const String& name, Node* ptr)
  162. {
  163. return ptr->GetChild(name, true);
  164. }
  165. // const VariantMap& Node::GetVars() const | File: ../Scene/Node.h
  166. VariantMap& NodeGetVars(Node* ptr)
  167. {
  168. // Assume that the vars will be modified and queue a network update attribute check
  169. ptr->MarkNetworkUpdate();
  170. return const_cast<VariantMap&>(ptr->GetVars());
  171. }
  172. // const Vector<SharedPtr<Component> >& Node::GetComponents() const | File: ../Scene/Node.h
  173. Component* NodeGetComponent(unsigned index, Node* ptr)
  174. {
  175. const Vector<SharedPtr<Component> >& components = ptr->GetComponents();
  176. if (index >= components.Size())
  177. {
  178. GetActiveASContext()->SetException("Index out of bounds");
  179. return nullptr;
  180. }
  181. else
  182. return components[index];
  183. }
  184. // ========================================================================================
  185. // bool Scene::LoadXML(Deserializer &source) | File: ../Scene/Scene.h
  186. bool SceneLoadXML(File* file, Scene* ptr)
  187. {
  188. return file && ptr->LoadXML(*file);
  189. }
  190. // bool Scene::LoadXML(Deserializer &source) | File: ../Scene/Scene.h
  191. bool SceneLoadXMLVectorBuffer(VectorBuffer& buffer, Scene* ptr)
  192. {
  193. return ptr->LoadXML(buffer);
  194. }
  195. // bool Scene::LoadJSON(Deserializer &source) | File: ../Scene/Scene.h
  196. bool SceneLoadJSON(File* file, Scene* ptr)
  197. {
  198. return file && ptr->LoadJSON(*file);
  199. }
  200. // bool Scene::LoadJSON(Deserializer &source) | File: ../Scene/Scene.h
  201. bool SceneLoadJSONVectorBuffer(VectorBuffer& buffer, Scene* ptr)
  202. {
  203. return ptr->LoadJSON(buffer);
  204. }
  205. // Node* Scene::Instantiate(Deserializer &source, const Vector3 &position, const Quaternion &rotation, CreateMode mode=REPLICATED) | File: ../Scene/Scene.h
  206. Node* SceneInstantiate(File* file, const Vector3& position, const Quaternion& rotation, CreateMode mode, Scene* ptr)
  207. {
  208. return file ? ptr->Instantiate(*file, position, rotation, mode) : nullptr;
  209. }
  210. // Node* Scene::Instantiate(Deserializer &source, const Vector3 &position, const Quaternion &rotation, CreateMode mode=REPLICATED) | File: ../Scene/Scene.h
  211. Node* SceneInstantiateVectorBuffer(VectorBuffer& buffer, const Vector3& position, const Quaternion& rotation, CreateMode mode, Scene* ptr)
  212. {
  213. return ptr->Instantiate(buffer, position, rotation, mode);
  214. }
  215. // Node* Scene::InstantiateXML(Deserializer &source, const Vector3 &position, const Quaternion &rotation, CreateMode mode=REPLICATED) | File: ../Scene/Scene.h
  216. Node* SceneInstantiateXML(File* file, const Vector3& position, const Quaternion& rotation, CreateMode mode, Scene* ptr)
  217. {
  218. return file ? ptr->InstantiateXML(*file, position, rotation, mode) : nullptr;
  219. }
  220. // Node* Scene::InstantiateXML(Deserializer &source, const Vector3 &position, const Quaternion &rotation, CreateMode mode=REPLICATED) | File: ../Scene/Scene.h
  221. Node* SceneInstantiateXMLVectorBuffer(VectorBuffer& buffer, const Vector3& position, const Quaternion& rotation, CreateMode mode, Scene* ptr)
  222. {
  223. return ptr->InstantiateXML(buffer, position, rotation, mode);
  224. }
  225. // Node* Scene::InstantiateXML(Deserializer &source, const Vector3 &position, const Quaternion &rotation, CreateMode mode=REPLICATED) | File: ../Scene/Scene.h
  226. Node* SceneInstantiateXMLFile(XMLFile* xml, const Vector3& position, const Quaternion& rotation, CreateMode mode, Scene* ptr)
  227. {
  228. return xml ? ptr->InstantiateXML(xml->GetRoot(), position, rotation, mode) : nullptr;
  229. }
  230. // Node* Scene::InstantiateJSON(Deserializer &source, const Vector3 &position, const Quaternion &rotation, CreateMode mode=REPLICATED) | File: ../Scene/Scene.h
  231. Node* SceneInstantiateJSON(File* file, const Vector3& position, const Quaternion& rotation, CreateMode mode, Scene* ptr)
  232. {
  233. return file ? ptr->InstantiateJSON(*file, position, rotation, mode) : nullptr;
  234. }
  235. // Node* Scene::InstantiateJSON(Deserializer &source, const Vector3 &position, const Quaternion &rotation, CreateMode mode=REPLICATED) | File: ../Scene/Scene.h
  236. Node* SceneInstantiateJSONVectorBuffer(VectorBuffer& buffer, const Vector3& position, const Quaternion& rotation, CreateMode mode, Scene* ptr)
  237. {
  238. return ptr->InstantiateJSON(buffer, position, rotation, mode);
  239. }
  240. // Node* Scene::InstantiateJSON(Deserializer &source, const Vector3 &position, const Quaternion &rotation, CreateMode mode=REPLICATED) | File: ../Scene/Scene.h
  241. Node* SceneInstantiateJSONFile(JSONFile* json, const Vector3& position, const Quaternion& rotation, CreateMode mode, Scene* ptr)
  242. {
  243. return json ? ptr->InstantiateJSON(json->GetRoot(), position, rotation, mode) : nullptr;
  244. }
  245. // bool Scene::GetNodesWithTag(PODVector< Node * > &dest, const String &tag) const | File: ../Scene/Scene.h
  246. CScriptArray* SceneGetNodesWithTag(const String& tag, Scene* ptr)
  247. {
  248. PODVector<Node*> nodes;
  249. ptr->GetNodesWithTag(nodes, tag);
  250. return VectorToHandleArray<Node>(nodes, "Array<Node@>");
  251. }
  252. // template<class T> T * Node::GetComponent(bool recursive=false) const | File: ../Scene/Node.h
  253. DebugRenderer* SceneGetDebugRenderer(Scene* ptr)
  254. {
  255. return ptr->GetComponent<DebugRenderer>();
  256. }
  257. // template<class T> T * Node::GetComponent(bool recursive=false) const | File: ../Scene/Node.h
  258. Octree* SceneGetOctree(Scene* ptr)
  259. {
  260. return ptr->GetComponent<Octree>();
  261. }
  262. // ========================================================================================
  263. // WeakPtr<Node> Bone::node_ | File: ../Graphics/Skeleton.h
  264. Node* BoneGetNode(Bone* ptr)
  265. {
  266. return ptr->node_;
  267. }
  268. // WeakPtr<Node> Bone::node_ | File: ../Graphics/Skeleton.h
  269. void BoneSetNode(Node* node, Bone* ptr)
  270. {
  271. ptr->node_ = node;
  272. }
  273. }