diff --git a/.editorconfig b/.editorconfig
index 10dbb73..738d363 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -17,9 +17,9 @@ tab_width = 2
# Microsoft .NET properties
csharp_preferred_modifier_order = public, private, protected, internal, new, abstract, virtual, sealed, override, static, readonly, extern, unsafe, volatile, async:suggestion
-csharp_style_var_elsewhere = false:none
-csharp_style_var_for_built_in_types = false:none
-csharp_style_var_when_type_is_apparent = false:none
+csharp_style_var_elsewhere = true
+csharp_style_var_for_built_in_types = true
+csharp_style_var_when_type_is_apparent = true
dotnet_naming_rule.constants_rule.severity = warning
dotnet_naming_rule.constants_rule.style = all_upper_style
dotnet_naming_rule.constants_rule.symbols = constants_symbols
@@ -66,11 +66,13 @@ resharper_align_multiline_for_stmt = true
resharper_align_multline_type_parameter_constrains = true
resharper_align_multline_type_parameter_list = true
resharper_align_tuple_components = true
-resharper_blank_lines_after_multiline_statements = 1
-resharper_blank_lines_around_multiline_case_section = 1
+resharper_blank_lines_after_block_statements = 0
+resharper_blank_lines_after_control_transfer_statements = 0
+resharper_blank_lines_after_multiline_statements = 0
+resharper_blank_lines_around_multiline_case_section = 0
resharper_blank_lines_around_single_line_type = 0
-resharper_blank_lines_before_control_transfer_statements = 1
-resharper_blank_lines_before_multiline_statements = 1
+resharper_blank_lines_before_control_transfer_statements = 0
+resharper_blank_lines_before_multiline_statements = 0
resharper_braces_for_for = required
resharper_braces_for_foreach = required
resharper_braces_for_ifelse = required
@@ -78,11 +80,12 @@ resharper_braces_for_while = required
resharper_csharp_align_multiline_parameter = true
resharper_csharp_align_multiple_declaration = true
resharper_csharp_blank_lines_around_field = 0
-resharper_csharp_max_line_length = 180
+resharper_csharp_max_line_length = 120
resharper_csharp_naming_rule.enum_member = AA_BB
resharper_csharp_stick_comment = false
resharper_csharp_wrap_after_declaration_lpar = true
resharper_csharp_wrap_after_invocation_lpar = true
+resharper_csharp_wrap_arguments_style = chop_if_long
resharper_csharp_wrap_before_declaration_lpar = true
resharper_csharp_wrap_before_invocation_lpar = true
resharper_csharp_wrap_before_ternary_opsigns = false
diff --git a/CentrED/Application.cs b/CentrED/Application.cs
index d957ec3..4d53c4e 100644
--- a/CentrED/Application.cs
+++ b/CentrED/Application.cs
@@ -5,10 +5,10 @@
using CentrED.Client;
using CentrED.Server;
-namespace CentrED;
+namespace CentrED;
-public class Application {
-
+public class Application
+{
static private AssemblyLoadContext _loadContext;
static private string? _rootDir;
@@ -87,7 +87,7 @@ static private IntPtr ResolveUnmanagedDll(Assembly assembly, string unmanagedDll
public static CentrEDGame CEDGame { get; private set; } = null!;
public static CEDServer? CEDServer;
public static readonly CentrEDClient CEDClient = new();
-
+
[STAThread]
public static void Main(string[] args)
{
@@ -100,11 +100,14 @@ public static void Main(string[] args)
_loadContext.ResolvingUnmanagedDll += ResolveUnmanagedDll;
_loadContext.Resolving += ResolveAssembly;
- using (CEDGame = new CentrEDGame()) {
- try {
+ using (CEDGame = new CentrEDGame())
+ {
+ try
+ {
CEDGame.Run();
}
- catch (Exception e) {
+ catch (Exception e)
+ {
Console.WriteLine(e.ToString());
File.WriteAllText("Crash.log", e.ToString());
}
diff --git a/CentrED/Camera.cs b/CentrED/Camera.cs
index 7da6dad..bc32c15 100644
--- a/CentrED/Camera.cs
+++ b/CentrED/Camera.cs
@@ -17,16 +17,12 @@ public class Camera
private Vector3 _up = new(-1, -1, 0);
/* This takes the coordinates (x, y, z) and turns it into the screen point (x, y + z, z) */
- private Matrix _oblique = new Matrix(
- 1, 0, 0, 0,
- 0, 1, 0, 0,
- 0, 1, 1, 0,
- 0, 0, 0, 1);
+ private Matrix _oblique = new Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1);
private Matrix _translation = Matrix.CreateTranslation(new Vector3(0, 128 * 4, 0));
public Vector3 Position = new(0, 0, 128 * 4);
-
+
//Look directly below camera
public Vector3 LookAt => new(Position.X, Position.Y, 0);
@@ -38,13 +34,15 @@ public class Camera
public bool Moved;
- public void Move(float xDelta, float yDelta) {
+ public void Move(float xDelta, float yDelta)
+ {
Position.X += xDelta;
Position.Y += yDelta;
Moved = true;
}
- public void ZoomIn(float delta) {
+ public void ZoomIn(float delta)
+ {
Zoom += delta;
Moved = true;
}
@@ -61,7 +59,7 @@ public void Update()
Matrix ortho = Matrix.CreateOrthographic(ScreenSize.Width, ScreenSize.Height, 0, 128 * 8);
Matrix scale = Matrix.CreateScale(Zoom, Zoom, 1f);
-
+
proj = _mirrorX * _oblique * _translation * ortho * scale;
Matrix.Multiply(ref world, ref view, out var worldView);
diff --git a/CentrED/CentrED.csproj b/CentrED/CentrED.csproj
index 430b0bc..7de998f 100644
--- a/CentrED/CentrED.csproj
+++ b/CentrED/CentrED.csproj
@@ -1,73 +1,73 @@
-
- Exe
- net7.0
- x64
+
+ Exe
+ net7.0
+ x64
- enable
- enable
- true
+ enable
+ enable
+ true
- false
- true
+ false
+ true
- true
- true
+ true
+ true
- ../output
- ../publish
- icon.ico
-
+ ../output
+ ../publish
+ icon.ico
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ..\lib\x64\ClassicUO.Assets.dll
-
-
- ..\lib\x64\ClassicUO.IO.dll
-
-
- ..\lib\x64\ClassicUO.Utility.dll
-
-
-
-
-
- PreserveNewest
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+ ..\lib\x64\ClassicUO.Assets.dll
+
+
+ ..\lib\x64\ClassicUO.IO.dll
+
+
+ ..\lib\x64\ClassicUO.Utility.dll
+
+
+
+
+
+ PreserveNewest
+
+
+
+
+
+
+
+
+
+
diff --git a/CentrED/CentrEDGame.cs b/CentrED/CentrEDGame.cs
index 1cda5e0..19a7c99 100644
--- a/CentrED/CentrEDGame.cs
+++ b/CentrED/CentrEDGame.cs
@@ -22,7 +22,11 @@ public CentrEDGame()
PreferredDepthStencilFormat = DepthFormat.Depth24
};
- _gdm.PreparingDeviceSettings += (sender, e) => { e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.DiscardContents; };
+ _gdm.PreparingDeviceSettings += (sender, e) =>
+ {
+ e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage =
+ RenderTargetUsage.DiscardContents;
+ };
IsMouseVisible = true;
Window.AllowUserResizing = true;
@@ -35,7 +39,7 @@ protected override void Initialize()
{
_gdm.GraphicsProfile = GraphicsProfile.HiDef;
}
-
+
_gdm.ApplyChanges();
NativeLibrary.Load(Path.Combine(AppContext.BaseDirectory, "x64", "zlib.dll"));
@@ -68,18 +72,19 @@ protected override void Update(GameTime gameTime)
protected override void Draw(GameTime gameTime)
{
// if (!IsActive)
- // return;
-
+ // return;
+
MapManager.Draw();
UIManager.Draw(gameTime);
base.Draw(gameTime);
}
-
-
- private void OnWindowResized(object? sender, EventArgs e) {
+
+
+ private void OnWindowResized(object? sender, EventArgs e)
+ {
GameWindow window = sender as GameWindow;
- if (window != null)
+ if (window != null)
MapManager.OnWindowsResized(window);
}
}
\ No newline at end of file
diff --git a/CentrED/Config.cs b/CentrED/Config.cs
index 4037c59..4f6dcda 100644
--- a/CentrED/Config.cs
+++ b/CentrED/Config.cs
@@ -1,37 +1,43 @@
using System.Text.Json;
-namespace CentrED;
+namespace CentrED;
-public class ConfigRoot {
+public class ConfigRoot
+{
public string ActiveProfile { get; set; } = "";
public string ServerConfigPath { get; set; } = "cedserver.xml";
}
-public static class Config {
-
+public static class Config
+{
private static ConfigRoot _configRoot;
private static string _configFilePath = "settings.json";
-
- static Config() {
- if (!File.Exists(_configFilePath)) {
+
+ static Config()
+ {
+ if (!File.Exists(_configFilePath))
+ {
var newConfig = new ConfigRoot();
File.WriteAllText(_configFilePath, JsonSerializer.Serialize(newConfig));
}
var jsonText = File.ReadAllText(_configFilePath);
- _configRoot = JsonSerializer.Deserialize(jsonText);
+ _configRoot = JsonSerializer.Deserialize(jsonText);
}
- public static void Save() {
+ public static void Save()
+ {
File.WriteAllText(_configFilePath, JsonSerializer.Serialize(_configRoot));
}
- public static string ActiveProfile {
+ public static string ActiveProfile
+ {
get => _configRoot.ActiveProfile;
set => _configRoot.ActiveProfile = value;
}
-
- public static string ServerConfigPath {
+
+ public static string ServerConfigPath
+ {
get => _configRoot.ServerConfigPath;
set => _configRoot.ServerConfigPath = value;
}
diff --git a/CentrED/HuesManager.cs b/CentrED/HuesManager.cs
index b02bdd3..fa8f111 100644
--- a/CentrED/HuesManager.cs
+++ b/CentrED/HuesManager.cs
@@ -4,7 +4,8 @@
namespace CentrED;
-public class HuesManager {
+public class HuesManager
+{
private static HuesManager _instance;
public static HuesManager Instance => _instance;
@@ -14,26 +15,30 @@ public class HuesManager {
public readonly string[] Names;
public readonly ushort[][] Colors;
- private unsafe HuesManager(GraphicsDevice gd) {
+ private unsafe HuesManager(GraphicsDevice gd)
+ {
var huesLoader = HuesLoader.Instance;
HuesCount = huesLoader.HuesCount + 1;
Texture = new Texture2D(gd, TEXTURE_WIDTH, HuesCount - 1);
uint[] buffer = System.Buffers.ArrayPool.Shared.Rent(TEXTURE_WIDTH * HuesCount);
- fixed (uint* ptr = buffer) {
+ fixed (uint* ptr = buffer)
+ {
huesLoader.CreateShaderColors(buffer);
Texture.SetDataPointerEXT(0, null, (IntPtr)ptr, TEXTURE_WIDTH * HuesCount * sizeof(uint));
}
System.Buffers.ArrayPool.Shared.Return(buffer);
-
+
Colors = new ushort[HuesCount + 1][];
Names = new string[HuesCount + 1];
Colors[0] = huesLoader.HuesRange[0].Entries[0].ColorTable;
Names[0] = "No Hue";
var i = 1;
- foreach (var huesGroup in huesLoader.HuesRange) {
- foreach (var hueEntry in huesGroup.Entries) {
+ foreach (var huesGroup in huesLoader.HuesRange)
+ {
+ foreach (var hueEntry in huesGroup.Entries)
+ {
Colors[i] = hueEntry.ColorTable;
Names[i] = new string(hueEntry.Name);
i++;
@@ -41,39 +46,47 @@ private unsafe HuesManager(GraphicsDevice gd) {
}
}
- public static void Initialize(GraphicsDevice gd) {
+ public static void Initialize(GraphicsDevice gd)
+ {
_instance = new HuesManager(gd);
}
- public enum HueMode {
+ public enum HueMode
+ {
NONE = 0,
HUED = 1,
PARTIAL = 2
}
- public Vector3 GetHueVector(StaticTile tile, float alpha = 1) {
+ public Vector3 GetHueVector(StaticTile tile, float alpha = 1)
+ {
return GetHueVector(tile.Id, tile.Hue, alpha);
}
-
- public Vector3 GetHueVector(ushort id, ushort hue, float alpha = 1) {
+
+ public Vector3 GetHueVector(ushort id, ushort hue, float alpha = 1)
+ {
var partial = TileDataLoader.Instance.StaticData[id].IsPartialHue;
var translucent = TileDataLoader.Instance.StaticData[id].IsTranslucent;
return GetHueVector(hue, partial, translucent ? 0.6f : alpha);
}
- public Vector3 GetHueVector(ushort hue, bool partial, float alpha = 1) {
+ public Vector3 GetHueVector(ushort hue, bool partial, float alpha = 1)
+ {
HueMode mode;
- if ((hue & 0x8000) != 0) {
+ if ((hue & 0x8000) != 0)
+ {
partial = true;
hue &= 0x7FFF;
}
- if (hue != 0) {
+ if (hue != 0)
+ {
// hue -= 1;
mode = partial ? HueMode.PARTIAL : HueMode.HUED;
}
- else {
+ else
+ {
mode = HueMode.NONE;
}
diff --git a/CentrED/IO/Models/Profile.cs b/CentrED/IO/Models/Profile.cs
index 88caa7a..a19ef23 100644
--- a/CentrED/IO/Models/Profile.cs
+++ b/CentrED/IO/Models/Profile.cs
@@ -1,16 +1,14 @@
using System.Text.Json.Serialization;
-namespace CentrED.IO.Models
+namespace CentrED.IO.Models;
+
+public class Profile
{
- public class Profile
- {
- [JsonIgnore]
- public string Name { get; set; }
- public string Hostname { get; set; } = "127.0.0.1";
- public int Port { get; set; } = 2597;
- public string Username { get; set; } = "";
- public string ClientPath { get; set; } = "";
- public string ClientVersion { get; set; } = "";
- public Dictionary RadarFavorites { get; set; } = new();
- }
-}
+ [JsonIgnore] public string Name { get; set; }
+ public string Hostname { get; set; } = "127.0.0.1";
+ public int Port { get; set; } = 2597;
+ public string Username { get; set; } = "";
+ public string ClientPath { get; set; } = "";
+ public string ClientVersion { get; set; } = "";
+ public Dictionary RadarFavorites { get; set; } = new();
+}
\ No newline at end of file
diff --git a/CentrED/IO/Models/RadarFavorite.cs b/CentrED/IO/Models/RadarFavorite.cs
index 5ffc0bf..fdfbf55 100644
--- a/CentrED/IO/Models/RadarFavorite.cs
+++ b/CentrED/IO/Models/RadarFavorite.cs
@@ -1,8 +1,7 @@
-namespace CentrED.IO.Models
+namespace CentrED.IO.Models;
+
+public class RadarFavorite
{
- public class RadarFavorite
- {
- public int X { get; set; }
- public int Y { get; set; }
- }
-}
+ public int X { get; set; }
+ public int Y { get; set; }
+}
\ No newline at end of file
diff --git a/CentrED/IO/ProfileManager.cs b/CentrED/IO/ProfileManager.cs
index 9b42d75..b68def9 100644
--- a/CentrED/IO/ProfileManager.cs
+++ b/CentrED/IO/ProfileManager.cs
@@ -3,7 +3,6 @@
namespace CentrED.IO;
-
public static class ProfileManager
{
private const string ProfilesDir = "profiles";
@@ -24,6 +23,7 @@ static ProfileManager()
Profiles.Add(profile);
}
}
+
public static string[] ProfileNames => Profiles.Select(p => p.Name).ToArray();
public static Profile ActiveProfile => Profiles.Find(p => p.Name == Config.ActiveProfile) ?? new Profile();
diff --git a/CentrED/Map/Epsilon.cs b/CentrED/Map/Epsilon.cs
index 6766e46..1c0b767 100644
--- a/CentrED/Map/Epsilon.cs
+++ b/CentrED/Map/Epsilon.cs
@@ -1,6 +1,7 @@
-namespace CentrED.Map;
+namespace CentrED.Map;
-public class Epsilon {
+public class Epsilon
+{
public static readonly float value = GetMachineEpsilonFloat();
private static float GetMachineEpsilonFloat()
@@ -15,8 +16,7 @@ private static float GetMachineEpsilonFloat()
{
machineEpsilon *= 0.5f;
comparison = 1.0f + machineEpsilon;
- }
- while (comparison > 1.0f);
+ } while (comparison > 1.0f);
return machineEpsilon;
}
diff --git a/CentrED/Map/LandObject.cs b/CentrED/Map/LandObject.cs
index 763167f..2d0c541 100644
--- a/CentrED/Map/LandObject.cs
+++ b/CentrED/Map/LandObject.cs
@@ -5,12 +5,14 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
-namespace CentrED.Map;
+namespace CentrED.Map;
-public class LandObject : MapObject {
+public class LandObject : MapObject
+{
public LandTile LandTile;
- public LandObject(CentrEDClient client, LandTile tile) {
+ public LandObject(CentrEDClient client, LandTile tile)
+ {
Tile = tile;
LandTile = tile;
ref var tileData = ref TileDataLoader.Instance.LandData[tile.Id];
@@ -20,25 +22,28 @@ public LandObject(CentrEDClient client, LandTile tile) {
Vector3 normalRight;
Vector3 normalLeft;
Vector3 normalBottom;
-
- if ((tileData.Flags & TileFlag.Wet) != 0) { // Water tiles are always flat
+
+ if ((tileData.Flags & TileFlag.Wet) != 0)
+ {
+ // Water tiles are always flat
cornerZ = new Vector4(tile.Z * TILE_Z_SCALE);
normalTop = normalRight = normalLeft = normalBottom = Vector3.UnitZ;
}
- else {
+ else
+ {
cornerZ = GetCornerZ(client, tile);
normalTop = ComputeNormal(client, tile.X, tile.Y);
normalRight = ComputeNormal(client, tile.X + 1, tile.Y);
normalLeft = ComputeNormal(client, tile.X, tile.Y + 1);
normalBottom = ComputeNormal(client, tile.X + 1, tile.Y + 1);
}
-
+
var normals = new Vector3[4];
normals[0] = normalTop;
normals[1] = normalRight;
normals[2] = normalLeft;
normals[3] = normalBottom;
-
+
var posX = (tile.X - 1) * TILE_SIZE;
var posY = (tile.Y - 1) * TILE_SIZE;
@@ -51,16 +56,20 @@ public LandObject(CentrEDClient client, LandTile tile) {
Texture2D? tileTex = null;
Rectangle bounds;
- var diamondTexture = IsFlat(cornerZ.X, cornerZ.Y, cornerZ.Z, cornerZ.W) || TexmapsLoader.Instance.GetValidRefEntry(tile.Id).Equals(UOFileIndex.Invalid);
- if (diamondTexture) {
+ var diamondTexture = IsFlat
+ (cornerZ.X, cornerZ.Y, cornerZ.Z, cornerZ.W) || TexmapsLoader.Instance.GetValidRefEntry(tile.Id).Equals
+ (UOFileIndex.Invalid);
+ if (diamondTexture)
+ {
Texture = ArtLoader.Instance.GetLandTexture(tile.Id, out bounds);
}
- else {
+ else
+ {
Texture = TexmapsLoader.Instance.GetLandTexture(tile.Id, out bounds);
}
-
+
float onePixel = Math.Max(1.0f / Texture.Width, Epsilon.value);
-
+
var texX = bounds.X / (float)Texture.Width + (onePixel / 2f);
var texY = bounds.Y / (float)Texture.Height + (onePixel / 2f);
var texWidth = (bounds.Width / (float)Texture.Width) - onePixel;
@@ -82,17 +91,19 @@ public LandObject(CentrEDClient client, LandTile tile) {
texCoords[3] = new Vector3(texX + texWidth, texY + texHeight, 0);
}
- for (int i = 0; i < 4; i++) {
+ for (int i = 0; i < 4; i++)
+ {
Vertices[i] = new MapVertex(coordinates[i], normals[i], texCoords[i], Vector3.Zero);
}
}
-
- private bool IsFlat(float x, float y, float z, float w) {
+
+ private bool IsFlat(float x, float y, float z, float w)
+ {
return x == y && x == z && x == w;
}
-
- private Vector4
- GetCornerZ(CentrEDClient client, LandTile tile) {
+
+ private Vector4 GetCornerZ(CentrEDClient client, LandTile tile)
+ {
var x = tile.X;
var y = tile.Y;
var top = tile;
@@ -100,26 +111,21 @@ private Vector4
var left = client.GetLandTile(x, Math.Min(client.Height * 8 - 1, y + 1));
var bottom = client.GetLandTile(Math.Min(client.Width * 8 - 1, x + 1), Math.Min(client.Height * 8 - 1, y + 1));
- return new Vector4(
- top.Z * TILE_Z_SCALE,
- right.Z * TILE_Z_SCALE,
- left.Z * TILE_Z_SCALE,
- bottom.Z * TILE_Z_SCALE
- );
+ return new Vector4
+ (top.Z * TILE_Z_SCALE, right.Z * TILE_Z_SCALE, left.Z * TILE_Z_SCALE, bottom.Z * TILE_Z_SCALE);
}
-
- private static (Vector2, Vector2)[] _normalOffsets =
+
+ private static (Vector2, Vector2)[] _normalOffsets =
{
- (new Vector2(1, 0), new Vector2(0, 1)),
- (new Vector2(0, 1), new Vector2(-1, 0)),
- (new Vector2(-1, 0), new Vector2(0, -1)),
- (new Vector2(0, -1), new Vector2(1, 0))
+ (new Vector2(1, 0), new Vector2(0, 1)), (new Vector2(0, 1), new Vector2(-1, 0)),
+ (new Vector2(-1, 0), new Vector2(0, -1)), (new Vector2(0, -1), new Vector2(1, 0))
};
-
-
+
+
private Vector3 ComputeNormal(CentrEDClient client, int tileX, int tileY)
{
- var t = client.GetLandTile(Math.Clamp(tileX, 0, client.Width * 8 - 1), Math.Clamp(tileY, 0, client.Height * 8 - 1));
+ var t = client.GetLandTile
+ (Math.Clamp(tileX, 0, client.Width * 8 - 1), Math.Clamp(tileY, 0, client.Height * 8 - 1));
Vector3 normal = Vector3.Zero;
@@ -127,8 +133,16 @@ private Vector3 ComputeNormal(CentrEDClient client, int tileX, int tileY)
{
(var tu, var tv) = _normalOffsets[i];
- var tx = client.GetLandTile(Math.Clamp((int)(tileX + tu.X), 0, client.Width * 8 - 1), Math.Clamp((int)(tileY + tu.Y), 0, client.Height * 8 - 1));
- var ty = client.GetLandTile(Math.Clamp((int)(tileX + tv.X), 0, client.Width * 8 - 1), Math.Clamp((int)(tileY + tu.Y), 0, client.Height * 8 - 1));
+ var tx = client.GetLandTile
+ (
+ Math.Clamp((int)(tileX + tu.X), 0, client.Width * 8 - 1),
+ Math.Clamp((int)(tileY + tu.Y), 0, client.Height * 8 - 1)
+ );
+ var ty = client.GetLandTile
+ (
+ Math.Clamp((int)(tileX + tv.X), 0, client.Width * 8 - 1),
+ Math.Clamp((int)(tileY + tu.Y), 0, client.Height * 8 - 1)
+ );
if (tx.Id == 0 || ty.Id == 0)
continue;
@@ -143,20 +157,24 @@ private Vector3 ComputeNormal(CentrEDClient client, int tileX, int tileY)
return Vector3.Normalize(normal);
}
- public void UpdateId(ushort newId) {
+ public void UpdateId(ushort newId)
+ {
Texture2D? tileTex = null;
Rectangle bounds;
- var isFlat = IsFlat(Vertices[0].Position.Z, Vertices[1].Position.Z, Vertices[2].Position.Z, Vertices[3].Position.Z);
+ var isFlat = IsFlat
+ (Vertices[0].Position.Z, Vertices[1].Position.Z, Vertices[2].Position.Z, Vertices[3].Position.Z);
var diamondTexture = isFlat || TexmapsLoader.Instance.GetValidRefEntry(newId).Equals(UOFileIndex.Invalid);
- if (diamondTexture) {
+ if (diamondTexture)
+ {
Texture = ArtLoader.Instance.GetLandTexture(newId, out bounds);
}
- else {
+ else
+ {
Texture = TexmapsLoader.Instance.GetLandTexture(newId, out bounds);
}
-
+
float onePixel = Math.Max(1.0f / Texture.Width, Epsilon.value);
-
+
var texX = bounds.X / (float)Texture.Width + (onePixel / 2f);
var texY = bounds.Y / (float)Texture.Height + (onePixel / 2f);
var texWidth = (bounds.Width / (float)Texture.Width) - onePixel;
@@ -177,8 +195,9 @@ public void UpdateId(ushort newId) {
texCoords[2] = new Vector3(texX, texY + texHeight, 0);
texCoords[3] = new Vector3(texX + texWidth, texY + texHeight, 0);
}
-
- for (int i = 0; i < 4; i++) {
+
+ for (int i = 0; i < 4; i++)
+ {
Vertices[i].TextureCoordinate = texCoords[i];
}
}
diff --git a/CentrED/Map/MapManager.cs b/CentrED/Map/MapManager.cs
index ebf23aa..cd697f2 100644
--- a/CentrED/Map/MapManager.cs
+++ b/CentrED/Map/MapManager.cs
@@ -14,8 +14,8 @@
namespace CentrED.Map;
-public class MapManager {
-
+public class MapManager
+{
private readonly GraphicsDevice _gfxDevice;
private readonly MapEffect _mapEffect;
@@ -76,84 +76,93 @@ public MapManager(GraphicsDevice gd)
_gfxDevice = gd;
_mapEffect = new MapEffect(gd);
_mapRenderer = new MapRenderer(gd);
- _shadowTarget = new RenderTarget2D(
- gd,
- gd.PresentationParameters.BackBufferWidth * 2,
- gd.PresentationParameters.BackBufferHeight * 2,
- false,
- SurfaceFormat.Single,
- DepthFormat.Depth24);
-
- _selectionTarget = new RenderTarget2D(
+ _shadowTarget = new RenderTarget2D
+ (
+ gd,
+ gd.PresentationParameters.BackBufferWidth * 2,
+ gd.PresentationParameters.BackBufferHeight * 2,
+ false,
+ SurfaceFormat.Single,
+ DepthFormat.Depth24
+ );
+
+ _selectionTarget = new RenderTarget2D
+ (
gd,
gd.PresentationParameters.BackBufferWidth,
gd.PresentationParameters.BackBufferHeight,
false,
SurfaceFormat.Color,
- DepthFormat.Depth24);
+ DepthFormat.Depth24
+ );
_postProcessRenderer = new PostProcessRenderer(gd);
_spriteBatch = new SpriteBatch(gd);
_background = CEDGame.Content.Load("background");
Client = CEDClient;
- Client.LandTileReplaced += (tile, newId) => {
- LandTiles.Find(l => l.LandTile.Equals(tile))?.UpdateId(newId);
- };
- Client.LandTileElevated += (tile, newZ) => {
- Vector2[] offsets = {
- new(0, 0), //top
+ Client.LandTileReplaced += (tile, newId) => { LandTiles.Find(l => l.LandTile.Equals(tile))?.UpdateId(newId); };
+ Client.LandTileElevated += (tile, newZ) =>
+ {
+ Vector2[] offsets =
+ {
+ new(0, 0), //top
new(-1, 0), //right
new(0, -1), //left
new(-1, -1) //bottom
};
-
- for (var i = 0; i < offsets.Length; i++) {
+
+ for (var i = 0; i < offsets.Length; i++)
+ {
var offset = offsets[i];
- var landObject = LandTiles.Find(l =>
- l.LandTile.X == (ushort)(tile.X + offset.X) &&
- l.LandTile.Y == (ushort)(tile.Y + offset.Y));
- if (landObject != null) {
+ var landObject = LandTiles.Find
+ (l => l.LandTile.X == (ushort)(tile.X + offset.X) && l.LandTile.Y == (ushort)(tile.Y + offset.Y));
+ if (landObject != null)
+ {
landObject.Vertices[i].Position.Z = newZ * MapObject.TILE_Z_SCALE;
landObject.UpdateId(landObject.LandTile.Id); //Just refresh ID to refresh if it's flat
}
}
//We need to update normals too
};
- Client.BlockLoaded += block => {
- block.StaticBlock.SortTiles(ref TileDataLoader.Instance.StaticData);
- };
- Client.BlockUnloaded += block => {
- var tiles = block.StaticBlock.AllTiles();
- foreach (var tile in tiles) {
- StaticTiles.RemoveAll(so => so.StaticTile.Equals(tile));
- }
- };
- Client.StaticTileRemoved += tile => {
- StaticTiles.RemoveAll(so => so.StaticTile.Equals(tile));
+ Client.BlockLoaded += block => { block.StaticBlock.SortTiles(ref TileDataLoader.Instance.StaticData); };
+ Client.BlockUnloaded += block =>
+ {
+ var tiles = block.StaticBlock.AllTiles();
+ foreach (var tile in tiles)
+ {
+ StaticTiles.RemoveAll(so => so.StaticTile.Equals(tile));
+ }
};
- Client.StaticTileAdded += tile => {
+ Client.StaticTileRemoved += tile => { StaticTiles.RemoveAll(so => so.StaticTile.Equals(tile)); };
+ Client.StaticTileAdded += tile =>
+ {
tile.Block?.SortTiles(ref TileDataLoader.Instance.StaticData);
StaticTiles.Add(new StaticObject(tile));
};
- Client.StaticTileMoved += (tile, newX, newY) => {
+ Client.StaticTileMoved += (tile, newX, newY) =>
+ {
StaticTiles.RemoveAll(so => so.StaticTile.Equals(tile));
var newTile = new StaticTile(tile.Id, newX, newY, tile.Z, tile.Hue, tile.Block);
StaticTiles.Add(new StaticObject(newTile));
};
- Client.StaticTileElevated += (tile, newZ) => {
+ Client.StaticTileElevated += (tile, newZ) =>
+ {
StaticTiles.RemoveAll(so => so.StaticTile.Equals(tile));
var newTile = new StaticTile(tile.Id, tile.X, tile.Y, newZ, tile.Hue, tile.Block);
StaticTiles.Add(new StaticObject(newTile));
};
- Client.StaticTileHued += (tile, newHue) => {
+ Client.StaticTileHued += (tile, newHue) =>
+ {
StaticTiles.First(so => so.StaticTile.Equals(tile)).Hue = newHue;
};
Client.Moved += SetPos;
- Client.Connected += () => {
+ Client.Connected += () =>
+ {
LandTiles.Clear();
StaticTiles.Clear();
};
- Client.Disconnected += () => {
+ Client.Disconnected += () =>
+ {
LandTiles.Clear();
StaticTiles.Clear();
};
@@ -175,48 +184,60 @@ public MapManager(GraphicsDevice gd)
_lightingState.LightDirection = new Vector3(0, -1, -1f);
_lightingState.LightDiffuseColor = Vector3.Normalize(new Vector3(1, 1, 1));
_lightingState.LightSpecularColor = Vector3.Zero;
- _lightingState.AmbientLightColor = new Vector3(
+ _lightingState.AmbientLightColor = new Vector3
+ (
1f - _lightingState.LightDiffuseColor.X,
1f - _lightingState.LightDiffuseColor.Y,
1f - _lightingState.LightDiffuseColor.Z
);
}
- public void Load(string clientPath, string clientVersion) {
+ public void Load(string clientPath, string clientVersion)
+ {
var valid = ClientVersionHelper.IsClientVersionValid(clientVersion, out UOFileManager.Version);
UOFileManager.BasePath = clientPath;
- UOFileManager.IsUOPInstallation = UOFileManager.Version >= ClientVersion.CV_7000 && File.Exists(UOFileManager.GetUOFilePath("MainMisc.uop"));
-
- if (!Task.WhenAll( new List
- {
- ArtLoader.Instance.Load(),
- HuesLoader.Instance.Load(),
- TileDataLoader.Instance.Load(),
- TexmapsLoader.Instance.Load(),
- }).Wait(TimeSpan.FromSeconds(10.0)))
+ UOFileManager.IsUOPInstallation = UOFileManager.Version >= ClientVersion.CV_7000 && File.Exists
+ (UOFileManager.GetUOFilePath("MainMisc.uop"));
+
+ if (!Task.WhenAll
+ (
+ new List
+ {
+ ArtLoader.Instance.Load(),
+ HuesLoader.Instance.Load(),
+ TileDataLoader.Instance.Load(),
+ TexmapsLoader.Instance.Load(),
+ }
+ ).Wait(TimeSpan.FromSeconds(10.0)))
Log.Panic("Loading files timeout.");
-
+
TextureAtlas.InitializeSharedTexture(_gfxDevice);
HuesManager.Initialize(_gfxDevice);
RadarMap.Initialize(_gfxDevice);
-
+
var landIds = new List();
- for (int i = 0; i < TileDataLoader.Instance.LandData.Length; i++) {
- if (!ArtLoader.Instance.GetValidRefEntry(i).Equals(UOFileIndex.Invalid)) {
+ for (int i = 0; i < TileDataLoader.Instance.LandData.Length; i++)
+ {
+ if (!ArtLoader.Instance.GetValidRefEntry(i).Equals(UOFileIndex.Invalid))
+ {
landIds.Add(i);
}
}
ValidLandIds = landIds.ToArray();
var staticIds = new List();
- for (int i = 0; i < TileDataLoader.Instance.StaticData.Length; i++) {
- if (!ArtLoader.Instance.GetValidRefEntry(i + ArtLoader.MAX_LAND_DATA_INDEX_COUNT).Equals(UOFileIndex.Invalid)) {
+ for (int i = 0; i < TileDataLoader.Instance.StaticData.Length; i++)
+ {
+ if (!ArtLoader.Instance.GetValidRefEntry(i + ArtLoader.MAX_LAND_DATA_INDEX_COUNT).Equals
+ (UOFileIndex.Invalid))
+ {
staticIds.Add(i);
}
}
ValidStaticIds = staticIds.ToArray();
}
- public void SetPos(ushort x, ushort y) {
+ public void SetPos(ushort x, ushort y)
+ {
Camera.Position.X = x * TILE_SIZE;
Camera.Position.Y = y * TILE_SIZE;
Camera.Moved = true;
@@ -237,7 +258,8 @@ private enum MouseDirection
// This is all just a fast math way to figure out what the direction of the mouse is.
private MouseDirection ProcessMouseMovement(ref MouseState mouseState, out float distance)
{
- Vector2 vec = new Vector2(mouseState.X - (Camera.ScreenSize.Width / 2), mouseState.Y - (Camera.ScreenSize.Height / 2));
+ Vector2 vec = new Vector2
+ (mouseState.X - (Camera.ScreenSize.Width / 2), mouseState.Y - (Camera.ScreenSize.Height / 2));
int hashf = 100 * (Math.Sign(vec.X) + 2) + 10 * (Math.Sign(vec.Y) + 2);
@@ -295,8 +317,10 @@ private MouseDirection ProcessMouseMovement(ref MouseState mouseState, out float
private MouseState _prevMouseState = Mouse.GetState();
private Rectangle _prevViewRange;
- public void Update(GameTime gameTime, bool isActive, bool processMouse, bool processKeyboard) {
- if (!Client.Initialized) return;
+ public void Update(GameTime gameTime, bool isActive, bool processMouse, bool processKeyboard)
+ {
+ if (!Client.Initialized)
+ return;
if (isActive && processMouse)
{
var mouse = Mouse.GetState();
@@ -339,19 +363,24 @@ public void Update(GameTime gameTime, bool isActive, bool processMouse, bool pro
{
Camera.ZoomIn((mouse.ScrollWheelValue - _prevMouseState.ScrollWheelValue) / WHEEL_DELTA);
}
-
- if (_gfxDevice.Viewport.Bounds.Contains(new Point(mouse.X, mouse.Y))) {
+
+ if (_gfxDevice.Viewport.Bounds.Contains(new Point(mouse.X, mouse.Y)))
+ {
var newSelected = GetMouseSelection(mouse.X, mouse.Y);
- if (newSelected != Selected) {
+ if (newSelected != Selected)
+ {
ActiveTool?.OnMouseLeave(Selected);
Selected = newSelected;
ActiveTool?.OnMouseEnter(Selected);
}
- if (Selected != null) {
- if (mouse.LeftButton == ButtonState.Pressed) {
+ if (Selected != null)
+ {
+ if (mouse.LeftButton == ButtonState.Pressed)
+ {
ActiveTool?.OnMousePressed(Selected);
}
- if (mouse.LeftButton == ButtonState.Released) {
+ if (mouse.LeftButton == ButtonState.Released)
+ {
ActiveTool?.OnMouseReleased(Selected);
}
}
@@ -387,34 +416,43 @@ public void Update(GameTime gameTime, bool isActive, bool processMouse, bool pro
}
CalculateViewRange(Camera, out var viewRange);
- if (_prevViewRange != viewRange) {
+ if (_prevViewRange != viewRange)
+ {
List requested = new List();
- for (var x = viewRange.Left / 8 - 1; x < viewRange.Right / 8 + 1; x++) {
- for (var y = viewRange.Top / 8 - 1; y < viewRange.Bottom / 8 + 1; y++) {
- if(_prevViewRange.Contains(x,y)) continue;
+ for (var x = viewRange.Left / 8 - 1; x < viewRange.Right / 8 + 1; x++)
+ {
+ for (var y = viewRange.Top / 8 - 1; y < viewRange.Bottom / 8 + 1; y++)
+ {
+ if (_prevViewRange.Contains(x, y))
+ continue;
requested.Add(new BlockCoords((ushort)x, (ushort)y));
}
}
- if (Client.Running) {
+ if (Client.Running)
+ {
Client.ResizeCache(viewRange.Width * viewRange.Height / 8);
Client.LoadBlocks(requested);
}
LandTiles.RemoveAll(o => !viewRange.Contains(o.Tile.X, o.Tile.Y));
StaticTiles.RemoveAll(o => !viewRange.Contains(o.Tile.X, o.Tile.Y));
-
- for (int x = viewRange.Left; x < viewRange.Right; x++) {
- for (int y = viewRange.Top; y < viewRange.Bottom; y++) {
- if(_prevViewRange.Contains(x, y)) continue;
- LandTiles.Add(new LandObject(Client, Client.GetLandTile(x,y)));
+
+ for (int x = viewRange.Left; x < viewRange.Right; x++)
+ {
+ for (int y = viewRange.Top; y < viewRange.Bottom; y++)
+ {
+ if (_prevViewRange.Contains(x, y))
+ continue;
+ LandTiles.Add(new LandObject(Client, Client.GetLandTile(x, y)));
var staticTiles = Client.GetStaticTiles(x, y);
- foreach (var staticTile in staticTiles) {
+ foreach (var staticTile in staticTiles)
+ {
StaticTiles.Add(new StaticObject(staticTile));
}
}
}
-
+
Camera.Update();
_lightSourceCamera.Position = Camera.Position;
@@ -430,7 +468,8 @@ public void Update(GameTime gameTime, bool isActive, bool processMouse, bool pro
_prevMouseState = Mouse.GetState();
}
- public void Reset() {
+ public void Reset()
+ {
Client.ResizeCache(0);
LandTiles.Clear();
StaticTiles.Clear();
@@ -438,20 +477,22 @@ public void Reset() {
}
public MapObject? Selected;
-
- public MapObject? GetMouseSelection(int x, int y) {
+
+ public MapObject? GetMouseSelection(int x, int y)
+ {
Color[] pixels = new Color[1];
_selectionTarget.GetData(0, new Rectangle(x, y, 1, 1), pixels, 0, 1);
var pixel = pixels[0];
var selectedIndex = pixel.R | (pixel.G << 8) | (pixel.B << 16);
- if (selectedIndex < 1 || selectedIndex > LandTiles.Count + StaticTiles.Count)
+ if (selectedIndex < 1 || selectedIndex > LandTiles.Count + StaticTiles.Count)
return null;
- if(selectedIndex > LandTiles.Count)
+ if (selectedIndex > LandTiles.Count)
return StaticTiles[selectedIndex - 1 - LandTiles.Count];
return LandTiles[selectedIndex - 1];
}
- public void CalculateViewRange(Camera camera, out Rectangle rect) {
+ public void CalculateViewRange(Camera camera, out Rectangle rect)
+ {
float zoom = camera.Zoom;
int screenWidth = camera.ScreenSize.Width;
@@ -461,15 +502,17 @@ public void CalculateViewRange(Camera camera, out Rectangle rect) {
float screenDiamondDiagonal = (screenWidth + screenHeight) / zoom / 2f;
Vector3 center = camera.Position;
-
+
// Render a few extra rows at the top to deal with things at lower z
var minTileX = Math.Max(0, (int)Math.Ceiling((center.X - screenDiamondDiagonal) / TILE_SIZE) - 8);
var minTileY = Math.Max(0, (int)Math.Ceiling((center.Y - screenDiamondDiagonal) / TILE_SIZE) - 8);
// Render a few extra rows at the bottom to deal with things at higher z
- var maxTileX = Math.Min(Client.Width * 8 - 1, (int)Math.Ceiling((center.X + screenDiamondDiagonal) / TILE_SIZE) + 8);
- var maxTileY = Math.Min(Client.Height * 8 - 1, (int)Math.Ceiling((center.Y + screenDiamondDiagonal) / TILE_SIZE) + 8);
-
+ var maxTileX = Math.Min
+ (Client.Width * 8 - 1, (int)Math.Ceiling((center.X + screenDiamondDiagonal) / TILE_SIZE) + 8);
+ var maxTileY = Math.Min
+ (Client.Height * 8 - 1, (int)Math.Ceiling((center.Y + screenDiamondDiagonal) / TILE_SIZE) + 8);
+
rect = new Rectangle(minTileX, minTileY, maxTileX - minTileX, maxTileY - minTileY);
}
@@ -485,11 +528,9 @@ private bool IsRock(ushort id)
case 4958:
case 4959:
case 4960:
- case 4962:
- return true;
+ case 4962: return true;
- default:
- return id >= 6001 && id <= 6012;
+ default: return id >= 6001 && id <= 6012;
}
}
@@ -556,13 +597,12 @@ private bool IsTree(ushort id)
case 39225:
case 39284:
case 46822:
- case 14492:
- return true;
+ case 14492: return true;
}
return false;
}
-
+
private bool CanDrawStatic(ushort id)
{
if (id >= TileDataLoader.Instance.StaticData.Length)
@@ -578,17 +618,15 @@ private bool CanDrawStatic(ushort id)
{
case 0x0001:
case 0x21BC:
- case 0x63D3:
- return false;
+ case 0x63D3: return false;
case 0x9E4C:
case 0x9E64:
case 0x9E65:
case 0x9E7D:
- return ((data.Flags & TileFlag.Background) == 0 &&
- (data.Flags & TileFlag.Surface) == 0
- // && (data.Flags & TileFlag.NoDraw) == 0
- );
+ return ((data.Flags & TileFlag.Background) == 0 && (data.Flags & TileFlag.Surface) == 0
+ // && (data.Flags & TileFlag.NoDraw) == 0
+ );
case 0x2198:
case 0x2199:
@@ -596,149 +634,232 @@ private bool CanDrawStatic(ushort id)
case 0x21A1:
case 0x21A2:
case 0x21A3:
- case 0x21A4:
- return false;
+ case 0x21A4: return false;
}
return true;
}
-
- private bool ShouldRender(short z) {
+
+ private bool ShouldRender(short z)
+ {
return z >= MIN_Z && z <= MAX_Z;
}
-
- private void DrawStatic(StaticObject so, Vector3 hueOverride = default) {
+
+ private void DrawStatic(StaticObject so, Vector3 hueOverride = default)
+ {
var tile = so.Tile;
- if (!CanDrawStatic(tile.Id) )
+ if (!CanDrawStatic(tile.Id))
return;
-
+
var landTile = Client.GetLandTile(tile.X, tile.Y);
if (!ShouldRender(tile.Z) || (ShouldRender(landTile.Z) && landTile.Z > tile.Z + 5))
return;
-
+
_mapRenderer.DrawMapObject(so, hueOverride);
}
-
+
private void DrawLand(LandObject lo, Vector3 hueOverride = default)
{
- if (lo.Tile.Id > TileDataLoader.Instance.LandData.Length) return;
- if (!ShouldRender(lo.Tile.Z)) return;
-
+ if (lo.Tile.Id > TileDataLoader.Instance.LandData.Length)
+ return;
+ if (!ShouldRender(lo.Tile.Z))
+ return;
+
_mapRenderer.DrawMapObject(lo, hueOverride);
}
- public void Draw() {
- if (!Client.Initialized) {
+ public void Draw()
+ {
+ if (!Client.Initialized)
+ {
DrawBackground();
return;
}
- _gfxDevice.Viewport = new Viewport(0, 0, _gfxDevice.PresentationParameters.BackBufferWidth,
- _gfxDevice.PresentationParameters.BackBufferHeight);
+ _gfxDevice.Viewport = new Viewport
+ (
+ 0,
+ 0,
+ _gfxDevice.PresentationParameters.BackBufferWidth,
+ _gfxDevice.PresentationParameters.BackBufferHeight
+ );
CalculateViewRange(Camera, out var rect);
-
+
_mapEffect.WorldViewProj = _lightSourceCamera.WorldViewProj;
_mapEffect.LightSource.Enabled = false;
_mapEffect.CurrentTechnique = _mapEffect.Techniques["ShadowMap"];
- _mapRenderer.Begin(_shadowTarget, _mapEffect, _lightSourceCamera, RasterizerState.CullNone,
- SamplerState.PointClamp, _depthStencilState, BlendState.AlphaBlend, null, null, true);
- if (IsDrawShadows) {
- foreach (var staticTile in StaticTiles) {
- if (!IsRock(staticTile.Tile.Id) && !IsTree(staticTile.Tile.Id) && !TileDataLoader.Instance.StaticData[staticTile.Tile.Id].IsFoliage)
+ _mapRenderer.Begin
+ (
+ _shadowTarget,
+ _mapEffect,
+ _lightSourceCamera,
+ RasterizerState.CullNone,
+ SamplerState.PointClamp,
+ _depthStencilState,
+ BlendState.AlphaBlend,
+ null,
+ null,
+ true
+ );
+ if (IsDrawShadows)
+ {
+ foreach (var staticTile in StaticTiles)
+ {
+ if (!IsRock(staticTile.Tile.Id) && !IsTree(staticTile.Tile.Id) &&
+ !TileDataLoader.Instance.StaticData[staticTile.Tile.Id].IsFoliage)
continue;
DrawStatic(staticTile);
}
- foreach (var landTile in LandTiles) {
+ foreach (var landTile in LandTiles)
+ {
DrawLand(landTile);
}
}
_mapRenderer.End();
-
+
_mapEffect.WorldViewProj = Camera.WorldViewProj;
-
+
_mapEffect.CurrentTechnique = _mapEffect.Techniques["Selection"];
- _mapRenderer.Begin(_selectionTarget, _mapEffect, Camera, RasterizerState.CullNone, SamplerState.PointClamp,
- _depthStencilState, BlendState.AlphaBlend, null, null, true);
+ _mapRenderer.Begin
+ (
+ _selectionTarget,
+ _mapEffect,
+ Camera,
+ RasterizerState.CullNone,
+ SamplerState.PointClamp,
+ _depthStencilState,
+ BlendState.AlphaBlend,
+ null,
+ null,
+ true
+ );
//0 is no tile in selection buffer
var i = 1;
- foreach (var tile in LandTiles) {
+ foreach (var tile in LandTiles)
+ {
var color = new Color(i & 0xFF, (i >> 8) & 0xFF, (i >> 16) & 0xFF);
DrawLand(tile, color.ToVector3());
i++;
}
- foreach (var tile in StaticTiles) {
+ foreach (var tile in StaticTiles)
+ {
var color = new Color(i & 0xFF, (i >> 8) & 0xFF, (i >> 16) & 0xFF);
DrawStatic(tile, color.ToVector3());
i++;
}
-
+
_mapRenderer.End();
-
+
_mapEffect.LightWorldViewProj = _lightSourceCamera.WorldViewProj;
_mapEffect.AmbientLightColor = _lightingState.AmbientLightColor;
_mapEffect.LightSource.Direction = _lightingState.LightDirection;
_mapEffect.LightSource.DiffuseColor = _lightingState.LightDiffuseColor;
_mapEffect.LightSource.SpecularColor = _lightingState.LightSpecularColor;
_mapEffect.LightSource.Enabled = true;
-
+
_mapEffect.CurrentTechnique = _mapEffect.Techniques["Terrain"];
- _mapRenderer.Begin(null, _mapEffect, Camera, RasterizerState.CullNone, SamplerState.PointClamp,
- _depthStencilState, BlendState.AlphaBlend, _shadowTarget, HuesManager.Instance.Texture, true);
+ _mapRenderer.Begin
+ (
+ null,
+ _mapEffect,
+ Camera,
+ RasterizerState.CullNone,
+ SamplerState.PointClamp,
+ _depthStencilState,
+ BlendState.AlphaBlend,
+ _shadowTarget,
+ HuesManager.Instance.Texture,
+ true
+ );
_spriteBatch.Begin();
- var backgroundRect = new Rectangle(
+ var backgroundRect = new Rectangle
+ (
_gfxDevice.PresentationParameters.BackBufferWidth / 2 - _background.Width / 2,
_gfxDevice.PresentationParameters.BackBufferHeight / 2 - _background.Height / 2,
_background.Width,
- _background.Height);
+ _background.Height
+ );
_spriteBatch.Draw(_background, backgroundRect, Color.White);
_spriteBatch.End();
- if (IsDrawLand) {
- foreach (var tile in LandTiles) {
- if(tile.Visible)
+ if (IsDrawLand)
+ {
+ foreach (var tile in LandTiles)
+ {
+ if (tile.Visible)
DrawLand(tile);
}
- foreach (var tile in GhostLandTiles) {
+ foreach (var tile in GhostLandTiles)
+ {
DrawLand(tile);
}
}
_mapRenderer.End();
-
+
_mapEffect.CurrentTechnique = _mapEffect.Techniques["Statics"];
- _mapRenderer.Begin(null, _mapEffect, Camera, RasterizerState.CullNone, SamplerState.PointClamp,
- _depthStencilState, BlendState.AlphaBlend, _shadowTarget, HuesManager.Instance.Texture, false);
- if (IsDrawStatic) {
- foreach (var tile in StaticTiles) {
- if(tile.Visible)
+ _mapRenderer.Begin
+ (
+ null,
+ _mapEffect,
+ Camera,
+ RasterizerState.CullNone,
+ SamplerState.PointClamp,
+ _depthStencilState,
+ BlendState.AlphaBlend,
+ _shadowTarget,
+ HuesManager.Instance.Texture,
+ false
+ );
+ if (IsDrawStatic)
+ {
+ foreach (var tile in StaticTiles)
+ {
+ if (tile.Visible)
DrawStatic(tile);
}
- foreach (var tile in GhostStaticTiles) {
+ foreach (var tile in GhostStaticTiles)
+ {
DrawStatic(tile);
}
}
_mapRenderer.End();
}
- private void DrawBackground() {
+ private void DrawBackground()
+ {
_mapEffect.CurrentTechnique = _mapEffect.Techniques["Terrain"];
- _mapRenderer.Begin(null, _mapEffect, Camera, RasterizerState.CullNone, SamplerState.PointClamp,
- _depthStencilState, BlendState.AlphaBlend, null,null, true);
+ _mapRenderer.Begin
+ (
+ null,
+ _mapEffect,
+ Camera,
+ RasterizerState.CullNone,
+ SamplerState.PointClamp,
+ _depthStencilState,
+ BlendState.AlphaBlend,
+ null,
+ null,
+ true
+ );
_spriteBatch.Begin();
- var backgroundRect = new Rectangle(
+ var backgroundRect = new Rectangle
+ (
_gfxDevice.PresentationParameters.BackBufferWidth / 2 - _background.Width / 2,
_gfxDevice.PresentationParameters.BackBufferHeight / 2 - _background.Height / 2,
_background.Width,
- _background.Height);
+ _background.Height
+ );
_spriteBatch.Draw(_background, backgroundRect, Color.White);
_spriteBatch.End();
_mapRenderer.End();
}
//TODO: Bring me back!
- public void DrawHighRes() {
+ public void DrawHighRes()
+ {
// Console.WriteLine("HIGH RES!");
// var myRenderTarget = new RenderTarget2D(_gfxDevice, 15360, 8640, false, SurfaceFormat.Color, DepthFormat.Depth24);
//
@@ -786,24 +907,29 @@ public void DrawHighRes() {
// Console.WriteLine("HIGH RES DONE!");
}
- public void OnWindowsResized(GameWindow window) {
+ public void OnWindowsResized(GameWindow window)
+ {
Camera.ScreenSize = window.ClientBounds;
Camera.Update();
-
- _shadowTarget = new RenderTarget2D(
+
+ _shadowTarget = new RenderTarget2D
+ (
_gfxDevice,
_gfxDevice.PresentationParameters.BackBufferWidth * 2,
_gfxDevice.PresentationParameters.BackBufferHeight * 2,
false,
SurfaceFormat.Single,
- DepthFormat.Depth24);
-
- _selectionTarget = new RenderTarget2D(
+ DepthFormat.Depth24
+ );
+
+ _selectionTarget = new RenderTarget2D
+ (
_gfxDevice,
_gfxDevice.PresentationParameters.BackBufferWidth,
_gfxDevice.PresentationParameters.BackBufferHeight,
false,
SurfaceFormat.Color,
- DepthFormat.Depth24);
+ DepthFormat.Depth24
+ );
}
}
\ No newline at end of file
diff --git a/CentrED/Map/MapObject.cs b/CentrED/Map/MapObject.cs
index 697b0c4..60fd984 100644
--- a/CentrED/Map/MapObject.cs
+++ b/CentrED/Map/MapObject.cs
@@ -3,7 +3,8 @@
namespace CentrED.Map;
-public abstract class MapObject {
+public abstract class MapObject
+{
public const float INVERSE_SQRT2 = 0.70711f;
public const float TILE_SIZE = 31.11f;
public const float TILE_Z_SCALE = 4.0f;
@@ -14,17 +15,23 @@ public abstract class MapObject {
public Texture2D Texture;
public MapVertex[] Vertices = new MapVertex[4];
- public ushort Hue {
- set {
- for (var index = 0; index < Vertices.Length; index++) {
+ public ushort Hue
+ {
+ set
+ {
+ for (var index = 0; index < Vertices.Length; index++)
+ {
Vertices[index].HueVec = HuesManager.Instance.GetHueVector(Tile.Id, value, Vertices[index].HueVec.Z);
}
}
}
-
- public float Alpha {
- set {
- for (var index = 0; index < Vertices.Length; index++) {
+
+ public float Alpha
+ {
+ set
+ {
+ for (var index = 0; index < Vertices.Length; index++)
+ {
Vertices[index].HueVec.Z = value;
}
}
diff --git a/CentrED/Map/RadarMap.cs b/CentrED/Map/RadarMap.cs
index 5900064..1fabace 100644
--- a/CentrED/Map/RadarMap.cs
+++ b/CentrED/Map/RadarMap.cs
@@ -4,45 +4,54 @@
using Microsoft.Xna.Framework.Graphics;
using static CentrED.Application;
-namespace CentrED.Map;
+namespace CentrED.Map;
-public class RadarMap {
+public class RadarMap
+{
private static RadarMap _instance;
public static RadarMap Instance => _instance;
-
+
private Texture2D _texture = null!;
public Texture2D Texture => _texture;
-
- private RadarMap(GraphicsDevice gd) {
- CEDClient.Connected += () => {
- _texture = new Texture2D(gd, CEDClient.Width, CEDClient.Height );
+
+ private RadarMap(GraphicsDevice gd)
+ {
+ CEDClient.Connected += () =>
+ {
+ _texture = new Texture2D(gd, CEDClient.Width, CEDClient.Height);
CEDClient.Send(new RequestRadarMapPacket());
};
-
+
CEDClient.RadarData += RadarData;
CEDClient.RadarUpdate += RadarUpdate;
}
- public static void Initialize(GraphicsDevice gd) {
+ public static void Initialize(GraphicsDevice gd)
+ {
_instance = new RadarMap(gd);
}
- private unsafe void RadarData(ushort[] data) {
+ private unsafe void RadarData(ushort[] data)
+ {
var width = CEDClient.Width;
var height = CEDClient.Height;
uint[] buffer = System.Buffers.ArrayPool.Shared.Rent(data.Length);
- for (ushort x = 0; x < width; x++) {
- for (ushort y = 0; y < height; y++) {
+ for (ushort x = 0; x < width; x++)
+ {
+ for (ushort y = 0; y < height; y++)
+ {
buffer[y * width + x] = HuesHelper.Color16To32(data[x * height + y]) | 0xFF_00_00_00;
}
}
- fixed (uint* ptr = buffer) {
+ fixed (uint* ptr = buffer)
+ {
_texture.SetDataPointerEXT(0, null, (IntPtr)ptr, data.Length * sizeof(uint));
}
}
- private void RadarUpdate(ushort x, ushort y, ushort color) {
- _texture.SetData(0, new Rectangle(x, y,1,1), new []{HuesHelper.Color16To32(color) | 0xFF_00_00_00},0,1);
+ private void RadarUpdate(ushort x, ushort y, ushort color)
+ {
+ _texture.SetData(0, new Rectangle(x, y, 1, 1), new[] { HuesHelper.Color16To32(color) | 0xFF_00_00_00 }, 0, 1);
}
}
\ No newline at end of file
diff --git a/CentrED/Map/StaticObject.cs b/CentrED/Map/StaticObject.cs
index 55aba3d..814688e 100644
--- a/CentrED/Map/StaticObject.cs
+++ b/CentrED/Map/StaticObject.cs
@@ -2,23 +2,25 @@
using ClassicUO.Assets;
using Microsoft.Xna.Framework;
-namespace CentrED.Map;
+namespace CentrED.Map;
-public class StaticObject : MapObject {
+public class StaticObject : MapObject
+{
public StaticTile StaticTile;
-
- public StaticObject(StaticTile tile) {
+
+ public StaticObject(StaticTile tile)
+ {
Tile = tile;
StaticTile = tile;
var posX = tile.X * TILE_SIZE;
var posY = tile.Y * TILE_SIZE;
var posZ = tile.Z * TILE_Z_SCALE;
-
+
Texture = ArtLoader.Instance.GetStaticTexture(tile.Id, out var bounds);
var projectedWidth = (bounds.Width / 2f) * INVERSE_SQRT2;
var depthOffset = tile.CellIndex * 0.0001f;
-
+
var coordinates = new Vector3[4];
coordinates[0] = new Vector3(posX - projectedWidth, posY + projectedWidth, posZ + bounds.Height);
coordinates[1] = new Vector3(posX + projectedWidth, posY - projectedWidth, posZ + bounds.Height);
@@ -30,7 +32,7 @@ public StaticObject(StaticTile tile) {
var texY = bounds.Y / (float)Texture.Height + onePixel / 2f;
var texWidth = bounds.Width / (float)Texture.Width - onePixel;
var texHeight = bounds.Height / (float)Texture.Height - onePixel;
-
+
var texCoords = new Vector3[4];
texCoords[0] = new Vector3(texX, texY, depthOffset);
texCoords[1] = new Vector3(texX + texWidth, texY, depthOffset);
@@ -38,7 +40,8 @@ public StaticObject(StaticTile tile) {
texCoords[3] = new Vector3(texX + texWidth, texY + texHeight, depthOffset);
var hue = HuesManager.Instance.GetHueVector(tile);
- for (int i = 0; i < 4; i++) {
+ for (int i = 0; i < 4; i++)
+ {
Vertices[i] = new MapVertex(coordinates[i], Vector3.UnitZ, texCoords[i], hue);
}
}
diff --git a/CentrED/Renderer/Effects/MapEffect.cs b/CentrED/Renderer/Effects/MapEffect.cs
index 3d8e485..7590ca2 100644
--- a/CentrED/Renderer/Effects/MapEffect.cs
+++ b/CentrED/Renderer/Effects/MapEffect.cs
@@ -15,25 +15,29 @@ public class MapEffect : Effect
private Vector3 _ambientLightColor = Vector3.One;
- public Matrix WorldViewProj {
+ public Matrix WorldViewProj
+ {
get { return _worldViewProj; }
set { _worldViewProj = value; }
}
- public Matrix LightWorldViewProj {
+ public Matrix LightWorldViewProj
+ {
get { return _lightWorldViewProj; }
set { _lightWorldViewProj = value; }
}
- public Vector3 AmbientLightColor {
+ public Vector3 AmbientLightColor
+ {
get { return _ambientLightColor; }
- set {
- _ambientLightColor = value;
- }
+ set { _ambientLightColor = value; }
}
- public DirectionalLight LightSource { get { return _lightSource; } }
+ public DirectionalLight LightSource
+ {
+ get { return _lightSource; }
+ }
protected static byte[] GetResource(string name)
{
@@ -52,17 +56,20 @@ protected static byte[] GetResource(string name)
}
}
- public MapEffect(GraphicsDevice device)
- : base(device, GetResource("CentrED.Renderer.Effects.Shaders.MapEffect.fxc"))
+ public MapEffect(GraphicsDevice device) : base
+ (device, GetResource("CentrED.Renderer.Effects.Shaders.MapEffect.fxc"))
{
_ambientLightColorParam = Parameters["AmbientLightColor"];
_worldViewProjParam = Parameters["WorldViewProj"];
_lightWorldViewProjParam = Parameters["LightWorldViewProj"];
- _lightSource = new DirectionalLight(Parameters["DirectionalLightDirection"],
- Parameters["DirectionalLightDiffuseColor"],
- Parameters["DirectionalLightSpecularColor"],
- null);
+ _lightSource = new DirectionalLight
+ (
+ Parameters["DirectionalLightDirection"],
+ Parameters["DirectionalLightDiffuseColor"],
+ Parameters["DirectionalLightSpecularColor"],
+ null
+ );
}
protected override void OnApply()
@@ -71,4 +78,4 @@ protected override void OnApply()
_lightWorldViewProjParam.SetValue(_lightWorldViewProj);
_ambientLightColorParam.SetValue(new Vector4(_ambientLightColor, 1));
}
-}
+}
\ No newline at end of file
diff --git a/CentrED/Renderer/MapRenderer.cs b/CentrED/Renderer/MapRenderer.cs
index e04c2eb..1788f24 100644
--- a/CentrED/Renderer/MapRenderer.cs
+++ b/CentrED/Renderer/MapRenderer.cs
@@ -19,10 +19,9 @@ public class LightingState
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct MapVertex : IVertexType
{
- VertexDeclaration IVertexType.VertexDeclaration {
- get {
- return VertexDeclaration;
- }
+ VertexDeclaration IVertexType.VertexDeclaration
+ {
+ get { return VertexDeclaration; }
}
public Vector3 Position;
@@ -34,43 +33,19 @@ VertexDeclaration IVertexType.VertexDeclaration {
static MapVertex()
{
- VertexDeclaration = new VertexDeclaration(
+ VertexDeclaration = new VertexDeclaration
+ (
new VertexElement[]
{
- new VertexElement(
- 0,
- VertexElementFormat.Vector3,
- VertexElementUsage.Position,
- 0
- ),
- new VertexElement(
- 12,
- VertexElementFormat.Vector3,
- VertexElementUsage.Normal,
- 0
- ),
- new VertexElement(
- 24,
- VertexElementFormat.Vector3,
- VertexElementUsage.TextureCoordinate,
- 0
- ),
- new VertexElement(
- 36,
- VertexElementFormat.Vector3,
- VertexElementUsage.TextureCoordinate,
- 0
- )
+ new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
+ new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
+ new VertexElement(24, VertexElementFormat.Vector3, VertexElementUsage.TextureCoordinate, 0),
+ new VertexElement(36, VertexElementFormat.Vector3, VertexElementUsage.TextureCoordinate, 0)
}
);
}
- public MapVertex(
- Vector3 position,
- Vector3 normal,
- Vector3 textureCoordinate,
- Vector3 hueVec
- )
+ public MapVertex(Vector3 position, Vector3 normal, Vector3 textureCoordinate, Vector3 hueVec)
{
Position = position;
Normal = normal;
@@ -79,10 +54,10 @@ Vector3 hueVec
}
}
-
public class MapRenderer
{
#region Draw Batcher
+
private class DrawBatcher
{
private const int MAX_TILES_PER_BATCH = 4096;
@@ -134,24 +109,15 @@ public DrawBatcher(GraphicsDevice device)
_vertexInfo = new MapVertex[MAX_VERTICES];
- _vertexBuffer = new DynamicVertexBuffer(
- device,
- typeof(MapVertex),
- MAX_VERTICES,
- BufferUsage.WriteOnly
- );
+ _vertexBuffer = new DynamicVertexBuffer(device, typeof(MapVertex), MAX_VERTICES, BufferUsage.WriteOnly);
- _indexBuffer = new IndexBuffer(
- device,
- IndexElementSize.SixteenBits,
- MAX_INDICES,
- BufferUsage.WriteOnly
- );
+ _indexBuffer = new IndexBuffer(device, IndexElementSize.SixteenBits, MAX_INDICES, BufferUsage.WriteOnly);
_indexBuffer.SetData(_indexData);
}
- public void Begin(
+ public void Begin
+ (
RenderTarget2D output,
MapEffect effect,
Camera camera,
@@ -192,7 +158,8 @@ private unsafe void Flush()
fixed (MapVertex* p = &_vertexInfo[0])
{
- _vertexBuffer.SetDataPointerEXT(0, (IntPtr)p, Unsafe.SizeOf() * _numTiles * 4, SetDataOptions.Discard);
+ _vertexBuffer.SetDataPointerEXT
+ (0, (IntPtr)p, Unsafe.SizeOf() * _numTiles * 4, SetDataOptions.Discard);
}
_gfxDevice.SetVertexBuffer(_vertexBuffer);
@@ -222,23 +189,27 @@ public unsafe void End()
_beginCalled = false;
}
-
- public void DrawMapObject(MapObject o, Vector3 hueOverride) {
+
+ public void DrawMapObject(MapObject o, Vector3 hueOverride)
+ {
if (_numTiles + 1 >= MAX_TILES_PER_BATCH)
Flush();
int cur = _numTiles * 4;
- for (var i = 0; i < 4; i++) {
+ for (var i = 0; i < 4; i++)
+ {
_vertexInfo[cur + i] = o.Vertices[i];
- if (hueOverride != default) {
+ if (hueOverride != default)
+ {
_vertexInfo[cur + i].HueVec = hueOverride;
}
}
_numTiles++;
}
}
-#endregion
+
+ #endregion
private readonly GraphicsDevice _gfxDevice;
@@ -265,12 +236,24 @@ private DrawBatcher GetBatcher(Texture2D texture)
}
}
- for (int i = 0; i < _batchers.Length; i++)
+ for (int i = 0; i < _batchers.Length; i++)
{
if (_textures[i] == null)
{
_textures[i] = texture;
- _batchers[i].Begin(_mapTarget, _effect, _camera, texture, _rasterizerState, _samplerState, _depthStencilState, _blendState, _shadowMap, _huesTexture);
+ _batchers[i].Begin
+ (
+ _mapTarget,
+ _effect,
+ _camera,
+ texture,
+ _rasterizerState,
+ _samplerState,
+ _depthStencilState,
+ _blendState,
+ _shadowMap,
+ _huesTexture
+ );
return _batchers[i];
}
}
@@ -278,7 +261,19 @@ private DrawBatcher GetBatcher(Texture2D texture)
/* TODO: Don't always evict the first one */
_batchers[0].End();
_textures[0] = texture;
- _batchers[0].Begin(_mapTarget, _effect, _camera, texture, _rasterizerState, _samplerState, _depthStencilState, _blendState, _shadowMap, _huesTexture);
+ _batchers[0].Begin
+ (
+ _mapTarget,
+ _effect,
+ _camera,
+ texture,
+ _rasterizerState,
+ _samplerState,
+ _depthStencilState,
+ _blendState,
+ _shadowMap,
+ _huesTexture
+ );
return _batchers[0];
}
@@ -294,7 +289,8 @@ public MapRenderer(GraphicsDevice device)
}
}
- public void Begin(
+ public void Begin
+ (
RenderTarget2D output,
MapEffect effect,
Camera camera,
@@ -330,7 +326,7 @@ bool clear
_textures[i] = null;
}
_gfxDevice.SetRenderTarget(output);
- if(clear)
+ if (clear)
_gfxDevice.Clear(Color.Black);
}
@@ -350,8 +346,9 @@ public unsafe void End()
_beginCalled = false;
}
- public void DrawMapObject(MapObject mapObject, Vector3 hueOverride) {
+ public void DrawMapObject(MapObject mapObject, Vector3 hueOverride)
+ {
var batcher = GetBatcher(mapObject.Texture);
batcher.DrawMapObject(mapObject, hueOverride);
}
-}
+}
\ No newline at end of file
diff --git a/CentrED/Renderer/PostProcessRenderer.cs b/CentrED/Renderer/PostProcessRenderer.cs
index d68ad21..364355c 100644
--- a/CentrED/Renderer/PostProcessRenderer.cs
+++ b/CentrED/Renderer/PostProcessRenderer.cs
@@ -13,10 +13,7 @@ public class PostProcessRenderer
private readonly VertexPositionTexture[] _vertexInfo = new VertexPositionTexture[4];
- private static readonly short[] _indexData = new short[6]
- {
- 0, 1, 2, 3, 2, 1
- };
+ private static readonly short[] _indexData = new short[6] { 0, 1, 2, 3, 2, 1 };
private RasterizerState _rasterizerState;
private SamplerState _samplerState;
@@ -28,55 +25,31 @@ public PostProcessRenderer(GraphicsDevice device)
{
_gfxDevice = device;
- _vertexBuffer = new DynamicVertexBuffer(
- device,
- typeof(VertexPositionTexture),
- 4,
- BufferUsage.WriteOnly
- );
+ _vertexBuffer = new DynamicVertexBuffer(device, typeof(VertexPositionTexture), 4, BufferUsage.WriteOnly);
- _indexBuffer = new IndexBuffer(
- device,
- IndexElementSize.SixteenBits,
- 6,
- BufferUsage.WriteOnly
- );
+ _indexBuffer = new IndexBuffer(device, IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly);
_indexBuffer.SetData(_indexData);
}
// Draw the input texture to fill the output target. Output can be null to draw to the back buffer.
// This is a simple point clamp scaling.
- public unsafe void Scale(
- Texture2D input,
- RenderTarget2D output
- )
+ public unsafe void Scale(Texture2D input, RenderTarget2D output)
{
var width = output == null ? _gfxDevice.PresentationParameters.BackBufferWidth : output.Width;
var height = output == null ? _gfxDevice.PresentationParameters.BackBufferHeight : output.Height;
_gfxDevice.SetRenderTarget(output);
- _vertexInfo[0] = new VertexPositionTexture(
- new Vector3(0, 0, 0),
- new Vector2(0, 0)
- );
- _vertexInfo[1] = new VertexPositionTexture(
- new Vector3(width, 0, 0),
- new Vector2(1, 0)
- );
- _vertexInfo[2] = new VertexPositionTexture(
- new Vector3(0, height, 0),
- new Vector2(0, 1)
- );
- _vertexInfo[3] = new VertexPositionTexture(
- new Vector3(width, height, 0),
- new Vector2(1, 1)
- );
+ _vertexInfo[0] = new VertexPositionTexture(new Vector3(0, 0, 0), new Vector2(0, 0));
+ _vertexInfo[1] = new VertexPositionTexture(new Vector3(width, 0, 0), new Vector2(1, 0));
+ _vertexInfo[2] = new VertexPositionTexture(new Vector3(0, height, 0), new Vector2(0, 1));
+ _vertexInfo[3] = new VertexPositionTexture(new Vector3(width, height, 0), new Vector2(1, 1));
fixed (VertexPositionTexture* p = &_vertexInfo[0])
{
- _vertexBuffer.SetDataPointerEXT(0, (IntPtr)p, Unsafe.SizeOf() * 4, SetDataOptions.Discard);
+ _vertexBuffer.SetDataPointerEXT
+ (0, (IntPtr)p, Unsafe.SizeOf() * 4, SetDataOptions.Discard);
}
_gfxDevice.SetVertexBuffer(_vertexBuffer);
diff --git a/CentrED/Renderer/StbRectPack/CRuntime.cs b/CentrED/Renderer/StbRectPack/CRuntime.cs
index aea5a1f..12eadf3 100644
--- a/CentrED/Renderer/StbRectPack/CRuntime.cs
+++ b/CentrED/Renderer/StbRectPack/CRuntime.cs
@@ -1,86 +1,85 @@
using System.Runtime.InteropServices;
-namespace CentrED.Renderer.StbRectPack
+namespace CentrED.Renderer.StbRectPack;
+
+internal static unsafe class CRuntime
{
- internal static unsafe class CRuntime
+ public static void* malloc(ulong size)
{
- public static void* malloc(ulong size)
- {
- return malloc((long)size);
- }
+ return malloc((long)size);
+ }
- public static void* malloc(long size)
- {
- var ptr = Marshal.AllocHGlobal((int)size);
+ public static void* malloc(long size)
+ {
+ var ptr = Marshal.AllocHGlobal((int)size);
- return ptr.ToPointer();
- }
+ return ptr.ToPointer();
+ }
- public static void free(void* a)
- {
- var ptr = new IntPtr(a);
- Marshal.FreeHGlobal(ptr);
- }
+ public static void free(void* a)
+ {
+ var ptr = new IntPtr(a);
+ Marshal.FreeHGlobal(ptr);
+ }
- public delegate int QSortComparer(void* a, void* b);
+ public delegate int QSortComparer(void* a, void* b);
- private static void qsortSwap(byte* data, long size, long pos1, long pos2)
- {
- var a = data + size * pos1;
- var b = data + size * pos2;
+ private static void qsortSwap(byte* data, long size, long pos1, long pos2)
+ {
+ var a = data + size * pos1;
+ var b = data + size * pos2;
- for (long k = 0; k < size; ++k)
- {
- var tmp = *a;
- *a = *b;
- *b = tmp;
+ for (long k = 0; k < size; ++k)
+ {
+ var tmp = *a;
+ *a = *b;
+ *b = tmp;
- a++;
- b++;
- }
+ a++;
+ b++;
}
+ }
- private static long qsortPartition(byte* data, long size, QSortComparer comparer, long left, long right)
+ private static long qsortPartition(byte* data, long size, QSortComparer comparer, long left, long right)
+ {
+ void* pivot = data + size * left;
+ var i = left - 1;
+ var j = right + 1;
+ for (;;)
{
- void* pivot = data + size * left;
- var i = left - 1;
- var j = right + 1;
- for (; ; )
+ do
{
- do
- {
- ++i;
- } while (comparer(data + size * i, pivot) < 0);
-
- do
- {
- --j;
- } while (comparer(data + size * j, pivot) > 0);
-
- if (i >= j)
- {
- return j;
- }
-
- qsortSwap(data, size, i, j);
- }
- }
-
+ ++i;
+ } while (comparer(data + size * i, pivot) < 0);
- private static void qsortInternal(byte* data, long size, QSortComparer comparer, long left, long right)
- {
- if (left < right)
+ do
{
- var p = qsortPartition(data, size, comparer, left, right);
+ --j;
+ } while (comparer(data + size * j, pivot) > 0);
- qsortInternal(data, size, comparer, left, p);
- qsortInternal(data, size, comparer, p + 1, right);
+ if (i >= j)
+ {
+ return j;
}
+
+ qsortSwap(data, size, i, j);
}
+ }
- public static void qsort(void* data, ulong count, ulong size, QSortComparer comparer)
+
+ private static void qsortInternal(byte* data, long size, QSortComparer comparer, long left, long right)
+ {
+ if (left < right)
{
- qsortInternal((byte*)data, (long)size, comparer, 0, (long)count - 1);
+ var p = qsortPartition(data, size, comparer, left, right);
+
+ qsortInternal(data, size, comparer, left, p);
+ qsortInternal(data, size, comparer, p + 1, right);
}
}
+
+ public static void qsort(void* data, ulong count, ulong size, QSortComparer comparer)
+ {
+ qsortInternal((byte*)data, (long)size, comparer, 0, (long)count - 1);
+ }
}
\ No newline at end of file
diff --git a/CentrED/Renderer/StbRectPack/Packer.cs b/CentrED/Renderer/StbRectPack/Packer.cs
index 457e947..2f3f54a 100644
--- a/CentrED/Renderer/StbRectPack/Packer.cs
+++ b/CentrED/Renderer/StbRectPack/Packer.cs
@@ -1,85 +1,79 @@
using Microsoft.Xna.Framework;
using static CentrED.Renderer.StbRectPack.StbRectPack;
-namespace CentrED.Renderer.StbRectPack
+namespace CentrED.Renderer.StbRectPack;
+
+///
+/// Simple Packer class that doubles size of the atlas if the place runs out
+///
+unsafe class Packer : IDisposable
{
- ///
- /// Simple Packer class that doubles size of the atlas if the place runs out
- ///
- unsafe class Packer : IDisposable
- {
- private readonly stbrp_context _context;
+ private readonly stbrp_context _context;
- public int Width => _context.width;
- public int Height => _context.height;
- public int PackeRectanglesCount { get; private set; }
+ public int Width => _context.width;
+ public int Height => _context.height;
+ public int PackeRectanglesCount { get; private set; }
- public Packer(int width = 256, int height = 256)
+ public Packer(int width = 256, int height = 256)
+ {
+ if (width <= 0)
{
- if (width <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(width));
- }
-
- if (height <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(height));
- }
-
- // Initialize the context
- var num_nodes = width;
- _context = new stbrp_context(num_nodes);
+ throw new ArgumentOutOfRangeException(nameof(width));
+ }
- fixed (stbrp_context* contextPtr = &_context)
- {
- stbrp_init_target(contextPtr, width, height, _context.all_nodes, num_nodes);
- }
+ if (height <= 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(height));
}
- public void Dispose()
+ // Initialize the context
+ var num_nodes = width;
+ _context = new stbrp_context(num_nodes);
+
+ fixed (stbrp_context* contextPtr = &_context)
{
- _context.Dispose();
+ stbrp_init_target(contextPtr, width, height, _context.all_nodes, num_nodes);
}
+ }
- ///
- /// Packs a rect. Returns null, if there's no more place left.
- ///
- ///
- ///
- ///
- public bool PackRect(int width, int height, out Rectangle packRectangle, int offset = 2)
+ public void Dispose()
+ {
+ _context.Dispose();
+ }
+
+ ///
+ /// Packs a rect. Returns null, if there's no more place left.
+ ///
+ ///
+ ///
+ ///
+ public bool PackRect(int width, int height, out Rectangle packRectangle, int offset = 2)
+ {
+ var rect = new stbrp_rect
{
- var rect = new stbrp_rect
- {
- id = PackeRectanglesCount,
- w = width + offset,
- h = height + offset
- };
+ id = PackeRectanglesCount,
+ w = width + offset,
+ h = height + offset
+ };
- int result;
- fixed (stbrp_context* contextPtr = &_context)
- {
- result = stbrp_pack_rects(contextPtr, &rect, 1);
- }
+ int result;
+ fixed (stbrp_context* contextPtr = &_context)
+ {
+ result = stbrp_pack_rects(contextPtr, &rect, 1);
+ }
- if (result == 0)
- {
- packRectangle = Rectangle.Empty;
- return false;
- }
+ if (result == 0)
+ {
+ packRectangle = Rectangle.Empty;
+ return false;
+ }
- packRectangle = new Rectangle
- (
- rect.x + (int)(offset / 2f),
- rect.y + (int)(offset / 2f),
- rect.w - offset,
- rect.h - offset
- );
+ packRectangle = new Rectangle
+ (rect.x + (int)(offset / 2f), rect.y + (int)(offset / 2f), rect.w - offset, rect.h - offset);
- ++PackeRectanglesCount;
+ ++PackeRectanglesCount;
- return true;
- }
+ return true;
}
-}
+}
\ No newline at end of file
diff --git a/CentrED/Renderer/StbRectPack/StbRectPack.cs b/CentrED/Renderer/StbRectPack/StbRectPack.cs
index 81a0468..b978480 100644
--- a/CentrED/Renderer/StbRectPack/StbRectPack.cs
+++ b/CentrED/Renderer/StbRectPack/StbRectPack.cs
@@ -1,52 +1,51 @@
-namespace CentrED.Renderer.StbRectPack
+namespace CentrED.Renderer.StbRectPack;
+
+static unsafe partial class StbRectPack
{
- static unsafe partial class StbRectPack
+ public struct stbrp_context : IDisposable
{
- public struct stbrp_context : IDisposable
+ public int width;
+ public int height;
+ public int align;
+ public int init_mode;
+ public int heuristic;
+ public int num_nodes;
+ public stbrp_node* active_head;
+ public stbrp_node* free_head;
+ public stbrp_node* extra;
+ public stbrp_node* all_nodes;
+
+
+ public stbrp_context(int nodesCount)
{
- public int width;
- public int height;
- public int align;
- public int init_mode;
- public int heuristic;
- public int num_nodes;
- public stbrp_node* active_head;
- public stbrp_node* free_head;
- public stbrp_node* extra;
- public stbrp_node* all_nodes;
-
-
- public stbrp_context(int nodesCount)
+ if (nodesCount <= 0)
{
- if (nodesCount <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(nodesCount));
- }
+ throw new ArgumentOutOfRangeException(nameof(nodesCount));
+ }
- width = height = align = init_mode = heuristic = num_nodes = 0;
- active_head = free_head = null;
+ width = height = align = init_mode = heuristic = num_nodes = 0;
+ active_head = free_head = null;
- //Allocate nodes
- all_nodes = (stbrp_node*)CRuntime.malloc(sizeof(stbrp_node) * nodesCount);
+ //Allocate nodes
+ all_nodes = (stbrp_node*)CRuntime.malloc(sizeof(stbrp_node) * nodesCount);
- //Allocate extras
- extra = (stbrp_node*)CRuntime.malloc(sizeof(stbrp_node) * 2);
+ //Allocate extras
+ extra = (stbrp_node*)CRuntime.malloc(sizeof(stbrp_node) * 2);
+ }
+
+ public void Dispose()
+ {
+ if (all_nodes != null)
+ {
+ CRuntime.free(all_nodes);
+ all_nodes = null;
}
- public void Dispose()
+ if (extra != null)
{
- if (all_nodes != null)
- {
- CRuntime.free(all_nodes);
- all_nodes = null;
- }
-
- if (extra != null)
- {
- CRuntime.free(extra);
- extra = null;
- }
+ CRuntime.free(extra);
+ extra = null;
}
}
}
-}
+}
\ No newline at end of file
diff --git a/CentrED/Renderer/UIRenderer.cs b/CentrED/Renderer/UIRenderer.cs
index ca27d33..2dd9ef5 100644
--- a/CentrED/Renderer/UIRenderer.cs
+++ b/CentrED/Renderer/UIRenderer.cs
@@ -13,9 +13,13 @@ public static class DrawVertDeclaration
static DrawVertDeclaration()
{
- unsafe { Size = sizeof(ImDrawVert); }
+ unsafe
+ {
+ Size = sizeof(ImDrawVert);
+ }
- Declaration = new VertexDeclaration(
+ Declaration = new VertexDeclaration
+ (
Size,
// Position
@@ -82,14 +86,18 @@ public virtual unsafe void RebuildFontAtlas()
// Copy the data to a managed array
var pixels = new byte[width * height * bytesPerPixel];
- unsafe { Marshal.Copy(new IntPtr(pixelData), pixels, 0, pixels.Length); }
+ unsafe
+ {
+ Marshal.Copy(new IntPtr(pixelData), pixels, 0, pixels.Length);
+ }
// Create and register the texture as an XNA texture
var tex2d = new Texture2D(_graphicsDevice, width, height, false, SurfaceFormat.Color);
tex2d.SetData(pixels);
// Should a texture already have been build previously, unbind it first so it can be deallocated
- if (_fontTextureId.HasValue) UnbindTexture(_fontTextureId.Value);
+ if (_fontTextureId.HasValue)
+ UnbindTexture(_fontTextureId.Value);
// Bind the new texture to an ImGui-friendly id
_fontTextureId = BindTexture(tex2d);
@@ -102,9 +110,11 @@ public virtual unsafe void RebuildFontAtlas()
///
/// Creates a pointer to a texture, which can be passed through ImGui calls such as . That pointer is then used by ImGui to let us know what texture to draw
///
- public virtual IntPtr BindTexture(Texture2D texture) {
+ public virtual IntPtr BindTexture(Texture2D texture)
+ {
var id = _loadedTextures.IndexOf(texture);
- if (id == -1) {
+ if (id == -1)
+ {
_loadedTextures.Add(texture);
id = _loadedTextures.Count - 1;
}
@@ -166,7 +176,13 @@ public void RenderDrawData(ImDrawDataPtr drawData)
drawData.ScaleClipRects(ImGui.GetIO().DisplayFramebufferScale);
// Setup projection
- _graphicsDevice.Viewport = new Viewport(0, 0, _graphicsDevice.PresentationParameters.BackBufferWidth, _graphicsDevice.PresentationParameters.BackBufferHeight);
+ _graphicsDevice.Viewport = new Viewport
+ (
+ 0,
+ 0,
+ _graphicsDevice.PresentationParameters.BackBufferWidth,
+ _graphicsDevice.PresentationParameters.BackBufferHeight
+ );
UpdateBuffers(drawData);
@@ -190,7 +206,8 @@ private unsafe void UpdateBuffers(ImDrawDataPtr drawData)
_vertexBuffer?.Dispose();
_vertexBufferSize = (int)(drawData.TotalVtxCount * 1.5f);
- _vertexBuffer = new VertexBuffer(_graphicsDevice, DrawVertDeclaration.Declaration, _vertexBufferSize, BufferUsage.None);
+ _vertexBuffer = new VertexBuffer
+ (_graphicsDevice, DrawVertDeclaration.Declaration, _vertexBufferSize, BufferUsage.None);
_vertexData = new byte[_vertexBufferSize * DrawVertDeclaration.Size];
}
@@ -199,7 +216,8 @@ private unsafe void UpdateBuffers(ImDrawDataPtr drawData)
_indexBuffer?.Dispose();
_indexBufferSize = (int)(drawData.TotalIdxCount * 1.5f);
- _indexBuffer = new IndexBuffer(_graphicsDevice, IndexElementSize.SixteenBits, _indexBufferSize, BufferUsage.None);
+ _indexBuffer = new IndexBuffer
+ (_graphicsDevice, IndexElementSize.SixteenBits, _indexBufferSize, BufferUsage.None);
_indexData = new byte[_indexBufferSize * sizeof(ushort)];
}
@@ -214,8 +232,20 @@ private unsafe void UpdateBuffers(ImDrawDataPtr drawData)
fixed (void* vtxDstPtr = &_vertexData[vtxOffset * DrawVertDeclaration.Size])
fixed (void* idxDstPtr = &_indexData[idxOffset * sizeof(ushort)])
{
- Buffer.MemoryCopy((void*)cmdList.VtxBuffer.Data, vtxDstPtr, _vertexData.Length, cmdList.VtxBuffer.Size * DrawVertDeclaration.Size);
- Buffer.MemoryCopy((void*)cmdList.IdxBuffer.Data, idxDstPtr, _indexData.Length, cmdList.IdxBuffer.Size * sizeof(ushort));
+ Buffer.MemoryCopy
+ (
+ (void*)cmdList.VtxBuffer.Data,
+ vtxDstPtr,
+ _vertexData.Length,
+ cmdList.VtxBuffer.Size * DrawVertDeclaration.Size
+ );
+ Buffer.MemoryCopy
+ (
+ (void*)cmdList.IdxBuffer.Data,
+ idxDstPtr,
+ _indexData.Length,
+ cmdList.IdxBuffer.Size * sizeof(ushort)
+ );
}
vtxOffset += cmdList.VtxBuffer.Size;
@@ -250,10 +280,12 @@ private unsafe void RenderCommandLists(ImDrawDataPtr drawData)
if (_loadedTextures.Count < drawCmd.TextureId.ToInt32())
{
- throw new InvalidOperationException($"Could not find a texture with id '{drawCmd.TextureId}', please check your bindings");
+ throw new InvalidOperationException
+ ($"Could not find a texture with id '{drawCmd.TextureId}', please check your bindings");
}
- _graphicsDevice.ScissorRectangle = new Rectangle(
+ _graphicsDevice.ScissorRectangle = new Rectangle
+ (
(int)drawCmd.ClipRect.X,
(int)drawCmd.ClipRect.Y,
(int)(drawCmd.ClipRect.Z - drawCmd.ClipRect.X),
@@ -267,13 +299,14 @@ private unsafe void RenderCommandLists(ImDrawDataPtr drawData)
pass.Apply();
#pragma warning disable CS0618 // // FNA does not expose an alternative method.
- _graphicsDevice.DrawIndexedPrimitives(
- primitiveType: PrimitiveType.TriangleList,
- baseVertex: (int)drawCmd.VtxOffset + vtxOffset,
- minVertexIndex: 0,
- numVertices: cmdList.VtxBuffer.Size,
- startIndex: (int)drawCmd.IdxOffset + idxOffset,
- primitiveCount: (int)drawCmd.ElemCount / 3
+ _graphicsDevice.DrawIndexedPrimitives
+ (
+ PrimitiveType.TriangleList,
+ (int)drawCmd.VtxOffset + vtxOffset,
+ 0,
+ cmdList.VtxBuffer.Size,
+ (int)drawCmd.IdxOffset + idxOffset,
+ (int)drawCmd.ElemCount / 3
);
#pragma warning restore CS0618
}
@@ -285,4 +318,4 @@ private unsafe void RenderCommandLists(ImDrawDataPtr drawData)
}
#endregion Internals
-}
+}
\ No newline at end of file
diff --git a/CentrED/Tools/DrawTool.cs b/CentrED/Tools/DrawTool.cs
index 22675f9..4bbf0c2 100644
--- a/CentrED/Tools/DrawTool.cs
+++ b/CentrED/Tools/DrawTool.cs
@@ -6,14 +6,16 @@
namespace CentrED.Tools;
-public class DrawTool : Tool {
+public class DrawTool : Tool
+{
public override string Name => "DrawTool";
private bool _pressed;
private MapObject _focusObject;
[Flags]
- enum DrawMode {
+ enum DrawMode
+ {
ON_TOP = 0,
REPLACE = 1,
SAME_POS = 2,
@@ -22,7 +24,8 @@ enum DrawMode {
private bool _withHue;
private int _drawMode;
- internal override void DrawWindow() {
+ internal override void DrawWindow()
+ {
ImGui.SetNextWindowSize(new System.Numerics.Vector2(200, 100), ImGuiCond.FirstUseEver);
ImGui.Begin(Name, ImGuiWindowFlags.NoTitleBar);
ImGui.Checkbox("With Hue", ref _withHue);
@@ -32,71 +35,91 @@ internal override void DrawWindow() {
ImGui.End();
}
- public override void OnMouseEnter(MapObject? o) {
- if (o == null) return;
+ public override void OnMouseEnter(MapObject? o)
+ {
+ if (o == null)
+ return;
ushort tileX = o.Tile.X;
ushort tileY = o.Tile.Y;
sbyte tileZ = o.Tile.Z;
- byte height = o switch {
+ byte height = o switch
+ {
StaticObject so => TileDataLoader.Instance.StaticData[so.Tile.Id].Height,
_ => 0
};
var newId = CEDGame.UIManager._tilesWindow._selectedId;
- if (TilesWindow.IsLandTile(newId)) {
- if (o is LandObject lo) {
+ if (TilesWindow.IsLandTile(newId))
+ {
+ if (o is LandObject lo)
+ {
lo.Visible = false;
var newTile = new LandTile((ushort)newId, lo.Tile.X, lo.Tile.Y, lo.Tile.Z);
CEDGame.MapManager.GhostLandTiles.Add(new LandObject(CEDClient, newTile));
}
}
- else {
- var newZ = (DrawMode)_drawMode switch {
+ else
+ {
+ var newZ = (DrawMode)_drawMode switch
+ {
DrawMode.ON_TOP => tileZ + height,
_ => tileZ
};
- if (o is StaticObject && (DrawMode)_drawMode == DrawMode.REPLACE) {
+ if (o is StaticObject && (DrawMode)_drawMode == DrawMode.REPLACE)
+ {
o.Visible = false;
}
- var newTile = new StaticTile(
+ var newTile = new StaticTile
+ (
(ushort)(newId - ArtLoader.MAX_LAND_DATA_INDEX_COUNT),
tileX,
tileY,
(sbyte)newZ,
- (ushort)(_withHue ? CEDGame.UIManager._huesWindow.SelectedId + 1 : 0));
+ (ushort)(_withHue ? CEDGame.UIManager._huesWindow.SelectedId + 1 : 0)
+ );
CEDGame.MapManager.GhostStaticTiles.Add(new StaticObject(newTile));
}
}
- public override void OnMouseLeave(MapObject? o) {
- if (TilesWindow.IsLandTile(CEDGame.UIManager._tilesWindow._selectedId)) {
- if (o is LandObject lo) {
+ public override void OnMouseLeave(MapObject? o)
+ {
+ if (TilesWindow.IsLandTile(CEDGame.UIManager._tilesWindow._selectedId))
+ {
+ if (o is LandObject lo)
+ {
lo.Visible = true;
CEDGame.MapManager.GhostLandTiles.Clear();
}
}
- else {
+ else
+ {
if (o != null)
o.Visible = true;
CEDGame.MapManager.GhostStaticTiles.Clear();
}
}
- public override void OnMousePressed(MapObject? o) {
- if (_pressed || o == null) return;
+ public override void OnMousePressed(MapObject? o)
+ {
+ if (_pressed || o == null)
+ return;
_pressed = true;
_focusObject = o;
}
- public override void OnMouseReleased(MapObject? o) {
- if (_pressed && o == _focusObject) {
+ public override void OnMouseReleased(MapObject? o)
+ {
+ if (_pressed && o == _focusObject)
+ {
var newId = CEDGame.UIManager._tilesWindow._selectedId;
- if (TilesWindow.IsLandTile(newId) && o is LandObject lo) {
+ if (TilesWindow.IsLandTile(newId) && o is LandObject lo)
+ {
lo.LandTile.Id = (ushort)CEDGame.UIManager._tilesWindow._selectedId;
}
- else {
+ else
+ {
var newTile = CEDGame.MapManager.GhostStaticTiles[0].StaticTile;
CEDGame.MapManager.Client.Add(newTile);
}
diff --git a/CentrED/Tools/ElevateTool.cs b/CentrED/Tools/ElevateTool.cs
index 41ba0fa..204d0df 100644
--- a/CentrED/Tools/ElevateTool.cs
+++ b/CentrED/Tools/ElevateTool.cs
@@ -2,11 +2,13 @@
using ImGuiNET;
using static CentrED.Application;
-namespace CentrED.Tools;
+namespace CentrED.Tools;
-public class ElevateTool : Tool {
+public class ElevateTool : Tool
+{
[Flags]
- enum ZMode {
+ enum ZMode
+ {
INC = 0,
DEC = 1,
SET = 2,
@@ -19,57 +21,71 @@ enum ZMode {
private MapObject _focusObject;
public override string Name => "ElevateTool";
- internal override void DrawWindow() {
- ImGui.SetNextWindowSize(new System.Numerics.Vector2(200, 100), ImGuiCond.FirstUseEver );
+ internal override void DrawWindow()
+ {
+ ImGui.SetNextWindowSize(new System.Numerics.Vector2(200, 100), ImGuiCond.FirstUseEver);
ImGui.Begin(Name, ImGuiWindowFlags.NoTitleBar);
ImGui.RadioButton("Inc", ref zMode, (int)ZMode.INC);
ImGui.RadioButton("Dec", ref zMode, (int)ZMode.DEC);
ImGui.RadioButton("Set", ref zMode, (int)ZMode.SET);
-
+
ImGui.InputInt("Value", ref value);
ImGui.End();
}
-
- private sbyte NewZ(BaseTile tile) => (sbyte)((ZMode)zMode switch {
+
+ private sbyte NewZ(BaseTile tile) => (sbyte)((ZMode)zMode switch
+ {
ZMode.INC => tile.Z + value,
ZMode.DEC => tile.Z - value,
ZMode.SET => value,
_ => throw new ArgumentOutOfRangeException()
});
-
- public override void OnMouseEnter(MapObject? o) {
- if (o is StaticObject so) {
+
+ public override void OnMouseEnter(MapObject? o)
+ {
+ if (o is StaticObject so)
+ {
var tile = so.StaticTile;
so.Alpha = 0.3f;
var newTile = new StaticTile(tile.Id, tile.X, tile.Y, NewZ(tile), tile.Hue);
CEDGame.MapManager.GhostStaticTiles.Add(new StaticObject(newTile));
- } else if (o is LandObject lo) {
+ }
+ else if (o is LandObject lo)
+ {
var tile = lo.LandTile;
lo.Visible = false;
var newTile = new LandTile(tile.Id, tile.X, tile.Y, NewZ(tile));
CEDGame.MapManager.GhostLandTiles.Add(new LandObject(CEDGame.MapManager.Client, newTile));
}
}
-
- public override void OnMouseLeave(MapObject? o) {
- if (o is StaticObject so) {
+
+ public override void OnMouseLeave(MapObject? o)
+ {
+ if (o is StaticObject so)
+ {
so.Alpha = 1f;
CEDGame.MapManager.GhostStaticTiles.Clear();
- } else if (o is LandObject lo) {
+ }
+ else if (o is LandObject lo)
+ {
lo.Visible = true;
CEDGame.MapManager.GhostLandTiles.Clear();
}
}
- public override void OnMousePressed(MapObject? o) {
- if (!_pressed && o != null) {
+ public override void OnMousePressed(MapObject? o)
+ {
+ if (!_pressed && o != null)
+ {
_pressed = true;
_focusObject = o;
}
}
-
- public override void OnMouseReleased(MapObject? o) {
- if (_pressed && o == _focusObject) {
+
+ public override void OnMouseReleased(MapObject? o)
+ {
+ if (_pressed && o == _focusObject)
+ {
o.Tile.Z = NewZ(o.Tile);
}
_pressed = false;
diff --git a/CentrED/Tools/HueTool.cs b/CentrED/Tools/HueTool.cs
index f3a29b4..5abaa1e 100644
--- a/CentrED/Tools/HueTool.cs
+++ b/CentrED/Tools/HueTool.cs
@@ -3,39 +3,48 @@
namespace CentrED.Tools;
-public class HueTool : Tool {
-
+public class HueTool : Tool
+{
public override string Name => "HueTool";
-
+
private bool _pressed;
private StaticObject _focusObject;
- public override void OnActivated(MapObject? o) {
+ public override void OnActivated(MapObject? o)
+ {
CEDGame.UIManager._huesWindow.Show = true;
}
- public override void OnMouseEnter(MapObject? o) {
- if (o is StaticObject so) {
+ public override void OnMouseEnter(MapObject? o)
+ {
+ if (o is StaticObject so)
+ {
so.Hue = (ushort)CEDGame.UIManager._huesWindow.SelectedId;
}
}
-
- public override void OnMouseLeave(MapObject? o) {
- if (o is StaticObject so) {
+
+ public override void OnMouseLeave(MapObject? o)
+ {
+ if (o is StaticObject so)
+ {
so.Hue = so.StaticTile.Hue;
}
}
- public override void OnMousePressed(MapObject? o) {
- if (!_pressed && o is StaticObject so) {
+ public override void OnMousePressed(MapObject? o)
+ {
+ if (!_pressed && o is StaticObject so)
+ {
_pressed = true;
_focusObject = so;
}
}
-
- public override void OnMouseReleased(MapObject? o) {
- if (_pressed && o is StaticObject so && so == _focusObject) {
- if(CEDGame.UIManager._huesWindow.SelectedId != -1)
+
+ public override void OnMouseReleased(MapObject? o)
+ {
+ if (_pressed && o is StaticObject so && so == _focusObject)
+ {
+ if (CEDGame.UIManager._huesWindow.SelectedId != -1)
so.StaticTile.Hue = (ushort)CEDGame.UIManager._huesWindow.SelectedId;
}
_pressed = false;
diff --git a/CentrED/Tools/MoveTool.cs b/CentrED/Tools/MoveTool.cs
index 6864bab..2ad622a 100644
--- a/CentrED/Tools/MoveTool.cs
+++ b/CentrED/Tools/MoveTool.cs
@@ -4,27 +4,32 @@
namespace CentrED.Tools;
-public class MoveTool : Tool {
+public class MoveTool : Tool
+{
public override string Name => "MoveTool";
private int _xDelta;
private int _yDelta;
-
+
private bool _pressed;
private StaticObject _focusObject;
- internal override void DrawWindow() {
- ImGui.SetNextWindowSize(new System.Numerics.Vector2(200, 100), ImGuiCond.FirstUseEver );
+ internal override void DrawWindow()
+ {
+ ImGui.SetNextWindowSize(new System.Numerics.Vector2(200, 100), ImGuiCond.FirstUseEver);
ImGui.Begin(Name, ImGuiWindowFlags.NoTitleBar);
ImGui.InputInt("X", ref _xDelta);
ImGui.InputInt("Y", ref _yDelta);
ImGui.End();
}
- public override void OnMouseEnter(MapObject? o) {
- if (o is StaticObject so) {
+ public override void OnMouseEnter(MapObject? o)
+ {
+ if (o is StaticObject so)
+ {
so.Alpha = 0.3f;
- var newTile = new StaticTile(
+ var newTile = new StaticTile
+ (
so.StaticTile.Id,
(ushort)(so.StaticTile.X + _xDelta),
(ushort)(so.StaticTile.Y + _yDelta),
@@ -34,24 +39,31 @@ public override void OnMouseEnter(MapObject? o) {
CEDGame.MapManager.GhostStaticTiles.Add(new StaticObject(newTile));
}
}
-
- public override void OnMouseLeave(MapObject? o) {
- if (o is StaticObject so) {
+
+ public override void OnMouseLeave(MapObject? o)
+ {
+ if (o is StaticObject so)
+ {
so.Alpha = 1f;
CEDGame.MapManager.GhostStaticTiles.Clear();
}
}
- public override void OnMousePressed(MapObject? o) {
- if (!_pressed && o is StaticObject so) {
+ public override void OnMousePressed(MapObject? o)
+ {
+ if (!_pressed && o is StaticObject so)
+ {
_pressed = true;
_focusObject = so;
}
}
-
- public override void OnMouseReleased(MapObject? o) {
- if (_pressed && o is StaticObject so && so == _focusObject) {
- so.StaticTile.UpdatePos((ushort)(so.StaticTile.X + _xDelta), (ushort)(so.StaticTile.Y + _yDelta), so.StaticTile.Z);
+
+ public override void OnMouseReleased(MapObject? o)
+ {
+ if (_pressed && o is StaticObject so && so == _focusObject)
+ {
+ so.StaticTile.UpdatePos
+ ((ushort)(so.StaticTile.X + _xDelta), (ushort)(so.StaticTile.Y + _yDelta), so.StaticTile.Z);
}
_pressed = false;
}
diff --git a/CentrED/Tools/RemoveTool.cs b/CentrED/Tools/RemoveTool.cs
index 005a67d..57ce246 100644
--- a/CentrED/Tools/RemoveTool.cs
+++ b/CentrED/Tools/RemoveTool.cs
@@ -1,35 +1,44 @@
using CentrED.Map;
using static CentrED.Application;
-namespace CentrED.Tools;
+namespace CentrED.Tools;
-public class RemoveTool : Tool {
+public class RemoveTool : Tool
+{
public override string Name => "RemoveTool";
private bool _pressed;
private StaticObject _focusObject;
-
- public override void OnMouseEnter(MapObject? o) {
- if (o is StaticObject so) {
+
+ public override void OnMouseEnter(MapObject? o)
+ {
+ if (o is StaticObject so)
+ {
so.Alpha = 0.2f;
}
}
- public override void OnMouseLeave(MapObject? o) {
- if (o is StaticObject so) {
+ public override void OnMouseLeave(MapObject? o)
+ {
+ if (o is StaticObject so)
+ {
so.Alpha = 1.0f;
}
}
- public override void OnMousePressed(MapObject? o) {
- if (!_pressed && o is StaticObject so) {
+ public override void OnMousePressed(MapObject? o)
+ {
+ if (!_pressed && o is StaticObject so)
+ {
_pressed = true;
_focusObject = so;
}
}
-
- public override void OnMouseReleased(MapObject? o) {
- if (_pressed && o is StaticObject so && so == _focusObject) {
+
+ public override void OnMouseReleased(MapObject? o)
+ {
+ if (_pressed && o is StaticObject so && so == _focusObject)
+ {
CEDClient.Remove(_focusObject.StaticTile);
}
_pressed = false;
diff --git a/CentrED/Tools/SelectTool.cs b/CentrED/Tools/SelectTool.cs
index d236805..e0521f0 100644
--- a/CentrED/Tools/SelectTool.cs
+++ b/CentrED/Tools/SelectTool.cs
@@ -1,17 +1,19 @@
using CentrED.Map;
using static CentrED.Application;
-namespace CentrED.Tools;
-
-public class SelectTool : Tool {
+namespace CentrED.Tools;
+public class SelectTool : Tool
+{
public override string Name => "Select";
- public override void OnMousePressed(MapObject? selected) {
+ public override void OnMousePressed(MapObject? selected)
+ {
CEDGame.UIManager._infoWindow.Selected = selected;
}
- public override void OnActivated(MapObject? o) {
+ public override void OnActivated(MapObject? o)
+ {
CEDGame.UIManager._infoWindow.Show = true;
}
}
\ No newline at end of file
diff --git a/CentrED/Tools/Tool.cs b/CentrED/Tools/Tool.cs
index 1d1091d..8eccee6 100644
--- a/CentrED/Tools/Tool.cs
+++ b/CentrED/Tools/Tool.cs
@@ -1,35 +1,36 @@
using CentrED.Map;
-namespace CentrED.Tools;
+namespace CentrED.Tools;
-public abstract class Tool {
+public abstract class Tool
+{
public abstract string Name { get; }
-
- internal virtual void DrawWindow() {
-
+
+ internal virtual void DrawWindow()
+ {
}
- public virtual void OnActivated(MapObject? o) {
-
+ public virtual void OnActivated(MapObject? o)
+ {
}
- public virtual void OnDeactivated(MapObject? o) {
-
+ public virtual void OnDeactivated(MapObject? o)
+ {
}
- public virtual void OnMouseEnter(MapObject? o) {
-
+ public virtual void OnMouseEnter(MapObject? o)
+ {
}
- public virtual void OnMouseLeave(MapObject? o) {
-
+ public virtual void OnMouseLeave(MapObject? o)
+ {
}
- public virtual void OnMousePressed(MapObject? o) {
-
+ public virtual void OnMousePressed(MapObject? o)
+ {
}
- public virtual void OnMouseReleased(MapObject? o) {
-
+ public virtual void OnMouseReleased(MapObject? o)
+ {
}
}
\ No newline at end of file
diff --git a/CentrED/UI/FilePicker.cs b/CentrED/UI/FilePicker.cs
index 1c6ab22..5451382 100644
--- a/CentrED/UI/FilePicker.cs
+++ b/CentrED/UI/FilePicker.cs
@@ -4,182 +4,182 @@
using Microsoft.Xna.Framework;
using Num = System.Numerics;
-namespace CentrED.UI
+namespace CentrED.UI;
+
+public class FilePicker
{
- public class FilePicker
- {
- static readonly Dictionary