mirror of
https://github.com/Ed94/HandmadeHero.git
synced 2025-06-16 11:41:47 -07:00
Day 28 complete!
This commit is contained in:
@ -93,7 +93,7 @@ int gen_main()
|
||||
builder.write();
|
||||
#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();
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,11 +6,72 @@
|
||||
#include "dependencies/gen.hpp"
|
||||
using namespace gen;
|
||||
|
||||
#define path_gen "./gen/"
|
||||
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen::init();
|
||||
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();
|
||||
return 0;
|
||||
}
|
||||
|
@ -18050,6 +18050,8 @@ namespace Parser
|
||||
);
|
||||
return { { nullptr }, 0 };
|
||||
}
|
||||
move_forward();
|
||||
content.Length++;
|
||||
|
||||
while ( left && current != '"' && current != '>' )
|
||||
{
|
||||
|
@ -30,15 +30,21 @@ struct EngineActions
|
||||
#if Build_Development
|
||||
b32 pause_renderer;
|
||||
|
||||
b32 load_auto_snapshot;
|
||||
b32 set_snapshot_slot_1;
|
||||
b32 set_snapshot_slot_2;
|
||||
b32 set_snapshot_slot_3;
|
||||
b32 set_snapshot_slot_4;
|
||||
|
||||
b32 force_null_access_violation;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct EngineState
|
||||
{
|
||||
f32 auto_snapshot_interval;
|
||||
f32 auto_snapshot_timer;
|
||||
|
||||
s32 wave_tone_hz;
|
||||
s32 tone_volume;
|
||||
s32 x_offset;
|
||||
@ -115,6 +121,7 @@ internal
|
||||
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 );
|
||||
memory->snapshots[ memory->active_snapshot_slot ].age = platform_api->get_wall_clock();
|
||||
}
|
||||
|
||||
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( transient_slot, state->game_memory.transient_size, state->game_memory.transient );
|
||||
memory->snapshots[ memory->active_snapshot_slot ].age = platform_api->get_wall_clock();
|
||||
}
|
||||
|
||||
internal
|
||||
@ -300,7 +308,7 @@ void input_poll_engine_actions( InputState* input, EngineActions* actions )
|
||||
|
||||
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;
|
||||
|
||||
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_down = (mouse->vertical_wheel.end < 0.f) * 10;
|
||||
|
||||
actions->load_auto_snapshot |= pressed( keyboard->L ) && keyboard->right_alt.ended_down;
|
||||
}
|
||||
|
||||
internal
|
||||
@ -402,7 +411,14 @@ void draw_rectangle( OffscreenBuffer* buffer
|
||||
if ( 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
|
||||
u8* row = rcast(u8*, buffer->memory )
|
||||
@ -439,14 +455,18 @@ void startup( Memory* memory, platform::ModuleAPI* platform_api )
|
||||
memory->game_loop_active = false;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
for ( s32 slot = 0; slot < memory->Num_Snapshot_Slots; ++ slot )
|
||||
{
|
||||
// TODO(Ed) : Specify default file paths for saving slots ?
|
||||
}
|
||||
#endif
|
||||
|
||||
EngineState* state = rcast( EngineState*, memory->persistent );
|
||||
assert( sizeof(EngineState) <= memory->persistent_size );
|
||||
|
||||
state->auto_snapshot_interval = 10.f;
|
||||
|
||||
state->tone_volume = 1000;
|
||||
|
||||
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 );
|
||||
assert( sizeof(hh::PlayerState) <= state->game_memory.persistent_size );
|
||||
|
||||
player->pos_x = 100;
|
||||
player->pos_y = 100;
|
||||
player->pos_x = 920;
|
||||
player->pos_y = 466;
|
||||
player->mid_jump = false;
|
||||
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 );
|
||||
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];
|
||||
|
||||
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 );
|
||||
|
||||
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
|
||||
// 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;
|
||||
@ -571,10 +615,8 @@ void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back
|
||||
|
||||
if ( ! memory->game_loop_active )
|
||||
{
|
||||
if ( engine_actions.set_snapshot_slot_1 ) memory->active_snapshot_slot = 0;
|
||||
if ( engine_actions.set_snapshot_slot_2 ) memory->active_snapshot_slot = 1;
|
||||
if ( engine_actions.set_snapshot_slot_3 ) memory->active_snapshot_slot = 2;
|
||||
if ( engine_actions.set_snapshot_slot_4 ) memory->active_snapshot_slot = 3;
|
||||
if ( engine_actions.set_snapshot_slot_1 ) memory->active_snapshot_slot = 1;
|
||||
if ( engine_actions.set_snapshot_slot_2 ) memory->active_snapshot_slot = 2;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -599,14 +641,18 @@ void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back
|
||||
|
||||
input_poll_player_actions( input, & player_actions );
|
||||
{
|
||||
player->pos_x += player_actions.player_x_move_digital * 5;
|
||||
player->pos_y -= player_actions.player_y_move_digital * 5;
|
||||
player->pos_x += scast(u32, player_actions.player_x_move_analog * 5);
|
||||
player->pos_y -= scast(u32, player_actions.player_y_move_analog * 5) - scast(u32, sinf( player->jump_time * TAU ) * 10);
|
||||
f32 move_speed = 200.f;
|
||||
|
||||
player->pos_x += scast(f32, player_actions.player_x_move_digital) * delta_time * move_speed;
|
||||
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 )
|
||||
{
|
||||
player->jump_time -= 0.025f;
|
||||
player->jump_time -= delta_time;
|
||||
}
|
||||
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 y_offset_f = scast(f32, state->y_offset);
|
||||
|
||||
// render_weird_graident( back_buffer, state->x_offset, state->y_offset );
|
||||
draw_rectangle( back_buffer
|
||||
, 0.f, 0.f
|
||||
, scast(f32, back_buffer->width), scast(f32, back_buffer->height)
|
||||
, 0x22, 0x22, 0x22 );
|
||||
render_player( back_buffer, player->pos_x, player->pos_y );
|
||||
, 1.f, 0.24f, 0.24f );
|
||||
|
||||
// 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 ( 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
|
||||
|
||||
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
|
||||
#if 0
|
||||
{
|
||||
if ( input->controllers[0].mouse->left.ended_down == true )
|
||||
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 )
|
||||
render_player( back_buffer, 5, 35 );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Engine_API
|
||||
|
@ -35,6 +35,7 @@ struct MemorySnapshot
|
||||
void* opaque_handle;
|
||||
void* opaque_handle_2;
|
||||
void* memory;
|
||||
u64 age;
|
||||
};
|
||||
|
||||
struct Memory
|
||||
@ -56,7 +57,7 @@ struct Memory
|
||||
// TODO(Ed) : Move this crap to state & replay archive definitions?
|
||||
#if Build_Development
|
||||
static constexpr
|
||||
s32 Num_Snapshot_Slots = 2;
|
||||
s32 Num_Snapshot_Slots = 3;
|
||||
// Abuse RAM to store snapshots of the Engine or Game state.
|
||||
MemorySnapshot snapshots[ Num_Snapshot_Slots ];
|
||||
s32 active_snapshot_slot;
|
||||
|
@ -3,15 +3,12 @@
|
||||
|
||||
NS_ENGINE_BEGIN
|
||||
|
||||
constexpr
|
||||
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
|
||||
Str const symbol_shutdown = str_ascii("?shutdown@engine@@YAXPEAUMemory@1@PEAUModuleAPI@platform@@@Z");
|
||||
constexpr
|
||||
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");
|
||||
constexpr 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 Str const symbol_shutdown = str_ascii( "?shutdown@engine@@YAXPEAUMemory@1@PEAUModuleAPI@platform@@@Z" );
|
||||
constexpr 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
|
||||
|
@ -70,8 +70,8 @@ struct Player
|
||||
|
||||
struct PlayerState
|
||||
{
|
||||
s32 pos_x;
|
||||
s32 pos_y;
|
||||
f32 pos_x;
|
||||
f32 pos_y;
|
||||
|
||||
b32 mid_jump;
|
||||
f32 jump_time;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "platform/compiler_ignores.hpp"
|
||||
|
||||
#if Build_Unity
|
||||
#include "platform/win32_platform.cpp"
|
||||
#include "platform/win32/win32_platform.cpp"
|
||||
#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__
|
||||
#endif
|
||||
|
||||
// TODO(Ed) : Add this sauce later
|
||||
#if 0
|
||||
#define congrats( message )
|
||||
#define ensure( condition, expression )
|
||||
#define fatal( message )
|
||||
#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 )
|
||||
# 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 checked_global_getter( global_var, procedure ) global_var
|
||||
#endif
|
||||
|
||||
# define congrats( message )
|
||||
# define ensure( condition, message )
|
||||
# define fatal( message )
|
||||
#endif
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "math_constants.hpp"
|
||||
#include "types.hpp"
|
||||
#include "strings.hpp"
|
||||
#include "context.hpp"
|
||||
|
||||
#define NS_PLATFORM_BEGIN namespace platform {
|
||||
#define NS_PLATFORM_END }
|
||||
@ -80,6 +81,8 @@ using FileRewindFn = void ( File* file );
|
||||
|
||||
using MemoryCopyFn = void( void* dest, u64 src_size, void* src );
|
||||
|
||||
using GetWallClockFn = u64();
|
||||
|
||||
struct ModuleAPI
|
||||
{
|
||||
Str path_root;
|
||||
@ -90,6 +93,8 @@ struct ModuleAPI
|
||||
DebugSetPauseRenderingFn* debug_set_pause_rendering;
|
||||
#endif
|
||||
|
||||
GetWallClockFn* get_wall_clock;
|
||||
|
||||
GetMonitorRefreshRateFn* get_monitor_refresh_rate;
|
||||
SetMonitorRefreshRateFn* set_monitor_refresh_rate;
|
||||
|
||||
@ -112,6 +117,12 @@ struct ModuleAPI
|
||||
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
|
||||
|
||||
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
Reference in New Issue
Block a user