Example #1
0
void MeganekkoActivity::OneTimeInit(const char * fromPackage, const char * launchIntentJSON, const char * launchIntentURI)
{
    const ovrJava * java = app->GetJava();
    SoundEffectContext = new ovrSoundEffectContext( *java->Env, java->ActivityObject );
    SoundEffectContext->Initialize();
    SoundEffectPlayer = new OvrGuiSys::ovrDummySoundEffectPlayer();

    Locale = ovrLocale::Create( *app, "default" );

    String fontName;
    GetLocale().GetString( "@string/font_name", "efigs.fnt", fontName );
    GuiSys->Init( this->app, *SoundEffectPlayer, fontName.ToCStr(), &app->GetDebugLines() );

    jmethodID oneTimeInitMethodId = GetMethodID("oneTimeInit", "()V");
    app->GetJava()->Env->CallVoidMethod(app->GetJava()->ActivityObject, oneTimeInitMethodId);

    // cache method IDs
    enteredVrModeMethodId = GetMethodID("enteredVrMode", "()V");
    leavingVrModeMethodId = GetMethodID("leavingVrMode", "()V");
    onHmdMountedMethodId = GetMethodID("onHmdMounted", "()V");
    onHmdUnmountedMethodId = GetMethodID("onHmdUnmounted", "()V");
    frameMethodId = GetMethodID("frame", "(J)V");
    onKeyShortPressMethodId = GetMethodID("onKeyShortPress", "(II)Z");
    onKeyDoubleTapMethodId = GetMethodID("onKeyDoubleTap", "(II)Z");
    onKeyLongPressMethodId = GetMethodID("onKeyLongPress", "(II)Z");
    onKeyDownMethodId = GetMethodID("onKeyDown", "(II)Z");
    onKeyUpMethodId = GetMethodID("onKeyUp", "(II)Z");
    onKeyMaxMethodId = GetMethodID("onKeyMax", "(II)Z");
    getNativeSceneMethodId = GetMethodID("getNativeScene", "()J");
}
bool HIDDevice::HIDInitialize(const String& path)
{

    DevDesc.Path = path;

    if (!openDevice())
    {
        LogText("OVR::OSX::HIDDevice - Failed to open HIDDevice: %s", path.ToCStr());
        return false;
    }

    // Setup notification for when a device is unplugged and plugged back in.
    if (!setupDevicePluggedInNotification())
    {
        LogText("OVR::OSX::HIDDevice - Failed to setup notification for when device plugged back in.");
        closeDevice(false);
        return false;
    }
    
    HIDManager->DevManager->pThread->AddTicksNotifier(this);

    
    LogText("OVR::OSX::HIDDevice - Opened '%s'\n"
            "                    Manufacturer:'%s'  Product:'%s'  Serial#:'%s'\n",
            DevDesc.Path.ToCStr(),
            DevDesc.Manufacturer.ToCStr(), DevDesc.Product.ToCStr(),
            DevDesc.SerialNumber.ToCStr());
    
    return true;
}
bool HIDDeviceManager::getPath(IOHIDDeviceRef device, String* pPath)
{

    String transport;
    if (!getStringProperty(device, CFSTR(kIOHIDTransportKey), &transport))
    {
        return false;
    }
    
    UInt16 vendorId;
    if (!getVendorId(device, &vendorId))
    {
        return false;
    }

    UInt16 productId;
    if (!getProductId(device, &productId))
    {
        return false;
    }
    
    String serialNumber;
	if (!getSerialNumberString(device, &serialNumber))
    {
        return false;
    }
    

    StringBuffer buffer;
    buffer.AppendFormat("%s:vid=%04hx:pid=%04hx:ser=%s",
                            transport.ToCStr(),
                            vendorId,
                            productId,
                            serialNumber.ToCStr());
    
    *pPath = String(buffer);
    
    return true;
}
Example #4
0
//==============================
// BitmapFontLocal::Load
bool BitmapFontLocal::Load( char const * languagePackageName, char const * fontInfoFileName )
{
	OvrApkFile languagePackageFile( ovr_OpenOtherApplicationPackage( languagePackageName ) );
	if ( !FontInfo.Load( languagePackageFile, fontInfoFileName ) )
	{
		return false;
	}

	// strip any path from the image file name path and prepend the path from the .fnt file -- i.e. always
	// require them to be loaded from the same directory.
	String baseName = FontInfo.ImageFileName.GetFilename();
	LOG( "fontInfoFileName = %s", fontInfoFileName );
	LOG( "image baseName = %s", baseName.ToCStr() );
	
	char imagePath[512];
	StripFileName( fontInfoFileName, imagePath, sizeof( imagePath ) );
	LOG( "imagePath = %s", imagePath );
	
	char imageFileName[512];
	StripPath( fontInfoFileName, imageFileName, sizeof( imageFileName ) );
	LOG( "imageFileName = %s", imageFileName );
	
	AppendPath( imagePath, sizeof( imagePath ), baseName.ToCStr() );
	if ( !LoadImage( languagePackageFile, imagePath ) )
	{
		return false;
	}

    // create the shaders for font rendering if not already created
    if ( FontProgram.vertexShader == 0 || FontProgram.fragmentShader == 0 )
    {
        FontProgram = BuildProgram( FontSingleTextureVertexShaderSrc, SDFFontFragmentShaderSrc );//SingleTextureFragmentShaderSrc );
    }

	return true;
}
Example #5
0
//-----------------------------------------------------------------------------
// Returns the pathname of the JSON file containing the stored profiles
String GetBaseOVRPath(bool create_dir)
{
    String path;

#if defined(OVR_OS_WIN32)

    TCHAR data_path[MAX_PATH];
    SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, NULL, 0, data_path);
    path = String(data_path);
    
    path += "/Oculus";

    if (create_dir)
    {   // Create the Oculus directory if it doesn't exist
        WCHAR wpath[128];
        OVR::UTF8Util::DecodeString(wpath, path.ToCStr());

        DWORD attrib = GetFileAttributes(wpath);
        bool exists = attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY);
        if (!exists)
        {   
            CreateDirectory(wpath, NULL);
        }
    }
        
