hedgewars/uStore.pas
changeset 7291 ad4b6c2b09e8
parent 7188 580cd247511e
child 7297 af64b509725c
equal deleted inserted replaced
7288:5d0704f23a2a 7291:ad4b6c2b09e8
   153 
   153 
   154     if SDL_MustLock(texsurf) then
   154     if SDL_MustLock(texsurf) then
   155         SDL_UnlockSurface(texsurf);
   155         SDL_UnlockSurface(texsurf);
   156 
   156 
   157     FreeTexture(CrosshairTex);
   157     FreeTexture(CrosshairTex);
   158     CrosshairTex:= Surface2Tex(texsurf, false);
   158     CrosshairTex:= Surface2Atlas(texsurf, false);
   159     SDL_FreeSurface(texsurf)
       
   160     end;
   159     end;
   161 
   160 
   162 SDL_FreeSurface(tmpsurf)
   161 SDL_FreeSurface(tmpsurf)
   163 end;
   162 end;
   164 
   163 
   187 
   186 
   188         DrawRoundRect(@r, cWhiteColor, cNearBlackColorChannels.value, texsurf, true);
   187         DrawRoundRect(@r, cWhiteColor, cNearBlackColorChannels.value, texsurf, true);
   189         rr:= r;
   188         rr:= r;
   190         inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
   189         inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
   191         DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false);
   190         DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false);
   192         HealthTex:= Surface2Tex(texsurf, false);
   191         HealthTex:= Surface2Atlas(texsurf, false);
   193         SDL_FreeSurface(texsurf);
       
   194 
   192 
   195         r.x:= 0;
   193         r.x:= 0;
   196         r.y:= 0;
   194         r.y:= 0;
   197         r.w:= 32;
   195         r.w:= 32;
   198         r.h:= 32;
   196         r.h:= 32;
   228         PLongwordArray(texsurf^.pixels)^[32 * 2 +  2]:= cNearBlackColor;
   226         PLongwordArray(texsurf^.pixels)^[32 * 2 +  2]:= cNearBlackColor;
   229         PLongwordArray(texsurf^.pixels)^[32 * 2 + 23]:= cNearBlackColor;
   227         PLongwordArray(texsurf^.pixels)^[32 * 2 + 23]:= cNearBlackColor;
   230         PLongwordArray(texsurf^.pixels)^[32 * 16 +  2]:= cNearBlackColor;
   228         PLongwordArray(texsurf^.pixels)^[32 * 16 +  2]:= cNearBlackColor;
   231         PLongwordArray(texsurf^.pixels)^[32 * 16 + 23]:= cNearBlackColor;
   229         PLongwordArray(texsurf^.pixels)^[32 * 16 + 23]:= cNearBlackColor;
   232 
   230 
   233         FlagTex:= Surface2Tex(texsurf, false);
   231         FlagTex:= Surface2Atlas(texsurf, false);
   234         SDL_FreeSurface(texsurf);
       
   235         texsurf:= nil;
   232         texsurf:= nil;
   236 
   233 
   237         AIKillsTex := RenderStringTex(inttostr(stats.AIKills), Clan^.Color, fnt16);
   234         AIKillsTex := RenderStringTex(inttostr(stats.AIKills), Clan^.Color, fnt16);
   238 
   235 
   239         dec(drY, r.h + 2);
   236         dec(drY, r.h + 2);
   261         r.x:= 0;
   258         r.x:= 0;
   262         r.y:= 0;
   259         r.y:= 0;
   263         r.w:= 28;
   260         r.w:= 28;
   264         r.h:= 28;
   261         r.h:= 28;
   265         DrawRoundRect(@r, cWhiteColor, cNearBlackColor, iconsurf, true);
   262         DrawRoundRect(@r, cWhiteColor, cNearBlackColor, iconsurf, true);
   266         ropeIconTex:= Surface2Tex(iconsurf, false);
   263         ropeIconTex:= Surface2Atlas(iconsurf, false);
   267         SDL_FreeSurface(iconsurf);
       
   268         iconsurf:= nil;
   264         iconsurf:= nil;
   269         end;
   265         end;
   270 end;
   266 end;
   271 
   267 
   272 procedure InitHealth;
   268 procedure InitHealth;
   297                 texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent);
   293                 texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent);
   298             if texsurf = nil then
   294             if texsurf = nil then
   299                 texsurf:= LoadImage(UserPathz[ptGraves] + '/Statue', ifTransparent);
   295                 texsurf:= LoadImage(UserPathz[ptGraves] + '/Statue', ifTransparent);
   300             if texsurf = nil then
   296             if texsurf = nil then
   301                 texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent);
   297                 texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent);
   302             GraveTex:= Surface2Tex(texsurf, false);
   298             GraveTex:= Surface2Atlas(texsurf, false);
   303             SDL_FreeSurface(texsurf)
       
   304             end
   299             end
   305 end;
   300 end;
   306 
   301 
   307 procedure StoreLoad(reload: boolean);
   302 procedure StoreLoad(reload: boolean);
   308 var s: shortstring;
   303 var s: shortstring;
   395                     Width:= tmpsurf^.w;
   390                     Width:= tmpsurf^.w;
   396                     Height:= tmpsurf^.h
   391                     Height:= tmpsurf^.h
   397                     end;
   392                     end;
   398                 if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then
   393                 if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then
   399                     begin
   394                     begin
   400                     Texture:= Surface2Tex(tmpsurf, true);
   395                     Texture:= Surface2Atlas(tmpsurf, true);
   401                     Texture^.Scale:= 2
   396                     Texture^.Scale:= 2
   402                     end
   397                     end
   403                 else
   398                 else
   404                     begin
   399                     begin
   405                     Texture:= Surface2Tex(tmpsurf, false);
   400                     Texture:= Surface2Atlas(tmpsurf, false);
   406                     // HACK: We should include some sprite attribute to define the texture wrap directions
   401                     // HACK: We should include some sprite attribute to define the texture wrap directions
   407                     if ((ii = sprWater) or (ii = sprSDWater)) and ((cReducedQuality and (rq2DWater or rqClampLess)) = 0) then
   402                     if ((ii = sprWater) or (ii = sprSDWater)) and ((cReducedQuality and (rq2DWater or rqClampLess)) = 0) then
   408                         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   403                         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   409                     end;
   404                     end;
   410                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, priority);
   405                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, priority);
   414 {$IFDEF USE_CONTEXT_RESTORE}
   409 {$IFDEF USE_CONTEXT_RESTORE}
   415                     Surface:= tmpsurf 
   410                     Surface:= tmpsurf 
   416 {$ELSE}
   411 {$ELSE}
   417                     if saveSurf then
   412                     if saveSurf then
   418                         Surface:= tmpsurf
   413                         Surface:= tmpsurf
   419                     else
   414                     //else
   420                         SDL_FreeSurface(tmpsurf)
   415                     //    SDL_FreeSurface(tmpsurf) released by FreeTexture
   421 {$ENDIF}
   416 {$ENDIF}
   422                     end
   417                     end
   423                 end
   418                 end
   424             else
   419             else
   425                 Surface:= nil
   420                 Surface:= nil
   430 
   425 
   431     tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent);
   426     tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent);
   432 if tmpsurf = nil then
   427 if tmpsurf = nil then
   433     tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent);
   428     tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent);
   434     
   429     
   435 HHTexture:= Surface2Tex(tmpsurf, false);
   430 HHTexture:= Surface2Atlas(tmpsurf, false);
   436 SDL_FreeSurface(tmpsurf);
       
   437 
   431 
   438 InitHealth;
   432 InitHealth;
   439 
   433 
   440 PauseTexture:= RenderStringTex(trmsg[sidPaused], cYellowColor, fntBig);
   434 PauseTexture:= RenderStringTex(trmsg[sidPaused], cYellowColor, fntBig);
   441 ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], cYellowColor, fntBig);
   435 ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], cYellowColor, fntBig);
   451         TryDo(trAmmo[NameId] <> '','No default text/translation found for ammo type #' + intToStr(ord(ai)) + '!',true);
   445         TryDo(trAmmo[NameId] <> '','No default text/translation found for ammo type #' + intToStr(ord(ai)) + '!',true);
   452         tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(trAmmo[NameId],fnt16)].Handle, Str2PChar(trAmmo[NameId]), cWhiteColorChannels);
   446         tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(trAmmo[NameId],fnt16)].Handle, Str2PChar(trAmmo[NameId]), cWhiteColorChannels);
   453         TryDo(tmpsurf <> nil,'Name-texture creation for ammo type #' + intToStr(ord(ai)) + ' failed!',true);
   447         TryDo(tmpsurf <> nil,'Name-texture creation for ammo type #' + intToStr(ord(ai)) + ' failed!',true);
   454         tmpsurf:= doSurfaceConversion(tmpsurf);
   448         tmpsurf:= doSurfaceConversion(tmpsurf);
   455         FreeTexture(NameTex);
   449         FreeTexture(NameTex);
   456         NameTex:= Surface2Tex(tmpsurf, false);
   450         NameTex:= Surface2Atlas(tmpsurf, false);
   457         SDL_FreeSurface(tmpsurf)
       
   458         end;
   451         end;
   459 
   452 
   460 // number of weapons in ammo menu
   453 // number of weapons in ammo menu
   461 for i:= Low(CountTexz) to High(CountTexz) do
   454 for i:= Low(CountTexz) to High(CountTexz) do
   462     begin
   455     begin
   463     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels);
   456     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels);
   464     tmpsurf:= doSurfaceConversion(tmpsurf);
   457     tmpsurf:= doSurfaceConversion(tmpsurf);
   465     FreeTexture(CountTexz[i]);
   458     FreeTexture(CountTexz[i]);
   466     CountTexz[i]:= Surface2Tex(tmpsurf, false);
   459     CountTexz[i]:= Surface2Atlas(tmpsurf, false);
   467     SDL_FreeSurface(tmpsurf)
       
   468     end;
   460     end;
   469 
   461 
   470 if not reload then
   462 if not reload then
   471     AddProgress;
   463     AddProgress;
   472 IMG_Quit();
   464 IMG_Quit();
   614         begin
   606         begin
   615         // free the mem of any previously assigned texture
   607         // free the mem of any previously assigned texture
   616         FreeTexture(HHGear^.Hedgehog^.HatTex);
   608         FreeTexture(HHGear^.Hedgehog^.HatTex);
   617 
   609 
   618         // assign new hat to hedgehog
   610         // assign new hat to hedgehog
   619         HHGear^.Hedgehog^.HatTex:= Surface2Tex(texsurf, true);
   611         HHGear^.Hedgehog^.HatTex:= Surface2Atlas(texsurf, true);
   620 
       
   621         // cleanup: free temporary surface mem
       
   622         SDL_FreeSurface(texsurf)
       
   623         end;
   612         end;
   624 end;
   613 end;
   625 
   614 
   626 function glLoadExtension(extension : shortstring) : boolean;
   615 function glLoadExtension(extension : shortstring) : boolean;
   627 begin
   616 begin
  1050         WriteToConsole(msgLoading + 'progress sprite: ');
  1039         WriteToConsole(msgLoading + 'progress sprite: ');
  1051         texsurf:= LoadImage(UserPathz[ptGraphics] + '/Progress', ifTransparent);
  1040         texsurf:= LoadImage(UserPathz[ptGraphics] + '/Progress', ifTransparent);
  1052         if texsurf = nil then
  1041         if texsurf = nil then
  1053             texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
  1042             texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
  1054 
  1043 
  1055         ProgrTex:= Surface2Tex(texsurf, false);
  1044         ProgrTex:= Surface2Atlas(texsurf, false);
  1056 
  1045 
  1057         squaresize:= texsurf^.w shr 1;
  1046         squaresize:= texsurf^.w shr 1;
  1058         numsquares:= texsurf^.h div squaresize;
  1047         numsquares:= texsurf^.h div squaresize;
  1059         SDL_FreeSurface(texsurf);
       
  1060 
  1048 
  1061         uMobile.GameLoading();
  1049         uMobile.GameLoading();
  1062         end;
  1050         end;
  1063 
  1051 
  1064     TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
  1052     TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
  1199 r.w:= 32;
  1187 r.w:= 32;
  1200 r.h:= 32;
  1188 r.h:= 32;
  1201 SDL_FillRect(tmpsurf, @r, $ffffffff);
  1189 SDL_FillRect(tmpsurf, @r, $ffffffff);
  1202 SDL_UpperBlit(iconsurf, iconrect, tmpsurf, @r);
  1190 SDL_UpperBlit(iconsurf, iconrect, tmpsurf, @r);
  1203 
  1191 
  1204 RenderHelpWindow:=  Surface2Tex(tmpsurf, true);
  1192 RenderHelpWindow:=  Surface2Atlas(tmpsurf, true);
  1205 SDL_FreeSurface(tmpsurf)
       
  1206 end;
  1193 end;
  1207 
  1194 
  1208 procedure RenderWeaponTooltip(atype: TAmmoType);
  1195 procedure RenderWeaponTooltip(atype: TAmmoType);
  1209 var r: TSDL_Rect;
  1196 var r: TSDL_Rect;
  1210     i: LongInt;
  1197     i: LongInt;