null nil RBX1 0 0 0 0 1 0 0 0 1 0 0 0 1 Workspace null null 0 11.5004616 328.678162 549.033936 0.999780774 -0.0107550351 0.0179694742 9.31322686e-10 0.858053982 0.513559699 -0.0209421311 -0.513447106 0.857865691 70 0 0 0 1 0 0 0 1 0 0 0 1 Camera true -0.5 0.5 0 0 -0.5 0.5 4 0 194 -2 126 -2 1 0 0 0 1 0 0 0 1 true 0.5 0.300000012 -0.5 0.5 0 0 -0.5 0.5 0 0 true 256 Terrain 0 -0.5 0.5 0 0 0 0 0 -0.5 0.5 3 0 0 0 0 0 2044 252 2044 StarterPack StarterGui true 0 10 1 Soundscape 1 CollectionService PhysicsService BadgeService Geometry RenderHooksService SocialService 1000 Debris Instance Instance CookiesService Teleport Service true Players Selection 4286611584 1 4278190080 4278190080 4290822336 100000 0 41.7332993 Lighting 4289967032 14:00:00 ChangeHistoryService false true true true TestService 10 false Script test = game:GetService("TestService") terrain = game.Workspace.Terrain history = game:GetService("ChangeHistoryService") --explicitly enable history history:SetEnabled(1) XZ_CHUNK = 32 Y_CHUNK = 4 cellCountList = {} materialList = {} indexList = {} wedgeCountList = {} function checkLayerData(layerIndex) local index = indexList[layerIndex] local newM, newB, newO = terrain:GetCell(XZ_CHUNK, Y_CHUNK*index, XZ_CHUNK) test:Check(cellCountList[layerIndex] == terrain:CountCells(), "Terrain cell count mismatch") test:Check(materialList[layerIndex] == (newM.Value), "Material mismatch") end function verifyLayersUndo(numLayers) for count = numLayers, 2, -1 do --do an undo history:Undo() checkLayerData(count-1) end --this is last undo (after this there should not be any cells present in the terrain) history:Undo() test:Check(0 == terrain:CountCells(), "Cell count") end function verifyLayersRedo(numLayers) for count = 1, numLayers do --do an undo history:Redo() checkLayerData(count) end end function generateLayers(numLayers, startMaterial, saveData) for index=1, numLayers do local start = Vector3int16.new(-XZ_CHUNK, Y_CHUNK*index, -XZ_CHUNK) local finish = Vector3int16.new(XZ_CHUNK, Y_CHUNK*index, XZ_CHUNK) terrain:SetCells(Region3int16.new(start,finish),index+startMaterial, 0, 0) if saveData then table.insert(cellCountList, terrain:CountCells()) table.insert(materialList, index+startMaterial) table.insert(indexList, index) history:SetWaypoint("GenerateLayers") end end end function wedgeCount() local count = 0 local start = Vector3int16.new(-XZ_CHUNK, Y_CHUNK, -XZ_CHUNK) local finish = Vector3int16.new(XZ_CHUNK, Y_CHUNK*5, XZ_CHUNK) for y=start.Y, finish.Y do for x=start.X, finish.X do for z=start.X, finish.Z do local newM, newB, newO = terrain:GetCell(x,y,z) if newB ~= Enum.CellBlock.Solid then count = count + 1 end end end end return count end function verifyAutoWedgeUndo(index) history:Undo() test:Check(wedgeCountList[index] == wedgeCount(), "Undo: Wedge count mismatch") end function verifyAutoWedgeRedo(index) history:Redo() test:Check(wedgeCountList[index] == wedgeCount(), "Redo: Wedge count mismatch") end function createAutoWedgeCells() table.insert(wedgeCountList, wedgeCount()) local start = Vector3int16.new(-XZ_CHUNK, Y_CHUNK, -XZ_CHUNK) local finish = Vector3int16.new(XZ_CHUNK, Y_CHUNK*5, XZ_CHUNK) terrain:AutowedgeCells(Region3int16.new(start,finish)) history:SetWaypoint("CreateAutoWedgeCells") table.insert(wedgeCountList, wedgeCount()) end function verifyWayPointsAbsorb(layerIndex) --first undo upto the last waypoint while (history:GetCanUndo()) do history:Undo() end -- specified layer must be present checkLayerData(layerIndex) end -- create layers of different materials generateLayers(5, 0, true) -- modification without setting waypoint to verify that only the last modification is saved generateLayers(1, 3, false) generateLayers(5, 5, true) -- verify undo/redo (10 states - max) verifyLayersUndo(10) verifyLayersRedo(10) -- RWM - change history no longer merges at 11, it depends on memory usage. --[[ -- add 11th entry in the change history to force an absorb createAutoWedgeCells() verifyAutoWedgeUndo(#wedgeCountList - 1) verifyAutoWedgeRedo(#wedgeCountList) -- first layer must be present as a result of absorb once the number of waypoints exceeds 10 verifyWayPointsAbsorb(1) ]]--