mirror of https://github.com/bjornbytes/lovr.git
getType -> getName;
This commit is contained in:
parent
b9c5dce584
commit
b0067233f7
|
@ -26,16 +26,6 @@ const char* HeadsetOrigins[] = {
|
|||
NULL
|
||||
};
|
||||
|
||||
const char* HeadsetTypes[] = {
|
||||
[HEADSET_UNKNOWN] = "unknown",
|
||||
[HEADSET_VIVE] = "vive",
|
||||
[HEADSET_RIFT] = "rift",
|
||||
[HEADSET_GEAR] = "gear",
|
||||
[HEADSET_GO] = "go",
|
||||
[HEADSET_WINDOWS_MR] = "windowsmr",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char* Subpaths[] = {
|
||||
[PATH_NONE] = "",
|
||||
[PATH_HEAD] = "head",
|
||||
|
@ -136,8 +126,8 @@ static int l_lovrHeadsetGetDriver(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetType(lua_State* L) {
|
||||
lua_pushstring(L, HeadsetTypes[lovrHeadsetDriver->getType()]);
|
||||
static int l_lovrHeadsetGetName(lua_State* L) {
|
||||
lua_pushstring(L, lovrHeadsetDriver->getName());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -419,7 +409,7 @@ static int l_lovrHeadsetGetMirrorTexture(lua_State* L) {
|
|||
|
||||
static const luaL_Reg lovrHeadset[] = {
|
||||
{ "getDriver", l_lovrHeadsetGetDriver },
|
||||
{ "getType", l_lovrHeadsetGetType },
|
||||
{ "getName", l_lovrHeadsetGetName },
|
||||
{ "getOriginType", l_lovrHeadsetGetOriginType },
|
||||
{ "getDisplayWidth", l_lovrHeadsetGetDisplayWidth },
|
||||
{ "getDisplayHeight", l_lovrHeadsetGetDisplayHeight },
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
static struct {
|
||||
HeadsetType type;
|
||||
float offset;
|
||||
|
||||
float clipNear;
|
||||
|
@ -39,8 +38,8 @@ static void desktopDestroy(void) {
|
|||
memset(&state, 0, sizeof(state));
|
||||
}
|
||||
|
||||
static HeadsetType desktopGetType(void) {
|
||||
return HEADSET_UNKNOWN;
|
||||
static const char* desktopGetName(void) {
|
||||
return "VR Simulator";
|
||||
}
|
||||
|
||||
static HeadsetOrigin desktopGetOriginType(void) {
|
||||
|
@ -73,6 +72,15 @@ static const float* desktopGetBoundsGeometry(int* count) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static bool desktopIsTracked(Path path, bool* tracked) {
|
||||
if (PATH_EQ(path, PATH_HEAD) || PATH_EQ(path, PATH_HANDS, PATH_LEFT) || PATH_EQ(path, PATH_HANDS, PATH_RIGHT)) {
|
||||
*tracked = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool desktopGetPose(Path path, float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az) {
|
||||
if (PATH_EQ(path, PATH_HEAD)) {
|
||||
*x = *y = *z = 0.f;
|
||||
|
@ -224,13 +232,14 @@ HeadsetInterface lovrHeadsetDesktopDriver = {
|
|||
.driverType = DRIVER_DESKTOP,
|
||||
.init = desktopInit,
|
||||
.destroy = desktopDestroy,
|
||||
.getType = desktopGetType,
|
||||
.getName = desktopGetName,
|
||||
.getOriginType = desktopGetOriginType,
|
||||
.getDisplayDimensions = desktopGetDisplayDimensions,
|
||||
.getClipDistance = desktopGetClipDistance,
|
||||
.setClipDistance = desktopSetClipDistance,
|
||||
.getBoundsDimensions = desktopGetBoundsDimensions,
|
||||
.getBoundsGeometry = desktopGetBoundsGeometry,
|
||||
.isTracked = desktopIsTracked,
|
||||
.getPose = desktopGetPose,
|
||||
.getVelocity = desktopGetVelocity,
|
||||
.getAngularVelocity = desktopGetAngularVelocity,
|
||||
|
|
|
@ -26,15 +26,6 @@ typedef enum {
|
|||
DRIVER_WEBVR
|
||||
} HeadsetDriver;
|
||||
|
||||
typedef enum {
|
||||
HEADSET_UNKNOWN,
|
||||
HEADSET_VIVE,
|
||||
HEADSET_RIFT,
|
||||
HEADSET_GEAR,
|
||||
HEADSET_GO,
|
||||
HEADSET_WINDOWS_MR
|
||||
} HeadsetType;
|
||||
|
||||
typedef enum {
|
||||
PATH_NONE,
|
||||
PATH_HEAD,
|
||||
|
@ -61,24 +52,19 @@ typedef union {
|
|||
#define PATH_EQ(p, ...) ((p).u64 == MAKE_PATH(__VA_ARGS__).u64)
|
||||
#define PATH_STARTS_WITH(p, ...) ((MAKE_PATH(__VA_ARGS__).u64 ^ p.u64 & MAKE_PATH(__VA_ARGS__).u64) == 0)
|
||||
|
||||
// The interface implemented by headset backends
|
||||
// - The 'next' pointer is used internally to create a linked list of tracking drivers.
|
||||
// - If the renderTo function is implemented, the backend is a "display" backend. Only the first
|
||||
// successfully initialized display backend will be used, the rest will be ignored. If this
|
||||
// becomes undesirable in the future, we could initialize subsequent display backends in a
|
||||
// special "headless" mode to let them know that they won't need to do any rendering.
|
||||
typedef struct HeadsetInterface {
|
||||
struct HeadsetInterface* next;
|
||||
HeadsetDriver driverType;
|
||||
bool (*init)(float offset, int msaa);
|
||||
void (*destroy)(void);
|
||||
HeadsetType (*getType)(void);
|
||||
const char* (*getName)(void);
|
||||
HeadsetOrigin (*getOriginType)(void);
|
||||
void (*getDisplayDimensions)(uint32_t* width, uint32_t* height);
|
||||
void (*getClipDistance)(float* clipNear, float* clipFar);
|
||||
void (*setClipDistance)(float clipNear, float clipFar);
|
||||
void (*getBoundsDimensions)(float* width, float* depth);
|
||||
const float* (*getBoundsGeometry)(int* count);
|
||||
bool (*isTracked)(Path path, bool* tracked);
|
||||
bool (*getPose)(Path path, float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az);
|
||||
bool (*getVelocity)(Path path, float* vx, float* vy, float* vz);
|
||||
bool (*getAngularVelocity)(Path path, float* vx, float* vy, float* vz);
|
||||
|
|
|
@ -36,7 +36,8 @@ typedef struct {
|
|||
RenderModel_TextureMap_t* deviceTextures[16];
|
||||
Canvas* canvas;
|
||||
vec_float_t boundsGeometry;
|
||||
HeadsetType type;
|
||||
char name[128];
|
||||
bool rift;
|
||||
float clipNear;
|
||||
float clipFar;
|
||||
float offset;
|
||||
|
@ -90,67 +91,65 @@ static bool getButtonState(Path path, bool touch, bool* value) {
|
|||
|
||||
uint64_t mask = touch ? input.ulButtonTouched : input.ulButtonPressed;
|
||||
|
||||
Chirality hand = SIDE_LEFT;
|
||||
switch (state.system->GetControllerRoleForTrackedDeviceIndex(deviceIndex)) {
|
||||
case ETrackedControllerRole_TrackedControllerRole_LeftHand: hand = SIDE_LEFT; break;
|
||||
case ETrackedControllerRole_TrackedControllerRole_RightHand: hand = SIDE_RIGHT; break;
|
||||
default: break;
|
||||
}
|
||||
if (state.rift) {
|
||||
Chirality hand = SIDE_LEFT;
|
||||
switch (state.system->GetControllerRoleForTrackedDeviceIndex(deviceIndex)) {
|
||||
case ETrackedControllerRole_TrackedControllerRole_LeftHand: hand = SIDE_LEFT; break;
|
||||
case ETrackedControllerRole_TrackedControllerRole_RightHand: hand = SIDE_RIGHT; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
switch (state.type) {
|
||||
case HEADSET_RIFT:
|
||||
switch (path.pieces[2]) {
|
||||
case PATH_TRIGGER:
|
||||
*value = (mask >> EVRButtonId_k_EButton_Axis1) & 1;
|
||||
return true;
|
||||
switch (path.pieces[2]) {
|
||||
case PATH_TRIGGER:
|
||||
*value = (mask >> EVRButtonId_k_EButton_Axis1) & 1;
|
||||
return true;
|
||||
|
||||
case PATH_GRIP:
|
||||
*value = (mask >> EVRButtonId_k_EButton_Axis2) & 1;
|
||||
return true;
|
||||
case PATH_GRIP:
|
||||
*value = (mask >> EVRButtonId_k_EButton_Axis2) & 1;
|
||||
return true;
|
||||
|
||||
case PATH_TRACKPAD:
|
||||
*value = (mask >> EVRButtonId_k_EButton_Axis0) & 1;
|
||||
return true;
|
||||
case PATH_TRACKPAD:
|
||||
*value = (mask >> EVRButtonId_k_EButton_Axis0) & 1;
|
||||
return true;
|
||||
|
||||
case PATH_A:
|
||||
*value = hand == SIDE_RIGHT && (mask >> EVRButtonId_k_EButton_A) & 1;
|
||||
return true;
|
||||
case PATH_A:
|
||||
*value = hand == SIDE_RIGHT && (mask >> EVRButtonId_k_EButton_A) & 1;
|
||||
return true;
|
||||
|
||||
case PATH_B:
|
||||
*value = hand == SIDE_RIGHT && (mask >> EVRButtonId_k_EButton_ApplicationMenu) & 1;
|
||||
return true;
|
||||
case PATH_B:
|
||||
*value = hand == SIDE_RIGHT && (mask >> EVRButtonId_k_EButton_ApplicationMenu) & 1;
|
||||
return true;
|
||||
|
||||
case PATH_X:
|
||||
*value = hand == SIDE_LEFT && (mask >> EVRButtonId_k_EButton_A) & 1;
|
||||
return true;
|
||||
case PATH_X:
|
||||
*value = hand == SIDE_LEFT && (mask >> EVRButtonId_k_EButton_A) & 1;
|
||||
return true;
|
||||
|
||||
case PATH_Y:
|
||||
*value = hand == SIDE_LEFT && (mask >> EVRButtonId_k_EButton_ApplicationMenu) & 1;
|
||||
return true;
|
||||
case PATH_Y:
|
||||
*value = hand == SIDE_LEFT && (mask >> EVRButtonId_k_EButton_ApplicationMenu) & 1;
|
||||
return true;
|
||||
|
||||
default: return false;
|
||||
}
|
||||
default: return false;
|
||||
}
|
||||
} else {
|
||||
switch (path.pieces[2]) {
|
||||
case PATH_TRIGGER:
|
||||
*value = (mask >> EVRButtonId_k_EButton_SteamVR_Trigger) & 1;
|
||||
return true;
|
||||
|
||||
default:
|
||||
switch (path.pieces[2]) {
|
||||
case PATH_TRIGGER:
|
||||
*value = (mask >> EVRButtonId_k_EButton_SteamVR_Trigger) & 1;
|
||||
return true;
|
||||
case PATH_TRACKPAD:
|
||||
*value = (mask >> EVRButtonId_k_EButton_SteamVR_Touchpad) & 1;
|
||||
return true;
|
||||
|
||||
case PATH_TRACKPAD:
|
||||
*value = (mask >> EVRButtonId_k_EButton_SteamVR_Touchpad) & 1;
|
||||
return true;
|
||||
case PATH_MENU:
|
||||
*value = (mask >> EVRButtonId_k_EButton_ApplicationMenu) & 1;
|
||||
return true;
|
||||
|
||||
case PATH_MENU:
|
||||
*value = (mask >> EVRButtonId_k_EButton_ApplicationMenu) & 1;
|
||||
return true;
|
||||
case PATH_GRIP:
|
||||
*value = (mask >> EVRButtonId_k_EButton_Grip) & 1;
|
||||
return true;
|
||||
|
||||
case PATH_GRIP:
|
||||
*value = (mask >> EVRButtonId_k_EButton_Grip) & 1;
|
||||
return true;
|
||||
|
||||
default: return false;
|
||||
}
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,18 +175,8 @@ static bool openvrInit(float offset, int msaa) {
|
|||
return false;
|
||||
}
|
||||
|
||||
state.system->GetStringTrackedDeviceProperty(HEADSET_INDEX, ETrackedDeviceProperty_Prop_ManufacturerName_String, buffer, 128, NULL);
|
||||
|
||||
if (!strncmp(buffer, "HTC", 128)) {
|
||||
state.type = HEADSET_VIVE;
|
||||
} else if (!strncmp(buffer, "Oculus", 128)) {
|
||||
state.type = HEADSET_RIFT;
|
||||
} else if (!strncmp(buffer, "WindowsMR", 128)) {
|
||||
state.type = HEADSET_WINDOWS_MR;
|
||||
} else {
|
||||
state.type = HEADSET_UNKNOWN;
|
||||
}
|
||||
|
||||
state.system->GetStringTrackedDeviceProperty(HEADSET_INDEX, ETrackedDeviceProperty_Prop_ManufacturerName_String, state.name, sizeof(state.name), NULL);
|
||||
state.rift = !strncmp(state.name, "Oculus", sizeof(state.name));
|
||||
state.clipNear = 0.1f;
|
||||
state.clipFar = 30.f;
|
||||
state.offset = state.compositor->GetTrackingSpace() == ETrackingUniverseOrigin_TrackingUniverseStanding ? 0. : offset;
|
||||
|
@ -214,8 +203,8 @@ static void openvrDestroy(void) {
|
|||
memset(&state, 0, sizeof(HeadsetState));
|
||||
}
|
||||
|
||||
static HeadsetType openvrGetType(void) {
|
||||
return state.type;
|
||||
static const char* openvrGetName(void) {
|
||||
return state.name;
|
||||
}
|
||||
|
||||
static HeadsetOrigin openvrGetOriginType(void) {
|
||||
|
@ -329,38 +318,36 @@ static int openvrGetAxis(Path path, float* x, float* y, float* z) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
switch (state.type) {
|
||||
case HEADSET_RIFT:
|
||||
switch (path.pieces[2]) {
|
||||
case PATH_TRIGGER:
|
||||
*x = input.rAxis[1].x;
|
||||
return 1;
|
||||
if (state.rift) {
|
||||
switch (path.pieces[2]) {
|
||||
case PATH_TRIGGER:
|
||||
*x = input.rAxis[1].x;
|
||||
return 1;
|
||||
|
||||
case PATH_GRIP:
|
||||
*x = input.rAxis[2].x;
|
||||
return 1;
|
||||
case PATH_GRIP:
|
||||
*x = input.rAxis[2].x;
|
||||
return 1;
|
||||
|
||||
case PATH_TRACKPAD:
|
||||
*x = input.rAxis[0].x;
|
||||
*y = input.rAxis[0].y;
|
||||
return 2;
|
||||
case PATH_TRACKPAD:
|
||||
*x = input.rAxis[0].x;
|
||||
*y = input.rAxis[0].y;
|
||||
return 2;
|
||||
|
||||
default: return 0;
|
||||
}
|
||||
default: return 0;
|
||||
}
|
||||
} else {
|
||||
switch (path.pieces[2]) {
|
||||
case PATH_TRIGGER:
|
||||
*x = input.rAxis[1].x;
|
||||
return 1;
|
||||
|
||||
default:
|
||||
switch (path.pieces[2]) {
|
||||
case PATH_TRIGGER:
|
||||
*x = input.rAxis[1].x;
|
||||
return 1;
|
||||
case PATH_TRACKPAD:
|
||||
*x = input.rAxis[0].x;
|
||||
*y = input.rAxis[0].y;
|
||||
return 2;
|
||||
|
||||
case PATH_TRACKPAD:
|
||||
*x = input.rAxis[0].x;
|
||||
*y = input.rAxis[0].y;
|
||||
return 2;
|
||||
|
||||
default: return 0;
|
||||
}
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -554,7 +541,7 @@ HeadsetInterface lovrHeadsetOpenVRDriver = {
|
|||
.driverType = DRIVER_OPENVR,
|
||||
.init = openvrInit,
|
||||
.destroy = openvrDestroy,
|
||||
.getType = openvrGetType,
|
||||
.getName = openvrGetName,
|
||||
.getOriginType = openvrGetOriginType,
|
||||
.getDisplayDimensions = openvrGetDisplayDimensions,
|
||||
.getClipDistance = openvrGetClipDistance,
|
||||
|
|
Loading…
Reference in New Issue