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}