Search in sources :

Example 1 with LongByReference

use of com.sun.jna.ptr.LongByReference in project jmonkeyengine by jMonkeyEngine.

the class OpenVR method initialize.

@Override
public boolean initialize() {
    logger.config("Initializing OpenVR system...");
    hmdErrorStore = new IntByReference();
    vrsystemFunctions = null;
    JOpenVRLibrary.VR_InitInternal(hmdErrorStore, JOpenVRLibrary.EVRApplicationType.EVRApplicationType_VRApplication_Scene);
    if (hmdErrorStore.getValue() == 0) {
        vrsystemFunctions = new VR_IVRSystem_FnTable(JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVRSystem_Version, hmdErrorStore).getPointer());
    }
    if (vrsystemFunctions == null || hmdErrorStore.getValue() != 0) {
        logger.severe("OpenVR Initialize Result: " + JOpenVRLibrary.VR_GetVRInitErrorAsEnglishDescription(hmdErrorStore.getValue()).getString(0));
        logger.severe("Initializing OpenVR system [FAILED]");
        return false;
    } else {
        logger.config("OpenVR initialized & VR connected.");
        vrsystemFunctions.setAutoSynch(false);
        vrsystemFunctions.read();
        tlastVsync = new FloatByReference();
        _tframeCount = new LongByReference();
        hmdDisplayFrequency = IntBuffer.allocate(1);
        hmdDisplayFrequency.put((int) JOpenVRLibrary.ETrackedDeviceProperty.ETrackedDeviceProperty_Prop_DisplayFrequency_Float);
        hmdTrackedDevicePoseReference = new TrackedDevicePose_t.ByReference();
        hmdTrackedDevicePoses = (TrackedDevicePose_t[]) hmdTrackedDevicePoseReference.toArray(JOpenVRLibrary.k_unMaxTrackedDeviceCount);
        poseMatrices = new Matrix4f[JOpenVRLibrary.k_unMaxTrackedDeviceCount];
        for (int i = 0; i < poseMatrices.length; i++) poseMatrices[i] = new Matrix4f();
        timePerFrame = 1.0 / hmdDisplayFrequency.get(0);
        // disable all this stuff which kills performance
        hmdTrackedDevicePoseReference.setAutoRead(false);
        hmdTrackedDevicePoseReference.setAutoWrite(false);
        hmdTrackedDevicePoseReference.setAutoSynch(false);
        for (int i = 0; i < JOpenVRLibrary.k_unMaxTrackedDeviceCount; i++) {
            hmdTrackedDevicePoses[i].setAutoRead(false);
            hmdTrackedDevicePoses[i].setAutoWrite(false);
            hmdTrackedDevicePoses[i].setAutoSynch(false);
        }
        // init controllers for the first time
        VRinput = new OpenVRInput(environment);
        VRinput.init();
        VRinput.updateConnectedControllers();
        // init bounds & chaperone info
        VRBounds.init();
        logger.config("Initializing OpenVR system [SUCCESS]");
        initSuccess = true;
        return true;
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) Matrix4f(com.jme3.math.Matrix4f) FloatByReference(com.sun.jna.ptr.FloatByReference) LongByReference(com.sun.jna.ptr.LongByReference) TrackedDevicePose_t(com.jme3.system.jopenvr.TrackedDevicePose_t) VR_IVRSystem_FnTable(com.jme3.system.jopenvr.VR_IVRSystem_FnTable)

Example 2 with LongByReference

use of com.sun.jna.ptr.LongByReference in project jna by java-native-access.

the class StructureTest method testAlignStruct.

