Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ToyMaker::SimObjectAspect< TSimObjectAspectDerived > Class Template Reference

An object containing closely related methods and data, and exposing object lifecycle and application event loops to a developer extending it. More...

#include <sim_system.hpp>

Inheritance diagram for ToyMaker::SimObjectAspect< TSimObjectAspectDerived >:
ToyMaker::BaseSimObjectAspect ToyMaker::SignalTracker ToyMaker::IActionHandler

Protected Member Functions

 SimObjectAspect (int explicitlyInitializeMe)
 
- Protected Member Functions inherited from ToyMaker::BaseSimObjectAspect
 BaseSimObjectAspect (const BaseSimObjectAspect &other)=delete
 
 BaseSimObjectAspect (BaseSimObjectAspect &&other)=delete
 
SimObjectgetSimObject ()
 Returns the sim object that this aspect is attached to.
 
template<typename TComponent>
void addComponent (const TComponent &component)
 Adds a component of some type to the underlying entity.
 
template<typename TComponent>
bool hasComponent ()
 Tests whether a component of some specific type is present on the object.
 
template<typename TComponent>
void updateComponent (const TComponent &component)
 Updates the value of a component belonging to this object to a new one.
 
template<typename TComponent>
TComponent getComponent (const float simulationProgress=1.f) const
 Gets the value of a component belonging to this object.
 
template<typename TComponent>
void removeComponent ()
 Removes a component of some type belonging to the underlying SimObject.
 
void addAspect (const nlohmann::json &jsonAspectProperties)
 Adds a new aspect to the underlying SimObject constructed based on its properties in JSON.
 
void addAspect (const BaseSimObjectAspect &aspect)
 Adds a new aspect to the underlying SimObject copied from an already existing aspect.
 
template<typename TSimObjectAspect>
bool hasAspect () const
 Tests whether an aspect of a particular type is attached to the underlying SimObject.
 
bool hasAspect (const std::string &aspectType) const
 Tests whether an aspect of a particular type is attached to the underlying SimObject.
 
template<typename TSimObjectAspect>
TSimObjectAspect & getAspect ()
 Gets an aspect of a particular type belonging to the underlying SimObject.
 
BaseSimObjectAspectgetAspect (const std::string &aspectType)
 Gets (a base class reference to) an aspect of a particular type belonging to the underlying SimObject.
 
template<typename TSimObjectAspect>
void removeAspect ()
 Removes an aspect from the underlying SimObject.
 
void addOrReplaceAspect (const BaseSimObjectAspect &aspect)
 Adds or replaces an aspect on the underlying SimObject with a new aspect constructed as a copy of another.
 
void addOrReplaceAspect (const nlohmann::json &jsonAspectProperties)
 Adds or replaces an aspect on the underlying SimObject with a new aspect constructed from its JSON description.
 
std::weak_ptr< FixedActionBindingdeclareFixedActionBinding (const std::string &context, const std::string &action, std::function< bool(const ActionData &, const ActionDefinition &)>)
 Binds some method (or any function) present on this object to an action generated by the InputManager.
 
EntityID getEntityID () const
 Gets the ID of the ECSWorld Entity belonging to our SimObject.
 
std::weak_ptr< ECSWorldgetWorld () const
 Gets a weak reference to the ECSWorld to which our SimObject's entity belongs.
 

Private Member Functions

std::string getAspectTypeName () const override
 Returns the aspect type string associated with TSimObjectAspectDerived.
 

Static Private Member Functions

static void registerSelf ()
 Registers the new aspect class and its constructor with the SimSystem.
 

Static Private Attributes

static Registrator< SimObjectAspect< TSimObjectAspectDerived > > & s_registrator
 The static helper class instance, responsible for making sure registerSelf() is called during the static initialization phase of the program.
 

Friends

class Registrator< SimObjectAspect< TSimObjectAspectDerived > >
 
class SimObject
 

Additional Inherited Members

- Public Member Functions inherited from ToyMaker::BaseSimObjectAspect
virtual ~BaseSimObjectAspect ()=default
 Destroys this object.
 
virtual void simulationUpdate (uint32_t simStepMillis)
 Overriding this allows an aspect to respond to simulation updates.
 
virtual void variableUpdate (uint32_t variableStepMillis)
 Overriding this allows an aspect to respond to variable updates.
 
bool handleAction (const ActionData &actionData, const ActionDefinition &actionDefinition) override final
 Pipes an action received from the InputManager via our SimObject to all that action's handler methods on this aspect.
 
