Particle.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (c) Craftwork Games. All rights reserved.
  2. // Licensed under the MIT license.
  3. // See LICENSE file in the project root for full license information.
  4. using System.Runtime.InteropServices;
  5. namespace MonoGame.Extended.Particles.Data;
  6. /// <summary>
  7. /// Represents an individual particle within the particle system.
  8. /// </summary>
  9. /// <remarks>
  10. /// The struct uses sequential layout with tight packing to optimize memory usage and performance.
  11. /// The fixed arrays are used to store positional, velocity, and color data efficiently in unmanaged memory.
  12. /// </remarks>
  13. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  14. public unsafe struct Particle
  15. {
  16. /// <summary>
  17. /// The time (in seconds) when this particle was created.
  18. /// </summary>
  19. public float Inception;
  20. /// <summary>
  21. /// The current age (in seconds) of this particle.
  22. /// </summary>
  23. public float Age;
  24. /// <summary>
  25. /// The current position of this particle in 2D space [X, Y].
  26. /// </summary>
  27. public fixed float Position[2];
  28. /// <summary>
  29. /// The current velocity vector of this particle [X, Y].
  30. /// </summary>
  31. public fixed float Velocity[2];
  32. /// <summary>
  33. /// The color of this particle in RGB format [R, G, B].
  34. /// </summary>
  35. public fixed float Color[3];
  36. /// <summary>
  37. /// The scale factor applied to this particle's visual representation.
  38. /// </summary>
  39. public fixed float Scale[2];
  40. /// <summary>
  41. /// The position where this particle was triggered or emitted from [X, Y].
  42. /// </summary>
  43. public fixed float TriggeredPos[2];
  44. /// <summary>
  45. /// The opacity (alpha) value of this particle, ranging from 0.0 (transparent) to 1.0 (opaque).
  46. /// </summary>
  47. public float Opacity;
  48. /// <summary>
  49. /// The rotation of this particle in radians.
  50. /// </summary>
  51. public float Rotation;
  52. /// <summary>
  53. /// The mass of this particle used during physics calculations.
  54. /// </summary>
  55. public float Mass;
  56. /// <summary>
  57. /// The depth at which this particle is rendered, used for layering particles.
  58. /// </summary>
  59. /// <remarks>
  60. /// Values range from 0.0 (front) to 1.0 (back).
  61. /// </remarks>
  62. public float LayerDepth;
  63. /// <summary>
  64. /// The size of the <see cref="Particle"/> struct in bytes.
  65. /// </summary>
  66. /// <remarks>
  67. /// Used for memory allocations and buffer operations.
  68. /// </remarks>
  69. public static readonly int SizeInBytes = Marshal.SizeOf<Particle>();
  70. }