hedgewars/uStore.pas
changeset 7304 8b3575750cd2
parent 7297 af64b509725c
child 7384 85b022855f9a
child 11317 62287d4044e7
equal deleted inserted replaced
7301:bea42438a2ec 7304:8b3575750cd2
    57 procedure BeginWater;
    57 procedure BeginWater;
    58 procedure EndWater;
    58 procedure EndWater;
    59 
    59 
    60 implementation
    60 implementation
    61 uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands,
    61 uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands,
    62      uDebug{$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF}, uMatrix;
    62      uDebug{$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF}, uMatrix, uAtlas;
    63 
    63 
    64 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    64 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    65 
    65 
    66 var MaxTextureSize: LongInt;
    66 var MaxTextureSize: LongInt;
    67 {$IFDEF SDL13}
    67 {$IFDEF SDL13}
   293                 texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent);
   293                 texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent);
   294             if texsurf = nil then
   294             if texsurf = nil then
   295                 texsurf:= LoadImage(UserPathz[ptGraves] + '/Statue', ifTransparent);
   295                 texsurf:= LoadImage(UserPathz[ptGraves] + '/Statue', ifTransparent);
   296             if texsurf = nil then
   296             if texsurf = nil then
   297                 texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent);
   297                 texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent);
   298             GraveTex:= Surface2Atlas(texsurf, false);
   298             GraveTex:= SurfaceSheet2Atlas(texsurf, 32, 32);
   299             end
   299             end
   300 end;
   300 end;
   301 
   301 
   302 procedure StoreLoad(reload: boolean);
   302 procedure StoreLoad(reload: boolean);
   303 var s: shortstring;
   303 var s: shortstring;
   304     ii: TSprite;
   304     ii: TSprite;
   305     fi: THWFont;
   305     fi: THWFont;
   306     ai: TAmmoType;
   306     ai: TAmmoType;
   307     tmpsurf: PSDL_Surface;
   307     tmpsurf: PSDL_Surface;
   308     i: LongInt;
   308     i: LongInt;
       
   309     sw, sh: LongInt;
   309 begin
   310 begin
   310 AddFileLog('StoreLoad()');
   311 AddFileLog('StoreLoad()');
   311 
   312 
   312 if not reload then
   313 if not reload then
   313     for fi:= Low(THWFont) to High(THWFont) do
   314     for fi:= Low(THWFont) to High(THWFont) do
   395                     Texture:= Surface2Atlas(tmpsurf, true);
   396                     Texture:= Surface2Atlas(tmpsurf, true);
   396                     Texture^.Scale:= 2
   397                     Texture^.Scale:= 2
   397                     end
   398                     end
   398                 else
   399                 else
   399                     begin
   400                     begin
   400                     Texture:= Surface2Atlas(tmpsurf, false);
   401                     sw:=Trunc(Width*scale);
       
   402                     sh:=Trunc(Height*scale);
       
   403                     if (sw > imageWidth) or (sh > imageHeight) then
       
   404                     begin
       
   405                         if not (ii in [sprPHammer, sprBalls, sprSnow]) then
       
   406                         begin
       
   407                             writeln(stdout, 'Dimension error in ' + FileName + ' [' + IntToStr(Integer(ii)) + ']');
       
   408                             halt(-1);
       
   409                         end;
       
   410                     end;
       
   411  
       
   412                     if (imageWidth > sw) or (imageHeight > sh) then
       
   413                     begin
       
   414                         writeln(stdout, 'Animation sheet?: ' + FileName + ' : ' + IntToStr(Round(imageWidth/sw)) + 'x' + IntToStr(Round(imageHeight/sh)));
       
   415                         Texture:= SurfaceSheet2Atlas(tmpsurf, Width, Height);
       
   416                     end
       
   417                     else Texture:= Surface2Atlas(tmpsurf, false);
       
   418 
   401                     // HACK: We should include some sprite attribute to define the texture wrap directions
   419                     // HACK: We should include some sprite attribute to define the texture wrap directions
   402                     if ((ii = sprWater) or (ii = sprSDWater)) and ((cReducedQuality and (rq2DWater or rqClampLess)) = 0) then
   420                     if ((ii = sprWater) or (ii = sprSDWater)) and ((cReducedQuality and (rq2DWater or rqClampLess)) = 0) then
   403                         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   421                         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   404                     end;
   422                     end;
   405                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, priority);
   423                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, priority);
   425 
   443 
   426     tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent);
   444     tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent);
   427 if tmpsurf = nil then
   445 if tmpsurf = nil then
   428     tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent);
   446     tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent);
   429     
   447     
   430 HHTexture:= Surface2Atlas(tmpsurf, false);
   448 HHTexture:= SurfaceSheet2Atlas(tmpsurf, 32, 32);
   431 
   449 
   432 InitHealth;
   450 InitHealth;
   433 
   451 
   434 PauseTexture:= RenderStringTex(trmsg[sidPaused], cYellowColor, fntBig);
   452 PauseTexture:= RenderStringTex(trmsg[sidPaused], cYellowColor, fntBig);
   435 ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], cYellowColor, fntBig);
   453 ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], cYellowColor, fntBig);
   466 
   484 
   467 procedure StoreRelease(reload: boolean);
   485 procedure StoreRelease(reload: boolean);
   468 var ii: TSprite;
   486 var ii: TSprite;
   469     ai: TAmmoType;
   487     ai: TAmmoType;
   470     i, t: LongInt;
   488     i, t: LongInt;
       
   489     nf: ^PTexture;
   471 begin
   490 begin
   472 for ii:= Low(TSprite) to High(TSprite) do
   491 for ii:= Low(TSprite) to High(TSprite) do
   473     begin
   492     begin
       
   493     nf:= @SpritesData[ii].Texture;
       
   494     writeln(stdout, 'Releasing ' + IntToStr(Integer(ii)) + ' tex: ' + IntToHex(Integer(nf), 8));
   474     FreeTexture(SpritesData[ii].Texture);
   495     FreeTexture(SpritesData[ii].Texture);
   475     SpritesData[ii].Texture:= nil;
   496     SpritesData[ii].Texture:= nil;
   476     if (SpritesData[ii].Surface <> nil) and (not reload) then
       
   477         begin
       
   478         //SDL_FreeSurface(SpritesData[ii].Surface); released by FreeTexture
       
   479         SpritesData[ii].Surface:= nil
       
   480         end
       
   481     end;
   497     end;
   482 SDL_FreeSurface(MissionIcons);
   498 SDL_FreeSurface(MissionIcons);
   483 
   499 
   484 // free the textures declared in uVariables
   500 // free the textures declared in uVariables
   485 FreeTexture(WeaponTooltipTex);
   501 FreeTexture(WeaponTooltipTex);
   606         begin
   622         begin
   607         // free the mem of any previously assigned texture
   623         // free the mem of any previously assigned texture
   608         FreeTexture(HHGear^.Hedgehog^.HatTex);
   624         FreeTexture(HHGear^.Hedgehog^.HatTex);
   609 
   625 
   610         // assign new hat to hedgehog
   626         // assign new hat to hedgehog
   611         HHGear^.Hedgehog^.HatTex:= Surface2Atlas(texsurf, true);
   627         HHGear^.Hedgehog^.HatTex:= SurfaceSheet2Atlas(texsurf, 32, 32)
   612         end;
   628         end;
   613 end;
   629 end;
   614 
   630 
   615 function glLoadExtension(extension : shortstring) : boolean;
   631 function glLoadExtension(extension : shortstring) : boolean;
   616 begin
   632 begin
  1039         WriteToConsole(msgLoading + 'progress sprite: ');
  1055         WriteToConsole(msgLoading + 'progress sprite: ');
  1040         texsurf:= LoadImage(UserPathz[ptGraphics] + '/Progress', ifTransparent);
  1056         texsurf:= LoadImage(UserPathz[ptGraphics] + '/Progress', ifTransparent);
  1041         if texsurf = nil then
  1057         if texsurf = nil then
  1042             texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
  1058             texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
  1043 
  1059 
  1044         ProgrTex:= Surface2Atlas(texsurf, false);
       
  1045 
       
  1046         squaresize:= texsurf^.w shr 1;
  1060         squaresize:= texsurf^.w shr 1;
  1047         numsquares:= texsurf^.h div squaresize;
  1061         numsquares:= texsurf^.h div squaresize;
       
  1062 
       
  1063         ProgrTex:= Surface2Atlas(texsurf, false);
  1048 
  1064 
  1049         uMobile.GameLoading();
  1065         uMobile.GameLoading();
  1050         end;
  1066         end;
  1051 
  1067 
  1052     TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
  1068     TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);