From: Ketmar Dark Date: Sat, 19 Aug 2017 13:22:00 +0000 (+0300) Subject: render code cleanup; collision code cleanup; reverted useless "speedup" X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=081ca9c0120de313aae7a94d1fe50b275cf2176d;p=d2df-sdl.git render code cleanup; collision code cleanup; reverted useless "speedup" --- diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 369f5ac..d4af70f 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -6869,8 +6869,8 @@ begin gDefaultMegawadStart := s; end; - s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad-restore')); - if (s <> '') then + if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or + (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then begin gDefaultMegawadStart := DF_Default_Megawad_Start; end; diff --git a/src/game/g_grid.pas b/src/game/g_grid.pas index 5b2f8b1..8197457 100644 --- a/src/game/g_grid.pas +++ b/src/game/g_grid.pas @@ -25,7 +25,7 @@ const GridCellBucketSize = 8; // WARNING! can't be less than 2! type - TGridQueryCB = function (obj: TObject; objx, objy, objw, objh: Integer; tag: Integer): Boolean is nested; // return `true` to stop + TGridQueryCB = function (obj: TObject; tag: Integer): Boolean is nested; // return `true` to stop type TBodyGrid = class; @@ -68,7 +68,7 @@ type next: Integer; // in this cell; index in mCells end; - GridInternalCB = function (grida: Integer): Boolean is nested; // return `true` to stop + TGridInternalCB = function (grida: Integer): Boolean is nested; // return `true` to stop TBodyGrid = class(TObject) private @@ -95,7 +95,7 @@ type procedure insert (body: TBodyProxy); procedure remove (body: TBodyProxy); - function forGridRect (x, y, w, h: Integer; cb: GridInternalCB): Boolean; + function forGridRect (x, y, w, h: Integer; cb: TGridInternalCB): Boolean; public constructor Create (aMinPixX, aMinPixY, aPixWidth, aPixHeight: Integer; aTileSize: Integer=GridDefaultTileSize); @@ -287,7 +287,7 @@ begin end; -function TBodyGrid.forGridRect (x, y, w, h: Integer; cb: GridInternalCB): Boolean; +function TBodyGrid.forGridRect (x, y, w, h: Integer; cb: TGridInternalCB): Boolean; var gx, gy: Integer; begin @@ -474,7 +474,7 @@ function TBodyGrid.forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask begin //e_WriteLog(Format(' query #%d body hit: (%d,%d)-(%dx%d) tag:%d', [mLastQuery, mCells[idx].body.mX, mCells[idx].body.mY, mCells[idx].body.mWidth, mCells[idx].body.mHeight, mCells[idx].body.mTag]), MSG_NOTIFY); px.mQueryMark := mLastQuery; - if (cb(px.mObj, px.mX, px.mY, px.mWidth, px.mHeight, px.mTag)) then begin result := true; exit; end; + if (cb(px.mObj, px.mTag)) then begin result := true; exit; end; end; end; idx := pi.next; @@ -486,7 +486,7 @@ function TBodyGrid.forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask begin //e_WriteLog(Format(' query #%d body hit: (%d,%d)-(%dx%d) tag:%d', [mLastQuery, mCells[idx].body.mX, mCells[idx].body.mY, mCells[idx].body.mWidth, mCells[idx].body.mHeight, mCells[idx].body.mTag]), MSG_NOTIFY); px.mQueryMark := mLastQuery; - if (cb(px.mObj, px.mX, px.mY, px.mWidth, px.mHeight, px.mTag)) then begin result := true; exit; end; + if (cb(px.mObj, px.mTag)) then begin result := true; exit; end; end; end; idx := mCells[idx].next; diff --git a/src/game/g_map.pas b/src/game/g_map.pas index 23fd6cb..2f1e856 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -1924,7 +1924,7 @@ end; // new algo procedure g_Map_CollectDrawPanels (x0, y0, wdt, hgt: Integer); - function checker (obj: TObject; objx, objy, objw, objh: Integer; tag: Integer): Boolean; + function checker (obj: TObject; tag: Integer): Boolean; var pan: TPanel; begin @@ -1962,7 +1962,7 @@ end; procedure g_Map_DrawPanelShadowVolumes(lightX: Integer; lightY: Integer; radius: Integer); - function checker (obj: TObject; objx, objy, objw, objh: Integer; tag: Integer): Boolean; + function checker (obj: TObject; tag: Integer): Boolean; var pan: TPanel; begin @@ -2145,44 +2145,42 @@ end; function g_Map_CollidePanel(X, Y: Integer; Width, Height: Word; PanelType: Word; b1x3: Boolean): Boolean; - - function checker (obj: TObject; objx, objy, objwidth, objheight: Integer; tag: Integer): Boolean; + function checker (obj: TObject; tag: Integer): Boolean; var pan: TPanel; begin result := false; // don't stop, ever + pan := TPanel(obj); + + if ((tag and (GridTagWall or GridTagDoor)) <> 0) then + begin + if not pan.Enabled then exit; + end; if ((tag and GridTagLift) <> 0) then begin - pan := TPanel(obj); - if ((WordBool(PanelType and (PANEL_LIFTUP)) and (pan.LiftType = 0)) or - (WordBool(PanelType and (PANEL_LIFTDOWN)) and (pan.LiftType = 1)) or - (WordBool(PanelType and (PANEL_LIFTLEFT)) and (pan.LiftType = 2)) or - (WordBool(PanelType and (PANEL_LIFTRIGHT)) and (pan.LiftType = 3))) and - g_Collide(X, Y, Width, Height, objx, objy, objwidth, objheight) then - begin - result := true; - exit; - end; + result := + ((WordBool(PanelType and PANEL_LIFTUP) and (pan.LiftType = 0)) or + (WordBool(PanelType and PANEL_LIFTDOWN) and (pan.LiftType = 1)) or + (WordBool(PanelType and PANEL_LIFTLEFT) and (pan.LiftType = 2)) or + (WordBool(PanelType and PANEL_LIFTRIGHT) and (pan.LiftType = 3))) and + g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height); + exit; end; if ((tag and GridTagBlockMon) <> 0) then begin - if ((not b1x3) or (objwidth+objheight >= 64)) and g_Collide(X, Y, Width, Height, objx, objy, objwidth, objheight) then - begin - result := True; - exit; - end; + result := ((not b1x3) or (pan.Width+pan.Height >= 64)) and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height); + exit; end; // other shit - result := g_Collide(X, Y, Width, Height, objx, objy, objwidth, objheight); + result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height); end; var tagmask: Integer = 0; begin - //TODO: detailed profile if WordBool(PanelType and PANEL_WALL) then tagmask := tagmask or GridTagWall or GridTagDoor; if WordBool(PanelType and PANEL_WATER) then tagmask := tagmask or GridTagWater; if WordBool(PanelType and PANEL_ACID1) then tagmask := tagmask or GridTagAcid1; @@ -2221,36 +2219,36 @@ end; function g_Map_CollideLiquid_Texture(X, Y: Integer; Width, Height: Word): DWORD; var - cctype: Integer = 3; // priority: 0: water, 1: acid1, 2: acid2; 3: others (nothing) + cctype: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit texid: DWORD; // slightly different from the old code, but meh... - function checker (obj: TObject; objx, objy, objwidth, objheight: Integer; tag: Integer): Boolean; - //var pan: TPanel; + function checker (obj: TObject; tag: Integer): Boolean; + var + pan: TPanel; begin result := false; // don't stop, ever - if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit; + //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit; // check priorities case cctype of - 0: if ((tag and GridTagWater) = 0) then exit; // only water - 1: if ((tag and (GridTagWater or GridTagAcid1)) = 0) then exit; // water, acid1 - //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // water, acid1, acid2 + 0: if ((tag and GridTagWater) = 0) then exit; // allowed: water + 1: if ((tag and (GridTagWater or GridTagAcid1)) = 0) then exit; // allowed: water, acid1 + //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2 end; // collision? - if not g_Collide(X, Y, Width, Height, objx, objy, objwidth, objheight) then exit; + pan := (obj as TPanel); + if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit; // yeah - //pan := (obj as TPanel); texid := TPanel(obj).GetTextureID(); // water? water has the highest priority, so stop right here if ((tag and GridTagWater) <> 0) then begin cctype := 0; result := true; exit; end; - // acid2 + // acid2? if ((tag and GridTagAcid2) <> 0) then cctype := 2; - // acid1 + // acid1? if ((tag and GridTagAcid1) <> 0) then cctype := 1; end; begin - //TODO: detailed profile? if (profMapCollision <> nil) then profMapCollision.sectionBeginAccum('liquids'); if gdbg_map_use_accel_coldet then begin diff --git a/src/game/z_aabbtree.pas b/src/game/z_aabbtree.pas index 31b6dd4..5b3fa62 100644 --- a/src/game/z_aabbtree.pas +++ b/src/game/z_aabbtree.pas @@ -195,7 +195,7 @@ type public // called when a overlapping node has been found during the call to forEachAABBOverlap() // return `true` to stop - type TQueryOverlapCB = function (abody: TTreeFlesh; objx, objy, objw, objh: Integer; atag: Integer): Boolean is nested; + type TQueryOverlapCB = function (abody: TTreeFlesh; atag: Integer): Boolean is nested; type TSegQueryCallback = function (abody: TTreeFlesh; ax, ay, bx, by: Single): Single is nested; // return dist from (ax,ay) to abody TSegmentQueryResult = record @@ -1249,7 +1249,7 @@ begin {$IFDEF aabbtree_query_count}Inc(mNodesDeepVisited);{$ENDIF} if ((node.tag and tagmask) <> 0) then begin - if (visitor(node.flesh, node.aabb.minX, node.aabb.minY, node.aabb.maxX, node.aabb.maxY, node.tag)) then begin result := nodeId; bigstack := nil; exit; end; + if (visitor(node.flesh, node.tag)) then begin result := nodeId; bigstack := nil; exit; end; end; end else @@ -1458,7 +1458,7 @@ function TDynAABBTree.pointQuery (ax, ay: TreeNumber; cb: TQueryOverlapCB): TTre begin result := node.aabb.contains(ax, ay); end; - function dummycb (abody: TTreeFlesh; objx, objy, objw, objh: Integer; atag: Integer): Boolean; begin result := false; end; + function dummycb (abody: TTreeFlesh; atag: Integer): Boolean; begin result := false; end; var nid: Integer; caabb: AABB2D; @@ -1486,7 +1486,7 @@ var result := node.aabb.intersects(curax, curay, curbx, curby); end; - function visitor (flesh: TTreeFlesh; objx, objy, objw, objh: Integer; tag: Integer): Boolean; + function visitor (flesh: TTreeFlesh; tag: Integer): Boolean; var hitFraction: Single; begin