Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::script::detail Namespace Reference

Implementation of bind_components(), compiled in the caller's code. More...

Classes

struct  Field
 
struct  Kind
 

Enumerations

enum class  FieldType : std::uint8_t { Number , Integer , Unsigned , Boolean }
 

Functions

template<typename Component , const auto & Fields>
constexpr Kind kind_of (std::string_view name)
 
AEGIS2D_SCRIPT_EXPORT void bind_kinds (ScriptState &lua, ecs::Registry &registry, std::span< const Kind > kinds)
 Gives the scripts of a state the components of a registry, through kinds.
 

Variables

constexpr std::array transform_fields
 
constexpr std::array velocity_fields
 
constexpr std::array sprite_fields
 
constexpr std::array animation_fields
 
constexpr std::array collider_fields
 
constexpr std::array health_fields
 
constexpr std::array damage_fields
 
constexpr std::array score_fields
 
constexpr std::array sine_motion_fields
 
constexpr std::array path_follower_fields
 
constexpr std::array kinds
 
constexpr std::array kind_names
 

Detailed Description

Implementation of bind_components(), compiled in the caller's code.

Enumeration Type Documentation

◆ FieldType

enum class aegis2d::script::detail::FieldType : std::uint8_t
strong
Enumerator
Number 
Integer 
Unsigned 
Boolean 

Function Documentation

◆ bind_kinds()

AEGIS2D_SCRIPT_EXPORT void aegis2d::script::detail::bind_kinds ( ScriptState &  lua,
ecs::Registry &  registry,
std::span< const Kind >  kinds 
)

Gives the scripts of a state the components of a registry, through kinds.

Parameters
luaState.
registryRegistry, kept by reference.
kindsComponent types, with static storage.

◆ kind_of()

template<typename Component , const auto & Fields>
constexpr Kind aegis2d::script::detail::kind_of ( std::string_view  name)
constexpr

Variable Documentation

◆ animation_fields

constexpr std::array aegis2d::script::detail::animation_fields
inlineconstexpr
Initial value:
{
Field<ecs::Animation>{
"first", FieldType::Unsigned,
[](const ecs::Animation& c) { return static_cast<double>(c.first); },
[](ecs::Animation& c, double v) { c.first = static_cast<std::uint32_t>(v); }},
Field<ecs::Animation>{
"count", FieldType::Unsigned,
[](const ecs::Animation& c) { return static_cast<double>(c.count); },
[](ecs::Animation& c, double v) { c.count = static_cast<std::uint32_t>(v); }},
Field<ecs::Animation>{
"frame_time", FieldType::Number,
[](const ecs::Animation& c) { return double{c.frame_time}; },
[](ecs::Animation& c, double v) { c.frame_time = static_cast<float>(v); }},
Field<ecs::Animation>{"loop", FieldType::Boolean,
[](const ecs::Animation& c) { return c.loop ? 1.0 : 0.0; },
[](ecs::Animation& c, double v) { c.loop = v != 0.0; }},
}
Frames of the entity's Sprite shown in turn, at a steady rate.
Definition components.hpp:56
std::uint32_t first
First frame of the clip in the sprite sheet.
Definition components.hpp:58

◆ collider_fields

constexpr std::array aegis2d::script::detail::collider_fields
inlineconstexpr
Initial value:
{
Field<ecs::Collider>{"width", FieldType::Number,
[](const ecs::Collider& c) { return double{c.size.x}; },
[](ecs::Collider& c, double v) { c.size.x = static_cast<float>(v); }},
Field<ecs::Collider>{"height", FieldType::Number,
[](const ecs::Collider& c) { return double{c.size.y}; },
[](ecs::Collider& c, double v) { c.size.y = static_cast<float>(v); }},
Field<ecs::Collider>{
"layer", FieldType::Unsigned,
[](const ecs::Collider& c) { return static_cast<double>(c.layer); },
[](ecs::Collider& c, double v) { c.layer = static_cast<std::uint32_t>(v); }},
Field<ecs::Collider>{
"mask", FieldType::Unsigned,
[](const ecs::Collider& c) { return static_cast<double>(c.mask); },
[](ecs::Collider& c, double v) { c.mask = static_cast<std::uint32_t>(v); }},
}
Axis-aligned box an entity collides with.
Definition components.hpp:101
Vec2 size
Width and height of the box, in logical pixels.
Definition components.hpp:103

◆ damage_fields