#elif defined(OVR_OS_MAC)

    const char* home = getenv("HOME");
    path = home;
    path += "/Library/Preferences/Oculus";

    if (create_dir)
    {   // Create the Oculus directory if it doesn't exist
        DIR* dir = opendir(path);
        if (dir == NULL)
        {
            mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO);
        }
        else
        {
            closedir(dir);
        }
    }

#else

    passwd* pwd = getpwuid(getuid());
    const char* home = pwd->pw_dir;
    path = home;
    path += "/.config/Oculus";

    if (create_dir)
    {   // Create the Oculus directory if it doesn't exist
        DIR* dir = opendir(path);
        if (dir == NULL)
        {
            mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO);
        }
        else
        {
            closedir(dir);
        }
    }

#endif

    return path;
}
bool DeviceManagerThread::OnMessage(MessageType type, const String& devicePath)
{
	Notifier::DeviceMessageType notifierMessageType = Notifier::DeviceMessage_DeviceAdded;
	if (type == DeviceAdded)
	{
	}
	else if (type == DeviceRemoved)
	{
		notifierMessageType = Notifier::DeviceMessage_DeviceRemoved;
	}
	else
	{
		OVR_ASSERT(false);
	}

	bool error = false;
    bool deviceFound = false;
	for (UPInt i = 0; i < MessageNotifiers.GetSize(); i++)
    {
		if (MessageNotifiers[i] && 
			MessageNotifiers[i]->OnDeviceMessage(notifierMessageType, devicePath, &error))
		{
			// The notifier belonged to a device with the specified device name so we're done.
            deviceFound = true;
			break;
		}
    }
    if (type == DeviceAdded && !deviceFound)
    {
        Lock::Locker devMgrLock(&DevMgrLock);
        // a new device was connected. Go through all device factories and
        // try to detect the device using HIDDeviceDesc.
        HIDDeviceDesc devDesc;
        if (pDeviceMgr->GetHIDDeviceDesc(devicePath, &devDesc))
        {
            Lock::Locker deviceLock(pDeviceMgr->GetLock());
            DeviceFactory* factory = pDeviceMgr->Factories.GetFirst();
            while(!pDeviceMgr->Factories.IsNull(factory))
            {
                if (factory->DetectHIDDevice(pDeviceMgr, devDesc))
                {
                    deviceFound = true;
                    break;
                }
                factory = factory->pNext;
            }
        }
    }

    if (!deviceFound && strstr(devicePath.ToCStr(), "#OVR00"))
    {
        Ptr<DeviceManager> pmgr;
        {
            Lock::Locker devMgrLock(&DevMgrLock);
            pmgr = pDeviceMgr;
        }
        // HMD plugged/unplugged
        // This is not a final solution to enumerate HMD devices and get
        // a first available handle. This won't work with multiple rifts.
        // @TODO (!AB)
        pmgr->EnumerateDevices<HMDDevice>();
    }

	return !error;
}