From: Ketmar Dark Date: Thu, 24 Aug 2017 01:06:38 +0000 (+0300) Subject: particle code uglyfying; more gitiks in holmes X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=4caa7355c2a35f38ee6fbd541cfed72751a520a4;p=d2df-sdl.git particle code uglyfying; more gitiks in holmes --- diff --git a/src/game/g_gfx.pas b/src/game/g_gfx.pas index d90fa3b..ab89576 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_NEW_SPARK_THINKER} unit g_gfx; interface @@ -67,7 +68,7 @@ var 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; @@ -537,17 +538,24 @@ end; // ////////////////////////////////////////////////////////////////////////// // 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 @@ -556,22 +564,30 @@ begin 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; @@ -587,23 +603,52 @@ begin 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 @@ -630,18 +675,18 @@ begin 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 7d4259c..a7cefab 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -102,14 +102,17 @@ var 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 @@ -143,6 +146,7 @@ var laserX0, laserY0, laserX1, laserY1: Integer; monMarkedUID: Integer = -1; + procedure g_Holmes_plrView (viewPortX, viewPortY, viewPortW, viewPortH: Integer); begin vpSet := true; @@ -172,8 +176,11 @@ procedure plrDebugMouse (var ev: THMouseEvent); 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; @@ -397,9 +404,9 @@ begin 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 @@ -414,9 +421,9 @@ 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; @@ -436,7 +443,14 @@ 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; @@ -502,6 +516,34 @@ begin 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 bbe1d6c..2c2a6b5 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -92,9 +92,14 @@ procedure g_Map_LoadState(Var Mem: TBinMemoryReader); 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 @@ -299,6 +304,24 @@ begin 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;