Day 28 complete!

This commit is contained in:
2023-10-01 20:17:14 -04:00
parent faa0bacc07
commit e1623995a7
27 changed files with 985 additions and 2538 deletions

View File

@ -0,0 +1,15 @@
#include "platform.hpp"
struct Context
{
Context* parent;
// AllocatorInfo allocator;
// Logger logger;
};
Context* make_context();
#include "gen/context.gen.hpp"

View File

@ -0,0 +1,3 @@
// This was generated by project/codegen/platform_gen.cpp
#define using_context() Context* parent;

View File

@ -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

View File

@ -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

View File

@ -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