ona/source/kym.cpp

65 lines
1.2 KiB
C++
Raw Normal View History

2023-02-18 04:34:40 +01:00
export module kym;
2023-02-19 17:50:29 +01:00
import coral;
import coral.math;
2023-02-18 04:34:40 +01:00
export namespace kym {
enum class value_type {
nil,
boolean,
integer,
scalar,
vector2,
vector3,
object,
};
struct value {
2023-02-20 16:27:14 +01:00
value_type type{value_type::nil};
2023-02-18 04:34:40 +01:00
2023-02-20 16:27:14 +01:00
value() = default;
2023-02-18 04:34:40 +01:00
2023-02-20 16:27:14 +01:00
value(bool boolean) {
this->data[1] = 0xff * boolean;
this->type = value_type::boolean;
}
2023-02-18 04:34:40 +01:00
2023-02-20 16:27:14 +01:00
value(coral::i64 integer) {
(*reinterpret_cast<coral::u64 *>(this->data)) =
(*reinterpret_cast<coral::u64 *>(&integer));
2023-02-18 04:34:40 +01:00
2023-02-20 16:27:14 +01:00
this->type = value_type::integer;
}
2023-02-18 04:34:40 +01:00
2023-02-20 16:27:14 +01:00
value(coral::f64 scalar) {
(*reinterpret_cast<coral::u64 *>(this->data)) =
(*reinterpret_cast<coral::u64 *>(&scalar));
2023-02-18 04:34:40 +01:00
2023-02-20 16:27:14 +01:00
this->type = value_type::scalar;
}
2023-02-18 04:34:40 +01:00
2023-02-20 16:27:14 +01:00
value(coral::vector2 vector2) {
(*reinterpret_cast<coral::u64 *>(this->data)) =
(*reinterpret_cast<coral::u64 *>(&vector2));
this->type = value_type::vector2;
}
2023-02-18 04:34:40 +01:00
2023-02-20 16:27:14 +01:00
value(coral::vector3 const & vector3) {
coral::copy(this->data, coral::as_bytes(&vector3));
this->type = value_type::vector3;
}
coral::optional<coral::i64> as_integer() const {
if (this->type == value_type::integer)
return (*reinterpret_cast<coral::i64 const *>(&this->data));
2023-02-18 04:34:40 +01:00
return {};
}
2023-02-20 16:27:14 +01:00
private:
coral::u8 data[12]{0};
2023-02-18 04:34:40 +01:00
};
};