Merge pull request #6068 from jherico/controllers

Making anonymous mappings work
This commit is contained in:
Brad Hefta-Gaub 2015-10-13 16:23:24 -07:00
commit 7846965fbc
19 changed files with 110 additions and 27 deletions

View file

@ -1,5 +1,9 @@
#include "Mapping.h"
namespace controller {
Mapping::Mapping(const QString& name ) : _name(name) {
}
}

View file

@ -27,7 +27,10 @@ namespace controller {
using Map = std::map<Endpoint::Pointer, Route::List>;
using Pointer = std::shared_ptr<Mapping>;
Mapping(const QString& name);
Map _channelMappings;
const QString _name;
void parse(const QString& json);
QString serialize();

View file

@ -59,6 +59,25 @@ namespace controller {
QJSValue _callable;
};
class ScriptEndpoint : public Endpoint {
public:
ScriptEndpoint(const QScriptValue& callable)
: Endpoint(UserInputMapper::Input(-1)), _callable(callable) {
}
virtual float value() {
float result = (float)_callable.call().toNumber();
return result;
}
virtual void apply(float newValue, float oldValue, const Pointer& source) {
_callable.call(QScriptValue(), QScriptValueList({ QScriptValue(newValue) }));
}
private:
QScriptValue _callable;
};
class CompositeEndpoint : public Endpoint, Endpoint::Pair {
public:
CompositeEndpoint(Endpoint::Pointer first, Endpoint::Pointer second)
@ -158,7 +177,7 @@ namespace controller {
qCWarning(controllers) << "Refusing to recreate mapping named " << mappingName;
}
qDebug() << "Creating new Mapping " << mappingName;
Mapping::Pointer mapping = std::make_shared<Mapping>();
auto mapping = std::make_shared<Mapping>(mappingName);
_mappingsByName[mappingName] = mapping;
return new MappingBuilderProxy(*this, mapping);
}
@ -297,6 +316,11 @@ namespace controller {
return endpointFor(UserInputMapper::Input(endpoint.toInt32()));
}
if (endpoint.isFunction()) {
auto result = std::make_shared<ScriptEndpoint>(endpoint);
return result;
}
qWarning() << "Unsupported input type " << endpoint.toString();
return Endpoint::Pointer();
}

View file

@ -39,7 +39,7 @@ namespace controller {
Q_INVOKABLE float getValue(const int& source);
Q_INVOKABLE void update();
Q_INVOKABLE QObject* newMapping(const QString& mappingName);
Q_INVOKABLE QObject* newMapping(const QString& mappingName = QUuid::createUuid().toString());
Q_INVOKABLE void enableMapping(const QString& mappingName, bool enable = true);
Q_INVOKABLE void disableMapping(const QString& mappingName) {
enableMapping(mappingName, false);

View file

@ -41,4 +41,9 @@ QObject* MappingBuilderProxy::join(const QJSValue& source1, const QJSValue& sour
return from(_parent.compositeEndpointFor(source1Endpoint, source2Endpoint));
}
QObject* MappingBuilderProxy::enable(bool enable) {
_parent.enableMapping(_mapping->_name, enable);
return this;
}
}

View file

@ -30,8 +30,10 @@ public:
Q_INVOKABLE QObject* from(const QJSValue& source);
Q_INVOKABLE QObject* from(const QScriptValue& source);
Q_INVOKABLE QObject* join(const QJSValue& source1, const QJSValue& source2);
Q_INVOKABLE QObject* enable(bool enable = true);
Q_INVOKABLE QObject* disable() { return enable(false); }
protected:
QObject* from(const Endpoint::Pointer& source);

View file

@ -27,7 +27,4 @@ void NullDisplayPlugin::preRender() {}
void NullDisplayPlugin::preDisplay() {}
void NullDisplayPlugin::display(GLuint sceneTexture, const glm::uvec2& sceneSize) {}
void NullDisplayPlugin::finishFrame() {}
void NullDisplayPlugin::activate() {}
void NullDisplayPlugin::deactivate() {}
void NullDisplayPlugin::stop() {}

View file

@ -15,8 +15,6 @@ public:
virtual ~NullDisplayPlugin() final {}
virtual const QString & getName() const override;
void activate() override;
void deactivate() override;
void stop() override;
virtual glm::uvec2 getRecommendedRenderSize() const override;

View file

@ -57,12 +57,12 @@ void OpenGLDisplayPlugin::customizeContext() {
}
void OpenGLDisplayPlugin::activate() {
_active = true;
DisplayPlugin::activate();
_timer.start(1);
}
void OpenGLDisplayPlugin::stop() {
_active = false;
DisplayPlugin::activate();
_timer.stop();
}

View file

@ -44,7 +44,6 @@ protected:
mutable QTimer _timer;
ProgramPtr _program;
ShapeWrapperPtr _plane;
bool _active{ false };
bool _vsyncSupported{ false };
};

View file

@ -10,9 +10,9 @@
//
#include "KeyboardMouseDevice.h"
#include <QtGUI/QKeyEvent>
#include <QtGUI/QMouseEvent>
#include <QtGUI/QTouchEvent>
#include <QtGui/QKeyEvent>
#include <QtGui/QMouseEvent>
#include <QtGui/QTouchEvent>
const QString KeyboardMouseDevice::NAME = "Keyboard/Mouse";

View file

