More pitch in voxel demo, vs project files
diff --git a/examples/voxel/voxel.cpp b/examples/voxel/voxel.cpp index 1bdc2f3..5464c73 100644 --- a/examples/voxel/voxel.cpp +++ b/examples/voxel/voxel.cpp
@@ -17,7 +17,9 @@ uint16_t *tiles[32][32]; std::vector<uint16_t *> free_tiles; -uint16_t tile_cache[32 * 32 * 130]; + +constexpr uint16_t tile_cache_size = 120; +uint16_t tile_cache[32 * 32 * tile_cache_size]; Vec3 position(64, 64, 100); float angle = 0.0f; @@ -49,7 +51,7 @@ } free_tiles.clear(); - for(uint8_t i = 0; i < 150; i++) { + for(uint8_t i = 0; i < tile_cache_size; i++) { free_tiles.push_back(&tile_cache[32 * 32 * i]); } } @@ -74,11 +76,6 @@ } uint16_t get_sample(int16_t x, int16_t y) { - /* if(x < 0 || y < 0 || x >= 1024 || y >= 1024) { - return 1; - }*/ - - // work out the tile coordinates for this sample uint8_t tx = (x >> 5) & 0x1f; uint8_t ty = (y >> 5) & 0x1f; @@ -141,17 +138,13 @@ float invz = 1.0f / z * 100.0f; // for each column on the screen... - for(uint8_t i = 0; i < screen.bounds.w; i++) { + for(uint16_t i = 0; i < screen.bounds.w; i++) { uint16_t sample = get_sample(sample_point.x, sample_point.y); uint8_t colour_index = sample >> 8; - // determine offset of sample from heightmap and colour map - //uint16_t sample_offset = (int8_t(sample_point.x) & 0x7f) + (int8_t(sample_point.y) & 0x7f) * 128; - - // convert the height map sample into a y coordinate on screen - - int height = (position.z - (sample & 0xff)) * invz + float(horizon) + sample_lean; + // convert the height map sample into a y coordinate on screen + int16_t height = (position.z - (sample & 0xff)) * invz + float(horizon) + sample_lean; // if the height is smaller (further up the screen) than our current height buffer // value then we need to draw a new vertical strip @@ -191,43 +184,16 @@ screen.pen = sky_colour; screen.clear(); - /* uint8_t buf[1024 * 32]; - uint8_t *p = (uint8_t *)_binary_demo_map_start; - uint32_t o = 0; - uint32_t v = 0; - uint32_t ms_start = now(); - for(int i = 0; i < 10000; i++) { - o += 1324; - o %= 1000000; - memcpy(buf, p + o, 1024); - v += buf[45]; - } - screen.text(std::to_string(v), &minimal_font[0][0], Point(10, 20));*/ uint32_t ms_start = now(); draw_world( position, // player position angle, // player direction lean, - 10.0f + pitch, // horizon position + 20.0f + pitch, // horizon position 3.0f, // near distance 300.0f // far distance ); -uint32_t ms_end = now(); - - - - - /* - - - sd_message = (char*)buffer;*/ - - uint8_t buffer[16 * 1024]; - //uint32_t ms_start = now(); - /*for(int i = 0; i < 10; i++) { - read_file(terrain_file, rand() & 0xffff, 16 * 1024, buffer); - }*/ - //uint32_t ms_end = now(); + uint32_t ms_end = now(); for(uint8_t y = 0; y < 32; y++) { for(uint8_t x = 0; x < 32; x++) { @@ -245,17 +211,6 @@ } } } -/* - for(uint8_t y = 0; y < 120; y++) { - for(uint8_t x = 0; x < 160; x++) { - uint16_t sample = get_sample(x * 2 + position.x, y * 2 + position.y); - uint8_t height = sample >> 8; - uint8_t colour_index = sample & 0xff; - screen.pen(colour_map_palette[height]); - //screen.pen(Pen(height, height, height)); - screen.pixel(Point(x, y)); - } - }*/ // work out the tile coordinates for the player position uint8_t tx = (int32_t(position.x) >> 5) & 0x1f; @@ -267,18 +222,12 @@ screen.watermark(); screen.mask = nullptr; screen.pen = Pen(255, 255, 255); - - screen.text(std::to_string(free_tiles.size()), minimal_font, Point(10, 20)); - -/* - screen.text(std::to_string(int(position.x)) + "," + std::to_string(int(position.y)), &minimal_font[0][0], Point(10, 10)); -*/ - screen.text(std::to_string(ms_end - ms_start), minimal_font, Point(1, 110)); + screen.text(std::to_string(ms_end - ms_start), minimal_font, Point(1, 230)); screen.pen = Pen(255, 0, 0); for (int i = 0; i < uint16_t(ms_end - ms_start); i++) { screen.pen = Pen(i * 5, 255 - (i * 5), 0); - screen.rectangle(Rect(i * 3 + 1, 117, 2, 2)); + screen.rectangle(Rect(i * 3 + 1, 237, 2, 2)); } } @@ -302,16 +251,10 @@ position.z -= 1.0f; } - // clip players z position to ensure they are above the ground - /* uint16_t sample_offset = (int8_t(position.x) & 0x7f) + (int8_t(position.y) & 0x7f) * 128; - if(position.z < (height_map[sample_offset] + 50)) { - position.z = height_map[sample_offset] + 50; - }*/ - // move player location if joystick y axis is forward/backwards position.x += sinf(deg2rad(angle)) * joystick.y; position.y += cosf(deg2rad(angle)) * joystick.y; - pitch = joystick.y * 10.0f; + pitch = joystick.y * 20.0f; position.x = position.x < 0.0f ? 1023.0f : position.x; position.y = position.y < 0.0f ? 1023.0f : position.y;
diff --git a/vs/32blit.sln b/vs/32blit.sln index d65389b..6b508b5 100644 --- a/vs/32blit.sln +++ b/vs/32blit.sln
@@ -153,6 +153,8 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{FA5CCE8B-0951-484A-8D0C-AA871780F4A3}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "voxel", "examples\voxel\voxel.vcxproj", "{2B7506AD-B420-4F2B-B002-6AAAF79D1E01}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -369,6 +371,14 @@ {D76C8D59-9C85-4D8A-8B78-7CAEE5DFC314}.Release|x64.Build.0 = Release|x64 {D76C8D59-9C85-4D8A-8B78-7CAEE5DFC314}.Release|x86.ActiveCfg = Release|Win32 {D76C8D59-9C85-4D8A-8B78-7CAEE5DFC314}.Release|x86.Build.0 = Release|Win32 + {2B7506AD-B420-4F2B-B002-6AAAF79D1E01}.Debug|x64.ActiveCfg = Debug|x64 + {2B7506AD-B420-4F2B-B002-6AAAF79D1E01}.Debug|x64.Build.0 = Debug|x64 + {2B7506AD-B420-4F2B-B002-6AAAF79D1E01}.Debug|x86.ActiveCfg = Debug|Win32 + {2B7506AD-B420-4F2B-B002-6AAAF79D1E01}.Debug|x86.Build.0 = Debug|Win32 + {2B7506AD-B420-4F2B-B002-6AAAF79D1E01}.Release|x64.ActiveCfg = Release|x64 + {2B7506AD-B420-4F2B-B002-6AAAF79D1E01}.Release|x64.Build.0 = Release|x64 + {2B7506AD-B420-4F2B-B002-6AAAF79D1E01}.Release|x86.ActiveCfg = Release|Win32 + {2B7506AD-B420-4F2B-B002-6AAAF79D1E01}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -398,6 +408,7 @@ {2E5A800D-8DD7-43EA-83C3-2E1ED6F547CB} = {E9DBB2E8-C9C5-4F46-9E6D-84D796FF4ABB} {479BBF48-BF4B-42AF-AF55-6D4E0A74C987} = {E9DBB2E8-C9C5-4F46-9E6D-84D796FF4ABB} {D76C8D59-9C85-4D8A-8B78-7CAEE5DFC314} = {FA5CCE8B-0951-484A-8D0C-AA871780F4A3} + {2B7506AD-B420-4F2B-B002-6AAAF79D1E01} = {E9DBB2E8-C9C5-4F46-9E6D-84D796FF4ABB} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A2B87694-5EB1-4C97-9262-7E18C4A3702E}
diff --git a/vs/examples/voxel/voxel.vcxproj b/vs/examples/voxel/voxel.vcxproj new file mode 100644 index 0000000..8870eac --- /dev/null +++ b/vs/examples/voxel/voxel.vcxproj
@@ -0,0 +1,173 @@ +<?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>16.0</VCProjectVersion> + <ProjectGuid>{2B7506AD-B420-4F2B-B002-6AAAF79D1E01}</ProjectGuid> + <RootNamespace>voxel</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>v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</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" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>_DEBUG;_CONSOLE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <AdditionalIncludeDirectories>..\..\..\32blit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <LanguageStandard>stdcpp14</LanguageStandard> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <AdditionalDependencies>32blit.lib;32blit-sdl.lib;SDL2.lib;SDL2main.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> + <AdditionalLibraryDirectories>$(OutputPath);$(SolutionDir)sdl\lib\$(PlatformTarget)\</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>_DEBUG;_CONSOLE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <AdditionalIncludeDirectories>..\..\..\32blit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <LanguageStandard>stdcpp14</LanguageStandard> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <AdditionalLibraryDirectories>$(OutputPath);$(SolutionDir)sdl\lib\$(PlatformTarget)\</AdditionalLibraryDirectories> + <AdditionalDependencies>32blit.lib;32blit-sdl.lib;SDL2.lib;SDL2main.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>NDEBUG;_CONSOLE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <AdditionalIncludeDirectories>..\..\..\32blit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <LanguageStandard>stdcpp14</LanguageStandard> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + <AdditionalLibraryDirectories>$(OutputPath);$(SolutionDir)sdl\lib\$(PlatformTarget)\</AdditionalLibraryDirectories> + <AdditionalDependencies>32blit.lib;32blit-sdl.lib;SDL2.lib;SDL2main.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>NDEBUG;_CONSOLE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <AdditionalIncludeDirectories>..\..\..\32blit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <LanguageStandard>stdcpp14</LanguageStandard> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + <AdditionalLibraryDirectories>$(OutputPath);$(SolutionDir)sdl\lib\$(PlatformTarget)\</AdditionalLibraryDirectories> + <AdditionalDependencies>32blit.lib;32blit-sdl.lib;SDL2.lib;SDL2main.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClInclude Include="..\..\..\examples\voxel\voxel.hpp" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="..\..\..\examples\voxel\voxel.cpp" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\32blit-sdl\32blit-sdl.vcxproj"> + <Project>{85db89b5-dea0-4429-b41e-0caa7db907ba}</Project> + </ProjectReference> + <ProjectReference Include="..\..\32blit\32blit.vcxproj"> + <Project>{280015a3-83d7-416f-a181-7cf88bcce12f}</Project> + </ProjectReference> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> \ No newline at end of file