Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions Intersect (Core)/ColorF.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace Intersect;


public partial class ColorF
public partial class ColorF : IEquatable<ColorF>
{
private const float Tolerance = 1.0f / 256.0f;

public ColorF()
{
Expand Down Expand Up @@ -32,25 +33,25 @@ public ColorF(float r, float g, float b)

public float B { get; set; }

public static ColorF White => new ColorF(255, 255, 255, 255);
public static ColorF White => new(255, 255, 255, 255);

public static ColorF Black => new ColorF(255, 0, 0, 0);
public static ColorF Black => new(255, 0, 0, 0);

public static ColorF Transparent => new ColorF(0, 0, 0, 0);
public static ColorF Transparent => new(0, 0, 0, 0);

public static ColorF Red => new ColorF(255, 255, 0, 0);
public static ColorF Red => new(255, 255, 0, 0);

public static ColorF Green => new ColorF(255, 0, 255, 0);
public static ColorF Green => new(255, 0, 255, 0);

public static ColorF Blue => new ColorF(255, 0, 0, 255);
public static ColorF Blue => new(255, 0, 0, 255);

public static ColorF Yellow => new ColorF(255, 255, 255, 0);
public static ColorF Yellow => new(255, 255, 255, 0);

public static ColorF LightCoral => new ColorF(255, 240, 128, 128);
public static ColorF LightCoral => new(255, 240, 128, 128);

public static ColorF ForestGreen => new ColorF(255, 34, 139, 34);
public static ColorF ForestGreen => new(255, 34, 139, 34);

public static ColorF Magenta => new ColorF(255, 255, 0, 255);
public static ColorF Magenta => new(255, 255, 0, 255);

public byte GetHue()
{
Expand All @@ -62,4 +63,8 @@ public static ColorF FromArgb(float a, float r, float g, float b)
return new ColorF(a, r, g, b);
}

public override bool Equals(object other) => other is ColorF color && Equals(color);

public bool Equals(ColorF other) => Math.Abs(R - other.R) < Tolerance && Math.Abs(G - other.G) < Tolerance &&
Math.Abs(B - other.B) < Tolerance && Math.Abs(A - other.A) < Tolerance;
}
81 changes: 51 additions & 30 deletions Intersect.Client.Core/Core/Graphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static FloatRect CurrentView
Renderer?.SetView(_currentView);
}
}

public static FloatRect WorldViewport => new(CurrentView.Position, CurrentView.Size / (Globals.Database?.WorldZoom ?? 1));

public static GameShader? DefaultShader;
Expand Down Expand Up @@ -123,13 +123,15 @@ public static GameFont FindFont(string font)
{
var size = 8;

if (font.IndexOf(',') > -1)
if (font.IndexOf(',') < 0)
{
var parts = font.Split(',');
font = parts[0];
_ = int.TryParse(parts[1], out size);
return sContentManager.GetFont(font, size);
}

var parts = font.Split(',');
font = parts[0];
_ = int.TryParse(parts[1], out size);

return sContentManager.GetFont(font, size);
}

Expand All @@ -147,14 +149,16 @@ public static void InitInGame()

public static void DrawIntro()
{
var imageTex = sContentManager.GetTexture(
Framework.Content.TextureType.Image, ClientConfiguration.Instance.IntroImages[Globals.IntroIndex]
);

if (imageTex != null)
if (!sContentManager.TryGetTexture(
TextureType.Image,
ClientConfiguration.Instance.IntroImages[Globals.IntroIndex],
out var texture
))
{
DrawFullScreenTextureFitMinimum(imageTex);
return;
}

DrawFullScreenTextureFitMinimum(texture);
}

private static void DrawMenu()
Expand Down Expand Up @@ -609,8 +613,7 @@ public static void Render(TimeSpan deltaTime, TimeSpan _)

