void OculusWorldDemoApp::InitMainFilePath() { // We try alternative relative locations for the file. const String contentBase = pPlatform->GetContentDirectory() + "/" + WORLDDEMO_ASSET_PATH; const char* baseDirectories[] = { "", contentBase.ToCStr(), #ifdef SHRDIR #define STR1(x) #x #define STR(x) STR1(x) STR(SHRDIR) "/OculusWorldDemo/Assets/Tuscany/" #endif }; String newPath; for(size_t i = 0; i < OVR_ARRAY_COUNT(baseDirectories); ++i) { newPath = baseDirectories[i]; newPath += WORLDDEMO_ASSET_FILE; OVR_DEBUG_LOG(("Trying to load the scene at: %s...", newPath.ToCStr())); if (SysFile(newPath).IsValid()) { OVR_DEBUG_LOG(("Success loading %s", newPath.ToCStr())); MainFilePath = newPath; return; } } OVR_DEBUG_LOG(("Unable to find any version of %s. Do you have your working directory set right?", WORLDDEMO_ASSET_FILE)); }
void UILabel::SetText( const String &text ) { VRMenuObject * object = GetMenuObject(); assert( object ); object->SetText( text.ToCStr() ); CalculateTextOffset(); }
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; }
void StringBuffer::operator = (const String& src) { const size_t size = src.GetSize(); Resize(size); OVR_ASSERT((pData != NULL) || (size == 0)); memcpy(pData, src.ToCStr(), size); }
// Returns HSWDisplayTimeNever (0) if there is no profile or this is the first time we are seeing this profile. time_t HSWDisplay::GetCurrentProfileLastHSWTime() const { // We store the timeout value in HMDState's pProfile. HMDState* pHMDState = (HMDState*)HMD->Handle; if (pHMDState) { const char* profileName = pHMDState->pProfile ? pHMDState->pProfile->GetValue(OVR_KEY_USER) : NULL; if (profileName) { if (LastProfileName == profileName) { return LastHSWTime; } LastProfileName = profileName; String timeKey = getHSWTimeKey(profileName); int lastTime = pHMDState->getIntValue(timeKey.ToCStr(), (int)HSWDisplayTimeNever); LastHSWTime = lastTime; return lastTime; } } return HSWDisplayTimeNever; }
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"); }
void GyroTempCalibration::SaveFile() { Ptr<JSON> root = *JSON::CreateObject(); root->AddNumberItem("Calibration Version", TEMP_CALIBRATION_FILE_VERSION_2); String str = GyroCalibrationToString(); root->AddStringItem("Data", str.ToCStr()); String path = GetCalibrationPath(true); root->Save(path); }
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; }
void OvrSoundManager::LoadSoundAssets() { Array<String> searchPaths; searchPaths.PushBack( "/storage/extSdCard/" ); searchPaths.PushBack( "/sdcard/" ); // First look for sound definition using SearchPaths for dev String foundPath; if ( GetFullPath( searchPaths, DEV_SOUNDS_RELATIVE, foundPath ) ) { JSON * dataFile = JSON::Load( foundPath.ToCStr() ); if ( dataFile == NULL ) { FAIL( "OvrSoundManager::LoadSoundAssets failed to load JSON meta file: %s", foundPath.ToCStr( ) ); } foundPath.StripTrailing( "sound_assets.json" ); LoadSoundAssetsFromJsonObject( foundPath, dataFile ); } else // if that fails, we are in release - load sounds from vrlib/res/raw and the assets folder { if ( ovr_PackageFileExists( VRLIB_SOUNDS ) ) { LoadSoundAssetsFromPackage( "res/raw/", VRLIB_SOUNDS ); } if ( ovr_PackageFileExists( APP_SOUNDS ) ) { LoadSoundAssetsFromPackage( "", APP_SOUNDS ); } } if ( SoundMap.IsEmpty() ) { #if defined( OVR_BUILD_DEBUG ) FAIL( "SoundManger - failed to load any sound definition files!" ); #else WARN( "SoundManger - failed to load any sound definition files!" ); #endif } }
void HMDDeviceFactory::EnumerateDevices(EnumerateVisitor& visitor) { // For now we'll assume the Rift DK1 is attached in extended monitor mode. Ultimately we need to // use XFree86 to enumerate X11 screens in case the Rift is attached as a separate screen. We also // need to be able to read the EDID manufacturer product code to be able to differentiate between // Rift models. bool foundHMD = false; Display* display = XOpenDisplay(NULL); if (display && XineramaIsActive(display)) { int numberOfScreens; XineramaScreenInfo* screens = XineramaQueryScreens(display, &numberOfScreens); for (int i = 0; i < numberOfScreens; i++) { XineramaScreenInfo screenInfo = screens[i]; if (screenInfo.width == 1280 && screenInfo.height == 800) { String deviceName = "OVR0001"; HMDDeviceCreateDesc hmdCreateDesc(this, deviceName, i); hmdCreateDesc.SetScreenParameters(screenInfo.x_org, screenInfo.y_org, 1280, 800, 0.14976f, 0.0936f); OVR_DEBUG_LOG_TEXT(("DeviceManager - HMD Found %s - %d\n", deviceName.ToCStr(), i)); // Notify caller about detected device. This will call EnumerateAddDevice // if the this is the first time device was detected. visitor.Visit(hmdCreateDesc); foundHMD = true; break; } } XFree(screens); } // Real HMD device is not found; however, we still may have a 'fake' HMD // device created via SensorDeviceImpl::EnumerateHMDFromSensorDisplayInfo. // Need to find it and set 'Enumerated' to true to avoid Removal notification. if (!foundHMD) { Ptr<DeviceCreateDesc> hmdDevDesc = getManager()->FindDevice("", Device_HMD); if (hmdDevDesc) hmdDevDesc->Enumerated = true; } }
// Helper function: obtain file information time. bool SysFile::GetFileStat(FileStat* pfileStat, const String& path) { #if defined(OVR_OS_WIN32) // 64-bit implementation on Windows. struct __stat64 fileStat; // Stat returns 0 for success. wchar_t *pwpath = (wchar_t*)OVR_ALLOC((UTF8Util::GetLength(path.ToCStr())+1)*sizeof(wchar_t)); UTF8Util::DecodeString(pwpath, path.ToCStr()); int ret = _wstat64(pwpath, &fileStat); OVR_FREE(pwpath); if (ret) return false; #else struct stat fileStat; // Stat returns 0 for success. if (stat(path, &fileStat) != 0) return false; #endif pfileStat->AccessTime = fileStat.st_atime; pfileStat->ModifyTime = fileStat.st_mtime; pfileStat->FileSize = fileStat.st_size; return true; }
//============================== // 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; }
bool HIDDevice::OnDeviceMessage(DeviceMessageType messageType, const String& devicePath, bool* error) { // Is this the correct device? if (DevDesc.Path.CompareNoCase(devicePath) != 0) { return false; } if (messageType == DeviceMessage_DeviceAdded && !Device) { // A closed device has been re-added. Try to reopen. if (!openDevice()) { LogError("OVR::Win32::HIDDevice - Failed to reopen a device '%s' that was re-added.\n", devicePath.ToCStr()); *error = true; return true; } LogText("OVR::Win32::HIDDevice - Reopened device '%s'\n", devicePath.ToCStr()); } HIDHandler::HIDDeviceMessageType handlerMessageType = HIDHandler::HIDDeviceMessage_DeviceAdded; if (messageType == DeviceMessage_DeviceAdded) { } else if (messageType == DeviceMessage_DeviceRemoved) { handlerMessageType = HIDHandler::HIDDeviceMessage_DeviceRemoved; } else { OVR_ASSERT(0); } if (Handler) { Handler->OnDeviceMessage(handlerMessageType); } *error = false; return true; }
void HSWDisplay::SetCurrentProfileLastHSWTime(time_t t) { // The timeout value is stored in HMDState's pProfile. HMDState* pHMDState = (HMDState*)HMD->Handle; if (pHMDState) { const char* profileName = pHMDState->pProfile ? pHMDState->pProfile->GetValue(OVR_KEY_USER) : NULL; if (profileName) { LastProfileName = profileName; LastHSWTime = (int)t; String timeKey = getHSWTimeKey(profileName); pHMDState->setIntValue(timeKey.ToCStr(), (int)t); } } }
//----------------------------------------------------------------------------- bool HIDDevice::HIDInitialize(const String& path) { const char* hid_path = path.ToCStr(); if (!openDevice(hid_path)) { LogText("OVR::Linux::HIDDevice - Failed to open HIDDevice: %s", hid_path); return false; } HIDManager->DevManager->pThread->AddTicksNotifier(this); HIDManager->AddNotificationDevice(this); LogText("OVR::Linux::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; }
static void LogHmdType(hmdType_t hmdType) { String str; switch(hmdType) { CASE_FOR_TYPE(HMD_GALAXY_OCULUS); CASE_FOR_TYPE(HMD_S4_GALAXY); CASE_FOR_TYPE(HMD_NOTE); CASE_FOR_TYPE(HMD_NOTE_4); CASE_FOR_TYPE(HMD_PM_GALAXY); CASE_FOR_TYPE(HMD_QM_GALAXY); CASE_FOR_TYPE(HMD_PM_GALAXY_WQHD); CASE_FOR_TYPE(HMD_QM_GALAXY_WQHD); default: str = "<type not known - add to LogHmdType function>"; } LogText("Detected HMD/Phone version: %s", str.ToCStr()); }
// DirPath should by a directory with a trailing slash. // Returns all files in all search paths, as unique relative paths. // Subdirectories will have a trailing slash. // All files and directories that start with . are skipped. StringHash< String > RelativeDirectoryFileList( const Array< String > & searchPaths, const char * RelativeDirPath ) { //Check each of the mirrors in searchPaths and build up a list of unique strings StringHash< String > uniqueStrings; const int numSearchPaths = searchPaths.GetSizeI(); for ( int index = 0; index < numSearchPaths; ++index ) { const String fullPath = searchPaths[index] + String( RelativeDirPath ); DIR * dir = opendir( fullPath.ToCStr() ); if ( dir != NULL ) { struct dirent * entry; while ( ( entry = readdir( dir ) ) != NULL ) { if ( entry->d_name[ 0 ] == '.' ) { continue; } if ( entry->d_type == DT_DIR ) { String s( RelativeDirPath ); s += entry->d_name; s += "/"; uniqueStrings.SetCaseInsensitive( s, s ); } else if ( entry->d_type == DT_REG ) { String s( RelativeDirPath ); s += entry->d_name; uniqueStrings.SetCaseInsensitive( s, s ); } } closedir( dir ); } } return uniqueStrings; }
void TestSerialFormatStuff() { for (int ii = 0; ii < 256; ++ii) { OVR_ASSERT(Base32FromChar[ii] == (char)DecodeBase32((char)ii)); } DK2BinarySerialFormat sa; sa.ProductId = DK2ProductId_DK2; sa.PartId = DK2PartId_HMD; sa.MinutesSinceEpoch = 65000; sa.UnitNumber = 2; sa.MacHash[0] = 0xa1; sa.MacHash[1] = 0xb2; sa.MacHash[2] = 0xc3; sa.MacHash[3] = 0xd4; sa.MacHash[4] = 0xe5; uint8_t buffer[12]; sa.ToBuffer(buffer); DK2BinarySerialFormat sb; OVR_ASSERT(sb.FromBuffer(buffer)); OVR_ASSERT(sa == sb); DK2PrintedSerialFormat psn; psn.FromBinary(sb); OVR_ASSERT(psn == sa); String s = psn.ToBase32(); DK2PrintedSerialFormat psn2; psn2.FromBase32(s.ToCStr()); OVR_ASSERT(psn == psn2); }
bool Gamepad::Open(const String& devicePathName) { Name = "Undefined"; Type = UNDEFINED; FileDescriptor = ::open(devicePathName.ToCStr(), O_RDONLY | O_NONBLOCK); if (FileDescriptor == -1) { return false; } // get the device name char name[128]; if (ioctl(FileDescriptor, JSIOCGNAME(sizeof(name)), name) < 0) { return false; } Name = name; // see if device name matches one of our supported devices static const UInt32 Wireless360Len = String(pNameXbox360Wireless).GetLength(); static const UInt32 Wired360Len = String(pNameXbox360Wired).GetLength(); if (Name.Substring(0, Wireless360Len) == pNameXbox360Wireless) { Type = XBOX360GAMEPADWIRELESS; return true; } else if(Name.Substring(0, Wired360Len) == pNameXbox360Wired) { Type = XBOX360GAMEPADWIRED; return true; } return false; }
bool HIDDevice::HIDInitialize(const String& path) { DevDesc.Path = path; if (!openDevice()) { LogText("OVR::Win32::HIDDevice - Failed to open HIDDevice: %s", path.ToCStr()); return false; } HIDManager->Manager->pThread->AddTicksNotifier(this); HIDManager->Manager->pThread->AddMessageNotifier(this); LogText("OVR::Win32::HIDDevice - Opened '%s'\n" " Manufacturer:'%s' Product:'%s' Serial#:'%s' Version:'%x'\n", DevDesc.Path.ToCStr(), DevDesc.Manufacturer.ToCStr(), DevDesc.Product.ToCStr(), DevDesc.SerialNumber.ToCStr(), DevDesc.VersionNumber); return true; }
// Loads the scene data void OculusWorldDemoApp::PopulateScene(const char *fileName) { ClearScene(); XmlHandler xmlHandler; if(!xmlHandler.ReadFile(fileName, pRender, &MainScene, &CollisionModels, &GroundCollisionModels, SrgbRequested, AnisotropicSample)) { Menu.SetPopupMessage("FILE LOAD FAILED"); Menu.SetPopupTimeout(10.0f, true); } MainScene.SetAmbient(Color4f(1.0f, 1.0f, 1.0f, 1.0f)); String mainFilePathNoExtension = MainFilePath; mainFilePathNoExtension.StripExtension(); unsigned int fillTextureLoadFlags = 0; fillTextureLoadFlags |= SrgbRequested ? TextureLoad_SrgbAware : 0; fillTextureLoadFlags |= AnisotropicSample ? TextureLoad_Anisotropic : 0; // 10x10x10 cubes. Ptr<Fill> fillR = *CreateTextureFill(pRender, mainFilePathNoExtension + "_greenCube.tga", fillTextureLoadFlags); PopulateCubeFieldScene(&GreenCubesScene, fillR.GetPtr(), 10, 10, 10, Vector3f(0.0f, 0.0f, 0.0f), 0.4f); Ptr<Fill> fillB = *CreateTextureFill(pRender, mainFilePathNoExtension + "_redCube.tga", fillTextureLoadFlags); PopulateCubeFieldScene(&RedCubesScene, fillB.GetPtr(), 10, 10, 10, Vector3f(0.0f, 0.0f, 0.0f), 0.4f); Ptr<Fill> fillY = *CreateTextureFill(pRender, mainFilePathNoExtension + "_yellowCube.tga", fillTextureLoadFlags); PopulateCubeFieldScene(&YellowCubesScene, fillY.GetPtr(), 10, 10, 10, Vector3f(0.0f, 0.0f, 0.0f), 0.4f); Ptr<Fill> imageFill = *CreateTextureFill(pRender, mainFilePathNoExtension + "_OculusCube.tga", fillTextureLoadFlags); PopulateCubeFieldScene(&OculusCubesScene, imageFill.GetPtr(), 11, 4, 35, Vector3f(0.0f, 0.0f, -6.0f), 0.5f); Vector3f blockModelSizeVec = Vector3f(BlockModelSize, BlockModelSize, BlockModelSize); // Handy untextured green cube. Ptr<Model> smallGreenCubeModel = *Model::CreateBox(Color(0, 255, 0, 255), Vector3f(0.0f, 0.0f, 0.0f), blockModelSizeVec); SmallGreenCube.World.Add(smallGreenCubeModel); // Textured cubes. Ptr<Model> smallOculusCubeModel = *Model::CreateBox(Color(255, 255, 255, 255), Vector3f(0.0f, 0.0f, 0.0f), blockModelSizeVec); smallOculusCubeModel->Fill = imageFill; SmallOculusCube.World.Add(smallOculusCubeModel); Ptr<Model> smallOculusGreenCubeModel = *Model::CreateBox(Color(255, 255, 255, 255), Vector3f(0.0f, 0.0f, 0.0f), blockModelSizeVec); smallOculusGreenCubeModel->Fill = fillR; SmallOculusGreenCube.World.Add(smallOculusGreenCubeModel); Ptr<Model> smallOculusRedCubeModel = *Model::CreateBox(Color(255, 255, 255, 255), Vector3f(0.0f, 0.0f, 0.0f), blockModelSizeVec); smallOculusRedCubeModel->Fill = fillB; SmallOculusRedCube.World.Add(smallOculusRedCubeModel); int textureLoadFlags = 0; textureLoadFlags |= SrgbRequested ? TextureLoad_SrgbAware : 0; textureLoadFlags |= AnisotropicSample ? TextureLoad_Anisotropic : 0; textureLoadFlags |= TextureLoad_MakePremultAlpha; textureLoadFlags |= TextureLoad_SwapTextureSet; Ptr<File> imageFile = *new SysFile(mainFilePathNoExtension + "_OculusCube.tga"); if (imageFile->IsValid()) TextureOculusCube = *LoadTextureTgaTopDown(pRender, imageFile, textureLoadFlags, 255); imageFile = *new SysFile(mainFilePathNoExtension + "_Cockpit_Panel.tga"); if (imageFile->IsValid()) CockpitPanelTexture = *LoadTextureTgaTopDown(pRender, imageFile, textureLoadFlags, 255); XmlHandler xmlHandler2; String controllerFilename = MainFilePath.GetPath() + "LeftController.xml"; if (!xmlHandler2.ReadFile(controllerFilename.ToCStr(), pRender, &ControllerScene, NULL, NULL)) { Menu.SetPopupMessage("CONTROLLER FILE LOAD FAILED"); Menu.SetPopupTimeout(10.0f, true); } ControllerScene.AddLight(Vector3f(0, 30.0f, 0), Color4f(1.0f, 1.0f, 1.0f, 1.0f)); ControllerScene.AddLight(Vector3f(0, -10.0f, 0), Color4f(.2f, .2f, .2f, 1.0f)); // Load "Floor Circle" models and textures - used to display floor for seated configuration. Ptr<File> floorImageFile = *new SysFile(mainFilePathNoExtension + "_SitFloorConcrete.tga"); Ptr<Texture> roundFloorTexture = *LoadTextureTgaTopDown(pRender, floorImageFile, textureLoadFlags, 220); if (roundFloorTexture) roundFloorTexture->SetSampleMode(Sample_Anisotropic | Sample_Repeat); Ptr<ShaderFill> fill = *new ShaderFill(*pRender->CreateShaderSet()); fill->GetShaders()->SetShader(pRender->LoadBuiltinShader(Shader_Vertex, VShader_MVP)); fill->GetShaders()->SetShader(pRender->LoadBuiltinShader(Shader_Fragment, FShader_Texture)); fill->SetTexture(0, roundFloorTexture); pRoundFloorModel[0] = *new Model(Prim_Triangles); pRoundFloorModel[0]->Fill = fill; AddFloorCircleModelVertices(pRoundFloorModel[0], 0.3f); OculusRoundFloor[0].World.Add(pRoundFloorModel[0]); pRoundFloorModel[1] = *new Model(Prim_Triangles); pRoundFloorModel[1]->Fill = fill; AddFloorCircleDonutModelVertices(pRoundFloorModel[1], 0.35f); OculusRoundFloor[1].World.Add(pRoundFloorModel[1]); if (ovr_GetTrackerCount(Session) > 0) PositionalTracker.Init(Session, mainFilePathNoExtension, pRender, SrgbRequested, AnisotropicSample); }
StringBuffer::StringBuffer(const String& src) : pData(NULL), Size(0), BufferSize(0), GrowSize(OVR_SBUFF_DEFAULT_GROW_SIZE), LengthIsSize(false) { AppendString(src.ToCStr(), src.GetSize()); }
void StringBuffer::operator = (const String& src) { Resize(src.GetSize()); memcpy(pData, src.ToCStr(), src.GetSize()); }
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; }
const char* FILEFile::GetFilePath() { return FileName.ToCStr(); }
void FILEFile::init() { // Open mode for file's open const char *omode = "rb"; if (OpenFlags & Open_Truncate) { if (OpenFlags & Open_Read) omode = "w+b"; else omode = "wb"; } else if (OpenFlags & Open_Create) { if (OpenFlags & Open_Read) omode = "a+b"; else omode = "ab"; } else if (OpenFlags & Open_Write) omode = "r+b"; #ifdef OVR_OS_WIN32 SysErrorModeDisabler disabler(FileName.ToCStr()); #endif #if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400) wchar_t womode[16]; wchar_t *pwFileName = (wchar_t*)OVR_ALLOC((UTF8Util::GetLength(FileName.ToCStr())+1) * sizeof(wchar_t)); UTF8Util::DecodeString(pwFileName, FileName.ToCStr()); OVR_ASSERT(strlen(omode) < sizeof(womode)/sizeof(womode[0])); UTF8Util::DecodeString(womode, omode); _wfopen_s(&fs, pwFileName, womode); OVR_FREE(pwFileName); #else fs = fopen(FileName.ToCStr(), omode); #endif if (fs) rewind (fs); Opened = (fs != NULL); // Set error code if (!Opened) ErrorCode = SFerror(); else { // If we are testing file seek correctness, pre-load the entire file so // that we can do comparison tests later. #ifdef OVR_FILE_VERIFY_SEEK_ERRORS TestPos = 0; fseek(fs, 0, SEEK_END); FileTestLength = ftell(fs); fseek(fs, 0, SEEK_SET); pFileTestBuffer = (UByte*)OVR_ALLOC(FileTestLength); if (pFileTestBuffer) { OVR_ASSERT(FileTestLength == (unsigned)Read(pFileTestBuffer, FileTestLength)); Seek(0, Seek_Set); } #endif ErrorCode = 0; } LastOp = 0; }
// Loads the scene data void OculusWorldDemoApp::PopulateScene(const char *fileName) { ClearScene(); XmlHandler xmlHandler; if(!xmlHandler.ReadFile(fileName, pRender, &MainScene, &CollisionModels, &GroundCollisionModels, SrgbRequested, AnisotropicSample)) { Menu.SetPopupMessage("FILE LOAD FAILED"); Menu.SetPopupTimeout(10.0f, true); } MainScene.SetAmbient(Color4f(1.0f, 1.0f, 1.0f, 1.0f)); String mainFilePathNoExtension = MainFilePath; mainFilePathNoExtension.StripExtension(); unsigned int fillTextureLoadFlags = 0; fillTextureLoadFlags |= SrgbRequested ? TextureLoad_SrgbAware : 0; fillTextureLoadFlags |= AnisotropicSample ? TextureLoad_Anisotropic : 0; // 10x10x10 cubes. Ptr<Fill> fillR = *CreateTextureFill(pRender, mainFilePathNoExtension + "_greenCube.tga", fillTextureLoadFlags); PopulateCubeFieldScene(&GreenCubesScene, fillR.GetPtr(), 10, 10, 10, Vector3f(0.0f, 0.0f, 0.0f), 0.4f); // 10x10x10 cubes. Ptr<Fill> fillB = *CreateTextureFill(pRender, mainFilePathNoExtension + "_redCube.tga", fillTextureLoadFlags); PopulateCubeFieldScene(&RedCubesScene, fillB.GetPtr(), 10, 10, 10, Vector3f(0.0f, 0.0f, 0.0f), 0.4f); // Anna: OculusWorldDemo/Assets/Tuscany/Tuscany_OculusCube.tga file needs to be added Ptr<Fill> imageFill = *CreateTextureFill(pRender, mainFilePathNoExtension + "_OculusCube.tga", fillTextureLoadFlags); PopulateCubeFieldScene(&OculusCubesScene, imageFill.GetPtr(), 11, 4, 35, Vector3f(0.0f, 0.0f, -6.0f), 0.5f); // Handy untextured green cube. Ptr<Model> smallGreenCubeModel = *Model::CreateBox(Color(0, 255, 0, 255), Vector3f(0.0f, 0.0f, 0.0f), Vector3f(0.004f, 0.004f, 0.004f)); SmallGreenCube.World.Add(smallGreenCubeModel); // Textured cubes. Ptr<Model> smallOculusCubeModel = *Model::CreateBox(Color(255, 255, 255, 255), Vector3f(0.0f, 0.0f, 0.0f), Vector3f(0.004f, 0.004f, 0.004f)); smallOculusCubeModel->Fill = imageFill; SmallOculusCube.World.Add(smallOculusCubeModel); Ptr<Model> smallOculusGreenCubeModel = *Model::CreateBox(Color(255, 255, 255, 255), Vector3f(0.0f, 0.0f, 0.0f), Vector3f(0.004f, 0.004f, 0.004f)); smallOculusGreenCubeModel->Fill = fillR; SmallOculusGreenCube.World.Add(smallOculusGreenCubeModel); Ptr<Model> smallOculusRedCubeModel = *Model::CreateBox(Color(255, 255, 255, 255), Vector3f(0.0f, 0.0f, 0.0f), Vector3f(0.004f, 0.004f, 0.004f)); smallOculusRedCubeModel->Fill = fillB; SmallOculusRedCube.World.Add(smallOculusRedCubeModel); int textureLoadFlags = 0; textureLoadFlags |= SrgbRequested ? TextureLoad_SrgbAware : 0; textureLoadFlags |= AnisotropicSample ? TextureLoad_Anisotropic : 0; textureLoadFlags |= TextureLoad_MakePremultAlpha; textureLoadFlags |= TextureLoad_SwapTextureSet; Ptr<File> imageFile = *new SysFile(mainFilePathNoExtension + "_redCube.tga"); if (imageFile->IsValid()) TextureRedCube = *LoadTextureTgaTopDown(pRender, imageFile, textureLoadFlags, 255); imageFile = *new SysFile(mainFilePathNoExtension + "_greenCube.tga"); if (imageFile->IsValid()) TextureGreenCube = *LoadTextureTgaTopDown(pRender, imageFile, textureLoadFlags, 255); imageFile = *new SysFile(mainFilePathNoExtension + "_OculusCube.tga"); if (imageFile->IsValid()) TextureOculusCube = *LoadTextureTgaTopDown(pRender, imageFile, textureLoadFlags, 255); imageFile = *new SysFile(mainFilePathNoExtension + "_Cockpit_Panel.tga"); if (imageFile->IsValid()) CockpitPanelTexture = *LoadTextureTgaTopDown(pRender, imageFile, textureLoadFlags, 255); XmlHandler xmlHandler2; String controllerFilename = MainFilePath.GetPath() + "LeftController.xml"; if (!xmlHandler2.ReadFile(controllerFilename.ToCStr(), pRender, &ControllerScene, NULL, NULL)) { Menu.SetPopupMessage("CONTROLLER FILE LOAD FAILED"); Menu.SetPopupTimeout(10.0f, true); } ControllerScene.AddLight(Vector3f(0, 30.0f, 0), Color4f(1.0f, 1.0f, 1.0f, 1.0f)); ControllerScene.AddLight(Vector3f(0, -10.0f, 0), Color4f(.2f, .2f, .2f, 1.0f)); }
GlTexture LoadTextureFromBuffer( const char * fileName, const MemBuffer & buffer, const TextureFlags_t & flags, int & width, int & height ) { const String ext = String( fileName ).GetExtension().ToLower(); // LOG( "Loading texture buffer %s (%s), length %i", fileName, ext.ToCStr(), buffer.Length ); GlTexture texId = 0; width = 0; height = 0; if ( fileName == NULL || buffer.Buffer == NULL || buffer.Length < 1 ) { // can't load anything from an empty buffer } else if ( ext == ".jpg" || ext == ".tga" || ext == ".png" || ext == ".bmp" || ext == ".psd" || ext == ".gif" || ext == ".hdr" || ext == ".pic" ) { // Uncompressed files loaded by stb_image int comp; stbi_uc * image = stbi_load_from_memory( (unsigned char *)buffer.Buffer, buffer.Length, &width, &height, &comp, 4 ); if ( image != NULL ) { const size_t dataSize = GetOvrTextureSize( Texture_RGBA, width, height ); texId = CreateGlTexture( fileName, Texture_RGBA, width, height, image, dataSize, 1 /* one mip level */, flags & TEXTUREFLAG_USE_SRGB, false ); free( image ); if ( !( flags & TEXTUREFLAG_NO_MIPMAPS ) ) { glBindTexture( texId.target, texId.texture ); glGenerateMipmap( texId.target ); glTexParameteri( texId.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); } } } else if ( ext == ".pvr" ) { texId = LoadTexturePVR( fileName, (const unsigned char *)buffer.Buffer, buffer.Length, ( flags & TEXTUREFLAG_USE_SRGB ), ( flags & TEXTUREFLAG_NO_MIPMAPS ), width, height ); } else if ( ext == ".ktx" ) { texId = LoadTextureKTX( fileName, (const unsigned char *)buffer.Buffer, buffer.Length, ( flags & TEXTUREFLAG_USE_SRGB ), ( flags & TEXTUREFLAG_NO_MIPMAPS ), width, height ); } else if ( ext == ".pkm" ) { LOG( "PKM format not supported" ); } else { LOG( "unsupported file extension %s", ext.ToCStr() ); } // Create a default texture if the load failed if ( texId.texture == 0 ) { LOG( "Failed to load %s", fileName ); if ( ( flags & TEXTUREFLAG_NO_DEFAULT ) == 0 ) { static uint8_t defaultTexture[8 * 8 * 3] = { 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 255,255,255, 255,255,255, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 255,255,255, 255,255,255, 64, 64, 64, 64, 64, 64, 255,255,255, 255,255,255, 64, 64, 64, 64, 64, 64, 255,255,255, 255,255,255, 64, 64, 64, 64, 64, 64, 255,255,255, 255,255,255, 64, 64, 64, 64, 64, 64, 255,255,255, 255,255,255, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 255,255,255, 255,255,255, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255 }; texId = LoadRGBTextureFromMemory( defaultTexture, 8, 8, flags & TEXTUREFLAG_USE_SRGB ); } } return texId; }
String GyroTempCalibration::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); } } #elif defined(OVR_OS_ANDROID) // TODO: We probably should use the location of Environment.getExternalStoragePublicDirectory() const char* home = "/sdcard"; path = home; path += "/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 // Note that getpwuid is not safe - it sometimes returns NULL for users from LDAP. const char* home = getenv("HOME"); 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; }
//----------------------------------------------------------------------------- // 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; }