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}
22 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF} geom
,
24 g_textures
, g_basic
, e_graphics
, g_phys
, g_grid
, g_player
, g_monsters
,
25 g_window
, g_map
, g_triggers
, g_items
, g_game
, g_panel
, g_console
, g_gfx
,
27 sdlcarcass
, glgfx
, gh_ui_common
, gh_ui
;
30 procedure g_Holmes_Draw ();
31 procedure g_Holmes_DrawUI ();
33 procedure g_Holmes_MouseEvent (var ev
: THMouseEvent
);
34 procedure g_Holmes_KeyEvent (var ev
: THKeyEvent
);
37 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
38 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
39 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
43 g_holmes_enabled
: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
49 {rttiobj,} typinfo
, e_texture
,
50 SysUtils
, Classes
, GL
, SDL2
,
51 MAPDEF
, g_main
, g_options
,
52 utils
, hashtable
, xparser
;
56 //globalInited: Boolean = false;
59 msB
: Word = 0; // button state
60 kbS
: Word = 0; // keyboard modifiers state
61 showGrid
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
62 showMonsInfo
: Boolean = false;
63 showMonsLOS2Plr
: Boolean = false;
64 showAllMonsCells
: Boolean = false;
65 showMapCurPos
: Boolean = false;
66 showLayersWindow
: Boolean = false;
67 showOutlineWindow
: Boolean = false;
68 showTriggers
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
69 showTraceBox
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
72 // ////////////////////////////////////////////////////////////////////////// //
73 {$INCLUDE g_holmes.inc}
74 {$INCLUDE g_holmes_ol.inc} // outliner
77 // ////////////////////////////////////////////////////////////////////////// //
78 {$INCLUDE g_holmes_cmd.inc}
79 procedure holmesInitCommands (); forward;
80 procedure holmesInitBinds (); forward;
83 // ////////////////////////////////////////////////////////////////////////// //
85 g_ol_nice
: Boolean = false;
86 g_ol_fill_walls
: Boolean = false;
87 g_ol_rlayer_back
: Boolean = false;
88 g_ol_rlayer_step
: Boolean = false;
89 g_ol_rlayer_wall
: Boolean = false;
90 g_ol_rlayer_door
: Boolean = false;
91 g_ol_rlayer_acid1
: Boolean = false;
92 g_ol_rlayer_acid2
: Boolean = false;
93 g_ol_rlayer_water
: Boolean = false;
94 g_ol_rlayer_fore
: Boolean = false;
97 // ////////////////////////////////////////////////////////////////////////// //
99 winHelp
: TUITopWindow
= nil;
100 winOptions
: TUITopWindow
= nil;
101 winLayers
: TUITopWindow
= nil;
102 winOutlines
: TUITopWindow
= nil;
105 procedure createHelpWindow (); forward;
106 procedure createOptionsWindow (); forward;
107 procedure createLayersWindow (); forward;
108 procedure createOutlinesWindow (); forward;
111 procedure toggleLayersWindowCB (me
: TUIControl
);
113 showLayersWindow
:= not showLayersWindow
;
114 if showLayersWindow
then
116 if (winLayers
= nil) then createLayersWindow();
117 uiAddWindow(winLayers
);
121 uiRemoveWindow(winLayers
);
125 procedure toggleOutlineWindowCB (me
: TUIControl
);
127 showOutlineWindow
:= not showOutlineWindow
;
128 if showOutlineWindow
then
130 if (winOutlines
= nil) then createOutlinesWindow();
131 uiAddWindow(winOutlines
);
135 uiRemoveWindow(winOutlines
);
140 procedure createHelpWindow ();
141 procedure addHelpEmptyLine ();
145 stx
:= TUIStaticText
.Create();
146 stx
.flExpand
:= true;
147 stx
.halign
:= 0; // center
151 winHelp
.appendChild(stx
);
154 procedure addHelpCaptionLine (const txt
: AnsiString);
158 stx
:= TUIStaticText
.Create();
159 stx
.flExpand
:= true;
160 stx
.halign
:= 0; // center
164 winHelp
.appendChild(stx
);
167 procedure addHelpCaption (const txt
: AnsiString);
171 stx
:= TUIStaticText
.Create();
172 stx
.flExpand
:= true;
173 stx
.halign
:= 0; // center
177 winHelp
.appendChild(stx
);
180 procedure addHelpKeyMouse (const key
, txt
, grp
: AnsiString);
186 box
:= TUIHBox
.Create();
187 box
.flExpand
:= true;
189 stx
:= TUIStaticText
.Create();
190 stx
.flExpand
:= true;
191 stx
.halign
:= 1; // right
192 stx
.valign
:= 0; // center
197 box
.appendChild(stx
);
199 span
:= TUISpan
.Create();
200 span
.flDefaultSize
:= TLaySize
.Create(4, 1);
201 span
.flExpand
:= true;
202 box
.appendChild(span
);
204 stx
:= TUIStaticText
.Create();
205 stx
.flExpand
:= true;
206 stx
.halign
:= -1; // left
207 stx
.valign
:= 0; // center
211 box
.appendChild(stx
);
212 winHelp
.appendChild(box
);
215 procedure addHelpKey (const key
, txt
: AnsiString); begin addHelpKeyMouse(key
, txt
, 'help-keys'); end;
216 procedure addHelpMouse (const key
, txt
: AnsiString); begin addHelpKeyMouse(key
, txt
, 'help-mouse'); end;
219 slist
: array of AnsiString = nil;
221 bind
: THolmesBinding
;
229 winHelp
:= TUITopWindow
.Create('Holmes Help');
230 winHelp
.escClose
:= true;
231 winHelp
.flHoriz
:= false;
234 for cmd
in cmdlist
do cmd
.helpmark
:= false;
237 for bind
in keybinds
do
239 if (Length(bind
.key
) = 0) then continue
;
240 if cmdlist
.get(bind
.cmdName
, cmd
) then
242 if (Length(cmd
.help
) > 0) then
244 cmd
.helpmark
:= true;
245 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
250 for cmd
in cmdlist
do
252 if not cmd
.helpmark
then continue
;
253 if (Length(cmd
.help
) = 0) then begin cmd
.helpmark
:= false; continue
; end;
255 while (f
< Length(slist
)) and (CompareText(slist
[f
], cmd
.section
) <> 0) do Inc(f
);
256 if (f
= Length(slist
)) then
258 SetLength(slist
, Length(slist
)+1);
259 slist
[High(slist
)] := cmd
.section
;
263 addHelpCaptionLine('KEYBOARD');
264 //llb := TUISimpleText.Create(0, 0);
265 for f
:= 0 to High(slist
) do
267 //if (f > 0) then llb.appendItem('');
268 if (f
> 0) then addHelpEmptyLine();
269 //llb.appendItem(slist[f], true, true);
270 addHelpCaption(slist
[f
]);
271 for cmd
in cmdlist
do
273 if not cmd
.helpmark
then continue
;
274 if (CompareText(cmd
.section
, slist
[f
]) <> 0) then continue
;
275 for bind
in keybinds
do
277 if (Length(bind
.key
) = 0) then continue
;
278 if (cmd
.name
= bind
.cmdName
) then
281 //while (Length(s) < maxkeylen) do s += ' ';
282 //s := ' '+s+' -- '+cmd.help;
284 addHelpMouse(bind
.key
, cmd
.help
);
291 for cmd
in cmdlist
do cmd
.helpmark
:= false;
294 for bind
in msbinds
do
296 if (Length(bind
.key
) = 0) then continue
;
297 if cmdlist
.get(bind
.cmdName
, cmd
) then
299 if (Length(cmd
.help
) > 0) then
301 cmd
.helpmark
:= true;
302 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
307 //llb.appendItem('');
308 //llb.appendItem('mouse', true, true);
309 if (f
> 0) then addHelpEmptyLine();
310 addHelpCaptionLine('MOUSE');
311 for bind
in msbinds
do
313 if (Length(bind
.key
) = 0) then continue
;
314 if cmdlist
.get(bind
.cmdName
, cmd
) then
316 if (Length(cmd
.help
) > 0) then
319 //while (Length(s) < maxkeylen) do s += ' ';
320 //s := ' '+s+' -- '+cmd.help;
322 addHelpKey(bind
.key
, cmd
.help
);
327 //winHelp.appendChild(llb);
329 winHelp
.flMaxSize
:= TLaySize
.Create(trunc(getScrWdt
/gh_ui_scale
), trunc(getScrHgt
/gh_ui_scale
));
330 uiLayoutCtl(winHelp
);
331 winHelp
.centerInScreen();
335 procedure winLayersClosed (me
: TUIControl
); begin showLayersWindow
:= false; end;
336 procedure winOutlinesClosed (me
: TUIControl
); begin showOutlineWindow
:= false; end;
338 procedure addCheckBox (parent
: TUIControl
; const text: AnsiString; pvar
: PBoolean);
342 cb
:= TUICheckBox
.Create();
346 parent
.appendChild(cb
);
349 procedure addButton (parent
: TUIControl
; const text: AnsiString; cb
: TUIControl
.TActionCB
);
353 but
:= TUIButton
.Create();
354 //but.flExpand := true;
357 parent
.appendChild(but
);
361 procedure createLayersWindow ();
365 winLayers
:= TUITopWindow
.Create('layers');
368 winLayers
.flHoriz
:= false;
369 winLayers
.escClose
:= true;
370 winLayers
.closeCB
:= winLayersClosed
;
372 box
:= TUIVBox
.Create();
373 addCheckBox(box
, '~background', @g_rlayer_back
);
374 addCheckBox(box
, '~steps', @g_rlayer_step
);
375 addCheckBox(box
, '~walls', @g_rlayer_wall
);
376 addCheckBox(box
, '~doors', @g_rlayer_door
);
377 addCheckBox(box
, 'acid~1', @g_rlayer_acid1
);
378 addCheckBox(box
, 'acid~2', @g_rlayer_acid2
);
379 addCheckBox(box
, 'wate~r', @g_rlayer_water
);
380 addCheckBox(box
, '~foreground', @g_rlayer_fore
);
381 winLayers
.appendChild(box
);
383 uiLayoutCtl(winLayers
);
387 procedure createOutlinesWindow ();
391 winOutlines
:= TUITopWindow
.Create('outlines');
392 winOutlines
.x0
:= 100;
393 winOutlines
.y0
:= 30;
394 winOutlines
.flHoriz
:= false;
395 winOutlines
.escClose
:= true;
396 winOutlines
.closeCB
:= winOutlinesClosed
;
398 box
:= TUIVBox
.Create();
399 box
.hasFrame
:= true;
400 box
.caption
:= 'layers';
401 addCheckBox(box
, '~background', @g_ol_rlayer_back
);
402 addCheckBox(box
, '~steps', @g_ol_rlayer_step
);
403 addCheckBox(box
, '~walls', @g_ol_rlayer_wall
);
404 addCheckBox(box
, '~doors', @g_ol_rlayer_door
);
405 addCheckBox(box
, 'acid~1', @g_ol_rlayer_acid1
);
406 addCheckBox(box
, 'acid~2', @g_ol_rlayer_acid2
);
407 addCheckBox(box
, 'wate~r', @g_ol_rlayer_water
);
408 addCheckBox(box
, '~foreground', @g_ol_rlayer_fore
);
409 winOutlines
.appendChild(box
);
411 box
:= TUIVBox
.Create();
412 box
.hasFrame
:= true;
413 box
.caption
:= 'options';
414 addCheckBox(box
, 'fi~ll walls', @g_ol_fill_walls
);
415 addCheckBox(box
, 'con~tours', @g_ol_nice
);
416 winOutlines
.appendChild(box
);
418 uiLayoutCtl(winOutlines
);
422 procedure createOptionsWindow ();
427 winOptions
:= TUITopWindow
.Create('Holmes Options');
428 winOptions
.flHoriz
:= false;
429 winOptions
.escClose
:= true;
431 box
:= TUIVBox
.Create();
432 box
.hasFrame
:= true;
433 box
.caption
:= 'visual';
434 addCheckBox(box
, 'map ~grid', @showGrid
);
435 addCheckBox(box
, 'cursor ~position on map', @showMapCurPos
);
436 addCheckBox(box
, '~monster info', @showMonsInfo
);
437 addCheckBox(box
, 'monster LO~S to player', @showMonsLOS2Plr
);
438 addCheckBox(box
, 'monster ~cells (SLOW!)', @showAllMonsCells
);
439 addCheckBox(box
, 'draw ~triggers (SLOW!)', @showTriggers
);
440 winOptions
.appendChild(box
);
442 box
:= TUIHBox
.Create();
443 box
.hasFrame
:= true;
444 box
.caption
:= 'windows';
446 addButton(box
, '~layers', toggleLayersWindowCB
);
447 span
:= TUISpan
.Create();
448 span
.flExpand
:= true;
449 span
.flDefaultSize
:= TLaySize
.Create(4, 1);
450 box
.appendChild(span
);
451 addButton(box
, '~outline', toggleOutlineWindowCB
);
452 winOptions
.appendChild(box
);
454 uiLayoutCtl(winOptions
);
455 winOptions
.centerInScreen();
459 procedure toggleLayersWindow (arg
: Integer=-1);
461 if (arg
< 0) then showLayersWindow
:= not showLayersWindow
else showLayersWindow
:= (arg
> 0);
462 showLayersWindow
:= not showLayersWindow
; // hack for callback
463 toggleLayersWindowCB(nil);
466 procedure toggleOutlineWindow (arg
: Integer=-1);
468 if (arg
< 0) then showOutlineWindow
:= not showOutlineWindow
else showOutlineWindow
:= (arg
> 0);
469 showOutlineWindow
:= not showOutlineWindow
; // hack for callback
470 toggleOutlineWindowCB(nil);
473 procedure toggleHelpWindow (arg
: Integer=-1);
475 if (winHelp
= nil) then createHelpWindow();
476 if (arg
< 0) then begin if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
) else uiRemoveWindow(winHelp
); end
477 else if (arg
= 0) then begin if uiVisibleWindow(winHelp
) then uiRemoveWindow(winHelp
); end
478 else begin if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
); end
481 procedure toggleOptionsWindow (arg
: Integer=-1);
483 if (winOptions
= nil) then createOptionsWindow();
484 if (arg
< 0) then begin if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
) else uiRemoveWindow(winOptions
); end
485 else if (arg
= 0) then begin if uiVisibleWindow(winOptions
) then uiRemoveWindow(winOptions
); end
486 else begin if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
); end
490 // ////////////////////////////////////////////////////////////////////////// //
492 vpSet
: Boolean = false;
495 laserSet
: Boolean = false;
496 laserX0
, laserY0
, laserX1
, laserY1
: Integer;
497 monMarkedUID
: Integer = -1;
498 platMarkedGUID
: Integer = -1;
501 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
508 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
515 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
522 laserSet
:= laserSet
; // shut up, fpc!
526 function pmsCurMapX (): Integer; inline; begin result
:= round(msX
/g_dbg_scale
)+vpx
; end;
527 function pmsCurMapY (): Integer; inline; begin result
:= round(msY
/g_dbg_scale
)+vpy
; end;
530 procedure plrDebugMouse (var ev
: THMouseEvent
);
532 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
533 if (gPlayer1
= nil) or not vpSet
then exit
;
534 //if (ev.kind <> THMouseEvent.Press) then exit;
535 //e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY);
540 {$IFDEF HOLMES_OLD_OUTLINES}
542 edgeBmp
: array of Byte = nil;
545 procedure drawOutlines ();
549 procedure clearEdgeBmp ();
551 SetLength(edgeBmp
, (gWinSizeX
+4)*(gWinSizeY
+4));
552 FillChar(edgeBmp
[0], Length(edgeBmp
)*sizeof(edgeBmp
[0]), 0);
555 procedure drawPanel (pan
: TPanel
);
557 sx
, len
, y0
, y1
: Integer;
559 if (pan
= nil) or (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
560 if (pan
.X
+pan
.Width
<= vpx
-1) or (pan
.Y
+pan
.Height
<= vpy
-1) then exit
;
561 if (pan
.X
>= vpx
+vpw
+1) or (pan
.Y
>= vpy
+vph
+1) then exit
;
562 if g_ol_nice
or g_ol_fill_walls
then
566 if (len
> gWinSizeX
+4) then len
:= gWinSizeX
+4;
567 if (sx
< 0) then begin len
+= sx
; sx
:= 0; end;
568 if (sx
+len
> gWinSizeX
+4) then len
:= gWinSizeX
+4-sx
;
569 if (len
< 1) then exit
;
571 assert(sx
+len
<= gWinSizeX
+4);
574 if (y0
< 0) then y0
:= 0;
575 if (y1
> gWinSizeY
+4) then y1
:= gWinSizeY
+4;
578 FillChar(edgeBmp
[y0
*(gWinSizeX
+4)+sx
], len
*sizeof(edgeBmp
[0]), 1);
584 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, r
, g
, b
);
593 procedure flushLine ();
595 if (lsy
> 0) and (lsx
> 0) then
600 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
606 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
607 glVertex2f(lex
-0+vpx
+0.37, lsy
-1+vpy
+0.37);
615 procedure startLine (y
: Integer);
621 procedure putPixel (x
: Integer);
623 if (x
< 1) then exit
;
624 if (lex
+1 <> x
) then flushLine();
625 if (lsx
< 0) then lsx
:= x
;
629 procedure drawEdges ();
635 glDisable(GL_TEXTURE_2D
);
638 glDisable(GL_LINE_SMOOTH
);
639 glDisable(GL_POLYGON_SMOOTH
);
640 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
643 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
649 if (a
[-1] = 0) or (a
[1] = 0) or (a
[-(gWinSizeX
+4)] = 0) or (a
[gWinSizeX
+4] = 0) or
650 (a
[-(gWinSizeX
+4)-1] = 0) or (a
[-(gWinSizeX
+4)+1] = 0) or
651 (a
[gWinSizeX
+4-1] = 0) or (a
[gWinSizeX
+4+1] = 0) then
662 procedure drawFilledWalls ();
668 glDisable(GL_TEXTURE_2D
);
671 glDisable(GL_LINE_SMOOTH
);
672 glDisable(GL_POLYGON_SMOOTH
);
673 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
676 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
680 if (a
[0] <> 0) then putPixel(x
);
687 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
695 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
696 for f
:= 0 to High(parr
) do
699 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
700 if ((pan
.PanelType
and ptype
) = 0) then continue
;
703 if g_ol_nice
then drawEdges();
704 if g_ol_fill_walls
then drawFilledWalls();
710 function doWallCB (pan
: TPanel
; tag
: Integer): Boolean;
712 result
:= false; // don't stop
713 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
714 if ((pan
.PanelType
and xptag
) = 0) then exit
;
718 procedure doWalls (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
724 if ((ptype
and (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) <> 0) then ptype
:= GridTagWall
or GridTagDoor
725 else panelTypeToTag(ptype
);
726 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
727 mapGrid
.forEachInAABB(vpx
-1, vpy
-1, vpw
+2, vph
+2, doWallCB
, ptype
);
728 if g_ol_nice
then drawEdges();
729 if g_ol_fill_walls
then drawFilledWalls();
733 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
734 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
735 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
736 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
737 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
738 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
739 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
740 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
745 oliner
: TOutliner
= nil;
747 procedure drawOutlines ();
751 procedure clearOliner ();
753 //if (oliner <> nil) and ((oliner.height <> vph+2) or (oliner.width <> vpw+2)) then begin oliner.Free(); oliner := nil; end;
754 if (oliner
= nil) then oliner
:= TOutliner
.Create(vpw
+2, vph
+2) else oliner
.setup(vpw
+2, vph
+2);
757 procedure drawOutline (ol
: TOutliner
; sx
, sy
: Integer);
758 procedure xline (x0
, x1
, y
: Integer);
762 if (g_dbg_scale
< 1.0) then
765 for x
:= x0
to x1
do glVertex2f(sx
+x
+0.375, sy
+y
+0.375);
771 glVertex2f(sx
+x0
+0, sy
+y
+0);
772 glVertex2f(sx
+x1
+1, sy
+y
+0);
773 glVertex2f(sx
+x1
+1, sy
+y
+1);
774 glVertex2f(sx
+x0
+0, sy
+y
+1);
780 sp
: TOutliner
.TSpanX
;
782 if (ol
= nil) then exit
;
784 glDisable(GL_POINT_SMOOTH
);
785 for y
:= 0 to ol
.height
-1 do
787 for sp
in ol
.eachSpanAtY(y
) do
789 if (g_dbg_scale
<= 1.0) then
792 glVertex2f(sx
+sp
.x0
+0.375, sy
+y
+0.375);
793 glVertex2f(sx
+sp
.x1
+0.375, sy
+y
+0.375);
799 glVertex2f(sx
+sp
.x0
+0, sy
+y
+0);
800 glVertex2f(sx
+sp
.x0
+1, sy
+y
+0);
801 glVertex2f(sx
+sp
.x0
+1, sy
+y
+1);
802 glVertex2f(sx
+sp
.x0
+0, sy
+y
+1);
804 glVertex2f(sx
+sp
.x1
+0, sy
+y
+0);
805 glVertex2f(sx
+sp
.x1
+1, sy
+y
+0);
806 glVertex2f(sx
+sp
.x1
+1, sy
+y
+1);
807 glVertex2f(sx
+sp
.x1
+0, sy
+y
+1);
811 for sp
in ol
.eachSpanEdgeAtY(y
, -1) do
813 xline(sp
.x0
, sp
.x1
, y
);
816 glVertex2f(sx+sp.x0+0, sy+y+0);
817 glVertex2f(sx+sp.x1+1, sy+y+0);
818 glVertex2f(sx+sp.x1+1, sy+y+1);
819 glVertex2f(sx+sp.x0+0, sy+y+1);
823 for sp
in ol
.eachSpanEdgeAtY(y
, +1) do
825 xline(sp
.x0
, sp
.x1
, y
);
828 glVertex2f(sx+sp.x0+0, sy+y+0);
829 glVertex2f(sx+sp.x1+1, sy+y+0);
830 glVertex2f(sx+sp.x1+1, sy+y+1);
831 glVertex2f(sx+sp.x0+0, sy+y+1);
838 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
846 if g_ol_nice
then clearOliner();
847 for f
:= 0 to High(parr
) do
850 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
851 if ((pan
.PanelType
and ptype
) = 0) then continue
;
852 if (pan
.X
> vpx
+vpw
+41) or (pan
.Y
> vpy
+vph
+41) then continue
;
853 if (pan
.X
+pan
.Width
< vpx
-41) then continue
;
854 if (pan
.Y
+pan
.Height
< vpy
-41) then continue
;
857 oliner
.addRect(pan
.X
-(vpx
+1), pan
.Y
-(vpy
+1), pan
.Width
, pan
.Height
);
859 if g_ol_fill_walls
then
861 fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, TGxRGBA
.Create(r
, g
, b
));
863 else if not g_ol_nice
then
865 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, TGxRGBA
.Create(r
, g
, b
));
870 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
871 drawOutline(oliner
, vpx
+1, vpy
+1);
876 if (vpw
< 2) or (vph
< 2) then exit
;
877 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
878 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
879 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
880 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
881 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
882 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
883 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
884 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
889 procedure plrDebugDraw ();
890 procedure drawTileGrid ();
894 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
896 drawLine(mapGrid
.gridX0
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, mapGrid
.gridX0
+mapGrid
.gridWidth
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, TGxRGBA
.Create(96, 96, 96));
899 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
901 drawLine(mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
, mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
+y
*mapGrid
.gridHeight
, TGxRGBA
.Create(96, 96, 96));
905 procedure drawAwakeCells ();
909 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
911 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
913 if awmIsSetHolmes(x
*mapGrid
.tileSize
+mapGrid
.gridX0
+1, y
*mapGrid
.tileSize
++mapGrid
.gridY0
+1) then
915 fillRect(x
*mapGrid
.tileSize
++mapGrid
.gridX0
, y
*mapGrid
.tileSize
++mapGrid
.gridY0
, monsGrid
.tileSize
, monsGrid
.tileSize
, TGxRGBA
.Create(128, 0, 128, 64));
921 procedure drawTraceBox ();
924 px
, py
, pw
, ph
: Integer;
929 if (Length(gPlayers
) < 1) then exit
;
931 if (plr
= nil) then exit
;
932 plr
.getMapBox(px
, py
, pw
, ph
);
933 drawRect(px
, py
, pw
, ph
, TGxRGBA
.Create(255, 0, 255, 200));
934 pdx
:= pmsCurMapX
-(px
+pw
div 2);
935 pdy
:= pmsCurMapY
-(py
+ph
div 2);
936 drawLine(px
+pw
div 2, py
+ph
div 2, px
+pw
div 2+pdx
, py
+ph
div 2+pdy
, TGxRGBA
.Create(255, 0, 255, 200));
937 pan
:= mapGrid
.traceBox(ex
, ey
, px
, py
, pw
, ph
, pdx
, pdy
, nil, GridTagObstacle
);
940 drawRect(px
+pdx
, py
+pdy
, pw
, ph
, TGxRGBA
.Create(255, 255, 255, 180));
944 drawRect(px
+pdx
, py
+pdy
, pw
, ph
, TGxRGBA
.Create(255, 255, 0, 180));
946 drawRect(ex
, ey
, pw
, ph
, TGxRGBA
.Create(255, 127, 0, 180));
949 procedure hilightCell (cx
, cy
: Integer);
951 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, TGxRGBA
.Create(0, 128, 0, 64));
954 procedure hilightCell1 (cx
, cy
: Integer);
956 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
957 cx
:= cx
and (not (monsGrid
.tileSize
-1));
958 cy
:= cy
and (not (monsGrid
.tileSize
-1));
959 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, TGxRGBA
.Create(255, 255, 0, 92));
962 function hilightWallTrc (pan
: TPanel
; tag
: Integer; x
, y
, prevx
, prevy
: Integer): Boolean;
964 result
:= false; // don't stop
965 if (pan
= nil) then exit
; // cell completion, ignore
966 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
967 fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, TGxRGBA
.Create(0, 128, 128, 64));
970 function monsCollector (mon
: TMonster
; tag
: Integer): Boolean;
973 mx
, my
, mw
, mh
: Integer;
976 mon
.getMapBox(mx
, my
, mw
, mh
);
977 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 255, 0, 96);
978 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
980 e_DrawPoint(8, ex
, ey
, 0, 255, 0);
984 procedure drawMonsterInfo (mon
: TMonster
);
986 mx
, my
, mw
, mh
: Integer;
988 procedure drawMonsterTargetLine ();
990 emx
, emy
, emw
, emh
: Integer;
995 if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_PLAYER
) then
997 eplr
:= g_Player_Get(mon
.MonsterTargetUID
);
998 if (eplr
<> nil) then eplr
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1000 else if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_MONSTER
) then
1002 enemy
:= g_Monsters_ByUID(mon
.MonsterTargetUID
);
1003 if (enemy
<> nil) then enemy
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1009 mon
.getMapBox(mx
, my
, mw
, mh
);
1010 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, TGxRGBA
.Create(255, 0, 0));
1011 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1013 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, TGxRGBA
.Create(0, 255, 0));
1017 procedure drawLOS2Plr ();
1019 emx
, emy
, emw
, emh
: Integer;
1023 eplr
:= gPlayers
[0];
1024 if (eplr
= nil) then exit
;
1025 eplr
.getMapBox(emx
, emy
, emw
, emh
);
1026 mon
.getMapBox(mx
, my
, mw
, mh
);
1027 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, TGxRGBA
.Create(255, 0, 0));
1028 {$IF DEFINED(D2F_DEBUG)}
1029 mapGrid
.dbgRayTraceTileHitCB
:= hilightCell1
;
1031 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1032 //if (mapGrid.traceRay(ex, ey, mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, hilightWallTrc, (GridTagWall or GridTagDoor)) <> nil) then
1034 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, TGxRGBA
.Create(0, 255, 0));
1036 {$IF DEFINED(D2F_DEBUG)}
1037 mapGrid
.dbgRayTraceTileHitCB
:= nil;
1042 if (mon
= nil) then exit
;
1043 mon
.getMapBox(mx
, my
, mw
, mh
);
1046 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1048 if showMonsInfo
then
1050 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1051 darkenRect(mx
-4, my
-7*8-6, 110, 7*8+6, 128);
1056 drawText6(mx
, my
, Format('%s(U:%u)', [monsTypeToString(mon
.MonsterType
), mon
.UID
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1058 drawText6(mx
, my
, Format('Beh: %s', [monsBehToString(mon
.MonsterBehaviour
)]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1060 drawText6(mx
, my
, Format('State:%s (%d)', [monsStateToString(mon
.MonsterState
), mon
.MonsterSleep
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1062 drawText6(mx
, my
, Format('Health:%d', [mon
.MonsterHealth
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1064 drawText6(mx
, my
, Format('Ammo:%d', [mon
.MonsterAmmo
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1066 drawText6(mx
, my
, Format('TgtUID:%u', [mon
.MonsterTargetUID
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1067 drawText6(mx
, my
, Format('TgtTime:%d', [mon
.MonsterTargetTime
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1070 drawMonsterTargetLine();
1071 if showMonsLOS2Plr
then drawLOS2Plr();
1073 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1074 property MonsterPain: Integer read FPain write FPain;
1075 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1079 function highlightAllMonsterCells (mon
: TMonster
): Boolean;
1081 result
:= false; // don't stop
1082 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1085 procedure drawSelectedPlatformCells ();
1089 if not showGrid
then exit
;
1090 pan
:= g_Map_PanelByGUID(platMarkedGUID
);
1091 if (pan
= nil) then exit
;
1092 mapGrid
.forEachBodyCell(pan
.proxyId
, hilightCell
);
1093 drawRect(pan
.x
, pan
.y
, pan
.width
, pan
.height
, TGxRGBA
.Create(0, 200, 0, 200));
1096 procedure drawTrigger (var trig
: TTrigger
);
1098 procedure drawPanelDest (pguid
: Integer);
1102 pan
:= g_Map_PanelByGUID(pguid
);
1103 if (pan
= nil) then exit
;
1105 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1106 pan
.x
+pan
.width
div 2, pan
.y
+pan
.height
div 2,
1107 TGxRGBA
.Create(255, 0, 255, 220));
1114 fillRect(trig
.x
, trig
.y
, trig
.width
, trig
.height
, TGxRGBA
.Create(255, 0, 255, 96));
1115 tts
:= trigType2Str(trig
.TriggerType
);
1116 tx
:= trig
.x
+(trig
.width
-Length(tts
)*6) div 2;
1117 darkenRect(tx
-2, trig
.y
-10, Length(tts
)*6+4, 10, 64);
1118 drawText6(tx
, trig
.y
-9, tts
, TGxRGBA
.Create(255, 127, 0));
1119 tx
:= trig
.x
+(trig
.width
-Length(trig
.mapId
)*6) div 2;
1120 darkenRect(tx
-2, trig
.y
-20, Length(trig
.mapId
)*6+4, 10, 64);
1121 drawText6(tx
, trig
.y
-19, trig
.mapId
, TGxRGBA
.Create(255, 255, 0));
1122 drawPanelDest(trig
.trigPanelGUID
);
1123 case trig
.TriggerType
of
1124 TRIGGER_NONE
: begin end;
1125 TRIGGER_EXIT
: begin end;
1126 TRIGGER_TELEPORT
: begin end;
1127 TRIGGER_OPENDOOR
: begin end;
1128 TRIGGER_CLOSEDOOR
: begin end;
1129 TRIGGER_DOOR
: begin end;
1130 TRIGGER_DOOR5
: begin end;
1131 TRIGGER_CLOSETRAP
: begin end;
1132 TRIGGER_TRAP
: begin end;
1133 TRIGGER_SECRET
: begin end;
1134 TRIGGER_LIFTUP
: begin end;
1135 TRIGGER_LIFTDOWN
: begin end;
1136 TRIGGER_LIFT
: begin end;
1137 TRIGGER_TEXTURE
: begin end;
1138 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
, TRIGGER_PRESS
:
1140 if (trig
.trigDataRec
.trigTWidth
> 0) and (trig
.trigDataRec
.trigTHeight
> 0) then
1143 trig
.trigDataRec
.trigTX
, trig
.trigDataRec
.trigTY
,
1144 trig
.trigDataRec
.trigTWidth
, trig
.trigDataRec
.trigTHeight
,
1145 TGxRGBA
.Create(0, 255, 255, 42));
1147 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1148 trig
.trigDataRec
.trigTX
+trig
.trigDataRec
.trigTWidth
div 2,
1149 trig
.trigDataRec
.trigTY
+trig
.trigDataRec
.trigTHeight
div 2,
1150 TGxRGBA
.Create(255, 0, 255, 220));
1153 TRIGGER_SOUND
: begin end;
1154 TRIGGER_SPAWNMONSTER
: begin end;
1155 TRIGGER_SPAWNITEM
: begin end;
1156 TRIGGER_MUSIC
: begin end;
1157 TRIGGER_PUSH
: begin end;
1158 TRIGGER_SCORE
: begin end;
1159 TRIGGER_MESSAGE
: begin end;
1160 TRIGGER_DAMAGE
: begin end;
1161 TRIGGER_HEALTH
: begin end;
1162 TRIGGER_SHOT
: begin end;
1163 TRIGGER_EFFECT
: begin end;
1164 TRIGGER_SCRIPT
: begin end;
1167 //trigPanelId: Integer;
1170 procedure drawTriggers ();
1174 for f
:= 0 to High(gTriggers
) do drawTrigger(gTriggers
[f
]);
1177 procedure drawGibsBoxes ();
1180 px
, py
, pw
, ph
: Integer;
1183 for f
:= 0 to High(gGibs
) do
1188 gib
.getMapBox(px
, py
, pw
, ph
);
1189 drawRect(px
, py
, pw
, ph
, TGxRGBA
.Create(255, 0, 255));
1195 scisave
: TScissorSave
;
1197 mx
, my
, mw
, mh
: Integer;
1201 if (gPlayer1
= nil) then exit
;
1203 scisave
.save(true); // enable scissoring
1206 //glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph);
1207 glScissor(0, gScreenHeight
-gPlayerScreenSize
.Y
-1, gPlayerScreenSize
.X
, gPlayerScreenSize
.Y
);
1209 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
1210 glTranslatef(-vpx
, -vpy
, 0);
1212 if (showGrid
) then drawTileGrid();
1215 if (laserSet
) then g_Mons_AlongLine(laserX0
, laserY0
, laserX1
, laserY1
, monsCollector
, true);
1217 if (monMarkedUID
<> -1) then
1219 mon
:= g_Monsters_ByUID(monMarkedUID
);
1220 if (mon
<> nil) then
1222 mon
.getMapBox(mx
, my
, mw
, mh
);
1223 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 0, 0, 30);
1224 drawMonsterInfo(mon
);
1228 if showAllMonsCells
and showGrid
then g_Mons_ForEach(highlightAllMonsterCells
);
1229 if showTriggers
then drawTriggers();
1230 if showGrid
then drawSelectedPlatformCells();
1234 if showTraceBox
then drawTraceBox();
1239 //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey);
1241 {$IF DEFINED(D2F_DEBUG)}
1242 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1244 pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid));
1245 if (pan <> nil) then writeln('end=(', ex, ',', ey, ')');
1246 {$IF DEFINED(D2F_DEBUG)}
1247 mapGrid.dbgRayTraceTileHitCB := nil;
1250 pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid));
1251 if (pan <> nil) then writeln('hit!');
1259 if showMapCurPos
then drawText8(4, gWinSizeY
-10, Format('mappos:(%d,%d)', [pmsCurMapX
, pmsCurMapY
]), TGxRGBA
.Create(255, 255, 0));
1263 // ////////////////////////////////////////////////////////////////////////// //
1264 procedure g_Holmes_MouseEvent (var ev
: THMouseEvent
);
1268 if g_Game_IsNet
then exit
;
1269 if not g_holmes_enabled
then exit
;
1271 holmesInitCommands();
1282 if (not he
.eaten
) then plrDebugMouse(he
);
1287 // ////////////////////////////////////////////////////////////////////////// //
1288 procedure g_Holmes_KeyEvent (var ev
: THKeyEvent
);
1290 doeat
: Boolean = false;
1291 {$IF DEFINED(D2F_DEBUG)}
1297 procedure dummyWallTrc (cx
, cy
: Integer);
1302 if g_Game_IsNet
then exit
;
1303 if not g_holmes_enabled
then exit
;
1305 holmesInitCommands();
1311 SDL_SCANCODE_LCTRL
, SDL_SCANCODE_RCTRL
,
1312 SDL_SCANCODE_LALT
, SDL_SCANCODE_RALT
,
1313 SDL_SCANCODE_LSHIFT
, SDL_SCANCODE_RSHIFT
:
1318 if (ev
.eaten
) then exit
;
1319 if keybindExecute(ev
) then begin ev
.eat(); exit
; end;
1323 {$IF DEFINED(D2F_DEBUG)}
1324 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1325 if ((ev
.scan
= SDL_SCANCODE_UP
) or (ev
.scan
= SDL_SCANCODE_DOWN
) or (ev
.scan
= SDL_SCANCODE_LEFT
) or (ev
.scan
= SDL_SCANCODE_RIGHT
)) and
1326 ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
1332 SDL_SCANCODE_UP
: dy
-= 120;
1333 SDL_SCANCODE_DOWN
: dy
+= 120;
1334 SDL_SCANCODE_LEFT
: dx
-= 120;
1335 SDL_SCANCODE_RIGHT
: dx
+= 120;
1337 {$IF DEFINED(D2F_DEBUG)}
1338 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1339 mapGrid
.dbgShowTraceLog
:= true;
1341 pan
:= g_Map_traceToNearest(pmsCurMapX
, pmsCurMapY
, dx
, dy
, (GridTagWall
or GridTagDoor
or GridTagStep
or GridTagAcid1
or GridTagAcid2
or GridTagWater
), @ex
, @ey
);
1342 {$IF DEFINED(D2F_DEBUG)}
1343 //mapGrid.dbgRayTraceTileHitCB := nil;
1344 mapGrid
.dbgShowTraceLog
:= false;
1346 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX
, pmsCurMapY
, dx
, dy
, ex
, ey
, (pan
<> nil)]);
1351 if (doeat
) then ev
.eat();
1355 // ////////////////////////////////////////////////////////////////////////// //
1356 procedure g_Holmes_Draw ();
1358 if g_Game_IsNet
then exit
;
1360 {$IF not DEFINED(HEADLESS)}
1361 holmesInitCommands();
1364 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
1365 glDisable(GL_STENCIL_TEST
);
1366 glDisable(GL_BLEND
);
1367 glDisable(GL_SCISSOR_TEST
);
1368 glDisable(GL_TEXTURE_2D
);
1370 if gGameOn
then plrDebugDraw();
1377 procedure g_Holmes_DrawUI ();
1379 if g_Game_IsNet
then exit
;
1380 if not g_holmes_enabled
then exit
;
1381 {$IF not DEFINED(HEADLESS)}
1382 gGfxDoClear
:= false;
1383 //if assigned(prerenderFrameCB) then prerenderFrameCB();
1385 glMatrixMode(GL_MODELVIEW
);
1389 if assigned(postrenderFrameCB
) then postrenderFrameCB();
1397 // ////////////////////////////////////////////////////////////////////////// //
1398 procedure bcOneMonsterThinkStep (); begin gmon_debug_think
:= false; gmon_debug_one_think_step
:= true; end;
1399 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active
:= false; g_dbgpan_mplat_step
:= true; end;
1400 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active
:= not g_dbgpan_mplat_active
; end;
1402 procedure bcToggleMonsterInfo (arg
: Integer=-1); begin if (arg
< 0) then showMonsInfo
:= not showMonsInfo
else showMonsInfo
:= (arg
> 0); end;
1403 procedure bcToggleMonsterLOSPlr (arg
: Integer=-1); begin if (arg
< 0) then showMonsLOS2Plr
:= not showMonsLOS2Plr
else showMonsLOS2Plr
:= (arg
> 0); end;
1404 procedure bcToggleMonsterCells (arg
: Integer=-1); begin if (arg
< 0) then showAllMonsCells
:= not showAllMonsCells
else showAllMonsCells
:= (arg
> 0); end;
1405 procedure bcToggleDrawTriggers (arg
: Integer=-1); begin if (arg
< 0) then showTriggers
:= not showTriggers
else showTriggers
:= (arg
> 0); end;
1407 procedure bcToggleCurPos (arg
: Integer=-1); begin if (arg
< 0) then showMapCurPos
:= not showMapCurPos
else showMapCurPos
:= (arg
> 0); end;
1408 procedure bcToggleGrid (arg
: Integer=-1); begin if (arg
< 0) then showGrid
:= not showGrid
else showGrid
:= (arg
> 0); end;
1410 procedure bcMonsterSpawn (s
: AnsiString);
1414 if not gGameOn
or g_Game_IsClient
then
1416 conwriteln('cannot spawn monster in this mode');
1419 mon
:= g_Mons_SpawnAt(s
, pmsCurMapX
, pmsCurMapY
);
1420 if (mon
= nil) then begin conwritefln('unknown monster id: ''%s''', [s
]); exit
; end;
1421 monMarkedUID
:= mon
.UID
;
1424 procedure bcMonsterWakeup ();
1428 if (monMarkedUID
<> -1) then
1430 mon
:= g_Monsters_ByUID(monMarkedUID
);
1431 if (mon
<> nil) then mon
.WakeUp();
1435 procedure bcPlayerTeleport ();
1437 x
, y
, w
, h
: Integer;
1439 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1440 if (gPlayers
[0] <> nil) then
1442 gPlayers
[0].getMapBox(x
, y
, w
, h
);
1443 gPlayers
[0].TeleportTo(pmsCurMapX
-w
div 2, pmsCurMapY
-h
div 2, true, 69); // 69: don't change dir
1447 procedure dbgToggleTraceBox (arg
: Integer=-1); begin if (arg
< 0) then showTraceBox
:= not showTraceBox
else showTraceBox
:= (arg
> 0); end;
1449 procedure dbgToggleHolmesPause (arg
: Integer=-1); begin if (arg
< 0) then g_Game_HolmesPause(not gPauseHolmes
) else g_Game_HolmesPause(arg
> 0); end;
1451 procedure cbAtcurSelectMonster ();
1452 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1454 result
:= true; // stop
1455 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), TMsgType
.Notify
);
1456 monMarkedUID
:= mon
.UID
;
1457 dumpPublishedProperties(mon
);
1461 x
, y
, w
, h
: Integer;
1464 if (Length(gPlayers
) > 0) then
1467 if (plr
<> nil) then
1469 plr
.getMapBox(x
, y
, w
, h
);
1470 if (pmsCurMapX
>= x
) and (pmsCurMapY
>= y
) and (pmsCurMapX
< x
+w
) and (pmsCurMapY
< y
+h
) then
1472 dumpPublishedProperties(plr
);
1476 //e_WriteLog('===========================', MSG_NOTIFY);
1477 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1478 //e_WriteLog('---------------------------', MSG_NOTIFY);
1481 procedure cbAtcurDumpMonsters ();
1482 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1484 result
:= false; // don't stop
1485 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), TMsgType
.Notify
);
1488 e_WriteLog('===========================', TMsgType
.Notify
);
1489 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1490 e_WriteLog('---------------------------', TMsgType
.Notify
);
1493 procedure cbAtcurDumpWalls ();
1494 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1496 result
:= false; // don't stop
1497 if (platMarkedGUID
= -1) then platMarkedGUID
:= pan
.guid
;
1498 e_LogWritefln('wall ''%s'' #%d(%d); enabled=%d (%d); (%d,%d)-(%d,%d)', [pan
.mapId
, pan
.arrIdx
, pan
.proxyId
, Integer(pan
.Enabled
), Integer(mapGrid
.proxyEnabled
[pan
.proxyId
]), pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
]);
1499 dumpPublishedProperties(pan
);
1502 hasTrigs
: Boolean = false;
1506 platMarkedGUID
:= -1;
1507 e_WriteLog('=== TOGGLE WALL ===', TMsgType
.Notify
);
1508 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1509 e_WriteLog('--- toggle wall ---', TMsgType
.Notify
);
1510 if showTriggers
then
1512 for f
:= 0 to High(gTriggers
) do
1514 trig
:= @gTriggers
[f
];
1515 if (pmsCurMapX
>= trig
.x
) and (pmsCurMapY
>= trig
.y
) and (pmsCurMapX
< trig
.x
+trig
.width
) and (pmsCurMapY
< trig
.y
+trig
.height
) then
1517 if not hasTrigs
then begin writeln('=== TRIGGERS ==='); hasTrigs
:= true; end;
1518 writeln('trigger ''', trig
.mapId
, ''' of type ''', trigType2Str(trig
.TriggerType
), '''');
1521 if hasTrigs
then writeln('--- triggers ---');
1525 procedure cbAtcurToggleWalls ();
1526 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1528 result
:= false; // don't stop
1529 //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);
1530 if pan
.Enabled
then g_Map_DisableWallGUID(pan
.guid
) else g_Map_EnableWallGUID(pan
.guid
);
1533 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1534 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1535 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1539 // ////////////////////////////////////////////////////////////////////////// //
1540 procedure holmesInitCommands ();
1542 if (cmdlist
<> nil) then exit
;
1543 cmdAdd('win_layers', toggleLayersWindow
, 'toggle layers window', 'window control');
1544 cmdAdd('win_outline', toggleOutlineWindow
, 'toggle outline window', 'window control');
1545 cmdAdd('win_help', toggleHelpWindow
, 'toggle help window', 'window control');
1546 cmdAdd('win_options', toggleOptionsWindow
, 'toggle options window', 'window control');
1548 cmdAdd('mon_think_step', bcOneMonsterThinkStep
, 'one monster think step', 'monster control');
1549 cmdAdd('mon_info', bcToggleMonsterInfo
, 'toggle monster info', 'monster control');
1550 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr
, 'toggle monster LOS to player', 'monster control');
1551 cmdAdd('mon_cells', bcToggleMonsterCells
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1552 cmdAdd('mon_wakeup', bcMonsterWakeup
, 'wake up selected monster', 'monster control');
1554 cmdAdd('mon_spawn', bcMonsterSpawn
, 'spawn monster', 'monster control');
1556 cmdAdd('mplat_step', bcOneMPlatThinkStep
, 'one mplat think step', 'mplat control');
1557 cmdAdd('mplat_toggle', bcMPlatToggle
, 'activate/deactivate moving platforms', 'mplat control');
1559 cmdAdd('plr_teleport', bcPlayerTeleport
, 'teleport player', 'player control');
1561 cmdAdd('dbg_curpos', bcToggleCurPos
, 'toggle "show cursor position on the map"', 'various');
1562 cmdAdd('dbg_grid', bcToggleGrid
, 'toggle grid', 'various');
1563 cmdAdd('dbg_triggers', bcToggleDrawTriggers
, 'show/hide triggers (SLOW!)', 'various');
1565 cmdAdd('atcur_select_monster', cbAtcurSelectMonster
, 'select monster to operate', 'monster control');
1566 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters
, 'dump monsters in cell', 'monster control');
1567 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls
, 'dump walls in cell', 'wall control');
1568 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls
, 'disable walls', 'wall control');
1570 cmdAdd('dbg_tracebox', dbgToggleTraceBox
, 'test traceBox()', 'player control');
1572 cmdAdd('hlm_pause', dbgToggleHolmesPause
, '"Holmes" pause mode', 'game control');
1576 procedure holmesInitBinds ();
1579 pr
: TTextParser
= nil;
1580 s
, kn
, v
: AnsiString;
1585 if not keybindsInited
then
1588 keybindAdd('F1', 'win_help');
1589 keybindAdd('M-F1', 'win_options');
1590 keybindAdd('C-O', 'win_outline');
1591 keybindAdd('C-L', 'win_layers');
1593 keybindAdd('M-M', 'mon_think_step');
1594 keybindAdd('M-I', 'mon_info');
1595 keybindAdd('M-L', 'mon_los_plr');
1596 keybindAdd('M-G', 'mon_cells');
1597 keybindAdd('M-A', 'mon_wakeup');
1599 keybindAdd('M-P', 'mplat_step');
1600 keybindAdd('M-O', 'mplat_toggle');
1602 keybindAdd('C-T', 'plr_teleport');
1603 keybindAdd('M-T', 'dbg_tracebox');
1605 keybindAdd('C-P', 'dbg_curpos');
1606 keybindAdd('C-G', 'dbg_grid');
1607 keybindAdd('C-X', 'dbg_triggers');
1609 keybindAdd('C-1', 'mon_spawn zombie');
1611 keybindAdd('C-S-P', 'hlm_pause');
1614 msbindAdd('LMB', 'atcur_select_monster');
1615 msbindAdd('M-LMB', 'atcur_dump_monsters');
1616 msbindAdd('RMB', 'atcur_dump_walls');
1617 msbindAdd('M-RMB', 'atcur_disable_walls');
1619 // load bindings from file
1621 st
:= openDiskFileRO(GameDir
+'holmes.rc');
1622 pr
:= TFileTextParser
.Create(st
);
1623 conwriteln('parsing "holmes.rc"...');
1624 while (pr
.tokType
<> pr
.TTEOF
) do
1627 if (s
= 'stop') then break
1628 else if (s
= 'unbind_keys') then keybinds
:= nil
1629 else if (s
= 'unbind_mouse') then msbinds
:= nil
1630 else if (s
= 'bind') then
1632 if (pr
.tokType
= pr
.TTStr
) then s
:= pr
.expectStr(false)
1633 else if (pr
.tokType
= pr
.TTInt
) then s
:= Format('%d', [pr
.expectInt()])
1634 else s
:= pr
.expectId();
1636 if (pr
.tokType
= pr
.TTStr
) then v
:= pr
.expectStr(false)
1637 else if (pr
.tokType
= pr
.TTInt
) then v
:= Format('%d', [pr
.expectInt()])
1638 else v
:= pr
.expectId();
1640 kn
:= parseModKeys(s
, kmods
, mbuts
);
1641 if (CompareText(kn
, 'lmb') = 0) or (CompareText(kn
, 'rmb') = 0) or (CompareText(kn
, 'mmb') = 0) or (CompareText(kn
, 'None') = 0) then
1651 except on e
: Exception
do // sorry
1652 if (pr
<> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
1654 if (pr
<> nil) then pr
.Free() else st
.Free(); // ownership
1659 procedure onMouseEvent (var ev
: THMouseEvent
);
1661 if not g_holmes_enabled
then exit
;
1662 g_Holmes_MouseEvent(ev
);
1665 procedure onKeyEvent (var ev
: THKeyEvent
);
1667 if not g_holmes_enabled
then exit
;
1668 g_Holmes_KeyEvent(ev
);
1673 evMouseCB
:= onMouseEvent
;
1674 evKeyCB
:= onKeyEvent
;
1676 conRegVar('hlm_ui_scale', @gh_ui_scale
, 0.01, 5.0, 'Holmes UI scale', '', false);