ona/source/app.cpp

96 lines
1.9 KiB
C++

export module app;
import core;
import core.image;
import core.lalgebra;
export namespace app {
struct path {
static constexpr core::usize max = 0xff;
static constexpr char seperator = '/';
core::u8 buffer[max + 1];
static constexpr path empty() {
path empty_path = {0};
empty_path.buffer[max] = max;
return empty_path;
}
core::slice<char const> as_slice() const {
return {reinterpret_cast<char const *>(this->buffer), this->size()};
}
constexpr core::usize size() const {
return max - this->buffer[max];
}
core::i16 compare(path const & that) {
return 0;
}
bool equals(path const & that) const {
return core::equals(this->as_slice().as_bytes(), that.as_slice().as_bytes());
}
constexpr path joined(core::slice<char const> const & text) const {
if (text.length > this->buffer[max]) return empty();
path joined_path = *this;
for (char const c : text) {
joined_path.buffer[joined_path.size()] = c;
joined_path.buffer[max] -= 1;
}
return joined_path;
}
core::u64 hash() {
return 0;
}
};
struct file_store {
virtual void read_file(app::path const & file_path, core::callable<void(core::readable const &)> const & then) = 0;
};
enum class log_level {
notice,
warning,
error,
};
struct system {
virtual bool poll() = 0;
virtual file_store & bundle() = 0;
virtual void log(log_level level, core::slice<char const> const & message) = 0;
virtual core::allocator & thread_safe_allocator() = 0;
};
struct graphics {
enum class show_error {
none,
out_of_memory,
};
struct canvas {
core::color background_color;
};
virtual void render(canvas & source_canvas) = 0;
virtual void present() = 0;
virtual show_error show(core::u16 physical_width, core::u16 physical_height) = 0;
virtual void retitle(core::slice<const char> const & updated_title) = 0;
};
}