87 RecountAllTeamsHealth; |
88 RecountAllTeamsHealth; |
88 GameState:= gsGame; |
89 GameState:= gsGame; |
89 end; |
90 end; |
90 gsConfirm, gsGame, gsChat: |
91 gsConfirm, gsGame, gsChat: |
91 begin |
92 begin |
|
93 // disable screenshot flash effect when about to make another screenshot |
|
94 if flagMakeCapture and (ScreenFade = sfFromWhite) then |
|
95 ScreenFade:= sfNone; |
92 if not cOnlyStats then |
96 if not cOnlyStats then |
93 // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible |
97 // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible |
94 DrawWorld(Lag); |
98 DrawWorld(Lag); |
95 DoGameTick(Lag); |
99 DoGameTick(Lag); |
96 if not cOnlyStats then ProcessVisualGears(Lag); |
100 if not cOnlyStats then ProcessVisualGears(Lag); |
125 // flash |
129 // flash |
126 playSound(sndShutter); |
130 playSound(sndShutter); |
127 ScreenFade:= sfFromWhite; |
131 ScreenFade:= sfFromWhite; |
128 ScreenFadeValue:= sfMax; |
132 ScreenFadeValue:= sfMax; |
129 ScreenFadeSpeed:= 5; |
133 ScreenFadeSpeed:= 5; |
130 |
134 |
131 if (not flagDumpLand and MakeScreenshot(s, 1, 0)) or |
135 if (not flagDumpLand and MakeScreenshot(s, 1, 0)) or |
132 (flagDumpLand and MakeScreenshot(s, 1, 1) and ((cReducedQuality and rqBlurryLand <> 0) or MakeScreenshot(s, 1, 2))) then |
136 (flagDumpLand and MakeScreenshot(s, 1, 1) and ((cReducedQuality and rqBlurryLand <> 0) or MakeScreenshot(s, 1, 2))) then |
133 WriteLnToConsole('Screenshot saved: ' + s) |
137 WriteLnToConsole('Screenshot saved: ' + s) |
134 else |
138 else |
135 begin |
139 begin |
143 procedure MainLoop; |
147 procedure MainLoop; |
144 var event: TSDL_Event; |
148 var event: TSDL_Event; |
145 PrevTime, CurrTime: LongWord; |
149 PrevTime, CurrTime: LongWord; |
146 isTerminated: boolean; |
150 isTerminated: boolean; |
147 previousGameState: TGameState; |
151 previousGameState: TGameState; |
|
152 wheelEvent: boolean; |
148 begin |
153 begin |
149 isTerminated:= false; |
154 isTerminated:= false; |
150 PrevTime:= SDL_GetTicks; |
155 PrevTime:= SDL_GetTicks; |
151 while isTerminated = false do |
156 while (not isTerminated) and allOK do |
152 begin |
157 begin |
|
158 wheelEvent:= false; |
153 SDL_PumpEvents(); |
159 SDL_PumpEvents(); |
154 |
160 |
155 while SDL_PeepEvents(@event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0 do |
161 while SDL_PeepEvents(@event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0 do |
156 begin |
162 begin |
157 case event.type_ of |
163 case event.type_ of |
175 |
181 |
176 SDL_MOUSEBUTTONUP: |
182 SDL_MOUSEBUTTONUP: |
177 if (GameState >= gsGame) then ProcessMouse(event.button, false); |
183 if (GameState >= gsGame) then ProcessMouse(event.button, false); |
178 |
184 |
179 SDL_MOUSEWHEEL: |
185 SDL_MOUSEWHEEL: |
|
186 begin |
|
187 wheelEvent:= true; |
180 ProcessMouseWheel(event.wheel.x, event.wheel.y); |
188 ProcessMouseWheel(event.wheel.x, event.wheel.y); |
181 |
189 end; |
182 SDL_TEXTINPUT: uChat.TextInput(event.text); |
190 |
|
191 SDL_TEXTINPUT: if GameState = gsChat then uChat.TextInput(event.text); |
183 |
192 |
184 SDL_WINDOWEVENT: |
193 SDL_WINDOWEVENT: |
185 if event.window.event = SDL_WINDOWEVENT_SHOWN then |
|
186 begin |
194 begin |
187 cHasFocus:= true; |
195 case event.window.event of |
188 onFocusStateChanged() |
196 SDL_WINDOWEVENT_FOCUS_GAINED: |
189 end |
197 begin |
190 else if event.window.event = SDL_WINDOWEVENT_MINIMIZED then |
198 cHasFocus:= true; |
191 begin |
199 onFocusStateChanged(); |
192 previousGameState:= GameState; |
200 end; |
193 GameState:= gsSuspend; |
201 SDL_WINDOWEVENT_FOCUS_LOST: |
194 end |
202 begin |
195 else if event.window.event = SDL_WINDOWEVENT_RESTORED then |
203 cHasFocus:= false; |
196 begin |
204 onFocusStateChanged(); |
197 GameState:= previousGameState; |
205 end; |
|
206 SDL_WINDOWEVENT_MINIMIZED: |
|
207 begin |
|
208 previousGameState:= GameState; |
|
209 GameState:= gsSuspend; |
|
210 end; |
|
211 SDL_WINDOWEVENT_RESTORED: |
|
212 begin |
|
213 GameState:= previousGameState; |
198 {$IFDEF ANDROID} |
214 {$IFDEF ANDROID} |
199 //This call is used to reinitialize the glcontext and reload the textures |
215 //This call is used to reinitialize the glcontext and reload the textures |
200 ParseCommand('fullscr '+intToStr(LongInt(cFullScreen)), true); |
216 ParseCommand('fullscr '+intToStr(LongInt(cFullScreen)), true); |
201 {$ENDIF} |
217 {$ENDIF} |
202 end |
218 end; |
203 else if event.window.event = SDL_WINDOWEVENT_RESIZED then |
219 SDL_WINDOWEVENT_RESIZED: |
204 begin |
220 begin |
205 cNewScreenWidth:= max(2 * (event.window.data1 div 2), cMinScreenWidth); |
221 cNewScreenWidth:= max(2 * (event.window.data1 div 2), cMinScreenWidth); |
206 cNewScreenHeight:= max(2 * (event.window.data2 div 2), cMinScreenHeight); |
222 cNewScreenHeight:= max(2 * (event.window.data2 div 2), cMinScreenHeight); |
207 cScreenResizeDelay:= RealTicks + 500{$IFDEF IPHONEOS}div 2{$ENDIF}; |
223 cScreenResizeDelay:= RealTicks + 500{$IFDEF IPHONEOS}div 2{$ENDIF}; |
|
224 end; |
|
225 end; // case closed |
208 end; |
226 end; |
|
227 |
209 {$IFDEF USE_TOUCH_INTERFACE} |
228 {$IFDEF USE_TOUCH_INTERFACE} |
210 SDL_FINGERMOTION: |
229 SDL_FINGERMOTION: |
211 onTouchMotion(event.tfinger.x, event.tfinger.y, event.tfinger.dx, event.tfinger.dy, event.tfinger.fingerId); |
230 onTouchMotion(event.tfinger.x, event.tfinger.y, event.tfinger.dx, event.tfinger.dy, event.tfinger.fingerId); |
212 |
231 |
213 SDL_FINGERDOWN: |
232 SDL_FINGERDOWN: |
226 ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
245 ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
227 SDL_QUITEV: |
246 SDL_QUITEV: |
228 isTerminated:= true |
247 isTerminated:= true |
229 end; //end case event.type_ of |
248 end; //end case event.type_ of |
230 end; //end while SDL_PollEvent(@event) <> 0 do |
249 end; //end while SDL_PollEvent(@event) <> 0 do |
|
250 |
|
251 if (not wheelEvent) then |
|
252 ResetMouseWheel(); |
231 |
253 |
232 if (CursorMovementX <> 0) or (CursorMovementY <> 0) then |
254 if (CursorMovementX <> 0) or (CursorMovementY <> 0) then |
233 handlePositionUpdate(CursorMovementX * cameraKeyboardSpeed, CursorMovementY * cameraKeyboardSpeed); |
255 handlePositionUpdate(CursorMovementX * cameraKeyboardSpeed, CursorMovementY * cameraKeyboardSpeed); |
234 |
256 |
235 if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks) and |
257 if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks) and |
294 StopVideoRecording(); |
316 StopVideoRecording(); |
295 end; |
317 end; |
296 {$ENDIF} |
318 {$ENDIF} |
297 |
319 |
298 /////////////////////////////////////////////////////////////////////////////// |
320 /////////////////////////////////////////////////////////////////////////////// |
299 procedure Game; |
321 procedure GameRoutine; |
300 //var p: TPathType; |
322 //var p: TPathType; |
301 var s: shortstring; |
323 var s: shortstring; |
302 i: LongInt; |
324 i: LongInt; |
303 begin |
325 begin |
304 initEverything(true); |
|
305 WriteLnToConsole('Hedgewars engine ' + cVersionString + '-r' + cRevisionString + |
326 WriteLnToConsole('Hedgewars engine ' + cVersionString + '-r' + cRevisionString + |
306 ' (' + cHashString + ') with protocol #' + inttostr(cNetProtoVersion)); |
327 ' (' + cHashString + ') with protocol #' + inttostr(cNetProtoVersion)); |
307 //AddFileLog('Prefix: "' + shortstring(PathPrefix) +'"'); |
328 //AddFileLog('Prefix: "' + shortstring(PathPrefix) +'"'); |
308 //AddFileLog('UserPrefix: "' + shortstring(UserPathPrefix) +'"'); |
329 //AddFileLog('UserPrefix: "' + shortstring(UserPathPrefix) +'"'); |
309 |
330 |
310 for i:= 0 to ParamCount do |
331 for i:= 0 to ParamCount do |
311 AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
332 AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
312 |
333 |
313 WriteToConsole('Init SDL... '); |
334 WriteToConsole('Init SDL... '); |
314 if not cOnlyStats then SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, 'SDL_Init', true); |
335 if not cOnlyStats then SDLCheck(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, 'SDL_Init', true); |
315 WriteLnToConsole(msgOK); |
336 WriteLnToConsole(msgOK); |
316 |
337 if not cOnlyStats then |
|
338 begin |
|
339 WriteToConsole('Init SDL_ttf... '); |
|
340 SDLCheck(TTF_Init() <> -1, 'TTF_Init', true); |
|
341 WriteLnToConsole(msgOK); |
|
342 end; |
|
343 |
|
344 if not allOK then exit; |
317 //SDL_StartTextInput(); |
345 //SDL_StartTextInput(); |
318 SDL_ShowCursor(0); |
346 SDL_ShowCursor(0); |
319 |
347 |
320 if not cOnlyStats then |
|
321 begin |
|
322 WriteToConsole('Init SDL_ttf... '); |
|
323 SDLTry(TTF_Init() <> -1, 'TTF_Init', true); |
|
324 WriteLnToConsole(msgOK); |
|
325 end; |
|
326 |
348 |
327 {$IFDEF USE_VIDEO_RECORDING} |
349 {$IFDEF USE_VIDEO_RECORDING} |
328 if GameType = gmtRecord then |
350 if GameType = gmtRecord then |
329 InitOffscreenOpenGL() |
351 InitOffscreenOpenGL() |
330 else |
352 else |
338 end; |
360 end; |
339 |
361 |
340 ControllerInit(); // has to happen before InitKbdKeyTable to map keys |
362 ControllerInit(); // has to happen before InitKbdKeyTable to map keys |
341 InitKbdKeyTable(); |
363 InitKbdKeyTable(); |
342 AddProgress(); |
364 AddProgress(); |
|
365 if not allOK then exit; |
343 |
366 |
344 LoadLocale(cPathz[ptLocale] + '/en.txt'); // Do an initial load with english |
367 LoadLocale(cPathz[ptLocale] + '/en.txt'); // Do an initial load with english |
345 if cLocaleFName <> 'en.txt' then |
368 if cLocaleFName <> 'en.txt' then |
346 begin |
369 begin |
347 // Try two letter locale first before trying specific locale overrides |
370 // Try two letter locale first before trying specific locale overrides |
380 SetSound(false); |
405 SetSound(false); |
381 |
406 |
382 InitSound(); |
407 InitSound(); |
383 |
408 |
384 isDeveloperMode:= false; |
409 isDeveloperMode:= false; |
385 TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
410 if checkFails(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true) then exit; |
386 //ParseCommand('rotmask', true); |
411 //ParseCommand('rotmask', true); |
|
412 if not allOK then exit; |
387 |
413 |
388 {$IFDEF USE_VIDEO_RECORDING} |
414 {$IFDEF USE_VIDEO_RECORDING} |
389 if GameType = gmtRecord then |
415 if GameType = gmtRecord then |
390 begin |
416 begin |
391 RecorderMainLoop(); |
417 RecorderMainLoop(); |
393 exit; |
419 exit; |
394 end; |
420 end; |
395 {$ENDIF} |
421 {$ENDIF} |
396 |
422 |
397 MainLoop; |
423 MainLoop; |
|
424 end; |
|
425 |
|
426 procedure Game; |
|
427 begin |
|
428 initEverything(true); |
|
429 GameRoutine; |
398 // clean up all the memory allocated |
430 // clean up all the memory allocated |
399 freeEverything(true); |
431 freeEverything(true); |
400 end; |
432 end; |
401 |
|
402 /////////////////////////////////////////////////////////////////////////////// |
433 /////////////////////////////////////////////////////////////////////////////// |
403 // preInitEverything - init variables that are going to be ovewritten by arguments |
434 // preInitEverything - init variables that are going to be ovewritten by arguments |
404 // initEverything - init variables only. Should be coupled by below |
435 // initEverything - init variables only. Should be coupled by below |
405 // freeEverything - free above. Pay attention to the init/free order! |
436 // freeEverything - free above. Pay attention to the init/free order! |
406 procedure preInitEverything; |
437 procedure preInitEverything; |
407 begin |
438 begin |
|
439 allOK:= true; |
408 Randomize(); |
440 Randomize(); |
409 |
441 |
410 uVariables.preInitModule; |
442 uVariables.preInitModule; |
411 uSound.preInitModule; |
443 uSound.preInitModule; |
412 end; |
444 end; |
500 var Preview: TPreviewAlpha; |
532 var Preview: TPreviewAlpha; |
501 {$ENDIF} |
533 {$ENDIF} |
502 begin |
534 begin |
503 initEverything(false); |
535 initEverything(false); |
504 |
536 |
505 IPCWaitPongEvent; |
537 if allOK then |
506 TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
538 begin |
507 |
539 IPCWaitPongEvent; |
508 ScriptOnPreviewInit; |
540 if checkFails(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true) then exit; |
509 {$IFDEF MOBILE} |
541 |
510 GenPreview(Preview); |
542 ScriptOnPreviewInit; |
511 {$ELSE} |
543 {$IFDEF MOBILE} |
512 GenPreviewAlpha(Preview); |
544 GenPreview(Preview); |
513 {$ENDIF} |
545 {$ELSE} |
514 WriteLnToConsole('Sending preview...'); |
546 GenPreviewAlpha(Preview); |
515 SendIPCRaw(@Preview, sizeof(Preview)); |
547 {$ENDIF} |
516 SendIPCRaw(@MaxHedgehogs, sizeof(byte)); |
548 WriteLnToConsole('Sending preview...'); |
517 WriteLnToConsole('Preview sent, disconnect'); |
549 SendIPCRaw(@Preview, sizeof(Preview)); |
|
550 SendIPCRaw(@MaxHedgehogs, sizeof(byte)); |
|
551 WriteLnToConsole('Preview sent, disconnect'); |
|
552 end; |
|
553 |
518 freeEverything(false); |
554 freeEverything(false); |
519 end; |
555 end; |
520 |
556 |
521 function EngineThread(p: pointer): Longint; cdecl; export; |
557 function EngineThread(p: pointer): Longint; cdecl; export; |
522 var e: TFLIBEvent; |
558 var e: TFLIBEvent; |