DEADSOFTWARE

render: use only r_render to access render-specific info
[d2df-sdl.git] / src / game / g_holmes.pas
index 83b74acc2ba7c6d00f9cbee483d13832f3adf8b1..414a30fe1ba40f1049230fe614de323a78fa3ea2 100644 (file)
@@ -2,8 +2,7 @@
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, version 3 of the License ONLY.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -21,8 +20,8 @@ interface
 uses
   mempool, geom,
   e_log, e_input,
-  g_textures, g_basic, e_graphics, g_phys, g_grid, g_player, g_monsters,
-  g_window, g_map, g_triggers, g_items, g_game, g_panel, g_console, g_gfx,
+  g_basic, g_phys, g_grid, g_player, g_monsters,
+  g_map, g_triggers, g_items, g_game, g_panel, g_console,
   xprofiler,
   sdlcarcass,
   fui_common, fui_events, fui_ctls,
@@ -48,14 +47,16 @@ var
 implementation
 
 uses
-{$IFDEF USE_NANOGL}
-  nanoGL,
-{$ELSE}
-  GL,
-{$ENDIF}
-  {rttiobj,} typinfo, e_texture,
+  {$INCLUDE ../nogl/noGLuses.inc}
+  {$IFDEF ENABLE_GFX}
+    g_gfx,
+  {$ENDIF}
+  {$IFDEF ENABLE_GIBS}
+    g_gibs,
+  {$ENDIF}
+  {rttiobj,} typinfo, e_res,
   SysUtils, Classes, SDL2,
-  MAPDEF, g_main, g_options,
+  MAPDEF, g_options,
   utils, hashtable, xparser;
 
 
@@ -564,7 +565,7 @@ var
 
   procedure clearEdgeBmp ();
   begin
-    SetLength(edgeBmp, (gWinSizeX+4)*(gWinSizeY+4));
+    SetLength(edgeBmp, (gScreenWidth+4)*(gScreenHeight+4));
     FillChar(edgeBmp[0], Length(edgeBmp)*sizeof(edgeBmp[0]), 0);
   end;
 
@@ -579,19 +580,19 @@ var
     begin
       sx := pan.X-(vpx-1);
       len := pan.Width;
-      if (len > gWinSizeX+4) then len := gWinSizeX+4;
+      if (len > gScreenWidth+4) then len := gScreenWidth+4;
       if (sx < 0) then begin len += sx; sx := 0; end;
-      if (sx+len > gWinSizeX+4) then len := gWinSizeX+4-sx;
+      if (sx+len > gScreenWidth+4) then len := gScreenWidth+4-sx;
       if (len < 1) then exit;
       assert(sx >= 0);
-      assert(sx+len <= gWinSizeX+4);
+      assert(sx+len <= gScreenWidth+4);
       y0 := pan.Y-(vpy-1);
       y1 := y0+pan.Height;
       if (y0 < 0) then y0 := 0;
-      if (y1 > gWinSizeY+4) then y1 := gWinSizeY+4;
+      if (y1 > gScreenHeight+4) then y1 := gScreenHeight+4;
       while (y0 < y1) do
       begin
-        FillChar(edgeBmp[y0*(gWinSizeX+4)+sx], len*sizeof(edgeBmp[0]), 1);
+        FillChar(edgeBmp[y0*(gScreenWidth+4)+sx], len*sizeof(edgeBmp[0]), 1);
         Inc(y0);
       end;
     end
@@ -656,15 +657,15 @@ var
     glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
     for y := 1 to vph do
     begin
-      a := @edgeBmp[y*(gWinSizeX+4)+1];
+      a := @edgeBmp[y*(gScreenWidth+4)+1];
       startLine(y);
       for x := 1 to vpw do
       begin
         if (a[0] <> 0) then
         begin
-          if (a[-1] = 0) or (a[1] = 0) or (a[-(gWinSizeX+4)] = 0) or (a[gWinSizeX+4] = 0) or
-             (a[-(gWinSizeX+4)-1] = 0) or (a[-(gWinSizeX+4)+1] = 0) or
-             (a[gWinSizeX+4-1] = 0) or (a[gWinSizeX+4+1] = 0) then
+          if (a[-1] = 0) or (a[1] = 0) or (a[-(gScreenWidth+4)] = 0) or (a[gScreenWidth+4] = 0) or
+             (a[-(gScreenWidth+4)-1] = 0) or (a[-(gScreenWidth+4)+1] = 0) or
+             (a[gScreenWidth+4-1] = 0) or (a[gScreenWidth+4+1] = 0) then
           begin
             putPixel(x);
           end;
@@ -689,7 +690,7 @@ var
     glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
     for y := 1 to vph do
     begin
-      a := @edgeBmp[y*(gWinSizeX+4)+1];
+      a := @edgeBmp[y*(gScreenWidth+4)+1];
       startLine(y);
       for x := 1 to vpw do
       begin
@@ -921,6 +922,7 @@ procedure plrDebugDraw ();
     end;
   end;
 
+{$IFDEF ENABLE_GFX}
   procedure drawAwakeCells ();
   var
     x, y: Integer;
@@ -937,6 +939,7 @@ procedure plrDebugDraw ();
       end;
     end;
   end;
+{$ENDIF}
 
   procedure drawTraceBox ();
   var
@@ -1229,6 +1232,7 @@ procedure plrDebugDraw ();
     for f := 0 to High(gTriggers) do drawTrigger(gTriggers[f]);
   end;
 
