mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Documentation
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using GlitchyEngine.Components;
|
||||
using GlitchyEngine.Math;
|
||||
|
||||
namespace GlitchyEngine;
|
||||
namespace GlitchyEngine.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Rigid body component for 2D physics.
|
||||
/// </summary>
|
||||
public class Rigidbody2D : Component
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -4,8 +4,16 @@ using GlitchyEngine.Math;
|
||||
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the translation (position) of the entity.
|
||||
/// </summary>
|
||||
public float3 Translation
|
||||
{
|
||||
get
|
||||
@@ -13,9 +21,6 @@ public class Transform : Component
|
||||
ScriptGlue.Transform_GetTranslation(Entity.UUID, out float3 translation);
|
||||
return translation;
|
||||
}
|
||||
set
|
||||
{
|
||||
ScriptGlue.Transform_SetTranslation(Entity.UUID, in value);
|
||||
}
|
||||
set => ScriptGlue.Transform_SetTranslation(Entity.UUID, in value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
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
|
||||
{
|
||||
protected internal UUID _uuid;
|
||||
|
||||
/// <summary>
|
||||
/// UUID used for identifying the object in the engine.
|
||||
/// UUID (Universally Unique Identifier) used for identifying the object in the engine.
|
||||
/// </summary>
|
||||
public UUID UUID => _uuid;
|
||||
|
||||
|
||||
+12
-1
@@ -7,13 +7,24 @@ public struct 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)
|
||||
{
|
||||
_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()
|
||||
{
|
||||
ScriptGlue.UUID_CreateNew(out UUID id);
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
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
|
||||
{
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ using System;
|
||||
|
||||
namespace GlitchyEngine.Editor;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the visibility of a button.
|
||||
/// </summary>
|
||||
public enum ButtonVisibility
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -4,6 +4,10 @@ using System.Text;
|
||||
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
+14
-8
@@ -12,7 +12,8 @@ namespace GlitchyEngine;
|
||||
public class Entity : EngineObject
|
||||
{
|
||||
/// <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>
|
||||
protected Entity()
|
||||
{
|
||||
@@ -31,7 +32,7 @@ public class Entity : EngineObject
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Entity.
|
||||
/// Creates a new Entity with the specified components attached to it.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the new entity.</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>
|
||||
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)]
|
||||
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)]
|
||||
public bool HasComponent(Type type) => ScriptGlue.Entity_HasComponent(_uuid, type);
|
||||
|
||||
@@ -240,14 +249,11 @@ public class Entity : EngineObject
|
||||
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 Vector3 Translation
|
||||
//{
|
||||
// get => Transform.Translation;
|
||||
// set => Transform.Translation = value;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the first entity with the given name.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,8 +3,17 @@ using System.Linq;
|
||||
|
||||
namespace GlitchyEngine.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extends the <see cref="IEnumerable{T}"/>-interface with useful methods.
|
||||
/// </summary>
|
||||
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)
|
||||
=> self.Select((item, index) => (item, index));
|
||||
}
|
||||
@@ -5,6 +5,9 @@ using System.Text;
|
||||
|
||||
namespace GlitchyEngine.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extends the <see cref="FieldInfo"/>-class with useful methods.
|
||||
/// </summary>
|
||||
public static class FieldInfoExtension
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -2,26 +2,75 @@
|
||||
|
||||
namespace GlitchyEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Provides methods to query the state of the input devices.
|
||||
/// </summary>
|
||||
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)]
|
||||
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)]
|
||||
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)]
|
||||
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)]
|
||||
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)]
|
||||
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)]
|
||||
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)]
|
||||
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)]
|
||||
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)]
|
||||
public static extern bool IsMouseButtonReleasing(MouseButton mouseButton);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
namespace GlitchyEngine;
|
||||
|
||||
/// <summary>
|
||||
/// An enum of all keys that can be queried using methods in <see cref="Input"/>.
|
||||
/// </summary>
|
||||
public enum Key
|
||||
{
|
||||
// Based on Win32 Virtual Keys
|
||||
|
||||
+48
-2
@@ -7,7 +7,10 @@ namespace GlitchyEngine;
|
||||
/// </summary>
|
||||
public class Log
|
||||
{
|
||||
public enum LogLevel
|
||||
/// <summary>
|
||||
/// The severity of the log message.
|
||||
/// </summary>
|
||||
private enum LogLevel
|
||||
{
|
||||
Trace = 0,
|
||||
Debug,
|
||||
@@ -18,53 +21,96 @@ public class Log
|
||||
Off
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs a trace message.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to log.</param>
|
||||
public static void Trace(string 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
LogMessage_Impl(LogLevel.Critical, obj.ToString());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
public static extern string LogMessage_Impl(LogLevel logLevel, string message);
|
||||
private static extern string LogMessage_Impl(LogLevel logLevel, string message);
|
||||
}
|
||||
|
||||
+15
-8
@@ -3,6 +3,9 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace GlitchyEngine.Math;
|
||||
|
||||
/// <summary>
|
||||
/// Provides constants and methods for trigonometric and vector calculations.
|
||||
/// </summary>
|
||||
public static class Math
|
||||
{
|
||||
/// An optimal representation of π.
|
||||
@@ -89,28 +92,32 @@ public static class Math
|
||||
|
||||
#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);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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 _);
|
||||
|
||||
// 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 _);
|
||||
|
||||
// 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 _);
|
||||
|
||||
// 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 _);
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
namespace GlitchyEngine;
|
||||
|
||||
/// <summary>
|
||||
/// An enum of all mouse buttons that can be queried using methods in <see cref="Input"/>.
|
||||
/// </summary>
|
||||
public enum MouseButton : byte
|
||||
{
|
||||
None = 0,
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using GlitchyEngine.Components;
|
||||
using GlitchyEngine.Core;
|
||||
|
||||
namespace GlitchyEngine.Physics;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a collision that occurred between two rigid bodies.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack=1)]
|
||||
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
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user