mirror of
https://github.com/Ed94/HandmadeHero.git
synced 2024-12-22 14:24:43 -08:00
Day 15 complete
This commit is contained in:
parent
3de4178fff
commit
c4cdac03fa
@ -6,7 +6,9 @@ Any code I do for this [series](https://handmadehero.org) will be here.
|
|||||||
|
|
||||||
## Scripts
|
## Scripts
|
||||||
|
|
||||||
* `build.ps1` - Builds the project use `.\scripts\build msvc debug` or `.\scripts\build clang debug`. Add `optimize` for optimized builds.
|
* `build.ps1` - Builds the project use `.\scripts\build msvc debug` or `.\scripts\build clang debug`.
|
||||||
|
* `optimize` for optimized builds.
|
||||||
|
* `dev` for development builds. ( Dev memory layout and code paths compiled ).
|
||||||
* `clean.ps1` - Cleans the project
|
* `clean.ps1` - Cleans the project
|
||||||
* `update_deps.ps1` - Updates the project dependencies to their latest from their respective repos. (Not done automatically on build)
|
* `update_deps.ps1` - Updates the project dependencies to their latest from their respective repos. (Not done automatically on build)
|
||||||
|
|
||||||
|
11
docs/Day 015.md
Normal file
11
docs/Day 015.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Day 15
|
||||||
|
|
||||||
|
Casey decides to restrict File IO to 32 bit limits for file size (under 4 gigs). This is due to a limitation do the win32 API in how much it can read into a provided buffer to `ReadFile` by the size of DWORD (4-bytes). For the purposes of this engine and problably almost all applications this is alright.
|
||||||
|
|
||||||
|
IF somehow more is needed, just reading in chunks of 4 gigs at a time is fine.
|
||||||
|
|
||||||
|
I ended up watching a vod earlier recommended: Mysteries of Memory Management Revealed,with Mark Russinovich
|
||||||
|
[Part 1](https://www.youtube.com/watch?v=TrFEgHr72Yg&t)
|
||||||
|
[Part 2](https://www.youtube.com/watch?v=RsQyc4xiJeo)
|
||||||
|
|
||||||
|
Was really nice, I got some of the equivalent info for linux.
|
@ -152,6 +152,19 @@ update_and_render( InputState* input, OffscreenBuffer* back_buffer, SoundBuffer*
|
|||||||
state->XOffset = 0;
|
state->XOffset = 0;
|
||||||
state->YOffset = 0;
|
state->YOffset = 0;
|
||||||
|
|
||||||
|
#if Build_Debug
|
||||||
|
{
|
||||||
|
using namespace platform;
|
||||||
|
|
||||||
|
char* file_path = __FILE__;
|
||||||
|
Debug_FileContent file_content = debug_file_read_content( file_path );
|
||||||
|
if ( file_content.Size )
|
||||||
|
{
|
||||||
|
debug_file_write_content( "test.out", file_content.Size, file_content.Data );
|
||||||
|
debug_file_free_content( & file_content );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
do_once_end
|
do_once_end
|
||||||
|
|
||||||
ControllerState* controller = & input->Controllers[0];
|
ControllerState* controller = & input->Controllers[0];
|
||||||
|
@ -67,7 +67,8 @@ ensure_impl( bool condition, char const* message ) {
|
|||||||
JslSetLightColour( 0, (255 << 8 ) ); \
|
JslSetLightColour( 0, (255 << 8 ) ); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
NS_WIN32_BEGIN
|
NS_PLATFORM_BEGIN
|
||||||
|
using namespace win32;
|
||||||
|
|
||||||
// TODO(Ed) : This is a global for now.
|
// TODO(Ed) : This is a global for now.
|
||||||
global bool Running;
|
global bool Running;
|
||||||
@ -112,6 +113,83 @@ global s32 DS_SecondaryBuffer_BytesPerSample;
|
|||||||
|
|
||||||
global s16* SoundBufferSamples;
|
global s16* SoundBufferSamples;
|
||||||
|
|
||||||
|
|
||||||
|
#if Build_Debug
|
||||||
|
internal
|
||||||
|
void debug_file_free_content( Debug_FileContent* content )
|
||||||
|
{
|
||||||
|
if ( content->Data)
|
||||||
|
{
|
||||||
|
VirtualFree( content->Data, 0, MEM_Release);
|
||||||
|
*content = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal
|
||||||
|
Debug_FileContent debug_file_read_content( char* file_path )
|
||||||
|
{
|
||||||
|
Debug_FileContent result {};
|
||||||
|
|
||||||
|
HANDLE file_handle = CreateFileA( file_path
|
||||||
|
, GENERIC_READ, FILE_SHARE_READ, 0
|
||||||
|
, OPEN_EXISTING, 0, 0
|
||||||
|
);
|
||||||
|
if ( file_handle == INVALID_HANDLE_VALUE )
|
||||||
|
{
|
||||||
|
// TODO(Ed) : Logging
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetFileSizeEx( file_handle, rcast(LARGE_INTEGER*, &result.Size) );
|
||||||
|
if ( result.Size == 0 )
|
||||||
|
{
|
||||||
|
// TODO(Ed) : Logging
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result.Data = VirtualAlloc( 0, result.Size, MEM_Commit_Zeroed | MEM_Reserve, Page_Read_Write );
|
||||||
|
|
||||||
|
u32 bytes_read;
|
||||||
|
if ( ReadFile( file_handle, result.Data, result.Size, rcast(LPDWORD, &bytes_read), 0 ) == false )
|
||||||
|
{
|
||||||
|
// TODO(Ed) : Logging
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( bytes_read != result.Size )
|
||||||
|
{
|
||||||
|
// TODO : Logging
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle( file_handle );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal
|
||||||
|
b32 debug_file_write_content( char* file_path, u32 content_size, void* content_memory )
|
||||||
|
{
|
||||||
|
HANDLE file_handle = CreateFileA( file_path
|
||||||
|
, GENERIC_WRITE, 0, 0
|
||||||
|
, CREATE_ALWAYS, 0, 0
|
||||||
|
);
|
||||||
|
if ( file_handle == INVALID_HANDLE_VALUE )
|
||||||
|
{
|
||||||
|
// TODO : Logging
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD bytes_written;
|
||||||
|
if ( WriteFile( file_handle, content_memory, content_size, & bytes_written, 0 ) == false )
|
||||||
|
{
|
||||||
|
// TODO : Logging
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle( file_handle );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
init_sound(HWND window_handle, s32 samples_per_second, s32 buffer_size )
|
init_sound(HWND window_handle, s32 samples_per_second, s32 buffer_size )
|
||||||
{
|
{
|
||||||
@ -489,8 +567,6 @@ main_window_callback(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_WIN32_END
|
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
input_process_digital_btn( engine::DigitalBtn* old_state, engine::DigitalBtn* new_state, u32 raw_btns, u32 btn_flag )
|
input_process_digital_btn( engine::DigitalBtn* old_state, engine::DigitalBtn* new_state, u32 raw_btns, u32 btn_flag )
|
||||||
{
|
{
|
||||||
@ -500,6 +576,8 @@ input_process_digital_btn( engine::DigitalBtn* old_state, engine::DigitalBtn* ne
|
|||||||
#undef had_transition
|
#undef had_transition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_PLATFORM_END
|
||||||
|
|
||||||
int CALLBACK
|
int CALLBACK
|
||||||
WinMain(
|
WinMain(
|
||||||
HINSTANCE instance,
|
HINSTANCE instance,
|
||||||
@ -509,6 +587,7 @@ WinMain(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
using namespace win32;
|
using namespace win32;
|
||||||
|
using namespace platform;
|
||||||
|
|
||||||
// Memory
|
// Memory
|
||||||
engine::Memory engine_memory {};
|
engine::Memory engine_memory {};
|
||||||
|
@ -9,3 +9,26 @@
|
|||||||
#include "generics.h"
|
#include "generics.h"
|
||||||
#include "math_constants.h"
|
#include "math_constants.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
#define NS_PLATFORM_BEGIN namespace platform {
|
||||||
|
#define NS_PLATFORM_END }
|
||||||
|
|
||||||
|
NS_PLATFORM_BEGIN
|
||||||
|
|
||||||
|
#if Build_Debug
|
||||||
|
/*
|
||||||
|
IMPORTANT : These are not for shipping code - they are blocking and the write isn't protected.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct Debug_FileContent
|
||||||
|
{
|
||||||
|
u32 Size;
|
||||||
|
void* Data;
|
||||||
|
};
|
||||||
|
|
||||||
|
void debug_file_free_content ( Debug_FileContent* file_content );
|
||||||
|
Debug_FileContent debug_file_read_content ( char* file_path );
|
||||||
|
b32 debug_file_write_content( char* file_path, u32 content_size, void* content_memory );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
NS_PLATFORM_END
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#define S64_MIN ( -0x7fffffffffffffffll - 1 )
|
#define S64_MIN ( -0x7fffffffffffffffll - 1 )
|
||||||
#define S64_MAX 0x7fffffffffffffffll
|
#define S64_MAX 0x7fffffffffffffffll
|
||||||
|
|
||||||
// Word size is the same as uw or size_t. This engine will not run on some weird compiler that doesn't
|
// Word size is the same as uw or size_t. This platform will not run on some weird compiler that doesn't
|
||||||
// Match the largest object to the word size of the architecture.
|
// Match the largest object to the word size of the architecture.
|
||||||
#if defined( ARCH_64_BIT )
|
#if defined( ARCH_64_BIT )
|
||||||
# define UWORD_MIN U64_MIN
|
# define UWORD_MIN U64_MIN
|
||||||
@ -104,4 +104,6 @@ typedef s8 b8;
|
|||||||
typedef s16 b16;
|
typedef s16 b16;
|
||||||
typedef s32 b32;
|
typedef s32 b32;
|
||||||
|
|
||||||
|
using mem_ptr = void*;
|
||||||
|
|
||||||
#pragma endregion Basic Types
|
#pragma endregion Basic Types
|
||||||
|
Loading…
Reference in New Issue
Block a user