Skip to content

Commit

Permalink
fix: Fixes wrong sector shift for tilematrix iteration (#1623)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanomerotta authored Dec 2, 2023
1 parent 130a567 commit fec7804
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Projects/Server/Maps/Map.StaticTileEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Server;

public partial class Map
{
public ref struct StaticTileEnumerable
public readonly ref struct StaticTileEnumerable
{
public static StaticTileEnumerable Empty
{
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions Projects/Server/TileMatrix/TileMatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/

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<TileMatrix> _instances = new();

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)];
}
Expand Down

0 comments on commit fec7804

Please sign in to comment.