Difference between revisions of "HPL3/SOMA/Scripting/Input Types"

From Frictional Wiki
< HPL3‎ | SOMA‎ | Scripting
Jump to navigation Jump to search
(Rough outline of InputHandler_types script)
 
m
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<br />
 
<br />
  
== What are Input types? ==
+
==What are Input types?==
 
Input types ''(InputHandler_types.hps)'' is a script consisting of two Shared '''Enum classes''' which can be considered as a list of possible actions.
 
Input types ''(InputHandler_types.hps)'' is a script consisting of two Shared '''Enum classes''' which can be considered as a list of possible actions.
  
Line 8: Line 8:
 
Names of these classes are somewhat self-explanatory:
 
Names of these classes are somewhat self-explanatory:
  
== eAction ==
+
==eAction==
 
- Button-like action (fixed step)
 
- Button-like action (fixed step)
  
=== Handler ===
+
===Handler===
These interactions are directly handled by ''"OnAction ( alAction, abPressed )"''. However the game some of these actions later converts to Analog type and then handles just like [[Input Types#eAnalogTypes|eAnalogTypes]]
+
These interactions are directly handled by ''"OnAction ( alAction, abPressed )"''. However the game some of these actions later converts to Analog type and then handles just like [[HPL3/SOMA/Scripting/Input Types#eAnalogTypes|eAnalogTypes]]
  
==== Params: ====
+
====Params:====
  
===== (int)  alAction =====
+
=====(int)  alAction=====
  
* Number representation <sub>(?of input type position?)</sub> in eAction
+
*Number representation <sub>(?of input type position?)</sub> in eAction
** addressable using one of the '''eAction enum''' entries
+
**addressable using one of the '''eAction enum''' entries
  
===== (bool)  abPressed =====
+
=====(bool)  abPressed=====
  
* Has it been pressed?
+
*Has it been pressed?
  
==== Typical use ====
+
====Typical use====
 
<syntaxhighlight lang="c++">
 
<syntaxhighlight lang="c++">
 
void OnAction(int alAction, bool abPressed)
 
void OnAction(int alAction, bool abPressed)
Line 39: Line 39:
 
</syntaxhighlight>code that takes care of FlashLight. <u>(- script/player/Player.hps)</u>
 
</syntaxhighlight>code that takes care of FlashLight. <u>(- script/player/Player.hps)</u>
  
== eAnalogTypes ==
+
==eAnalogTypes==
 
- Joystick-like action (Analog step)
 
- Joystick-like action (Analog step)
  
=== Handler ===
+
===Handler===
 
These are being handled by functions ''"OnAnalogInput ( alAnalogID, avAmount )"'' .
 
These are being handled by functions ''"OnAnalogInput ( alAnalogID, avAmount )"'' .
  
==== Params: ====
+
====Params:====
  
* (int)  alAnalogId
+
*(int)  alAnalogId
** number representation <sub>(?of input type position?)</sub> in eAnalogTypes
+
**number representation <sub>(?of input type position?)</sub> in eAnalogTypes
*** addressable using one of the '''eAnalogTypes enum''' entries
+
***addressable using one of the '''eAnalogTypes enum''' entries
* (cVector3f)  avAmount
+
*(cVector3f)  avAmount
** 3D vector <sub>(?Basket class?)</sub> with parameters:
+
**3D vector <sub>(?Basket class?)</sub> with parameters:
*** X
+
***X
*** Y
+
***Y
*** Z
+
***Z
** Values of [-1.0f ; 1.0f]
+
**Values of [-1.0f ; 1.0f]
  
==== Typical use ====
+
====Typical use====
 
<syntaxhighlight lang="c++">
 
<syntaxhighlight lang="c++">
 
void OnAnalogInput(int alAnalogId, const cVector3f &in avAmount)
 
void OnAnalogInput(int alAnalogId, const cVector3f &in avAmount)
Line 93: Line 93:
 
</syntaxhighlight>Here you can see also already mentioned analog type ''(eAnalogType_Move)'' that was earlier sampled and quantized from ''eAction_Forward / _Backward / _Right / _Left'', by other script. <u>(- script/player/Player.hps)</u>
 
</syntaxhighlight>Here you can see also already mentioned analog type ''(eAnalogType_Move)'' that was earlier sampled and quantized from ''eAction_Forward / _Backward / _Right / _Left'', by other script. <u>(- script/player/Player.hps)</u>
  
''Weakspot''
+
==Uses==
 +
This class could be considered a Weak Spot in case you ever wanted to do some new player implementations or to make your game controllable by virtually anything.
  
''This is your weakspot in case you want to control the game using almost anything imaginable. Only thing needed is an Controller emulator that translates''
+
With a slight combination of [[HPL3/SOMA/Scripting/Input Handler|Input Handler]] and [[HPL3/SOMA/Scripting/Player Overview|Player]] scripts even [https://youtu.be/ZS0fIS2qrSA implementing a Microphone is possible.]

Latest revision as of 03:57, 14 September 2021


What are Input types?

Input types (InputHandler_types.hps) is a script consisting of two Shared Enum classes which can be considered as a list of possible actions.

?Be sure to use them correctly as trying to add own Enum Class while trying to use them as a part of gameplay should not work.?

Names of these classes are somewhat self-explanatory:

eAction

- Button-like action (fixed step)

Handler

These interactions are directly handled by "OnAction ( alAction, abPressed )". However the game some of these actions later converts to Analog type and then handles just like eAnalogTypes

Params:

(int) alAction
  • Number representation (?of input type position?) in eAction
    • addressable using one of the eAction enum entries
(bool) abPressed
  • Has it been pressed?

Typical use

void OnAction(int alAction, bool abPressed)
	{	
		///////////////////////////////////
		// Flashlight
		if(abPressed && alAction==eAction_Flashlight)
		{
			
			SetFlashlightOn(!mbFlashlightOn);
		}
	}

code that takes care of FlashLight. (- script/player/Player.hps)

eAnalogTypes

- Joystick-like action (Analog step)

Handler

These are being handled by functions "OnAnalogInput ( alAnalogID, avAmount )" .

Params:

  • (int) alAnalogId
    • number representation (?of input type position?) in eAnalogTypes
      • addressable using one of the eAnalogTypes enum entries
  • (cVector3f) avAmount
    • 3D vector (?Basket class?) with parameters:
      • X
      • Y
      • Z
    • Values of [-1.0f ; 1.0f]

Typical use

	void OnAnalogInput(int alAnalogId, const cVector3f &in avAmount)
	{
         //....................
         //////////////////////
         // Move
         if(alAnalogId == eAnalogType_Move || alAnalogId == eAnalogType_GamepadMove)
		{
			iCharacterBody@ pCharBody = mBaseObj.GetCharacterBody();
			float fLength = avAmount.Length();
			
			if(fLength > 0.1f)
			{
				//////////////////////////////
				// Lean
				if(mbAnalogLeanPressed)
				{
					Lean(avAmount.x);		
				}
				//////////////////////////////
				// Movement
				else
				{
					if(cMath_Abs(avAmount.y) > 0.001f)
						pCharBody.Move(eCharDir_Forward, avAmount.y);
				
					if(cMath_Abs(avAmount.x) > 0.001f)
						pCharBody.Move(eCharDir_Right, avAmount.x);
				}
			}
		}
         //....................
	}

Here you can see also already mentioned analog type (eAnalogType_Move) that was earlier sampled and quantized from eAction_Forward / _Backward / _Right / _Left, by other script. (- script/player/Player.hps)

Uses

This class could be considered a Weak Spot in case you ever wanted to do some new player implementations or to make your game controllable by virtually anything.

With a slight combination of Input Handler and Player scripts even implementing a Microphone is possible.