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::BaseSimObjectAspect Class Referenceabstract

The base class for all aspects, providing an interface to its attached SimObject, and consequently, the engine's SceneSystem. More...

#include <sim_system.hpp>

Inheritance diagram for ToyMaker::BaseSimObjectAspect:
ToyMaker::SignalTracker ToyMaker::IActionHandler ToyMaker::SimObjectAspect< BoardLocations > ToyMaker::SimObjectAspect< PlayerCPURandom > ToyMaker::SimObjectAspect< PlayerLocal > ToyMaker::SimObjectAspect< QueryClick > ToyMaker::SimObjectAspect< RenderDebugViewer > ToyMaker::SimObjectAspect< UIButton > ToyMaker::SimObjectAspect< UIImage > ToyMaker::SimObjectAspect< UIPanel > ToyMaker::SimObjectAspect< UIText > ToyMaker::SimObjectAspect< UrController > ToyMaker::SimObjectAspect< UrLookAtBoard > ToyMaker::SimObjectAspect< UrRecords > ToyMaker::SimObjectAspect< UrSceneManager > ToyMaker::SimObjectAspect< UrSceneView > ToyMaker::SimObjectAspect< UrUINavigation > ToyMaker::SimObjectAspect< UrUIRecordsBrowser > ToyMaker::SimObjectAspect< UrUITutorialsBrowser > ToyMaker::SimObjectAspect< UrUIVersion > ToyMaker::SimObjectAspect< UrUIView > ToyMaker::SimObjectAspect< TSimObjectAspectDerived >

Public Member Functions

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.
 

Protected Member Functions

 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.
 
virtual std::string getAspectTypeName () const =0
 Overridable function for fetching the aspect type string of an aspect.
 

Static Protected Member Functions

template<typename TSimObjectAspectDerived>
static void registerAspect ()
 Registers an implementation of an aspect with the SimSystem.
 

Private Types

enum  AspectState : uint8_t { ATTACHED =1 , ACTIVE =2 }
 Enum for mask values representing the readiness of an aspect.
 

Private Member Functions

void activateFixedActionBindings ()
 Called when an aspect has just been activated to bind its handler method to its associated action.
 
void deactivateFixedActionBindings ()
 Called when an aspect's SimObject has been deactivated, retiring all currently active action bindings.
 
void onAttached_ ()
 
void onDetached_ ()
 
void onActivated_ ()
 
void onDeactivated_ ()
 
