Documentation

This commit is contained in:
Simon Lübeß
2023-12-13 14:45:33 +01:00
parent ed756f5847
commit a129156641
17 changed files with 211 additions and 37 deletions
+4 -2
View File
@@ -1,8 +1,10 @@
using GlitchyEngine.Components;
using GlitchyEngine.Math; using GlitchyEngine.Math;
namespace GlitchyEngine; namespace GlitchyEngine.Components;
/// <summary>
/// Rigid body component for 2D physics.
/// </summary>
public class Rigidbody2D : Component public class Rigidbody2D : Component
{ {
/// <summary> /// <summary>
+9 -4
View File
@@ -4,8 +4,16 @@ using GlitchyEngine.Math;
namespace GlitchyEngine; namespace GlitchyEngine;
/// <summary>
/// Represents the position, rotation and scale of an entity in the world.
/// <br/><br/>
/// Every entity has a transform component.
/// </summary>
public class Transform : Component public class Transform : Component
{ {
/// <summary>
/// Gets or sets the translation (position) of the entity.
/// </summary>
public float3 Translation public float3 Translation
{ {
get get
@@ -13,9 +21,6 @@ public class Transform : Component
ScriptGlue.Transform_GetTranslation(Entity.UUID, out float3 translation); ScriptGlue.Transform_GetTranslation(Entity.UUID, out float3 translation);
return translation; return translation;
} }
set set => ScriptGlue.Transform_SetTranslation(Entity.UUID, in value);
{
ScriptGlue.Transform_SetTranslation(Entity.UUID, in value);
}
} }
} }
+4 -1
View File
@@ -1,11 +1,14 @@
namespace GlitchyEngine.Core; namespace GlitchyEngine.Core;
/// <summary>
/// The base class for all classes that represent something that belongs to the engine (Entities, Components and Assets).
/// </summary>
public abstract class EngineObject public abstract class EngineObject
{ {
protected internal UUID _uuid; protected internal UUID _uuid;
/// <summary> /// <summary>
/// UUID used for identifying the object in the engine. /// UUID (Universally Unique Identifier) used for identifying the object in the engine.
/// </summary> /// </summary>
public UUID UUID => _uuid; public UUID UUID => _uuid;
+12 -1
View File
@@ -7,13 +7,24 @@ public struct UUID
{ {
private ulong _uuid; private ulong _uuid;
/// <summary>
/// Create a new instance of a <see cref="UUID"/> with the given value as ID.
/// </summary>
/// <param name="uuid">The id.</param>
public UUID(ulong uuid) public UUID(ulong uuid)
{ {
_uuid = uuid; _uuid = uuid;
} }
public static UUID Zero = new UUID(0); /// <summary>
/// A <see cref="UUID"/> with the ID 0.
/// </summary>
public static readonly UUID Zero = new UUID(0);
/// <summary>
/// Creates a new random <see cref="UUID"/>.
/// </summary>
/// <returns>The newly created <see cref="UUID"/></returns>
public static UUID CreateNew() public static UUID CreateNew()
{ {
ScriptGlue.UUID_CreateNew(out UUID id); ScriptGlue.UUID_CreateNew(out UUID id);
+4
View File
@@ -2,6 +2,10 @@
namespace GlitchyEngine.Editor; namespace GlitchyEngine.Editor;
/// <summary>
/// Specifies, that the field should be readonly, so that it cannot be changed in the editor.<br/>
/// Note, that this only affects the editor. Scripts can still change the values.
/// </summary>
public sealed class ReadonlyAttribute : Attribute public sealed class ReadonlyAttribute : Attribute
{ {
} }
+3
View File
@@ -3,6 +3,9 @@ using System;
namespace GlitchyEngine.Editor; namespace GlitchyEngine.Editor;
/// <summary>
/// Specifies the visibility of a button.
/// </summary>
public enum ButtonVisibility public enum ButtonVisibility
{ {
/// <summary> /// <summary>
+4
View File
@@ -4,6 +4,10 @@ using System.Text;
namespace GlitchyEngine.Editor; namespace GlitchyEngine.Editor;
/// <summary>
/// Specifies the properties of the textfield for the <see cref="string"/> that the attribute is attached to.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public sealed class TextFieldAttribute : Attribute public sealed class TextFieldAttribute : Attribute
{ {
/// <summary> /// <summary>
+15 -9
View File
@@ -12,7 +12,8 @@ namespace GlitchyEngine;
public class Entity : EngineObject public class Entity : EngineObject
{ {
/// <summary> /// <summary>
/// Don't call this constructor yourself. /// Only to be called by the engine. Don't call this constructor yourself, it will not result in a valid entity.
/// If you want to create a new entity use <see cref="Entity(string)"/> or <see cref="Entity(string, Type[])"/>
/// </summary> /// </summary>
protected Entity() protected Entity()
{ {
@@ -20,7 +21,7 @@ public class Entity : EngineObject
// This constructor will be called by the Engine to initialize the scripts fields. // This constructor will be called by the Engine to initialize the scripts fields.
// Especially don't call Create here! Because Create would try and create a new entity. // Especially don't call Create here! Because Create would try and create a new entity.
} }
/// <summary> /// <summary>
/// Creates a new Entity. /// Creates a new Entity.
/// </summary> /// </summary>
@@ -31,7 +32,7 @@ public class Entity : EngineObject
} }
/// <summary> /// <summary>
/// Creates a new Entity. /// Creates a new Entity with the specified components attached to it.
/// </summary> /// </summary>
/// <param name="name">The name of the new entity.</param> /// <param name="name">The name of the new entity.</param>
/// <param name="components">The components that the entity shall have.</param> /// <param name="components">The components that the entity shall have.</param>
@@ -56,9 +57,17 @@ public class Entity : EngineObject
/// <param name="uuid">The ID of the entity that belongs to this instance.</param> /// <param name="uuid">The ID of the entity that belongs to this instance.</param>
internal Entity(UUID uuid) : base(uuid) { } internal Entity(UUID uuid) : base(uuid) { }
/// <summary>
/// Returns <see langword="true"/> if a component of the given type is attached to this entity.
/// </summary>
/// <typeparam name="T">The type of the component.</typeparam>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool HasComponent<T>() => HasComponent(typeof(T)); public bool HasComponent<T>() => HasComponent(typeof(T));
/// <summary>
/// Returns <see langword="true"/> if a component of the given type is attached to this entity.
/// </summary>
/// <param name="type">The type of the component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool HasComponent(Type type) => ScriptGlue.Entity_HasComponent(_uuid, type); public bool HasComponent(Type type) => ScriptGlue.Entity_HasComponent(_uuid, type);
@@ -240,14 +249,11 @@ public class Entity : EngineObject
ScriptGlue.Entity_RemoveScript(_uuid); ScriptGlue.Entity_RemoveScript(_uuid);
} }
/// <summary>
/// Gets the <see cref="GlitchyEngine.Transform"/> <see cref="Component"/> of this <see cref="Entity"/>.
/// </summary>
public Transform Transform => GetComponent<Transform>(); public Transform Transform => GetComponent<Transform>();
//public Vector3 Translation
//{
// get => Transform.Translation;
// set => Transform.Translation = value;
//}
/// <summary> /// <summary>
/// Returns the first entity with the given name. /// Returns the first entity with the given name.
/// </summary> /// </summary>
+9
View File
@@ -3,8 +3,17 @@ using System.Linq;
namespace GlitchyEngine.Extensions; namespace GlitchyEngine.Extensions;
/// <summary>
/// Extends the <see cref="IEnumerable{T}"/>-interface with useful methods.
/// </summary>
public static class EnumExtension public static class EnumExtension
{ {
/// <summary>
/// Enumerates the enumerable and returns a tuple containing the item and the index for every item.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="self"></param>
/// <returns></returns>
public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> self) public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> self)
=> self.Select((item, index) => (item, index)); => self.Select((item, index) => (item, index));
} }
@@ -5,6 +5,9 @@ using System.Text;
namespace GlitchyEngine.Extensions; namespace GlitchyEngine.Extensions;
/// <summary>
/// Extends the <see cref="FieldInfo"/>-class with useful methods.
/// </summary>
public static class FieldInfoExtension public static class FieldInfoExtension
{ {
/// <summary> /// <summary>
+49
View File
@@ -2,26 +2,75 @@
namespace GlitchyEngine; namespace GlitchyEngine;
/// <summary>
/// Provides methods to query the state of the input devices.
/// </summary>
public static class Input public static class Input
{ {
/// <summary>
/// Returns <see langword="true"/> if the specified key is in the pressed down state.
/// </summary>
/// <param name="key">The key to query.</param>
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool IsKeyPressed(Key key); public static extern bool IsKeyPressed(Key key);
/// <summary>
/// Returns <see langword="true"/> if the specified <see cref="key"/> is in the released state.
/// </summary>
/// <param name="key">The key to query.</param>
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool IsKeyReleased(Key key); public static extern bool IsKeyReleased(Key key);
/// <summary>
/// Returns <see langword="true"/> if the state of the specified <see cref="key"/> changed this frame (i.e. changed from pressed to released or from released to pressed).
/// </summary>
/// <param name="key">The key to query.</param>
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool IsKeyToggled(Key key); public static extern bool IsKeyToggled(Key key);
/// <summary>
/// Returns <see langword="true"/> if <see cref="key"/> is being pressed down this frame
/// (<see cref="IsKeyPressed"/> was <see langword="false"/> last frame and is <see langword="true"/> this frame).
/// </summary>
/// <param name="key">The key to query.</param>
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool IsKeyPressing(Key key); public static extern bool IsKeyPressing(Key key);
/// <summary>
/// Returns <see langword="true"/> if <see cref="key"/> is being released this frame
/// (<see cref="IsKeyPressed"/> was <see langword="true"/> last frame and is <see langword="false"/> this frame).
/// </summary>
/// <param name="key">The key to query.</param>
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool IsKeyReleasing(Key key); public static extern bool IsKeyReleasing(Key key);
/// <summary>
/// Returns <see langword="true"/> if the specified mouse button is in the pressed down state.
/// </summary>
/// <param name="mouseButton">The button to query.</param>
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool IsMouseButtonPressed(MouseButton mouseButton); public static extern bool IsMouseButtonPressed(MouseButton mouseButton);
/// <summary>
/// Returns <see langword="true"/> if the specified mouse button is in the released state.
/// </summary>
/// <param name="mouseButton">The button to query.</param>
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool IsMouseButtonReleased(MouseButton mouseButton); public static extern bool IsMouseButtonReleased(MouseButton mouseButton);
/// <summary>
/// Returns <see langword="true"/> if the mouse button is being pressed down this frame
/// (<see cref="IsMouseButtonPressed"/> was <see langword="false"/> last frame and is <see langword="true"/> this frame).
/// </summary>
/// <param name="mouseButton">The button to query.</param>
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool IsMouseButtonPressing(MouseButton mouseButton); public static extern bool IsMouseButtonPressing(MouseButton mouseButton);
/// <summary>
/// Returns <see langword="true"/> if the mouse button is being released this frame
/// (<see cref="IsMouseButtonPressed"/> was <see langword="true"/> last frame and is <see langword="false"/> this frame).
/// </summary>
/// <param name="mouseButton">The button to query.</param>
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool IsMouseButtonReleasing(MouseButton mouseButton); public static extern bool IsMouseButtonReleasing(MouseButton mouseButton);
} }
+3
View File
@@ -1,5 +1,8 @@
namespace GlitchyEngine; namespace GlitchyEngine;
/// <summary>
/// An enum of all keys that can be queried using methods in <see cref="Input"/>.
/// </summary>
public enum Key public enum Key
{ {
// Based on Win32 Virtual Keys // Based on Win32 Virtual Keys
+53 -7
View File
@@ -7,7 +7,10 @@ namespace GlitchyEngine;
/// </summary> /// </summary>
public class Log public class Log
{ {
public enum LogLevel /// <summary>
/// The severity of the log message.
/// </summary>
private enum LogLevel
{ {
Trace = 0, Trace = 0,
Debug, Debug,
@@ -18,53 +21,96 @@ public class Log
Off Off
} }
/// <summary>
/// Logs a trace message.
/// </summary>
/// <param name="message">The message to log.</param>
public static void Trace(string message) public static void Trace(string message)
{ {
LogMessage_Impl(LogLevel.Trace, message); LogMessage_Impl(LogLevel.Trace, message);
} }
/// <summary>
/// Logs an info message.
/// </summary>
/// <param name="message">The message to log.</param>
public static void Info(string message) public static void Info(string message)
{ {
LogMessage_Impl(LogLevel.Info, message); LogMessage_Impl(LogLevel.Info, message);
} }
/// <summary>
/// Logs a warning message.
/// </summary>
/// <param name="message">The message to log.</param>
public static void Warning(string message) public static void Warning(string message)
{ {
LogMessage_Impl(LogLevel.Warning, message); LogMessage_Impl(LogLevel.Warning, message);
} }
/// <summary>
/// Logs an error message.
/// </summary>
/// <param name="message">The message to log.</param>
public static void Error(string message) public static void Error(string message)
{ {
LogMessage_Impl(LogLevel.Error, message); LogMessage_Impl(LogLevel.Error, message);
} }
/// <summary>
/// Logs a critical error message.
/// </summary>
/// <param name="message">The message to log.</param>
public static void Critical(string message) public static void Critical(string message)
{ {
LogMessage_Impl(LogLevel.Critical, message); LogMessage_Impl(LogLevel.Critical, message);
} }
/// <summary>
/// Serializes the given object (using <see cref="object.ToString"/>) and logs it as a trace message.
/// </summary>
/// <param name="obj">The object to serialize.</param>
public static void Trace(object obj) public static void Trace(object obj)
{ {
LogMessage_Impl(LogLevel.Trace, obj.ToString()); LogMessage_Impl(LogLevel.Trace, obj.ToString());
} }
/// <summary>
/// Serializes the given object (using <see cref="object.ToString"/>) and logs it as an info message.
/// </summary>
/// <param name="obj">The object to serialize.</param>
public static void Info(object obj) public static void Info(object obj)
{ {
LogMessage_Impl(LogLevel.Info, obj.ToString()); LogMessage_Impl(LogLevel.Info, obj.ToString());
} }
/// <summary>
/// Serializes the given object (using <see cref="object.ToString"/>) and logs it as a warning message.
/// </summary>
/// <param name="obj">The object to serialize.</param>
public static void Warning(object obj) public static void Warning(object obj)
{ {
LogMessage_Impl(LogLevel.Warning, obj.ToString()); LogMessage_Impl(LogLevel.Warning, obj.ToString());
} }
/// <summary>
/// Serializes the given object (using <see cref="object.ToString"/>) and logs it as an error message.
/// </summary>
/// <param name="obj">The object to serialize.</param>
public static void Error(object obj) public static void Error(object obj)
{ {
LogMessage_Impl(LogLevel.Error, obj.ToString()); LogMessage_Impl(LogLevel.Error, obj.ToString());
} }
/// <summary>
/// Serializes the given object (using <see cref="object.ToString"/>) and logs it as a critical error message.
/// </summary>
/// <param name="obj">The object to serialize.</param>
public static void Critical(object obj) public static void Critical(object obj)
{ {
LogMessage_Impl(LogLevel.Critical, obj.ToString()); LogMessage_Impl(LogLevel.Critical, obj.ToString());
} }
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
public static extern string LogMessage_Impl(LogLevel logLevel, string message); private static extern string LogMessage_Impl(LogLevel logLevel, string message);
} }
+20 -13
View File
@@ -3,6 +3,9 @@ using System.Runtime.CompilerServices;
namespace GlitchyEngine.Math; namespace GlitchyEngine.Math;
/// <summary>
/// Provides constants and methods for trigonometric and vector calculations.
/// </summary>
public static class Math public static class Math
{ {
/// An optimal representation of π. /// An optimal representation of π.
@@ -89,28 +92,32 @@ public static class Math
#region modf / frac / trunc #region modf / frac / trunc
// Splits the value x into fractional and integer parts, each of which has the same sign as x. /// <summary>
/// Splits the value x into fractional and integer parts, each of which has the same sign as x.
/// </summary>
public static float modf(float x, out float integerPart) => ScriptGlue.modf_float(x, out integerPart); public static float modf(float x, out float integerPart) => ScriptGlue.modf_float(x, out integerPart);
// Splits the value x into fractional and integer parts, each of which has the same sign as x. /// <inheritdoc cref="modf(float,out float)"/>
public static float2 modf(float2 x, out float2 integerPart) => ScriptGlue.modf_float2(x, out integerPart); public static float2 modf(float2 x, out float2 integerPart) => ScriptGlue.modf_float2(x, out integerPart);
// Splits the value x into fractional and integer parts, each of which has the same sign as x. /// <inheritdoc cref="modf(float2,out float2)"/>
public static float3 modf(float3 x, out float3 integerPart) => ScriptGlue.modf_float3(x, out integerPart); public static float3 modf(float3 x, out float3 integerPart) => ScriptGlue.modf_float3(x, out integerPart);
// Splits the value x into fractional and integer parts, each of which has the same sign as x. /// <inheritdoc cref="modf(float2,out float2)"/>
public static float4 modf(float4 x, out float4 integerPart) => ScriptGlue.modf_float4(x, out integerPart); public static float4 modf(float4 x, out float4 integerPart) => ScriptGlue.modf_float4(x, out integerPart);
// Returns the fractional (or decimal) part of x; which is greater than or equal to 0 and less than 1. /// <summary>
/// Returns the fractional (or decimal) part of x; which is greater than or equal to 0 and less than 1.
/// </summary>
public static float frac(float x) => modf(x, out _); public static float frac(float x) => modf(x, out _);
// Returns the fractional (or decimal) part of x; which is greater than or equal to 0 and less than 1. /// <inheritdoc cref="frac(float)"/>
public static float2 frac(float2 x) => modf(x, out _); public static float2 frac(float2 x) => modf(x, out _);
// Returns the fractional (or decimal) part of x; which is greater than or equal to 0 and less than 1. /// <inheritdoc cref="frac(float)"/>
public static float3 frac(float3 x) => modf(x, out _); public static float3 frac(float3 x) => modf(x, out _);
// Returns the fractional (or decimal) part of x; which is greater than or equal to 0 and less than 1. /// <inheritdoc cref="frac(float)"/>
public static float4 frac(float4 x) => modf(x, out _); public static float4 frac(float4 x) => modf(x, out _);
+3
View File
@@ -1,5 +1,8 @@
namespace GlitchyEngine; namespace GlitchyEngine;
/// <summary>
/// An enum of all mouse buttons that can be queried using methods in <see cref="Input"/>.
/// </summary>
public enum MouseButton : byte public enum MouseButton : byte
{ {
None = 0, None = 0,
+4
View File
@@ -1,8 +1,12 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using GlitchyEngine.Components;
using GlitchyEngine.Core; using GlitchyEngine.Core;
namespace GlitchyEngine.Physics; namespace GlitchyEngine.Physics;
/// <summary>
/// Represents a collision that occurred between two rigid bodies.
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack=1)] [StructLayout(LayoutKind.Sequential, Pack=1)]
public struct Collision2D public struct Collision2D
{ {
@@ -0,0 +1,12 @@
using System;
namespace GlitchyEngine.Serialization;
/// <summary>
/// Specifies that the field is to be serialized.
/// </summary>
/// <seealso cref="DontSerializeFieldAttribute"/>
[AttributeUsage(AttributeTargets.Field)]
public sealed class SerializeFieldAttribute : Attribute
{
}