From: Ketmar Dark Date: Sun, 3 Sep 2017 17:05:34 +0000 (+0300) Subject: gibs and corpses now affected by mplats X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=1f3c760a3beb696acb34781fa305b10942aee2b1;p=d2df-sdl.git gibs and corpses now affected by mplats TODO: create gib/corpse grid, to speed up spatial queries --- diff --git a/src/game/g_gfx.pas b/src/game/g_gfx.pas index bd8d9ae..a719ce6 100644 --- a/src/game/g_gfx.pas +++ b/src/game/g_gfx.pas @@ -14,6 +14,7 @@ * along with this program. If not, see . *) {$INCLUDE ../shared/a_modes.inc} +{.$DEFINE D2F_DEBUG_FALL_MPLAT} unit g_gfx; interface @@ -171,9 +172,9 @@ begin awakeMinX := mapGrid.gridX0; awakeMinY := mapGrid.gridY0; SetLength(awakeMap, awakeMapW*awakeMapH); - {$IF DEFINED(D2F_DEBUG)} + //{$IF DEFINED(D2F_DEBUG)} e_LogWritefln('particle awake map: %sx%s (for grid of size %sx%s)', [awakeMapW, awakeMapH, mapGrid.gridWidth, mapGrid.gridHeight]); - {$ENDIF} + //{$ENDIF} awakeDirty := true; awmClear(); end; @@ -466,6 +467,9 @@ var ex, ey: Integer; checkEnv: Boolean; floorJustTraced: Boolean; + {$IF DEFINED(D2F_DEBUG_FALL_MPLAT)} + oldFloorY: Integer; + {$ENDIF} begin if not gpart_dbg_phys_enabled then goto _done; @@ -668,9 +672,16 @@ begin // check if our ground wasn't moved since the last scan if not floorJustTraced then begin - e_LogWritefln('force rescanning vpart at (%d,%d); floorY=%d', [x, y, floorY]); + {$IF DEFINED(D2F_DEBUG_FALL_MPLAT)} + oldFloorY := floorY; + {$ENDIF} findFloor(true); // force trace - e_LogWritefln(' rescanned vpart at (%d,%d); floorY=%d', [x, y, floorY]); + {$IF DEFINED(D2F_DEBUG_FALL_MPLAT)} + if (floorY <> oldFloorY) then + begin + e_LogWritefln('force rescanning vpart at (%s,%s); oldFloorY=%s; floorY=%s', [x, y, oldFloorY, floorY]); + end; + {$ENDIF} if (floorType = TFloorType.LiquidOut) then env := TEnvType.ELiquid else env := TEnvType.EAir; if (y <> floorY) then continue; end; diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas index 42f52c5..a1248f0 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -1134,6 +1134,23 @@ procedure plrDebugDraw (); for f := 0 to High(gTriggers) do drawTrigger(gTriggers[f]); end; + procedure drawGibsBoxes (); + var + f: Integer; + px, py, pw, ph: Integer; + gib: PGib; + begin + for f := 0 to High(gGibs) do + begin + gib := @gGibs[f]; + if gib.alive then + begin + gib.getMapBox(px, py, pw, ph); + drawRect(px, py, pw, ph, 255, 0, 255); + end; + end; + end; + var mon: TMonster; mx, my, mw, mh: Integer; @@ -1167,6 +1184,8 @@ begin if showTriggers then drawTriggers(); if showGrid then drawSelectedPlatformCells(); + //drawGibsBoxes(); + glPopMatrix(); glDisable(GL_SCISSOR_TEST); diff --git a/src/game/g_panel.pas b/src/game/g_panel.pas index 0a3f8f7..bcd1c4c 100644 --- a/src/game/g_panel.pas +++ b/src/game/g_panel.pas @@ -601,6 +601,55 @@ var plr.positionChanged(); end; + procedure gibMove (gib: PGib); + var + px, py, pw, ph, dx, dy: Integer; + begin + if (gib = nil) or not gib.alive then exit; + gib.getMapBox(px, py, pw, ph); + { + writeln('gib: p=(', px, ',', py, '); obj=(', gib.Obj.X, ',', gib.Obj.Y, ')'); + px := gib.Obj.X; + py := gib.Obj.Y; + } + if (py+ph <> Y) then + begin + // push gib + if doPush(px, py, pw, ph, dx, dy) then + begin + gib.Obj.X += dx; + gib.Obj.Y += dy; + gib.positionChanged(); + end; + exit; + end; + if (px+pw <= X) then exit; + if (px >= X+Width) then exit; + gib.Obj.X += mMovingSpeed.X; + gib.Obj.Y += mMovingSpeed.Y; + gib.positionChanged(); + end; + + procedure corpseMove (cor: TCorpse); + var + px, py, pw, ph, dx, dy: Integer; + begin + if (cor = nil) then exit; + cor.getMapBox(px, py, pw, ph); + if (py+ph <> Y) then + begin + // push gib + if doPush(px, py, pw, ph, dx, dy) then + begin + cor.moveBy(dx, dy); // will call `positionChanged()` for us + end; + exit; + end; + if (px+pw <= X) then exit; + if (px >= X+Width) then exit; + cor.moveBy(mMovingSpeed.X, mMovingSpeed.Y); // will call `positionChanged()` for us + end; + var f: Integer; mon: TMonster; @@ -631,6 +680,10 @@ begin g_Mons_ForEachAt(nx, ny, Width, Height, monPush); // move and push players for f := 0 to High(gPlayers) do plrMove(gPlayers[f]); + // move and push gibs + for f := 0 to High(gGibs) do gibMove(@gGibs[f]); + // move and push corpses + for f := 0 to High(gCorpses) do corpseMove(gCorpses[f]); // reverse moving direction, if necessary if (mMovingSpeed.X < 0) and (nx <= mMovingStart.X) then mMovingSpeed.X := -mMovingSpeed.X else if (mMovingSpeed.X > 0) and (nx >= mMovingEnd.X) then mMovingSpeed.X := -mMovingSpeed.X; diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 1c01e2f..afd5b7a 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -318,7 +318,7 @@ type procedure CatchFire(Attacker: Word); //WARNING! this does nothing for now, but still call it! - procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! + procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right! procedure getMapBox (out x, y, w, h: Integer); inline; @@ -413,6 +413,7 @@ type procedure LoadState(var Mem: TBinMemoryReader); override; end; + PGib = ^TGib; TGib = record alive: Boolean; ID: DWORD; @@ -421,10 +422,13 @@ type Color: TRGB; Obj: TObj; - procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! + procedure getMapBox (out x, y, w, h: Integer); inline; + + procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right! end; + PShell = ^TShell; TShell = record SpriteID: DWORD; alive: Boolean; @@ -434,7 +438,9 @@ type CX, CY: Integer; Obj: TObj; - procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! + procedure getMapBox (out x, y, w, h: Integer); inline; + + procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right! end; TCorpse = class (TObject) @@ -457,7 +463,11 @@ type procedure SaveState(var Mem: TBinMemoryWriter); procedure LoadState(var Mem: TBinMemoryReader); - procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! + procedure getMapBox (out x, y, w, h: Integer); inline; + + procedure moveBy (dx, dy: Integer); inline; + + procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right! property Obj: TObj read FObj; property State: Byte read FState; @@ -616,10 +626,6 @@ var BotList: Array of TBotProfile; -procedure TGib.positionChanged (); begin end; -procedure TShell.positionChanged (); begin end; - - function Lerp(X, Y, Factor: Integer): Integer; begin Result := X + ((Y - X) div Factor); @@ -1712,6 +1718,27 @@ begin end; end; + +procedure TGib.getMapBox (out x, y, w, h: Integer); inline; +begin + x := Obj.X+Obj.Rect.X; + y := Obj.Y+Obj.Rect.Y; + w := Obj.Rect.Width; + h := Obj.Rect.Height; +end; + +procedure TShell.getMapBox (out x, y, w, h: Integer); inline; +begin + x := Obj.X; + y := Obj.Y; + w := Obj.Rect.Width; + h := Obj.Rect.Height; +end; + + +procedure TGib.positionChanged (); inline; begin end; +procedure TShell.positionChanged (); inline; begin end; + procedure g_Player_DrawCorpses(); var i: Integer; @@ -2046,7 +2073,7 @@ begin resetWeaponQueue(); end; -procedure TPlayer.positionChanged (); +procedure TPlayer.positionChanged (); inline; begin end; @@ -6095,7 +6122,26 @@ begin inherited; end; -procedure TCorpse.positionChanged (); begin end; +procedure TCorpse.positionChanged (); inline; begin end; + +procedure TCorpse.moveBy (dx, dy: Integer); inline; +begin + if (dx <> 0) or (dy <> 0) then + begin + FObj.X += dx; + FObj.Y += dy; + positionChanged(); + end; +end; + + +procedure TCorpse.getMapBox (out x, y, w, h: Integer); inline; +begin + x := FObj.X+PLAYER_CORPSERECT.X; + y := FObj.Y+PLAYER_CORPSERECT.Y; + w := PLAYER_CORPSERECT.Width; + h := PLAYER_CORPSERECT.Height; +end; procedure TCorpse.Damage(Value: Word; vx, vy: Integer); var diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 0ac255f..e77934c 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -881,6 +881,17 @@ begin Inc(idx); end; end; + + {$IF DEFINED(D2F_DEBUG)} + if (arg = '--game-scale') or (arg = '-game-scale') then + begin + if (idx <= ParamCount) then + begin + if not conParseFloat(g_dbg_scale, ParamStr(idx)) then g_dbg_scale := 1.0; + Inc(idx); + end; + end; + {$ENDIF} end; e_WriteLog('Initializing OpenGL', MSG_NOTIFY);