virtual void onAttached ()
 Callback for when an aspect has just been attached to an object (but which hasn't yet been activated).
 
virtual void onDetached ()
 Callback for when an aspect is about to be removed from an object (after it has been deactivated).
 
virtual void onActivated ()
 Callback for when the aspect is activated (after it is attached to an active SimObject, or if the SimObject it was attached to has just been activated)
 
virtual void onDeactivated ()
 Callback for when the aspect is deactivated (just prior to being detached, or when its SimObject has been deactivated).
 
bool isAttached ()
 Tests whether this aspect is attached to a SimObject.
 
bool isActive ()
 Tests whether the SimObject this aspect is attached to is active on the SceneSystem and the SimSystem.
 
void attach (SimObject *owner)
 Causes this aspect to be detached from its previous owner and to be attached to a new one.
 
void detach ()
 Causes this aspect to be disconnected from its current SimObject.
 
virtual std::shared_ptr< BaseSimObjectAspectclone () const =0
 A method which must be overridden to specify how a new aspect should be constructed as a copy of this one.
 

Private Attributes

std::map< std::pair< std::string, std::string >, std::shared_ptr< FixedActionBinding >, std::less< std::pair< std::string, std::string > > > mFixedActionBindings {}
 The set of action bindings owned by this aspect.
 
SimObjectmSimObject { nullptr }
 The SimObject underlying this aspect.
 
uint8_t mState { 0x0 }
 Value representing the readiness of this aspect.
 

Friends

class SimObject
 

Detailed Description

The base class for all aspects, providing an interface to its attached SimObject, and consequently, the engine's SceneSystem.

See also
SimObjectAspect

Member Function Documentation

◆ addAspect() [1/2]

void BaseSimObjectAspect::addAspect ( const BaseSimObjectAspect & aspect)
protected

Adds a new aspect to the underlying SimObject copied from an already existing aspect.

Parameters
aspectThe aspect being copied.

◆ addAspect() [2/2]

void BaseSimObjectAspect::addAspect ( const nlohmann::json & jsonAspectProperties)
protected

Adds a new aspect to the underlying SimObject constructed based on its properties in JSON.

Parameters
jsonAspectPropertiesThe properties of the aspect in JSON.

◆ addComponent()

template<typename TComponent>
void ToyMaker::BaseSimObjectAspect::addComponent ( const TComponent & component)
protected

Adds a component of some type to the underlying entity.

Template Parameters
TComponentThe type of component being added.
Parameters
componentThe value of the component when it is added.

◆ addOrReplaceAspect() [1/2]

void BaseSimObjectAspect::addOrReplaceAspect ( const BaseSimObjectAspect & aspect)
protected

Adds or replaces an aspect on the underlying SimObject with a new aspect constructed as a copy of another.

Parameters
aspectThe aspect being copied.

◆ addOrReplaceAspect() [2/2]

void BaseSimObjectAspect::addOrReplaceAspect ( const nlohmann::json & jsonAspectProperties)
protected

Adds or replaces an aspect on the underlying SimObject with a new aspect constructed from its JSON description.

Parameters
jsonAspectPropertiesThe JSON description of the aspect, including its type and value.

◆ attach()

void BaseSimObjectAspect::attach ( SimObject * owner)
private

Causes this aspect to be detached from its previous owner and to be attached to a new one.

Parameters
ownerThe new owner of this aspect.

◆ clone()

virtual std::shared_ptr< BaseSimObjectAspect > ToyMaker::BaseSimObjectAspect::clone ( ) const
privatepure virtual

A method which must be overridden to specify how a new aspect should be constructed as a copy of this one.

Returns
std::shared_ptr<BaseSimObjectAspect> The newly constructed aspect.

Implemented in BoardLocations, PlayerCPURandom, PlayerLocal, QueryClick, RenderDebugViewer, UIButton, UIImage, UIPanel, UIText, UrController, UrLookAtBoard, UrRecords, UrSceneManager, UrSceneView, UrUINavigation, UrUIRecordsBrowser, UrUITutorialsBrowser, UrUIVersion, and UrUIView.

◆ declareFixedActionBinding()

std::weak_ptr< FixedActionBinding > BaseSimObjectAspect::declareFixedActionBinding ( const std::string & context,
const std::string & action,
std::function< bool(const ActionData &, const ActionDefinition &)> handler )
protected

Binds some method (or any function) present on this object to an action generated by the InputManager.

Usage

// NOTE: Class inherited from SimObjectAspect
class QueryClick: public ToyMaker::SimObjectAspect<QueryClick>, public IUsePointer {
// ...
// NOTE: Handler for UI Tap actions
bool onLeftClick(const ToyMaker::ActionData& actionData, const ToyMaker::ActionDefinition& actionDefinition);
// NOTE: Binding responsible for forwarding UI Tap actions to onLeftClick()
std::weak_ptr<ToyMaker::FixedActionBinding> handlerLeftClick {
"UI",
"Tap",
[this](const ToyMaker::ActionData& actionData, const ToyMaker::ActionDefinition& actionDefinition) {
return this->onLeftClick(actionData, actionDefinition);
}
)
};
// ...
};
The interface used by aspects, objects, which cast pointer rays to interact with objects present in t...
Definition interface_pointer_callback.hpp:35
The aspect responsible for conducting raycasts and calling pointer event callbacks on eligible object...
Definition query_click.hpp:37
std::weak_ptr< FixedActionBinding > declareFixedActionBinding(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...
Definition sim_system.cpp:219
An object containing closely related methods and data, and exposing object lifecycle and application ...
Definition sim_system.hpp:956
The definition of a single action, including whether it represents state or change,...
Definition input_data.hpp:511
A union that may contain any one of SimpleActionData, OneAxisActionData, TwoAxisActionData,...
Definition input_data.hpp:721
Parameters
contextThe name of the context of the bound action.
actionThe name of the action itself.
Returns
std::weak_ptr<FixedActionBinding> A weak pointer to the object representing the binding itself.

◆ getAspect() [1/2]

template<typename TSimObjectAspect>
TSimObjectAspect & ToyMaker::BaseSimObjectAspect::getAspect ( )
protected

Gets an aspect of a particular type belonging to the underlying SimObject.

Template Parameters
TSimObjectAspectThe type of the aspect being retrieved.
Returns
TSimObjectAspect& The retrieved aspect.

◆ getAspect() [2/2]

BaseSimObjectAspect & BaseSimObjectAspect::getAspect ( const std::string & aspectType)
protected

Gets (a base class reference to) an aspect of a particular type belonging to the underlying SimObject.

Parameters
aspectTypeThe aspect type name of the aspect being retrieved.
Returns
BaseSimObjectAspect& The retrieved aspect.

◆ getAspectTypeName()

◆ getComponent()

template<typename TComponent>
TComponent ToyMaker::BaseSimObjectAspect::getComponent ( const float simulationProgress = 1.f) const
protected

Gets the value of a component belonging to this object.

Template Parameters
TComponentThe type of component being retrieved.
Parameters
simulationProgressThe progress towards the next simulation step after the previous one represented as a value between 0 and 1.
Returns
TComponent The retrieved component value.

◆ getEntityID()

EntityID BaseSimObjectAspect::getEntityID ( ) const
protected

Gets the ID of the ECSWorld Entity belonging to our SimObject.

Returns
EntityID This object's entity's ECS entity ID.

◆ getLocalViewport()

ViewportNode & BaseSimObjectAspect::getLocalViewport ( )

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).

