summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 798a263)
raw | patch | inline | side by side (parent: 798a263)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Thu, 24 Aug 2017 01:06:38 +0000 (04:06 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Thu, 24 Aug 2017 01:07:16 +0000 (04:07 +0300) |
src/game/g_gfx.pas | patch | blob | history | |
src/game/g_holmes.pas | patch | blob | history | |
src/game/g_map.pas | patch | blob | history |
diff --git a/src/game/g_gfx.pas b/src/game/g_gfx.pas
index d90fa3b042f5cdbb9cdc5dd75efcfac3c5bb5a57..ab895762d3cae8f6b59ed2cc18fe77fc87ed3650 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_NEW_SPARK_THINKER}
unit g_gfx;
interface
implementation
uses
- g_map, g_basic, Math, e_graphics, GL, GLExt,
+ g_map, g_panel, g_basic, Math, e_graphics, GL, GLExt,
g_options, g_console, SysUtils, g_triggers, MAPDEF,
g_game, g_language, g_net;
// ////////////////////////////////////////////////////////////////////////// //
procedure TParticle.thinkerSpark ();
var
- w, h: Integer;
dX, dY: SmallInt;
+ {$IF not DEFINED(D2F_NEW_SPARK_THINKER)}
b: Integer;
s: ShortInt;
+ {$ELSE}
+ pan: TPanel;
+ ex, ey: Integer;
+ {$ENDIF}
begin
- w := gMapInfo.Width;
- h := gMapInfo.Height;
-
dX := Round(VelX);
dY := Round(VelY);
+ {$IF DEFINED(D2F_NEW_SPARK_THINKER)}
+ if (Abs(VelX) < 0.1) and (Abs(VelY) < 0.1) then
+ begin
+ pan := g_Map_traceToNearest(X, Y-1, X, Y+1, (GridTagWall or GridTagDoor or GridTagStep or GridTagAcid1 or GridTagAcid2 or GridTagWater), @ex, @ey);
+ end;
+ {$ELSE}
if (Abs(VelX) < 0.1) and (Abs(VelY) < 0.1) and
(not isBlockedAt(X, Y-1) {ByteBool(gCollideMap[Y-1, X] and MARK_BLOCKED)}) and
(not isBlockedAt(X, Y) {ByteBool(gCollideMap[Y, X] and MARK_BLOCKED)}) and
VelY := 0.8;
AccelY := 0.5;
end;
+ {$ENDIF}
- if dX <> 0 then
+ if (dX <> 0) then
begin
- if dX > 0 then
- s := 1
- else
- s := -1;
-
+ {$IF DEFINED(D2F_NEW_SPARK_THINKER)}
+ pan := g_Map_traceToNearest(X, Y, X+dX, Y, (GridTagWall or GridTagDoor or GridTagStep or GridTagAcid1 or GridTagAcid2 or GridTagWater), @ex, @ey);
+ //e_WriteLog(Format('spark h-trace: (%d,%d)-(%d,%d); dx=%d; end=(%d,%d); hit=%d', [X, Y, X+dX, Y, dX, ex, ey, Integer(pan <> nil)]), MSG_NOTIFY);
+ X := ex;
+ // free to ride?
+ if (pan <> nil) then
+ begin
+ // nope
+ if ((pan.tag and (GridTagAcid1 or GridTagAcid2 or GridTagWater)) <> 0) then begin die(); exit; end;
+ VelX := 0;
+ AccelX := 0;
+ end;
+ if (X < 0) or (X >= gMapInfo.Width) then begin die(); exit; end;
+ {$ELSE}
+ if (dX > 0) then s := 1 else s := -1;
dX := Abs(dX);
-
for b := 1 to dX do
begin
- if (X+s >= w) or (X+s <= 0) then begin die(); break; end;
-
+ if (X+s >= gMapInfo.Width) or (X+s <= 0) then begin die(); break; end;
//c := gCollideMap[Y, X+s];
-
if isBlockedAt(X+s, Y) {ByteBool(c and MARK_BLOCKED)} then
begin // Ñòåíà/äâåðü - ïàäàåò âåðòèêàëüíî
VelX := 0;
break;
end;
end;
+ {$ENDIF}
end;
- if dY <> 0 then
+ if (dY <> 0) then
begin
- if dY > 0 then
- s := 1
+ {$IF DEFINED(D2F_NEW_SPARK_THINKER)}
+ pan := g_Map_traceToNearest(X, Y, X, Y+dY, (GridTagWall or GridTagDoor or GridTagStep or GridTagAcid1 or GridTagAcid2 or GridTagWater), @ex, @ey);
+ //e_WriteLog(Format('spark y-trace: (%d,%d)-(%d,%d); dy=%d; end=(%d,%d); hit=%d', [X, Y, X, Y+dY, dY, ex, ey, Integer(pan <> nil)]), MSG_NOTIFY);
+ (*
+ if (pan <> nil) then
+ begin
+ e_WriteLog(Format('spark y-trace: %08x (%d,%d)-(%d,%d); dy=%d; end=(%d,%d); hittag=%04x', [LongWord(@self), X, Y, X, Y+dY, dY, ex, ey, pan.tag]), MSG_NOTIFY);
+ end
else
- s := -1;
-
+ begin
+ e_WriteLog(Format('spark y-trace: %08x (%d,%d)-(%d,%d); dy=%d; end=(%d,%d); hit=%d', [LongWord(@self), X, Y, X, Y+dY, dY, ex, ey, Integer(pan <> nil)]), MSG_NOTIFY);
+ end;
+ *)
+ Y := ey;
+ // free to ride?
+ if (pan <> nil) then
+ begin
+ //die(); exit;
+ // nope
+ if ((pan.tag and (GridTagAcid1 or GridTagAcid2 or GridTagWater)) <> 0) then begin die(); exit; end;
+ if (dY < 0) then
+ begin
+ VelY := -VelY;
+ AccelY := abs(AccelY);
+ end
+ else
+ begin
+ VelX := 0;
+ AccelX := 0;
+ VelY := 0;
+ AccelY := 0.8;
+ end;
+ end;
+ if (Y < 0) or (Y >= gMapInfo.Height) then begin die(); exit; end;
+ {$ELSE}
+ if (dY > 0) then s := 1 else s := -1;
dY := Abs(dY);
-
for b := 1 to dY do
begin
- if (Y+s >= h) or (Y+s <= 0) then begin die(); break; end;
-
+ if (Y+s >= gMapInfo.Height) or (Y+s <= 0) then begin die(); break; end;
//c := gCollideMap[Y+s, X];
-
if isBlockedAt(X, Y+s) {ByteBool(c and MARK_BLOCKED)} then
begin // Ñòåíà/äâåðü - ïàäàåò âåðòèêàëüíî
if s < 0 then
break;
end;
end;
+ {$ENDIF}
end;
- if VelX <> 0.0 then
- VelX := VelX + AccelX;
- if VelY <> 0.0 then
+ if (VelX <> 0.0) then VelX += AccelX;
+
+ if (VelY <> 0.0) then
begin
- if AccelY < 10 then
- AccelY := AccelY + 0.08;
- VelY := VelY + AccelY;
+ if (AccelY < 10) then AccelY += 0.08;
+ VelY += AccelY;
end;
- Time := Time + 1;
+ Time += 1;
end;
diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas
index 7d4259c061c6e3a2a0408460e77d51ed426791b7..a7cefab7441ff8081c1c8c1d06d4c10c802700de 100644 (file)
--- a/src/game/g_holmes.pas
+++ b/src/game/g_holmes.pas
msY: Integer = -666;
msB: Word = 0; // button state
kbS: Word = 0; // keyboard modifiers state
+ showGrid: Boolean = true;
showMonsInfo: Boolean = false;
showMonsLOS2Plr: Boolean = false;
showAllMonsCells: Boolean = false;
+ showMapCurPos: Boolean = false;
// ////////////////////////////////////////////////////////////////////////// //
{$INCLUDE g_holmes.inc}
+
// ////////////////////////////////////////////////////////////////////////// //
procedure g_Holmes_VidModeChanged ();
begin
laserX0, laserY0, laserX1, laserY1: Integer;
monMarkedUID: Integer = -1;
+
procedure g_Holmes_plrView (viewPortX, viewPortY, viewPortW, viewPortH: Integer);
begin
vpSet := true;
function wallToggle (pan: TPanel; tag: Integer): Boolean;
begin
result := false; // don't stop
- e_WriteLog(Format('wall #%d(%d); enabled=%d (%d)', [pan.arrIdx, pan.proxyId, Integer(pan.Enabled), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
- if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
+ e_WriteLog(Format('wall #%d(%d); enabled=%d (%d); (%d,%d)-(%d,%d)', [pan.arrIdx, pan.proxyId, Integer(pan.Enabled), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.X, pan.Y, pan.Width, pan.Height]), MSG_NOTIFY);
+ if ((kbS and THKeyEvent.ModAlt) <> 0) then
+ begin
+ if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
+ end;
end;
function monsAtDump (mon: TMonster; tag: Integer): Boolean;
glPushMatrix();
glTranslatef(-vpx, -vpy, 0);
- drawTileGrid();
+ if (showGrid) then drawTileGrid();
- g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
+ if (laserSet) then g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
if (monMarkedUID <> -1) then
begin
if showAllMonsCells then g_Mons_ForEach(highlightAllMonsterCells);
- //e_DrawPoint(16, laserX0, laserY0, 255, 255, 255);
-
glPopMatrix();
+
+ if showMapCurPos then drawText8(4, gWinSizeY-10, Format('mappos:(%d,%d)', [pmsCurMapX, pmsCurMapY]), 255, 255, 0);
end;
function g_Holmes_KeyEvent (var ev: THKeyEvent): Boolean;
var
mon: TMonster;
+ pan: TPanel;
x, y, w, h: Integer;
+ ex, ey: Integer;
+
+ procedure dummyWallTrc (cx, cy: Integer);
+ begin
+ end;
+
begin
result := false;
msB := ev.bstate;
end;
exit;
end;
+ // C-P: show cursor position on the map
+ if (ev.scan = SDL_SCANCODE_P) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
+ begin
+ result := true;
+ showMapCurPos := not showMapCurPos;
+ exit;
+ end;
+ // C-G: toggle grid
+ if (ev.scan = SDL_SCANCODE_G) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
+ begin
+ result := true;
+ showGrid := not showGrid;
+ exit;
+ end;
+ // C-DOWN: trace down 10 pixels from cursor
+ if (ev.scan = SDL_SCANCODE_DOWN) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
+ begin
+ result := true;
+ {$IF DEFINED(D2F_DEBUG)}
+ mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
+ {$ENDIF}
+ pan := g_Map_traceToNearest(pmsCurMapX, pmsCurMapY, pmsCurMapX, pmsCurMapY+10, (GridTagWall or GridTagDoor or GridTagStep or GridTagAcid1 or GridTagAcid2 or GridTagWater), @ex, @ey);
+ {$IF DEFINED(D2F_DEBUG)}
+ mapGrid.dbgRayTraceTileHitCB := nil;
+ {$ENDIF}
+ e_WriteLog(Format('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX, pmsCurMapY, pmsCurMapX, pmsCurMapY+10, ex, ey, Integer(pan <> nil)]), MSG_NOTIFY);
+ exit;
+ end;
end;
end;
diff --git a/src/game/g_map.pas b/src/game/g_map.pas
index bbe1d6c3c7dc535a53ed9b84e1ffd31d84e459c1..2c2a6b5c1a18c16e16c35cd2f4210eb79c5b6662 100644 (file)
--- a/src/game/g_map.pas
+++ b/src/game/g_map.pas
procedure g_Map_DrawPanelShadowVolumes(lightX: Integer; lightY: Integer; radius: Integer);
-// returns wall index in `gWalls` or -1
+// returns panel or nil
+// sets `ex` and `ey` to `x1` and `y1` when no hit was detected
function g_Map_traceToNearestWall (x0, y0, x1, y1: Integer; hitx: PInteger=nil; hity: PInteger=nil): TPanel;
+// returns panel or nil
+// sets `ex` and `ey` to `x1` and `y1` when no hit was detected
+function g_Map_traceToNearest (x0, y0, x1, y1: Integer; tag: Integer; hitx: PInteger=nil; hity: PInteger=nil): TPanel;
+
type
TForEachPanelCB = function (pan: TPanel): Boolean; // return `true` to stop
end;
end;
+// returns panel or nil
+function g_Map_traceToNearest (x0, y0, x1, y1: Integer; tag: Integer; hitx: PInteger=nil; hity: PInteger=nil): TPanel;
+var
+ ex, ey: Integer;
+begin
+ result := mapGrid.traceRay(ex, ey, x0, y0, x1, y1, nil, tag);
+ if (result <> nil) then
+ begin
+ if (hitx <> nil) then hitx^ := ex;
+ if (hity <> nil) then hity^ := ey;
+ end
+ else
+ begin
+ if (hitx <> nil) then hitx^ := x1;
+ if (hity <> nil) then hity^ := y1;
+ end;
+end;
+
function g_Map_HasAnyPanelAtPoint (x, y: Integer; panelType: Word): Boolean;