Exemplo n.º 1
0
        //mxd
        private void UpdateGldefsLight()
        {
            DynamicLightData light         = General.Map.Data.GldefsEntries[thing.Type];
            float            intensity_mod = General.Settings.GZDynamicLightIntensity;
            float            scale_mod     = General.Settings.GZDynamicLightRadius;

            //apply settings
            lightRenderStyle = light.Subtractive ? DynamicLightRenderStyle.NEGATIVE : DynamicLightRenderStyle.NORMAL;
            lightColor       = new Color4((float)lightRenderStyle / 100.0f, light.Color.Red * intensity_mod, light.Color.Green * intensity_mod, light.Color.Blue * intensity_mod);
            Vector2D o = new Vector2D(light.Offset.X, light.Offset.Y).GetRotated(thing.Angle - Angle2D.PIHALF);

            lightOffset = new Vector3(o.x, o.y, light.Offset.Z);
            lightType   = light.Type;

            if (lightType == DynamicLightType.SECTOR)
            {
                lightPrimaryRadius = light.Interval * thing.Sector.Brightness / 5.0f;
            }
            else
            {
                lightPrimaryRadius   = light.PrimaryRadius * scale_mod;
                lightSecondaryRadius = light.SecondaryRadius * scale_mod;
            }

            lightInterval = light.Interval;
            UpdateLightRadius(lightInterval);
        }
Exemplo n.º 2
0
        //mxd
        private void UpdateGldefsLight()
        {
            DynamicLightData light = General.Map.Data.GldefsEntries[thing.Type];

            GZGeneral.LightData ld = light.Type;

            //apply settings
            lightColor = new Color4((float)ld.LightRenderStyle / 100.0f, light.Color.Red, light.Color.Green, light.Color.Blue);
            Vector2D o = new Vector2D(light.Offset.X, light.Offset.Y).GetRotated(thing.Angle - Angle2D.PIHALF);

            lightOffset = new Vector3(o.x, o.y, light.Offset.Z);
            lightType   = light.Type;

            if (ld.LightModifier == GZGeneral.LightModifier.SECTOR)
            {
                lightPrimaryRadius = light.Interval * thing.Sector.Brightness / 5.0f;
            }
            else
            {
                lightPrimaryRadius   = light.PrimaryRadius;
                lightSecondaryRadius = light.SecondaryRadius;
            }

            lightInterval = light.Interval;
            UpdateLightRadius(lightInterval);
        }
