Plasma Engine  2.0
Loading...
Searching...
No Matches
InputComponent.h
1#pragma once
2
3#include <Core/Input/Declarations.h>
4#include <Core/Messages/EventMessage.h>
5#include <Core/Messages/TriggerMessage.h>
6#include <Core/World/World.h>
7#include <GameEngine/GameEngineDLL.h>
8
10
12struct PL_GAMEENGINE_DLL plInputMessageGranularity
13{
14 using StorageType = plInt8;
15
17 enum Enum
18 {
22
23 Default = PressOnly
24 };
25};
26
27PL_DECLARE_REFLECTABLE_TYPE(PL_GAMEENGINE_DLL, plInputMessageGranularity);
28
30struct PL_GAMEENGINE_DLL plMsgInputActionTriggered : public plEventMessage
31{
32 PL_DECLARE_MESSAGE_TYPE(plMsgInputActionTriggered, plEventMessage);
33
36
39
42
43private:
44 const char* GetInputAction() const { return m_sInputAction; }
45 void SetInputAction(const char* szInputAction) { m_sInputAction.Assign(szInputAction); }
46};
47
55class PL_GAMEENGINE_DLL plInputComponent : public plComponent
56{
57 PL_DECLARE_COMPONENT_TYPE(plInputComponent, plComponent, plInputComponentManager);
58
60 // plComponent
61
62public:
63 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
64 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
65
66
68 // plInputComponent
69
70public:
73
78 float GetCurrentInputState(const char* szInputAction, bool bOnlyKeyPressed = false) const; // [ scriptable ]
79
80 plString m_sInputSet; // [ property ]
81 plEnum<plInputMessageGranularity> m_Granularity; // [ property ]
82 bool m_bForwardToBlackboard = false; // [ property ]
83
84protected:
85 void Update();
86
87 plEventMessageSender<plMsgInputActionTriggered> m_InputEventSender; // [ event ]
88};
Base class of all component types.
Definition Component.h:25
Simple component manager implementation that calls an update method on all components every frame.
Definition ComponentManager.h:142
A message sender that sends all messages to the next component derived from plEventMessageHandlerComp...
Definition EventMessage.h:39
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
void Assign(const char(&string)[N])
Assigning a new string from a string constant is a slow operation, but the hash computation can happe...
This component polls all input events from the given input set every frame and broadcasts the informa...
Definition InputComponent.h:56
Reads a world description from a stream. Allows to instantiate that world multiple times in different...
Definition WorldReader.h:47
Stores an entire plWorld in a stream.
Definition WorldWriter.h:13
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Base class for all messages that are sent as 'events'.
Definition EventMessage.h:8
Which types of input events are broadcast.
Definition InputComponent.h:13
Enum
Which types of input events are broadcast.
Definition InputComponent.h:18
@ PressAndRelease
Key pressed and key released events are sent.
Definition InputComponent.h:20
@ PressOnly
Key pressed events are sent, but nothing else.
Definition InputComponent.h:19
@ PressReleaseAndDown
Key pressed and released events are sent, and while a key is down, another message is sent every fram...
Definition InputComponent.h:21
plInputComponent raises this event when it detects input
Definition InputComponent.h:31
plHashedString m_sInputAction
The input action string.
Definition InputComponent.h:35
plEnum< plTriggerState > m_TriggerState
The 'trigger state', depending on the key state and the configuration on the plInputComponent.
Definition InputComponent.h:38
float m_fKeyPressValue
For analog keys, how much they are pressed. Typically between 0 and 1.
Definition InputComponent.h:41