Skip to content

Can I feel free to use my class in component? #1098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
atkdefender opened this issue Mar 21, 2025 · 1 comment
Open

Can I feel free to use my class in component? #1098

atkdefender opened this issue Mar 21, 2025 · 1 comment

Comments

@atkdefender
Copy link

atkdefender commented Mar 21, 2025

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;
}

@sschmid
Copy link
Owner

sschmid commented May 23, 2025

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

No branches or pull requests

2 participants