Skip to content

Commit

Permalink
Reverted Smooth Chunk Building
Browse files Browse the repository at this point in the history
  • Loading branch information
Jukitsu committed Dec 20, 2023
1 parent 9264c73 commit 659949e
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Jukcraft.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
# Visual Studio Version 16
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GLFW", "vendor\glfw\GLFW.vcxproj", "{154B857C-0182-860D-AA6E-6C109684020F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Glad", "vendor\glad\Glad.vcxproj", "{BDD6857C-A90D-870D-52FA-6C103E10030F}"
Expand Down
9 changes: 3 additions & 6 deletions Jukcraft/Jukcraft.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>GLFW_INCLUDE_NONE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>GLFW_INCLUDE_NONE;JUK_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>src;..\vendor\glad\include;..\vendor\glfw\include;..\vendor\glm;..\vendor\stb;..\vendor\spdlog\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -100,7 +99,7 @@
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<WarningLevel>Level3</WarningLevel>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<PreprocessorDefinitions>GLFW_INCLUDE_NONE;GLM_FORCE_INLINE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>GLFW_INCLUDE_NONE;GLM_FORCE_INLINE;JUK_BETA;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>src;..\vendor\glad\include;..\vendor\glfw\include;..\vendor\glm;..\vendor\stb;..\vendor\spdlog\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
Expand All @@ -111,7 +110,6 @@
<FloatingPointModel>Fast</FloatingPointModel>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<LanguageStandard>stdcpp17</LanguageStandard>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -140,7 +138,6 @@
<FloatingPointModel>Fast</FloatingPointModel>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<LanguageStandard>stdcpp17</LanguageStandard>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -166,8 +163,8 @@
<ClInclude Include="src\models\Model.h" />
<ClInclude Include="src\pch.h" />
<ClInclude Include="src\physics\constants.h" />
<ClInclude Include="src\renderer\chunk\Mesh.h" />
<ClInclude Include="src\renderer\Renderer.h" />
<ClInclude Include="src\renderer\chunk\Mesh.h" />
<ClInclude Include="src\renderer\gfx\buffers\DynamicBuffer.h" />
<ClInclude Include="src\renderer\gfx\buffers\StagingBuffer.h" />
<ClInclude Include="src\renderer\gfx\objects\Buffer.h" />
Expand Down
11 changes: 9 additions & 2 deletions Jukcraft/Jukcraft.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<Filter Include="renderer">
<UniqueIdentifier>{9C6AA017-8837-FB22-B150-E9CA9D7C30B1}</UniqueIdentifier>
</Filter>
<Filter Include="renderer\chunk">
<UniqueIdentifier>{C4E6214A-B0B4-1550-9948-867685B5F1B4}</UniqueIdentifier>
</Filter>
<Filter Include="renderer\gfx">
<UniqueIdentifier>{30E2E770-1C45-7715-C5CA-AFCBB10C4398}</UniqueIdentifier>
</Filter>
Expand Down Expand Up @@ -97,6 +100,9 @@
<ClInclude Include="src\renderer\Renderer.h">
<Filter>renderer</Filter>
</ClInclude>
<ClInclude Include="src\renderer\chunk\Mesh.h">
<Filter>renderer\chunk</Filter>
</ClInclude>
<ClInclude Include="src\renderer\gfx\buffers\DynamicBuffer.h">
<Filter>renderer\gfx\buffers</Filter>
</ClInclude>
Expand Down Expand Up @@ -130,7 +136,6 @@
<ClInclude Include="src\world\chunk\util.h">
<Filter>world\chunk</Filter>
</ClInclude>
<ClInclude Include="src\renderer\chunk\Mesh.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\core\App.cpp">
Expand Down Expand Up @@ -162,6 +167,9 @@
</ClCompile>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\pch.cpp" />
<ClCompile Include="src\renderer\chunk\Mesh.cpp">
<Filter>renderer\chunk</Filter>
</ClCompile>
<ClCompile Include="src\renderer\gfx\buffers\DynamicBuffer.cpp">
<Filter>renderer\gfx\buffers</Filter>
</ClCompile>
Expand All @@ -180,6 +188,5 @@
<ClCompile Include="src\world\chunk\ChunkManager.cpp">
<Filter>world\chunk</Filter>
</ClCompile>
<ClCompile Include="src\renderer\chunk\Mesh.cpp" />
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion Jukcraft/src/core/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ namespace Jukcraft {
glfwSetWindowUserPointer(handle, this);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
THROW_ERROR("Failed to load GL");
#ifdef _DEBUG

#ifdef JUK_DEBUG
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(GLDebugMsgCallback, nullptr);
#endif

glfwSetWindowSizeCallback(handle, [](GLFWwindow* window, int width, int height) {
((Window*)glfwGetWindowUserPointer(window))->onResize(width, height);
});
Expand Down
2 changes: 1 addition & 1 deletion Jukcraft/src/world/chunk/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Jukcraft {
else if (ly >= CHUNK_HEIGHT / 2 - 3 && ly < CHUNK_HEIGHT / 2 - 1)
setBlock(glm::uvec3(lx, ly, lz), 3);
else
setBlock(glm::uvec3(lx, ly, lz), 1);
setBlock(glm::uvec3(lx, ly, lz), std::rand() % 3 ? 1 : 0);
}

lightMap = new uint8_t * *[CHUNK_HEIGHT];
Expand Down
20 changes: 10 additions & 10 deletions Jukcraft/src/world/chunk/ChunkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Jukcraft {
blocks,
*this
);
chunksToUpdates.push(chunk);
chunksToUpdates.insert(chunk);
chunksToLight.insert(chunk);
if (z > 0) {
std::shared_ptr<Chunk>& northernChunk = chunks[x][z - 1];
Expand Down Expand Up @@ -43,32 +43,32 @@ namespace Jukcraft {
blocks,
*this
);
chunksToUpdates.push(chunk);
chunksToUpdates.insert(chunk);
chunksToLight.insert(chunk);
return chunk;
}

void ChunkManager::tick() {
std::vector<std::future<void>> results;
if (!chunksToUpdates.empty()) {
auto& chunk = chunksToUpdates.front();
chunksToUpdates.pop();
for (std::shared_ptr<Chunk> chunk : chunksToUpdates) {
chunk->updateLayers();
// results.push_back(std::async(std::launch::async, std::bind(&Chunk::updateLayers, chunk.get())));
}
chunksToUpdates.clear();

}

void ChunkManager::updateChunkAtPosition(std::shared_ptr<Chunk>& chunk, const glm::ivec3& localPos) {
chunksToUpdates.push(chunk);
chunksToUpdates.insert(chunk);

if (Chunk::IsOutside(localPos + IEAST) && !chunk->neighbourChunks.east.expired())
chunksToUpdates.push(chunk->neighbourChunks.east.lock());
chunksToUpdates.insert(chunk->neighbourChunks.east.lock());
if (Chunk::IsOutside(localPos + INORTH) && !chunk->neighbourChunks.north.expired())
chunksToUpdates.push(chunk->neighbourChunks.north.lock());
chunksToUpdates.insert(chunk->neighbourChunks.north.lock());
if (Chunk::IsOutside(localPos + IWEST) && !chunk->neighbourChunks.west.expired())
chunksToUpdates.push(chunk->neighbourChunks.west.lock());
chunksToUpdates.insert(chunk->neighbourChunks.west.lock());
if (Chunk::IsOutside(localPos + ISOUTH) && !chunk->neighbourChunks.south.expired())
chunksToUpdates.push(chunk->neighbourChunks.south.lock());
chunksToUpdates.insert(chunk->neighbourChunks.south.lock());

}

Expand Down
2 changes: 1 addition & 1 deletion Jukcraft/src/world/chunk/ChunkManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Jukcraft {
private:

std::shared_ptr<Chunk> chunks[WORLD_SIZE][WORLD_SIZE];
std::queue<std::shared_ptr<Chunk>> chunksToUpdates;
std::unordered_set<std::shared_ptr<Chunk>> chunksToUpdates;
std::unordered_set<std::shared_ptr<Chunk>> chunksToLight;
const std::vector<Block>& blocks;
gfx::Buffer chunkUbo;
Expand Down
3 changes: 3 additions & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ project "Jukcraft"
runtime "debug"
symbols "on"

defines "JUK_DEBUG"

filter "configurations:Beta"
runtime "debug"
optimize "on"
Expand All @@ -227,6 +229,7 @@ project "Jukcraft"

defines {
"GLM_FORCE_INLINE",
"JUK_BETA"
}

filter "configurations:Release"
Expand Down
3 changes: 0 additions & 3 deletions vendor/glad/Glad.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -101,7 +100,6 @@
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<FloatingPointModel>Fast</FloatingPointModel>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -127,7 +125,6 @@
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<FloatingPointModel>Fast</FloatingPointModel>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down

0 comments on commit 659949e

Please sign in to comment.