System

namespace tnt
namespace doo

Variables

template<typename T> concept system = requires { typename T::component; } and requires (T &t, object const& o, nlohmann::json& j, typename T::component const& c) { { t.add_object(o, c) } -> detail::void_type; { t.remove(o) } -> detail::void_type; { t.clear() } -> detail::void_type; { t.Update(o, 1.f) } -> detail::void_type; { t.from_json(o, j) } -> detail::void_type; { t.to_json(o, j) } -> detail::void_type; { t.active } -> std::same_as<tnt::sparse_set<tnt::doo::object>>; }

A concept representing the minimal requirements that a type must fulfill to be a DOO ECS system.

template<system T>
struct system_base : public tnt::crtp<T>
#include <System.hpp>

A helper class for defining custom DOO ECS systems.

Template Parameters
  • T: The class that will be used as a system.

Public Types

using component = typename T::component

The component type stored by this system.

Public Functions

void add_object(object const &id, component const &c)

Add the data of the object with given id to the system.

Parameters
  • id: The id of the object.

  • c: The component data.

void Update(object const &id, float time_)

Update the data of the desired object.

Parameters
  • id: The id of the object.

  • time_: The time elapsed since the last Update call.

void remove(object const &id)

Remove the data of the desired object from the system.

Parameters
  • id: The id of the object to remove.

void clear () noexcept(noexcept(super.clear()))

Remove the data of all the objects from the system.

void from_json(object const &id, nlohmann::json const &j)

Load the data of an object from a json chunk.

Parameters
  • id: The id of the desired object.

  • j: The json chunk containing the data of the component.

void to_json(object const &id, nlohmann::json &j)

Serialize the component data of the given object to a json chunk.

Parameters
  • id: The id of the desired object.

  • j: The json chunk where the data will be stored.

namespace detail

Variables

template<typename T> concept void_type = std::is_void_v<T>