Skip to content

Commit

Permalink
Added Support for Enter Play Mode Options
Browse files Browse the repository at this point in the history
• Runtime Monitoring now works properly with Disabled Domain and Scene reloads in Enter Play Mode Options.
• ISettableValue is now deprecated.
  • Loading branch information
JohnBaracuda committed Nov 13, 2022
1 parent 46dbfe1 commit fec2949
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 98 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Thread-Dispatcher will be removed as a dependency in a future release.


## [3.4.1] - 2022-11-13

### Fixed
- Runtime Monitoring now works properly with Disabled Domain and Scene reloads in Enter Play Mode Options.

### Deprecated (Removing in [4.0.0])
- ISettableValue is now deprecated.


## [3.4.0] - 2022-10-30

### Added
Expand Down
10 changes: 5 additions & 5 deletions Runtime/Scripts/Core/Profiles/MonitorProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected MonitorProfile(

if (TryGetMetaAttribute<MFontNameAttribute>(out var fontAttribute))
{
MonitoringRegistry.Singleton.AddUsedFont(fontAttribute.FontName);
Monitor.InternalRegistry.AddUsedFont(fontAttribute.FontName);
}

if (TryGetMetaAttribute<MVisibleAttribute>(out var enabledAttribute))
Expand Down Expand Up @@ -158,7 +158,7 @@ protected MonitorProfile(
{
var readableString = MonitoredMemberType.HumanizedName();
tags.Add(readableString);
MonitoringRegistry.Singleton.AddUsedType(MonitoredMemberType);
Monitor.InternalRegistry.AddUsedType(MonitoredMemberType);
}

if (settings.FilterTags)
Expand All @@ -169,7 +169,7 @@ protected MonitorProfile(
foreach (var tag in optionsAttribute.Tags)
{
customTags.Add(tag);
MonitoringRegistry.Singleton.AddUsedTag(tag);
Monitor.InternalRegistry.AddUsedTag(tag);
tags.Add(tag);
}
}
Expand All @@ -178,7 +178,7 @@ protected MonitorProfile(
foreach (var tag in memberTags.Tags)
{
customTags.Add(tag);
MonitoringRegistry.Singleton.AddUsedTag(tag);
Monitor.InternalRegistry.AddUsedTag(tag);
tags.Add(tag);
}
}
Expand All @@ -187,7 +187,7 @@ protected MonitorProfile(
foreach (var tag in classTags.Tags)
{
customTags.Add(tag);
MonitoringRegistry.Singleton.AddUsedTag(tag);
Monitor.InternalRegistry.AddUsedTag(tag);
tags.Add(tag);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/Core/Systems/MonitoringDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Baracuda.Monitoring.Systems
{
internal sealed class MonitoringDisplay : LazySingleton<MonitoringDisplay>, IMonitoringUI
internal sealed class MonitoringDisplay : IMonitoringUI
{
#region Data

Expand Down
6 changes: 5 additions & 1 deletion Runtime/Scripts/Core/Systems/MonitoringEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Baracuda.Monitoring
{
internal class MonitoringEvents : LazySingleton<MonitoringEvents>, IMonitoringEvents
internal class MonitoringEvents : IMonitoringEvents
{
/// <summary>
/// Event is invoked when profiling process for the current system has been completed.
Expand Down Expand Up @@ -59,7 +59,9 @@ internal void RaiseMonitorHandleDisposed(IMonitorHandle handle)

#pragma warning disable CS0612
[Obsolete]
#pragma warning disable CS0618
public event ProfilingCompletedListener __ProfilingCompleted
#pragma warning restore CS0618
{
add
{
Expand Down Expand Up @@ -90,7 +92,9 @@ public event ProfilingCompletedListener __ProfilingCompleted
}

[Obsolete]
#pragma warning disable CS0618
private ProfilingCompletedListener __completed;
#pragma warning restore CS0618
#pragma warning restore CS0612

#endregion
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/Core/Systems/MonitoringProfiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async Task<bool> ProfileAsync()
ProfileInternalAsync(Dispatcher.RuntimeToken).Wait(Dispatcher.RuntimeToken);
}

MonitoringRegistry.Singleton.RegisterProfiles(_instanceProfiles, _staticProfiles);
Monitor.InternalRegistry.RegisterProfiles(_instanceProfiles, _staticProfiles);
return true;
}
catch (OperationCanceledException oce)
Expand Down
29 changes: 25 additions & 4 deletions Runtime/Scripts/Core/Systems/MonitoringRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Baracuda.Monitoring
{
#pragma warning disable CS0067

internal class MonitoringRegistry : LazySingleton<MonitoringRegistry>, IMonitoringRegistry
internal class MonitoringRegistry : IMonitoringRegistry
{
#region Data

Expand All @@ -35,6 +35,7 @@ internal class MonitoringRegistry : LazySingleton<MonitoringRegistry>, IMonitori

#endregion


#region Public

/// <summary>
Expand Down Expand Up @@ -94,6 +95,7 @@ public IMonitorHandle[] GetMonitorHandlesForTarget<T>(T target) where T : class

#endregion


#region Internal

internal void AddUsedTag(string tag)
Expand Down Expand Up @@ -140,11 +142,12 @@ internal void RegisterProfiles(Dictionary<Type, List<MonitorProfile>> instancePr
_staticProfiles = staticProfiles;
CreateInitialInstanceMonitorHandles();
CreateStaticMonitorHandles();
MonitoringEvents.Singleton.RaiseProfilingCompleted(_staticMonitorHandles, _instanceMonitorHandles);
Monitor.InternalEvents.RaiseProfilingCompleted(_staticMonitorHandles, _instanceMonitorHandles);
}

#endregion


#region Instance Monitor Handles

private void CreateInitialInstanceMonitorHandles()
Expand Down Expand Up @@ -187,7 +190,7 @@ private void CreateInstanceMonitorHandles(object target, Type type)
units.Add(unit);
_instanceMonitorHandles.Add(unit);
_monitorHandles.Add(unit);
MonitoringEvents.Singleton.RaiseMonitorHandleCreated(unit);
Monitor.InternalEvents.RaiseMonitorHandleCreated(unit);
}
}

Expand All @@ -214,14 +217,15 @@ private void DestroyMonitorHandleForTarget(object target)
unit.Dispose();
_instanceMonitorHandles.Remove(unit);
_monitorHandles.Remove(unit);
MonitoringEvents.Singleton.RaiseMonitorHandleDisposed(unit);
Monitor.InternalEvents.RaiseMonitorHandleDisposed(unit);
}

_activeInstanceHandles.Remove(target);
}

#endregion


#region Static Monitor Handles

private void CreateStaticMonitorHandles()
Expand All @@ -240,5 +244,22 @@ private void CreateStaticMonitorHandle(MonitorProfile staticProfile)
}

#endregion


#region Ctor

internal MonitoringRegistry(MonitoringRegistry old)
{
if (old == null)
{
return;
}
foreach (var target in old._registeredTargets)
{
_registeredTargets.AddUnique(target);
}
}

#endregion
}
}
3 changes: 1 addition & 2 deletions Runtime/Scripts/Core/Systems/MonitoringTicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Baracuda.Monitoring.Systems
{
internal class MonitoringTicker
internal class MonitoringTicker : MonitoredObject
{
public bool ValidationTickEnabled { get; set; } = true;

Expand All @@ -25,7 +25,6 @@ internal class MonitoringTicker
internal MonitoringTicker()
{
Monitor.Events.ProfilingCompleted += MonitoringEventsOnProfilingCompleted;
Monitor.StartMonitoring(this);
}

private void MonitoringEventsOnProfilingCompleted(IReadOnlyList<IMonitorHandle> staticUnits, IReadOnlyList<IMonitorHandle> instanceUnits)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ private const BindingFlags INSTANCE_FLAGS
* Setup
*/



internal ValueProcessorFactory()
{
var settings = Monitor.Settings;
Expand Down
13 changes: 0 additions & 13 deletions Runtime/Scripts/Core/Types/LazySingleton.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Runtime/Scripts/Core/Types/LazySingleton.cs.meta

This file was deleted.

19 changes: 1 addition & 18 deletions Runtime/Scripts/Core/Units/ValueHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Baracuda.Monitoring.Units
/// </summary>
/// <typeparam name="TTarget"></typeparam>
/// <typeparam name="TValue"></typeparam>
internal abstract class ValueHandle<TTarget, TValue> : MonitorHandle, ISettableValue<TValue>, IGettableValue<TValue> where TTarget : class
internal abstract class ValueHandle<TTarget, TValue> : MonitorHandle, IGettableValue<TValue> where TTarget : class
{
#region Fields

Expand Down Expand Up @@ -207,23 +207,6 @@ public void SetValue(TValue value)
RaiseValueChanged(state);
}

public void SetValue(object value)
{
_setValue?.Invoke(_target, (TValue) value);
_lastValue = (TValue) value;
var state = GetState();
RaiseValueChanged(state);
}

public void SetValueStruct<TStruct>(TStruct value) where TStruct : struct
{
var converted = value.ConvertFast<TStruct, TValue>();
_setValue?.Invoke(_target, converted);
_lastValue = converted;
var state = GetState();
RaiseValueChanged(state);
}

#endregion

//--------------------------------------------------------------------------------------------------------------
Expand Down
23 changes: 8 additions & 15 deletions Runtime/Scripts/Interfaces/ISettableValue.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
// Copyright (c) 2022 Jonathan Lang

using System;

namespace Baracuda.Monitoring
{
/// <summary>
/// Interface is not yet in use.
/// </summary>
[Obsolete("This API will be removed in 4.0.0")]
public interface ISettableValue<in TValue> : ISettableValue
{
/// <summary>
/// Interface is not yet in use.
/// </summary>
[Obsolete("This API will be removed in 4.0.0")]
void SetValue(TValue value);
}

/// <summary>
/// Interface is not yet in use.
/// </summary>
[Obsolete("This API will be removed in 4.0.0")]
public interface ISettableValue
{
/// <summary>
/// Interface is not yet in use.
/// </summary>

[Obsolete("This API will be removed in 4.0.0")]
void SetValue(object value);

/// <summary>
/// Interface is not yet in use.
/// </summary>
[Obsolete("This API will be removed in 4.0.0")]
void SetValueStruct<TStruct>(TStruct value) where TStruct : struct;
}
}
24 changes: 13 additions & 11 deletions Runtime/Scripts/Modules/ConsoleMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class ConsoleMonitor : MonitorModuleBase
private static int messageCacheSize = 10;

private static readonly char[] trimValues = {'\r', '\n'};
private static readonly Color errorColor = new Color(1f, 0.5f, 0.52f);
private static readonly Color logColor = new Color(0.8f, 0.75f, 1f);
private static readonly Color warningColor = new Color(1f, 0.96f, 0.56f);
private static readonly Color stackTraceColor = new Color(0.65f, 0.7f, 0.75f);
private static Color ErrorColor => new Color(1f, 0.5f, 0.52f);
private static Color LogColor => new Color(0.8f, 0.75f, 1f);
private static Color WarningColor => new Color(1f, 0.96f, 0.56f);
private static Color StackTraceColor => new Color(0.65f, 0.7f, 0.75f);

private static event Action UpdateDisplayedLogs;

Expand Down Expand Up @@ -121,6 +121,8 @@ static ConsoleMonitor()
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void Setup()
{
messageLogCache.Clear();
lastLogStacktrace = null;
Application.logMessageReceivedThreaded -= OnLogMessageReceived;
Application.logMessageReceivedThreaded += OnLogMessageReceived;
}
Expand Down Expand Up @@ -169,7 +171,7 @@ private string StacktraceProcessor(string stacktrace)
if (truncateStacktrace && stacktrace.Length > maxStacktraceLenght)
{
sb.Append("<color=#");
sb.Append(ColorUtility.ToHtmlStringRGB(stackTraceColor));
sb.Append(ColorUtility.ToHtmlStringRGB(StackTraceColor));
sb.Append('>');
sb.Append(stacktrace.Substring(0, maxStacktraceLenght));
sb.Append("</color>");
Expand All @@ -178,7 +180,7 @@ private string StacktraceProcessor(string stacktrace)
else
{
sb.Append("<color=#");
sb.Append(ColorUtility.ToHtmlStringRGB(stackTraceColor));
sb.Append(ColorUtility.ToHtmlStringRGB(StackTraceColor));
sb.Append('>');
sb.Append(stacktrace);
sb.Append("</color>");
Expand All @@ -198,15 +200,15 @@ private static Color GetColor(LogType logType)
switch (logType)
{
case LogType.Log:
return logColor;
return LogColor;
case LogType.Error:
return errorColor;
return ErrorColor;
case LogType.Assert:
return warningColor;
return WarningColor;
case LogType.Warning:
return warningColor;
return WarningColor;
case LogType.Exception:
return errorColor;
return ErrorColor;
default:
throw new ArgumentOutOfRangeException(nameof(logType), logType, null);
}
Expand Down
Loading

0 comments on commit fec2949

Please sign in to comment.