mirror of
https://github.com/Ed94/HandmadeHero.git
synced 2024-12-22 14:24:43 -08:00
Day 7 complete
This commit is contained in:
parent
7ddbc13bc5
commit
d4f04c33b3
8
.vscode/c_cpp_properties.json
vendored
8
.vscode/c_cpp_properties.json
vendored
@ -3,7 +3,9 @@
|
|||||||
{
|
{
|
||||||
"name": "Win32 msvc",
|
"name": "Win32 msvc",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/project/**"
|
"${workspaceFolder}/project/",
|
||||||
|
"${workspaceFolder}/project/dependencies/",
|
||||||
|
"${workspaceFolder}/project/platform/",
|
||||||
],
|
],
|
||||||
"defines": [
|
"defines": [
|
||||||
"_DEBUG",
|
"_DEBUG",
|
||||||
@ -19,7 +21,9 @@
|
|||||||
{
|
{
|
||||||
"name": "Win32 clang",
|
"name": "Win32 clang",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/project/**"
|
"${workspaceFolder}/project/",
|
||||||
|
"${workspaceFolder}/project/dependencies/",
|
||||||
|
"${workspaceFolder}/project/platform/",
|
||||||
],
|
],
|
||||||
"defines": [
|
"defines": [
|
||||||
"_DEBUG",
|
"_DEBUG",
|
||||||
|
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -30,10 +30,11 @@
|
|||||||
"list": "cpp",
|
"list": "cpp",
|
||||||
"xhash": "cpp",
|
"xhash": "cpp",
|
||||||
"shared_mutex": "cpp",
|
"shared_mutex": "cpp",
|
||||||
"mutex": "cpp"
|
"mutex": "cpp",
|
||||||
|
"system_error": "cpp"
|
||||||
},
|
},
|
||||||
"C_Cpp.intelliSenseEngineFallback": "disabled",
|
"C_Cpp.intelliSenseEngineFallback": "disabled",
|
||||||
"C_Cpp.errorSquiggles": "disabled", // This doesn't work well with how the headers are included.
|
"C_Cpp.errorSquiggles": "enabled",
|
||||||
"C_Cpp.default.compilerPath": "cl.exe",
|
"C_Cpp.default.compilerPath": "cl.exe",
|
||||||
"C_Cpp.exclusionPolicy": "checkFilesAndFolders",
|
"C_Cpp.exclusionPolicy": "checkFilesAndFolders",
|
||||||
"C_Cpp.files.exclude": {
|
"C_Cpp.files.exclude": {
|
||||||
|
@ -14,10 +14,10 @@
|
|||||||
<CleanCommand>pwsh $(WorkspaceDirectory)/scripts/clean.ps1</CleanCommand>
|
<CleanCommand>pwsh $(WorkspaceDirectory)/scripts/clean.ps1</CleanCommand>
|
||||||
<BuildWorkingDirectory></BuildWorkingDirectory>
|
<BuildWorkingDirectory></BuildWorkingDirectory>
|
||||||
<CancelBuild></CancelBuild>
|
<CancelBuild></CancelBuild>
|
||||||
<RunCommand>$(WorkspaceDirectory)/projects/build/handmade_win32.exe</RunCommand>
|
<RunCommand>$(WorkspaceDirectory)/build/handmade_win32.exe</RunCommand>
|
||||||
<RunCommandWorkingDirectory>$(WorkspaceDirectory)/projects</RunCommandWorkingDirectory>
|
<RunCommandWorkingDirectory>$(WorkspaceDirectory)/data</RunCommandWorkingDirectory>
|
||||||
<DebugCommand>$(WorkspaceDirectory)/projects/build/handmade_win32.exe</DebugCommand>
|
<DebugCommand>$(WorkspaceDirectory)/build/handmade_win32.exe</DebugCommand>
|
||||||
<ExePathCommand>$(WorkspaceDirectory)/projects/build/handmade_win32.exe</ExePathCommand>
|
<ExePathCommand>$(WorkspaceDirectory)/build/handmade_win32.exe</ExePathCommand>
|
||||||
<DebugSln></DebugSln>
|
<DebugSln></DebugSln>
|
||||||
<UseVisualStudioEnvBat>false</UseVisualStudioEnvBat>
|
<UseVisualStudioEnvBat>false</UseVisualStudioEnvBat>
|
||||||
<Configurations>
|
<Configurations>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# HandmadeHero
|
# HandmadeHero
|
||||||
|
|
||||||
Any code I do for this series will be here.
|
Any code I do for this [series](https://handmadehero.org) will be here.
|
||||||
|
|
||||||
***(Only original hand-written code will be here, no code from the series itself)***
|
***(Only original hand-written code will be here, no code from the series itself)***
|
||||||
|
|
||||||
|
@ -12,23 +12,34 @@
|
|||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
// #include <stdio.h>
|
||||||
|
|
||||||
#include "win32.h"
|
#include "win32.h"
|
||||||
|
|
||||||
// Using this to get dualsense controllers
|
// Using this to get dualsense controllers
|
||||||
#include "JoyShockLibrary/JoyShockLibrary.h"
|
#include "JoyShockLibrary/JoyShockLibrary.h"
|
||||||
|
|
||||||
|
// TOOD(Ed): Redo these macros properly later.
|
||||||
|
|
||||||
#define congrats( message ) do { \
|
#define congrats( message ) do { \
|
||||||
JslSetLightColour( 0, (255 << 16) | (215 << 8) ); \
|
JslSetLightColour( 0, (255 << 16) | (215 << 8) ); \
|
||||||
JslSetRumble( 0, 0, 255 ); \
|
|
||||||
MessageBoxA( 0, message, "Congratulations!", MB_OK | MB_ICONEXCLAMATION ); \
|
MessageBoxA( 0, message, "Congratulations!", MB_OK | MB_ICONEXCLAMATION ); \
|
||||||
JslSetLightColour( 0, (255 << 8 ) ); \
|
JslSetLightColour( 0, (255 << 8 ) ); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define ensure( condition, message ) ensure_impl( condition, message )
|
||||||
|
inline bool
|
||||||
|
ensure_impl( bool condition, char const* message ) {
|
||||||
|
if ( ! condition ) {
|
||||||
|
JslSetLightColour( 0, (255 << 16) );
|
||||||
|
MessageBoxA( 0, message, "Ensure Failure", MB_OK | MB_ICONASTERISK );
|
||||||
|
JslSetLightColour( 0, ( 255 << 8 ) );
|
||||||
|
}
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
#define fatal(message) do { \
|
#define fatal(message) do { \
|
||||||
JslSetLightColour( 0, (255 << 16) ); \
|
JslSetLightColour( 0, (255 << 16) ); \
|
||||||
JslSetRumble( 0, 0, 255 ); \
|
|
||||||
MessageBoxA( 0, message, "Fatal Error", MB_OK | MB_ICONERROR ); \
|
MessageBoxA( 0, message, "Fatal Error", MB_OK | MB_ICONERROR ); \
|
||||||
JslSetLightColour( 0, (255 << 8 ) ); \
|
JslSetLightColour( 0, (255 << 8 ) ); \
|
||||||
} while (0)
|
} while (0)
|
||||||
@ -59,7 +70,100 @@ struct WinDimensions
|
|||||||
global OffscreenBuffer BackBuffer;
|
global OffscreenBuffer BackBuffer;
|
||||||
global WinDimensions WindowDimensions;
|
global WinDimensions WindowDimensions;
|
||||||
|
|
||||||
WinDimensions get_window_dimensions( HWND window_handle )
|
HRESULT WINAPI
|
||||||
|
DirectSoundCreate(LPGUID lpGuid, LPDIRECTSOUND* ppDS, LPUNKNOWN pUnkOuter );
|
||||||
|
|
||||||
|
using DirectSoundCreateFn = HRESULT WINAPI (LPGUID lpGuid, LPDIRECTSOUND* ppDS, LPUNKNOWN pUnkOuter );
|
||||||
|
|
||||||
|
global DirectSoundCreateFn* direct_sound_create;
|
||||||
|
|
||||||
|
|
||||||
|
internal void
|
||||||
|
init_sound(HWND window_handle, s32 samples_per_second, s32 buffer_size )
|
||||||
|
{
|
||||||
|
// Load library
|
||||||
|
HMODULE sound_library = LoadLibraryA( "dsound.dll" );
|
||||||
|
if ( ! ensure(sound_library, "Failed to load direct sound library" ) )
|
||||||
|
{
|
||||||
|
// TOOD : Diagnostic
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get direct sound object
|
||||||
|
direct_sound_create = rcast( DirectSoundCreateFn*, GetProcAddress( sound_library, "DirectSoundCreate" ));
|
||||||
|
if ( ! ensure(direct_sound_create, "Failed to get direct_sound_create_procedure" ) )
|
||||||
|
{
|
||||||
|
// TOOD : Diagnostic
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LPDIRECTSOUND direct_sound;
|
||||||
|
if ( ! SUCCEEDED(direct_sound_create( 0, & direct_sound, 0 )) )
|
||||||
|
{
|
||||||
|
// TODO : Diagnostic
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! SUCCEEDED( direct_sound->SetCooperativeLevel(window_handle, DSSCL_PRIORITY) ) )
|
||||||
|
{
|
||||||
|
// TODO : Diagnostic
|
||||||
|
}
|
||||||
|
|
||||||
|
WAVEFORMATEX
|
||||||
|
wave_format {};
|
||||||
|
wave_format.wFormatTag = WAVE_FORMAT_PCM; /* format type */
|
||||||
|
wave_format.nChannels = 2; /* number of channels (i.e. mono, stereo...) */
|
||||||
|
wave_format.nSamplesPerSec = samples_per_second; /* sample rate */
|
||||||
|
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.nAvgBytesPerSec = wave_format.nSamplesPerSec * wave_format.nBlockAlign; /* for buffer estimation */
|
||||||
|
wave_format.cbSize = 0; /* the count in bytes of the size of */
|
||||||
|
|
||||||
|
LPDIRECTSOUNDBUFFER primary_buffer;
|
||||||
|
{
|
||||||
|
DSBUFFERDESC
|
||||||
|
buffer_description { sizeof(buffer_description) };
|
||||||
|
buffer_description.dwFlags = DSBCAPS_PRIMARYBUFFER;
|
||||||
|
buffer_description.dwBufferBytes = 0;
|
||||||
|
|
||||||
|
if ( ! SUCCEEDED( direct_sound->CreateSoundBuffer( & buffer_description, & primary_buffer, 0 ) ))
|
||||||
|
{
|
||||||
|
// TODO : Diagnostic
|
||||||
|
}
|
||||||
|
if ( ! SUCCEEDED( primary_buffer->SetFormat( & wave_format ) ) )
|
||||||
|
{
|
||||||
|
// TODO : Diagnostic
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format is finally set!
|
||||||
|
}
|
||||||
|
|
||||||
|
LPDIRECTSOUNDBUFFER secondary_buffer;
|
||||||
|
{
|
||||||
|
DSBUFFERDESC
|
||||||
|
buffer_description { sizeof(buffer_description) };
|
||||||
|
buffer_description.dwFlags = 0;
|
||||||
|
buffer_description.dwBufferBytes = buffer_size;
|
||||||
|
buffer_description.lpwfxFormat = & wave_format;
|
||||||
|
|
||||||
|
if ( ! SUCCEEDED( direct_sound->CreateSoundBuffer( & buffer_description, & secondary_buffer, 0 ) ))
|
||||||
|
{
|
||||||
|
// TODO : Diagnostic
|
||||||
|
}
|
||||||
|
if ( ! SUCCEEDED( secondary_buffer->SetFormat( & wave_format ) ) )
|
||||||
|
{
|
||||||
|
// TODO : Diagnostic
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create primary buffer
|
||||||
|
|
||||||
|
// Create secondary buffer
|
||||||
|
|
||||||
|
// Start playing
|
||||||
|
}
|
||||||
|
|
||||||
|
internal WinDimensions
|
||||||
|
get_window_dimensions( HWND window_handle )
|
||||||
{
|
{
|
||||||
RECT client_rect;
|
RECT client_rect;
|
||||||
GetClientRect( window_handle, & client_rect );
|
GetClientRect( window_handle, & client_rect );
|
||||||
@ -148,7 +252,7 @@ resize_dib_section( OffscreenBuffer* buffer, u32 width, u32 height )
|
|||||||
|
|
||||||
// We want to "touch" a pixel on every 4-byte boundary
|
// We want to "touch" a pixel on every 4-byte boundary
|
||||||
u32 BitmapMemorySize = (buffer->Width * buffer->Height) * buffer->BytesPerPixel;
|
u32 BitmapMemorySize = (buffer->Width * buffer->Height) * buffer->BytesPerPixel;
|
||||||
buffer->Memory = VirtualAlloc( NULL, BitmapMemorySize, MEM_Commit_Zeroed, Page_Read_Write );
|
buffer->Memory = VirtualAlloc( NULL, BitmapMemorySize, MEM_Commit_Zeroed | MEM_Reserve, Page_Read_Write );
|
||||||
|
|
||||||
// TODO(Ed) : Clear to black
|
// TODO(Ed) : Clear to black
|
||||||
}
|
}
|
||||||
@ -208,8 +312,9 @@ main_window_callback(
|
|||||||
case WM_KEYUP:
|
case WM_KEYUP:
|
||||||
{
|
{
|
||||||
u32 vk_code = w_param;
|
u32 vk_code = w_param;
|
||||||
bool is_down = (l_param >> 31) == 0;
|
b32 is_down = (l_param >> 31) == 0;
|
||||||
bool was_down = (l_param >> 30) != 0;
|
b32 was_down = (l_param >> 30);
|
||||||
|
b32 alt_down = (l_param & (1 << 29));
|
||||||
|
|
||||||
switch ( vk_code )
|
switch ( vk_code )
|
||||||
{
|
{
|
||||||
@ -273,6 +378,12 @@ main_window_callback(
|
|||||||
OutputDebugStringA( "Space\n" );
|
OutputDebugStringA( "Space\n" );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case VK_F4:
|
||||||
|
{
|
||||||
|
if ( alt_down )
|
||||||
|
Running = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -377,6 +488,8 @@ 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 );
|
||||||
|
|
||||||
|
init_sound( window_handle, 48000, 48000 * sizeof(s16) * 2 );
|
||||||
|
|
||||||
MSG msg_info;
|
MSG msg_info;
|
||||||
|
|
||||||
u32 x_offset = 0;
|
u32 x_offset = 0;
|
||||||
|
@ -5,6 +5,8 @@ Alternative header for windows.h
|
|||||||
#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 <dsound.h>
|
||||||
|
|
||||||
// #include "windows/windows_base.h"
|
// #include "windows/windows_base.h"
|
||||||
// #include "windows/window.h"
|
// #include "windows/window.h"
|
||||||
@ -115,12 +117,12 @@ WIN_LIB_API DWORD WINAPI XInputSetState
|
|||||||
|
|
||||||
DWORD WINAPI xinput_get_state_stub( DWORD dwUserIndex, XINPUT_STATE* pVibration ) {
|
DWORD WINAPI xinput_get_state_stub( DWORD dwUserIndex, XINPUT_STATE* pVibration ) {
|
||||||
OutputDebugStringA( "xinput_get_state stubbed!\n");
|
OutputDebugStringA( "xinput_get_state stubbed!\n");
|
||||||
return ERROR_CALL_NOT_IMPLEMENTED;
|
return ERROR_DEVICE_NOT_CONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD WINAPI xinput_set_state_stub( DWORD dwUserIndex, XINPUT_VIBRATION* pVibration ) {
|
DWORD WINAPI xinput_set_state_stub( DWORD dwUserIndex, XINPUT_VIBRATION* pVibration ) {
|
||||||
OutputDebugStringA( "xinput_set_state stubbed!\n");
|
OutputDebugStringA( "xinput_set_state stubbed!\n");
|
||||||
return ERROR_CALL_NOT_IMPLEMENTED;
|
return ERROR_DEVICE_NOT_CONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
using XInputGetStateFn = DWORD WINAPI( DWORD dwUserIndex, XINPUT_STATE* pVibration );
|
using XInputGetStateFn = DWORD WINAPI( DWORD dwUserIndex, XINPUT_STATE* pVibration );
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user