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