152 /////////////////////////////////////////////////////////////////////////////// |
152 /////////////////////////////////////////////////////////////////////////////// |
153 procedure MainLoop; |
153 procedure MainLoop; |
154 var event: TSDL_Event; |
154 var event: TSDL_Event; |
155 PrevTime, CurrTime: LongWord; |
155 PrevTime, CurrTime: LongWord; |
156 isTerminated: boolean; |
156 isTerminated: boolean; |
157 {$IFDEF SDL2} |
|
158 previousGameState: TGameState; |
157 previousGameState: TGameState; |
159 {$ELSE} |
|
160 prevFocusState: boolean; |
|
161 {$ENDIF} |
|
162 begin |
158 begin |
163 isTerminated:= false; |
159 isTerminated:= false; |
164 PrevTime:= SDL_GetTicks; |
160 PrevTime:= SDL_GetTicks; |
165 while isTerminated = false do |
161 while isTerminated = false do |
166 begin |
162 begin |
167 SDL_PumpEvents(); |
163 SDL_PumpEvents(); |
168 |
164 |
169 while SDL_PeepEvents(@event, 1, SDL_GETEVENT, {$IFDEF SDL2}SDL_FIRSTEVENT, SDL_LASTEVENT{$ELSE}SDL_ALLEVENTS{$ENDIF}) > 0 do |
165 while SDL_PeepEvents(@event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0 do |
170 begin |
166 begin |
171 case event.type_ of |
167 case event.type_ of |
172 {$IFDEF SDL2} |
|
173 SDL_KEYDOWN: |
168 SDL_KEYDOWN: |
174 if GameState = gsChat then |
169 if GameState = gsChat then |
175 begin |
170 begin |
176 // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3 |
171 // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3 |
177 KeyPressChat(SDL_GetKeyFromScancode(event.key.keysym.sym), event.key.keysym.sym, event.key.keysym.modifier); |
172 KeyPressChat(event.key.keysym); |
178 end |
173 end |
179 else |
174 else |
180 if GameState >= gsGame then ProcessKey(event.key); |
175 if GameState >= gsGame then ProcessKey(event.key); |
181 SDL_KEYUP: |
176 SDL_KEYUP: |
182 if (GameState <> gsChat) and (GameState >= gsGame) then |
177 if (GameState <> gsChat) and (GameState >= gsGame) then |
183 ProcessKey(event.key); |
178 ProcessKey(event.key); |
|
179 |
|
180 SDL_MOUSEBUTTONDOWN: |
|
181 if GameState = gsConfirm then |
|
182 ParseCommand('quit', true) |
|
183 else |
|
184 if (GameState >= gsGame) then ProcessMouse(event.button, true); |
|
185 |
|
186 SDL_MOUSEBUTTONUP: |
|
187 if (GameState >= gsGame) then ProcessMouse(event.button, false); |
|
188 |
|
189 SDL_MOUSEWHEEL: |
|
190 ProcessMouseWheel(event.wheel.x, event.wheel.y); |
|
191 |
|
192 SDL_TEXTINPUT: uChat.TextInput(event.text); |
184 |
193 |
185 SDL_WINDOWEVENT: |
194 SDL_WINDOWEVENT: |
186 if event.window.event = SDL_WINDOWEVENT_SHOWN then |
195 if event.window.event = SDL_WINDOWEVENT_SHOWN then |
187 begin |
196 begin |
188 cHasFocus:= true; |
197 cHasFocus:= true; |
215 onTouchDown(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId); |
224 onTouchDown(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId); |
216 |
225 |
217 SDL_FINGERUP: |
226 SDL_FINGERUP: |
218 onTouchUp(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId); |
227 onTouchUp(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId); |
219 {$ENDIF} |
228 {$ENDIF} |
220 {$ELSE} |
|
221 SDL_KEYDOWN: |
|
222 if GameState = gsChat then |
|
223 KeyPressChat(event.key.keysym.unicode, event.key.keysym.sym, event.key.keysym.modifier) |
|
224 else |
|
225 if GameState >= gsGame then ProcessKey(event.key); |
|
226 SDL_KEYUP: |
|
227 if (GameState <> gsChat) and (GameState >= gsGame) then |
|
228 ProcessKey(event.key); |
|
229 |
|
230 SDL_MOUSEBUTTONDOWN: |
|
231 if GameState = gsConfirm then |
|
232 ParseCommand('quit', true) |
|
233 else |
|
234 if (GameState >= gsGame) then ProcessMouse(event.button, true); |
|
235 |
|
236 SDL_MOUSEBUTTONUP: |
|
237 if (GameState >= gsGame) then ProcessMouse(event.button, false); |
|
238 |
|
239 SDL_ACTIVEEVENT: |
|
240 if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
|
241 begin |
|
242 prevFocusState:= cHasFocus; |
|
243 cHasFocus:= event.active.gain = 1; |
|
244 if prevFocusState xor cHasFocus then |
|
245 onFocusStateChanged() |
|
246 end; |
|
247 |
|
248 SDL_VIDEORESIZE: |
|
249 begin |
|
250 // using lower values than cMinScreenWidth or cMinScreenHeight causes widget overlap and off-screen widget parts |
|
251 // Change by sheepluva: |
|
252 // Let's only use even numbers for custom width/height since I ran into scaling issues with odd width values. |
|
253 // Maybe just fixes the symptom not the actual cause(?), I'm too tired to find out :P |
|
254 cNewScreenWidth:= max(2 * (event.resize.w div 2), cMinScreenWidth); |
|
255 cNewScreenHeight:= max(2 * (event.resize.h div 2), cMinScreenHeight); |
|
256 cScreenResizeDelay:= RealTicks+500; |
|
257 end; |
|
258 {$ENDIF} |
|
259 SDL_JOYAXISMOTION: |
229 SDL_JOYAXISMOTION: |
260 ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
230 ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
261 SDL_JOYHATMOTION: |
231 SDL_JOYHATMOTION: |
262 ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
232 ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
263 SDL_JOYBUTTONDOWN: |
233 SDL_JOYBUTTONDOWN: |
349 |
319 |
350 for i:= 0 to ParamCount do |
320 for i:= 0 to ParamCount do |
351 AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
321 AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
352 |
322 |
353 WriteToConsole('Init SDL... '); |
323 WriteToConsole('Init SDL... '); |
354 if not cOnlyStats then SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, true); |
324 if not cOnlyStats then SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, 'SDL_Init', true); |
355 WriteLnToConsole(msgOK); |
325 WriteLnToConsole(msgOK); |
356 |
326 |
357 {$IFDEF SDL2} |
327 //SDL_StartTextInput(); |
358 SDL_StartTextInput(); |
|
359 {$ELSE} |
|
360 SDL_EnableUNICODE(1); |
|
361 {$ENDIF} |
|
362 SDL_ShowCursor(0); |
328 SDL_ShowCursor(0); |
363 |
329 |
364 if not cOnlyStats then |
330 if not cOnlyStats then |
365 begin |
331 begin |
366 WriteToConsole('Init SDL_ttf... '); |
332 WriteToConsole('Init SDL_ttf... '); |
367 SDLTry(TTF_Init() <> -1, true); |
333 SDLTry(TTF_Init() <> -1, 'TTF_Init', true); |
368 WriteLnToConsole(msgOK); |
334 WriteLnToConsole(msgOK); |
369 end; |
335 end; |
370 |
336 |
371 {$IFDEF USE_VIDEO_RECORDING} |
337 {$IFDEF USE_VIDEO_RECORDING} |
372 if GameType = gmtRecord then |
338 if GameType = gmtRecord then |