Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Examples/Minimal/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static void Main(string[] _)
var game = new Minimal();

using var window = new Window(game);
window.Initialize();
window.Run();
}
}
Expand Down
9 changes: 6 additions & 3 deletions Examples/MultipleWindows/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
private static readonly List<IWindow> _windows = [];
private static readonly List<IInputContext> _inputContexts = [];
private static readonly ConcurrentQueue<WindowOptions> _windowQueue = [];
private static readonly CancellationTokenSource _cancellationTokenSource = new();

Check failure on line 28 in Examples/MultipleWindows/Program.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Dispose '_cancellationTokenSource' when it is no longer needed.

See more on https://sonarcloud.io/project/issues?id=Av3boy_SharpEngine&issues=AZ8PGH9Bh1Y3gYnR6kUu&open=AZ8PGH9Bh1Y3gYnR6kUu&pullRequest=135

/// <summary>
/// The main entry point of the application.
Expand All @@ -39,7 +39,7 @@
Console.WriteLine("end");
Console.ReadLine();

// StartWindowQueueTask();

Check warning on line 42 in Examples/MultipleWindows/Program.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this commented out code.

See more on https://sonarcloud.io/project/issues?id=Av3boy_SharpEngine&issues=AZ8PGH9Bh1Y3gYnR6kUt&open=AZ8PGH9Bh1Y3gYnR6kUt&pullRequest=135
//
// while (!_cancellationTokenSource.IsCancellationRequested)
// {
Expand Down Expand Up @@ -117,13 +117,16 @@
private static void EnqueueWindow()
{
var window = CreateWindow();
foreach (var mouse in window!.Input!.Mice)
mouse.Click += Mouse_Click;

_inputContexts.Add(window.Input);
// Prefer the higher-level Window event to avoid wiring low-level input handlers.
window.OnButtonMouseDown += (mouse, button) => Mouse_Click(mouse, (MouseButton)button, mouse.Position);

Check warning on line 122 in Examples/MultipleWindows/Program.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unnecessary cast to 'MouseButton'.

See more on https://sonarcloud.io/project/issues?id=Av3boy_SharpEngine&issues=AZ8PGH9Bh1Y3gYnR6kUy&open=AZ8PGH9Bh1Y3gYnR6kUy&pullRequest=135

if (window.Input is not null)
_inputContexts.Add(window.Input);

_windows.Add(window);
}

private static void Mouse_Click(IMouse args1, MouseButton arg2, System.Numerics.Vector2 arg3)

Check warning on line 130 in Examples/MultipleWindows/Program.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused method parameter 'arg3'.

See more on https://sonarcloud.io/project/issues?id=Av3boy_SharpEngine&issues=AZ8PGH9Bh1Y3gYnR6kUx&open=AZ8PGH9Bh1Y3gYnR6kUx&pullRequest=135

Check warning on line 130 in Examples/MultipleWindows/Program.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused method parameter 'args1'.

See more on https://sonarcloud.io/project/issues?id=Av3boy_SharpEngine&issues=AZ8PGH9Bh1Y3gYnR6kUv&open=AZ8PGH9Bh1Y3gYnR6kUv&pullRequest=135

Check warning on line 130 in Examples/MultipleWindows/Program.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused method parameter 'arg2'.

See more on https://sonarcloud.io/project/issues?id=Av3boy_SharpEngine&issues=AZ8PGH9Bh1Y3gYnR6kUw&open=AZ8PGH9Bh1Y3gYnR6kUw&pullRequest=135
=> _windowQueue.Enqueue(WindowOptions.Default);
}
4 changes: 4 additions & 0 deletions ObjLoader/DataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,9 @@ public void AddNormal(Normal normal)
/// <inheritdoc />
public void AddVertex(Vertex vertex)
=> Vertices.Add(vertex);

/// <inheritdoc />
public void AddMaterial(Material currentMaterial)
=> Materials.Add(currentMaterial);
}
}
13 changes: 10 additions & 3 deletions ObjLoader/IMaterialDataStore.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
namespace SharpEngine.Core.ObjLoader;
using SharpEngine.Core.Components.Properties;