constexpr std::array aegis2d::script::detail::damage_fields
inlineconstexpr
Initial value:
{
Field<ecs::Damage>{"amount", FieldType::Integer,
[](const ecs::Damage& c) { return static_cast<double>(c.amount); },
[](ecs::Damage& c, double v) { c.amount = static_cast<std::int32_t>(v); }},
Field<ecs::Damage>{"consumed_on_hit", FieldType::Boolean,
[](const ecs::Damage& c) { return c.consumed_on_hit ? 1.0 : 0.0; },
[](ecs::Damage& c, double v) { c.consumed_on_hit = v != 0.0; }},
}
How much damage an entity deals to what it hits.
Definition components.hpp:128
std::int32_t amount
Health points removed from the target by one hit.
Definition components.hpp:130

◆ health_fields

constexpr std::array aegis2d::script::detail::health_fields
inlineconstexpr
Initial value:
{
Field<ecs::Health>{"points", FieldType::Integer,
[](const ecs::Health& c) { return static_cast<double>(c.points); },
[](ecs::Health& c, double v) { c.points = static_cast<std::int32_t>(v); }},
}
How much damage an entity can still take.
Definition components.hpp:115
std::int32_t points
Remaining health points.
Definition components.hpp:117

◆ kind_names

constexpr std::array aegis2d::script::detail::kind_names
inlineconstexpr
Initial value:
= [] {
std::array<std::string_view, kinds.size()> result{};
std::ranges::transform(kinds, result.begin(), [](const Kind& kind) { return kind.name; });
return result;
}()
constexpr std::array kinds
Definition components.hpp:216
Definition components.hpp:166

◆ kinds

constexpr std::array aegis2d::script::detail::kinds
inlineconstexpr
Initial value:
{
kind_of<ecs::Transform, transform_fields>("Transform"),
kind_of<ecs::Velocity, velocity_fields>("Velocity"),
kind_of<ecs::Sprite, sprite_fields>("Sprite"),
kind_of<ecs::Animation, animation_fields>("Animation"),
kind_of<ecs::Collider, collider_fields>("Collider"),
kind_of<ecs::Health, health_fields>("Health"),
kind_of<ecs::Damage, damage_fields>("Damage"),
kind_of<ecs::Score, score_fields>("Score"),
kind_of<ecs::SineMotion, sine_motion_fields>("SineMotion"),
kind_of<ecs::PathFollower, path_follower_fields>("PathFollower"),
}

◆ path_follower_fields

constexpr std::array aegis2d::script::detail::path_follower_fields
inlineconstexpr
Initial value:
{
Field<ecs::PathFollower>{
"speed", FieldType::Number, [](const ecs::PathFollower& c) { return double{c.speed}; },
[](ecs::PathFollower& c, double v) { c.speed = static_cast<float>(v); }},
Field<ecs::PathFollower>{
"progress", FieldType::Number,
[](const ecs::PathFollower& c) { return double{c.progress}; },
[](ecs::PathFollower& c, double v) { c.progress = static_cast<float>(v); }},
Field<ecs::PathFollower>{"arrived", FieldType::Boolean,
[](const ecs::PathFollower& c) { return c.arrived ? 1.0 : 0.0; },
[](ecs::PathFollower& c, double v) { c.arrived = v != 0.0; }},
}
An entity that walks along waypoints, such as an enemy of a tower defense on the path found by NavGri...
Definition path_following.hpp:26
float speed
Speed along the path, in logical pixels per second.
Definition path_following.hpp:31

◆ score_fields

constexpr std::array aegis2d::script::detail::score_fields
inlineconstexpr
Initial value:
{
Field<ecs::Score>{"points", FieldType::Unsigned,
[](const ecs::Score& c) { return static_cast<double>(c.points); },
[](ecs::Score& c, double v) { c.points = static_cast<std::uint32_t>(v); }},
}
Points a player has earned.
Definition components.hpp:143
std::uint32_t points
Total points; it stops at the largest value instead of wrapping.
Definition components.hpp:145

◆ sine_motion_fields

