Skip to content

Commit

Permalink
Refactor, namespaces and day night cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Jukitsu committed Oct 19, 2023
1 parent 45b50e0 commit 18c526f
Show file tree
Hide file tree
Showing 85 changed files with 2,148 additions and 1,998 deletions.
14 changes: 7 additions & 7 deletions FaithfulMinecraftClone.sln → Jukcraft.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GLFW", "vendor\glfw\GLFW.vc
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Glad", "vendor\glad\Glad.vcxproj", "{BDD6857C-A90D-870D-52FA-6C103E10030F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MinecraftClone", "MinecraftClone\MinecraftClone.vcxproj", "{2F1A8EC6-1BE8-81CC-047C-F2F2F0E85D31}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Jukcraft", "Jukcraft\Jukcraft.vcxproj", "{DF39F0F5-CB06-4B01-F41F-39A9E04B808F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glm", "vendor\glm\glm.vcxitems", "{6577880B-D180-887C-5AFC-9E7CC604947C}"
EndProject
Expand All @@ -31,12 +31,12 @@ Global
{BDD6857C-A90D-870D-52FA-6C103E10030F}.Debug|x64.Build.0 = Debug|x64
{BDD6857C-A90D-870D-52FA-6C103E10030F}.Release|x64.ActiveCfg = Release|x64
{BDD6857C-A90D-870D-52FA-6C103E10030F}.Release|x64.Build.0 = Release|x64
{2F1A8EC6-1BE8-81CC-047C-F2F2F0E85D31}.Beta|x64.ActiveCfg = Beta|x64
{2F1A8EC6-1BE8-81CC-047C-F2F2F0E85D31}.Beta|x64.Build.0 = Beta|x64
{2F1A8EC6-1BE8-81CC-047C-F2F2F0E85D31}.Debug|x64.ActiveCfg = Debug|x64
{2F1A8EC6-1BE8-81CC-047C-F2F2F0E85D31}.Debug|x64.Build.0 = Debug|x64
{2F1A8EC6-1BE8-81CC-047C-F2F2F0E85D31}.Release|x64.ActiveCfg = Release|x64
{2F1A8EC6-1BE8-81CC-047C-F2F2F0E85D31}.Release|x64.Build.0 = Release|x64
{DF39F0F5-CB06-4B01-F41F-39A9E04B808F}.Beta|x64.ActiveCfg = Beta|x64
{DF39F0F5-CB06-4B01-F41F-39A9E04B808F}.Beta|x64.Build.0 = Beta|x64
{DF39F0F5-CB06-4B01-F41F-39A9E04B808F}.Debug|x64.ActiveCfg = Debug|x64
{DF39F0F5-CB06-4B01-F41F-39A9E04B808F}.Debug|x64.Build.0 = Debug|x64
{DF39F0F5-CB06-4B01-F41F-39A9E04B808F}.Release|x64.ActiveCfg = Release|x64
{DF39F0F5-CB06-4B01-F41F-39A9E04B808F}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
33 changes: 15 additions & 18 deletions MinecraftClone/MinecraftClone.vcxproj → Jukcraft/Jukcraft.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{2F1A8EC6-1BE8-81CC-047C-F2F2F0E85D31}</ProjectGuid>
<ProjectGuid>{DF39F0F5-CB06-4B01-F41F-39A9E04B808F}</ProjectGuid>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MinecraftClone</RootNamespace>
<RootNamespace>Jukcraft</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
Expand Down Expand Up @@ -56,23 +56,23 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>..\bin\Debug-windowsMinecraftClone\</OutDir>
<IntDir>..\bin-int\Debug-windowsMinecraftClone\</IntDir>
<TargetName>MinecraftClone</TargetName>
<OutDir>..\bin\Debug-windowsJukcraft\</OutDir>
<IntDir>..\bin-int\Debug-windowsJukcraft\</IntDir>
<TargetName>Jukcraft</TargetName>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Beta|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>..\bin\Beta-windowsMinecraftClone\</OutDir>
<IntDir>..\bin-int\Beta-windowsMinecraftClone\</IntDir>
<TargetName>MinecraftClone</TargetName>
<OutDir>..\bin\Beta-windowsJukcraft\</OutDir>
<IntDir>..\bin-int\Beta-windowsJukcraft\</IntDir>
<TargetName>Jukcraft</TargetName>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>..\bin\Release-windowsMinecraftClone\</OutDir>
<IntDir>..\bin-int\Release-windowsMinecraftClone\</IntDir>
<TargetName>MinecraftClone</TargetName>
<OutDir>..\bin\Release-windowsJukcraft\</OutDir>
<IntDir>..\bin-int\Release-windowsJukcraft\</IntDir>
<TargetName>Jukcraft</TargetName>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -91,7 +91,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>opengl32.lib;gdi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Beta|x64'">
Expand All @@ -117,7 +117,7 @@
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>opengl32.lib;gdi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down Expand Up @@ -146,7 +146,7 @@
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>opengl32.lib;gdi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand All @@ -159,8 +159,8 @@
<ClInclude Include="src\core\Window.h" />
<ClInclude Include="src\core\util.h" />
<ClInclude Include="src\pch.h" />
<ClInclude Include="src\renderer\gfx\buffers\DynamicBuffer.h" />
<ClInclude Include="src\renderer\Renderer.h" />
<ClInclude Include="src\renderer\gfx\buffers\DynamicBuffer.h" />
<ClInclude Include="src\renderer\gfx\objects\Buffer.h" />
<ClInclude Include="src\renderer\gfx\objects\Shader.h" />
<ClInclude Include="src\renderer\gfx\objects\VertexArray.h" />
Expand Down Expand Up @@ -197,9 +197,6 @@
<Project>{BDD6857C-A90D-870D-52FA-6C103E10030F}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="src\renderer\gfx\buffers\DynamicBuffer.inl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<Filter Include="renderer\gfx">
<UniqueIdentifier>{30E2E770-1C45-7715-C5CA-AFCBB10C4398}</UniqueIdentifier>
</Filter>
<Filter Include="renderer\gfx\buffers">
<UniqueIdentifier>{CC693B0B-B8F8-C4D4-6117-D9CF4D85D57A}</UniqueIdentifier>
</Filter>
<Filter Include="renderer\gfx\objects">
<UniqueIdentifier>{0949E6C7-F5D7-6F91-9EF6-838C8A648037}</UniqueIdentifier>
</Filter>
<Filter Include="renderer\models">
<UniqueIdentifier>{EF8827A6-5B14-956A-6425-185FD02FF16A}</UniqueIdentifier>
</Filter>
Expand Down Expand Up @@ -61,14 +67,17 @@
<ClInclude Include="src\renderer\Renderer.h">
<Filter>renderer</Filter>
</ClInclude>
<ClInclude Include="src\renderer\gfx\buffers\DynamicBuffer.h">
<Filter>renderer\gfx\buffers</Filter>
</ClInclude>
<ClInclude Include="src\renderer\gfx\objects\Buffer.h">
<Filter>renderer\gfx</Filter>
<Filter>renderer\gfx\objects</Filter>
</ClInclude>
<ClInclude Include="src\renderer\gfx\objects\Shader.h">
<Filter>renderer\gfx</Filter>
<Filter>renderer\gfx\objects</Filter>
</ClInclude>
<ClInclude Include="src\renderer\gfx\objects\VertexArray.h">
<Filter>renderer\gfx</Filter>
<Filter>renderer\gfx\objects</Filter>
</ClInclude>
<ClInclude Include="src\renderer\models\Model.h">
<Filter>renderer\models</Filter>
Expand All @@ -91,7 +100,6 @@
<ClInclude Include="src\world\chunk\util.h">
<Filter>world\chunk</Filter>
</ClInclude>
<ClInclude Include="src\renderer\gfx\buffers\DynamicBuffer.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\core\App.cpp">
Expand Down Expand Up @@ -130,7 +138,4 @@
<Filter>world\chunk</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="src\renderer\gfx\buffers\DynamicBuffer.inl" />
</ItemGroup>
</Project>
22 changes: 11 additions & 11 deletions MinecraftClone/Makefile → Jukcraft/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ endif

ifeq ($(config),debug)
RESCOMP = windres
TARGETDIR = ../bin/Debug-windowsMinecraftClone
TARGET = $(TARGETDIR)/MinecraftClone.exe
OBJDIR = ../bin-int/Debug-windowsMinecraftClone
TARGETDIR = ../bin/Debug-windowsJukcraft
TARGET = $(TARGETDIR)/Jukcraft.exe
OBJDIR = ../bin-int/Debug-windowsJukcraft
PCH = src/pch.h
GCH = $(OBJDIR)/$(notdir $(PCH)).gch
DEFINES += -DGLFW_INCLUDE_NONE
Expand All @@ -41,9 +41,9 @@ endif

ifeq ($(config),beta)
RESCOMP = windres
TARGETDIR = ../bin/Beta-windowsMinecraftClone
TARGET = $(TARGETDIR)/MinecraftClone.exe
OBJDIR = ../bin-int/Beta-windowsMinecraftClone
TARGETDIR = ../bin/Beta-windowsJukcraft
TARGET = $(TARGETDIR)/Jukcraft.exe
OBJDIR = ../bin-int/Beta-windowsJukcraft
PCH = src/pch.h
GCH = $(OBJDIR)/$(notdir $(PCH)).gch
DEFINES += -DGLFW_INCLUDE_NONE -DGLM_FORCE_INLINE
Expand All @@ -70,9 +70,9 @@ endif

ifeq ($(config),release)
RESCOMP = windres
TARGETDIR = ../bin/Release-windowsMinecraftClone
TARGET = $(TARGETDIR)/MinecraftClone.exe
OBJDIR = ../bin-int/Release-windowsMinecraftClone
TARGETDIR = ../bin/Release-windowsJukcraft
TARGET = $(TARGETDIR)/Jukcraft.exe
OBJDIR = ../bin-int/Release-windowsJukcraft
PCH = src/pch.h
GCH = $(OBJDIR)/$(notdir $(PCH)).gch
DEFINES += -DGLFW_INCLUDE_NONE -DGLM_FORCE_INLINE -DSPDLOG_NO_EXCEPTIONS
Expand Down Expand Up @@ -122,7 +122,7 @@ ifeq (.exe,$(findstring .exe,$(ComSpec)))
endif

$(TARGET): $(GCH) ${CUSTOMFILES} $(OBJECTS) $(LDDEPS) $(RESOURCES) | $(TARGETDIR)
@echo Linking MinecraftClone
@echo Linking Jukcraft
$(SILENT) $(LINKCMD)
$(POSTBUILDCMDS)

Expand All @@ -145,7 +145,7 @@ else
endif

clean:
@echo Cleaning MinecraftClone
@echo Cleaning Jukcraft
ifeq (posix,$(SHELLTYPE))
$(SILENT) rm -f $(TARGET)
$(SILENT) rm -rf $(OBJDIR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ layout(early_fragment_tests) in;

layout(location = 0) in VS_OUT {
vec3 v_TexCoords;
vec3 v_Light;
float v_Shading;
float v_Light;
} fs_In;

layout(binding = 0) uniform sampler2DArray u_TextureArraySampler;

layout(location = 0) out vec4 fragColor;

void main(void) {
fragColor = texture(u_TextureArraySampler, fs_In.v_TexCoords) * fs_In.v_Shading * fs_In.v_Light;
fragColor = texture(u_TextureArraySampler, fs_In.v_TexCoords) * vec4(fs_In.v_Light, 1.0f) * fs_In.v_Shading;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ layout(location = 1) in uint a_VertexLight;

layout(location = 0) out VS_OUT {
vec3 v_TexCoords;
vec3 v_Light;
float v_Shading;
float v_Light;
} vs_Out;

const vec2 c_TexCoords[4] = vec2[4] (
Expand All @@ -22,15 +22,26 @@ layout(std140, binding = 0) uniform u_Camera {
};

layout(location = 0) uniform vec3 u_ChunkPos;
layout(location = 1) uniform float u_Daylight;

void main(void) {
vec3 pos = u_ChunkPos + vec3(a_VertexData >> 17 & 0x1F, a_VertexData >> 22, a_VertexData >> 12 & 0x1F);

gl_Position = u_CameraTransforms * vec4(pos, 1.0f);

vs_Out.v_TexCoords = vec3(c_TexCoords[a_VertexData >> 10 & 0x3], a_VertexData >> 2 & 0xFF);
vs_Out.v_Shading = pow(float((a_VertexData & 0x3) + 2) / 5.0f, 2.2f);

uint blockLight = a_VertexLight & 0xF;
uint skyLight = (a_VertexLight >> 4) & 0xF;
vs_Out.v_Light = pow(0.8f, 15 - max(blockLight, skyLight));

float blocklightMultiplier = pow(0.8, 15.0 - blockLight);
float skylightMultiplier = pow(0.8, 15.0 - skyLight);

vs_Out.v_Light = vec3(
clamp(blocklightMultiplier * 1.5, skylightMultiplier * u_Daylight, 1.0),
clamp(blocklightMultiplier * 1.25, skylightMultiplier * u_Daylight, 1.0),
clamp(skylightMultiplier * (2.0 - pow(u_Daylight, 2)), blocklightMultiplier, 1.0)
);

vs_Out.v_Shading = pow(float((a_VertexData & 0x3) + 2) / 5.0f, 2.2f);
}
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
33 changes: 33 additions & 0 deletions Jukcraft/src/blocks/Block.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once
#include "renderer/models/Model.h"

namespace Jukcraft {
class Block {
public:
Block(const char*, BlockID id, const Model& model, const std::vector<uint8_t>& textures, bool transparent, uint8_t light)
:id(id), model(model), textures(textures), transparent(transparent), light(light) {
CHECK(textures.size() == model.getQuads().size(), "Texture layout does not match model");
}
bool isCube() const {
return model.getQuads().size() == 6;
}
constexpr const Model& getModel() const {
return model;
}
constexpr const std::vector<uint8_t>& getTextureLayout() const {
return textures;
}
constexpr bool isTransparent() const {
return transparent;
}
constexpr uint8_t getLight() const {
return light;
}
private:
BlockID id;
const Model& model;
std::vector<uint8_t> textures;
bool transparent;
uint8_t light;
};
}
Loading

0 comments on commit 18c526f

Please sign in to comment.