mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2025-01-01 05:50:34 +01:00
Optimized load.lua by avoiding multi-argument packing
This commit is contained in:
parent
9cda649c93
commit
636773487a
9
load.lua
9
load.lua
@ -6,19 +6,20 @@ function mapgen_rivers.load_map(filename, bytes, signed, size)
|
|||||||
if #data < bytes*size then
|
if #data < bytes*size then
|
||||||
data = minetest.decompress(data)
|
data = minetest.decompress(data)
|
||||||
end
|
end
|
||||||
|
local sbyte = string.byte
|
||||||
|
|
||||||
local map = {}
|
local map = {}
|
||||||
|
|
||||||
for i=1, size do
|
for i=1, size do
|
||||||
local i0, i1 = (i-1)*bytes+1, i*bytes
|
local i0 = (i-1)*bytes+1
|
||||||
local elements = {data:byte(i0, i1)}
|
local elements = {data:byte(i0, i1)}
|
||||||
local n = elements[1]
|
local n = sbyte(data, i0)
|
||||||
if signed and n >= 128 then
|
if signed and n >= 128 then
|
||||||
n = n - 256
|
n = n - 256
|
||||||
end
|
end
|
||||||
|
|
||||||
for j=2, bytes do
|
for j=1, bytes-1 do
|
||||||
n = n*256 + elements[j]
|
n = n*256 + sbyte(data, i0+j)
|
||||||
end
|
end
|
||||||
|
|
||||||
map[i] = n
|
map[i] = n
|
||||||
|
Loading…
Reference in New Issue
Block a user