Пример #1
0
void input_poll(void)
{
SDL_Event evt;
int32_t key;
int ino;//, key;
	
	while(SDL_PollEvent(&evt))
	{
		switch(evt.type)
		{
			case SDL_KEYDOWN:
			case SDL_KEYUP:
			{
				key = evt.key.keysym.sym;
				
				static uint8_t shiftstates = 0;
				extern bool freezeframe;
				
				if (console.IsVisible() && !IsNonConsoleKey(key))
				{
					if (key == SDLK_LSHIFT)
					{
						if (evt.type == SDL_KEYDOWN)
							shiftstates |= LEFTMASK;
						else
							shiftstates &= ~LEFTMASK;
					}
					else if (key == SDLK_RSHIFT)
					{
						if (evt.type == SDL_KEYDOWN)
							shiftstates |= RIGHTMASK;
						else
							shiftstates &= ~RIGHTMASK;
					}
					else
					{
						int ch = key;
						if (shiftstates != 0)
						{
							ch = toupper(ch);
							if (ch == '.') ch = '>';
							if (ch == '-') ch = '_';
							if (ch == '/') ch = '?';
							if (ch == '1') ch = '!';
						}
						
						if (evt.type == SDL_KEYDOWN)
							console.HandleKey(ch);
						else
							console.HandleKeyRelease(ch);
					}
				}
				else
				{
					ino = input_get_action(key);//mappings[key];
					
					if (ino != -1)
						inputs[ino] = (evt.type == SDL_KEYDOWN);
					
					if (evt.type == SDL_KEYDOWN)
					{
						if (key == '`')		// bring up console
						{
							if (!freezeframe)
							{
								sound(SND_SWITCH_WEAPON);
								console.SetVisible(true);
							}
						}
						else
						{
							last_sdl_action.key = key;
						}
					}
				}
			}
			break;
			
			case SDL_QUIT:
			{
				inputs[ESCKEY] = true;
				game.running = false;
			}
			break;
			
			case SDL_JOYBUTTONDOWN:
			{
			    Uint8 but = evt.jbutton.button;
			    last_sdl_action.jbut = but;
			    ino = input_get_action_but(but);//mappings[key];
				if (ino != -1)
					inputs[ino] = (evt.jbutton.state == SDL_PRESSED);
			}
			break;

			case SDL_JOYBUTTONUP:
			{
			    Uint8 but = evt.jbutton.button;
			    ino = input_get_action_but(but);//mappings[key];
				if (ino != -1)
					inputs[ino] = (evt.jbutton.state == SDL_PRESSED);
			}
			break;
			
			case SDL_JOYHATMOTION:
			{
			    if (evt.jhat.value != SDL_HAT_CENTERED)
			    {
			        last_sdl_action.jhat = evt.jhat.hat;
			        last_sdl_action.jhat_value = evt.jhat.value;
			    }
			    ino = input_get_action_hat(evt.jhat.hat,evt.jhat.value);//mappings[key];
			    //cleanup all hat-binded states
			    for (int i=0;i<INPUT_COUNT;i++)
			    {
			        if (mappings[i].jhat!=-1)
			            inputs[i] = false;
			    }
			
				if (ino != -1)
					inputs[ino] = true;
			}
			break;

			case SDL_JOYAXISMOTION:
			{
			    if (evt.jaxis.value > 20000 || evt.jaxis.value < -20000) //dead zone
			    {
			        last_sdl_action.jaxis = evt.jaxis.axis;
			        last_sdl_action.jaxis_value = evt.jaxis.value;
			        ino = input_get_action_axis(evt.jaxis.axis,evt.jaxis.value);//mappings[key];
			        for (int i=0;i<INPUT_COUNT;i++)
			        {
			            if (mappings[i].jaxis!=-1)
			                inputs[i] = false;
			        }
			
				    if (ino != -1)
					    inputs[ino] = true;
			    }
			}
			break;

		}
	}
}
Пример #2
0
void input_poll(void)
{
SDL_Event evt;
int ino, key;
	
	while(SDL_PollEvent(&evt))
	{
		switch(evt.type)
		{
			case SDL_KEYDOWN:
			case SDL_KEYUP:
			{
				key = evt.key.keysym.sym;
				
				#ifndef __SDLSHIM__
				static uint8_t shiftstates = 0;
				extern bool freezeframe;
				
				if (console.IsVisible() && !IsNonConsoleKey(key))
				{
					if (key == SDLK_LSHIFT)
					{
						if (evt.type == SDL_KEYDOWN)
							shiftstates |= LEFTMASK;
						else
							shiftstates &= ~LEFTMASK;
					}
					else if (key == SDLK_RSHIFT)
					{
						if (evt.type == SDL_KEYDOWN)
							shiftstates |= RIGHTMASK;
						else
							shiftstates &= ~RIGHTMASK;
					}
					else
					{
						int ch = key;
						if (shiftstates != 0)
						{
							ch = toupper(ch);
							if (ch == '.') ch = '>';
							if (ch == '-') ch = '_';
							if (ch == '/') ch = '?';
							if (ch == '1') ch = '!';
						}
						
						if (evt.type == SDL_KEYDOWN)
							console.HandleKey(ch);
						else
							console.HandleKeyRelease(ch);
					}
				}
				else
				#endif	// __SDLSHIM__
				{
					ino = mappings[key];
					if (ino != 0xff)
						inputs[ino] = (evt.type == SDL_KEYDOWN);
					
					if (evt.type == SDL_KEYDOWN)
					{
						if (Replay::IsPlaying() && ino <= LASTCONTROLKEY)
						{
							stat("user interrupt - stopping playback of replay");
							Replay::end_playback();
							memset(inputs, 0, sizeof(inputs));
							inputs[ino] = true;
						}
						
						#ifndef __SDLSHIM__
						if (key == '`')		// bring up console
						{
							if (!freezeframe)
							{
								sound(SND_SWITCH_WEAPON);
								console.SetVisible(true);
							}
						}
						else
						#endif
						{
							last_sdl_key = key;
						}
					}
				}
			}
			break;
			
			case SDL_QUIT:
			{
				inputs[ESCKEY] = true;
				game.running = false;
			}
			break;
		}
	}
}