12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- -- Test, and example of how to use the map API
- require("map")
- local function slowLoadMap(map, chunkTime, func, funcDone)
- TestMapUpdateSched = nil
- local loadNextChunk
- local x, y = 1, 1
- loadNextChunk = function()
- func(map, x, y)
- if x>=map.xChunks then
- x = 1
- y = y+1
- if y > map.yChunks then
- schedule(chunkTime, funcDone)
- return
- end
- else
- x = x+1
- end
- TestMapUpdateSched = schedule(chunkTime, loadNextChunk)
- end
- loadNextChunk()
- end
- function DeleteTestMap()
- talk("Deleting map")
- schedule(1000, slowLoadMap, TestMap, 50, UnloadMapChunk, function()
- TestMap = nil
- talk("Done deleting map")
- end)
- end
- function TestGenerateMap()
- if not exists("TestMap") then
- talk("Creating map object")
- TestMap = CreateMap(
- vector{0, 0, 0}, -- position
- vector{1, 1, 0.1}, -- scale
- 16, -- cubeWidth
- 0.5, -- cubeHeight
- "modter/pixelated", -- printName
- 16 -- chunkSize
- )
- end
- talk("Importing map data")
- SetMapDataFile(TestMap, 256, 256, "Add-ons/Support_MapGeneration/maps/hawaii256.map")
-
- talk("Building map")
- schedule(1000, slowLoadMap, TestMap, 50, UpdateMapChunk, function() talk("Done updating map") end)
- end
- function StopMap()
- if TestMapUpdateSched then
- talk("Stopping map generation")
- cancel(TestMapUpdateSched)
- TestMapUpdateSched = nil
- else
- talk("No map generation in progress")
- end
- end
- StopMap()
- TestGenerateMap()
- --DeleteTestMap()
|