Merge branch 'dev'

This commit is contained in:
Mikhail 2026-01-22 17:48:41 +08:00
commit c84aa33113
5 changed files with 59 additions and 8 deletions

View File

@ -32,22 +32,23 @@ namespace DCFApixels.DebugXCore.Internal
private void OnGUI() private void OnGUI()
{ {
_pos = GUILayout.BeginScrollView(_pos, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); _pos = GUILayout.BeginScrollView(_pos, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
float tmpValue; float tmpFloat;
int tmpInt;
DebugX.GlobalTimeScale = EditorGUILayout.FloatField("TimeScale", DebugX.GlobalTimeScale); DebugX.GlobalTimeScale = EditorGUILayout.FloatField("TimeScale", DebugX.GlobalTimeScale);
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
tmpValue = EditorGUILayout.Slider(DebugX.GlobalTimeScale, 0, 2); tmpFloat = EditorGUILayout.Slider(DebugX.GlobalTimeScale, 0, 2);
if (EditorGUI.EndChangeCheck()) if (EditorGUI.EndChangeCheck())
{ {
DebugX.GlobalTimeScale = tmpValue; DebugX.GlobalTimeScale = tmpFloat;
} }
DebugX.GlobalDotSize = EditorGUILayout.FloatField("DotSize", DebugX.GlobalDotSize); DebugX.GlobalDotSize = EditorGUILayout.FloatField("DotSize", DebugX.GlobalDotSize);
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
tmpValue = EditorGUILayout.Slider(DebugX.GlobalDotSize, 0, 2); tmpFloat = EditorGUILayout.Slider(DebugX.GlobalDotSize, 0, 2);
if (EditorGUI.EndChangeCheck()) if (EditorGUI.EndChangeCheck())
{ {
DebugX.GlobalDotSize = tmpValue; DebugX.GlobalDotSize = tmpFloat;
} }
DebugX.GlobalColor = EditorGUILayout.ColorField("Color", DebugX.GlobalColor); DebugX.GlobalColor = EditorGUILayout.ColorField("Color", DebugX.GlobalColor);
@ -58,12 +59,16 @@ namespace DCFApixels.DebugXCore.Internal
DebugX.GlobalGreaterPassAlpha = EditorGUILayout.FloatField("GreaterPassAlpha", DebugX.GlobalGreaterPassAlpha); DebugX.GlobalGreaterPassAlpha = EditorGUILayout.FloatField("GreaterPassAlpha", DebugX.GlobalGreaterPassAlpha);
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
tmpValue = EditorGUILayout.Slider(DebugX.GlobalGreaterPassAlpha, 0, 1); tmpFloat = EditorGUILayout.Slider(DebugX.GlobalGreaterPassAlpha, 0, 1);
if (EditorGUI.EndChangeCheck()) if (EditorGUI.EndChangeCheck())
{ {
DebugX.GlobalGreaterPassAlpha = tmpValue; DebugX.GlobalGreaterPassAlpha = tmpFloat;
} }
DebugX.AvailablePoolMemory = EditorGUILayout.IntField("AvailablePoolMemory (kb)", DebugX.AvailablePoolMemory);
EditorGUI.BeginChangeCheck();
if (GUILayout.Button("Reset")) if (GUILayout.Button("Reset"))
{ {
DebugX.ResetGlobals(); DebugX.ResetGlobals();

View File

@ -27,6 +27,7 @@ namespace DCFApixels
private const string GLOBAL_DOT_SIZE_PREF_NAME = "DCFApixels.DebugX.DotSize"; private const string GLOBAL_DOT_SIZE_PREF_NAME = "DCFApixels.DebugX.DotSize";
private const string GLOBAL_COLOR_PREF_NAME = "DCFApixels.DebugX.Color"; private const string GLOBAL_COLOR_PREF_NAME = "DCFApixels.DebugX.Color";
private const string GLOBAL_GREATER_PASS_ALPHA_PREF_NAME = "DCFApixels.DebugX.GreaterPassAlpha"; private const string GLOBAL_GREATER_PASS_ALPHA_PREF_NAME = "DCFApixels.DebugX.GreaterPassAlpha";
private const string GLOBAL_AVAILABLE_POOL_MEMORY_PREF_NAME = "DCFApixels.DebugX.AvailablePoolMemory";
private readonly static int GlobalDotSizePropertyID = Shader.PropertyToID("_DebugX_GlobalDotSize"); private readonly static int GlobalDotSizePropertyID = Shader.PropertyToID("_DebugX_GlobalDotSize");
private readonly static int GlobalColorPropertyID = Shader.PropertyToID("_DebugX_GlobalColor"); private readonly static int GlobalColorPropertyID = Shader.PropertyToID("_DebugX_GlobalColor");

View File

@ -17,6 +17,8 @@ using UnityEngine.PlayerLoop;
using Unity.Collections.LowLevel.Unsafe; using Unity.Collections.LowLevel.Unsafe;
using DCFApixels.DebugXCore.Internal; using DCFApixels.DebugXCore.Internal;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace DCFApixels namespace DCFApixels
{ {
@ -661,6 +663,25 @@ namespace DCFApixels
} }
private class GizmosBuffer<T> : GizmosBuffer where T : IGizmo<T> private class GizmosBuffer<T> : GizmosBuffer where T : IGizmo<T>
{ {
private static int _lastAvailablePoolMemory;
private static int _bufferMaxSize;
private static readonly int _elementSize = RuntimeHelpers.IsReferenceOrContainsReferences<T>() ? sizeof(IntPtr) : Marshal.SizeOf<T>();
private static void CheckAvailablePoolMemory()
{
if(_bufferMaxSize != 0 && _lastAvailablePoolMemory == DebugX.AvailablePoolMemory)
{
return;
}
if(DebugX.AvailablePoolMemory < _elementSize * 10)
{
_bufferMaxSize = DebugX.AvailablePoolMemory * 1024 / _elementSize;
}
else
{
_bufferMaxSize = DebugX.AvailablePoolMemory / _elementSize * 1024;
}
_lastAvailablePoolMemory = DebugX.AvailablePoolMemory;
}
private class DummyRenderer : IGizmoRenderer<T> private class DummyRenderer : IGizmoRenderer<T>
{ {
public int ExecuteOrder { get { return 0; } } public int ExecuteOrder { get { return 0; } }
@ -714,17 +735,24 @@ namespace DCFApixels
[IN(LINE)] [IN(LINE)]
public void Add(T value, float time, Color color) public void Add(T value, float time, Color color)
{ {
CheckAvailablePoolMemory();
if ((_gizmos.Count + 1) >= _bufferMaxSize) { return; }
_gizmos.Add(new GizmoInternal<T>(value, time, color)); _gizmos.Add(new GizmoInternal<T>(value, time, color));
} }
[IN(LINE)] [IN(LINE)]
public void AddRange(ReadOnlySpan<T> values, float time, Color color) public void AddRange(ReadOnlySpan<T> values, float time, Color color)
{ {
CheckAvailablePoolMemory();
if ((_gizmos.Count + values.Length) >= _bufferMaxSize) { return; }
_gizmos.UpSize(_gizmos._count + values.Length); _gizmos.UpSize(_gizmos._count + values.Length);
for (int i = 0; i < values.Length; i++) for (int i = 0; i < values.Length; i++)
{ {
_gizmos.Add(new GizmoInternal<T>(values[i], time, color)); _gizmos.Add(new GizmoInternal<T>(values[i], time, color));
} }
} }
public sealed override int UpdateTimer(float deltaTime) public sealed override int UpdateTimer(float deltaTime)
{ {

View File

@ -67,6 +67,20 @@ namespace DCFApixels
#if UNITY_EDITOR #if UNITY_EDITOR
EditorPrefs.SetFloat(GLOBAL_GREATER_PASS_ALPHA_PREF_NAME, _globalGreaterPassAlphaCache); EditorPrefs.SetFloat(GLOBAL_GREATER_PASS_ALPHA_PREF_NAME, _globalGreaterPassAlphaCache);
#endif
}
}
private static int _availablePoolMemory; //KB
public static int AvailablePoolMemory
{
get { return _availablePoolMemory; }
set
{
value = Mathf.Max(0, value);
if (_availablePoolMemory == value) { return; }
_availablePoolMemory = value;
#if UNITY_EDITOR
EditorPrefs.SetInt(GLOBAL_AVAILABLE_POOL_MEMORY_PREF_NAME, value);
#endif #endif
} }
} }
@ -77,6 +91,7 @@ namespace DCFApixels
EditorPrefs.DeleteKey(GLOBAL_DOT_SIZE_PREF_NAME); EditorPrefs.DeleteKey(GLOBAL_DOT_SIZE_PREF_NAME);
EditorPrefs.DeleteKey(GLOBAL_COLOR_PREF_NAME); EditorPrefs.DeleteKey(GLOBAL_COLOR_PREF_NAME);
EditorPrefs.DeleteKey(GLOBAL_GREATER_PASS_ALPHA_PREF_NAME); EditorPrefs.DeleteKey(GLOBAL_GREATER_PASS_ALPHA_PREF_NAME);
EditorPrefs.DeleteKey(GLOBAL_AVAILABLE_POOL_MEMORY_PREF_NAME);
#endif #endif
_timeScaleCache = default; _timeScaleCache = default;
_dotSizeCache = default; _dotSizeCache = default;
@ -92,11 +107,13 @@ namespace DCFApixels
var colorCode = EditorPrefs.GetInt(GLOBAL_COLOR_PREF_NAME, -1); var colorCode = EditorPrefs.GetInt(GLOBAL_COLOR_PREF_NAME, -1);
GlobalColor = (Color)(*(Color32*)&colorCode); GlobalColor = (Color)(*(Color32*)&colorCode);
GlobalGreaterPassAlpha = EditorPrefs.GetFloat(GLOBAL_GREATER_PASS_ALPHA_PREF_NAME, 0.1f); GlobalGreaterPassAlpha = EditorPrefs.GetFloat(GLOBAL_GREATER_PASS_ALPHA_PREF_NAME, 0.1f);
AvailablePoolMemory = EditorPrefs.GetInt(GLOBAL_AVAILABLE_POOL_MEMORY_PREF_NAME, 524288);
#else #else
GlobalTimeScale = 1; GlobalTimeScale = 1;
GlobalDotSize = 1; GlobalDotSize = 1;
GlobalColor = Color.white; GlobalColor = Color.white;
GlobalGreaterPassAlpha = 0.1f; GlobalGreaterPassAlpha = 0.1f;
AvailablePoolMemory = 524288;
#endif #endif
} }
} }

View File

@ -29,7 +29,7 @@ namespace DCFApixels
_singleWarningToggle = false; _singleWarningToggle = false;
} }
#endif #endif
settings = settings.SetSize(DebugXTextSettings.DEFAULT_FONT_SIZE); settings = settings.Size(DebugXTextSettings.DEFAULT_FONT_SIZE);
} }
return h.Gizmo(new TextGizmo(position, text, settings)); return h.Gizmo(new TextGizmo(position, text, settings));
} }