1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
23 g_textures
, g_basic
, e_graphics
, g_phys
, g_grid
, g_player
, g_monsters
,
24 g_window
, g_map
, g_triggers
, g_items
, g_game
, g_panel
, g_console
,
32 // both for but and for bstate
45 kind
: Byte; // motion, press, release
47 dx
, dy
: Integer; // for wheel this is wheel motion, otherwise this is relative mouse motion
48 but
: Word; // current pressed button or 0
49 bstate
: Word; // button state
50 kstate
: Word; // keyboard state (see THKeyEvent);
62 procedure g_Holmes_VidModeChanged ();
63 procedure g_Holmes_WindowFocused ();
64 procedure g_Holmes_WindowBlured ();
66 procedure g_Holmes_Draw ();
68 function g_Holmes_mouseEvent (var ev
: THMouseEvent
): Boolean; // returns `true` if event was eaten
69 function g_Holmes_KeyEvent (var ev
: THKeyEvent
): Boolean; // returns `true` if event was eaten
72 procedure g_Holmes_plrView (viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer);
73 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
84 //globalInited: Boolean = false;
87 msB
: Word = 0; // button state
88 kbS
: Word = 0; // keyboard modifiers state
91 // ////////////////////////////////////////////////////////////////////////// //
92 // cursor (hi, Death Track!)
96 const cursorImg
: array[0..curWidth
*curHeight
-1] of Byte = (
97 0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
98 0,0,3,2,0,0,0,0,0,0,0,0,0,0,0,0,0,
99 1,0,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,
100 1,1,3,3,2,2,0,0,0,0,0,0,0,0,0,0,0,
101 1,1,3,3,4,2,2,0,0,0,0,0,0,0,0,0,0,
102 1,1,3,3,4,4,2,2,0,0,0,0,0,0,0,0,0,
103 1,1,3,3,4,4,4,2,2,0,0,0,0,0,0,0,0,
104 1,1,3,3,4,4,4,4,2,2,0,0,0,0,0,0,0,
105 1,1,3,3,4,4,4,5,6,2,2,0,0,0,0,0,0,
106 1,1,3,3,4,4,5,6,7,5,2,2,0,0,0,0,0,
107 1,1,3,3,4,5,6,7,5,4,5,2,2,0,0,0,0,
108 1,1,3,3,5,6,7,5,4,5,6,7,2,2,0,0,0,
109 1,1,3,3,6,7,5,4,5,6,7,7,7,2,2,0,0,
110 1,1,3,3,7,5,4,5,6,7,7,7,7,7,2,2,0,
111 1,1,3,3,5,4,5,6,8,8,8,8,8,8,8,8,2,
112 1,1,3,3,4,5,6,3,8,8,8,8,8,8,8,8,8,
113 1,1,3,3,5,6,3,3,1,1,1,1,1,1,1,0,0,
114 1,1,3,3,6,3,3,1,1,1,1,1,1,1,1,0,0,
115 1,1,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,
116 1,1,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,
117 1,1,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,
118 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
119 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
121 const cursorPal
: array[0..9*4-1] of Byte = (
135 curtexid
: GLuint
= 0;
137 procedure createCursorTexture ();
143 if (curtexid
<> 0) then exit
; //begin glDeleteTextures(1, @curtexid); curtexid := 0; end;
145 GetMem(tex
, curWidth
*curHeight
*4);
148 for y
:= 0 to curHeight
-1 do
150 for x
:= 0 to curWidth
-1 do
152 c
:= cursorImg
[y
*curWidth
+x
]*4;
153 tpp
^ := cursorPal
[c
+0]; Inc(tpp
);
154 tpp
^ := cursorPal
[c
+1]; Inc(tpp
);
155 tpp
^ := cursorPal
[c
+2]; Inc(tpp
);
156 tpp
^ := cursorPal
[c
+3]; Inc(tpp
);
160 glGenTextures(1, @curtexid
);
161 if (curtexid
= 0) then raise Exception
.Create('can''t create Holmes texture');
163 glBindTexture(GL_TEXTURE_2D
, curtexid
);
164 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
165 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
166 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
167 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
169 //GLfloat[4] bclr = 0.0;
170 //glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, bclr.ptr);
172 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, curWidth
, curHeight
, 0, GL_RGBA
{gltt}, GL_UNSIGNED_BYTE
, tex
);
178 procedure drawCursor ();
180 if (curtexid
= 0) then createCursorTexture() else glBindTexture(GL_TEXTURE_2D
, curtexid
);
183 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
184 glEnable(GL_TEXTURE_2D
);
186 glColor4f(1, 1, 1, 0.9);
189 glTexCoord2f(0.0, 0.0); glVertex2i(msX
, msY
); // top-left
190 glTexCoord2f(1.0, 0.0); glVertex2i(msX
+curWidth
, msY
); // top-right
191 glTexCoord2f(1.0, 1.0); glVertex2i(msX
+curWidth
, msY
+curHeight
); // bottom-right
192 glTexCoord2f(0.0, 1.0); glVertex2i(msX
, msY
+curHeight
); // bottom-left
196 glDisable(GL_TEXTURE_2D
);
197 glColor4f(1, 1, 1, 1);
198 glBindTexture(GL_TEXTURE_2D
, 0);
202 // ////////////////////////////////////////////////////////////////////////// //
203 procedure g_Holmes_VidModeChanged ();
205 e_WriteLog(Format('Inspector: videomode changed: %dx%d', [gScreenWidth
, gScreenHeight
]), MSG_NOTIFY
);
206 curtexid
:= 0; // texture is possibly lost here, idc
207 //createCursorTexture();
210 procedure g_Holmes_WindowFocused ();
216 procedure g_Holmes_WindowBlured ();
221 // ////////////////////////////////////////////////////////////////////////// //
223 vpSet
: Boolean = false;
226 laserSet
: Boolean = false;
227 laserX0
, laserY0
, laserX1
, laserY1
: Integer;
228 monMarkedUID
: Integer = -1;
230 procedure g_Holmes_plrView (viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer);
239 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
249 function pmsCurMapX (): Integer; inline; begin result
:= msX
+vpx
; end;
250 function pmsCurMapY (): Integer; inline; begin result
:= msY
+vpy
; end;
253 procedure plrDebugMouse (var ev
: THMouseEvent
);
255 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
257 result
:= false; // don't stop
258 if pan
.Enabled
then g_Map_DisableWall(pan
.arrIdx
) else g_Map_EnableWall(pan
.arrIdx
);
261 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
263 result
:= false; // don't stop
264 e_WriteLog(Format('monster #%d; UID=%d', [mon
.arrIdx
, mon
.UID
]), MSG_NOTIFY
);
265 monMarkedUID
:= mon
.UID
;
266 //if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
270 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
271 if (gPlayer1
= nil) then exit
;
272 if (ev
.kind
<> THMouseEvent
.Press
) then exit
;
274 if (ev
.but
= THMouseEvent
.Left
) then
276 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
280 if (ev
.but
= THMouseEvent
.Right
) then
283 e_WriteLog('===========================', MSG_NOTIFY
);
284 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
285 e_WriteLog('---------------------------', MSG_NOTIFY
);
291 procedure plrDebugDraw ();
293 function monsCollector (mon
: TMonster
; tag
: Integer): Boolean;
296 mx
, my
, mw
, mh
: Integer;
299 mon
.getMapBox(mx
, my
, mw
, mh
);
300 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 255, 0, 96);
301 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
303 e_DrawPoint(8, ex
, ey
, 0, 255, 0);
309 mx
, my
, mw
, mh
: Integer;
311 //e_DrawPoint(4, plrMouseX, plrMouseY, 255, 0, 255);
312 if (gPlayer1
= nil) then exit
;
314 //e_WriteLog(Format('(%d,%d)-(%d,%d)', [laserX0, laserY0, laserX1, laserY1]), MSG_NOTIFY);
317 glTranslatef(-vpx
, -vpy
, 0);
319 g_Mons_AlongLine(laserX0
, laserY0
, laserX1
, laserY1
, monsCollector
, true);
321 if (monMarkedUID
<> -1) then
323 mon
:= g_Monsters_ByUID(monMarkedUID
);
326 mon
.getMapBox(mx
, my
, mw
, mh
);
327 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 0, 0, 30);
331 //e_DrawPoint(16, laserX0, laserY0, 255, 255, 255);
338 procedure drawTileGrid ();
343 while (y < mapGrid.gridY0+mapGrid.gridHeight) do
346 while (x < mapGrid.gridX0+mapGrid.gridWidth) do
348 if (x+mapGrid.tileSize > vpx) and (y+mapGrid.tileSize > vpy) and
349 (x < vpx+vpw) and (y < vpy+vph) then
351 e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96);
353 Inc(x, mapGrid.tileSize);
355 Inc(y, mapGrid.tileSize);
361 // ////////////////////////////////////////////////////////////////////////// //
362 function g_Holmes_mouseEvent (var ev
: THMouseEvent
): Boolean;
373 function g_Holmes_KeyEvent (var ev
: THKeyEvent
): Boolean;
379 // ////////////////////////////////////////////////////////////////////////// //
380 procedure g_Holmes_Draw ();
382 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
383 glDisable(GL_STENCIL_TEST
);
385 glDisable(GL_SCISSOR_TEST
);
386 glDisable(GL_TEXTURE_2D
);