NAP
Public Member Functions | Public Attributes | List of all members
InputService Class Reference

#include <inputservice.h>

Public Member Functions

 InputService (ServiceConfiguration *configuration)
 
 InputService (const InputService &that)=delete
 
InputServiceoperator= (const InputService &)=delete
 
void processWindowEvents (Window &window, InputRouter &inputRouter, const EntityList &entities)
 
void processControllerEvents (int controllerID, InputRouter &inputRouter, const EntityList &entities)
 
void processAllEvents (InputRouter &inputRouter, const EntityList &entities)
 
void addEvent (InputEventPtr inEvent)
 
virtual void postUpdate (double deltaTime)
 
- Public Member Functions inherited from Service
UNPREFIXED_MODULE_NAME_INPUTCASE Service (ServiceConfiguration *configuration)
 
virtual void getDependentServices (std::vector< rtti::TypeInfo > &dependencies) override
 
virtual bool init (nap::utility::ErrorState &errorState) override
 
virtual void update (double deltaTime) override
 
virtual void shutdown () override
 
 Service (ServiceConfiguration *configuration)
 
virtual ~Service ()
 
CoregetCore ()
 
const CoregetCore () const
 
std::string getTypeName () const
 
const ModulegetModule () const
 
 Service (Service &)=delete
 
Serviceoperator= (const Service &)=delete
 
 Service (Service &&)=delete
 
Serviceoperator= (Service &&)=delete
 

Public Attributes

Signal< const ControllerConnectionEvent & > controllerConnectionChanged
 Signal emitted when a controller is removed or added. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Service
virtual void registerObjectCreators (rtti::Factory &factory)
 
virtual void getDependentServices (std::vector< rtti::TypeInfo > &dependencies)
 
virtual void created ()
 
virtual bool init (utility::ErrorState &error)
 
virtual void preUpdate (double deltaTime)
 
virtual void update (double deltaTime)
 
virtual void preShutdown ()
 
virtual void shutdown ()
 
virtual void preResourcesLoaded ()
 
virtual void postResourcesLoaded ()
 
template<typename SERVICE_CONFIG >
SERVICE_CONFIG * getConfiguration ()
 
template<typename SERVICE_CONFIG >
const SERVICE_CONFIG * getConfiguration () const
 
std::string getIniFilePath () const
 
std::string getIniFilePath (const std::string &appendix) const
 

Description

Stores and processes input events. Currently supports two types of input events: ControllerEvent and WindowInputEvent. Window input events are generated from a window and contain mouse, keyboard and touch events. Controller events are generated from an external piece of hardware such as a game controller or joystick and are not related to a window Separate functions are available to forward stored input events to parts of the scene / a set of entities. It's important to call process..() at least once every frame! Dangling events, ie: events that are not processed, are cleared automatically each frame.

Inheritance diagram for InputService:
[legend]
Collaboration diagram for InputService:
[legend]

Constructor & Destructor Documentation

◆ InputService() [1/2]

InputService ( ServiceConfiguration configuration)

◆ InputService() [2/2]

InputService ( const InputService that)
delete

Member Function Documentation

◆ addEvent()

void addEvent ( InputEventPtr  inEvent)

Adds an input event to the queue, to be processed later.

Parameters
inEventthe event to add, ownership is transfered here

◆ operator=()

InputService& operator= ( const InputService )
delete

◆ postUpdate()

virtual void postUpdate ( double  deltaTime)
virtual

Clears all dangling input events.

Reimplemented from Service.

◆ processAllEvents()

void processAllEvents ( InputRouter inputRouter,
const EntityList entities 
)

Utility function that processes all input events. This call forwards all events, regardless of where they come from, to the given list of entities. This only works when there is exactly 1 window and therefore no reason to distinguish between windows. When there are multiple windows call processWindowEvents and processControllerEvents individually! Individual calls ensure that input events from a certain window are forwarded to the right part of the system.

Parameters
inputRouterThe input router that selects what InputComponents receive input messages.
entitiesA list of root entities that are used to traverse the entity hierarchy.

◆ processControllerEvents()

void processControllerEvents ( int  controllerID,
InputRouter inputRouter,
const EntityList entities 
)

Forwards all input events associated with a specific 'game' controller, to all input components that are part of the list of entities The input router controls how the events are forwarded. A default input router will suffice in most cases

Parameters
controllerIDthe game controller id, starting from 0
inputRouterThe input router that selects what InputComponents receive input messages.
entitiesA list of root entities that are used to traverse the entity hierarchy.

◆ processWindowEvents()

void processWindowEvents ( Window window,
InputRouter inputRouter,
const EntityList entities 
)

Forwards all input events, generated from a window, to all input components that are part of the list of entities The input router controls how the events are forwarded. A default input router will suffice in most cases The need for this as a separate function is because the same parts of a scene can be drawn to different windows. By explicitly giving a window the user can associate events coming from a specific window to a specific part of the scene.

Parameters
windowThe window to process the input events for (mouse, keyboard touch etc.)
inputRouterThe input router that selects what InputComponents receive input messages.
entitiesA list of root entities that are used to traverse the entity hierarchy.

Member Data Documentation

◆ controllerConnectionChanged

Signal<const ControllerConnectionEvent&> controllerConnectionChanged

Signal emitted when a controller is removed or added.