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
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program 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.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "openal_wrapper.h"
24 #include "SDL_thread.h"
29 int numdialogueboxes[max_dialogues];
30 int dialoguetype[max_dialogues];
31 int dialogueboxlocation[max_dialogues][max_dialoguelength];
32 float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
33 int dialogueboxsound[max_dialogues][max_dialoguelength];
34 char dialoguetext[max_dialogues][max_dialoguelength][128];
35 char dialoguename[max_dialogues][max_dialoguelength][64];
36 XYZ dialoguecamera[max_dialogues][max_dialoguelength];
37 XYZ participantlocation[max_dialogues][10];
38 int participantfocus[max_dialogues][max_dialoguelength];
39 int participantaction[max_dialogues][max_dialoguelength];
40 float participantyaw[max_dialogues][10];
41 XYZ participantfacing[max_dialogues][max_dialoguelength][10];
42 float dialoguecamerayaw[max_dialogues][max_dialoguelength];
43 float dialoguecamerapitch[max_dialogues][max_dialoguelength];
48 int dialoguegonethrough[20];
50 const char *pathtypenames[] = {"keepwalking", "pause"};
51 const char *editortypenames[] = {
52 "active", "sitting", "sitting wall", "sleeping",
53 "dead1", "dead2", "dead3", "dead4"
58 Texture terraintexture;
59 Texture terraintexture2;
60 Texture loadscreentexture;
61 Texture Maparrowtexture;
62 Texture Mapboxtexture;
63 Texture Mapcircletexture;
64 Texture cursortexture;
65 GLuint screentexture = 0;
66 GLuint screentexture2 = 0;
67 Texture Mainmenuitems[10];
73 int newscreenwidth = 0;
74 int newscreenheight = 0;
81 int oldmousecoordh = 0;
82 int oldmousecoordv = 0;
85 SkyBox *skybox = NULL;
91 float hawkcalldelay = 0;
103 bool stealthloading = 0;
113 bool editorenabled = 0;
115 float editorsize = 0;
117 float editorpitch = 0;
122 int numpathpoints = 0;
123 int numpathpointconnect[30] = {};
124 int pathpointconnect[30][30] = {};
125 int pathpointselected = 0;
129 int numchallengelevels = 0;
131 bool console = false;
132 std::string consoletext[15] = {};
133 std::string displaytext[15] = {};
134 float displaytime[15] = {};
135 float displayblinkdelay = 0;
136 bool displayblink = 0;
137 int displayselected = 0;
138 float consoleblinkdelay = 0;
139 bool consoleblink = 0;
140 int consoleselected = 0;
142 unsigned short crouchkey = 0, jumpkey = 0, forwardkey = 0, backkey = 0, leftkey = 0, rightkey = 0, drawkey = 0, throwkey = 0, attackkey = 0;
143 unsigned short consolekey = 0;
147 int oldenvironment = 0;
149 float changedelay = 0;
151 bool waiting = false;
152 Account* accountactive = NULL;
155 void Game::fireSound(int sound)
157 emit_sound_at(sound);
160 void Game::inputText(string& str, int* charselected)
165 SDL_StartTextInput();
169 while (SDL_PollEvent(&evenement)) {
170 switch (evenement.type) {
171 case SDL_TEXTEDITING:
172 /* FIXME - We should handle this for complete input method support */
175 str.insert(*charselected, evenement.text.text);
176 (*charselected) += strlen(evenement.text.text);
179 if (evenement.key.keysym.sym == SDLK_ESCAPE) {
183 } else if (evenement.key.keysym.sym == SDLK_BACKSPACE) {
184 if ((*charselected) > 0) {
186 str.erase(*charselected, 1);
188 } else if (evenement.key.keysym.sym == SDLK_DELETE) {
189 if ((*charselected) < str.size()) {
190 str.erase(*charselected, 1);
192 } else if (evenement.key.keysym.sym == SDLK_HOME) {
194 } else if (evenement.key.keysym.sym == SDLK_END) {
195 (*charselected) = str.size();
196 } else if (evenement.key.keysym.sym == SDLK_LEFT) {
197 if ((*charselected) != 0)
199 } else if (evenement.key.keysym.sym == SDLK_RIGHT) {
200 if ((*charselected) < str.size())
202 } else if (evenement.key.keysym.sym == SDLK_RETURN) {
214 int setKeySelected_thread(void* data)
216 using namespace Game;
219 while (scancode == -1) {
220 SDL_WaitEvent(&evenement);
221 switch (evenement.type) {
223 scancode = evenement.key.keysym.scancode;
225 case SDL_MOUSEBUTTONDOWN:
226 scancode = SDL_NUM_SCANCODES + evenement.button.button;
232 if (scancode != SDL_SCANCODE_ESCAPE) {
236 forwardkey = scancode;
248 crouchkey = scancode;
260 attackkey = scancode;
263 consolekey = scancode;
275 void Game::setKeySelected()
278 printf("launch thread\n");
279 SDL_Thread* thread = SDL_CreateThread(setKeySelected_thread, NULL, NULL);
280 if ( thread == NULL ) {
281 fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());