ona/source/runtime.cpp

57 lines
1.4 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;
import coral.sequence;
2023-02-18 04:34:40 +01:00
extern "C" int main(int argc, char const * const * argv) {
return app::display("Ona Runtime", [](app::system & system, app::graphics & graphics) -> 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
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};
2023-02-22 21:53:58 +01:00
coral::contiguous_writer script_writer{&script_source};
if (!coral::stream(script_writer, file, stream_buffer).is_ok()) return;
}
2023-02-18 04:34:40 +01:00
system.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) {
coral::stack<coral::u8> error_message{&system.thread_safe_allocator()};
{
2023-02-22 21:53:58 +01:00
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;
}
2023-02-18 04:34:40 +01:00
// app::canvas canvas_2d();
while (system.poll()) {
// canvas_2d.render(graphics);
graphics.present();
}
return 0;
});
}