+{$IFDEF ENABLE_GIBS}
   procedure drawGibsBoxes ();
   var
     f: Integer;
@@ -1246,6 +1250,7 @@ procedure plrDebugDraw ();
       end;
     end;
   end;
+{$ENDIF}
 
 var
   mon: TMonster;
@@ -1254,6 +1259,8 @@ var
   mx, my, mw, mh: Integer;
   //pan: TPanel;
   //ex, ey: Integer;
+  s: AnsiString;
+  dx, dy: Integer;
 begin
   if (gPlayer1 = nil) then exit;
 
@@ -1261,7 +1268,7 @@ begin
 
   gxSetContext(hlmContext);
   try
-    //glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph);
+    //glScissor(0, gScreenHeight-gPlayerScreenSize.Y-1, vpw, vph);
     //hlmContext.clip := TGxRect.Create(0, gScreenHeight-gPlayerScreenSize.Y-1, gPlayerScreenSize.X, gPlayerScreenSize.Y);
 
     {
@@ -1300,12 +1307,15 @@ begin
     if showTriggers then drawTriggers();
     if showGrid then drawSelectedPlatformCells();
 
-    //drawAwakeCells();
+    {$IFDEF ENABLE_GFX}
+      // drawAwakeCells();
+    {$ENDIF}
 
     if showTraceBox then drawTraceBox();
 
-    //drawGibsBoxes();
-
+    {$IFDEF ENABLE_GIBS}
+      // drawGibsBoxes();
+    {$ENDIF}
 
     //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey);
     (*
@@ -1328,10 +1338,19 @@ begin
 
   if showMapCurPos then
   begin
+    s := Format('mappos:(%d,%d)', [pmsCurMapX, pmsCurMapY]);
     gxSetContext(hlmContext);
     hlmContext.font := 'win8';
+    hlmContext.color := TGxRGBA.Create(0, 0, 0);
+    for dy := -1 to 1 do
+    begin
+      for dx := -1 to 1 do
+      begin
+        if (dx <> 0) or (dy <> 0) then hlmContext.drawText(4+dx, gScreenHeight-10+dy, s);
+      end;
+    end;
     hlmContext.color := TGxRGBA.Create(255, 255, 0);
-    hlmContext.drawText(4, gWinSizeY-10, Format('mappos:(%d,%d)', [pmsCurMapX, pmsCurMapY]));
+    hlmContext.drawText(4, gScreenHeight-10, s);
     gxSetContext(nil);
   end;
 end;
@@ -1387,12 +1406,8 @@ end;
 
 // ////////////////////////////////////////////////////////////////////////// //
 procedure g_Holmes_OnEvent (var ev: TFUIEvent);
-{$IF not DEFINED(HEADLESS)}
-var
-  doeat: Boolean = false;
-{$ENDIF}
+  var doeat: Boolean = false;
 begin
-{$IF not DEFINED(HEADLESS)}
   if g_Game_IsNet then exit;
   if not g_holmes_enabled then exit;
   if g_holmes_imfunctional then exit;
@@ -1405,12 +1420,14 @@ begin
 
   if (ev.key) then
   begin
+{$IFDEF USE_SDL2}
     case ev.scan of
       SDL_SCANCODE_LCTRL, SDL_SCANCODE_RCTRL,
       SDL_SCANCODE_LALT, SDL_SCANCODE_RALT,
       SDL_SCANCODE_LSHIFT, SDL_SCANCODE_RSHIFT:
         doeat := true;
     end;
+{$ENDIF}
   end
   else if (ev.mouse) then
   begin
@@ -1436,7 +1453,6 @@ begin
   end;
 
   if (doeat) then ev.eat();
-{$ENDIF}
 end;
 
 
@@ -1447,10 +1463,10 @@ begin
   if not g_holmes_enabled then exit;
   if g_holmes_imfunctional then exit;
 
-  {$IF not DEFINED(HEADLESS)}
   holmesInitCommands();
   holmesInitBinds();
 
+{$IFDEF ENABLE_RENDER}
   glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
   glDisable(GL_STENCIL_TEST);
   glDisable(GL_BLEND);
@@ -1458,7 +1474,7 @@ begin
   glDisable(GL_TEXTURE_2D);
 
   if gGameOn then plrDebugDraw();
-  {$ENDIF}
+{$ENDIF}
 
   laserSet := false;
 end;
@@ -1470,8 +1486,9 @@ begin
   if not g_holmes_enabled then exit;
   if g_holmes_imfunctional then exit;
 
-  {$IF not DEFINED(HEADLESS)}
   gGfxDoClear := false;
+
+{$IFDEF ENABLE_RENDER}
   //if assigned(prerenderFrameCB) then prerenderFrameCB();
   uiDraw();
   glMatrixMode(GL_MODELVIEW);
@@ -1482,7 +1499,7 @@ begin
   finally
     glPopMatrix();
   end;
-  {$ENDIF}
+{$ENDIF}
 end;
 
 
@@ -1734,7 +1751,7 @@ begin
 
     // load bindings from file
     try
-      st := openDiskFileRO(GameDir+'holmes.rc');
+      st := e_OpenResourceRO(ConfigDirs, 'holmes.rc');
       pr := TFileTextParser.Create(st);
       conwriteln('parsing "holmes.rc"...');
       while (pr.tokType <> pr.TTEOF) do