Kohi Game Engine
entry.h
Go to the documentation of this file.
1 
38 #pragma once
39 
42 #include "core/engine.h"
43 #include "logger.h"
44 #include "platform/filesystem.h"
45 
52 
54 
60 extern const char* application_config_path_get(void);
61 
66 int main(void) {
67 
68  // TODO: load up application config file, get it parsed and ready to hand off.
69  // Request the application instance from the application.
70  application app_inst = {0};
71 
72  const char* app_file_content = filesystem_read_entire_text_file(application_config_path_get());
73  if (!app_file_content) {
74  KFATAL("Failed to read app_config.kson file text. Application cannot start.");
75  return -68;
76  }
77 
78  if (!application_config_parse_file_content(app_file_content, &app_inst.app_config)) {
79  KFATAL("Failed to parse application config. Cannot start.");
80  return -69;
81  }
82 
83  if (!create_application(&app_inst)) {
84  KFATAL("Could not create application!");
85  return -1;
86  }
87 
88  // Ensure the function pointers exist.
89  if (!app_inst.render_frame || !app_inst.prepare_frame || !app_inst.update || !app_inst.initialize) {
90  KFATAL("The application's function pointers must be assigned!");
91  return -2;
92  }
93 
94  // Initialization.
95  if (!engine_create(&app_inst)) {
96  KFATAL("Engine failed to create!.");
97  return 1;
98  }
99 
100  if (!initialize_application(&app_inst)) {
101  KFATAL("Could not initialize application!");
102  return -1;
103  }
104 
105  // Begin the engine loop.
106  if (!engine_run(&app_inst)) {
107  KINFO("Application did not shutdown gracefully.");
108  return 2;
109  }
110 
111  return 0;
112 }
KAPI b8 application_config_parse_file_content(const char *file_content, application_config *out_config)
Attempt to parse the application config file's content into the actual application config structure.
This file contains types to be consumed by the application library.
_Bool b8
8-bit boolean type
Definition: defines.h:58
This file contains structures and logic pertaining to the overall engine itself. The engine is respon...
KAPI b8 engine_create(struct application *app)
Creates the engine, standing up the platform layer and all underlying subsystems.
KAPI b8 engine_run(struct application *app)
Starts the main engine loop.
b8 initialize_application(application *app)
const char * application_config_path_get(void)
Gets the application config path from the application.
b8 create_application(application *out_app)
Externally-defined function to create a application, provided by the consumer of this library.
int main(void)
The main entry point of the application.
Definition: entry.h:66
This file contains structures and functions for interacting with the file system.
KAPI const char * filesystem_read_entire_text_file(const char *filepath)
Opens and reads all text content of the file at the provided path. No file handle required....
This file contains structures and logic pertaining to the logging system.
#define KFATAL(message,...)
Logs a fatal-level message. Should be used to stop the application when hit.
Definition: logger.h:75
#define KINFO(message,...)
Logs an info-level message. Should be used for non-erronuous informational purposes.
Definition: logger.h:111
Represents the basic application state in a application. Called for creation by the application.
Definition: application_types.h:46
b8(* prepare_frame)(struct application *app_inst, struct frame_data *p_frame_data)
Function pointer to application's prepare_frame function.
Definition: application_types.h:79
application_config app_config
The application configuration.
Definition: application_types.h:48
b8(* initialize)(struct application *app_inst)
Function pointer to application's initialize function.
Definition: application_types.h:63
b8(* render_frame)(struct application *app_inst, struct frame_data *p_frame_data)
Function pointer to application's render_frame function.
Definition: application_types.h:87
b8(* update)(struct application *app_inst, struct frame_data *p_frame_data)
Function pointer to application's update function.
Definition: application_types.h:71