objc2_gameplay_kit/generated/
GKComponent.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11    /// A component is the data and logic for one part of an object in an entity-component system.
12    /// Entities have many components but components are associated with only a single entity.
13    ///
14    /// Components across entities are best arranged in ComponentSystems, which are homogeneous
15    /// collections of components that the game logic updates in a deterministic order.
16    ///
17    ///
18    /// See: GKComponentSystem
19    ///
20    /// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkcomponent?language=objc)
21    #[unsafe(super(NSObject))]
22    #[derive(Debug, PartialEq, Eq, Hash)]
23    pub struct GKComponent;
24);
25
26extern_conformance!(
27    unsafe impl NSCoding for GKComponent {}
28);
29
30extern_conformance!(
31    unsafe impl NSCopying for GKComponent {}
32);
33
34unsafe impl CopyingHelper for GKComponent {
35    type Result = Self;
36}
37
38extern_conformance!(
39    unsafe impl NSObjectProtocol for GKComponent {}
40);
41
42extern_conformance!(
43    unsafe impl NSSecureCoding for GKComponent {}
44);
45
46impl GKComponent {
47    extern_methods!(
48        #[cfg(feature = "GKEntity")]
49        /// The entity that this component belongs to. Defaults to nil until the component is added to an entity.
50        #[unsafe(method(entity))]
51        #[unsafe(method_family = none)]
52        pub unsafe fn entity(&self) -> Option<Retained<GKEntity>>;
53
54        /// Updates the component with the given delta time since the last update. Each component should
55        /// perform its time-based logic in this method.
56        #[unsafe(method(updateWithDeltaTime:))]
57        #[unsafe(method_family = none)]
58        pub unsafe fn updateWithDeltaTime(&self, seconds: NSTimeInterval);
59
60        /// Override this to perform game logic when this component is added to an entity
61        #[unsafe(method(didAddToEntity))]
62        #[unsafe(method_family = none)]
63        pub unsafe fn didAddToEntity(&self);
64
65        /// Override this to perform game logic before this entity is removed from it's entity
66        #[unsafe(method(willRemoveFromEntity))]
67        #[unsafe(method_family = none)]
68        pub unsafe fn willRemoveFromEntity(&self);
69    );
70}
71
72/// Methods declared on superclass `NSObject`.
73impl GKComponent {
74    extern_methods!(
75        #[unsafe(method(init))]
76        #[unsafe(method_family = init)]
77        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
78
79        #[unsafe(method(new))]
80        #[unsafe(method_family = new)]
81        pub unsafe fn new() -> Retained<Self>;
82    );
83}
84
85extern_class!(
86    /// A component system is a homogeneous collection of components that are intended to be called at the same time.
87    /// The system is homogeneous, meaning it only allows members of the same class into the system.
88    ///
89    /// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkcomponentsystem?language=objc)
90    #[unsafe(super(NSObject))]
91    #[derive(Debug, PartialEq, Eq, Hash)]
92    pub struct GKComponentSystem<ComponentType: ?Sized = AnyObject>;
93);
94
95impl<ComponentType: ?Sized + Message + AsRef<GKComponent>> GKComponentSystem<ComponentType> {
96    /// Unchecked conversion of the generic parameter.
97    ///
98    /// # Safety
99    ///
100    /// The generic must be valid to reinterpret as the given type.
101    #[inline]
102    pub unsafe fn cast_unchecked<NewComponentType: ?Sized + Message + AsRef<GKComponent>>(
103        &self,
104    ) -> &GKComponentSystem<NewComponentType> {
105        unsafe { &*((self as *const Self).cast()) }
106    }
107}
108
109extern_conformance!(
110    unsafe impl<ComponentType: ?Sized + AsRef<GKComponent>> NSFastEnumeration
111        for GKComponentSystem<ComponentType>
112    {
113    }
114);
115
116extern_conformance!(
117    unsafe impl<ComponentType: ?Sized + AsRef<GKComponent>> NSObjectProtocol
118        for GKComponentSystem<ComponentType>
119    {
120    }
121);
122
123impl<ComponentType: Message + AsRef<GKComponent>> GKComponentSystem<ComponentType> {
124    extern_methods!(
125        /// The collection's component class. Any selector the component supports can be called on the system and it will be forwarded
126        /// to each of the components in the collection.
127        #[unsafe(method(componentClass))]
128        #[unsafe(method_family = none)]
129        pub unsafe fn componentClass(&self) -> &'static AnyClass;
130
131        /// The array of components currently in the system.
132        #[unsafe(method(components))]
133        #[unsafe(method_family = none)]
134        pub unsafe fn components(&self) -> Retained<NSArray<ComponentType>>;
135
136        /// Supports getting components via a [] subscript.
137        #[unsafe(method(objectAtIndexedSubscript:))]
138        #[unsafe(method_family = none)]
139        pub unsafe fn objectAtIndexedSubscript(&self, idx: NSUInteger) -> Retained<ComponentType>;
140
141        /// Initializes a system for the given component class. The receiver can now only accept components of the given class.
142        ///
143        /// # Safety
144        ///
145        /// `cls` probably has further requirements.
146        #[unsafe(method(initWithComponentClass:))]
147        #[unsafe(method_family = init)]
148        pub unsafe fn initWithComponentClass(
149            this: Allocated<Self>,
150            cls: &AnyClass,
151        ) -> Retained<Self>;
152
153        /// Adds a component to the system. The component must be of the same class as the system's componentClass.
154        /// The component is added to the tail of the collection and will be processed after components that were added before it.
155        ///
156        ///
157        /// Throws a if the component added is not a kind of the system's componentClass.
158        #[unsafe(method(addComponent:))]
159        #[unsafe(method_family = none)]
160        pub unsafe fn addComponent(&self, component: &ComponentType);
161
162        #[cfg(feature = "GKEntity")]
163        /// Adds the supported component from the entity's component collection.
164        /// This is conceptually the same as the pseudo-code:
165        ///
166        /// for (GKComponent *component in entity.components)
167        /// if (component.class == system.componentClass)
168        /// [system addComponent:component]
169        ///
170        ///
171        /// See: GKEntity.components
172        #[unsafe(method(addComponentWithEntity:))]
173        #[unsafe(method_family = none)]
174        pub unsafe fn addComponentWithEntity(&self, entity: &GKEntity);
175
176        #[cfg(feature = "GKEntity")]
177        /// Removes the supported component from the entity's component collection
178        /// This is conceptually the same as the pseudo-code:
179        ///
180        /// for (GKComponent *component in entity.components)
181        /// if (component.class == system.componentClass)
182        /// [system removeComponent:component]
183        #[unsafe(method(removeComponentWithEntity:))]
184        #[unsafe(method_family = none)]
185        pub unsafe fn removeComponentWithEntity(&self, entity: &GKEntity);
186
187        /// Removes a component from the system
188        ///
189        /// Does nothing if the component is not in this system
190        #[unsafe(method(removeComponent:))]
191        #[unsafe(method_family = none)]
192        pub unsafe fn removeComponent(&self, component: &ComponentType);
193
194        /// Updates each component with the given delta time since the last update. Each component thus performs its time
195        /// based logic with a single message.
196        #[unsafe(method(updateWithDeltaTime:))]
197        #[unsafe(method_family = none)]
198        pub unsafe fn updateWithDeltaTime(&self, seconds: NSTimeInterval);
199
200        /// Returns the class of the specified generic index
201        #[unsafe(method(classForGenericArgumentAtIndex:))]
202        #[unsafe(method_family = none)]
203        pub unsafe fn classForGenericArgumentAtIndex(&self, index: NSUInteger)
204            -> &'static AnyClass;
205    );
206}
207
208/// Methods declared on superclass `NSObject`.
209impl<ComponentType: Message + AsRef<GKComponent>> GKComponentSystem<ComponentType> {
210    extern_methods!(
211        #[unsafe(method(init))]
212        #[unsafe(method_family = init)]
213        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
214
215        #[unsafe(method(new))]
216        #[unsafe(method_family = new)]
217        pub unsafe fn new() -> Retained<Self>;
218    );
219}