2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
22 #include "openal_wrapper.h"
23 #include "SDL_thread.h"
28 const char *pathtypenames[] = {"keepwalking", "pause"};
29 const char *editortypenames[] = {
30 "active", "sitting", "sitting wall", "sleeping",
31 "dead1", "dead2", "dead3", "dead4"
36 Texture terraintexture;
37 Texture terraintexture2;
38 Texture loadscreentexture;
39 Texture Maparrowtexture;
40 Texture Mapboxtexture;
41 Texture Mapcircletexture;
42 Texture cursortexture;
43 GLuint screentexture = 0;
44 GLuint screentexture2 = 0;
45 Texture Mainmenuitems[10];
51 int newscreenwidth = 0;
52 int newscreenheight = 0;
59 int oldmousecoordh = 0;
60 int oldmousecoordv = 0;
63 SkyBox *skybox = NULL;
69 float hawkcalldelay = 0;
81 bool stealthloading = 0;
91 bool editorenabled = 0;
95 float editorpitch = 0;
100 int numpathpoints = 0;
101 int numpathpointconnect[30] = {};
102 int pathpointconnect[30][30] = {};
103 int pathpointselected = 0;
107 int numchallengelevels = 0;
109 bool console = false;
110 std::string consoletext[15] = {};
111 std::string displaytext[15] = {};
112 float displaytime[15] = {};
113 float displayblinkdelay = 0;
114 bool displayblink = 0;
115 unsigned displayselected = 0;
116 float consoleblinkdelay = 0;
117 bool consoleblink = 0;
118 unsigned consoleselected = 0;
120 unsigned short crouchkey = 0, jumpkey = 0, forwardkey = 0, backkey = 0, leftkey = 0, rightkey = 0, drawkey = 0, throwkey = 0, attackkey = 0;
121 unsigned short consolekey = 0;
125 int oldenvironment = 0;
127 float changedelay = 0;
129 bool waiting = false;
130 Account* accountactive = NULL;
133 void Game::fireSound(int sound)
135 emit_sound_at(sound);
138 void Game::inputText(string& str, unsigned* charselected)
143 SDL_StartTextInput();
147 while (SDL_PollEvent(&evenement)) {
148 if (!sdlEventProc(evenement)) {
152 switch (evenement.type) {
153 case SDL_TEXTEDITING:
154 /* FIXME - We should handle this for complete input method support */
157 str.insert(*charselected, evenement.text.text);
158 (*charselected) += strlen(evenement.text.text);
161 if (evenement.key.keysym.sym == SDLK_ESCAPE) {
165 } else if (evenement.key.keysym.sym == SDLK_BACKSPACE) {
166 if ((*charselected) > 0) {
168 str.erase(*charselected, 1);
170 } else if (evenement.key.keysym.sym == SDLK_DELETE) {
171 if ((*charselected) < str.size()) {
172 str.erase(*charselected, 1);
174 } else if (evenement.key.keysym.sym == SDLK_HOME) {
176 } else if (evenement.key.keysym.sym == SDLK_END) {
177 (*charselected) = str.size();
178 } else if (evenement.key.keysym.sym == SDLK_LEFT) {
179 if ((*charselected) != 0)
181 } else if (evenement.key.keysym.sym == SDLK_RIGHT) {
182 if ((*charselected) < str.size())
184 } else if (evenement.key.keysym.sym == SDLK_RETURN) {
196 int setKeySelected_thread(void* data)
198 using namespace Game;
201 while (scancode == -1) {
202 SDL_WaitEvent(&evenement);
203 switch (evenement.type) {
205 scancode = evenement.key.keysym.scancode;
207 case SDL_MOUSEBUTTONDOWN:
208 scancode = SDL_NUM_SCANCODES + evenement.button.button;
214 if (scancode != SDL_SCANCODE_ESCAPE) {
218 forwardkey = scancode;
230 crouchkey = scancode;
242 attackkey = scancode;
245 consolekey = scancode;
257 void Game::setKeySelected()
260 printf("launch thread\n");
261 SDL_Thread* thread = SDL_CreateThread(setKeySelected_thread, NULL, NULL);
262 if ( thread == NULL ) {
263 fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());