Refactor namespaces

- Rename `gaemstone.ECS` namespace inside
  of the main project to just `gaemstone`
- Rename `gaemstone.Flecs` to just `flecs`
- All built-in Flecs modules are now lower-case
- Add flecs.core.Observer tag
- Add flecs.system.System tag
main
copygirl 12 months ago
parent 47530de27e
commit 6b78cb2985
  1. 1
      src/Immersion/ManagedComponentTest.cs
  2. 4
      src/Immersion/ObserverTest.cs
  3. 12
      src/Immersion/Program.cs
  4. 2
      src/gaemstone.Bloxel/Client/Systems/ChunkMeshGenerator.cs
  5. 35
      src/gaemstone.Client/Systems/EntityInspector.cs
  6. 13
      src/gaemstone.Client/Systems/ImGuiManager.cs
  7. 23
      src/gaemstone.Client/Systems/InputManager.cs
  8. 9
      src/gaemstone.Client/Systems/Renderer.cs
  9. 3
      src/gaemstone.Client/Systems/TextureManager.cs
  10. 4
      src/gaemstone.Client/Systems/Windowing.cs
  11. 8
      src/gaemstone.SourceGen/ModuleGenerator.cs
  12. 6
      src/gaemstone.SourceGen/RelevantSymbolReceiver.cs
  13. 4
      src/gaemstone.SourceGen/Structure/MethodEntityInfo.cs
  14. 4
      src/gaemstone.SourceGen/Structure/ModuleEntityInfo.cs
  15. 12
      src/gaemstone.SourceGen/Structure/ParameterInfo.cs
  16. 17
      src/gaemstone/Doc+Extensions.cs
  17. 3
      src/gaemstone/Doc.cs
  18. 16
      src/gaemstone/Flecs/Core.cs
  19. 11
      src/gaemstone/Flecs/CoreDoc.cs
  20. 7
      src/gaemstone/Flecs/Doc.cs
  21. 7
      src/gaemstone/Flecs/Meta.cs
  22. 13
      src/gaemstone/Flecs/Metrics.cs
  23. 7
      src/gaemstone/Flecs/Monitor.cs
  24. 9
      src/gaemstone/Flecs/Pipeline.cs
  25. 9
      src/gaemstone/Flecs/Rest.cs
  26. 9
      src/gaemstone/Flecs/Script.cs
  27. 10
      src/gaemstone/Flecs/System.cs
  28. 9
      src/gaemstone/Flecs/Timer.cs
  29. 7
      src/gaemstone/Flecs/Units.cs
  30. 22
      src/gaemstone/Module+Attributes.cs
  31. 2
      src/gaemstone/Module+Components.cs
  32. 3
      src/gaemstone/Module.cs
  33. 2
      src/gaemstone/System+Terms.cs
  34. 2
      src/gaemstone/System.cs
  35. 16
      src/gaemstone/Universe+Modules.cs
  36. 12
      src/gaemstone/Universe.cs

@ -1,4 +1,5 @@
using System;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;

@ -1,7 +1,7 @@
using System;
using gaemstone.ECS;
using gaemstone;
using static flecs.core;
using static gaemstone.Bloxel.Components.CoreComponents;
using static gaemstone.Flecs.Core;
namespace Immersion;

