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 int numdialogueboxes[max_dialogues];
29 int dialoguetype[max_dialogues];
30 int dialogueboxlocation[max_dialogues][max_dialoguelength];
31 float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
32 int dialogueboxsound[max_dialogues][max_dialoguelength];
33 char dialoguetext[max_dialogues][max_dialoguelength][128];
34 char dialoguename[max_dialogues][max_dialoguelength][64];
35 XYZ dialoguecamera[max_dialogues][max_dialoguelength];
36 XYZ participantlocation[max_dialogues][10];
37 int participantfocus[max_dialogues][max_dialoguelength];
38 int participantaction[max_dialogues][max_dialoguelength];
39 float participantyaw[max_dialogues][10];
40 XYZ participantfacing[max_dialogues][max_dialoguelength][10];
41 float dialoguecamerayaw[max_dialogues][max_dialoguelength];
42 float dialoguecamerapitch[max_dialogues][max_dialoguelength];
47 int dialoguegonethrough[20];
49 const char *pathtypenames[] = {"keepwalking", "pause"};
50 const char *editortypenames[] = {
51 "active", "sitting", "sitting wall", "sleeping",
52 "dead1", "dead2", "dead3", "dead4"
57 Texture terraintexture;
58 Texture terraintexture2;
59 Texture loadscreentexture;
60 Texture Maparrowtexture;
61 Texture Mapboxtexture;
62 Texture Mapcircletexture;
63 Texture cursortexture;
64 GLuint screentexture = 0;
65 GLuint screentexture2 = 0;
66 Texture Mainmenuitems[10];
72 int newscreenwidth = 0;
73 int newscreenheight = 0;
80 int oldmousecoordh = 0;
81 int oldmousecoordv = 0;
84 SkyBox *skybox = NULL;
90 float hawkcalldelay = 0;
102 bool stealthloading = 0;
112 bool editorenabled = 0;
114 float editorsize = 0;
116 float editorpitch = 0;
121 int numpathpoints = 0;
122 int numpathpointconnect[30] = {};
123 int pathpointconnect[30][30] = {};
124 int pathpointselected = 0;
128 int numchallengelevels = 0;
130 bool console = false;
131 std::string consoletext[15] = {};
132 std::string displaytext[15] = {};
133 float displaytime[15] = {};
134 float displayblinkdelay = 0;
135 bool displayblink = 0;
136 unsigned displayselected = 0;
137 float consoleblinkdelay = 0;
138 bool consoleblink = 0;
139 unsigned consoleselected = 0;
141 unsigned short crouchkey = 0, jumpkey = 0, forwardkey = 0, backkey = 0, leftkey = 0, rightkey = 0, drawkey = 0, throwkey = 0, attackkey = 0;
142 unsigned short consolekey = 0;
146 int oldenvironment = 0;
148 float changedelay = 0;
150 bool waiting = false;
151 Account* accountactive = NULL;
154 void Game::fireSound(int sound)
156 emit_sound_at(sound);
159 void Game::inputText(string& str, unsigned* charselected)
164 SDL_StartTextInput();
168 while (SDL_PollEvent(&evenement)) {
169 if (!sdlEventProc(evenement)) {
173 switch (evenement.type) {
174 case SDL_TEXTEDITING:
175 /* FIXME - We should handle this for complete input method support */
178 str.insert(*charselected, evenement.text.text);
179 (*charselected) += strlen(evenement.text.text);
182 if (evenement.key.keysym.sym == SDLK_ESCAPE) {
186 } else if (evenement.key.keysym.sym == SDLK_BACKSPACE) {
187 if ((*charselected) > 0) {
189 str.erase(*charselected, 1);
191 } else if (evenement.key.keysym.sym == SDLK_DELETE) {
192 if ((*charselected) < str.size()) {
193 str.erase(*charselected, 1);
195 } else if (evenement.key.keysym.sym == SDLK_HOME) {
197 } else if (evenement.key.keysym.sym == SDLK_END) {
198 (*charselected) = str.size();
199 } else if (evenement.key.keysym.sym == SDLK_LEFT) {
200 if ((*charselected) != 0)
202 } else if (evenement.key.keysym.sym == SDLK_RIGHT) {
203 if ((*charselected) < str.size())
205 } else if (evenement.key.keysym.sym == SDLK_RETURN) {
217 int setKeySelected_thread(void* data)
219 using namespace Game;
222 while (scancode == -1) {
223 SDL_WaitEvent(&evenement);
224 switch (evenement.type) {
226 scancode = evenement.key.keysym.scancode;
228 case SDL_MOUSEBUTTONDOWN:
229 scancode = SDL_NUM_SCANCODES + evenement.button.button;
235 if (scancode != SDL_SCANCODE_ESCAPE) {
239 forwardkey = scancode;
251 crouchkey = scancode;
263 attackkey = scancode;
266 consolekey = scancode;
278 void Game::setKeySelected()
281 printf("launch thread\n");
282 SDL_Thread* thread = SDL_CreateThread(setKeySelected_thread, NULL, NULL);
283 if ( thread == NULL ) {
284 fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());