File: input.c

package info (click to toggle)
egoboo-data 2.22-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 44,296 kB
  • ctags: 2,618
  • sloc: ansic: 23,985; makefile: 94
file content (119 lines) | stat: -rw-r--r-- 2,938 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// input.c

// Egoboo, Copyright (C) 2000 Aaron Bishop

#include "egoboo.h"

//--------------------------------------------------------------------------------------------
void read_mouse()
{
  int x,y,b;
  if (menuactive)
	  b = SDL_GetMouseState(&x,&y);
  else
	  b = SDL_GetRelativeMouseState(&x,&y);
  mousex = x; // mousex and mousey are the wrong type to use in above call
  mousey = y;
  mousebutton[0] = (b&SDL_BUTTON(1)) ? 1:0;
  mousebutton[1] = (b&SDL_BUTTON(3)) ? 1:0; 
  mousebutton[2] = (b&SDL_BUTTON(2)) ? 1:0; // Middle is 2 on SDL
  mousebutton[3] = (b&SDL_BUTTON(4)) ? 1:0;
}

//--------------------------------------------------------------------------------------------
void read_key()
{
  sdlkeybuffer = SDL_GetKeyState(NULL);
//  if(sdlkeybuffer[SDLK_RETURN]) exit(1); MN: this should no longer be necessary
}

//--------------------------------------------------------------------------------------------
void read_joystick()
{
  int button;

  if(joyaon) {
    SDL_JoystickUpdate();
    joyax = SDL_JoystickGetAxis(sdljoya,0) / 32;
    if(joyax<100 && joyax>-100) joyax=0;
      joyay = SDL_JoystickGetAxis(sdljoya,1) / 32;
    if(joyay<100 && joyay>-100) joyay=0;
    button = SDL_JoystickNumButtons(sdljoya);
    while(button >= 0)
    {
      joyabutton[button] = SDL_JoystickGetButton(sdljoya, button);
      button--;
    }
  }
  if(joybon) {
    SDL_JoystickUpdate();
    joybx = SDL_JoystickGetAxis(sdljoyb,0) / 32;
    if(joybx<100 && joybx>-100) joybx=0;
      joyby = SDL_JoystickGetAxis(sdljoyb,1) / 32;
    if(joyby<100 && joyby>-100) joyby=0;
    button = SDL_JoystickNumButtons(sdljoyb);
    while(button >= 0)
    {
      joybbutton[button] = SDL_JoystickGetButton(sdljoyb, button);
      button--;
    }
  }
}

//--------------------------------------------------------------------------------------------
void reset_press()
{
    // ZZ> This function resets key press information
/*PORT
    int cnt;
    cnt = 0;
    while(cnt < 256)
    {
        keypress[cnt] = FALSE;
        cnt++;
    }
*/
}

//--------------------------------------------------------------------------------------------
void read_input()
{
    // ZZ> This function gets all the current player input states
    int cnt;
    SDL_Event ev;

	SDL_PumpEvents();
    read_key();
    read_mouse();
    read_joystick();

    while(SDL_PollEvent(&ev))
      {
	switch(ev.type)
	  {
	  case SDL_MOUSEBUTTONDOWN:
	    pending_click = TRUE;
	    break;
	  }
      }

    // Set up for button masks
    jab = 0;
    jbb = 0;
    msb = 0;


    // Joystick mask
    cnt = 0;
    while(cnt < JOYBUTTON)
    {
        jab |= (joyabutton[cnt]<<cnt);
        jbb |= (joybbutton[cnt]<<cnt);
        cnt++;
    }


    // Mouse mask
    msb=(mousebutton[3]<<3)|(mousebutton[2]<<2)|(mousebutton[1]<<1)|(mousebutton[0]<<0);
}