Skip to content

Commit

Permalink
Deduplicate UpdateVoxelData Code
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin452 committed Mar 22, 2024
1 parent 9ea4d13 commit 8d36385
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions src/world/chunks/chunkmain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ function NewChunk(x, z)
end
if x <= ChunkSize and x >= 1 and z <= ChunkSize and z >= 1 and y >= 1 and y <= WorldHeight then
local _, _, _ = (self.x - 1) * ChunkSize + x - 1, y, (self.z - 1) * ChunkSize + z - 1
self.voxels[x][z] = ReplaceChar(self.voxels[x][z], (y - 1) * TileDataSize + 1, string.char(blockvalue))

self.changes[#self.changes + 1] = { x, y, z }
UpdateVoxelData(self, blockvalue, x, y, z)
end
end
--TODO continue optimizing chunk.setVoxel
Expand All @@ -153,7 +151,7 @@ function NewChunk(x, z)
@return Nothing.
--]]
chunk.setVoxel = function(self, x, y, z, blockvalue, manuallyPlaced)
SetVoxelInternal(manuallyPlaced,self,x,y,z,blockvalue)
SetVoxelInternal(manuallyPlaced, self, x, y, z, blockvalue)
end
chunk.setVoxelData = function(self, x, y, z, blockvalue)
SetVoxelDataInternal(self, x, y, z, blockvalue, "First")
Expand Down
12 changes: 6 additions & 6 deletions src/world/chunks/chunkutils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,9 @@ local function HandleManuallyPlacedBlockTileLightableSub(gx, gy, gz, manuallyPla
end
end

local function UpdateVoxelData(self, blockvalue, x, y, z)
if blockvalue ~= -1 then
self.voxels[x][z] = ReplaceChar(self.voxels[x][z], (y - 1) * TileDataSize + 1, string.char(blockvalue))
self.changes[#self.changes + 1] = { x, y, z }
end
function UpdateVoxelData(self, blockvalue, x, y, z)
self.voxels[x][z] = ReplaceChar(self.voxels[x][z], (y - 1) * TileDataSize + 1, string.char(blockvalue))
self.changes[#self.changes + 1] = { x, y, z }
end

local function HandleSunDownSubstract(gx, gy, gz)
Expand Down Expand Up @@ -346,7 +344,9 @@ function SetVoxelInternal(manuallyPlaced, self, x, y, z, blockvalue)
end
HandleLightSourceBlock(self, gx, gy, gz, x, y, z, blockvalue, destroyLight)
HandleManuallyPlacedBlockTileLightableSub(gx, gy, gz, manuallyPlaced, destroyLight)
UpdateVoxelData(self, blockvalue, x, y, z)
if blockvalue ~= -1 then
UpdateVoxelData(self, blockvalue, x, y, z)
end
HandleSunDownSubstract(gx, gy, gz)
end
_JPROFILER.pop("SetVoxelInternal")
Expand Down

0 comments on commit 8d36385

Please sign in to comment.