hedgewars/hwengine.pas
changeset 11512 bd9a2f1b0080
parent 11507 382f91348d91
child 11537 bf86c6cb9341
equal deleted inserted replaced
11511:24bef86e3f3a 11512:bd9a2f1b0080
   340 
   340 
   341     for i:= 0 to ParamCount do
   341     for i:= 0 to ParamCount do
   342         AddFileLog(inttostr(i) + ': ' + ParamStr(i));
   342         AddFileLog(inttostr(i) + ': ' + ParamStr(i));
   343 
   343 
   344     WriteToConsole('Init SDL... ');
   344     WriteToConsole('Init SDL... ');
   345     if not cOnlyStats then SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, 'SDL_Init', true);
   345     if not cOnlyStats then SDLCheck(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, 'SDL_Init', true);
   346     WriteLnToConsole(msgOK);
   346     WriteLnToConsole(msgOK);
   347 
   347     if not cOnlyStats then
       
   348         begin
       
   349         WriteToConsole('Init SDL_ttf... ');
       
   350         SDLCheck(TTF_Init() <> -1, 'TTF_Init', true);
       
   351         WriteLnToConsole(msgOK);
       
   352         end;
       
   353 
       
   354     if not allOK then
       
   355     begin
       
   356         freeEverything(true);
       
   357         exit
       
   358     end;
   348     //SDL_StartTextInput();
   359     //SDL_StartTextInput();
   349     SDL_ShowCursor(0);
   360     SDL_ShowCursor(0);
   350 
   361 
   351     if not cOnlyStats then
       
   352         begin
       
   353         WriteToConsole('Init SDL_ttf... ');
       
   354         SDLTry(TTF_Init() <> -1, 'TTF_Init', true);
       
   355         WriteLnToConsole(msgOK);
       
   356         end;
       
   357 
   362 
   358 {$IFDEF USE_VIDEO_RECORDING}
   363 {$IFDEF USE_VIDEO_RECORDING}
   359     if GameType = gmtRecord then
   364     if GameType = gmtRecord then
   360         InitOffscreenOpenGL()
   365         InitOffscreenOpenGL()
   361     else
   366     else
   399             end
   404             end
   400         else
   405         else
   401             LoadRecordFromFile(recordFileName);
   406             LoadRecordFromFile(recordFileName);
   402         end;
   407         end;
   403 
   408 
   404     ScriptOnGameInit;
   409     if allOK then
   405     s:= 'eproto ' + inttostr(cNetProtoVersion);
       
   406     SendIPCRaw(@s[0], Length(s) + 1); // send proto version
       
   407 
       
   408     InitTeams();
       
   409     AssignStores();
       
   410 
       
   411     if GameType = gmtRecord then
       
   412         SetSound(false);
       
   413 
       
   414     InitSound();
       
   415 
       
   416     isDeveloperMode:= false;
       
   417     TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
       
   418     //ParseCommand('rotmask', true);
       
   419 
       
   420 {$IFDEF USE_VIDEO_RECORDING}
       
   421     if GameType = gmtRecord then
       
   422     begin
   410     begin
   423         RecorderMainLoop();
   411         ScriptOnGameInit;
   424         freeEverything(true);
   412         s:= 'eproto ' + inttostr(cNetProtoVersion);
   425         exit;
   413         SendIPCRaw(@s[0], Length(s) + 1); // send proto version
       
   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;
   426     end;
   437     end;
   427 {$ENDIF}
       
   428 
       
   429     MainLoop;
       
   430     // clean up all the memory allocated
   438     // clean up all the memory allocated
   431     freeEverything(true);
   439     freeEverything(true);
   432 end;
   440 end;
   433 
   441 
   434 ///////////////////////////////////////////////////////////////////////////////
   442 ///////////////////////////////////////////////////////////////////////////////
   435 // preInitEverything - init variables that are going to be ovewritten by arguments
   443 // preInitEverything - init variables that are going to be ovewritten by arguments
   436 // initEverything - init variables only. Should be coupled by below
   444 // initEverything - init variables only. Should be coupled by below
   437 // freeEverything - free above. Pay attention to the init/free order!
   445 // freeEverything - free above. Pay attention to the init/free order!
   438 procedure preInitEverything;
   446 procedure preInitEverything;
   439 begin
   447 begin
       
   448     allOK:= true;
   440     Randomize();
   449     Randomize();
   441 
   450 
   442     uVariables.preInitModule;
   451     uVariables.preInitModule;
   443     uSound.preInitModule;
   452     uSound.preInitModule;
   444 end;
   453 end;
   535 {$ENDIF}
   544 {$ENDIF}
   536 begin
   545 begin
   537     initEverything(false);
   546     initEverything(false);
   538 
   547 
   539     InitIPC;
   548     InitIPC;
   540     IPCWaitPongEvent;
   549     if allOK then
   541     TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   550     begin
   542 
   551         IPCWaitPongEvent;
   543     ScriptOnPreviewInit;
   552         TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   544 {$IFDEF MOBILE}
   553 
   545     GenPreview(Preview);
   554         ScriptOnPreviewInit;
   546 {$ELSE}
   555     {$IFDEF MOBILE}
   547     GenPreviewAlpha(Preview);
   556         GenPreview(Preview);
   548 {$ENDIF}
   557     {$ELSE}
   549     WriteLnToConsole('Sending preview...');
   558         GenPreviewAlpha(Preview);
   550     SendIPCRaw(@Preview, sizeof(Preview));
   559     {$ENDIF}
   551     SendIPCRaw(@MaxHedgehogs, sizeof(byte));
   560         WriteLnToConsole('Sending preview...');
   552     WriteLnToConsole('Preview sent, disconnect');
   561         SendIPCRaw(@Preview, sizeof(Preview));
       
   562         SendIPCRaw(@MaxHedgehogs, sizeof(byte));
       
   563         WriteLnToConsole('Preview sent, disconnect');
       
   564     end;
       
   565 
   553     freeEverything(false);
   566     freeEverything(false);
   554 end;
   567 end;
   555 
   568 
   556 {$IFDEF HWLIBRARY}
   569 {$IFDEF HWLIBRARY}
   557 procedure RunEngine(argc: LongInt; argv: PPChar); cdecl; export;
   570 procedure RunEngine(argc: LongInt; argv: PPChar); cdecl; export;