96typedef uint64_t kinc_ticks_t;
178#elif defined(__clang__)
179 __builtin_debugtrap();
181#if defined(__aarch64__)
182 __asm__
volatile(
".inst 0xd4200000");
183#elif defined(__x86_64__)
184 __asm__
volatile(
"int $0x03");
186 kinc_log(KINC_LOG_LEVEL_WARNING,
"Oh no, kinc_debug_break is not implemented for the current compiler and CPU.");
292#include <ittnotify.h>
294extern __itt_domain *kinc_itt_domain;
297#ifdef KINC_SUPERLUMINAL
298#include <Superluminal/PerformanceAPI_capi.h>
308 __itt_task_begin(kinc_itt_domain, __itt_null, __itt_null, __itt_string_handle_create(name));
311#ifdef KINC_SUPERLUMINAL
312 PerformanceAPI_BeginEvent(name, NULL, color);
321 __itt_task_end(kinc_itt_domain);
324#ifdef KINC_SUPERLUMINAL
325 PerformanceAPI_EndEvent();
348bool kinc_internal_frame(
void);
349const char *kinc_internal_save_path(
void);
350bool kinc_internal_handle_messages(
void);
351void kinc_internal_shutdown(
void);
352void kinc_internal_update_callback(
void);
353void kinc_internal_foreground_callback(
void);
354void kinc_internal_resume_callback(
void);
355void kinc_internal_pause_callback(
void);
356void kinc_internal_background_callback(
void);
357void kinc_internal_shutdown_callback(
void);
358void kinc_internal_drop_files_callback(
wchar_t *);
359char *kinc_internal_cut_callback(
void);
360char *kinc_internal_copy_callback(
void);
361void kinc_internal_paste_callback(
char *);
362void kinc_internal_login_callback(
void);
363void kinc_internal_logout_callback(
void);
365#ifdef KINC_IMPLEMENTATION_ROOT
366#define KINC_IMPLEMENTATION
369#ifdef KINC_IMPLEMENTATION
371#ifdef KINC_IMPLEMENTATION_ROOT
372#undef KINC_IMPLEMENTATION
375#ifdef KINC_IMPLEMENTATION_ROOT
376#define KINC_IMPLEMENTATION
379#undef KINC_IMPLEMENTATION
382#define KINC_IMPLEMENTATION
387#if !defined(KINC_WASM) && !defined(KINC_EMSCRIPTEN) && !defined(KINC_ANDROID) && !defined(KINC_WINDOWS) && !defined(KINC_CONSOLE)
393static void (*update_callback)(
void *) = NULL;
394static void *update_callback_data = NULL;
395static void (*foreground_callback)(
void *) = NULL;
396static void *foreground_callback_data = NULL;
397static void (*background_callback)(
void *) = NULL;
398static void *background_callback_data = NULL;
399static void (*pause_callback)(
void *) = NULL;
400static void *pause_callback_data = NULL;
401static void (*resume_callback)(
void *) = NULL;
402static void *resume_callback_data = NULL;
403static void (*shutdown_callback)(
void *) = NULL;
404static void *shutdown_callback_data = NULL;
405static void (*drop_files_callback)(
wchar_t *,
void *) = NULL;
406static void *drop_files_callback_data = NULL;
407static char *(*cut_callback)(
void *) = NULL;
408static void *cut_callback_data = NULL;
409static char *(*copy_callback)(
void *) = NULL;
410static void *copy_callback_data = NULL;
411static void (*paste_callback)(
char *,
void *) = NULL;
412static void *paste_callback_data = NULL;
413static void (*login_callback)(
void *) = NULL;
414static void *login_callback_data = NULL;
415static void (*logout_callback)(
void *) = NULL;
416static void *logout_callback_data = NULL;
418#if defined(KINC_IOS) || defined(KINC_MACOS)
419bool withAutoreleasepool(
bool (*f)(
void));
423 update_callback = callback;
424 update_callback_data = data;
428 foreground_callback = callback;
429 foreground_callback_data = data;
433 resume_callback = callback;
434 resume_callback_data = data;
438 pause_callback = callback;
439 pause_callback_data = data;
443 background_callback = callback;
444 background_callback_data = data;
448 shutdown_callback = callback;
449 shutdown_callback_data = data;
453 drop_files_callback = callback;
454 drop_files_callback_data = data;
458 cut_callback = callback;
459 cut_callback_data = data;
463 copy_callback = callback;
464 copy_callback_data = data;
468 paste_callback = callback;
469 paste_callback_data = data;
473 login_callback = callback;
474 login_callback_data = data;
478 logout_callback = callback;
479 logout_callback_data = data;
482void kinc_internal_update_callback(
void) {
483 if (update_callback != NULL) {
484 update_callback(update_callback_data);
488void kinc_internal_foreground_callback(
void) {
489 if (foreground_callback != NULL) {
490 foreground_callback(foreground_callback_data);
494void kinc_internal_resume_callback(
void) {
495 if (resume_callback != NULL) {
496 resume_callback(resume_callback_data);
500void kinc_internal_pause_callback(
void) {
501 if (pause_callback != NULL) {
502 pause_callback(pause_callback_data);
506void kinc_internal_background_callback(
void) {
507 if (background_callback != NULL) {
508 background_callback(background_callback_data);
512void kinc_internal_shutdown_callback(
void) {
513 if (shutdown_callback != NULL) {
514 shutdown_callback(shutdown_callback_data);
518void kinc_internal_drop_files_callback(
wchar_t *filePath) {
519 if (drop_files_callback != NULL) {
520 drop_files_callback(filePath, drop_files_callback_data);
524char *kinc_internal_cut_callback(
void) {
525 if (cut_callback != NULL) {
526 return cut_callback(cut_callback_data);
531char *kinc_internal_copy_callback(
void) {
532 if (copy_callback != NULL) {
533 return copy_callback(copy_callback_data);
538void kinc_internal_paste_callback(
char *value) {
539 if (paste_callback != NULL) {
540 paste_callback(value, paste_callback_data);
544void kinc_internal_login_callback(
void) {
545 if (login_callback != NULL) {
546 login_callback(login_callback_data);
550void kinc_internal_logout_callback(
void) {
551 if (logout_callback != NULL) {
552 logout_callback(logout_callback_data);
556static bool running =
false;
558static char application_name[1024] = {
"Kinc Application"};
561 return application_name;
565 strcpy(application_name, name);
578bool kinc_internal_frame(
void) {
579 kinc_internal_update_callback();
580 kinc_internal_handle_messages();
587#if !defined(KINC_WASM) && !defined(KINC_EMSCRIPTEN)
590#if defined(KINC_IOS) || defined(KINC_MACOS)
591 while (withAutoreleasepool(kinc_internal_frame)) {
594 while (kinc_internal_frame()) {
597 kinc_internal_shutdown();
610void kinc_memory_emergency(
void) {}
613#if !defined(KINC_SONY) && !defined(KINC_NINTENDO)
614static float safe_zone = 0.9f;
637#if !defined(KINC_SONY)
638bool is_save_load_initialized(
void) {
642bool is_ps4_japanese_button_style(
void) {
646bool is_save_load_broken(
void) {
651#if !defined(KINC_CONSOLE)
653#define SAVE_RESULT_NONE 0
654#define SAVE_RESULT_SUCCESS 1
655#define SAVE_RESULT_FAILURE 2
656volatile int save_result = SAVE_RESULT_SUCCESS;
662static uint8_t *current_file = NULL;
663static size_t current_file_size = 0;
665bool kinc_save_file_loaded(
void) {
669uint8_t *kinc_get_save_file(
void) {
673size_t kinc_get_save_file_size(
void) {
674 return current_file_size;
677void kinc_load_save_file(
const char *filename) {
680 current_file_size = 0;
682 kinc_file_reader_t reader;
685 current_file = (uint8_t *)malloc(current_file_size);
691void kinc_save_save_file(
const char *filename, uint8_t *data,
size_t size) {
692 kinc_file_writer_t writer;
699bool kinc_save_is_saving(
void) {
707#if !defined(KINC_WINDOWS) && !defined(KINC_LINUX) && !defined(KINC_MACOS)
709 kinc_log(KINC_LOG_LEVEL_WARNING,
"Oh no, kinc_copy_to_clipboard is not implemented for this system.");
Provides an API very similar to fread and friends but handles the intricacies of where files are actu...
KINC_FUNC bool kinc_file_reader_open(kinc_file_reader_t *reader, const char *filepath, int type)
Opens a file for reading.
KINC_FUNC size_t kinc_file_reader_size(kinc_file_reader_t *reader)
Figures out the size of a file.
KINC_FUNC bool kinc_file_reader_close(kinc_file_reader_t *reader)
Closes a file.
KINC_FUNC size_t kinc_file_reader_read(kinc_file_reader_t *reader, void *data, size_t size)
Reads data from a file starting from the current reading-position and increases the reading-position ...
Provides an API very similar to fwrite and friends but uses a directory that can actually used for pe...
KINC_FUNC bool kinc_file_writer_open(kinc_file_writer_t *writer, const char *filepath)
Opens a file for writing.
KINC_FUNC void kinc_file_writer_write(kinc_file_writer_t *writer, void *data, int size)
Writes data to a file starting from the current writing-position and increases the writing-position a...
KINC_FUNC void kinc_file_writer_close(kinc_file_writer_t *writer)
Closes a file.
Provides basic functionality that's used all over the place. There's usually no need to manually incl...
Contains basic logging functionality.
KINC_FUNC void kinc_log(kinc_log_level_t log_level, const char *format,...)
Logging function similar to printf including some system-specific bonuses.
KINC_FUNC void kinc_set_cut_callback(char *(*callback)(void *), void *data)
Sets a callback which is called when the application is instructed to cut, typically via ctrl+x or cm...
KINC_FUNC bool kinc_waiting_for_login(void)
Returns true if kinc_login was called and the login-process is still ongoing.
KINC_FUNC void kinc_vibrate(int milliseconds)
Vibrates the whole system if supported. This is primarily supported on mobile phones but don't blame ...
KINC_FUNC bool kinc_debugger_attached(void)
Returns whether a debugger is currently attached to the running program. This is not yet working thou...
static void kinc_marker_start(const char *name, uint32_t color)
Starts a marker for profiling. Please match it with a marker_end-call in the same function.
Definition system.h:306
KINC_FUNC void kinc_set_login_callback(void(*callback)(void *), void *data)
Sets a callback which is called when a user logs in.
KINC_FUNC int kinc_height(void)
Returns the current height of the initial application-window which is equivalent to calling kinc_wind...
KINC_FUNC const char * kinc_system_id(void)
Returns an ID representing the current type of target-system.
KINC_FUNC const char * kinc_application_name(void)
Returns the current application name as set by kinc_init or kinc_set_application_name.
KINC_FUNC bool kinc_automatic_safe_zone(void)
Returns whether the system itself handles configuration of the safe-zone.
KINC_FUNC void kinc_set_safe_zone(float value)
Sets the safe-zone for systems which return false for kinc_automatic_safe_zone.
KINC_FUNC void kinc_set_foreground_callback(void(*callback)(void *), void *data)
Sets a callback which is called whenever the application is brought to the foreground.
KINC_FUNC const char * kinc_language(void)
Returns the current system-language.
KINC_FUNC void kinc_set_shutdown_callback(void(*callback)(void *), void *data)
Sets a callback which is called whenever the application is about to shut down.
KINC_FUNC void kinc_allow_user_change(void)
Allows the system to logout the current user.
KINC_FUNC void kinc_unlock_achievement(int id)
Unlocks an achievement or trophy or however you prefer to call it.
KINC_FUNC int kinc_init(const char *name, int width, int height, struct kinc_window_options *win, struct kinc_framebuffer_options *frame)
Initializes a Kinc application and creates an initial window for systems which support windows (syste...
KINC_FUNC kinc_ticks_t kinc_timestamp(void)
Returns a timestamp for right now in a system-specific unit.
KINC_FUNC void kinc_set_update_callback(void(*callback)(void *), void *data)
Sets the update-callback which drives the application and is called for every frame.
KINC_FUNC void kinc_set_keep_screen_on(bool on)
Instructs the system whether it is allowed to turn off the screen while the application is running.
KINC_FUNC void kinc_set_drop_files_callback(void(*callback)(wchar_t *, void *), void *data)
Sets a callback which is called when files are dropped on the application-window.
KINC_FUNC void kinc_set_paste_callback(void(*callback)(char *, void *), void *data)
Sets a callback which is called when the application is instructed to paste, typically via ctrl+v or ...
KINC_FUNC double kinc_time(void)
Returns the current time. This can also be calculated ala kinc_timestamp() / kinc_frequency() but kin...
KINC_FUNC void kinc_set_application_name(const char *name)
Changes the application-name that was initially set by kinc_init.
KINC_FUNC void kinc_LivePP_start(void)
Currently only supported on Windows. Starts up Live++ (see https://liveplusplus.tech),...
KINC_FUNC void kinc_set_pause_callback(void(*callback)(void *), void *data)
Sets a callback which is called whenever the application is paused.
KINC_FUNC void kinc_set_logout_callback(void(*callback)(void *), void *data)
Sets a callback which is called when a user logs out.
KINC_INLINE void kinc_debug_break(void)
Tries to halt program-execution in an attached debugger when compiled in debug-mode (aka when NDEBUG ...
Definition system.h:174
KINC_FUNC int kinc_cpu_cores(void)
Returns the number of proper CPU-cores (not the number of hardware-threads).
static void kinc_marker_end(const char *name)
Ends the previously started marker of the same function.
Definition system.h:319
KINC_FUNC int kinc_width(void)
Returns the current width of the initial application-window which is equivalent to calling kinc_windo...
KINC_FUNC void kinc_start(void)
Starts Kinc's main-loop. kinc_set_update_callback should be called before kinc_start so the main-loop...
KINC_FUNC void kinc_stop(void)
Stops Kinc's main loop and thereby returns to the function which called kinc_start.
KINC_FUNC void kinc_copy_to_clipboard(const char *text)
Copies the provided string to the system's clipboard.
KINC_FUNC int kinc_hardware_threads(void)
Returns the number of hardware-threads.
KINC_FUNC void kinc_set_resume_callback(void(*callback)(void *), void *data)
Sets a callback which is called whenever the application was paused and is being resumed.
KINC_FUNC void kinc_set_background_callback(void(*callback)(void *), void *data)
Sets a callback which is called whenever the application is brought to the background.
KINC_FUNC void kinc_LivePP_stop(void)
Stops Live++, typically called right after kinc_start().
KINC_FUNC double kinc_frequency(void)
Returns the frequency of system-timestamps.
KINC_FUNC void kinc_disallow_user_change(void)
Disallows the system to logout the current user.
KINC_FUNC float kinc_safe_zone(void)
Returns the portion of the screen which can be safely used for important content. This is mostly rele...
KINC_FUNC void kinc_load_url(const char *url)
Instruct the system to load up the provided URL which will usually open it in the system's default br...
KINC_FUNC void kinc_set_copy_callback(char *(*callback)(void *), void *data)
Sets a callback which is called when the application is instructed to copy, typically via ctrl+c or c...
KINC_FUNC void kinc_login(void)
Instructs the system to login a user if that is supported.
Provides functionality for creating and handling windows.
KINC_FUNC int kinc_window_width(int window)
Returns the width of a window.
KINC_FUNC int kinc_window_height(int window)
Returns the height of a window.