1 #ifndef EAGINE_EXAMPLE_ECS_COMPONENTS_HPP // NOLINT(llvm-header-guard)
9 #define EAGINE_EXAMPLE_ECS_COMPONENTS_HPP
11 #include "decay_modes.hpp"
21 struct element_name : ecs::component<element_name> {
22 static constexpr
auto uid() noexcept {
29 element_name() =
default;
31 element_name(std::string lat, std::string eng)
32 : latin{std::move(lat)}
33 , english{std::move(eng)} {}
35 element_name(std::string lat)
36 : latin{std::move(lat)} {}
40 struct element_name_manip : ecs::basic_manipulator<element_name, Const> {
41 using ecs::basic_manipulator<element_name, Const>::basic_manipulator;
43 auto get_latin_name() const -> const std::
string& {
44 return this->read().latin;
47 auto get_english_name() const -> const std::
string& {
48 const auto& name = this->read().english;
50 return this->read().latin;
55 auto has_english_name() const ->
bool {
56 return !this->read().english.empty();
61 struct get_manipulator<element_name, Const> {
62 using type = element_name_manip<Const>;
66 struct element_protons : ecs::component<element_protons> {
67 static constexpr
auto uid() noexcept {
73 element_protons() noexcept = default;
75 element_protons(
short n)
79 struct isotope_neutrons : ecs::component<isotope_neutrons> {
80 static constexpr
auto uid() noexcept {
86 isotope_neutrons() noexcept = default;
88 isotope_neutrons(
short n)
92 struct element_period : ecs::component<element_period> {
93 static constexpr
auto uid() noexcept {
99 element_period() noexcept = default;
101 element_period(
short n)
105 struct element_group : ecs::component<element_group> {
106 static constexpr
auto uid() noexcept {
112 element_group() noexcept = default;
114 element_group(
short n)
118 struct atomic_weight : ecs::component<atomic_weight> {
119 static constexpr
auto uid() noexcept {
125 atomic_weight() noexcept = default;
127 atomic_weight(
float w)
131 struct half_life : ecs::component<half_life> {
132 static constexpr
auto uid() noexcept {
136 std::chrono::duration<float> time_seconds;
138 half_life() noexcept = default;
140 template <typename R, typename P>
141 half_life(std::chrono::duration<R, P> hl)
142 : time_seconds{hl} {}
144 static auto milliseconds(
float ms) noexcept -> half_life {
145 return {std::chrono::duration<float, std::ratio<1LL, 1000LL>>{ms}};
148 static auto seconds(
float s) noexcept -> half_life {
149 return {std::chrono::duration<float, std::ratio<1LL, 1LL>>{s}};
152 static auto minutes(
float m) noexcept -> half_life {
153 return {std::chrono::duration<float, std::ratio<60LL, 1LL>>{m}};
156 static auto hours(
float h) noexcept -> half_life {
157 return {std::chrono::duration<float, std::ratio<3600LL, 1LL>>{h}};
160 static auto days(
float d) noexcept -> half_life {
161 return {std::chrono::duration<float, std::ratio<86400LL, 1LL>>{d}};
164 static auto years(
float y) noexcept -> half_life {
165 return {std::chrono::duration<float, std::ratio<31556952LL, 1LL>>{y}};
170 std::vector<element_symbol> products;
173 class decay_modes : ecs::component<decay_modes> {
175 static constexpr
auto uid() noexcept {
181 if(
auto nid{known_decay_modes::get_id(symbol)}) {
182 for(
auto& [
id, v, info] : _modes) {
187 _modes.push_back({nid, nv, {}});
188 return &std::get<2>(_modes.back());
193 template <
typename Function>
194 void for_each(
const Function& func) {
195 for(
auto& [
id, v, info] : _modes) {
196 EAGINE_MAYBE_UNUSED(v);
197 if(
auto mode_info{known_decay_modes::get_info(
id)}) {
198 func(*mode_info, info);
203 template <
typename Function>
204 void for_each(
const Function& func)
const {
205 for(
const auto& [
id, v, info] : _modes) {
206 EAGINE_MAYBE_UNUSED(v);
207 if(
auto mode_info{known_decay_modes::get_info(
id)}) {
208 func(*mode_info, info);
214 std::vector<std::tuple<identifier_t, int, decay>> _modes;
Application harness / wrapper code is placed in this namespace.
Definition: eagine.hpp:72
GLsizei sizei_type
Signed integer size type.
Definition: config.hpp:88
Class providing access to the contents of a file.
Definition: file_contents.hpp:30
static constexpr auto clamp(T x, Min min, Max max) noexcept
Clamps x to be between min and max.
Definition: functions.hpp:96
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
tvec< gl_types::float_type, 2 > vec2
Alias for a 2D vector type.
Definition: vector.hpp:28
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
auto integer_hash(I x, type_identity< H > hid={}, type_identity< I > iid={}) -> H
Creates a hash value with type H from an integer value of type I.
Definition: integer_hash.hpp:72
static constexpr auto as_bytes(basic_span< T, P, S > spn) noexcept -> basic_block< std::is_const_v< T >>
Converts a span into a basic_block.
Definition: block.hpp:39
#define EAGINE_ID_V(NAME)
Macro for constructing instances of eagine::identifier_t.
Definition: identifier.hpp:359
static auto unit_torus(vertex_attrib_bits attr_bits, valid_if_greater_than< int, 4 > rings, valid_if_greater_than< int, 3 > sections, valid_if_ge0_lt1< float > radius_ratio)
Constructs instances of unit_torus_gen.
Definition: torus.hpp:110
#define EAGINE_ID(NAME)
Macro for constructing instances of eagine::identifier.
Definition: identifier.hpp:353
prog_var_location< EAGINE_ID_V(Uniform)> uniform_location
Alias for shader program uniform location wrapper.
Definition: prog_var_loc.hpp:115
gl_object_name< renderbuffer_tag > renderbuffer_name
Alias for GL renderbuffer object handle.
Definition: object_name.hpp:138
opt_c_api_constant< mp_list< buffer_clear_bit, buffer_blit_bit >, bitfield_type_i > depth_buffer_bit
Definition: constants.hpp:6149
std::conditional_t< IsAvailable, std::conditional_t< IsStatic, static_c_api_function< ApiTraits, Tag, Signature, function >, dynamic_c_api_function< ApiTraits, Tag, Signature > >, unimplemented_c_api_function< ApiTraits, Tag, Signature > > opt_c_api_function
Template alias used for switching between static and dynamic function.
Definition: c_api_wrap.hpp:1096
Common code is placed in this namespace.
Definition: eagine.hpp:21
Class representing a value animated between two points, with easing.
Definition: animated_value.hpp:20
gl_owned_object_name< shader_tag > owned_shader_name
Alias for owned GL shader object handle.
Definition: object_name.hpp:208
tvec< gl_types::float_type, 4 > vec4
Alias for a 4D vector type.
Definition: vector.hpp:36
#define EAGINE_MSG_ID(API, NAME)
Macro for instantiating objects of static_message_id.
Definition: message_id.hpp:148
auto to_cartesian(unit_spherical_coordinate< T, V > c) noexcept -> vector< T, 3, V >
Converts unit spherical coordinate to cartesian vector.
Definition: coordinates.hpp:53
static auto make_index(basic_span< T, P, S > spn, basic_span< I, PI, SI > idx, Compare compare) -> bool
Makes the index of a span according to compare, into another span.
Definition: span_algo.hpp:641
static constexpr auto cover(T *addr, S size) noexcept -> span_if_mutable< T >
Creates a span starting at the specified pointer and specified length.
Definition: span.hpp:465
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
GLint int_type
Signed integer type.
Definition: config.hpp:70
basic_block< true > const_block
Alias for const byte memory span.
Definition: block.hpp:32
auto update(F deltaT) -> auto &
Updates the transition factor by the specified amount.
Definition: animated_value.hpp:54
convertible_matrix_constructor< rotation_x< matrix< T, 4, 4, true, V > >> matrix_rotation_x
Alias for constructor of rotation along x-axis transformation matrix.
Definition: matrix_rotation.hpp:124
static auto type_name(const T &) noexcept -> std::string
Returns the demangled name for type T.
Definition: type_name.hpp:24
Primary template for conditionally valid values.
Definition: decl.hpp:49
static auto smooth_lerp(const T &a, const T &b, C coef)
Linear interpolation with coef transformed by sine_sigmoid01.
Definition: interpolate.hpp:42
static constexpr auto view(T *addr, S size) noexcept -> const_span< T >
Creates a view starting at the specified pointer and specified length.
Definition: span.hpp:458
gl_owned_object_name< texture_tag > owned_texture_name
Alias for owned GL texture object handle.
Definition: object_name.hpp:213
basic_block< false > block
Alias for non-const byte memory span.
Definition: block.hpp:27
static void apply(byte_getter get_byte, char_putter put_char)
Uses get_byte to read input bytes, encodes them and calls put_char.
auto is_done() const noexcept -> bool
Indicates if the current transition factor is higher than current duration.
Definition: animated_value.hpp:60
static auto add_triangle_adjacency(std::shared_ptr< generator > gen, drawing_variant var) noexcept
Constructs instances of triangle_adjacency_gen modifier.
Definition: adjacency.hpp:61
@ wrap_coord
UV-texture wrapping coordinate.
Definition: 005_path_nv_text.cpp:19
static auto find(basic_span< T1, P1, S1 > where, basic_span< T2, P2, S2 > what) -> basic_span< T1, P1, S1 >
Finds the position of the last occurrence of what in a span.
Definition: span_algo.hpp:374
@ position
Vertex position.
GLuint uint_type
Unsigned integer type.
Definition: config.hpp:73
static auto unit_cube(vertex_attrib_bits attr_bits)
Constructs instances of unit_cube_gen.
Definition: cube.hpp:92
convertible_matrix_constructor< perspective< matrix< T, 4, 4, true, V > >> matrix_perspective
Alias for constructor of perspective projection matrix.
Definition: matrix_perspective.hpp:177
static auto scale(std::shared_ptr< generator > gen, std::array< float, 3 > s) noexcept
Constructs instances of scaled_gen modifier.
Definition: scaled.hpp:41
@ color
Vertex color value.
static auto rebox(std::shared_ptr< generator > gen) noexcept
Constructs instances of reboxed_gen modifier.
Definition: reboxed.hpp:33
@ highest
Slowest compression method highest compression level.
convertible_matrix_constructor< translation< matrix< T, 4, 4, true, V > >> matrix_translation
Alias for constructor of uniform translation transformation matrix.
Definition: matrix_translation.hpp:95
gl_object_name< framebuffer_tag > framebuffer_name
Alias for GL framebuffer object handle.
Definition: object_name.hpp:118
static constexpr auto limit_cast(Src value) noexcept -> std::enable_if_t< std::is_convertible_v< Src, Dst >, Dst >
Casts value to Dst type if the value fits in that type.
Definition: is_within_limits.hpp:133
static constexpr auto radians_(T value) noexcept -> radians_t< T >
Creates a tagged quantity storing value in radians.
Definition: quantities.hpp:50
static constexpr auto std_size(T v) noexcept
Converts argument to std size type.
Definition: types.hpp:52
gl_owned_object_name< vertex_array_tag > owned_vertex_array_name
Alias for owned GL vertex array object handle.
Definition: object_name.hpp:224
Class for encoding byte blocks into hexdump-like format.
Definition: hexdump.hpp:29
prog_var_location< EAGINE_ID_V(VertexAttr)> vertex_attrib_location
Alias for program vertex attribute location wrapper.
Definition: prog_var_loc.hpp:104
auto serialize(T &value, Backend &backend) -> std::enable_if_t< std::is_base_of_v< serializer_backend, Backend >, serialization_errors >
Serializes a value with the specified serialization backend.
Definition: write.hpp:480
unsigned char byte
Byte type alias.
Definition: types.hpp:24
static constexpr auto turns_(T value) noexcept
Creates a tagged quantity in full turn units.
Definition: quantities.hpp:82
static auto finally(Func func) -> func_on_scope_exit< Func >
Function constructing on-scope-exit actions.
Definition: scope_exit.hpp:144
static auto fill(basic_span< T, P, S > spn, const V &v) -> basic_span< T, P, S >
Fills a span with copies of the specified value.
Definition: span_algo.hpp:536
@ pivot
Shape pivot point.
basic_line< T, 3, V > line
Alias for lines in 3D space.
Definition: primitives.hpp:52
convertible_matrix_constructor< rotation_z< matrix< T, 4, 4, true, V > >> matrix_rotation_z
Alias for constructor of rotation along z-axis transformation matrix.
Definition: matrix_rotation.hpp:152
static auto unit_icosahedron(vertex_attrib_bits attr_bits)
Constructs instances of unit_icosahedron_gen.
Definition: icosahedron.hpp:71
@ box_coord
Normalized coordinate within shape bounding box.
#define EAGINE_THIS_MEM_FUNC_C(FUNC)
Macro for creating object of member_function_constant in member functions.
Definition: mem_func_const.hpp:206
static constexpr auto maximum(T a, T b) noexcept
Returns the maximum value of a and b.
Definition: functions.hpp:61
Class wrapping the main function arguments, providing a convenient API.
Definition: program_args.hpp:1082
static auto unit_twisted_torus(vertex_attrib_bits attr_bits, int twist, valid_if_greater_than< int, 2 > rings, valid_if_greater_than< int, 3 > sections, valid_if_ge0_lt1< float > radius_ratio)
Constructs instances of unit_twisted_torus_gen.
Definition: twisted_torus.hpp:77
static auto unit_screen(vertex_attrib_bits attr_bits)
Constructs instances of unit_screen_gen.
Definition: screen.hpp:61
static auto to_patches(std::shared_ptr< generator > gen) noexcept
Constructs instances of to_patches_gen modifier.
Definition: to_patches.hpp:32
static constexpr auto right_angles_(T value) noexcept
Creates a tagged quantity in units of right angle.
Definition: quantities.hpp:61
auto from_json_text(string_view, main_ctx_parent) -> compound
Creates a compound from a JSON text string view.
static constexpr auto array_size(const T(&)[N]) noexcept
Returns the number of elements in the array passed as argument.
Definition: array_size.hpp:19
@ occlusion
Vertex (ambient) light occlusion value.
@ face_coord
Generic face coordinate.
tvec< gl_types::float_type, 3 > vec3
Alias for a 3D vector type.
Definition: vector.hpp:32
auto extract(const ok< Outcome > &x) noexcept -> const auto &
Overload of extract for instantiations of the ok template.
Definition: extract.hpp:193
Combined wrapper for the GL API operations and constants.
Definition: basic_gl_api.hpp:27
static constexpr auto degrees_(T value) noexcept -> degrees_t< T >
Creates a tagged quantity storing value in degrees.
Definition: quantities.hpp:183
static auto from_value_tree(valtree::compound source, main_ctx_parent parent)
Constructs instances of value_tree_loader.
Definition: value_tree.hpp:88
prog_var_location< EAGINE_ID_V(ShdrStrBlk)> shader_storage_block_index
Alias for program shader storage block location wrapper.
Definition: prog_var_loc.hpp:170
Class for encoding byte blocks into binary format.
Definition: bindump.hpp:27
void draw_using_instructions(const basic_gl_api< A > &api, span< const shape_draw_operation > ops) noexcept
Takes a sequence of draw operations from a shape generator and draws them.
integer_range(B, E) -> integer_range< std::common_type_t< B, E >>
Deduction guide for integer_range.
convertible_matrix_constructor< rotation_y< matrix< T, 4, 4, true, V > >> matrix_rotation_y
Alias for constructor of rotation along y-axis transformation matrix.
Definition: matrix_rotation.hpp:138
@ weight
Generic vertex weight value.
auto set(T value, valid_if_positive< F > duration, S slope) -> auto &
Sets the next point to animate into, duration and sigmoid slope.
Definition: animated_value.hpp:31
math::unit_spherical_coordinate< gl_types::float_type, math_use_simd > unit_spherical_coordinate
Alias for math::unit_spherical_coordinate instantiation.
Definition: coordinates.hpp:20
static constexpr auto as_chars(block blk) noexcept
Converts a block into a span of characters.
Definition: block.hpp:48
opt_c_api_constant< mp_list< buffer_clear_bit, buffer_blit_bit >, bitfield_type_i > color_buffer_bit
Definition: constants.hpp:6138
static constexpr auto minimum(T a, T b) noexcept
Returns the minimum value of a and b.
Definition: functions.hpp:47
static auto embed(identifier res_id, string_view src_path) noexcept -> embedded_resource
Triggers the embedding of data from a file on the specified path.
Definition: embed.hpp:105
void draw_instanced_using_instructions(const basic_gl_api< A > &api, span< const shape_draw_operation > ops, gl_types::sizei_type inst_count) noexcept
Takes a sequence of draw operations from a shape generator and draws them.
@ normal
Vertex normal vector.
auto operations() noexcept -> basic_gl_operations< ApiTraits > &
Returns a reference to the wrapped operations.
Definition: basic_gl_api.hpp:52
static auto center(std::shared_ptr< generator > gen) noexcept
Constructs instances of centered_gen modifier.
Definition: centered.hpp:35
auto from_yaml_text(string_view, main_ctx_parent) -> compound
Creates a compound from a YAML text string view.
static void apply(byte_getter get_byte, char_putter put_char)
Uses get_byte to read input bytes, encodes them and calls put_char.
gl_owned_object_name< program_tag > owned_program_name
Alias for owned GL program object handle.
Definition: object_name.hpp:188
basic_triangle< T, 3, V > triangle
Alias for triangles in 3D space.
Definition: primitives.hpp:117
static constexpr auto right_angle_() noexcept
Creates a tagged quantity a right angle value.
Definition: quantities.hpp:71
static auto line_triangle_intersection(const line< T, V > &ray, const triangle< T, V > &tri) noexcept -> optionally_valid< vector< T, 3, V >>
Finds line-triangle intersection point.
Definition: intersection.hpp:186
basic_identifier< 10, 6, default_identifier_char_set, identifier_t > identifier
Default identifier type used throughout the project.
Definition: identifier.hpp:346