HandmadeHero/project/platform/platform.hpp

155 lines
4.6 KiB
C++
Raw Normal View History

2023-09-15 18:35:27 -07:00
/*
Platform abstraction layer for the project.
Services the platform provides to the engine & game.
2023-09-23 18:03:33 -07:00
2023-09-24 19:37:05 -07:00
This should be the only file the engine or game layer can include related to the platform layer.
(Public Interface essentially...)
2023-09-15 18:35:27 -07:00
*/
#pragma once
2023-09-20 21:26:23 -07:00
#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
2023-09-21 23:16:40 -07:00
#pragma warning( disable: 5045 ) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
2023-09-26 22:16:41 -07:00
#pragma warning( disable: 5264 ) // Support for 'const' variables unused
#pragma warning( disable: 4820 ) // Support auto-adding padding to structs
2023-09-20 21:26:23 -07:00
2023-09-23 18:03:33 -07:00
// TODO(Ed) : REMOVE THESE WHEN HE GETS TO THEM
#include <math.h> // TODO : Implement math ourselves
#include <stdio.h> // TODO : Implement output logging ourselves
#include "grime.hpp"
#include "macros.hpp"
#include "generics.hpp"
#include "math_constants.hpp"
#include "types.hpp"
2023-09-26 22:16:41 -07:00
#include "strings.hpp"
2023-09-20 11:43:55 -07:00
#define NS_PLATFORM_BEGIN namespace platform {
#define NS_PLATFORM_END }
NS_PLATFORM_BEGIN
2023-09-26 14:26:35 -07:00
// On-Demand platform interface.
// Everything exposed here should be based on a feature a game may want to provide a user
// (Example: Letting the user change the refresh-rate of the monitor or the engine's target frame-rate)
#if Build_Development
2023-09-20 11:43:55 -07:00
/*
IMPORTANT : These are not for shipping code - they are blocking and the write isn't protected.
*/
struct Debug_FileContent
{
void* Data;
2023-09-20 21:26:23 -07:00
u32 Size;
2023-09-26 22:16:41 -07:00
Byte _PAD_[4];
};
struct BinaryModule
{
void* OpaqueHandle;
2023-09-20 11:43:55 -07:00
};
2023-09-26 14:26:35 -07:00
using DebugFileFreeContentFn = void ( Debug_FileContent* file_content );
using DebugFileReadContentFn = Debug_FileContent ( char const* file_path );
using DebugFileWriteContentFn = b32 ( char const* file_path, u32 content_size, void* content_memory );
2023-09-24 19:37:05 -07:00
2023-09-26 14:26:35 -07:00
using DebugSetPauseRenderingFn = void (b32 value);
2023-09-26 22:16:41 -07:00
// TODO(Ed): This also assumes the symbol name is always within size of the provided buffer, needs to fail if not.
// Note: This is a temporary solution until there is more infrastructure for the engine to use.
void get_symbol_from_module_table( Debug_FileContent symbol_table, u32 symbol_ID, char* symbol_name )
{
struct Token
{
char const* Ptr;
u32 Len;
char _PAD_[4];
};
Token tokens[256] = {};
s32 idx = 0;
char const* scanner = rcast( char const*, symbol_table.Data );
u32 left = symbol_table.Size;
while ( left )
{
if ( *scanner == '\n' || *scanner == '\r' )
{
++ scanner;
-- left;
}
else
{
tokens[idx].Ptr = scanner;
while ( left && *scanner != '\r' && *scanner != '\n' )
{
-- left;
++ scanner;
++ tokens[idx].Len;
}
++ idx;
}
}
Token& token = tokens[symbol_ID];
while ( token.Len -- )
{
*symbol_name = *token.Ptr;
++ symbol_name;
++ token.Ptr;
}
*symbol_name = '\0';
}
2023-09-24 19:37:05 -07:00
#endif
2023-09-23 18:03:33 -07:00
#pragma region Settings Exposure
2023-09-24 19:37:05 -07:00
// Exposing specific properties for user configuration in settings
2023-09-23 18:03:33 -07:00
// Returns the current monitor refresh rate.
2023-09-26 14:26:35 -07:00
using GetMonitorRefreshRateFn = u32();
2023-09-23 18:03:33 -07:00
// Sets the monitor refresh rate
2023-09-26 14:26:35 -07:00
// Must be of the compatiable listing for the monitor the window surface is presenting to
using SetMonitorRefreshRateFn = void ( u32 rate_in_hz );
using GetEngineFrameTargetFn = u32 ();
using SetEngineFrameTargetFn = void ( u32 rate_in_hz );
2023-09-26 22:16:41 -07:00
// This module api will be used to manage the editor and game modules from the engine side,
// without the platform layer needing to know about it.
using LoadBinaryModuleFn = BinaryModule ( char const* module_path );
using UnloadBinaryModuleFn = void ( BinaryModule* module );
using GetModuleProcedureFn = void* ( BinaryModule module, char const* symbol );
2023-09-26 14:26:35 -07:00
struct ModuleAPI
{
#if Build_Development
DebugFileFreeContentFn* debug_file_free_content;
DebugFileReadContentFn* debug_file_read_content;
DebugFileWriteContentFn* debug_file_write_content;
DebugSetPauseRenderingFn* debug_set_pause_rendering;
#endif
2023-09-23 18:03:33 -07:00
2023-09-26 14:26:35 -07:00
GetMonitorRefreshRateFn* get_monitor_refresh_rate;
SetMonitorRefreshRateFn* set_monitor_refresh_rate;
2023-09-23 18:03:33 -07:00
2023-09-26 14:26:35 -07:00
GetEngineFrameTargetFn* get_engine_frame_target;
SetEngineFrameTargetFn* set_engine_frame_target;
2023-09-26 22:16:41 -07:00
LoadBinaryModuleFn* load_binary_module;
UnloadBinaryModuleFn* unload_binary_module;
GetModuleProcedureFn* get_module_procedure;
2023-09-26 14:26:35 -07:00
};
2023-09-23 18:03:33 -07:00
#pragma endregion Settings Exposure
2023-09-24 19:37:05 -07:00
NS_PLATFORM_END