hedgewars/hwengine.pas
changeset 3615 b78d7959540a
parent 3613 cfd3c6536a09
child 3617 1df21e06b8ba
equal deleted inserted replaced
3614:5806f8f614b7 3615:b78d7959540a
    27 interface
    27 interface
    28 {$ELSE}
    28 {$ELSE}
    29 program hwengine;
    29 program hwengine;
    30 {$ENDIF}
    30 {$ENDIF}
    31 
    31 
    32 uses
    32 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uKeys, uSound, 
    33     SDLh in 'SDLh.pas',
    33      uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, sysutils;
    34     uConsts in 'uConsts.pas',
    34      
    35     uGame in 'uGame.pas',
    35 type arrayofpchar = array[0..9] of PChar;
    36     uMisc in 'uMisc.pas',
       
    37     uStore in 'uStore.pas',
       
    38     uWorld in 'uWorld.pas',
       
    39     uIO in 'uIO.pas',
       
    40     uGears in 'uGears.pas',
       
    41     uVisualGears in 'uVisualGears.pas',
       
    42     uConsole in 'uConsole.pas',
       
    43     uKeys in 'uKeys.pas',
       
    44     uTeams in 'uTeams.pas',
       
    45     uSound in 'uSound.pas',
       
    46     uRandom in 'uRandom.pas',
       
    47     uAI in 'uAI.pas',
       
    48     uAIMisc in 'uAIMisc.pas',
       
    49 //  uAIAmmoTests in 'uAIAmmoTests.pas',
       
    50 //  uAIActions in 'uAIActions.pas',
       
    51     uCollisions in 'uCollisions.pas',
       
    52     uLand in 'uLand.pas',
       
    53 //  uLandTemplates in 'uLandTemplates.pas',
       
    54 //  uLandObjects in 'uLandObjects.pas',
       
    55 //  uLandGraphics in 'uLandGraphics.pas',
       
    56     uLocale in 'uLocale.pas',
       
    57     uAmmos in 'uAmmos.pas',
       
    58 //  uSHA in 'uSHA.pas',
       
    59 //  uFloat in 'uFloat.pas',
       
    60     uStats in 'uStats.pas',
       
    61     uChat in 'uChat.pas',
       
    62     uLandTexture in 'uLandTexture.pas',
       
    63     uScript in 'uScript.pas',
       
    64     sysutils;
       
    65 
       
    66 // also: GSHandlers.inc
       
    67 //       GearDrawing.inc
       
    68 //       CCHandlers.inc
       
    69 //       HHHandlers.inc
       
    70 //       SinTable.inc
       
    71 //       proto.inc
       
    72 
       
    73 var isTerminated: boolean = false;
    36 var isTerminated: boolean = false;
    74     alsoShutdownFrontend: boolean = false;
    37     alsoShutdownFrontend: boolean = false;
       
    38 
    75 {$IFDEF HWLIBRARY}
    39 {$IFDEF HWLIBRARY}
    76 type arrayofpchar = array[0..9] of PChar;
       
    77 
       
    78 procedure initEverything(complete:boolean);
    40 procedure initEverything(complete:boolean);
    79 procedure freeEverything(complete:boolean);
    41 procedure freeEverything(complete:boolean);
    80 
    42 
    81 implementation
    43 implementation
    82 {$ELSE}
    44 {$ELSE}
   161 
   123 
   162 ////////////////////
   124 ////////////////////
   163 procedure OnDestroy;
   125 procedure OnDestroy;
   164 begin
   126 begin
   165     WriteLnToConsole('Freeing resources...');
   127     WriteLnToConsole('Freeing resources...');
   166     if isSoundEnabled then ReleaseSound();
       
   167     FreeActionsList();
       
   168     StoreRelease();
   128     StoreRelease();
   169     FreeGearsList();
       
   170     FreeVisualGears();
       
   171     FreeLand();
       
   172     ControllerClose();
   129     ControllerClose();
   173     SendKB();
   130     SendKB();
   174     CloseIPC();
   131     CloseIPC();
   175     TTF_Quit();
   132     TTF_Quit();
   176 {$IFDEF SDL13}
   133 {$IFDEF SDL13}
   202                 SDL_ACTIVEEVENT:
   159                 SDL_ACTIVEEVENT:
   203                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
   160                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
   204                         cHasFocus:= event.active.gain = 1;
   161                         cHasFocus:= event.active.gain = 1;
   205 {$ENDIF}
   162 {$ENDIF}
   206 {$IFNDEF IPHONEOS}
   163 {$IFNDEF IPHONEOS}
   207                 //SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450));
       
   208                 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
   164                 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
   209                 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true;
   165                 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true;
   210 {$ENDIF}
   166 {$ENDIF}
   211                 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
   167                 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
   212                 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
   168                 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
   317         InitIPC;
   273         InitIPC;
   318     WriteLnToConsole(msgGettingConfig);
   274     WriteLnToConsole(msgGettingConfig);
   319 
   275 
   320     LoadLocale(Pathz[ptLocale] + '/en.txt');  // Do an initial load with english
   276     LoadLocale(Pathz[ptLocale] + '/en.txt');  // Do an initial load with english
   321     if cLocaleFName <> 'en.txt' then
   277     if cLocaleFName <> 'en.txt' then
   322         begin
   278     begin
   323         // Try two letter locale first before trying specific locale overrides
   279         // Try two letter locale first before trying specific locale overrides
   324         if (Length(cLocaleFName) > 6) and (Copy(cLocaleFName,1,2)+'.txt' <> 'en.txt') then 
   280         if (Length(cLocaleFName) > 6) and (Copy(cLocaleFName,1,2)+'.txt' <> 'en.txt') then 
   325             LoadLocale(Pathz[ptLocale] + '/' + Copy(cLocaleFName,1,2)+'.txt');
   281             LoadLocale(Pathz[ptLocale] + '/' + Copy(cLocaleFName,1,2)+'.txt');
   326         LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName);
   282         LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName);
   327         end;
   283     end;
   328 
   284 
   329     if recordFileName = '' then
   285     if recordFileName = '' then
   330         SendIPCAndWaitReply('C')        // ask for game config
   286         SendIPCAndWaitReply('C')        // ask for game config
   331     else
   287     else
   332         LoadRecordFromFile(recordFileName);
   288         LoadRecordFromFile(recordFileName);
   347     TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   303     TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   348 
   304 
   349     ParseCommand('rotmask', true);
   305     ParseCommand('rotmask', true);
   350 
   306 
   351     MainLoop();
   307     MainLoop();
       
   308     // clean up SDL and GL context
   352     OnDestroy();
   309     OnDestroy();
       
   310     // clean up all the other memory allocated
   353     freeEverything(true);
   311     freeEverything(true);
   354     if alsoShutdownFrontend then halt;
   312     if alsoShutdownFrontend then halt;
   355 end;
   313 end;
   356 
   314 
   357 procedure initEverything (complete:boolean);
   315 procedure initEverything (complete:boolean);
   382         //uLandObjects does not need initialization
   340         //uLandObjects does not need initialization
   383         //uLandTemplates does not need initialization
   341         //uLandTemplates does not need initialization
   384         uLandTexture.initModule;
   342         uLandTexture.initModule;
   385         //uLocale does not need initialization
   343         //uLocale does not need initialization
   386         uRandom.initModule; 
   344         uRandom.initModule; 
   387         //uSHA is initialized internally
       
   388         uScript.initModule;
   345         uScript.initModule;
   389         uSound.initModule;
   346         uSound.initModule;
   390         uStats.initModule;
   347         uStats.initModule;
   391         uStore.initModule;
   348         uStore.initModule;
   392         uTeams.initModule;
   349         uTeams.initModule;
   398 procedure freeEverything (complete:boolean);
   355 procedure freeEverything (complete:boolean);
   399 begin
   356 begin
   400     if complete then
   357     if complete then
   401     begin
   358     begin
   402         uWorld.freeModule;
   359         uWorld.freeModule;
   403         uVisualGears.freeModule;    //stub
   360         uVisualGears.freeModule;
   404         uTeams.freeModule;
   361         uTeams.freeModule;
   405         uStore.freeModule;          //stub
   362         uStore.freeModule;          //stub
   406         uStats.freeModule;          //stub
   363         uStats.freeModule;          //stub
   407         uSound.freeModule;          //stub
   364         uSound.freeModule;
   408         uScript.freeModule;
   365         uScript.freeModule;
   409         //uSHA does not need to be freed
       
   410         uRandom.freeModule;         //stub
   366         uRandom.freeModule;         //stub
   411         //uLocale does not need to be freed
   367         //uLocale does not need to be freed
   412         //uLandTemplates does not need to be freed
   368         //uLandTemplates does not need to be freed
   413         uLandTexture.freeModule;
   369         uLandTexture.freeModule;
   414         //uLandObjects does not need to be freed
   370         //uLandObjects does not need to be freed
   421         uChat.freeModule;           //stub
   377         uChat.freeModule;           //stub
   422         uAmmos.freeModule;
   378         uAmmos.freeModule;
   423         uAIMisc.freeModule;         //stub
   379         uAIMisc.freeModule;         //stub
   424         //uAIAmmoTests does not need to be freed
   380         //uAIAmmoTests does not need to be freed
   425         //uAIActions does not need to be freed
   381         //uAIActions does not need to be freed
   426         uAI.freeModule;             //stub
   382         uAI.freeModule;
   427     end;
   383     end;
   428     
   384     
   429     uIO.freeModule;             //stub
   385     uIO.freeModule;             //stub
   430     uLand.freeModule;
   386     uLand.freeModule;
   431 
   387