1
1
package openvr.lib
2
2
3
3
import kool.*
4
+ import kool.lib.toByteArray
4
5
import org.lwjgl.openvr.AppOverrideKeys
5
6
import org.lwjgl.openvr.OpenVR.IVRApplications
6
7
import org.lwjgl.openvr.VRApplications.*
7
- import org.lwjgl.system.MemoryStack.stackGet
8
8
import org.lwjgl.system.MemoryUtil.*
9
9
import java.nio.ByteBuffer
10
10
@@ -130,23 +130,23 @@ object vrApplications : vrInterface {
130
130
* @param temporary
131
131
*/
132
132
fun addApplicationManifest (applicationManifestFullPath : String , temporary : Boolean = false): Error =
133
- Error of nVRApplications_AddApplicationManifest(addressOfAscii(applicationManifestFullPath), temporary)
133
+ stak { Error of nVRApplications_AddApplicationManifest(it. addressOfAscii(applicationManifestFullPath), temporary) }
134
134
135
135
/* *
136
136
* Removes an application manifest from the list to load when building the list of installed applications.
137
137
*
138
138
* @param applicationManifestFullPath
139
139
*/
140
140
infix fun removeApplicationManifest (applicationManifestFullPath : String ): Error =
141
- Error of nVRApplications_RemoveApplicationManifest(addressOfAscii(applicationManifestFullPath))
141
+ stak { Error of nVRApplications_RemoveApplicationManifest(it. addressOfAscii(applicationManifestFullPath)) }
142
142
143
143
/* *
144
144
* Returns true if an application is installed.
145
145
*
146
146
* @param appKey
147
147
*/
148
148
infix fun isApplicationInstalled (appKey : String ): Boolean =
149
- nVRApplications_IsApplicationInstalled(addressOfAscii(appKey))
149
+ stak { nVRApplications_IsApplicationInstalled(it. addressOfAscii(appKey)) }
150
150
151
151
/* * Returns the number of applications available in the list. */
152
152
val applicationCount: Int
@@ -163,9 +163,11 @@ object vrApplications : vrInterface {
163
163
* @param appKeyBuffer
164
164
*/
165
165
@JvmOverloads
166
- fun getApplicationKeyByIndex (applicationIndex : Int , pErr : VRApplicationErrorBuffer = pError): ByteBuffer =
167
- stackGet().malloc(maxKeyLength).apply {
168
- pErr[0 ] = nVRApplications_GetApplicationKeyByIndex(applicationIndex, adr, maxKeyLength)
166
+ fun getApplicationKeyByIndex (applicationIndex : Int , pErr : VRApplicationErrorBuffer = pError): ByteArray =
167
+ stak {
168
+ val buf = it.malloc(maxKeyLength)
169
+ pErr[0 ] = nVRApplications_GetApplicationKeyByIndex(applicationIndex, buf.adr, maxKeyLength)
170
+ buf.toByteArray()
169
171
}
170
172
171
173
/* *
@@ -179,9 +181,11 @@ object vrApplications : vrInterface {
179
181
* @param appKeyBuffer
180
182
*/
181
183
@JvmOverloads
182
- fun getApplicationKeyByProcessId (processId : Int , pErr : VRApplicationErrorBuffer = pError): ByteBuffer =
183
- stackGet().malloc(maxKeyLength).apply {
184
- pErr[0 ] = nVRApplications_GetApplicationKeyByProcessId(processId, adr, maxKeyLength)
184
+ fun getApplicationKeyByProcessId (processId : Int , pErr : VRApplicationErrorBuffer = pError): ByteArray =
185
+ stak {
186
+ val buf = it.malloc(maxKeyLength)
187
+ pErr[0 ] = nVRApplications_GetApplicationKeyByProcessId(processId, buf.adr, maxKeyLength)
188
+ buf.toByteArray()
185
189
}
186
190
187
191
/* *
@@ -192,7 +196,7 @@ object vrApplications : vrInterface {
192
196
* @param appKey
193
197
*/
194
198
infix fun launchApplication (appKey : String ): Error =
195
- Error of nVRApplications_LaunchApplication(addressOfAscii(appKey))
199
+ stak { Error of nVRApplications_LaunchApplication(it. addressOfAscii(appKey)) }
196
200
197
201
/* *
198
202
* Launches an instance of an application of type template, with its app key being {@code newAppKey} (which must be unique) and optionally override
@@ -203,7 +207,7 @@ object vrApplications : vrInterface {
203
207
* @param keys
204
208
*/
205
209
fun launchTemplateApplication (templateAppKey : String , newAppKey : String , keys : AppOverrideKeys .Buffer ): Error =
206
- Error of nVRApplications_LaunchTemplateApplication(addressOfAscii(templateAppKey), addressOfAscii(newAppKey), keys.adr, keys.rem)
210
+ stak { Error of nVRApplications_LaunchTemplateApplication(it. addressOfAscii(templateAppKey), it. addressOfAscii(newAppKey), keys.adr, keys.rem) }
207
211
208
212
/* *
209
213
* Launches the application currently associated with this mime type and passes it the option args, typically the filename or object name of the item
@@ -213,23 +217,23 @@ object vrApplications : vrInterface {
213
217
* @param args
214
218
*/
215
219
fun launchApplicationFromMimeType (mimeType : String , args : String ): Error =
216
- Error of nVRApplications_LaunchApplicationFromMimeType(addressOfAscii(mimeType), addressOfAscii(args))
220
+ stak { Error of nVRApplications_LaunchApplicationFromMimeType(it. addressOfAscii(mimeType), it. addressOfAscii(args)) }
217
221
218
222
/* *
219
223
* Launches the dashboard overlay application if it is not already running. This call is only valid for dashboard overlay applications.
220
224
*
221
225
* @param appKey
222
226
*/
223
227
infix fun launchDashboardOverlay (appKey : String ): Error =
224
- Error of nVRApplications_LaunchDashboardOverlay(addressOfAscii(appKey))
228
+ stak { Error of nVRApplications_LaunchDashboardOverlay(it. addressOfAscii(appKey)) }
225
229
226
230
/* *
227
231
* Cancel a pending launch for an application.
228
232
*
229
233
* @param appKey
230
234
*/
231
235
infix fun cancelApplicationLaunch (appKey : String ): Boolean =
232
- nVRApplications_CancelApplicationLaunch(addressOfAscii(appKey))
236
+ stak { nVRApplications_CancelApplicationLaunch(it. addressOfAscii(appKey)) }
233
237
234
238
/* *
235
239
* Identifies a running application. OpenVR can't always tell which process started in response to a URL. This function allows a URL handler (or the
@@ -240,15 +244,15 @@ object vrApplications : vrInterface {
240
244
* @param appKey
241
245
*/
242
246
fun identifyApplication (processId : Int , appKey : String ): Error =
243
- Error of nVRApplications_IdentifyApplication(processId, addressOfAscii(appKey))
247
+ stak { Error of nVRApplications_IdentifyApplication(processId, it. addressOfAscii(appKey)) }
244
248
245
249
/* *
246
250
* Returns the process ID for an application. Return 0 if the application was not found or is not running.
247
251
*
248
252
* @param appKey
249
253
*/
250
254
infix fun getApplicationProcessId (appKey : String ): Int =
251
- nVRApplications_GetApplicationProcessId(addressOfAscii(appKey))
255
+ stak { nVRApplications_GetApplicationProcessId(it. addressOfAscii(appKey)) }
252
256
253
257
/* *
254
258
* Kind of useless on JVM, but it will be offered anyway on the enum itself
@@ -280,12 +284,13 @@ object vrApplications : vrInterface {
280
284
* @param error
281
285
*/
282
286
@JvmOverloads
283
- fun getApplicationPropertyString (appKey : String , property : Property , propertyValueBufferLen : Int = vr.maxPropertyStringSize, error : VRApplicationErrorBuffer = pError): String = stackGet().run {
284
- val appKeyEncoded = addressOfAscii(appKey)
285
- val propertyValueBuffer = malloc(propertyValueBufferLen)
286
- val result = nVRApplications_GetApplicationPropertyString(appKeyEncoded, property.i, propertyValueBuffer.adr, propertyValueBufferLen, error.adr)
287
- memASCII(propertyValueBuffer, result - 1 )
288
- }
287
+ fun getApplicationPropertyString (appKey : String , property : Property , propertyValueBufferLen : Int = vr.maxPropertyStringSize, error : VRApplicationErrorBuffer = pError): String =
288
+ stak {
289
+ val appKeyEncoded = it.addressOfAscii(appKey)
290
+ val propertyValueBuffer = it.malloc(propertyValueBufferLen)
291
+ val result = nVRApplications_GetApplicationPropertyString(appKeyEncoded, property.i, propertyValueBuffer.adr, propertyValueBufferLen, error.adr)
292
+ memASCII(propertyValueBuffer, result - 1 )
293
+ }
289
294
290
295
/* *
291
296
* Returns a bool value for an application property. Returns false in all error cases.
@@ -298,7 +303,7 @@ object vrApplications : vrInterface {
298
303
*/
299
304
@JvmOverloads
300
305
fun getApplicationPropertyBool (appKey : String , property : Property , error : VRApplicationErrorBuffer = pError): Boolean =
301
- nVRApplications_GetApplicationPropertyBool(addressOfAscii(appKey), property.i, error.adr)
306
+ stak { nVRApplications_GetApplicationPropertyBool(it. addressOfAscii(appKey), property.i, error.adr) }
302
307
303
308
/* *
304
309
* Returns a uint64 value for an application property. Returns 0 in all error cases.
@@ -311,7 +316,7 @@ object vrApplications : vrInterface {
311
316
*/
312
317
@JvmOverloads
313
318
fun getApplicationPropertyLong (appKey : String , property : Property , error : VRApplicationErrorBuffer = pError): Long =
314
- nVRApplications_GetApplicationPropertyUint64(addressOfAscii(appKey), property.i, error.adr)
319
+ stak { nVRApplications_GetApplicationPropertyUint64(it. addressOfAscii(appKey), property.i, error.adr) }
315
320
316
321
/* *
317
322
* Sets the application auto-launch flag. This is only valid for applications which return true for
@@ -321,7 +326,7 @@ object vrApplications : vrInterface {
321
326
* @param autoLaunch
322
327
*/
323
328
fun setApplicationAutoLaunch (appKey : String , autoLaunch : Boolean ): Error =
324
- Error of nVRApplications_SetApplicationAutoLaunch(addressOfAscii(appKey), autoLaunch)
329
+ stak { Error of nVRApplications_SetApplicationAutoLaunch(it. addressOfAscii(appKey), autoLaunch) }
325
330
326
331
/* *
327
332
* Gets the application auto-launch flag. This is only valid for applications which return true for
@@ -330,7 +335,7 @@ object vrApplications : vrInterface {
330
335
* @param appKey
331
336
*/
332
337
infix fun getApplicationAutoLaunch (appKey : String ): Boolean =
333
- nVRApplications_GetApplicationAutoLaunch(addressOfAscii(appKey))
338
+ stak { nVRApplications_GetApplicationAutoLaunch(it. addressOfAscii(appKey)) }
334
339
335
340
/* *
336
341
* Adds this mime-type to the list of supported mime types for this application.
@@ -339,7 +344,7 @@ object vrApplications : vrInterface {
339
344
* @param mimeType
340
345
*/
341
346
fun setDefaultApplicationForMimeType (appKey : String , mimeType : String ): Error =
342
- Error of nVRApplications_SetDefaultApplicationForMimeType(addressOfAscii(appKey), addressOfAscii(mimeType))
347
+ stak { Error of nVRApplications_SetDefaultApplicationForMimeType(it. addressOfAscii(appKey), it. addressOfAscii(mimeType)) }
343
348
344
349
/* *
345
350
* Return the app key that will open this mime type. TODO offer a more convenient one?
@@ -348,8 +353,8 @@ object vrApplications : vrInterface {
348
353
* @param appKeyBuffer
349
354
*/
350
355
fun getDefaultApplicationForMimeType (mimeType : String , appKeyBuffer : ByteBuffer ? ): Boolean =
351
- nVRApplications_GetDefaultApplicationForMimeType(addressOfAscii(mimeType), appKeyBuffer?.adr
352
- ? : NULL , appKeyBuffer?.cap ? : 0 )
356
+ stak { nVRApplications_GetDefaultApplicationForMimeType(it. addressOfAscii(mimeType), appKeyBuffer?.adr
357
+ ? : NULL , appKeyBuffer?.cap ? : 0 ) }
353
358
354
359
/* *
355
360
* Get the list of supported mime types for this application, comma-delimited. TODO offer a more convenient one?
@@ -358,32 +363,35 @@ object vrApplications : vrInterface {
358
363
* @param mimeTypesBuffer
359
364
*/
360
365
fun getApplicationSupportedMimeTypes (appKey : String , mimeTypesBuffer : ByteBuffer ? ): Boolean =
361
- nVRApplications_GetApplicationSupportedMimeTypes(addressOfAscii(appKey), mimeTypesBuffer?.adr
362
- ? : NULL , mimeTypesBuffer?.rem ? : 0 )
366
+ stak { nVRApplications_GetApplicationSupportedMimeTypes(it. addressOfAscii(appKey), mimeTypesBuffer?.adr
367
+ ? : NULL , mimeTypesBuffer?.rem ? : 0 ) }
363
368
364
369
/* *
365
370
* Get the list of app-keys that support this mime type, comma-delimited, the return value is number of bytes you need to return the full string.
366
371
*
367
372
* @param mimeType
368
373
* @param appKeysThatSupportBufferSize
369
374
*/
370
- fun getApplicationsThatSupportMimeType (mimeType : String , appKeysThatSupportBufferSize : Int ): String {
371
- val appKeysThatSupportBuffer = stackGet().malloc(appKeysThatSupportBufferSize)
372
- val result = nVRApplications_GetApplicationsThatSupportMimeType(addressOfAscii(mimeType), appKeysThatSupportBuffer.adr, appKeysThatSupportBufferSize)
373
- return memASCII(appKeysThatSupportBuffer, result - 1 )
374
- }
375
+ fun getApplicationsThatSupportMimeType (mimeType : String , appKeysThatSupportBufferSize : Int ): String =
376
+ stak {
377
+ val appKeysThatSupportBuffer = it.malloc(appKeysThatSupportBufferSize)
378
+ val pMimeType = it.addressOfAscii(mimeType)
379
+ val result = nVRApplications_GetApplicationsThatSupportMimeType(pMimeType, appKeysThatSupportBuffer.adr, appKeysThatSupportBufferSize)
380
+ memASCII(appKeysThatSupportBuffer, result - 1 )
381
+ }
375
382
376
383
/* *
377
384
* Get the args list from an app launch that had the process already running, you call this when you get a {@link VR#EVREventType_VREvent_ApplicationMimeTypeLoad}.
378
385
*
379
386
* @param handle
380
387
* @param argsSize
381
388
*/
382
- fun getApplicationLaunchArguments (handle : Int , argsSize : Int ): String {
383
- val args = stackGet().malloc(argsSize)
384
- val result = nVRApplications_GetApplicationLaunchArguments(handle, args.adr, argsSize)
385
- return memASCII(args, result - 1 )
386
- }
389
+ fun getApplicationLaunchArguments (handle : Int , argsSize : Int ): String =
390
+ stak {
391
+ val args = it.malloc(argsSize)
392
+ val result = nVRApplications_GetApplicationLaunchArguments(handle, args.adr, argsSize)
393
+ memASCII(args, result - 1 )
394
+ }
387
395
388
396
/* *
389
397
* Returns the app key for the application that is starting up.
@@ -414,7 +422,7 @@ object vrApplications : vrInterface {
414
422
* @param appKey
415
423
*/
416
424
infix fun performApplicationPrelaunchCheck (appKey : String ): Error =
417
- Error of nVRApplications_PerformApplicationPrelaunchCheck(addressOfAscii(appKey))
425
+ stak { Error of nVRApplications_PerformApplicationPrelaunchCheck(it. addressOfAscii(appKey)) }
418
426
419
427
/* *
420
428
* Kind of useless on JVM, but it will be offered anyway on the enum itself
@@ -441,7 +449,7 @@ object vrApplications : vrInterface {
441
449
* @param workingDirectory
442
450
*/
443
451
fun launchInternalProcess (binaryPath : String , arguments : String , workingDirectory : String ): Error =
444
- Error of nVRApplications_LaunchInternalProcess(addressOfAscii(binaryPath), addressOfAscii(arguments), addressOfAscii(workingDirectory))
452
+ stak { Error of nVRApplications_LaunchInternalProcess(it. addressOfAscii(binaryPath), it. addressOfAscii(arguments), it. addressOfAscii(workingDirectory)) }
445
453
446
454
/* *
447
455
* Returns the current scene process ID according to the application system. A scene process will get scene focus once it starts rendering, but it will
0 commit comments