initial push

This commit is contained in:
sam 2024-04-12 00:16:29 +12:00
commit 97316cb334
65 changed files with 568 additions and 0 deletions

BIN
.vs/samcraft/v17/.suo Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

31
samcraft.sln Normal file
View file

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34525.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "samcraft", "samcraft\samcraft.vcxproj", "{9F1375E7-E000-4E27-B2C5-5311F7C817B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9F1375E7-E000-4E27-B2C5-5311F7C817B8}.Debug|x64.ActiveCfg = Debug|x64
{9F1375E7-E000-4E27-B2C5-5311F7C817B8}.Debug|x64.Build.0 = Debug|x64
{9F1375E7-E000-4E27-B2C5-5311F7C817B8}.Debug|x86.ActiveCfg = Debug|Win32
{9F1375E7-E000-4E27-B2C5-5311F7C817B8}.Debug|x86.Build.0 = Debug|Win32
{9F1375E7-E000-4E27-B2C5-5311F7C817B8}.Release|x64.ActiveCfg = Release|x64
{9F1375E7-E000-4E27-B2C5-5311F7C817B8}.Release|x64.Build.0 = Release|x64
{9F1375E7-E000-4E27-B2C5-5311F7C817B8}.Release|x86.ActiveCfg = Release|Win32
{9F1375E7-E000-4E27-B2C5-5311F7C817B8}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7C13A468-0079-4665-88C6-38CD2A885C00}
EndGlobalSection
EndGlobal

15
samcraft/chunk.c Normal file
View file

@ -0,0 +1,15 @@
#include "chunk.h"
vector3 index_to_coord(int i) {
vector3 pos;
pos.x = i % WIDTH;
pos.z = (i / WIDTH) % WIDTH;
pos.y = i / (WIDTH * WIDTH);
return pos;
}
int coord_to_index(vector3 coord) {
int index = coord.x + coord.z * WIDTH + coord.y * WIDTH * WIDTH;
return index;
}

12
samcraft/chunk.h Normal file
View file

@ -0,0 +1,12 @@
#ifndef __CHUNK_H__
#define __CHUNK_H__
#include "vector3.h"
#define WIDTH 5
#define HEIGHT 10
vector3 index_to_coord(int i);
int coord_to_index(vector3 pos);
#endif

160
samcraft/faces.h Normal file
View file

@ -0,0 +1,160 @@
#ifndef __FACES_H__
#define __FACES_H__
float bottom[] = {
-0.5f,
-0.5f,
-0.5f,
0.5f,
-0.5f,
-0.5f,
-0.5f,
-0.5f,
0.5f,
0.5f,
-0.5f,
-0.5f,
0.5f,
-0.5f,
0.5f,
-0.5f,
-0.5f,
0.5f,
};
float top[] = {
-0.5f,
0.5f,
-0.5f,
-0.5f,
0.5f,
0.5f,
0.5f,
0.5f,
-0.5f,
0.5f,
0.5f,
-0.5f,
-0.5f,
0.5f,
0.5f,
0.5f,
0.5f,
0.5f,
};
float front[] = {
-0.5f,
-0.5f,
0.5f,
0.5f,
-0.5f,
0.5f,
-0.5f,
0.5f,
0.5f,
0.5f,
-0.5f,
0.5f,
0.5f,
0.5f,
0.5f,
-0.5f,
0.5f,
0.5f,
};
float back[] = {
-0.5f,
-0.5f,
-0.5f,
-0.5f,
0.5f,
-0.5f,
0.5f,
-0.5f,
-0.5f,
0.5f,
-0.5f,
-0.5f,
-0.5f,
0.5f,
-0.5f,
0.5f,
0.5f,
-0.5f,
};
float right[] = {
0.5f,
-0.5f,
-0.5f,
0.5f,
0.5f,
0.5f,
0.5f,
-0.5f,
0.5f,
0.5f,
-0.5f,
-0.5f,
0.5f,
0.5f,
-0.5f,
0.5f,
0.5f,
0.5f,
};
float left[] = {
-0.5f,
-0.5f,
-0.5f,
-0.5f,
-0.5f,
0.5f,
-0.5f,
0.5f,
0.5f,
-0.5f,
-0.5f,
-0.5f,
-0.5f,
0.5f,
0.5f,
-0.5f,
0.5f,
-0.5f,
};
#endif

