diff --git a/.gitmodules b/.gitmodules index 0254b18..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "handmade-hero-notes"] - path = handmade-hero-notes - url = https://github.com/Ed94/handmade-hero-notes diff --git a/docs/Day 001.md b/docs/Day 001.md new file mode 100644 index 0000000..af559ce --- /dev/null +++ b/docs/Day 001.md @@ -0,0 +1,7 @@ +# Day 1 + +Project initially setup. Followed the video and the book. + +I went extra since I already have a perferred setup I've recently grown accoustmed to and I'm going to take advantage of the metaprogramming library I've recently made for myself. Although I doubt it'll see much action... + +I'll be keeping the code pretty C like as Casey does in the series. Main purpose is to be able to use whitebox. diff --git a/docs/Day 002.md b/docs/Day 002.md new file mode 100644 index 0000000..5eccb56 --- /dev/null +++ b/docs/Day 002.md @@ -0,0 +1,9 @@ +# Day 2 + +Pretty smooth so far, modular header library is showing its limitations... + +I have enough practice messsing with forwards and library linkage now that it wasn't much of a show stopper at least. All the mess is quarantined in the in win32.h and so far it looks like it will be enough to keep it all there. + +I added extra stuff in `grime.h`, `macros.h`, and `types.h` that he will either go over soon from my vauge memory last time I just watched him (instead of doing) + stuff from gencpp's version of the zpl library. + +![img](https://files.catbox.moe/wxasgz.png) diff --git a/docs/Day 003.md b/docs/Day 003.md new file mode 100644 index 0000000..f37e400 --- /dev/null +++ b/docs/Day 003.md @@ -0,0 +1,4 @@ +# Day 3 + +Was able to follow along just fine, lots of more `Gdi32`` stuff to forward in `win32.h`. + diff --git a/docs/Day 004.md b/docs/Day 004.md new file mode 100644 index 0000000..5c6c0db --- /dev/null +++ b/docs/Day 004.md @@ -0,0 +1,2 @@ +# Day 4 + diff --git a/docs/Day 011.md b/docs/Day 011.md new file mode 100644 index 0000000..c1a72af --- /dev/null +++ b/docs/Day 011.md @@ -0,0 +1,4 @@ +# Day 11 + +Architecture discussion was great. Did some diagramming of it. + diff --git a/docs/Visuals.afdesign b/docs/Visuals.afdesign new file mode 100644 index 0000000..bb87c7b Binary files /dev/null and b/docs/Visuals.afdesign differ diff --git a/handmade-hero-notes b/handmade-hero-notes deleted file mode 160000 index 5d1c77a..0000000 --- a/handmade-hero-notes +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5d1c77a44299fb8eddc4417cfe5e899289e555af diff --git a/project/engine.cpp b/project/engine.cpp new file mode 100644 index 0000000..4df59cb --- /dev/null +++ b/project/engine.cpp @@ -0,0 +1,61 @@ +#include "engine.h" + +NS_ENGINE_BEGIN + +internal void +render_weird_graident(OffscreenBuffer* buffer, u32 x_offset, u32 y_offset ) +{ + // TODO(Ed): See if with optimizer if buffer should be passed by value. + + struct Pixel { + u8 Blue; + u8 Green; + u8 Red; + u8 Alpha; + }; + + u8* row = rcast( u8*, buffer->Memory); + local_persist float wildcard = 0; + for ( u32 y = 0; y < buffer->Height; ++ y ) + { + // u8* pixel = rcast(u8*, row); + // Pixel* pixel = rcast( Pixel*, row ); + u32* pixel = rcast(u32*, row); + for ( u32 x = 0; x < buffer->Width; ++ x ) + { + /* Pixel in memory: + ----------------------------------------------- + Pixel + 0 Pixel + 1 Pixel + 2 Pixel + 3 + RR GG GG XX + ----------------------------------------------- + x86-64 : Little Endian Arch + 0x XX BB GG RR + */ + #if 0 + u8 blue = scast(u8, x + x_offset * u8(wildcard) % 256); + u8 green = scast(u8, y + y_offset - u8(wildcard) % 128); + u8 red = scast(u8, wildcard) % 256 - x * 0.4f; + #else + u8 blue = scast(u8, x + x_offset); + u8 green = scast(u8, y + y_offset); + u8 red = 0; + #endif + + + *pixel++ = (red << 16) | (green << 8) | blue; + } + wildcard += 0.5375f; + row += buffer->Pitch; + } +} + +internal +void update_and_render( OffscreenBuffer* back_buffer + // Temp (for feature parity) + , u32 x_offset, u32 y_offset +) +{ + render_weird_graident( back_buffer, x_offset, y_offset ); +} + +NS_ENGINE_END diff --git a/project/engine.h b/project/engine.h new file mode 100644 index 0000000..8ba7b7d --- /dev/null +++ b/project/engine.h @@ -0,0 +1,30 @@ +/* + Services the engine provides to the platform layer +*/ + +#pragma once + +#include "platform.h" + +#define NS_ENGINE_BEGIN namespace engine { +#define NS_ENGINE_END } + +NS_ENGINE_BEGIN + +struct OffscreenBuffer +{ + void* Memory; // Lets use directly mess with the "pixel's memory buffer" + u32 Width; + u32 Height; + u32 Pitch; + u32 BytesPerPixel; +}; + +// Needs a contextual reference to four things: +// Timing, Input, Bitmap Buffer, Sound Buffer +void update_and_render( OffscreenBuffer* back_buffer + // Temp (for feature parity) + , u32 x_offset, u32 y_offset +); + +NS_ENGINE_END diff --git a/project/handmace.cpp b/project/handmace.cpp new file mode 100644 index 0000000..482856c --- /dev/null +++ b/project/handmace.cpp @@ -0,0 +1,8 @@ +/* + Hnadmade Hero game code layer. +*/ + +#pragma once + +#include "engine.h" + diff --git a/project/handmade_win32.cpp b/project/platform/handmade_win32.cpp similarity index 93% rename from project/handmade_win32.cpp rename to project/platform/handmade_win32.cpp index 392573e..3d11f98 100644 --- a/project/handmade_win32.cpp +++ b/project/platform/handmade_win32.cpp @@ -1,3 +1,22 @@ +/* + TODO : This is not a final platform layer + + - Saved game locations + - Getting a handle to our own executable file + - Asset loading path + - Threading (launch a thread) + - Raw Input (support for multiple keyboards) + - Sleep / timeBeginPeriod + - ClipCursor() (for multimonitor support) + - Fullscreen support + - WM_SETCURSOR (control cursor visibility) + - QueryCancelAutoplay + - WM_ACTIVATEAPP (for when not active) + - Blit speed improvemnts (BitBlt) + - Hardware acceleration ( OpenGL or Direct3D or both ) + - GetKeyboardLayout (for French keyboards, international WASD support) +*/ + #if __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-const-variable" @@ -6,21 +25,19 @@ #pragma clang diagnostic ignored "-Wunknown-pragmas" #pragma clang diagnostic ignored "-Wvarargs" #pragma clang diagnostic ignored "-Wunused-function" +#pragma clang diagnostic ignored "-Wunused-but-set-variable" #endif -#include "grime.h" -#include "macros.h" -#include "types.h" -#include "math_constants.h" - -// #include - -// TODO : Implement sound ourselves -#include +#include // TODO : Implement math ourselves +// Platform Layer headers +#include "platform.h" +#include "jsl.h" // Using this to get dualsense controllers #include "win32.h" -// Using this to get dualsense controllers -#include "JoyShockLibrary/JoyShockLibrary.h" + +// Engine layer headers +#include "engine.h" + // TOOD(Ed): Redo these macros properly later. @@ -47,7 +64,6 @@ ensure_impl( bool condition, char const* message ) { JslSetLightColour( 0, (255 << 8 ) ); \ } while (0) - NS_WIN32_BEGIN // TODO(Ed) : This is a global for now. @@ -248,51 +264,6 @@ get_window_dimensions( HWND window_handle ) return result; } -internal void -render_weird_graident(OffscreenBuffer* buffer, u32 x_offset, u32 y_offset ) -{ - // TODO(Ed): See if with optimizer if buffer should be passed by value. - - struct Pixel { - u8 Blue; - u8 Green; - u8 Red; - u8 Alpha; - }; - - u8* row = rcast( u8*, buffer->Memory); - local_persist float wildcard = 0; - for ( u32 y = 0; y < buffer->Height; ++ y ) - { - // u8* pixel = rcast(u8*, row); - // Pixel* pixel = rcast( Pixel*, row ); - u32* pixel = rcast(u32*, row); - for ( u32 x = 0; x < buffer->Width; ++ x ) - { - /* Pixel in memory: - ----------------------------------------------- - Pixel + 0 Pixel + 1 Pixel + 2 Pixel + 3 - RR GG GG XX - ----------------------------------------------- - x86-64 : Little Endian Arch - 0x XX BB GG RR - */ - #if 0 - u8 blue = scast(u8, x + x_offset * u8(wildcard) % 256); - u8 green = scast(u8, y + y_offset - u8(wildcard) % 128); - u8 red = scast(u8, wildcard) % 256 - x * 0.4f; - #else - u8 blue = scast(u8, x + x_offset); - u8 green = scast(u8, y + y_offset); - u8 red = 0; - #endif - - *pixel++ = (red << 16) | (green << 8) | blue; - } - wildcard += 0.5375f; - row += buffer->Pitch; - } -} internal void resize_dib_section( OffscreenBuffer* buffer, u32 width, u32 height ) @@ -357,7 +328,7 @@ main_window_callback( LPARAM l_param ) { - LRESULT result; + LRESULT result = 0; switch ( system_messages ) { @@ -528,10 +499,9 @@ WinMain( } } - // MessageBox( 0, L"First message!", L"Handmade Hero", MB_Ok_Btn | MB_Icon_Information ); - WNDCLASS + WNDCLASSW window_class {}; window_class.style = CS_Horizontal_Redraw | CS_Vertical_Redraw; window_class.lpfnWndProc = main_window_callback; @@ -742,10 +712,10 @@ WinMain( } } + engine::update_and_render( rcast(engine::OffscreenBuffer*, & BackBuffer.Memory), x_offset, y_offset ); + // Rendering { - render_weird_graident( &BackBuffer, x_offset, y_offset ); - WinDimensions dimensions = get_window_dimensions( window_handle ); HDC device_context = GetDC( window_handle ); display_buffer_in_window( device_context, dimensions.Width, dimensions.Height, &BackBuffer @@ -865,3 +835,6 @@ WinMain( return 0; } + +// Engine layer translation unit. +#include "engine.cpp" diff --git a/project/platform/jsl.h b/project/platform/jsl.h new file mode 100644 index 0000000..056fc10 --- /dev/null +++ b/project/platform/jsl.h @@ -0,0 +1,12 @@ +// Joyshock grime wrapper + +#if __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" +#endif + +#include "JoyShockLibrary/JoyShockLibrary.h" + +#if __clang__ +#pragma clang diagnostic pop +#endif \ No newline at end of file diff --git a/project/platform/platform.h b/project/platform/platform.h new file mode 100644 index 0000000..1ef2ba6 --- /dev/null +++ b/project/platform/platform.h @@ -0,0 +1,11 @@ +/* + Platform abstraction layer for the project. + Services the platform provides to the engine & game. +*/ + +#pragma once +#include "grime.h" +#include "macros.h" +#include "math_constants.h" +#include "types.h" + diff --git a/project/platform/win32.h b/project/platform/win32.h index e7bde4e..ca7ad02 100644 --- a/project/platform/win32.h +++ b/project/platform/win32.h @@ -1,5 +1,5 @@ /* -Alternative header for windows.h + Windows dependency header */ #pragma once diff --git a/scripts/build.ps1 b/scripts/build.ps1 index a299cb4..ea50587 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -8,7 +8,9 @@ Push-Location $path_root #region Arguments $vendor = $null - $release = $null + $optimized = $false + $debug = $false + $analysis = $false [array] $vendors = @( "clang", "msvc" ) @@ -16,12 +18,13 @@ Push-Location $path_root if ( $args ) { $args | ForEach-Object { switch ($_){ - { $_ -in $vendors } { $vendor = $_; break } - "release" { $release = $true } - "debug" { $release = $false } + { $_ -in $vendors } { $vendor = $_; break } + "optimized" { $optimized = $true } + "debug" { $debug = $true } + "analysis" { $analysis = $true } } }} -#endregion Arguments +#endregion Argument #region Configuration if ($IsWindows) { @@ -47,10 +50,9 @@ function run-compiler { param( $compiler, $unit, $compiler_args ) - $compiler_args += @( - ($flag_define + 'UNICODE'), - ($flag_define + '_UNICODE') - ) + if ( $analysis ) { + $compiler_args += $flag_syntax_only + } write-host "`Compiling $unit" write-host "Compiler config:" @@ -109,28 +111,34 @@ function run-linker if ( $vendor -match "clang" ) { # https://clang.llvm.org/docs/ClangCommandLineReference.html + $flag_all_c = '/TC' + $flag_all_cpp = '/TP' $flag_compile = '-c' $flag_color_diagnostics = '-fcolor-diagnostics' $flag_no_color_diagnostics = '-fno-color-diagnostics' $flag_debug = '-g' $flag_debug_codeview = '-gcodeview' $flag_define = '-D' - $flag_exceptions_disabled = '-fno-exceptions' + $flag_exceptions_disabled = '-fno-exceptions' $flag_preprocess = '-E' $flag_include = '-I' $flag_library = '-l' $flag_library_path = '-L' $flag_link_win = '-Wl,' $flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE' + $flag_link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS' $flag_link_win_machine_32 = '/MACHINE:X86' $flag_link_win_machine_64 = '/MACHINE:X64' $flag_link_win_debug = '/DEBUG' $flag_link_win_pdb = '/PDB:' $flag_link_win_path_output = '/OUT:' $flag_no_optimization = '-O0' + $flag_optimize_fast = '-O2' + $flag_optimize_size = '-O1' $flag_path_output = '-o' $flag_preprocess_non_intergrated = '-no-integrated-cpp' $flag_profiling_debug = '-fdebug-info-for-profiling' + $flag_syntax_only = '-fsyntax-only' $flag_target_arch = '-target' $flag_wall = '-Wall' $flag_warning = '-W' @@ -169,10 +177,15 @@ if ( $vendor -match "clang" ) $flag_preprocess_non_intergrated, ( $flag_path_output + $object ) ) - if ( $release -eq $false ) { + if ( $optimized ) { + $compiler_args += $flag_optimize_fast + } + else { + $compiler_args += $flag_no_optimization + } + if ( $debug ) { $compiler_args += ( $flag_define + 'Build_Debug' ) $compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug - $compiler_args += $flag_no_optimization } $warning_ignores | ForEach-Object { @@ -187,12 +200,10 @@ if ( $vendor -match "clang" ) $flag_link_win_machine_64, $( $flag_link_win_path_output + $executable ) ) - if ( $release -eq $false ) { + if ( $debug ) { $linker_args += $flag_link_win_debug $linker_args += $flag_link_win_pdb + $pdb } - else { - } $libraries | ForEach-Object { $linker_args += $_ + '.lib' @@ -209,11 +220,13 @@ if ( $vendor -match "clang" ) if ( $vendor -match "msvc" ) { # https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170 + $flag_all_c = '/TC' + $flag_all_cpp = '/TP' $flag_compile = '/c' $flag_debug = '/Zi' $flag_define = '/D' - $flag_exceptions_disabled = '/EHs-c-' - $flag_RTTI_disabled = '/GR-' + $flag_exceptions_disabled = '/EHs-c-' + $flag_RTTI_disabled = '/GR-' $flag_include = '/I' $flag_full_src_path = '/FC' $flag_nologo = '/nologo' @@ -232,11 +245,15 @@ if ( $vendor -match "msvc" ) $flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE' $flag_link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS' $flag_no_optimization = '/Od' + $flag_optimize_fast = '/O2' + $flag_optimize_size = '/O1' + $flag_optimized_debug = '/Zo' $flag_out_name = '/OUT:' $flag_path_interm = '/Fo' $flag_path_debug = '/Fd' $flag_path_output = '/Fe' $flag_preprocess_conform = '/Zc:preprocessor' + $flag_syntax_only = '/Zs' # This works because this project uses a single unit to build function build-simple @@ -249,6 +266,7 @@ if ( $vendor -match "msvc" ) $compiler_args += @( $flag_nologo, + $flag_all_cpp, $flag_exceptions_disabled, ( $flag_define + '_HAS_EXCEPTIONS=0' ), $flag_RTTI_disabled, @@ -257,19 +275,33 @@ if ( $vendor -match "msvc" ) ( $flag_path_interm + $path_build + '\' ), ( $flag_path_output + $path_build + '\' ) ) - if ( $release -eq $false ) { + + if ( $optimize ) { + $compiler_args += $flag_optimize_fast + } + else { + $compiler_args += $flag_no_optimization + } + + if ( $debug ) + { $compiler_args += $flag_debug $compiler_args += ( $flag_define + 'Build_Debug' ) $compiler_args += ( $flag_path_debug + $path_build + '\' ) $compiler_args += $flag_link_win_rt_static_debug - $compiler_args += $flag_no_optimization + + if ( $optimized ) { + $compiler_args += $flag_optimized_debug + } } else { $compiler_args += $flag_link_win_rt_static } + $compiler_args += $includes | ForEach-Object { $flag_include + $_ } - $compiler_args += $flag_compile, $unit - run-compiler $compiler $unit $compiler_args + $compiler_args += $unit + # $compiler_args += $flag_compile, $unit + # run-compiler $compiler $unit $compiler_args $linker_args += @( $flag_nologo, @@ -284,7 +316,11 @@ if ( $vendor -match "msvc" ) } $linker_args += $object - run-linker $linker $executable $linker_args + # run-linker $linker $executable $linker_args + + $compiler_args += $flag_linker + $compiler_args += $linker_args + run-compiler $compiler $unit $compiler_args } $compiler = 'cl' @@ -354,10 +390,13 @@ $lib_user32 = 'User32.lib' # Github $lib_jsl = Join-Path $path_deps 'JoyShockLibrary/x64/JoyShockLibrary.lib' -$unit = Join-Path $path_project 'handmade_win32.cpp' -$executable = Join-Path $path_build 'handmade_win32.exe' +$unit = Join-Path $path_platform 'handmade_win32.cpp' +$executable = Join-Path $path_build 'handmade_win32.exe' -$compiler_args = @() +$compiler_args = @( + ($flag_define + 'UNICODE'), + ($flag_define + '_UNICODE') +) $linker_args = @( $lib_gdi32,