Replace [Symbol] with [Public] and [Private]

wip/source-generators
copygirl 1 year ago
parent 03d672febf
commit 976d9fd326
  1. 6
      src/gaemstone.Bloxel/Components/CoreComponents.cs
  2. 4
      src/gaemstone.Bloxel/Systems/BasicWorldGenerator.cs
  3. 26
      src/gaemstone.Client/Components/InputComponents.cs
  4. 8
      src/gaemstone.Client/Components/RenderingComponents.cs
  5. 8
      src/gaemstone.Client/Components/ResourceComponents.cs
  6. 11
      src/gaemstone.SourceGen/Generators/AutoRegisterComponentsGenerator.cs
  7. 4
      src/gaemstone/Components/TransformComponents.cs
  8. 18
      src/gaemstone/ECS/Module+Attributes.cs

@ -2,17 +2,17 @@ using gaemstone.ECS;
namespace gaemstone.Bloxel.Components;
[Module]
[Public, Module]
public partial class CoreComponents
{
[Symbol, Component]
[Component]
public readonly struct Chunk
{
public ChunkPos Position { get; }
public Chunk(ChunkPos pos) => Position = pos;
}
[Symbol, Component]
[Component]
public class ChunkStoreBlocks
: ChunkPaletteStorage<Entity>
{

@ -6,7 +6,7 @@ using static gaemstone.Bloxel.Constants;
namespace gaemstone.Bloxel.Systems;
[Module]
[Public, Module]
[DependsOn<gaemstone.Bloxel.Components.CoreComponents>]
public partial class BasicWorldGenerator
{
@ -22,7 +22,7 @@ public partial class BasicWorldGenerator
_noise.SetFractalGain(0.6f);
}
[Symbol, Tag]
[Tag]
public struct HasBasicWorldGeneration { }
[System]

@ -4,33 +4,33 @@ using gaemstone.ECS;
namespace gaemstone.Client.Components;
[Module]
[Public, Module]
public partial class InputComponents
{
[Symbol, Entity, Path("/Input")]
[Entity, Path("/Input")]
[Add<Input>]
public struct Input { }
[Symbol, Entity, Path("/Input/Mouse")]
[Entity, Path("/Input/Mouse")]
[Add<Mouse>]
public struct Mouse { }
[Symbol, Entity, Path("/Input/Keyboard")]
[Entity, Path("/Input/Keyboard")]
[Add<Keyboard>]
public struct Keyboard { }
[Symbol, Tag]
[Tag]
public struct Gamepad { }
/// <summary> Present on inputs / actions that are currently active. </summary>
[Symbol, Component] public struct Active { public TimeSpan Duration; }
[Component] public struct Active { public TimeSpan Duration; }
/// <summary> Present on inputs / actions were activated this frame. </summary>
[Symbol, Tag] public struct Activated { }
[Tag] public struct Activated { }
/// <summary> Present on inputs / actions were deactivated this frame. </summary>
[Symbol, Tag] public struct Deactivated { }
[Tag] public struct Deactivated { }
/// <summary>
@ -41,7 +41,7 @@ public partial class InputComponents
/// This is set if a UI element is focused that captures
/// navigational or text input.
/// </remarks>
[Symbol, Relation, Tag, Exclusive]
[Relation, Tag, Exclusive]
public struct InputCapturedBy { }
/// <summary>
@ -52,7 +52,7 @@ public partial class InputComponents
/// This could for example include the mouse currently being over
/// a UI element, preventing the game from handling mouse input.
/// </remarks>
[Symbol, Relation, Tag, Exclusive]
[Relation, Tag, Exclusive]
public struct MouseInputCapturedBy { }
/// <summary>
@ -62,13 +62,13 @@ public partial class InputComponents
/// <remarks>
/// This is set when a camera controller assumes control of the mouse.
/// </remarks>
[Symbol, Relation, Tag, Exclusive]
[Relation, Tag, Exclusive]
[With<InputCapturedBy>]
[With<MouseInputCapturedBy>]
public struct CursorCapturedBy { }
[Component]
[Private, Component]
internal readonly struct RawValue1D
{
private readonly float _value;
@ -78,7 +78,7 @@ public partial class InputComponents
public static implicit operator RawValue1D(float value) => new(value);
}
[Component]
[Private, Component]
internal readonly struct RawValue2D
{
private readonly Vector2 _value;

@ -5,10 +5,10 @@ using Silk.NET.OpenGL;
namespace gaemstone.Client.Components;
[Module]
[Public, Module]
public partial class RenderingComponents
{
[Symbol, Component]
[Component]
public readonly struct MeshHandle
{
public uint Handle { get; }
@ -19,7 +19,7 @@ public partial class RenderingComponents
{ Handle = handle; Count = count; IsIndexed = indexed; }
}
[Symbol, Component]
[Component]
public readonly struct TextureHandle
{
public TextureTarget Target { get; }
@ -29,7 +29,7 @@ public partial class RenderingComponents
=> (Target, Handle) = (target, handle);
}
[Symbol, Component]
[Component]
public readonly struct TextureCoords4
{
public Vector2 TopLeft { get; }

@ -2,10 +2,10 @@ using gaemstone.ECS;
namespace gaemstone.Client.Components;
[Module]
[Public, Module]
public partial class ResourceComponents
{
[Symbol, Tag]
[Tag]
public struct Resource { }
// Entities can have for example Texture as a tag, in which case
@ -14,9 +14,9 @@ public partial class ResourceComponents
// Entities can also have a (Texture, $T) pair where $T is a resource,
// meaning the entity has that resource assigned as their texture.
[Symbol, Relation, Tag, IsA<Resource>]
[Relation, Tag, IsA<Resource>]
public struct Texture { }
[Symbol, Relation, Tag, IsA<Resource>]
[Relation, Tag, IsA<Resource>]
public struct Mesh { }
}

@ -9,6 +9,8 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace gaemstone.SourceGen.Generators;
// TODO: "Jump to Definition" feature to open the file + line in which a module / component / system is defined.
[Generator]
public partial class AutoRegisterComponentsGenerator
: ISourceGenerator
@ -158,7 +160,7 @@ public partial class AutoRegisterComponentsGenerator
var @var = $"entity{c.Name}";
var path = (c.Path ?? c.Name).ToStringLiteral();
sb.AppendLine($$""" var {{ @var }} = world.New(module, {{ path }})""");
if (c.IsSymbol) sb.AppendLine($$""" .Symbol("{{ c.Name }}")""");
if (c.IsPublic) sb.AppendLine($$""" .Symbol("{{ c.Name }}")""");
if (c.IsRelation) sb.AppendLine($$""" .Add<gaemstone.Doc.Relation>()""");
if (c.IsTag) sb.AppendLine($$""" .Add<gaemstone.Flecs.Core.Tag>()""");
if (c.IsComponent) sb.AppendLine($$""" .Build().InitComponent<{{ c.Name }}>()""");
@ -194,6 +196,7 @@ public partial class AutoRegisterComponentsGenerator
public List<ComponentInfo> Components { get; } = new();
public string? Path { get; }
public bool IsPublic { get; }
public bool IsStatic => Symbol.IsStatic;
public ModuleInfo(INamedTypeSymbol symbol)
@ -201,6 +204,7 @@ public partial class AutoRegisterComponentsGenerator
Symbol = symbol;
Path = symbol.GetAttribute("gaemstone.ECS.PathAttribute")?
.ConstructorArguments.FirstOrDefault().Value as string;
IsPublic = symbol.HasAttribute("gaemstone.ECS.PublicAttribute");
}
}
@ -215,7 +219,7 @@ public partial class AutoRegisterComponentsGenerator
public List<(ITypeSymbol, ITypeSymbol)> RelationsToAdd { get; }
public string? Path { get; }
public bool IsSymbol { get; } // TODO: Get rid of this.
public bool IsPublic { get; }
public bool IsRelation { get; }
public bool IsTag => (Type is RegisterType.Tag);
public bool IsComponent => (Type is RegisterType.Component
@ -235,7 +239,8 @@ public partial class AutoRegisterComponentsGenerator
Path = symbol.GetAttribute("gaemstone.ECS.PathAttribute")?
.ConstructorArguments.FirstOrDefault().Value as string;
IsSymbol = symbol.HasAttribute("gaemstone.ECS.SymbolAttribute");
IsPublic = symbol.HasAttribute("gaemstone.ECS.PublicAttribute")
|| (Module.IsPublic && !symbol.HasAttribute("gaemstone.ECS.PrivateAttribute"));
IsRelation = symbol.HasAttribute("gaemstone.ECS.RelationAttribute");
SingletonAddSelf = IsSingleton

@ -3,10 +3,10 @@ using gaemstone.ECS;
namespace gaemstone.Components;
[Module]
[Public, Module]
public partial class TransformComponents
{
[Symbol, Component]
[Component]
public struct GlobalTransform
{
public Matrix4x4 Value;

@ -14,12 +14,22 @@ public class PathAttribute : Attribute
}
/// <summary>
/// Register the entity under a globally unique symbol.
/// Uses the type's name by default.
/// <p>
/// Components marked with this attribute are automatically registered with
/// a <see cref="EntityRef.Symbol"/> equal to their <see cref="EntityRef.Name"/>.
/// Symbols are unique string identifiers used to look up their entities.
/// </p>
/// <p>
/// Modules marked with this attribute apply this property to all their
/// components, except ones marked with <see cref="PrivateAttribute"/>.
/// </p>
/// </summary>
// TODO: Remove [Symbol], introduce [Public] for modules and [Private] or so.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)]
public class SymbolAttribute : Attribute { }
public class PublicAttribute : Attribute { }
/// <seealso cref="PublicAttribute"/>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)]
public class PrivateAttribute : Attribute { }
/// <summary>

Loading…
Cancel
Save