From fec78040bc86a733544009c7cb29476d5f4a7a28 Mon Sep 17 00:00:00 2001
From: Stefano Merotta <97297186+stefanomerotta@users.noreply.github.com>
Date: Sat, 2 Dec 2023 01:09:26 +0100
Subject: [PATCH] fix: Fixes wrong sector shift for tilematrix iteration
(#1623)
---
Projects/Server/Maps/Map.StaticTileEnumerator.cs | 4 ++--
Projects/Server/TileMatrix/TileMatrix.cs | 12 ++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/Projects/Server/Maps/Map.StaticTileEnumerator.cs b/Projects/Server/Maps/Map.StaticTileEnumerator.cs
index de3252f68b..302d522ab9 100644
--- a/Projects/Server/Maps/Map.StaticTileEnumerator.cs
+++ b/Projects/Server/Maps/Map.StaticTileEnumerator.cs
@@ -20,7 +20,7 @@ namespace Server;
public partial class Map
{
- public ref struct StaticTileEnumerable
+ public readonly ref struct StaticTileEnumerable
{
public static StaticTileEnumerable Empty
{
@@ -69,7 +69,7 @@ public StaticTileEnumerator(Map map, Point2D p, bool includeStatics, bool includ
if (includeStatics)
{
- var tiles = map.Tiles.GetStaticBlock(p.X >> SectorShift, p.Y >> SectorShift);
+ var tiles = map.Tiles.GetStaticBlock(p.X >> TileMatrix.SectorShift, p.Y >> TileMatrix.SectorShift);
_tiles = tiles[p.X & 0x7][p.Y & 0x7];
_index = -1;
}
diff --git a/Projects/Server/TileMatrix/TileMatrix.cs b/Projects/Server/TileMatrix/TileMatrix.cs
index c52053f583..95f9ad4d38 100644
--- a/Projects/Server/TileMatrix/TileMatrix.cs
+++ b/Projects/Server/TileMatrix/TileMatrix.cs
@@ -13,19 +13,19 @@
* along with this program. If not, see . *
*************************************************************************/
+using Server.Logging;
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using System.Threading;
-using Server.Logging;
namespace Server;
public class TileMatrix
{
+ public const int SectorShift = 3;
+
private static readonly ILogger logger = LogFactory.GetLogger(typeof(TileMatrix));
private static readonly List _instances = new();
@@ -82,8 +82,8 @@ public TileMatrix(Map owner, int fileIndex, int mapID, int width, int height)
}
_fileIndex = fileIndex;
- BlockWidth = width >> 3;
- BlockHeight = height >> 3;
+ BlockWidth = width >> SectorShift;
+ BlockHeight = height >> SectorShift;
_map = owner;
@@ -296,7 +296,7 @@ public LandTile[] GetLandBlock(int x, int y)
public LandTile GetLandTile(int x, int y)
{
- var tiles = GetLandBlock(x >> 3, y >> 3);
+ var tiles = GetLandBlock(x >> SectorShift, y >> SectorShift);
return tiles[((y & 0x7) << 3) + (x & 0x7)];
}