108
samcraft/main.c Normal file
View file

@ -0,0 +1,108 @@
#include <raylib.h>
#include <raymath.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "faces.h"
#include "chunk.h"
#include "vector3.h"
void add_face(Mesh* mesh, float* face, vector3 pos) {
int start = mesh->vertexCount * 3;
mesh->vertexCount += 6;
mesh->triangleCount += 2;
Mesh* ptr = realloc(mesh->vertices, (mesh->vertexCount * 3) * sizeof(float));
assert(ptr != NULL);
mesh->vertices = ptr;
for (int i = 0; i < 18; i += 3) {
mesh->vertices[start + i] = face[i] + pos.x;
mesh->vertices[start + i + 1] = face[i + 1] + pos.y;
mesh->vertices[start + i + 2] = face[i + 2] + pos.z;
}
}
int get_block_at(int* chunk, vector3 pos) {
if (pos.x < 0 || pos.x >= WIDTH || pos.z < 0 || pos.z >= WIDTH || pos.y < 0 || pos.y >= HEIGHT) return 0;
return chunk[coord_to_index(pos)];
}
Mesh gen_mesh(int* chunk) {
Mesh mesh = { 0 };
mesh.vertices = malloc(0);
mesh.vertexCount = 0;
for (int i = 0; i < WIDTH * WIDTH * HEIGHT; i++) {
if (chunk[i] == 0) continue;
vector3 pos = index_to_coord(i);
if(get_block_at(chunk, (vector3){ pos.x, pos.y - 1, pos.z }) == 0)
add_face(&mesh, bottom, pos);
if (get_block_at(chunk, (vector3) { pos.x, pos.y + 1, pos.z }) == 0)
add_face(&mesh, top, pos);
if (get_block_at(chunk, (vector3) { pos.x - 1, pos.y, pos.z }) == 0)
add_face(&mesh, left, pos);
if (get_block_at(chunk, (vector3) { pos.x + 1, pos.y, pos.z }) == 0)
add_face(&mesh, right, pos);
if (get_block_at(chunk, (vector3) { pos.x, pos.y, pos.z - 1 }) == 0)
add_face(&mesh, back, pos);
if (get_block_at(chunk, (vector3) { pos.x, pos.y, pos.z + 1 }) == 0)
add_face(&mesh, front, pos);
}
UploadMesh(&mesh, false);
printf("mesh generated, %d verts, %d tris\n", mesh.vertexCount, mesh.triangleCount);
return mesh;
}
int main() {
InitWindow(800, 600, "samcraft");
SetTargetFPS(60);
int* chunk = malloc(WIDTH * WIDTH * HEIGHT * sizeof(int));
assert(chunk != NULL);
for (int i = 0; i < WIDTH * WIDTH * HEIGHT; i++) {
chunk[i] = GetRandomValue(0, 1);
}
Mesh chunk_mesh = gen_mesh(chunk);
Material mat = LoadMaterialDefault();
Matrix matrix = MatrixIdentity();
Camera camera = { 0 };
camera.position = (Vector3){ 10.0f, 10.0f, 10.0f };
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
camera.projection = CAMERA_PERSPECTIVE;
camera.fovy = 70.0f;
while (!WindowShouldClose()) {
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
DisableCursor();
BeginDrawing();
{
ClearBackground(BLACK);
BeginMode3D(camera);
{
DrawMesh(chunk_mesh, mat, matrix);
DrawGrid(10, 10);
}
EndMode3D();
}
EndDrawing();
}
CloseWindow();
return 0;
}

