Merge anotak's optimizations - stage 1

This commit is contained in:
ZZYZX 2017-02-08 14:18:01 +02:00
parent 34d1af9446
commit 09b8c27dab
19 changed files with 918 additions and 808 deletions

View file

@ -220,14 +220,21 @@ namespace CodeImp.DoomBuilder.Actions
// Go for all methods on obj
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
foreach(MethodInfo m in methods)
//foreach(MethodInfo m in methods)
int methodsCount = methods.Length;
for (int i = 0; i < methodsCount; i++)
{
MethodInfo m = methods[i];
// Check if the method has this attribute
ActionAttribute[] attrs = (ActionAttribute[])m.GetCustomAttributes(typeof(BeginActionAttribute), true);
ActionAttribute[] attrs = (ActionAttribute[])methods[i].GetCustomAttributes(typeof(BeginActionAttribute), true);
int attrsCount = attrs.Length;
// Go for all attributes
foreach(ActionAttribute a in attrs)
//foreach(ActionAttribute a in attrs)
for (int j = 0; j < attrsCount; j++)
{
ActionAttribute a = attrs[j];
// Create a delegate for this method
ActionDelegate del = (ActionDelegate)Delegate.CreateDelegate(typeof(ActionDelegate), obj, m);
@ -243,10 +250,13 @@ namespace CodeImp.DoomBuilder.Actions
// Check if the method has this attribute
attrs = (ActionAttribute[])m.GetCustomAttributes(typeof(EndActionAttribute), true);
attrsCount = attrs.Length;
// Go for all attributes
foreach(ActionAttribute a in attrs)
//foreach (ActionAttribute a in attrs)
for (int j = 0; j < attrsCount; j++)
{
ActionAttribute a = attrs[j];
// Create a delegate for this method
ActionDelegate del = (ActionDelegate)Delegate.CreateDelegate(typeof(ActionDelegate), obj, m);
@ -312,14 +322,20 @@ namespace CodeImp.DoomBuilder.Actions
// Go for all methods on obj
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
foreach(MethodInfo m in methods)
//foreach (MethodInfo m in methods)
int methodsCount = methods.Length;
for(int i = 0; i < methodsCount; i++)
{
MethodInfo m = methods[i];
// Check if the method has this attribute
ActionAttribute[] attrs = (ActionAttribute[])m.GetCustomAttributes(typeof(BeginActionAttribute), true);
// Go for all attributes
foreach(ActionAttribute a in attrs)
//foreach (ActionAttribute a in attrs)
int attrsCount = attrs.Length;
for(int j = 0; j < attrsCount; j++)
{
ActionAttribute a = attrs[j];
// Create a delegate for this method
ActionDelegate del = (ActionDelegate)Delegate.CreateDelegate(typeof(ActionDelegate), obj, m);
@ -334,8 +350,11 @@ namespace CodeImp.DoomBuilder.Actions
attrs = (ActionAttribute[])m.GetCustomAttributes(typeof(EndActionAttribute), true);
// Go for all attributes
foreach(ActionAttribute a in attrs)
//foreach (ActionAttribute a in attrs)
attrsCount = attrs.Length;
for (int j = 0; j < attrsCount; j++)
{
ActionAttribute a = attrs[j];
// Create a delegate for this method
ActionDelegate del = (ActionDelegate)Delegate.CreateDelegate(typeof(ActionDelegate), obj, m);

View file

@ -53,11 +53,21 @@ namespace CodeImp.DoomBuilder.Controls
{
InitializeComponent();
Reset();
}
#endregion
#region ================== Setup
public void Reset()
{
// Only when running (this.DesignMode won't do when not this, but one of parent controls is in design mode)
if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
{
//mxd. Setup script numbers
scriptnumbers.Location = new Point(arg0.Location.X, arg0.Location.Y + 2);
scriptnumbers.Items.Clear();
foreach (ScriptItem si in General.Map.NumberedScripts.Values)
scriptnumbers.Items.Add(new ColoredComboBoxItem(si, si.IsInclude ? SystemColors.HotTrack : SystemColors.WindowText));
scriptnumbers.DropDownWidth = Tools.GetDropDownWidth(scriptnumbers);
@ -65,6 +75,7 @@ namespace CodeImp.DoomBuilder.Controls
//mxd. Setup script names
if (General.Map.UDMF)
{
scriptnames.Items.Clear();
scriptnames.Location = scriptnumbers.Location;
foreach (ScriptItem nsi in General.Map.NamedScripts.Values)
scriptnames.Items.Add(new ColoredComboBoxItem(nsi, nsi.IsInclude ? SystemColors.HotTrack : SystemColors.WindowText));
@ -78,10 +89,6 @@ namespace CodeImp.DoomBuilder.Controls
}
}
#endregion
#region ================== Setup
public void SetValue(Linedef l, bool first)
{
SetValue(l.Fields, l.Args, first);

View file

@ -585,7 +585,7 @@ namespace CodeImp.DoomBuilder.Controls
// Show the whole thing
this.Show();
this.Update();
//this.Update(); // ano - don't think this is needed, and is slow
}
private static void UpdateTexturePanel(Panel panel, string texturename, Label texturenamelabel, Label sizelabel, int maxlabelright, Panel image, int sizeref, bool extendedinfoshown, bool required)

View file

@ -369,7 +369,7 @@ namespace CodeImp.DoomBuilder.Controls
// Show the whole thing
this.Show();
this.Update();
//this.Update(); // ano - don't think this is needed, and is slow
}
//mxd

View file

@ -41,12 +41,7 @@ namespace CodeImp.DoomBuilder.Controls
public TagsSelector()
{
InitializeComponent();
tagspermapelement = new List<List<int>>();
usedtags = new List<int>();
rangemodes = new List<int>();
offsetmodes = new List<int>();
infos = new List<TagInfo>();
Reset();
}
#endregion
@ -154,7 +149,6 @@ namespace CodeImp.DoomBuilder.Controls
else
infos.Add(new TagInfo(tag, string.Empty));
}
foreach(TagInfo info in infos) tagpicker.Items.Add(info);
tagpicker.DropDownWidth = DoomBuilder.Geometry.Tools.GetDropDownWidth(tagpicker);
}
@ -219,6 +213,18 @@ namespace CodeImp.DoomBuilder.Controls
#endregion
#region ================== Methods
public void Reset()
{
tagspermapelement = new List<List<int>>();
usedtags = new List<int>();
rangemodes = new List<int>();
offsetmodes = new List<int>();
infos = new List<TagInfo>();
tagslist.Links.Clear();
infos.Clear();
tagpicker.Items.Clear();
usedtags.Clear();
}
// Creates a single tag collection to display. int.MinValue means "mixed tag"
private List<int> GetDisplayTags()

View file

@ -240,7 +240,7 @@ namespace CodeImp.DoomBuilder.Controls
// Show the whole thing
this.Show();
this.Update();
//this.Update(); // ano - don't think this is needed, and is slow
}
//mxd

View file

@ -58,7 +58,7 @@ namespace CodeImp.DoomBuilder.Controls
// Show the whole thing
this.Show();
this.Update();
//this.Update(); // ano - don't think this is needed, and is slow
}
}
}

