oculus1

view libovr/Src/OVR_Profile.h @ 23:0c76f70fb7e9

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 28 Sep 2013 04:13:33 +0300
parents
children
line source
1 /************************************************************************************
3 PublicHeader: OVR.h
4 Filename : OVR_Profile.h
5 Content : Structs and functions for loading and storing device profile settings
6 Created : February 14, 2013
7 Notes :
8 Profiles are used to store per-user settings that can be transferred and used
9 across multiple applications. For example, player IPD can be configured once
10 and reused for a unified experience across games. Configuration and saving of profiles
11 can be accomplished in game via the Profile API or by the official Oculus Configuration
12 Utility.
14 Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved.
16 Use of this software is subject to the terms of the Oculus license
17 agreement provided at the time of installation or download, or which
18 otherwise accompanies this software in either electronic or hard copy form.
20 ************************************************************************************/
22 #ifndef OVR_Profile_h
23 #define OVR_Profile_h
25 #include "Kernel/OVR_String.h"
26 #include "Kernel/OVR_RefCount.h"
27 #include "Kernel/OVR_Array.h"
29 namespace OVR {
31 // Defines the profile object for each device type
32 enum ProfileType
33 {
34 Profile_Unknown = 0,
35 Profile_RiftDK1 = 1,
36 Profile_RiftDKHD = 2,
37 };
39 class Profile;
41 // -----------------------------------------------------------------------------
42 // ***** ProfileManager
44 // Profiles are interfaced through a ProfileManager object. Applications should
45 // create a ProfileManager each time they intend to read or write user profile data.
46 // The scope of the ProfileManager object defines when disk I/O is performed. Disk
47 // reads are performed on the first profile access and disk writes are performed when
48 // the ProfileManager goes out of scope. All profile interactions between these times
49 // are performed in local memory and are fast. A typical profile interaction might
50 // look like this:
51 //
52 // {
53 // Ptr<ProfileManager> pm = *ProfileManager::Create();
54 // Ptr<Profile> profile = pm->LoadProfile(Profile_RiftDK1,
55 // pm->GetDefaultProfileName(Profile_RiftDK1));
56 // if (profile)
57 // { // Retrieve the current profile settings
58 // }
59 // } // Profile will be destroyed and any disk I/O completed when going out of scope
61 class ProfileManager : public RefCountBase<ProfileManager>
62 {
63 protected:
64 // Synchronize ProfileManager access since it may be accessed from multiple threads,
65 // as it's shared through DeviceManager.
66 Lock ProfileLock;
67 Array<Ptr<Profile> > ProfileCache;
68 ProfileType CacheDevice;
69 String DefaultProfile;
70 bool Changed;
71 char NameBuff[32];
73 public:
74 static ProfileManager* Create();
76 // Static interface functions
77 int GetProfileCount(ProfileType device);
78 const char* GetProfileName(ProfileType device, unsigned int index);
79 bool HasProfile(ProfileType device, const char* name);
80 Profile* LoadProfile(ProfileType device, unsigned int index);
81 Profile* LoadProfile(ProfileType device, const char* name);
82 Profile* GetDeviceDefaultProfile(ProfileType device);
83 const char* GetDefaultProfileName(ProfileType device);
84 bool SetDefaultProfileName(ProfileType device, const char* name);
85 bool Save(const Profile* profile);
86 bool Delete(const Profile* profile);
88 protected:
89 ProfileManager();
90 ~ProfileManager();
91 void LoadCache(ProfileType device);
92 void SaveCache();
93 void ClearCache();
94 Profile* CreateProfileObject(const char* user,
95 ProfileType device,
96 const char** device_name);
97 };
99 //-------------------------------------------------------------------
100 // ***** Profile
102 // The base profile for all HMD devices. This object is never created directly.
103 // Instead derived objects provide specific data implementations. Some settings
104 // such as IPD will be tied to a specific user and be consistent between ,
105 // implementations but other settings like optical distortion may vary between devices.
107 class Profile : public RefCountBase<Profile>
108 {
109 public:
110 enum { MaxNameLen = 32 };
112 enum GenderType
113 {
114 Gender_Unspecified = 0,
115 Gender_Male = 1,
116 Gender_Female = 2
117 };
119 ProfileType Type; // The type of device profile
120 char Name[MaxNameLen]; // The name given to this profile
122 protected:
123 GenderType Gender; // The gender of the user
124 float PlayerHeight; // The height of the user in meters
125 float IPD; // Distance between eyes in meters
127 public:
128 // These are properties which are intrinsic to the user and affect scene setup
129 GenderType GetGender() { return Gender; };
130 float GetPlayerHeight() { return PlayerHeight; };
131 float GetIPD() { return IPD; };
132 float GetEyeHeight();
134 void SetGender(GenderType gender) { Gender = gender; };
135 void SetPlayerHeight(float height) { PlayerHeight = height; };
136 void SetIPD(float ipd) { IPD = ipd; };
139 protected:
140 Profile(ProfileType type, const char* name);
142 virtual Profile* Clone() const = 0;
143 virtual bool ParseProperty(const char* prop, const char* sval);
145 friend class ProfileManager;
146 };
149 //-----------------------------------------------------------------------------
150 // ***** RiftDK1Profile
152 // This profile is specific to the Rift Dev Kit 1 and contains overrides specific
153 // to that device and lens cup settings.
154 class RiftDK1Profile : public Profile
155 {
156 public:
157 enum EyeCupType
158 {
159 EyeCup_A = 0,
160 EyeCup_B = 1,
161 EyeCup_C = 2
162 };
164 protected:
165 EyeCupType EyeCups; // Which eye cup does the player use
166 int LL; // Configuration Utility IPD setting
167 int LR; // Configuration Utility IPD setting
168 int RL; // Configuration Utility IPD setting
169 int RR; // Configuration Utility IPD setting
171 public:
172 EyeCupType GetEyeCup() { return EyeCups; };
173 void SetEyeCup(EyeCupType cup) { EyeCups = cup; };
175 protected:
176 RiftDK1Profile(const char* name);
178 virtual Profile* Clone() const;
179 virtual bool ParseProperty(const char* prop, const char* sval);
181 friend class ProfileManager;
182 };
185 String GetBaseOVRPath(bool create_dir);
187 }
189 #endif // OVR_Profile_h