mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 11:42:55 +02:00
Working on test code, new controller interface
This commit is contained in:
parent
80c95cd8eb
commit
14f33258ae
6 changed files with 243 additions and 48 deletions
|
@ -1,23 +1,36 @@
|
||||||
#include "NewControllerScriptingInterface.h"
|
#include "NewControllerScriptingInterface.h"
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include <QtScript/QScriptValue>
|
#include <GLMHelpers.h>
|
||||||
|
#include <DependencyManager.h>
|
||||||
#include "GLMHelpers.h"
|
#include <input-plugins/UserInputMapper.h>
|
||||||
|
|
||||||
#include "impl/MappingBuilderProxy.h"
|
#include "impl/MappingBuilderProxy.h"
|
||||||
|
|
||||||
namespace Controllers {
|
namespace Controllers {
|
||||||
|
void NewControllerScriptingInterface::update() {
|
||||||
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
|
static float last = secTimestampNow();
|
||||||
|
float now = secTimestampNow();
|
||||||
|
userInputMapper->update(now - last);
|
||||||
|
last = now;
|
||||||
|
}
|
||||||
|
|
||||||
QObject* NewControllerScriptingInterface::newMapping() {
|
QObject* NewControllerScriptingInterface::newMapping() {
|
||||||
qDebug() << "Creating new Mapping proxy";
|
qDebug() << "Creating new Mapping proxy";
|
||||||
return new MappingBuilderProxy(std::make_shared<Mapping>());
|
return new MappingBuilderProxy(std::make_shared<Mapping>());
|
||||||
}
|
}
|
||||||
|
|
||||||
float NewControllerScriptingInterface::getValue(const QScriptValue& source) {
|
float NewControllerScriptingInterface::getValue(const int& source) {
|
||||||
return 0;
|
//UserInputMapper::Input input; input._id = source;
|
||||||
}
|
//auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
|
//auto deviceProxy = userInputMapper->getDeviceProxy(input);
|
||||||
|
//return deviceProxy->getButton(input, 0) ? 1.0 : 0.0;
|
||||||
|
|
||||||
|
return (sin(secTimestampNow()) + 1.0f) / 2.0f;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace controllers
|
} // namespace controllers
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,9 @@ namespace Controllers {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Q_INVOKABLE void update();
|
||||||
Q_INVOKABLE QObject* newMapping();
|
Q_INVOKABLE QObject* newMapping();
|
||||||
Q_INVOKABLE float getValue(const QScriptValue& source);
|
Q_INVOKABLE float getValue(const int& source);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
|
|
||||||
set(TARGET_NAME controllers-test)
|
set(TARGET_NAME controllers-test)
|
||||||
|
|
||||||
AUTOSCRIBE_SHADER_LIB(gpu model render-utils )
|
|
||||||
|
|
||||||
# This is not a testcase -- just set it up as a regular hifi project
|
# This is not a testcase -- just set it up as a regular hifi project
|
||||||
setup_hifi_project(Script)
|
setup_hifi_project(Script)
|
||||||
set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/")
|
set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/")
|
||||||
|
|
||||||
# link in the shared libraries
|
# link in the shared libraries
|
||||||
link_hifi_libraries(shared script-engine input-plugins controllers)
|
link_hifi_libraries(shared script-engine plugins input-plugins display-plugins controllers)
|
||||||
|
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
add_dependency_external_projects(OpenVR)
|
||||||
|
find_package(OpenVR REQUIRED)
|
||||||
|
target_include_directories(${TARGET_NAME} PRIVATE ${OPENVR_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(${TARGET_NAME} ${OPENVR_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
|
||||||
copy_dlls_beside_windows_executable()
|
copy_dlls_beside_windows_executable()
|
137
tests/controllers/qml/content.qml
Normal file
137
tests/controllers/qml/content.qml
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
import QtQuick 2.1
|
||||||
|
import QtQuick.Controls 1.0
|
||||||
|
import QtQuick.Layouts 1.0
|
||||||
|
import QtQuick.Dialogs 1.0
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: root
|
||||||
|
implicitHeight: column1.height + 24
|
||||||
|
implicitWidth: column1.width + 24
|
||||||
|
color: "lightgray"
|
||||||
|
|
||||||
|
property real itemSize: 128
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: graphTemplate
|
||||||
|
Item {
|
||||||
|
implicitHeight: canvas.height + 2 + text.height
|
||||||
|
implicitWidth: canvas.width
|
||||||
|
property string text: loadText
|
||||||
|
|
||||||
|
Canvas {
|
||||||
|
id: canvas
|
||||||
|
width: root.itemSize; height: root.itemSize;
|
||||||
|
antialiasing: false
|
||||||
|
property int controlId: control
|
||||||
|
property real value: 0.0
|
||||||
|
property int drawWidth: 1
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 50; running: true; repeat: true
|
||||||
|
onTriggered: {
|
||||||
|
parent.value = NewControllers.getValue(canvas.controlId)
|
||||||
|
parent.requestPaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onPaint: {
|
||||||
|
var ctx = canvas.getContext('2d');
|
||||||
|
ctx.save();
|
||||||
|
|
||||||
|
var image = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||||
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
ctx.drawImage(image, -drawWidth, 0, canvas.width, canvas.height)
|
||||||
|
ctx.fillStyle = 'green'
|
||||||
|
// draw a filles rectangle
|
||||||
|
var height = canvas.height * canvas.value
|
||||||
|
ctx.fillRect(canvas.width - drawWidth, canvas.height - height,
|
||||||
|
drawWidth, height)
|
||||||
|
ctx.restore()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
id: text
|
||||||
|
text: parent.text
|
||||||
|
anchors.topMargin: 2
|
||||||
|
anchors.horizontalCenter: canvas.horizontalCenter
|
||||||
|
anchors.top: canvas.bottom
|
||||||
|
font.pointSize: 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Column {
|
||||||
|
id: column1
|
||||||
|
x: 12; y: 12
|
||||||
|
spacing: 24
|
||||||
|
Row {
|
||||||
|
spacing: 16
|
||||||
|
Loader {
|
||||||
|
sourceComponent: graphTemplate;
|
||||||
|
property string loadText: "Key Left"
|
||||||
|
property int control: ControllerIds.Hardware.Keyboard2.Left
|
||||||
|
}
|
||||||
|
Loader {
|
||||||
|
sourceComponent: graphTemplate;
|
||||||
|
property string loadText: "DPad Up"
|
||||||
|
property int control: ControllerIds.Hardware.X360Controller1.DPadUp
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Loader {
|
||||||
|
sourceComponent: graphTemplate;
|
||||||
|
property string loadText: "Yaw Left"
|
||||||
|
property int control: ControllerIds.Actions.YAW_LEFT
|
||||||
|
}
|
||||||
|
Loader {
|
||||||
|
sourceComponent: graphTemplate;
|
||||||
|
property string loadText: "Yaw Left"
|
||||||
|
property int control: ControllerIds.Actions.YAW_LEFT
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Loader { sourceComponent: graphTemplate; }
|
||||||
|
// Loader { sourceComponent: graphTemplate; }
|
||||||
|
// Loader { sourceComponent: graphTemplate; }
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Row {
|
||||||
|
spacing: 16
|
||||||
|
Loader { sourceComponent: graphTemplate; }
|
||||||
|
Loader { sourceComponent: graphTemplate; }
|
||||||
|
Loader { sourceComponent: graphTemplate; }
|
||||||
|
Loader { sourceComponent: graphTemplate; }
|
||||||
|
}
|
||||||
|
Row {
|
||||||
|
spacing: 16
|
||||||
|
Loader { sourceComponent: graphTemplate; }
|
||||||
|
Loader { sourceComponent: graphTemplate; }
|
||||||
|
Loader { sourceComponent: graphTemplate; }
|
||||||
|
Loader { sourceComponent: graphTemplate; }
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
Button {
|
||||||
|
text: "Go!"
|
||||||
|
onClicked: {
|
||||||
|
//
|
||||||
|
|
||||||
|
// var newMapping = NewControllers.newMapping();
|
||||||
|
// console.log("Mapping Object " + newMapping);
|
||||||
|
// var routeBuilder = newMapping.from("Hello");
|
||||||
|
// console.log("Route Builder " + routeBuilder);
|
||||||
|
// routeBuilder.clamp(0, 1).clamp(0, 1).to("Goodbye");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 50; running: true; repeat: true
|
||||||
|
onTriggered: {
|
||||||
|
NewControllers.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,42 +2,13 @@ import QtQuick 2.1
|
||||||
import QtQuick.Controls 1.0
|
import QtQuick.Controls 1.0
|
||||||
import QtQuick.Layouts 1.0
|
import QtQuick.Layouts 1.0
|
||||||
import QtQuick.Dialogs 1.0
|
import QtQuick.Dialogs 1.0
|
||||||
import com.highfidelity.test 1.0
|
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
id: window
|
id: window
|
||||||
visible: true
|
visible: true
|
||||||
|
|
||||||
AppHook {
|
Loader {
|
||||||
|
id: pageLoader
|
||||||
|
source: "content.qml"
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewControllers {
|
|
||||||
// id: newControllers
|
|
||||||
// }
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
id: page
|
|
||||||
width: 320; height: 480
|
|
||||||
color: "lightgray"
|
|
||||||
Text {
|
|
||||||
id: helloText
|
|
||||||
text: "Hello world!"
|
|
||||||
y: 30
|
|
||||||
anchors.horizontalCenter: page.horizontalCenter
|
|
||||||
font.pointSize: 24; font.bold: true
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseArea {
|
|
||||||
anchors.fill: parent
|
|
||||||
onClicked: {
|
|
||||||
var newMapping = NewControllers.newMapping();
|
|
||||||
console.log("Mapping Object " + newMapping);
|
|
||||||
var routeBuilder = newMapping.from("Hello");
|
|
||||||
console.log("Route Builder " + routeBuilder);
|
|
||||||
routeBuilder.clamp(0, 1).clamp(0, 1).to("Goodbye");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <mutex>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
@ -21,6 +23,7 @@
|
||||||
#include <QtCore/QElapsedTimer>
|
#include <QtCore/QElapsedTimer>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QLoggingCategory>
|
#include <QtCore/QLoggingCategory>
|
||||||
|
#include <QtCore/QRegularExpression>
|
||||||
|
|
||||||
#include <QtGui/QResizeEvent>
|
#include <QtGui/QResizeEvent>
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
|
@ -32,6 +35,11 @@
|
||||||
#include <QtQml/QQmlContext>
|
#include <QtQml/QQmlContext>
|
||||||
|
|
||||||
#include <controllers/NewControllerScriptingInterface.h>
|
#include <controllers/NewControllerScriptingInterface.h>
|
||||||
|
#include <DependencyManager.h>
|
||||||
|
#include <plugins/PluginManager.h>
|
||||||
|
#include <input-plugins/InputPlugin.h>
|
||||||
|
#include <input-plugins/KeyboardMouseDevice.h>
|
||||||
|
#include <input-plugins/UserInputMapper.h>
|
||||||
|
|
||||||
const QString& getQmlDir() {
|
const QString& getQmlDir() {
|
||||||
static QString dir;
|
static QString dir;
|
||||||
|
@ -55,13 +63,72 @@ public:
|
||||||
|
|
||||||
using namespace Controllers;
|
using namespace Controllers;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
|
QString sanatizeName(const QString& name) {
|
||||||
|
QString cleanName{ name };
|
||||||
|
cleanName.remove(QRegularExpression{ "[\\(\\)\\.\\s]" });
|
||||||
|
return cleanName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QVariantMap& getInputMap() {
|
||||||
|
static std::once_flag once;
|
||||||
|
static QVariantMap map;
|
||||||
|
std::call_once(once, [&] {
|
||||||
|
{
|
||||||
|
QVariantMap hardwareMap;
|
||||||
|
// Controller.Hardware.*
|
||||||
|
auto devices = DependencyManager::get<UserInputMapper>()->getDevices();
|
||||||
|
for (const auto& deviceMapping : devices) {
|
||||||
|
auto device = deviceMapping.second.get();
|
||||||
|
auto deviceName = sanatizeName(device->getName());
|
||||||
|
auto deviceInputs = device->getAvailabeInputs();
|
||||||
|
QVariantMap deviceMap;
|
||||||
|
for (const auto& inputMapping : deviceInputs) {
|
||||||
|
auto input = inputMapping.first;
|
||||||
|
auto inputName = sanatizeName(inputMapping.second);
|
||||||
|
deviceMap.insert(inputName, input.getID());
|
||||||
|
}
|
||||||
|
hardwareMap.insert(deviceName, deviceMap);
|
||||||
|
}
|
||||||
|
map.insert("Hardware", hardwareMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Controller.Actions.*
|
||||||
|
{
|
||||||
|
QVariantMap actionMap;
|
||||||
|
auto actionNames = DependencyManager::get<UserInputMapper>()->getActionNames();
|
||||||
|
int actionNumber = 0;
|
||||||
|
for (const auto& actionName : actionNames) {
|
||||||
|
actionMap.insert(sanatizeName(actionName), actionNumber++);
|
||||||
|
}
|
||||||
|
map.insert("Actions", actionMap);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
DependencyManager::set<UserInputMapper>();
|
||||||
|
PluginManager::getInstance()->getInputPlugins();
|
||||||
|
|
||||||
|
foreach(auto inputPlugin, PluginManager::getInstance()->getInputPlugins()) {
|
||||||
|
QString name = inputPlugin->getName();
|
||||||
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
|
if (name == KeyboardMouseDevice::NAME) {
|
||||||
|
auto keyboardMouseDevice = static_cast<KeyboardMouseDevice*>(inputPlugin.data()); // TODO: this seems super hacky
|
||||||
|
keyboardMouseDevice->registerToUserInputMapper(*userInputMapper);
|
||||||
|
keyboardMouseDevice->assignDefaultInputMapping(*userInputMapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Register our component type with QML.
|
// Register our component type with QML.
|
||||||
qmlRegisterType<AppHook>("com.highfidelity.test", 1, 0, "AppHook");
|
qmlRegisterType<AppHook>("com.highfidelity.test", 1, 0, "AppHook");
|
||||||
//qmlRegisterType<NewControllerScriptingInterface>("com.highfidelity.test", 1, 0, "NewControllers");
|
//qmlRegisterType<NewControllerScriptingInterface>("com.highfidelity.test", 1, 0, "NewControllers");
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
QQmlApplicationEngine engine(getQmlDir() + "main.qml");
|
QQmlApplicationEngine engine;
|
||||||
engine.rootContext()->setContextProperty("NewControllers", new NewControllerScriptingInterface());
|
engine.rootContext()->setContextProperty("NewControllers", new NewControllerScriptingInterface());
|
||||||
|
engine.rootContext()->setContextProperty("ControllerIds", getInputMap());
|
||||||
|
engine.load(getQmlDir() + "main.qml");
|
||||||
app.exec();
|
app.exec();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue