2023-02-18 04:34:40 +01:00
|
|
|
export module runtime;
|
|
|
|
|
|
|
|
import app;
|
|
|
|
|
2023-02-19 17:50:29 +01:00
|
|
|
import coral;
|
|
|
|
import coral.files;
|
2023-02-22 16:35:33 +01:00
|
|
|
import coral.io;
|
2023-02-19 17:50:29 +01:00
|
|
|
import coral.math;
|
|
|
|
import coral.sequence;
|
2023-02-18 04:34:40 +01:00
|
|
|
|
|
|
|
extern "C" int main(int argc, char const * const * argv) {
|
2023-02-23 15:02:17 +01:00
|
|
|
return app::client::run("Ona Runtime", [](app::client & client) -> int {
|
2023-02-19 17:50:29 +01:00
|
|
|
constexpr coral::path config_path{"config.kym"};
|
2023-02-19 17:45:40 +01:00
|
|
|
bool is_config_loaded{false};
|
2023-02-18 04:34:40 +01:00
|
|
|
|
2023-02-23 15:02:17 +01:00
|
|
|
client.resources().read_file(config_path, [&](coral::reader & file) {
|
|
|
|
coral::allocator * const allocator{&client.thread_safe_allocator()};
|
2023-02-19 18:43:37 +01:00
|
|
|
|
|
|
|
coral::stack<coral::u8> script_source{allocator};
|
2023-02-20 02:28:58 +01:00
|
|
|
{
|
|
|
|
coral::u8 stream_buffer[1024]{0};
|
2023-02-22 21:53:58 +01:00
|
|
|
coral::contiguous_writer script_writer{&script_source};
|
2023-02-20 02:28:58 +01:00
|
|
|
|
|
|
|
if (!coral::stream(script_writer, file, stream_buffer).is_ok()) return;
|
|
|
|
}
|
2023-02-18 04:34:40 +01:00
|
|
|
|
2023-02-23 15:02:17 +01:00
|
|
|
client.log(app::log_level::notice, script_source.as_slice().as_chars());
|
2023-02-18 04:34:40 +01:00
|
|
|
|
2023-02-23 00:19:42 +01:00
|
|
|
is_config_loaded = true;
|
2023-02-19 18:16:43 +01:00
|
|
|
});
|
|
|
|
|
2023-02-19 18:43:37 +01:00
|
|
|
if (!is_config_loaded) {
|
2023-02-23 15:02:17 +01:00
|
|
|
coral::stack<coral::u8> error_message{&client.thread_safe_allocator()};
|
2023-02-19 18:43:37 +01:00
|
|
|
{
|
2023-02-22 21:53:58 +01:00
|
|
|
coral::contiguous_writer error_writer{&error_message};
|
2023-02-19 18:43:37 +01:00
|
|
|
|
2023-02-20 02:28:58 +01:00
|
|
|
if (!error_writer.write(coral::slice{"failed to load "}.as_bytes()).is_ok())
|
2023-02-19 18:43:37 +01:00
|
|
|
return coral::u8_max;
|
|
|
|
|
2023-02-20 02:28:58 +01:00
|
|
|
if (!error_writer.write(config_path.as_slice().as_bytes()).is_ok())
|
2023-02-19 18:43:37 +01:00
|
|
|
return coral::u8_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
return coral::u8_max;
|
|
|
|
}
|
2023-02-18 04:34:40 +01:00
|
|
|
|
2023-02-23 15:02:17 +01:00
|
|
|
client.display(1280, 800);
|
|
|
|
|
|
|
|
while (client.poll()) {
|
2023-02-18 04:34:40 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|