private static void DrawMap(Guid mapId, int layer = 0)
{
var map = MapInstance.Get(mapId);
if (map == null)
if (!MapInstance.TryGet(mapId, out var map))
{
return;
}
Expand All @@ -631,18 +634,24 @@ private static void DrawMap(Guid mapId, int layer = 0)

private static void DrawMapPanorama(Guid mapId)
{
var map = MapInstance.Get(mapId);
if (map != null)
if (!MapInstance.TryGet(mapId, out var map))
{
if (!new FloatRect(
map.GetX(), map.GetY(), Options.TileWidth * Options.MapWidth, Options.TileHeight * Options.MapHeight
).IntersectsWith(WorldViewport))
{
return;
}
return;
}

var mapBounds = new FloatRect(
map.GetX(),
map.GetY(),
Options.TileWidth * Options.MapWidth,
Options.TileHeight * Options.MapHeight
);

map.DrawPanorama();
if (!mapBounds.IntersectsWith(WorldViewport))
{
return;
}

map.DrawPanorama();
}

public static void DrawOverlay()
Expand All @@ -652,8 +661,7 @@ public static void DrawOverlay()
return;
}

var map = MapInstance.Get(Globals.Me?.MapId ?? Guid.Empty);
if (map != null)
if (MapInstance.TryGet(Globals.Me?.MapId ?? default, out var map))
{
float ecTime = Timing.Global.MillisecondsUtc - sOverlayUpdate;

Expand Down Expand Up @@ -1027,14 +1035,28 @@ private static void ClearDarknessTexture()

private static void GenerateLightMap()
{
// If we're not allowed to draw lighting, exit out.
if (!Globals.Database.EnableLighting || Renderer == default || Globals.Me == default)
if (Renderer == default)
{
return;
}

if (sDarknessTexture == default)
{
return;
}

var mapId = Globals.Me?.MapId ?? default;
if (mapId == default)
{
return;
}

if (!Globals.Database.EnableLighting)
{
return;
}

var map = MapInstance.Get(Globals.Me.MapId);
if (map == null || sDarknessTexture == null)
if (!MapInstance.TryGet(mapId, out var map))
{
return;
}
Expand Down Expand Up @@ -1159,8 +1181,7 @@ public static void UpdatePlayerLight()
}

//Draw Light Around Player
var map = MapInstance.Get(Globals.Me.MapId);
if (map != null)
if (MapInstance.TryGet(Globals.Me.MapId, out var map))
{
float ecTime = Timing.Global.MillisecondsUtc - sLightUpdate;
var valChange = 255 * ecTime / 2000f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public partial class MonoContentManager : GameContentManager

public MonoContentManager()
{
Init(this);

var rootPath = Path.GetFullPath(ClientConfiguration.ResourcesDirectory);

if (!Directory.Exists(rootPath))
Expand Down Expand Up @@ -288,7 +286,7 @@ public override void LoadSounds()
}
}
}

}

public override void LoadMusic()
Expand Down
73 changes: 40 additions & 33 deletions Intersect.Client.Framework/File Management/GameContentManager.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Intersect.Async;
using Intersect.Client.Framework.Audio;
using Intersect.Client.Framework.Content;
Expand Down Expand Up @@ -26,37 +27,43 @@ public enum UI
Debug,
}

public static GameContentManager Current;
public static GameContentManager Current { get; private set; }

protected Dictionary<string, IAsset> mAnimationDict = new Dictionary<string, IAsset>();
protected readonly Dictionary<string, IAsset> mAnimationDict = [];

protected Dictionary<string, IAsset> mEntityDict = new Dictionary<string, IAsset>();
protected readonly Dictionary<string, IAsset> mEntityDict = [];

protected Dictionary<string, IAsset> mFaceDict = new Dictionary<string, IAsset>();
protected readonly Dictionary<string, IAsset> mFaceDict = [];

protected Dictionary<string, IAsset> mFogDict = new Dictionary<string, IAsset>();
protected readonly Dictionary<string, IAsset> mFogDict = [];

protected List<GameFont> mFontDict = new List<GameFont>();
protected readonly List<GameFont> mFontDict = [];