Returns
ViewportNode& A reference to this aspect's node's closest ancestor viewport.

◆ getSimObject()

SimObject & BaseSimObjectAspect::getSimObject ( )
protected

Returns the sim object that this aspect is attached to.

Returns
SimObject& A reference to the sim object to which this aspect belongs.

◆ getWorld()

std::weak_ptr< ECSWorld > BaseSimObjectAspect::getWorld ( ) const
protected

Gets a weak reference to the ECSWorld to which our SimObject's entity belongs.

Returns
std::weak_ptr<ECSWorld> The ECSWorld our SimObject's entity belongs to.

◆ handleAction()

bool BaseSimObjectAspect::handleAction ( const ActionData & actionData,
const ActionDefinition & actionDefinition )
finaloverridevirtual

Pipes an action received from the InputManager via our SimObject to all that action's handler methods on this aspect.

Parameters
actionDataThe data describing the action event.
actionDefinitionThe definition of the action event.
Return values
trueThe action was handled by this aspect;
falseThe action was not handled by this aspect;
Todo
Shouldn't this be private? Will something bad happen if we make this private?

Reimplemented from ToyMaker::IActionHandler.

◆ hasAspect() [1/2]

template<typename TSimObjectAspect>
bool ToyMaker::BaseSimObjectAspect::hasAspect ( ) const
protected

Tests whether an aspect of a particular type is attached to the underlying SimObject.

Template Parameters
TSimObjectAspectThe type of aspect whose existence is being tested.
Return values
trueAn aspect of the specified type exists;
falseNo aspect of the type specified exists;

◆ hasAspect() [2/2]

bool BaseSimObjectAspect::hasAspect ( const std::string & aspectType) const
protected

Tests whether an aspect of a particular type is attached to the underlying SimObject.

Parameters
aspectTypeThe aspect type name of the aspect.
Return values
trueAn aspect of this type exists;
falseNo aspect of this type exists;

◆ hasComponent()

template<typename TComponent>
bool ToyMaker::BaseSimObjectAspect::hasComponent ( )
protected

Tests whether a component of some specific type is present on the object.

