From 5c72767aba48c236cd81972a6d79ff67b64ecd92 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Thu, 21 Sep 2017 23:00:06 +0300 Subject: [PATCH] hashtable cosmetix; holmes scissoring fixes --- src/game/g_holmes.inc | 28 +++++++++++++ src/game/g_holmes.pas | 84 +++++++++++++++++++-------------------- src/game/g_holmes_cmd.inc | 5 +-- src/game/g_triggers.pas | 8 ++-- src/shared/hashtable.pas | 28 ++++++++----- 5 files changed, 93 insertions(+), 60 deletions(-) diff --git a/src/game/g_holmes.inc b/src/game/g_holmes.inc index 3cfdd17..c053b4c 100644 --- a/src/game/g_holmes.inc +++ b/src/game/g_holmes.inc @@ -153,6 +153,34 @@ begin end; +// ////////////////////////////////////////////////////////////////////////// // +type + TScissorSave = record + public + wassc: Boolean; + scxywh: packed array[0..3] of GLint; + + public + procedure save (enableScissoring: Boolean); + procedure restore (); + end; + +procedure TScissorSave.save (enableScissoring: Boolean); +begin + wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0); + if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]); + //conwritefln('(%d,%d)-(%d,%d)', [scxywh[0], scxywh[1], scxywh[2], scxywh[3]]); + if enableScissoring then glEnable(GL_SCISSOR_TEST); +end; + + +procedure TScissorSave.restore (); +begin + glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]); + if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST); +end; + + // ////////////////////////////////////////////////////////////////////////// // // fonts const kgiFont6: array[0..256*8-1] of Byte = ( diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas index e64c205..33db7d0 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -1035,8 +1035,6 @@ var begin if (vpw < 2) or (vph < 2) then exit; - glScissor(0, gScreenHeight-gPlayerScreenSize.Y, gPlayerScreenSize.X, gPlayerScreenSize.Y); - glEnable(GL_SCISSOR_TEST); if g_ol_rlayer_back then doWallsOld(gRenderBackgrounds, PANEL_BACK, 255, 127, 0); if g_ol_rlayer_step then doWallsOld(gSteps, PANEL_STEP, 192, 192, 192); if g_ol_rlayer_wall then doWallsOld(gWalls, PANEL_WALL, 255, 255, 255); @@ -1045,8 +1043,6 @@ begin if g_ol_rlayer_acid2 then doWallsOld(gAcid2, PANEL_ACID2, 198, 198, 0); if g_ol_rlayer_water then doWallsOld(gWater, PANEL_WATER, 0, 255, 255); if g_ol_rlayer_fore then doWallsOld(gRenderForegrounds, PANEL_FORE, 210, 210, 210); - glScissor(0, 0, gScreenWidth, gScreenHeight); - glDisable(GL_SCISSOR_TEST); end; {$ENDIF} @@ -1357,6 +1353,7 @@ procedure plrDebugDraw (); end; var + scisave: TScissorSave; mon: TMonster; mx, my, mw, mh: Integer; //pan: TPanel; @@ -1364,58 +1361,61 @@ var begin if (gPlayer1 = nil) then exit; - glEnable(GL_SCISSOR_TEST); - glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph); - + scisave.save(true); // enable scissoring glPushMatrix(); - glScalef(g_dbg_scale, g_dbg_scale, 1.0); - glTranslatef(-vpx, -vpy, 0); + try + //glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph); + glScissor(0, gScreenHeight-gPlayerScreenSize.Y-1, gPlayerScreenSize.X, gPlayerScreenSize.Y); - if (showGrid) then drawTileGrid(); - drawOutlines(); + glScalef(g_dbg_scale, g_dbg_scale, 1.0); + glTranslatef(-vpx, -vpy, 0); - if (laserSet) then g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true); + if (showGrid) then drawTileGrid(); + drawOutlines(); - if (monMarkedUID <> -1) then - begin - mon := g_Monsters_ByUID(monMarkedUID); - if (mon <> nil) then + if (laserSet) then g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true); + + if (monMarkedUID <> -1) then begin - mon.getMapBox(mx, my, mw, mh); - e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30); - drawMonsterInfo(mon); + 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); + drawMonsterInfo(mon); + end; end; - end; - if showAllMonsCells and showGrid then g_Mons_ForEach(highlightAllMonsterCells); - if showTriggers then drawTriggers(); - if showGrid then drawSelectedPlatformCells(); + if showAllMonsCells and showGrid then g_Mons_ForEach(highlightAllMonsterCells); + if showTriggers then drawTriggers(); + if showGrid then drawSelectedPlatformCells(); - //drawAwakeCells(); + //drawAwakeCells(); - if showTraceBox then drawTraceBox(); + if showTraceBox then drawTraceBox(); - //drawGibsBoxes(); + //drawGibsBoxes(); - //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey); - (* - {$IF DEFINED(D2F_DEBUG)} - mapGrid.dbgRayTraceTileHitCB := hilightCell1; - {$ENDIF} - pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid)); - if (pan <> nil) then writeln('end=(', ex, ',', ey, ')'); - {$IF DEFINED(D2F_DEBUG)} - mapGrid.dbgRayTraceTileHitCB := nil; - {$ENDIF} - - pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid)); - if (pan <> nil) then writeln('hit!'); - *) + //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey); + (* + {$IF DEFINED(D2F_DEBUG)} + mapGrid.dbgRayTraceTileHitCB := hilightCell1; + {$ENDIF} + pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid)); + if (pan <> nil) then writeln('end=(', ex, ',', ey, ')'); + {$IF DEFINED(D2F_DEBUG)} + mapGrid.dbgRayTraceTileHitCB := nil; + {$ENDIF} - glPopMatrix(); + pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid)); + if (pan <> nil) then writeln('hit!'); + *) - glDisable(GL_SCISSOR_TEST); + finally + glPopMatrix(); + scisave.restore(); + end; if showMapCurPos then drawText8(4, gWinSizeY-10, Format('mappos:(%d,%d)', [pmsCurMapX, pmsCurMapY]), 255, 255, 0); end; diff --git a/src/game/g_holmes_cmd.inc b/src/game/g_holmes_cmd.inc index 63b0ae5..578f865 100644 --- a/src/game/g_holmes_cmd.inc +++ b/src/game/g_holmes_cmd.inc @@ -110,12 +110,9 @@ end; // ////////////////////////////////////////////////////////////////////////// // -function ansistrEquCB (constref a, b: AnsiString): Boolean; begin result := (a = b); end; -function ansistrHashCB (constref a: AnsiString): LongWord; begin if (Length(a) > 0) then result := fnvHash(PChar(a)^, Length(a)) else result := 0; end; - function hashNewCommand (): TCmdHash; begin - result := TCmdHash.Create(ansistrHashCB, ansistrEquCB); + result := TCmdHash.Create(hashStrHash, hashStrEqu, hashStrFree); end; diff --git a/src/game/g_triggers.pas b/src/game/g_triggers.pas index f378cd1..ac5a523 100644 --- a/src/game/g_triggers.pas +++ b/src/game/g_triggers.pas @@ -24,8 +24,6 @@ uses xdynrec, hashtable, exoma; type - THashStrVariant = specialize THashBase; - TActivator = record UID: Word; TimeOut: Word; @@ -237,7 +235,7 @@ begin if (Length(afldname) > 4) and (afldname[1] = 'u') and (afldname[2] = 's') and (afldname[3] = 'e') and (afldname[4] = 'r') then begin - if (me.userVars = nil) then me.userVars := THashStrVariant.Create(hashStrHash, hashStrEqu); + if (me.userVars = nil) then me.userVars := hashNewStrVariant(); me.userVars.put(afldname, aval); exit; end; @@ -2438,7 +2436,7 @@ begin // update cached trigger variables trigUpdateCacheData(ptg^, ptg.trigDataRec); - ptg.userVars := nil; //THashStrVariant.Create(hashStrHash, hashStrEqu); + ptg.userVars := nil; try ptg.exoThink := TExprBase.parseStatList(tgclist, VarToStr(trec.user['exoma_think'])); @@ -3339,7 +3337,7 @@ begin if (uvcount < 0) or (uvcount > 1024*1024) then raise XStreamError.Create('invalid number of user vars in trigger'); if (uvcount > 0) then begin - gTriggers[i].userVars := THashStrVariant.Create(hashStrHash, hashStrEqu); + gTriggers[i].userVars := hashNewStrVariant(); vv := Unassigned; while (uvcount > 0) do begin diff --git a/src/shared/hashtable.pas b/src/shared/hashtable.pas index 85133c3..495f432 100644 --- a/src/shared/hashtable.pas +++ b/src/shared/hashtable.pas @@ -185,12 +185,14 @@ type THashStrInt = specialize THashBase; THashIntStr = specialize THashBase; THashStrStr = specialize THashBase; + THashStrVariant = specialize THashBase; -function hashNewIntInt (): THashIntInt; -function hashNewStrInt (): THashStrInt; -function hashNewIntStr (): THashIntStr; -function hashNewStrStr (): THashStrStr; +function hashNewIntInt (): THashIntInt; inline; +function hashNewStrInt (): THashStrInt; inline; +function hashNewIntStr (): THashIntStr; inline; +function hashNewStrStr (): THashStrStr; inline; +function hashNewStrVariant (): THashStrVariant; inline; function u32Hash (a: LongWord): LongWord; inline; @@ -206,12 +208,13 @@ function hashIntHash (constref k: Integer): LongWord; function hashStrEqu (constref a, b: AnsiString): Boolean; function hashStrHash (constref k: AnsiString): LongWord; procedure hashStrFree (var s: AnsiString); +procedure hashVariantFree (var v: Variant); implementation uses - SysUtils; + SysUtils, Variants; // ////////////////////////////////////////////////////////////////////////// // @@ -235,6 +238,7 @@ end; function hashIntEqu (constref a, b: Integer): Boolean; begin result := (a = b); end; function hashStrEqu (constref a, b: AnsiString): Boolean; begin result := (a = b); end; procedure hashStrFree (var s: AnsiString); begin s := ''; end; +procedure hashVariantFree (var v: Variant); begin v := Unassigned; end; {$PUSH} {$RANGECHECKS OFF} @@ -257,30 +261,36 @@ end; {$POP} -function hashNewIntInt (): THashIntInt; +function hashNewIntInt (): THashIntInt; inline; begin result := THashIntInt.Create(hashIntHash, hashIntEqu); end; -function hashNewStrInt (): THashStrInt; +function hashNewStrInt (): THashStrInt; inline; begin result := THashStrInt.Create(hashStrHash, hashStrEqu, hashStrFree); end; -function hashNewIntStr (): THashIntStr; +function hashNewIntStr (): THashIntStr; inline; begin result := THashIntStr.Create(hashIntHash, hashIntEqu, nil, hashStrFree); end; -function hashNewStrStr (): THashStrStr; +function hashNewStrStr (): THashStrStr; inline; begin result := THashStrStr.Create(hashStrHash, hashStrEqu, hashStrFree, hashStrFree); end; +function hashNewStrVariant (): THashStrVariant; inline; +begin + result := THashStrVariant.Create(hashStrHash, hashStrEqu, hashStrFree, hashVariantFree); +end; + + // ////////////////////////////////////////////////////////////////////////// // {$PUSH} {$RANGECHECKS OFF} -- 2.29.2