@ code cleanup

This commit is contained in:
codeimp 2010-09-16 11:39:16 +00:00
parent 159617106e
commit 7be6466f80
4 changed files with 28 additions and 59 deletions

View file

@ -153,26 +153,18 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
ImageData img = General.Map.Data.GetFlatImage(s.LongFloorTexture); ImageData img = General.Map.Data.GetFlatImage(s.LongFloorTexture);
if((img != null) && img.IsImageLoaded) if((img != null) && img.IsImageLoaded)
{ {
float xpan, ypan, xscale, yscale, rotate; // Fetch ZDoom fields
int color, light; Vector2D offset = new Vector2D(s.Fields.GetValue("xpanningfloor", 0.0f),
bool absolute; s.Fields.GetValue("ypanningfloor", 0.0f));
Vector2D scale = new Vector2D(s.Fields.GetValue("xscalefloor", 1.0f),
try s.Fields.GetValue("yscalefloor", 1.0f));
{ float rotate = s.Fields.GetValue("rotationfloor", 0.0f);
// Fetch ZDoom fields int color = s.Fields.GetValue("lightcolor", -1);
xpan = s.Fields.ContainsKey("xpanningfloor") ? (float)s.Fields["xpanningfloor"].Value : 0.0f; int light = s.Fields.GetValue("lightfloor", 0);
ypan = s.Fields.ContainsKey("ypanningfloor") ? (float)s.Fields["ypanningfloor"].Value : 0.0f; bool absolute = s.Fields.GetValue("lightfloorabsolute", false);
xscale = s.Fields.ContainsKey("xscalefloor") ? (float)s.Fields["xscalefloor"].Value : 1.0f;
yscale = s.Fields.ContainsKey("yscalefloor") ? (float)s.Fields["yscalefloor"].Value : 1.0f;
rotate = s.Fields.ContainsKey("rotationfloor") ? (float)s.Fields["rotationfloor"].Value : 0.0f;
color = s.Fields.ContainsKey("lightcolor") ? (int)s.Fields["lightcolor"].Value : -1;
light = s.Fields.ContainsKey("lightfloor") ? (int)s.Fields["lightfloor"].Value : 0;
absolute = s.Fields.ContainsKey("lightfloorabsolute") ? (bool)s.Fields["lightfloorabsolute"].Value : false;
}
catch(Exception) { return; }
// Setup the vertices with the given settings // Setup the vertices with the given settings
SetupSurfaceVertices(vertices, s, img, xpan, ypan, xscale, yscale, rotate, color, light, absolute); SetupSurfaceVertices(vertices, s, img, offset, scale, rotate, color, light, absolute);
} }
} }
@ -182,38 +174,28 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
ImageData img = General.Map.Data.GetFlatImage(s.LongFloorTexture); ImageData img = General.Map.Data.GetFlatImage(s.LongFloorTexture);
if((img != null) && img.IsImageLoaded) if((img != null) && img.IsImageLoaded)
{ {
float xpan, ypan, xscale, yscale, rotate; // Fetch ZDoom fields
int color, light; Vector2D offset = new Vector2D(s.Fields.GetValue("xpanningceiling", 0.0f),
bool absolute; s.Fields.GetValue("ypanningceiling", 0.0f));
Vector2D scale = new Vector2D(s.Fields.GetValue("xscaleceiling", 1.0f),
s.Fields.GetValue("yscaleceiling", 1.0f));
float rotate = s.Fields.GetValue("rotationceiling", 0.0f);
int color = s.Fields.GetValue("lightcolor", -1);
int light = s.Fields.GetValue("lightceiling", 0);
bool absolute = s.Fields.GetValue("lightceilingabsolute", false);
try
{
// Fetch ZDoom fields
xpan = s.Fields.ContainsKey("xpanningceiling") ? (float)s.Fields["xpanningceiling"].Value : 0.0f;
ypan = s.Fields.ContainsKey("ypanningceiling") ? (float)s.Fields["ypanningceiling"].Value : 0.0f;
xscale = s.Fields.ContainsKey("xscaleceiling") ? (float)s.Fields["xscaleceiling"].Value : 1.0f;
yscale = s.Fields.ContainsKey("yscaleceiling") ? (float)s.Fields["yscaleceiling"].Value : 1.0f;
rotate = s.Fields.ContainsKey("rotationceiling") ? (float)s.Fields["rotationceiling"].Value : 0.0f;
color = s.Fields.ContainsKey("lightcolor") ? (int)s.Fields["lightcolor"].Value : -1;
light = s.Fields.ContainsKey("lightceiling") ? (int)s.Fields["lightceiling"].Value : 0;
absolute = s.Fields.ContainsKey("lightceilingabsolute") ? (bool)s.Fields["lightceilingabsolute"].Value : false;
}
catch(Exception) { return; }
// Setup the vertices with the given settings // Setup the vertices with the given settings
SetupSurfaceVertices(vertices, s, img, xpan, ypan, xscale, yscale, rotate, color, light, absolute); SetupSurfaceVertices(vertices, s, img, offset, scale, rotate, color, light, absolute);
} }
} }
// This applies the given values on the vertices // This applies the given values on the vertices
private void SetupSurfaceVertices(FlatVertex[] vertices, Sector s, ImageData img, float xpan, float ypan, private void SetupSurfaceVertices(FlatVertex[] vertices, Sector s, ImageData img, Vector2D offset,
float xscale, float yscale, float rotate, int color, int light, bool absolute) Vector2D scale, float rotate, int color, int light, bool absolute)
{ {
// Prepare for math! // Prepare for math!
rotate = Angle2D.DegToRad(rotate); rotate = Angle2D.DegToRad(rotate);
Vector2D scale = new Vector2D(xscale, yscale);
Vector2D texscale = new Vector2D(1.0f / img.ScaledWidth, 1.0f / img.ScaledHeight); Vector2D texscale = new Vector2D(1.0f / img.ScaledWidth, 1.0f / img.ScaledHeight);
Vector2D offset = new Vector2D(xpan, ypan);
if(!absolute) light = s.Brightness + light; if(!absolute) light = s.Brightness + light;
PixelColor lightcolor = PixelColor.FromInt(color); PixelColor lightcolor = PixelColor.FromInt(color);
PixelColor brightness = PixelColor.FromInt(General.Map.Renderer2D.CalculateBrightness(light)); PixelColor brightness = PixelColor.FromInt(General.Map.Renderer2D.CalculateBrightness(light));

View file

@ -112,21 +112,11 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
else else
this.RenderPass = RenderPass.Solid; this.RenderPass = RenderPass.Solid;
} }
// From UDMF field else
else if(Sidedef.Line.Fields.ContainsKey("renderstyle") ||
Sidedef.Line.Fields.ContainsKey("alpha"))
{ {
string field = "translucent"; // From UDMF field
string field = Sidedef.Line.Fields.GetValue("renderstyle", "translucent");
if(Sidedef.Line.Fields.ContainsKey("renderstyle")) alpha = (byte)(Sidedef.Line.Fields.GetValue("alpha", 1.0f) * 255.0f);
field = Sidedef.Line.Fields["renderstyle"].Value.ToString();
if(Sidedef.Line.Fields.ContainsKey("alpha"))
{
float a;
if(float.TryParse(Sidedef.Line.Fields["alpha"].Value.ToString(), out a))
alpha = (byte)(a * 255.0f);
}
if(field == "add") if(field == "add")
this.RenderPass = RenderPass.Additive; this.RenderPass = RenderPass.Additive;

View file

@ -459,6 +459,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// Find sectors with 3 vertices, because they can be sloped // Find sectors with 3 vertices, because they can be sloped
foreach(Sector s in General.Map.Map.Sectors) foreach(Sector s in General.Map.Map.Sectors)
{ {
// ========== Thing vertex slope ==========
if(s.Sidedefs.Count == 3) if(s.Sidedefs.Count == 3)
{ {
List<Thing> slopeceilingthings = new List<Thing>(3); List<Thing> slopeceilingthings = new List<Thing>(3);

View file

@ -189,12 +189,8 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
CropPoly(ref poly, osd.Floor.plane, true); CropPoly(ref poly, osd.Floor.plane, true);
// Determine if we should repeat the middle texture // Determine if we should repeat the middle texture
repeatmidtex = false;
if(Sidedef.Fields.ContainsKey("wrapmidtex")) if(Sidedef.Fields.ContainsKey("wrapmidtex"))
{ repeatmidtex = Sidedef.Fields.GetValue("wrapmidtex", false);
if(Sidedef.Fields["wrapmidtex"].Value is bool)
repeatmidtex = (bool)Sidedef.Fields["wrapmidtex"].Value;
}
else else
repeatmidtex = Sidedef.Line.IsFlagSet("wrapmidtex"); repeatmidtex = Sidedef.Line.IsFlagSet("wrapmidtex");