Fix null warnings in StandardRenderSystem, remove SceneGraph module, temporarily disable nullables in TestGame.
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
using Voile.Rendering;
|
||||
using Voile.SceneGraph;
|
||||
|
||||
namespace Voile;
|
||||
|
||||
public class Circle2d : Drawable2d
|
||||
{
|
||||
public override void OnDraw(RenderSystem renderer)
|
||||
{
|
||||
renderer.DrawCircle(32f, Color.AliceBlue);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using Voile.Utils;
|
||||
using Voile.Input;
|
||||
using Voile.Systems.Particles;
|
||||
using System.Numerics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
public class TestGame : Game
|
||||
{
|
||||
@@ -12,6 +13,7 @@ public class TestGame : Game
|
||||
public override void Initialize()
|
||||
{
|
||||
InitializeDefault();
|
||||
|
||||
_particleSystem = new ParticleSystem();
|
||||
|
||||
ResourceManager.AddResourceLoaderAssociation(new ParticleEmitterSettingsResourceLoader());
|
||||
@@ -33,13 +35,13 @@ public class TestGame : Game
|
||||
|
||||
if (!ResourceManager.TryLoad("test_emitter.toml", out _emitterSettings))
|
||||
{
|
||||
|
||||
throw new Exception("Failed to load emitter settings!");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Ready()
|
||||
{
|
||||
_emitterId = _particleSystem!.CreateEmitter(Renderer.WindowSize / 2, _emitterSettings);
|
||||
_emitterId = _particleSystem.CreateEmitter(Renderer.WindowSize / 2, _emitterSettings);
|
||||
}
|
||||
|
||||
protected override void Run()
|
||||
@@ -87,8 +89,8 @@ public class TestGame : Game
|
||||
Renderer.EndBlended();
|
||||
}
|
||||
|
||||
private ParticleSystem? _particleSystem;
|
||||
[NotNull] private ParticleSystem _particleSystem;
|
||||
private int _emitterId;
|
||||
private ResourceRef<ParticleEmitterSettingsResource>? _emitterSettings;
|
||||
private ResourceRef<ParticleEmitterSettingsResource> _emitterSettings;
|
||||
private Logger _logger = new(nameof(TestGame));
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Nullable>disable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
using Voile;
|
||||
using Voile.Extensions;
|
||||
using Voile.SceneGraph;
|
||||
using Voile.Utils;
|
||||
|
||||
public class TestPlayer : RectangleShape2d
|
||||
{
|
||||
public float SprintSpeed { get; set; } = 400f;
|
||||
protected override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
Color = Color.Cyan;
|
||||
|
||||
_camera = new Camera2d()
|
||||
{
|
||||
Current = true,
|
||||
};
|
||||
|
||||
if (Layer is not null)
|
||||
{
|
||||
Layer.AddEntity(_camera);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdate(double dt)
|
||||
{
|
||||
base.OnUpdate(dt);
|
||||
|
||||
var sprinting = Input.IsActionDown("sprint");
|
||||
_speed = sprinting ? SprintSpeed : 200f;
|
||||
|
||||
var velocity = Input.GetInputDirection("left", "right", "up", "down") * _speed;
|
||||
Position += velocity * (float)dt;
|
||||
|
||||
if (_camera is not null)
|
||||
{
|
||||
_camera.Position = _camera.Position.Lerp(Position, dt * 5f);
|
||||
}
|
||||
}
|
||||
|
||||
private Logger _logger = new(nameof(TestPlayer));
|
||||
private float _speed = 200f;
|
||||
private Camera2d? _camera;
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
using System.Numerics;
|
||||
using Voile;
|
||||
using Voile.Rendering;
|
||||
using Voile.SceneGraph;
|
||||
using Voile.UI;
|
||||
using Voile.Utils;
|
||||
|
||||
public class UiLayer : Layer
|
||||
{
|
||||
protected override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
|
||||
GetResources();
|
||||
CreateUiElements();
|
||||
}
|
||||
|
||||
protected override void OnUpdate(double dt)
|
||||
{
|
||||
base.OnUpdate(dt);
|
||||
if (Scene is null) return;
|
||||
_screenContainer.UpdateRect(Vector2.Zero, Scene.Renderer.WindowSize);
|
||||
}
|
||||
|
||||
protected override void OnBeginDraw(RenderSystem renderer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnDraw(RenderSystem renderer)
|
||||
{
|
||||
_screenContainer.Render(renderer);
|
||||
}
|
||||
|
||||
protected override void OnEndDraw(RenderSystem renderer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void CreateUiElements()
|
||||
{
|
||||
if (Scene is null) return;
|
||||
|
||||
_screenContainer.UpdateRect(Vector2.Zero, Scene.Renderer.WindowSize);
|
||||
|
||||
var style = new PanelStyle()
|
||||
{
|
||||
BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 1.0f)
|
||||
};
|
||||
|
||||
_panel = new MarginPanel(style)
|
||||
{
|
||||
ExpandRatio = new Vector2(0.5f, 1f),
|
||||
AbsoluteMargin = Vector2.One * 16f
|
||||
};
|
||||
_screenContainer.AddChild(_panel);
|
||||
|
||||
var exampleText = new TextLabel()
|
||||
{
|
||||
Font = _defaultFont!,
|
||||
FontSize = 20,
|
||||
Text = "This Panel will occupy 50% of the screen.\nThis text in particular is inside a panel with an absolute margin of 16px.\nHow cool is that?"
|
||||
};
|
||||
|
||||
var contentPanel = new MarginPanel(new PanelStyle()
|
||||
{
|
||||
BackgroundColor = new Color(0.25f, 0.25f, 0.25f, 1.0f)
|
||||
})
|
||||
{
|
||||
AbsoluteMargin = Vector2.One * 32f
|
||||
};
|
||||
|
||||
_panel.AddChild(contentPanel);
|
||||
|
||||
var verticalPanel = new MarginPanel(new PanelStyle()
|
||||
{
|
||||
BackgroundColor = new Color(0.1f, 0.1f, 0.1f, 1.0f),
|
||||
})
|
||||
{
|
||||
AbsoluteMargin = Vector2.One * 8f,
|
||||
};
|
||||
|
||||
contentPanel.AddChild(verticalPanel);
|
||||
verticalPanel.AddChild(exampleText);
|
||||
}
|
||||
|
||||
private void GetResources()
|
||||
{
|
||||
ResourceManager.TryGetResource("inter_regular", out _defaultFont);
|
||||
}
|
||||
|
||||
|
||||
private Font? _defaultFont;
|
||||
private Container _screenContainer = new();
|
||||
private Panel? _panel;
|
||||
|
||||
private Logger _logger = new(nameof(UiLayer));
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
using System.Numerics;
|
||||
using Voile;
|
||||
using Voile.Rendering;
|
||||
using Voile.SceneGraph;
|
||||
|
||||
public class World : Drawable2d
|
||||
{
|
||||
protected override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
|
||||
_randomPositions = new Vector2[_rectangleAmount];
|
||||
for (int i = 0; i < _rectangleAmount - 1; i++)
|
||||
{
|
||||
_randomPositions[i] = MathUtils.RandomVector2(Position, Vector2.One * 2048f);
|
||||
}
|
||||
}
|
||||
public override void OnDraw(RenderSystem renderer)
|
||||
{
|
||||
for (int i = 0; i < _rectangleAmount; i++)
|
||||
{
|
||||
renderer.SetTransform(_randomPositions[i], PivotOffset, 0);
|
||||
renderer.DrawRectangle(Vector2.One * 16f, _rectangleColor);
|
||||
}
|
||||
}
|
||||
|
||||
private Color _rectangleColor = new Color(0.25f, 0.25f, 0.25f, 1.0f);
|
||||
private int _rectangleAmount = 6000;
|
||||
private Vector2[] _randomPositions;
|
||||
}
|
||||
Reference in New Issue
Block a user