Kohi Game Engine
platform.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include "defines.h"
17 
18 typedef struct platform_system_config {
20  const char* application_name;
22  i32 x;
24  i32 y;
30 
31 typedef struct dynamic_library_function {
32  const char* name;
33  void* pfn;
35 
36 typedef struct dynamic_library {
37  const char* name;
38  const char* filename;
42 
43  // darray
46 
47 typedef enum platform_error_code {
54 
65 b8 platform_system_startup(u64* memory_requirement, void* state, void* config);
66 
72 void platform_system_shutdown(void* plat_state);
73 
81 
89 void* platform_allocate(u64 size, b8 aligned);
90 
97 void platform_free(void* block, b8 aligned);
98 
106 void* platform_zero_memory(void* block, u64 size);
107 
116 void* platform_copy_memory(void* dest, const void* source, u64 size);
117 
126 void* platform_set_memory(void* dest, i32 value, u64 size);
127 
135 void platform_console_write(const char* message, u8 colour);
136 
144 void platform_console_write_error(const char* message, u8 colour);
145 
152 
161 
168 
177 KAPI void platform_get_handle_info(u64* out_size, void* memory);
178 
186 KAPI b8 platform_dynamic_library_load(const char* name, dynamic_library* out_library);
187 
195 
204 
209 
214 
223 KAPI platform_error_code platform_copy_file(const char *source, const char *dest, b8 overwrite_if_exists);
224 
232 KAPI b8 platform_watch_file(const char* file_path, u32* out_watch_id);
233 
This file contains global type definitions which are used throughout the entire engine and applicatio...
#define KAPI
Import/export qualifier.
Definition: defines.h:177
unsigned int u32
Unsigned 32-bit integer.
Definition: defines.h:25
_Bool b8
8-bit boolean type
Definition: defines.h:58
double f64
64-bit floating point number
Definition: defines.h:50
signed int i32
Signed 32-bit integer.
Definition: defines.h:39
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:28
unsigned char u8
Unsigned 8-bit integer.
Definition: defines.h:19
i32 platform_get_processor_count(void)
Obtains the number of logical processor cores.
void platform_free(void *block, b8 aligned)
Frees the given block of memory.
void platform_system_shutdown(void *plat_state)
Shuts down the platform layer.
KAPI b8 platform_watch_file(const char *file_path, u32 *out_watch_id)
Watch a file at the given path.
void * platform_set_memory(void *dest, i32 value, u64 size)
Sets the bytes of memory to the given value.
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.
struct dynamic_library_function dynamic_library_function
struct dynamic_library dynamic_library
void * platform_zero_memory(void *block, u64 size)
Performs platform-specific zeroing out of the given block of memory.
platform_error_code
Definition: platform.h:47
@ PLATFORM_ERROR_SUCCESS
Definition: platform.h:48
@ PLATFORM_ERROR_FILE_EXISTS
Definition: platform.h:52
@ PLATFORM_ERROR_UNKNOWN
Definition: platform.h:49
@ PLATFORM_ERROR_FILE_LOCKED
Definition: platform.h:51
@ PLATFORM_ERROR_FILE_NOT_FOUND
Definition: platform.h:50
struct platform_system_config platform_system_config
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.
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 memor...
void * platform_copy_memory(void *dest, const void *source, u64 size)
Copies the bytes of memory in source to dest, of the given size.
KAPI void platform_sleep(u64 ms)
Sleep on the thread for the provided milliseconds. This blocks the main thread. Should only be used f...
void * platform_allocate(u64 size, b8 aligned)
Performs platform-specific memory allocation of the given size.
f64 platform_get_absolute_time(void)
Gets the absolute time since the application started.
b8 platform_pump_messages(void)
Performs any platform-specific message pumping that is required for windowing, etc.
KAPI b8 platform_dynamic_library_load(const char *name, dynamic_library *out_library)
Loads a dynamic library.
KAPI const char * platform_dynamic_library_extension(void)
Returns the file extension for the current platform.
KAPI b8 platform_unwatch_file(u32 watch_id)
Stops watching the file with the given watch identifier.
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...
KAPI const char * platform_dynamic_library_prefix(void)
Returns a file prefix for libraries for the current platform.
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 o...
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 sup...
KAPI b8 platform_dynamic_library_unload(dynamic_library *library)
Unloads the given dynamic library.
Definition: platform.h:31
void * pfn
Definition: platform.h:33
const char * name
Definition: platform.h:32
Definition: platform.h:36
dynamic_library_function * functions
Definition: platform.h:44
const char * filename
Definition: platform.h:38
const char * name
Definition: platform.h:37
void * internal_data
Definition: platform.h:40
u64 internal_data_size
Definition: platform.h:39
u32 watch_id
Definition: platform.h:41
Definition: platform.h:18
i32 y
y The initial y position of the main window.
Definition: platform.h:24
i32 height
height The initial height of the main window.
Definition: platform.h:28
i32 width
width The initial width of the main window.
Definition: platform.h:26
const char * application_name
application_name The name of the application.
Definition: platform.h:20
i32 x
x The initial x position of the main window.
Definition: platform.h:22