summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-02-12 17:29:24 +0000
committerubq323 <ubq323@ubq323.website>2023-02-12 17:29:32 +0000
commit24b06ededb117588adab64af1c60a0c53e2a8feb (patch)
tree65333308393c24370350a31c2a3ae18fcdb110e1
parent3c2ce647d376e87a02fccb79f3de7a90fbf72f08 (diff)
change hash function, remove caching of noise vectors; noise won't use unbounded memory now
-rw-r--r--client/main.lua2
-rw-r--r--server/noise.lua16
2 files changed, 6 insertions, 12 deletions
diff --git a/client/main.lua b/client/main.lua
index 03df16a..d58551e 100644
--- a/client/main.lua
+++ b/client/main.lua
@@ -89,7 +89,7 @@ function love.update(dt)
update_local_player(local_player,dt)
if love.keyboard.isScancodeDown"q" then camera.zoom = camera.zoom*1.05 end
if love.keyboard.isScancodeDown"e" then camera.zoom = camera.zoom/1.05 end
- camera.zoom = math.max(1,math.min(50,camera.zoom))
+ camera.zoom = math.max(2.5,math.min(50,camera.zoom))
sync_local_player(local_player)
end
diff --git a/server/noise.lua b/server/noise.lua
index bf7ac2e..c0ca57c 100644
--- a/server/noise.lua
+++ b/server/noise.lua
@@ -9,8 +9,8 @@ math.randomseed(os.time())
local function hash_list(t)
local h = #t
for _,x in ipairs(t) do
- x = bit.bxor(bit.rshift(x,16),x) * 0x45d9f3b
- x = bit.bxor(bit.rshift(x,16),x) * 0x45d9f3b
+ x = bit.bxor(bit.rshift(x,16),x) * 0x7feb352d
+ x = bit.bxor(bit.rshift(x,15),x) * 0x846ca68b
x = bit.bxor(bit.rshift(x,16),x)
h = bit.bxor(h,x + 0x9e3779b9 + bit.lshift(h,6) + bit.rshift(h,2))
end
@@ -33,17 +33,11 @@ end
local function slerp(a,b,t) return lerp(a,b,smoothstep(t)) end
local PerlinNoise = class()
-function PerlinNoise.make(cls,ind_seed)
- local grid = {}
- setmetatable(grid,{__index=function(t,k) t[k] = {} return t[k] end})
- return setmetatable({grid=grid,ind_seed=ind_seed},cls)
+function PerlinNoise.make(cls,seed)
+ return setmetatable({seed=seed},cls)
end
function PerlinNoise.vertex(self,ix,iy)
- local v = self.grid[ix][iy]
- if v then return v end
- local vv = hash_to_unit_vec{ix,iy,self.ind_seed}
- self.grid[ix][iy] = vv
- return vv
+ return hash_to_unit_vec{ix,iy,self.seed}
end
function PerlinNoise.at(self,x,y)