ona/source/runtime.cpp

56 lines
1.3 KiB
C++
Raw Normal View History

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;
2023-02-23 21:13:56 +01:00
import coral.stack;
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-23 21:13:56 +01:00
coral::small_stack<coral::u8> script_source{allocator};
{
coral::u8 stream_buffer[1024]{0};
2023-02-23 21:13:56 +01:00
coral::stack_writer script_writer{&script_source};
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
is_config_loaded = true;
2023-02-19 18:16:43 +01:00
});
if (!is_config_loaded) {
2023-02-23 21:13:56 +01:00
coral::small_stack<coral::u8> error_message{&client.thread_safe_allocator()};
{
2023-02-23 21:13:56 +01:00
coral::stack_writer error_writer{&error_message};
if (!error_writer.write(coral::slice{"failed to load "}.as_bytes()).is_ok())
return coral::u8_max;
if (!error_writer.write(config_path.as_slice().as_bytes()).is_ok())
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;
});
}