Skip to content

Commit

Permalink
Decoupled CUO libs from Shared, Server and Client
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Jan 28, 2025
1 parent 553cae0 commit 32ee05c
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 36 deletions.
4 changes: 3 additions & 1 deletion CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ public void Load(string clientPath, string clientVersion)
}
}
ValidStaticIds = staticIds.ToArray();
Client.InitTileData(ref tdl.LandData, ref tdl.StaticData);
var landTileData = tdl.LandData.Select(ltd => new TileDataLand((ulong)ltd.Flags, ltd.TexID, ltd.Name)).ToArray();
var staticTileData = tdl.StaticData.Select(std => new TileDataStatic((ulong)std.Flags, std.Weight, std.Layer, std.Count, std.AnimID, std.Hue, std.LightIndex, std.Height, std.Name)).ToArray();
Client.InitTileData(landTileData, staticTileData);
}

public Vector2 Position
Expand Down
7 changes: 3 additions & 4 deletions Client/CentrEDClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Net.Sockets;
using CentrED.Client.Map;
using CentrED.Network;
using ClassicUO.Assets;
using static CentrED.Client.AdminHandling;

namespace CentrED.Client;
Expand Down Expand Up @@ -36,8 +35,8 @@ public sealed class CentrEDClient : ILogging, IDisposable
public List<String> Clients { get; } = new();
public bool Running;
private string? _status;
internal LandTiles[]? LandTileData;
internal StaticTiles[]? StaticTileData;
internal TileDataLand[]? LandTileData;
internal TileDataStatic[]? StaticTileData;
public Admin Admin = new([], []);

public string Status
Expand Down Expand Up @@ -72,7 +71,7 @@ public void Connect(string hostname, int port, string username, string password)
} while (!Initialized && Running);
}

public void InitTileData(ref LandTiles[] landTileData, ref StaticTiles[] staticTileData)
public void InitTileData(TileDataLand[] landTileData, TileDataStatic[] staticTileData)
{
LandTileData = landTileData;
StaticTileData = staticTileData;
Expand Down
6 changes: 0 additions & 6 deletions Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,4 @@
<ProjectReference Include="..\Shared\Shared.csproj"/>
</ItemGroup>

<ItemGroup>
<Reference Include="ClassicUO.Assets">
<HintPath>..\lib\x64\ClassicUO.Assets.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
6 changes: 0 additions & 6 deletions Server/Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,4 @@
<ProjectReference Include="..\Shared\Shared.csproj"/>
</ItemGroup>

<ItemGroup>
<Reference Include="ClassicUO.Assets">
<HintPath>..\lib\x64\ClassicUO.Assets.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
6 changes: 0 additions & 6 deletions Shared/Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,4 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

<ItemGroup>
<Reference Include="ClassicUO.Assets">
<HintPath>..\lib\x64\ClassicUO.Assets.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
5 changes: 2 additions & 3 deletions Shared/StaticBlock.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.ObjectModel;
using CentrED.Network;
using ClassicUO.Assets;

namespace CentrED;

Expand Down Expand Up @@ -93,7 +92,7 @@ internal bool RemoveTileInternal(StaticTile tile)
return removed;
}

