Skip to content

Commit

Permalink
fixing again render distance/Chunk Slice/Proc gen bugs...
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin452 committed Feb 28, 2024
1 parent a5e0d7a commit dc4d29d
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 110 deletions.
6 changes: 1 addition & 5 deletions src/client/drawhud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ end
local exampleModelReference = nil
function DrawTestBlock()
if enableTESTBLOCK == false and modelalreadycreated == 1 then
LuaCraftPrintLoggingNormal("[NORMAL LOGGING] Condition met. Disabling test block and removing model...")
if exampleModelReference then
-- Trouver l'indice du modèle dans la liste
local modelIndex = nil
Expand Down Expand Up @@ -217,9 +216,6 @@ end
local chunkBordersModels = {}
function DrawChunkBorders3D()
if enableF8 == false and ChunkBorderAlreadyCreated == 1 then
LuaCraftPrintLoggingNormal("[NORMAL LOGGING] Condition met. Disabling test block and removing models...")

-- Supprimer tous les modèles de la liste
for _, model in ipairs(chunkBordersModels) do
local modelIndex = nil
for i, sceneModel in ipairs(scene.modelList) do
Expand All @@ -235,7 +231,7 @@ function DrawChunkBorders3D()
end
end

chunkBordersModels = {} -- Réinitialiser la table des modèles
chunkBordersModels = {}

ChunkBorderAlreadyCreated = 0
elseif enableF8 and ChunkBorderAlreadyCreated == 0 then
Expand Down
2 changes: 1 addition & 1 deletion src/init/!init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require("src/init/windowsettingsinit")
require("src/init/worldinit")
require("src/init/structureinit")

local function initWorldGenerationVariables()
function initWorldGenerationVariables()
ChunkSize = 16
SliceHeight = 8
WorldHeight = 128
Expand Down
4 changes: 0 additions & 4 deletions src/utils/filesystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ function createFileIfNotExists(filePath)
local file, err = io.open(filePath, "r")

if not file then
-- Créer le répertoire s'il n'existe pas
local directory = filePath:match("(.+\\).-$")
os.execute('mkdir "' .. directory .. '"')

Expand All @@ -131,7 +130,6 @@ function loadAndSaveLuaCraftFileSystem()
local luaCraftDirectory = userDirectory .. ".LuaCraft\\"
local configFilePath = luaCraftDirectory .. "luacraftconfig.txt"

-- Check and create file if not exists
createFileIfNotExists(configFilePath)

LuaCraftPrintLoggingNormal("Directory contents before attempting to load settings:")
Expand Down Expand Up @@ -163,7 +161,6 @@ function loadAndSaveLuaCraftFileSystem()

LuaCraftPrintLoggingNormal("Settings loaded successfully.")

-- Verify and Update Default Values
checkAndUpdateDefaults(Settings)

-- Open the file in Writter mod
Expand Down Expand Up @@ -245,6 +242,5 @@ function writeToLog(string, message)
file:write(os.date("[%Y-%m-%d %H:%M:%S] ") .. string .. message .. "\n")
file:close()
else
--LuaCraftErrorLogging("Failed to open log file. Error: " .. err)
end
end
8 changes: 5 additions & 3 deletions src/utils/mouselogic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ function KeyPressed(k)
elseif k == "f1" then
enableTESTBLOCK = not enableTESTBLOCK
elseif k == "f2" then
-- for _, chunk in ipairs(renderChunks) do
-- if chunk.active then

for _, chunk in ipairs(renderChunks) do
chunk:removeModel()
--
-- chunk:sunlight()
-- chunk:processRequests()
-- end
-- end
end
end
end
if gamestate == gamestateGamePausing then
Expand Down
25 changes: 18 additions & 7 deletions src/utils/settingshandling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function reloadConfig()
lovewindow.setVSync(globalVSync and 1 or 0)
end

-- local renderdistanceValue = file_content:match("renderdistance=(%d+)")
-- globalRenderDistance = tonumber(renderdistanceValue) or 6
-- local renderdistanceValue = file_content:match("renderdistance=(%d+)")
-- globalRenderDistance = tonumber(renderdistanceValue) or 6

local printNormalValue = file_content:match("LuaCraftPrintLoggingNormal=(%w+)")
EnableLuaCraftPrintLoggingNormalLogging = printNormalValue:lower() == "true"
Expand Down Expand Up @@ -50,18 +50,29 @@ function toggleVSync()
end
_JPROFILER.pop("toggleVSync")
end
function getRenderDistanceValue()
local file_path = userDirectory .. ".LuaCraft\\luacraftconfig.txt"
local file_content, error_message = customReadFile(file_path)

if file_content then
local current_renderdistance = tonumber(file_content:match("renderdistance=(%d+)")) or 6
return current_renderdistance * 16 --ChunkSize
else
LuaCraftErrorLogging("Failed to read luacraftconfig.txt. Error: " .. error_message)
return
end
end

function renderdistanceSetting()
_JPROFILER.push("renderdistanceSetting")
local file_path = userDirectory .. ".LuaCraft\\luacraftconfig.txt"
local file_content, error_message = customReadFile(file_path)

if file_content then
local current_renderdistance = tonumber(file_content:match("renderdistance=(%d+)")) or 0
globalRenderDistance = current_renderdistance + 6
globalRenderDistance = current_renderdistance + 2

if globalRenderDistance > 24 then
globalRenderDistance = 6
if globalRenderDistance > 20 then
globalRenderDistance = 2
end

file_content = file_content:gsub("renderdistance=(%d+)", "renderdistance=" .. globalRenderDistance)
Expand All @@ -76,7 +87,7 @@ function renderdistanceSetting()
else
LuaCraftErrorLogging("Failed to read luacraftconfig.txt. Error: " .. error_message)
end
_JPROFILER.pop("renderdistanceSetting")
return globalRenderDistance
end

function printNormalLoggingSettings()
Expand Down
16 changes: 14 additions & 2 deletions src/world/chunk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ function NewChunk(x, z)
chunk.changes = {}
chunk.updatedSunLight = false
chunk.isPopulated = false
chunk.isPopulated2 = false
for i = 1, ChunkSize do
chunk.heightMap[i] = {}
end

chunk.active = false
GenerateTerrain(chunk, x, z, StandardTerrain)

local gx, gz = (chunk.x - 1) * ChunkSize + rand(0, 15), (chunk.z - 1) * ChunkSize + rand(0, 15)
Expand All @@ -34,6 +35,7 @@ function NewChunk(x, z)
for i = 1, caveCount2 do
NewCave(gx, rand(48, 80), gz)
end
-- LightingUpdate()
end

chunk.sunlight = function(self)
Expand All @@ -56,7 +58,7 @@ function NewChunk(x, z)
end
end
end
--LightingUpdate()
-- LightingUpdate()
end

chunk.processRequests = function(self)
Expand Down Expand Up @@ -283,6 +285,16 @@ function NewChunk(x, z)
self.changes[#self.changes + 1] = { x, y, z }
end
end
chunk.removeModel = function(self)
print(chunk)
-- Supprimez le modèle de ce Chunk
-- (Remplacez ceci par le code réel pour supprimer le modèle)
end
function updateAllChunksModel()
for _, chunk in ipairs(renderChunks) do
chunk:updateModel()
end
end

-- update this chunk's model slices based on what changes it has stored
chunk.updateModel = function(self)
Expand Down
1 change: 1 addition & 0 deletions src/world/gen/caves.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function NewCave(x, y, z)
end
end
end
--LightingUpdate()
end

CaveList[#CaveList + 1] = t
Expand Down
Loading

0 comments on commit dc4d29d

Please sign in to comment.