[NUI.Physics2D] Add binding for Chipmunk2D physics engine
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Physics2D / src / internal / chipmunk / DelegateExtensions.cs
1 /*
2  * Copyright (c) 2023 Codefoco (codefoco@codefoco.com)
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  * 
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13  * 
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22
23 using System;
24 using System.Runtime.InteropServices;
25
26 namespace Tizen.NUI.Physics2D.Chipmunk
27 {
28     /// <summary>
29     /// Create a ToFunctionPointer extension method for each delegate type. Unfortunately C# 7.0
30     /// can't do something like that (you will need C# 7.3), thus we create one extension method for
31     /// each delegate public static IntPtr ToFunctionPointer T (this T d) where T : Delegate
32     /// </summary>
33     static internal class DelegateExtensions
34     {
35         public static IntPtr ToFunctionPointer(this BodyArbiterIteratorFunction d)
36         {
37             if (d == null)
38             {
39                 return IntPtr.Zero;
40             }
41
42             return Marshal.GetFunctionPointerForDelegate<BodyArbiterIteratorFunction>(d);
43         }
44
45         public static IntPtr ToFunctionPointer(this BodyConstraintIteratorFunction d)
46         {
47             if (d == null)
48             {
49                 return IntPtr.Zero;
50             }
51
52             return Marshal.GetFunctionPointerForDelegate<BodyConstraintIteratorFunction>(d);
53         }
54
55         public static IntPtr ToFunctionPointer(this BodyShapeIteratorFunction d)
56         {
57             if (d == null)
58             {
59                 return IntPtr.Zero;
60             }
61
62             return Marshal.GetFunctionPointerForDelegate<BodyShapeIteratorFunction>(d);
63         }
64
65         public static IntPtr ToFunctionPointer(this BodyVelocityFunction d)
66         {
67             if (d == null)
68             {
69                 return IntPtr.Zero;
70             }
71
72             return Marshal.GetFunctionPointerForDelegate<BodyVelocityFunction>(d);
73         }
74
75         public static IntPtr ToFunctionPointer(this BodyPositionFunction d)
76         {
77             if (d == null)
78             {
79                 return IntPtr.Zero;
80             }
81
82             return Marshal.GetFunctionPointerForDelegate<BodyPositionFunction>(d);
83         }
84
85         public static IntPtr ToFunctionPointer(this CollisionBeginFunction d)
86         {
87             if (d == null)
88             {
89                 return IntPtr.Zero;
90             }
91
92             return Marshal.GetFunctionPointerForDelegate<CollisionBeginFunction>(d);
93         }
94
95
96         public static IntPtr ToFunctionPointer(this CollisionPreSolveFunction d)
97         {
98             if (d == null)
99             {
100                 return IntPtr.Zero;
101             }
102
103             return Marshal.GetFunctionPointerForDelegate<CollisionPreSolveFunction>(d);
104         }
105
106
107         public static IntPtr ToFunctionPointer(this CollisionPostSolveFunction d)
108         {
109             if (d == null)
110             {
111                 return IntPtr.Zero;
112             }
113
114             return Marshal.GetFunctionPointerForDelegate<CollisionPostSolveFunction>(d);
115         }
116
117
118         public static IntPtr ToFunctionPointer(this CollisionSeparateFunction d)
119         {
120             if (d == null)
121             {
122                 return IntPtr.Zero;
123             }
124
125             return Marshal.GetFunctionPointerForDelegate<CollisionSeparateFunction>(d);
126         }
127
128
129         public static IntPtr ToFunctionPointer(this PostStepFunction d)
130         {
131             if (d == null)
132             {
133                 return IntPtr.Zero;
134             }
135
136             return Marshal.GetFunctionPointerForDelegate<PostStepFunction>(d);
137         }
138
139
140         public static IntPtr ToFunctionPointer(this SpaceSegmentQueryFunction d)
141         {
142             if (d == null)
143             {
144                 return IntPtr.Zero;
145             }
146
147             return Marshal.GetFunctionPointerForDelegate<SpaceSegmentQueryFunction>(d);
148         }
149
150         public static IntPtr ToFunctionPointer(this SpacePointQueryFunction d)
151         {
152             if (d == null)
153             {
154                 return IntPtr.Zero;
155             }
156
157             return Marshal.GetFunctionPointerForDelegate<SpacePointQueryFunction>(d);
158         }
159
160         public static IntPtr ToFunctionPointer(this SpaceBBQueryFunction d)
161         {
162             if (d == null)
163             {
164                 return IntPtr.Zero;
165             }
166
167             return Marshal.GetFunctionPointerForDelegate<SpaceBBQueryFunction>(d);
168         }
169
170
171         public static IntPtr ToFunctionPointer(this SpaceObjectIteratorFunction d)
172         {
173             if (d == null)
174             {
175                 return IntPtr.Zero;
176             }
177
178             return Marshal.GetFunctionPointerForDelegate<SpaceObjectIteratorFunction>(d);
179         }
180
181
182         public static IntPtr ToFunctionPointer(this SpaceDebugDrawCircleImpl d)
183         {
184             if (d == null)
185             {
186                 return IntPtr.Zero;
187             }
188
189             return Marshal.GetFunctionPointerForDelegate<SpaceDebugDrawCircleImpl>(d);
190         }
191
192
193         public static IntPtr ToFunctionPointer(this SpaceDebugDrawSegmentImpl d)
194         {
195             if (d == null)
196             {
197                 return IntPtr.Zero;
198             }
199
200             return Marshal.GetFunctionPointerForDelegate<SpaceDebugDrawSegmentImpl>(d);
201         }
202
203         public static IntPtr ToFunctionPointer(this SpaceDebugDrawFatSegmentImpl d)
204         {
205             if (d == null)
206             {
207                 return IntPtr.Zero;
208             }
209
210             return Marshal.GetFunctionPointerForDelegate<SpaceDebugDrawFatSegmentImpl>(d);
211         }
212
213         public static IntPtr ToFunctionPointer(this SpaceDebugDrawPolygonImpl d)
214         {
215             if (d == null)
216             {
217                 return IntPtr.Zero;
218             }
219
220             return Marshal.GetFunctionPointerForDelegate<SpaceDebugDrawPolygonImpl>(d);
221         }
222
223         public static IntPtr ToFunctionPointer(this SpaceDebugDrawDotImpl d)
224         {
225             if (d == null)
226             {
227                 return IntPtr.Zero;
228             }
229
230             return Marshal.GetFunctionPointerForDelegate<SpaceDebugDrawDotImpl>(d);
231         }
232
233         public static IntPtr ToFunctionPointer(this SpaceDebugDrawColorForShapeImpl d)
234         {
235             if (d == null)
236             {
237                 return IntPtr.Zero;
238             }
239
240             return Marshal.GetFunctionPointerForDelegate<SpaceDebugDrawColorForShapeImpl>(d);
241         }
242
243
244         public static IntPtr ToFunctionPointer(this ConstraintSolveFunction d)
245         {
246             if (d == null)
247             {
248                 return IntPtr.Zero;
249             }
250
251             return Marshal.GetFunctionPointerForDelegate<ConstraintSolveFunction>(d);
252         }
253
254         public static IntPtr ToFunctionPointer(this DampedSpringForceFunction d)
255         {
256             if (d == null)
257             {
258                 return IntPtr.Zero;
259             }
260
261             return Marshal.GetFunctionPointerForDelegate<DampedSpringForceFunction>(d);
262         }
263
264         public static IntPtr ToFunctionPointer(this DampedRotarySpringTorqueFunction d)
265         {
266             if (d == null)
267             {
268                 return IntPtr.Zero;
269             }
270
271             return Marshal.GetFunctionPointerForDelegate<DampedRotarySpringTorqueFunction>(d);
272         }
273
274         public static IntPtr ToFunctionPointer(this SpaceShapeQueryFunction d)
275         {
276             if (d == null)
277             {
278                 return IntPtr.Zero;
279             }
280
281             return Marshal.GetFunctionPointerForDelegate<SpaceShapeQueryFunction>(d);
282         }
283
284         public static IntPtr ToFunctionPointer(this MarchSegmentFunction d)
285         {
286             if (d == null)
287             {
288                 return IntPtr.Zero;
289             }
290
291             return Marshal.GetFunctionPointerForDelegate<MarchSegmentFunction>(d);
292         }
293
294         public static IntPtr ToFunctionPointer(this MarchSampleFunction d)
295         {
296             if (d == null)
297             {
298                 return IntPtr.Zero;
299             }
300
301             return Marshal.GetFunctionPointerForDelegate<MarchSampleFunction>(d);
302         }
303     }
304 }