@ -23,12 +23,12 @@ var universe = new Universe<Program>();
var world = universe.World;
// TODO: Figure out a nice way to get rid of "compile errors" here.
universe.Modules.Import<gaemstone.Flecs.Timer>();
universe.Modules.Import<gaemstone.Flecs.Script>();
universe.Modules.Import<gaemstone.Flecs.Rest>();
universe.Modules.Import<gaemstone.Flecs.Monitor>();
universe.Modules.Import<gaemstone.Flecs.Units>();
universe.Modules.Import<gaemstone.Flecs.Metrics>();
universe.Modules.Import<flecs.timer>();
universe.Modules.Import<flecs.script>();
universe.Modules.Import<flecs.rest>();
universe.Modules.Import<flecs.monitor>();
universe.Modules.Import<flecs.units>();
universe.Modules.Import<flecs.metrics>();
var window = Window.Create(WindowOptions.Default with {
Title = "gæmstone - Immersion",

@ -43,7 +43,7 @@ public partial class ChunkMeshGenerator
public static void GenerateChunkMeshes<T>(
World<T> world, Canvas canvas,
Entity<T> entity, in Chunk chunk, ChunkStoreBlocks blocks,
Has<BasicWorldGenerationDone> _1, Not<Mesh, Flecs.Core.Wildcard> _2)
Has<BasicWorldGenerationDone> _1, Not<Mesh, flecs.core.Wildcard> _2)
{
var result = Generate(world, canvas.GL, chunk.Position, blocks);
if (result is MeshHandle handle) {

@ -4,7 +4,6 @@ using System.Linq;
using System.Numerics;
using gaemstone.Client.Utility;
using gaemstone.ECS;
using gaemstone.Flecs;
using ImGuiNET;
using static gaemstone.Client.Systems.ImGuiManager;
using ImGuiInternal = ImGuiNET.Internal.ImGui;
@ -20,7 +19,7 @@ public partial class EntityInspector
public struct InspectorWindow { }
[Relation, Exclusive]
[Add<Core.OnDeleteTarget, Core.Delete>]
[Add<flecs.core.OnDeleteTarget, flecs.core.Delete>]
public struct Selected { }
[Tag]
@ -173,7 +172,7 @@ public partial class EntityInspector
if (!isOpen) window.Delete();
}
[Observer<Core.OnRemove>]
[Observer<flecs.core.OnRemove>]
public static void ClearStorageOnRemove<T>(Entity<T> _1, InspectorWindow _2)
{
// TODO: Clear out settings store for the window.
@ -197,9 +196,9 @@ public partial class EntityInspector
ImGui.TableSetupColumn("Entity", ImGuiTableColumnFlags.WidthFixed);
ImGui.TableNextColumn();
var hasExpanded = window.Has<Expanded, Core.Wildcard>();
var hasExpanded = window.Has<Expanded, flecs.core.Wildcard>();
if (IconButtonWithToolTip(ForkAwesome.Outdent, "Collapse all items in the Explorer View", hasExpanded))
window.Remove<Expanded, Core.Wildcard>();
window.Remove<Expanded, flecs.core.Wildcard>();
if (history != null) {
var hasPrev = ((selected != null) ? history.Current?.Prev : history.Current) != null;
@ -374,10 +373,10 @@ public partial class EntityInspector
// nullable, so let's be explicit about the type here.
var world = window.World;
var Wildcard = world.Entity<Core.Wildcard>().Value;
var Any = world.Entity<Core.Any>().Value;
var This = world.Entity<Core.This>().Value;
var Variable = world.Entity<Core.Variable>().Value;
var Wildcard = world.Entity<flecs.core.Wildcard>().Value;
var Any = world.Entity<flecs.core.Any>().Value;
var This = world.Entity<flecs.core.This>().Value;
var Variable = world.Entity<flecs.core.Variable>().Value;
bool IsSpecialEntity(Entity entity)
=> (entity == Wildcard) || (entity == Any)
|| (entity == This) || (entity == Variable);
@ -396,7 +395,7 @@ public partial class EntityInspector
for (var i = 0; i < iter.Count; i++) {
var entity = iter.Entity(i);
var count = IsSpecialEntity(entity) ? 0
: world.Pair<Core.ChildOf>(entity).Count;
: world.Pair<flecs.core.ChildOf>(entity).Count;
result.Add(new ExplorerEntry<T>(entity, count, isExpanded, isDisabled));
}
}
@ -480,7 +479,7 @@ public partial class EntityInspector
private static void ComponentsTab<T>(Entity<T> window, History? history, Entity<T>? sel)
{
if (sel is not Entity<T> selected) return;
var ChildOf = window.World.Entity<Core.ChildOf>();
var ChildOf = window.World.Entity<flecs.core.ChildOf>();
foreach (var id in selected.Type) {
// Hide ChildOf relations, as they are visible in the explorer.
if (id.IsPair && (id.Value.RelationUnsafe == ChildOf)) continue;
@ -492,8 +491,8 @@ public partial class EntityInspector
{
if (sel is not Entity<T> selected) return;
var world = window.World;
var ChildOf = world.Entity<Core.ChildOf>();
var Wildcard = world.Entity<Core.Wildcard>();
var ChildOf = world.Entity<flecs.core.ChildOf>();
var Wildcard = world.Entity<flecs.core.Wildcard>();
if (ImGui.CollapsingHeader($"As {ForkAwesome.Tag} Component", ImGuiTreeNodeFlags.DefaultOpen))
foreach (var iter in world.Term(new(selected)))
@ -631,7 +630,7 @@ public partial class EntityInspector
bool scrollTo = true) // Should entity be scrolled to in the explorer view?
{
if (entity is Entity<T> e1) window.Add<Selected>(e1);
else window.Remove<Selected, Core.Wildcard>();
else window.Remove<Selected, flecs.core.Wildcard>();
for (var p = entity?.Parent; p is Entity<T> parent; p = parent.Parent)
window.Add<Expanded>(parent);
@ -671,7 +670,7 @@ public partial class EntityInspector
private static (Entity<T>? DisplayType, float Priority) FindDisplayType<T>(Entity<T> entity)
{
var world = entity.World;
var component = world.Entity<Core.Component>();
var component = world.Entity<flecs.core.Component>();
var rule = (Rule<T>)(_findDisplayTypeRule ??= world.Rule(new(
$"$Type, gaemstone.Doc.DisplayType($Type)")));
@ -682,8 +681,8 @@ public partial class EntityInspector
foreach (var iter in rule.Iter().SetVar(rule.ThisVar!, entity))
for (var i = 0; i < iter.Count; i++) {
var type = iter.GetVar(typeVar);
if ((type == component) && (entity.GetOrNull<Core.Component>(component)?.Size == 0))
type = world.Entity<Core.Tag>();
if ((type == component) && (entity.GetOrNull<flecs.core.Component>(component)?.Size == 0))
type = world.Entity<flecs.core.Tag>();
var priority = type?.GetOrNull<Priority>()?.Value ?? float.MaxValue;
if (priority <= curPriority) { curType = type; curPriority = priority; }
}
@ -773,7 +772,7 @@ public partial class EntityInspector
if (isHeaderLike) pos.X += ImGui.GetStyle().FramePadding.X;
drawList.AddText(ImGui.GetFont(), ImGui.GetFontSize(), pos, color.RGBA, displayName);
if (!isHeaderLike && canClick && hovered) {
// Draw a hyperlink-link underscore.
// Draw a hyperlink-link undersflecs.core.
var p1 = pos + new Vector2( 0, size.Y - 1.75f);
var p2 = pos + new Vector2(size.X, size.Y - 1.75f);
if (docIcon != null) p1.X += ImGui.CalcTextSize($"{docIcon} ").X;

@ -5,7 +5,6 @@ using System.Text;
using gaemstone.Client.Utility;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using gaemstone.Flecs;
using ImGuiNET;
using Silk.NET.Input;
using Silk.NET.OpenGL.Extensions.ImGui;
@ -21,12 +20,12 @@ namespace gaemstone.Client.Systems;
[DependsOn<gaemstone.Client.Systems.Windowing>]
public partial class ImGuiManager
{
[Entity, Add<Pipeline.Phase>]
[DependsOn<Pipeline.OnLoad>]
[Entity, Add<flecs.pipeline.Phase>]
[DependsOn<flecs.pipeline.OnLoad>]
public struct ImGuiUpdatePhase { }
[Entity, Add<Pipeline.Phase>]
[DependsOn<Pipeline.OnStore>]
[Entity, Add<flecs.pipeline.Phase>]
[DependsOn<flecs.pipeline.OnStore>]
public struct ImGuiRenderPhase { }
[Singleton]
@ -85,7 +84,7 @@ public partial class ImGuiManager
}
[System]
[DependsOn<Pipeline.OnLoad>]
[DependsOn<flecs.pipeline.OnLoad>]
public static unsafe void Initialize<T>(World<T> world, GameWindow window, Canvas canvas,
[Source<Input>] InputContext inputContext, Not<ImGuiData> _)
=> world.Entity<ImGuiData>().Set(new ImGuiData(
@ -141,7 +140,7 @@ public partial class ImGuiManager
})));
[System]
[DependsOn<Pipeline.OnLoad>]
[DependsOn<flecs.pipeline.OnLoad>]
public static void UpdateMouse<T>(World<T> world,
[Source<Mouse>] MouseImpl impl, ImGuiData _)
{

@ -2,7 +2,6 @@ using System;
using System.Linq;
using System.Numerics;
using gaemstone.ECS;
using gaemstone.Flecs;
using Silk.NET.Input;
using static gaemstone.Client.Components.InputComponents;
using static gaemstone.Client.Systems.Windowing;
@ -21,7 +20,7 @@ public partial class InputManager
[Component] public record class GamepadImpl(IGamepad Value) { }
[System]
[DependsOn<Pipeline.OnLoad>]
[DependsOn<flecs.pipeline.OnLoad>]
public static void Initialize<T>(World<T> world,
GameWindow window, [Source<Input>] Not<InputContext> _)
{
@ -42,25 +41,25 @@ public partial class InputManager
}
[Observer<Core.OnAdd>]
[Observer<flecs.core.OnAdd>]
public static void OnCursorCaptured<T>(World<T> universe,
[Source<Input>] Has<CursorCapturedBy, Core.Wildcard> _)
[Source<Input>] Has<CursorCapturedBy, flecs.core.Wildcard> _)
=> universe.Entity<Mouse>().GetOrThrow<MouseImpl>()
.Value.Cursor.CursorMode = CursorMode.Raw;
[Observer<Core.OnRemove>]
[Observer<flecs.core.OnRemove>]
public static void OnCursorReleased<T>(World<T> universe,
[Source<Input>] Has<CursorCapturedBy, Core.Wildcard> _)
[Source<Input>] Has<CursorCapturedBy, flecs.core.Wildcard> _)
=> universe.Entity<Mouse>().GetOrThrow<MouseImpl>()
.Value.Cursor.CursorMode = CursorMode.Normal;
[System]
[DependsOn<Pipeline.OnLoad>]
[DependsOn<flecs.pipeline.OnLoad>]
public static void ProcessMouse<T>(TimeSpan delta, Entity<T> entity, MouseImpl impl)
{
var mouse = impl.Value;
var isCaptured = entity.Parent?.Has<CursorCapturedBy, Core.Any>() ?? false;
var isCaptured = entity.Parent?.Has<CursorCapturedBy, flecs.core.Any>() ?? false;
ref var position = ref entity.NewChild("Position").Build().GetMut<RawValue2D>();
ref var posDelta = ref entity.NewChild("Delta" ).Build().GetMut<RawValue2D>();
posDelta = mouse.Position - position;
@ -76,7 +75,7 @@ public partial class InputManager
}
[System]
[DependsOn<Pipeline.OnLoad>]
[DependsOn<flecs.pipeline.OnLoad>]
public static void ProcessKeyboard<T>(TimeSpan delta, Entity<T> entity, KeyboardImpl impl)
{
var keyboard = impl.Value;
@ -87,7 +86,7 @@ public partial class InputManager
}
[System]
[DependsOn<Pipeline.OnLoad>]
[DependsOn<flecs.pipeline.OnLoad>]
public static void ProcessGamepad<T>(TimeSpan delta, Entity<T> entity, GamepadImpl impl)
{
var gamepad = impl.Value;
@ -150,12 +149,12 @@ public partial class InputManager
// public static void OnActiveAdded(EntityRef entity, Active _)
// => entity.Add<Activated>();
// [Observer<Core.OnRemove>]
// [Observer<flecs.core.OnRemove>]
// public static void OnActiveRemoved<T>(Entity<T> entity, Active _)
// => entity.Add<Deactivated>();
// [System]
// [DependsOn<Pipeline.PostFrame>]
// [DependsOn<flecs.pipeline.PostFrame>]
// public static void ClearDeActivated<T>(Entity<T> entity, Has<Or<Activated, Deactivated>> _)
// => entity.Remove<Activated>().Remove<Deactivated>();
}

@ -4,7 +4,6 @@ using System.Numerics;
using System.Runtime.InteropServices;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using gaemstone.Flecs;
using Silk.NET.OpenGL;
using Silk.NET.Windowing;
using static gaemstone.Client.Components.CameraComponents;
@ -26,7 +25,7 @@ public partial class Renderer
private static int _modelMatrixUniform;
private static object? _renderEntityRule;
[Observer<Core.OnSet>]
[Observer<flecs.core.OnSet>]
public static void OnCanvasSet(Canvas canvas)
{
var GL = canvas.GL;
@ -55,7 +54,7 @@ public partial class Renderer
}
[System]
[DependsOn<Pipeline.PreStore>]
[DependsOn<flecs.pipeline.PreStore>]
public static void Clear(Canvas canvas)
{
var GL = canvas.GL;
@ -66,7 +65,7 @@ public partial class Renderer
}
[System]
[DependsOn<Pipeline.OnStore>]
[DependsOn<flecs.pipeline.OnStore>]
public static void Render<T>(World<T> world, Canvas canvas,
in GlobalTransform cameraTransform, in Camera camera, CameraViewport? viewport)
{
@ -128,7 +127,7 @@ public partial class Renderer
}
[System]
[DependsOn<Pipeline.PostFrame>]
[DependsOn<flecs.pipeline.PostFrame>]
public static void SwapBuffers(GameWindow window)
=> window.Handle.SwapBuffers();

@ -1,7 +1,6 @@
using System;
using System.IO;
using gaemstone.ECS;
using gaemstone.Flecs;
using Silk.NET.OpenGL;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
@ -17,7 +16,7 @@ namespace gaemstone.Client.Systems;
[DependsOn<gaemstone.Client.Systems.Windowing>]
public partial class TextureManager
{
[Observer<Core.OnSet>]
[Observer<flecs.core.OnSet>]
public static void OnCanvasSet(Canvas canvas)
{
var GL = canvas.GL;

@ -1,6 +1,4 @@
using System.Drawing;
using gaemstone.ECS;
using gaemstone.Flecs;
using Silk.NET.OpenGL;
using Silk.NET.Windowing;
@ -29,7 +27,7 @@ public partial class Windowing
}
[System]
[DependsOn<Pipeline.PreFrame>]
[DependsOn<flecs.pipeline.PreFrame>]
public static void ProcessWindow(GameWindow window, Canvas canvas)
{
canvas.Size = new(window.Handle.Size.X, window.Handle.Size.Y);

@ -81,8 +81,10 @@ public class ModuleGenerator
private void AppendHeader(StringBuilder sb, string @namespace)
=> sb.AppendLine($$"""
// <auto-generated/>
#pragma warning disable
using System.Collections.Generic;
using System.Collections.Immutable;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
@ -188,8 +190,8 @@ public class ModuleGenerator
sb.AppendLine($"\t\t\t.Symbol({e.EntitySymbol.ToStringLiteral()})");
// Tags and relations in Flecs are marked as empty components.
if (e.IsTag || e.IsRelation) sb.AppendLine("\t\t\t.Add<gaemstone.Flecs.Core.Component>()");
if (e.IsTag && e.IsRelation) sb.AppendLine("\t\t\t.Add<gaemstone.Flecs.Core.Tag>()");
if (e.IsTag || e.IsRelation) sb.AppendLine("\t\t\t.Add<flecs.core.Component>()");
if (e.IsTag && e.IsRelation) sb.AppendLine("\t\t\t.Add<flecs.core.Tag>()");
sb.Append( "\t\t\t");
if (!e.IsBuiltIn) sb.Append(".Build()");
@ -322,7 +324,7 @@ public class ModuleGenerator
// If system doesn't have an explicit phase set, default to OnUpdate.
if (e is MethodEntityInfo { IsSystem: true, HasPhaseSet: false })
sb.AppendLine($"\t\t{@var}.Add<gaemstone.Flecs.Core.DependsOn, gaemstone.Flecs.Pipeline.OnUpdate>();");
sb.AppendLine($"\t\t{@var}.Add<flecs.core.DependsOn, flecs.pipeline.OnUpdate>();");
}
}

@ -12,7 +12,7 @@ namespace gaemstone.SourceGen;
public class RelevantSymbolReceiver
: ISyntaxContextReceiver
{
// Attributes from gaemstone.ECS and gaemstone.Doc are considered.
// Attributes from gaemstone and gaemstone.Doc are considered.
private static readonly HashSet<string> RelevantAttributeNames = new(){
// Base entity attributes
"Module", // Can also be [Singleton]
@ -68,7 +68,7 @@ public class RelevantSymbolReceiver
Symbols.Add(symbol, symbol switch {
INamedTypeSymbol typeSymbol =>
typeSymbol.GetAttributes().Any(attr => attr.AttributeClass!
.GetFullName() == "gaemstone.ECS.ModuleAttribute")
.GetFullName() == "gaemstone.ModuleAttribute")
? new ModuleEntityInfo(typeSymbol)
: new TypeEntityInfo(typeSymbol),
IMethodSymbol methodSymbol => new MethodEntityInfo(methodSymbol),
@ -88,7 +88,7 @@ public class RelevantSymbolReceiver
var sep = name.LastIndexOf('.');
if (sep < 0) return null;
if (name.AsSpan()[..sep] is not ("gaemstone.ECS" or "gaemstone.Doc")) return null;
if (name.AsSpan()[..sep] is not ("gaemstone" or "gaemstone.Doc")) return null;
return name[(sep+1)..^"Attribute".Length];
}

@ -88,9 +88,9 @@ public class MethodEntityInfo : BaseEntityInfo
param.TermIndex = termIndex++;
// See if we have any [DependsOn<...>] attributes for this system.
// If not, ModuleGenerator will add [DependsOn<gaemstone.Flecs.Pipeline.OnUpdate>].
// If not, ModuleGenerator will add [DependsOn<flecs.pipeline.OnUpdate>].
HasPhaseSet = IsSystem && RelationsToAdd.Any(entry => entry.Relation
.GetFullName(FullNameStyle.NoGeneric) == "gaemstone.ECS.DependsOnAttribute");
.GetFullName(FullNameStyle.NoGeneric) == "gaemstone.DependsOnAttribute");
// TODO: Handle systems with [Source].
// TODO: Validate ObserverEvents.

@ -19,7 +19,7 @@ public class ModuleEntityInfo : TypeEntityInfo
IsPartial = classDecl.Modifiers.Any(t => t.IsKind(SyntaxKind.PartialKeyword));
HasLifetimeInterface = Symbol.AllInterfaces.Any(i =>
i.GetFullName(FullNameStyle.NoGeneric) == "gaemstone.ECS.IModuleLifetime");
i.GetFullName(FullNameStyle.NoGeneric) == "gaemstone.IModuleLifetime");
IsBuiltIn = Has("BuiltIn");
}
@ -38,7 +38,7 @@ public class ModuleEntityInfo : TypeEntityInfo
public IEnumerable<string> GetDependencies()
{
foreach (var (relation, target) in RelationsToAdd)
if (relation.GetFullName(FullNameStyle.NoGeneric) == "gaemstone.Flecs.Core.DependsOn")
if (relation.GetFullName(FullNameStyle.NoGeneric) == "flecs.core.DependsOn")
yield return GetModulePath(target);
}

@ -54,9 +54,9 @@ public class ParameterInfo : BaseInfo
}
else
{
IsOr = typeFullName.StartsWith("gaemstone.ECS.Or");
var isHas = typeFullName.StartsWith("gaemstone.ECS.Has");
var isNot = typeFullName.StartsWith("gaemstone.ECS.Not");
IsOr = typeFullName.StartsWith("gaemstone.Or");
var isHas = typeFullName.StartsWith("gaemstone.Has");
var isNot = typeFullName.StartsWith("gaemstone.Not");
if (IsGeneric)
{
@ -66,7 +66,7 @@ public class ParameterInfo : BaseInfo
// Has<...> usually doesn't support a generic type as its own type parameter.
// However, Has<Or<...>> is an exception to this rule, so we check for this here.
if (isHas && (args is [ INamedTypeSymbol { IsGenericType: true } argType ])
&& argType.GetFullName(FullNameStyle.NoGeneric) == "gaemstone.ECS.Or")
&& argType.GetFullName(FullNameStyle.NoGeneric) == "gaemstone.Or")
{
TermTypes = argType.TypeArguments.ToImmutableList();
FieldType = null;
@ -91,13 +91,13 @@ public class ParameterInfo : BaseInfo
// If the type of the parameter has the [Tag] attribute,
// the only way to sensibly use it is to check for its (non-)existance.
// (This would also apply to [Relation, Tag] but should be no issue.)
if (Symbol.Type.HasAttribute("gaemstone.ECS.TagAttribute")) isHas = true;
if (Symbol.Type.HasAttribute("gaemstone.TagAttribute")) isHas = true;
// TODO: Make sure [Tag] is used appropriately.
}
Source = Get("Source")?.AttributeClass!.TypeArguments[0]
// If the type of the parameter has the [Singleton] attribute, use it as the default Source.
?? ((FieldType?.HasAttribute("gaemstone.ECS.SingletonAttribute") == true) ? FieldType : null);
?? ((FieldType?.HasAttribute("gaemstone.SingletonAttribute") == true) ? FieldType : null);
Kind = isHas ? ParameterKind.Has
: isNot ? ParameterKind.Not

@ -1,6 +1,5 @@
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using gaemstone.Flecs;
using static flecs_hub.flecs;
namespace gaemstone;
@ -9,11 +8,11 @@ public static unsafe class DocExtensions
{
private static Entity<TContext> Set<TContext, T>(Entity<TContext> entity, string? value)
{
var id = entity.World.Pair<Flecs.Doc.Description, T>();
var id = entity.World.Pair<flecs.doc.Description, T>();
if (value != null) {
var str = GlobalHeapAllocator.Instance.AllocateCString(value);
var desc = new Flecs.Doc.Description { Value = (void*)(nint)str };
var desc = new flecs.doc.Description { Value = (void*)(nint)str };
entity.Set(id, desc);
} else {
entity.Remove(id);
@ -23,28 +22,28 @@ public static unsafe class DocExtensions
}
public static string? GetDocName<TContext>(this Entity<TContext> entity, bool fallbackToEntityName = true)
=> fallbackToEntityName || entity.Has<Flecs.Doc.Description, Core.Name>()
=> fallbackToEntityName || entity.Has<flecs.doc.Description, flecs.core.Name>()
? ecs_doc_get_name(entity.World, entity).FlecsToString() : null;
public static Entity<TContext> SetDocName<TContext>(this Entity<TContext> entity, string? value)
=> Set<TContext, Core.Name>(entity, value);
=> Set<TContext, flecs.core.Name>(entity, value);
public static string? GetDocBrief<TContext>(this Entity<TContext> entity)
=> ecs_doc_get_brief(entity.World, entity).FlecsToString()!;
public static Entity<TContext> SetDocBrief<TContext>(this Entity<TContext> entity, string? value)
=> Set<TContext, Flecs.Doc.Brief>(entity, value);
=> Set<TContext, flecs.doc.Brief>(entity, value);
public static string? GetDocDetail<TContext>(this Entity<TContext> entity)
=> ecs_doc_get_detail(entity.World, entity).FlecsToString()!;
public static Entity<TContext> SetDocDetail<TContext>(this Entity<TContext> entity, string? value)
=> Set<TContext, Flecs.Doc.Detail>(entity, value);
=> Set<TContext, flecs.doc.Detail>(entity, value);
public static string? GetDocLink<TContext>(this Entity<TContext> entity)
=> ecs_doc_get_link(entity.World, entity).FlecsToString()!;
public static Entity<TContext> SetDocLink<TContext>(this Entity<TContext> entity, string? value)
=> Set<TContext, Flecs.Doc.Link>(entity, value);
=> Set<TContext, flecs.doc.Link>(entity, value);
public static string? GetDocColor<TContext>(this Entity<TContext> entity)
=> ecs_doc_get_color(entity.World, entity).FlecsToString()!;
public static Entity<TContext> SetDocColor<TContext>(this Entity<TContext> entity, string? value)
=> Set<TContext, Flecs.Doc.Color>(entity, value);
=> Set<TContext, flecs.doc.Color>(entity, value);
}

@ -1,6 +1,3 @@
using gaemstone.ECS;
using static gaemstone.Flecs.Core;
namespace gaemstone;
[Module]

@ -1,21 +1,19 @@
using gaemstone;
using gaemstone.ECS;
namespace gaemstone.Flecs;
namespace flecs;
[BuiltIn, Module, Path("/flecs/core")]
public partial class Core
#pragma warning disable IDE1006 // Naming rule violation
#pragma warning disable CS8981 // Only contains lower-cased ascii characters
public partial class core
: IModuleImport
{
// Entity Tags
// TODO:
// [Tag] public struct Observer { }
// // Technically, this type should be in the Flecs.System addon,
// // but unfortunately due to language limitations, it has to reside here.
// [Tag, Path("/flecs/system/System")]
// public struct System { }
[Tag] public struct Observer { }
// TODO: Put back World?
[Tag] public struct Module { }
[Tag] public struct Private { }
[Tag] public struct Prefab { }

@ -1,14 +1,17 @@
using System.Runtime.InteropServices;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using static flecs_hub.flecs;
namespace gaemstone.Flecs;
namespace flecs;
[BuiltIn, Module, Path("/flecs/coredoc")]
[DependsOn<gaemstone.Flecs.Meta>]
[DependsOn<gaemstone.Flecs.Doc>]
public unsafe partial class CoreDoc
[DependsOn<flecs.meta>]
[DependsOn<flecs.doc>]
#pragma warning disable IDE1006 // Naming rule violation
#pragma warning disable CS8981 // Only contains lower-cased ascii characters
public unsafe partial class coredoc
: IModuleImport
{
static Entity<T> IModuleImport.Import<T>(World<T> world)

@ -1,12 +1,15 @@
using System.Runtime.InteropServices;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using static flecs_hub.flecs;
namespace gaemstone.Flecs;
namespace flecs;
[BuiltIn, Module, Path("/flecs/doc")]
public unsafe partial class Doc
#pragma warning disable IDE1006 // Naming rule violation
#pragma warning disable CS8981 // Only contains lower-cased ascii characters
public unsafe partial class doc
: IModuleImport
{
[Tag] public struct Brief { }

@ -1,12 +1,15 @@
using System.Runtime.InteropServices;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using static flecs_hub.flecs;
namespace gaemstone.Flecs;
namespace flecs;
[BuiltIn, Module, Path("/flecs/meta")]
public unsafe partial class Meta
#pragma warning disable IDE1006 // Naming rule violation
#pragma warning disable CS8981 // Only contains lower-cased ascii characters
public unsafe partial class meta
: IModuleImport
{
static Entity<T> IModuleImport.Import<T>(World<T> world)

@ -1,15 +1,18 @@
using System.Runtime.InteropServices;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using static flecs_hub.flecs;
namespace gaemstone.Flecs;
namespace flecs;
[BuiltIn, Module, Path("/flecs/timer")]
[DependsOn<gaemstone.Flecs.Pipeline>]
[DependsOn<gaemstone.Flecs.Meta>]
[DependsOn<gaemstone.Flecs.Units>]
public unsafe partial class Metrics
[DependsOn<flecs.pipeline>]
[DependsOn<flecs.meta>]
[DependsOn<flecs.units>]
#pragma warning disable IDE1006 // Naming rule violation
#pragma warning disable CS8981 // Only contains lower-cased ascii characters
public unsafe partial class metrics
: IModuleImport
{
static Entity<T> IModuleImport.Import<T>(World<T> world)

@ -1,12 +1,15 @@
using System.Runtime.InteropServices;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using static flecs_hub.flecs;
namespace gaemstone.Flecs;
namespace flecs;
[BuiltIn, Module, Path("/flecs/monitor")]
public unsafe partial class Monitor
#pragma warning disable IDE1006 // Naming rule violation
#pragma warning disable CS8981 // Only contains lower-cased ascii characters
public unsafe partial class monitor
: IModuleImport
{
static Entity<T> IModuleImport.Import<T>(World<T> world)

@ -1,13 +1,16 @@
using System.Runtime.InteropServices;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using static flecs_hub.flecs;
namespace gaemstone.Flecs;
namespace flecs;
[BuiltIn, Module, Path("/flecs/pipeline")]
[DependsOn<gaemstone.Flecs.System>]
public unsafe partial class Pipeline
[DependsOn<flecs.system>]
#pragma warning disable IDE1006 // Naming rule violation
#pragma warning disable CS8981 // Only contains lower-cased ascii characters
public unsafe partial class pipeline
: IModuleImport
{
[Entity] public struct Phase { }

@ -1,13 +1,16 @@
using System.Runtime.InteropServices;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using static flecs_hub.flecs;
namespace gaemstone.Flecs;
namespace flecs;
[BuiltIn, Module, Path("/flecs/rest")]
[DependsOn<gaemstone.Flecs.Pipeline>]
public unsafe partial class Rest
[DependsOn<flecs.pipeline>]
#pragma warning disable IDE1006 // Naming rule violation
#pragma warning disable CS8981 // Only contains lower-cased ascii characters
public unsafe partial class rest
: IModuleImport
{
static Entity<T> IModuleImport.Import<T>(World<T> world)

@ -1,13 +1,16 @@
using System.Runtime.InteropServices;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using static flecs_hub.flecs;
namespace gaemstone.Flecs;
namespace flecs;
[BuiltIn, Module, Path("/flecs/script")]
[DependsOn<gaemstone.Flecs.Meta>]
public unsafe partial class Script
[DependsOn<flecs.meta>]
#pragma warning disable IDE1006 // Naming rule violation
#pragma warning disable CS8981 // Only contains lower-cased ascii characters
public unsafe partial class script
: IModuleImport
{
static Entity<T> IModuleImport.Import<T>(World<T> world)

@ -1,14 +1,20 @@
using System.Runtime.InteropServices;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using static flecs_hub.flecs;
namespace gaemstone.Flecs;
namespace flecs;
[BuiltIn, Module, Path("/flecs/system")]
public unsafe partial class System
#pragma warning disable IDE1006 // Naming rule violation
#pragma warning disable CS8981 // Only contains lower-cased ascii characters
public unsafe partial class system
: IModuleImport
{
[Tag]
public struct System { }
static Entity<T> IModuleImport.Import<T>(World<T> world)
{
using var alloc = TempAllocator.Use();

@ -1,13 +1,16 @@
using System.Runtime.InteropServices;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using static flecs_hub.flecs;
namespace gaemstone.Flecs;
namespace flecs;
[BuiltIn, Module, Path("/flecs/timer")]
[DependsOn<gaemstone.Flecs.Pipeline>]
public unsafe partial class Timer
[DependsOn<flecs.pipeline>]
#pragma warning disable IDE1006 // Naming rule violation
#pragma warning disable CS8981 // Only contains lower-cased ascii characters
public unsafe partial class timer
: IModuleImport
{
static Entity<T> IModuleImport.Import<T>(World<T> world)

@ -1,12 +1,15 @@
using System.Runtime.InteropServices;
using gaemstone;
using gaemstone.ECS;
using gaemstone.ECS.Utility;
using static flecs_hub.flecs;
namespace gaemstone.Flecs;
namespace flecs;
[BuiltIn, Module, Path("/flecs/units")]
public unsafe partial class Units
#pragma warning disable IDE1006 // Naming rule violation
#pragma warning disable CS8981 // Only contains lower-cased ascii characters
public unsafe partial class units
: IModuleImport
{
static Entity<T> IModuleImport.Import<T>(World<T> world)

@ -1,7 +1,6 @@
using System;
using static gaemstone.Flecs.Core;
namespace gaemstone.ECS;
namespace gaemstone;
/// <summary>
/// Entities marked with this attribute are automatically registered with a
@ -57,13 +56,22 @@ public class SetAttribute<TComponent> : Attribute
/// <seealso cref="IsA"/>
public class IsAAttribute<TTarget> : AddAttribute<IsA, TTarget> { }
public class IsAAttribute<TTarget>
: AddAttribute<flecs.core.IsA, TTarget> { }
/// <seealso cref="ChildOf"/>
public class ChildOfAttribute<TTarget> : AddAttribute<ChildOf, TTarget> { }
public class ChildOfAttribute<TTarget>
: AddAttribute<flecs.core.ChildOf, TTarget> { }
/// <seealso cref="DependsOn"/>
public class DependsOnAttribute<TTarget> : AddAttribute<DependsOn, TTarget> { }
public class DependsOnAttribute<TTarget>
: AddAttribute<flecs.core.DependsOn, TTarget> { }
/// <seealso cref="Exclusive"/>
public class ExclusiveAttribute : AddAttribute<Exclusive> { }
public class ExclusiveAttribute
: AddAttribute<flecs.core.Exclusive> { }
/// <seealso cref="With"/>
public class WithAttribute<TTarget> : AddAttribute<With, TTarget> { }
public class WithAttribute<TTarget>
: AddAttribute<flecs.core.With, TTarget> { }

@ -1,6 +1,6 @@
using System;
namespace gaemstone.ECS;
namespace gaemstone;
/// <summary> Use a custom name or path for this entity instead of the type's name. </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct

@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
using gaemstone.ECS;
namespace gaemstone.ECS;
namespace gaemstone;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
public class ModuleAttribute : SingletonAttribute { }

@ -1,7 +1,7 @@
using System;
using gaemstone.Utility;
namespace gaemstone.ECS;
namespace gaemstone;
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)]
public class SourceAttribute<T> : Attribute { }

@ -1,6 +1,6 @@
using System;
namespace gaemstone.ECS;
namespace gaemstone;
[AttributeUsage(AttributeTargets.Method)]
public class SystemAttribute : Attribute { }

@ -1,7 +1,5 @@
using System;
using gaemstone.ECS;
using static gaemstone.Flecs.Core;
using Module = gaemstone.Flecs.Core.Module;
namespace gaemstone;
@ -54,20 +52,24 @@ public class ModuleManager<TContext>
$"Unexpected operation, {T.Path} is a built-in module");
var builder = World.New(T.Path)
.Add<Module>().Add<Disabled>()
.Add<flecs.core.Module>()
.Add<flecs.core.Disabled>()
.Set<IModuleInfo>(new ModuleInfo<T>());
foreach (var depPath in T.Dependencies) {
var dependency = World.LookupPathOrNull(depPath) ??
World.New(depPath).Add<Module>().Add<Disabled>().Build();
builder.Add<DependsOn>(dependency);
var dependency = World.LookupPathOrNull(depPath)
?? World.New(depPath)
.Add<flecs.core.Module>()
.Add<flecs.core.Disabled>()
.Build();
builder.Add<flecs.core.DependsOn>(dependency);
}
var module = builder.Build().CreateLookup<T>();
// Ensure all parent entities have the Module tag set.
for (var p = module.Parent; p is Entity<TContext> parent; p = parent.Parent)
parent.Add<Module>();
parent.Add<flecs.core.Module>();
Console.WriteLine($"Registered module {module.Path}");

@ -17,14 +17,14 @@ public class Universe<TContext>
.CreateLookup<Doc.Relation>();
// Bootstrap core module from Flecs.
Modules.Import<Flecs.Core>();
Modules.Import<flecs.core>();
// Import addon modules from Flecs we use for the engine.
Modules.Import<Flecs.System>();
Modules.Import<Flecs.Pipeline>();
Modules.Import<Flecs.Meta>();
Modules.Import<Flecs.Doc>();
Modules.Import<Flecs.CoreDoc>();
Modules.Import<flecs.system>();
Modules.Import<flecs.pipeline>();
Modules.Import<flecs.meta>();
Modules.Import<flecs.doc>();
Modules.Import<flecs.coredoc>();
Modules.Register<Doc>();
}

Loading…
Cancel
Save