// Constructor for hires patches public TexturePatch(string lumpname, int x, int y, bool flipx, bool flipy, int rotate, PixelColor blend, float alpha, int style) { // Initialize this.lumpname = lumpname; this.x = x; this.y = y; this.flipx = flipx; this.flipy = flipy; this.rotate = rotate; this.blend = blend; this.alpha = alpha; this.style = (TexturePathRenderStyle)style; }
// Constructor for simple patches public TexturePatch(string lumpname, int x, int y) { // Initialize this.lumpname = lumpname; this.x = x; this.y = y; this.flipx = false; this.flipy = false; this.rotate = 0; this.blend = new PixelColor(0, 0, 0, 0); this.alpha = 1.0f; this.style = TexturePathRenderStyle.Copy; }
public readonly bool Skip; //mxd // Constructor for simple patches public TexturePatch(string lumpname, int x, int y) { // Initialize this.LumpName = lumpname; this.X = x; this.Y = y; this.FlipX = false; this.FlipY = false; this.Rotate = 0; this.BlendColor = new PixelColor(0, 0, 0, 0); this.Alpha = 1.0f; this.RenderStyle = TexturePathRenderStyle.COPY; this.BlendStyle = TexturePathBlendStyle.NONE; //mxd this.HasLongName = false; //mxd this.Skip = false; //mxd }
//mxd. Constructor for hires patches public TexturePatch(PatchStructure patch) { // Initialize this.LumpName = patch.Name.ToUpperInvariant(); this.X = patch.OffsetX; this.Y = patch.OffsetY; this.FlipX = patch.FlipX; this.FlipY = patch.FlipY; this.Rotate = patch.Rotation; this.BlendColor = patch.BlendColor; this.Alpha = patch.Alpha; this.RenderStyle = patch.RenderStyle; this.BlendStyle = patch.BlendStyle; this.HasLongName = (Path.GetFileNameWithoutExtension(this.LumpName) != this.LumpName); this.Skip = patch.Skip; //mxd. Check data so we don't perform unneeded operations later on if (this.Alpha == 1.0f) { switch (this.RenderStyle) { case TexturePathRenderStyle.BLEND: case TexturePathRenderStyle.COPY_ALPHA: case TexturePathRenderStyle.COPY_NEW_ALPHA: case TexturePathRenderStyle.OVERLAY: this.RenderStyle = TexturePathRenderStyle.COPY; break; } } //mxd. and get rid of render styles we don't support if (this.RenderStyle == TexturePathRenderStyle.OVERLAY) { this.RenderStyle = TexturePathRenderStyle.COPY; } }
} //mxd #endregion #region ================== Constructor / Disposer // Constructor internal PatchStructure(TexturesParser parser) { // Initialize alpha = 1.0f; renderstyle = TexturePathRenderStyle.COPY; //mxd blendstyle = TexturePathBlendStyle.NONE; //mxd // There should be 3 tokens separated by 2 commas now: // Name, Width, Height // First token is the class name parser.SkipWhitespace(true); name = parser.StripTokenQuotes(parser.ReadToken(false)); //mxd. Don't skip newline if (string.IsNullOrEmpty(name)) { parser.ReportError("Expected patch name"); return; } //mxd. Skip what must be skipped skip = (name.ToUpperInvariant() == IGNORE_SPRITE); //mxd name = name.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); // Now we should find a comma if (!parser.NextTokenIs(",")) { return; //mxd } // Next is the patch width parser.SkipWhitespace(true); string tokenstr = parser.ReadToken(); if (string.IsNullOrEmpty(tokenstr) || !int.TryParse(tokenstr, NumberStyles.Integer, CultureInfo.InvariantCulture, out offsetx)) { parser.ReportError("Expected offset in pixels"); return; } // Now we should find a comma again if (!parser.NextTokenIs(",")) { return; //mxd } // Next is the patch height parser.SkipWhitespace(true); tokenstr = parser.ReadToken(); if (string.IsNullOrEmpty(tokenstr) || !int.TryParse(tokenstr, NumberStyles.Integer, CultureInfo.InvariantCulture, out offsety)) { parser.ReportError("Expected offset in pixels"); return; } // Next token is the beginning of the texture scope. If not, then the patch info ends here. if (!parser.NextTokenIs("{", false)) { return; //mxd } // Now parse the contents of texture structure bool done = false; //mxd while (!done && parser.SkipWhitespace(true)) { string token = parser.ReadToken(); token = token.ToLowerInvariant(); switch (token) { case "flipx": flipx = true; break; case "flipy": flipy = true; break; case "alpha": if (!ReadTokenFloat(parser, token, out alpha)) { return; } alpha = General.Clamp(alpha, 0.0f, 1.0f); break; case "rotate": if (!ReadTokenInt(parser, token, out rotation)) { return; } rotation = rotation % 360; //Coalesce multiples if (rotation < 0) { rotation += 360; //Force positive } if (rotation != 0 && rotation != 90 && rotation != 180 && rotation != 270) { parser.LogWarning("Unsupported rotation (" + rotation + ") in patch \"" + name + "\""); rotation = 0; } break; case "style": //mxd string s; if (!ReadTokenString(parser, token, out s)) { return; } int index = Array.IndexOf(renderStyles, s.ToLowerInvariant()); renderstyle = index == -1 ? TexturePathRenderStyle.COPY : (TexturePathRenderStyle)index; break; case "blend": //mxd parser.SkipWhitespace(false); PixelColor color = new PixelColor(); // Blend <string color>[,<float alpha>] block? token = parser.ReadToken(false); if (!parser.ReadByte(token, ref color.r)) { if (!ZDTextParser.GetColorFromString(token, ref color)) { parser.ReportError("Unsupported patch blend definition"); return; } } // That's Blend <int r>,<int g>,<int b>[,<float alpha>] block else { if (!parser.SkipWhitespace(false) || !parser.NextTokenIs(",", false) || !parser.SkipWhitespace(false) || !parser.ReadByte(ref color.g) || !parser.NextTokenIs(",", false) || !parser.SkipWhitespace(false) || !parser.ReadByte(ref color.b)) { parser.ReportError("Unsupported patch blend definition"); return; } } // Alpha block? float blendalpha = -1f; parser.SkipWhitespace(false); if (parser.NextTokenIs(",", false)) { parser.SkipWhitespace(false); if (!ReadTokenFloat(parser, token, out blendalpha)) { parser.ReportError("Unsupported patch blend alpha value"); return; } } // Blend may never be 0 when using the Tint effect if (blendalpha > 0.0f) { color.a = (byte)General.Clamp((int)(blendalpha * 255), 1, 254); blendstyle = TexturePathBlendStyle.TINT; } else if (blendalpha < 0.0f) { color.a = 255; blendstyle = TexturePathBlendStyle.BLEND; } else { // Ignore Blend when alpha == 0 parser.LogWarning("Blend with zero alpha will be ignored by ZDoom"); break; } // Store the color blendcolor = color; break; case "}": // Patch scope ends here, // break out of this parse loop done = true; break; } } }