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
2023-10-06 23:33:39 -07:00
# if INTELLISENSE_DIRECTIVES
// TODO(Ed) : REMOVE THESE WHEN CASEY GETS TO THEM
2023-09-23 18:03:33 -07:00
# include <stdio.h> // TODO : Implement output logging ourselves
2023-10-11 14:52:13 -07:00
# include "platform_module.hpp"
2023-09-23 18:52:38 -07:00
# include "grime.hpp"
# include "macros.hpp"
# include "generics.hpp"
# include "math_constants.hpp"
# include "types.hpp"
2023-10-06 23:33:39 -07:00
# include "intrinsics.hpp"
2023-09-26 22:16:41 -07:00
# include "strings.hpp"
2023-10-01 17:17:14 -07:00
# include "context.hpp"
2023-10-06 23:33:39 -07:00
# endif
2023-09-20 11:43:55 -07:00
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-28 10:44:43 -07:00
using DebugSetPauseRenderingFn = void ( b32 value ) ;
2023-09-28 12:41:30 -07:00
# endif
2023-09-26 22:16:41 -07:00
2023-09-28 10:44:43 -07:00
struct File
2023-09-26 22:16:41 -07:00
{
2023-09-30 07:05:37 -07:00
void * opaque_handle ;
Str path ;
void * data ;
u32 size ;
2023-09-20 11:43:55 -07:00
} ;
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.
2023-09-28 10:44:43 -07:00
struct BinaryModule
{
2023-09-30 07:05:37 -07:00
void * opaque_handle ;
2023-09-28 10:44:43 -07:00
} ;
2023-09-26 22:16:41 -07:00
using LoadBinaryModuleFn = BinaryModule ( char const * module_path ) ;
using UnloadBinaryModuleFn = void ( BinaryModule * module ) ;
using GetModuleProcedureFn = void * ( BinaryModule module , char const * symbol ) ;
2023-09-28 10:44:43 -07:00
// The file interface is really just made for the engine to use.
// It will allow for only reading or writting to a file at a time.
// Note: If anything more robust is needed, I'll grab it from the zpl-c library.
2023-09-28 12:41:30 -07:00
// TODO(Ed) : These need to be converted to an async interface.
2023-09-28 10:44:43 -07:00
using FileCheckExistsFn = b32 ( Str const file_path ) ;
using FileCloseFn = void ( File * file ) ;
using FileDelete = b32 ( Str const file_path ) ;
using FileReadContentFn = b32 ( File * file ) ;
using FileReadStreamFn = b32 ( File * file , u32 content_size , void * content_memory ) ;
using FileWriteContentFn = u32 ( File * file , u32 content_size , void * content_memory ) ;
using FileWriteStreamFn = u32 ( File * file , u32 content_size , void * content_memory ) ;
using FileRewindFn = void ( File * file ) ;
2023-09-30 07:05:37 -07:00
using MemoryCopyFn = void ( void * dest , u64 src_size , void * src ) ;
2023-10-01 17:17:14 -07:00
using GetWallClockFn = u64 ( ) ;
2023-09-26 14:26:35 -07:00
struct ModuleAPI
{
2023-09-29 12:58:18 -07:00
Str path_root ;
Str path_binaries ;
Str path_scratch ;
2023-09-26 14:26:35 -07:00
2023-09-28 10:44:43 -07:00
# if Build_Development
2023-09-26 14:26:35 -07:00
DebugSetPauseRenderingFn * debug_set_pause_rendering ;
# endif
2023-09-23 18:03:33 -07:00
2023-10-01 17:17:14 -07:00
GetWallClockFn * get_wall_clock ;
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-28 10:44:43 -07:00
FileCheckExistsFn * file_check_exists ; // Checks if a file exists
FileCloseFn * file_close ; // Files successfuly provided to the user are not automatically closed, use this to close them.
FileDelete * file_delete ; // Deletes a file from the file system
FileReadContentFn * file_read_content ; // Read all content within file
FileReadStreamFn * file_read_stream ; // Read next chunk of content within file
FileRewindFn * file_rewind ; // Rewinds the file stream to the beginning
FileWriteContentFn * file_write_content ; // Writes content to file (overwrites)
FileWriteStreamFn * file_write_stream ; // Appends content to file
2023-09-30 07:05:37 -07:00
MemoryCopyFn * memory_copy ;
2023-09-26 14:26:35 -07:00
} ;
2023-09-23 18:03:33 -07:00
2023-10-01 17:17:14 -07:00
# if Build_Development
2023-10-11 14:52:13 -07:00
// TODO(Ed): This can't be done this way, we need a separate interface for other modules to use this.
// (At least, we need to hookup the symbols statically or at runtime somehow, and right now the only thing that does is the module api passthrough via the Engine API)
2023-10-01 17:17:14 -07:00
void impl_congrats ( char const * message ) ;
bool impl_ensure ( bool condition , char const * message ) ;
void impl_fatal ( char const * message ) ;
# endif
2023-09-23 18:03:33 -07:00
# pragma endregion Settings Exposure
2023-09-24 19:37:05 -07:00
NS_PLATFORM_END