mirror of
https://github.com/Ed94/HandmadeHero.git
synced 2024-11-10 03:44:53 -08:00
Day 16 complete
This commit is contained in:
parent
c4cdac03fa
commit
100cf96d4f
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,3 +21,4 @@ vc140.pdb
|
|||||||
build
|
build
|
||||||
|
|
||||||
**/*.dll
|
**/*.dll
|
||||||
|
data/test.out
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
<ShowEmptyFolders>true</ShowEmptyFolders>
|
<ShowEmptyFolders>true</ShowEmptyFolders>
|
||||||
<IsVirtual>false</IsVirtual>
|
<IsVirtual>false</IsVirtual>
|
||||||
<IsFolder>false</IsFolder>
|
<IsFolder>false</IsFolder>
|
||||||
<BuildCommand>pwsh $(WorkspaceDirectory)/scripts/build.ps1 msvc</BuildCommand>
|
<BuildCommand>pwsh $(WorkspaceDirectory)/scripts/build.ps1 msvc dev debug</BuildCommand>
|
||||||
<RebuildCommand>pwsh $(WorkspaceDirectory)/scripts/clean; $(WorkspaceDirectory)scripts/build msvc</RebuildCommand>
|
<RebuildCommand>pwsh $(WorkspaceDirectory)/scripts/clean.ps1; $(WorkspaceDirectory)scripts/build.ps1 msvc dev debug</RebuildCommand>
|
||||||
<BuildFileCommand></BuildFileCommand>
|
<BuildFileCommand></BuildFileCommand>
|
||||||
<CleanCommand>pwsh $(WorkspaceDirectory)/scripts/clean.ps1</CleanCommand>
|
<CleanCommand>pwsh $(WorkspaceDirectory)/scripts/clean.ps1</CleanCommand>
|
||||||
<BuildWorkingDirectory></BuildWorkingDirectory>
|
<BuildWorkingDirectory></BuildWorkingDirectory>
|
||||||
@ -21,8 +21,9 @@
|
|||||||
<DebugSln></DebugSln>
|
<DebugSln></DebugSln>
|
||||||
<UseVisualStudioEnvBat>false</UseVisualStudioEnvBat>
|
<UseVisualStudioEnvBat>false</UseVisualStudioEnvBat>
|
||||||
<Configurations>
|
<Configurations>
|
||||||
<Configuration>Debug</Configuration>
|
<Configuration>Dev Optimzied</Configuration>
|
||||||
<Configuration>Release</Configuration>
|
<Configuration>Dev </Configuration>
|
||||||
|
<Configuration>Optimized</Configuration>
|
||||||
</Configurations>
|
</Configurations>
|
||||||
<Platforms>
|
<Platforms>
|
||||||
<Platform>x64</Platform>
|
<Platform>x64</Platform>
|
||||||
@ -41,6 +42,8 @@
|
|||||||
<Define>UNICODE</Define>
|
<Define>UNICODE</Define>
|
||||||
<Define>_UNICODE</Define>
|
<Define>_UNICODE</Define>
|
||||||
<Define>GEN_TIME</Define>
|
<Define>GEN_TIME</Define>
|
||||||
|
<Define>Build_Debug</Define>
|
||||||
|
<Define>Build_Development</Define>
|
||||||
</Defines>
|
</Defines>
|
||||||
<ConfigProperties>
|
<ConfigProperties>
|
||||||
<ConfigAndPlatform>
|
<ConfigAndPlatform>
|
||||||
|
3
docs/Day 016.md
Normal file
3
docs/Day 016.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Day 16
|
||||||
|
|
||||||
|
Finding out about the linker's map file was nice.
|
@ -17,10 +17,10 @@ using GetSoundSampleValueFn = s16( EngineState* state, SoundBuffer* sound_buffer
|
|||||||
internal s16
|
internal s16
|
||||||
square_wave_sample_value( EngineState* state, SoundBuffer* sound_buffer )
|
square_wave_sample_value( EngineState* state, SoundBuffer* sound_buffer )
|
||||||
{
|
{
|
||||||
s16 sample_value = (sound_buffer->RunningSampleIndex / (state->WavePeriod / 2) ) % 2 ?
|
s32 sample_value = (sound_buffer->RunningSampleIndex / (state->WavePeriod / 2) ) % 2 ?
|
||||||
state->ToneVolume : - state->ToneVolume;
|
state->ToneVolume : - state->ToneVolume;
|
||||||
|
|
||||||
return sample_value;
|
return scast(s16, sample_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal s16
|
internal s16
|
||||||
@ -30,7 +30,7 @@ sine_wave_sample_value( EngineState* state, SoundBuffer* sound_buffer )
|
|||||||
|
|
||||||
// time = TAU * (f32)sound_buffer->RunningSampleIndex / (f32)SoundTest_WavePeriod;
|
// time = TAU * (f32)sound_buffer->RunningSampleIndex / (f32)SoundTest_WavePeriod;
|
||||||
f32 sine_value = sinf( time );
|
f32 sine_value = sinf( time );
|
||||||
s16 sample_value = scast(u16, sine_value * state->ToneVolume);
|
s16 sample_value = scast(s16, sine_value * scast(f32, state->ToneVolume));
|
||||||
|
|
||||||
time += TAU * 1.0f / scast(f32, state->WavePeriod );
|
time += TAU * 1.0f / scast(f32, state->WavePeriod );
|
||||||
return sample_value;
|
return sample_value;
|
||||||
@ -40,7 +40,7 @@ internal void
|
|||||||
output_sound( EngineState* state, SoundBuffer* sound_buffer, GetSoundSampleValueFn* get_sample_value )
|
output_sound( EngineState* state, SoundBuffer* sound_buffer, GetSoundSampleValueFn* get_sample_value )
|
||||||
{
|
{
|
||||||
s16* sample_out = sound_buffer->Samples;
|
s16* sample_out = sound_buffer->Samples;
|
||||||
for ( u32 sample_index = 0; sample_index < sound_buffer->NumSamples; ++ sample_index )
|
for ( s32 sample_index = 0; sample_index < sound_buffer->NumSamples; ++ sample_index )
|
||||||
{
|
{
|
||||||
s16 sample_value = get_sample_value( state, sound_buffer );
|
s16 sample_value = get_sample_value( state, sound_buffer );
|
||||||
sound_buffer->RunningSampleIndex++;
|
sound_buffer->RunningSampleIndex++;
|
||||||
@ -97,7 +97,7 @@ render_weird_graident(OffscreenBuffer* buffer, u32 x_offset, u32 y_offset )
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
*pixel++ = (red << 16) | (green << 8) | blue;
|
*pixel++ = u32(red << 16) | u32(green << 8) | blue;
|
||||||
}
|
}
|
||||||
wildcard += 0.5375f;
|
wildcard += 0.5375f;
|
||||||
row += buffer->Pitch;
|
row += buffer->Pitch;
|
||||||
@ -120,8 +120,7 @@ shutdown()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO : I rather expose the back_buffer and sound_buffer using getters for access in any function.
|
// TODO : I rather expose the back_buffer and sound_buffer using getters for access in any function.
|
||||||
internal void
|
void update_and_render( InputState* input, OffscreenBuffer* back_buffer, SoundBuffer* sound_buffer, Memory* memory )
|
||||||
update_and_render( InputState* input, OffscreenBuffer* back_buffer, SoundBuffer* sound_buffer, Memory* memory )
|
|
||||||
{
|
{
|
||||||
// Graphics & Input Test
|
// Graphics & Input Test
|
||||||
local_persist u32 x_offset = 0;
|
local_persist u32 x_offset = 0;
|
||||||
@ -178,8 +177,8 @@ update_and_render( InputState* input, OffscreenBuffer* back_buffer, SoundBuffer*
|
|||||||
y_offset += pad->DPad.Down.State;
|
y_offset += pad->DPad.Down.State;
|
||||||
y_offset -= pad->DPad.Up.State;
|
y_offset -= pad->DPad.Up.State;
|
||||||
|
|
||||||
x_offset += pad->Stick.Left.X.End;
|
x_offset += scast(u32, pad->Stick.Left.X.End);
|
||||||
y_offset += pad->Stick.Left.Y.End;
|
y_offset += scast(u32, pad->Stick.Left.Y.End);
|
||||||
|
|
||||||
if ( pad->Triangle.State )
|
if ( pad->Triangle.State )
|
||||||
{
|
{
|
||||||
@ -211,17 +210,17 @@ update_and_render( InputState* input, OffscreenBuffer* back_buffer, SoundBuffer*
|
|||||||
// TODO(Ed) : Add rumble test
|
// TODO(Ed) : Add rumble test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( controller->XPad )
|
if ( controller->XPad )
|
||||||
{
|
{
|
||||||
XInputPadState* pad = controller->XPad;
|
XInputPadState* pad = controller->XPad;
|
||||||
|
|
||||||
x_offset += pad->DPad.Right.State;
|
x_offset += pad->DPad.Right.State;
|
||||||
x_offset -= pad->DPad.Left.State;
|
x_offset -= pad->DPad.Left.State;
|
||||||
y_offset += pad->DPad.Down.State;
|
y_offset -= pad->DPad.Down.State;
|
||||||
y_offset -= pad->DPad.Up.State;
|
y_offset += pad->DPad.Up.State;
|
||||||
|
|
||||||
x_offset += pad->Stick.Left.X.End;
|
x_offset += scast(u32, pad->Stick.Left.X.End);
|
||||||
y_offset += pad->Stick.Left.Y.End;
|
y_offset += scast(u32, pad->Stick.Left.Y.End);
|
||||||
|
|
||||||
if ( pad->Y.State )
|
if ( pad->Y.State )
|
||||||
{
|
{
|
||||||
@ -253,6 +252,44 @@ update_and_render( InputState* input, OffscreenBuffer* back_buffer, SoundBuffer*
|
|||||||
// TODO(Ed) : Add rumble test
|
// TODO(Ed) : Add rumble test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( controller->Keyboard )
|
||||||
|
{
|
||||||
|
KeyboardState* keyboard = controller->Keyboard;
|
||||||
|
|
||||||
|
x_offset += keyboard->D.State;
|
||||||
|
x_offset -= keyboard->A.State;
|
||||||
|
y_offset += keyboard->W.State;
|
||||||
|
y_offset -= keyboard->S.State;
|
||||||
|
|
||||||
|
if ( keyboard->Esc.State )
|
||||||
|
{
|
||||||
|
// TODO : Add exit game
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( keyboard->Space.State )
|
||||||
|
{
|
||||||
|
wave_switch ^= true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( keyboard->Up.State )
|
||||||
|
{
|
||||||
|
state->ToneVolume += 10;
|
||||||
|
}
|
||||||
|
if ( keyboard->Down.State )
|
||||||
|
{
|
||||||
|
state->ToneVolume -= 10;
|
||||||
|
}
|
||||||
|
if ( keyboard->Left.State )
|
||||||
|
{
|
||||||
|
state->WaveToneHz -= 1;
|
||||||
|
state->WavePeriod = sound_buffer->SamplesPerSecond / state->WaveToneHz;
|
||||||
|
}
|
||||||
|
if ( keyboard->Right.State )
|
||||||
|
{
|
||||||
|
state->WaveToneHz += 1;
|
||||||
|
state->WavePeriod = sound_buffer->SamplesPerSecond / state->WaveToneHz;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(Ed) : Allow sample offsets here for more robust platform options
|
// TODO(Ed) : Allow sample offsets here for more robust platform options
|
||||||
if ( ! wave_switch )
|
if ( ! wave_switch )
|
||||||
|
@ -50,6 +50,7 @@ struct SoundBuffer
|
|||||||
u32 RunningSampleIndex;
|
u32 RunningSampleIndex;
|
||||||
s32 SamplesPerSecond;
|
s32 SamplesPerSecond;
|
||||||
s32 NumSamples;
|
s32 NumSamples;
|
||||||
|
char _PAD_[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DigitalBtn
|
struct DigitalBtn
|
||||||
@ -76,10 +77,18 @@ struct AnalogStick
|
|||||||
|
|
||||||
struct KeyboardState
|
struct KeyboardState
|
||||||
{
|
{
|
||||||
|
DigitalBtn Q;
|
||||||
|
DigitalBtn E;
|
||||||
DigitalBtn W;
|
DigitalBtn W;
|
||||||
DigitalBtn A;
|
DigitalBtn A;
|
||||||
DigitalBtn S;
|
DigitalBtn S;
|
||||||
DigitalBtn D;
|
DigitalBtn D;
|
||||||
|
DigitalBtn Esc;
|
||||||
|
DigitalBtn Up;
|
||||||
|
DigitalBtn Down;
|
||||||
|
DigitalBtn Left;
|
||||||
|
DigitalBtn Right;
|
||||||
|
DigitalBtn Space;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MousesState
|
struct MousesState
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
- GetKeyboardLayout (for French keyboards, international WASD support)
|
- GetKeyboardLayout (for French keyboards, international WASD support)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if __clang__
|
#ifdef __clang__
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wunused-const-variable"
|
#pragma clang diagnostic ignored "-Wunused-const-variable"
|
||||||
#pragma clang diagnostic ignored "-Wswitch"
|
#pragma clang diagnostic ignored "-Wswitch"
|
||||||
@ -77,11 +77,12 @@ global bool Running;
|
|||||||
struct OffscreenBuffer
|
struct OffscreenBuffer
|
||||||
{
|
{
|
||||||
BITMAPINFO Info;
|
BITMAPINFO Info;
|
||||||
|
char _PAD_[4];
|
||||||
void* Memory; // Lets use directly mess with the "pixel's memory buffer"
|
void* Memory; // Lets use directly mess with the "pixel's memory buffer"
|
||||||
u32 Width;
|
s32 Width;
|
||||||
u32 Height;
|
s32 Height;
|
||||||
u32 Pitch;
|
s32 Pitch;
|
||||||
u32 BytesPerPixel;
|
s32 BytesPerPixel;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WinDimensions
|
struct WinDimensions
|
||||||
@ -115,7 +116,6 @@ global s16* SoundBufferSamples;
|
|||||||
|
|
||||||
|
|
||||||
#if Build_Debug
|
#if Build_Debug
|
||||||
internal
|
|
||||||
void debug_file_free_content( Debug_FileContent* content )
|
void debug_file_free_content( Debug_FileContent* content )
|
||||||
{
|
{
|
||||||
if ( content->Data)
|
if ( content->Data)
|
||||||
@ -125,7 +125,6 @@ void debug_file_free_content( Debug_FileContent* content )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
|
||||||
Debug_FileContent debug_file_read_content( char* file_path )
|
Debug_FileContent debug_file_read_content( char* file_path )
|
||||||
{
|
{
|
||||||
Debug_FileContent result {};
|
Debug_FileContent result {};
|
||||||
@ -165,7 +164,6 @@ Debug_FileContent debug_file_read_content( char* file_path )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
|
||||||
b32 debug_file_write_content( char* file_path, u32 content_size, void* content_memory )
|
b32 debug_file_write_content( char* file_path, u32 content_size, void* content_memory )
|
||||||
{
|
{
|
||||||
HANDLE file_handle = CreateFileA( file_path
|
HANDLE file_handle = CreateFileA( file_path
|
||||||
@ -202,12 +200,15 @@ init_sound(HWND window_handle, s32 samples_per_second, s32 buffer_size )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get direct sound object
|
// Get direct sound object
|
||||||
|
#pragma warning( push )
|
||||||
|
#pragma warning( disable: 4191 )
|
||||||
direct_sound_create = rcast( DirectSoundCreateFn*, GetProcAddress( sound_library, "DirectSoundCreate" ));
|
direct_sound_create = rcast( DirectSoundCreateFn*, GetProcAddress( sound_library, "DirectSoundCreate" ));
|
||||||
if ( ! ensure( direct_sound_create, "Failed to get direct_sound_create_procedure" ) )
|
if ( ! ensure( direct_sound_create, "Failed to get direct_sound_create_procedure" ) )
|
||||||
{
|
{
|
||||||
// TOOD : Diagnostic
|
// TOOD : Diagnostic
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#pragma warning( pop )
|
||||||
|
|
||||||
LPDIRECTSOUND direct_sound;
|
LPDIRECTSOUND direct_sound;
|
||||||
if ( ! SUCCEEDED(direct_sound_create( 0, & direct_sound, 0 )) )
|
if ( ! SUCCEEDED(direct_sound_create( 0, & direct_sound, 0 )) )
|
||||||
@ -223,7 +224,7 @@ init_sound(HWND window_handle, s32 samples_per_second, s32 buffer_size )
|
|||||||
wave_format {};
|
wave_format {};
|
||||||
wave_format.wFormatTag = WAVE_FORMAT_PCM; /* format type */
|
wave_format.wFormatTag = WAVE_FORMAT_PCM; /* format type */
|
||||||
wave_format.nChannels = 2; /* number of channels (i.e. mono, stereo...) */
|
wave_format.nChannels = 2; /* number of channels (i.e. mono, stereo...) */
|
||||||
wave_format.nSamplesPerSec = samples_per_second; /* sample rate */
|
wave_format.nSamplesPerSec = scast(u32, samples_per_second); /* sample rate */
|
||||||
wave_format.wBitsPerSample = 16; /* number of bits per sample of mono data */
|
wave_format.wBitsPerSample = 16; /* number of bits per sample of mono data */
|
||||||
wave_format.nBlockAlign = wave_format.nChannels * wave_format.wBitsPerSample / 8 ; /* block size of data */
|
wave_format.nBlockAlign = wave_format.nChannels * wave_format.wBitsPerSample / 8 ; /* block size of data */
|
||||||
wave_format.nAvgBytesPerSec = wave_format.nSamplesPerSec * wave_format.nBlockAlign; /* for buffer estimation */
|
wave_format.nAvgBytesPerSec = wave_format.nSamplesPerSec * wave_format.nBlockAlign; /* for buffer estimation */
|
||||||
@ -453,88 +454,6 @@ main_window_callback(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_SYSKEYDOWN:
|
|
||||||
case WM_SYSKEYUP:
|
|
||||||
case WM_KEYDOWN:
|
|
||||||
case WM_KEYUP:
|
|
||||||
{
|
|
||||||
u32 vk_code = w_param;
|
|
||||||
b32 is_down = (l_param >> 31) == 0;
|
|
||||||
b32 was_down = (l_param >> 30);
|
|
||||||
b32 alt_down = (l_param & (1 << 29));
|
|
||||||
|
|
||||||
switch ( vk_code )
|
|
||||||
{
|
|
||||||
case 'Q':
|
|
||||||
{
|
|
||||||
OutputDebugStringA( "Q\n" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'E':
|
|
||||||
{
|
|
||||||
OutputDebugStringA( "E\n" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'W':
|
|
||||||
{
|
|
||||||
OutputDebugStringA( "W\n" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'A':
|
|
||||||
{
|
|
||||||
OutputDebugStringA( "A\n" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'S':
|
|
||||||
{
|
|
||||||
OutputDebugStringA( "S\n" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'D':
|
|
||||||
{
|
|
||||||
OutputDebugStringA( "D\n" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VK_ESCAPE:
|
|
||||||
{
|
|
||||||
OutputDebugStringA( "Escape\n" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VK_UP:
|
|
||||||
{
|
|
||||||
OutputDebugStringA( "Up\n" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VK_DOWN:
|
|
||||||
{
|
|
||||||
OutputDebugStringA( "Down\n" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VK_LEFT:
|
|
||||||
{
|
|
||||||
OutputDebugStringA( "Left\n" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VK_RIGHT:
|
|
||||||
{
|
|
||||||
OutputDebugStringA( "Right\n" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VK_SPACE:
|
|
||||||
{
|
|
||||||
OutputDebugStringA( "Space\n" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VK_F4:
|
|
||||||
{
|
|
||||||
if ( alt_down )
|
|
||||||
Running = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
{
|
||||||
PAINTSTRUCT info;
|
PAINTSTRUCT info;
|
||||||
@ -576,6 +495,13 @@ input_process_digital_btn( engine::DigitalBtn* old_state, engine::DigitalBtn* ne
|
|||||||
#undef had_transition
|
#undef had_transition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void
|
||||||
|
input_process_keyboard_key( engine::DigitalBtn* key, b32 is_down )
|
||||||
|
{
|
||||||
|
key->State = is_down;
|
||||||
|
key->HalfTransitions += is_down;
|
||||||
|
}
|
||||||
|
|
||||||
NS_PLATFORM_END
|
NS_PLATFORM_END
|
||||||
|
|
||||||
int CALLBACK
|
int CALLBACK
|
||||||
@ -672,7 +598,7 @@ WinMain(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WinDimensions dimensions = get_window_dimensions( window_handle );
|
// WinDimensions dimensions = get_window_dimensions( window_handle );
|
||||||
resize_dib_section( &BackBuffer, 1280, 720 );
|
resize_dib_section( &BackBuffer, 1280, 720 );
|
||||||
|
|
||||||
SoundOutput sound_output;
|
SoundOutput sound_output;
|
||||||
@ -709,6 +635,10 @@ WinMain(
|
|||||||
|
|
||||||
engine::InputState input {};
|
engine::InputState input {};
|
||||||
|
|
||||||
|
engine::KeyboardState keyboard;
|
||||||
|
input.Controllers[0].Keyboard = & keyboard;
|
||||||
|
// Important: Assuming keyboard always connected for now, and assigning to first controller.
|
||||||
|
|
||||||
using EngineXInputPadStates = engine::XInputPadState[ Max_Controllers ];
|
using EngineXInputPadStates = engine::XInputPadState[ Max_Controllers ];
|
||||||
EngineXInputPadStates xpad_states[2];
|
EngineXInputPadStates xpad_states[2];
|
||||||
EngineXInputPadStates* old_xpads = & xpad_states[0];
|
EngineXInputPadStates* old_xpads = & xpad_states[0];
|
||||||
@ -754,9 +684,11 @@ WinMain(
|
|||||||
Running = true;
|
Running = true;
|
||||||
while( Running )
|
while( Running )
|
||||||
{
|
{
|
||||||
|
keyboard = {};
|
||||||
|
|
||||||
// Window Management
|
// Window Management
|
||||||
{
|
{
|
||||||
if ( PeekMessageW( & window_msg_info, 0, 0, 0, PM_Remove_Messages_From_Queue ) )
|
while ( PeekMessageW( & window_msg_info, 0, 0, 0, PM_Remove_Messages_From_Queue ) )
|
||||||
{
|
{
|
||||||
if ( window_msg_info.message == WM_QUIT )
|
if ( window_msg_info.message == WM_QUIT )
|
||||||
{
|
{
|
||||||
@ -764,10 +696,98 @@ WinMain(
|
|||||||
Running = false;
|
Running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Keyboard input handling
|
||||||
|
switch (window_msg_info.message)
|
||||||
|
{
|
||||||
|
case WM_SYSKEYDOWN:
|
||||||
|
case WM_SYSKEYUP:
|
||||||
|
case WM_KEYDOWN:
|
||||||
|
case WM_KEYUP:
|
||||||
|
{
|
||||||
|
WPARAM vk_code = window_msg_info.wParam;
|
||||||
|
b32 is_down = scast(b32, (window_msg_info.lParam >> 31) == 0 );
|
||||||
|
b32 was_down = scast(b32, (window_msg_info.lParam >> 30) );
|
||||||
|
b32 alt_down = scast(b32, (window_msg_info.lParam & (1 << 29)) );
|
||||||
|
|
||||||
|
switch ( vk_code )
|
||||||
|
{
|
||||||
|
case 'Q':
|
||||||
|
{
|
||||||
|
input_process_keyboard_key( & keyboard.Q, is_down );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'E':
|
||||||
|
{
|
||||||
|
input_process_keyboard_key( & keyboard.E, is_down );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'W':
|
||||||
|
{
|
||||||
|
input_process_keyboard_key( & keyboard.W, is_down );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'A':
|
||||||
|
{
|
||||||
|
input_process_keyboard_key( & keyboard.A, is_down );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'S':
|
||||||
|
{
|
||||||
|
input_process_keyboard_key( & keyboard.S, is_down );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
{
|
||||||
|
input_process_keyboard_key( & keyboard.D, is_down );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VK_ESCAPE:
|
||||||
|
{
|
||||||
|
input_process_keyboard_key( & keyboard.Esc, is_down );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VK_UP:
|
||||||
|
{
|
||||||
|
input_process_keyboard_key( & keyboard.Up, is_down );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VK_DOWN:
|
||||||
|
{
|
||||||
|
input_process_keyboard_key( & keyboard.Down, is_down );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VK_LEFT:
|
||||||
|
{
|
||||||
|
input_process_keyboard_key( & keyboard.Left, is_down );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VK_RIGHT:
|
||||||
|
{
|
||||||
|
input_process_keyboard_key( & keyboard.Right, is_down );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VK_SPACE:
|
||||||
|
{
|
||||||
|
input_process_keyboard_key( & keyboard.Space, is_down );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VK_F4:
|
||||||
|
{
|
||||||
|
if ( alt_down )
|
||||||
|
Running = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
TranslateMessage( & window_msg_info );
|
TranslateMessage( & window_msg_info );
|
||||||
DispatchMessageW( & window_msg_info );
|
DispatchMessageW( & window_msg_info );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
{
|
{
|
||||||
@ -901,8 +921,8 @@ WinMain(
|
|||||||
b32 sound_is_valid = false;
|
b32 sound_is_valid = false;
|
||||||
DWORD ds_play_cursor;
|
DWORD ds_play_cursor;
|
||||||
DWORD ds_write_cursor;
|
DWORD ds_write_cursor;
|
||||||
DWORD byte_to_lock;
|
DWORD byte_to_lock = 0;
|
||||||
DWORD bytes_to_write;
|
DWORD bytes_to_write = 0;
|
||||||
if ( SUCCEEDED( DS_SecondaryBuffer->GetCurrentPosition( & ds_play_cursor, & ds_write_cursor ) ))
|
if ( SUCCEEDED( DS_SecondaryBuffer->GetCurrentPosition( & ds_play_cursor, & ds_write_cursor ) ))
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -971,10 +991,10 @@ WinMain(
|
|||||||
#define MS_PER_SECOND 1000
|
#define MS_PER_SECOND 1000
|
||||||
#define MegaCycles_Per_Second (1000 * 1000)
|
#define MegaCycles_Per_Second (1000 * 1000)
|
||||||
u64 cycles_elapsed = end_cycle_count - last_cycle_time;
|
u64 cycles_elapsed = end_cycle_count - last_cycle_time;
|
||||||
s32 mega_cycles_elapsed = cycles_elapsed / MegaCycles_Per_Second;
|
u64 mega_cycles_elapsed = cycles_elapsed / MegaCycles_Per_Second;
|
||||||
u64 frame_time_elapsed = frame_cycle_time_end - last_frame_time;
|
u64 frame_time_elapsed = frame_cycle_time_end - last_frame_time;
|
||||||
u32 ms_per_frame = MS_PER_SECOND * frame_time_elapsed / perf_counter_frequency;
|
u32 ms_per_frame = scast(u32, MS_PER_SECOND * frame_time_elapsed / perf_counter_frequency);
|
||||||
u32 fps = perf_counter_frequency / frame_time_elapsed;
|
u32 fps = scast(u32, perf_counter_frequency / frame_time_elapsed);
|
||||||
|
|
||||||
// char ms_timing_debug[256] {};
|
// char ms_timing_debug[256] {};
|
||||||
// wsprintfA( ms_timing_debug, "%d ms\n" "FPS: %d\n" "mega cycles: %d\n", ms_per_frame, fps, mega_cycles_elapsed );
|
// wsprintfA( ms_timing_debug, "%d ms\n" "FPS: %d\n" "mega cycles: %d\n", ms_per_frame, fps, mega_cycles_elapsed );
|
||||||
|
@ -1,12 +1,19 @@
|
|||||||
// Joyshock grime wrapper
|
// Joyshock grime wrapper
|
||||||
|
|
||||||
#if __clang__
|
#include "grime.h"
|
||||||
|
|
||||||
|
#ifdef COMPILER_CLANG
|
||||||
# pragma clang diagnostic push
|
# pragma clang diagnostic push
|
||||||
# pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
|
# pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
|
||||||
|
#elif COMPILER_MSVC
|
||||||
|
# pragma warning( push )
|
||||||
|
# pragma warning( disable: 4820 )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "JoyShockLibrary/JoyShockLibrary.h"
|
#include "JoyShockLibrary/JoyShockLibrary.h"
|
||||||
|
|
||||||
#if __clang__
|
#ifdef COMPILER_CLANG
|
||||||
# pragma clang diagnostic pop
|
# pragma clang diagnostic pop
|
||||||
|
#elif COMPILER_MSVC
|
||||||
|
# pragma warning( pop )
|
||||||
#endif
|
#endif
|
@ -14,7 +14,7 @@
|
|||||||
# define TAU_OVER_4 1.570796326794896619231321691639751442f
|
# define TAU_OVER_4 1.570796326794896619231321691639751442f
|
||||||
# define TAU_OVER_8 0.785398163397448309615660845819875721f
|
# define TAU_OVER_8 0.785398163397448309615660845819875721f
|
||||||
|
|
||||||
# define E 2.71828182845904523536f
|
# define Euler 2.71828182845904523536f
|
||||||
# define SQRT_TWO 1.41421356237309504880168872420969808f
|
# define SQRT_TWO 1.41421356237309504880168872420969808f
|
||||||
# define SQRT_THREE 1.73205080756887729352744634150587236f
|
# define SQRT_THREE 1.73205080756887729352744634150587236f
|
||||||
# define SQRT_FIVE 2.23606797749978969640917366873127623f
|
# define SQRT_FIVE 2.23606797749978969640917366873127623f
|
||||||
|
@ -4,6 +4,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#pragma warning( disable: 4201 ) // Support for non-standard nameless struct or union extesnion
|
||||||
|
#pragma warning( disable: 4100 ) // Support for unreferenced formal parameters
|
||||||
|
#pragma warning( disable: 4800 ) // Support implicit conversion to bools
|
||||||
|
#pragma warning( disable: 4365 ) // Support for signed/unsigned mismatch auto-conversion
|
||||||
|
#pragma warning( disable: 4189 ) // Support for unused variables
|
||||||
|
#pragma warning( disable: 4514 ) // Support for unused inline functions
|
||||||
|
#pragma warning( disable: 4505 ) // Support for unused static functions
|
||||||
|
#pragma warning( disable: 5045 ) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
|
||||||
|
|
||||||
#include "grime.h"
|
#include "grime.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "generics.h"
|
#include "generics.h"
|
||||||
@ -22,8 +32,9 @@ NS_PLATFORM_BEGIN
|
|||||||
|
|
||||||
struct Debug_FileContent
|
struct Debug_FileContent
|
||||||
{
|
{
|
||||||
u32 Size;
|
|
||||||
void* Data;
|
void* Data;
|
||||||
|
u32 Size;
|
||||||
|
char _PAD_[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
void debug_file_free_content ( Debug_FileContent* file_content );
|
void debug_file_free_content ( Debug_FileContent* file_content );
|
||||||
|
@ -3,11 +3,15 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#pragma warning( push )
|
||||||
|
#pragma warning( disable: 5105 )
|
||||||
|
#pragma warning( disable: 4820 )
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <xinput.h>
|
#include <xinput.h>
|
||||||
#include <mmeapi.h>
|
#include <mmeapi.h>
|
||||||
#include <dsound.h>
|
#include <dsound.h>
|
||||||
|
#pragma warning( pop )
|
||||||
|
|
||||||
// #include "windows/windows_base.h"
|
// #include "windows/windows_base.h"
|
||||||
// #include "windows/window.h"
|
// #include "windows/window.h"
|
||||||
@ -146,8 +150,11 @@ xinput_load_library_bindings()
|
|||||||
{
|
{
|
||||||
HMODULE xinput_lib = LoadLibraryA( XINPUT_DLL_A );
|
HMODULE xinput_lib = LoadLibraryA( XINPUT_DLL_A );
|
||||||
|
|
||||||
|
#pragma warning( push )
|
||||||
|
#pragma warning( disable: 4191 )
|
||||||
xinput_get_state = rcast( XInputGetStateFn*, GetProcAddress( xinput_lib, "XInputGetState" ));
|
xinput_get_state = rcast( XInputGetStateFn*, GetProcAddress( xinput_lib, "XInputGetState" ));
|
||||||
xinput_set_state = rcast( XInputSetStateFn*, GetProcAddress( xinput_lib, "XInputSetState" ));
|
xinput_set_state = rcast( XInputSetStateFn*, GetProcAddress( xinput_lib, "XInputSetState" ));
|
||||||
|
#pragma warning( pop )
|
||||||
}
|
}
|
||||||
#pragma endregion XInput
|
#pragma endregion XInput
|
||||||
|
|
||||||
|
@ -131,6 +131,7 @@ if ( $vendor -match "clang" )
|
|||||||
$flag_library = '-l'
|
$flag_library = '-l'
|
||||||
$flag_library_path = '-L'
|
$flag_library_path = '-L'
|
||||||
$flag_linker = '-Wl,'
|
$flag_linker = '-Wl,'
|
||||||
|
$flag_link_mapfile = '-Map'
|
||||||
$flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
|
$flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
|
||||||
$flag_link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS'
|
$flag_link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS'
|
||||||
$flag_link_win_machine_32 = '/MACHINE:X86'
|
$flag_link_win_machine_32 = '/MACHINE:X86'
|
||||||
@ -141,6 +142,7 @@ if ( $vendor -match "clang" )
|
|||||||
$flag_no_optimization = '-O0'
|
$flag_no_optimization = '-O0'
|
||||||
$flag_optimize_fast = '-O2'
|
$flag_optimize_fast = '-O2'
|
||||||
$flag_optimize_size = '-O1'
|
$flag_optimize_size = '-O1'
|
||||||
|
$flag_optimize_intrinsics = '-Oi'
|
||||||
$flag_path_output = '-o'
|
$flag_path_output = '-o'
|
||||||
$flag_preprocess_non_intergrated = '-no-integrated-cpp'
|
$flag_preprocess_non_intergrated = '-no-integrated-cpp'
|
||||||
$flag_profiling_debug = '-fdebug-info-for-profiling'
|
$flag_profiling_debug = '-fdebug-info-for-profiling'
|
||||||
@ -149,7 +151,7 @@ if ( $vendor -match "clang" )
|
|||||||
$flag_target_arch = '-target'
|
$flag_target_arch = '-target'
|
||||||
$flag_wall = '-Wall'
|
$flag_wall = '-Wall'
|
||||||
$flag_warning = '-W'
|
$flag_warning = '-W'
|
||||||
$flag_warning_as_error = '-Werror'
|
$flag_warnings_as_errors = '-Werror'
|
||||||
$flag_win_nologo = '/nologo'
|
$flag_win_nologo = '/nologo'
|
||||||
|
|
||||||
$ignore_warning_ms_include = 'no-microsoft-include'
|
$ignore_warning_ms_include = 'no-microsoft-include'
|
||||||
@ -175,6 +177,7 @@ if ( $vendor -match "clang" )
|
|||||||
|
|
||||||
$object = $executable -replace '\.exe', '.obj'
|
$object = $executable -replace '\.exe', '.obj'
|
||||||
$pdb = $executable -replace '\.exe', '.pdb'
|
$pdb = $executable -replace '\.exe', '.pdb'
|
||||||
|
$map = $executable -replace '\.exe', '.map'
|
||||||
|
|
||||||
$compiler_args += @(
|
$compiler_args += @(
|
||||||
$flag_no_color_diagnostics,
|
$flag_no_color_diagnostics,
|
||||||
@ -213,6 +216,7 @@ if ( $vendor -match "clang" )
|
|||||||
if ( $debug ) {
|
if ( $debug ) {
|
||||||
$linker_args += $flag_link_win_debug
|
$linker_args += $flag_link_win_debug
|
||||||
$linker_args += $flag_link_win_pdb + $pdb
|
$linker_args += $flag_link_win_pdb + $pdb
|
||||||
|
$linker_args += $flag_link_mapfile + $map
|
||||||
}
|
}
|
||||||
|
|
||||||
$libraries | ForEach-Object {
|
$libraries | ForEach-Object {
|
||||||
@ -241,7 +245,7 @@ if ( $vendor -match "msvc" )
|
|||||||
$flag_compile = '/c'
|
$flag_compile = '/c'
|
||||||
$flag_debug = '/Zi'
|
$flag_debug = '/Zi'
|
||||||
$flag_define = '/D'
|
$flag_define = '/D'
|
||||||
$flag_exceptions_disabled = '/EHs-c-'
|
$flag_exceptions_disabled = '/EHsc-'
|
||||||
$flag_RTTI_disabled = '/GR-'
|
$flag_RTTI_disabled = '/GR-'
|
||||||
$flag_include = '/I'
|
$flag_include = '/I'
|
||||||
$flag_full_src_path = '/FC'
|
$flag_full_src_path = '/FC'
|
||||||
@ -249,6 +253,8 @@ if ( $vendor -match "msvc" )
|
|||||||
$flag_dll = '/LD'
|
$flag_dll = '/LD'
|
||||||
$flag_dll_debug = '/LDd'
|
$flag_dll_debug = '/LDd'
|
||||||
$flag_linker = '/link'
|
$flag_linker = '/link'
|
||||||
|
$flag_link_mapfile = '/MAP:'
|
||||||
|
$flag_link_optimize_references = '/OPT:REF'
|
||||||
$flag_link_win_debug = '/DEBUG'
|
$flag_link_win_debug = '/DEBUG'
|
||||||
$flag_link_win_pdb = '/PDB:'
|
$flag_link_win_pdb = '/PDB:'
|
||||||
$flag_link_win_machine_32 = '/MACHINE:X86'
|
$flag_link_win_machine_32 = '/MACHINE:X86'
|
||||||
@ -263,6 +269,7 @@ if ( $vendor -match "msvc" )
|
|||||||
$flag_no_optimization = '/Od'
|
$flag_no_optimization = '/Od'
|
||||||
$flag_optimize_fast = '/O2'
|
$flag_optimize_fast = '/O2'
|
||||||
$flag_optimize_size = '/O1'
|
$flag_optimize_size = '/O1'
|
||||||
|
$flag_optimize_intrinsics = '/Oi'
|
||||||
$flag_optimized_debug = '/Zo'
|
$flag_optimized_debug = '/Zo'
|
||||||
$flag_out_name = '/OUT:'
|
$flag_out_name = '/OUT:'
|
||||||
$flag_path_interm = '/Fo'
|
$flag_path_interm = '/Fo'
|
||||||
@ -271,6 +278,8 @@ if ( $vendor -match "msvc" )
|
|||||||
$flag_preprocess_conform = '/Zc:preprocessor'
|
$flag_preprocess_conform = '/Zc:preprocessor'
|
||||||
$flag_set_stack_size = '/F'
|
$flag_set_stack_size = '/F'
|
||||||
$flag_syntax_only = '/Zs'
|
$flag_syntax_only = '/Zs'
|
||||||
|
$flag_wall = '/Wall'
|
||||||
|
$flag_warnings_as_errors = '/WX'
|
||||||
|
|
||||||
# This works because this project uses a single unit to build
|
# This works because this project uses a single unit to build
|
||||||
function build-simple
|
function build-simple
|
||||||
@ -280,13 +289,14 @@ if ( $vendor -match "msvc" )
|
|||||||
|
|
||||||
$object = $executable -replace '\.exe', '.obj'
|
$object = $executable -replace '\.exe', '.obj'
|
||||||
$pdb = $executable -replace '\.exe', '.pdb'
|
$pdb = $executable -replace '\.exe', '.pdb'
|
||||||
|
$map = $executable -replace '\.exe', '.map'
|
||||||
|
|
||||||
$compiler_args += @(
|
$compiler_args += @(
|
||||||
$flag_nologo,
|
$flag_nologo,
|
||||||
# $flag_all_cpp,
|
# $flag_all_cpp,
|
||||||
# $flag_exceptions_disabled,
|
$flag_exceptions_disabled,
|
||||||
# ( $flag_define + '_HAS_EXCEPTIONS=0' ),
|
( $flag_define + '_HAS_EXCEPTIONS=0' ),
|
||||||
# $flag_RTTI_disabled,
|
$flag_RTTI_disabled,
|
||||||
$flag_preprocess_conform,
|
$flag_preprocess_conform,
|
||||||
$flag_full_src_path,
|
$flag_full_src_path,
|
||||||
( $flag_path_interm + $path_build + '\' ),
|
( $flag_path_interm + $path_build + '\' ),
|
||||||
@ -328,6 +338,7 @@ if ( $vendor -match "msvc" )
|
|||||||
if ( $debug ) {
|
if ( $debug ) {
|
||||||
$linker_args += $flag_link_win_debug
|
$linker_args += $flag_link_win_debug
|
||||||
$linker_args += $flag_link_win_pdb + $pdb
|
$linker_args += $flag_link_win_pdb + $pdb
|
||||||
|
$linker_args += $flag_link_mapfile + $map
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
}
|
}
|
||||||
@ -417,6 +428,11 @@ $compiler_args = @(
|
|||||||
($flag_define + 'UNICODE'),
|
($flag_define + 'UNICODE'),
|
||||||
($flag_define + '_UNICODE')
|
($flag_define + '_UNICODE')
|
||||||
# ($flag_set_stack_size + $stack_size)
|
# ($flag_set_stack_size + $stack_size)
|
||||||
|
$flag_wall
|
||||||
|
$flag_warnings_as_errors
|
||||||
|
$flag_optimize_intrinsics
|
||||||
|
|
||||||
|
($flag_define + 'Build_DLL=0' )
|
||||||
)
|
)
|
||||||
|
|
||||||
if ( $dev ) {
|
if ( $dev ) {
|
||||||
@ -434,6 +450,7 @@ $linker_args = @(
|
|||||||
$lib_jsl,
|
$lib_jsl,
|
||||||
|
|
||||||
$flag_link_win_subsystem_windows
|
$flag_link_win_subsystem_windows
|
||||||
|
$flag_link_optimize_references
|
||||||
)
|
)
|
||||||
|
|
||||||
build-simple $includes $compiler_args $linker_args $unit $executable
|
build-simple $includes $compiler_args $linker_args $unit $executable
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user