diff --git a/.vscode/bookmarks.json b/.vscode/bookmarks.json
index cdebe3b..e0b8318 100644
--- a/.vscode/bookmarks.json
+++ b/.vscode/bookmarks.json
@@ -14,22 +14,22 @@
"label": "Static Data"
},
{
- "line": 631,
+ "line": 640,
"column": 0,
"label": "Timing"
},
{
- "line": 1453,
+ "line": 1471,
"column": 4,
"label": "Main Loop : Audio Processing"
},
{
- "line": 1572,
+ "line": 1590,
"column": 2,
"label": "Main Loop : Timing Update"
},
{
- "line": 1656,
+ "line": 1674,
"column": 0,
"label": "Main Loop : End"
}
diff --git a/HandmadeHero.vcxproj b/HandmadeHero.vcxproj
index 35ef6ad..c35545b 100644
--- a/HandmadeHero.vcxproj
+++ b/HandmadeHero.vcxproj
@@ -15,18 +15,20 @@
- $(ProjectDir)project;$(IncludePath)
+ $(ProjectDir)project;$(IncludePath);
$(ProjectDir)data;$(windir)System32;$(LibraryPath)
pwsh -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(ProjectDir)scripts\build.ps1 msvc dev engine
pwsh ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(ProjectDir)scripts\clean.ps1
GEN_TIME;Build_Development;Build_Debug;$(NMakePreprocessorDefinitions)
- $(VC_IncludePath);$(WindowsSDK_IncludePath)
+ $(VC_IncludePath);$(WindowsSDK_IncludePath);$(UniversalCRT_IncludePath);
+
+
@@ -34,12 +36,13 @@
-
+
+
@@ -68,6 +71,11 @@
+
+
+
+
+
Makefile
true
diff --git a/docs/Day 024.md b/docs/Day 024.md
new file mode 100644
index 0000000..06fca40
--- /dev/null
+++ b/docs/Day 024.md
@@ -0,0 +1,5 @@
+# Day 24
+
+Did lots of cleanup & refactoring on my side.
+
+Started to use gencpp to generate the engne module symbol constants for the platform layer.
diff --git a/engine_symbol_table.hpp b/engine_symbol_table.hpp
deleted file mode 100644
index e69de29..0000000
diff --git a/project/codegen/engine_postbuild_gen.cpp b/project/codegen/engine_postbuild_gen.cpp
index ed1d866..7d197ad 100644
--- a/project/codegen/engine_postbuild_gen.cpp
+++ b/project/codegen/engine_postbuild_gen.cpp
@@ -18,7 +18,7 @@ using namespace gen;
constexpr StrC fname_handmade_engine_symbols = txt("handmade_engine.symbols");
-String get_symbol_from_module_table( FileContents symbol_table, u32 symbol_ID )
+void get_symbols_from_module_table( FileContents symbol_table, Array symbols )
{
struct Token
{
@@ -26,11 +26,8 @@ String get_symbol_from_module_table( FileContents symbol_table, u32 symbol_ID )
u32 Len;
};
- Token tokens[256] = {};
-
char const* scanner = rcast( char const*, symbol_table.data );
u32 left = symbol_table.size;
- u32 line = 0;
while ( left )
{
if ( *scanner == '\n' || *scanner == '\r' )
@@ -40,23 +37,17 @@ String get_symbol_from_module_table( FileContents symbol_table, u32 symbol_ID )
}
else
{
- tokens[line].Ptr = scanner;
+ Token token {};
+ token.Ptr = scanner;
while ( left && *scanner != '\r' && *scanner != '\n' )
{
-- left;
++ scanner;
- ++ tokens[line].Len;
+ ++ token.Len;
}
-
- if ( line == symbol_ID )
- {
- String result = String::make_length( GlobalAllocator, tokens[line].Ptr, tokens[line].Len );
- return result;
- }
- ++ line;
+ symbols.append( String::make_length( GlobalAllocator, token.Ptr, token.Len ) );
}
}
- return {};
}
int gen_main()
@@ -74,25 +65,24 @@ int gen_main()
builder.print( fmt_newline );
builder.print_fmt( "NS_ENGINE_BEGIN\n\n" );
- StrC symbol_on_module_load = get_symbol_from_module_table( symbol_table, engine::ModuleAPI::Sym_OnModuleReload );
- StrC symbol_startup = get_symbol_from_module_table( symbol_table, engine::ModuleAPI::Sym_Startup );
- StrC symbol_shutdown = get_symbol_from_module_table( symbol_table, engine::ModuleAPI::Sym_Shutdown );
- StrC symbol_update_and_render = get_symbol_from_module_table( symbol_table, engine::ModuleAPI::Sym_UpdateAndRender );
- StrC symbol_update_audio = get_symbol_from_module_table( symbol_table, engine::ModuleAPI::Sym_UpdateAudio );
+ Array symbols = Array::init_reserve( GlobalAllocator, kilobytes(1) );
+ get_symbols_from_module_table( symbol_table, symbols );
- builder.print( parse_variable( token_fmt( "symbol", symbol_on_module_load, stringize(
+ using ModuleAPI = engine::ModuleAPI;
+
+ builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_OnModuleReload], stringize(
constexpr const Str symbol_on_module_load = str_ascii("");
))));
- builder.print( parse_variable( token_fmt( "symbol", symbol_startup, stringize(
+ builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_Startup], stringize(
constexpr const Str symbol_startup = str_ascii("");
))));
- builder.print( parse_variable( token_fmt( "symbol", symbol_shutdown, stringize(
+ builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_Shutdown], stringize(
constexpr const Str symbol_shutdown = str_ascii("");
))));
- builder.print( parse_variable( token_fmt( "symbol", symbol_update_and_render, stringize(
+ builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_UpdateAndRender], stringize(
constexpr const Str symbol_update_and_render = str_ascii("");
))));
- builder.print( parse_variable( token_fmt( "symbol", symbol_update_audio, stringize(
+ builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_UpdateAudio], stringize(
constexpr const Str symbol_update_audio = str_ascii("");
))));
diff --git a/project/engine/engine.cpp b/project/engine/engine.cpp
index 06b61f0..5dadc35 100644
--- a/project/engine/engine.cpp
+++ b/project/engine/engine.cpp
@@ -150,12 +150,13 @@ render_weird_graident(OffscreenBuffer* buffer, u32 x_offset, u32 y_offset )
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;
+ u8 red = scast(u8, y + x_offset);
+ u8 green = scast(u8, x + y_offset);
+ u8 blue = scast(u8, x + y - x_offset - y_offset);
+ // blue *= 2;
#endif
- *pixel++ = u32(red << 16) | u32(green/2 << 16) | blue/2 << 0;
+ *pixel++ = u32(red/2 << 16) | u32(green/6 << 8) | blue/2 << 0;
}
wildcard += 0.5375f;
row += buffer->Pitch;
@@ -197,7 +198,11 @@ render_player( OffscreenBuffer* buffer, s32 pos_x, s32 pos_y )
internal
void begin_recording_input( EngineState* state, InputState* input, platform::ModuleAPI* platform_api )
{
- state->ActiveInputRecordingFile.Path = str_ascii("test_input.hmi");
+ Str file_name = str_ascii("test_input.hmi");
+ StrPath file_path = {};
+ file_path.concat( platform_api->path_scratch, file_name );
+
+ state->ActiveInputRecordingFile.Path = file_path;
state->InputRecordingIndex = 1;
// TODO(Ed) : If game persist memory is larger than 4 gb, this will need to be done in chunks...
@@ -215,9 +220,11 @@ internal
void begin_playback_input( EngineState* state, InputState* input, platform::ModuleAPI* platform_api )
{
Str file_name = str_ascii("test_input.hmi");
- if ( platform_api->file_check_exists( file_name ) )
+ StrPath file_path = {};
+ file_path.concat( platform_api->path_scratch, file_name );
+ if ( platform_api->file_check_exists( file_path ) )
{
- state->ActivePlaybackFile.Path = str_ascii("test_input.hmi");
+ state->ActivePlaybackFile.Path = file_path;
state->InputPlayingIndex = 1;
}
@@ -254,7 +261,7 @@ InputStateSnapshot input_state_snapshot( InputState* input )
if ( controller->Keyboard )
{
- snapshot.Controllers[idx].Keyboard = *controller->Keyboard;
+ snapshot.Controllers[idx].Keyboard = *controller->Keyboard;
}
if ( controller->Mouse )
diff --git a/project/platform/platform.hpp b/project/platform/platform.hpp
index 3d2fe81..2405c45 100644
--- a/project/platform/platform.hpp
+++ b/project/platform/platform.hpp
@@ -80,8 +80,9 @@ using FileRewindFn = void ( File* file );
struct ModuleAPI
{
- Str PathRoot;
- Str PathBinaries;
+ Str path_root;
+ Str path_binaries;
+ Str path_scratch;
#if Build_Development
DebugSetPauseRenderingFn* debug_set_pause_rendering;
diff --git a/project/platform/strings.hpp b/project/platform/strings.hpp
index 0b7eb57..8e08352 100644
--- a/project/platform/strings.hpp
+++ b/project/platform/strings.hpp
@@ -22,8 +22,7 @@ struct Str
str_append( Len, Data, src.Len, src.Data );
}
- static
- void concast( u32 dest_size, Str* dest, Str const str_a, Str const str_b )
+ void concat( u32 dest_size, Str* dest, Str const str_a, Str const str_b )
{
str_concat( dest_size, dest->Data
, str_a.Len, str_a.Data
@@ -42,8 +41,8 @@ struct Str
}
};
-template< u32 capacity >
// Fixed length raw strings.
+template< u32 capacity >
struct StrFixed
{
constexpr static u32 Capacity = capacity;
@@ -188,3 +187,5 @@ u32 str_length( char const* str )
return result;
}
+
+using StrPath = StrFixed< S16_MAX >;
diff --git a/project/platform/win32.hpp b/project/platform/win32.hpp
index 3618837..1182e03 100644
--- a/project/platform/win32.hpp
+++ b/project/platform/win32.hpp
@@ -84,9 +84,10 @@ enum MB : UINT
enum Mem : DWORD
{
- MEM_Commit_Zeroed = MEM_COMMIT,
- MEM_Reserve = MEM_RESERVE,
- MEM_Release = MEM_RELEASE,
+ MEM_Commit_Zeroed = MEM_COMMIT,
+ MEM_Reserve = MEM_RESERVE,
+ MEM_Release = MEM_RELEASE,
+ MEM_Use_Large_pages = MEM_LARGE_PAGES,
};
enum Page : DWORD
diff --git a/project/platform/win32_platform.cpp b/project/platform/win32_platform.cpp
index de6460e..8bb9a83 100644
--- a/project/platform/win32_platform.cpp
+++ b/project/platform/win32_platform.cpp
@@ -97,8 +97,9 @@ struct DirectSoundBuffer
};
#pragma region Static Data
-global StrFixed< S16_MAX > Path_Root;
-global StrFixed< S16_MAX > Path_Binaries;
+global StrPath Path_Root;
+global StrPath Path_Binaries;
+global StrPath Path_Scratch;
// TODO(Ed) : This is a global for now.
global b32 Running = false;
@@ -130,14 +131,19 @@ global f32 Engine_Frame_Target_MS = 1000.f / scast(f32, Engine_Refresh_Hz);
internal
FILETIME file_get_last_write_time( char const* path )
{
+ WIN32_FILE_ATTRIBUTE_DATA engine_dll_file_attributes = {};
+ GetFileAttributesExA( path, GetFileExInfoStandard, & engine_dll_file_attributes );
+
+ return engine_dll_file_attributes.ftLastWriteTime;
+#if 0
WIN32_FIND_DATAA dll_file_info = {};
HANDLE dll_file_handle = FindFirstFileA( path, & dll_file_info );
if ( dll_file_handle == INVALID_HANDLE_VALUE )
{
FindClose( dll_file_handle );
}
-
return dll_file_info.ftLastWriteTime;
+#endif
}
struct AudioTimeMarker
@@ -503,6 +509,9 @@ poll_input( engine::InputState* input, u32 jsl_num_devices, JSL_DeviceHandle* js
// Keyboard Polling
// Keyboards are unified for now.
{
+ // TODO(Ed): this needs to be moved out of heere when frames are detached from polling input.
+ input->Controllers[0].Keyboard = {};
+
constexpr u32 is_down = 0x80000000;
input_process_digital_btn( & old_keyboard->Q, & new_keyboard->Q, GetAsyncKeyState( 'Q' ), is_down );
input_process_digital_btn( & old_keyboard->E, & new_keyboard->E, GetAsyncKeyState( 'E' ), is_down );
@@ -685,7 +694,8 @@ display_buffer_in_window( HDC device_context, u32 window_width, u32 window_heigh
, x, y, width, height
, x, y, width, height
#endif
- , 0, 0, window_width, window_height
+ , 0, 0, buffer->Width, buffer->Height
+ // , 0, 0, window_width, window_height
, 0, 0, buffer->Width, buffer->Height
, buffer->Memory, & buffer->Info
, DIB_ColorTable_RGB, RO_Source_To_Dest );
@@ -1147,13 +1157,11 @@ WinMain( HINSTANCE instance, HINSTANCE prev_instance, LPSTR commandline, int sho
// Memory
engine::Memory engine_memory {};
{
- engine_memory.PersistentSize = megabytes( 128 );
- // engine_memory.FrameSize = megabytes( 64 );
- engine_memory.TransientSize = gigabytes( 2 );
+ u64 total_size = gigabytes( 4 );
- u64 total_size = engine_memory.PersistentSize
- // + engine_memory.FrameSize
- + engine_memory.TransientSize;
+ engine_memory.PersistentSize = total_size - megabytes( 128 );
+ // engine_memory.FrameSize = megabytes( 64 );
+ engine_memory.TransientSize = total_size - engine_memory.PersistentSize;
#if Build_Debug
void* base_address = rcast(void*, terabytes( 1 ));
@@ -1177,7 +1185,7 @@ WinMain( HINSTANCE instance, HINSTANCE prev_instance, LPSTR commandline, int sho
{
window_class.style = CS_Horizontal_Redraw | CS_Vertical_Redraw;
window_class.lpfnWndProc = main_window_callback;
- // window_class.cbClsExtra = ;
+ // window_class.cbClsExtra = ;about:blank#blocked
// window_class.cbWndExtra = ;
window_class.hInstance = instance;
// window_class.hIcon = ;
@@ -1193,13 +1201,13 @@ WinMain( HINSTANCE instance, HINSTANCE prev_instance, LPSTR commandline, int sho
}
window_handle = CreateWindowExW(
- // WS_EX_LAYERED | WS_EX_TOPMOST,
- WS_EX_LAYERED,
+ WS_EX_LAYERED | WS_EX_TOPMOST,
+ // WS_EX_LAYERED,
window_class.lpszClassName,
L"Handmade Hero",
WS_Overlapped_Window | WS_Initially_Visible,
CW_Use_Default, CW_Use_Default, // x, y
- 1100, 700, // width, height
+ CW_Use_Default, CW_Use_Default, // width, height
0, 0, // parent, menu
instance, 0 // instance, param
);
@@ -1212,7 +1220,7 @@ WinMain( HINSTANCE instance, HINSTANCE prev_instance, LPSTR commandline, int sho
}
}
// WinDimensions dimensions = get_window_dimensions( window_handle );
- resize_dib_section( &Surface_Back_Buffer, 1280, 720 );
+ resize_dib_section( &Surface_Back_Buffer, 1920, 1080 );
// Setup pathing
StrFixed< S16_MAX > path_pdb_lock {};
@@ -1247,11 +1255,21 @@ WinMain( HINSTANCE instance, HINSTANCE prev_instance, LPSTR commandline, int sho
Path_Engine_DLL_InUse.concat( Path_Binaries, FName_Engine_DLL_InUse );
path_pdb_lock.concat( Path_Binaries, FName_Engine_PDB_Lock );
+
+ Path_Scratch.concat( Path_Root, str_ascii("scratch") );
+ Path_Scratch.Data[ Path_Scratch.Len ] = '\\';
+ ++ Path_Scratch.Len;
+
+ CreateDirectoryA( Path_Scratch, 0 );
}
// Prepare platform API
ModuleAPI platform_api {};
{
+ platform_api.path_root = Path_Root;
+ platform_api.path_binaries = Path_Binaries;
+ platform_api.path_scratch = Path_Scratch;
+
#if Build_Development
platform_api.debug_set_pause_rendering = & debug_set_pause_rendering;
#endif
diff --git a/scripts/build.ps1 b/scripts/build.ps1
index 81d4535..21979b3 100644
--- a/scripts/build.ps1
+++ b/scripts/build.ps1
@@ -201,8 +201,7 @@ if ( $vendor -match "clang" )
$map = join-path $path_build (split-path $map -Leaf)
# The PDB file has to also be time-stamped so that we can reload the DLL at runtime
- $timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
- $pdb = $binary -replace '\.(exe|dll)$', "_$timestamp.pdb"
+ $pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
$compiler_args += @(
$flag_no_color_diagnostics,
@@ -322,8 +321,7 @@ if ( $vendor -match "msvc" )
$map = join-path $path_build (split-path $map -Leaf)
# The PDB file has to also be time-stamped so that we can reload the DLL at runtime
- $timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
- $pdb = $binary -replace '\.(exe|dll)$', "_$timestamp.pdb"
+ $pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
$compiler_args += @(
$flag_nologo,