DEADSOFTWARE

experimental grid with buckets
[d2df-sdl.git] / src / game / g_map.pas
index b5e457cdc197ecdde00cc5731d2090aaa2968e96..634eff9be7ae4625b4483ad4e2b929508075922e 100644 (file)
@@ -208,6 +208,8 @@ begin
   if (pan.Width < 1) or (pan.Height < 1) then exit;
   //if (pan.Width = 1) then aabb.maxX += 1;
   //if (pan.Height = 1) then aabb.maxY += 1;
+  //if (pan.Width < 3) or (pan.Height < 3) then exit;
+  //aabb := AABB2D.Create(pan.X, pan.Y, pan.X+pan.Width-2, pan.Y+pan.Height-2);
   if not aabb.valid then raise Exception.Create('wutafuuuuuuu?!');
   result := aabb.valid;
 end;
@@ -2263,30 +2265,28 @@ 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_accel_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
+      //e_WriteLog(Format('coldet query: x=%d; y=%d; w=%d; h=%d', [X, Y, Width, Height]), MSG_NOTIFY);
+      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 := (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
-      begin
-        result := gMapGrid.forEachInAABB(X, Y, Width, Height, checker, (GridTagWallDoor or GridTagWater or GridTagAcid1 or GridTagAcid2 or GridTagStep or GridTagLift or GridTagBlockMon));
+        //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;
 
 
@@ -2340,27 +2340,24 @@ var
 begin
   //TODO: detailed profile?
   if (profMapCollision <> nil) then profMapCollision.sectionBeginAccum('liquid coldet');
-  try
-    if gdbg_map_use_accel_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, (GridTagWater or GridTagAcid1 or GridTagAcid2));
-      end
-      else
-      begin
-        gMapGrid.forEachInAABB(X, Y, Width, Height, checker, (GridTagWater or GridTagAcid1 or GridTagAcid2));
-      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);