Exemplo n.º 3
0
        private bool ParseLight(string lighttype)
        {
            DynamicLightData light = new DynamicLightData {
                Type = GldefsLightType.GLDEFS_TO_GZDOOM_LIGHT_TYPE[lighttype]
            };

            // Find classname
            SkipWhitespace(true);
            string lightname = StripQuotes(ReadToken());

            if (string.IsNullOrEmpty(lightname))
            {
                ReportError("Expected " + lighttype + " name");
                return(false);
            }

            // Now find opening brace
            if (!NextTokenIs("{", false))
            {
                ReportError("Expected opening brace");
                return(false);
            }

            // Read gldefs light structure
            while (SkipWhitespace(true))
            {
                string token = ReadToken().ToLowerInvariant();
                if (string.IsNullOrEmpty(token))
                {
                    continue;
                }

                switch (token)
                {
                case "color":
                    SkipWhitespace(true);
                    token = ReadToken();
                    if (!float.TryParse(token, NumberStyles.Float, CultureInfo.InvariantCulture, out light.Color.Red))
                    {
                        // Not numeric!
                        ReportError("Expected Red color value, but got \"" + token + "\"");
                        return(false);
                    }

                    SkipWhitespace(true);
                    token = ReadToken();
                    if (!float.TryParse(token, NumberStyles.Float, CultureInfo.InvariantCulture, out light.Color.Green))
                    {
                        // Not numeric!
                        ReportError("Expected Green color value, but got \"" + token + "\"");
                        return(false);
                    }

                    SkipWhitespace(true);
                    token = ReadToken();
                    if (!float.TryParse(token, NumberStyles.Float, CultureInfo.InvariantCulture, out light.Color.Blue))
                    {
                        // Not numeric!
                        ReportError("Expected Blue color value, but got \"" + token + "\"");
                        return(false);
                    }

                    // Check the value
                    if (light.Color.Red == 0.0f && light.Color.Green == 0.0f && light.Color.Blue == 0.0f)
                    {
                        LogWarning("\"" + lightname + "\" light Color value is "
                                   + light.Color.Red + "," + light.Color.Green + "," + light.Color.Blue
                                   + ". It won't be shown in GZDoom");
                    }
                    else if (light.Color.Red > 1.0f || light.Color.Green > 1.0f || light.Color.Blue > 1.0f ||
                             light.Color.Red < 0.0f || light.Color.Green < 0.0f || light.Color.Blue < 0.0f)
                    {
                        // Clamp values
                        light.Color.Red   = General.Clamp(light.Color.Red, 0.0f, 1.0f);
                        light.Color.Green = General.Clamp(light.Color.Green, 0.0f, 1.0f);
                        light.Color.Blue  = General.Clamp(light.Color.Blue, 0.0f, 1.0f);

                        // Notify user
                        LogWarning("\"" + lightname + "\" light Color value was clamped. Color values must be in [0.0 .. 1.0] range");
                    }
                    break;

                case "size":
                    if (lighttype != GldefsLightType.SECTOR)
                    {
                        SkipWhitespace(true);

                        token = ReadToken();
                        if (!int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out light.PrimaryRadius))
                        {
                            // Not numeric!
                            ReportError("Expected Size value, but got \"" + token + "\"");
                            return(false);
                        }

                        if (light.PrimaryRadius < 0)
                        {
                            ReportError("Size value should be positive, but is \"" + light.PrimaryRadius + "\"");
                            return(false);
                        }

                        light.PrimaryRadius *= 2;
                    }
                    else
                    {
                        ReportError("\"" + token + "\" is not valid property for " + lighttype);
                        return(false);
                    }
                    break;

                case "offset":
                    SkipWhitespace(true);
                    token = ReadToken();
                    if (!ReadSignedFloat(token, ref light.Offset.X))
                    {
                        // Not numeric!
                        ReportError("Expected Offset X value, but got \"" + token + "\"");
                        return(false);
                    }

                    SkipWhitespace(true);
                    token = ReadToken();
                    if (!ReadSignedFloat(token, ref light.Offset.Z))
                    {
                        // Not numeric!
                        ReportError("Expected Offset Y value, but got \"" + token + "\"");
                        return(false);
                    }

                    SkipWhitespace(true);
                    token = ReadToken();
                    if (!ReadSignedFloat(token, ref light.Offset.Y))
                    {
                        // Not numeric!
                        ReportError("Expected Offset Z value, but got \"" + token + "\"");
                        return(false);
                    }
                    break;

                case "subtractive":
                {
                    SkipWhitespace(true);

                    token = ReadToken();
                    int i;
                    if (!int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out i))
                    {
                        // Not numeric!
                        ReportError("expected Subtractive value, but got \"" + token + "\"");
                        return(false);
                    }

                    light.Subtractive = (i == 1);
                }
                break;

                case "dontlightself":
                {
                    SkipWhitespace(true);

                    token = ReadToken();
                    int i;
                    if (!int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out i))
                    {
                        // Not numeric!
                        ReportError("Expected DontLightSelf value, but got \"" + token + "\"");
                        return(false);
                    }

                    light.DontLightSelf = (i == 1);
                }
                break;

                case "interval":
                    if (lighttype == GldefsLightType.PULSE || lighttype == GldefsLightType.FLICKER2)
                    {
                        SkipWhitespace(true);

                        token = ReadToken();
                        float interval = 0f;
                        if (!ReadSignedFloat(token, ref interval))
                        {
                            // Not numeric!
                            ReportError("Expected Interval value, but got \"" + token + "\"");
                            return(false);
                        }

                        if (interval <= 0)
                        {
                            ReportError("Interval value should be greater than zero, but is \"" + interval + "\"");
                            return(false);
                        }

                        //I wrote logic for dynamic lights animation first, so here I modify gldefs settings to fit in existing logic
                        if (lighttype == GldefsLightType.PULSE)
                        {
                            light.Interval = (int)(interval * 35);  //measured in tics (35 per second) in PointLightPulse, measured in seconds in gldefs' PulseLight
                        }
                        else                                        //FLICKER2. Seems like PointLightFlickerRandom to me
                        {
                            light.Interval = (int)(interval * 350); //0.1 is one second for FlickerLight2
                        }
                    }
                    else
                    {
                        ReportError("\"" + token + "\" is not valid property for " + lighttype);
                        return(false);
                    }
                    break;

                case "secondarysize":
                    if (lighttype == GldefsLightType.PULSE || lighttype == GldefsLightType.FLICKER || lighttype == GldefsLightType.FLICKER2)
                    {
                        SkipWhitespace(true);

                        token = ReadToken();
                        if (!ReadSignedInt(token, ref light.SecondaryRadius))
                        {
                            // Not numeric!
                            ReportError("Expected SecondarySize value, but got \"" + token + "\"");
                            return(false);
                        }

                        if (light.SecondaryRadius < 0)
                        {
                            ReportError("SecondarySize value should be positive, but is \"" + light.SecondaryRadius + "\"");
                            return(false);
                        }

                        light.SecondaryRadius *= 2;
                    }
                    else
                    {
                        ReportError("\"" + token + "\" is not valid property for " + lighttype);
                        return(false);
                    }
                    break;

                case "chance":
                    if (lighttype == GldefsLightType.FLICKER)
                    {
                        SkipWhitespace(true);

                        token = ReadToken();
                        float chance = 0f;
                        if (!ReadSignedFloat(token, ref chance))
                        {
                            // Not numeric!
                            ReportError("Expected Chance value, but got \"" + token + "\"");
                            return(false);
                        }

                        // Check range
                        if (chance > 1.0f || chance < 0.0f)
                        {
                            ReportError("Chance must be in [0.0 .. 1.0] range, but is " + chance);
                            return(false);
                        }

                        // Transforming from 0.0 .. 1.0 to 0 .. 359 to fit in existing logic
                        light.Interval = (int)(chance * 359.0f);
                    }
                    else
                    {
                        ReportError("\"" + token + "\" is not valid property for " + lighttype);
                        return(false);
                    }
                    break;

                case "scale":
                    if (lighttype == GldefsLightType.SECTOR)
                    {
                        SkipWhitespace(true);

                        token = ReadToken();
                        float scale = 0f;
                        if (!ReadSignedFloat(token, ref scale))
                        {
                            // Not numeric!
                            ReportError("Expected Scale value, but got \"" + token + "\"");
                            return(false);
                        }

                        // Check range
                        if (scale > 1.0f || scale < 0.0f)
                        {
                            ReportError("Scale must be in [0.0 .. 1.0] range, but is " + scale);
                            return(false);
                        }

                        //sector light doesn't have animation, so we will store it's size in Interval
                        //transforming from 0.0 .. 1.0 to 0 .. 10 to preserve value.
                        light.Interval = (int)(scale * 10.0f);
                    }
                    else
                    {
                        ReportError("\"" + token + "\" is not valid property for " + lighttype);
                        return(false);
                    }
                    break;

                case "}":
                {
                    bool skip = (light.Color.Red == 0.0f && light.Color.Green == 0.0f && light.Color.Blue == 0.0f);

                    // Light-type specific checks
                    if (light.Type == DynamicLightType.NORMAL && light.PrimaryRadius == 0)
                    {
                        LogWarning("\"" + lightname + "\" light Size is 0. It won't be shown in GZDoom");
                        skip = true;
                    }

                    if (light.Type == DynamicLightType.FLICKER || light.Type == DynamicLightType.PULSE || light.Type == DynamicLightType.RANDOM)
                    {
                        if (light.PrimaryRadius == 0 && light.SecondaryRadius == 0)
                        {
                            LogWarning("\"" + lightname + "\" light Size and SecondarySize are 0. It won't be shown in GZDoom");
                            skip = true;
                        }
                    }

                    // Add to the collection?
                    if (!skip)
                    {
                        lightsbyname[lightname] = light;
                    }

                    // Break out of this parsing loop
                    return(true);
                }
                }
            }

            // All done here
            return(true);
        }