hedgewars/hwengine.pas
changeset 3697 d5b30d6373fc
parent 3693 09892cdb8f95
child 3709 c7849b74748d
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    27 interface
    27 interface
    28 {$ELSE}
    28 {$ELSE}
    29 program hwengine;
    29 program hwengine;
    30 {$ENDIF}
    30 {$ENDIF}
    31 
    31 
    32 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uKeys, uSound, 
    32 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uKeys, uSound,
    33      uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, sysutils;
    33      uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, sysutils;
    34      
    34 
    35 var isTerminated: boolean = false;
    35 var isTerminated: boolean = false;
    36     alsoShutdownFrontend: boolean = false;
    36     alsoShutdownFrontend: boolean = false;
    37 
    37 
    38 {$IFDEF HWLIBRARY}
    38 {$IFDEF HWLIBRARY}
    39 type arrayofpchar = array[0..9] of PChar;
    39 type arrayofpchar = array[0..9] of PChar;
   135     SDL_Quit();
   135     SDL_Quit();
   136     isTerminated:= false;
   136     isTerminated:= false;
   137 end;
   137 end;
   138 
   138 
   139 ///////////////////
   139 ///////////////////
   140 procedure MainLoop; 
   140 procedure MainLoop;
   141 var PrevTime, CurrTime: Longword;
   141 var PrevTime, CurrTime: Longword;
   142     event: TSDL_Event;
   142     event: TSDL_Event;
   143 begin
   143 begin
   144     PrevTime:= SDL_GetTicks;
   144     PrevTime:= SDL_GetTicks;
   145     while isTerminated = false do
   145     while isTerminated = false do
   179             CurrTime:= SDL_GetTicks;
   179             CurrTime:= SDL_GetTicks;
   180             if PrevTime + cTimerInterval <= CurrTime then
   180             if PrevTime + cTimerInterval <= CurrTime then
   181             begin
   181             begin
   182                 DoTimer(CurrTime - PrevTime);
   182                 DoTimer(CurrTime - PrevTime);
   183                 PrevTime:= CurrTime
   183                 PrevTime:= CurrTime
   184             end 
   184             end
   185             else SDL_Delay(1);
   185             else SDL_Delay(1);
   186             IPCCheckSock();
   186             IPCCheckSock();
   187         end;
   187         end;
   188     end;
   188     end;
   189 end;
   189 end;
   227     cLocaleFName:= gameArgs[4];
   227     cLocaleFName:= gameArgs[4];
   228     cAltDamage:= gameArgs[5] = '1';
   228     cAltDamage:= gameArgs[5] = '1';
   229     val(gameArgs[6], cScreenHeight);
   229     val(gameArgs[6], cScreenHeight);
   230     val(gameArgs[7], cScreenWidth);
   230     val(gameArgs[7], cScreenWidth);
   231     recordFileName:= gameArgs[8];
   231     recordFileName:= gameArgs[8];
   232     
   232 
   233     val(gameArgs[9], cReducedQuality);
   233     val(gameArgs[9], cReducedQuality);
   234 {$ENDIF}
   234 {$ENDIF}
   235 
   235 
   236     initEverything(true);
   236     initEverything(true);
   237     WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
   237     WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
   241         AddFileLog(inttostr(i) + ': ' + ParamStr(i));
   241         AddFileLog(inttostr(i) + ': ' + ParamStr(i));
   242 {$ENDIF}
   242 {$ENDIF}
   243 
   243 
   244     for p:= Succ(Low(TPathType)) to High(TPathType) do
   244     for p:= Succ(Low(TPathType)) to High(TPathType) do
   245         if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p];
   245         if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p];
   246         
   246 
   247     WriteToConsole('Init SDL... ');
   247     WriteToConsole('Init SDL... ');
   248     SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true);
   248     SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true);
   249     WriteLnToConsole(msgOK);
   249     WriteLnToConsole(msgOK);
   250 
   250 
   251     SDL_EnableUNICODE(1);
   251     SDL_EnableUNICODE(1);
   274 
   274 
   275     LoadLocale(Pathz[ptLocale] + '/en.txt');  // Do an initial load with english
   275     LoadLocale(Pathz[ptLocale] + '/en.txt');  // Do an initial load with english
   276     if cLocaleFName <> 'en.txt' then
   276     if cLocaleFName <> 'en.txt' then
   277     begin
   277     begin
   278         // Try two letter locale first before trying specific locale overrides
   278         // Try two letter locale first before trying specific locale overrides
   279         if (Length(cLocaleFName) > 6) and (Copy(cLocaleFName,1,2)+'.txt' <> 'en.txt') then 
   279         if (Length(cLocaleFName) > 6) and (Copy(cLocaleFName,1,2)+'.txt' <> 'en.txt') then
   280             LoadLocale(Pathz[ptLocale] + '/' + Copy(cLocaleFName,1,2)+'.txt');
   280             LoadLocale(Pathz[ptLocale] + '/' + Copy(cLocaleFName,1,2)+'.txt');
   281         LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName);
   281         LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName);
   282     end;
   282     end;
   283 
   283 
   284     if recordFileName = '' then
   284     if recordFileName = '' then
   319     uMisc.initModule;
   319     uMisc.initModule;
   320     uConsole.initModule;    // MUST happen after uMisc
   320     uConsole.initModule;    // MUST happen after uMisc
   321 
   321 
   322     uLand.initModule;
   322     uLand.initModule;
   323     uIO.initModule;
   323     uIO.initModule;
   324     
   324 
   325     if complete then
   325     if complete then
   326     begin
   326     begin
   327         uAI.initModule;
   327         uAI.initModule;
   328         //uAIActions does not need initialization
   328         //uAIActions does not need initialization
   329         //uAIAmmoTests does not need initialization
   329         //uAIAmmoTests does not need initialization
   338         //uLandGraphics does not need initialization
   338         //uLandGraphics does not need initialization
   339         //uLandObjects does not need initialization
   339         //uLandObjects does not need initialization
   340         //uLandTemplates does not need initialization
   340         //uLandTemplates does not need initialization
   341         uLandTexture.initModule;
   341         uLandTexture.initModule;
   342         //uLocale does not need initialization
   342         //uLocale does not need initialization
   343         uRandom.initModule; 
   343         uRandom.initModule;
   344         uScript.initModule;
   344         uScript.initModule;
   345         uSound.initModule;
   345         uSound.initModule;
   346         uStats.initModule;
   346         uStats.initModule;
   347         uStore.initModule;
   347         uStore.initModule;
   348         uTeams.initModule;
   348         uTeams.initModule;
   378         uAIMisc.freeModule;         //stub
   378         uAIMisc.freeModule;         //stub
   379         //uAIAmmoTests does not need to be freed
   379         //uAIAmmoTests does not need to be freed
   380         //uAIActions does not need to be freed
   380         //uAIActions does not need to be freed
   381         uAI.freeModule;             //stub
   381         uAI.freeModule;             //stub
   382     end;
   382     end;
   383     
   383 
   384     uIO.freeModule;             //stub
   384     uIO.freeModule;             //stub
   385     uLand.freeModule;
   385     uLand.freeModule;
   386 
   386 
   387     uConsole.freeModule;
   387     uConsole.freeModule;
   388     uMisc.freeModule;           // uMisc closes the debug log.
   388     uMisc.freeModule;           // uMisc closes the debug log.
   459     GetParams();
   459     GetParams();
   460 
   460 
   461     if GameType = gmtLandPreview then GenLandPreview()
   461     if GameType = gmtLandPreview then GenLandPreview()
   462     else if GameType = gmtSyntax then DisplayUsage()
   462     else if GameType = gmtSyntax then DisplayUsage()
   463     else Game();
   463     else Game();
   464     
   464 
   465     if GameType = gmtSyntax then
   465     if GameType = gmtSyntax then
   466         ExitCode:= 1
   466         ExitCode:= 1
   467     else
   467     else
   468         ExitCode:= 0;
   468         ExitCode:= 0;
   469 {$ENDIF}
   469 {$ENDIF}