Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: c46c66f61ee9a741b5d423d7f658bca129885a30 (plain)
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
/*
   input.cc
   This file is part of the Osirion project and is distributed under 
   the terms and conditions of the GNU General Public License version 2 
*/

//project headers
#include "client/client.h"

namespace client {

void Input::init()
{
	con_debug << "Initializing input..." << std::endl;

	//condebug << "SDL_DEFAULT_REPEAT_DELAY " << SDL_DEFAULT_REPEAT_DELAY <<  std::endl;
	//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,  SDL_DEFAULT_REPEAT_INTERVAL);
	SDL_EnableKeyRepeat(10,  SDL_DEFAULT_REPEAT_INTERVAL);
}

void Input::shutdown()
{
	con_debug << "Shutting down input..." << std::endl;
}

/* 
see
http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdlevent.html
*/

// handle key_release events for the game world
void Input::handle_keyreleased(SDL_keysym* keysym)
{
	switch( keysym->sym ) {
	case SDLK_SPACE:
		camera.nextmode();
		break;
	default:
		break;
	}
}

// handle pressed keys for the game world
void Input::handle_keypressed(SDL_keysym* keysym)
{
	switch( keysym->sym ) {
	case SDLK_LEFT:
		camera.rotate_left();
		break;
	case SDLK_RIGHT:
		camera.rotate_right();
		break;
	case SDLK_UP:
		camera.rotate_up();
		break;
	case SDLK_DOWN:
		camera.rotate_down();
		break;
	case SDLK_KP_PLUS:
		game.ship.set_thrust(game.ship.thrust() + 0.08f);
		break;
	case SDLK_KP_MINUS:	
		game.ship.set_thrust(game.ship.thrust() - 0.1f);
		break;
	case SDLK_KP4:
		game.ship.set_yaw(game.ship.yaw() + 10);
		break;
	case SDLK_KP6:
		game.ship.set_yaw(game.ship.yaw() - 10);
		break;
	default:
        	break;
	}

}

void Input::frame()
{
    SDL_Event event;

    while( SDL_PollEvent( &event ) ) {

        switch( event.type ) {
        case SDL_KEYDOWN:
		/*
		if (event.key.keysym.sym == SDLK_ESCAPE) {
			client::application.shutdown();
		} 
		*/
		if (core::connected() && !console.visible()) {
			// send key events to the game world
			handle_keypressed( &event.key.keysym );
		}
		break;

	case SDL_KEYUP:
		if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') {
			console.toggle();
		} else if (console.visible()) {
			// send key events to the console
			console.handle_keyreleased( &event.key.keysym );
		} else if (core::connected()) {
			// send key events to the game world
			handle_keyreleased( &event.key.keysym );
		}
		break;

        case SDL_QUIT:
            	client::application.shutdown();
            	break;
        }

    }

}

} // namespace client