source: golgotha/src/golg/input.hh

Last change on this file was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 3.8 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef G1_INPUT_HH
10#define G1_INPUT_HH
11
12
13#include "device/device.hh"
14#include "device/keys.hh"
15#include "player_type.hh"
16#include "time/time.hh"
17
18// This class will gather global key presses and store only those relavant to the game.
19// This should also allow playstation input to be inserted at this level.
20
21// Ussage :
22
23// if (g1_input.active(g1_input_class::LEFT))
24//   move_to_the_left();
25
26
27class i4_key_matchup_class;
28
29class g1_input_class : public i4_event_handler_class
30{
31  i4_key_matchup_class *matchup;
32public:
33  enum in_type
34  { LEFT =0,
35    RIGHT,
36    UP,
37    DOWN,
38    BUTTON_1,
39    BUTTON_2,
40    BUTTON_3,
41    STRAFE_LEFT,
42    STRAFE_RIGHT,
43    STRAFE_MODIFIER,
44    ZOOM_IN,
45    ZOOM_OUT,
46    ZOOM_UP,
47    ZOOM_DOWN,
48    ZOOM_LEFT,
49    ZOOM_RIGHT,
50    NUM_STANK_CONTROLS,
51  };
52
53  enum input_state { NOT_PRESSED,
54                     PRESSED,
55                     PRESSED_AND_RELEASED };  // this state is so we don't miss a button between
56                                              // frames
57private:
58
59  w8 in[NUM_STANK_CONTROLS];
60
61  i4_time_class time_down[NUM_STANK_CONTROLS];   // time the key was pressed
62  w32 time_qued[NUM_STANK_CONTROLS];             // milli secs of unprocessed time
63
64  sw8 keys[I4_NUM_KEYS];
65
66  g1_player_type command_player_num;
67  i4_bool esc, cont;
68 
69  enum {CHEATCODE_BUFFERSIZE = 16};
70
71  char cheat_code_buffer[CHEATCODE_BUFFERSIZE]; //keeps a buffer of the last 16 keys for whatever reason
72
73public:
74  enum { MOUSE_SCROLL_LEFT=1,
75         MOUSE_SCROLL_RIGHT=2,
76         MOUSE_SCROLL_UP=4,
77         MOUSE_SCROLL_DOWN=8 };
78
79  int mouse_scroll_flags;
80  i4_bool key_pressed;
81
82  virtual void receive_event(i4_event *ev);
83
84  void que_keys(i4_time_class cur_time);
85
86  void commands_are_for_player(g1_player_type pl) { command_player_num=pl; }
87
88  void acknowledge();  // called by game after it has examined all the key states
89                       // g1_input then changes all PRESSED_AND_RELEASED to NOT_PRESSED
90
91  void init();
92
93  char *grab_cheat_keys()  { return cheat_code_buffer; }
94  void  clear_cheat_keys() { memset(cheat_code_buffer,0,CHEATCODE_BUFFERSIZE); }
95
96  w32 deque_time(in_type t);
97
98  i4_bool strafe_active() { return (i4_bool)(in[STRAFE_MODIFIER]); }
99  i4_bool strafe_left()   { return (i4_bool)(in[STRAFE_LEFT]  || (in[LEFT] && strafe_active())); } 
100  i4_bool strafe_right()  { return (i4_bool)(in[STRAFE_RIGHT] || (in[RIGHT] && strafe_active())); }
101 
102  i4_bool left()       { return (i4_bool)(in[LEFT] && !strafe_active()); }
103  i4_bool right()      { return (i4_bool)(in[RIGHT] && !strafe_active()); }
104  i4_bool up()         { return in[UP]; }
105  i4_bool down()       { return in[DOWN]; }
106  i4_bool button_1()   { return in[BUTTON_1]; }
107  i4_bool button_2()   { return in[BUTTON_2]; }
108  i4_bool button_3()   { return in[BUTTON_3]; }
109
110  i4_bool zoom_in()    { return in[ZOOM_IN]; }
111  i4_bool zoom_out()   { return in[ZOOM_OUT]; }
112  i4_bool zoom_up()    { return in[ZOOM_UP]; }
113  i4_bool zoom_down()  { return in[ZOOM_DOWN]; }
114  i4_bool zoom_left()  { return in[ZOOM_LEFT]; }
115  i4_bool zoom_right() { return in[ZOOM_RIGHT]; }
116
117  i4_bool esc_pressed() { return esc; }
118  void reset_esc() { esc=i4_F; }
119
120  void uninit();
121  char *name() { return "g1_input"; }
122};
123
124extern g1_input_class g1_input;
125
126#endif
127
Note: See TracBrowser for help on using the repository browser.