]> git.jsancho.org Git - lugaru.git/blob - Source/Game.cpp
Added braces to all statements with clang-tidy and ran clang-format again
[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 firstLoadDone = false;
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 Text* textmono = NULL;
94 float fps = 0;
95
96 bool editorenabled = 0;
97 int editortype = 0;
98 float editorsize = 0;
99 float editoryaw = 0;
100 float editorpitch = 0;
101
102 int tryquit = 0;
103
104 XYZ pathpoint[30];
105 int numpathpoints = 0;
106 int numpathpointconnect[30] = {};
107 int pathpointconnect[30][30] = {};
108 int pathpointselected = 0;
109
110 int endgame = 0;
111 bool scoreadded = 0;
112 int numchallengelevels = 0;
113
114 bool console = false;
115 std::string consoletext[15] = {};
116 float consoleblinkdelay = 0;
117 bool consoleblink = 0;
118 unsigned consoleselected = 0;
119
120 unsigned short crouchkey = 0, jumpkey = 0, forwardkey = 0, backkey = 0, leftkey = 0, rightkey = 0, drawkey = 0, throwkey = 0, attackkey = 0;
121 unsigned short consolekey = 0;
122
123 int loading = 0;
124
125 int oldenvironment = 0;
126 int targetlevel = 0;
127 float changedelay = 0;
128
129 bool waiting = false;
130 }
131
132 void Game::fireSound(int sound)
133 {
134     emit_sound_at(sound);
135 }
136
137 void Game::inputText(string& str, unsigned* charselected)
138 {
139     SDL_Event evenement;
140
141     if (!waiting) {
142         SDL_StartTextInput();
143         waiting = true;
144     }
145
146     while (SDL_PollEvent(&evenement)) {
147         if (!sdlEventProc(evenement)) {
148             tryquit = 1;
149             break;
150         }
151         switch (evenement.type) {
152             case SDL_TEXTEDITING:
153                 /* FIXME - We should handle this for complete input method support */
154                 break;
155             case SDL_TEXTINPUT:
156                 str.insert(*charselected, evenement.text.text);
157                 (*charselected) += strlen(evenement.text.text);
158                 break;
159             case SDL_KEYDOWN:
160                 if (evenement.key.keysym.sym == SDLK_ESCAPE) {
161                     str.clear();
162                     *charselected = 0;
163                     waiting = false;
164                 } else if (evenement.key.keysym.sym == SDLK_BACKSPACE) {
165                     if ((*charselected) > 0) {
166                         (*charselected)--;
167                         str.erase(*charselected, 1);
168                     }
169                 } else if (evenement.key.keysym.sym == SDLK_DELETE) {
170                     if ((*charselected) < str.size()) {
171                         str.erase(*charselected, 1);
172                     }
173                 } else if (evenement.key.keysym.sym == SDLK_HOME) {
174                     (*charselected) = 0;
175                 } else if (evenement.key.keysym.sym == SDLK_END) {
176                     (*charselected) = str.size();
177                 } else if (evenement.key.keysym.sym == SDLK_LEFT) {
178                     if ((*charselected) != 0) {
179                         (*charselected)--;
180                     }
181                 } else if (evenement.key.keysym.sym == SDLK_RIGHT) {
182                     if ((*charselected) < str.size()) {
183                         (*charselected)++;
184                     }
185                 } else if (evenement.key.keysym.sym == SDLK_RETURN) {
186                     waiting = false;
187                 }
188                 break;
189         }
190     }
191
192     if (!waiting) {
193         SDL_StopTextInput();
194     }
195 }