Vixen
dd8b0a81
csharp
public sealed class BehaviorStateAnalyzer

Reports a Behavior that keeps what the world already knows.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The rule the layering rests on. docs/plan/04-ecs-and-scripting.md § The rule that keeps this coherent: component data lives in ECS, and a behaviour holds no state that is not either a component or private scratch. Without it the ECS below becomes decoration.

⚠ The rule was deliberately narrowed and this analyzer enforces the narrow one. A behaviour carrying [DataContract] serialises its own members into a .vxscene, on purpose — a designer's Speed should not become a generated component struct with an archetype nobody queries. So *data* on a behaviour is fine. What is banned is the shape that makes the ECS decoration: a behaviour keeping a second copy of something the world is already the authority on — an entity handle, or a component.

⚠ Why an entity handle in particular is an error rather than a style note. An Entity is a slot in a running process. A [DataContract] behaviour holding one writes a stale slot number into the file and reads it back as a handle into a different world — which resolves to the wrong entity or fails a version check, silently either way. `WorldSerializer` refuses to write `Parent`, `Child` and `Sibling` for exactly this reason and says out loud that it cannot do the same for a game's own component.

What it deliberately does not do is judge how hot the data is. Doc 04 asks for a third diagnostic — a warning about hot data, promoting a field into a component — and there is no static predicate for "hot": the document itself says profiling is what decides. A rule whose predicate cannot be false is worse than no rule.

Fields and properties (3)

  • public const string HandleDiagnosticId

    The id reported for a behaviour member that holds an entity handle.

  • public const string ComponentDiagnosticId

    The id reported for a behaviour member that holds a copy of a component.

  • public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics

    Returns a set of descriptors for the diagnostics that this analyzer is capable of producing.

Methods (1)

  • public override void Initialize(AnalysisContext context)

    Called once at session start to register actions in the analysis context.

Used by (2)

  • BehaviorStateTestsVixen.Engine.Generators.Tests
  • RealExampleRuleTestsVixen.DocGen.Tests