summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b79ddd9)
raw | patch | inline | side by side (parent: b79ddd9)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Wed, 23 Aug 2017 00:20:27 +0000 (03:20 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Wed, 23 Aug 2017 18:23:55 +0000 (21:23 +0300) |
diff --git a/src/game/g_basic.pas b/src/game/g_basic.pas
index 2300b1380fcb892f99c50ba8100f9295daabfc9d..53177473ac59a0c7da0a4f9d264fd60167f80212 100644 (file)
--- a/src/game/g_basic.pas
+++ b/src/game/g_basic.pas
// `true` if no obstacles
if (g_profile_los) then g_Mons_LOS_Start();
- result := not g_Map_traceToNearestWall(x1, y1, x2, y2, @wallHitX, @wallHitY);
+ result := (g_Map_traceToNearestWall(x1, y1, x2, y2, @wallHitX, @wallHitY) = nil);
if (g_profile_los) then g_Mons_LOS_End();
end;
diff --git a/src/game/g_console.pas b/src/game/g_console.pas
index a5652ce5c799f874c538018dc40d32746cf3c1f6..c9568f02005d8f09b7f75481eb2d1cb02f38be1b 100644 (file)
--- a/src/game/g_console.pas
+++ b/src/game/g_console.pas
AddCommand('pr_phys_enabled', ProfilerCommands, 'enable/disable particle physics');
AddCommand('los_enabled', ProfilerCommands, 'enable/disable LOS calculations');
+ AddCommand('mon_think', ProfilerCommands, 'enable/disable monster thinking');
+
AddCommand('p1_name', GameCVars);
AddCommand('p2_name', GameCVars);
AddCommand('p1_color', GameCVars);
diff --git a/src/game/g_game.pas b/src/game/g_game.pas
index 3ae3e82289e9436573bf15beda801dbc2100a93d..99e1a3d8ce26a22509465542a792278615d3ce9a 100644 (file)
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
g_profile_los: Boolean = false;
g_profile_history_size: Integer = 1000;
+ postdrawMouse: procedure = nil;
+
procedure g_ResetDynlights ();
procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
if gPlayer1 <> nil then gPlayer1.NoTarget := False;
if gPlayer2 <> nil then gPlayer2.NoTarget := False;
+ {$IF DEFINED(D2F_DEBUG)}
if gPlayer1 <> nil then gPlayer1.NoTarget := True;
gAimLine := true;
+ {$ENDIF}
end;
procedure g_Game_ExecuteEvent(Name: String);
//glTranslatef(a, b+p.IncCam, 0);
+ p.viewPortX := sX;
+ p.viewPortY := sY;
+ p.viewPortW := sWidth;
+ p.viewPortH := sHeight;
+
renderMapInternal(-c, -d, a, b+p.IncCam, true);
if p.FSpectator then
Format('%d:%.2d:%.2d', [gTime div 1000 div 3600, (gTime div 1000 div 60) mod 60, gTime div 1000 mod 60]),
gStdFont);
+ if gGameOn and assigned(postdrawMouse) then postdrawMouse();
+
if gGameOn then drawProfilers();
end;
if (cmd = 'pr_enabled') then begin binaryFlag(gpart_dbg_enabled, 'particles'); exit; end;
if (cmd = 'pr_phys_enabled') then begin binaryFlag(gpart_dbg_phys_enabled, 'particle physics'); exit; end;
if (cmd = 'los_enabled') then begin binaryFlag(gmon_dbg_los_enabled, 'LOS calculations'); exit; end;
+ if (cmd = 'mon_think') then begin binaryFlag(gmon_debug_think, 'monster thinking'); exit; end;
end;
diff --git a/src/game/g_grid.pas b/src/game/g_grid.pas
index 925fb80ca042470d6b78acb7cb623952ef2d77cb..c6fe09534a639f958ca7c300f354120d08a9eee7 100644 (file)
--- a/src/game/g_grid.pas
+++ b/src/game/g_grid.pas
//mTileSize: Integer;
const mTileSize = GridDefaultTileSize;
+ public
+ const tileSize = mTileSize;
+
private
mMinX, mMinY: Integer; // so grids can start at any origin
mWidth, mHeight: Integer; // in tiles
ptag: Integer;
lastWasInGrid: Boolean;
tbcross: Boolean;
- f, tedist: Integer;
+ f: Integer;
+ //tedist: Integer;
begin
+ log := false;
result := Default(ITP);
tagmask := tagmask and TagFullMask;
if (tagmask = 0) or not assigned(cb) then exit;
if (dx > 0) then incx := 1 else if (dx < 0) then incx := -1 else incx := 0;
if (dy > 0) then incy := 1 else if (dy < 0) then incy := -1 else incy := 0;
+ if (incx = 0) and (incy = 0) then exit; // just incase
+
dx := abs(dx);
dy := abs(dy);
if (ccidx = -1) then
begin
// we have nothing interesting here anymore, jump directly to tile edge
+ (*
+ if (incx = 0) then
+ begin
+ // vertical line
+ if (incy < 0) then tedist := y-(y and (not tsize)) else tedist := (y or (tsize-1))-y;
+ if (tedist > 1) then
+ begin
+ if (log) then e_WriteLog(Format(' doing vertical jump from tile (%d,%d) - (%d,%d) by %d steps', [(x div tsize), (y div tsize), x, y, tedist]), MSG_NOTIFY);
+ y += incy*tedist;
+ Inc(i, tedist);
+ if (log) then e_WriteLog(Format(' jumped to tile (%d,%d) - (%d,%d) by %d steps', [(x div tsize), (y div tsize), x, y, tedist]), MSG_NOTIFY);
+ end;
+ end
+ else if (incy = 0) then
+ begin
+ // horizontal line
+ if (incx < 0) then tedist := x-(x and (not tsize)) else tedist := (x or (tsize-1))-x;
+ if (tedist > 1) then
+ begin
+ if (log) then e_WriteLog(Format(' doing horizontal jump from tile (%d,%d) - (%d,%d) by %d steps', [(x div tsize), (y div tsize), x, y, tedist]), MSG_NOTIFY);
+ x += incx*tedist;
+ Inc(i, tedist);
+ if (log) then e_WriteLog(Format(' jumped to tile (%d,%d) - (%d,%d) by %d steps', [(x div tsize), (y div tsize), x, y, tedist]), MSG_NOTIFY);
+ end;
+ end;
+ *)
+ (*
+ else if (
// get minimal distance to tile edges
if (incx < 0) then tedist := x-(x and (not tsize)) else if (incx > 0) then tedist := (x or (tsize+1))-x else tedist := 0;
{$IF DEFINED(D2F_DEBUG)}
Inc(i, tedist);
if (log) then e_WriteLog(Format(' jumped to tile (%d,%d) - (%d,%d) by %d steps', [(x div tsize), (y div tsize), x, y, tedist]), MSG_NOTIFY);
end;
+ *)
end;
end
else
diff --git a/src/game/g_map.pas b/src/game/g_map.pas
index 0b573c22cbd05472c84e1ea8e6e15934e3e482b8..6bae3695568f44127da5ec7890efb32c1a15a2be 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
-function g_Map_traceToNearestWall (x0, y0, x1, y1: Integer; hitx: PInteger=nil; hity: PInteger=nil): Boolean;
+function g_Map_traceToNearestWall (x0, y0, x1, y1: Integer; hitx: PInteger=nil; hity: PInteger=nil): TPanel;
type
TForEachPanelCB = function (pan: TPanel): Boolean; // return `true` to stop
profMapCollision: TProfiler = nil; //WARNING: FOR DEBUGGING ONLY!
gDrawPanelList: TBinaryHeapObj = nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
+
function panelTypeToTag (panelType: Word): Integer; // returns GridTagXXX
+type
+ TPanelGrid = specialize TBodyGridBase<TPanel>;
+
+var
+ mapGrid: TPanelGrid = nil;
+
+
implementation
uses
FLAG_SIGNATURE = $47414C46; // 'FLAG'
-type
- TPanelGrid = specialize TBodyGridBase<TPanel>;
-
-
function panelTypeToTag (panelType: Word): Integer;
begin
case panelType of
RespawnPoints: Array of TRespawnPoint;
FlagPoints: Array [FLAG_RED..FLAG_BLUE] of PFlagPoint;
//DOMFlagPoints: Array of TFlagPoint;
- mapGrid: TPanelGrid = nil;
procedure g_Map_ProfilersBegin ();
// wall index in `gWalls` or -1
-function g_Map_traceToNearestWall (x0, y0, x1, y1: Integer; hitx: PInteger=nil; hity: PInteger=nil): Boolean;
+function g_Map_traceToNearestWall (x0, y0, x1, y1: Integer; hitx: PInteger=nil; hity: PInteger=nil): TPanel;
var
ex, ey: Integer;
begin
- result := (mapGrid.traceRay(ex, ey, x0, y0, x1, y1, nil, (GridTagWall or GridTagDoor)) <> nil);
- if result then
+ result := mapGrid.traceRay(ex, ey, x0, y0, x1, y1, nil, (GridTagWall or GridTagDoor));
+ if (result <> nil) then
begin
if (hitx <> nil) then hitx^ := ex;
if (hity <> nil) then hity^ := ey;
calcBoundingBox(gLifts);
calcBoundingBox(gBlockMon);
- e_WriteLog(Format('map dimensions: (%d,%d)-(%d,%d)', [mapX0, mapY0, mapX1, mapY1]), MSG_WARNING);
+ e_WriteLog(Format('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0, mapY0, mapX1, mapY1, gMapInfo.Width, gMapInfo.Height]), MSG_WARNING);
+
+ if (mapX0 > 0) then mapX0 := 0;
+ if (mapY0 > 0) then mapY0 := 0;
+
+ if (mapX1 < gMapInfo.Width-1) then mapX1 := gMapInfo.Width-1;
+ if (mapY1 < gMapInfo.Height-1) then mapY1 := gMapInfo.Height-1;
- mapGrid := TPanelGrid.Create(mapX0-512, mapY0-512, mapX1-mapX0+1+512*2, mapY1-mapY0+1+512*2);
+ mapGrid := TPanelGrid.Create(mapX0-128, mapY0-128, mapX1-mapX0+1+128*2, mapY1-mapY0+1+128*2);
addPanelsToGrid(gWalls, PANEL_WALL);
addPanelsToGrid(gWalls, PANEL_CLOSEDOOR);
_textures := MapReader.GetTextures();
_texnummap := nil;
+ // Çàãðóçêà îïèñàíèÿ êàðòû:
+ e_WriteLog(' Reading map info...', MSG_NOTIFY);
+ g_Game_SetLoadingText(_lc[I_LOAD_MAP_HEADER], 0, False);
+ Header := MapReader.GetMapHeader();
+
+ with gMapInfo do
+ begin
+ Name := Header.MapName;
+ Description := Header.MapDescription;
+ Author := Header.MapAuthor;
+ MusicName := Header.MusicName;
+ SkyName := Header.SkyName;
+ Height := Header.Height;
+ Width := Header.Width;
+ end;
+
// Äîáàâëåíèå òåêñòóð â Textures[]:
if _textures <> nil then
begin
e_WriteLog('Creating map grid', MSG_NOTIFY);
mapCreateGrid();
-
// Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
if (triggers <> nil) and not gLoadGameMode then
begin
CreateMonster(monsters[a]);
end;
- // Çàãðóçêà îïèñàíèÿ êàðòû:
- e_WriteLog(' Reading map info...', MSG_NOTIFY);
- g_Game_SetLoadingText(_lc[I_LOAD_MAP_HEADER], 0, False);
- Header := MapReader.GetMapHeader();
-
MapReader.Free();
- with gMapInfo do
- begin
- Name := Header.MapName;
- Description := Header.MapDescription;
- Author := Header.MapAuthor;
- MusicName := Header.MusicName;
- SkyName := Header.SkyName;
- Height := Header.Height;
- Width := Header.Width;
- end;
-
// Çàãðóçêà íåáà:
if gMapInfo.SkyName <> '' then
begin
if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(gWalls[ID].PanelType, ID);
{$IFDEF MAP_DEBUG_ENABLED_FLAG}
- e_WriteLog(Format('wall #%d(%d) enabled (%d) (%d,%d)-(%d,%d)', [Integer(ID), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.x, pan.y, pan.width, pan.height]), MSG_NOTIFY);
+ //e_WriteLog(Format('wall #%d(%d) enabled (%d) (%d,%d)-(%d,%d)', [Integer(ID), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.x, pan.y, pan.width, pan.height]), MSG_NOTIFY);
{$ENDIF}
end;
if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pan.PanelType, ID);
{$IFDEF MAP_DEBUG_ENABLED_FLAG}
- e_WriteLog(Format('wall #%d(%d) disabled (%d) (%d,%d)-(%d,%d)', [Integer(ID), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.x, pan.y, pan.width, pan.height]), MSG_NOTIFY);
+ //e_WriteLog(Format('wall #%d(%d) disabled (%d) (%d,%d)-(%d,%d)', [Integer(ID), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.x, pan.y, pan.width, pan.height]), MSG_NOTIFY);
{$ENDIF}
end;
index a52ddf1738be26e9b78ebd1e22cbd34ba76cbc55..719a2b759d9da4b136d3c97275d411f187963cae 100644 (file)
--- a/src/game/g_monsters.pas
+++ b/src/game/g_monsters.pas
interface
uses
- g_basic, e_graphics, g_phys, g_textures,
+ g_basic, e_graphics, g_phys, g_textures, g_grid,
g_saveload, BinEditor, g_panel, xprofiler;
const
FFireAttacker: Word;
vilefire: TAnimation;
+ {$IF DEFINED(D2F_DEBUG)}
+ public
+ {$ENDIF}
proxyId: Integer; // node in dyntree or -1
arrIdx: Integer; // in gMonsters
+ {$IF DEFINED(D2F_DEBUG)}
+ private
+ {$ENDIF}
FDieTriggers: Array of Integer;
FSpawnTrigger: Integer;
profMonsLOS: TProfiler = nil; //WARNING: FOR DEBUGGING ONLY!
+type
+ TMonsterGrid = specialize TBodyGridBase<TMonster>;
+
+var
+ monsGrid: TMonsterGrid = nil;
+
+
+var
+ gmon_debug_think: Boolean = true;
+
+
implementation
uses
e_log, g_main, g_sound, g_gfx, g_player, g_game,
g_weapons, g_triggers, MAPDEF, g_items, g_options,
g_console, g_map, Math, SysUtils, g_menu, wadreader,
- g_language, g_netmsg, g_grid;
+ g_language, g_netmsg;
// ////////////////////////////////////////////////////////////////////////// //
// ////////////////////////////////////////////////////////////////////////// //
-type
- TMonsterGrid = specialize TBodyGridBase<TMonster>;
-
-var
- monsGrid: TMonsterGrid = nil;
-
-
function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
begin
if not assigned(cb) then begin result := nil; exit; end;
gMon := True; // Äëÿ ðàáîòû BlockMon'à
- for a := 0 to High(gMonsters) do
+ if (gmon_debug_think) then
begin
- if (gMonsters[a] = nil) then continue;
- if not gMonsters[a].FRemoved then
+ for a := 0 to High(gMonsters) do
begin
- if g_Game_IsClient then
- gMonsters[a].ClientUpdate()
+ if (gMonsters[a] = nil) then continue;
+ if not gMonsters[a].FRemoved then
+ begin
+ if g_Game_IsClient then
+ gMonsters[a].ClientUpdate()
+ else
+ gMonsters[a].Update();
+ end
else
- gMonsters[a].Update();
- end
- else
- begin
- gMonsters[a].Free();
- gMonsters[a] := nil;
+ begin
+ gMonsters[a].Free();
+ gMonsters[a] := nil;
+ end;
end;
end;
end;
-///!!!FIXME!!!
function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
begin
- //result := false;
- //if g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon);
result := cb(mon);
end;
diff --git a/src/game/g_player.pas b/src/game/g_player.pas
index 8981721df6bbddeb5e0cde76baa242b1e8c0cab6..69cc9021fc74547423ced6a82f1c626c4155cb93 100644 (file)
--- a/src/game/g_player.pas
+++ b/src/game/g_player.pas
FDummy: Boolean;
FFireTime: Integer;
+ // debug: viewport offset
+ viewPortX, viewPortY, viewPortW, viewPortH: Integer;
+
+ function isValidViewPort (): Boolean; inline;
+
constructor Create(); virtual;
destructor Destroy(); override;
procedure Respawn(Silent: Boolean; Force: Boolean = False); virtual;
e_log, g_map, g_items, g_console, SysUtils, g_gfx, Math,
g_options, g_triggers, g_menu, MAPDEF, g_game, g_grid,
wadreader, g_main, g_monsters, CONFIG, g_language,
- g_net, g_netmsg;
+ g_net, g_netmsg, g_window, GL;
type
TBotProfile = record
{ T P l a y e r : }
+function TPlayer.isValidViewPort (): Boolean; inline; begin result := (viewPortW > 0) and (viewPortH > 0); end;
+
procedure TPlayer.BFGHit();
begin
g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
constructor TPlayer.Create();
begin
+ viewPortX := 0;
+ viewPortY := 0;
+ viewPortW := 0;
+ viewPortH := 0;
+
FIamBot := False;
FDummy := False;
FSpawned := False;
DrawAim();
end;
+
+var
+ plrMouseX: Integer = -666;
+ plrMouseY: Integer = -666;
+ vpx, vpy: Integer;
+ //vpw, vph: Integer;
+ laserX0, laserY0, laserX1, laserY1: Integer;
+ monMarkedUID: Integer = -1;
+
+function pmsCurMapX (): Integer; inline; begin result := plrMouseX+vpx; end;
+function pmsCurMapY (): Integer; inline; begin result := plrMouseY+vpy; end;
+
+procedure plrDebugMouse (msx, msy, but: Integer; bstate: Integer);
+
+ function wallToggle (pan: TPanel; tag: Integer): Boolean;
+ begin
+ result := false; // don't stop
+ if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
+ end;
+
+ function monsAtDump (mon: TMonster; tag: Integer): Boolean;
+ begin
+ result := false; // don't stop
+ e_WriteLog(Format('monster #%d; UID=%d', [mon.arrIdx, mon.UID]), MSG_NOTIFY);
+ monMarkedUID := mon.UID;
+ //if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
+ end;
+
+begin
+ plrMouseX := msx;
+ plrMouseY := msy;
+ //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
+ if (gPlayer1 = nil) then exit;
+
+ if (but = MouseLeft) then
+ begin
+ mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
+ exit;
+ end;
+
+ if (but = MouseRight) then
+ begin
+ monMarkedUID := -1;
+ e_WriteLog('===========================', MSG_NOTIFY);
+ monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, monsAtDump);
+ e_WriteLog('---------------------------', MSG_NOTIFY);
+ exit;
+ end;
+end;
+
+
+procedure plrDebugDrawMouse ();
+
+ function monsCollector (mon: TMonster; tag: Integer): Boolean;
+ var
+ ex, ey: Integer;
+ mx, my, mw, mh: Integer;
+ begin
+ result := false;
+ mon.getMapBox(mx, my, mw, mh);
+ e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
+ if lineAABBIntersects(laserX0, laserY0, laserX1, laserY1, mx, my, mw, mh, ex, ey) then
+ begin
+ e_DrawPoint(8, ex, ey, 0, 255, 0);
+ end;
+ end;
+
+var
+ mon: TMonster;
+ mx, my, mw, mh: Integer;
+begin
+ e_DrawPoint(4, plrMouseX, plrMouseY, 255, 0, 255);
+ if (gPlayer1 = nil) then exit;
+
+ //e_WriteLog(Format('(%d,%d)-(%d,%d)', [laserX0, laserY0, laserX1, laserY1]), MSG_NOTIFY);
+
+ glPushMatrix();
+ glTranslatef(-vpx, -vpy, 0);
+
+ g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
+
+ if (monMarkedUID <> -1) then
+ begin
+ mon := g_Monsters_ByUID(monMarkedUID);
+ if (mon <> nil) then
+ begin
+ mon.getMapBox(mx, my, mw, mh);
+ e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
+ end;
+ end;
+
+ //e_DrawPoint(16, laserX0, laserY0, 255, 255, 255);
+
+ glPopMatrix();
+end;
+
+
procedure TPlayer.DrawAim();
procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
- function monsCollector (mon: TMonster; tag: Integer): Boolean;
+ procedure drawTileGrid ();
var
- ex, ey: Integer;
- mx, my, mw, mh: Integer;
+ x, y: Integer;
begin
- result := false;
- mon.getMapBox(mx, my, mw, mh);
- e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
- if lineAABBIntersects(ax0, ay0, ax1, ay1, mx, my, mw, mh, ex, ey) then
+ y := mapGrid.gridY0;
+ while (y < mapGrid.gridY0+mapGrid.gridHeight) do
begin
- e_DrawPoint(8, ex, ey, 0, 255, 0);
+ x := mapGrid.gridX0;
+ while (x < mapGrid.gridX0+mapGrid.gridWidth) do
+ begin
+ if (x+mapGrid.tileSize > viewPortX) and (y+mapGrid.tileSize > viewPortY) and
+ (x < viewPortX+viewPortW) and (y < viewPortY+viewPortH) then
+ begin
+ e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96);
+ end;
+ Inc(x, mapGrid.tileSize);
+ end;
+ Inc(y, mapGrid.tileSize);
end;
end;
//mon: TMonster;
//mx, my, mw, mh: Integer;
begin
+ if isValidViewPort and (self = gPlayer1) then
+ begin
+ vpx := viewPortX;
+ vpy := viewPortY;
+ //vpw := viewPortW;
+ //vpy := viewPortH;
+ evMouseCB := plrDebugMouse;
+ postdrawMouse := plrDebugDrawMouse;
+ end;
+
+ laserX0 := ax0;
+ laserY0 := ay0;
+ laserX1 := ax1;
+ laserY1 := ay1;
+
e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
- if g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) then
+ if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
begin
e_DrawLine(sz, ax0, ay0, ex, ey, 0, 255, 0, 96);
- e_DrawPoint(4, ex, ey, 255, 127, 0);
end
else
begin
end;
}
- g_Mons_AlongLine(ax0, ay0, ax1, ay1, monsCollector, true);
+ drawTileGrid();
end;
var
end;
xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
- {$IF FALSE}
- e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
- {$ELSE}
+ {$IF DEFINED(D2F_DEBUG)}
drawCast(sz, wx, wy, xx, yy);
+ {$ELSE}
+ e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
{$ENDIF}
end;
diff --git a/src/game/g_weapons.pas b/src/game/g_weapons.pas
index ca4630ed2023d55edc648994e9021a736d8b9b53..aa78ebd94e7ddae5fa7f224eada8b21f0cf3f79e 100644 (file)
--- a/src/game/g_weapons.pas
+++ b/src/game/g_weapons.pas
stt := curTimeMicro();
{$ENDIF}
- wallHitFlag := g_Map_traceToNearestWall(x, y, x2, y2, @wallHitX, @wallHitY);
+ wallHitFlag := (g_Map_traceToNearestWall(x, y, x2, y2, @wallHitX, @wallHitY) <> nil);
if wallHitFlag then
begin
x2 := wallHitX;
diff --git a/src/game/g_window.pas b/src/game/g_window.pas
index c53cba0bb63cc4d259e4277edcfe6300d18efa84..f5c4618dfc59c9e32de902c998c4f82e87109861 100644 (file)
--- a/src/game/g_window.pas
+++ b/src/game/g_window.pas
gwin_has_stencil: Boolean = false;
gwin_k8_enable_light_experiments: Boolean = false;
+
+// both for but and for bstate
+const
+ MouseLeft = $0001;
+ MouseRight = $0002;
+ MouseMiddle = $0004;
+ MouseWheelUp = $0008;
+ MouseWheelDown = $0010;
+
+type
+ // but=0: motion; but <0: release, do (-but) to get MouseXXX
+ // on press, bstate will contain pressed button; on release it won't
+ TMouseHandler = procedure (x, y, but: Integer; bstate: Integer);
+
+var
+ evMouseCB: TMouseHandler = nil;
+
+
implementation
uses
ticksOverflow: Int64 = -1;
lastTicks: Uint32 = 0; // to detect overflow
{$ENDIF}
+ curMsButState: Integer = 0;
+ curMsX: Integer = 0;
+ curMsY: Integer = 0;
const
// TODO: move this to a separate file
SDL_WINDOWEVENT_MINIMIZED:
begin
+ curMsButState := 0;
if not wMinimized then
begin
e_ResizeWindow(0, 0);
SDL_WINDOWEVENT_RESTORED:
begin
+ curMsButState := 0;
if wMinimized then
begin
e_ResizeWindow(gScreenWidth, gScreenHeight);
begin
wActivate := True;
//e_WriteLog('window gained focus!', MSG_NOTIFY);
+ curMsButState := 0;
end;
SDL_WINDOWEVENT_FOCUS_LOST:
begin
wDeactivate := True;
//e_WriteLog('window lost focus!', MSG_NOTIFY);
+ curMsButState := 0;
end;
end;
key, keychr: Word;
uc: UnicodeChar;
//joy: Integer;
+ but: Integer;
+
+ function buildBut (b: Byte): Integer;
+ begin
+ result := 0;
+ case b of
+ SDL_BUTTON_LEFT: result := result or MouseLeft;
+ SDL_BUTTON_MIDDLE: result := result or MouseMiddle;
+ SDL_BUTTON_RIGHT: result := result or MouseRight;
+ end;
+ end;
+
+ function buildButState (b: Byte): Integer;
+ begin
+ result := 0;
+ case b of
+ SDL_BUTTON_LEFT: result := result or MouseLeft;
+ SDL_BUTTON_MIDDLE: result := result or MouseMiddle;
+ SDL_BUTTON_RIGHT: result := result or MouseRight;
+ end;
+ end;
begin
Result := False;
case ev.type_ of
KeyPress(key);
end;
+ SDL_MOUSEBUTTONDOWN:
+ begin
+ curMsX := ev.button.x;
+ curMsY := ev.button.y;
+ but := buildBut(ev.button.button);
+ if (but <> 0) then
+ begin
+ // ev.button.clicks: Byte
+ curMsButState := curMsButState or but;
+ if assigned(evMouseCB) then evMouseCB(ev.button.x, ev.button.y, but, curMsButState);
+ end;
+ end;
+ SDL_MOUSEBUTTONUP:
+ begin
+ curMsX := ev.button.x;
+ curMsY := ev.button.y;
+ but := buildBut(ev.button.button);
+ if (but <> 0) then
+ begin
+ curMsButState := curMsButState and (not but);
+ if assigned(evMouseCB) then evMouseCB(ev.button.x, ev.button.y, -but, curMsButState);
+ end;
+ end;
+ SDL_MOUSEWHEEL:
+ begin
+ if assigned(evMouseCB) then
+ begin
+ (*
+ if (ev.wheel.direction = SDL_MOUSEWHEEL_FLIPPED) then
+ begin
+ ev.wheel.x := -ev.wheel.x;
+ ev.wheel.y := -ev.wheel.y;
+ end;
+ *)
+ if (ev.wheel.y > 0) then evMouseCB(curMsX, curMsY, MouseWheelUp, curMsButState);
+ if (ev.wheel.y < 0) then evMouseCB(curMsX, curMsY, MouseWheelDown, curMsButState);
+ end;
+ end;
+ SDL_MOUSEMOTION:
+ begin
+ curMsX := ev.motion.x;
+ curMsY := ev.motion.y;
+ if assigned(evMouseCB) then evMouseCB(curMsX, curMsY, 0, curMsButState);
+ end;
+
SDL_TEXTINPUT:
begin
Utf8ToUnicode(@uc, PChar(ev.text.text), 1);