UrhoMap.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using Urho.Audio;
  4. using Urho.Navigation;
  5. using Urho.Physics;
  6. using Urho.Urho2D;
  7. using Urho.Resources;
  8. using Urho.Gui;
  9. using Urho.Network;
  10. namespace Urho {
  11. /// <summary>
  12. /// Helper functions to return elements from a VariantMap
  13. /// </summary>
  14. internal static class UrhoMap {
  15. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  16. extern static IntPtr urho_map_get_ptr (IntPtr handle, int stringHash);
  17. static public SoundSource get_SoundSource(IntPtr handle, int stringHash)
  18. {
  19. return Runtime.LookupObject<SoundSource>(urho_map_get_ptr(handle, stringHash));
  20. }
  21. static public Sound get_Sound(IntPtr handle, int stringHash)
  22. {
  23. return Runtime.LookupObject<Sound>(urho_map_get_ptr(handle, stringHash));
  24. }
  25. static public Animation get_Animation(IntPtr handle, int stringHash)
  26. {
  27. return Runtime.LookupObject<Animation>(urho_map_get_ptr(handle, stringHash));
  28. }
  29. static public ParticleEffect get_ParticleEffect(IntPtr handle, int stringHash)
  30. {
  31. return Runtime.LookupObject<ParticleEffect>(urho_map_get_ptr(handle, stringHash));
  32. }
  33. static public Camera get_Camera (IntPtr handle, int stringHash)
  34. {
  35. return Runtime.LookupObject<Camera>(urho_map_get_ptr(handle, stringHash));
  36. }
  37. static public Component get_Component (IntPtr handle, int stringHash)
  38. {
  39. return Runtime.LookupObject<Component>(urho_map_get_ptr(handle, stringHash));
  40. }
  41. static public Connection get_Connection (IntPtr handle, int stringHash)
  42. {
  43. return Runtime.LookupObject<Connection>(urho_map_get_ptr(handle, stringHash));
  44. }
  45. static public CrowdAgent get_CrowdAgent (IntPtr handle, int stringHash)
  46. {
  47. return Runtime.LookupObject<CrowdAgent>(urho_map_get_ptr(handle, stringHash));
  48. }
  49. static public IntPtr get_IntPtr (IntPtr handle, int stringHash)
  50. {
  51. return urho_map_get_ptr (handle, stringHash);
  52. }
  53. static public MouseMode get_MouseMode (IntPtr handle, int stringHash)
  54. {
  55. return (MouseMode) urho_map_get_int (handle, stringHash);
  56. }
  57. static public NavigationMesh get_NavigationMesh (IntPtr handle, int stringHash)
  58. {
  59. return Runtime.LookupObject<NavigationMesh>(urho_map_get_ptr(handle, stringHash));
  60. }
  61. static public Node get_Node (IntPtr handle, int stringHash)
  62. {
  63. return Runtime.LookupObject<Node>(urho_map_get_ptr(handle, stringHash));
  64. }
  65. static public UrhoObject get_Object (IntPtr handle, int stringHash)
  66. {
  67. return Runtime.LookupObject<UrhoObject>(urho_map_get_ptr(handle, stringHash));
  68. }
  69. static public Obstacle get_Obstacle (IntPtr handle, int stringHash)
  70. {
  71. return Runtime.LookupObject<Obstacle>(urho_map_get_ptr(handle, stringHash));
  72. }
  73. static public PhysicsWorld get_PhysicsWorld (IntPtr handle, int stringHash)
  74. {
  75. return Runtime.LookupObject<PhysicsWorld>(urho_map_get_ptr(handle, stringHash));
  76. }
  77. static public PhysicsWorld2D get_PhysicsWorld2D (IntPtr handle, int stringHash)
  78. {
  79. return Runtime.LookupObject<PhysicsWorld2D>(urho_map_get_ptr(handle, stringHash));
  80. }
  81. static public RenderSurface get_RenderSurface (IntPtr handle, int stringHash)
  82. {
  83. var ptr = urho_map_get_ptr(handle, stringHash);
  84. return ptr == IntPtr.Zero ? null : new RenderSurface(ptr);
  85. }
  86. static public Resource get_Resource (IntPtr handle, int stringHash)
  87. {
  88. return Runtime.LookupObject<Resource>(urho_map_get_ptr(handle, stringHash));
  89. }
  90. static public RigidBody get_RigidBody (IntPtr handle, int stringHash)
  91. {
  92. return Runtime.LookupObject<RigidBody>(urho_map_get_ptr(handle, stringHash));
  93. }
  94. static public RigidBody2D get_RigidBody2D (IntPtr handle, int stringHash)
  95. {
  96. return Runtime.LookupObject<RigidBody2D>(urho_map_get_ptr(handle, stringHash));
  97. }
  98. static public Scene get_Scene (IntPtr handle, int stringHash)
  99. {
  100. return Runtime.LookupObject<Scene>(urho_map_get_ptr(handle, stringHash));
  101. }
  102. static public Serializable get_Serializable (IntPtr handle, int stringHash)
  103. {
  104. throw new Exception ("Not implemented, as we need to figure out serializable mapping");
  105. }
  106. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  107. extern static IntPtr urho_map_get_buffer (IntPtr handle, int stringHash, out int size);
  108. static public CollisionData [] get_CollisionData (IntPtr handle, int stringHash)
  109. {
  110. int size;
  111. var buffer = urho_map_get_buffer (handle, stringHash, out size);
  112. return CollisionData.FromContactData (buffer, size);
  113. }
  114. static public byte[] get_Buffer(IntPtr handle, int stringHash)
  115. {
  116. int size;
  117. var buffer = urho_map_get_buffer(handle, stringHash, out size);
  118. var bytes = new byte[size];
  119. Marshal.Copy(buffer, bytes, 0, size);
  120. return bytes;
  121. }
  122. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  123. extern static IntPtr urho_map_get_String (IntPtr handle, int stringHash);
  124. static public string get_String (IntPtr handle, int stringHash)
  125. {
  126. return Marshal.PtrToStringAnsi(urho_map_get_String (handle, stringHash));
  127. }
  128. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  129. extern static int urho_map_get_StringHash (IntPtr handle, int stringHash);
  130. static public StringHash get_StringHash (IntPtr handle, int stringHash)
  131. {
  132. return new StringHash (urho_map_get_StringHash (handle, stringHash));
  133. }
  134. static public Texture get_Texture (IntPtr handle, int stringHash)
  135. {
  136. return Runtime.LookupObject<Texture>(urho_map_get_ptr(handle, stringHash));
  137. }
  138. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  139. extern static Variant urho_map_get_Variant (IntPtr handle, int stringHash);
  140. static public Variant get_Variant (IntPtr handle, int stringHash)
  141. {
  142. return urho_map_get_Variant (handle, stringHash);
  143. }
  144. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  145. extern static Vector3 urho_map_get_Vector3 (IntPtr handle, int stringHash);
  146. static public Vector3 get_Vector3 (IntPtr handle, int stringHash)
  147. {
  148. return urho_map_get_Vector3 (handle, stringHash);
  149. }
  150. static public View get_View (IntPtr handle, int stringHash)
  151. {
  152. var ptr = urho_map_get_ptr(handle, stringHash);
  153. return ptr == IntPtr.Zero ? null : new View(ptr);
  154. }
  155. static public UIElement get_UIElement (IntPtr handle, int stringHash)
  156. {
  157. return Runtime.LookupObject<UIElement>(urho_map_get_ptr(handle, stringHash));
  158. }
  159. static public WorkItem get_WorkItem (IntPtr handle, int stringHash)
  160. {
  161. return new WorkItem (urho_map_get_ptr (handle, stringHash));
  162. }
  163. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  164. extern static bool urho_map_get_bool (IntPtr handle, int stringHash);
  165. static public bool get_bool (IntPtr handle, int stringHash)
  166. {
  167. return urho_map_get_bool (handle, stringHash);
  168. }
  169. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  170. extern static float urho_map_get_float (IntPtr handle, int stringHash);
  171. static public float get_float (IntPtr handle, int stringHash)
  172. {
  173. return urho_map_get_float (handle, stringHash);
  174. }
  175. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  176. extern static int urho_map_get_int (IntPtr handle, int stringHash);
  177. static public int get_int (IntPtr handle, int stringHash)
  178. {
  179. return urho_map_get_int (handle, stringHash);
  180. }
  181. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  182. extern static uint urho_map_get_uint (IntPtr handle, int stringHash);
  183. static public uint get_uint (IntPtr handle, int stringHash)
  184. {
  185. return urho_map_get_uint (handle, stringHash);
  186. }
  187. }
  188. }