2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 Lugaru is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 #include "openal_wrapper.h"
22 #include "SDL_thread.h"
27 int numdialogueboxes[max_dialogues];
28 int dialoguetype[max_dialogues];
29 int dialogueboxlocation[max_dialogues][max_dialoguelength];
30 float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
31 int dialogueboxsound[max_dialogues][max_dialoguelength];
32 char dialoguetext[max_dialogues][max_dialoguelength][128];
33 char dialoguename[max_dialogues][max_dialoguelength][64];
34 XYZ dialoguecamera[max_dialogues][max_dialoguelength];
35 XYZ participantlocation[max_dialogues][10];
36 int participantfocus[max_dialogues][max_dialoguelength];
37 int participantaction[max_dialogues][max_dialoguelength];
38 float participantyaw[max_dialogues][10];
39 XYZ participantfacing[max_dialogues][max_dialoguelength][10];
40 float dialoguecamerayaw[max_dialogues][max_dialoguelength];
41 float dialoguecamerapitch[max_dialogues][max_dialoguelength];
46 int dialoguegonethrough[20];
48 const char *pathtypenames[] = {"keepwalking", "pause"};
49 const char *editortypenames[] = {
50 "active", "sitting", "sitting wall", "sleeping",
51 "dead1", "dead2", "dead3", "dead4"
56 Texture terraintexture;
57 Texture terraintexture2;
58 Texture loadscreentexture;
59 Texture Maparrowtexture;
60 Texture Mapboxtexture;
61 Texture Mapcircletexture;
62 Texture cursortexture;
63 GLuint screentexture = 0;
64 GLuint screentexture2 = 0;
65 Texture Mainmenuitems[10];
71 int newscreenwidth = 0;
72 int newscreenheight = 0;
79 int oldmousecoordh = 0;
80 int oldmousecoordv = 0;
83 SkyBox *skybox = NULL;
89 float hawkcalldelay = 0;
101 bool stealthloading = 0;
111 bool editorenabled = 0;
113 float editorsize = 0;
115 float editorpitch = 0;
120 int numpathpoints = 0;
121 int numpathpointconnect[30] = {};
122 int pathpointconnect[30][30] = {};
123 int pathpointselected = 0;
127 int numchallengelevels = 0;
129 bool console = false;
130 std::string consoletext[15] = {};
131 std::string displaytext[15] = {};
132 float displaytime[15] = {};
133 float displayblinkdelay = 0;
134 bool displayblink = 0;
135 unsigned displayselected = 0;
136 float consoleblinkdelay = 0;
137 bool consoleblink = 0;
138 unsigned consoleselected = 0;
140 unsigned short crouchkey = 0, jumpkey = 0, forwardkey = 0, backkey = 0, leftkey = 0, rightkey = 0, drawkey = 0, throwkey = 0, attackkey = 0;
141 unsigned short consolekey = 0;
145 int oldenvironment = 0;
147 float changedelay = 0;
149 bool waiting = false;
150 Account* accountactive = NULL;
153 void Game::fireSound(int sound)
155 emit_sound_at(sound);
158 void Game::inputText(string& str, unsigned* charselected)
163 SDL_StartTextInput();
167 while (SDL_PollEvent(&evenement)) {
168 switch (evenement.type) {
169 case SDL_TEXTEDITING:
170 /* FIXME - We should handle this for complete input method support */
173 str.insert(*charselected, evenement.text.text);
174 (*charselected) += strlen(evenement.text.text);
177 if (evenement.key.keysym.sym == SDLK_ESCAPE) {
181 } else if (evenement.key.keysym.sym == SDLK_BACKSPACE) {
182 if ((*charselected) > 0) {
184 str.erase(*charselected, 1);
186 } else if (evenement.key.keysym.sym == SDLK_DELETE) {
187 if ((*charselected) < str.size()) {
188 str.erase(*charselected, 1);
190 } else if (evenement.key.keysym.sym == SDLK_HOME) {
192 } else if (evenement.key.keysym.sym == SDLK_END) {
193 (*charselected) = str.size();
194 } else if (evenement.key.keysym.sym == SDLK_LEFT) {
195 if ((*charselected) != 0)
197 } else if (evenement.key.keysym.sym == SDLK_RIGHT) {
198 if ((*charselected) < str.size())
200 } else if (evenement.key.keysym.sym == SDLK_RETURN) {
212 int setKeySelected_thread(void* data)
214 using namespace Game;
217 while (scancode == -1) {
218 SDL_WaitEvent(&evenement);
219 switch (evenement.type) {
221 scancode = evenement.key.keysym.scancode;
223 case SDL_MOUSEBUTTONDOWN:
224 scancode = SDL_NUM_SCANCODES + evenement.button.button;
230 if (scancode != SDL_SCANCODE_ESCAPE) {
234 forwardkey = scancode;
246 crouchkey = scancode;
258 attackkey = scancode;
261 consolekey = scancode;
273 void Game::setKeySelected()
276 printf("launch thread\n");
277 SDL_Thread* thread = SDL_CreateThread(setKeySelected_thread, NULL, NULL);
278 if ( thread == NULL ) {
279 fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());