ViewportNodegetLocalViewport ()
 Returns the closest ancestor viewport to this node, if one exists (which it should, since this shouldn't be called until this aspect is attached to an active SimObject).
 
- Public Member Functions inherited from ToyMaker::SignalTracker
 SignalTracker ()
 Constructs a new SignalTracker object.
 
 SignalTracker (const SignalTracker &other)
 Constructs a new SignalTracker.
 
SignalTrackeroperator= (const SignalTracker &other)
 Copy assignment operator.
 
 SignalTracker (SignalTracker &&other)
 Moves resources from another SignalTracker into this one, invalidating them from the other.
 
SignalTrackeroperator= (SignalTracker &&other)
 Moves resources from another SignalTracker into this one, destroying this tracker's resources in the process.
 
void connect (const std::string &theirSignal, const std::string &ourObserver, SignalTracker &other)
 Method that connects one of this objects SignalObservers to another tracker's Signal.
 
- Static Protected Member Functions inherited from ToyMaker::BaseSimObjectAspect
template<typename TSimObjectAspectDerived>
static void registerAspect ()
 Registers an implementation of an aspect with the SimSystem.
 

Detailed Description

template<typename TSimObjectAspectDerived>
class ToyMaker::SimObjectAspect< TSimObjectAspectDerived >

An object containing closely related methods and data, and exposing object lifecycle and application event loops to a developer extending it.

Each SimObjectAspect implementation represents some behaviour and/or data representing the object it is attached to.

Implementations should strive to be orthogonal to other aspects in the project. This does not mean, however, that two aspect implementations cannot be related to or dependent on each other. But they should, as far as possible, be made so that the addition of one does not require the removal of another on the same object.

Usage:

Example aspect class header:

// NOTE: Inherit (using CRTP) SimObjectAspect.
class UrLookAtBoard: public ToyMaker::SimObjectAspect<UrLookAtBoard> {
public:
// NOTE: Basic constructor, explicitly calling the constructor of the base class.
UrLookAtBoard() : SimObjectAspect<UrLookAtBoard>{0} {}
// NOTE: Aspect type string of this aspect.
inline static std::string getSimObjectAspectTypeName() { return "UrLookAtBoard"; }
// NOTE: Explicit static constructor function for this type from its JSON description.
static std::shared_ptr<ToyMaker::BaseSimObjectAspect> create(const nlohmann::json& jsonAspectProperties);
// NOTE: Override for its clone method for making valid copies of this aspect.
std::shared_ptr<ToyMaker::BaseSimObjectAspect> clone() const override;
private:
// NOTE: Property belonging to this aspect describing it in some way.
glm::vec3 mOffset { 0.f, 1.f, 2.f };
// NOTE: (optional) override(s) for object lifecycle/engine event loop hooks.
void onActivated() override;
};
An object containing closely related methods and data, and exposing object lifecycle and application ...
Definition sim_system.hpp:956
Stupid utility class for centering the game camera in the 3D scene on the game board object.
Definition ur_look_at_board.hpp:22

Example aspect constructor implementation:

// NOTE: manual mapping from JSON description to object properties
std::shared_ptr<ToyMaker::BaseSimObjectAspect> UrLookAtBoard::create(const nlohmann::json& jsonAspectProperties) {
std::shared_ptr<UrLookAtBoard> lookAtBoardAspect { std::make_shared<UrLookAtBoard>() };
lookAtBoardAspect->mOffset = glm::vec3{
jsonAspectProperties.at("offset")[0].get<float>(),
jsonAspectProperties.at("offset")[1].get<float>(),
jsonAspectProperties.at("offset")[2].get<float>(),
};
return lookAtBoardAspect;
}
// NOTE: Custom value copy implementation
std::shared_ptr<ToyMaker::BaseSimObjectAspect> UrLookAtBoard::clone() const {
std::shared_ptr<UrLookAtBoard> lookAtBoardAspect { std::make_shared<UrLookAtBoard>() };
lookAtBoardAspect->mOffset = mOffset;
return lookAtBoardAspect;
}
std::shared_ptr< ToyMaker::BaseSimObjectAspect > clone() const override
A method which must be overridden to specify how a new aspect should be constructed as a copy of this...
Definition ur_look_at_board.cpp:13

The aspect's description in JSON:

{ "type": "UrLookAtBoard", "offset": [0.0, 1.0, 7.0] }

Member Function Documentation

◆ getAspectTypeName()

template<typename TSimObjectAspectDerived>
std::string ToyMaker::SimObjectAspect< TSimObjectAspectDerived >::getAspectTypeName ( ) const
inlineoverrideprivatevirtual

Returns the aspect type string associated with TSimObjectAspectDerived.

Returns
std::string The aspect type string of the aspect.

Implements ToyMaker::BaseSimObjectAspect.


The documentation for this class was generated from the following file: