DEADSOFTWARE

tree: desperate attempts to win several microseconds...
[d2df-sdl.git] / src / game / g_map.pas
index 7334c3e184c3dad142fbf51a546bb195793f4b2b..e439d17db2b9643ea8451966dc98354690f15be7 100644 (file)
@@ -134,8 +134,8 @@ var
   BackID:  DWORD = DWORD(-1);
   gExternalResources: TStringList;
 
-  gdbg_map_use_grid_render: Boolean = true;
-  gdbg_map_use_grid_coldet: Boolean = true;
+  gdbg_map_use_accel_render: Boolean = true;
+  gdbg_map_use_accel_coldet: Boolean = true;
   gdbg_map_use_tree_draw: Boolean = false;
   gdbg_map_use_tree_coldet: Boolean = false;
   gdbg_map_dump_coldet_tree_queries: Boolean = false;
@@ -1949,7 +1949,7 @@ begin
   dplClear();
   ptag := panelTypeToTag(PanelType);
 
-  if gdbg_map_use_grid_render then
+  if gdbg_map_use_accel_render then
   begin
     if gdbg_map_use_tree_draw then
     begin
@@ -1957,7 +1957,7 @@ begin
     end
     else
     begin
-      gMapGrid.forEachInAABB(x0, y0, wdt, hgt, checker);
+      gMapGrid.forEachInAABB(x0, y0, wdt, hgt, checker, ptag);
     end;
     // sort and draw the list (we need to sort it, or rendering is fucked)
     while gDrawPanelList.count > 0 do
@@ -2003,7 +2003,7 @@ begin
   end
   else
   begin
-    gMapGrid.forEachInAABB(lightX-radius, lightY-radius, radius*2, radius*2, checker);
+    gMapGrid.forEachInAABB(lightX-radius, lightY-radius, radius*2, radius*2, checker, GridTagWallDoor);
   end;
 end;
 
@@ -2263,30 +2263,27 @@ function g_Map_CollidePanel(X, Y: Integer; Width, Height: Word; PanelType: Word;
 begin
   //TODO: detailed profile
   if (profMapCollision <> nil) then profMapCollision.sectionBeginAccum('wall coldet');
-  try
-    if gdbg_map_use_grid_coldet then
+  if gdbg_map_use_accel_coldet then
+  begin
+    if gdbg_map_use_tree_coldet then
     begin
-      if gdbg_map_use_tree_coldet then
-      begin
-        result := (mapTree.aabbQuery(X, Y, Width, Height, checker, (GridTagWallDoor or GridTagWater or GridTagAcid1 or GridTagAcid2 or GridTagStep or GridTagLift or GridTagBlockMon)) <> nil);
-        if (gdbg_map_dump_coldet_tree_queries) and (mapTree.nodesVisited <> 0) then
-        begin
-          //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
-          g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]));
-        end;
-      end
-      else
+      result := (mapTree.aabbQuery(X, Y, Width, Height, checker, (GridTagWallDoor or GridTagWater or GridTagAcid1 or GridTagAcid2 or GridTagStep or GridTagLift or GridTagBlockMon)) <> nil);
+      if (gdbg_map_dump_coldet_tree_queries) and (mapTree.nodesVisited <> 0) then
       begin
-        result := gMapGrid.forEachInAABB(X, Y, Width, Height, checker);
+        //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
+        g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]));
       end;
     end
     else
     begin
-      result := g_Map_CollidePanelOld(X, Y, Width, Height, PanelType, b1x3);
+      result := gMapGrid.forEachInAABB(X, Y, Width, Height, checker, (GridTagWallDoor or GridTagWater or GridTagAcid1 or GridTagAcid2 or GridTagStep or GridTagLift or GridTagBlockMon));
     end;
-  finally
-    if (profMapCollision <> nil) then profMapCollision.sectionEnd();
+  end
+  else
+  begin
+    result := g_Map_CollidePanelOld(X, Y, Width, Height, PanelType, b1x3);
   end;
+  if (profMapCollision <> nil) then profMapCollision.sectionEnd();
 end;
 
 
@@ -2337,43 +2334,27 @@ var
     end;
   end;
 
-{var
-  cctype1: Integer = 3; // priority: 0: water, 1: acid1, 2: acid2; 3: others (nothing)
-  texid1: DWORD;}
 begin
   //TODO: detailed profile?
   if (profMapCollision <> nil) then profMapCollision.sectionBeginAccum('liquid coldet');
-  try
-    if gdbg_map_use_grid_coldet then
+  if gdbg_map_use_accel_coldet then
+  begin
+    texid := TEXTURE_NONE;
+    if gdbg_map_use_tree_coldet then
     begin
-      texid := TEXTURE_NONE;
-      if gdbg_map_use_tree_coldet then
-      begin
-        mapTree.aabbQuery(X, Y, Width, Height, checker);
-        {
-        cctype1 := cctype;
-        texid1 := texid;
-        cctype := 3;
-        texid := TEXTURE_NONE;
-        gMapGrid.forEachInAABB(X, Y, Width, Height, checker);
-        if (cctype1 <> cctype) or (texid1 <> texid) then
-        begin
-          e_WriteLog(Format('g_Map_CollideLiquid_Texture(%d, %d, %u, %u): tree(cctype:%d;texid:%u); grid(cctype:%d;texid:%u)', [X, Y, Width, Height, cctype1, texid1, cctype, texid]), MSG_WARNING);
-        end;}
-      end
-      else
-      begin
-        gMapGrid.forEachInAABB(X, Y, Width, Height, checker);
-      end;
-      result := texid;
+      mapTree.aabbQuery(X, Y, Width, Height, checker, (GridTagWater or GridTagAcid1 or GridTagAcid2));
     end
     else
     begin
-      result := g_Map_CollideLiquid_TextureOld(X, Y, Width, Height);
+      gMapGrid.forEachInAABB(X, Y, Width, Height, checker, (GridTagWater or GridTagAcid1 or GridTagAcid2));
     end;
-  finally
-    if (profMapCollision <> nil) then profMapCollision.sectionEnd();
+    result := texid;
+  end
+  else
+  begin
+    result := g_Map_CollideLiquid_TextureOld(X, Y, Width, Height);
   end;
+  if (profMapCollision <> nil) then profMapCollision.sectionEnd();
 end;
 
 procedure g_Map_EnableWall(ID: DWORD);