Day 15 complete

This commit is contained in:
2023-09-20 14:43:55 -04:00
parent 3de4178fff
commit c4cdac03fa
6 changed files with 135 additions and 5 deletions

View File

@ -152,6 +152,19 @@ update_and_render( InputState* input, OffscreenBuffer* back_buffer, SoundBuffer*
state->XOffset = 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
ControllerState* controller = & input->Controllers[0];

View File

@ -67,7 +67,8 @@ ensure_impl( bool condition, char const* message ) {
JslSetLightColour( 0, (255 << 8 ) ); \
} while (0)
NS_WIN32_BEGIN
NS_PLATFORM_BEGIN
using namespace win32;
// TODO(Ed) : This is a global for now.
global bool Running;
@ -112,6 +113,83 @@ global s32 DS_SecondaryBuffer_BytesPerSample;
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
init_sound(HWND window_handle, s32 samples_per_second, s32 buffer_size )
{
@ -489,8 +567,6 @@ main_window_callback(
return result;
}
NS_WIN32_END
internal void
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
}
NS_PLATFORM_END
int CALLBACK
WinMain(
HINSTANCE instance,
@ -509,6 +587,7 @@ WinMain(
)
{
using namespace win32;
using namespace platform;
// Memory
engine::Memory engine_memory {};

View File

@ -9,3 +9,26 @@
#include "generics.h"
#include "math_constants.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

View File

@ -22,7 +22,7 @@
#define S64_MIN ( -0x7fffffffffffffffll - 1 )
#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.
#if defined( ARCH_64_BIT )
# define UWORD_MIN U64_MIN
@ -104,4 +104,6 @@ typedef s8 b8;
typedef s16 b16;
typedef s32 b32;
using mem_ptr = void*;
#pragma endregion Basic Types