mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using static System.Compiler;
|
||||||
|
|
||||||
|
namespace GlitchyEngine.Generators
|
||||||
|
{
|
||||||
|
public class NewDisposableComponentGenerator : Generator
|
||||||
|
{
|
||||||
|
public override String Name => "New Disposable Component";
|
||||||
|
|
||||||
|
public override void InitUI()
|
||||||
|
{
|
||||||
|
AddEdit("name", "Component Name", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Generate(String outFileName, String outText, ref Flags generateFlags)
|
||||||
|
{
|
||||||
|
var name = mParams["name"];
|
||||||
|
if (name.EndsWith(".bf", .OrdinalIgnoreCase))
|
||||||
|
name.RemoveFromEnd(3);
|
||||||
|
outFileName.Append(name);
|
||||||
|
|
||||||
|
outText.AppendF(
|
||||||
|
$"""
|
||||||
|
using GlitchyEngine.World;
|
||||||
|
|
||||||
|
namespace {Namespace}
|
||||||
|
{{
|
||||||
|
struct {name} : IDisposableComponent
|
||||||
|
{{
|
||||||
|
public void Dispose() mut
|
||||||
|
{{
|
||||||
|
// TODO: Dispose of the content
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using static System.Compiler;
|
||||||
|
|
||||||
|
namespace GlitchyEngine.Generators
|
||||||
|
{
|
||||||
|
public class NewStructGenerator : Generator
|
||||||
|
{
|
||||||
|
public override String Name => "New Struct";
|
||||||
|
|
||||||
|
public override void InitUI()
|
||||||
|
{
|
||||||
|
AddEdit("name", "Struct Name", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Generate(String outFileName, String outText, ref Flags generateFlags)
|
||||||
|
{
|
||||||
|
var name = mParams["name"];
|
||||||
|
if (name.EndsWith(".bf", .OrdinalIgnoreCase))
|
||||||
|
name.RemoveFromEnd(3);
|
||||||
|
outFileName.Append(name);
|
||||||
|
outText.AppendF(
|
||||||
|
$"""
|
||||||
|
namespace {Namespace}
|
||||||
|
{{
|
||||||
|
struct {name}
|
||||||
|
{{
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
#if GE_GRAPHICS_DX11
|
||||||
|
|
||||||
|
using DirectX.D3D11;
|
||||||
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
|
using internal GlitchyEngine.Renderer;
|
||||||
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
|
namespace GlitchyEngine.Renderer
|
||||||
|
{
|
||||||
|
internal typealias D3DDepthStencilStateDesc = DirectX.D3D11.DepthStencilStateDescription;
|
||||||
|
internal typealias DxDSSDesc = DirectX.D3D11.DepthStencilStateDescription;
|
||||||
|
internal typealias GEDSSDesc = GlitchyEngine.Renderer.DepthStencilStateDescription;
|
||||||
|
|
||||||
|
internal typealias DxDepthStencilOpDesc = DirectX.D3D11.DepthStencilOperationDescription;
|
||||||
|
|
||||||
|
extension StencilOperation
|
||||||
|
{
|
||||||
|
public static explicit operator DirectX.D3D11.StencilOperation(Self self)
|
||||||
|
{
|
||||||
|
return (.)self.Underlying;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension DepthStencilOperationDescription
|
||||||
|
{
|
||||||
|
public static explicit operator DxDepthStencilOpDesc(Self desc)
|
||||||
|
{
|
||||||
|
return DxDepthStencilOpDesc((.)desc.StencilFailOperation, (.)desc.StencilDepthFailOperation,
|
||||||
|
(.)desc.StencilPassOperation, (.)desc.StencilFunction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension DepthStencilStateDescription
|
||||||
|
{
|
||||||
|
public static explicit operator DxDSSDesc(Self desc)
|
||||||
|
{
|
||||||
|
return DxDSSDesc(desc.DepthEnabled, desc.WriteDepth ? .All : .Zero, (.)desc.DepthFunction, desc.StencilEnabled,
|
||||||
|
desc.StencilReadMask, desc.StencilWriteMask, (.)desc.FrontFace, (.)desc.BackFace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension DepthStencilState
|
||||||
|
{
|
||||||
|
internal DxDSSDesc nativeDescription;
|
||||||
|
internal ID3D11DepthStencilState* nativeDepthStencilState ~ _?.Release();
|
||||||
|
|
||||||
|
public this(GEDSSDesc description)
|
||||||
|
{
|
||||||
|
_description = description;
|
||||||
|
nativeDescription = (.)description;
|
||||||
|
|
||||||
|
var result = NativeDevice.CreateDepthStencilState(ref nativeDescription, &nativeDepthStencilState);
|
||||||
|
if (result.Failed)
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Error($"Failed to create depth stencil state. Message({(int)result}): {result}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -87,6 +87,14 @@ namespace GlitchyEngine.Renderer
|
|||||||
SetReference!(_currentBlendState, blendState);
|
SetReference!(_currentBlendState, blendState);
|
||||||
NativeContext.OutputMerger.SetBlendState(_currentBlendState.nativeBlendState, blendFactor);
|
NativeContext.OutputMerger.SetBlendState(_currentBlendState.nativeBlendState, blendFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DepthStencilState _currentDepthStencilState ~ _?.ReleaseRef();
|
||||||
|
|
||||||
|
public override void SetDepthStencilState(DepthStencilState depthStencilState, uint8 stencilReference)
|
||||||
|
{
|
||||||
|
SetReference!(_currentDepthStencilState, depthStencilState);
|
||||||
|
NativeContext.OutputMerger.SetDepthStencilState(_currentDepthStencilState.nativeDepthStencilState, stencilReference);
|
||||||
|
}
|
||||||
|
|
||||||
public override void DrawIndexed(GeometryBinding geometry)
|
public override void DrawIndexed(GeometryBinding geometry)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
using GlitchyEngine.Core;
|
||||||
|
|
||||||
|
namespace GlitchyEngine.Renderer
|
||||||
|
{
|
||||||
|
/// The stencil operations that can be performed during depth-stencil testing.
|
||||||
|
public enum StencilOperation : uint32
|
||||||
|
{
|
||||||
|
/// Keep the existing stencil data.
|
||||||
|
Keep = 1,
|
||||||
|
/// Set the stencil data to 0.
|
||||||
|
Zero= 2,
|
||||||
|
/// Set the stencil data to the reference value set by calling ID3D11DeviceContext::OMSetDepthStencilState.
|
||||||
|
Replace = 3,
|
||||||
|
/// Increment the stencil value by 1, and clamp the result.
|
||||||
|
IncrementAndClamp = 4,
|
||||||
|
/// Decrement the stencil value by 1, and clamp the result.
|
||||||
|
DecrementAndClamp = 5,
|
||||||
|
/// Invert the stencil data.
|
||||||
|
Invert = 6,
|
||||||
|
/// Increment the stencil value by 1, and wrap the result if necessary.
|
||||||
|
Increment = 7,
|
||||||
|
/// Decrement the stencil value by 1, and wrap the result if necessary.
|
||||||
|
Decrement = 8
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DepthStencilOperationDescription
|
||||||
|
{
|
||||||
|
/// The stencil operation to perform when stencil testing fails.
|
||||||
|
public StencilOperation StencilFailOperation = .Keep;
|
||||||
|
|
||||||
|
/// The stencil operation to perform when stencil testing passes and depth testing fails.
|
||||||
|
public StencilOperation StencilDepthFailOperation = .Keep;
|
||||||
|
|
||||||
|
/// The stencil operation to perform when stencil testing and depth testing both pass.
|
||||||
|
public StencilOperation StencilPassOperation = .Keep;
|
||||||
|
|
||||||
|
/// A function that compares stencil data against existing stencil data.
|
||||||
|
public ComparisonFunction StencilFunction = .Always;
|
||||||
|
|
||||||
|
public this(StencilOperation stencilFailOperation = .Keep, StencilOperation stencilDepthFailOperation = .Keep,
|
||||||
|
StencilOperation stencilPassOperation = .Keep, ComparisonFunction stencilFunction = .Always)
|
||||||
|
{
|
||||||
|
StencilFunction = stencilFunction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public const Self Default = Self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DepthStencilStateDescription
|
||||||
|
{
|
||||||
|
/// True if depth testing is enabled.
|
||||||
|
public bool DepthEnabled = true;
|
||||||
|
|
||||||
|
/// If true writing to the depth-stencil buffer is enabled.
|
||||||
|
public bool WriteDepth = true;
|
||||||
|
|
||||||
|
/// The function that is used to compare depth data against the existing depth data.
|
||||||
|
public ComparisonFunction DepthFunction = .Less;
|
||||||
|
|
||||||
|
/// True if stencil testing is enabled.
|
||||||
|
public bool StencilEnabled = false;
|
||||||
|
|
||||||
|
public uint8 StencilReadMask = 255;
|
||||||
|
public uint8 StencilWriteMask = 255;
|
||||||
|
|
||||||
|
public DepthStencilOperationDescription FrontFace = .();
|
||||||
|
public DepthStencilOperationDescription BackFace = .();
|
||||||
|
|
||||||
|
public this(bool depthEnabled = true, bool writeDepth = true, ComparisonFunction depthFunction = .Less,
|
||||||
|
bool stencilEnabled = false, uint8 stencilReadMask = 255, uint8 stencilWriteMask = 255,
|
||||||
|
DepthStencilOperationDescription frontFace = .(),
|
||||||
|
DepthStencilOperationDescription backFace = .())
|
||||||
|
{
|
||||||
|
DepthEnabled = depthEnabled;
|
||||||
|
WriteDepth = writeDepth;
|
||||||
|
DepthFunction = depthFunction;
|
||||||
|
StencilEnabled = stencilEnabled;
|
||||||
|
StencilReadMask = stencilReadMask;
|
||||||
|
StencilWriteMask = stencilWriteMask;
|
||||||
|
FrontFace = frontFace;
|
||||||
|
BackFace = backFace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public const DepthStencilStateDescription Default = Self();
|
||||||
|
}
|
||||||
|
|
||||||
|
class DepthStencilState : RefCounter
|
||||||
|
{
|
||||||
|
public DepthStencilStateDescription _description;
|
||||||
|
|
||||||
|
public extern this(DepthStencilStateDescription description);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,11 +19,9 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DisposeComponent(void* component)
|
public void Dispose() mut
|
||||||
{
|
{
|
||||||
Self* self = (Self*)component;
|
ReleaseRefAndNullify!(_mesh);
|
||||||
|
|
||||||
ReleaseRefAndNullify!(self._mesh);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,11 @@ namespace GlitchyEngine.Renderer
|
|||||||
{
|
{
|
||||||
_rendererAPI.SetBlendState(blendState, blendFactor);
|
_rendererAPI.SetBlendState(blendState, blendFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SetDepthStencilState(DepthStencilState depthStencilState, uint8 stencilReference = 0)
|
||||||
|
{
|
||||||
|
_rendererAPI.SetDepthStencilState(depthStencilState, stencilReference);
|
||||||
|
}
|
||||||
|
|
||||||
[Inline]
|
[Inline]
|
||||||
public static void DrawIndexed(GeometryBinding geometry)
|
public static void DrawIndexed(GeometryBinding geometry)
|
||||||
|
|||||||
@@ -597,6 +597,20 @@ namespace GlitchyEngine.Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void DrawQuad(Matrix transform, Texture2D texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1))
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Log.EngineLogger.AssertDebug(s_sceneRunning, "Missing call of BeginScene.");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QueueQuadInstance(transform, color, texture, transform.Translation.Z, uvTransform);
|
||||||
|
|
||||||
|
if(s_drawOrder == .Immediate)
|
||||||
|
{
|
||||||
|
DrawDeferred();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void DrawQuadPivotCorner(Vector3 position, Vector2 size, float rotation, Texture2D texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1))
|
public static void DrawQuadPivotCorner(Vector3 position, Vector2 size, float rotation, Texture2D texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1))
|
||||||
{
|
{
|
||||||
DrawQuad(position + Vector3(size.X / 2, size.Y / -2, 0), size, rotation, texture, color, uvTransform);
|
DrawQuad(position + Vector3(size.X / 2, size.Y / -2, 0), size, rotation, texture, color, uvTransform);
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public extern void SetBlendState(BlendState blendState, ColorRGBA blendFactor);
|
public extern void SetBlendState(BlendState blendState, ColorRGBA blendFactor);
|
||||||
|
|
||||||
|
public extern void SetDepthStencilState(DepthStencilState depthStencilState, uint8 stencilReference);
|
||||||
|
|
||||||
public extern void DrawIndexed(GeometryBinding geometry);
|
public extern void DrawIndexed(GeometryBinding geometry);
|
||||||
|
|
||||||
public extern void DrawInstanced(GeometryBinding geometry);
|
public extern void DrawInstanced(GeometryBinding geometry);
|
||||||
|
|||||||
@@ -28,12 +28,10 @@ namespace GlitchyEngine.World
|
|||||||
|
|
||||||
public SkeletonPose Pose => _pose;
|
public SkeletonPose Pose => _pose;
|
||||||
|
|
||||||
public static void DisposeComponent(void* component)
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Self* animationComponent = (Self*)component;
|
_animationClip?.ReleaseRef();
|
||||||
|
delete _pose;
|
||||||
animationComponent._animationClip?.ReleaseRef();
|
|
||||||
delete animationComponent._pose;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,9 @@ namespace GlitchyEngine.World
|
|||||||
_debugName = new String(name);
|
_debugName = new String(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DisposeComponent(void* component)
|
public void Dispose() mut
|
||||||
{
|
{
|
||||||
Self* self = (Self*)component;
|
DeleteAndNullify!(_debugName);
|
||||||
|
|
||||||
DeleteAndNullify!(self._debugName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace GlitchyEngine.World
|
|||||||
|
|
||||||
typealias DisposeFunction = function void(void* component);
|
typealias DisposeFunction = function void(void* component);
|
||||||
|
|
||||||
internal typealias ComponentPoolEntry = (uint32 Id, IComponentPool Pool, DisposeFunction DisposeFunction);
|
internal typealias ComponentPoolEntry = (uint32 Id, IComponentPool Pool, DisposeFunction DisposeComponent);
|
||||||
internal Dictionary<Type, ComponentPoolEntry> _componentPools = new .();
|
internal Dictionary<Type, ComponentPoolEntry> _componentPools = new .();
|
||||||
|
|
||||||
/// A list containing all pools whose components need to be disposed before removal.
|
/// A list containing all pools whose components need to be disposed before removal.
|
||||||
@@ -60,7 +60,7 @@ namespace GlitchyEngine.World
|
|||||||
uint32 id = (uint32)_componentPools.Count;
|
uint32 id = (uint32)_componentPools.Count;
|
||||||
ComponentPool<T> componentPool = new ComponentPool<T>(MaxEntities);
|
ComponentPool<T> componentPool = new ComponentPool<T>(MaxEntities);
|
||||||
|
|
||||||
DisposeFunction disposeFunction = => T.DisposeComponent;
|
DisposeFunction disposeFunction = => DisposeComponent<T>;
|
||||||
|
|
||||||
_componentPools.Add(typeof(T), (id, componentPool, disposeFunction));
|
_componentPools.Add(typeof(T), (id, componentPool, disposeFunction));
|
||||||
|
|
||||||
@@ -68,6 +68,13 @@ namespace GlitchyEngine.World
|
|||||||
_disposingPools.Add(typeof(T));
|
_disposingPools.Add(typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Enables us to bind a function pointer to the components dispose function
|
||||||
|
private static void DisposeComponent<T>(void* component) where T : IDisposableComponent
|
||||||
|
{
|
||||||
|
T* myComponent = (T*)component;
|
||||||
|
(*myComponent).Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
/** @brief Returns the component pool for the given component type.
|
/** @brief Returns the component pool for the given component type.
|
||||||
* @param TComponent The type of the component whose component pool will be returned.
|
* @param TComponent The type of the component whose component pool will be returned.
|
||||||
* @returns A reference to the component pool.
|
* @returns A reference to the component pool.
|
||||||
@@ -137,7 +144,7 @@ namespace GlitchyEngine.World
|
|||||||
// Get pointer to component
|
// Get pointer to component
|
||||||
void* component = pool.Pool.Get(listEntity.ID.Index);
|
void* component = pool.Pool.Get(listEntity.ID.Index);
|
||||||
// Dispose component
|
// Dispose component
|
||||||
pool.DisposeFunction(component);
|
pool.DisposeComponent(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,7 +152,7 @@ namespace GlitchyEngine.World
|
|||||||
/**
|
/**
|
||||||
* Assigns a component of type T to the specified entity and returns it.
|
* Assigns a component of type T to the specified entity and returns it.
|
||||||
*/
|
*/
|
||||||
public T* AssignComponent<T>(Entity entity) where T : struct
|
public T* AssignComponent<T>(Entity entity) where T : struct, new
|
||||||
{
|
{
|
||||||
if(entity.Index > _entities.Count)
|
if(entity.Index > _entities.Count)
|
||||||
return null;
|
return null;
|
||||||
@@ -167,8 +174,12 @@ namespace GlitchyEngine.World
|
|||||||
// return null;
|
// return null;
|
||||||
|
|
||||||
listEntity.ComponentMask[entry.Id] = true;
|
listEntity.ComponentMask[entry.Id] = true;
|
||||||
|
|
||||||
return (.)entry.Pool.Get(entity.Index);
|
T* component = (T*)entry.Pool.Get(entity.Index);
|
||||||
|
|
||||||
|
*component = T();
|
||||||
|
|
||||||
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -214,7 +225,7 @@ namespace GlitchyEngine.World
|
|||||||
listEntity.ComponentMask[entry.Id] = false;
|
listEntity.ComponentMask[entry.Id] = false;
|
||||||
|
|
||||||
// Get component and call dispose
|
// Get component and call dispose
|
||||||
T.DisposeComponent(entry.Pool.Get(entity.Index));
|
DisposeComponent<T>(entry.Pool.Get(entity.Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
public T* GetComponent<T>(Entity entity) where T : struct
|
public T* GetComponent<T>(Entity entity) where T : struct
|
||||||
@@ -303,10 +314,9 @@ namespace GlitchyEngine.World
|
|||||||
{
|
{
|
||||||
public bool IsDisposed;
|
public bool IsDisposed;
|
||||||
|
|
||||||
public static void DisposeComponent(void* component)
|
public void Dispose() mut
|
||||||
{
|
{
|
||||||
Self* testComponent = (Self*)component;
|
IsDisposed = true;
|
||||||
testComponent.IsDisposed = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ namespace GlitchyEngine.World
|
|||||||
* @Note This function will be called when the given component was removed from the entity
|
* @Note This function will be called when the given component was removed from the entity
|
||||||
* or when the entity itself was removed.
|
* or when the entity itself was removed.
|
||||||
*/
|
*/
|
||||||
static void DisposeComponent(void* component);
|
void Dispose() mut;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,9 @@ namespace GlitchyEngine.World
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DisposeComponent(void* component)
|
public void Dispose() mut
|
||||||
{
|
{
|
||||||
Self* meshRenderComponent = (Self*)component;
|
_material?.ReleaseRef();
|
||||||
meshRenderComponent._material?.ReleaseRef();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,12 +40,10 @@ namespace GlitchyEngine.World
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DisposeComponent(void* component)
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Self* meshRenderComponent = (Self*)component;
|
_material?.ReleaseRef();
|
||||||
|
_skeleton?.ReleaseRef();
|
||||||
meshRenderComponent._material?.ReleaseRef();
|
|
||||||
meshRenderComponent._skeleton?.ReleaseRef();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user