hedgewars/uStore.pas
changeset 10262 435c82ab9058
parent 10260 25155aaede77
child 10266 a90a55ec5b98
equal deleted inserted replaced
10261:c81125782cf6 10262:435c82ab9058
    40 function  LoadDataImageAltPath(const path, altPath: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
    40 function  LoadDataImageAltPath(const path, altPath: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
    41 // like LoadDataImage but uses altFile as fallback-filename if file cannot be loaded
    41 // like LoadDataImage but uses altFile as fallback-filename if file cannot be loaded
    42 function  LoadDataImageAltFile(const path: TPathType; const filename, altFile: shortstring; imageFlags: LongInt): PSDL_Surface;
    42 function  LoadDataImageAltFile(const path: TPathType; const filename, altFile: shortstring; imageFlags: LongInt): PSDL_Surface;
    43 
    43 
    44 procedure LoadHedgehogHat(var HH: THedgehog; newHat: shortstring);
    44 procedure LoadHedgehogHat(var HH: THedgehog; newHat: shortstring);
       
    45 procedure LoadHedgehogHat2(var HH: THedgehog; newHat: shortstring; allowSurfReuse: boolean);
       
    46 
    45 procedure SetupOpenGL;
    47 procedure SetupOpenGL;
    46 procedure SetScale(f: GLfloat);
    48 procedure SetScale(f: GLfloat);
    47 function  RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
    49 function  RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
    48 procedure RenderWeaponTooltip(atype: TAmmoType);
    50 procedure RenderWeaponTooltip(atype: TAmmoType);
    49 procedure ShowWeaponTooltip(x, y: LongInt);
    51 procedure ShowWeaponTooltip(x, y: LongInt);
    93     shaderWater: GLuint;
    95     shaderWater: GLuint;
    94 
    96 
    95     // attributes
    97     // attributes
    96 {$ENDIF}
    98 {$ENDIF}
    97 
    99 
       
   100     prevHat: shortstring;
       
   101     tmpHatSurf: PSDL_Surface;
       
   102 
    98 const
   103 const
    99     cHHFileName = 'Hedgehog';
   104     cHHFileName = 'Hedgehog';
   100     cCHFileName = 'Crosshair';
   105     cCHFileName = 'Crosshair';
       
   106 
       
   107 procedure freeTmpHatSurf();
       
   108 begin
       
   109     if tmpHatSurf = nil then exit;
       
   110     SDL_FreeSurface(tmpHatSurf);
       
   111     tmpHatSurf:= nil;
       
   112     prevHat:= 'NoHat';
       
   113 end;
   101 
   114 
   102 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: PChar): TSDL_Rect;
   115 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: PChar): TSDL_Rect;
   103 var w, h: LongInt;
   116 var w, h: LongInt;
   104     tmpsurf: PSDL_Surface;
   117     tmpsurf: PSDL_Surface;
   105     clr: TSDL_Color;
   118     clr: TSDL_Color;
   274                         end;
   287                         end;
   275 
   288 
   276                     if Hat <> 'NoHat' then
   289                     if Hat <> 'NoHat' then
   277                         begin
   290                         begin
   278                         if (Length(Hat) > 39) and (Copy(Hat,1,8) = 'Reserved') and (Copy(Hat,9,32) = PlayerHash) then
   291                         if (Length(Hat) > 39) and (Copy(Hat,1,8) = 'Reserved') and (Copy(Hat,9,32) = PlayerHash) then
   279                             LoadHedgehogHat(Hedgehogs[i], 'Reserved/' + Copy(Hat,9,Length(Hat)-8))
   292                             LoadHedgehogHat2(Hedgehogs[i], 'Reserved/' + Copy(Hat,9,Length(Hat)-8), true)
   280                         else
   293                         else
   281                             LoadHedgehogHat(Hedgehogs[i], Hat);
   294                             LoadHedgehogHat2(Hedgehogs[i], Hat, true);
   282                         end
   295                         end
   283                     end;
   296                     end;
   284         end;
   297         end;
       
   298 
       
   299     freeTmpHatSurf();
       
   300 
   285     MissionIcons:= LoadDataImage(ptGraphics, 'missions', ifCritical);
   301     MissionIcons:= LoadDataImage(ptGraphics, 'missions', ifCritical);
   286     iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask);
   302     iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask);
   287     if iconsurf <> nil then
   303     if iconsurf <> nil then
   288         begin
   304         begin
   289         r.x:= 0;
   305         r.x:= 0;
   699 
   715 
   700     LoadDataImageAltFile:= tmpsurf;
   716     LoadDataImageAltFile:= tmpsurf;
   701 end;
   717 end;
   702 
   718 
   703 procedure LoadHedgehogHat(var HH: THedgehog; newHat: shortstring);
   719 procedure LoadHedgehogHat(var HH: THedgehog; newHat: shortstring);
   704 var texsurf: PSDL_Surface;
   720 begin
       
   721     LoadHedgehogHat2(HH, newHat, false);
       
   722 end;
       
   723 
       
   724 procedure LoadHedgehogHat2(var HH: THedgehog; newHat: shortstring; allowSurfReuse: boolean);
   705 begin
   725 begin
   706     // free the mem of any previously assigned texture.  This was previously only if the new one could be loaded, but, NoHat is usually a better choice
   726     // free the mem of any previously assigned texture.  This was previously only if the new one could be loaded, but, NoHat is usually a better choice
   707     if HH.HatTex <> nil then
   727     if HH.HatTex <> nil then
   708         begin
   728         begin
   709         FreeTexture(HH.HatTex);
   729         FreeTexture(HH.HatTex);
   710         HH.HatTex:= nil
   730         HH.HatTex:= nil
   711         end;
   731         end;
   712     texsurf:= LoadDataImage(ptHats, newHat, ifNone);
   732 
       
   733     // load new hat surface if this hat is different than the one already loaded
       
   734     if newHat <> prevHat then
       
   735         begin
       
   736         freeTmpHatSurf();
       
   737         tmpHatSurf:= LoadDataImage(ptHats, newHat, ifNone);
       
   738         end;
       
   739 
   713 AddFileLog('Hat => '+newHat);
   740 AddFileLog('Hat => '+newHat);
   714     // only do something if the hat could be loaded
   741     // only do something if the hat could be loaded
   715     if texsurf <> nil then
   742     if tmpHatSurf <> nil then
   716         begin
   743         begin
   717 AddFileLog('Got Hat');
   744 AddFileLog('Got Hat');
   718 
   745 
   719         // assign new hat to hedgehog
   746         // assign new hat to hedgehog
   720         HH.HatTex:= Surface2Tex(texsurf, true);
   747         HH.HatTex:= Surface2Tex(tmpHatSurf, true);
   721 
   748 
       
   749         // remember that this hat was used last
       
   750         if allowSurfReuse then
       
   751             prevHat:= newHat
   722         // cleanup: free temporary surface mem
   752         // cleanup: free temporary surface mem
   723         SDL_FreeSurface(texsurf)
   753         else
       
   754             freeTmpHatSurf();
   724         end;
   755         end;
   725 end;
   756 end;
   726 
   757 
   727 function glLoadExtension(extension : shortstring) : boolean;
   758 function glLoadExtension(extension : shortstring) : boolean;
   728 begin
   759 begin
  1675     SDLwindow:= nil;
  1706     SDLwindow:= nil;
  1676     SDLGLcontext:= nil;
  1707     SDLGLcontext:= nil;
  1677 {$ELSE}
  1708 {$ELSE}
  1678     SDLPrimSurface:= nil;
  1709     SDLPrimSurface:= nil;
  1679 {$ENDIF}
  1710 {$ENDIF}
       
  1711 
       
  1712     prevHat:= 'NoHat';
       
  1713     tmpHatSurf:= nil;
  1680 end;
  1714 end;
  1681 
  1715 
  1682 procedure freeModule;
  1716 procedure freeModule;
  1683 begin
  1717 begin
  1684 {$IFDEF GL2}
  1718 {$IFDEF GL2}