2020-04-26 23:29:36 +02:00
|
|
|
local worldpath = minetest.get_worldpath() .. "/river_data/"
|
2020-04-14 21:11:54 +02:00
|
|
|
|
2020-04-13 15:59:34 +02:00
|
|
|
local function load_map(filename, bytes, signed, size)
|
2020-11-14 17:31:36 +01:00
|
|
|
local file = io.open(worldpath .. filename, 'rb')
|
2020-04-09 21:13:38 +02:00
|
|
|
local data = file:read('*all')
|
2020-04-13 15:59:34 +02:00
|
|
|
if #data < bytes*size then
|
|
|
|
data = minetest.decompress(data)
|
|
|
|
end
|
2020-04-09 21:13:38 +02:00
|
|
|
|
|
|
|
local map = {}
|
|
|
|
|
|
|
|
for i=1, size do
|
|
|
|
local i0, i1 = (i-1)*bytes+1, i*bytes
|
|
|
|
local elements = {data:byte(i0, i1)}
|
|
|
|
local n = elements[1]
|
|
|
|
if signed and n >= 128 then
|
|
|
|
n = n - 256
|
|
|
|
end
|
|
|
|
|
|
|
|
for j=2, bytes do
|
|
|
|
n = n*256 + elements[j]
|
|
|
|
end
|
|
|
|
|
|
|
|
map[i] = n
|
|
|
|
end
|
|
|
|
file:close()
|
|
|
|
|
|
|
|
return map
|
|
|
|
end
|
|
|
|
|
|
|
|
return load_map
|