TerrainStrokeEdit
Package: Libraries.Game.Graphics.Worlds · Inherits from: Libraries.Language.Object, Libraries.Interface.Undo.Edit
A TerrainStrokeEdit undoes and redoes one TerrainStroke. It holds a copy of every region the stroke touched from before the stroke and from after it. Undo puts the "before" copies back, and Redo the "after" copies. A copy can be undefined, meaning there was no region there, so strokes that add or remove regions undo too. It is an Edit from the standard library's undo system, so it can go into an EditManager, the way Quorum Studio's editors keep their undo lists. A TerrainEditHistory keeps these edits with a limit on how much memory they use. Undo and Redo change the TerrainData and add the regions to its edited areas. They don't redraw anything: afterward, call the WorldTerrain's Rebuild, as after any edit. Each region copy holds 8 bytes per sample, about 0.5 MB for a 256 by 256 region, and an edit holds two copies of each region it touched.
Example Code
use Libraries.Game.Graphics.Worlds.TerrainStroke
use Libraries.Game.Graphics.Worlds.TerrainStrokeEdit
// After a stroke, as in TerrainStroke's example:
TerrainStrokeEdit edit = stroke:End()
if edit not= undefined
output edit:GetUndoName()
edit:Undo()
edit:Redo()
end
Actions
CanRedo()
This action returns true if the stroke can be redone: it has been undone.
Returns
boolean: True if Redo can be called.
CanUndo()
This action returns true if the stroke can be undone: it is not undone already.
Returns
boolean: True if Undo can be called.
ChangesShape()
This action returns true if the stroke changed the ground's shape, so meshes must be rebuilt after undoing or redoing it.
Returns
boolean: True if heights or regions changed.
ChangesSplat()
This action returns true if the stroke changed splat weights, so the splat texture must be rebuilt after undoing or redoing it.
Returns
boolean: True if splat weights or regions changed.
Dispose()
This action lets go of the region copies. The edit can't be undone or redone afterward.
GetLargestHeightChange()
This action returns the biggest change in height the stroke made at any sample, such as 2.4 for ground raised by up to 2.4, or -1.5 for ground lowered by up to 1.5. Regions the stroke added or removed are left out.
Returns
number: The change in world units, or 0 if no height changed.
GetMemorySize()
This action returns about how many bytes the edit's region copies use.
Returns
integer: The size in bytes.
GetName()
This action returns what the stroke did, such as "raise".
Returns
text: The name.
GetRedoName()
This action returns a name for redoing the stroke, such as "Redo raise".
Returns
text: The name.
GetRegionCount()
This action returns how many regions the stroke touched.
Returns
integer: The number of regions.
GetUndoName()
This action returns a name for undoing the stroke, such as "Undo raise".
Returns
text: The name.
Redo()
This action puts every region the stroke touched back the way it was after the stroke.
Setup(Libraries.Game.Graphics.Worlds.TerrainData data, text name, boolean changesShape, boolean changesSplat, Libraries.Containers.Array<integer> locationsX, Libraries.Containers.Array<integer> locationsZ, Libraries.Containers.Array<Libraries.Game.Graphics.Worlds.TerrainRegion> beforeCopies, Libraries.Containers.Array<Libraries.Game.Graphics.Worlds.TerrainRegion> afterCopies)
This action fills in the edit. TerrainStroke's End calls it; other code should not need to.
Parameters
dataLibraries.Game.Graphics.Worlds.TerrainData: The terrain the stroke changed.nametext: What the stroke did, such as "raise".changesShapeboolean: True if the stroke changed heights or regions.changesSplatboolean: True if the stroke changed splat weights or regions.locationsXLibraries.Containers.Array<integer>: The touched regions' locations along x.locationsZLibraries.Containers.Array<integer>: The touched regions' locations along z, in the same order.beforeCopiesLibraries.Containers.Array<Libraries.Game.Graphics.Worlds.TerrainRegion>: Copies of the regions from before the stroke, undefined where there was none.afterCopiesLibraries.Containers.Array<Libraries.Game.Graphics.Worlds.TerrainRegion>: Copies of the regions from after the stroke, undefined where there is none.
Undo()
This action puts every region the stroke touched back the way it was before the stroke.