138 // flash |
138 // flash |
139 playSound(sndShutter); |
139 playSound(sndShutter); |
140 ScreenFade:= sfFromWhite; |
140 ScreenFade:= sfFromWhite; |
141 ScreenFadeValue:= sfMax; |
141 ScreenFadeValue:= sfMax; |
142 ScreenFadeSpeed:= 5; |
142 ScreenFadeSpeed:= 5; |
143 |
143 |
144 if (not flagDumpLand and MakeScreenshot(s, 1, 0)) or |
144 if (not flagDumpLand and MakeScreenshot(s, 1, 0)) or |
145 (flagDumpLand and MakeScreenshot(s, 1, 1) and ((cReducedQuality and rqBlurryLand <> 0) or MakeScreenshot(s, 1, 2))) then |
145 (flagDumpLand and MakeScreenshot(s, 1, 1) and ((cReducedQuality and rqBlurryLand <> 0) or MakeScreenshot(s, 1, 2))) then |
146 WriteLnToConsole('Screenshot saved: ' + s) |
146 WriteLnToConsole('Screenshot saved: ' + s) |
147 else |
147 else |
148 begin |
148 begin |
160 previousGameState: TGameState; |
160 previousGameState: TGameState; |
161 wheelEvent: boolean; |
161 wheelEvent: boolean; |
162 begin |
162 begin |
163 isTerminated:= false; |
163 isTerminated:= false; |
164 PrevTime:= SDL_GetTicks; |
164 PrevTime:= SDL_GetTicks; |
165 while isTerminated = false do |
165 while (not isTerminated) and allOK do |
166 begin |
166 begin |
167 wheelEvent:= false; |
167 wheelEvent:= false; |
168 SDL_PumpEvents(); |
168 SDL_PumpEvents(); |
169 |
169 |
170 while SDL_PeepEvents(@event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0 do |
170 while SDL_PeepEvents(@event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0 do |
325 StopVideoRecording(); |
325 StopVideoRecording(); |
326 end; |
326 end; |
327 {$ENDIF} |
327 {$ENDIF} |
328 |
328 |
329 /////////////////////////////////////////////////////////////////////////////// |
329 /////////////////////////////////////////////////////////////////////////////// |
330 procedure Game; |
330 procedure GameRoutine; |
331 //var p: TPathType; |
331 //var p: TPathType; |
332 var s: shortstring; |
332 var s: shortstring; |
333 i: LongInt; |
333 i: LongInt; |
334 begin |
334 begin |
335 initEverything(true); |
|
336 WriteLnToConsole('Hedgewars engine ' + cVersionString + '-r' + cRevisionString + |
335 WriteLnToConsole('Hedgewars engine ' + cVersionString + '-r' + cRevisionString + |
337 ' (' + cHashString + ') with protocol #' + inttostr(cNetProtoVersion)); |
336 ' (' + cHashString + ') with protocol #' + inttostr(cNetProtoVersion)); |
338 AddFileLog('Prefix: "' + shortstring(PathPrefix) +'"'); |
337 AddFileLog('Prefix: "' + shortstring(PathPrefix) +'"'); |
339 AddFileLog('UserPrefix: "' + shortstring(UserPathPrefix) +'"'); |
338 AddFileLog('UserPrefix: "' + shortstring(UserPathPrefix) +'"'); |
340 |
339 |
349 WriteToConsole('Init SDL_ttf... '); |
348 WriteToConsole('Init SDL_ttf... '); |
350 SDLCheck(TTF_Init() <> -1, 'TTF_Init', true); |
349 SDLCheck(TTF_Init() <> -1, 'TTF_Init', true); |
351 WriteLnToConsole(msgOK); |
350 WriteLnToConsole(msgOK); |
352 end; |
351 end; |
353 |
352 |
354 if not allOK then |
353 if not allOK then exit; |
355 begin |
|
356 freeEverything(true); |
|
357 exit |
|
358 end; |
|
359 //SDL_StartTextInput(); |
354 //SDL_StartTextInput(); |
360 SDL_ShowCursor(0); |
355 SDL_ShowCursor(0); |
361 |
356 |
362 |
357 |
363 {$IFDEF USE_VIDEO_RECORDING} |
358 {$IFDEF USE_VIDEO_RECORDING} |
374 end; |
369 end; |
375 |
370 |
376 ControllerInit(); // has to happen before InitKbdKeyTable to map keys |
371 ControllerInit(); // has to happen before InitKbdKeyTable to map keys |
377 InitKbdKeyTable(); |
372 InitKbdKeyTable(); |
378 AddProgress(); |
373 AddProgress(); |
|
374 if not allOK then exit; |
379 |
375 |
380 LoadLocale(cPathz[ptLocale] + '/en.txt'); // Do an initial load with english |
376 LoadLocale(cPathz[ptLocale] + '/en.txt'); // Do an initial load with english |
381 if cLocaleFName <> 'en.txt' then |
377 if cLocaleFName <> 'en.txt' then |
382 begin |
378 begin |
383 // Try two letter locale first before trying specific locale overrides |
379 // Try two letter locale first before trying specific locale overrides |
387 end; |
383 end; |
388 LoadLocale(cPathz[ptLocale] + '/' + cLocaleFName) |
384 LoadLocale(cPathz[ptLocale] + '/' + cLocaleFName) |
389 end |
385 end |
390 else cLocale := 'en'; |
386 else cLocale := 'en'; |
391 |
387 |
|
388 if not allOK then exit; |
392 WriteLnToConsole(msgGettingConfig); |
389 WriteLnToConsole(msgGettingConfig); |
393 |
390 |
394 if cTestLua then |
391 if cTestLua then |
395 begin |
392 begin |
396 ParseCommand('script ' + cScriptName, true); |
393 ParseCommand('script ' + cScriptName, true); |
404 end |
401 end |
405 else |
402 else |
406 LoadRecordFromFile(recordFileName); |
403 LoadRecordFromFile(recordFileName); |
407 end; |
404 end; |
408 |
405 |
409 if allOK then |
406 if not allOK then exit; |
|
407 ScriptOnGameInit; |
|
408 s:= 'eproto ' + inttostr(cNetProtoVersion); |
|
409 SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
|
410 |
|
411 InitTeams(); |
|
412 AssignStores(); |
|
413 |
|
414 if GameType = gmtRecord then |
|
415 SetSound(false); |
|
416 |
|
417 InitSound(); |
|
418 |
|
419 isDeveloperMode:= false; |
|
420 if checkFails(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true) then exit; |
|
421 //ParseCommand('rotmask', true); |
|
422 if not allOK then exit; |
|
423 |
|
424 {$IFDEF USE_VIDEO_RECORDING} |
|
425 if GameType = gmtRecord then |
410 begin |
426 begin |
411 ScriptOnGameInit; |
427 RecorderMainLoop(); |
412 s:= 'eproto ' + inttostr(cNetProtoVersion); |
428 freeEverything(true); |
413 SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
429 exit; |
414 |
|
415 InitTeams(); |
|
416 AssignStores(); |
|
417 |
|
418 if GameType = gmtRecord then |
|
419 SetSound(false); |
|
420 |
|
421 InitSound(); |
|
422 |
|
423 isDeveloperMode:= false; |
|
424 TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
|
425 //ParseCommand('rotmask', true); |
|
426 |
|
427 {$IFDEF USE_VIDEO_RECORDING} |
|
428 if GameType = gmtRecord then |
|
429 begin |
|
430 RecorderMainLoop(); |
|
431 freeEverything(true); |
|
432 exit; |
|
433 end; |
|
434 {$ENDIF} |
|
435 |
|
436 MainLoop; |
|
437 end; |
430 end; |
|
431 {$ENDIF} |
|
432 |
|
433 MainLoop; |
|
434 end; |
|
435 |
|
436 procedure Game; |
|
437 begin |
|
438 initEverything(true); |
|
439 GameRoutine; |
438 // clean up all the memory allocated |
440 // clean up all the memory allocated |
439 freeEverything(true); |
441 freeEverything(true); |
440 end; |
442 end; |
441 |
|
442 /////////////////////////////////////////////////////////////////////////////// |
443 /////////////////////////////////////////////////////////////////////////////// |
443 // preInitEverything - init variables that are going to be ovewritten by arguments |
444 // preInitEverything - init variables that are going to be ovewritten by arguments |
444 // initEverything - init variables only. Should be coupled by below |
445 // initEverything - init variables only. Should be coupled by below |
445 // freeEverything - free above. Pay attention to the init/free order! |
446 // freeEverything - free above. Pay attention to the init/free order! |
446 procedure preInitEverything; |
447 procedure preInitEverything; |