hank
2019-01-22 9bb554260c63842b23919b1f128b9cc8488b7f50
commit | author | age
9bb554 1 #pragma once
H 2
3 #include <stdint.h>
4 #include <stdarg.h>
5
6 #include "UnityForwardDecls.h"
7 #include "UnityRendering.h"
8
9 // unity plugin functions
10
11 // audio plugin api
12 typedef int     (*UnityPluginGetAudioEffectDefinitionsFunc)(struct UnityAudioEffectDefinition*** descptr);
13
14 // OLD rendering plugin api (will become obsolete soon)
15 typedef void    (*UnityPluginSetGraphicsDeviceFunc)(void* device, int deviceType, int eventType);
16 typedef void    (*UnityPluginRenderMarkerFunc)(int marker);
17
18 // new rendering plugin api
19 typedef void    (*UnityPluginLoadFunc)(struct IUnityInterfaces* unityInterfaces);
20 typedef void    (*UnityPluginUnloadFunc)();
21
22
23 // log handler function
24 #ifdef __cplusplus
25 typedef bool (*LogEntryHandler)(LogType logType, const char* log, va_list list);
26 #endif
27
28 //
29 // these are functions referenced in trampoline and implemented in unity player lib
30 //
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 // life cycle management
37
38 void    UnityInitStartupTime();
39 void    UnityInitRuntime(int argc, char* argv[]);
40 void    UnityInitApplicationNoGraphics(const char* appPathName);
41 void    UnityInitApplicationGraphics(int forceDirectRendering);
42 void    UnityCleanup();
43 void    UnityLoadApplication();
44 void    UnityPlayerLoop();                  // normal player loop
45 void    UnityBatchPlayerLoop();             // batch mode like player loop, without rendering (usable for background processing)
46 void    UnitySetPlayerFocus(int focused);   // send OnApplicationFocus() message to scripts
47 void    UnityLowMemory();
48 void    UnityPause(int pause);
49 int     UnityIsPaused();                    // 0 if player is running, 1 if paused
50 void    UnityWillPause();                   // send the message that app will pause
51 void    UnityWillResume();                  // send the message that app will resume
52 void    UnityInputProcess();
53 void    UnityDeliverUIEvents();             // unity processing impacting UI will be called in there
54
55
56 // rendering
57
58 int     UnityGetRenderingAPIs(int capacity, int* outAPIs);
59 void    UnityFinishRendering();
60
61 // OpenGL ES.
62
63 int     UnityHasRenderingAPIExtension(const char* extension);
64 void    UnityOnSetCurrentGLContext(EAGLContext* context);
65
66 // This must match the one in ApiEnumsGLES.h
67 typedef enum UnityFramebufferTarget
68 {
69     kDrawFramebuffer = 0,
70     kReadFramebuffer,
71     kFramebufferTargetCount
72 } UnityFramebufferTarget;
73 void    UnityBindFramebuffer(UnityFramebufferTarget target, int fbo);
74 void    UnityRegisterFBO(UnityRenderBufferHandle color, UnityRenderBufferHandle depth, unsigned fbo);
75
76 // controling player internals
77
78 // TODO: needs some cleanup
79 void    UnitySetAudioSessionActive(int active);
80 void    UnityGLInvalidateState();
81 void    UnityReloadResources();
82 int     UnityIsCaptureScreenshotRequested();
83 void    UnityCaptureScreenshot();
84 void    UnitySendMessage(const char* obj, const char* method, const char* msg);
85
86 EAGLContext*        UnityGetDataContextGLES();
87
88 #ifdef __cplusplus
89 void    UnitySetLogEntryHandler(LogEntryHandler newHandler);
90 #endif
91
92
93 // plugins support
94
95 // WARNING: old UnityRegisterRenderingPlugin will become obsolete soon
96 void    UnityRegisterRenderingPlugin(UnityPluginSetGraphicsDeviceFunc setDevice, UnityPluginRenderMarkerFunc renderMarker);
97
98 void    UnityRegisterRenderingPluginV5(UnityPluginLoadFunc loadPlugin, UnityPluginUnloadFunc unloadPlugin);
99 void    UnityRegisterAudioPlugin(UnityPluginGetAudioEffectDefinitionsFunc getAudioEffectDefinitions);
100
101
102 // resolution/orientation handling
103
104 void    UnityGetRenderingResolution(unsigned* w, unsigned* h);
105 void    UnityGetSystemResolution(unsigned* w, unsigned* h);
106
107 void    UnityRequestRenderingResolution(unsigned w, unsigned h);
108
109 int     UnityIsOrientationEnabled(unsigned /*ScreenOrientation*/ orientation);
110
111 int     UnityHasOrientationRequest();
112 int     UnityShouldAutorotate();
113 int     UnityRequestedScreenOrientation(); // returns ScreenOrientation
114 void    UnityOrientationRequestWasCommitted();
115
116 int     UnityReportResizeView(unsigned w, unsigned h, unsigned /*ScreenOrientation*/ contentOrientation);   // returns ScreenOrientation
117 void    UnityReportBackbufferChange(UnityRenderBufferHandle colorBB, UnityRenderBufferHandle depthBB);
118
119
120 // player settings
121
122 int     UnityDisableDepthAndStencilBuffers();
123 int     UnityUseAnimatedAutorotation();
124 int     UnityGetDesiredMSAASampleCount(int defaultSampleCount);
125 int     UnityGetSRGBRequested();
126 int     UnityGetShowActivityIndicatorOnLoading();
127 int     UnityGetAccelerometerFrequency();
128 int     UnityGetTargetFPS();
129 int     UnityGetAppBackgroundBehavior();
130
131
132 // push notifications
133 #if !UNITY_TVOS
134 void    UnitySendLocalNotification(UILocalNotification* notification);
135 #endif
136 void    UnitySendRemoteNotification(NSDictionary* notification);
137 void    UnitySendDeviceToken(NSData* deviceToken);
138 void    UnitySendRemoteNotificationError(NSError* error);
139
140 // native events
141
142 void    UnityInvalidateDisplayDataCache(void* screen);
143 void    UnityUpdateDisplayList(void** screens, int screenCount);
144
145
146 // profiler
147
148 void*   UnityCreateProfilerCounter(const char*);
149 void    UnityDestroyProfilerCounter(void*);
150 void    UnityStartProfilerCounter(void*);
151 void    UnityEndProfilerCounter(void*);
152
153
154 // sensors
155
156 void    UnitySensorsSetGyroRotationRate(int idx, float x, float y, float z);
157 void    UnitySensorsSetGyroRotationRateUnbiased(int idx, float x, float y, float z);
158 void    UnitySensorsSetGravity(int idx, float x, float y, float z);
159 void    UnitySensorsSetUserAcceleration(int idx, float x, float y, float z);
160 void    UnitySensorsSetAttitude(int idx, float x, float y, float z, float w);
161 void    UnityDidAccelerate(float x, float y, float z, double timestamp);
162 void    UnitySetJoystickPosition(int joyNum, int axis, float pos);
163 int     UnityStringToKey(const char *name);
164 void    UnitySetKeyState(int key, int /*bool*/ state);
165
166 // WWW connection handling
167
168 void    UnityReportWWWStatusError(void* udata, int status, const char* error);
169
170 void    UnityReportWWWReceivedResponse(void* udata, int status, unsigned expectedDataLength, const char* respHeader);
171 void    UnityReportWWWReceivedData(void* udata, const void* buffer, unsigned totalRead, unsigned expectedTotal);
172 void    UnityReportWWWFinishedLoadingData(void* udata);
173 void    UnityReportWWWSentData(void* udata, unsigned totalWritten, unsigned expectedTotal);
174
175 // AVCapture
176
177 void    UnityReportAVCapturePermission();
178 void    UnityDidCaptureVideoFrame(intptr_t tex, void* udata);
179
180 // logging override
181
182 #ifdef __cplusplus
183 } // extern "C"
184 #endif
185
186
187 // touches processing
188
189 #ifdef __cplusplus
190 extern "C" {
191 #endif
192
193 void    UnitySetViewTouchProcessing(UIView* view, int /*ViewTouchProcessing*/ processingPolicy);
194 void    UnityDropViewTouchProcessing(UIView* view);
195
196 void    UnitySendTouchesBegin(NSSet* touches, UIEvent* event);
197 void    UnitySendTouchesEnded(NSSet* touches, UIEvent* event);
198 void    UnitySendTouchesCancelled(NSSet* touches, UIEvent* event);
199 void    UnitySendTouchesMoved(NSSet* touches, UIEvent* event);
200
201 void    UnityCancelTouches();
202
203 #ifdef __cplusplus
204 } // extern "C"
205 #endif
206
207
208 //
209 // these are functions referenced and implemented in trampoline
210 //
211
212 #ifdef __cplusplus
213 extern "C" {
214 #endif
215
216 // UnityAppController.mm
217 UIViewController*       UnityGetGLViewController();
218 UIView*                 UnityGetGLView();
219 UIWindow*               UnityGetMainWindow();
220 enum ScreenOrientation  UnityCurrentOrientation();
221
222 // Unity/DisplayManager.mm
223 float                   UnityScreenScaleFactor(UIScreen* screen);
224
225 #ifdef __cplusplus
226 } // extern "C"
227 #endif
228
229
230 //
231 // these are functions referenced in unity player lib and implemented in trampoline
232 //
233
234 #ifdef __cplusplus
235 extern "C" {
236 #endif
237
238 // iPhone_Sensors.mm
239 void            UnityInitJoysticks();
240 void            UnityCoreMotionStart();
241 void            UnityCoreMotionStop();
242 int             UnityIsGyroEnabled(int idx);
243 int             UnityIsGyroAvailable();
244 void            UnityUpdateGyroData();
245 void            UnitySetGyroUpdateInterval(int idx, float interval);
246 float           UnityGetGyroUpdateInterval(int idx);
247 void            UnityUpdateJoystickData();
248 int             UnityGetJoystickCount();
249 void            UnityGetJoystickName(int idx, char* buffer, int maxLen);
250 void            UnityGetJoystickAxisName(int idx, int axis, char* buffer, int maxLen);
251 void            UnityGetNiceKeyname(int key, char* buffer, int maxLen);
252
253 // UnityAppController+Rendering.mm
254 void            UnityInitMainScreenRenderingCallback();
255 void            UnityGfxInitedCallback();
256 void            UnityPresentContextCallback(struct UnityFrameStats const* frameStats);
257 void            UnityFramerateChangeCallback(int targetFPS);
258 int             UnitySelectedRenderingAPI();
259
260 NSBundle*           UnityGetMetalBundle();
261 MTLDeviceRef        UnityGetMetalDevice();
262 MTLCommandQueueRef  UnityGetMetalCommandQueue();
263
264 EAGLContext*        UnityGetDataContextEAGL();
265
266 UnityRenderBufferHandle UnityBackbufferColor();
267 UnityRenderBufferHandle UnityBackbufferDepth();
268
269 // UI/ActivityIndicator.mm
270 void            UnityStartActivityIndicator();
271 void            UnityStopActivityIndicator();
272
273 // UI/Keyboard.mm
274 void            UnityKeyboard_Create(unsigned keyboardType, int autocorrection, int multiline, int secure, int alert, const char* text, const char* placeholder);
275 void            UnityKeyboard_Show();
276 void            UnityKeyboard_Hide();
277 void            UnityKeyboard_GetRect(float* x, float* y, float* w, float* h);
278 void            UnityKeyboard_SetText(const char* text);
279 NSString*       UnityKeyboard_GetText();
280 int             UnityKeyboard_IsActive();
281 int             UnityKeyboard_IsDone();
282 int             UnityKeyboard_WasCanceled();
283 void            UnityKeyboard_SetInputHidden(int hidden);
284 int             UnityKeyboard_IsInputHidden();
285
286 int             UnityKeyboard_CanGetSelection();
287 void            UnityKeyboard_GetSelection(int* location, int* range);
288
289 // UI/UnityViewControllerBase.mm
290 void            UnityNotifyAutoOrientationChange();
291
292 // Unity/AVCapture.mm
293 int             UnityGetAVCapturePermission(int captureTypes);
294 void            UnityRequestAVCapturePermission(int captureTypes);
295
296 // Unity/CameraCapture.mm
297 void            UnityEnumVideoCaptureDevices(void* udata, void(*callback)(void* udata, const char* name, int frontFacing));
298 void*           UnityInitCameraCapture(int device, int w, int h, int fps, void* udata);
299 void            UnityStartCameraCapture(void* capture);
300 void            UnityPauseCameraCapture(void* capture);
301 void            UnityStopCameraCapture(void* capture);
302 void            UnityCameraCaptureExtents(void* capture, int* w, int* h);
303 void            UnityCameraCaptureReadToMemory(void* capture, void* dst, int w, int h);
304 int             UnityCameraCaptureVideoRotationDeg(void* capture);
305 int             UnityCameraCaptureVerticallyMirrored(void* capture);
306
307
308 // Unity/DeviceSettings.mm
309 const char*     UnityDeviceUniqueIdentifier();
310 const char*     UnityVendorIdentifier();
311 const char*     UnityAdvertisingIdentifier();
312 int             UnityAdvertisingTrackingEnabled();
313 const char*     UnityDeviceName();
314 const char*     UnitySystemName();
315 const char*     UnitySystemVersion();
316 const char*     UnityDeviceModel();
317 int             UnityDeviceCPUCount();
318 int             UnityDeviceGeneration();
319 float           UnityDeviceDPI();
320 const char*     UnitySystemLanguage();
321
322 // Unity/DisplayManager.mm
323 EAGLContext*    UnityGetMainScreenContextGLES();
324 EAGLContext*    UnityGetContextEAGL();
325 void            UnityStartFrameRendering();
326 void            UnityDestroyUnityRenderSurfaces();
327
328 // Unity/Filesystem.mm
329 const char*     UnityApplicationDir();
330 const char*     UnityDocumentsDir();
331 const char*     UnityLibraryDir();
332 const char*     UnityCachesDir();
333 int             UnityUpdateNoBackupFlag(const char* path, int setFlag); // Returns 1 if successful, otherwise 0
334
335 // Unity/WWWConnection.mm
336 void*           UnityStartWWWConnectionGet(void* udata, const void* headerDict, const char* url);
337 void*           UnityStartWWWConnectionPost(void* udata, const void* headerDict, const char* url, const void* data, unsigned length);
338 void            UnityDestroyWWWConnection(void* connection);
339 void            UnityShouldCancelWWW(const void* connection);
340
341 //Apple TV Remote
342 int         UnityGetAppleTVRemoteAllowExitToMenu();
343 void        UnitySetAppleTVRemoteAllowExitToMenu(int val);
344 int         UnityGetAppleTVRemoteAllowRotation();
345 void        UnitySetAppleTVRemoteAllowRotation(int val);
346 int         UnityGetAppleTVRemoteReportAbsoluteDpadValues();
347 void        UnitySetAppleTVRemoteReportAbsoluteDpadValues(int val);
348 int         UnityGetAppleTVRemoteTouchesEnabled();
349 void        UnitySetAppleTVRemoteTouchesEnabled(int val);
350
351 #ifdef __cplusplus
352 } // extern "C"
353 #endif
354
355
356 #ifdef __OBJC__
357 // This is basically a wrapper for [NSString UTF8String] with additional strdup.
358 //
359 // Apparently multiple calls on UTF8String will leak memory (NSData objects) that are collected
360 // only when @autoreleasepool is exited. This function serves as documentation for this and as a
361 // handy wrapper.
362 inline char* AllocCString(NSString* value)
363 {
364     if (value == nil)
365         return 0;
366
367     const char* str = [value UTF8String];
368     return str ? strdup(str) : 0;
369 }
370
371 #endif