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
9 changes: 1 addition & 8 deletions Core/Entities/Properties/Meshes/MeshService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ public Mesh LoadMesh(string identifier, Mesh mesh)

var vertexBufferObject = Window.GL.GenBuffer();
Window.GL.BindBuffer(GLEnum.ArrayBuffer, vertexBufferObject);

unsafe
{
fixed (float* meshDataPtr = meshData)
{
Window.GL.BufferData(GLEnum.ArrayBuffer, (uint)meshData.Length * sizeof(float), meshDataPtr, GLEnum.StaticDraw);
}
}
Window.GL.BufferData<float>(GLEnum.ArrayBuffer, (uint)meshData.Length * sizeof(float), meshData, GLEnum.StaticDraw);

Meshes.Add(identifier, mesh);
return mesh;
Expand Down
22 changes: 8 additions & 14 deletions Core/Entities/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,15 @@ public void Initialize()
InitializeBuffers();
}

private unsafe void InitializeBuffers()
private void InitializeBuffers()
{
fixed (float* vertexDataPtr = _vertices)
{
var vertexBufferObject = Window.GL.GenBuffer();
Window.GL.BindBuffer(GLEnum.ArrayBuffer, vertexBufferObject);
Window.GL.BufferData(GLEnum.ArrayBuffer, (uint)_vertices.Length * sizeof(float), vertexDataPtr, GLEnum.StaticDraw);
}

fixed (uint* indicieDataPtr = _indices)
{
var elementBufferObject = Window.GL.GenBuffer();
Window.GL.BindBuffer(GLEnum.ElementArrayBuffer, elementBufferObject);
Window.GL.BufferData(GLEnum.ElementArrayBuffer, (uint)_indices.Length * sizeof(uint), indicieDataPtr, GLEnum.StaticDraw);
}
var vertexBufferObject = Window.GL.GenBuffer();
Window.GL.BindBuffer(GLEnum.ArrayBuffer, vertexBufferObject);
Window.GL.BufferData<float>(GLEnum.ArrayBuffer, (uint)_vertices.Length * sizeof(float), _vertices, GLEnum.StaticDraw);

var elementBufferObject = Window.GL.GenBuffer();
Window.GL.BindBuffer(GLEnum.ElementArrayBuffer, elementBufferObject);
Window.GL.BufferData<uint>(GLEnum.ElementArrayBuffer, (uint)_indices.Length * sizeof(uint), _indices, GLEnum.StaticDraw);
}

/// <summary>
Expand Down
19 changes: 10 additions & 9 deletions Core/Interfaces/IGame.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SharpEngine.Core.Entities.Views;
using SharpEngine.Core.Entities.Views.Settings;
using SharpEngine.Core.Enums;

using Silk.NET.Input;
Expand All @@ -9,50 +10,50 @@ namespace SharpEngine.Core.Interfaces;
/// Contains definitions the Game class must implement.
/// To consider: move into a abstract class so that the game doesn't necessarily have to implement all methods.
/// </summary>
public interface IGame
public class Game
{
/// <summary>
/// Gets or sets the core settings of the game.
/// </summary>
public ISettings CoreSettings { get; }
public ISettings CoreSettings { get; init; } = new DefaultSettings();

/// <summary>
/// Gets or sets the camera of the game.
/// </summary>
public CameraView Camera { get; set; }
public CameraView Camera { get; set; } = new(new System.Numerics.Vector3(0), new DefaultViewSettings());

/// <summary>
/// Executed when a mouse button is pressed.
/// </summary>
public void HandleMouseDown(IMouse mouse, MouseButton button);
public virtual void HandleMouseDown(IMouse mouse, MouseButton button) { }

/// <summary>
/// A method executed when the mouse state is changed
/// </summary>
/// <param name="mouse">The state of the mouse on the current frame.</param>
public void HandleMouse(IMouse mouse);
public virtual void HandleMouse(IMouse mouse) { }

/// <summary>
/// Gets or sets the event executed when the mouse wheel is scrolled.
/// </summary>
/// <param name="direction">The direction the wheel was scrolled.</param>
/// <param name="scrollWheel">Contains information about the scroll wheel changes during the current frame.</param>
public void HandleMouseWheel(MouseWheelScrollDirection direction, ScrollWheel scrollWheel);
public virtual void HandleMouseWheel(MouseWheelScrollDirection direction, ScrollWheel scrollWheel) { }

/// <summary>
/// Executed when a key is pressed.
/// </summary>
/// <param name="input">The state of the keyboard on the current frame.</param>
/// <param name="deltaTime">The time since the last frame.</param>
public void HandleKeyboard(IKeyboard input, double deltaTime);
public virtual void HandleKeyboard(IKeyboard input, double deltaTime) { }

/// <summary>
/// Executed when the game is first loaded.
/// </summary>
public void Initialize();
public virtual void Initialize() { }

/// <summary>
/// Executed each frame.
/// </summary>
public void Update(double deltaTime, IInputContext input);
public virtual void Update(double deltaTime, IInputContext input) { }
}
20 changes: 20 additions & 0 deletions Core/Interfaces/ISettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SharpEngine.Core.Renderers;
using Silk.NET.Windowing;

