- Added sector ceilings/floors flood-fill feature

- Fixed a bug in Visual Mode with undo/redo and texture not loading
This commit is contained in:
codeimp 2009-02-22 12:09:58 +00:00
parent dcce76ac77
commit e5784213ec
4 changed files with 109 additions and 3 deletions

View file

@ -597,9 +597,9 @@ placevisualstart
floodfilltextures
{
title = "Flood Fill Textures";
title = "Paste Texture Flood-Fill";
category = "visual";
description = "This allows you to select a texture and flood-fill all adjacent textures that are identical to the original with the selected texture.";
description = "This allows you to flood-fill all adjacent textures or flats that are identical to the original with the copied texture.";
allowkeys = true;
allowmouse = true;
allowscroll = true;

View file

@ -128,7 +128,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
public virtual void OnCopyTextureOffsets() { }
public virtual void OnPasteTextureOffsets() { }
protected virtual void SetTexture(string texturename) { }
public virtual void OnTextureFloodfill() { }
// Processing
public virtual void OnProcess(double deltatime)
@ -147,6 +146,53 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
}
}
// Flood-fill textures
public virtual void OnTextureFloodfill()
{
if(BuilderPlug.Me.CopiedFlat != null)
{
string oldtexture = GetTextureName();
long oldtexturelong = Lump.MakeLongName(oldtexture);
string newtexture = BuilderPlug.Me.CopiedFlat;
if(newtexture != oldtexture)
{
General.Map.UndoRedo.CreateUndo("Flood-fill flats with " + newtexture);
mode.Renderer.SetCrosshairBusy(true);
General.Interface.RedrawDisplay();
// Get the texture
ImageData newtextureimage = General.Map.Data.GetFlatImage(newtexture);
if(newtextureimage != null)
{
bool fillceilings = (this is VisualCeiling);
// Do the fill
Tools.FloodfillFlats(this.Sector.Sector, fillceilings, oldtexturelong, newtextureimage, true);
// Get the changed sectors
List<Sector> changes = General.Map.Map.GetMarkedSectors(true);
foreach(Sector s in changes)
{
// Update the visual sector
if(mode.VisualSectorExists(s))
{
BaseVisualSector vs = (mode.GetVisualSector(s) as BaseVisualSector);
if(fillceilings)
vs.Ceiling.Setup();
else
vs.Floor.Setup();
}
}
General.Map.Data.UpdateUsedTextures();
mode.Renderer.SetCrosshairBusy(false);
mode.ShowTargetInfo();
}
}
}
}
// Copy properties
public virtual void OnCopyProperties()

View file

@ -1286,6 +1286,61 @@ namespace CodeImp.DoomBuilder.Geometry
#endregion
#region ================== Flat Floodfill
// This performs flat floodfill over sector floors or ceilings that match with the same flat
// NOTE: This method uses the sectors marking to indicate which sides have been filled
// When resetsectormarks is set to true, all sectors will first be marked false (not aligned).
// Setting resetsectormarks to false is usefull to fill only within a specific selection
// (set the marked property to true for the sectors outside the selection)
public static void FloodfillFlats(Sector start, bool fillceilings, long originalflat, ImageData fillflat, bool resetsectormarks)
{
Stack<Sector> todo = new Stack<Sector>(50);
// Mark all sectors false (they will be marked true when the flat is modified)
if(resetsectormarks) General.Map.Map.ClearMarkedSectors(false);
// Begin with first sector
if(((start.LongFloorTexture == originalflat) && !fillceilings) ||
((start.LongCeilTexture == originalflat) && fillceilings))
{
todo.Push(start);
}
// Continue until nothing more to align
while(todo.Count > 0)
{
// Get the sector to do
Sector s = todo.Pop();
// Apply new flat
if(fillceilings)
s.SetCeilTexture(fillflat.Name);
else
s.SetFloorTexture(fillflat.Name);
s.Marked = true;
// Go for all sidedefs to add neighbouring sectors
foreach(Sidedef sd in s.Sidedefs)
{
// Sector on the other side of the line that we haven't checked yet?
if((sd.Other != null) && !sd.Other.Sector.Marked)
{
Sector os = sd.Other.Sector;
// Check if texture matches
if(((os.LongFloorTexture == originalflat) && !fillceilings) ||
((os.LongCeilTexture == originalflat) && fillceilings))
{
todo.Push(os);
}
}
}
}
}
#endregion
#region ================== Texture Floodfill
// This performs texture floodfill along all walls that match with the same texture
@ -1297,6 +1352,9 @@ namespace CodeImp.DoomBuilder.Geometry
{
Stack<SidedefFillJob> todo = new Stack<SidedefFillJob>(50);
// Mark all sidedefs false (they will be marked true when the texture is aligned)
if(resetsidemarks) General.Map.Map.ClearMarkedSidedefs(false);
// Begin with first sidedef
if(SidedefTextureMatch(start, originaltexture))
{

View file

@ -192,6 +192,7 @@ namespace CodeImp.DoomBuilder.VisualModes
{
base.OnUndoEnd();
ResourcesReloaded();
General.Map.Data.UpdateUsedTextures();
renderer.SetCrosshairBusy(false);
}
@ -206,6 +207,7 @@ namespace CodeImp.DoomBuilder.VisualModes
{
base.OnRedoEnd();
ResourcesReloaded();
General.Map.Data.UpdateUsedTextures();
renderer.SetCrosshairBusy(false);
}