Some undo/redo system optimizations in Visual Mode

This commit is contained in:
codeimp 2009-06-16 08:49:14 +00:00
parent c4c9ea94c1
commit 656edc7f13
3 changed files with 92 additions and 22 deletions

View file

@ -119,6 +119,7 @@ namespace CodeImp.DoomBuilder.Map
this.ceiltexname = "-";
this.longfloortexname = MapSet.EmptyLongName;
this.longceiltexname = MapSet.EmptyLongName;
this.updateneeded = true;
this.triangulationneeded = true;
this.surfaceentry = new SurfaceEntry(-1, -1, -1);
@ -204,11 +205,8 @@ namespace CodeImp.DoomBuilder.Map
internal void PostDeserialize(MapSet map)
{
triangles.PostDeserialize(map);
// We need to rebuild the vertex buffer,
// but the triangulation was deserialized
updateneeded = true;
triangulationneeded = false;
triangulationneeded = true;
}
// This copies all properties to another sector

View file

@ -291,7 +291,7 @@ namespace CodeImp.DoomBuilder.VisualModes
#region ================== Visibility Culling
// This preforms visibility culling
private void DoCulling()
protected void DoCulling()
{
Dictionary<Linedef, Linedef> visiblelines = new Dictionary<Linedef, Linedef>(200);
Vector2D campos2d = (Vector2D)General.Map.VisualCamera.Position;
@ -634,12 +634,7 @@ namespace CodeImp.DoomBuilder.VisualModes
visiblethings.Clear();
// Make new blockmap
if(blockmap != null)
{
blockmap.Dispose();
blockmap = new VisualBlockMap();
FillBlockMap();
}
FillBlockMap();
// Visibility culling (this re-creates the needed resources)
DoCulling();
@ -701,8 +696,6 @@ namespace CodeImp.DoomBuilder.VisualModes
newsectors.Add(vs.Key, vs.Value);
}
General.WriteLogLine("VisualSectors disposed: " + counter);
// Things depend on the sector they are in and because we can't
// easily determine which ones changed, we dispose all things
foreach(KeyValuePair<Thing, VisualThing> vt in allthings)
@ -719,17 +712,12 @@ namespace CodeImp.DoomBuilder.VisualModes
visiblethings.Clear();
// Make new blockmap
if(blockmap != null)
{
blockmap.Dispose();
blockmap = new VisualBlockMap();
FillBlockMap();
}
FillBlockMap();
// Visibility culling (this re-creates the needed resources)
DoCulling();
}
/// <summary>
/// Implement this to create an instance of your VisualSector implementation.
/// </summary>
@ -767,6 +755,9 @@ namespace CodeImp.DoomBuilder.VisualModes
/// </summary>
protected virtual void FillBlockMap()
{
if(blockmap != null) blockmap.Dispose();
blockmap = new VisualBlockMap();
blockmap.AddLinedefsSet(General.Map.Map.Linedefs);
blockmap.AddThingsSet(General.Map.Map.Things);
blockmap.AddSectorsSet(General.Map.Map.Sectors);

View file

@ -512,10 +512,91 @@ namespace CodeImp.DoomBuilder.BuilderModes
PickTarget();
}
// After resources were partially reloaded
// This usually happens when geometry is changed by undo, redo, cut or paste actions
// and uses the marks to check what needs to be reloaded.
protected override void ResourcesReloadedPartial()
{
base.ResourcesReloadedPartial();
// Detect geometry changes. When linedefs and/or vertices are marked, this means
// that the shape of sectors has changed. In that case we must rebuild the sectors entirely.
bool geometrychanges = false;
bool sectorsmarked = false;
foreach(Linedef ld in General.Map.Map.Linedefs)
if(ld.Marked) geometrychanges = true;
foreach(Vertex v in General.Map.Map.Vertices)
if(v.Marked) geometrychanges = true;
if(geometrychanges)
{
// Let the core do this (it will just dispose the sectors that were changed)
base.ResourcesReloadedPartial();
}
else
{
// Neighbour sectors must be updated as well
foreach(Sector s in General.Map.Map.Sectors)
{
if(s.Marked)
{
sectorsmarked = true;
foreach(Sidedef sd in s.Sidedefs)
if(sd.Other != null) sd.Other.Marked = true;
}
}
// Go for all sidedefs to update
foreach(Sidedef sd in General.Map.Map.Sidedefs)
{
if(sd.Marked)
{
BaseVisualSector vs = (BaseVisualSector)GetVisualSector(sd.Sector);
VisualSidedefParts parts = vs.GetSidedefParts(sd);
parts.SetupAllParts();
}
}
// Go for all sectors to update
foreach(Sector s in General.Map.Map.Sectors)
{
if(s.Marked)
{
BaseVisualSector vs = (BaseVisualSector)GetVisualSector(s);
vs.Floor.Setup();
vs.Ceiling.Setup();
}
}
if(!sectorsmarked)
{
// No sectors or geometry changed. So we only have
// to update things when they have changed.
foreach(KeyValuePair<Thing, VisualThing> vt in allthings)
if(vt.Key.Marked) vt.Value.Update();
}
else
{
// Things depend on the sector they are in and because we can't
// easily determine which ones changed, we dispose all things
foreach(KeyValuePair<Thing, VisualThing> vt in allthings)
vt.Value.Dispose();
}
// Apply new lists
allthings = new Dictionary<Thing, VisualThing>(allthings.Count);
// Clear visibility collections
visiblesectors.Clear();
visibleblocks.Clear();
visiblegeometry.Clear();
visiblethings.Clear();
// Make new blockmap
FillBlockMap();
// Visibility culling (this re-creates the needed resources)
DoCulling();
}
// Determine what we're aiming at now
PickTarget();
}