summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1c31522)
raw | patch | inline | side by side (parent: 1c31522)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sun, 3 Sep 2017 17:05:34 +0000 (20:05 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sun, 3 Sep 2017 17:06:20 +0000 (20:06 +0300) |
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 bd8d9ae5567495f7b857f9f3a77575c024d4596a..a719ce69b0c6c21ccaa77bd025ea080e61b3ba1a 100644 (file)
--- a/src/game/g_gfx.pas
+++ b/src/game/g_gfx.pas
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
{$INCLUDE ../shared/a_modes.inc}
+{.$DEFINE D2F_DEBUG_FALL_MPLAT}
unit g_gfx;
interface
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;
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;
// 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 42f52c51ecbed1abe90d4db45678a3ad218d781a..a1248f00155a5218285e177273ba6ad5d6795595 100644 (file)
--- a/src/game/g_holmes.pas
+++ b/src/game/g_holmes.pas
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;
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 0a3f8f7900c6f417115570d89c89a581ecb035e5..bcd1c4c1d4040d2dc820e8c2747a663dd237b82b 100644 (file)
--- a/src/game/g_panel.pas
+++ b/src/game/g_panel.pas
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;
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 1c01e2f032ae7750f7531d20322c569baac24623..afd5b7af33fbbf7a596800a70fa1e721ee957c3d 100644 (file)
--- a/src/game/g_player.pas
+++ b/src/game/g_player.pas
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;
procedure LoadState(var Mem: TBinMemoryReader); override;
end;
+ PGib = ^TGib;
TGib = record
alive: Boolean;
ID: DWORD;
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;
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)
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;
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);
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;
resetWeaponQueue();
end;
-procedure TPlayer.positionChanged ();
+procedure TPlayer.positionChanged (); inline;
begin
end;
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 0ac255fd0c580c5682ab6653929a7a9c2a2be679..e77934cbb8892120c7fa6e93b5dbf7ececb619c1 100644 (file)
--- a/src/game/g_window.pas
+++ b/src/game/g_window.pas
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);