mirror of
https://github.com/Ed94/HandmadeHero.git
synced 2024-12-21 22:14:43 -08:00
Day 24 complete
This commit is contained in:
parent
4417738a6d
commit
465339743a
8
.vscode/bookmarks.json
vendored
8
.vscode/bookmarks.json
vendored
@ -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"
|
||||
}
|
||||
|
@ -15,18 +15,20 @@
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Development|x64'">
|
||||
<IncludePath>$(ProjectDir)project;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(ProjectDir)project;$(IncludePath);</IncludePath>
|
||||
<LibraryPath>$(ProjectDir)data;$(windir)System32;$(LibraryPath)</LibraryPath>
|
||||
<NMakeBuildCommandLine>pwsh -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(ProjectDir)scripts\build.ps1 msvc dev engine</NMakeBuildCommandLine>
|
||||
<NMakeCleanCommandLine>pwsh ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(ProjectDir)scripts\clean.ps1</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_TIME;Build_Development;Build_Debug;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<ExternalIncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath)</ExternalIncludePath>
|
||||
<ExternalIncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(UniversalCRT_IncludePath);</ExternalIncludePath>
|
||||
<NMakeReBuildCommandLine>
|
||||
</NMakeReBuildCommandLine>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="project\dependencies\gen.hpp" />
|
||||
<ClInclude Include="project\engine\engine.hpp" />
|
||||
<ClInclude Include="project\engine\engine_game_api.hpp" />
|
||||
<ClInclude Include="project\gen\engine_symbol_table.hpp" />
|
||||
<ClInclude Include="project\handmade.hpp" />
|
||||
<ClInclude Include="project\platform\generics.hpp" />
|
||||
<ClInclude Include="project\platform\grime.hpp" />
|
||||
@ -34,12 +36,13 @@
|
||||
<ClInclude Include="project\platform\macros.hpp" />
|
||||
<ClInclude Include="project\platform\math_constants.hpp" />
|
||||
<ClInclude Include="project\platform\platform.hpp" />
|
||||
<ClInclude Include="project\platform\platform_engine_api.hpp" />
|
||||
<ClInclude Include="project\platform\strings.hpp" />
|
||||
<ClInclude Include="project\platform\types.hpp" />
|
||||
<ClInclude Include="project\platform\win32.hpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="project\codegen\engine_postbuild_gen.cpp" />
|
||||
<ClCompile Include="project\codegen\platform_gen.cpp" />
|
||||
<ClCompile Include="project\engine\engine.cpp" />
|
||||
<ClCompile Include="project\handmade.cpp" />
|
||||
<ClCompile Include="project\handmade_engine.cpp" />
|
||||
@ -68,6 +71,11 @@
|
||||
<None Include="scripts\helpers\target_arch.psm1" />
|
||||
<None Include="scripts\update_deps.ps1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="project\codegen\Readme.md" />
|
||||
<Content Include="project\gen\Readme.md" />
|
||||
<Content Include="scripts\rebuild.ps1" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Development|x64'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
|
5
docs/Day 024.md
Normal file
5
docs/Day 024.md
Normal file
@ -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.
|
@ -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<String> 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<String> symbols = Array<String>::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("<symbol>");
|
||||
))));
|
||||
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("<symbol>");
|
||||
))));
|
||||
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("<symbol>");
|
||||
))));
|
||||
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("<symbol>");
|
||||
))));
|
||||
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("<symbol>");
|
||||
))));
|
||||
|
||||
|
@ -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 )
|
||||
|
@ -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;
|
||||
|
@ -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 >;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user