mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-02 17:00:23 -04:00
also update terrain collision on terrain edit undo (#5003)
This commit is contained in:
@@ -60,4 +60,22 @@ public partial class Terrain
|
||||
HeightMap.Update( new ReadOnlySpan<ushort>( Storage.HeightMap ) );
|
||||
ControlMap.Update( new ReadOnlySpan<UInt32>( Storage.ControlMap ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the collider heights/materials from the current CPU data for a region.
|
||||
/// </summary>
|
||||
public void UpdateCollision( SyncFlags flags, RectInt region )
|
||||
{
|
||||
Assert.NotNull( Storage );
|
||||
|
||||
region.Left = Math.Clamp( region.Left, 0, Storage.Resolution - 1 );
|
||||
region.Right = Math.Clamp( region.Right, 0, Storage.Resolution - 1 );
|
||||
region.Top = Math.Clamp( region.Top, 0, Storage.Resolution - 1 );
|
||||
region.Bottom = Math.Clamp( region.Bottom, 0, Storage.Resolution - 1 );
|
||||
|
||||
if ( flags.HasFlag( SyncFlags.Height ) )
|
||||
UpdateColliderHeights( region.Left, region.Top, region.Width, region.Height );
|
||||
if ( flags.HasFlag( SyncFlags.Control ) )
|
||||
UpdateColliderMaterials( region.Left, region.Top, region.Width, region.Height );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public abstract class BaseBrushTool : EditorTool
|
||||
return region;
|
||||
}
|
||||
|
||||
Action CreateUndoAction<T>( Terrain terrain, T[] dest, T[] region, RectInt dirtyRegion ) => () =>
|
||||
Action CreateUndoAction<T>( Terrain terrain, T[] dest, T[] region, RectInt dirtyRegion, Terrain.SyncFlags flags ) => () =>
|
||||
{
|
||||
if ( !terrain.IsValid() )
|
||||
return;
|
||||
@@ -176,6 +176,7 @@ public abstract class BaseBrushTool : EditorTool
|
||||
}
|
||||
}
|
||||
terrain.SyncGPUTexture();
|
||||
terrain.UpdateCollision( flags, dirtyRegion );
|
||||
};
|
||||
|
||||
protected virtual void OnPaintEnded( Terrain terrain )
|
||||
@@ -194,8 +195,8 @@ public abstract class BaseBrushTool : EditorTool
|
||||
var regionAfter = CopyRegion( terrain.Storage.HeightMap, terrain.Storage.Resolution, _dirtyRegion );
|
||||
|
||||
SceneEditorSession.Active.UndoSystem.Insert( $"Terrain {DisplayInfo.For( this ).Name}",
|
||||
CreateUndoAction( terrain, terrain.Storage.HeightMap, regionBefore, _dirtyRegion ),
|
||||
CreateUndoAction( terrain, terrain.Storage.HeightMap, regionAfter, _dirtyRegion ) );
|
||||
CreateUndoAction( terrain, terrain.Storage.HeightMap, regionBefore, _dirtyRegion, Terrain.SyncFlags.Height ),
|
||||
CreateUndoAction( terrain, terrain.Storage.HeightMap, regionAfter, _dirtyRegion, Terrain.SyncFlags.Height ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -205,8 +206,8 @@ public abstract class BaseBrushTool : EditorTool
|
||||
var regionAfter = CopyRegion( terrain.Storage.ControlMap, terrain.Storage.Resolution, _dirtyRegion );
|
||||
|
||||
SceneEditorSession.Active.UndoSystem.Insert( $"Terrain {DisplayInfo.For( this ).Name}",
|
||||
CreateUndoAction( terrain, terrain.Storage.ControlMap, regionBefore, _dirtyRegion ),
|
||||
CreateUndoAction( terrain, terrain.Storage.ControlMap, regionAfter, _dirtyRegion ) );
|
||||
CreateUndoAction( terrain, terrain.Storage.ControlMap, regionBefore, _dirtyRegion, Terrain.SyncFlags.Control ),
|
||||
CreateUndoAction( terrain, terrain.Storage.ControlMap, regionAfter, _dirtyRegion, Terrain.SyncFlags.Control ) );
|
||||
}
|
||||
|
||||
_snapshot = null;
|
||||
|
||||
@@ -149,6 +149,7 @@ public class PaintTextureTool : EditorTool
|
||||
}
|
||||
|
||||
terrain.SyncGPUTexture();
|
||||
terrain.UpdateCollision( Terrain.SyncFlags.Control, dirtyRegion );
|
||||
};
|
||||
|
||||
SceneEditorSession.Active.UndoSystem.Insert( $"Terrain {DisplayInfo.For( this ).Name}", CreateUndoAction( regionBefore ), CreateUndoAction( regionAfter ) );
|
||||
|
||||
Reference in New Issue
Block a user