View file

@ -986,6 +986,7 @@ namespace CodeImp.DoomBuilder.Map
// Limit intersection offset to the line
if(bounded) if(u < lengthinv) u = lengthinv; else if(u > (1f - lengthinv)) u = 1f - lengthinv;
/*
// Calculate intersection point
Vector2D i = v1 + u * (v2 - v1);
@ -993,6 +994,12 @@ namespace CodeImp.DoomBuilder.Map
// which is the shortest distance to the line
float ldx = p.x - i.x;
float ldy = p.y - i.y;
*/
// ano - let's check to see if we can do the previous faster without using operator overloading and etc
// the answer: running it int.MaxValue / 64 times it tended to be around 100ms faster
float ldx = p.x - (v1.x + u * (v2.x - v1.x));
float ldy = p.y - (v1.y + u * (v2.y - v1.y));
return ldx * ldx + ldy * ldy;
}

View file

@ -2194,12 +2194,16 @@ namespace CodeImp.DoomBuilder.Map
//DebugConsole.Clear();
//DebugConsole.WriteLine("CorrectSectorReferences for " + lines.Count + " lines");
// ano - set a bunch of foreaches to be for()s because they're faster
// Create a list of sidedefs to perform sector creation with
List<LinedefSide> edges = new List<LinedefSide>();
if(existing_only)
{
foreach(Linedef l in lines)
int lineCount = lines.Count;
for(int i = 0; i < lineCount; i++)
{
Linedef l = lines[i];
// Add only existing sides as edges (or front side if line has none)
if(l.Front != null || l.Back == null)
edges.Add(new LinedefSide(l, true));
@ -2209,8 +2213,10 @@ namespace CodeImp.DoomBuilder.Map
}
else
{
foreach(Linedef l in lines)
int lineCount = lines.Count;
for (int i = 0; i < lineCount; i++)
{
Linedef l = lines[i];
// Add front side
edges.Add(new LinedefSide(l, true));
@ -2221,8 +2227,10 @@ namespace CodeImp.DoomBuilder.Map
}
HashSet<Sidedef> sides_correct = new HashSet<Sidedef>();
foreach(LinedefSide ls in edges)
int edgeCount = edges.Count;
for (int i = 0; i < edgeCount; i++)
{
LinedefSide ls = edges[i];
if (ls.Front && ls.Line.Front != null)
sides_correct.Add(ls.Line.Front);
else if(!ls.Front && ls.Line.Back != null)
@ -2241,8 +2249,9 @@ namespace CodeImp.DoomBuilder.Map
SectorBuilder builder = new SectorBuilder();
List<Sector> sectors_reused = new List<Sector>();
foreach(LinedefSide ls in edges)
for (int i = 0; i < edgeCount; i++)
{
LinedefSide ls = edges[i];
// Skip if edge is ignored
//DebugConsole.WriteLine((ls.Ignore ? "Ignoring line " : "Processing line ") + ls.Line.Index);
if (ls.Ignore) continue;
@ -2263,8 +2272,9 @@ namespace CodeImp.DoomBuilder.Map
if(side_exists && sectorsides.Contains(edge.Front ? edge.Line.Front : edge.Line.Back))
has_dragged_sides = true; //mxd
foreach(LinedefSide ls2 in edges)
for (int k = 0; k < edgeCount; k++)
{
LinedefSide ls2 = edges[k];
if (ls2.Line == edge.Line)
{
line_is_ours = true;
@ -2276,12 +2286,16 @@ namespace CodeImp.DoomBuilder.Map
}
}
if(line_is_ours)
// ano - so this inner part was already commented out
// so i just put the /* */ around it
/*if(line_is_ours)
{
//if(edge.Line.Front == null && edge.Line.Back == null)
//has_zero_sided_lines = true;
}
else
else*/
if(!line_is_ours)
{
has_existing_lines = true;
has_existing_sides |= side_exists; //mxd
@ -2331,8 +2345,9 @@ namespace CodeImp.DoomBuilder.Map
}
// Remove any sides that weren't part of a sector
foreach(LinedefSide ls in edges)
for (int i = 0; i < edgeCount; i++)
{
LinedefSide ls = edges[i];
if (ls.Ignore || ls.Line == null) continue;
if(ls.Front)

View file

@ -30,6 +30,6 @@ using CodeImp.DoomBuilder;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.3.0.2859")]
[assembly: AssemblyVersion("2.3.0.2866")]
[assembly: NeutralResourcesLanguageAttribute("en")]
[assembly: AssemblyHash("5a5c6d0")]
[assembly: AssemblyHash("34d1af9")]

View file

@ -94,6 +94,11 @@ namespace CodeImp.DoomBuilder.Rendering
// Disposing
private bool isdisposed;
// ano - static stuff to prevent often alloc/dealloc performance hits
private static StringFormat strFormat;
private static SolidBrush brush;
private static Pen pen;
#endregion
#region ================== Properties
@ -157,6 +162,8 @@ namespace CodeImp.DoomBuilder.Rendering
this.updateneeded = true;
this.textureupdateneeded = true; //mxd
InitializeStatics();
// Register as resource
General.Map.Graphics.RegisterResource(this);
@ -181,6 +188,8 @@ namespace CodeImp.DoomBuilder.Rendering
this.updateneeded = true;
this.textureupdateneeded = true;
InitializeStatics();
// Register as resource
General.Map.Graphics.RegisterResource(this);
@ -210,6 +219,27 @@ namespace CodeImp.DoomBuilder.Rendering
#region ================== Methods
// ano - share resources instead of constantly alloc/dealloc
public void InitializeStatics()
{
if (strFormat == null)
{
strFormat = new StringFormat();
strFormat.FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap;
strFormat.Alignment = StringAlignment.Center;
strFormat.LineAlignment = StringAlignment.Center;
}
if (brush == null)
{
// if we actually see magenta, know we made a mistake somewhere
brush = new SolidBrush(System.Drawing.Color.Magenta);
}
if (pen == null)
{
pen = new Pen(System.Drawing.Color.Magenta);
}
}
// This updates the text if needed
public void Update(float translatex, float translatey, float scalex, float scaley)
{
@ -354,12 +384,6 @@ namespace CodeImp.DoomBuilder.Rendering
g.CompositingQuality = CompositingQuality.HighQuality;
// Draw text
using(StringFormat sf = new StringFormat())
{
sf.FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap;
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
// Draw text with BG
if(drawbg)
{
@ -388,16 +412,19 @@ namespace CodeImp.DoomBuilder.Rendering
p.AddArc(pathrect.Left, pathrect.Bottom - radius, radius, radius, 90, 90);
// Fill'n'draw bg
using(SolidBrush brush = new SolidBrush(color.ToColor()))
brush.Color = color.ToColor();
g.FillPath(brush, p);
using(Pen pen = new Pen(backcolor.ToColor(), outlinewidth))
pen.Color = backcolor.ToColor();
g.DrawPath(pen, p);
// Draw text
textrect.Inflate(4, 2);
using(SolidBrush brush = new SolidBrush(backcolor.ToColor()))
g.DrawString(text, font, brush, textrect, sf);
brush.Color = backcolor.ToColor();
g.DrawString(text, font, brush, textrect, strFormat);
}
// Draw plain text
else
@ -408,13 +435,13 @@ namespace CodeImp.DoomBuilder.Rendering
RectangleF plaintextrect = textrect;
plaintextrect.Inflate(6, 4);
using(SolidBrush brush = new SolidBrush(backcolor.ToColor()))
brush.Color = backcolor.ToColor();
g.FillRectangle(brush, plainbgrect);
using(SolidBrush brush = new SolidBrush(color.ToColor()))
g.DrawString(text, font, brush, plaintextrect, sf);
}
brush.Color = color.ToColor();
g.DrawString(text, font, brush, plaintextrect, strFormat);
}
}
return result;

View file

@ -152,6 +152,8 @@ namespace CodeImp.DoomBuilder.Windows
{
preventchanges = true;
argscontrol.Reset();
undocreated = false;
// Keep this list
this.lines = lines;
if(lines.Count > 1) this.Text = "Edit Linedefs (" + lines.Count + ")";

View file

@ -245,10 +245,27 @@ namespace CodeImp.DoomBuilder.Windows
// This sets up the form to edit the given lines
public void Setup(ICollection<Linedef> lines)
{
// Window setup
// ano - moved this here because we don't reinstantiate the thing every time anymore
if (General.Settings.StoreSelectedEditTab)
{
int activetab = General.Settings.ReadSetting("windows." + configname + ".activetab", 0);
// When front or back tab was previously selected, switch to appropriate side (selectfront/selectback are set in BaseVisualGeometrySidedef.OnEditEnd)
if ((selectfront || selectback) && (activetab == 1 || activetab == 2))
tabs.SelectTab(selectfront ? 1 : 2);
else
tabs.SelectTab(activetab);
}
preventchanges = true;
undocreated = false;
argscontrol.Reset();
tagsselector.Reset();
// Keep this list
this.lines = lines;
if(lines.Count > 1) this.Text = "Edit Linedefs (" + lines.Count + ")";
linedefprops = new List<LinedefProperties>();

View file

@ -850,7 +850,7 @@ namespace CodeImp.DoomBuilder.Windows
// Refresh
statusbar.Invalidate();
this.Update();
//this.Update(); // ano - this is unneeded afaict and slow
}
// This changes status text to Ready
@ -2116,18 +2116,21 @@ namespace CodeImp.DoomBuilder.Windows
internal void CheckEditModeButton(string modeclassname)
{
// Go for all items
foreach(ToolStripItem i in editmodeitems)
//foreach(ToolStripItem item in editmodeitems)
int itemCount = editmodeitems.Count;
for(int i = 0; i < itemCount; i++)
{
ToolStripItem item = editmodeitems[i];
// Check what type it is
if(i is ToolStripMenuItem)
if(item is ToolStripMenuItem)
{
// Check if mode type matches with given name
(i as ToolStripMenuItem).Checked = ((i.Tag as EditModeInfo).Type.Name == modeclassname);
(item as ToolStripMenuItem).Checked = ((item.Tag as EditModeInfo).Type.Name == modeclassname);
}
else if(i is ToolStripButton)
else if(item is ToolStripButton)
{
// Check if mode type matches with given name
(i as ToolStripButton).Checked = ((i.Tag as EditModeInfo).Type.Name == modeclassname);
(item as ToolStripButton).Checked = ((item.Tag as EditModeInfo).Type.Name == modeclassname);
}
}
}
@ -2136,11 +2139,14 @@ namespace CodeImp.DoomBuilder.Windows
internal void RemoveEditModeButtons()
{
// Go for all items
foreach(ToolStripItem i in editmodeitems)
//foreach(ToolStripItem item in editmodeitems)
int itemCount = editmodeitems.Count;
for (int i = 0; i < itemCount; i++)
{
ToolStripItem item = editmodeitems[i];
// Remove it and restart
menumode.DropDownItems.Remove(i);
i.Dispose();
menumode.DropDownItems.Remove(item);
item.Dispose();
}
// Done

View file

@ -90,7 +90,7 @@ namespace CodeImp.DoomBuilder.Windows
public void Setup(ICollection<Sector> sectors)
{
preventchanges = true; //mxd
undocreated = false;
// Keep this list
this.sectors = sectors;
if(sectors.Count > 1) this.Text = "Edit Sectors (" + sectors.Count + ")";

View file

@ -292,7 +292,7 @@ namespace CodeImp.DoomBuilder.Windows
public void Setup(ICollection<Sector> sectors)
{
preventchanges = true; //mxd
undocreated = false;
// Keep this list
this.sectors = sectors;
if(sectors.Count > 1) this.Text = "Edit Sectors (" + sectors.Count + ")";

View file

@ -141,6 +141,8 @@ namespace CodeImp.DoomBuilder.Windows
public void Setup(ICollection<Thing> things)
{
preventchanges = true;
undocreated = false;
argscontrol.Reset();
// Keep this list
this.things = things;

View file

@ -164,6 +164,8 @@ namespace CodeImp.DoomBuilder.Windows
public void Setup(ICollection<Thing> things)
{
preventchanges = true;
undocreated = false;
argscontrol.Reset();
// Keep this list
this.things = things;

View file

@ -29,5 +29,5 @@ using System.Resources;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.3.0.2859")]
[assembly: AssemblyVersion("2.3.0.2866")]
[assembly: NeutralResourcesLanguageAttribute("en")]