DEADSOFTWARE

game: fix spectator camera
[d2df-sdl.git] / src / game / renders / opengl / r_map.pas
index 371b13db5ac8810e30444257144ad501c272054e..ecc219200a203a4c8d0a58298849c33350299731 100644 (file)
@@ -42,6 +42,7 @@ interface
   procedure r_Map_Update;
 
   procedure r_Map_Draw (x, y, w, h, camx, camy: Integer; player: TPlayer; out acx, acy: Integer);
+  procedure r_Map_GetSpectatorLimits (out x0, y0, x1, y1: Integer);
 
 implementation
 
@@ -584,12 +585,13 @@ implementation
   end;
 
   procedure r_Map_DrawPanel (p: TPanel);
-    var Texture, spec: Integer; t: TGLMultiTexture; count, frame: LongInt; a: TAnimInfo;
+    var Texture, x, y, w, h: Integer; t: TGLMultiTexture; count, frame: LongInt; a: TAnimInfo;
   begin
     ASSERT(p <> nil);
     ASSERT(p.FCurTexture >= -1); (* p.FCurTexture = -1 -> invisible texture *)
     if p.FCurTexture >= 0 then
     begin
+      r_Common_GetPanelPos(p, x, y, w, h);
       ASSERT(p.FCurTexture <= High(p.TextureIDs));
       Texture := p.TextureIDs[p.FCurTexture].Texture;
       ASSERT(Texture >= -1); (* Texture = -1 -> texture not found *)
@@ -606,21 +608,21 @@ implementation
             a.loop := p.AnimLoop;
             g_Anim_GetFrameByTime(a, (gTime - p.AnimTime) DIV GAME_TICK, count, frame);
           end;
-          r_Draw_TextureRepeat(t.GetTexture(frame), p.x, p.y, p.width, p.height, false, 255, 255, 255, 255 - p.alpha, p.blending);
+          r_Draw_TextureRepeat(t.GetTexture(frame), x, y, w, h, false, 255, 255, 255, 255 - p.alpha, p.blending);
         end
         else if RenTextures[Texture].spec = 0 then
         begin
-          r_Draw_TextureRepeat(nil, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255, false);
+          r_Draw_TextureRepeat(nil, x, y, w, h, false, 255, 255, 255, 255, false);
         end;
         case RenTextures[Texture].spec of
-          TEXTURE_SPECIAL_WATER: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 0, 255, 255);
-          TEXTURE_SPECIAL_ACID1: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 230, 0, 255);
-          TEXTURE_SPECIAL_ACID2: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 230, 0, 0, 255);
+          TEXTURE_SPECIAL_WATER: r_Draw_Filter(x, y, x + w, y + h, 0, 0, 255, 255);
+          TEXTURE_SPECIAL_ACID1: r_Draw_Filter(x, y, x + w, y + h, 0, 230, 0, 255);
+          TEXTURE_SPECIAL_ACID2: r_Draw_Filter(x, y, x + w, y + h, 230, 0, 0, 255);
         end;
       end
       else
       begin
-        r_Draw_TextureRepeat(nil, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255, false);
+        r_Draw_TextureRepeat(nil, x, y, w, h, false, 255, 255, 255, 255, false);
       end;
     end;
   end;
@@ -702,7 +704,7 @@ implementation
   end;
 
   function r_Map_GetMonsterTexture (m, a: Integer; d: TDirection; out t: TGLMultiTexture; out dx, dy: Integer; out flip: Boolean): Boolean;
-    // var c: Integer;
+    var w: Integer;
   begin
     t := nil; dx := 0; dy := 0; flip := false;
     result := MonTextures[m, a, d] <> nil;
@@ -727,9 +729,8 @@ implementation
       end;
       if flip then
       begin
-//        c := (MONSTERTABLE[MonsterType].Rect.X - dx) + MONSTERTABLE[MonsterType].Rect.Width;
-//        dx := MTABLE[m].width - c - MONSTERTABLE[MonsterType].Rect.X;
-        dx := -dx;
+        if (m = MONSTER_SOUL) and (a = ANIM_DIE) then w := 64 else w := 0;
+        dx := -dx - w;
       end;
     end;
   end;
@@ -752,16 +753,20 @@ implementation
   end;
 
   procedure r_Map_DrawMonster (constref mon: TMonster);
-    var m, a, xx, yy, dx, dy: Integer; d: TDirection; flip: Boolean; t: TGLMultiTexture;
+    var m, a, xx, yy, dx, dy: Integer; d, da: TDirection; flip: Boolean; t: TGLMultiTexture;
   begin
     m := mon.MonsterType;
     a := mon.MonsterAnim;
     d := mon.GameDirection;
 
+    (* hack: barrel tracks player, fix it in game logic *)
+    if m = MONSTER_BARREL then d := TDirection.D_LEFT;
+
     r_Common_GetObjectPos(mon.obj, xx, yy);
     if r_Map_GetMonsterTexture(m, a, d, t, dx, dy, flip) then
     begin
-      r_Draw_MultiTextureRepeat(t, mon.DirAnim[a, d], false, xx + dx, yy + dy, t.width, t.height, flip, 255, 255, 255, 255, false);
+      da := mon.GameDirection;
+      r_Draw_MultiTextureRepeat(t, mon.DirAnim[a, da], false, xx + dx, yy + dy, t.width, t.height, flip, 255, 255, 255, 255, false);
     end;
     if DebugFrames then
     begin
@@ -1707,6 +1712,34 @@ implementation
     g_Anim_GetFrameByTime(FlagAnim, tick, count, FlagFrame);
   end;
 
+  procedure r_Map_GetSpectatorLimits (out x0, y0, x1, y1: Integer);
+    var w, h: Integer;
+  begin
+    w := Round(gScreenWidth / g_dbg_scale);
+    if gMapInfo.Width > w then
+    begin
+      x0 := w div 2;
+      x1 := gMapInfo.Width - w div 2 - 1;
+    end
+    else
+    begin
+      x0 := gMapInfo.Width div 2;
+      x1 := gMapInfo.Width div 2;
+    end;
+
+    h := Round(gScreenHeight / g_dbg_scale);
+    if gMapInfo.Height > h then
+    begin
+      y0 := h div 2;
+      y1 := gMapInfo.Height - h div 2 - 1;
+    end
+    else
+    begin
+      y0 := gMapInfo.Height div 2;
+      y1 := gMapInfo.Height div 2;
+    end;
+  end;
+
 initialization
   conRegVar('r_sq_draw', @UseAccel, 'accelerated spatial queries in rendering', 'accelerated rendering');
   conRegVar('r_debug_camera_scale', @DebugCameraScale, 0.0001, 1000.0, '', '');