namespace SharpEngine.Core.Interfaces;

Expand All @@ -19,4 +20,23 @@ public interface ISettings

/// <summary>Gets or sets which renderer should be enabled for the current window.</summary>
public RenderFlags RendererFlags { get; set; }

/// <summary>Gets or sets the settings for a window.</summary>
WindowOptions WindowOptions { get; set; }
}

/// <inheritdoc cref="ISettings" />
public class DefaultSettings : ISettings
{
/// <inheritdoc/>
public bool UseWireFrame { get; set; }

/// <inheritdoc/>
public bool PrintFrameRate { get; set; }

/// <inheritdoc/>
public RenderFlags RendererFlags { get; set; } = RenderFlags.All;

/// <inheritdoc/>
public WindowOptions WindowOptions { get; set; }
}
4 changes: 2 additions & 2 deletions Core/Renderers/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Renderer : RendererBase
private LampShader _lampShader;
private LightingShader _lightingShader;

private readonly IGame _game;
private readonly Game _game;
private readonly Scene _scene;

// Read only once, load into OpenGL buffer once.
Expand All @@ -35,7 +35,7 @@ public class Renderer : RendererBase
/// </summary>
/// <param name="game">The game the renderer is being used for.</param>
/// <param name="scene">The game scene to be rendered.</param>
public Renderer(IGame game, Scene scene) : base(game.CoreSettings)
public Renderer(Game game, Scene scene) : base(game.CoreSettings)
{
_game = game;
_scene = scene;
Expand Down
2 changes: 1 addition & 1 deletion Core/Renderers/UIRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class UIRenderer : RendererBase
/// <summary>
/// Initializes a new instance of <see cref="UIRenderer"/>.
/// </summary>
public UIRenderer(IGame game, Scene scene) : base(game.CoreSettings)
public UIRenderer(Game game, Scene scene) : base(game.CoreSettings)
{
_scene = scene;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
Required by some low level OpenGL functions.
We should see if there is a better way to approach where ever these unsafe contexts are being used.
-->
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Platforms>AnyCPU;x64;x86</Platforms>
<GeneratePackageOnBuild>$(GenerateNuGetPackages)</GeneratePackageOnBuild>
<PackageProjectUrl>https://github.com/Av3boy/SharpEngine</PackageProjectUrl>
<PackageTags>game-engine;</PackageTags>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>

<!-- Required, atleast for now since another NuGet package with the SharpEngine.Core name already exists. -->
<PackageId>$(AssemblyName).NET</PackageId>
<Configurations>Debug;Release;LauncherNonWindows</Configurations>

</PropertyGroup>

Expand Down
44 changes: 22 additions & 22 deletions Core/SilkWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace SharpEngine.Core;
/// <summary>
/// Represents a class abstraction for the <see cref="IWindow"/> interface.
/// </summary>
public abstract class SilkWindow : IWindow
public abstract class SilkWindow : IDisposable
{
/// <inheritdoc />
public virtual IWindowHost? Parent { get; }
Expand All @@ -39,12 +39,12 @@ public abstract class SilkWindow : IWindow
/// <inheritdoc />
public Vector2D<int> Size { get; set; }

/// <inheritdoc />
public string Title
{
get => CurrentWindow.Title;
set => CurrentWindow.Title = value;
}
// /// <inheritdoc />
// public string Title
// {
// get => CurrentWindow.Title;
// set => CurrentWindow.Title = value;
// }

/// <inheritdoc />
public WindowState WindowState { get; set; }
Expand Down Expand Up @@ -158,21 +158,21 @@ public virtual void Close() { }
/// <inheritdoc />
public virtual void ContinueEvents() { }

private IWindow? _currentWindow;

/// <summary>Gets or sets the current window.</summary>
public IWindow CurrentWindow
{
get => _currentWindow ?? this;
set => _currentWindow = value;
}

/// <inheritdoc />
public virtual IWindow CreateWindow(WindowOptions opts)
{
CurrentWindow = Silk.NET.Windowing.Window.Create(opts);
return CurrentWindow;
}
// private IWindow? _currentWindow;
//
// /// <summary>Gets or sets the current window.</summary>
// public IWindow CurrentWindow
// {
// get => _currentWindow!;
// set => _currentWindow = value;
// }

/// <inheritdoc />
// 7public IWindow CreateWindow(WindowOptions opts)
// 7{
// 7 CurrentWindow = Silk.NET.Windowing.Window.Create(opts);
// 7 return CurrentWindow;
// 7}

/// <inheritdoc />
protected virtual void Dispose(bool disposing) { }
Expand Down
Loading