DEADSOFTWARE

gl: implement touch screen controls
[d2df-sdl.git] / src / game / opengl / r_map.pas
index 2ec57d478ebc1fd7821c2741315fff2615889037..a35980d798eb0b9f5f301152f515435f31832a3f 100644 (file)
@@ -17,7 +17,7 @@ unit r_map;
 
 interface
 
-  uses g_panel, MAPDEF; // TPanel, TDFColor
+  uses g_panel, MAPDEF, binheap; // TPanel, TDFColor
 
   procedure r_Map_Initialize;
   procedure r_Map_Finalize;
@@ -38,12 +38,23 @@ interface
   procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor);
   procedure r_Panel_DrawShadowVolume (constref p: TPanel; lightX, lightY: Integer; radius: Integer);
 
+  type
+    TBinHeapPanelDrawCmp = class
+      public
+        class function less (const a, b: TPanel): Boolean; inline;
+    end;
+
+    TBinHeapPanelDraw = specialize TBinaryHeapBase<TPanel, TBinHeapPanelDrawCmp>;
+
+  var
+    gDrawPanelList: TBinHeapPanelDraw = nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
+
 implementation
 
   uses
     {$INCLUDE ../nogl/noGLuses.inc}
     SysUtils, Classes, Math, e_log, wadreader, CONFIG, utils, g_language,
-    r_graphics, r_animations, r_textures, g_textures,
+    r_graphics, r_animations, r_textures, g_animations,
     g_base, g_basic, g_game, g_options,
     g_map
   ;
@@ -55,17 +66,23 @@ implementation
       Anim: Boolean;
     end;
     FlagFrames: array [FLAG_RED..FLAG_BLUE] of DWORD;
-    FlagAnim: TAnimationState;
+    FlagAnim: TAnimState;
+
+  class function TBinHeapPanelDrawCmp.less (const a, b: TPanel): Boolean; inline;
+  begin
+    if (a.tag < b.tag) then begin result := true; exit; end;
+    if (a.tag > b.tag) then begin result := false; exit; end;
+    result := (a.arrIdx < b.arrIdx);
+  end;
 
   procedure r_Map_Initialize;
   begin
-    FlagAnim := TAnimationState.Create(True, 8, 5);
+    FlagAnim := TAnimState.Create(True, 8, 5);
   end;
 
   procedure r_Map_Finalize;
   begin
-    FlagAnim.Free;
-    FlagAnim := nil;
+    FlagAnim.Invalidate;
   end;
 
   procedure r_Map_Load;
@@ -264,7 +281,7 @@ end;
           else
             Mirror := TMirrorType.None;
           dx := IfThen(f.Direction = TDirection.D_LEFT, -1, +1);
-          r_AnimationState_Draw(FlagFrames[i], FlagAnim, tx + dx, ty + 1, 0, Mirror, False);
+          r_AnimState_Draw(FlagFrames[i], FlagAnim, tx + dx, ty + 1, 0, Mirror, False);
           if g_debug_Frames then
             e_DrawQuad(tx + f.Obj.Rect.X, ty + f.Obj.Rect.Y, tx + f.Obj.Rect.X + f.Obj.Rect.Width - 1, ty + f.Obj.Rect.Y + f.Obj.Rect.Height - 1, 0, 255, 0)
         end
@@ -300,14 +317,14 @@ end;
       IsAnim := RenTextures[Texture].Anim;
       if IsAnim then
       begin
-        if p.TextureIDs[p.FCurTexture].AnTex <> nil then
+        if p.TextureIDs[p.FCurTexture].AnTex.IsValid() then
         begin
           FramesID := RenTextures[Texture].ID;
           w := RenTextures[Texture].Width;
           h := RenTextures[Texture].Height;
           for xx := 0 to tw div w - 1 do
             for yy := 0 to th div h - 1 do
-              r_AnimationState_Draw(FramesID, p.TextureIDs[p.FCurTexture].AnTex, tx + xx * w, ty + yy * h, p.Alpha, TMirrorType.None, p.Blending);
+              r_AnimState_Draw(FramesID, p.TextureIDs[p.FCurTexture].AnTex, tx + xx * w, ty + yy * h, p.Alpha, TMirrorType.None, p.Blending);
         end
       end
       else