summaryrefslogtreecommitdiff
path: root/client/chunk.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-02-23 11:53:10 +0000
committerubq323 <ubq323@ubq323.website>2023-02-25 01:51:36 +0000
commit41a7a40ecf71613c6cb3f7823491c45d9c9c63e0 (patch)
tree737c9955ef433642d3fcfc45bd3ce8c0bb3041fd /client/chunk.lua
parent447f46c1710f507622306a338cc8c82b1ce3aa5c (diff)
implement new rendering system using gpu instancing
this has extremely better performance on my machine also, player is circle now
Diffstat (limited to 'client/chunk.lua')
-rw-r--r--client/chunk.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/client/chunk.lua b/client/chunk.lua
new file mode 100644
index 0000000..73fe949
--- /dev/null
+++ b/client/chunk.lua
@@ -0,0 +1,42 @@
+local class = require"common.class"
+local chunk = require"common.chunk"
+local Chunk = require"common.chunk".Chunk
+local CHUNK_SIZE = require"common.constants".CHUNK_SIZE
+
+local ChunkC = class.extend(chunk.Chunk)
+function ChunkC.make(cls,...)
+ local self = chunk.Chunk.make(cls,...)
+ self.imesh = cls.imesh_from_chunk_data(self)
+ return self
+end
+local function tile_to_vattr(tile)
+ -- for now tiles are always numbers
+ -- so this just returns the input
+ -- this function might move to drawing.lua once it does something less trivial
+ assert(type(tile) == "number","can't send non-numerical tile to gpu")
+ return tile
+end
+function ChunkC.imesh_from_chunk_data(the_chunk)
+ local mesh_data = {}
+ for q=0,CHUNK_SIZE-1 do
+ for r =0,CHUNK_SIZE-1 do
+ local t = the_chunk:_atqr(q,r)
+ table.insert(mesh_data,{tile_to_vattr(t)})
+ end
+ end
+
+ local imesh = love.graphics.newMesh({
+ {"tile_type","float",1}
+ }, mesh_data, nil, "dynamic")
+
+ return imesh
+end
+
+function ChunkC.set_at(self,hoffs,tile)
+ Chunk.set_at(self,hoffs,tile)
+
+ local idx = chunk.index(hoffs.q,hoffs.r)
+ self.imesh:setVertexAttribute(idx, 1, tile_to_vattr(tile))
+end
+
+return {ChunkC=ChunkC}