ona/source/runtime.cpp

57 lines
1.4 KiB
C++

export module runtime;
import app;
import coral;
import coral.files;
import coral.io;
import coral.math;
import coral.sequence;
extern "C" int main(int argc, char const * const * argv) {
return app::display("Ona Runtime", [](app::system & system, app::graphics & graphics) -> int {
constexpr coral::path config_path{"config.kym"};
bool is_config_loaded{false};
system.res_fs().read_file(config_path, [&](coral::reader & file) {
coral::allocator * const allocator{&system.thread_safe_allocator()};
coral::stack<coral::u8> script_source{allocator};
{
coral::u8 stream_buffer[1024]{0};
coral::contiguous_writer script_writer{&script_source};
if (!coral::stream(script_writer, file, stream_buffer).is_ok()) return;
}
system.log(app::log_level::notice, script_source.as_slice().as_chars());
is_config_loaded = true;
});
if (!is_config_loaded) {
coral::stack<coral::u8> error_message{&system.thread_safe_allocator()};
{
coral::contiguous_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;
}
// app::canvas canvas_2d();
while (system.poll()) {
// canvas_2d.render(graphics);
graphics.present();
}
return 0;
});
}