summaryrefslogtreecommitdiff
path: root/server/server.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-02-03 19:37:28 +0000
committerubq323 <ubq323@ubq323.website>2023-02-03 19:51:07 +0000
commit1ebd7d9b7b62c8e05d527611a1944ed1a876b890 (patch)
treecfc5ddf3fc15985c4369aa12d56de5fa8d6fc7e5 /server/server.lua
parentec6a391cb9cf0c0feac0fe3615a59cc7cb6db2d5 (diff)
debug drawing change, zoom clamping, partial refactoring of class mechanisms to allow inheritance, minor refactor of noise generator, changes to temp worldgen, rework of class constructor mechanism
Diffstat (limited to 'server/server.lua')
-rw-r--r--server/server.lua41
1 files changed, 32 insertions, 9 deletions
diff --git a/server/server.lua b/server/server.lua
index 67860ea..08f75c0 100644
--- a/server/server.lua
+++ b/server/server.lua
@@ -60,19 +60,42 @@ local function player_move_packet(player,x,y)
return json.encode{t="move",id=player.id,x=x,y=y}
end
+
+-- worldgen
local the_tiles = {}
-local ng = noise.NoiseAgg.make_perlin_octaves(4)
-for q = 1,chunk.SIZE-1 do
- for r = 1,chunk.SIZE-1 do
- local p = coords.Hex.make(q,r):to_pos()
- local nv = ng:at(p.x/20,p.y/20)
- assert(nv ~= 1,"oopsy")
- the_tiles[chunk.index(q,r)] = nv > 0 and 1+math.floor(math.sqrt(nv)*8) or false
+local function p(amp,scale) return {scale=scale,amp=amp,gen=noise.PerlinNoise:make()} end
+local ng = noise.NoiseAgg:make{
+ p(1,20),
+ -- p(0.7,2),
+ p(0.5,15),
+ --p(2,200),
+}
+local ng2 = noise.NoiseAgg:make{p(1,20),p(0.5,15)}
+
+for q = 0,chunk.SIZE-1 do
+ for r = 0,chunk.SIZE-1 do
+ local p = coords.Hex:make(q,r):to_pos()
+ local ix = chunk.index(q,r)
+ local nv = ng:at(p.x,p.y)
+ if nv <= 0 then
+ the_tiles[ix] = false
+ else
+ local nv2 = ng2:at(p.x,p.y)
+ nv2 = math.max(-0.9999999,math.min(0.9999999,nv2*2.5))
+ nv2 = (nv2+1)/2
+ print(nv2)
+
+ local tv = 1+math.floor(nv2*8)
+ assert(1<=tv and tv<=8,"oopsy woopsy")
+ the_tiles[ix] = tv
+ end
end
end
-local the_chunk = Chunk.make(the_tiles)
+local the_chunk = Chunk:make(the_tiles)
print"generated chunk"
+
+
while true do
local ev = host:service(100)
if ev then
@@ -115,7 +138,7 @@ while true do
end
end
elseif op == "settile" then
- local h = coords.Hex.make(j.q,j.r)
+ local h = coords.Hex:make(j.q,j.r)
the_chunk:set_at(h,j.tile)
-- print(player.id,"settile",h,j.tile)
for i,otherplayer in ipairs(playerlist) do