using System.Runtime.InteropServices;

namespace SabreTools.Data.Models.BSP
{
    /// <summary>
    /// The worldlights lumps (Lump 15 for LDR and Lump 54 for HDR)
    /// contain information on each static light entity in the world,
    /// and are used to provide direct lighting for dynamically lit entities.
    /// The data is generated by VRAD from the entity lump. VRAD uses
    /// information from these lumps instead of referring to light
    /// entities from Entity lump.
    /// </summary>
    /// <see href="https://developer.valvesoftware.com/wiki/BSP_(Source)"/>
    [StructLayout(LayoutKind.Sequential)]
    public sealed class WorldLight
    {
        public Vector3D Origin = new();

        public Vector3D Intensity = new();

        /// <summary>
        /// For surfaces and spotlights
        /// </summary>
        public Vector3D Normal = new();

        public int Cluster;

        public EmitType EmitType;

        public int Style;

        /// <summary>
        /// Start of penumbra for emit_spotlight
        /// </summary>
        public float StopDot;

        /// <summary>
        /// End of penumbra for emit_spotlight
        /// </summary>
        public float StopDot2;

        public float Exponent;

        /// <summary>
        /// Cutoff distance
        /// </summary>
        public float Radius;

        // falloff for emit_spotlight + emit_point:
        // 1 / (constant_attn + linear_attn * dist + quadratic_attn * dist^2)

        public float ConstantAttn;

        public float LinearAttn;

        public float QuadraticAttn;

        /// <summary>
        /// Uses a combination of the DWL_FLAGS_ defines.
        /// </summary>
        public int Flags;

        public int Texinfo;

        /// <summary>
        /// Entity that this light it relative to
        /// </summary>
        public int Owner;
    }
}
