mirror of
https://github.com/Ed94/HandmadeHero.git
synced 2024-12-22 06:14:45 -08:00
Day 28 complete!
This commit is contained in:
parent
faa0bacc07
commit
e1623995a7
23
.vscode/bookmarks.json
vendored
23
.vscode/bookmarks.json
vendored
@ -1,35 +1,20 @@
|
|||||||
{
|
{
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"path": "project/platform/win32_platform.cpp",
|
"path": "project/platform/win32/win32_platform.cpp",
|
||||||
"bookmarks": [
|
"bookmarks": [
|
||||||
{
|
{
|
||||||
"line": 59,
|
"line": 39,
|
||||||
"column": 0,
|
"column": 0,
|
||||||
"label": "Struct Defs"
|
"label": "Struct Defs"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"line": 98,
|
"line": 58,
|
||||||
"column": 0,
|
"column": 0,
|
||||||
"label": "Static Data"
|
"label": "Static Data"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"line": 661,
|
"line": 980,
|
||||||
"column": 0,
|
|
||||||
"label": "Timing"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"line": 1592,
|
|
||||||
"column": 4,
|
|
||||||
"label": "Main Loop : Audio Processing"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"line": 1713,
|
|
||||||
"column": 2,
|
|
||||||
"label": "Main Loop : Timing Update"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"line": 1797,
|
|
||||||
"column": 0,
|
"column": 0,
|
||||||
"label": "Main Loop : End"
|
"label": "Main Loop : End"
|
||||||
}
|
}
|
||||||
|
2
.vscode/c_cpp_properties.json
vendored
2
.vscode/c_cpp_properties.json
vendored
@ -12,6 +12,7 @@
|
|||||||
"UNICODE",
|
"UNICODE",
|
||||||
"_UNICODE",
|
"_UNICODE",
|
||||||
"GEN_TIME",
|
"GEN_TIME",
|
||||||
|
"INTELLISENSE_DIRECTIVES",
|
||||||
"Build_Debug",
|
"Build_Debug",
|
||||||
"Build_Development",
|
"Build_Development",
|
||||||
],
|
],
|
||||||
@ -31,6 +32,7 @@
|
|||||||
"UNICODE",
|
"UNICODE",
|
||||||
"_UNICODE",
|
"_UNICODE",
|
||||||
"GEN_TIME",
|
"GEN_TIME",
|
||||||
|
"INTELLISENSE_DIRECTIVES",
|
||||||
],
|
],
|
||||||
"windowsSdkVersion": "10.0.22621.0",
|
"windowsSdkVersion": "10.0.22621.0",
|
||||||
"compilerPath": "clang.exe",
|
"compilerPath": "clang.exe",
|
||||||
|
13
.vscode/launch.json
vendored
13
.vscode/launch.json
vendored
@ -16,11 +16,20 @@
|
|||||||
{
|
{
|
||||||
"type":"cppvsdbg",
|
"type":"cppvsdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name" : "Debug handmade platform gen msvc",
|
"name" : "Debug handmade engine (post_build) gen msvc",
|
||||||
"program": "${workspaceFolder}/build/engine_postbuild_gen.exe",
|
"program": "${workspaceFolder}/build/engine_postbuild_gen.exe",
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}/build",
|
"cwd": "${workspaceFolder}/build",
|
||||||
"visualizerFile": "${workspaceFolder}/scripts/handmade.natvis"
|
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type":"cppvsdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"name" : "Debug handmade platform gen msvc",
|
||||||
|
"program": "${workspaceFolder}/build/platform_gen.exe",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}/project/platform",
|
||||||
|
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,13 @@
|
|||||||
<ClInclude Include="project\dependencies\gen.hpp" />
|
<ClInclude Include="project\dependencies\gen.hpp" />
|
||||||
<ClInclude Include="project\engine\engine.hpp" />
|
<ClInclude Include="project\engine\engine.hpp" />
|
||||||
<ClInclude Include="project\engine\engine_game_api.hpp" />
|
<ClInclude Include="project\engine\engine_game_api.hpp" />
|
||||||
|
<ClInclude Include="project\engine\engine_to_platform_api.hpp" />
|
||||||
<ClInclude Include="project\gen\engine_symbol_table.hpp" />
|
<ClInclude Include="project\gen\engine_symbol_table.hpp" />
|
||||||
<ClInclude Include="project\handmade.hpp" />
|
<ClInclude Include="project\handmade.hpp" />
|
||||||
|
<ClInclude Include="project\platform\compiler_ignores.hpp" />
|
||||||
|
<ClInclude Include="project\platform\context.hpp" />
|
||||||
<ClInclude Include="project\platform\generics.hpp" />
|
<ClInclude Include="project\platform\generics.hpp" />
|
||||||
|
<ClInclude Include="project\platform\gen\context.gen.hpp" />
|
||||||
<ClInclude Include="project\platform\grime.hpp" />
|
<ClInclude Include="project\platform\grime.hpp" />
|
||||||
<ClInclude Include="project\platform\jsl.hpp" />
|
<ClInclude Include="project\platform\jsl.hpp" />
|
||||||
<ClInclude Include="project\platform\macros.hpp" />
|
<ClInclude Include="project\platform\macros.hpp" />
|
||||||
@ -39,14 +43,20 @@
|
|||||||
<ClInclude Include="project\platform\strings.hpp" />
|
<ClInclude Include="project\platform\strings.hpp" />
|
||||||
<ClInclude Include="project\platform\types.hpp" />
|
<ClInclude Include="project\platform\types.hpp" />
|
||||||
<ClInclude Include="project\platform\win32.hpp" />
|
<ClInclude Include="project\platform\win32.hpp" />
|
||||||
|
<ClInclude Include="project\platform\win32\win32.hpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="project\codegen\engine_postbuild_gen.cpp" />
|
<ClCompile Include="project\codegen\engine_postbuild_gen.cpp" />
|
||||||
<ClCompile Include="project\codegen\platform_gen.cpp" />
|
<ClCompile Include="project\codegen\platform_gen.cpp" />
|
||||||
<ClCompile Include="project\engine\engine.cpp" />
|
<ClCompile Include="project\engine\engine.cpp" />
|
||||||
|
<ClCompile Include="project\engine\test_samples.cpp" />
|
||||||
<ClCompile Include="project\handmade.cpp" />
|
<ClCompile Include="project\handmade.cpp" />
|
||||||
<ClCompile Include="project\handmade_engine.cpp" />
|
<ClCompile Include="project\handmade_engine.cpp" />
|
||||||
<ClCompile Include="project\handmade_win32.cpp" />
|
<ClCompile Include="project\handmade_win32.cpp" />
|
||||||
|
<ClCompile Include="project\platform\win32\win32_audio.cpp" />
|
||||||
|
<ClCompile Include="project\platform\win32\win32_input.cpp" />
|
||||||
|
<ClCompile Include="project\platform\win32\win32_platform.cpp" />
|
||||||
|
<ClCompile Include="project\platform\win32\win32_platform_api.cpp" />
|
||||||
<ClCompile Include="project\platform\win32_platform.cpp" />
|
<ClCompile Include="project\platform\win32_platform.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
BIN
data/binaries/handmade_engine.exp
Normal file
BIN
data/binaries/handmade_engine.exp
Normal file
Binary file not shown.
BIN
data/binaries/handmade_engine.lib
Normal file
BIN
data/binaries/handmade_engine.lib
Normal file
Binary file not shown.
BIN
data/binaries/handmade_win32.exp
Normal file
BIN
data/binaries/handmade_win32.exp
Normal file
Binary file not shown.
BIN
data/binaries/handmade_win32.lib
Normal file
BIN
data/binaries/handmade_win32.lib
Normal file
Binary file not shown.
@ -93,7 +93,7 @@ int gen_main()
|
|||||||
builder.write();
|
builder.write();
|
||||||
#pragma pop_macro("str_ascii")
|
#pragma pop_macro("str_ascii")
|
||||||
|
|
||||||
log_fmt("Generaton finished for Handmade Hero: Engine Module\n");
|
log_fmt("Generaton finished for Handmade Hero: Engine Module\n\n");
|
||||||
// gen::deinit();
|
// gen::deinit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,72 @@
|
|||||||
#include "dependencies/gen.hpp"
|
#include "dependencies/gen.hpp"
|
||||||
using namespace gen;
|
using namespace gen;
|
||||||
|
|
||||||
|
#define path_gen "./gen/"
|
||||||
|
|
||||||
|
|
||||||
int gen_main()
|
int gen_main()
|
||||||
{
|
{
|
||||||
gen::init();
|
gen::init();
|
||||||
log_fmt("Generating code for Handmade Hero: Platform Module\n");
|
log_fmt("Generating code for Handmade Hero: Platform Module\n");
|
||||||
log_fmt("Generaton finished for Handmade Hero: Platform Module\n");
|
|
||||||
|
CodeComment generation_notice = def_comment( txt("This was generated by project/codegen/platform_gen.cpp") );
|
||||||
|
|
||||||
|
Builder builder = Builder::open( path_gen "context.gen.hpp");
|
||||||
|
builder.print( generation_notice );
|
||||||
|
builder.print( fmt_newline );
|
||||||
|
|
||||||
|
FileContents h_context = file_read_contents(GlobalAllocator, true, "context.hpp");
|
||||||
|
CodeBody code_context = parse_global_body( { h_context.size, rcast( char const*, h_context.data ) } );
|
||||||
|
|
||||||
|
CodeStruct context_struct = {};
|
||||||
|
for ( Code code : code_context )
|
||||||
|
{
|
||||||
|
if ( code->Type == ECode::Struct )
|
||||||
|
{
|
||||||
|
if ( str_compare( code->Name, txt("Context") ) == 0 )
|
||||||
|
{
|
||||||
|
context_struct = code;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Array<Code> context_data_members = Array<Code>::init_reserve( GlobalAllocator, kilobytes( 1 ) );
|
||||||
|
for ( Code code : context_struct->Body )
|
||||||
|
{
|
||||||
|
if ( code->Type == ECode::Variable )
|
||||||
|
{
|
||||||
|
context_data_members.append( code );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeDefine using_context;
|
||||||
|
{
|
||||||
|
String using_context_content = String::make_reserve( GlobalAllocator, kilobytes( 1 ) );
|
||||||
|
{
|
||||||
|
String
|
||||||
|
content = using_context_content;
|
||||||
|
content.append( "\\\n" );
|
||||||
|
|
||||||
|
for ( s32 id = 0; id < context_data_members.num() - 1; ++id )
|
||||||
|
{
|
||||||
|
Code code = context_data_members[ id ];
|
||||||
|
content.append( code.to_string() );
|
||||||
|
|
||||||
|
// Default serializer inserts a newline at the end of the string, we need to insert a line continuation
|
||||||
|
content[ content.length() - 1 ] = '\\';
|
||||||
|
content.append( "\n" );
|
||||||
|
}
|
||||||
|
content.append( context_data_members[ context_data_members.num() - 1 ]->to_string() );
|
||||||
|
}
|
||||||
|
using_context = def_define( txt("using_context()"), using_context_content );
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.print( using_context );
|
||||||
|
builder.write();
|
||||||
|
|
||||||
|
log_fmt("Generaton finished for Handmade Hero: Platform Module\n\n");
|
||||||
// gen::deinit();
|
// gen::deinit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -18050,6 +18050,8 @@ namespace Parser
|
|||||||
);
|
);
|
||||||
return { { nullptr }, 0 };
|
return { { nullptr }, 0 };
|
||||||
}
|
}
|
||||||
|
move_forward();
|
||||||
|
content.Length++;
|
||||||
|
|
||||||
while ( left && current != '"' && current != '>' )
|
while ( left && current != '"' && current != '>' )
|
||||||
{
|
{
|
||||||
|
@ -30,15 +30,21 @@ struct EngineActions
|
|||||||
#if Build_Development
|
#if Build_Development
|
||||||
b32 pause_renderer;
|
b32 pause_renderer;
|
||||||
|
|
||||||
|
b32 load_auto_snapshot;
|
||||||
b32 set_snapshot_slot_1;
|
b32 set_snapshot_slot_1;
|
||||||
b32 set_snapshot_slot_2;
|
b32 set_snapshot_slot_2;
|
||||||
b32 set_snapshot_slot_3;
|
b32 set_snapshot_slot_3;
|
||||||
b32 set_snapshot_slot_4;
|
b32 set_snapshot_slot_4;
|
||||||
|
|
||||||
|
b32 force_null_access_violation;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EngineState
|
struct EngineState
|
||||||
{
|
{
|
||||||
|
f32 auto_snapshot_interval;
|
||||||
|
f32 auto_snapshot_timer;
|
||||||
|
|
||||||
s32 wave_tone_hz;
|
s32 wave_tone_hz;
|
||||||
s32 tone_volume;
|
s32 tone_volume;
|
||||||
s32 x_offset;
|
s32 x_offset;
|
||||||
@ -115,6 +121,7 @@ internal
|
|||||||
void take_engine_snapshot( Memory* memory, platform::ModuleAPI* platform_api )
|
void take_engine_snapshot( Memory* memory, platform::ModuleAPI* platform_api )
|
||||||
{
|
{
|
||||||
platform_api->memory_copy( memory->snapshots[ memory->active_snapshot_slot ].memory, memory->total_size(), memory->persistent );
|
platform_api->memory_copy( memory->snapshots[ memory->active_snapshot_slot ].memory, memory->total_size(), memory->persistent );
|
||||||
|
memory->snapshots[ memory->active_snapshot_slot ].age = platform_api->get_wall_clock();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
@ -128,6 +135,7 @@ void take_game_snapshot( Memory* memory, platform::ModuleAPI* platform_api )
|
|||||||
|
|
||||||
platform_api->memory_copy( persistent_slot, state->game_memory.persistent_size, state->game_memory.persistent );
|
platform_api->memory_copy( persistent_slot, state->game_memory.persistent_size, state->game_memory.persistent );
|
||||||
platform_api->memory_copy( transient_slot, state->game_memory.transient_size, state->game_memory.transient );
|
platform_api->memory_copy( transient_slot, state->game_memory.transient_size, state->game_memory.transient );
|
||||||
|
memory->snapshots[ memory->active_snapshot_slot ].age = platform_api->get_wall_clock();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
@ -300,7 +308,7 @@ void input_poll_engine_actions( InputState* input, EngineActions* actions )
|
|||||||
|
|
||||||
actions->toggle_wave_tone |= pressed( keyboard->Q );
|
actions->toggle_wave_tone |= pressed( keyboard->Q );
|
||||||
|
|
||||||
actions->loop_mode_game |= pressed( keyboard->L ) && ! keyboard->right_shift.ended_down;
|
actions->loop_mode_game |= pressed( keyboard->L ) && ! keyboard->right_shift.ended_down && ! keyboard->right_alt.ended_down;
|
||||||
actions->loop_mode_engine |= pressed( keyboard->L ) && keyboard->right_shift.ended_down;
|
actions->loop_mode_engine |= pressed( keyboard->L ) && keyboard->right_shift.ended_down;
|
||||||
|
|
||||||
MousesState* mouse = controller->mouse;
|
MousesState* mouse = controller->mouse;
|
||||||
@ -311,6 +319,7 @@ void input_poll_engine_actions( InputState* input, EngineActions* actions )
|
|||||||
actions->move_up = (mouse->vertical_wheel.end > 0.f) * 10;
|
actions->move_up = (mouse->vertical_wheel.end > 0.f) * 10;
|
||||||
actions->move_down = (mouse->vertical_wheel.end < 0.f) * 10;
|
actions->move_down = (mouse->vertical_wheel.end < 0.f) * 10;
|
||||||
|
|
||||||
|
actions->load_auto_snapshot |= pressed( keyboard->L ) && keyboard->right_alt.ended_down;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
@ -402,7 +411,14 @@ void draw_rectangle( OffscreenBuffer* buffer
|
|||||||
if ( max_y_32 > buffer_height )
|
if ( max_y_32 > buffer_height )
|
||||||
max_y_32 = buffer_height;
|
max_y_32 = buffer_height;
|
||||||
|
|
||||||
s32 color = (scast(s32, red) << 16) | (scast(s32, green) << 8) | (scast(s32, blue) << 0);
|
s32 red_32 = round_f32_to_s32( 255.f * red );
|
||||||
|
s32 green_32 = round_f32_to_s32( 255.f * green );
|
||||||
|
s32 blue_32 = round_f32_to_s32( 255.f * blue );
|
||||||
|
|
||||||
|
s32 color =
|
||||||
|
(scast(s32, red_32) << 16)
|
||||||
|
| (scast(s32, green_32) << 8)
|
||||||
|
| (scast(s32, blue_32) << 0);
|
||||||
|
|
||||||
// Start with the pixel on the top left corner of the rectangle
|
// Start with the pixel on the top left corner of the rectangle
|
||||||
u8* row = rcast(u8*, buffer->memory )
|
u8* row = rcast(u8*, buffer->memory )
|
||||||
@ -439,14 +455,18 @@ void startup( Memory* memory, platform::ModuleAPI* platform_api )
|
|||||||
memory->game_loop_active = false;
|
memory->game_loop_active = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
for ( s32 slot = 0; slot < memory->Num_Snapshot_Slots; ++ slot )
|
for ( s32 slot = 0; slot < memory->Num_Snapshot_Slots; ++ slot )
|
||||||
{
|
{
|
||||||
// TODO(Ed) : Specify default file paths for saving slots ?
|
// TODO(Ed) : Specify default file paths for saving slots ?
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
EngineState* state = rcast( EngineState*, memory->persistent );
|
EngineState* state = rcast( EngineState*, memory->persistent );
|
||||||
assert( sizeof(EngineState) <= memory->persistent_size );
|
assert( sizeof(EngineState) <= memory->persistent_size );
|
||||||
|
|
||||||
|
state->auto_snapshot_interval = 10.f;
|
||||||
|
|
||||||
state->tone_volume = 1000;
|
state->tone_volume = 1000;
|
||||||
|
|
||||||
state->x_offset = 0;
|
state->x_offset = 0;
|
||||||
@ -465,8 +485,8 @@ void startup( Memory* memory, platform::ModuleAPI* platform_api )
|
|||||||
hh::PlayerState* player = rcast( hh::PlayerState*, state->game_memory.persistent );
|
hh::PlayerState* player = rcast( hh::PlayerState*, state->game_memory.persistent );
|
||||||
assert( sizeof(hh::PlayerState) <= state->game_memory.persistent_size );
|
assert( sizeof(hh::PlayerState) <= state->game_memory.persistent_size );
|
||||||
|
|
||||||
player->pos_x = 100;
|
player->pos_x = 920;
|
||||||
player->pos_y = 100;
|
player->pos_y = 466;
|
||||||
player->mid_jump = false;
|
player->mid_jump = false;
|
||||||
player->jump_time = 0.f;
|
player->jump_time = 0.f;
|
||||||
}
|
}
|
||||||
@ -483,6 +503,22 @@ void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back
|
|||||||
EngineState* state = rcast( EngineState*, memory->persistent );
|
EngineState* state = rcast( EngineState*, memory->persistent );
|
||||||
assert( sizeof(EngineState) <= memory->persistent_size );
|
assert( sizeof(EngineState) <= memory->persistent_size );
|
||||||
|
|
||||||
|
// Engine auto_snapshot
|
||||||
|
{
|
||||||
|
state->auto_snapshot_timer += delta_time;
|
||||||
|
if ( state->auto_snapshot_timer >= state->auto_snapshot_interval )
|
||||||
|
{
|
||||||
|
state->auto_snapshot_timer = 0.f;
|
||||||
|
|
||||||
|
s32 current_slot = memory->active_snapshot_slot;
|
||||||
|
memory->active_snapshot_slot = 0;
|
||||||
|
|
||||||
|
take_engine_snapshot( memory, platform_api );
|
||||||
|
memory->active_snapshot_slot = current_slot;
|
||||||
|
state->auto_snapshot_timer = 0.f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ControllerState* controller = & input->controllers[0];
|
ControllerState* controller = & input->controllers[0];
|
||||||
|
|
||||||
EngineActions engine_actions {};
|
EngineActions engine_actions {};
|
||||||
@ -490,6 +526,14 @@ void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back
|
|||||||
|
|
||||||
input_poll_engine_actions( input, & engine_actions );
|
input_poll_engine_actions( input, & engine_actions );
|
||||||
|
|
||||||
|
if ( engine_actions.load_auto_snapshot )
|
||||||
|
{
|
||||||
|
s32 current_slot = memory->active_snapshot_slot;
|
||||||
|
memory->active_snapshot_slot = 0;
|
||||||
|
load_engine_snapshot( memory, platform_api );
|
||||||
|
memory->active_snapshot_slot = current_slot;
|
||||||
|
}
|
||||||
|
|
||||||
#if Build_Development
|
#if Build_Development
|
||||||
// Ease of use: Allow user to press L key without shift if engine loop recording is active.
|
// Ease of use: Allow user to press L key without shift if engine loop recording is active.
|
||||||
engine_actions.loop_mode_engine |= engine_actions.loop_mode_game && memory->engine_loop_active;
|
engine_actions.loop_mode_engine |= engine_actions.loop_mode_game && memory->engine_loop_active;
|
||||||
@ -571,10 +615,8 @@ void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back
|
|||||||
|
|
||||||
if ( ! memory->game_loop_active )
|
if ( ! memory->game_loop_active )
|
||||||
{
|
{
|
||||||
if ( engine_actions.set_snapshot_slot_1 ) memory->active_snapshot_slot = 0;
|
if ( engine_actions.set_snapshot_slot_1 ) memory->active_snapshot_slot = 1;
|
||||||
if ( engine_actions.set_snapshot_slot_2 ) memory->active_snapshot_slot = 1;
|
if ( engine_actions.set_snapshot_slot_2 ) memory->active_snapshot_slot = 2;
|
||||||
if ( engine_actions.set_snapshot_slot_3 ) memory->active_snapshot_slot = 2;
|
|
||||||
if ( engine_actions.set_snapshot_slot_4 ) memory->active_snapshot_slot = 3;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -599,14 +641,18 @@ void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back
|
|||||||
|
|
||||||
input_poll_player_actions( input, & player_actions );
|
input_poll_player_actions( input, & player_actions );
|
||||||
{
|
{
|
||||||
player->pos_x += player_actions.player_x_move_digital * 5;
|
f32 move_speed = 200.f;
|
||||||
player->pos_y -= player_actions.player_y_move_digital * 5;
|
|
||||||
player->pos_x += scast(u32, player_actions.player_x_move_analog * 5);
|
player->pos_x += scast(f32, player_actions.player_x_move_digital) * delta_time * move_speed;
|
||||||
player->pos_y -= scast(u32, player_actions.player_y_move_analog * 5) - scast(u32, sinf( player->jump_time * TAU ) * 10);
|
player->pos_y -= scast(f32, player_actions.player_y_move_digital) * delta_time * move_speed;
|
||||||
|
|
||||||
|
player->pos_x += scast(f32, player_actions.player_x_move_analog * delta_time * move_speed);
|
||||||
|
player->pos_y -= scast(f32, player_actions.player_y_move_analog * delta_time * move_speed);
|
||||||
|
player->pos_y += sinf( player->jump_time * TAU ) * 200.f * delta_time;
|
||||||
|
|
||||||
if ( player->jump_time > 0.f )
|
if ( player->jump_time > 0.f )
|
||||||
{
|
{
|
||||||
player->jump_time -= 0.025f;
|
player->jump_time -= delta_time;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -624,21 +670,97 @@ void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back
|
|||||||
f32 x_offset_f = scast(f32, state->x_offset);
|
f32 x_offset_f = scast(f32, state->x_offset);
|
||||||
f32 y_offset_f = scast(f32, state->y_offset);
|
f32 y_offset_f = scast(f32, state->y_offset);
|
||||||
|
|
||||||
// render_weird_graident( back_buffer, state->x_offset, state->y_offset );
|
|
||||||
draw_rectangle( back_buffer
|
draw_rectangle( back_buffer
|
||||||
, 0.f, 0.f
|
, 0.f, 0.f
|
||||||
, scast(f32, back_buffer->width), scast(f32, back_buffer->height)
|
, scast(f32, back_buffer->width), scast(f32, back_buffer->height)
|
||||||
, 0x22, 0x22, 0x22 );
|
, 1.f, 0.24f, 0.24f );
|
||||||
render_player( back_buffer, player->pos_x, player->pos_y );
|
|
||||||
|
// Draw tilemap
|
||||||
|
u32 tilemap[9][16] = {
|
||||||
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
|
||||||
|
{ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||||
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 },
|
||||||
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 },
|
||||||
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
|
{ 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||||
|
{ 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||||
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
|
||||||
|
{ 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
|
||||||
|
};
|
||||||
|
|
||||||
|
f32 upper_left_x = 0;
|
||||||
|
f32 upper_left_y = 0;
|
||||||
|
|
||||||
|
f32 tile_width = 119;
|
||||||
|
f32 tile_height = 116;
|
||||||
|
|
||||||
|
for ( s32 row = 0; row < 9; ++ row )
|
||||||
|
{
|
||||||
|
for ( s32 col = 0; col < 16; ++ col )
|
||||||
|
{
|
||||||
|
u32 tileID = tilemap[row][col];
|
||||||
|
f32 grey[3] = { 0.15f, 0.15f, 0.15f };
|
||||||
|
|
||||||
|
if ( tileID == 1 )
|
||||||
|
{
|
||||||
|
grey[0] = 0.22f;
|
||||||
|
grey[1] = 0.22f;
|
||||||
|
grey[2] = 0.22f;
|
||||||
|
}
|
||||||
|
|
||||||
|
f32 min_x = upper_left_x + scast(f32, col) * tile_width;
|
||||||
|
f32 min_y = upper_left_y + scast(f32, row) * tile_height;
|
||||||
|
f32 max_x = min_x + tile_width;
|
||||||
|
f32 max_y = min_y + tile_height;
|
||||||
|
|
||||||
|
draw_rectangle( back_buffer
|
||||||
|
, min_x, min_y
|
||||||
|
, max_x, max_y
|
||||||
|
, grey[0], grey[1], grey[2] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Player
|
||||||
|
f32 player_width = 50.f;
|
||||||
|
f32 player_height = 100.f;
|
||||||
|
|
||||||
|
f32 player_red = 0.3f;
|
||||||
|
f32 player_green = 0.3f;
|
||||||
|
f32 player_blue = 0.3f;
|
||||||
|
|
||||||
|
draw_rectangle( back_buffer
|
||||||
|
, player->pos_x, player->pos_y
|
||||||
|
, player->pos_x + player_width, player->pos_y + player_height
|
||||||
|
, player_red, player_green, player_blue );
|
||||||
|
|
||||||
|
// Auto-Snapshot percent bar
|
||||||
|
if (1)
|
||||||
|
{
|
||||||
|
f32 snapshot_percent_x = ((state->auto_snapshot_timer / state->auto_snapshot_interval)) * (f32)back_buffer->width / 4.f;
|
||||||
|
draw_rectangle( back_buffer
|
||||||
|
, 0.f, 0.f
|
||||||
|
, snapshot_percent_x, 10.f
|
||||||
|
, 0x00, 0.15f, 0.35f );
|
||||||
|
}
|
||||||
|
|
||||||
#if Build_Development
|
#if Build_Development
|
||||||
if ( memory->replay_mode == ReplayMode_Record )
|
if ( memory->replay_mode == ReplayMode_Record )
|
||||||
render_player( back_buffer, player->pos_x + 20, player->pos_y - 20 );
|
{
|
||||||
|
draw_rectangle( back_buffer
|
||||||
|
, scast(f32, player->pos_x) + 50.f, scast(f32, player->pos_y) - 50.f
|
||||||
|
, scast(f32, player->pos_x) + 10.f, scast(f32, player->pos_y) + 40.f
|
||||||
|
, 1.f, 1.f, 1.f );
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
render_player( back_buffer, (s32)input->controllers[0].mouse->X.end, (s32)input->controllers[0].mouse->Y.end );
|
// Change above to use draw rectangle
|
||||||
|
draw_rectangle( back_buffer
|
||||||
|
, (f32)input->controllers[0].mouse->X.end, (f32)input->controllers[0].mouse->Y.end
|
||||||
|
, (f32)input->controllers[0].mouse->X.end + 10.f, (f32)input->controllers[0].mouse->Y.end + 10.f
|
||||||
|
, 1.f, 1.f, 0.f );
|
||||||
|
|
||||||
// Mouse buttons test
|
// Mouse buttons test
|
||||||
|
#if 0
|
||||||
{
|
{
|
||||||
if ( input->controllers[0].mouse->left.ended_down == true )
|
if ( input->controllers[0].mouse->left.ended_down == true )
|
||||||
render_player( back_buffer, 5, 5 );
|
render_player( back_buffer, 5, 5 );
|
||||||
@ -650,6 +772,7 @@ void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back
|
|||||||
if ( input->controllers[0].mouse->right.ended_down == true )
|
if ( input->controllers[0].mouse->right.ended_down == true )
|
||||||
render_player( back_buffer, 5, 35 );
|
render_player( back_buffer, 5, 35 );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine_API
|
Engine_API
|
||||||
|
@ -35,6 +35,7 @@ struct MemorySnapshot
|
|||||||
void* opaque_handle;
|
void* opaque_handle;
|
||||||
void* opaque_handle_2;
|
void* opaque_handle_2;
|
||||||
void* memory;
|
void* memory;
|
||||||
|
u64 age;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Memory
|
struct Memory
|
||||||
@ -56,7 +57,7 @@ struct Memory
|
|||||||
// TODO(Ed) : Move this crap to state & replay archive definitions?
|
// TODO(Ed) : Move this crap to state & replay archive definitions?
|
||||||
#if Build_Development
|
#if Build_Development
|
||||||
static constexpr
|
static constexpr
|
||||||
s32 Num_Snapshot_Slots = 2;
|
s32 Num_Snapshot_Slots = 3;
|
||||||
// Abuse RAM to store snapshots of the Engine or Game state.
|
// Abuse RAM to store snapshots of the Engine or Game state.
|
||||||
MemorySnapshot snapshots[ Num_Snapshot_Slots ];
|
MemorySnapshot snapshots[ Num_Snapshot_Slots ];
|
||||||
s32 active_snapshot_slot;
|
s32 active_snapshot_slot;
|
||||||
|
@ -3,15 +3,12 @@
|
|||||||
|
|
||||||
NS_ENGINE_BEGIN
|
NS_ENGINE_BEGIN
|
||||||
|
|
||||||
constexpr
|
constexpr Str const symbol_on_module_load = str_ascii( "?on_module_reload@engine@@YAXPEAUMemory@1@PEAUModuleAPI@platform@@@Z" );
|
||||||
Str const symbol_on_module_load = str_ascii("?on_module_reload@engine@@YAXPEAUMemory@1@PEAUModuleAPI@platform@@@Z");
|
constexpr Str const symbol_startup = str_ascii( "?startup@engine@@YAXPEAUMemory@1@PEAUModuleAPI@platform@@@Z" );
|
||||||
constexpr
|
constexpr Str const symbol_shutdown = str_ascii( "?shutdown@engine@@YAXPEAUMemory@1@PEAUModuleAPI@platform@@@Z" );
|
||||||
Str const symbol_startup = str_ascii("?startup@engine@@YAXPEAUMemory@1@PEAUModuleAPI@platform@@@Z");
|
constexpr Str const symbol_update_and_render =
|
||||||
constexpr
|
str_ascii( "?update_and_render@engine@@YAXMPEAUInputState@1@PEAUOffscreenBuffer@1@PEAUMemory@1@PEAUModuleAPI@platform@@PEAUThreadContext@1@@Z" );
|
||||||
Str const symbol_shutdown = str_ascii("?shutdown@engine@@YAXPEAUMemory@1@PEAUModuleAPI@platform@@@Z");
|
constexpr Str const symbol_update_audio =
|
||||||
constexpr
|
str_ascii( "?update_audio@engine@@YAXMPEAUAudioBuffer@1@PEAUMemory@1@PEAUModuleAPI@platform@@PEAUThreadContext@1@@Z" );
|
||||||
Str const symbol_update_and_render = str_ascii("?update_and_render@engine@@YAXMPEAUInputState@1@PEAUOffscreenBuffer@1@PEAUMemory@1@PEAUModuleAPI@platform@@PEAUThreadContext@1@@Z");
|
|
||||||
constexpr
|
|
||||||
Str const symbol_update_audio = str_ascii("?update_audio@engine@@YAXMPEAUAudioBuffer@1@PEAUMemory@1@PEAUModuleAPI@platform@@PEAUThreadContext@1@@Z");
|
|
||||||
|
|
||||||
NS_ENGINE_END
|
NS_ENGINE_END
|
||||||
|
@ -70,8 +70,8 @@ struct Player
|
|||||||
|
|
||||||
struct PlayerState
|
struct PlayerState
|
||||||
{
|
{
|
||||||
s32 pos_x;
|
f32 pos_x;
|
||||||
s32 pos_y;
|
f32 pos_y;
|
||||||
|
|
||||||
b32 mid_jump;
|
b32 mid_jump;
|
||||||
f32 jump_time;
|
f32 jump_time;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "platform/compiler_ignores.hpp"
|
#include "platform/compiler_ignores.hpp"
|
||||||
|
|
||||||
#if Build_Unity
|
#if Build_Unity
|
||||||
#include "platform/win32_platform.cpp"
|
#include "platform/win32/win32_platform.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
15
project/platform/context.hpp
Normal file
15
project/platform/context.hpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "platform.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
struct Context
|
||||||
|
{
|
||||||
|
Context* parent;
|
||||||
|
// AllocatorInfo allocator;
|
||||||
|
// Logger logger;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Context* make_context();
|
||||||
|
|
||||||
|
|
||||||
|
#include "gen/context.gen.hpp"
|
3
project/platform/gen/context.gen.hpp
Normal file
3
project/platform/gen/context.gen.hpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// This was generated by project/codegen/platform_gen.cpp
|
||||||
|
|
||||||
|
#define using_context() Context* parent;
|
@ -67,47 +67,12 @@
|
|||||||
# define compiler_decorated_func_name __FUNCDNAME__
|
# define compiler_decorated_func_name __FUNCDNAME__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO(Ed) : Add this sauce later
|
#if Build_Development
|
||||||
#if 0
|
# define congrats( message ) platform::impl_congrats( message )
|
||||||
|
# define ensure( condition, message ) platform::impl_ensure( condition, message )
|
||||||
|
# define fatal( message ) platform::impl_fatal( message )
|
||||||
|
#else
|
||||||
# define congrats( message )
|
# define congrats( message )
|
||||||
#define ensure( condition, expression )
|
# define ensure( condition, message )
|
||||||
# define fatal( message )
|
# define fatal( message )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Just experimenting with a way to check for global variables being accessed from the wrong place.
|
|
||||||
// (Could also be done with gencpp technically)
|
|
||||||
#if 0
|
|
||||||
enum class EGlobalVarsAllowFuncs
|
|
||||||
{
|
|
||||||
ProcessPendingWindowMessages,
|
|
||||||
Num,
|
|
||||||
Invalid,
|
|
||||||
};
|
|
||||||
EGlobalVarsAllowFuncs to_type( char const* proc_name )
|
|
||||||
{
|
|
||||||
char const* global_vars_allowed_funcs[] {
|
|
||||||
"process_pending_window_messages"
|
|
||||||
};
|
|
||||||
|
|
||||||
if ( proc_name )
|
|
||||||
{
|
|
||||||
for ( u32 idx = 0; idx < array_count( global_vars_allowed_funcs ); ++idx )
|
|
||||||
{
|
|
||||||
if ( strcmp( proc_name, global_vars_allowed_funcs[idx] ) == 0 )
|
|
||||||
{
|
|
||||||
return scast( EGlobalVarsAllowFuncs, idx );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return EGlobalVarsAllowFuncs::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if Build_Development
|
|
||||||
# define checked_global_getter( global_var, procedure ) \
|
|
||||||
( ensure( to_type(procedure) != EGlobalVarsAllowFuncs::Invalid), global_var )
|
|
||||||
#else
|
|
||||||
# define checked_global_getter( global_var, procedure ) global_var
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "math_constants.hpp"
|
#include "math_constants.hpp"
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
#include "strings.hpp"
|
#include "strings.hpp"
|
||||||
|
#include "context.hpp"
|
||||||
|
|
||||||
#define NS_PLATFORM_BEGIN namespace platform {
|
#define NS_PLATFORM_BEGIN namespace platform {
|
||||||
#define NS_PLATFORM_END }
|
#define NS_PLATFORM_END }
|
||||||
@ -80,6 +81,8 @@ using FileRewindFn = void ( File* file );
|
|||||||
|
|
||||||
using MemoryCopyFn = void( void* dest, u64 src_size, void* src );
|
using MemoryCopyFn = void( void* dest, u64 src_size, void* src );
|
||||||
|
|
||||||
|
using GetWallClockFn = u64();
|
||||||
|
|
||||||
struct ModuleAPI
|
struct ModuleAPI
|
||||||
{
|
{
|
||||||
Str path_root;
|
Str path_root;
|
||||||
@ -90,6 +93,8 @@ struct ModuleAPI
|
|||||||
DebugSetPauseRenderingFn* debug_set_pause_rendering;
|
DebugSetPauseRenderingFn* debug_set_pause_rendering;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
GetWallClockFn* get_wall_clock;
|
||||||
|
|
||||||
GetMonitorRefreshRateFn* get_monitor_refresh_rate;
|
GetMonitorRefreshRateFn* get_monitor_refresh_rate;
|
||||||
SetMonitorRefreshRateFn* set_monitor_refresh_rate;
|
SetMonitorRefreshRateFn* set_monitor_refresh_rate;
|
||||||
|
|
||||||
@ -112,6 +117,12 @@ struct ModuleAPI
|
|||||||
MemoryCopyFn* memory_copy;
|
MemoryCopyFn* memory_copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if Build_Development
|
||||||
|
void impl_congrats( char const* message );
|
||||||
|
bool impl_ensure( bool condition, char const* message );
|
||||||
|
void impl_fatal( char const* message );
|
||||||
|
#endif
|
||||||
|
|
||||||
#pragma endregion Settings Exposure
|
#pragma endregion Settings Exposure
|
||||||
|
|
||||||
NS_PLATFORM_END
|
NS_PLATFORM_END
|
||||||
|
@ -1,187 +0,0 @@
|
|||||||
/*
|
|
||||||
Windows dependency header
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#pragma warning( push )
|
|
||||||
#pragma warning( disable: 5105 )
|
|
||||||
#pragma warning( disable: 4820 )
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
#include <xinput.h>
|
|
||||||
#include <mmeapi.h>
|
|
||||||
#include <dsound.h>
|
|
||||||
#include <timeapi.h>
|
|
||||||
#pragma warning( pop )
|
|
||||||
|
|
||||||
// #include "windows/windows_base.h"
|
|
||||||
// #include "windows/window.h"
|
|
||||||
|
|
||||||
// #include "windows/file.h"
|
|
||||||
// #include "windows/io.h"
|
|
||||||
|
|
||||||
// #if Build_Debug
|
|
||||||
// # include "windows/dbghelp.h"
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
#if Build_DLL
|
|
||||||
# define WIN_LIB_API extern "C" __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
# define WIN_LIB_API extern "C"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// #ifndef CONST
|
|
||||||
// # define CONST const
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
// SAL BS
|
|
||||||
#ifndef _In_
|
|
||||||
# define _In_
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define NS_WIN32_BEGIN namespace win32 {
|
|
||||||
#define NS_WIN32_END }
|
|
||||||
|
|
||||||
NS_WIN32_BEGIN
|
|
||||||
|
|
||||||
enum LWA : DWORD
|
|
||||||
{
|
|
||||||
LWA_Alpha = 0x00000002,
|
|
||||||
LWA_ColorKey = 0x00000001,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum BI : DWORD
|
|
||||||
{
|
|
||||||
BI_RGB_Uncompressed = 0L,
|
|
||||||
BI_RunLength_Encoded_8bpp = 1L,
|
|
||||||
BI_RunLength_Encoded_4bpp = 2L,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum CS : UINT
|
|
||||||
{
|
|
||||||
CS_Own_Device_Context = CS_OWNDC,
|
|
||||||
CS_Horizontal_Redraw = CS_HREDRAW,
|
|
||||||
CS_Vertical_Redraw = CS_VREDRAW,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum CW : s32
|
|
||||||
{
|
|
||||||
CW_Use_Default = CW_USEDEFAULT,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum DIB : UINT
|
|
||||||
{
|
|
||||||
DIB_ColorTable_RGB = 0,
|
|
||||||
DIB_ColorTable_Palette = 1
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
enum MB : UINT
|
|
||||||
{
|
|
||||||
MB_Ok_Btn = MB_OK,
|
|
||||||
MB_Icon_Information = MB_ICONINFORMATION,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Mem : DWORD
|
|
||||||
{
|
|
||||||
MEM_Commit_Zeroed = MEM_COMMIT,
|
|
||||||
MEM_Reserve = MEM_RESERVE,
|
|
||||||
MEM_Release = MEM_RELEASE,
|
|
||||||
MEM_Use_Large_pages = MEM_LARGE_PAGES,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Page : DWORD
|
|
||||||
{
|
|
||||||
Page_Read_Write = PAGE_READWRITE,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum PM : UINT
|
|
||||||
{
|
|
||||||
PM_Remove_Messages_From_Queue = PM_REMOVE,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum RasterOps : DWORD
|
|
||||||
{
|
|
||||||
RO_Source_To_Dest = (DWORD)0x00CC0020,
|
|
||||||
RO_Blackness = (DWORD)0x00000042,
|
|
||||||
RO_Whiteness = (DWORD)0x00FF0062,
|
|
||||||
};
|
|
||||||
|
|
||||||
#define WM_ACTIVATEAPP 0x001C
|
|
||||||
|
|
||||||
enum WS : UINT
|
|
||||||
{
|
|
||||||
WS_Overlapped_Window = WS_OVERLAPPEDWINDOW,
|
|
||||||
WS_Initially_Visible = WS_VISIBLE,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum XI_State : DWORD
|
|
||||||
{
|
|
||||||
XI_PluggedIn = ERROR_SUCCESS,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template< typename ProcSignature >
|
|
||||||
ProcSignature* get_procedure_from_library( HMODULE library_module, char const* symbol )
|
|
||||||
{
|
|
||||||
void* address = rcast( void*, GetProcAddress( library_module, symbol ) );
|
|
||||||
return rcast( ProcSignature*, address );
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma region XInput
|
|
||||||
WIN_LIB_API DWORD WINAPI XInputGetState
|
|
||||||
(
|
|
||||||
DWORD dwUserIndex, // Index of the gamer associated with the device
|
|
||||||
XINPUT_STATE* pState // Receives the current state
|
|
||||||
);
|
|
||||||
|
|
||||||
WIN_LIB_API DWORD WINAPI XInputSetState
|
|
||||||
(
|
|
||||||
DWORD dwUserIndex, // Index of the gamer associated with the device
|
|
||||||
XINPUT_VIBRATION* pVibration // The vibration information to send to the controller
|
|
||||||
);
|
|
||||||
|
|
||||||
DWORD WINAPI xinput_get_state_stub( DWORD dwUserIndex, XINPUT_STATE* pVibration ) {
|
|
||||||
do_once_start
|
|
||||||
OutputDebugStringA( "xinput_get_state stubbed!\n");
|
|
||||||
do_once_end
|
|
||||||
return ERROR_DEVICE_NOT_CONNECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD WINAPI xinput_set_state_stub( DWORD dwUserIndex, XINPUT_VIBRATION* pVibration ) {
|
|
||||||
do_once_start
|
|
||||||
OutputDebugStringA( "xinput_set_state stubbed!\n");
|
|
||||||
do_once_end
|
|
||||||
return ERROR_DEVICE_NOT_CONNECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
using XInputGetStateFn = DWORD WINAPI( DWORD dwUserIndex, XINPUT_STATE* pVibration );
|
|
||||||
using XInputSetStateFn = DWORD WINAPI( DWORD dwUserIndex, XINPUT_VIBRATION* pVibration );
|
|
||||||
|
|
||||||
global XInputGetStateFn* xinput_get_state = xinput_get_state_stub;
|
|
||||||
global XInputSetStateFn* xinput_set_state = xinput_set_state_stub;
|
|
||||||
|
|
||||||
internal void
|
|
||||||
xinput_load_library_bindings()
|
|
||||||
{
|
|
||||||
HMODULE xinput_lib = LoadLibraryA( XINPUT_DLL_A );
|
|
||||||
|
|
||||||
XInputGetStateFn* get_state = get_procedure_from_library< XInputGetStateFn >( xinput_lib, "XInputGetState" );
|
|
||||||
XInputSetStateFn* set_state = get_procedure_from_library< XInputSetStateFn >( xinput_lib, "XInputSetState" );
|
|
||||||
|
|
||||||
if ( get_state )
|
|
||||||
xinput_get_state = get_state;
|
|
||||||
|
|
||||||
if ( set_state )
|
|
||||||
xinput_set_state = set_state;
|
|
||||||
}
|
|
||||||
#pragma endregion XInput
|
|
||||||
|
|
||||||
NS_WIN32_END
|
|
||||||
#undef _SAL_nop_impl_
|
|
||||||
#undef _SAL2_Source_
|
|
||||||
#undef _Deref_post2_impl_
|
|
||||||
#undef _Outptr_result_bytebuffer_
|
|
||||||
#undef _At_
|
|
||||||
#undef _When_
|
|
||||||
#undef GDI_DIBSIZE
|
|
File diff suppressed because it is too large
Load Diff
171
scripts/.clang-format
Normal file
171
scripts/.clang-format
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
# Format Style Options - Created with Clang Power Tools
|
||||||
|
---
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
|
||||||
|
AlignAfterOpenBracket: BlockIndent
|
||||||
|
AlignArrayOfStructures: Left
|
||||||
|
AlignConsecutiveAssignments:
|
||||||
|
Enabled: true
|
||||||
|
AcrossEmptyLines: true
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: true
|
||||||
|
PadOperators: true
|
||||||
|
AlignConsecutiveBitFields:
|
||||||
|
Enabled: true
|
||||||
|
AcrossEmptyLines: true
|
||||||
|
AcrossComments: false
|
||||||
|
AlignConsecutiveDeclarations:
|
||||||
|
Enabled: true
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignConsecutiveMacros:
|
||||||
|
Enabled: true
|
||||||
|
AcrossEmptyLines: true
|
||||||
|
AcrossComments: false
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignOperands: DontAlign
|
||||||
|
|
||||||
|
AlignTrailingComments: true
|
||||||
|
|
||||||
|
AllowAllArgumentsOnNextLine: false
|
||||||
|
AllowAllConstructorInitializersOnNextLine: false
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortLambdasOnASingleLine: None
|
||||||
|
AllowShortEnumsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: None
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
|
||||||
|
BinPackArguments: false
|
||||||
|
BinPackParameters: false
|
||||||
|
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: false
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: false
|
||||||
|
SplitEmptyRecord: false
|
||||||
|
SplitEmptyNamespace: false
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
BeforeWhile: false
|
||||||
|
|
||||||
|
BreakAfterAttributes: Always
|
||||||
|
BreakArrays: true
|
||||||
|
# BreakBeforeInlineASMColon: OnlyMultiline
|
||||||
|
BreakBeforeBinaryOperators: NonAssignment
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
BreakBeforeInheritanceComma: true
|
||||||
|
BreakInheritanceList: BeforeComma
|
||||||
|
BreakBeforeConceptDeclarations: true
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializers: BeforeComma
|
||||||
|
BreakStringLiterals: true
|
||||||
|
|
||||||
|
ColumnLimit: 160
|
||||||
|
|
||||||
|
CompactNamespaces: true
|
||||||
|
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
|
ConstructorInitializerIndentWidth : 4
|
||||||
|
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
|
||||||
|
Cpp11BracedListStyle: false
|
||||||
|
|
||||||
|
DeriveLineEnding: true
|
||||||
|
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
|
||||||
|
FixNamespaceComments: true
|
||||||
|
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
|
||||||
|
IndentCaseBlocks: false
|
||||||
|
IndentCaseLabels: true
|
||||||
|
IndentExternBlock: AfterExternBlock
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentRequires: true
|
||||||
|
IndentWidth: 4
|
||||||
|
IndentWrappedFunctionNames: true
|
||||||
|
|
||||||
|
# InsertNewlineAtEOF: true
|
||||||
|
# InsertTrailingCommas: Wrapped
|
||||||
|
|
||||||
|
LambdaBodyIndentation: OuterScope
|
||||||
|
|
||||||
|
Language: Cpp
|
||||||
|
|
||||||
|
MaxEmptyLinesToKeep: 4
|
||||||
|
|
||||||
|
NamespaceIndentation: All
|
||||||
|
|
||||||
|
PointerAlignment: Left
|
||||||
|
|
||||||
|
QualifierAlignment: Leave
|
||||||
|
|
||||||
|
ReferenceAlignment: Left
|
||||||
|
|
||||||
|
ReflowComments: true
|
||||||
|
|
||||||
|
# RequiresExpressionIndentation: OuterScope
|
||||||
|
|
||||||
|
SeparateDefinitionBlocks: Always
|
||||||
|
|
||||||
|
ShortNamespaceLines: 40
|
||||||
|
|
||||||
|
SortIncludes: false
|
||||||
|
SortUsingDeclarations: false
|
||||||
|
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: true
|
||||||
|
SpaceAfterTemplateKeyword: false
|
||||||
|
|
||||||
|
SpaceAroundPointerQualifiers: Default
|
||||||
|
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: true
|
||||||
|
SpaceBeforeCpp11BracedList: true
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeParens: ControlStatementsExceptControlMacros
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
SpacesBeforeTrailingComments: 4
|
||||||
|
|
||||||
|
SpaceInEmptyBlock: true
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesInAngles: true
|
||||||
|
SpacesInCStyleCastParentheses: true
|
||||||
|
SpacesInConditionalStatement: true
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInLineCommentPrefix:
|
||||||
|
Minimum: 1
|
||||||
|
Maximum: 20
|
||||||
|
SpacesInParentheses: true
|
||||||
|
SpacesInSquareBrackets: true
|
||||||
|
|
||||||
|
Standard: c++17
|
||||||
|
|
||||||
|
TabWidth: 4
|
||||||
|
|
||||||
|
UseTab: ForIndentation
|
||||||
|
...
|
@ -1,11 +1,17 @@
|
|||||||
|
if ( $CursorPosition ) {
|
||||||
Clear-Host
|
Clear-Host
|
||||||
|
}
|
||||||
|
|
||||||
$target_arch = Join-Path $PSScriptRoot 'helpers/target_arch.psm1'
|
$target_arch = Join-Path $PSScriptRoot 'helpers/target_arch.psm1'
|
||||||
$devshell = Join-Path $PSScriptRoot 'helpers/devshell.ps1'
|
$devshell = Join-Path $PSScriptRoot 'helpers/devshell.ps1'
|
||||||
|
$format_cpp = Join-Path $PSScriptRoot 'helpers/format_cpp.psm1'
|
||||||
|
$config_toolchain = Join-Path $PSScriptRoot 'helpers/configure_toolchain.ps1'
|
||||||
|
|
||||||
$path_root = git rev-parse --show-toplevel
|
$path_root = git rev-parse --show-toplevel
|
||||||
$path_build = Join-Path $path_root 'build'
|
$path_build = Join-Path $path_root 'build'
|
||||||
|
|
||||||
Import-Module $target_arch
|
Import-Module $target_arch
|
||||||
|
Import-Module $format_cpp
|
||||||
|
|
||||||
Push-Location $path_root
|
Push-Location $path_root
|
||||||
|
|
||||||
@ -18,6 +24,7 @@ Push-Location $path_root
|
|||||||
$platform = $null
|
$platform = $null
|
||||||
$engine = $null
|
$engine = $null
|
||||||
$game = $null
|
$game = $null
|
||||||
|
$verbose = $null
|
||||||
|
|
||||||
[array] $vendors = @( "clang", "msvc" )
|
[array] $vendors = @( "clang", "msvc" )
|
||||||
|
|
||||||
@ -33,362 +40,13 @@ if ( $args ) { $args | ForEach-Object {
|
|||||||
"platform" { $platform = $true }
|
"platform" { $platform = $true }
|
||||||
"engine" { $engine = $true }
|
"engine" { $engine = $true }
|
||||||
"game" { $game = $true }
|
"game" { $game = $true }
|
||||||
|
"verbose" { $verbose = $true }
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
#endregion Argument
|
#endregion Argument
|
||||||
|
|
||||||
#region Toolchain Configuration
|
# Load up toolchain configuraion
|
||||||
if ($IsWindows) {
|
. $config_toolchain
|
||||||
# This HandmadeHero implementation is only designed for 64-bit systems
|
|
||||||
& $devshell -arch amd64
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $vendor -eq $null ) {
|
|
||||||
write-host "No vendor specified, assuming clang available"
|
|
||||||
$compiler = "clang"
|
|
||||||
}
|
|
||||||
|
|
||||||
write-host "Building HandmadeHero with $vendor"
|
|
||||||
|
|
||||||
if ( $dev ) {
|
|
||||||
if ( $debug -eq $null ) {
|
|
||||||
$debug = $true
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $optimize -eq $null ) {
|
|
||||||
$optimize = $false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function run-compiler
|
|
||||||
{
|
|
||||||
param( $compiler, $unit, $compiler_args )
|
|
||||||
|
|
||||||
if ( $analysis ) {
|
|
||||||
$compiler_args += $flag_syntax_only
|
|
||||||
}
|
|
||||||
|
|
||||||
write-host "`Compiling $unit"
|
|
||||||
write-host "Compiler config:"
|
|
||||||
$compiler_args | ForEach-Object {
|
|
||||||
write-host $_ -ForegroundColor Cyan
|
|
||||||
}
|
|
||||||
|
|
||||||
$time_taken = Measure-Command {
|
|
||||||
& $compiler $compiler_args 2>&1 | ForEach-Object {
|
|
||||||
$color = 'White'
|
|
||||||
switch ($_){
|
|
||||||
{ $_ -match "error" } { $color = 'Red' ; break }
|
|
||||||
{ $_ -match "warning" } { $color = 'Yellow'; break }
|
|
||||||
}
|
|
||||||
write-host `t $_ -ForegroundColor $color
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( Test-Path($unit) ) {
|
|
||||||
write-host "$unit compile finished in $($time_taken.TotalMilliseconds) ms"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
write-host "Compile failed for $unit" -ForegroundColor Red
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function run-linker
|
|
||||||
{
|
|
||||||
param( $linker, $binary, $linker_args )
|
|
||||||
|
|
||||||
write-host "`Linking $binary"
|
|
||||||
write-host "Linker config:"
|
|
||||||
$linker_args | ForEach-Object {
|
|
||||||
write-host $_ -ForegroundColor Cyan
|
|
||||||
}
|
|
||||||
|
|
||||||
$time_taken = Measure-Command {
|
|
||||||
& $linker $linker_args 2>&1 | ForEach-Object {
|
|
||||||
$color = 'White'
|
|
||||||
switch ($_){
|
|
||||||
{ $_ -match "error" } { $color = 'Red' ; break }
|
|
||||||
{ $_ -match "warning" } { $color = 'Yellow'; break }
|
|
||||||
}
|
|
||||||
write-host `t $_ -ForegroundColor $color
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( Test-Path($binary) ) {
|
|
||||||
write-host "$binary linking finished in $($time_taken.TotalMilliseconds) ms"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
write-host "Linking failed for $binary" -ForegroundColor Red
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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_preprocess = '-E'
|
|
||||||
$flag_include = '-I'
|
|
||||||
$flag_section_data = '-fdata-sections'
|
|
||||||
$flag_section_functions = '-ffunction-sections'
|
|
||||||
$flag_library = '-l'
|
|
||||||
$flag_library_path = '-L'
|
|
||||||
$flag_linker = '-Wl,'
|
|
||||||
if ( $IsWindows ) {
|
|
||||||
$flag_link_dll = '/DLL'
|
|
||||||
$flag_link_mapfile = '/MAP:'
|
|
||||||
$flag_link_optimize_references = '/OPT:REF'
|
|
||||||
}
|
|
||||||
if ( $IsLinux ) {
|
|
||||||
$flag_link_mapfile = '--Map='
|
|
||||||
$flag_link_optimize_references = '--gc-sections'
|
|
||||||
}
|
|
||||||
$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_optimize_intrinsics = '-Oi'
|
|
||||||
$flag_path_output = '-o'
|
|
||||||
$flag_preprocess_non_intergrated = '-no-integrated-cpp'
|
|
||||||
$flag_profiling_debug = '-fdebug-info-for-profiling'
|
|
||||||
$flag_set_stack_size = '-stack='
|
|
||||||
$flag_syntax_only = '-fsyntax-only'
|
|
||||||
$flag_target_arch = '-target'
|
|
||||||
$flag_wall = '-Wall'
|
|
||||||
$flag_warning = '-W'
|
|
||||||
$flag_warnings_as_errors = '-Werror'
|
|
||||||
$flag_win_nologo = '/nologo'
|
|
||||||
|
|
||||||
$ignore_warning_ms_include = 'no-microsoft-include'
|
|
||||||
$ignore_warning_return_type_c_linkage = 'no-return-type-c-linkage'
|
|
||||||
|
|
||||||
$target_arch = Get-TargetArchClang
|
|
||||||
|
|
||||||
$warning_ignores = @(
|
|
||||||
$ignore_warning_ms_include,
|
|
||||||
$ignore_warning_return_type_c_linkage
|
|
||||||
)
|
|
||||||
|
|
||||||
# https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170
|
|
||||||
$libraries = @(
|
|
||||||
'Kernel32' # For Windows API
|
|
||||||
# 'msvcrt', # For the C Runtime (Dynamically Linked)
|
|
||||||
# 'libucrt',
|
|
||||||
'libcmt' # For the C Runtime (Static Linkage)
|
|
||||||
)
|
|
||||||
|
|
||||||
function build-simple
|
|
||||||
{
|
|
||||||
param( [array]$includes, [array]$compiler_args, [array]$linker_args, [string]$unit, [string]$binary )
|
|
||||||
Write-Host "build-simple: clang"
|
|
||||||
|
|
||||||
$object = $unit -replace '\.cpp', '.obj'
|
|
||||||
$map = $unit -replace '\.cpp', '.map'
|
|
||||||
$object = join-path $path_build (split-path $object -Leaf)
|
|
||||||
$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
|
|
||||||
$pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
|
|
||||||
|
|
||||||
$compiler_args += @(
|
|
||||||
$flag_no_color_diagnostics,
|
|
||||||
$flag_exceptions_disabled,
|
|
||||||
$flag_target_arch, $target_arch,
|
|
||||||
$flag_wall,
|
|
||||||
$flag_preprocess_on_intergrated,
|
|
||||||
# $flag_section_data,
|
|
||||||
# $flag_section_functions,
|
|
||||||
( $flag_path_output + $object )
|
|
||||||
)
|
|
||||||
if ( $optimize ) {
|
|
||||||
$compiler_args += $flag_optimize_fast
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$compiler_args += $flag_no_optimization
|
|
||||||
}
|
|
||||||
if ( $debug ) {
|
|
||||||
$compiler_args += ( $flag_define + 'Build_Debug=1' )
|
|
||||||
$compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$compiler_args += ( $flag_define + 'Build_Debug=0' )
|
|
||||||
}
|
|
||||||
|
|
||||||
$warning_ignores | ForEach-Object {
|
|
||||||
$compiler_args += $flag_warning + $_
|
|
||||||
}
|
|
||||||
$compiler_args += $includes | ForEach-Object { $flag_include + $_ }
|
|
||||||
|
|
||||||
$compiler_args += $flag_compile, $unit
|
|
||||||
run-compiler $compiler $unit $compiler_args
|
|
||||||
|
|
||||||
$linker_args += @(
|
|
||||||
$flag_link_win_machine_64,
|
|
||||||
$( $flag_link_win_path_output + $binary )
|
|
||||||
)
|
|
||||||
if ( $debug ) {
|
|
||||||
$linker_args += $flag_link_win_debug
|
|
||||||
$linker_args += $flag_link_win_pdb + $pdb
|
|
||||||
$linker_args += $flag_link_mapfile + $map
|
|
||||||
}
|
|
||||||
|
|
||||||
$libraries | ForEach-Object {
|
|
||||||
$linker_args += $_ + '.lib'
|
|
||||||
}
|
|
||||||
|
|
||||||
$linker_args += $object
|
|
||||||
run-linker $linker $binary $linker_args
|
|
||||||
|
|
||||||
# $compiler_args += $unit
|
|
||||||
# $linker_args | ForEach-Object {
|
|
||||||
# $compiler_args += $flag_linker + $_
|
|
||||||
# }
|
|
||||||
# run-compiler $compiler $unit $compiler_args
|
|
||||||
}
|
|
||||||
|
|
||||||
$compiler = 'clang++'
|
|
||||||
$linker = 'lld-link'
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = '/EHsc-'
|
|
||||||
$flag_RTTI_disabled = '/GR-'
|
|
||||||
$flag_include = '/I'
|
|
||||||
$flag_full_src_path = '/FC'
|
|
||||||
$flag_nologo = '/nologo'
|
|
||||||
$flag_dll = '/LD'
|
|
||||||
$flag_dll_debug = '/LDd'
|
|
||||||
$flag_linker = '/link'
|
|
||||||
$flag_link_dll = '/DLL'
|
|
||||||
$flag_link_no_incremental = '/INCREMENTAL:NO'
|
|
||||||
$flag_link_mapfile = '/MAP:'
|
|
||||||
$flag_link_optimize_references = '/OPT:REF'
|
|
||||||
$flag_link_win_debug = '/DEBUG'
|
|
||||||
$flag_link_win_pdb = '/PDB:'
|
|
||||||
$flag_link_win_machine_32 = '/MACHINE:X86'
|
|
||||||
$flag_link_win_machine_64 = '/MACHINE:X64'
|
|
||||||
$flag_link_win_path_output = '/OUT:'
|
|
||||||
$flag_link_win_rt_dll = '/MD'
|
|
||||||
$flag_link_win_rt_dll_debug = '/MDd'
|
|
||||||
$flag_link_win_rt_static = '/MT'
|
|
||||||
$flag_link_win_rt_static_debug = '/MTd'
|
|
||||||
$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_optimize_intrinsics = '/Oi'
|
|
||||||
$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_set_stack_size = '/F'
|
|
||||||
$flag_syntax_only = '/Zs'
|
|
||||||
$flag_wall = '/Wall'
|
|
||||||
$flag_warnings_as_errors = '/WX'
|
|
||||||
|
|
||||||
# This works because this project uses a single unit to build
|
|
||||||
function build-simple
|
|
||||||
{
|
|
||||||
param( [array]$includes, [array]$compiler_args, [array]$linker_args, [string]$unit, [string]$binary )
|
|
||||||
Write-Host "build-simple: msvc"
|
|
||||||
|
|
||||||
$object = $unit -replace '\.(cpp)$', '.obj'
|
|
||||||
$map = $unit -replace '\.(cpp)$', '.map'
|
|
||||||
$object = join-path $path_build (split-path $object -Leaf)
|
|
||||||
$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
|
|
||||||
$pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
|
|
||||||
|
|
||||||
$compiler_args += @(
|
|
||||||
$flag_nologo,
|
|
||||||
# $flag_all_cpp,
|
|
||||||
$flag_exceptions_disabled,
|
|
||||||
( $flag_define + '_HAS_EXCEPTIONS=0' ),
|
|
||||||
$flag_RTTI_disabled,
|
|
||||||
$flag_preprocess_conform,
|
|
||||||
$flag_full_src_path,
|
|
||||||
( $flag_path_interm + $path_build + '\' ),
|
|
||||||
( $flag_path_output + $path_build + '\' )
|
|
||||||
)
|
|
||||||
|
|
||||||
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=1' )
|
|
||||||
$compiler_args += ( $flag_path_debug + $path_build + '\' )
|
|
||||||
$compiler_args += $flag_link_win_rt_static_debug
|
|
||||||
|
|
||||||
if ( $optimize ) {
|
|
||||||
$compiler_args += $flag_optimized_debug
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$compiler_args += ( $flag_define + 'Build_Debug=0' )
|
|
||||||
$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
|
|
||||||
|
|
||||||
$linker_args += @(
|
|
||||||
$flag_nologo,
|
|
||||||
$flag_link_win_machine_64,
|
|
||||||
$flag_link_no_incremental,
|
|
||||||
( $flag_link_win_path_output + $binary )
|
|
||||||
)
|
|
||||||
if ( $debug ) {
|
|
||||||
$linker_args += $flag_link_win_debug
|
|
||||||
$linker_args += $flag_link_win_pdb + $pdb
|
|
||||||
$linker_args += $flag_link_mapfile + $map
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
}
|
|
||||||
|
|
||||||
$linker_args += $object
|
|
||||||
run-linker $linker $binary $linker_args
|
|
||||||
|
|
||||||
# $compiler_args += $unit
|
|
||||||
# $compiler_args += $flag_linker
|
|
||||||
# $compiler_args += $linker_args
|
|
||||||
# run-compiler $compiler $unit $compiler_args
|
|
||||||
}
|
|
||||||
|
|
||||||
$compiler = 'cl'
|
|
||||||
$linker = 'link'
|
|
||||||
}
|
|
||||||
#endregion Configuration
|
|
||||||
|
|
||||||
#region Building
|
#region Building
|
||||||
$path_project = Join-Path $path_root 'project'
|
$path_project = Join-Path $path_root 'project'
|
||||||
@ -450,31 +108,31 @@ else {
|
|||||||
$compiler_args += ( $flag_define + 'Build_Development=0' )
|
$compiler_args += ( $flag_define + 'Build_Development=0' )
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $engine )
|
function build-engine
|
||||||
{
|
{
|
||||||
$path_pdb_lock = Join-Path $path_binaries 'handmade_engine.pdb.lock'
|
$path_pdb_lock = Join-Path $path_binaries 'handmade_engine.pdb.lock'
|
||||||
New-Item $path_pdb_lock -ItemType File -Force -Verbose
|
New-Item $path_pdb_lock -ItemType File -Force
|
||||||
|
|
||||||
# Delete old PDBs
|
# Delete old PDBs
|
||||||
[Array]$pdb_files = Get-ChildItem -Path $path_binaries -Filter "handmade_engine_*.pdb"
|
[Array]$pdb_files = Get-ChildItem -Path $path_binaries -Filter "handmade_engine_*.pdb"
|
||||||
foreach ($file in $pdb_files) {
|
foreach ($file in $pdb_files) {
|
||||||
Remove-Item -Path $file.FullName -Force
|
Remove-Item -Path $file.FullName -Force
|
||||||
Write-Host "Deleted $file" -ForegroundColor Green
|
if ( $verbose ) { Write-Host "Deleted $file" -ForegroundColor Green }
|
||||||
}
|
}
|
||||||
|
|
||||||
$engine_compiler_args = $compiler_args
|
$local:compiler_args = $script:compiler_args
|
||||||
$engine_compiler_args += ($flag_define + 'Build_DLL=1' )
|
$compiler_args += ($flag_define + 'Build_DLL=1' )
|
||||||
|
|
||||||
if ( $vendor -eq 'msvc' )
|
if ( $vendor -eq 'msvc' )
|
||||||
{
|
{
|
||||||
$engine_compiler_args += ($flag_define + 'Engine_API=__declspec(dllexport)')
|
$compiler_args += ($flag_define + 'Engine_API=__declspec(dllexport)')
|
||||||
}
|
}
|
||||||
if ( $vendor -eq 'clang' )
|
if ( $vendor -eq 'clang' )
|
||||||
{
|
{
|
||||||
$engine_compiler_args += ($flag_define + 'Engine_API=__attribute__((visibility("default")))')
|
$compiler_args += ($flag_define + 'Engine_API=__attribute__((visibility("default")))')
|
||||||
}
|
}
|
||||||
|
|
||||||
$linker_args = @(
|
$local:linker_args = @(
|
||||||
$flag_link_dll
|
$flag_link_dll
|
||||||
# $flag_link_optimize_references
|
# $flag_link_optimize_references
|
||||||
)
|
)
|
||||||
@ -482,8 +140,13 @@ if ( $engine )
|
|||||||
$unit = Join-Path $path_project 'handmade_engine.cpp'
|
$unit = Join-Path $path_project 'handmade_engine.cpp'
|
||||||
$dynamic_library = Join-Path $path_binaries 'handmade_engine.dll'
|
$dynamic_library = Join-Path $path_binaries 'handmade_engine.dll'
|
||||||
|
|
||||||
build-simple $includes $engine_compiler_args $linker_args $unit $dynamic_library
|
build-simple $includes $compiler_args $linker_args $unit $dynamic_library
|
||||||
|
|
||||||
|
Remove-Item $path_pdb_lock -Force
|
||||||
|
|
||||||
|
#region CodeGen Post-Build
|
||||||
|
if ( -not $handmade_process_active ) {
|
||||||
|
# Create the symbol table
|
||||||
if ( Test-Path $dynamic_library )
|
if ( Test-Path $dynamic_library )
|
||||||
{
|
{
|
||||||
# $data_path = Join-Path $path_data 'handmade_engine.dll'
|
# $data_path = Join-Path $path_data 'handmade_engine.dll'
|
||||||
@ -541,11 +204,11 @@ if ( $engine )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
write-host "Engine Symbol Table:" -ForegroundColor Green
|
if ($verbose) { write-host "Engine Symbol Table:" -ForegroundColor Green }
|
||||||
$engine_symbols.GetEnumerator() | ForEach-Object {
|
$engine_symbols.GetEnumerator() | ForEach-Object {
|
||||||
$paddedName = $_.Key.PadRight($maxNameLength)
|
$paddedName = $_.Key.PadRight($maxNameLength)
|
||||||
$decoratedName = $_.Value
|
$decoratedName = $_.Value
|
||||||
write-host "`t$paddedName, $decoratedName" -ForegroundColor Green
|
if ($verbose ) { write-host "`t$paddedName, $decoratedName" -ForegroundColor Green }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Write the symbol table to a file
|
# Write the symbol table to a file
|
||||||
@ -553,53 +216,91 @@ if ( $engine )
|
|||||||
$engine_symbols.Values | Out-File -Path $path_engine_symbols
|
$engine_symbols.Values | Out-File -Path $path_engine_symbols
|
||||||
}
|
}
|
||||||
|
|
||||||
Remove-Item $path_pdb_lock -Force -Verbose
|
|
||||||
|
|
||||||
#region CodeGen
|
|
||||||
if ( $handmade_process_active -eq $null ) {
|
|
||||||
# Delete old PDBs
|
# Delete old PDBs
|
||||||
$pdb_files = Get-ChildItem -Path $path_build -Filter "engine_postbuild_gen_*.pdb"
|
$pdb_files = Get-ChildItem -Path $path_build -Filter "engine_postbuild_gen_*.pdb"
|
||||||
foreach ($file in $pdb_files) {
|
foreach ($file in $pdb_files) {
|
||||||
Remove-Item -Path $file.FullName -Force
|
Remove-Item -Path $file.FullName -Force
|
||||||
Write-Host "Deleted $file" -ForegroundColor Green
|
if ($verbose) { Write-Host "Deleted $file" -ForegroundColor Green }
|
||||||
}
|
}
|
||||||
|
|
||||||
$engine_codegen_compiler_args = @()
|
$compiler_args = @()
|
||||||
$engine_codegen_compiler_args += ( $flag_define + 'GEN_TIME' )
|
$compiler_args += ( $flag_define + 'GEN_TIME' )
|
||||||
|
|
||||||
$engine_codegen_linker_args = @(
|
$linker_args = @(
|
||||||
$flag_link_win_subsystem_console
|
$flag_link_win_subsystem_console
|
||||||
)
|
)
|
||||||
|
|
||||||
$unit = Join-Path $path_codegen 'engine_postbuild_gen.cpp'
|
$unit = Join-Path $path_codegen 'engine_postbuild_gen.cpp'
|
||||||
$executable = Join-Path $path_build 'engine_postbuild_gen.exe'
|
$executable = Join-Path $path_build 'engine_postbuild_gen.exe'
|
||||||
|
|
||||||
build-simple $includes $engine_codegen_compiler_args $engine_codegen_linker_args $unit $executable
|
build-simple $includes $compiler_args $linker_args $unit $executable
|
||||||
write-host
|
|
||||||
|
|
||||||
Push-Location $path_build
|
Push-Location $path_build
|
||||||
& $executable
|
$time_taken = Measure-Command {
|
||||||
|
& $executable 2>&1 | ForEach-Object {
|
||||||
|
write-host `t $_ -ForegroundColor Green
|
||||||
|
}
|
||||||
|
}
|
||||||
Pop-Location
|
Pop-Location
|
||||||
|
|
||||||
$path_generated_file = Join-Path $path_build 'engine_symbol_table.hpp'
|
$path_generated_file = Join-Path $path_build 'engine_symbol_table.hpp'
|
||||||
move-item $path_generated_file (join-path $path_gen (split-path $path_generated_file -leaf)) -Force
|
move-item $path_generated_file (join-path $path_gen (split-path $path_generated_file -leaf)) -Force
|
||||||
}
|
}
|
||||||
#endregion CodeGen
|
}
|
||||||
|
if ( $engine ) {
|
||||||
|
build-engine
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $platform )
|
function build-platform
|
||||||
{
|
{
|
||||||
|
# CodeGen Pre-Build
|
||||||
|
if ( $true )
|
||||||
|
{
|
||||||
|
# Delete old PDBs
|
||||||
|
$pdb_files = Get-ChildItem -Path $path_build -Filter "platform_gen_*.pdb"
|
||||||
|
foreach ($file in $pdb_files) {
|
||||||
|
Remove-Item -Path $file.FullName -Force
|
||||||
|
if ( $verbose ) { Write-Host "Deleted $file" -ForegroundColor Green }
|
||||||
|
}
|
||||||
|
|
||||||
|
$path_platform_gen = Join-Path $path_platform 'gen'
|
||||||
|
|
||||||
|
if ( -not (Test-Path $path_platform_gen) ) {
|
||||||
|
New-Item $path_platform_gen -ItemType Directory
|
||||||
|
}
|
||||||
|
|
||||||
|
$local:compiler_args = @()
|
||||||
|
$compiler_args += ( $flag_define + 'GEN_TIME' )
|
||||||
|
|
||||||
|
$local:linker_args = @(
|
||||||
|
$flag_link_win_subsystem_console
|
||||||
|
)
|
||||||
|
|
||||||
|
$unit = Join-Path $path_codegen 'platform_gen.cpp'
|
||||||
|
$executable = Join-Path $path_build 'platform_gen.exe'
|
||||||
|
|
||||||
|
build-simple $includes $compiler_args $linker_args $unit $executable
|
||||||
|
|
||||||
|
Push-Location $path_platform
|
||||||
|
$time_taken = Measure-Command {
|
||||||
|
& $executable 2>&1 | ForEach-Object {
|
||||||
|
write-host `t $_ -ForegroundColor Green
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
|
|
||||||
# Delete old PDBs
|
# Delete old PDBs
|
||||||
$pdb_files = Get-ChildItem -Path $path_binaries -Filter "handmade_win32_*.pdb"
|
$pdb_files = Get-ChildItem -Path $path_binaries -Filter "handmade_win32_*.pdb"
|
||||||
foreach ($file in $pdb_files) {
|
foreach ($file in $pdb_files) {
|
||||||
Remove-Item -Path $file.FullName -Force
|
Remove-Item -Path $file.FullName -Force
|
||||||
Write-Host "Deleted $file" -ForegroundColor Green
|
if ( $verbose ) { Write-Host "Deleted $file" -ForegroundColor Green }
|
||||||
}
|
}
|
||||||
|
|
||||||
$platform_compiler_args = $compiler_args
|
$local:compiler_args = $script:compiler_args
|
||||||
$platform_compiler_args += ($flag_define + 'Build_DLL=0' )
|
$compiler_args += ($flag_define + 'Build_DLL=0' )
|
||||||
|
|
||||||
$linker_args = @(
|
$local:linker_args = @(
|
||||||
$lib_gdi32,
|
$lib_gdi32,
|
||||||
# $lib_xinput,
|
# $lib_xinput,
|
||||||
$lib_user32,
|
$lib_user32,
|
||||||
@ -614,7 +315,7 @@ if ( $platform )
|
|||||||
$unit = Join-Path $path_project 'handmade_win32.cpp'
|
$unit = Join-Path $path_project 'handmade_win32.cpp'
|
||||||
$executable = Join-Path $path_binaries 'handmade_win32.exe'
|
$executable = Join-Path $path_binaries 'handmade_win32.exe'
|
||||||
|
|
||||||
build-simple $includes $platform_compiler_args $linker_args $unit $executable
|
build-simple $includes $compiler_args $linker_args $unit $executable
|
||||||
|
|
||||||
# if ( Test-Path $executable )
|
# if ( Test-Path $executable )
|
||||||
# {
|
# {
|
||||||
@ -622,6 +323,9 @@ if ( $platform )
|
|||||||
# move-item $executable $data_path -Force
|
# move-item $executable $data_path -Force
|
||||||
# }
|
# }
|
||||||
}
|
}
|
||||||
|
if ( $platform ) {
|
||||||
|
build-platform
|
||||||
|
}
|
||||||
|
|
||||||
$path_jsl_dll = Join-Path $path_binaries 'JoyShockLibrary.dll'
|
$path_jsl_dll = Join-Path $path_binaries 'JoyShockLibrary.dll'
|
||||||
if ( (Test-Path $path_jsl_dll) -eq $false )
|
if ( (Test-Path $path_jsl_dll) -eq $false )
|
||||||
@ -631,5 +335,12 @@ if ( (Test-Path $path_jsl_dll) -eq $false )
|
|||||||
}
|
}
|
||||||
#endregion Handmade Runtime
|
#endregion Handmade Runtime
|
||||||
|
|
||||||
|
$include = @(
|
||||||
|
'*.cpp'
|
||||||
|
'*.hpp'
|
||||||
|
)
|
||||||
|
format-cpp $path_gen $include
|
||||||
|
format-cpp (Join-Path $path_platform 'gen' ) $include
|
||||||
|
|
||||||
Pop-Location
|
Pop-Location
|
||||||
#endregion Building
|
#endregion Building
|
||||||
|
Binary file not shown.
356
scripts/helpers/configure_toolchain.ps1
Normal file
356
scripts/helpers/configure_toolchain.ps1
Normal file
@ -0,0 +1,356 @@
|
|||||||
|
# This is meant to be used with build.ps1, and is not a standalone script.
|
||||||
|
|
||||||
|
if ($IsWindows) {
|
||||||
|
# This HandmadeHero implementation is only designed for 64-bit systems
|
||||||
|
& $devshell -arch amd64
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $vendor -eq $null ) {
|
||||||
|
write-host "No vendor specified, assuming clang available"
|
||||||
|
$compiler = "clang"
|
||||||
|
}
|
||||||
|
|
||||||
|
write-host "Building HandmadeHero with $vendor"
|
||||||
|
|
||||||
|
if ( $dev ) {
|
||||||
|
if ( $debug -eq $null ) {
|
||||||
|
$debug = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $optimize -eq $null ) {
|
||||||
|
$optimize = $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function run-compiler
|
||||||
|
{
|
||||||
|
param( $compiler, $unit, $compiler_args )
|
||||||
|
|
||||||
|
if ( $analysis ) {
|
||||||
|
$compiler_args += $flag_syntax_only
|
||||||
|
}
|
||||||
|
|
||||||
|
write-host "`Compiling $unit"
|
||||||
|
if ( $verbose ) {
|
||||||
|
write-host "Compiler config:"
|
||||||
|
$compiler_args | ForEach-Object {
|
||||||
|
write-host $_ -ForegroundColor Cyan
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$time_taken = Measure-Command {
|
||||||
|
& $compiler $compiler_args 2>&1 | ForEach-Object {
|
||||||
|
$color = 'White'
|
||||||
|
switch ($_){
|
||||||
|
{ $_ -match "error" } { $color = 'Red' ; break }
|
||||||
|
{ $_ -match "warning" } { $color = 'Yellow'; break }
|
||||||
|
}
|
||||||
|
write-host `t $_ -ForegroundColor $color
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( Test-Path($unit) ) {
|
||||||
|
write-host "$unit compile finished in $($time_taken.TotalMilliseconds) ms`n"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
write-host "Compile failed for $unit`n" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function run-linker
|
||||||
|
{
|
||||||
|
param( $linker, $binary, $linker_args )
|
||||||
|
|
||||||
|
write-host "`Linking $binary"
|
||||||
|
if ( $verbose ) {
|
||||||
|
write-host "Linker config:"
|
||||||
|
$linker_args | ForEach-Object {
|
||||||
|
write-host $_ -ForegroundColor Cyan
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$time_taken = Measure-Command {
|
||||||
|
& $linker $linker_args 2>&1 | ForEach-Object {
|
||||||
|
$color = 'White'
|
||||||
|
switch ($_){
|
||||||
|
{ $_ -match "error" } { $color = 'Red' ; break }
|
||||||
|
{ $_ -match "warning" } { $color = 'Yellow'; break }
|
||||||
|
}
|
||||||
|
write-host `t $_ -ForegroundColor $color
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( Test-Path($binary) ) {
|
||||||
|
write-host "$binary linking finished in $($time_taken.TotalMilliseconds) ms`n"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
write-host "Linking failed for $binary`n" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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_preprocess = '-E'
|
||||||
|
$flag_include = '-I'
|
||||||
|
$flag_section_data = '-fdata-sections'
|
||||||
|
$flag_section_functions = '-ffunction-sections'
|
||||||
|
$flag_library = '-l'
|
||||||
|
$flag_library_path = '-L'
|
||||||
|
$flag_linker = '-Wl,'
|
||||||
|
if ( $IsWindows ) {
|
||||||
|
$flag_link_dll = '/DLL'
|
||||||
|
$flag_link_mapfile = '/MAP:'
|
||||||
|
$flag_link_optimize_references = '/OPT:REF'
|
||||||
|
}
|
||||||
|
if ( $IsLinux ) {
|
||||||
|
$flag_link_mapfile = '--Map='
|
||||||
|
$flag_link_optimize_references = '--gc-sections'
|
||||||
|
}
|
||||||
|
$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_optimize_intrinsics = '-Oi'
|
||||||
|
$flag_path_output = '-o'
|
||||||
|
$flag_preprocess_non_intergrated = '-no-integrated-cpp'
|
||||||
|
$flag_profiling_debug = '-fdebug-info-for-profiling'
|
||||||
|
$flag_set_stack_size = '-stack='
|
||||||
|
$flag_syntax_only = '-fsyntax-only'
|
||||||
|
$flag_target_arch = '-target'
|
||||||
|
$flag_wall = '-Wall'
|
||||||
|
$flag_warning = '-W'
|
||||||
|
$flag_warnings_as_errors = '-Werror'
|
||||||
|
$flag_win_nologo = '/nologo'
|
||||||
|
|
||||||
|
$ignore_warning_ms_include = 'no-microsoft-include'
|
||||||
|
$ignore_warning_return_type_c_linkage = 'no-return-type-c-linkage'
|
||||||
|
|
||||||
|
$target_arch = Get-TargetArchClang
|
||||||
|
|
||||||
|
$warning_ignores = @(
|
||||||
|
$ignore_warning_ms_include,
|
||||||
|
$ignore_warning_return_type_c_linkage
|
||||||
|
)
|
||||||
|
|
||||||
|
# https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170
|
||||||
|
$libraries = @(
|
||||||
|
'Kernel32' # For Windows API
|
||||||
|
# 'msvcrt', # For the C Runtime (Dynamically Linked)
|
||||||
|
# 'libucrt',
|
||||||
|
'libcmt' # For the C Runtime (Static Linkage)
|
||||||
|
)
|
||||||
|
|
||||||
|
function build-simple
|
||||||
|
{
|
||||||
|
param( [array]$includes, [array]$compiler_args, [array]$linker_args, [string]$unit, [string]$binary )
|
||||||
|
#Write-Host "build-simple: clang"
|
||||||
|
|
||||||
|
$object = $unit -replace '\.cpp', '.obj'
|
||||||
|
$map = $unit -replace '\.cpp', '.map'
|
||||||
|
$object = join-path $path_build (split-path $object -Leaf)
|
||||||
|
$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
|
||||||
|
$pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
|
||||||
|
|
||||||
|
$compiler_args += @(
|
||||||
|
$flag_no_color_diagnostics,
|
||||||
|
$flag_exceptions_disabled,
|
||||||
|
$flag_target_arch, $target_arch,
|
||||||
|
$flag_wall,
|
||||||
|
$flag_preprocess_on_intergrated,
|
||||||
|
# $flag_section_data,
|
||||||
|
# $flag_section_functions,
|
||||||
|
( $flag_path_output + $object )
|
||||||
|
)
|
||||||
|
if ( $optimize ) {
|
||||||
|
$compiler_args += $flag_optimize_fast
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$compiler_args += $flag_no_optimization
|
||||||
|
}
|
||||||
|
if ( $debug ) {
|
||||||
|
$compiler_args += ( $flag_define + 'Build_Debug=1' )
|
||||||
|
$compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$compiler_args += ( $flag_define + 'Build_Debug=0' )
|
||||||
|
}
|
||||||
|
|
||||||
|
$warning_ignores | ForEach-Object {
|
||||||
|
$compiler_args += $flag_warning + $_
|
||||||
|
}
|
||||||
|
$compiler_args += $includes | ForEach-Object { $flag_include + $_ }
|
||||||
|
|
||||||
|
$compiler_args += $flag_compile, $unit
|
||||||
|
run-compiler $compiler $unit $compiler_args
|
||||||
|
|
||||||
|
$linker_args += @(
|
||||||
|
$flag_link_win_machine_64,
|
||||||
|
$( $flag_link_win_path_output + $binary )
|
||||||
|
)
|
||||||
|
if ( $debug ) {
|
||||||
|
$linker_args += $flag_link_win_debug
|
||||||
|
$linker_args += $flag_link_win_pdb + $pdb
|
||||||
|
$linker_args += $flag_link_mapfile + $map
|
||||||
|
}
|
||||||
|
|
||||||
|
$libraries | ForEach-Object {
|
||||||
|
$linker_args += $_ + '.lib'
|
||||||
|
}
|
||||||
|
|
||||||
|
$linker_args += $object
|
||||||
|
run-linker $linker $binary $linker_args
|
||||||
|
|
||||||
|
# $compiler_args += $unit
|
||||||
|
# $linker_args | ForEach-Object {
|
||||||
|
# $compiler_args += $flag_linker + $_
|
||||||
|
# }
|
||||||
|
# run-compiler $compiler $unit $compiler_args
|
||||||
|
}
|
||||||
|
|
||||||
|
$compiler = 'clang++'
|
||||||
|
$linker = 'lld-link'
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = '/EHsc-'
|
||||||
|
$flag_RTTI_disabled = '/GR-'
|
||||||
|
$flag_include = '/I'
|
||||||
|
$flag_full_src_path = '/FC'
|
||||||
|
$flag_nologo = '/nologo'
|
||||||
|
$flag_dll = '/LD'
|
||||||
|
$flag_dll_debug = '/LDd'
|
||||||
|
$flag_linker = '/link'
|
||||||
|
$flag_link_dll = '/DLL'
|
||||||
|
$flag_link_no_incremental = '/INCREMENTAL:NO'
|
||||||
|
$flag_link_mapfile = '/MAP:'
|
||||||
|
$flag_link_optimize_references = '/OPT:REF'
|
||||||
|
$flag_link_win_debug = '/DEBUG'
|
||||||
|
$flag_link_win_pdb = '/PDB:'
|
||||||
|
$flag_link_win_machine_32 = '/MACHINE:X86'
|
||||||
|
$flag_link_win_machine_64 = '/MACHINE:X64'
|
||||||
|
$flag_link_win_path_output = '/OUT:'
|
||||||
|
$flag_link_win_rt_dll = '/MD'
|
||||||
|
$flag_link_win_rt_dll_debug = '/MDd'
|
||||||
|
$flag_link_win_rt_static = '/MT'
|
||||||
|
$flag_link_win_rt_static_debug = '/MTd'
|
||||||
|
$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_optimize_intrinsics = '/Oi'
|
||||||
|
$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_set_stack_size = '/F'
|
||||||
|
$flag_syntax_only = '/Zs'
|
||||||
|
$flag_wall = '/Wall'
|
||||||
|
$flag_warnings_as_errors = '/WX'
|
||||||
|
|
||||||
|
# This works because this project uses a single unit to build
|
||||||
|
function build-simple
|
||||||
|
{
|
||||||
|
param( [array]$includes, [array]$compiler_args, [array]$linker_args, [string]$unit, [string]$binary )
|
||||||
|
#Write-Host "build-simple: msvc"
|
||||||
|
|
||||||
|
$object = $unit -replace '\.(cpp)$', '.obj'
|
||||||
|
$map = $unit -replace '\.(cpp)$', '.map'
|
||||||
|
$object = join-path $path_build (split-path $object -Leaf)
|
||||||
|
$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
|
||||||
|
$pdb = $binary -replace '\.(exe|dll)$', "_$(get-random).pdb"
|
||||||
|
|
||||||
|
$compiler_args += @(
|
||||||
|
$flag_nologo,
|
||||||
|
# $flag_all_cpp,
|
||||||
|
$flag_exceptions_disabled,
|
||||||
|
( $flag_define + '_HAS_EXCEPTIONS=0' ),
|
||||||
|
$flag_RTTI_disabled,
|
||||||
|
$flag_preprocess_conform,
|
||||||
|
$flag_full_src_path,
|
||||||
|
( $flag_path_interm + $path_build + '\' ),
|
||||||
|
( $flag_path_output + $path_build + '\' )
|
||||||
|
)
|
||||||
|
|
||||||
|
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=1' )
|
||||||
|
$compiler_args += ( $flag_path_debug + $path_build + '\' )
|
||||||
|
$compiler_args += $flag_link_win_rt_static_debug
|
||||||
|
|
||||||
|
if ( $optimize ) {
|
||||||
|
$compiler_args += $flag_optimized_debug
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$compiler_args += ( $flag_define + 'Build_Debug=0' )
|
||||||
|
$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
|
||||||
|
|
||||||
|
$linker_args += @(
|
||||||
|
$flag_nologo,
|
||||||
|
$flag_link_win_machine_64,
|
||||||
|
$flag_link_no_incremental,
|
||||||
|
( $flag_link_win_path_output + $binary )
|
||||||
|
)
|
||||||
|
if ( $debug ) {
|
||||||
|
$linker_args += $flag_link_win_debug
|
||||||
|
$linker_args += $flag_link_win_pdb + $pdb
|
||||||
|
$linker_args += $flag_link_mapfile + $map
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
}
|
||||||
|
|
||||||
|
$linker_args += $object
|
||||||
|
run-linker $linker $binary $linker_args
|
||||||
|
|
||||||
|
# $compiler_args += $unit
|
||||||
|
# $compiler_args += $flag_linker
|
||||||
|
# $compiler_args += $linker_args
|
||||||
|
# run-compiler $compiler $unit $compiler_args
|
||||||
|
}
|
||||||
|
|
||||||
|
$compiler = 'cl'
|
||||||
|
$linker = 'link'
|
||||||
|
}
|
26
scripts/helpers/format_cpp.psm1
Normal file
26
scripts/helpers/format_cpp.psm1
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# format_cpp.psm1
|
||||||
|
|
||||||
|
function format-cpp
|
||||||
|
{
|
||||||
|
param( $path, $include, $exclude )
|
||||||
|
|
||||||
|
# Format generated gencpp
|
||||||
|
Write-Host "Beginning format"
|
||||||
|
$formatParams = @(
|
||||||
|
'-i' # In-place
|
||||||
|
'-style=file:./scripts/.clang-format'
|
||||||
|
'-verbose'
|
||||||
|
)
|
||||||
|
|
||||||
|
$targetFiles = @(
|
||||||
|
Get-ChildItem -Recurse -Path $path -Include $include -Exclude $exclude
|
||||||
|
| Select-Object -ExpandProperty FullName
|
||||||
|
)
|
||||||
|
|
||||||
|
$time_taken = Measure-Command {
|
||||||
|
clang-format $formatParams $targetFiles
|
||||||
|
}
|
||||||
|
Write-Host "Formatting complete in $($time_taken.TotalMilliseconds) ms`n"
|
||||||
|
}
|
||||||
|
|
||||||
|
Export-ModuleMember -Function format-cpp
|
Loading…
Reference in New Issue
Block a user