Skip to content

Commit

Permalink
fix: reverting replacement of Dispose() to Destroy()
Browse files Browse the repository at this point in the history
  • Loading branch information
brmassa committed Sep 17, 2024
1 parent db2bcaf commit 3e2af96
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Prowl.Editor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private static int Run(CliOpenOptions options)
else if (Hotkeys.IsHotkeyDown("SaveScene", new() { Key = Key.S, Ctrl = true }))
EditorGuiManager.SaveScene();

Application.isPlaying = PlayMode.Current == PlayMode.Mode.Playing;
Application.IsPlaying = PlayMode.Current == PlayMode.Mode.Playing;


try
Expand Down
2 changes: 1 addition & 1 deletion Prowl.Players/Prowl.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class Program
public static int Main(string[] args)
{

Application.isPlaying = true;
Application.IsPlaying = true;
Application.DataPath = Data.FullName;


Expand Down
36 changes: 18 additions & 18 deletions Prowl.Runtime/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace Prowl.Runtime;

public static class Application
{
public static bool isRunning;
public static bool isPlaying = false;
public static bool isEditor { get; private set; }
public static bool IsRunning { get; private set; }
public static bool IsPlaying { get; set; }
public static bool IsEditor { get; private set; }

public static string? DataPath = null;

Expand All @@ -25,24 +25,24 @@ public static class Application
public static event Action Render;
public static event Action Quitting;

private static readonly TimeData AppTime = new();
private static readonly TimeData s_appTime = new();

private static readonly GraphicsBackend[] preferredWindowsBackends = // Covers Windows/UWP
private static readonly GraphicsBackend[] s_preferredWindowsBackends = // Covers Windows/UWP
[
GraphicsBackend.Vulkan,
GraphicsBackend.OpenGL,
GraphicsBackend.Direct3D11,
GraphicsBackend.OpenGLES,
];

private static readonly GraphicsBackend[] preferredUnixBackends = // Cover Unix-like (Linux, FreeBSD, OpenBSD)
private static readonly GraphicsBackend[] s_preferredUnixBackends = // Cover Unix-like (Linux, FreeBSD, OpenBSD)
[
GraphicsBackend.Vulkan,
GraphicsBackend.OpenGL,
GraphicsBackend.OpenGLES,
];

private static readonly GraphicsBackend[] preferredMacBackends = // Covers MacOS/Apple
private static readonly GraphicsBackend[] s_preferredMacBackends = // Covers macOS/Apple
[
GraphicsBackend.Metal,
GraphicsBackend.OpenGL,
Expand All @@ -53,20 +53,20 @@ public static GraphicsBackend GetBackend()
{
if (RuntimeUtils.IsWindows())
{
return preferredWindowsBackends[0];
return s_preferredWindowsBackends[0];
}
else if (RuntimeUtils.IsMac())
{
return preferredMacBackends[0];
return s_preferredMacBackends[0];
}

return preferredUnixBackends[0];
return s_preferredUnixBackends[0];
}

public static void Run(string title, int width, int height, IAssetProvider assetProvider, bool editor)
{
AssetProvider = assetProvider;
isEditor = editor;
IsEditor = editor;

Debug.Log("Initializing...");

Expand All @@ -76,10 +76,10 @@ public static void Run(string title, int width, int height, IAssetProvider asset

Screen.Closing += AppClose;

isRunning = true;
isPlaying = true; // Base application is not the editor, isplaying is always true
IsRunning = true;
IsPlaying = true; // Base application is not the editor, IsPlaying is always true

Screen.Start($"{title} - {GetBackend()}", new Vector2Int(width, height), new Vector2Int(100, 100), WindowState.Normal);
Screen.Start($"{title} - {GetBackend()}", new Vector2Int(width, height), new Vector2Int(100, 100));
}

static void AppInitialize()
Expand All @@ -88,7 +88,7 @@ static void AppInitialize()
SceneManager.Initialize();
AudioSystem.Initialize();

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

AssemblyManager.Initialize();

Expand All @@ -103,9 +103,9 @@ static void AppUpdate()
{
AudioSystem.UpdatePool();

AppTime.Update();
s_appTime.Update();

Time.TimeStack.Push(AppTime);
Time.TimeStack.Push(s_appTime);

Update.Invoke();
Render.Invoke();
Expand All @@ -120,7 +120,7 @@ static void AppUpdate()

static void AppClose()
{
isRunning = false;
IsRunning = false;
Quitting.Invoke();
Graphics.Dispose();
Physics.Dispose();
Expand Down
5 changes: 3 additions & 2 deletions Prowl.Runtime/AssetRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public AssetRef(Guid id)
/// the specified alias.
/// </summary>
/// <param name="id"></param>
/// <param name="fileId"></param>
public AssetRef(Guid id, ushort fileId)
{
instance = null;
Expand All @@ -152,8 +153,8 @@ public AssetRef(Guid id, ushort fileId)
public AssetRef(T? res)
{
instance = res;
assetID = res != null ? res.AssetID : Guid.Empty;
fileID = res != null ? res.FileID : (ushort)0;
assetID = res?.AssetID ?? Guid.Empty;
fileID = res?.FileID ?? 0;
}

public object? GetInstance()
Expand Down
10 changes: 5 additions & 5 deletions Prowl.Runtime/Audio/AudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public static class AudioSystem

private static readonly List<ActiveAudio> _active = [];
private static readonly List<ActiveAudio> _pool = [];
private static AudioListener _listener;
private static AudioListener? s_listener;

public static AudioListener Listener => _listener;
public static AudioListener Listener => s_listener;

public static AudioEngine Engine => _engine;

Expand Down Expand Up @@ -75,17 +75,17 @@ public static void UpdatePool()

public static void RegisterListener(AudioListener audioListener)
{
if (_listener != null)
if (s_listener != null)
{
Debug.LogWarning("Audio listener already registered, only the first in the scene will work as intended! Please destroy that one first before instantiating a new Listener.");
return;
}
_listener = audioListener;
s_listener = audioListener;
}

public static void UnregisterListener(AudioListener audioListener)
{
_listener = null;
s_listener = null;
}

public static AudioBuffer GetAudioBuffer(AudioClip clip)
Expand Down
48 changes: 24 additions & 24 deletions Prowl.Runtime/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ public struct Color

public float grayscale => 0.299f * r + 0.587f * g + 0.114f * b;

public static Color black => new Color(0f, 0f, 0f, 1f);
public static Color black => new(0f, 0f, 0f, 1f);

public static Color blue => new Color(0f, 0f, 1f, 1f);
public static Color blue => new(0f, 0f, 1f, 1f);

public static Color clear => new Color(0f, 0f, 0f, 0f);
public static Color clear => new(0f, 0f, 0f, 0f);

public static Color cyan => new Color(0f, 1f, 1f, 1f);
public static Color cyan => new(0f, 1f, 1f, 1f);

public static Color gray => new Color(0.5f, 0.5f, 0.5f, 1f);
public static Color gray => new(0.5f, 0.5f, 0.5f, 1f);

public static Color green => new Color(0f, 1f, 0f, 1f);
public static Color green => new(0f, 1f, 0f, 1f);

public static Color grey => new Color(0.5f, 0.5f, 0.5f, 1f);
public static Color grey => new(0.5f, 0.5f, 0.5f, 1f);

public static Color magenta => new Color(1f, 0f, 1f, 1f);
public static Color magenta => new(1f, 0f, 1f, 1f);

public static Color red => new Color(1f, 0f, 0f, 1f);
public static Color red => new(1f, 0f, 0f, 1f);

public static Color white => new Color(1f, 1f, 1f, 1f);
public static Color white => new(1f, 1f, 1f, 1f);

public static Color yellow => new Color(1f, 0.9215f, 0.0156f, 1f);
public static Color yellow => new(1f, 0.9215f, 0.0156f, 1f);

public float this[int index]
{
Expand Down Expand Up @@ -121,7 +121,7 @@ public static Color FromHSV(float h, float s, float v, float a = 1)
float t = v * (1 - s * (1 - f));

// build our rgb color
Color color = new Color(0, 0, 0, a);
Color color = new(0, 0, 0, a);

switch (i)
{
Expand Down Expand Up @@ -165,27 +165,27 @@ public static Color FromHSV(float h, float s, float v, float a = 1)
return color;
}

public static Color operator +(Color a, Color b) => new Color(a.r + b.r, a.g + b.g, a.b + b.b, a.a + b.a);
public static Color operator +(Color a, Color b) => new(a.r + b.r, a.g + b.g, a.b + b.b, a.a + b.a);

public static Color operator /(Color a, float b) => new Color(a.r / b, a.g / b, a.b / b, a.a / b);
public static Color operator /(Color a, float b) => new(a.r / b, a.g / b, a.b / b, a.a / b);

public static bool operator ==(Color lhs, Color rhs) => lhs == rhs;
public static bool operator ==(Color lhs, Color rhs) => lhs.Equals(rhs);

public static implicit operator Vector4(Color c) => new Vector4(c.r, c.g, c.b, c.a);
public static implicit operator System.Numerics.Vector4(Color c) => new System.Numerics.Vector4(c.r, c.g, c.b, c.a);
public static implicit operator Vector4(Color c) => new(c.r, c.g, c.b, c.a);
public static implicit operator System.Numerics.Vector4(Color c) => new(c.r, c.g, c.b, c.a);

public static implicit operator Color(Vector4 v) => new Color((float)v.x, (float)v.y, (float)v.z, (float)v.w);
public static implicit operator Color(System.Numerics.Vector4 v) => new Color(v.X, v.Y, v.Z, v.W);
public static implicit operator Color(Vector4 v) => new((float)v.x, (float)v.y, (float)v.z, (float)v.w);
public static implicit operator Color(System.Numerics.Vector4 v) => new(v.X, v.Y, v.Z, v.W);

public static bool operator !=(Color lhs, Color rhs) => lhs != rhs;
public static bool operator !=(Color lhs, Color rhs) => !lhs.Equals(rhs);

public static Color operator *(Color a, Color b) => new Color(a.r * b.r, a.g * b.g, a.b * b.b, a.a * b.a);
public static Color operator *(Color a, Color b) => new(a.r * b.r, a.g * b.g, a.b * b.b, a.a * b.a);

public static Color operator *(Color a, float b) => new Color(a.r * b, a.g * b, a.b * b, a.a * b);
public static Color operator *(Color a, float b) => new(a.r * b, a.g * b, a.b * b, a.a * b);

public static Color operator *(float b, Color a) => new Color(a.r * b, a.g * b, a.b * b, a.a * b);
public static Color operator *(float b, Color a) => new(a.r * b, a.g * b, a.b * b, a.a * b);

public static Color operator -(Color a, Color b) => new Color(a.r - b.r, a.g - b.g, a.b - b.b, a.a - b.a);
public static Color operator -(Color a, Color b) => new(a.r - b.r, a.g - b.g, a.b - b.b, a.a - b.a);

public override bool Equals(object? other)
{
Expand Down
1 change: 1 addition & 0 deletions Prowl.Runtime/EngineObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public static EngineObject Instantiate(EngineObject obj, bool keepAssetID = fals
/// Force the object to dispose immediately
/// You are advised to not use this! Use Destroy() Instead.
/// </summary>
/// TODO: FIXME: replacing GameObject and EngineObject calls crashes the app
[Obsolete("You are advised to not use this! Use Destroy() Instead.")]
public void Dispose()
{
Expand Down
2 changes: 1 addition & 1 deletion Prowl.Runtime/GameObject/MonoBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ internal void Do(Action action)

try
{
if (Application.isPlaying || always)
if (Application.IsPlaying || always)
action();
}
catch (Exception e)
Expand Down
2 changes: 1 addition & 1 deletion Prowl.Runtime/Physics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class PhysicsSetting : ScriptableSingleton<PhysicsSetting>

public static class Physics
{
public static bool IsReady => isInitialized && Application.isPlaying;
public static bool IsReady => isInitialized && Application.IsPlaying;

public static Simulation? Sim { get; private set; }
public static BufferPool? Pool { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion Prowl.Runtime/SceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static void Update()
if (_gameObjects[i].enabledInHierarchy)
_gameObjects[i].PreUpdate();

if (Application.isPlaying)
if (Application.IsPlaying)
Physics.Update();

ForeachComponent((x) =>
Expand Down
4 changes: 2 additions & 2 deletions Prowl.Runtime/Utils/ScriptableSingleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ protected string GetFilePath(string? dataPath)
ArgumentNullException.ThrowIfNull(dataPath);

// Persistent across sessions for a single project
if (Application.isEditor == false)
if (Application.IsEditor == false)
throw new InvalidOperationException("Editor Settings are only available in the editor");
directory = Path.Combine(dataPath, "ProjectSettings", "Editor");
break;
case FilePathAttribute.Location.EditorPreference:
// Persistent across all projects
// TODO: !Application.isRunning is just a hack to allow CLI operations that do not depend on the editor
if (!Application.isRunning || Application.isEditor == false)
if (!Application.IsRunning || Application.IsEditor == false)
throw new InvalidOperationException("Preferences are only available in the editor");
directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Prowl", "Editor");
break;
Expand Down

0 comments on commit 3e2af96

Please sign in to comment.