在Windows + Pascal + SDL_2_0_5中优化多个纹理以获得更好的性能

时间:2017-01-26 21:34:26

标签: windows textures sdl pascal sdl-2

我正在使用pascal和SDL 2.0.5为Windows制作多人游戏。 我为太空船装载了510个点作为纹理,并在程序上使它们形成了翅膀的痕迹(太空中没有空气,但是谁在乎!它很酷)。您可以在下面找到相关的图片和代码。

现在。屏幕上还会有7个太空飞船,这会让游戏爬行。没有提到游戏中将通过多个SAME纹理的组合生成的各种其他粒子。有没有办法优化这个?加载纹理和一次实例如何?问题的最佳表现方法是什么?

enter image description here

var
  //TRAILS
kentro2:array[1..255]of pSDL_Point;
TC:array [1..255] of PSDL_Texture;
TC2:array [1..255] of PSDL_Texture;
gwnia2:array [1..255] of double;
TCRect:array [1..255] of PSDL_RECT;
TCRECT1:array [1..255] of PSDL_RECT;
sdlFlip2 : PSDL_RendererFlip; 

{..}

FOR J:=1 TO 255 DO
    BEGIN
      tc[J]:= IMG_LoadTexture( sdlRenderer, 'trail10001.png' );
      tc2[J]:= IMG_LoadTexture( sdlRenderer, 'trail10002.png' );
    end;

{..}

FOR J:=1 TO 255 DO
     BEGIN
       NEW(TCRECT[J]);
       NEW(TCRECT1[J]);
       new(kentro2[j]);
     end; 

{..}

  IF ((METRITISTRAILS<255) AND (TRAiLSbool=false))THEN
      BEGIN
    trailscontainer:=METRITISTRAILS;
      end
      else
      begin
       TRAiLSCONTAINER:=255;
     trailsbool:=true;
       end;

      IF (METRITISTRAILS=255)THEN
   BEGIN
    METRITISTRAILS:=0;
   end;
    METRITIStRAILS+=1;





   gwnia2[METRITIStRAILS]:= -SHIPIDX;
   kentro2[METRITIStRAILS]^.X:=KENTRO^.X;
   kentro2[METRITIStRAILS]^.Y:=KENTRO^.Y;

   TCRECT[METRITIStRAILS]^.x:=RECTTEX2^.x;
   TCRECT[METRITIStRAILS]^.y:=RECTTEX2^.y;
   TCRECT[METRITIStRAILS]^.h:=RECTTEX2^.h;
   TCRECT[METRITIStRAILS]^.w:=RECTTEX2^.w;

       TCRECT1[METRITIStRAILS]^.x:=RECTTEX^.x;
       TCRECT1[METRITIStRAILS]^.y:=RECTTEX^.y;
       TCRECT1[METRITIStRAILS]^.w:=RECTTEX^.w;
       TCRECT1[METRITIStRAILS]^.h:=RECTTEX^.h;     

 SDL_RenderCopyEX(sdlRenderer,tc[METRITIStRAILS],tcrect1[METRITIStRAILS], TCRECT[METRITIStRAILS],gwnia2[METRITIStRAILS],kentro2[METRITIStRAILS],sdlflip);
 SDL_RenderCopyEX(sdlRenderer,tc2[METRITIStRAILS],tcrect1[METRITIStRAILS], TCRECT[METRITIStRAILS],gwnia2[METRITIStRAILS],kentro2[METRITIStRAILS],sdlflip);


       FOR J:=1 TO TRAiLSCONTAINER DO
           BEGIN
               if j<>metritistrails then
              begin


                 TCRECT[j]^.x+=THYMISOUGIATRAILSX-rect2^.x;
         TCRECT[j]^.Y+=THYMISOUGIATRAILSy-rect2^.y;  


                SDL_SetTextureAlphaMod( tc[J],j-giaalpha);
                SDL_SetTextureAlphaMod( tc2[J],j-giaalpha);
  SDL_RenderCopyex(sdlRenderer,tc[j],tcrect1[j], TCRECT[j],gwnia2[j],kentro2[j],sdlflip2);
   SDL_RenderCopyex(sdlRenderer,tc2[j],tcrect1[j], TCRECT[j],gwnia2[j],kentro2[j],sdlflip2);
              end;
              SDL_SetRenderDrawColor( sdlRenderer, 0,0, 0, 0 );

           end;
          giaalpha+=1;
              if giaalpha>=255 then
              giaalpha:=0;  

0 个答案:

没有答案