hedgewars/uStore.pas
branchqmlfrontend
changeset 12855 1b2b84315d27
parent 12844 22cc3d82905a
child 12876 b544bbbd0696
child 12895 c77d75dafe2e
child 12920 21827fc9ca98
equal deleted inserted replaced
11843:01f88c3b7b66 12855:1b2b84315d27
    24 uses SysUtils, uConsts, SDLh, GLunit, uTypes, uLandTexture, uCaptions, uChat;
    24 uses SysUtils, uConsts, SDLh, GLunit, uTypes, uLandTexture, uCaptions, uChat;
    25 
    25 
    26 procedure initModule;
    26 procedure initModule;
    27 procedure freeModule;
    27 procedure freeModule;
    28 
    28 
       
    29 procedure LoadFonts();
    29 procedure StoreLoad(reload: boolean);
    30 procedure StoreLoad(reload: boolean);
    30 procedure StoreRelease(reload: boolean);
    31 procedure StoreRelease(reload: boolean);
    31 procedure RenderHealth(var Hedgehog: THedgehog);
    32 procedure RenderHealth(var Hedgehog: THedgehog);
    32 function makeHealthBarTexture(w, h, Color: Longword): PTexture;
    33 function makeHealthBarTexture(w, h, Color: Longword): PTexture;
    33 procedure AddProgress;
    34 procedure AddProgress;
    59 procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
    60 procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
    60 procedure SetSkyColor(r, g, b: real);
    61 procedure SetSkyColor(r, g, b: real);
    61 
    62 
    62 implementation
    63 implementation
    63 uses uMisc, uConsole, uVariables, uUtils, uTextures, uRender, uRenderUtils,
    64 uses uMisc, uConsole, uVariables, uUtils, uTextures, uRender, uRenderUtils,
    64      uCommands, uPhysFSLayer, uDebug
    65      uCommands, uPhysFSLayer, uDebug, adler32
    65     {$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF};
    66     {$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF};
    66 
    67 
    67 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    68 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    68 
    69 
    69 var 
    70 var 
    70     SDLwindow: PSDL_Window;
       
    71     SDLGLcontext: PSDL_GLContext;
       
    72     squaresize : LongInt;
    71     squaresize : LongInt;
    73     numsquares : LongInt;
    72     numsquares : LongInt;
    74     ProgrTex: PTexture;
    73     ProgrTex: PTexture;
       
    74     LoadingText: PTexture;
    75 
    75 
    76     prevHat: shortstring;
    76     prevHat: shortstring;
    77     tmpHatSurf: PSDL_Surface;
    77     tmpHatSurf: PSDL_Surface;
    78 
    78 
    79 const
    79 const
   148     rr.w:= w;
   148     rr.w:= w;
   149     rr.h:= h;
   149     rr.h:= h;
   150 
   150 
   151     texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RMask, GMask, BMask, AMask);
   151     texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RMask, GMask, BMask, AMask);
   152     if not checkFails(texsurf <> nil, errmsgCreateSurface, true) then
   152     if not checkFails(texsurf <> nil, errmsgCreateSurface, true) then
   153         checkFails(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
   153         checkFails(SDL_SetColorKey(texsurf, SDL_TRUE, 0) = 0, errmsgTransparentSet, true);
   154 
   154 
   155     if not allOK then exit(nil);
   155     if not allOK then exit(nil);
   156 
   156 
   157     DrawRoundRect(@rr, cWhiteColor, cNearBlackColor, texsurf, true);
   157     DrawRoundRect(@rr, cWhiteColor, cNearBlackColor, texsurf, true);
   158 
   158 
   197         r.y:= 0;
   197         r.y:= 0;
   198         r.w:= 32;
   198         r.w:= 32;
   199         r.h:= 32;
   199         r.h:= 32;
   200         texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask);
   200         texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask);
   201         if not checkFails(texsurf <> nil, errmsgCreateSurface, true) then
   201         if not checkFails(texsurf <> nil, errmsgCreateSurface, true) then
   202             checkFails(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
   202             checkFails(SDL_SetColorKey(texsurf, SDL_TRUE, 0) = 0, errmsgTransparentSet, true);
   203         if not allOK then exit;
   203         if not allOK then exit;
   204 
   204 
   205         r.w:= 26;
   205         r.w:= 26;
   206         r.h:= 19;
   206         r.h:= 19;
   207 
   207 
   340     if TeamsArray[t] <> nil then
   340     if TeamsArray[t] <> nil then
   341         with TeamsArray[t]^ do
   341         with TeamsArray[t]^ do
   342             begin
   342             begin
   343             if GraveName = '' then
   343             if GraveName = '' then
   344                 GraveName:= 'Statue';
   344                 GraveName:= 'Statue';
   345             texsurf:= LoadDataImageAltFile(ptGraves, GraveName, 'Statue', ifCritical or ifTransparent);
   345             texsurf:= LoadDataImageAltFile(ptGraves, GraveName, 'Statue', ifCritical or ifColorKey);
   346             GraveTex:= Surface2Tex(texsurf, false);
   346             GraveTex:= Surface2Tex(texsurf, false);
   347             SDL_FreeSurface(texsurf)
   347             SDL_FreeSurface(texsurf)
   348             end
   348             end
   349 end;
   349 end;
   350 
   350 
   351 procedure StoreLoad(reload: boolean);
   351 procedure LoadFonts();
   352 var s: shortstring;
   352 var s: shortstring;
   353     ii: TSprite;
       
   354     fi: THWFont;
   353     fi: THWFont;
   355     ai: TAmmoType;
   354 begin
   356     tmpsurf: PSDL_Surface;
   355 AddFileLog('LoadFonts();');
   357     i, imflags: LongInt;
   356 
   358 begin
   357 if (not cOnlyStats) then
   359 AddFileLog('StoreLoad()');
       
   360 
       
   361 if (not reload) and (not cOnlyStats) then
       
   362     for fi:= Low(THWFont) to High(THWFont) do
   358     for fi:= Low(THWFont) to High(THWFont) do
   363         with Fontz[fi] do
   359         with Fontz[fi] do
   364             begin
   360             begin
   365             s:= cPathz[ptFonts] + '/' + Name;
   361             s:= cPathz[ptFonts] + '/' + Name;
   366             WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... ');
   362             WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... ');
   367             Handle:= TTF_OpenFontRW(rwopsOpenRead(s), true, Height);
   363             Handle:= TTF_OpenFontRW(rwopsOpenRead(s), true, Height);
   368             if SDLCheck(Handle <> nil, 'TTF_OpenFontRW', true) then exit;
   364             if SDLCheck(Handle <> nil, 'TTF_OpenFontRW', true) then exit;
   369             TTF_SetFontStyle(Handle, style);
   365             TTF_SetFontStyle(Handle, style);
   370             WriteLnToConsole(msgOK)
   366             WriteLnToConsole(msgOK)
   371             end;
   367             end;
       
   368 end;
       
   369 
       
   370 procedure StoreLoad(reload: boolean);
       
   371 var ii: TSprite;
       
   372     ai: TAmmoType;
       
   373     tmpsurf, tmpoverlay: PSDL_Surface;
       
   374     i, y, imflags: LongInt;
       
   375 begin
       
   376 AddFileLog('StoreLoad()');
   372 
   377 
   373 if not cOnlyStats then
   378 if not cOnlyStats then
   374     begin
   379     begin
   375     MakeCrossHairs;
   380     MakeCrossHairs;
   376     LoadGraves;
   381     LoadGraves;
   401             begin
   406             begin
   402             if reload then
   407             if reload then
   403                 tmpsurf:= Surface
   408                 tmpsurf:= Surface
   404             else
   409             else
   405                 begin
   410                 begin
   406                 imflags := (ifAlpha or ifTransparent);
   411                 imflags := (ifAlpha or ifColorKey);
   407 
   412 
   408                 // these sprites are optional
   413                 // these sprites are optional
   409                 if not (ii in [sprHorizont, sprHorizontL, sprHorizontR, sprSky, sprSkyL, sprSkyR, sprChunk]) then // FIXME: hack
   414                 if critical then 
   410                     imflags := (imflags or ifCritical);
   415                     imflags := (imflags or ifCritical);
   411 
   416 
   412                 // load the image
   417                 // load the image
   413                 tmpsurf := LoadDataImageAltPath(Path, AltPath, FileName, imflags)
   418                 tmpsurf := LoadDataImageAltPath(Path, AltPath, FileName, imflags);
       
   419                 if (tmpsurf <> nil) and checkSum then
       
   420                     for y := 0 to tmpsurf^.h-1 do
       
   421                         syncedPixelDigest:= Adler32Update(syncedPixelDigest, @PByteArray(tmpsurf^.pixels)^[y*tmpsurf^.pitch], tmpsurf^.w*4)
   414                 end;
   422                 end;
   415 
   423 
   416             if tmpsurf <> nil then
   424             if tmpsurf <> nil then
   417                 begin
   425                 begin
   418                 if getImageDimensions then
   426                 if getImageDimensions then
   419                     begin
   427                     begin
   420                     imageWidth:= tmpsurf^.w;
   428                     imageWidth:= tmpsurf^.w;
   421                     imageHeight:= tmpsurf^.h
   429                     imageHeight:= tmpsurf^.h
   422                     end;
   430                     end;
   423                 if getDimensions then
   431                 if getDimensions then
       
   432                     if Height = -1 then //BlueWater
       
   433                         begin
       
   434                         Width:= tmpsurf^.w;
       
   435                         Height:= tmpsurf^.h div watFrames;
       
   436                         end
       
   437                     else if Height = -2 then //SDWater
       
   438                         begin
       
   439                         Width:= tmpsurf^.w;
       
   440                         Height:= tmpsurf^.h div watSDFrames;
       
   441                         end
       
   442                     else
       
   443                         begin
       
   444                         Width:= tmpsurf^.w;
       
   445                         Height:= tmpsurf^.h
       
   446                         end;
       
   447                 if (ii in [sprAMAmmos, sprAMAmmosBW]) then
   424                     begin
   448                     begin
   425                     Width:= tmpsurf^.w;
   449                     tmpoverlay := LoadDataImage(Path, copy(FileName, 1, length(FileName)-5), (imflags and (not ifCritical)));
   426                     Height:= tmpsurf^.h
   450                     if tmpoverlay <> nil then
       
   451                         begin
       
   452                         copyToXY(tmpoverlay, tmpsurf, 0, 0);
       
   453                         SDL_FreeSurface(tmpoverlay)
       
   454                         end
   427                     end;
   455                     end;
   428                 if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then
   456                 if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then
   429                     begin
   457                     begin
   430                     Texture:= Surface2Tex(tmpsurf, true);
   458                     Texture:= Surface2Tex(tmpsurf, true);
   431                     Texture^.Scale:= 2
   459                     Texture^.Scale:= 2
   460     WriteNames(fnt16);
   488     WriteNames(fnt16);
   461 
   489 
   462     if not reload then
   490     if not reload then
   463         AddProgress;
   491         AddProgress;
   464 
   492 
   465     tmpsurf:= LoadDataImage(ptGraphics, cHHFileName, ifAlpha or ifCritical or ifTransparent);
   493     tmpsurf:= LoadDataImage(ptGraphics, cHHFileName, ifAlpha or ifCritical or ifColorKey);
   466 
   494 
   467     HHTexture:= Surface2Tex(tmpsurf, false);
   495     HHTexture:= Surface2Tex(tmpsurf, false);
   468     SDL_FreeSurface(tmpsurf);
   496     SDL_FreeSurface(tmpsurf);
   469 
   497 
   470     InitHealth;
   498     InitHealth;
   632         exit;
   660         exit;
   633         end;
   661         end;
   634 
   662 
   635     tmpsurf:= doSurfaceConversion(tmpsurf);
   663     tmpsurf:= doSurfaceConversion(tmpsurf);
   636 
   664 
   637     if (imageFlags and ifTransparent) <> 0 then
   665     if (imageFlags and ifColorKey) <> 0 then
   638         if checkFails(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true) then exit;
   666         if checkFails(SDL_SetColorKey(tmpsurf, SDL_TRUE, 0) = 0, errmsgTransparentSet, true) then exit;
   639 
   667 
   640     WriteLnToConsole(msgOK + ' (' + inttostr(tmpsurf^.w) + 'x' + inttostr(tmpsurf^.h) + ')');
   668     WriteLnToConsole(msgOK + ' (' + inttostr(tmpsurf^.w) + 'x' + inttostr(tmpsurf^.h) + ')');
   641 
   669 
   642     LoadImage:= tmpsurf //Result
   670     LoadImage:= tmpsurf //Result
   643 end;
   671 end;
   768 begin
   796 begin
   769     if cOnlyStats then exit;
   797     if cOnlyStats then exit;
   770     if Step = 0 then
   798     if Step = 0 then
   771     begin
   799     begin
   772         WriteToConsole(msgLoading + 'progress sprite: ');
   800         WriteToConsole(msgLoading + 'progress sprite: ');
   773         texsurf:= LoadDataImage(ptGraphics, 'Progress', ifCritical or ifTransparent);
   801         texsurf:= LoadDataImage(ptGraphics, 'Progress', ifCritical or ifColorKey);
   774 
   802 
   775         ProgrTex:= Surface2Tex(texsurf, false);
   803         ProgrTex:= Surface2Tex(texsurf, false);
       
   804 
       
   805         LoadingText:= RenderStringTex(trmsg[sidLoading], $FFF39EE8, fntBig);
   776 
   806 
   777         squaresize:= texsurf^.w shr 1;
   807         squaresize:= texsurf^.w shr 1;
   778         numsquares:= texsurf^.h div squaresize;
   808         numsquares:= texsurf^.h div squaresize;
   779         SDL_FreeSurface(texsurf);
   809         SDL_FreeSurface(texsurf);
       
   810 
   780         {$IFNDEF PAS2C}
   811         {$IFNDEF PAS2C}
   781         with mobileRecord do
   812         with mobileRecord do
   782             if GameLoading <> nil then
   813             if GameLoading <> nil then
   783                 GameLoading();
   814                 GameLoading();
   784         {$ENDIF}
   815         {$ENDIF}
   795     r.y:= (Step mod numsquares) * squaresize;
   826     r.y:= (Step mod numsquares) * squaresize;
   796     r.w:= squaresize;
   827     r.w:= squaresize;
   797     r.h:= squaresize;
   828     r.h:= squaresize;
   798 
   829 
   799     DrawTextureFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex);
   830     DrawTextureFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex);
       
   831     DrawTexture( -LoadingText^.w div 2, (cScreenHeight - LoadingText^.h) shr 1 - (squaresize div 2) - (LoadingText^.h div 2) - 8, LoadingText);
   800 
   832 
   801     SwapBuffers;
   833     SwapBuffers;
   802 
   834 
   803     inc(Step);
   835     inc(Step);
   804 end;
   836 end;
   808     {$IFNDEF PAS2C}
   840     {$IFNDEF PAS2C}
   809     with mobileRecord do
   841     with mobileRecord do
   810         if GameLoaded <> nil then
   842         if GameLoaded <> nil then
   811             GameLoaded();
   843             GameLoaded();
   812     {$ENDIF}
   844     {$ENDIF}
   813     WriteLnToConsole('Freeing progress surface... ');
   845     WriteLnToConsole('Freeing progress textures... ');
   814     FreeAndNilTexture(ProgrTex);
   846     FreeAndNilTexture(ProgrTex);
       
   847     FreeAndNilTexture(LoadingText);
   815     Step:= 0
   848     Step:= 0
   816 end;
   849 end;
   817 
   850 
   818 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
   851 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
   819 var tmpsurf: PSDL_SURFACE;
   852 var tmpsurf: PSDL_SURFACE;
   926 
   959 
   927 r.x:= cFontBorder + 6;
   960 r.x:= cFontBorder + 6;
   928 r.y:= cFontBorder + 4;
   961 r.y:= cFontBorder + 4;
   929 r.w:= 32;
   962 r.w:= 32;
   930 r.h:= 32;
   963 r.h:= 32;
   931 SDL_FillRect(tmpsurf, @r, $ffffffff);
   964 SDL_FillRect(tmpsurf, @r, $ff000000);
   932 SDL_UpperBlit(iconsurf, iconrect, tmpsurf, @r);
   965 SDL_UpperBlit(iconsurf, iconrect, tmpsurf, @r);
   933 
   966 
   934 RenderHelpWindow:=  Surface2Tex(tmpsurf, true);
   967 RenderHelpWindow:=  Surface2Tex(tmpsurf, true);
   935 SDL_FreeSurface(tmpsurf)
   968 SDL_FreeSurface(tmpsurf)
   936 end;
   969 end;
   937 
   970 
   938 procedure RenderWeaponTooltip(atype: TAmmoType);
   971 procedure RenderWeaponTooltip(atype: TAmmoType);
   939 var r: TSDL_Rect;
   972 var r: TSDL_Rect;
   940     i: LongInt;
   973     i: LongInt;
       
   974     ammoname: ansistring;
       
   975     ammocap: ansistring;
       
   976     ammodesc: ansistring;
   941     extra: ansistring;
   977     extra: ansistring;
   942     extracolor: LongInt;
   978     extracolor: LongInt;
   943 begin
   979 begin
   944 // don't do anything if the window shouldn't be shown
   980 // don't do anything if the window shouldn't be shown
   945     if (cReducedQuality and rqTooltipsOff) <> 0 then
   981     if (cReducedQuality and rqTooltipsOff) <> 0 then
   962 extra:= _S'';
   998 extra:= _S'';
   963 extracolor:= 0;
   999 extracolor:= 0;
   964 
  1000 
   965 if (CurrentTeam <> nil) and (Ammoz[atype].SkipTurns >= CurrentTeam^.Clan^.TurnNumber) then // weapon or utility is not yet available
  1001 if (CurrentTeam <> nil) and (Ammoz[atype].SkipTurns >= CurrentTeam^.Clan^.TurnNumber) then // weapon or utility is not yet available
   966     begin
  1002     begin
   967     extra:= trmsg[sidNotYetAvailable];
  1003     if (atype = amTardis) and (suddenDeathDmg) then
       
  1004         extra:= trmsg[sidNotAvailableInSD]
       
  1005     else
       
  1006         extra:= trmsg[sidNotYetAvailable];
   968     extracolor:= LongInt($ffc77070);
  1007     extracolor:= LongInt($ffc77070);
   969     end
  1008     end
   970 else if (Ammoz[atype].Ammo.Propz and ammoprop_NoRoundEnd) <> 0 then // weapon or utility will not end your turn
  1009 else if (Ammoz[atype].Ammo.Propz and ammoprop_NoRoundEnd) <> 0 then // weapon or utility will not end your turn
   971     begin
  1010     begin
   972     extra:= trmsg[sidNoEndTurn];
  1011     extra:= trmsg[sidNoEndTurn];
   976     begin
  1015     begin
   977     extra:= _S'';
  1016     extra:= _S'';
   978     extracolor:= 0;
  1017     extracolor:= 0;
   979     end;
  1018     end;
   980 
  1019 
       
  1020 if length(trluaammo[Ammoz[atype].NameId]) > 0  then
       
  1021     ammoname := trluaammo[Ammoz[atype].NameId]
       
  1022 else
       
  1023     ammoname := trammo[Ammoz[atype].NameId];
       
  1024 
       
  1025 if length(trluaammoc[Ammoz[atype].NameId]) > 0 then
       
  1026     ammocap := trluaammoc[Ammoz[atype].NameId]
       
  1027 else
       
  1028     ammocap := trammoc[Ammoz[atype].NameId];
       
  1029 
       
  1030 if length(trluaammod[Ammoz[atype].NameId]) > 0 then
       
  1031     ammodesc := trluaammod[Ammoz[atype].NameId]
       
  1032 else
       
  1033     ammodesc := trammod[Ammoz[atype].NameId];
       
  1034 
       
  1035 if length(trluaammoa[Ammoz[atype].NameId]) > 0 then
       
  1036     ammodesc := ammodesc + '|' + trluaammoa[Ammoz[atype].NameId];
       
  1037 
   981 // render window and return the texture
  1038 // render window and return the texture
   982 WeaponTooltipTex:= RenderHelpWindow(trammo[Ammoz[atype].NameId], trammoc[Ammoz[atype].NameId], trammod[Ammoz[atype].NameId], extra, extracolor, SpritesData[sprAMAmmos].Surface, @r)
  1039 WeaponTooltipTex:= RenderHelpWindow(ammoname, ammocap, ammodesc, extra, extracolor, SpritesData[sprAMAmmos].Surface, @r)
   983 end;
  1040 end;
   984 
  1041 
   985 procedure ShowWeaponTooltip(x, y: LongInt);
  1042 procedure ShowWeaponTooltip(x, y: LongInt);
   986 begin
  1043 begin
   987 // draw the texture if it exists
  1044 // draw the texture if it exists
  1129     if reinit then
  1186     if reinit then
  1130         begin
  1187         begin
  1131         // clean the window from any previous content
  1188         // clean the window from any previous content
  1132         RenderClear();
  1189         RenderClear();
  1133         if SuddenDeathDmg then
  1190         if SuddenDeathDmg then
  1134             SetSkyColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255)
  1191             SetSkyColor(SDSkyColor.r * (SDTint.r/255) / 255, SDSkyColor.g * (SDTint.g/255) / 255, SDSkyColor.b * (SDTint.b/255) / 255)
  1135         else if ((cReducedQuality and rqNoBackground) = 0) then
  1192         else if ((cReducedQuality and rqNoBackground) = 0) then
  1136             SetSkyColor(SkyColor.r / 255, SkyColor.g / 255, SkyColor.b / 255)
  1193             SetSkyColor(SkyColor.r / 255, SkyColor.g / 255, SkyColor.b / 255)
  1137         else
  1194         else
  1138             SetSkyColor(RQSkyColor.r / 255, RQSkyColor.g / 255, RQSkyColor.b / 255);
  1195             SetSkyColor(RQSkyColor.r / 255, RQSkyColor.g / 255, RQSkyColor.b / 255);
  1139 
  1196