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
QueryClick Class Reference

The aspect responsible for conducting raycasts and calling pointer event callbacks on eligible objects. More...

#include <query_click.hpp>

Inheritance diagram for QueryClick:
ToyMaker::SimObjectAspect< QueryClick > IUsePointer ToyMaker::BaseSimObjectAspect ToyMaker::SignalTracker ToyMaker::IActionHandler

Public Member Functions

std::shared_ptr< BaseSimObjectAspect > clone () const override
 Creates a new query click aspect using this one as its blueprint.
 
- 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.
 
- Public Member Functions inherited from IUsePointer
 ~IUsePointer ()=default
 Virtual IUsePointer destructor, so that subclasses can use their own.
 

Static Public Member Functions

static std::string getSimObjectAspectTypeName ()
 Gets the aspect type string associated with this class.
 
static std::shared_ptr< BaseSimObjectAspect > create (const nlohmann::json &jsonAspectProperties)
 Creates a query click object based on its description in JSON.
 

Protected Member Functions

bool onPointerMove (const ToyMaker::ActionData &actionData, const ToyMaker::ActionDefinition &actionDefinition)
 Method responsible for calling hover callbacks when a pointer move event is received.
 
bool onLeftClick (const ToyMaker::ActionData &actionData, const ToyMaker::ActionDefinition &actionDefinition)
 Method responsible for calling left mouse button press callbacks on eligible objects when a pointer click event is received.
 
bool onLeftRelease (const ToyMaker::ActionData &actionData, const ToyMaker::ActionDefinition &actionDefinition)
 Method responsible for calling left mouse button release callbacks on eligible objects when a pointer button release event is received.
 
- Protected Member Functions inherited from ToyMaker::SimObjectAspect< QueryClick >
 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.
 
- Protected Member Functions inherited from IUsePointer
bool leftClickOn (ILeftClickable &clickable, glm::vec4 clickLocation)
 Calls the left mouse button press (or equivalent) callback on an object.
 
bool leftReleaseOn (ILeftClickable &clickable, glm::vec4 clickLocation)
 Calls the left mouse button release (or equivalent) callback on an object.
 
bool pointerEnter (IHoverable &hoverable, glm::vec4 hoverLocation)
 Callback for when a pointer enters a region containing an object.
 
bool pointerLeave (IHoverable &hoverable)
 Callback for when a pointer leaves a region containing an object.
 

Protected Attributes

std::weak_ptr< ToyMaker::FixedActionBindinghandlerPointerMove
 The binding connecting the pointer move action to its handler method on this object.
 
std::weak_ptr< ToyMaker::FixedActionBindinghandlerLeftClick
 The binding connecting the pointer left click action to its handler method on this object.
 
std::weak_ptr< ToyMaker::FixedActionBindinghandlerLeftRelease
 The binding connecting the pointer left release action to its handler method on this object.
 

Private Member Functions

 QueryClick ()
 Constructs a new Query Click aspect.
 
ToyMaker::Ray rayFromClickCoordinates (glm::vec2 clickCoordinates)
 Converts the location of a pointer event from its normalized viewport coordinates to a camera relative ray into the scene.
 

Private Attributes

std::vector< std::shared_ptr< ToyMaker::SceneNodeCore > > mPreviousQueryResults {}
 A list of results from previous pointer queries.
 

Additional Inherited Members

- 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

The aspect responsible for conducting raycasts and calling pointer event callbacks on eligible objects.

It has access to object click callbacks through its IUsePointer interface.

Should be attached to a SimObject which is a part of the CameraSystem.

Its appearance in JSON is as follows:

{ "type": "QueryClick" }

Member Function Documentation

◆ clone()

std::shared_ptr< ToyMaker::BaseSimObjectAspect > QueryClick::clone ( ) const
overridevirtual

Creates a new query click aspect using this one as its blueprint.

Returns
std::shared_ptr<BaseSimObjectAspect> The newly constructed query click object.

Implements ToyMaker::BaseSimObjectAspect.

◆ create()

std::shared_ptr< ToyMaker::BaseSimObjectAspect > QueryClick::create ( const nlohmann::json & jsonAspectProperties)
static

Creates a query click object based on its description in JSON.

Parameters
jsonAspectPropertiesThe json description of this aspect.
Returns
std::shared_ptr<BaseSimObjectAspect> The newly constructed aspect.

◆ getSimObjectAspectTypeName()

static std::string QueryClick::getSimObjectAspectTypeName ( )
inlinestatic