protected Dictionary<string, IAsset> mGuiDict = new Dictionary<string, IAsset>();
protected readonly Dictionary<string, IAsset> mGuiDict = [];

protected Dictionary<string, IAsset> mImageDict = new Dictionary<string, IAsset>();
protected readonly Dictionary<string, IAsset> mImageDict = [];

protected Dictionary<string, IAsset> mItemDict = new Dictionary<string, IAsset>();
protected readonly Dictionary<string, IAsset> mItemDict = [];

protected Dictionary<string, IAsset> mMiscDict = new Dictionary<string, IAsset>();
protected readonly Dictionary<string, IAsset> mMiscDict = [];

protected Dictionary<string, IAsset> mMusicDict = new Dictionary<string, IAsset>();
protected readonly Dictionary<string, IAsset> mMusicDict = [];

protected Dictionary<string, IAsset> mPaperdollDict = new Dictionary<string, IAsset>();
protected readonly Dictionary<string, IAsset> mPaperdollDict = [];

protected Dictionary<string, IAsset> mResourceDict = new Dictionary<string, IAsset>();
protected readonly Dictionary<string, IAsset> mResourceDict = [];

protected Dictionary<string, GameShader> mShaderDict = new Dictionary<string, GameShader>();
protected readonly Dictionary<string, GameShader> mShaderDict = [];

protected Dictionary<string, IAsset> mSoundDict = new Dictionary<string, IAsset>();
protected readonly Dictionary<string, IAsset> mSoundDict = [];

protected Dictionary<KeyValuePair<UI, string>, string> mUiDict = new Dictionary<KeyValuePair<UI, string>, string>();
protected readonly Dictionary<KeyValuePair<UI, string>, string> mUiDict = [];

protected readonly Dictionary<string, IAsset> mSpellDict = [];

protected readonly Dictionary<string, IAsset> mTexturePackDict = [];

protected readonly Dictionary<string, IAsset> mTilesetDict = [];

/// <summary>
/// Contains all indexed files and their caches from sound pack files.
Expand All @@ -68,20 +75,13 @@ public enum UI
/// </summary>
public AssetPacker MusicPacks { get; set; }

protected Dictionary<string, IAsset> mSpellDict = new Dictionary<string, IAsset>();

protected Dictionary<string, IAsset> mTexturePackDict = new Dictionary<string, IAsset>();

//Game Content
protected Dictionary<string, IAsset> mTilesetDict = new Dictionary<string, IAsset>();

public bool TilesetsLoaded = false;

public ContentWatcher ContentWatcher { get; protected set; }

public void Init(GameContentManager manager)
protected GameContentManager()
{
Current = manager;
Current = this;
}

//Content Loading
Expand Down Expand Up @@ -199,8 +199,14 @@ public string[] GetTextureNames(TextureType type)
return null;
}

public bool TryGetTexture(TextureType textureType, string textureName, [NotNullWhen(true)] out GameTexture? texture)
{
texture = GetTexture(textureType, textureName);
return texture != default;
}

//Content Getters
public virtual GameTexture GetTexture(TextureType type, string name)
public virtual GameTexture? GetTexture(TextureType type, string name)
{
if (string.IsNullOrEmpty(name))
{
Expand Down Expand Up @@ -282,19 +288,20 @@ public virtual GameTexture GetTexture(TextureType type, string name)
return textureDict.TryGetValue(name.ToLower(), out var asset) ? asset as GameTexture : default;
}

public virtual GameShader GetShader(string name)
public bool TryGetShader(string shaderName, [NotNullWhen(true)] out GameShader? shader)
{
if (string.IsNullOrEmpty(name))
{
return null;
}
shader = GetShader(shaderName);
return shader != default;
}

if (mShaderDict == null)
public virtual GameShader? GetShader(string name)
{
if (string.IsNullOrEmpty(name))
{
return null;
}

return mShaderDict.TryGetValue(name.ToLower(), out var effect) ? effect : null;
return mShaderDict?.GetValueOrDefault(name.ToLower());
}

public virtual GameFont GetFont(string name, int size)
Expand Down
Loading