141
samcraft/samcraft.vcxproj Normal file
View file

@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{9f1375e7-e000-4e27-b2c5-5311f7c817b8}</ProjectGuid>
<RootNamespace>samcraft</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="chunk.c" />
<ClCompile Include="main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="chunk.h" />
<ClInclude Include="faces.h" />
<ClInclude Include="vector3.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="chunk.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="faces.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="chunk.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="vector3.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

10
samcraft/vector3.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef __VECTOR3_H__
#define __VECTOR3_H__
typedef struct {
float x;
float y;
float z;
} vector3;
#endif

Binary file not shown.

BIN
samcraft/x64/Debug/main.obj Normal file

Binary file not shown.

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\sam\source\repos\samcraft\x64\Debug\samcraft.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>

Binary file not shown.

View file

@ -0,0 +1,5 @@
 main.c
C:\Users\sam\source\repos\samcraft\samcraft\main.c(19,17): warning C4133: '=': incompatible types - from 'Mesh *' to 'float *'
samcraft.vcxproj -> C:\Users\sam\source\repos\samcraft\x64\Debug\samcraft.exe
'pwsh.exe' is not recognized as an internal or external command,
operable program or batch file.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,2 @@
C:\Users\sam\source\repos\samcraft\samcraft\chunk.c;C:\Users\sam\source\repos\samcraft\samcraft\x64\Debug\chunk.obj
C:\Users\sam\source\repos\samcraft\samcraft\main.c;C:\Users\sam\source\repos\samcraft\samcraft\x64\Debug\main.obj

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.38.33130:TargetPlatformVersion=10.0.22621.0:VcpkgTriplet=x64-windows:
Debug|x64|C:\Users\sam\source\repos\samcraft\|

View file

@ -0,0 +1 @@
C:\Users\sam\source\repos\samcraft\samcraft\x64\Debug\samcraft.vcxproj.CopyComplete

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,2 @@

C:\Users\sam\source\repos\samcraft\x64\Debug\raylib.dll

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\sam\source\repos\samcraft\x64\Release\samcraft.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,10 @@
 main.c
C:\Users\sam\source\repos\samcraft\samcraft\main.c(19,17): warning C4133: '=': incompatible types - from 'Mesh *' to 'float *'
Generating code
1 of 10 functions (10.0%) were compiled, the rest were copied from previous compilation.
0 functions were new in current compilation
0 functions had inline decision re-evaluated but remain unchanged
Finished generating code
samcraft.vcxproj -> C:\Users\sam\source\repos\samcraft\x64\Release\samcraft.exe
'pwsh.exe' is not recognized as an internal or external command,
operable program or batch file.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,2 @@
C:\Users\sam\source\repos\samcraft\samcraft\chunk.c;C:\Users\sam\source\repos\samcraft\samcraft\x64\Release\chunk.obj
C:\Users\sam\source\repos\samcraft\samcraft\main.c;C:\Users\sam\source\repos\samcraft\samcraft\x64\Release\main.obj

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.38.33130:TargetPlatformVersion=10.0.22621.0:VcpkgTriplet=x64-windows:
Release|x64|C:\Users\sam\source\repos\samcraft\|

View file

@ -0,0 +1 @@
C:\Users\sam\source\repos\samcraft\samcraft\x64\Release\samcraft.vcxproj.CopyComplete

Binary file not shown.

View file

@ -0,0 +1,2 @@

C:\Users\sam\source\repos\samcraft\x64\Release\raylib.dll

BIN
x64/Debug/raylib.dll Normal file

Binary file not shown.

BIN
x64/Debug/samcraft.exe Normal file

Binary file not shown.

BIN
x64/Debug/samcraft.pdb Normal file

Binary file not shown.

BIN
x64/Release/raylib.dll Normal file

Binary file not shown.

BIN
x64/Release/samcraft.exe Normal file

Binary file not shown.

BIN
x64/Release/samcraft.pdb Normal file

Binary file not shown.