Gets the aspect type string associated with this class.

Returns
std::string The aspect type string for this class.

◆ onLeftClick()

bool QueryClick::onLeftClick ( const ToyMaker::ActionData & actionData,
const ToyMaker::ActionDefinition & actionDefinition )
protected

Method responsible for calling left mouse button press callbacks on eligible objects when a pointer click event is received.

Parameters
actionDataThe location of the pointer click.
actionDefinitionThe definition of the pointer click action.
Return values
trueThe action was handled by an object supporting the click callback.
falseThe action was not handled by any object.

◆ onLeftRelease()

bool QueryClick::onLeftRelease ( const ToyMaker::ActionData & actionData,
const ToyMaker::ActionDefinition & actionDefinition )
protected

Method responsible for calling left mouse button release callbacks on eligible objects when a pointer button release event is received.

Parameters
actionDataThe location of the pointer button release event.
actionDefinitionThe definition of the pointer button release action.
Return values
trueThe pointer button release action was handled by an objects supporting the appropriate callback.
falseThe pointer button release action was not handledy by any object.

◆ onPointerMove()

bool QueryClick::onPointerMove ( const ToyMaker::ActionData & actionData,
const ToyMaker::ActionDefinition & actionDefinition )
protected

Method responsible for calling hover callbacks when a pointer move event is received.

Parameters
actionDataPointer move event data.
actionDefinitionPointer move event definition.
Return values
trueThe pointer move event was handled by an object handling hover events.
falseThe pointer move event wasn't handled by any object.

◆ rayFromClickCoordinates()

ToyMaker::Ray QueryClick::rayFromClickCoordinates ( glm::vec2 clickCoordinates)
private

Converts the location of a pointer event from its normalized viewport coordinates to a camera relative ray into the scene.

Parameters
clickCoordinatesThe normalized coordinates of the pointer relative to this aspect's camera's viewport.
Returns
ToyMaker::Ray The ray constructed from pointer coordinates.

Member Data Documentation

◆ handlerLeftClick

std::weak_ptr<ToyMaker::FixedActionBinding> QueryClick::handlerLeftClick
protected
Initial value:
{
"UI",
"Tap",
[this](const ToyMaker::ActionData& actionData, const ToyMaker::ActionDefinition& actionDefinition) {
return this->onLeftClick(actionData, actionDefinition);
}
)
}
bool onLeftClick(const ToyMaker::ActionData &actionData, const ToyMaker::ActionDefinition &actionDefinition)
Method responsible for calling left mouse button press callbacks on eligible objects when a pointer c...
Definition query_click.cpp:65
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
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

The binding connecting the pointer left click action to its handler method on this object.

◆ handlerLeftRelease

std::weak_ptr<ToyMaker::FixedActionBinding> QueryClick::handlerLeftRelease
protected
Initial value:
{
"UI",
"Untap",
[this](const ToyMaker::ActionData& actionData, const ToyMaker::ActionDefinition& actionDefinition) {
return this->onLeftRelease(actionData, actionDefinition);
}
)
}
bool onLeftRelease(const ToyMaker::ActionData &actionData, const ToyMaker::ActionDefinition &actionDefinition)
Method responsible for calling left mouse button release callbacks on eligible objects when a pointer...
Definition query_click.cpp:100

The binding connecting the pointer left release action to its handler method on this object.

◆ handlerPointerMove

std::weak_ptr<ToyMaker::FixedActionBinding> QueryClick::handlerPointerMove
protected
Initial value:
{
"UI",
"PointerMove",
[this](const ToyMaker::ActionData& actionData, const ToyMaker::ActionDefinition& actionDefinition) {
return this->onPointerMove(actionData, actionDefinition);
}
)
}
bool onPointerMove(const ToyMaker::ActionData &actionData, const ToyMaker::ActionDefinition &actionDefinition)
Method responsible for calling hover callbacks when a pointer move event is received.
Definition query_click.cpp:134

The binding connecting the pointer move action to its handler method on this object.

◆ mPreviousQueryResults

std::vector<std::shared_ptr<ToyMaker::SceneNodeCore> > QueryClick::mPreviousQueryResults {}
private

A list of results from previous pointer queries.

Used in order to compare results from the two most recent frames, to determine whether or not hover events should be fired this frame.

Todo
We're storing shared pointers to nodes in the scene tree here. There's a bug in waiting if we have a reference to a node that was taken off the active scene tree between queries. I don't really know how to think about the problem just now.

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