summaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/OVR_Profile.h
blob: df25fead9573269f099339d4700da9e5903d8c1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/************************************************************************************

PublicHeader:   OVR.h
Filename    :   OVR_Profile.h
Content     :   Structs and functions for loading and storing device profile settings
Created     :   February 14, 2013
Notes       :
   Profiles are used to store per-user settings that can be transferred and used
   across multiple applications.  For example, player IPD can be configured once 
   and reused for a unified experience across games.  Configuration and saving of profiles
   can be accomplished in game via the Profile API or by the official Oculus Configuration
   Utility.

Copyright   :   Copyright 2013 Oculus VR, Inc. All Rights reserved.

Use of this software is subject to the terms of the Oculus license
agreement provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.

************************************************************************************/

#ifndef OVR_Profile_h
#define OVR_Profile_h

#include "Kernel/OVR_String.h"
#include "Kernel/OVR_RefCount.h"
#include "Kernel/OVR_Array.h"

namespace OVR {

// Defines the profile object for each device type
enum ProfileType
{
    Profile_Unknown       = 0,
    Profile_GenericHMD    = 10,
    Profile_RiftDK1       = 11,
    Profile_RiftDKHD      = 12,
};

class Profile;

// -----------------------------------------------------------------------------
// ***** ProfileManager

// Profiles are interfaced through a ProfileManager object.  Applications should
// create a ProfileManager each time they intend to read or write user profile data.
// The scope of the ProfileManager object defines when disk I/O is performed.  Disk
// reads are performed on the first profile access and disk writes are performed when
// the ProfileManager goes out of scope.  All profile interactions between these times
// are performed in local memory and are fast.  A typical profile interaction might
// look like this:
//
// {
//     Ptr<ProfileManager> pm      = *ProfileManager::Create();
//     Ptr<Profile>        profile = pm->LoadProfile(Profile_RiftDK1,
//                                                   pm->GetDefaultProfileName(Profile_RiftDK1));
//     if (profile)
//     {   // Retrieve the current profile settings
//     }
// }   // Profile will be destroyed and any disk I/O completed when going out of scope

class ProfileManager : public RefCountBase<ProfileManager>
{
protected:
    // Synchronize ProfileManager access since it may be accessed from multiple threads,
    // as it's shared through DeviceManager.
    Lock                    ProfileLock;
    Array<Ptr<Profile> >    ProfileCache;
    ProfileType             CacheDevice;
    String                  DefaultProfile;
    bool                    Changed;
    char                    NameBuff[32];
    
public:
    static ProfileManager* Create();

    // Static interface functions
    int                 GetProfileCount(ProfileType device);
    const char*         GetProfileName(ProfileType device, unsigned int index);
    bool                HasProfile(ProfileType device, const char* name);
    Profile*            LoadProfile(ProfileType device, unsigned int index);
    Profile*            LoadProfile(ProfileType device, const char* name);
    Profile*            GetDeviceDefaultProfile(ProfileType device);
    const char*         GetDefaultProfileName(ProfileType device);
    bool                SetDefaultProfileName(ProfileType device, const char* name);
    bool                Save(const Profile* profile);
    bool                Delete(const Profile* profile);

protected:
    ProfileManager();
    ~ProfileManager();
    void                LoadCache(ProfileType device);
    void                SaveCache();
    void                ClearCache();
    Profile*            CreateProfileObject(const char* user,
                                            ProfileType device,
                                            const char** device_name);
};

//-------------------------------------------------------------------
// ***** Profile

// The base profile for all users.  This object is not created directly.
// Instead derived device objects provide add specific device members to 
// the base profile

class Profile : public RefCountBase<Profile>
{
public:
    enum { MaxNameLen    = 32 };

    enum GenderType
    {
        Gender_Unspecified  = 0,
        Gender_Male         = 1,
        Gender_Female       = 2
    };

    ProfileType          Type;              // The type of device profile
    char                 Name[MaxNameLen];  // The name given to this profile

protected:
    GenderType           Gender;            // The gender of the user
    float                PlayerHeight;      // The height of the user in meters
    float                IPD;               // Distance between eyes in meters

public:
    virtual Profile*     Clone() const = 0;

    // These are properties which are intrinsic to the user and affect scene setup
    GenderType           GetGender()                     { return Gender; };
    float                GetPlayerHeight()               { return PlayerHeight; };
    float                GetIPD()                        { return IPD; };
    float                GetEyeHeight();    
    
    void                 SetGender(GenderType gender)    { Gender = gender; };
    void                 SetPlayerHeight(float height)   { PlayerHeight = height; };
    void                 SetIPD(float ipd)               { IPD = ipd; };

protected:
    Profile(ProfileType type, const char* name);
    
    virtual bool         ParseProperty(const char* prop, const char* sval);
    
    friend class ProfileManager;
};

//-----------------------------------------------------------------------------
// ***** HMDProfile

// The generic HMD profile is used for properties that are common to all headsets
class HMDProfile : public Profile
{
protected:
    // FOV extents in pixels measured by a user
    int                 LL;       // left eye outer extent
    int                 LR;       // left eye inner extent
    int                 RL;       // right eye inner extent
    int                 RR;       // right eye outer extent

public:
    virtual Profile*    Clone() const;

    void SetLL(int val) { LL = val; };
    void SetLR(int val) { LR = val; };
    void SetRL(int val) { RL = val; };
    void SetRR(int val) { RR = val; };

    int GetLL() { return LL; };
    int GetLR() { return LR; };
    int GetRL() { return RL; };
    int GetRR() { return RR; };

protected:
    HMDProfile(ProfileType type, const char* name);

    virtual bool        ParseProperty(const char* prop, const char* sval);

    friend class ProfileManager;
};

// For headsets that use eye cups
enum EyeCupType
{
    EyeCup_A = 0,
    EyeCup_B = 1,
    EyeCup_C = 2
};

//-----------------------------------------------------------------------------
// ***** RiftDK1Profile

// This profile is specific to the Rift Dev Kit 1 and contains overrides specific 
// to that device and lens cup settings.
class RiftDK1Profile : public HMDProfile
{
protected:
    EyeCupType          EyeCups;   // Which eye cup does the player use

public:
    virtual Profile*    Clone() const;

    EyeCupType          GetEyeCup() { return EyeCups; };
    void                SetEyeCup(EyeCupType cup) { EyeCups = cup; };

protected:
    RiftDK1Profile(const char* name);

    virtual bool        ParseProperty(const char* prop, const char* sval);

    friend class ProfileManager;
};

//-----------------------------------------------------------------------------
// ***** RiftDKHDProfile

// This profile is specific to the Rift HD Dev Kit and contains overrides specific 
// to that device and lens cup settings.
class RiftDKHDProfile : public HMDProfile
{
protected:
    EyeCupType          EyeCups;   // Which eye cup does the player use

public:
    virtual Profile*    Clone() const;

    EyeCupType          GetEyeCup() { return EyeCups; };
    void                SetEyeCup(EyeCupType cup) { EyeCups = cup; };

protected:
    RiftDKHDProfile(const char* name);

    virtual bool        ParseProperty(const char* prop, const char* sval);

    friend class ProfileManager;
};


String GetBaseOVRPath(bool create_dir);

}

#endif // OVR_Profile_h