Linedefs Mode, Sectors Mode, Vertices Mode, Sound Environment Mode, Sound Propagation Mode: slightly improved performance when moving the mouse

This commit is contained in:
biwa 2020-10-31 16:09:22 +01:00 committed by spherallic
parent f097fec1a2
commit 5884ca770e
3 changed files with 87 additions and 13 deletions

View file

@ -69,7 +69,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Interface
private bool editpressed;
private bool selectionfromhighlight; //mxd
// The blockmap makes is used to make finding lines faster
BlockMap<BlockEntry> blockmap;
#endregion
#region ================== Properties
@ -576,9 +579,20 @@ namespace CodeImp.DoomBuilder.BuilderModes
labels.Add(linedef, l);
}
}
/// <summary>
/// Create a blockmap containing linedefs. This is used to speed up determining the closest line
/// to the mouse cursor
/// </summary>
private void CreateBlockmap()
{
RectangleF area = MapSet.CreateArea(General.Map.Map.Vertices);
blockmap = new BlockMap<BlockEntry>(area);
blockmap.AddLinedefsSet(General.Map.Map.Linedefs);
}
#endregion
#region ================== Events
public override void OnHelp()
@ -630,6 +644,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
BuilderPlug.Me.MenusForm.SyncronizeThingEditButton.ToolTipText = "Synchronized Things Editing" + Environment.NewLine + BuilderPlug.Me.MenusForm.SyncronizeThingEditLinedefsItem.ToolTipText;
General.Interface.EndToolbarUpdate(); //mxd
// Create the blockmap
CreateBlockmap();
// Convert geometry selection to linedefs selection
General.Map.Map.ConvertSelection(SelectionType.Linedefs);
UpdateSelectionInfo(); //mxd
@ -956,6 +973,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
base.OnUndoEnd();
// Recreate the blockmap to not include the potentially un-done lines anymore
CreateBlockmap();
// Update selection info and labels
UpdateSelectionInfo();
SetupSectorLabels();
@ -966,6 +986,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
base.OnRedoEnd();
// Recreate the blockmap to include the potentially re-done linedefs again
CreateBlockmap();
// Update selection info and labels
UpdateSelectionInfo();
SetupSectorLabels();
@ -992,7 +1015,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
else if(paintselectpressed && !editpressed && !selecting) //mxd. Drag-select
{
// Find the nearest thing within highlight range
Linedef l = General.Map.Map.NearestLinedefRange(mousemappos, BuilderPlug.Me.HighlightRange / renderer.Scale);
Linedef l = MapSet.NearestLinedefRange(blockmap, mousemappos, BuilderPlug.Me.HighlightRange / renderer.Scale);
if(l != null)
{
@ -1024,11 +1047,11 @@ namespace CodeImp.DoomBuilder.BuilderModes
else if(e.Button == MouseButtons.None) // Not holding any buttons?
{
// Find the nearest linedef within highlight range
Linedef l = General.Map.Map.NearestLinedefRange(mousemappos, BuilderPlug.Me.HighlightRange / renderer.Scale);
Linedef l = MapSet.NearestLinedefRange(blockmap, mousemappos, BuilderPlug.Me.HighlightRange / renderer.Scale);
//mxd. Render insert vertex preview
Linedef sl = General.Map.Map.NearestLinedefRange(mousemappos, BuilderPlug.Me.StitchRange / renderer.Scale);
if(sl != null)
Linedef sl = MapSet.NearestLinedefRange(blockmap, mousemappos, BuilderPlug.Me.StitchRange / renderer.Scale);
if (sl != null)
{
bool snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid;
bool snaptonearest = General.Interface.CtrlState ^ General.Interface.AutoMerge;
@ -1523,6 +1546,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Map.IsChanged = true;
General.Map.Map.Update();
// Recreate the blockmap since it shouldn't include the deleted linedefs anymore
CreateBlockmap();
// Redraw screen
SetupSectorLabels(); //mxd
UpdateSelectionInfo(); //mxd
@ -1609,7 +1635,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Update cache values
General.Map.IsChanged = true;
General.Map.Map.Update();
// Recreate the blockmap since it shouldn't include the dissolved linedefs anymore
CreateBlockmap();
// Redraw screen
SetupSectorLabels(); //mxd
UpdateSelectionInfo(); //mxd

View file

@ -74,6 +74,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// The blockmap makes synchronized editing faster
BlockMap<BlockEntry> blockmap;
bool addedlinedefstoblockmap;
#endregion
@ -692,6 +693,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
blockmap = new BlockMap<BlockEntry>(area);
blockmap.AddSectorsSet(General.Map.Map.Sectors);
blockmap.AddThingsSet(General.Map.Map.Things);
// Don't add linedefs here. They are only needed for paint select, so let's save some
// time (and add them when paint select is used t he first time)
addedlinedefstoblockmap = false;
}
#endregion
@ -1093,8 +1098,15 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
else if(paintselectpressed && !editpressed && !selecting) //mxd. Drag-select
{
// If linedefs were not added to the blockmap yet add them here
if (!addedlinedefstoblockmap)
{
blockmap.AddLinedefsSet(General.Map.Map.Linedefs);
addedlinedefstoblockmap = true;
}
// Find the nearest linedef within highlight range
Linedef l = General.Map.Map.NearestLinedefRange(mousemappos, BuilderPlug.Me.HighlightRange / renderer.Scale);
Linedef l = MapSet.NearestLinedefRange(blockmap, mousemappos, BuilderPlug.Me.HighlightRange / renderer.Scale);
Sector s = null;
if(l != null)

View file

@ -56,6 +56,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
private bool editpressed;
private bool selectionfromhighlight; //mxd
// The blockmap makes is used to make finding lines faster
BlockMap<BlockEntry> blockmap;
#endregion
#region ================== Properties
@ -70,6 +73,17 @@ namespace CodeImp.DoomBuilder.BuilderModes
#region ================== Methods
/// <summary>
/// Create a blockmap containing linedefs. This is used to speed up determining the closest line
/// to the mouse cursor
/// </summary>
private void CreateBlockmap()
{
RectangleF area = MapSet.CreateArea(General.Map.Map.Vertices);
blockmap = new BlockMap<BlockEntry>(area);
blockmap.AddLinedefsSet(General.Map.Map.Linedefs);
}
public override void OnHelp()
{
General.ShowHelp("e_vertices.html");
@ -107,6 +121,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Interface.AddButton(BuilderPlug.Me.MenusForm.PerpendicularLinedef); //JBR
General.Interface.AddButton(BuilderPlug.Me.MenusForm.ParallelLinedef); //JBR
// Create the blockmap
CreateBlockmap();
// Convert geometry selection to vertices only
General.Map.Map.ConvertSelection(SelectionType.Vertices);
UpdateSelectionInfo(); //mxd
@ -304,7 +321,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
else if(!selecting) //mxd. We don't want to do this stuff while multiselecting
{
// Find the nearest linedef within highlight range
Linedef l = General.Map.Map.NearestLinedefRange(mousemappos, BuilderPlug.Me.SplitLinedefsRange / renderer.Scale);
Linedef l = MapSet.NearestLinedefRange(blockmap, mousemappos, BuilderPlug.Me.SplitLinedefsRange / renderer.Scale);
if(l != null)
{
// Create undo
@ -481,7 +498,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
else if(e.Button == MouseButtons.None) // Not holding any buttons?
{
//mxd. Render insert vertex preview
Linedef l = General.Map.Map.NearestLinedefRange(mousemappos, BuilderPlug.Me.SplitLinedefsRange / renderer.Scale);
Linedef l = MapSet.NearestLinedefRange(blockmap, mousemappos, BuilderPlug.Me.SplitLinedefsRange / renderer.Scale);
if(l != null)
{
@ -555,6 +572,22 @@ namespace CodeImp.DoomBuilder.BuilderModes
Highlight(null);
}
public override void OnUndoEnd()
{
base.OnUndoEnd();
// Recreate the blockmap
CreateBlockmap();
}
public override void OnRedoEnd()
{
base.OnRedoEnd();
// Recreate the blockmap
CreateBlockmap();
}
//mxd
protected override void BeginViewPan()
{
@ -851,7 +884,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Map.UndoRedo.CreateUndo("Insert vertex");
// Snap to geometry?
Linedef l = General.Map.Map.NearestLinedefRange(mousemappos, BuilderPlug.Me.SplitLinedefsRange / renderer.Scale);
Linedef l = MapSet.NearestLinedefRange(blockmap, mousemappos, BuilderPlug.Me.SplitLinedefsRange / renderer.Scale);
if(snaptonearest && (l != null))
{
// Snip to grid also?
@ -912,7 +945,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
if(snaptonearest)
{
//mxd. Check if snapped vertex is still on top of a linedef
l = General.Map.Map.NearestLinedefRange(v.Position, BuilderPlug.Me.SplitLinedefsRange / renderer.Scale);
l = MapSet.NearestLinedefRange(blockmap, v.Position, BuilderPlug.Me.SplitLinedefsRange / renderer.Scale);
if(l != null)
{