namespace SharpEngine.Core.ObjLoader;

/// <summary>
/// Contains definitions for the material data store, which provides methods to manage material information during the OBJ file loading process.
/// </summary>
public interface IMaterialDataStore
{
/// <summary>
/// Adds a material to the material data store.
/// </summary>
/// <param name="currentMaterial">The material to add.</param>
void AddMaterial(Material currentMaterial);

/// <summary>
/// Sets the material for the current group.
/// </summary>
/// <param name="materialName">The name of the material to set.</param>
public void SetMaterial(string materialName);

void SetMaterial(string materialName);
}
13 changes: 13 additions & 0 deletions ObjLoader/Loaders/IFileManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.IO;

namespace SharpEngine.Core.ObjLoader.Loader.Loaders
{
/// <summary>
/// Represents an abstraction of a stream reader for testability.
/// </summary>
public interface IFileManager
{
/// <inheritdoc cref="StreamReader.StreamReader(string)"/>
StreamReader StreamReader(string path);
}
}
17 changes: 15 additions & 2 deletions ObjLoader/Loaders/LoaderBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.IO.Abstractions;

namespace SharpEngine.Core.ObjLoader.Loader.Loaders
{
Expand All @@ -7,6 +8,18 @@ namespace SharpEngine.Core.ObjLoader.Loader.Loaders
/// </summary>
public abstract class LoaderBase
{
private readonly IFileStreamFactory _fileStreamFactory;
private readonly IFileManager _fileManager;

/// <summary>
/// Initializes a new instance of the <see cref="LoaderBase"/>.
/// </summary>
protected LoaderBase(IFileStreamFactory fileStreamFactory, IFileManager fileManager)
{
_fileStreamFactory = fileStreamFactory;
_fileManager = fileManager;
}

/// <summary>
/// Parses the file at the specified path and processes each line via <see cref="ParseLine(string, string)"/>.
/// </summary>
Expand All @@ -16,8 +29,8 @@ public abstract class LoaderBase
/// <param name="path">The path of the file to open and parse.</param>
public void ParseFile(string path)
{
using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
using var lineStreamReader = new StreamReader(fileStream);
using var fileStream = _fileStreamFactory.FileSystem.FileStream.New(path, FileMode.Open, FileAccess.Read);
using var lineStreamReader = _fileManager.StreamReader(path);

while (!lineStreamReader.EndOfStream)
{
Expand Down
12 changes: 8 additions & 4 deletions ObjLoader/Loaders/MaterialLoader/MaterialLibraryLoader.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using SharpEngine.Core.Components.Properties;
using SharpEngine.Core.Components.ObjLoader.DataStore;
using SharpEngine.Core.Components.Properties;
using SharpEngine.Core.ObjLoader.Loader.Loaders;
using SharpEngine.Shared.Extensions;

using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Numerics;

namespace SharpEngine.Core.ObjLoader.Loaders.MaterialLoader
Expand All @@ -19,7 +21,7 @@ namespace SharpEngine.Core.ObjLoader.Loaders.MaterialLoader
/// </remarks>
public class MaterialLibraryLoader : LoaderBase
{
private readonly DataStore _dataStore;
private readonly IMaterialDataStore _dataStore;
private readonly Dictionary<string, Action<string>> _parseActionDictionary = [];
private readonly List<string> _unrecognizedLines = [];

Expand All @@ -35,7 +37,9 @@ public class MaterialLibraryLoader : LoaderBase
/// Ns, d, Tr, illum, map_*, bump, disp, decal) to populate Material instances.
/// </remarks>
/// <param name="dataStore">DataStore used to register and store parsed materials and texture references.</param>
public MaterialLibraryLoader(DataStore dataStore)
/// <param name="fileStreamFactory">Represents a factory for creating file streams.</param>
/// <param name="fileManager">Represents a manager for handling file operations.</param>
public MaterialLibraryLoader(IMaterialDataStore dataStore, IFileStreamFactory fileStreamFactory, IFileManager fileManager) : base(fileStreamFactory, fileManager)
{
_dataStore = dataStore;

Expand Down Expand Up @@ -92,7 +96,7 @@ protected override void ParseLine(string keyword, string data)
private void PushMaterial(string materialName)
{
_currentMaterial = new Material(materialName);
_dataStore.Materials.Add(_currentMaterial);
_dataStore.AddMaterial(_currentMaterial);
}

private static Vector3 ParseVec3(string data)
Expand Down
7 changes: 6 additions & 1 deletion ObjLoader/Loaders/ObjLoader/ObjLoader.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using SharpEngine.Core.Entities.Properties.Meshes;
using SharpEngine.Core.ObjLoader.Loader.Loaders;
using SharpEngine.Core.ObjLoader.TypeParsers;

using Silk.NET.OpenGL;

using System.Collections.Generic;
using System.IO.Abstractions;

namespace SharpEngine.Core.ObjLoader.Loaders.ObjLoader
{
Expand All @@ -21,7 +24,9 @@ public class ObjLoader : LoaderBase
/// </summary>
/// <param name="path">The path to the OBJ file.</param>
/// <param name="dataStore">The data store to populate during parsing.</param>
public ObjLoader(string path, DataStore dataStore)
/// <param name="fileStreamFactory">Represents a factory for creating file streams.</param>
/// <param name="fileManager">Represents a manager for handling file operations.</param>
public ObjLoader(string path, DataStore dataStore, IFileStreamFactory fileStreamFactory, IFileManager fileManager) : base(fileStreamFactory, fileManager)
{
_path = path;
_dataStore = dataStore;
Expand Down
35 changes: 28 additions & 7 deletions ObjLoader/Loaders/ObjLoader/ObjLoaderFactory.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
using SharpEngine.Core.Components.Properties.Meshes;
using SharpEngine.Core.Entities.Properties.Meshes;
using SharpEngine.Core.ObjLoader.Loader.Loaders;
using SharpEngine.Core.ObjLoader.Loader.TypeParsers;
using SharpEngine.Core.ObjLoader.Loaders.MaterialLoader;

using Silk.NET.OpenGL;

using System;
using System.Collections.Generic;
using System.IO;

using SharpEngine.Core.Entities.Properties.Meshes;
using SharpEngine.Core.Components.Properties.Meshes;
using SharpEngine.Core.ObjLoader.Loaders.MaterialLoader;
using SharpEngine.Core.ObjLoader.Loader.TypeParsers;
using System.IO.Abstractions;

namespace SharpEngine.Core.ObjLoader.Loaders.ObjLoader
{
/// <summary>
/// Represents a testable wrapper for creating stream file related objects.
/// </summary>
public class FileManager : IFileManager
{
/// <inheritdoc />
public StreamReader StreamReader(string path)
=> new(path);
}

/// <summary>
/// Handles loading 3D models.
/// </summary>
public static class ObjLoaderFactory
{
private static readonly FileSystem _fileSystem;
private static readonly FileManager _fileManager;

static ObjLoaderFactory()

Check warning on line 34 in ObjLoader/Loaders/ObjLoader/ObjLoaderFactory.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Initialize all 'static fields' inline and remove the 'static constructor'.

See more on https://sonarcloud.io/project/issues?id=Av3boy_SharpEngine&issues=AZ8PGIAxh1Y3gYnR6kUz&open=AZ8PGIAxh1Y3gYnR6kUz&pullRequest=135
{
_fileSystem = new FileSystem();
_fileManager = new FileManager();
}

const string FbxExtension = ".fbx";
const string ObjExtension = ".obj";

Expand Down Expand Up @@ -56,13 +77,13 @@
var textureParser = new TextureParser(dataStore);
var vertexParser = new VertexParser(dataStore);

var materialLibraryLoader = new MaterialLibraryLoader(dataStore);
var materialLibraryLoader = new MaterialLibraryLoader(dataStore, _fileSystem.FileStream, _fileManager);

var materialLoader = new MaterialLibraryLoaderFacade(materialLibraryLoader, path);
var materialLibraryParser = new MaterialLibraryParser(materialLoader);
var useMaterialParser = new UseMaterialParser(dataStore);

var loader = new ObjLoader(path, dataStore)
var loader = new ObjLoader(path, dataStore, _fileSystem.FileStream, _fileManager)
.SetupTypeParsers(faceParser, groupParser, normalParser, textureParser, vertexParser, materialLibraryParser, useMaterialParser);

return loader.Load(gl);
Expand Down
1 change: 1 addition & 0 deletions ObjLoader/SharpEngine.Core.ObjLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<!-- TODO: This should be used with unit testing. -->
<ItemGroup>
<PackageReference Include="System.IO.Abstractions" Version="22.1.1" />
<PackageReference Include="TestableIO.System.IO.Abstractions" Version="22.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions SharpEngine.Core.ArchitectureTests/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace SharpEngine.Core.ArchitectureTests;

public class Class1

Check warning on line 3 in SharpEngine.Core.ArchitectureTests/Class1.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this empty class, write its code or make it an "interface".

See more on https://sonarcloud.io/project/issues?id=Av3boy_SharpEngine&issues=AZ8PGIDih1Y3gYnR6kVD&open=AZ8PGIDih1Y3gYnR6kVD&pullRequest=135
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
27 changes: 26 additions & 1 deletion SharpEngine.Core/Audio/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace SharpEngine.Core.Audio;
/// </summary>
public static class Audio
{
private static AudioPlayerBase? audioPlayer = null;

/// <summary>
/// Plays an audio file if it is in the WAV format.
/// </summary>
Expand All @@ -18,11 +20,34 @@ public static void Play(string filePath)
switch (Path.GetExtension(filePath))
{
case ".wav":
new WavPlayer().Play(filePath);
audioPlayer = new WavPlayer();
audioPlayer.Play(filePath);
break;

case ".mp3":
audioPlayer = new Mp3Player();
audioPlayer.Play(filePath);
break;

default:
throw new NotSupportedException("Unsupported file format.");
}
}

/// <inheritdoc cref="AudioPlayerBase.Stop"/>
public static void Stop()
{
audioPlayer?.Stop();
audioPlayer = null;
}

/// <summary>
/// Pauses the currently playing audio, if any.
/// </summary>
public static void Pause() => audioPlayer?.Pause();

/// <summary>
/// Resumes the currently paused audio, if any.
/// </summary>
public static void Resume() => audioPlayer?.Resume();
}
2 changes: 1 addition & 1 deletion SharpEngine.Core/Audio/AudioBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public AudioBuffer(AL al)
/// </summary>
/// <param name="data">The data to be loaded into the buffer.</param>
/// <param name="wavData">Details about the data.</param>
public void LoadData(ReadOnlySpan<byte> data, WavData wavData)
public void LoadData(ReadOnlySpan<byte> data, AudioData wavData)
{
unsafe
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace SharpEngine.Core.Audio;

/// <summary>
/// Represents audio data in WAV format.
/// Represents the data in a audio file.
/// </summary>
public class WavData
public class AudioData
{
/// <summary>Gets or sets the number of channels used in the data.</summary>
public short NumChannels { get; set; }
Expand Down
8 changes: 8 additions & 0 deletions SharpEngine.Core/Audio/AudioDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ namespace SharpEngine.Core.Audio;
/// </summary>
public unsafe class AudioDevice : IDisposable
{
// Shared single AudioDevice instance to ensure a single OpenAL context is used
private static readonly AudioDevice _shared = new AudioDevice();

/// <summary>
/// Gets the shared audio device instance used by the application.
/// </summary>
public static AudioDevice Shared => _shared;

/// <summary>Gets the OpenAL context.</summary>
public AL Al { get; }

Expand Down
Loading