private void testAlignStruct(int index) {
    AlignmentTest lib = Native.loadLibrary("testlib", AlignmentTest.class);
    try {
        IntByReference offset = new IntByReference();
        LongByReference value = new LongByReference();
        Class<?> cls = Class.forName(getClass().getName() + "$TestStructure" + index);
        Structure s = (Structure) cls.newInstance();
        int result = lib.testStructureAlignment(s, index, offset, value);
        assertEquals("Wrong native value at field " + result + "=0x" + Long.toHexString(value.getValue()) + " (actual native field offset=" + offset.getValue() + ") in " + s, -2, result);
    } catch (Exception e) {
        throw new Error(e);
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) LongByReference(com.sun.jna.ptr.LongByReference)

Example 3 with LongByReference

use of com.sun.jna.ptr.LongByReference in project jna by java-native-access.

the class SystemBTest method testHostPageSize.

public void testHostPageSize() {
    int machPort = SystemB.INSTANCE.mach_host_self();
    assertTrue(machPort > 0);
    LongByReference pPageSize = new LongByReference();
    int ret = SystemB.INSTANCE.host_page_size(machPort, pPageSize);
    assertEquals(ret, 0);
    // Probably 4096, definitely a power of 2
    assertTrue(pPageSize.getValue() > 0);
    assertEquals(pPageSize.getValue() & (pPageSize.getValue() - 1), 0);
}
Also used : LongByReference(com.sun.jna.ptr.LongByReference)

Example 4 with LongByReference

use of com.sun.jna.ptr.LongByReference in project jna by java-native-access.

the class ByReferenceArgumentsTest method testLongByReference.

public void testLongByReference() {
    LongByReference lref = new LongByReference();
    lib.incrementInt64ByReference(lref);
    assertEquals("Long argument not modified", 1, lref.getValue());
}
Also used : LongByReference(com.sun.jna.ptr.LongByReference) NativeLongByReference(com.sun.jna.ptr.NativeLongByReference)

Example 5 with LongByReference

use of com.sun.jna.ptr.LongByReference in project intellij-community by JetBrains.

the class NativeFileManager method getProcessesUsing.

public static List<Process> getProcessesUsing(File file) {
    List<Process> processes = new LinkedList<>();
    // If the DLL was not present (XP or other OS), do not try to find it again.
    if (ourFailed) {
        return processes;
    }
    try {
        IntByReference session = new IntByReference();
        char[] sessionKey = new char[Win32RestartManager.CCH_RM_SESSION_KEY + 1];
        int error = Win32RestartManager.INSTANCE.RmStartSession(session, 0, sessionKey);
        if (error != 0) {
            Runner.logger().warn("Unable to start restart manager session");
            return processes;
        }
        StringArray resources = new StringArray(new WString[] { new WString(file.toString()) });
        error = Win32RestartManager.INSTANCE.RmRegisterResources(session.getValue(), 1, resources, 0, Pointer.NULL, 0, null);
        if (error != 0) {
            Runner.logger().warn("Unable to register restart manager resource " + file.getAbsolutePath());
            return processes;
        }
        IntByReference procInfoNeeded = new IntByReference();
        Win32RestartManager.RmProcessInfo info = new Win32RestartManager.RmProcessInfo();
        Win32RestartManager.RmProcessInfo[] infos = (Win32RestartManager.RmProcessInfo[]) info.toArray(MAX_PROCESSES);
        IntByReference procInfo = new IntByReference(infos.length);
        error = Win32RestartManager.INSTANCE.RmGetList(session.getValue(), procInfoNeeded, procInfo, info, new LongByReference());
        if (error != 0) {
            Runner.logger().warn("Unable to get the list of processes using " + file.getAbsolutePath());
            return processes;
        }
        for (int i = 0; i < procInfo.getValue(); i++) {
            processes.add(new Process(infos[i].Process.dwProcessId, new String(infos[i].strAppName).trim()));
        }
        Win32RestartManager.INSTANCE.RmEndSession(session.getValue());
    } catch (Throwable t) {
        // Best effort approach, if no DLL is found ignore.
        ourFailed = true;
    }
    return processes;
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) WString(com.sun.jna.WString) LinkedList(java.util.LinkedList) WString(com.sun.jna.WString) StringArray(com.sun.jna.StringArray) LongByReference(com.sun.jna.ptr.LongByReference)

Aggregations

LongByReference (com.sun.jna.ptr.LongByReference)5 IntByReference (com.sun.jna.ptr.IntByReference)3 Matrix4f (com.jme3.math.Matrix4f)1 TrackedDevicePose_t (com.jme3.system.jopenvr.TrackedDevicePose_t)1 VR_IVRSystem_FnTable (com.jme3.system.jopenvr.VR_IVRSystem_FnTable)1 StringArray (com.sun.jna.StringArray)1 WString (com.sun.jna.WString)1 FloatByReference (com.sun.jna.ptr.FloatByReference)1 NativeLongByReference (com.sun.jna.ptr.NativeLongByReference)1 LinkedList (java.util.LinkedList)1