From: Ketmar Dark Date: Sun, 27 Aug 2017 15:12:06 +0000 (+0300) Subject: Holmes should eat player keys now X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=commitdiff_plain;h=d46592a9a1b2cb649e26f30e54622708334b5061 Holmes should eat player keys now --- diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas index 021c3dd..6e208d7 100644 --- a/src/engine/e_input.pas +++ b/src/engine/e_input.pas @@ -105,6 +105,9 @@ function e_JoyAxisToKey(id: Word; ax: Byte; dir: Byte): Word; function e_JoyHatToKey(id: Word; hat: Byte; dir: Byte): Word; procedure e_SetKeyState(key: Word; state: Integer); +procedure e_UnpressAllKeys (); +procedure e_KeyUpDown (key: Word; down: Boolean); + var {e_MouseInfo: TMouseInfo;} e_EnableInput: Boolean = False; @@ -188,6 +191,21 @@ begin SetLength(Joysticks, 0); end; + +procedure e_UnpressAllKeys (); +var + i: Integer; +begin + for i := 0 to High(KeyBuffer) do KeyBuffer[i] := False; +end; + + +procedure e_KeyUpDown (key: Word; down: Boolean); +begin + if (key > 0) and (key < Length(KeyBuffer)) then KeyBuffer[key] := down; +end; + + function PollKeyboard(): Boolean; var Keys: PByte; @@ -196,12 +214,12 @@ var begin Result := False; Keys := SDL_GetKeyboardState(@NKeys); - if (Keys = nil) or (NKeys < 1) then - Exit; + if (Keys = nil) or (NKeys < 1) then Exit; for i := 0 to NKeys do - KeyBuffer[i] := ((PByte(NativeUInt(Keys) + i)^) <> 0); - for i := NKeys to High(KeyBuffer) do - KeyBuffer[i] := False; + begin + if ((PByte(NativeUInt(Keys) + i)^) <> 0) then KeyBuffer[i] := false; + end; + for i := NKeys to High(KeyBuffer) do KeyBuffer[i] := False; end; function PollJoysticks(): Boolean; diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas index 98c458c..3a50ffa 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -312,30 +312,23 @@ begin end; +var + olEdgeL: array of Boolean = nil; + olEdgeR: array of Boolean = nil; + olEdgeU: array of Boolean = nil; + olEdgeD: array of Boolean = nil; + +procedure drawOutlines (); +begin +end; + + procedure plrDebugDraw (); procedure drawTileGrid (); var x, y: Integer; begin - { - y := mapGrid.gridY0; - while (y < mapGrid.gridY0+mapGrid.gridHeight) do - begin - x := mapGrid.gridX0; - while (x < mapGrid.gridX0+mapGrid.gridWidth) do - begin - if (x+mapGrid.tileSize > vpx) and (y+mapGrid.tileSize > vpy) and - (x < vpx+vpw) and (y < vpy+vph) then - begin - //e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96); - drawRect(x, y, mapGrid.tileSize, mapGrid.tileSize, 96, 96, 96, 255); - end; - Inc(x, mapGrid.tileSize); - end; - Inc(y, mapGrid.tileSize); - end; - } for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do begin drawLine(mapGrid.gridX0, mapGrid.gridY0+y*mapGrid.tileSize, mapGrid.gridX0+mapGrid.gridWidth, mapGrid.gridY0+y*mapGrid.tileSize, 96, 96, 96, 255); @@ -493,6 +486,8 @@ begin glPushMatrix(); glTranslatef(-vpx, -vpy, 0); + drawOutlines(); + if (showGrid) then drawTileGrid(); if (laserSet) then g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true); diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 40f7402..17aa047 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -250,6 +250,7 @@ begin begin curMsButState := 0; curKbState := 0; + e_UnpressAllKeys(); if not wMinimized then begin e_ResizeWindow(0, 0); @@ -336,6 +337,7 @@ begin curMsButState := 0; curKbState := 0; wDeactivate := True; + e_UnpressAllKeys(); //e_WriteLog('window lost focus!', MSG_NOTIFY); g_Holmes_WindowBlured(); end; @@ -450,9 +452,14 @@ begin kbev.sym := ev.key.keysym.sym; kbev.bstate := curMsButState; kbev.kstate := curKbState; - if g_Holmes_keyEvent(kbev) then exit; + if g_Holmes_keyEvent(kbev) then + begin + if (ev.type_ <> SDL_KEYDOWN) then e_KeyUpDown(ev.key.keysym.scancode, false); + exit; + end; end; if (ev.type_ = SDL_KEYDOWN) then KeyPress(key); + e_KeyUpDown(ev.key.keysym.scancode, (ev.type_ = SDL_KEYDOWN)); end; SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP: