X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_map.pas;h=e439d17db2b9643ea8451966dc98354690f15be7;hb=9b63e74cbbb33cef5b1219c0afa82e43cfc40eeb;hp=11a7d79459680c945d174ca81c4bb45c4618d279;hpb=fe14f41dc8700dee5a80949a41c58e7d3943f464;p=d2df-sdl.git diff --git a/src/game/g_map.pas b/src/game/g_map.pas index 11a7d79..e439d17 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -134,10 +134,11 @@ var BackID: DWORD = DWORD(-1); gExternalResources: TStringList; - gdbg_map_use_grid_render: Boolean = true; - gdbg_map_use_grid_coldet: Boolean = true; - gdbg_map_use_tree_draw: 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; profMapCollision: TProfiler = nil; //WARNING: FOR DEBUGGING ONLY! implementation @@ -156,16 +157,16 @@ const MUSIC_SIGNATURE = $4953554D; // 'MUSI' FLAG_SIGNATURE = $47414C46; // 'FLAG' - GridTagInvalid = -1; - GridTagWallDoor = 0; - GridTagBack = 1; - GridTagFore = 2; - GridTagWater = 3; - GridTagAcid1 = 4; - GridTagAcid2 = 5; - GridTagStep = 6; - GridTagLift = 7; - GridTagBlockMon = 8; + GridTagInvalid = 0; + GridTagWallDoor = $0001; + GridTagBack = $0002; + GridTagFore = $0004; + GridTagWater = $0008; + GridTagAcid1 = $0010; + GridTagAcid2 = $0020; + GridTagStep = $0040; + GridTagLift = $0080; + GridTagBlockMon = $0100; function panelTypeToTag (panelType: Word): Integer; @@ -200,9 +201,15 @@ function TDynAABBTreeMap.getFleshAABB (var aabb: AABB2D; flesh: TTreeFlesh): Boo var pan: TPanel; begin + result := false; + if (flesh = nil) then begin aabb := AABB2D.Create(0, 0, 0, 0); exit; end; pan := (flesh as TPanel); - aabb.setDims(pan.X, pan.Y, pan.X+pan.Width-1, pan.Y+pan.Height-1); - result := true; + aabb := AABB2D.Create(pan.X, pan.Y, pan.X+pan.Width, pan.Y+pan.Height); + 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 not aabb.valid then raise Exception.Create('wutafuuuuuuu?!'); + result := aabb.valid; end; var @@ -1003,7 +1010,7 @@ var begin panels[idx].tag := tag; gMapGrid.insertBody(panels[idx], panels[idx].X, panels[idx].Y, panels[idx].Width, panels[idx].Height, tag); - mapTree.insertObject(panels[idx], true); // as static object + mapTree.insertObject(panels[idx], tag, true); // as static object end; end; @@ -1896,8 +1903,8 @@ var pan: TPanel; begin result := false; // don't stop, ever + //e_WriteLog(Format(' *body: tag:%d; ptag:%d; pantype=%d', [tag, ptag, PanelType]), MSG_NOTIFY); if (tag <> ptag) then exit; - //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY); if obj = nil then begin e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY); exit; end; if not (obj is TPanel) then begin e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY); exit; end; @@ -1910,18 +1917,6 @@ var dplAddPanel(pan); end; - function checkerTree (obj: TObject): Boolean; - var - pan: TPanel; - begin - result := false; // don't stop, ever - pan := (obj as TPanel); - if (pan.tag <> ptag) then exit; - if (PanelType = PANEL_CLOSEDOOR) then begin if not pan.Door then exit; end else begin if pan.Door then exit; end; - //e_WriteLog(Format(' body hit: (%d,%d)-(%dx%d) tag: %d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY); - dplAddPanel(pan); - end; - procedure DrawPanels (stp: Integer; var panels: TPanelArray; drawDoors: Boolean=False); var idx: Integer; @@ -1954,15 +1949,15 @@ 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 - mapTree.aabbQuery(x0, y0, wdt, hgt, checkerTree); + mapTree.aabbQuery(x0, y0, wdt, hgt, checker, ptag); 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 @@ -2001,24 +1996,14 @@ procedure g_Map_DrawPanelShadowVolumes(lightX: Integer; lightY: Integer; radius: pan.DrawShadowVolume(lightX, lightY, radius); end; - function checkerTree (obj: TObject): Boolean; - var - pan: TPanel; - begin - result := false; // don't stop, ever - pan := (obj as TPanel); - if (pan.tag <> GridTagWallDoor) then exit; // only walls - pan.DrawShadowVolume(lightX, lightY, radius); - end; - begin if gdbg_map_use_tree_draw then begin - mapTree.aabbQuery(lightX-radius, lightY-radius, radius*2, radius*2, checkerTree); + mapTree.aabbQuery(lightX-radius, lightY-radius, radius*2, radius*2, checker, GridTagWallDoor); 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; @@ -2275,36 +2260,30 @@ function g_Map_CollidePanel(X, Y: Integer; Width, Height: Word; PanelType: Word; end; end; - function checkerTree (obj: TObject): Boolean; - var - pan: TPanel; - begin - pan := (obj as TPanel); - result := checker(obj, pan.tag); - end; - 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 - mapTree.aabbQuery(X, Y, Width, Height, checkerTree); - 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; @@ -2320,6 +2299,7 @@ var a: Integer; begin result := false; // don't stop, ever + if (tag <> GridTagWater) and (tag <> GridTagAcid1) and (tag <> GridTagAcid2) then exit; pan := (obj as TPanel); a := pan.ArrIdx; // water @@ -2354,38 +2334,27 @@ var end; end; - function checkerTree (obj: TObject): Boolean; - var - pan: TPanel; - begin - pan := (obj as TPanel); - result := checker(obj, pan.tag); - end; - 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, checkerTree); - 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);