FSO.SimAntics.VMContext.RefreshLighting C# (CSharp) Method

RefreshLighting() public method

public RefreshLighting ( ushort room, bool commit ) : void
room ushort
commit bool
return void
        public void RefreshLighting(ushort room, bool commit)
        {
            if (RoomInfo == null) return;
            var info = RoomInfo[room];
            info.Light.AmbientLight = 0;
            info.Light.OutsideLight = 0;
            if (info.Room.IsOutside)
            {
                info.Light.OutsideLight = 100;
            }
            else
            {
                float areaScale = Math.Max(1, info.Room.Area / 100f);
                foreach (var ent in info.Entities)
                {
                    var flags2 = (VMEntityFlags2)ent.GetValue(VMStackObjectVariable.FlagField2);
                    var cont = ent.GetValue(VMStackObjectVariable.LightingContribution);
                    if (cont > 0)
                    {
                        if ((flags2 & (VMEntityFlags2.ArchitectualWindow | VMEntityFlags2.ArchitectualDoor)) > 0)
                            info.Light.OutsideLight += (ushort)Math.Min(100, cont / areaScale);
                        else
                            info.Light.AmbientLight += (ushort)Math.Min(100, cont / areaScale);
                    }
                }
                if (info.Light.OutsideLight > 100) info.Light.OutsideLight = 100;
            }

            if (commit && UseWorld) {
                Blueprint.Light = new RoomLighting[RoomInfo.Length];
                for (int i = 0; i < RoomInfo.Length; i++)
                {
                    Blueprint.Light[i] = RoomInfo[i].Light;
                }
                Blueprint.Damage.Add(new BlueprintDamage(BlueprintDamageType.LIGHTING_CHANGED));
            }
        }