From: Ketmar Dark Date: Wed, 23 Aug 2017 00:20:27 +0000 (+0300) Subject: alot of debugging code X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=c185246bfc49a2ae31fc79ef7c73dc6bcc1073e2;p=d2df-sdl.git alot of debugging code --- diff --git a/src/game/g_basic.pas b/src/game/g_basic.pas index 2300b13..5317747 100644 --- a/src/game/g_basic.pas +++ b/src/game/g_basic.pas @@ -207,7 +207,7 @@ begin // `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 a5652ce..c9568f0 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -414,6 +414,8 @@ begin 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 3ae3e82..99e1a3d 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -316,6 +316,8 @@ var 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); @@ -767,8 +769,10 @@ begin 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); @@ -2898,6 +2902,11 @@ begin //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 @@ -3265,6 +3274,8 @@ begin 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; @@ -4979,6 +4990,7 @@ begin 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 925fb80..c6fe095 100644 --- a/src/game/g_grid.pas +++ b/src/game/g_grid.pas @@ -64,6 +64,9 @@ type //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 @@ -1316,8 +1319,10 @@ var 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; @@ -1331,6 +1336,8 @@ begin 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); @@ -1410,6 +1417,34 @@ begin 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)} @@ -1431,6 +1466,7 @@ begin 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 0b573c2..6bae369 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -93,7 +93,7 @@ procedure g_Map_LoadState(Var Mem: TBinMemoryReader); 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 @@ -184,9 +184,17 @@ var 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; + +var + mapGrid: TPanelGrid = nil; + + implementation uses @@ -204,10 +212,6 @@ const FLAG_SIGNATURE = $47414C46; // 'FLAG' -type - TPanelGrid = specialize TBodyGridBase; - - function panelTypeToTag (panelType: Word): Integer; begin case panelType of @@ -255,7 +259,6 @@ var RespawnPoints: Array of TRespawnPoint; FlagPoints: Array [FLAG_RED..FLAG_BLUE] of PFlagPoint; //DOMFlagPoints: Array of TFlagPoint; - mapGrid: TPanelGrid = nil; procedure g_Map_ProfilersBegin (); @@ -279,12 +282,12 @@ end; // 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; @@ -1158,9 +1161,15 @@ begin 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); @@ -1267,6 +1276,22 @@ begin _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 @@ -1526,7 +1551,6 @@ begin e_WriteLog('Creating map grid', MSG_NOTIFY); mapCreateGrid(); - // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû: if (triggers <> nil) and not gLoadGameMode then begin @@ -1592,24 +1616,8 @@ 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 @@ -2380,7 +2388,7 @@ 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; @@ -2398,7 +2406,7 @@ begin 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; diff --git a/src/game/g_monsters.pas b/src/game/g_monsters.pas index a52ddf1..719a2b7 100644 --- a/src/game/g_monsters.pas +++ b/src/game/g_monsters.pas @@ -19,7 +19,7 @@ unit g_monsters; 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 @@ -80,8 +80,14 @@ type 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; @@ -226,13 +232,24 @@ var profMonsLOS: TProfiler = nil; //WARNING: FOR DEBUGGING ONLY! +type + TMonsterGrid = specialize TBodyGridBase; + +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; // ////////////////////////////////////////////////////////////////////////// // @@ -278,13 +295,6 @@ end; // ////////////////////////////////////////////////////////////////////////// // -type - TMonsterGrid = specialize TBodyGridBase; - -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; @@ -1293,20 +1303,23 @@ begin 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; @@ -4569,13 +4582,10 @@ begin 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 8981721..69cc902 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -249,6 +249,11 @@ type 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; @@ -521,7 +526,7 @@ uses 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 @@ -1845,6 +1850,8 @@ end; { 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), @@ -1988,6 +1995,11 @@ end; constructor TPlayer.Create(); begin + viewPortX := 0; + viewPortY := 0; + viewPortW := 0; + viewPortH := 0; + FIamBot := False; FDummy := False; FSpawned := False; @@ -2303,20 +2315,124 @@ begin 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; @@ -2325,11 +2441,25 @@ procedure TPlayer.DrawAim(); //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 @@ -2353,7 +2483,7 @@ procedure TPlayer.DrawAim(); end; } - g_Mons_AlongLine(ax0, ay0, ax1, ay1, monsCollector, true); + drawTileGrid(); end; var @@ -2442,10 +2572,10 @@ begin 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 ca4630e..aa78ebd 100644 --- a/src/game/g_weapons.pas +++ b/src/game/g_weapons.pas @@ -1512,7 +1512,7 @@ begin 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 c53cba0..f5c4618 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -41,6 +41,24 @@ var 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 @@ -69,6 +87,9 @@ var 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 @@ -242,6 +263,7 @@ begin SDL_WINDOWEVENT_MINIMIZED: begin + curMsButState := 0; if not wMinimized then begin e_ResizeWindow(0, 0); @@ -293,6 +315,7 @@ begin SDL_WINDOWEVENT_RESTORED: begin + curMsButState := 0; if wMinimized then begin e_ResizeWindow(gScreenWidth, gScreenHeight); @@ -312,12 +335,14 @@ begin 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; @@ -373,6 +398,27 @@ var 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 @@ -400,6 +446,51 @@ begin 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);