DEADSOFTWARE

render: load shell textures in render
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Mon, 17 Jan 2022 16:35:32 +0000 (19:35 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Fri, 9 Jun 2023 07:53:39 +0000 (10:53 +0300)
src/game/g_player.pas
src/game/g_weapons.pas
src/game/opengl/r_player.pas

index 7f6516397df411b6236cf890038e3aadde0efdf9..8aa0a7df42ca1edaefc70d9a825660cc5e41d8fc 100644 (file)
@@ -539,12 +539,10 @@ type
 
   PShell = ^TShell;
   TShell = record
-    SpriteID: DWORD;
-    alive:     Boolean;
+    alive:    Boolean;
     SType:    Byte;
     RAngle:   Integer;
     Timeout:  Cardinal;
-    CX, CY:   Integer;
     Obj:      TObj;
 
     procedure getMapBox (out x, y, w, h: Integer); inline;
@@ -1538,33 +1536,22 @@ begin
 end;
 
 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
-var
-  SID: DWORD;
 begin
   if (gShells = nil) or (Length(gShells) = 0) then
     Exit;
 
   with gShells[CurrentShell] do
   begin
-    SpriteID := 0;
     g_Obj_Init(@Obj);
     Obj.Rect.X := 0;
     Obj.Rect.Y := 0;
     if T = SHELL_BULLET then
     begin
-      if g_Texture_Get('TEXTURE_SHELL_BULLET', SID) then
-        SpriteID := SID;
-      CX := 2;
-      CY := 1;
       Obj.Rect.Width := 4;
       Obj.Rect.Height := 2;
     end
     else
     begin
-      if g_Texture_Get('TEXTURE_SHELL_SHELL', SID) then
-        SpriteID := SID;
-      CX := 4;
-      CY := 2;
       Obj.Rect.Width := 7;
       Obj.Rect.Height := 3;
     end;
index a5114e15a613670dd90af85c54bd33668b9ce2c0..fc539280d670a88d3865bcced28f874febf908e1 100644 (file)
@@ -1137,9 +1137,6 @@ begin
   g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
   g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
 
-  g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
-  g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
-
   //wgunMonHash := hashNewIntInt();
   wgunHitHeap := TBinaryHeapHitTimes.Create();
 end;
index 93f1b2398a32e7bc4eb3ed7ed19b8a5630230327..650aa225c859749b644559a233aa04cb755fbbc0 100644 (file)
@@ -52,6 +52,8 @@ implementation
 
   var
     PunchFrames: array [Boolean, 0..2] of DWORD;
+    BulletTexture: DWORD;
+    ShellTexture: DWORD;
 
   procedure r_Player_Load;
   begin
@@ -61,6 +63,10 @@ implementation
     g_Frames_CreateWAD(@PunchFrames[True, 0], 'FRAMES_PUNCH_BERSERK', GameWAD + ':WEAPONS\PUNCHB', 64, 64, 4, False);
     g_Frames_CreateWAD(@PunchFrames[True, 1], 'FRAMES_PUNCH_BERSERK_UP', GameWAD + ':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
     g_Frames_CreateWAD(@PunchFrames[True, 2], 'FRAMES_PUNCH_BERSERK_DN', GameWAD + ':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
+    g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD + ':TEXTURES\EBULLET');
+    g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD + ':TEXTURES\ESHELL');
+    g_Texture_Get('TEXTURE_SHELL_BULLET', BulletTexture);
+    g_Texture_Get('TEXTURE_SHELL_SHELL', ShellTexture);
   end;
 
   procedure r_Player_Free;
@@ -140,27 +146,37 @@ end;
           r_Player_DrawCorpse(gCorpses[i])
   end;
 
-procedure r_Player_DrawShells;
-var
-  i, fX, fY: Integer;
-  a: TDFPoint;
-begin
-  if gShells <> nil then
-    for i := 0 to High(gShells) do
-      if gShells[i].alive then
-        with gShells[i] do
+  procedure r_Player_DrawShells;
+    var i, fX, fY: Integer; a: TDFPoint; TextureID: DWORD = DWORD(-1);
+  begin
+    if gShells <> nil then
+    begin
+      for i := 0 to High(gShells) do
+      begin
+        if gShells[i].alive and g_Obj_Collide(sX, sY, sWidth, sHeight, @gShells[i].Obj) then
         begin
-          if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
-            Continue;
-
-          Obj.lerp(gLerpFactor, fX, fY);
-
-          a.X := CX;
-          a.Y := CY;
-
-          e_DrawAdv(SpriteID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
-        end;
-end;
+          gShells[i].Obj.lerp(gLerpFactor, fX, fY);
+          case gShells[i].SType of
+            SHELL_BULLET:
+            begin
+              TextureID := BulletTexture;
+              a.X := 2;
+              a.Y := 1;
+            end;
+            SHELL_SHELL, SHELL_DBLSHELL:
+            begin
+              TextureID := ShellTexture;
+              a.X := 4;
+              a.Y := 2;
+            end
+          else
+            Assert(false)
+          end;
+          e_DrawAdv(TextureID, fX, fY, 0, True, False, gShells[i].RAngle, @a, TMirrorType.None);
+        end
+      end
+    end
+  end;
 
 procedure r_Player_DrawIndicator (p: TPlayer; Color: TRGB);
 var