mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2025-07-04 17:30:39 +02:00
Add all code for generating a grid on world creation.
Not tested ; will likely need much testing and bugfix.
This commit is contained in:
28
load.lua
28
load.lua
@ -1,6 +1,6 @@
|
||||
local worldpath = minetest.world_data_path
|
||||
|
||||
local function load_map(filename, bytes, signed, size)
|
||||
function mapgen_rivers.load_map(filename, bytes, signed, size)
|
||||
local file = io.open(worldpath .. filename, 'rb')
|
||||
local data = file:read('*all')
|
||||
if #data < bytes*size then
|
||||
@ -28,4 +28,28 @@ local function load_map(filename, bytes, signed, size)
|
||||
return map
|
||||
end
|
||||
|
||||
return load_map
|
||||
function mapgen_rivers.write_map(filename, data, bytes)
|
||||
local size = #data
|
||||
local file = io.open(worldpath .. filename, 'wb')
|
||||
local mfloor = math.floor
|
||||
local schar = string.char
|
||||
local upack = unpack
|
||||
|
||||
local bytelist = {}
|
||||
for j=1, bytes do
|
||||
bytelist[j] = 0
|
||||
end
|
||||
|
||||
for i=1, size do
|
||||
local n = mfloor(data[i])
|
||||
for j=bytes, 2, -1 do
|
||||
bytelist[j] = n % 256
|
||||
n = mfloor(n / 256)
|
||||
end
|
||||
bytelist[1] = n % 256
|
||||
|
||||
file:write(schar(upack(bytelist)))
|
||||
end
|
||||
|
||||
file:close()
|
||||
end
|
||||
|
Reference in New Issue
Block a user