Skip to content

Commit

Permalink
Split Ecs class into different files
Browse files Browse the repository at this point in the history
  • Loading branch information
BeanCheeseBurrito committed Apr 12, 2024
1 parent 377d025 commit 93986a2
Show file tree
Hide file tree
Showing 9 changed files with 525 additions and 504 deletions.
503 changes: 0 additions & 503 deletions src/Flecs.NET/Core/Ecs.cs → src/Flecs.NET/Core/Ecs/Aliases.cs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/Flecs.NET/Core/Ecs/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Flecs.NET.Core
{
public static partial class Ecs
{
/// <summary>
/// Default path separator.
/// </summary>
public const string DefaultSeparator = ".";

/// <summary>
/// Default path root.
/// </summary>
public const string DefaultRootSeparator = "::";
}
}
91 changes: 91 additions & 0 deletions src/Flecs.NET/Core/Ecs/Debug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace Flecs.NET.Core
{
public static partial class Ecs
{
#if NETCOREAPP3_0_OR_GREATER
/// <summary>
/// Debug assert.
/// </summary>
/// <param name="condition"></param>
/// <param name="message"></param>
/// <param name="line"></param>
/// <param name="member"></param>
/// <param name="file"></param>
/// <param name="conditionStr"></param>
[Conditional("DEBUG")]
public static void Assert(
bool condition,
string message = "",
[CallerLineNumber] int line = default,
[CallerMemberName] string member = "",
[CallerFilePath] string file = "",
[CallerArgumentExpression("condition")] string conditionStr = "")
{
if (condition)
return;

throw new AssertionException($"\n[Flecs.NET Assertion Failed]: {member}, Line {line}, {file}\n[Condition]: {conditionStr}\n[Assertion Message]: {message}");
}

/// <summary>
/// Debug assert.
/// </summary>
/// <param name="message"></param>
/// <param name="line"></param>
/// <param name="member"></param>
/// <param name="file"></param>
[Conditional("DEBUG")]
public static void Error(
string message = "",
[CallerLineNumber] int line = default,
[CallerMemberName] string member = "",
[CallerFilePath] string file = "")
{
throw new ErrorException($"\n[Flecs.NET Error]: {member}, Line {line}, {file}\n[Error Message]: {message}");
}
#else
/// <summary>
/// Debug assert.
/// </summary>
/// <param name="condition"></param>
/// <param name="message"></param>
/// <param name="line"></param>
/// <param name="member"></param>
/// <param name="file"></param>
[Conditional("DEBUG")]
public static void Assert(
bool condition,
string message = "",
[CallerLineNumber] int line = default,
[CallerMemberName] string member = "",
[CallerFilePath] string file = "")
{
if (condition)
return;

throw new AssertionException(
$"\n[Flecs.NET Assertion Failed]: {member}, Line {line}, {file}\n[Assertion Message]: {message}");
}

/// <summary>
/// Debug assert.
/// </summary>
/// <param name="message"></param>
/// <param name="line"></param>
/// <param name="member"></param>
/// <param name="file"></param>
[Conditional("DEBUG")]
public static void Error(
string message = "",
[CallerLineNumber] int line = default,
[CallerMemberName] string member = "",
[CallerFilePath] string file = "")
{
throw new ErrorException($"\n[Flecs.NET Error]: {member}, Line {line}, {file}\n[Error Message]: {message}");
}
#endif
}
}
137 changes: 137 additions & 0 deletions src/Flecs.NET/Core/Ecs/Delegates.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using System;
using static Flecs.NET.Bindings.Native;

