hedgewars/hwengine.pas
changeset 5565 1a326ba319c9
parent 5562 8056d82b4d23
child 5577 272c82f82cee
child 5616 a96231121eac
equal deleted inserted replaced
5564:4f42009237df 5565:1a326ba319c9
   122 ////////////////////
   122 ////////////////////
   123 procedure OnDestroy;
   123 procedure OnDestroy;
   124 begin
   124 begin
   125     WriteLnToConsole('Freeing resources...');
   125     WriteLnToConsole('Freeing resources...');
   126     FreeActionsList();
   126     FreeActionsList();
   127     uVisualGears.freeModule;
       
   128     StoreRelease();
   127     StoreRelease();
   129     ControllerClose();
   128     ControllerClose();
   130     CloseIPC();
   129     CloseIPC();
   131     TTF_Quit();
   130     TTF_Quit();
   132 {$IFDEF SDL13}
   131 {$IFDEF SDL13}
   198             IPCCheckSock();
   197             IPCCheckSock();
   199         end;
   198         end;
   200     end;
   199     end;
   201 end;
   200 end;
   202 
   201 
   203 /////////////////////////
       
   204 procedure ShowMainWindow;
       
   205 begin
       
   206     if cFullScreen then ParseCommand('fullscr 1', true)
       
   207     else ParseCommand('fullscr 0', true);
       
   208     SDL_ShowCursor(0)
       
   209 end;
       
   210 
       
   211 ///////////////
   202 ///////////////
   212 {$IFDEF HWLIBRARY}
   203 {$IFDEF HWLIBRARY}
   213 procedure Game(gameArgs: PPChar); cdecl; export;
   204 procedure Game(gameArgs: PPChar); cdecl; export;
   214 {$ELSE}
   205 {$ELSE}
   215 procedure Game;
   206 procedure Game;
   237     val(gameArgs[9], rotationQt);
   228     val(gameArgs[9], rotationQt);
   238     recordFileName:= gameArgs[10];
   229     recordFileName:= gameArgs[10];
   239     cStereoMode:= smNone;
   230     cStereoMode:= smNone;
   240 {$ENDIF}
   231 {$ENDIF}
   241 
   232 
   242     cLogfileBase:= 'game';
       
   243     initEverything(true);
   233     initEverything(true);
   244 
   234 
   245     WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
   235     WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
   246     AddFileLog('Prefix: "' + PathPrefix +'"');
   236     AddFileLog('Prefix: "' + PathPrefix +'"');
   247     AddFileLog('UserPrefix: "' + UserPathPrefix +'"');
   237     AddFileLog('UserPrefix: "' + UserPathPrefix +'"');
   259     WriteToConsole('Init SDL... ');
   249     WriteToConsole('Init SDL... ');
   260     SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, true);
   250     SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, true);
   261     WriteLnToConsole(msgOK);
   251     WriteLnToConsole(msgOK);
   262 
   252 
   263     SDL_EnableUNICODE(1);
   253     SDL_EnableUNICODE(1);
       
   254     SDL_ShowCursor(0);
   264 
   255 
   265     WriteToConsole('Init SDL_ttf... ');
   256     WriteToConsole('Init SDL_ttf... ');
   266     SDLTry(TTF_Init() <> -1, true);
   257     SDLTry(TTF_Init() <> -1, true);
   267     WriteLnToConsole(msgOK);
   258     WriteLnToConsole(msgOK);
   268 
   259 
   269 {$IFDEF WIN32}
   260     // show main window
   270     s:= SDL_getenv('SDL_VIDEO_CENTERED');
   261     if cFullScreen then ParseCommand('fullscr 1', true)
   271     SDL_putenv('SDL_VIDEO_CENTERED=1');
   262     else ParseCommand('fullscr 0', true);
   272     ShowMainWindow();
       
   273     SDL_putenv(str2pchar('SDL_VIDEO_CENTERED=' + s));
       
   274 {$ELSE}
       
   275     ShowMainWindow();
       
   276 {$ENDIF}
       
   277 
   263 
   278     ControllerInit(); // has to happen before InitKbdKeyTable to map keys
   264     ControllerInit(); // has to happen before InitKbdKeyTable to map keys
   279     InitKbdKeyTable();
   265     InitKbdKeyTable();
   280     AddProgress();
   266     AddProgress();
   281 
   267 
   332 end;
   318 end;
   333 
   319 
   334 procedure initEverything (complete:boolean);
   320 procedure initEverything (complete:boolean);
   335 begin
   321 begin
   336     Randomize();
   322     Randomize();
       
   323 
       
   324     if complete then cLogfileBase:= 'game'
       
   325     else cLogfileBase:= 'preview';
   337 
   326 
   338     // uConsts does not need initialization as they are all consts
   327     // uConsts does not need initialization as they are all consts
   339     uUtils.initModule;
   328     uUtils.initModule;
   340     uMisc.initModule;
   329     uMisc.initModule;
   341     uVariables.initModule;
   330     uVariables.initModule;
   423 
   412 
   424 /////////////////////////
   413 /////////////////////////
   425 procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF};
   414 procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF};
   426 var Preview: TPreview;
   415 var Preview: TPreview;
   427 begin
   416 begin
   428     cLogfileBase:= 'preview';
       
   429     initEverything(false);
   417     initEverything(false);
   430 {$IFDEF HWLIBRARY}
   418 {$IFDEF HWLIBRARY}
   431     WriteLnToConsole('Preview connecting on port ' + inttostr(port));
   419     WriteLnToConsole('Preview connecting on port ' + inttostr(port));
   432     ipcPort:= port;
   420     ipcPort:= port;
   433 {$ENDIF}
   421 {$ENDIF}
   494 
   482 
   495     if GameType = gmtLandPreview then GenLandPreview()
   483     if GameType = gmtLandPreview then GenLandPreview()
   496     else if GameType = gmtSyntax then DisplayUsage()
   484     else if GameType = gmtSyntax then DisplayUsage()
   497     else Game();
   485     else Game();
   498 
   486 
   499     if GameType = gmtSyntax then
   487     // return 1 when engine is not called correctly
   500         ExitCode:= 1
   488     ExitCode:= LongInt(GameType = gmtSyntax);
   501     else
       
   502         ExitCode:= 0;
       
   503 {$ENDIF}
   489 {$ENDIF}
   504 end.
   490 end.