public void SortTiles(ref StaticTiles[] tiledata)
public void SortTiles(ref TileDataStatic[] tiledata)
{
foreach (var staticTiles in _tiles)
{
Expand All @@ -102,7 +101,7 @@ public void SortTiles(ref StaticTiles[] tiledata)
foreach (var tile in staticTiles)
{
if (tile.Id < tiledata.Length)
tile.UpdatePriority(tiledata[tile.Id]);
tile.UpdatePriority(ref tiledata[tile.Id]);
else
{
Landscape.LogError($"StaticTile with invalid Id: {tile.Id}@{tile.X},{tile.Y},{tile.Z}");
Expand Down
3 changes: 1 addition & 2 deletions Shared/StaticTile.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CentrED.Network;
using ClassicUO.Assets;

namespace CentrED;

Expand Down Expand Up @@ -136,7 +135,7 @@ public void UpdatePos(ushort newX, ushort newY, sbyte newZ)
_block?.OnChanged();
}

public void UpdatePriority(StaticTiles tileData)
public void UpdatePriority(ref TileDataStatic tileData)
{
PriorityZ = _z;
if (tileData.IsBackground)
Expand Down
152 changes: 152 additions & 0 deletions Shared/TileDataFlag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
namespace CentrED;

[Flags]
public enum TileDataFlag : ulong
{
/// <summary>
/// Nothing is flagged.
/// </summary>
None = 0x00000000,
/// <summary>
/// Not yet documented.
/// </summary>
Background = 0x00000001,
/// <summary>
/// Not yet documented.
/// </summary>
Weapon = 0x00000002,
/// <summary>
/// Not yet documented.
/// </summary>
Transparent = 0x00000004,
/// <summary>
/// The tile is rendered with partial alpha-transparency.
/// </summary>
Translucent = 0x00000008,
/// <summary>
/// The tile is a wall.
/// </summary>
Wall = 0x00000010,
/// <summary>
/// The tile can cause damage when moved over.
/// </summary>
Damaging = 0x00000020,
/// <summary>
/// The tile may not be moved over or through.
/// </summary>
Impassable = 0x00000040,
/// <summary>
/// Not yet documented.
/// </summary>
Wet = 0x00000080,
/// <summary>
/// Unknown.
/// </summary>
Unknown1 = 0x00000100,
/// <summary>
/// The tile is a surface. It may be moved over, but not through.
/// </summary>
Surface = 0x00000200,
/// <summary>
/// The tile is a stair, ramp, or ladder.
/// </summary>
Bridge = 0x00000400,
/// <summary>
/// The tile is stackable
/// </summary>
Generic = 0x00000800,
/// <summary>
/// The tile is a window. Like <see cref="TileDataFlag.NoShoot" />, tiles with this flag block line of sight.
/// </summary>
Window = 0x00001000,
/// <summary>
/// The tile blocks line of sight.
/// </summary>
NoShoot = 0x00002000,
/// <summary>
/// For single-amount tiles, the string "a " should be prepended to the tile name.
/// </summary>
ArticleA = 0x00004000,
/// <summary>
/// For single-amount tiles, the string "an " should be prepended to the tile name.
/// </summary>
ArticleAn = 0x00008000,
/// <summary>
/// Not yet documented.
/// </summary>
Internal = 0x00010000,
/// <summary>
/// The tile becomes translucent when walked behind. Boat masts also have this flag.
/// </summary>
Foliage = 0x00020000,
/// <summary>
/// Only gray pixels will be hued
/// </summary>
PartialHue = 0x00040000,
/// <summary>
/// Unknown.
/// </summary>
NoHouse = 0x00080000,
/// <summary>
/// The tile is a map--in the cartography sense. Unknown usage.
/// </summary>
Map = 0x00100000,
/// <summary>
/// The tile is a container.
/// </summary>
Container = 0x00200000,
/// <summary>
/// The tile may be equiped.
/// </summary>
Wearable = 0x00400000,
/// <summary>
/// The tile gives off light.
/// </summary>
LightSource = 0x00800000,
/// <summary>
/// The tile is animated.
/// </summary>
Animation = 0x01000000,
/// <summary>
/// Gargoyles can fly over
/// </summary>
NoDiagonal = 0x02000000,
/// <summary>
/// Unknown.
/// </summary>
Unknown2 = 0x04000000,
/// <summary>
/// Not yet documented.
/// </summary>
Armor = 0x08000000,
/// <summary>
/// The tile is a slanted roof.
/// </summary>
Roof = 0x10000000,
/// <summary>
/// The tile is a door. Tiles with this flag can be moved through by ghosts and GMs.
/// </summary>
Door = 0x20000000,
/// <summary>
/// Not yet documented.
/// </summary>
StairBack = 0x40000000,
/// <summary>
/// Not yet documented.
/// </summary>
StairRight = 0x80000000,
/// Blend Alphas, tile blending.
AlphaBlend = 0x0100000000,
/// Uses new art style?
UseNewArt = 0x0200000000,
/// Has art being used?
ArtUsed = 0x0400000000,
/// Disallow shadow on this tile, lightsource? lava?
NoShadow = 0x1000000000,
/// Let pixels bleed in to other tiles? Is this Disabling Texture Clamp?
PixelBleed = 0x2000000000,
/// Play tile animation once.
PlayAnimOnce = 0x4000000000,
/// Movable multi? Cool ships and vehicles etc?
MultiMovable = 0x10000000000
}
19 changes: 19 additions & 0 deletions Shared/TileDataLand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace CentrED;

public struct TileDataLand
{
public TileDataLand(ulong flags, ushort textId, string name)
{
Flags = (TileDataFlag) flags;
TexID = textId;
Name = name;
}

public TileDataFlag Flags;
public ushort TexID;
public string Name;

public bool IsWet => (Flags & TileDataFlag.Wet) != 0;
public bool IsImpassable => (Flags & TileDataFlag.Impassable) != 0;
public bool IsNoDiagonal => (Flags & TileDataFlag.NoDiagonal) != 0;
}
15 changes: 7 additions & 8 deletions Shared/TileDataProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text;
using ClassicUO.Assets;

namespace CentrED;

Expand Down Expand Up @@ -32,7 +31,7 @@ public TileDataProvider(String tileDataPath)
var xsize = 4 + 32 * tsize;

var staticCount = (uint)((file.Length - file.Position) / xsize * 32);
StaticTiles = new StaticTiles[staticCount];
StaticTiles = new TileDataStatic[staticCount];
for (var i = 0; i < staticCount; i++)
{
if (i % 32 == 0)
Expand All @@ -47,11 +46,11 @@ public TileDataProvider(String tileDataPath)

public TileDataVersion Version { get; }

public LandTiles[] LandTiles = new LandTiles[0x4000];
public TileDataLand[] LandTiles = new TileDataLand[0x4000];

public StaticTiles[] StaticTiles;
public TileDataStatic[] StaticTiles;

private LandTiles ReadLandTileData(BinaryReader reader)
private TileDataLand ReadLandTileData(BinaryReader reader)
{
var flags = Version switch
{
Expand All @@ -60,10 +59,10 @@ private LandTiles ReadLandTileData(BinaryReader reader)
};
var textureId = reader.ReadUInt16();
var name = Encoding.ASCII.GetString(reader.ReadBytes(20)).Trim();
return new LandTiles(flags, textureId, name);
return new TileDataLand(flags, textureId, name);
}

private StaticTiles ReadStaticTileData(BinaryReader reader)
private TileDataStatic ReadStaticTileData(BinaryReader reader)
{
var flags = Version switch
{
Expand All @@ -78,6 +77,6 @@ private StaticTiles ReadStaticTileData(BinaryReader reader)
var lightIndex = reader.ReadUInt16();
var height = reader.ReadByte();
var tileName = Encoding.ASCII.GetString(reader.ReadBytes(20)).Trim();
return new StaticTiles(flags, weight, layer, count, animId, hue, lightIndex, height, tileName);
return new TileDataStatic(flags, weight, layer, count, animId, hue, lightIndex, height, tileName);
}
}
Loading

0 comments on commit 32ee05c

Please sign in to comment.