namespace Flecs.NET.Core
{
public static unsafe partial class Ecs
{
/// <summary>
/// App init action.
/// </summary>
public delegate int AppInitAction(ecs_world_t* world);

/// <summary>
/// Context free.
/// </summary>
public delegate void ContextFree(void* ctx);

/// <summary>
/// Copy type hook callback.
/// </summary>
public delegate void CopyCallback(void* src, void* dst, int count, ecs_type_info_t* typeInfo);

/// <summary>
/// Copy type hook callback.
/// </summary>
/// <typeparam name="T"></typeparam>
public delegate void CopyCallback<T>(ref T src, ref T dst, TypeInfo typeInfo);

/// <summary>
/// Ctor type hook callback.
/// </summary>
public delegate void CtorCallback(void* data, int count, ecs_type_info_t* typeInfo);

/// <summary>
/// Ctor type hook callback.
/// </summary>
/// <typeparam name="T"></typeparam>
public delegate void CtorCallback<T>(ref T data, TypeInfo typeInfo);

/// <summary>
/// Dtor type hook callback.
/// </summary>
public delegate void DtorCallback(void* data, int count, ecs_type_info_t* typeInfo);

/// <summary>
/// Dtor type hook callback.
/// </summary>
/// <typeparam name="T"></typeparam>
public delegate void DtorCallback<T>(ref T data, TypeInfo typeInfo);

/// <summary>
/// Each entity callback.
/// </summary>
public delegate void EachEntityCallback(Entity entity);

/// <summary>
/// Each id callback.
/// </summary>
public delegate void EachIdCallback(Id id);

/// <summary>
/// Each index callback.
/// </summary>
public delegate void EachIndexCallback(Iter it, int i);

/// <summary>
/// Finish action.
/// </summary>
public delegate void FiniAction(ecs_world_t* world, void* ctx);

/// <summary>
/// Free.
/// </summary>
public delegate void Free(IntPtr data);

/// <summary>
/// GroupBy action.
/// </summary>
public delegate ulong GroupByAction(ecs_world_t* world, ecs_table_t* table, ulong groupId, void* ctx);

/// <summary>
/// GroupBy action.
/// </summary>
public delegate ulong GroupByCallback(World world, Table table, Entity group);

/// <summary>
/// Group create action.
/// </summary>
public delegate void* GroupCreateAction(ecs_world_t* world, ulong groupId, void* groupByCtx);

/// <summary>
/// Group delete action.
/// </summary>
public delegate void GroupDeleteAction(ecs_world_t* world, ulong groupId, void* groupCtx, void* groupByCtx);

/// <summary>
/// Iter action.
/// </summary>
public delegate void IterAction(ecs_iter_t* it);

/// <summary>
/// Iter callback.
/// </summary>
public delegate void IterCallback(Iter it);

/// <summary>
/// Iter next action.
/// </summary>
public delegate byte IterNextAction(ecs_iter_t* it);

/// <summary>
/// Move type hook callback.
/// </summary>
public delegate void MoveCallback(void* src, void* dst, int count, ecs_type_info_t* typeInfo);

/// <summary>
/// Move type hook callback.
/// </summary>
/// <typeparam name="T"></typeparam>
public delegate void MoveCallback<T>(ref T src, ref T dst, TypeInfo typeInfo);

/// <summary>
/// OrderBy action.
/// </summary>
public delegate int OrderByAction(ulong e1, void* ptr1, ulong e2, void* ptr2);

/// <summary>
/// A callback that takes a reference to a world.
/// </summary>
public delegate void WorldCallback(ref World world);

/// <summary>
/// A callback that takes a reference to a term.
/// </summary>
public delegate void TermCallback(ref Term term);
}
}
33 changes: 33 additions & 0 deletions src/Flecs.NET/Core/Ecs/Doc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using static Flecs.NET.Bindings.Native;

namespace Flecs.NET.Core
{
public static partial class Ecs
{
/// <summary>
/// Utilities for documenting entities, components and systems.
/// </summary>
public static class Doc
{
/// <summary>
/// Reference to <see cref="EcsDocBrief"/>.
/// </summary>
public static ref ulong Brief => ref EcsDocBrief;

/// <summary>
/// Reference to <see cref="EcsDocDetail"/>.
/// </summary>
public static ref ulong Detail => ref EcsDocDetail;

/// <summary>
/// Reference to <see cref="EcsDocLink"/>.
/// </summary>
public static ref ulong Link => ref EcsDocLink;

/// <summary>
/// Reference to <see cref="EcsDocColor"/>.
/// </summary>
public static ref ulong Color => ref EcsDocColor;
}
}
}
5 changes: 5 additions & 0 deletions src/Flecs.NET/Core/Ecs/Ecs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Flecs.NET.Core
{
///
public static partial class Ecs { }
}
100 changes: 100 additions & 0 deletions src/Flecs.NET/Core/Ecs/Exceptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;

namespace Flecs.NET.Core
{
public static partial class Ecs
{
/// <summary>
/// Flecs.NET assertion exception.
/// </summary>
[Serializable]
public class AssertionException : Exception
{
/// <summary>
///
/// </summary>
public AssertionException()
{
}

/// <summary>
///
/// </summary>
/// <param name="message"></param>
public AssertionException(string message) : base(message)
{
}

/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <param name="innerException"></param>
public AssertionException(string message, Exception innerException) : base(message, innerException)
{
}
}

/// <summary>
/// Flecs.NET error exception.
/// </summary>
[Serializable]
public class ErrorException : Exception
{
/// <summary>
///
/// </summary>
public ErrorException()
{
}

/// <summary>
///
/// </summary>
/// <param name="message"></param>
public ErrorException(string message) : base(message)
{
}

/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <param name="innerException"></param>
public ErrorException(string message, Exception innerException) : base(message, innerException)
{
}
}

/// <summary>
/// Flecs native exception.
/// </summary>
[Serializable]
public class NativeException : Exception
{
/// <summary>
///
/// </summary>
public NativeException()
{
}

/// <summary>
///
/// </summary>
/// <param name="message"></param>
public NativeException(string message) : base(message)
{
}

/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <param name="innerException"></param>
public NativeException(string message, Exception innerException) : base(message, innerException)
{
}
}
}
}
Loading

0 comments on commit 93986a2

Please sign in to comment.