@ -13,6 +13,9 @@
#define hifi_KeyboardMouseDevice_h
#include <chrono>
#include <QtCore/QPoint>
#include "InputDevice.h"
#include "InputPlugin.h"
@ -65,9 +68,6 @@ public:
virtual bool isJointController() const override { return false; }
const QString& getName() const override { return NAME; }
virtual void activate() override {};
virtual void deactivate() override {};
virtual void pluginFocusOutEvent() override { focusOutEvent(); }
virtual void pluginUpdate(float deltaTime, bool jointsCaptured) override { update(deltaTime, jointsCaptured); }

View file

@ -34,8 +34,6 @@ public:
virtual void init() override;
virtual void deinit() override;
virtual void activate() override {};
virtual void deactivate() override {};
virtual void pluginFocusOutEvent() override;
virtual void pluginUpdate(float deltaTime, bool jointsCaptured) override;

View file

@ -85,6 +85,7 @@ bool SixenseManager::isSupported() const {
}
void SixenseManager::activate() {
InputPlugin::activate();
#ifdef HAVE_SIXENSE
_calibrationState = CALIBRATION_STATE_IDLE;
_avatarPosition = DEFAULT_AVATAR_POSITION;
@ -125,6 +126,7 @@ void SixenseManager::activate() {
}
void SixenseManager::deactivate() {
InputPlugin::deactivate();
#ifdef HAVE_SIXENSE
CONTAINER->removeMenuItem(MENU_NAME, TOGGLE_SMOOTH);
CONTAINER->removeMenu(MENU_PATH);

View file

@ -79,6 +79,7 @@ bool ViveControllerManager::isSupported() const {
}
void ViveControllerManager::activate() {
InputPlugin::activate();
#ifdef Q_OS_WIN
CONTAINER->addMenu(MENU_PATH);
CONTAINER->addMenuItem(MENU_PATH, RENDER_CONTROLLERS,
@ -143,6 +144,8 @@ void ViveControllerManager::activate() {
}
void ViveControllerManager::deactivate() {
InputPlugin::deactivate();
#ifdef Q_OS_WIN
CONTAINER->removeMenuItem(MENU_NAME, RENDER_CONTROLLERS);
CONTAINER->removeMenu(MENU_PATH);

View file

@ -33,9 +33,18 @@ public:
virtual void deinit();
/// Called when a plugin is being activated for use. May be called multiple times.
virtual void activate() = 0;
virtual void activate() {
_active = true;
}
/// Called when a plugin is no longer being used. May be called multiple times.
virtual void deactivate() = 0;
virtual void deactivate() {
_active = false;
}
virtual bool isActive() {
return _active;
}
/**
* Called by the application during it's idle phase. If the plugin needs to do
@ -48,6 +57,7 @@ public:
virtual void loadSettings() {}
protected:
bool _active{ false };
static PluginContainer* CONTAINER;
static QString UNKNOWN_PLUGIN_ID;

View file

@ -2,7 +2,7 @@
set(TARGET_NAME controllers-test)
# This is not a testcase -- just set it up as a regular hifi project
setup_hifi_project(Script)
setup_hifi_project(Script Qml)
set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/")
# link in the shared libraries

View file

@ -8,10 +8,21 @@ import "./controls"
Column {
id: root
property var xbox: NewControllers.Hardware.X360Controller1
property var actions: NewControllers.Actions
property var standard: NewControllers.Standard
property string mappingName: "TestMapping"
property var testMapping: null
property var xbox: null
Component.onCompleted: {
var patt = /^X360Controller/;
for (var prop in NewControllers.Hardware) {
if(patt.test(prop)) {
root.xbox = NewControllers.Hardware[prop]
break
}
}
}
spacing: 12
@ -49,13 +60,15 @@ Column {
mapping.from(xbox.LT).to(standard.LT);
mapping.from(xbox.RT).to(standard.RT);
NewControllers.enableMapping("Default");
enabled = false;
text = "Built"
}
}
Button {
text: "Build Mapping"
onClicked: {
var mapping = NewControllers.newMapping(root.mappingName);
var mapping = NewControllers.newMapping();
// Inverting a value
mapping.from(xbox.RY).invert().to(standard.RY);
// Assigning a value from a function
@ -63,17 +76,22 @@ Column {
// Constrainting a value to -1, 0, or 1, with a deadzone
mapping.from(xbox.LY).deadZone(0.5).constrainToInteger().to(standard.LY);
mapping.join(standard.LB, standard.RB).pulse(0.5).to(actions.Yaw);
mapping.from(actions.Yaw).clamp(0, 1).invert().to(actions.YAW_RIGHT);
mapping.from(actions.Yaw).clamp(-1, 0).to(actions.YAW_LEFT);
testMapping = mapping;
enabled = false
text = "Built"
}
}
Button {
text: "Enable Mapping"
onClicked: NewControllers.enableMapping(root.mappingName)
onClicked: root.testMapping.enable()
}
Button {
text: "Disable Mapping"
onClicked: NewControllers.disableMapping(root.mappingName)
onClicked: root.testMapping.disable()
}
}
@ -85,6 +103,7 @@ Column {
Row {
spacing: 8
ScrollingGraph {
controlId: NewControllers.Actions.Yaw
label: "Yaw"
@ -92,6 +111,22 @@ Column {
max: 3.0
size: 128
}
ScrollingGraph {
controlId: NewControllers.Actions.YAW_LEFT
label: "Yaw Left"
min: -3.0
max: 3.0
size: 128
}
ScrollingGraph {
controlId: NewControllers.Actions.YAW_RIGHT
label: "Yaw Right"
min: -3.0
max: 3.0
size: 128
}
}
}

View file

@ -82,6 +82,9 @@ public:
int main(int argc, char** argv) {
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
for (auto path : qApp->libraryPaths()) {
qDebug() << path;
}
{