Kohi Game Engine
|
This file contains the platform layer, or at least the interface to it. Each platform should provide its own implementation of this in a .c file, and should be compiled exclusively of the rest. More...
#include "defines.h"
Go to the source code of this file.
Data Structures | |
struct | platform_system_config |
struct | dynamic_library_function |
struct | dynamic_library |
Typedefs | |
typedef struct platform_system_config | platform_system_config |
typedef struct dynamic_library_function | dynamic_library_function |
typedef struct dynamic_library | dynamic_library |
typedef enum platform_error_code | platform_error_code |
Enumerations | |
enum | platform_error_code { PLATFORM_ERROR_SUCCESS = 0 , PLATFORM_ERROR_UNKNOWN = 1 , PLATFORM_ERROR_FILE_NOT_FOUND = 2 , PLATFORM_ERROR_FILE_LOCKED = 3 , PLATFORM_ERROR_FILE_EXISTS = 4 } |
Functions | |
b8 | platform_system_startup (u64 *memory_requirement, void *state, void *config) |
Performs startup routines within the platform layer. Should be called twice, once to obtain the memory requirement (with state=0), then a second time passing an allocated block of memory to state. More... | |
void | platform_system_shutdown (void *plat_state) |
Shuts down the platform layer. More... | |
b8 | platform_pump_messages (void) |
Performs any platform-specific message pumping that is required for windowing, etc. More... | |
void * | platform_allocate (u64 size, b8 aligned) |
Performs platform-specific memory allocation of the given size. More... | |
void | platform_free (void *block, b8 aligned) |
Frees the given block of memory. More... | |
void * | platform_zero_memory (void *block, u64 size) |
Performs platform-specific zeroing out of the given block of memory. More... | |
void * | platform_copy_memory (void *dest, const void *source, u64 size) |
Copies the bytes of memory in source to dest, of the given size. More... | |
void * | platform_set_memory (void *dest, i32 value, u64 size) |
Sets the bytes of memory to the given value. More... | |
void | platform_console_write (const char *message, u8 colour) |
Performs platform-specific printing to the console of the given message and colour code (if supported). More... | |
void | platform_console_write_error (const char *message, u8 colour) |
Performs platform-specific printing to the error console of the given message and colour code (if supported). More... | |
f64 | platform_get_absolute_time (void) |
Gets the absolute time since the application started. More... | |
KAPI void | platform_sleep (u64 ms) |
Sleep on the thread for the provided milliseconds. This blocks the main thread. Should only be used for giving time back to the OS for unused update power. Therefore it is not exported. Times are approximate. More... | |
i32 | platform_get_processor_count (void) |
Obtains the number of logical processor cores. More... | |
KAPI void | platform_get_handle_info (u64 *out_size, void *memory) |
Obtains the required memory amount for platform-specific handle data, and optionally obtains a copy of that data. Call twice, once with memory=0 to obtain size, then a second time where memory = allocated block. More... | |
KAPI b8 | platform_dynamic_library_load (const char *name, dynamic_library *out_library) |
Loads a dynamic library. More... | |
KAPI b8 | platform_dynamic_library_unload (dynamic_library *library) |
Unloads the given dynamic library. More... | |
KAPI b8 | platform_dynamic_library_load_function (const char *name, dynamic_library *library) |
Loads an exported function of the given name from the provided loaded library. More... | |
KAPI const char * | platform_dynamic_library_extension (void) |
Returns the file extension for the current platform. More... | |
KAPI const char * | platform_dynamic_library_prefix (void) |
Returns a file prefix for libraries for the current platform. More... | |
KAPI platform_error_code | platform_copy_file (const char *source, const char *dest, b8 overwrite_if_exists) |
Copies file at source to destination, optionally overwriting. More... | |
KAPI b8 | platform_watch_file (const char *file_path, u32 *out_watch_id) |
Watch a file at the given path. More... | |
KAPI b8 | platform_unwatch_file (u32 watch_id) |
Stops watching the file with the given watch identifier. More... | |
This file contains the platform layer, or at least the interface to it. Each platform should provide its own implementation of this in a .c file, and should be compiled exclusively of the rest.
typedef struct dynamic_library dynamic_library |
typedef struct dynamic_library_function dynamic_library_function |
typedef enum platform_error_code platform_error_code |
typedef struct platform_system_config platform_system_config |
enum platform_error_code |
Performs platform-specific memory allocation of the given size.
size | The size of the allocation in bytes. |
aligned | Indicates if the allocation should be aligned. |
void platform_console_write | ( | const char * | message, |
u8 | colour | ||
) |
Performs platform-specific printing to the console of the given message and colour code (if supported).
message | The message to be printed. |
colour | The colour to print the text in (if supported). |
void platform_console_write_error | ( | const char * | message, |
u8 | colour | ||
) |
Performs platform-specific printing to the error console of the given message and colour code (if supported).
message | The message to be printed. |
colour | The colour to print the text in (if supported). |
KAPI platform_error_code platform_copy_file | ( | const char * | source, |
const char * | dest, | ||
b8 | overwrite_if_exists | ||
) |
Copies file at source to destination, optionally overwriting.
source | The source file path. |
dest | The destination file path. |
overwrite_if_exists | Indicates if the file should be overwritten if it exists. |
void* platform_copy_memory | ( | void * | dest, |
const void * | source, | ||
u64 | size | ||
) |
Copies the bytes of memory in source to dest, of the given size.
dest | The destination memory block. |
source | The source memory block. |
size | The size of data to be copied. |
KAPI const char* platform_dynamic_library_extension | ( | void | ) |
Returns the file extension for the current platform.
KAPI b8 platform_dynamic_library_load | ( | const char * | name, |
dynamic_library * | out_library | ||
) |
Loads a dynamic library.
name | The name of the library file, excluding the extension. Required. |
out_library | A pointer to hold the loaded library. Required. |
KAPI b8 platform_dynamic_library_load_function | ( | const char * | name, |
dynamic_library * | library | ||
) |
Loads an exported function of the given name from the provided loaded library.
name | The function name to be loaded. |
library | A pointer to the library to load the function from. |
KAPI const char* platform_dynamic_library_prefix | ( | void | ) |
Returns a file prefix for libraries for the current platform.
KAPI b8 platform_dynamic_library_unload | ( | dynamic_library * | library | ) |
Unloads the given dynamic library.
library | A pointer to the loaded library. Required. |
void platform_free | ( | void * | block, |
b8 | aligned | ||
) |
Frees the given block of memory.
block | The block to be freed. |
aligned | Indicates if the block of memory is aligned. |
f64 platform_get_absolute_time | ( | void | ) |
Gets the absolute time since the application started.
Obtains the required memory amount for platform-specific handle data, and optionally obtains a copy of that data. Call twice, once with memory=0 to obtain size, then a second time where memory = allocated block.
out_size | A pointer to hold the memory requirement. |
memory | Allocated block of memory. |
i32 platform_get_processor_count | ( | void | ) |
Obtains the number of logical processor cores.
b8 platform_pump_messages | ( | void | ) |
Performs any platform-specific message pumping that is required for windowing, etc.
Sets the bytes of memory to the given value.
dest | The destination block of memory. |
value | The value to be set. |
size | The size of data to set. |
Sleep on the thread for the provided milliseconds. This blocks the main thread. Should only be used for giving time back to the OS for unused update power. Therefore it is not exported. Times are approximate.
ms | The number of milliseconds to sleep for. |
void platform_system_shutdown | ( | void * | plat_state | ) |
Shuts down the platform layer.
plat_state | A pointer to the platform layer state. |
Performs startup routines within the platform layer. Should be called twice, once to obtain the memory requirement (with state=0), then a second time passing an allocated block of memory to state.
memory_requirement | A pointer to hold the memory requirement in bytes. |
state | A pointer to a block of memory to hold state. If obtaining memory requirement only, pass 0. |
config | A pointer to a configuration platform_system_config structure required by this system. |
Stops watching the file with the given watch identifier.
watch_id | The watch identifier |
Watch a file at the given path.
file_path | The file path. Required. |
out_watch_id | A pointer to hold the watch identifier. |
void* platform_zero_memory | ( | void * | block, |
u64 | size | ||
) |
Performs platform-specific zeroing out of the given block of memory.
block | The block to be zeroed out. |
size | The size of data to zero out. |