Kohi Game Engine
platform.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include "defines.h"
17 #include "input_types.h"
18 #include "logger.h"
19 
20 typedef struct platform_system_config {
22  const char* application_name;
24 
25 typedef struct dynamic_library_function {
26  const char* name;
27  void* pfn;
29 
30 typedef struct dynamic_library {
31  const char* name;
32  const char* filename;
36 
37  // darray
40 
41 typedef enum platform_error_code {
48 
49 struct platform_state;
50 
54 typedef struct kwindow_config {
59  const char* title;
60  const char* name;
62 
63 struct kwindow_platform_state;
65 
69 typedef struct kwindow {
71  const char* name;
73  const char* title;
74 
79 
85 
90 
92  struct kwindow_platform_state* platform_state;
93 
97 
98 typedef void (*platform_filewatcher_file_deleted_callback)(u32 watcher_id, void* context);
99 typedef void (*platform_filewatcher_file_written_callback)(u32 watcher_id, const char* file_path, b8 is_binary, void* context);
100 typedef void (*platform_window_closed_callback)(const struct kwindow* window);
101 typedef void (*platform_window_resized_callback)(const struct kwindow* window);
102 typedef void (*platform_process_key)(keys key, b8 pressed);
103 typedef void (*platform_process_mouse_button)(mouse_buttons button, b8 pressed);
104 typedef void (*platform_process_mouse_move)(i16 x, i16 y);
105 typedef void (*platform_process_mouse_wheel)(i8 z_delta);
106 
117 KAPI b8 platform_system_startup(u64* memory_requirement, struct platform_state* state, platform_system_config* config);
118 
125 
134 KAPI b8 platform_window_create(const kwindow_config* config, struct kwindow* window, b8 show_immediately);
135 
141 KAPI void platform_window_destroy(struct kwindow* window);
142 
150 
159 
167 KAPI const char* platform_window_title_get(const struct kwindow* window);
168 
176 KAPI b8 platform_window_title_set(struct kwindow* window, const char* title);
177 
185 
193 KAPI void* platform_allocate(u64 size, b8 aligned);
194 
201 KAPI void platform_free(void* block, b8 aligned);
202 
210 KAPI void* platform_zero_memory(void* block, u64 size);
211 
220 KAPI void* platform_copy_memory(void* dest, const void* source, u64 size);
221 
230 KAPI void* platform_set_memory(void* dest, i32 value, u64 size);
231 
240 KAPI void platform_console_write(struct platform_state* platform, log_level level, const char* message);
241 
248 
257 
264 
273 KAPI void platform_get_handle_info(u64* out_size, void* memory);
274 
281 
290 
298 
307 
312 
317 
326 KAPI platform_error_code platform_copy_file(const char* source, const char* dest, b8 overwrite_if_exists);
327 
334 
341 
349 
356 
363 
370 
384  const char* file_path,
385  b8 is_binary,
386  platform_filewatcher_file_written_callback watcher_written_callback,
387  void* watcher_written_context,
388  platform_filewatcher_file_deleted_callback watcher_deleted_callback,
389  void* watcher_deleted_context,
390  u32* out_watch_id);
This file contains global type definitions which are used throughout the entire engine and applicatio...
#define KAPI
Import/export qualifier.
Definition: defines.h:205
unsigned int u32
Unsigned 32-bit integer.
Definition: defines.h:25
signed char i8
Signed 8-bit integer.
Definition: defines.h:33
_Bool b8
8-bit boolean type
Definition: defines.h:58
float f32
32-bit floating point number
Definition: defines.h:47
double f64
64-bit floating point number
Definition: defines.h:50
signed int i32
Signed 32-bit integer.
Definition: defines.h:39
unsigned short u16
Unsigned 16-bit integer.
Definition: defines.h:22
signed short i16
Signed 16-bit integer.
Definition: defines.h:36
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:28
keys
Represents available keyboard keys.
Definition: input_types.h:21
mouse_buttons
Represents available mouse buttons.
Definition: input_types.h:8
This file contains structures and logic pertaining to the logging system.
log_level
Represents levels of logging.
Definition: logger.h:33
KAPI i32 platform_get_processor_count(void)
Obtains the number of logical processor cores.
KAPI void platform_window_destroy(struct kwindow *window)
Destroys the given window.
void(* platform_process_mouse_wheel)(i8 z_delta)
Definition: platform.h:105
KAPI void platform_system_shutdown(struct platform_state *state)
Shuts down the platform layer.
void(* platform_filewatcher_file_deleted_callback)(u32 watcher_id, void *context)
Definition: platform.h:98
KAPI b8 platform_window_create(const kwindow_config *config, struct kwindow *window, b8 show_immediately)
Creates a new window from the given config and optionally opens it immediately.
KAPI void platform_console_write(struct platform_state *platform, log_level level, const char *message)
Performs platform-specific printing to the console of the given message and log level.
KAPI b8 platform_window_show(struct kwindow *window)
Shows the given window. Has no effect if the window is already shown.
KAPI b8 platform_window_title_set(struct kwindow *window, const char *title)
Sets the given window's title, if it exists.
KAPI f64 platform_get_absolute_time(void)
Gets the absolute time since the application started.
KAPI void platform_register_process_mouse_wheel_callback(platform_process_mouse_wheel callback)
Registers the system-level handler for a mouse wheel being scrolled.
KAPI const char * platform_window_title_get(const struct kwindow *window)
Obtains the window title from the given window, if it exists. NOTE: Returns a constant copy of the st...
KAPI b8 platform_system_startup(u64 *memory_requirement, struct platform_state *state, platform_system_config *config)
Performs startup routines within the platform layer. Should be called twice, once to obtain the memor...
struct dynamic_library_function dynamic_library_function
struct dynamic_library dynamic_library
KAPI void platform_register_window_closed_callback(platform_window_closed_callback callback)
Registers the system-level handler for a window being closed.
KAPI void platform_register_process_mouse_move_callback(platform_process_mouse_move callback)
Registers the system-level handler for a mouse being moved.
platform_error_code
Definition: platform.h:41
@ PLATFORM_ERROR_SUCCESS
Definition: platform.h:42
@ PLATFORM_ERROR_FILE_EXISTS
Definition: platform.h:46
@ PLATFORM_ERROR_UNKNOWN
Definition: platform.h:43
@ PLATFORM_ERROR_FILE_LOCKED
Definition: platform.h:45
@ PLATFORM_ERROR_FILE_NOT_FOUND
Definition: platform.h:44
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.
KAPI void platform_register_window_resized_callback(platform_window_resized_callback callback)
Registers the system-level handler for a window being resized.
void(* platform_process_mouse_button)(mouse_buttons button, b8 pressed)
Definition: platform.h:103
KAPI void * platform_zero_memory(void *block, u64 size)
Performs platform-specific zeroing out of the given block of memory.
void(* platform_window_closed_callback)(const struct kwindow *window)
Definition: platform.h:100
KAPI void platform_sleep(u64 ms)
Sleep on the thread for the provided milliseconds. This blocks the main thread. Should only be used f...
KAPI void * platform_allocate(u64 size, b8 aligned)
Performs platform-specific memory allocation of the given size.
void(* platform_process_key)(keys key, b8 pressed)
Definition: platform.h:102
KAPI b8 platform_dynamic_library_load(const char *name, dynamic_library *out_library)
Loads a dynamic library.
void(* platform_window_resized_callback)(const struct kwindow *window)
Definition: platform.h:101
KAPI const char * platform_dynamic_library_extension(void)
Returns the file extension for the current platform.
KAPI void platform_register_process_key(platform_process_key callback)
Registers the system-level handler for a keyboard key being pressed.
KAPI void * platform_dynamic_library_load_function(const char *name, dynamic_library *library)
Loads an exported function of the given name from the provided loaded library.
KAPI b8 platform_watch_file(const char *file_path, b8 is_binary, platform_filewatcher_file_written_callback watcher_written_callback, void *watcher_written_context, platform_filewatcher_file_deleted_callback watcher_deleted_callback, void *watcher_deleted_context, u32 *out_watch_id)
Watch a file at the given path.
KAPI b8 platform_unwatch_file(u32 watch_id)
Stops watching the file with the given watch identifier.
struct kwindow kwindow
Represents a window in the application.
KAPI void * platform_set_memory(void *dest, i32 value, u64 size)
Sets the bytes of memory to the given value.
KAPI void platform_register_process_mouse_button_callback(platform_process_mouse_button callback)
Registers the system-level handler for a mouse button being pressed.
KAPI const char * platform_dynamic_library_prefix(void)
Returns a file prefix for libraries for the current platform.
KAPI b8 platform_pump_messages(void)
Performs any platform-specific message pumping that is required for windowing, etc.
void(* platform_filewatcher_file_written_callback)(u32 watcher_id, const char *file_path, b8 is_binary, void *context)
Definition: platform.h:99
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_process_mouse_move)(i16 x, i16 y)
Definition: platform.h:104
KAPI b8 platform_dynamic_library_unload(dynamic_library *library)
Unloads the given dynamic library.
KAPI 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 b8 platform_window_hide(struct kwindow *window)
Hides the given window. Has no effect if the window is already hidden. Note that this does not destro...
KAPI void platform_free(void *block, b8 aligned)
Frees the given block of memory.
struct kwindow_config kwindow_config
A configuration structure used to create new windows.
KAPI f32 platform_device_pixel_ratio(const struct kwindow *window)
Returns the device pixel ratio of the supplied window.
Definition: platform.h:25
void * pfn
Definition: platform.h:27
const char * name
Definition: platform.h:26
Definition: platform.h:30
dynamic_library_function * functions
Definition: platform.h:38
const char * filename
Definition: platform.h:32
const char * name
Definition: platform.h:31
void * internal_data
Definition: platform.h:34
u64 internal_data_size
Definition: platform.h:33
u32 watch_id
Definition: platform.h:35
A configuration structure used to create new windows.
Definition: platform.h:54
i32 position_y
Definition: platform.h:56
const char * title
Definition: platform.h:59
u32 width
Definition: platform.h:57
const char * name
Definition: platform.h:60
u32 height
Definition: platform.h:58
i32 position_x
Definition: platform.h:55
The internal state of a window for the renderer frontend.
Definition: renderer_types.h:255
Represents a window in the application.
Definition: platform.h:69
f32 device_pixel_ratio
Represents the pixel density of this window. Should only ever be read from, as the platform layer is ...
Definition: platform.h:84
u16 height
The height of the window in pixels.
Definition: platform.h:78
u16 width
The width of the window in pixels.
Definition: platform.h:76
u16 frames_since_resize
Indicates the number of frames that have passed since the last resize event.
Definition: platform.h:89
const char * title
The title of the window.
Definition: platform.h:73
struct kwindow_renderer_state * renderer_state
Holds renderer-specific data.
Definition: platform.h:95
const char * name
The internal name of the window.
Definition: platform.h:71
b8 resizing
Indicates if this window is currently being resized.
Definition: platform.h:87
struct kwindow_platform_state * platform_state
Holds platform-specific data.
Definition: platform.h:92
Definition: platform.h:20
const char * application_name
application_name The name of the application.
Definition: platform.h:22