From 976d9fd32670fda080b76e7312dcbd353fdfc465 Mon Sep 17 00:00:00 2001 From: copygirl Date: Tue, 3 Jan 2023 15:00:21 +0100 Subject: [PATCH] Replace [Symbol] with [Public] and [Private] --- .../Components/CoreComponents.cs | 6 ++--- .../Systems/BasicWorldGenerator.cs | 4 +-- .../Components/InputComponents.cs | 26 +++++++++---------- .../Components/RenderingComponents.cs | 8 +++--- .../Components/ResourceComponents.cs | 8 +++--- .../AutoRegisterComponentsGenerator.cs | 11 +++++--- .../Components/TransformComponents.cs | 4 +-- src/gaemstone/ECS/Module+Attributes.cs | 18 ++++++++++--- 8 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/gaemstone.Bloxel/Components/CoreComponents.cs b/src/gaemstone.Bloxel/Components/CoreComponents.cs index 2fd60ef..f6bf299 100644 --- a/src/gaemstone.Bloxel/Components/CoreComponents.cs +++ b/src/gaemstone.Bloxel/Components/CoreComponents.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 { diff --git a/src/gaemstone.Bloxel/Systems/BasicWorldGenerator.cs b/src/gaemstone.Bloxel/Systems/BasicWorldGenerator.cs index 6b2a9da..398032b 100644 --- a/src/gaemstone.Bloxel/Systems/BasicWorldGenerator.cs +++ b/src/gaemstone.Bloxel/Systems/BasicWorldGenerator.cs @@ -6,7 +6,7 @@ using static gaemstone.Bloxel.Constants; namespace gaemstone.Bloxel.Systems; -[Module] +[Public, Module] [DependsOn] public partial class BasicWorldGenerator { @@ -22,7 +22,7 @@ public partial class BasicWorldGenerator _noise.SetFractalGain(0.6f); } - [Symbol, Tag] + [Tag] public struct HasBasicWorldGeneration { } [System] diff --git a/src/gaemstone.Client/Components/InputComponents.cs b/src/gaemstone.Client/Components/InputComponents.cs index 1f4a0a1..fc8d898 100644 --- a/src/gaemstone.Client/Components/InputComponents.cs +++ b/src/gaemstone.Client/Components/InputComponents.cs @@ -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] public struct Input { } - [Symbol, Entity, Path("/Input/Mouse")] + [Entity, Path("/Input/Mouse")] [Add] public struct Mouse { } - [Symbol, Entity, Path("/Input/Keyboard")] + [Entity, Path("/Input/Keyboard")] [Add] public struct Keyboard { } - [Symbol, Tag] + [Tag] public struct Gamepad { } /// Present on inputs / actions that are currently active. - [Symbol, Component] public struct Active { public TimeSpan Duration; } + [Component] public struct Active { public TimeSpan Duration; } /// Present on inputs / actions were activated this frame. - [Symbol, Tag] public struct Activated { } + [Tag] public struct Activated { } /// Present on inputs / actions were deactivated this frame. - [Symbol, Tag] public struct Deactivated { } + [Tag] public struct Deactivated { } /// @@ -41,7 +41,7 @@ public partial class InputComponents /// This is set if a UI element is focused that captures /// navigational or text input. /// - [Symbol, Relation, Tag, Exclusive] + [Relation, Tag, Exclusive] public struct InputCapturedBy { } /// @@ -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. /// - [Symbol, Relation, Tag, Exclusive] + [Relation, Tag, Exclusive] public struct MouseInputCapturedBy { } /// @@ -62,13 +62,13 @@ public partial class InputComponents /// /// This is set when a camera controller assumes control of the mouse. /// - [Symbol, Relation, Tag, Exclusive] + [Relation, Tag, Exclusive] [With] [With] 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; diff --git a/src/gaemstone.Client/Components/RenderingComponents.cs b/src/gaemstone.Client/Components/RenderingComponents.cs index c6c0808..d6d47ce 100644 --- a/src/gaemstone.Client/Components/RenderingComponents.cs +++ b/src/gaemstone.Client/Components/RenderingComponents.cs @@ -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; } diff --git a/src/gaemstone.Client/Components/ResourceComponents.cs b/src/gaemstone.Client/Components/ResourceComponents.cs index 5157ded..d875e97 100644 --- a/src/gaemstone.Client/Components/ResourceComponents.cs +++ b/src/gaemstone.Client/Components/ResourceComponents.cs @@ -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] + [Relation, Tag, IsA] public struct Texture { } - [Symbol, Relation, Tag, IsA] + [Relation, Tag, IsA] public struct Mesh { } } diff --git a/src/gaemstone.SourceGen/Generators/AutoRegisterComponentsGenerator.cs b/src/gaemstone.SourceGen/Generators/AutoRegisterComponentsGenerator.cs index 75b4fc9..4fa5a5c 100644 --- a/src/gaemstone.SourceGen/Generators/AutoRegisterComponentsGenerator.cs +++ b/src/gaemstone.SourceGen/Generators/AutoRegisterComponentsGenerator.cs @@ -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()"""); if (c.IsTag) sb.AppendLine($$""" .Add()"""); if (c.IsComponent) sb.AppendLine($$""" .Build().InitComponent<{{ c.Name }}>()"""); @@ -194,6 +196,7 @@ public partial class AutoRegisterComponentsGenerator public List 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 diff --git a/src/gaemstone/Components/TransformComponents.cs b/src/gaemstone/Components/TransformComponents.cs index b0d030c..28970c5 100644 --- a/src/gaemstone/Components/TransformComponents.cs +++ b/src/gaemstone/Components/TransformComponents.cs @@ -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; diff --git a/src/gaemstone/ECS/Module+Attributes.cs b/src/gaemstone/ECS/Module+Attributes.cs index b10d904..ca0603a 100644 --- a/src/gaemstone/ECS/Module+Attributes.cs +++ b/src/gaemstone/ECS/Module+Attributes.cs @@ -14,12 +14,22 @@ public class PathAttribute : Attribute } /// -/// Register the entity under a globally unique symbol. -/// Uses the type's name by default. +///

+/// Components marked with this attribute are automatically registered with +/// a equal to their . +/// Symbols are unique string identifiers used to look up their entities. +///

+///

+/// Modules marked with this attribute apply this property to all their +/// components, except ones marked with . +///

///
-// 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 { } + +/// +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] +public class PrivateAttribute : Attribute { } ///