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 switch (evenement.type) {
170 case SDL_TEXTEDITING:
171 /* FIXME - We should handle this for complete input method support */
174 str.insert(*charselected, evenement.text.text);
175 (*charselected) += strlen(evenement.text.text);
178 if (evenement.key.keysym.sym == SDLK_ESCAPE) {
182 } else if (evenement.key.keysym.sym == SDLK_BACKSPACE) {
183 if ((*charselected) > 0) {
185 str.erase(*charselected, 1);
187 } else if (evenement.key.keysym.sym == SDLK_DELETE) {
188 if ((*charselected) < str.size()) {
189 str.erase(*charselected, 1);
191 } else if (evenement.key.keysym.sym == SDLK_HOME) {
193 } else if (evenement.key.keysym.sym == SDLK_END) {
194 (*charselected) = str.size();
195 } else if (evenement.key.keysym.sym == SDLK_LEFT) {
196 if ((*charselected) != 0)
198 } else if (evenement.key.keysym.sym == SDLK_RIGHT) {
199 if ((*charselected) < str.size())
201 } else if (evenement.key.keysym.sym == SDLK_RETURN) {
213 int setKeySelected_thread(void* data)
215 using namespace Game;
218 while (scancode == -1) {
219 SDL_WaitEvent(&evenement);
220 switch (evenement.type) {
222 scancode = evenement.key.keysym.scancode;
224 case SDL_MOUSEBUTTONDOWN:
225 scancode = SDL_NUM_SCANCODES + evenement.button.button;
231 if (scancode != SDL_SCANCODE_ESCAPE) {
235 forwardkey = scancode;
247 crouchkey = scancode;
259 attackkey = scancode;
262 consolekey = scancode;
274 void Game::setKeySelected()
277 printf("launch thread\n");
278 SDL_Thread* thread = SDL_CreateThread(setKeySelected_thread, NULL, NULL);
279 if ( thread == NULL ) {
280 fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());