Skip to content

Implement static type hook interfaces#88

Merged
BeanCheeseBurrito merged 1 commit intomainfrom
type-hook-interfaces
Mar 12, 2025
Merged

Implement static type hook interfaces#88
BeanCheeseBurrito merged 1 commit intomainfrom
type-hook-interfaces

Conversation

@BeanCheeseBurrito
Copy link
Copy Markdown
Owner

This PR adds a new way of registering type hook callbacks. You can implement any of the following interfaces and the callback will automatically be used when the component is first registered.

  • ICtorHook
  • IDtorHook
  • ICopyHook
  • IMoveHook
  • IOnAddHook
  • IOnSetHook
  • IOnRemoveHook
public record struct Position(int X, int Y) :
    ICtorHook<Position>,
    IDtorHook<Position>,
    ICopyHook<Position>,
    IMoveHook<Position>,
    IOnAddHook<Position>,
    IOnSetHook<Position>,
    IOnRemoveHook<Position>
{
    public static void Ctor(ref Position data, TypeInfo _) { }
    public static void Dtor(ref Position data, TypeInfo _) { }
    public static void Copy(ref Position dst, ref Position src, TypeInfo _) { }
    public static void Move(ref Position dst, ref Position src, TypeInfo _) { }
    public static void OnAdd(Iter it, int i, ref Position data) { }
    public static void OnSet(Iter it, int i, ref Position data) { }
    public static void OnRemove(Iter it, int i, ref Position data) { }
}

using World world = World.Create();
world.Entity().Add<Position>(); // Hook callbacks will get registered the first time a component is used.

@BeanCheeseBurrito BeanCheeseBurrito merged commit 4d09824 into main Mar 12, 2025
@BeanCheeseBurrito BeanCheeseBurrito deleted the type-hook-interfaces branch March 12, 2025 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant