1 #pragma once
2 #include <string>
3 //#include "SDL_keycode.h"
4 
5 
6 // These IDs are referenced in the user config files.
7 // To keep them valid, make sure to:
8 // - Add new actions at the end of the enum
9 // - Instead of deleting an action, replace it with a dummy one eg A_Unused
10 
11 enum Actions
12 {	A_ShowOptions, A_PrevTab, A_NextTab, A_RestartGame, A_ResetGame, A_Screenshot, NumActions  };
13 
14 const static std::string csActions[NumActions] =
15 {	"ShowOptions", "PrevTab", "NextTab", "RestartGame", "ResetGame", "Screenshot"  };
16 
17 
18 enum PlayerActions
19 {	A_Throttle, A_Brake, A_Steering, A_HandBrake, A_Boost, A_Flip,
20 	A_ShiftUp, A_ShiftDown, A_PrevCamera, A_NextCamera, A_LastChk, A_Rewind, NumPlayerActions
21 };
22 
23 const static std::string csPlayerActions[NumPlayerActions] =
24 {	"Throttle", "Brake", "Steering", "HandBrake", "Boost", "Flip",
25 	"ShiftUp", "ShiftDown", "PrevCamera", "NextCamera", "LastChk", "Rewind"
26 };
27 
28 namespace ICS
29 {	class InputControlSystem;  class Control;  }
30 
31 
32 //  Input
33 //-----------------------------------------------------------------
34 struct InputAction
35 {
36 	int mId;
37 	std::string mName;
38 	SDL_Keycode mKeyInc, mKeyDec;
39 
40 	enum Type
41 	{	Trigger = 0x00,
42 		Axis = 0x01,     // 2-sided axis, centered in the middle, keyboard emulation with left & right keys
43 		HalfAxis = 0x11  // 1-sided axis, keyboard emulation with 1 key
44 	} mType;
45 
46 	ICS::InputControlSystem* mICS;
47 	ICS::Control* mControl;
48 
49 	InputAction(int id, bool player, SDL_Keycode incKey, Type type = Trigger)
mIdInputAction50 		: mId(id), mKeyInc(incKey), mKeyDec(SDLK_UNKNOWN), mType(type)
51 		, mICS(0), mControl(0)
52 	{
53 		mName = player ? csPlayerActions[id] : csActions[id];
54 	}
InputActionInputAction55 	InputAction(int id, bool player, SDL_Keycode decKey, SDL_Keycode incKey)
56 		: mId(id), mKeyInc(incKey), mKeyDec(decKey), mType(Axis)
57 		, mICS(0), mControl(0)
58 	{
59 		mName = player ? csPlayerActions[id] : csActions[id];
60 	}
61 };
62 
63 
64 class CInput
65 {
66 public:
67 	class App* app;
68 	CInput(App* app1);
69 
70 	//  Input
71 	float mPlayerInputState[4][NumPlayerActions];
72 	boost::mutex mPlayerInputStateMutex;
73 
74 	std::vector<InputAction> mInputActions;
75 	std::vector<InputAction> mInputActionsPlayer[4];
76 
77 	///  Add
78 	//  Global trigger
AddGlob(Actions a,SDL_Keycode key)79 	void AddGlob(Actions a, SDL_Keycode key)
80 	{
81 		mInputActions.push_back(InputAction(a,false,key));
82 	}
83 	//  player trigger
AddTrig(int plr,PlayerActions a,SDL_Keycode key)84 	void AddTrig(int plr, PlayerActions a, SDL_Keycode key)
85 	{
86 		mInputActionsPlayer[plr].push_back(InputAction(a,true, key));
87 	}
88 	//  player Axis
AddAxis(int plr,PlayerActions a,SDL_Keycode incKey,SDL_Keycode decKey)89 	void AddAxis(int plr, PlayerActions a, SDL_Keycode incKey, SDL_Keycode decKey)
90 	{
91 		mInputActionsPlayer[plr].push_back(InputAction(a,true, incKey,decKey));
92 	}
93 	//  player Half axis
AddHalf(int plr,PlayerActions a,SDL_Keycode key)94 	void AddHalf(int plr, PlayerActions a, SDL_Keycode key)
95 	{
96 		mInputActionsPlayer[plr].push_back(InputAction(a,true, key, InputAction::HalfAxis));
97 	}
98 
99 	void LoadInputDefaults();
100 	void LoadInputDefaults(std::vector<InputAction>& actions, ICS::InputControlSystem* ICS);
101 };
102