Template Parameters
TComponentThe type of component whose existence is being tested.
Return values
trueThe component exists;
falseThe component does not exist;

◆ isActive()

bool ToyMaker::BaseSimObjectAspect::isActive ( )
inlineprivate

Tests whether the SimObject this aspect is attached to is active on the SceneSystem and the SimSystem.

Return values
trueThe underlying SimObject (and therefore this aspect) is active.
falseThe underlying SimObject (and therefore this aspect) is inactive, or the SimObject does not exist.

◆ isAttached()

bool ToyMaker::BaseSimObjectAspect::isAttached ( )
inlineprivate

Tests whether this aspect is attached to a SimObject.

Return values
trueThis aspect is attached to a SimObject;
falseThis aspect is untethered;

◆ onActivated()

virtual void ToyMaker::BaseSimObjectAspect::onActivated ( )
inlineprivatevirtual

Callback for when the aspect is activated (after it is attached to an active SimObject, or if the SimObject it was attached to has just been activated)

Reimplemented in PlayerCPURandom, PlayerLocal, UIButton, UIImage, UIPanel, UIText, UrController, UrLookAtBoard, UrRecords, UrSceneManager, UrSceneView, UrUIRecordsBrowser, UrUITutorialsBrowser, UrUIVersion, and UrUIView.

◆ onDeactivated()

virtual void ToyMaker::BaseSimObjectAspect::onDeactivated ( )
inlineprivatevirtual

Callback for when the aspect is deactivated (just prior to being detached, or when its SimObject has been deactivated).

Reimplemented in UrRecords.

◆ registerAspect()

template<typename TSimObjectAspectDerived>
static void ToyMaker::BaseSimObjectAspect::registerAspect ( )
inlinestaticprotected

Registers an implementation of an aspect with the SimSystem.

This gives the sim system a pointer to the function responsible for the construction of an aspect, allowing the aspect to be constructed by its description in a JSON scene file.

Template Parameters
TSimObjectAspectDerivedThe derived aspect's type.
See also
SimSystem

◆ removeAspect()

template<typename TSimObjectAspect>
void ToyMaker::BaseSimObjectAspect::removeAspect ( )
protected

Removes an aspect from the underlying SimObject.

Template Parameters
TSimObjectAspectThe type of the aspect being removed.

◆ removeComponent()

template<typename TComponent>
void ToyMaker::BaseSimObjectAspect::removeComponent ( )
protected

Removes a component of some type belonging to the underlying SimObject.

Template Parameters
TComponentThe type of component being removed.

◆ simulationUpdate()

virtual void ToyMaker::BaseSimObjectAspect::simulationUpdate ( uint32_t simStepMillis)
inlinevirtual

Overriding this allows an aspect to respond to simulation updates.

Parameters
simStepMillisThe time by which the simulation should be advanced, in milliseconds.
See also
SceneSystem::simulationStep()

◆ updateComponent()

template<typename TComponent>
void ToyMaker::BaseSimObjectAspect::updateComponent ( const TComponent & component)
protected

Updates the value of a component belonging to this object to a new one.

Template Parameters
TComponentThe type of component being updated.
Parameters
componentThe new value of the component.

◆ variableUpdate()

virtual void ToyMaker::BaseSimObjectAspect::variableUpdate ( uint32_t variableStepMillis)
inlinevirtual

Overriding this allows an aspect to respond to variable updates.

Parameters
variableStepMillisThe time since the execution of the last frame, in milliseconds.
See also
SceneSystem::variableStep

Reimplemented in UrSceneManager, UrSceneView, and UrUIView.

Member Data Documentation

◆ mFixedActionBindings

std::map< std::pair<std::string, std::string>, std::shared_ptr<FixedActionBinding>, std::less<std::pair<std::string, std::string> > > ToyMaker::BaseSimObjectAspect::mFixedActionBindings {}
private

The set of action bindings owned by this aspect.

See also
declareFixedActionBinding()

◆ mState

uint8_t ToyMaker::BaseSimObjectAspect::mState { 0x0 }
private

Value representing the readiness of this aspect.

See also
AspectState

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