Skip to content

Commit

Permalink
Add a performance warning when OpenDream is compiled in Debug (#1487)
Browse files Browse the repository at this point in the history
* Add a performance warning when OD was compiled in Debug

* Add a similar warning to the compiler

* Some code formatting fixes
Bring `OpenDreamClient.States` in line with the rest of the codebase
  • Loading branch information
wixoaGit authored Oct 14, 2023
1 parent 09fbc7a commit d75c0b5
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 284 deletions.
6 changes: 5 additions & 1 deletion DMCompiler/DMCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public static bool Compile(DMCompilerSettings settings) {

_compileStartTime = DateTime.Now;

#if DEBUG
ForcedWarning("This compiler was compiled in the Debug .NET configuration. This will impact compile speed.");
#endif

if (settings.SuppressUnimplementedWarnings) {
ForcedWarning("Unimplemented proc & var warnings are currently suppressed");
}
Expand Down Expand Up @@ -83,7 +87,7 @@ public static bool Compile(DMCompilerSettings settings) {

public static void AddResourceDirectory(string dir) {
dir = dir.Replace('\\', Path.DirectorySeparatorChar);

_resourceDirectories.Add(dir);
}

Expand Down
11 changes: 3 additions & 8 deletions DMCompiler/Program.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using OpenDreamShared.Compiler;
using Robust.Shared.Utility;

namespace DMCompiler {

struct Argument {
internal struct Argument {
/// <summary> The text we found that's in the '--whatever' format. May be null if no such text was present.</summary>
public string? Name;
/// <summary> The value, either set in a '--whatever=whoever' format or just left by itself anonymously. May be null.</summary>
public string? Value;
}



class Program {
static void Main(string[] args) {
internal static class Program {
private static void Main(string[] args) {
if (!TryParseArguments(args, out DMCompilerSettings settings)) {
Environment.Exit(1);
return;
Expand Down
44 changes: 20 additions & 24 deletions OpenDreamClient/States/Connecting/ConnectingControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,33 @@
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;

namespace OpenDreamClient.States.Connecting
{
[GenerateTypedNameReferences]
public sealed partial class ConnectingControl : Control
{
public ConnectingControl(IResourceCache resCache, IConfigurationManager configMan)
{
namespace OpenDreamClient.States.Connecting;

RobustXamlLoader.Load(this);
[GenerateTypedNameReferences]
public sealed partial class ConnectingControl : Control {
public ConnectingControl(IResourceCache resCache, IConfigurationManager configMan) {
RobustXamlLoader.Load(this);

Panel.PanelOverride = new StyleBoxFlat(Color.Black);
Panel.PanelOverride = new StyleBoxFlat(Color.Black);

ConnectingLabel.FontOverride = new VectorFont(resCache.GetResource<FontResource>("/Fonts/NotoSans-Regular.ttf"), 24);
WIPLabel.FontOverride = new VectorFont(resCache.GetResource<FontResource>("/Fonts/NotoSans-Bold.ttf"), 32);
ConnectingLabel.FontOverride = new VectorFont(resCache.GetResource<FontResource>("/Fonts/NotoSans-Regular.ttf"), 24);
WIPLabel.FontOverride = new VectorFont(resCache.GetResource<FontResource>("/Fonts/NotoSans-Bold.ttf"), 32);

LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide);
LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide);

LayoutContainer.SetAnchorPreset(VBox, LayoutContainer.LayoutPreset.Center);
LayoutContainer.SetGrowHorizontal(VBox, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetGrowVertical(VBox, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetAnchorPreset(VBox, LayoutContainer.LayoutPreset.Center);
LayoutContainer.SetGrowHorizontal(VBox, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetGrowVertical(VBox, LayoutContainer.GrowDirection.Both);

LayoutContainer.SetAnchorPreset(ConnectingLabel, LayoutContainer.LayoutPreset.Center);
LayoutContainer.SetGrowHorizontal(ConnectingLabel, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetGrowVertical(ConnectingLabel, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetAnchorPreset(ConnectingLabel, LayoutContainer.LayoutPreset.Center);
LayoutContainer.SetGrowHorizontal(ConnectingLabel, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetGrowVertical(ConnectingLabel, LayoutContainer.GrowDirection.Both);

LayoutContainer.SetAnchorPreset(WIP, LayoutContainer.LayoutPreset.VerticalCenterWide);
LayoutContainer.SetGrowHorizontal(WIP, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetGrowVertical(WIP, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetAnchorPreset(WIP, LayoutContainer.LayoutPreset.VerticalCenterWide);
LayoutContainer.SetGrowHorizontal(WIP, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetGrowVertical(WIP, LayoutContainer.GrowDirection.Both);

var logoTexture = resCache.GetResource<TextureResource>("/OpenDream/Logo/logo.png");
Logo.Texture = logoTexture;
}
var logoTexture = resCache.GetResource<TextureResource>("/OpenDream/Logo/logo.png");
Logo.Texture = logoTexture;
}
}
30 changes: 13 additions & 17 deletions OpenDreamClient/States/Connecting/ConnectingState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@
using Robust.Client.UserInterface;
using Robust.Shared.Configuration;

namespace OpenDreamClient.States.Connecting
{
public sealed class ConnectingState : State
{
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
namespace OpenDreamClient.States.Connecting;

private ConnectingControl _connectingControl = default!;
public sealed class ConnectingState : State {
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;

protected override void Startup()
{
_connectingControl = new ConnectingControl(_resourceCache, _configurationManager);
_userInterfaceManager.StateRoot.AddChild(_connectingControl);
}
private ConnectingControl _connectingControl = default!;

protected override void Shutdown()
{
_connectingControl.Dispose();
}
protected override void Startup() {
_connectingControl = new ConnectingControl(_resourceCache, _configurationManager);
_userInterfaceManager.StateRoot.AddChild(_connectingControl);
}

protected override void Shutdown() {
_connectingControl.Dispose();
}
}
74 changes: 34 additions & 40 deletions OpenDreamClient/States/DreamUserInterfaceStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,45 @@
using Robust.Client;
using Robust.Client.State;

namespace OpenDreamClient.States
{
/// <summary>
/// Handles changing the UI state depending on connection status.
/// </summary>
[UsedImplicitly]
public sealed class DreamUserInterfaceStateManager
{
[Dependency] private readonly IGameController _gameController = default!;
[Dependency] private readonly IBaseClient _client = default!;
[Dependency] private readonly IStateManager _stateManager = default!;
namespace OpenDreamClient.States;

public void Initialize()
{
_client.RunLevelChanged += ((_, args) =>
{
switch (args.NewLevel)
{
case ClientRunLevel.InGame:
case ClientRunLevel.Connected:
case ClientRunLevel.SinglePlayerGame:
_stateManager.RequestStateChange<InGameState>();
break;

case ClientRunLevel.Initialize when args.OldLevel < ClientRunLevel.Connected:
_stateManager.RequestStateChange<MainMenuState>();
break;
/// <summary>
/// Handles changing the UI state depending on connection status.
/// </summary>
[UsedImplicitly]
public sealed class DreamUserInterfaceStateManager {
[Dependency] private readonly IGameController _gameController = default!;
[Dependency] private readonly IBaseClient _client = default!;
[Dependency] private readonly IStateManager _stateManager = default!;

// When we disconnect from the server:
case ClientRunLevel.Error:
case ClientRunLevel.Initialize when args.OldLevel >= ClientRunLevel.Connected:
if (_gameController.LaunchState.FromLauncher)
{
_stateManager.RequestStateChange<ConnectingState>();
break;
}
public void Initialize() {
_client.RunLevelChanged += ((_, args) => {
switch (args.NewLevel) {
case ClientRunLevel.InGame:
case ClientRunLevel.Connected:
case ClientRunLevel.SinglePlayerGame:
_stateManager.RequestStateChange<InGameState>();
break;

_stateManager.RequestStateChange<MainMenuState>();
break;
case ClientRunLevel.Initialize when args.OldLevel < ClientRunLevel.Connected:
_stateManager.RequestStateChange<MainMenuState>();
break;

case ClientRunLevel.Connecting:
// When we disconnect from the server:
case ClientRunLevel.Error:
case ClientRunLevel.Initialize when args.OldLevel >= ClientRunLevel.Connected:
if (_gameController.LaunchState.FromLauncher) {
_stateManager.RequestStateChange<ConnectingState>();
break;
}
});
}
}

_stateManager.RequestStateChange<MainMenuState>();
break;

case ClientRunLevel.Connecting:
_stateManager.RequestStateChange<ConnectingState>();
break;
}
});
}
}
16 changes: 6 additions & 10 deletions OpenDreamClient/States/InGameState.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using Robust.Client.State;

namespace OpenDreamClient.States
{
public sealed class InGameState : State
{
protected override void Startup()
{
}
namespace OpenDreamClient.States;

protected override void Shutdown()
{
}
public sealed class InGameState : State {
protected override void Startup() {
}

protected override void Shutdown() {
}
}
60 changes: 36 additions & 24 deletions OpenDreamClient/States/MainMenu/MainMenuControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,45 @@
Orientation="Vertical">
<TextureRect Name="Logo"
Stretch="KeepCentered" />
<BoxContainer Orientation="Horizontal"
SeparationOverride="4">
<Label Text="Username: " FontColorOverride="#FFFFFF"/>
<LineEdit Name="UsernameBoxProtected"
PlaceHolder="JoeGenero"
HorizontalExpand="True" />
</BoxContainer>
<Control MinSize="0 2" />
<BoxContainer Orientation="Horizontal"
SeparationOverride="4">
<Label Text="Address: " FontColorOverride="#FFFFFF"/>
<LineEdit Name="AddressBoxProtected"
PlaceHolder="127.0.0.1:25566"
HorizontalExpand="True" />
<BoxContainer Orientation="Vertical"
SetWidth="371"
HorizontalAlignment="Center">
<BoxContainer Orientation="Horizontal"
SeparationOverride="4">
<Label Text="Username: " FontColorOverride="#FFFFFF"/>
<LineEdit Name="UsernameBoxProtected"
PlaceHolder="JoeGenero"
HorizontalExpand="True" />
</BoxContainer>
<Control MinSize="0 2" />
<BoxContainer Orientation="Horizontal"
SeparationOverride="4">
<Label Text="Address: " FontColorOverride="#FFFFFF"/>
<LineEdit Name="AddressBoxProtected"
PlaceHolder="127.0.0.1:25566"
HorizontalExpand="True" />
</BoxContainer>
<Control MinSize="0 2" />
<Button Name="ConnectButtonProtected"
Text="Connect"
TextAlign="Center" />
<Control MinSize="0 2" />
<Button Name="QuitButtonProtected"
Text="Quit"
TextAlign="Center" />
</BoxContainer>
<Control MinSize="0 2" />
<Button Name="ConnectButtonProtected"
Text="Connect"
TextAlign="Center" />
<Control MinSize="0 2" />
<Button Name="QuitButtonProtected"
Text="Quit"
TextAlign="Center" />
<Control MinHeight="128"></Control>
<BoxContainer Name="WIP" Orientation="Horizontal"
<BoxContainer Name="Notices" Orientation="Vertical"
SeparationOverride="4">
<Label Name="WIPLabel" Text="Work In Progress" FontColorOverride="#FFFFFF"/>
<Label Name="WIPLabel"
Text="Work In Progress"
FontColorOverride="#FFFFFF"
HorizontalAlignment="Center"/>
<Label Name="DebugWarningLabel"
Text="OpenDream was compiled in the Debug .NET configuration. This will heavily impact performance!"
FontColorOverride="#FF1111"
HorizontalAlignment="Center"
Visible="False"/>
</BoxContainer>
</BoxContainer>

Expand Down
49 changes: 25 additions & 24 deletions OpenDreamClient/States/MainMenu/MainMenuControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,37 @@
using Robust.Shared;
using Robust.Shared.Configuration;

namespace OpenDreamClient.States.MainMenu
{
[GenerateTypedNameReferences]
public sealed partial class MainMenuControl : Control
{
public LineEdit UserNameBox => UsernameBoxProtected;
public LineEdit AddressBox => AddressBoxProtected;
public Button ConnectButton => ConnectButtonProtected;
public Button QuitButton => QuitButtonProtected;
namespace OpenDreamClient.States.MainMenu;

public MainMenuControl(IResourceCache resCache, IConfigurationManager configMan)
{
RobustXamlLoader.Load(this);
[GenerateTypedNameReferences]
public sealed partial class MainMenuControl : Control {
public LineEdit UserNameBox => UsernameBoxProtected;
public LineEdit AddressBox => AddressBoxProtected;
public Button ConnectButton => ConnectButtonProtected;
public Button QuitButton => QuitButtonProtected;

Panel.PanelOverride = new StyleBoxFlat(Color.Black);
WIPLabel.FontOverride = new VectorFont(resCache.GetResource<FontResource>("/Fonts/NotoSans-Bold.ttf"), 32);
public MainMenuControl(IResourceCache resCache, IConfigurationManager configMan) {
RobustXamlLoader.Load(this);

LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide);
Panel.PanelOverride = new StyleBoxFlat(Color.Black);
WIPLabel.FontOverride = new VectorFont(resCache.GetResource<FontResource>("/Fonts/NotoSans-Bold.ttf"), 32);

LayoutContainer.SetAnchorPreset(VBox, LayoutContainer.LayoutPreset.Center);
LayoutContainer.SetGrowHorizontal(VBox, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetGrowVertical(VBox, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide);

var logoTexture = resCache.GetResource<TextureResource>("/OpenDream/Logo/logo.png");
Logo.Texture = logoTexture;
LayoutContainer.SetAnchorPreset(VBox, LayoutContainer.LayoutPreset.Center);
LayoutContainer.SetGrowHorizontal(VBox, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetGrowVertical(VBox, LayoutContainer.GrowDirection.Both);

var currentUserName = configMan.GetCVar(CVars.PlayerName);
UserNameBox.Text = currentUserName;
var logoTexture = resCache.GetResource<TextureResource>("/OpenDream/Logo/logo.png");
Logo.Texture = logoTexture;

AddressBoxProtected.Text = "127.0.0.1:25566";
}
var currentUserName = configMan.GetCVar(CVars.PlayerName);
UserNameBox.Text = currentUserName;

AddressBoxProtected.Text = "127.0.0.1:25566";

#if DEBUG
DebugWarningLabel.Visible = true;
#endif
}
}
Loading

0 comments on commit d75c0b5

Please sign in to comment.