mirror of https://github.com/bjornbytes/lovr.git
rm tracking drivers;
This commit is contained in:
parent
a1d0b2fa11
commit
dcd1e58d0d
|
@ -87,30 +87,18 @@ static Device luax_optdevice(lua_State* L, int index) {
|
|||
}
|
||||
|
||||
static int l_lovrHeadsetStart(lua_State* L) {
|
||||
lovrHeadsetDisplayDriver->start();
|
||||
lovrHeadsetInterface->start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetDriver(lua_State* L) {
|
||||
if (lua_gettop(L) == 0) {
|
||||
luax_pushenum(L, HeadsetDriver, lovrHeadsetDisplayDriver->driverType);
|
||||
return 1;
|
||||
} else {
|
||||
Device device = luax_optdevice(L, 1);
|
||||
float position[4], orientation[4];
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getPose(device, position, orientation)) {
|
||||
luax_pushenum(L, HeadsetDriver, driver->driverType);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
luax_pushenum(L, HeadsetDriver, lovrHeadsetInterface->driverType);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetName(lua_State* L) {
|
||||
char name[256];
|
||||
if (lovrHeadsetDisplayDriver->getName(name, sizeof(name))) {
|
||||
if (lovrHeadsetInterface->getName(name, sizeof(name))) {
|
||||
lua_pushstring(L, name);
|
||||
} else {
|
||||
lua_pushnil(L);
|
||||
|
@ -119,34 +107,34 @@ static int l_lovrHeadsetGetName(lua_State* L) {
|
|||
}
|
||||
|
||||
static int l_lovrHeadsetGetOriginType(lua_State* L) {
|
||||
luax_pushenum(L, HeadsetOrigin, lovrHeadsetDisplayDriver->getOriginType());
|
||||
luax_pushenum(L, HeadsetOrigin, lovrHeadsetInterface->getOriginType());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetDisplayWidth(lua_State* L) {
|
||||
uint32_t width, height;
|
||||
lovrHeadsetDisplayDriver->getDisplayDimensions(&width, &height);
|
||||
lovrHeadsetInterface->getDisplayDimensions(&width, &height);
|
||||
lua_pushinteger(L, width);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetDisplayHeight(lua_State* L) {
|
||||
uint32_t width, height;
|
||||
lovrHeadsetDisplayDriver->getDisplayDimensions(&width, &height);
|
||||
lovrHeadsetInterface->getDisplayDimensions(&width, &height);
|
||||
lua_pushinteger(L, height);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetDisplayDimensions(lua_State* L) {
|
||||
uint32_t width, height;
|
||||
lovrHeadsetDisplayDriver->getDisplayDimensions(&width, &height);
|
||||
lovrHeadsetInterface->getDisplayDimensions(&width, &height);
|
||||
lua_pushinteger(L, width);
|
||||
lua_pushinteger(L, height);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetDisplayFrequency(lua_State* L) {
|
||||
float frequency = lovrHeadsetDisplayDriver->getDisplayFrequency ? lovrHeadsetDisplayDriver->getDisplayFrequency() : 0.f;
|
||||
float frequency = lovrHeadsetInterface->getDisplayFrequency ? lovrHeadsetInterface->getDisplayFrequency() : 0.f;
|
||||
if (frequency == 0.f) {
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
|
@ -156,14 +144,14 @@ static int l_lovrHeadsetGetDisplayFrequency(lua_State* L) {
|
|||
}
|
||||
|
||||
static int l_lovrHeadsetGetViewCount(lua_State* L) {
|
||||
lua_pushinteger(L, lovrHeadsetDisplayDriver->getViewCount());
|
||||
lua_pushinteger(L, lovrHeadsetInterface->getViewCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetViewPose(lua_State* L) {
|
||||
float position[4], orientation[4];
|
||||
uint32_t view = luax_checku32(L, 1) - 1;
|
||||
if (!lovrHeadsetDisplayDriver->getViewPose(view, position, orientation)) {
|
||||
if (!lovrHeadsetInterface->getViewPose(view, position, orientation)) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
@ -182,7 +170,7 @@ static int l_lovrHeadsetGetViewPose(lua_State* L) {
|
|||
static int l_lovrHeadsetGetViewAngles(lua_State* L) {
|
||||
float left, right, up, down;
|
||||
uint32_t view = luax_checku32(L, 1) - 1;
|
||||
if (!lovrHeadsetDisplayDriver->getViewAngles(view, &left, &right, &up, &down)) {
|
||||
if (!lovrHeadsetInterface->getViewAngles(view, &left, &right, &up, &down)) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
@ -195,7 +183,7 @@ static int l_lovrHeadsetGetViewAngles(lua_State* L) {
|
|||
|
||||
static int l_lovrHeadsetGetClipDistance(lua_State* L) {
|
||||
float clipNear, clipFar;
|
||||
lovrHeadsetDisplayDriver->getClipDistance(&clipNear, &clipFar);
|
||||
lovrHeadsetInterface->getClipDistance(&clipNear, &clipFar);
|
||||
lua_pushnumber(L, clipNear);
|
||||
lua_pushnumber(L, clipFar);
|
||||
return 2;
|
||||
|
@ -204,27 +192,27 @@ static int l_lovrHeadsetGetClipDistance(lua_State* L) {
|
|||
static int l_lovrHeadsetSetClipDistance(lua_State* L) {
|
||||
float clipNear = luax_checkfloat(L, 1);
|
||||
float clipFar = luax_checkfloat(L, 2);
|
||||
lovrHeadsetDisplayDriver->setClipDistance(clipNear, clipFar);
|
||||
lovrHeadsetInterface->setClipDistance(clipNear, clipFar);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetBoundsWidth(lua_State* L) {
|
||||
float width, depth;
|
||||
lovrHeadsetDisplayDriver->getBoundsDimensions(&width, &depth);
|
||||
lovrHeadsetInterface->getBoundsDimensions(&width, &depth);
|
||||
lua_pushnumber(L, width);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetBoundsDepth(lua_State* L) {
|
||||
float width, depth;
|
||||
lovrHeadsetDisplayDriver->getBoundsDimensions(&width, &depth);
|
||||
lovrHeadsetInterface->getBoundsDimensions(&width, &depth);
|
||||
lua_pushnumber(L, depth);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetBoundsDimensions(lua_State* L) {
|
||||
float width, depth;
|
||||
lovrHeadsetDisplayDriver->getBoundsDimensions(&width, &depth);
|
||||
lovrHeadsetInterface->getBoundsDimensions(&width, &depth);
|
||||
lua_pushnumber(L, width);
|
||||
lua_pushnumber(L, depth);
|
||||
return 2;
|
||||
|
@ -232,7 +220,7 @@ static int l_lovrHeadsetGetBoundsDimensions(lua_State* L) {
|
|||
|
||||
static int l_lovrHeadsetGetBoundsGeometry(lua_State* L) {
|
||||
uint32_t count;
|
||||
const float* points = lovrHeadsetDisplayDriver->getBoundsGeometry(&count);
|
||||
const float* points = lovrHeadsetInterface->getBoundsGeometry(&count);
|
||||
|
||||
if (!points) {
|
||||
lua_pushnil(L);
|
||||
|
@ -262,32 +250,24 @@ static int l_lovrHeadsetGetBoundsGeometry(lua_State* L) {
|
|||
static int l_lovrHeadsetIsTracked(lua_State* L) {
|
||||
Device device = luax_optdevice(L, 1);
|
||||
float position[4], orientation[4];
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getPose(device, position, orientation)) {
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
lua_pushboolean(L, false);
|
||||
lua_pushboolean(L, lovrHeadsetInterface->getPose(device, position, orientation));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetPose(lua_State* L) {
|
||||
Device device = luax_optdevice(L, 1);
|
||||
float position[4], orientation[4];
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getPose(device, position, orientation)) {
|
||||
float angle, ax, ay, az;
|
||||
quat_getAngleAxis(orientation, &angle, &ax, &ay, &az);
|
||||
lua_pushnumber(L, position[0]);
|
||||
lua_pushnumber(L, position[1]);
|
||||
lua_pushnumber(L, position[2]);
|
||||
lua_pushnumber(L, angle);
|
||||
lua_pushnumber(L, ax);
|
||||
lua_pushnumber(L, ay);
|
||||
lua_pushnumber(L, az);
|
||||
return 7;
|
||||
}
|
||||
if (lovrHeadsetInterface->getPose(device, position, orientation)) {
|
||||
float angle, ax, ay, az;
|
||||
quat_getAngleAxis(orientation, &angle, &ax, &ay, &az);
|
||||
lua_pushnumber(L, position[0]);
|
||||
lua_pushnumber(L, position[1]);
|
||||
lua_pushnumber(L, position[2]);
|
||||
lua_pushnumber(L, angle);
|
||||
lua_pushnumber(L, ax);
|
||||
lua_pushnumber(L, ay);
|
||||
lua_pushnumber(L, az);
|
||||
return 7;
|
||||
}
|
||||
for (int i = 0; i < 7; i++) {
|
||||
lua_pushnumber(L, 0.);
|
||||
|
@ -298,13 +278,11 @@ static int l_lovrHeadsetGetPose(lua_State* L) {
|
|||
static int l_lovrHeadsetGetPosition(lua_State* L) {
|
||||
Device device = luax_optdevice(L, 1);
|
||||
float position[4], orientation[4];
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getPose(device, position, orientation)) {
|
||||
lua_pushnumber(L, position[0]);
|
||||
lua_pushnumber(L, position[1]);
|
||||
lua_pushnumber(L, position[2]);
|
||||
return 3;
|
||||
}
|
||||
if (lovrHeadsetInterface->getPose(device, position, orientation)) {
|
||||
lua_pushnumber(L, position[0]);
|
||||
lua_pushnumber(L, position[1]);
|
||||
lua_pushnumber(L, position[2]);
|
||||
return 3;
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
lua_pushnumber(L, 0.);
|
||||
|
@ -315,16 +293,14 @@ static int l_lovrHeadsetGetPosition(lua_State* L) {
|
|||
static int l_lovrHeadsetGetOrientation(lua_State* L) {
|
||||
Device device = luax_optdevice(L, 1);
|
||||
float position[4], orientation[4];
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getPose(device, position, orientation)) {
|
||||
float angle, ax, ay, az;
|
||||
quat_getAngleAxis(orientation, &angle, &ax, &ay, &az);
|
||||
lua_pushnumber(L, angle);
|
||||
lua_pushnumber(L, ax);
|
||||
lua_pushnumber(L, ay);
|
||||
lua_pushnumber(L, az);
|
||||
return 4;
|
||||
}
|
||||
if (lovrHeadsetInterface->getPose(device, position, orientation)) {
|
||||
float angle, ax, ay, az;
|
||||
quat_getAngleAxis(orientation, &angle, &ax, &ay, &az);
|
||||
lua_pushnumber(L, angle);
|
||||
lua_pushnumber(L, ax);
|
||||
lua_pushnumber(L, ay);
|
||||
lua_pushnumber(L, az);
|
||||
return 4;
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
lua_pushnumber(L, 0.);
|
||||
|
@ -335,13 +311,11 @@ static int l_lovrHeadsetGetOrientation(lua_State* L) {
|
|||
static int l_lovrHeadsetGetVelocity(lua_State* L) {
|
||||
Device device = luax_optdevice(L, 1);
|
||||
float velocity[4], angularVelocity[4];
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getVelocity(device, velocity, angularVelocity)) {
|
||||
lua_pushnumber(L, velocity[0]);
|
||||
lua_pushnumber(L, velocity[1]);
|
||||
lua_pushnumber(L, velocity[2]);
|
||||
return 3;
|
||||
}
|
||||
if (lovrHeadsetInterface->getVelocity(device, velocity, angularVelocity)) {
|
||||
lua_pushnumber(L, velocity[0]);
|
||||
lua_pushnumber(L, velocity[1]);
|
||||
lua_pushnumber(L, velocity[2]);
|
||||
return 3;
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
lua_pushnumber(L, 0.);
|
||||
|
@ -352,13 +326,11 @@ static int l_lovrHeadsetGetVelocity(lua_State* L) {
|
|||
static int l_lovrHeadsetGetAngularVelocity(lua_State* L) {
|
||||
Device device = luax_optdevice(L, 1);
|
||||
float velocity[4], angularVelocity[4];
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getVelocity(device, velocity, angularVelocity)) {
|
||||
lua_pushnumber(L, angularVelocity[0]);
|
||||
lua_pushnumber(L, angularVelocity[1]);
|
||||
lua_pushnumber(L, angularVelocity[2]);
|
||||
return 3;
|
||||
}
|
||||
if (lovrHeadsetInterface->getVelocity(device, velocity, angularVelocity)) {
|
||||
lua_pushnumber(L, angularVelocity[0]);
|
||||
lua_pushnumber(L, angularVelocity[1]);
|
||||
lua_pushnumber(L, angularVelocity[2]);
|
||||
return 3;
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
lua_pushnumber(L, 0.);
|
||||
|
@ -370,11 +342,9 @@ static int l_lovrHeadsetIsDown(lua_State* L) {
|
|||
Device device = luax_optdevice(L, 1);
|
||||
DeviceButton button = luax_checkenum(L, 2, DeviceButton, NULL);
|
||||
bool down, changed;
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->isDown(device, button, &down, &changed)) {
|
||||
lua_pushboolean(L, down);
|
||||
return 1;
|
||||
}
|
||||
if (lovrHeadsetInterface->isDown(device, button, &down, &changed)) {
|
||||
lua_pushboolean(L, down);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -383,11 +353,9 @@ static int l_lovrHeadsetWasPressed(lua_State* L) {
|
|||
Device device = luax_optdevice(L, 1);
|
||||
DeviceButton button = luax_checkenum(L, 2, DeviceButton, NULL);
|
||||
bool down, changed;
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->isDown(device, button, &down, &changed)) {
|
||||
lua_pushboolean(L, down && changed);
|
||||
return 1;
|
||||
}
|
||||
if (lovrHeadsetInterface->isDown(device, button, &down, &changed)) {
|
||||
lua_pushboolean(L, down && changed);
|
||||
return 1;
|
||||
}
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
|
@ -397,11 +365,9 @@ static int l_lovrHeadsetWasReleased(lua_State* L) {
|
|||
Device device = luax_optdevice(L, 1);
|
||||
DeviceButton button = luax_checkenum(L, 2, DeviceButton, NULL);
|
||||
bool down, changed;
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->isDown(device, button, &down, &changed)) {
|
||||
lua_pushboolean(L, !down && changed);
|
||||
return 1;
|
||||
}
|
||||
if (lovrHeadsetInterface->isDown(device, button, &down, &changed)) {
|
||||
lua_pushboolean(L, !down && changed);
|
||||
return 1;
|
||||
}
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
|
@ -411,11 +377,9 @@ static int l_lovrHeadsetIsTouched(lua_State* L) {
|
|||
Device device = luax_optdevice(L, 1);
|
||||
DeviceButton button = luax_checkenum(L, 2, DeviceButton, NULL);
|
||||
bool touched;
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->isTouched(device, button, &touched)) {
|
||||
lua_pushboolean(L, touched);
|
||||
return 1;
|
||||
}
|
||||
if (lovrHeadsetInterface->isTouched(device, button, &touched)) {
|
||||
lua_pushboolean(L, touched);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -432,13 +396,11 @@ static int l_lovrHeadsetGetAxis(lua_State* L) {
|
|||
DeviceAxis axis = luax_checkenum(L, 2, DeviceAxis, NULL);
|
||||
int count = axisCounts[axis];
|
||||
float value[4];
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getAxis(device, axis, value)) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
lua_pushnumber(L, value[i]);
|
||||
}
|
||||
return count;
|
||||
if (lovrHeadsetInterface->getAxis(device, axis, value)) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
lua_pushnumber(L, value[i]);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
for (int i = 0; i < count; i++) {
|
||||
lua_pushnumber(L, 0.);
|
||||
|
@ -449,40 +411,38 @@ static int l_lovrHeadsetGetAxis(lua_State* L) {
|
|||
static int l_lovrHeadsetGetSkeleton(lua_State* L) {
|
||||
Device device = luax_optdevice(L, 1);
|
||||
float poses[HAND_JOINT_COUNT * 8];
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getSkeleton(device, poses)) {
|
||||
if (!lua_istable(L, 2)) {
|
||||
lua_createtable(L, HAND_JOINT_COUNT, 0);
|
||||
} else {
|
||||
lua_settop(L, 2);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < HAND_JOINT_COUNT; i++) {
|
||||
lua_createtable(L, 8, 0);
|
||||
|
||||
float angle, ax, ay, az;
|
||||
float* pose = poses + i * 8;
|
||||
quat_getAngleAxis(pose + 4, &angle, &ax, &ay, &az);
|
||||
lua_pushnumber(L, pose[0]);
|
||||
lua_pushnumber(L, pose[1]);
|
||||
lua_pushnumber(L, pose[2]);
|
||||
lua_pushnumber(L, angle);
|
||||
lua_pushnumber(L, ax);
|
||||
lua_pushnumber(L, ay);
|
||||
lua_pushnumber(L, az);
|
||||
lua_rawseti(L, -8, 7);
|
||||
lua_rawseti(L, -7, 6);
|
||||
lua_rawseti(L, -6, 5);
|
||||
lua_rawseti(L, -5, 4);
|
||||
lua_rawseti(L, -4, 3);
|
||||
lua_rawseti(L, -3, 2);
|
||||
lua_rawseti(L, -2, 1);
|
||||
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
if (lovrHeadsetInterface->getSkeleton(device, poses)) {
|
||||
if (!lua_istable(L, 2)) {
|
||||
lua_createtable(L, HAND_JOINT_COUNT, 0);
|
||||
} else {
|
||||
lua_settop(L, 2);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < HAND_JOINT_COUNT; i++) {
|
||||
lua_createtable(L, 8, 0);
|
||||
|
||||
float angle, ax, ay, az;
|
||||
float* pose = poses + i * 8;
|
||||
quat_getAngleAxis(pose + 4, &angle, &ax, &ay, &az);
|
||||
lua_pushnumber(L, pose[0]);
|
||||
lua_pushnumber(L, pose[1]);
|
||||
lua_pushnumber(L, pose[2]);
|
||||
lua_pushnumber(L, angle);
|
||||
lua_pushnumber(L, ax);
|
||||
lua_pushnumber(L, ay);
|
||||
lua_pushnumber(L, az);
|
||||
lua_rawseti(L, -8, 7);
|
||||
lua_rawseti(L, -7, 6);
|
||||
lua_rawseti(L, -6, 5);
|
||||
lua_rawseti(L, -5, 4);
|
||||
lua_rawseti(L, -4, 3);
|
||||
lua_rawseti(L, -3, 2);
|
||||
lua_rawseti(L, -2, 1);
|
||||
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
|
@ -493,11 +453,9 @@ static int l_lovrHeadsetVibrate(lua_State* L) {
|
|||
float strength = luax_optfloat(L, 2, 1.f);
|
||||
float duration = luax_optfloat(L, 3, .5f);
|
||||
float frequency = luax_optfloat(L, 4, 0.f);
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->vibrate(device, strength, duration, frequency)) {
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
if (lovrHeadsetInterface->vibrate(device, strength, duration, frequency)) {
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
|
@ -513,12 +471,7 @@ static int l_lovrHeadsetNewModel(lua_State* L) {
|
|||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
ModelData* modelData = NULL;
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if ((modelData = driver->newModelData(device, animated)) != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
ModelData* modelData = lovrHeadsetInterface->newModelData(device, animated);
|
||||
|
||||
if (modelData) {
|
||||
Model* model = lovrModelCreate(modelData);
|
||||
|
@ -534,11 +487,9 @@ static int l_lovrHeadsetNewModel(lua_State* L) {
|
|||
static int l_lovrHeadsetAnimate(lua_State* L) {
|
||||
Device device = luax_optdevice(L, 1);
|
||||
Model* model = luax_checktype(L, 2, Model);
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->animate(device, model)) {
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
if (lovrHeadsetInterface->animate(device, model)) {
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
|
@ -546,7 +497,7 @@ static int l_lovrHeadsetAnimate(lua_State* L) {
|
|||
|
||||
static int l_lovrHeadsetRenderTo(lua_State* L) {
|
||||
lua_settop(L, 1);
|
||||
lovrHeadsetDisplayDriver->renderTo(renderHelper, L);
|
||||
lovrHeadsetInterface->renderTo(renderHelper, L);
|
||||
lovrGraphicsSetViewMatrix(0, NULL);
|
||||
lovrGraphicsSetViewMatrix(1, NULL);
|
||||
lovrGraphicsSetProjection(0, NULL);
|
||||
|
@ -555,21 +506,15 @@ static int l_lovrHeadsetRenderTo(lua_State* L) {
|
|||
}
|
||||
|
||||
static int l_lovrHeadsetIsFocused(lua_State* L) {
|
||||
lua_pushboolean(L, lovrHeadsetDisplayDriver->isFocused());
|
||||
lua_pushboolean(L, lovrHeadsetInterface->isFocused());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetUpdate(lua_State* L) {
|
||||
double dt = 0.;
|
||||
|
||||
if (lovrHeadsetDisplayDriver->update) {
|
||||
dt = lovrHeadsetDisplayDriver->update();
|
||||
}
|
||||
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->update && driver != lovrHeadsetDisplayDriver) {
|
||||
driver->update();
|
||||
}
|
||||
if (lovrHeadsetInterface->update) {
|
||||
dt = lovrHeadsetInterface->update();
|
||||
}
|
||||
|
||||
lua_pushnumber(L, dt);
|
||||
|
@ -577,22 +522,22 @@ static int l_lovrHeadsetUpdate(lua_State* L) {
|
|||
}
|
||||
|
||||
static int l_lovrHeadsetGetTime(lua_State* L) {
|
||||
lua_pushnumber(L, lovrHeadsetDisplayDriver->getDisplayTime());
|
||||
lua_pushnumber(L, lovrHeadsetInterface->getDisplayTime());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetDeltaTime(lua_State* L) {
|
||||
lua_pushnumber(L, lovrHeadsetDisplayDriver->getDeltaTime());
|
||||
lua_pushnumber(L, lovrHeadsetInterface->getDeltaTime());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetMirrorTexture(lua_State* L) {
|
||||
Texture* texture = NULL;
|
||||
if (lovrHeadsetDisplayDriver->getMirrorTexture)
|
||||
texture = lovrHeadsetDisplayDriver->getMirrorTexture();
|
||||
luax_pushtype(L, Texture, texture);
|
||||
|
||||
return 1;
|
||||
if (lovrHeadsetInterface->getMirrorTexture) {
|
||||
Texture* texture = lovrHeadsetInterface->getMirrorTexture();
|
||||
luax_pushtype(L, Texture, texture);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetHands(lua_State* L) {
|
||||
|
@ -606,11 +551,9 @@ static int l_lovrHeadsetGetHands(lua_State* L) {
|
|||
float position[4], orientation[4];
|
||||
Device hands[] = { DEVICE_HAND_LEFT, DEVICE_HAND_RIGHT };
|
||||
for (size_t i = 0; i < COUNTOF(hands); i++) {
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->getPose(hands[i], position, orientation)) {
|
||||
luax_pushenum(L, Device, hands[i]);
|
||||
lua_rawseti(L, -2, ++count);
|
||||
}
|
||||
if (lovrHeadsetInterface->getPose(hands[i], position, orientation)) {
|
||||
luax_pushenum(L, Device, hands[i]);
|
||||
lua_rawseti(L, -2, ++count);
|
||||
}
|
||||
}
|
||||
lua_pushnil(L);
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
#include "headset/headset.h"
|
||||
#include "util.h"
|
||||
|
||||
HeadsetInterface* lovrHeadsetDisplayDriver = NULL;
|
||||
HeadsetInterface* lovrHeadsetTrackingDrivers = NULL;
|
||||
HeadsetInterface* lovrHeadsetInterface = NULL;
|
||||
static bool initialized = false;
|
||||
|
||||
bool lovrHeadsetInit(HeadsetDriver* drivers, size_t count, float supersample, float offset, uint32_t msaa, bool overlay) {
|
||||
if (initialized) return false;
|
||||
initialized = true;
|
||||
|
||||
HeadsetInterface** trackingDrivers = &lovrHeadsetTrackingDrivers;
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
HeadsetInterface* interface = NULL;
|
||||
|
||||
|
@ -27,39 +24,21 @@ bool lovrHeadsetInit(HeadsetDriver* drivers, size_t count, float supersample, fl
|
|||
default: continue;
|
||||
}
|
||||
|
||||
bool hasDisplay = interface->renderTo != NULL;
|
||||
bool shouldInitialize = !hasDisplay || !lovrHeadsetDisplayDriver;
|
||||
|
||||
if (shouldInitialize && interface->init(supersample, offset, msaa, overlay)) {
|
||||
if (hasDisplay) {
|
||||
lovrHeadsetDisplayDriver = interface;
|
||||
}
|
||||
|
||||
*trackingDrivers = interface;
|
||||
trackingDrivers = &interface->next;
|
||||
if (interface->init(supersample, offset, msaa, overlay)) {
|
||||
lovrHeadsetInterface = interface;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lovrAssert(lovrHeadsetDisplayDriver, "No headset display driver available, check t.headset.drivers in conf.lua");
|
||||
lovrAssert(lovrHeadsetInterface, "No headset display driver available, check t.headset.drivers in conf.lua");
|
||||
return true;
|
||||
}
|
||||
|
||||
void lovrHeadsetDestroy() {
|
||||
if (!initialized) return;
|
||||
initialized = false;
|
||||
|
||||
HeadsetInterface* driver = lovrHeadsetTrackingDrivers;
|
||||
while (driver) {
|
||||
if (driver != lovrHeadsetDisplayDriver) {
|
||||
driver->destroy();
|
||||
}
|
||||
HeadsetInterface* next = driver->next;
|
||||
driver->next = NULL;
|
||||
driver = next;
|
||||
}
|
||||
|
||||
if (lovrHeadsetDisplayDriver) {
|
||||
lovrHeadsetDisplayDriver->destroy();
|
||||
lovrHeadsetDisplayDriver = NULL;
|
||||
if (lovrHeadsetInterface) {
|
||||
lovrHeadsetInterface->destroy();
|
||||
lovrHeadsetInterface = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,6 @@ typedef enum {
|
|||
// - In general, most input results should be kept constant between calls to update.
|
||||
|
||||
typedef struct HeadsetInterface {
|
||||
struct HeadsetInterface* next;
|
||||
HeadsetDriver driverType;
|
||||
bool (*init)(float supersample, float offset, uint32_t msaa, bool overlay);
|
||||
void (*start)(void);
|
||||
|
@ -144,12 +143,8 @@ extern HeadsetInterface lovrHeadsetOpenXRDriver;
|
|||
extern HeadsetInterface lovrHeadsetWebXRDriver;
|
||||
extern HeadsetInterface lovrHeadsetDesktopDriver;
|
||||
|
||||
// Active drivers
|
||||
extern HeadsetInterface* lovrHeadsetDisplayDriver;
|
||||
extern HeadsetInterface* lovrHeadsetTrackingDrivers;
|
||||
|
||||
#define FOREACH_TRACKING_DRIVER(i)\
|
||||
for (HeadsetInterface* i = lovrHeadsetTrackingDrivers; i != NULL; i = i->next)
|
||||
// Active driver
|
||||
extern HeadsetInterface* lovrHeadsetInterface;
|
||||
|
||||
bool lovrHeadsetInit(HeadsetDriver* drivers, size_t count, float supersample, float offset, uint32_t msaa, bool overlay);
|
||||
void lovrHeadsetDestroy(void);
|
||||
|
|
|
@ -328,5 +328,6 @@ HeadsetInterface lovrHeadsetDesktopDriver = {
|
|||
.newModelData = desktop_newModelData,
|
||||
.animate = desktop_animate,
|
||||
.renderTo = desktop_renderTo,
|
||||
.isFocused = desktop_isFocused,
|
||||
.update = desktop_update
|
||||
};
|
||||
|
|
|
@ -31,30 +31,13 @@ extern double webxr_update(void);
|
|||
static bool webxrAttached = false;
|
||||
static HeadsetInterface* previousHeadsetDriver;
|
||||
|
||||
static void setDriver(HeadsetInterface* new) {
|
||||
if (lovrHeadsetTrackingDrivers == lovrHeadsetDisplayDriver) {
|
||||
lovrHeadsetTrackingDrivers = new;
|
||||
} else {
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->next == lovrHeadsetDisplayDriver) {
|
||||
driver->next = new;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new->next = lovrHeadsetDisplayDriver->next;
|
||||
lovrHeadsetDisplayDriver->next = NULL;
|
||||
lovrHeadsetDisplayDriver = new;
|
||||
}
|
||||
|
||||
void webxr_attach() {
|
||||
if (webxrAttached || lovrHeadsetDisplayDriver == &lovrHeadsetWebXRDriver) {
|
||||
if (webxrAttached || lovrHeadsetInterface == &lovrHeadsetWebXRDriver) {
|
||||
return;
|
||||
}
|
||||
|
||||
previousHeadsetDriver = lovrHeadsetDisplayDriver;
|
||||
setDriver(&lovrHeadsetWebXRDriver);
|
||||
previousHeadsetDriver = lovrHeadsetInterface;
|
||||
lovrHeadsetInterface = &lovrHeadsetWebXRDriver;
|
||||
webxrAttached = true;
|
||||
}
|
||||
|
||||
|
@ -63,7 +46,7 @@ void webxr_detach() {
|
|||
return;
|
||||
}
|
||||
|
||||
setDriver(previousHeadsetDriver);
|
||||
lovrHeadsetInterface = previousHeadsetDriver;
|
||||
previousHeadsetDriver = NULL;
|
||||
webxrAttached = false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue