]> git.jsancho.org Git - lugaru.git/blob - Source/Game.cpp
Cleaned up console printing code, replaced global displaytext by local vars in Menu
[lugaru.git] / Source / Game.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
4
5 This file is part of Lugaru.
6
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.
11
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.
16
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/>.
19 */
20
21 #include "Game.hpp"
22
23 #include "Audio/openal_wrapper.hpp"
24 #include "Level/Dialog.hpp"
25
26 #include <SDL_thread.h>
27
28 extern int mainmenu;
29
30 const char *pathtypenames[] = {"keepwalking", "pause"};
31 const char *editortypenames[] = {
32     "active", "sitting", "sitting wall", "sleeping",
33     "dead1", "dead2", "dead3", "dead4"
34 };
35
36 namespace Game
37 {
38 Texture terraintexture;
39 Texture terraintexture2;
40 Texture loadscreentexture;
41 Texture Maparrowtexture;
42 Texture Mapboxtexture;
43 Texture Mapcircletexture;
44 Texture cursortexture;
45 GLuint screentexture = 0;
46 GLuint screentexture2 = 0;
47 Texture Mainmenuitems[10];
48
49 int selected = 0;
50 int keyselect = 0;
51
52 int newdetail = 0;
53 int newscreenwidth = 0;
54 int newscreenheight = 0;
55
56 bool gameon = 0;
57 float deltah = 0;
58 float deltav = 0;
59 int mousecoordh = 0;
60 int mousecoordv = 0;
61 int oldmousecoordh = 0;
62 int oldmousecoordv = 0;
63 float yaw = 0;
64 float pitch = 0;
65 SkyBox *skybox = NULL;
66 bool cameramode = 0;
67 bool firstload = 0;
68
69 Texture hawktexture;
70 float hawkyaw = 0;
71 float hawkcalldelay = 0;
72
73 float leveltime = 0;
74 float wonleveltime = 0;
75 float loadtime = 0;
76
77 Model hawk;
78 XYZ hawkcoords;
79 XYZ realhawkcoords;
80
81 Model eye;
82 Model iris;
83 Model cornea;
84
85 bool stealthloading = 0;
86
87 int musictype = 0;
88
89 XYZ mapcenter;
90 float mapradius = 0;
91
92 Text *text = NULL;
93 float fps = 0;
94
95 bool editorenabled = 0;
96 int editortype = 0;
97 float editorsize = 0;
98 float editoryaw = 0;
99 float editorpitch = 0;
100
101 int tryquit = 0;
102
103 XYZ pathpoint[30];
104 int numpathpoints = 0;
105 int numpathpointconnect[30] = {};
106 int pathpointconnect[30][30] = {};
107 int pathpointselected = 0;
108
109 int endgame = 0;
110 bool scoreadded = 0;
111 int numchallengelevels = 0;
112
113 bool console = false;
114 std::string consoletext[15] = {};
115 float consoleblinkdelay = 0;
116 bool consoleblink = 0;
117 unsigned consoleselected = 0;
118
119 unsigned short crouchkey = 0, jumpkey = 0, forwardkey = 0, backkey = 0, leftkey = 0, rightkey = 0, drawkey = 0, throwkey = 0, attackkey = 0;
120 unsigned short consolekey = 0;
121
122 int loading = 0;
123
124 int oldenvironment = 0;
125 int targetlevel = 0;
126 float changedelay = 0;
127
128 bool waiting = false;
129 }
130
131 void Game::fireSound(int sound)
132 {
133     emit_sound_at(sound);
134 }
135
136 void Game::inputText(string& str, unsigned* charselected)
137 {
138     SDL_Event evenement;
139
140     if (!waiting) {
141         SDL_StartTextInput();
142         waiting = true;
143     }
144
145     while (SDL_PollEvent(&evenement)) {
146         if (!sdlEventProc(evenement)) {
147             tryquit = 1;
148             break;
149         }
150         switch (evenement.type) {
151         case SDL_TEXTEDITING:
152             /* FIXME - We should handle this for complete input method support */
153             break;
154         case SDL_TEXTINPUT:
155             str.insert(*charselected, evenement.text.text);
156             (*charselected) += strlen(evenement.text.text);
157             break;
158         case SDL_KEYDOWN:
159             if (evenement.key.keysym.sym == SDLK_ESCAPE) {
160                 str.clear();
161                 *charselected = 0;
162                 waiting = false;
163             } else if (evenement.key.keysym.sym == SDLK_BACKSPACE) {
164                 if ((*charselected) > 0) {
165                     (*charselected)--;
166                     str.erase(*charselected, 1);
167                 }
168             } else if (evenement.key.keysym.sym == SDLK_DELETE) {
169                 if ((*charselected) < str.size()) {
170                     str.erase(*charselected, 1);
171                 }
172             } else if (evenement.key.keysym.sym == SDLK_HOME) {
173                 (*charselected) = 0;
174             } else if (evenement.key.keysym.sym == SDLK_END) {
175                 (*charselected) = str.size();
176             } else if (evenement.key.keysym.sym == SDLK_LEFT) {
177                 if ((*charselected) != 0)
178                     (*charselected)--;
179             } else if (evenement.key.keysym.sym == SDLK_RIGHT) {
180                 if ((*charselected) < str.size())
181                     (*charselected)++;
182             } else if (evenement.key.keysym.sym == SDLK_RETURN) {
183                 waiting = false;
184             }
185             break;
186         }
187     }
188
189     if (!waiting) {
190         SDL_StopTextInput();
191     }
192 }