Entitas icon indicating copy to clipboard operation
Entitas copied to clipboard

Can I feel free to use my class in component?

Open atkdefender opened this issue 9 months ago • 1 comments

Ask AI, it says "Your component-embedded class leads to multiple pointer jumps, further reducing CPU cache hit rate.". It's that ture? Should I care about that? What if my class in component has function in it? Different answer?

public struct HealthComponent : IComponent {
    public int CurrentHP;
    public int MaxHP;
}

From ↑ to ↓

public class HealthComponent : IComponent {
    public HealthData Health; 
}

public class HealthData { 
    public int CurrentHP;
    public int MaxHP;
}

atkdefender avatar Mar 21 '25 08:03 atkdefender

Hi!

True, each ref to another class is a jump, but you can use classes in components. In your case I think the following makes sense, also avoiding an additional class:

public sealed class HealthComponent : IComponent
{
    public int CurrentHealth;
    public int MaxHealth;
}

sschmid avatar May 23 '25 11:05 sschmid