source: trunk/src/input/input.h @ 1768

Last change on this file since 1768 was 1768, checked in by touky, 8 years ago

Added Attachment/base logic with working attachment with EasyCharacterController.
Added RayCastResult & a naïve integration for EasyCharacterController.
Enjoy !

  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11//
12// The Input static class
13// ----------------------
14//
15
16#if !defined __LOL_INPUT_INPUT_H__
17#define __LOL_INPUT_INPUT_H__
18
19#include <cstring>
20#include "lol/math/vector.h"
21#include "input/stick.h"
22
23namespace lol
24{
25
26class WorldEntity;
27
28//Partial Key reap-off of the SDLK enum
29#define LOLK_UNKNOWN = 0;
30
31#define LOLK_RETURN = '\r';
32#define LOLK_ESCAPE = '\033';
33#define LOLK_BACKSPACE = '\b';
34#define LOLK_TAB = '\t';
35#define LOLK_SPACE = ' ';
36#define LOLK_EXCLAIM = '!';
37#define LOLK_QUOTEDBL = '"';
38#define LOLK_HASH = '#';
39#define LOLK_PERCENT = '%';
40#define LOLK_DOLLAR = '$';
41#define LOLK_AMPERSAND = '&';
42#define LOLK_QUOTE = '\'';
43#define LOLK_LEFTPAREN = '(';
44#define LOLK_RIGHTPAREN = ')';
45#define LOLK_ASTERISK = '*';
46#define LOLK_PLUS = '+';
47#define LOLK_COMMA = ';';
48#define LOLK_MINUS = '-';
49#define LOLK_PERIOD = '.';
50#define LOLK_SLASH = '/';
51#define LOLK_0 = '0';
52#define LOLK_1 = '1';
53#define LOLK_2 = '2';
54#define LOLK_3 = '3';
55#define LOLK_4 = '4';
56#define LOLK_5 = '5';
57#define LOLK_6 = '6';
58#define LOLK_7 = '7';
59#define LOLK_8 = '8';
60#define LOLK_9 = '9';
61#define LOLK_COLON = ':';
62#define LOLK_SEMICOLON = ';';
63#define LOLK_LESS = '<';
64#define LOLK_EQUALS = '=';
65#define LOLK_GREATER = '>';
66#define LOLK_QUESTION = '?';
67#define LOLK_AT = '@';
68/*
69    Skip uppercase letters
70    */
71#define LOLK_LEFTBRACKET = '[';
72#define LOLK_BACKSLASH = '\\';
73#define LOLK_RIGHTBRACKET = ']';
74#define LOLK_CARET = '^';
75#define LOLK_UNDERSCORE = '_';
76#define LOLK_BACKQUOTE = '`';
77#define LOLK_a = 'a';
78#define LOLK_b = 'b';
79#define LOLK_c = 'c';
80#define LOLK_d = 'd';
81#define LOLK_e = 'e';
82#define LOLK_f = 'f';
83#define LOLK_g = 'g';
84#define LOLK_h = 'h';
85#define LOLK_i = 'i';
86#define LOLK_j = 'j';
87#define LOLK_k = 'k';
88#define LOLK_l = 'l';
89#define LOLK_m = 'm';
90#define LOLK_n = 'n';
91#define LOLK_o = 'o';
92#define LOLK_p = 'p';
93#define LOLK_q = 'q';
94#define LOLK_r = 'r';
95#define LOLK_s = 's';
96#define LOLK_t = 't';
97#define LOLK_u = 'u';
98#define LOLK_v = 'v';
99#define LOLK_w = 'w';
100#define LOLK_x = 'x';
101#define LOLK_y = 'y';
102#define LOLK_z = 'z';
103
104struct ActionSetting
105{
106        int                                             ActionId;
107        float                                   BufferingTime;
108        float                                   BufferedSince;
109
110        ActionSetting(int NewActionId)
111        {
112                memset(this, 0, sizeof(ActionSetting));
113                ActionId = NewActionId;
114        }
115};
116
117struct ButtonSetting
118{
119        int                                             RawButtonId;
120        int                                             CurStatus;
121        int                                             PrevStatus;
122        Array<ActionSetting>    AssociatedActionList;
123
124        ButtonSetting(int NewRawButtonId)
125        {
126                memset(this, 0, sizeof(ButtonSetting));
127                RawButtonId = NewRawButtonId;
128        }
129        int GetActionSettingIdx(int ActionId)
130        {
131                for (int i = 0; i < AssociatedActionList.Count(); i++)
132                        if (AssociatedActionList[i].ActionId == ActionId)
133                                return i;
134                return -1;
135        }
136};
137
138class Input
139{
140private:
141        static Array<ButtonSetting>     InputAssocationList;
142
143        static int GetButtonSettingIdx(int ButtonId)
144        {
145                for (int i = 0; i < InputAssocationList.Count(); i++)
146                        if (InputAssocationList[i].RawButtonId == ButtonId)
147                                return i;
148                return -1;
149        }
150
151        static void UpdateActionStatus(float seconds);
152
153public:
154
155    /* These methods are general queries */
156    static ivec2 GetMousePos();
157    static ivec3 GetMouseButtons();
158
159        //BH : Shouldn't use this
160    static int GetButtonState(int button);
161
162        //Action management
163        static void LinkActionIdToButtonId(int ActionId, int ButtonId);
164        static void UnlinkActionId(int ActionId);
165        static int GetActionStatus(int ActionId);
166        static bool WasActionJustReleased(int ActionId);
167
168    /* Entities can subscribe to events */
169    static void TrackMouse(WorldEntity *e);
170    static void UntrackMouse(WorldEntity *e);
171
172    /* These methods are called by the underlying input listeners */
173    static void SetMousePos(ivec2 coord);
174    static void SetMouseButton(int index);
175    static void UnsetMouseButton(int index);
176
177    /*
178     * Joystick handling
179     */
180
181    static Stick *CreateStick();
182    static void DestroyStick(Stick *stick);
183
184    static Stick *TrackStick(int desired);
185    static void UntrackStick(Stick *stick);
186};
187
188} /* namespace lol */
189
190#endif // __LOL_INPUT_INPUT_H__
191
Note: See TracBrowser for help on using the repository browser.