constexpr std::array aegis2d::script::detail::sine_motion_fields
inlineconstexpr
Initial value:
{
Field<ecs::SineMotion>{
"x", FieldType::Number, [](const ecs::SineMotion& c) { return double{c.amplitude.x}; },
[](ecs::SineMotion& c, double v) { c.amplitude.x = static_cast<float>(v); }},
Field<ecs::SineMotion>{
"y", FieldType::Number, [](const ecs::SineMotion& c) { return double{c.amplitude.y}; },
[](ecs::SineMotion& c, double v) { c.amplitude.y = static_cast<float>(v); }},
Field<ecs::SineMotion>{"period", FieldType::Number,
[](const ecs::SineMotion& c) { return double{c.period}; },
[](ecs::SineMotion& c, double v) { c.period = static_cast<float>(v); }},
}
Sine wave added to an entity's movement, like an enemy weaving up and down.
Definition components.hpp:230
Vec2 amplitude
Largest offset from the path, in logical pixels, and its direction: {0, 48} weaves 48 pixels up and d...
Definition components.hpp:233

◆ sprite_fields

constexpr std::array aegis2d::script::detail::sprite_fields
inlineconstexpr
Initial value:
{
Field<ecs::Sprite>{"texture", FieldType::Unsigned,
[](const ecs::Sprite& c) { return static_cast<double>(c.texture); },
[](ecs::Sprite& c, double v) { c.texture = static_cast<std::uint32_t>(v); }},
Field<ecs::Sprite>{"width", FieldType::Number,
[](const ecs::Sprite& c) { return double{c.size.x}; },
[](ecs::Sprite& c, double v) { c.size.x = static_cast<float>(v); }},
Field<ecs::Sprite>{"height", FieldType::Number,
[](const ecs::Sprite& c) { return double{c.size.y}; },
[](ecs::Sprite& c, double v) { c.size.y = static_cast<float>(v); }},
Field<ecs::Sprite>{"frame", FieldType::Unsigned,
[](const ecs::Sprite& c) { return static_cast<double>(c.frame); },
[](ecs::Sprite& c, double v) { c.frame = static_cast<std::uint32_t>(v); }},
Field<ecs::Sprite>{"layer", FieldType::Integer,
[](const ecs::Sprite& c) { return static_cast<double>(c.layer); },
[](ecs::Sprite& c, double v) { c.layer = static_cast<std::int32_t>(v); }},
Field<ecs::Sprite>{"r", FieldType::Number,
[](const ecs::Sprite& c) { return double{c.tint.x}; },
[](ecs::Sprite& c, double v) { c.tint.x = static_cast<float>(v); }},
Field<ecs::Sprite>{"g", FieldType::Number,
[](const ecs::Sprite& c) { return double{c.tint.y}; },
[](ecs::Sprite& c, double v) { c.tint.y = static_cast<float>(v); }},
Field<ecs::Sprite>{"b", FieldType::Number,
[](const ecs::Sprite& c) { return double{c.tint.z}; },
[](ecs::Sprite& c, double v) { c.tint.z = static_cast<float>(v); }},
Field<ecs::Sprite>{"a", FieldType::Number,
[](const ecs::Sprite& c) { return double{c.tint.w}; },
[](ecs::Sprite& c, double v) { c.tint.w = static_cast<float>(v); }},
}
What an entity looks like.
Definition components.hpp:34
std::uint32_t texture
Texture of the resource manager (render::TextureId), 0 for a plain rectangle.
Definition components.hpp:37

◆ transform_fields

constexpr std::array aegis2d::script::detail::transform_fields
inlineconstexpr
Initial value:
{
Field<ecs::Transform>{
"x", FieldType::Number, [](const ecs::Transform& c) { return double{c.position.x}; },
[](ecs::Transform& c, double v) { c.position.x = static_cast<float>(v); }},
Field<ecs::Transform>{
"y", FieldType::Number, [](const ecs::Transform& c) { return double{c.position.y}; },
[](ecs::Transform& c, double v) { c.position.y = static_cast<float>(v); }},
}
Where an entity is.
Definition components.hpp:17
Vec2 position
Center of the entity.
Definition components.hpp:19

◆ velocity_fields

constexpr std::array aegis2d::script::detail::velocity_fields
inlineconstexpr
Initial value:
{
Field<ecs::Velocity>{"x", FieldType::Number,
[](const ecs::Velocity& c) { return double{c.value.x}; },
[](ecs::Velocity& c, double v) { c.value.x = static_cast<float>(v); }},
Field<ecs::Velocity>{"y", FieldType::Number,
[](const ecs::Velocity& c) { return double{c.value.y}; },
[](ecs::Velocity& c, double v) { c.value.y = static_cast<float>(v); }},
}
How fast an entity moves.
Definition components.hpp:25
Vec2 value
Speed in logical pixels per second.
Definition components.hpp:27