Structs.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Runtime.InteropServices;
  6. using Urho.Physics;
  7. using Urho.Gui;
  8. using Urho.Urho2D;
  9. using Urho.Resources;
  10. namespace Urho {
  11. [StructLayout (LayoutKind.Sequential)]
  12. public struct Ray {
  13. public Vector3 Origin;
  14. public Vector3 Direction;
  15. public Ray(Vector3 origin, Vector3 direction)
  16. {
  17. Origin = origin;
  18. Direction = Vector3.Normalize(direction);
  19. }
  20. }
  21. [StructLayout (LayoutKind.Sequential)]
  22. public struct IntRect {
  23. public int Left, Top, Right, Bottom;
  24. public IntRect (int left, int top, int right, int bottom)
  25. {
  26. Left = left;
  27. Top = top;
  28. Right = right;
  29. Bottom = bottom;
  30. }
  31. }
  32. [StructLayout (LayoutKind.Sequential)]
  33. public unsafe struct TypeInfo {
  34. public StringHash Type;
  35. public UrhoString TypeName;
  36. public TypeInfo* BaseTypeInfo;
  37. }
  38. [StructLayout (LayoutKind.Sequential)]
  39. public struct Rect {
  40. public Vector2 Min, Max;
  41. public Rect (int left, int top, int right, int bottom)
  42. {
  43. Min = new Vector2 (left, top);
  44. Max = new Vector2 (right, bottom);
  45. }
  46. public Rect (Vector2 min, Vector2 max)
  47. {
  48. Min = min;
  49. Max = max;
  50. }
  51. }
  52. [StructLayout (LayoutKind.Sequential)]
  53. public struct ResourceRef {
  54. public StringHash Type;
  55. public UrhoString Name;
  56. }
  57. [StructLayout (LayoutKind.Sequential)]
  58. public struct HashIteratorBase {
  59. }
  60. [StructLayout (LayoutKind.Sequential)]
  61. public struct Iterator {
  62. }
  63. [StructLayout (LayoutKind.Sequential)]
  64. public struct ResourceRefList {
  65. }
  66. [StructLayout (LayoutKind.Sequential)]
  67. public struct BoundingBox {
  68. public Vector3 Min;
  69. public float DummyMin;
  70. public Vector3 Max;
  71. public float DummyMax;
  72. public BoundingBox (float min, float max)
  73. {
  74. DummyMax = 0;
  75. DummyMin = 0;
  76. Min = new Vector3 (min, min, min);
  77. Max = new Vector3 (max, max, max);
  78. }
  79. public BoundingBox (Vector3 min, Vector3 max)
  80. {
  81. DummyMax = 0;
  82. DummyMin = 0;
  83. Min = min;
  84. Max = max;
  85. }
  86. }
  87. [StructLayout(LayoutKind.Sequential)]
  88. public struct AnimationTriggerPoint {
  89. public float Time;
  90. public Variant Variant;
  91. }
  92. [StructLayout(LayoutKind.Explicit)]
  93. public struct VariantValue {
  94. [FieldOffset(0)] public int Int;
  95. [FieldOffset(0)] public byte Bool;
  96. [FieldOffset(0)] public float Float;
  97. [FieldOffset(0)] public IntPtr Ptr;
  98. [FieldOffset(8)] public int Int2;
  99. [FieldOffset(8)] public float Float2;
  100. [FieldOffset(8)] public IntPtr Ptr2;
  101. [FieldOffset(16)] public int Int3;
  102. [FieldOffset(16)] public float Float3;
  103. [FieldOffset(16)] public IntPtr Ptr3;
  104. [FieldOffset(24)] public int Int4;
  105. [FieldOffset(24)] public float Float4;
  106. [FieldOffset(24)] public IntPtr Ptr4;
  107. }
  108. [StructLayout(LayoutKind.Sequential)]
  109. public struct Variant {
  110. public VariantType Type;
  111. public VariantValue Value;
  112. }
  113. [StructLayout (LayoutKind.Sequential)]
  114. public struct Matrix3x4 {
  115. public float m00;
  116. public float m01;
  117. public float m02;
  118. public float m03;
  119. public float m10;
  120. public float m11;
  121. public float m12;
  122. public float m13;
  123. public float m20;
  124. public float m21;
  125. public float m22;
  126. public float m23;
  127. }
  128. [StructLayout (LayoutKind.Sequential)]
  129. public struct Color {
  130. public float R, G, B, A;
  131. public Color (float r = 1f, float g = 1f, float b = 1f, float a = 1f)
  132. {
  133. R = r;
  134. G = g;
  135. B = b;
  136. A = a;
  137. }
  138. public Color (Color source)
  139. {
  140. R = source.R;
  141. G = source.G;
  142. B = source.B;
  143. A = source.A;
  144. }
  145. public Color (Color source, float alpha)
  146. {
  147. R = source.R;
  148. G = source.G;
  149. B = source.B;
  150. A = alpha;
  151. }
  152. public static Color White = new Color (1, 1, 1);
  153. public static Color Gray = new Color (0.5f, 0.5f, 0.5f);
  154. public static Color Black = new Color (0.0f, 0.0f, 0.0f);
  155. public static Color Red = new Color (1.0f, 0.0f, 0.0f);
  156. public static Color Green = new Color (0.0f, 1.0f, 0.0f);
  157. public static Color Blue = new Color (0.0f, 0.0f, 1.0f);
  158. public static Color Cyan = new Color (0.0f, 1.0f, 1.0f);
  159. public static Color Magenta = new Color (1.0f, 0.0f, 1.0f);
  160. public static Color Yellow = new Color (1.0f, 1.0f, 0.0f);
  161. public static Color Transparent = new Color (0.0f, 0.0f, 0.0f, 0.0f);
  162. }
  163. [StructLayout (LayoutKind.Sequential)]
  164. public struct Frustum {
  165. }
  166. [StructLayout (LayoutKind.Sequential)]
  167. public struct WeakPtr {
  168. IntPtr ptr;
  169. IntPtr refCountPtr;
  170. public T GetUrhoObject<T>() where T : UrhoObject => Runtime.LookupObject<T>(ptr);
  171. public T GetRefCounted<T>() where T : RefCounted => Runtime.LookupRefCounted<T>(ptr);
  172. }
  173. [StructLayout (LayoutKind.Sequential)]
  174. public struct TouchState {
  175. public int TouchID;
  176. public IntVector2 Position, LastPosition, Delta;
  177. public float Pressure;
  178. WeakPtr touchedElementPtr;
  179. public UIElement TouchedElement => touchedElementPtr.GetUrhoObject<UIElement>();
  180. }
  181. [StructLayout (LayoutKind.Sequential)]
  182. public struct ColorFrame {
  183. public Color Color;
  184. public float Time;
  185. }
  186. [StructLayout (LayoutKind.Sequential)]
  187. public struct JoystickState {
  188. public IntPtr JoystickPtr;
  189. public IntPtr JoystickIdPtr;
  190. public IntPtr ControllerPtr;
  191. IntPtr screenJoystickPtr;
  192. public UIElement ScreenJoystick => Runtime.LookupObject<UIElement>(screenJoystickPtr);
  193. public UrhoString Name;
  194. public VectorBase Buttons;
  195. public VectorBase ButtonPress;
  196. public VectorBase Axes;
  197. public VectorBase Hats;
  198. public float GetAxisPosition(int position)
  199. {
  200. if (position >= Axes.Size)
  201. return 0;
  202. return Axes.Buffer.ReadSingle(position * sizeof(float));
  203. }
  204. public byte GetButtonDown(int position)
  205. {
  206. if (position >= Buttons.Size)
  207. return 0;
  208. return Marshal.ReadByte(Buttons.Buffer, position * sizeof(byte));
  209. }
  210. public byte GetButtonPress(int position)
  211. {
  212. if (position >= ButtonPress.Size)
  213. return 0;
  214. return Marshal.ReadByte(ButtonPress.Buffer, position * sizeof(byte));
  215. }
  216. public int GetHatPosition(int position)
  217. {
  218. if (position >= Hats.Size)
  219. return 0;
  220. return Marshal.ReadInt32(Hats.Buffer, position * sizeof(int));
  221. }
  222. }
  223. [StructLayout(LayoutKind.Sequential)]
  224. public struct VectorBase {
  225. public uint Size;
  226. public uint Capacity;
  227. public IntPtr Buffer;
  228. }
  229. [StructLayout (LayoutKind.Sequential)]
  230. public struct TextureFrame {
  231. }
  232. [StructLayout (LayoutKind.Sequential)]
  233. public struct LightBatchQueue {
  234. }
  235. [StructLayout (LayoutKind.Sequential)]
  236. public struct Bone {
  237. public UrhoString Name;
  238. public int NameHash;
  239. public uint ParentIndex;
  240. public Vector3 InitialPosition;
  241. public Quaternion InitialRotation;
  242. public Vector3 InitialScale;
  243. public Matrix3x4 OffsetMatrix;
  244. byte animated; //bool is not blittable.
  245. public bool Animated { get { return animated != 0; } set { animated = (byte)(value ? 1 : 0); } }
  246. public byte CollisionMask;
  247. public float Radius;
  248. public BoundingBox BoundingBox;
  249. WeakPtr Node;
  250. }
  251. public unsafe class BoneWrapper
  252. {
  253. readonly object objHolder;
  254. readonly Bone* b;
  255. public BoneWrapper(object objHolder, Bone* bone)
  256. {
  257. this.objHolder = objHolder;
  258. this.b = bone;
  259. }
  260. public UrhoString Name { get { return b->Name; } set { b->Name = value; } }
  261. public int NameHash { get { return b->NameHash; } set { b->NameHash = value; } }
  262. public uint ParentIndex { get { return b->ParentIndex; } set { b->ParentIndex = value; } }
  263. public Vector3 InitialPosition { get { return b->InitialPosition; } set { b->InitialPosition = value; } }
  264. public Quaternion InitialRotation { get { return b->InitialRotation; } set { b->InitialRotation = value; } }
  265. public Vector3 InitialScale { get { return b->InitialScale; } set { b->InitialScale = value; } }
  266. public Matrix3x4 OffsetMatrix { get { return b->OffsetMatrix; } set { b->OffsetMatrix = value; } }
  267. public bool Animated { get { return b->Animated; } set { b->Animated = value; } }
  268. public byte CollisionMask { get { return b->CollisionMask; } set { b->CollisionMask = value; } }
  269. public float Radius { get { return b->Radius; } set { b->Radius = value; } }
  270. public BoundingBox BoundingBox { get { return b->BoundingBox; } set { b->BoundingBox = value; } }
  271. }
  272. // DEBATABLE: maybe we should let the binder handle it?
  273. [StructLayout(LayoutKind.Sequential)]
  274. public struct RayQueryResult {
  275. public Vector3 Position;
  276. public Vector3 Normal;
  277. public Vector2 TextureUV;
  278. public float Distance;
  279. IntPtr drawablePtr;
  280. public Drawable Drawable => Runtime.LookupObject<Drawable>(drawablePtr);
  281. IntPtr nodePtr;
  282. public Node Node => Runtime.LookupObject<Node>(nodePtr);
  283. public uint SubObject;
  284. }
  285. // DEBATABLE: maybe we should let the binder handle it?
  286. [StructLayout (LayoutKind.Sequential)]
  287. public struct RenderPathCommand {
  288. }
  289. // DEBATABLE: maybe we should let the binder handle it?
  290. [StructLayout (LayoutKind.Sequential)]
  291. public struct GPUObject {
  292. }
  293. // DEBATABLE: maybe we should let the binder handle it?
  294. [StructLayout (LayoutKind.Sequential)]
  295. public struct GraphicsImpl {
  296. }
  297. [StructLayout (LayoutKind.Sequential)]
  298. public struct FontGlyph {
  299. public short X, Y, Width, Height, OffsetX, OffsetY, AdvanceX;
  300. public int Page;
  301. byte used;
  302. public bool Used { get { return used != 0; } set { used = (byte) (value ? 1 : 0); }}
  303. }
  304. // DEBATABLE: maybe we should let the binder handle it?
  305. [StructLayout (LayoutKind.Sequential)]
  306. public struct RandomAccessIterator {
  307. }
  308. // DEBATABLE: maybe we should let the binder handle it?
  309. [StructLayout (LayoutKind.Sequential)]
  310. public struct ModelMorph {
  311. }
  312. // DEBATABLE: maybe we should let the binder handle it?
  313. [StructLayout (LayoutKind.Sequential)]
  314. public struct Octant {
  315. }
  316. // DEBATABLE: maybe we should let the binder handle it?
  317. [StructLayout (LayoutKind.Sequential)]
  318. public struct CompressedLevel {
  319. public IntPtr ImageData;
  320. public CompressedFormat Format;
  321. public int Width, Height, Depth;
  322. public uint BlockSize, DataSize, RowSize, RowCount;
  323. }
  324. // DEBATABLE: maybe we should let the binder handle it?
  325. [StructLayout (LayoutKind.Sequential)]
  326. public struct Billboard {
  327. public Vector3 Position;
  328. public Vector2 Size;
  329. public Rect Uv;
  330. public Color Color;
  331. public float Rotation;
  332. byte enabled; //bool is not blittable.
  333. public bool Enabled { get { return enabled != 0; } set { enabled = (byte)(value ? 1 : 0); } }
  334. public float SortDistance;
  335. }
  336. public unsafe class BillboardWrapper
  337. {
  338. readonly object bbHolder;
  339. readonly Billboard* bb;
  340. public BillboardWrapper(object bbHolder, Billboard* bb)
  341. {
  342. this.bbHolder = bbHolder;
  343. this.bb = bb;
  344. }
  345. public Vector3 Position { get { return bb->Position; } set { bb->Position = value; } }
  346. public Vector2 Size { get { return bb->Size; } set { bb->Size = value; } }
  347. public Rect Uv { get { return bb->Uv; } set { bb->Uv = value; } }
  348. public Color Color { get { return bb->Color; } set { bb->Color = value; } }
  349. public float Rotation { get { return bb->Rotation; } set { bb->Rotation = value; } }
  350. public bool Enabled { get { return bb->Enabled; } set { bb->Enabled = value; } }
  351. public float SortDistance { get { return bb->SortDistance; } set { bb->SortDistance = value; } }
  352. }
  353. // DEBATABLE: maybe we should let the binder handle it?
  354. [StructLayout (LayoutKind.Sequential)]
  355. public struct AnimationTrack {
  356. }
  357. // DEBATABLE: maybe we should let the binder handle it?
  358. [StructLayout (LayoutKind.Sequential)]
  359. public struct CustomGeometryVertex {
  360. }
  361. // DEBATABLE: maybe we should let the binder handle it?
  362. [StructLayout (LayoutKind.Sequential)]
  363. public struct NetworkState {
  364. }
  365. // DEBATABLE: maybe we should let the binder handle it?
  366. [StructLayout (LayoutKind.Sequential)]
  367. public struct ComponentReplicationState {
  368. }
  369. // DEBATABLE: maybe we should let the binder handle it?
  370. [StructLayout (LayoutKind.Sequential)]
  371. public struct ShaderParameter {
  372. }
  373. // DEBATABLE: maybe we should let the binder handle it?
  374. [StructLayout (LayoutKind.Sequential)]
  375. public struct UrhoString
  376. {
  377. public uint Length;
  378. public uint Capacity;
  379. public IntPtr Buffer;
  380. }
  381. [StructLayout (LayoutKind.Sequential)]
  382. public struct BiasParameters {
  383. public float ConstantBias;
  384. public float SlopeScaleBias;
  385. public BiasParameters (float constantBias, float slopeScaleBias)
  386. {
  387. ConstantBias = constantBias;
  388. SlopeScaleBias = slopeScaleBias;
  389. }
  390. }
  391. [StructLayout (LayoutKind.Sequential)]
  392. public struct CascadeParameters {
  393. public float Split1, Split2, Split3, Split4;
  394. public float FadeStart;
  395. public float BiasAutoAdjust;
  396. public CascadeParameters (float split1, float split2, float split3, float split4, float fadeStart, float biasAutoAdjust = 1f)
  397. {
  398. Split1 = split1;
  399. Split2 = split2;
  400. Split3 = split3;
  401. Split4 = split4;
  402. FadeStart = fadeStart;
  403. BiasAutoAdjust = biasAutoAdjust;
  404. }
  405. }
  406. [StructLayout (LayoutKind.Sequential)]
  407. public struct FocusParameters {
  408. public byte Focus;
  409. public byte NonUniform;
  410. public byte AutoSize;
  411. public float Quantize;
  412. public float MinView;
  413. }
  414. }
  415. namespace Urho.IO {
  416. [StructLayout (LayoutKind.Sequential)]
  417. public struct PackageEntry {
  418. public int Offset, Size, Checksum;
  419. }
  420. }
  421. namespace Urho.Urho2D {
  422. // DEBATABLE: maybe we should let the binder handle it?
  423. [StructLayout(LayoutKind.Sequential)]
  424. public struct TileMapInfo2D {
  425. public Orientation2D Orientation;
  426. public int Width;
  427. public int Height;
  428. public float TileWidth;
  429. public float TileHeight;
  430. //calculated properties:
  431. public float MapWidth => Width * TileWidth;
  432. public float MapHeight
  433. {
  434. get
  435. {
  436. if (Orientation == Orientation2D.Staggered)
  437. return (Height + 1) * 0.5f * TileHeight;
  438. return Height * TileHeight;
  439. }
  440. }
  441. }
  442. }
  443. namespace Urho.Navigation {
  444. [StructLayout(LayoutKind.Sequential)]
  445. public struct dtQueryFilter {
  446. //public float[] AreaCost; // Cost per area type. (Used by default implementation.)
  447. //public ushort IncludeFlags; // Flags for polygons that can be visited. (Used by default implementation.)
  448. //public ushort ExcludeFlags; // Flags for polygons that should not be visted. (Used by default implementation.)
  449. }
  450. [StructLayout(LayoutKind.Sequential)]
  451. public struct CrowdObstacleAvoidanceParams {
  452. public float VelBias;
  453. public float WeightDesVel;
  454. public float WeightCurVel;
  455. public float WeightSide;
  456. public float WeightToi;
  457. public float HorizTime;
  458. public byte GridSize;
  459. public byte AdaptiveDivs;
  460. public byte AdaptiveRings;
  461. public byte AdaptiveDepth;
  462. };
  463. }
  464. namespace Urho.Physics {
  465. [StructLayout(LayoutKind.Sequential)]
  466. public struct PhysicsRaycastResult {
  467. public Vector3 Position;
  468. public Vector3 Normal;
  469. public float Distance;
  470. IntPtr bodyPtr;
  471. public RigidBody Body => Runtime.LookupObject<RigidBody>(bodyPtr);
  472. }
  473. }
  474. namespace Urho.Resources {
  475. [StructLayout (LayoutKind.Sequential)]
  476. public struct XPathResultSet {
  477. }
  478. }
  479. namespace Urho.Network {
  480. [StructLayout (LayoutKind.Sequential)]
  481. public struct ReplicationState {
  482. IntPtr connection;
  483. public Connection Connection => Runtime.LookupObject<Connection> (connection);
  484. }
  485. [StructLayout (LayoutKind.Sequential)]
  486. public unsafe struct DirtyBits {
  487. public fixed byte Data [8];
  488. public byte Count;
  489. }
  490. [StructLayout (LayoutKind.Sequential)]
  491. public struct NodeReplicationState {
  492. }
  493. }