DEADSOFTWARE

render: separate gfx logic and drawing
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Mon, 7 Jun 2021 17:15:24 +0000 (20:15 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Tue, 29 Jun 2021 09:51:11 +0000 (12:51 +0300)
src/game/Doom2DF.lpr
src/game/g_gfx.pas
src/game/opengl/r_game.pas
src/game/opengl/r_gfx.pas [new file with mode: 0644]

index 3286f29b89a26b1ae4bb1ff1aa8c5b3facf27dbc..87b41f84c59d98061329483828812f1d08fdcdbb 100644 (file)
@@ -155,6 +155,7 @@ uses
 
   r_console in 'opengl/r_console.pas',
   r_game in 'opengl/r_game.pas',
 
   r_console in 'opengl/r_console.pas',
   r_game in 'opengl/r_game.pas',
+  r_gfx in 'opengl/r_gfx.pas',
 
 {$IFDEF USE_FMOD}
   fmod in '../lib/FMOD/fmod.pas',
 
 {$IFDEF USE_FMOD}
   fmod in '../lib/FMOD/fmod.pas',
index bf8fc5aa2fd8a5e4d90b3dbd8ca47cbfb13ecfaa..3a9c79cf7b7102bce7e6e22e00dcd8e6008a491d 100644 (file)
@@ -64,8 +64,6 @@ procedure g_GFX_OnceAnim (X, Y: Integer; Anim: TAnimation; AnimType: Byte = 0);
 procedure g_Mark (x, y, Width, Height: Integer; t: Byte; st: Boolean=true);
 
 procedure g_GFX_Update ();
 procedure g_Mark (x, y, Width, Height: Integer; t: Byte; st: Boolean=true);
 
 procedure g_GFX_Update ();
-procedure g_GFX_Draw ();
-
 
 var
   gpart_dbg_enabled: Boolean = true;
 
 var
   gpart_dbg_enabled: Boolean = true;
@@ -75,6 +73,64 @@ var
 //WARNING: only for Holmes!
 function awmIsSetHolmes (x, y: Integer): Boolean; inline;
 
 //WARNING: only for Holmes!
 function awmIsSetHolmes (x, y: Integer): Boolean; inline;
 
+  type (* private state *)
+    TPartType = (Blood, Spark, Bubbles, Water);
+    TPartState = (Free, Normal, Stuck, Sleeping);
+    TFloorType = (Wall, LiquidIn, LiquidOut);
+      // Wall: floorY is just before floor
+      // LiquidIn: floorY is liquid *start* (i.e. just in a liquid)
+      // LiquidOut: floorY is liquid *end* (i.e. just out of a liquid)
+    TEnvType = (EAir, ELiquid, EWall); // where particle is now
+
+    // note: this MUST be record, so we can keep it in
+    // dynamic array and has sequential memory access pattern
+    PParticle = ^TParticle;
+    TParticle = record
+      x, y: Integer;
+      oldX, oldY: Integer;
+      velX, velY: Single;
+      accelX, accelY: Single;
+      state: TPartState;
+      particleType: TPartType;
+      red, green, blue: Byte;
+      alpha: Byte;
+      time, liveTime, waitTime: Word;
+      stickDX: Integer; // STATE_STICK: -1,1: stuck to a wall; 0: stuck to ceiling
+      justSticked: Boolean; // not used
+      floorY: Integer; // actually, floor-1; `Unknown`: unknown
+      floorType: TFloorType;
+      env: TEnvType; // where particle is now
+      ceilingY: Integer; // actually, ceiling+1; `Unknown`: unknown
+      wallEndY: Integer; // if we stuck to a wall, this is where wall ends
+
+      //k8: sorry, i have to emulate virtual methods this way, 'cause i haet `Object`
+      procedure thinkerBloodAndWater ();
+      procedure thinkerSpark ();
+     procedure thinkerBubble ();
+
+      procedure findFloor (force: Boolean=false); // this updates `floorY` if forced or Unknown
+      procedure findCeiling (force: Boolean=false); // this updates `ceilingY` if forced or Unknown
+
+      procedure freeze (); inline; // remove velocities and acceleration
+      procedure sleep (); inline; // switch to sleep mode
+
+      function checkAirStreams (): Boolean; // `true`: affected by air stream
+
+      function alive (): Boolean; inline;
+      procedure die (); inline;
+      procedure think (); inline;
+    end;
+
+    TOnceAnim = record
+      AnimType:   Byte;
+      x, y:       Integer;
+      oldX, oldY: Integer;
+      Animation:  TAnimation;
+    end;
+
+  var (* private state *)
+    Particles: array of TParticle = nil;
+    OnceAnims: array of TOnceAnim = nil;
 
 implementation
 
 
 implementation
 
@@ -88,66 +144,7 @@ uses
 const
   Unknown = Integer($7fffffff);
 
 const
   Unknown = Integer($7fffffff);
 
-
-type
-  TPartType = (Blood, Spark, Bubbles, Water);
-  TPartState = (Free, Normal, Stuck, Sleeping);
-  TFloorType = (Wall, LiquidIn, LiquidOut);
-    // Wall: floorY is just before floor
-    // LiquidIn: floorY is liquid *start* (i.e. just in a liquid)
-    // LiquidOut: floorY is liquid *end* (i.e. just out of a liquid)
-  TEnvType = (EAir, ELiquid, EWall); // where particle is now
-
-  // note: this MUST be record, so we can keep it in
-  // dynamic array and has sequential memory access pattern
-  PParticle = ^TParticle;
-  TParticle = record
-    x, y: Integer;
-    oldX, oldY: Integer;
-    velX, velY: Single;
-    accelX, accelY: Single;
-    state: TPartState;
-    particleType: TPartType;
-    red, green, blue: Byte;
-    alpha: Byte;
-    time, liveTime, waitTime: Word;
-    stickDX: Integer; // STATE_STICK: -1,1: stuck to a wall; 0: stuck to ceiling
-    justSticked: Boolean; // not used
-    floorY: Integer; // actually, floor-1; `Unknown`: unknown
-    floorType: TFloorType;
-    env: TEnvType; // where particle is now
-    ceilingY: Integer; // actually, ceiling+1; `Unknown`: unknown
-    wallEndY: Integer; // if we stuck to a wall, this is where wall ends
-
-    //k8: sorry, i have to emulate virtual methods this way, 'cause i haet `Object`
-    procedure thinkerBloodAndWater ();
-    procedure thinkerSpark ();
-    procedure thinkerBubble ();
-
-    procedure findFloor (force: Boolean=false); // this updates `floorY` if forced or Unknown
-    procedure findCeiling (force: Boolean=false); // this updates `ceilingY` if forced or Unknown
-
-    procedure freeze (); inline; // remove velocities and acceleration
-    procedure sleep (); inline; // switch to sleep mode
-
-    function checkAirStreams (): Boolean; // `true`: affected by air stream
-
-    function alive (): Boolean; inline;
-    procedure die (); inline;
-    procedure think (); inline;
-  end;
-
-  TOnceAnim = record
-    AnimType:   Byte;
-    x, y:       Integer;
-    oldX, oldY: Integer;
-    Animation:  TAnimation;
-  end;
-
-
 var
 var
-  Particles: array of TParticle = nil;
-  OnceAnims: array of TOnceAnim = nil;
   MaxParticles: Integer = 0;
   CurrentParticle: Integer = 0;
   // awakeMap has one bit for each map grid cell; on g_Mark,
   MaxParticles: Integer = 0;
   CurrentParticle: Integer = 0;
   // awakeMap has one bit for each map grid cell; on g_Mark,
@@ -1688,64 +1685,4 @@ begin
   end;
 end;
 
   end;
 end;
 
-
-procedure g_GFX_Draw ();
-  var
-    a, len, fx, fy: Integer;
-begin
-  if not gpart_dbg_enabled then exit;
-
-  if (Particles <> nil) then
-  begin
-    glDisable(GL_TEXTURE_2D);
-         if (g_dbg_scale < 0.6) then glPointSize(1)
-    else if (g_dbg_scale > 1.3) then glPointSize(g_dbg_scale+1)
-    else glPointSize(2);
-    glDisable(GL_POINT_SMOOTH);
-
-    glEnable(GL_BLEND);
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
-    glBegin(GL_POINTS);
-
-    len := High(Particles);
-    for a := 0 to len do
-    begin
-      with Particles[a] do
-      begin
-        if not alive then continue;
-        if (x >= sX) and (y >= sY) and (x <= sX+sWidth) and (sY <= sY+sHeight) then
-        begin
-          fx := nlerp(oldx, x, gLerpFactor);
-          fy := nlerp(oldy, y, gLerpFactor);
-          glColor4ub(red, green, blue, alpha);
-          glVertex2f(fx+0.37, fy+0.37);
-        end;
-      end;
-    end;
-
-    glEnd();
-
-    glDisable(GL_BLEND);
-  end;
-
-  if (OnceAnims <> nil) then
-  begin
-    len := High(OnceAnims);
-    for a := 0 to len do
-    begin
-      if (OnceAnims[a].Animation <> nil) then
-      begin
-        with OnceAnims[a] do
-        begin
-          fx := nlerp(oldx, x, gLerpFactor);
-          fy := nlerp(oldy, y, gLerpFactor);
-          Animation.Draw(x, y, TMirrorType.None);
-        end;
-      end;
-    end;
-  end;
-end;
-
-
 end.
 end.
index 6dd62a21839e82a8e581f1fbd742e8900bdb9cb7..d2ead67c0117c15fc2483501c54765c954dc973c 100644 (file)
@@ -32,7 +32,7 @@ implementation
     g_textures, e_input, e_sound,
     g_language, g_console, g_menu, g_triggers, g_player, g_options, g_monsters, g_map, g_panel, g_window,
     g_items, g_weapons, g_gfx, g_phys, g_net, g_gui, g_netmaster,
     g_textures, e_input, e_sound,
     g_language, g_console, g_menu, g_triggers, g_player, g_options, g_monsters, g_map, g_panel, g_window,
     g_items, g_weapons, g_gfx, g_phys, g_net, g_gui, g_netmaster,
-    g_game, r_console
+    g_game, r_console, r_gfx
   ;
 
   var
   ;
 
   var
@@ -1247,7 +1247,7 @@ begin
   drawOther('monsters', @g_Monsters_Draw);
   drawOther('itemdrop', @g_Items_DrawDrop);
   drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
   drawOther('monsters', @g_Monsters_Draw);
   drawOther('itemdrop', @g_Items_DrawDrop);
   drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
-  drawOther('gfx', @g_GFX_Draw);
+  drawOther('gfx', @r_GFX_Draw);
   drawOther('flags', @g_Map_DrawFlags);
   drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
   drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
   drawOther('flags', @g_Map_DrawFlags);
   drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
   drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
diff --git a/src/game/opengl/r_gfx.pas b/src/game/opengl/r_gfx.pas
new file mode 100644 (file)
index 0000000..6b27ec3
--- /dev/null
@@ -0,0 +1,91 @@
+(* Copyright (C)  Doom 2D: Forever Developers
+ *
+ * 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, 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *)
+{$INCLUDE ../../shared/a_modes.inc}
+unit r_gfx;
+
+interface
+
+  procedure r_GFX_Draw;
+
+implementation
+
+  uses
+    {$INCLUDE ../nogl/noGLuses.inc}
+    SysUtils, Classes, Math,
+    utils,
+    e_graphics,
+    g_game,
+    g_gfx
+  ;
+
+procedure r_GFX_Draw;
+  var
+    a, len, fx, fy: Integer;
+begin
+  if not gpart_dbg_enabled then exit;
+
+  if (Particles <> nil) then
+  begin
+    glDisable(GL_TEXTURE_2D);
+         if (g_dbg_scale < 0.6) then glPointSize(1)
+    else if (g_dbg_scale > 1.3) then glPointSize(g_dbg_scale+1)
+    else glPointSize(2);
+    glDisable(GL_POINT_SMOOTH);
+
+    glEnable(GL_BLEND);
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+    glBegin(GL_POINTS);
+
+    len := High(Particles);
+    for a := 0 to len do
+    begin
+      with Particles[a] do
+      begin
+        if not alive then continue;
+        if (x >= sX) and (y >= sY) and (x <= sX+sWidth) and (sY <= sY+sHeight) then
+        begin
+          fx := nlerp(oldx, x, gLerpFactor);
+          fy := nlerp(oldy, y, gLerpFactor);
+          glColor4ub(red, green, blue, alpha);
+          glVertex2f(fx+0.37, fy+0.37);
+        end;
+      end;
+    end;
+
+    glEnd();
+
+    glDisable(GL_BLEND);
+  end;
+
+  if (OnceAnims <> nil) then
+  begin
+    len := High(OnceAnims);
+    for a := 0 to len do
+    begin
+      if (OnceAnims[a].Animation <> nil) then
+      begin
+        with OnceAnims[a] do
+        begin
+          fx := nlerp(oldx, x, gLerpFactor);
+          fy := nlerp(oldy, y, gLerpFactor);
+          Animation.Draw(x, y, TMirrorType.None);
+        end;
+      end;
+    end;
+  end;
+end;
+
+end.