Merge branch 'master' of https://github.com/highfidelity/hifi into blue

This commit is contained in:
samcake 2017-10-23 17:12:31 -07:00
commit ccdda798c0
15 changed files with 233 additions and 142 deletions

View file

@ -85,6 +85,7 @@ EntityScriptServer::EntityScriptServer(ReceivedMessage& message) : ThreadedAssig
packetReceiver.registerListener(PacketType::ReloadEntityServerScript, this, "handleReloadEntityServerScriptPacket");
packetReceiver.registerListener(PacketType::EntityScriptGetStatus, this, "handleEntityScriptGetStatusPacket");
packetReceiver.registerListener(PacketType::EntityServerScriptLog, this, "handleEntityServerScriptLogPacket");
packetReceiver.registerListener(PacketType::EntityScriptCallMethod, this, "handleEntityScriptCallMethodPacket");
static const int LOG_INTERVAL = MSECS_PER_SECOND / 10;
auto timer = new QTimer(this);
@ -231,6 +232,27 @@ void EntityScriptServer::pushLogs() {
}
}
void EntityScriptServer::handleEntityScriptCallMethodPacket(QSharedPointer<ReceivedMessage> receivedMessage, SharedNodePointer senderNode) {
if (_entitiesScriptEngine && _entityViewer.getTree() && !_shuttingDown) {
auto entityID = QUuid::fromRfc4122(receivedMessage->read(NUM_BYTES_RFC4122_UUID));
auto method = receivedMessage->readString();
quint16 paramCount;
receivedMessage->readPrimitive(&paramCount);
QStringList params;
for (int param = 0; param < paramCount; param++) {
auto paramString = receivedMessage->readString();
params << paramString;
}
_entitiesScriptEngine->callEntityScriptMethod(entityID, method, params, senderNode->getUUID());
}
}
void EntityScriptServer::run() {
// make sure we request our script once the agent connects to the domain
auto nodeList = DependencyManager::get<NodeList>();

View file

@ -54,6 +54,9 @@ private slots:
void pushLogs();
void handleEntityScriptCallMethodPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
private:
void negotiateAudioFormat();
void selectAudioFormat(const QString& selectedCodecName);

View file

@ -14,6 +14,8 @@
import Hifi 1.0
import QtQuick 2.5
import QtGraphicalEffects 1.0
import TabletScriptingInterface 1.0
import "toolbars"
import "../styles-uit"
@ -243,9 +245,15 @@ Item {
MouseArea {
anchors.fill: parent;
acceptedButtons: Qt.LeftButton;
onClicked: goFunction("hifi://" + hifiUrl);
onClicked: {
tabletInterface.playSound(TabletEnums.ButtonClick);
goFunction("hifi://" + hifiUrl);
}
hoverEnabled: true;
onEntered: hoverThunk();
onEntered: {
tabletInterface.playSound(TabletEnums.ButtonHover);
hoverThunk();
}
onExited: unhoverThunk();
}
StateImage {
@ -261,6 +269,7 @@ Item {
}
}
function go() {
tabletInterface.playSound(TabletEnums.ButtonClick);
goFunction(drillDownToPlace ? ("/places/" + placeName) : ("/user_stories/" + storyId));
}
MouseArea {

View file

@ -1,6 +1,6 @@
//
// skyboxchanger.qml
//
// SkyboxChanger.qml
// qml/hifi
//
// Created by Cain Kilgore on 9th August 2017
// Copyright 2017 High Fidelity, Inc.
@ -9,33 +9,73 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick.Layouts 1.3
import QtQuick 2.5
import "../styles-uit"
import "../controls-uit" as HifiControls
import QtQuick.Controls 2.2
Rectangle {
Item {
id: root;
color: hifi.colors.baseGray;
HifiConstants { id: hifi; }
property var defaultThumbnails: [];
property var defaultFulls: [];
ListModel {
id: skyboxModel;
}
function getSkyboxes() {
var xmlhttp = new XMLHttpRequest();
var url = "http://mpassets.highfidelity.com/5fbdbeef-1cf8-4954-811d-3d4acbba4dc9-v1/skyboxes.json";
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState === XMLHttpRequest.DONE && xmlhttp.status === 200) {
sortSkyboxes(xmlhttp.responseText);
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
function sortSkyboxes(response) {
var arr = JSON.parse(response);
var arrLength = arr.length;
for (var i = 0; i < arrLength; i++) {
defaultThumbnails.push(arr[i].thumb);
defaultFulls.push(arr[i].full);
skyboxModel.append({});
}
setSkyboxes();
}
function setSkyboxes() {
for (var i = 0; i < skyboxModel.count; i++) {
skyboxModel.setProperty(i, "thumbnailPath", defaultThumbnails[i]);
skyboxModel.setProperty(i, "fullSkyboxPath", defaultFulls[i]);
}
}
Component.onCompleted: {
getSkyboxes();
}
Item {
id: titleBarContainer;
// Size
width: parent.width;
height: 50;
// Anchors
height: childrenRect.height;
anchors.left: parent.left;
anchors.top: parent.top;
RalewaySemiBold {
anchors.right: parent.right;
anchors.topMargin: 20;
RalewayBold {
id: titleBarText;
text: "Skybox Changer";
// Text size
size: hifi.fontSizes.overlayTitle;
// Anchors
anchors.fill: parent;
anchors.leftMargin: 16;
// Style
anchors.top: parent.top;
anchors.left: parent.left;
anchors.leftMargin: 40
height: paintedHeight;
color: hifi.colors.lightGrayText;
// Alignment
horizontalAlignment: Text.AlignHCenter;
verticalAlignment: Text.AlignVCenter;
}
@ -43,131 +83,61 @@ Rectangle {
id: titleBarDesc;
text: "Click an image to choose a new Skybox.";
wrapMode: Text.Wrap
// Text size
size: 14;
// Anchors
anchors.fill: parent;
anchors.top: titleBarText.bottom
anchors.leftMargin: 16;
anchors.rightMargin: 16;
// Style
anchors.top: titleBarText.bottom;
anchors.left: parent.left;
anchors.leftMargin: 40
height: paintedHeight;
color: hifi.colors.lightGrayText;
// Alignment
horizontalAlignment: Text.AlignHCenter;
verticalAlignment: Text.AlignVCenter;
}
}
}
// This RowLayout could be a GridLayout instead for further expandability.
// As this SkyboxChanger task only required 6 images, implementing GridLayout wasn't necessary.
// In the future if this is to be expanded to add more Skyboxes, it might be worth changing this.
RowLayout {
id: row1
GridView {
id: gridView
interactive: true
clip: true
anchors.top: titleBarContainer.bottom
anchors.left: parent.left
anchors.leftMargin: 30
Layout.fillWidth: true
anchors.topMargin: 30
spacing: 10
Image {
width: 200; height: 200
fillMode: Image.Stretch
source: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_1.jpg"
clip: true
id: preview1
MouseArea {
anchors.topMargin: 20
anchors.horizontalCenter: parent.horizontalCenter
width: 400
anchors.bottom: parent.bottom
currentIndex: -1
cellWidth: 200
cellHeight: 200
model: skyboxModel
delegate: Item {
width: gridView.cellWidth
height: gridView.cellHeight
Item {
anchors.fill: parent
onClicked: {
sendToScript({method: 'changeSkybox', url: 'http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/1.jpg'});
Image {
source: thumbnailPath
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
fillMode: Image.Stretch
sourceSize.width: parent.width
sourceSize.height: parent.height
mipmap: true
}
}
Layout.fillWidth: true
}
Image {
width: 200; height: 200
fillMode: Image.Stretch
source: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_2.jpg"
clip: true
id: preview2
MouseArea {
anchors.fill: parent
onClicked: {
sendToScript({method: 'changeSkybox', url: 'http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/2.png'});
sendToScript({method: 'changeSkybox', url: fullSkyboxPath});
}
}
}
}
RowLayout {
id: row2
anchors.top: row1.bottom
anchors.topMargin: 10
anchors.left: parent.left
Layout.fillWidth: true
anchors.leftMargin: 30
spacing: 10
Image {
width: 200; height: 200
fillMode: Image.Stretch
source: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_3.jpg"
clip: true
id: preview3
MouseArea {
anchors.fill: parent
onClicked: {
sendToScript({method: 'changeSkybox', url: 'http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/3.jpg'});
}
}
}
Image {
width: 200; height: 200
fillMode: Image.Stretch
source: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_4.jpg"
clip: true
id: preview4
MouseArea {
anchors.fill: parent
onClicked: {
sendToScript({method: 'changeSkybox', url: 'http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/4.jpg'});
}
}
}
}
RowLayout {
id: row3
anchors.top: row2.bottom
anchors.topMargin: 10
anchors.left: parent.left
Layout.fillWidth: true
anchors.leftMargin: 30
spacing: 10
Image {
width: 200; height: 200
fillMode: Image.Stretch
source: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_5.jpg"
clip: true
id: preview5
MouseArea {
anchors.fill: parent
onClicked: {
sendToScript({method: 'changeSkybox', url: 'http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/5.png'});
}
}
}
Image {
width: 200; height: 200
fillMode: Image.Stretch
source: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_6.jpg"
clip: true
id: preview6
MouseArea {
anchors.fill: parent
onClicked: {
sendToScript({method: 'changeSkybox', url: 'http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/6.jpg'});
}
}
ScrollBar.vertical: ScrollBar {
parent: gridView.parent
anchors.top: gridView.top
anchors.left: gridView.right
anchors.bottom: gridView.bottom
anchors.leftMargin: 10
width: 19
}
}
signal sendToScript(var message);
}
}

View file

@ -1,5 +1,6 @@
import QtQuick 2.0
import QtGraphicalEffects 1.0
import TabletScriptingInterface 1.0
Item {
id: newEntityButton
@ -122,9 +123,11 @@ Item {
hoverEnabled: true
enabled: true
onClicked: {
tabletInterface.playSound(TabletEnums.ButtonClick);
newEntityButton.clicked();
}
onEntered: {
tabletInterface.playSound(TabletEnums.ButtonHover);
newEntityButton.state = "hover state";
}
onExited: {

View file

@ -5090,6 +5090,7 @@ void Application::update(float deltaTime) {
}
this->updateCamera(appRenderArgs._renderArgs);
appRenderArgs._eyeToWorld = _myCamera.getTransform();
appRenderArgs._isStereo = false;
{

View file

@ -96,6 +96,7 @@ void Line3DOverlay::setEnd(const glm::vec3& end) {
} else {
_direction = glm::vec3(0.0f);
}
notifyRenderTransformChange();
}
void Line3DOverlay::setLocalEnd(const glm::vec3& localEnd) {

View file

@ -20,7 +20,8 @@
class EntitiesScriptEngineProvider {
public:
virtual void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const QStringList& params = QStringList()) = 0;
virtual void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName,
const QStringList& params = QStringList(), const QUuid& remoteCallerID = QUuid()) = 0;
virtual QFuture<QVariant> getLocalEntityScriptDetails(const EntityItemID& entityID) = 0;
};

View file

@ -566,6 +566,11 @@ void EntityScriptingInterface::callEntityMethod(QUuid id, const QString& method,
}
}
void EntityScriptingInterface::callEntityServerMethod(QUuid id, const QString& method, const QStringList& params) {
PROFILE_RANGE(script_entities, __FUNCTION__);
DependencyManager::get<EntityScriptClient>()->callEntityServerMethod(id, method, params);
}
QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const {
PROFILE_RANGE(script_entities, __FUNCTION__);

View file

@ -188,11 +188,11 @@ public slots:
*/
Q_INVOKABLE void deleteEntity(QUuid entityID);
/// Allows a script to call a method on an entity's script. The method will execute in the entity script
/// engine. If the entity does not have an entity script or the method does not exist, this call will have
/// no effect.
/**jsdoc
* Call a method on an entity. If it is running an entity script (specified by the `script` property)
* Call a method on an entity. Allows a script to call a method on an entity's script.
* The method will execute in the entity script engine. If the entity does not have an
* entity script or the method does not exist, this call will have no effect.
* If it is running an entity script (specified by the `script` property)
* and it exposes a property with the specified name `method`, it will be called
* using `params` as the list of arguments.
*
@ -203,10 +203,29 @@ public slots:
*/
Q_INVOKABLE void callEntityMethod(QUuid entityID, const QString& method, const QStringList& params = QStringList());
/// finds the closest model to the center point, within the radius
/// will return a EntityItemID.isKnownID = false if no models are in the radius
/// this function will not find any models in script engine contexts which don't have access to models
/**jsdoc
* Call a server method on an entity. Allows a client entity script to call a method on an
* entity's server script. The method will execute in the entity server script engine. If
* the entity does not have an entity server script or the method does not exist, this call will
* have no effect. If the entity is running an entity script (specified by the `serverScripts` property)
* and it exposes a property with the specified name `method`, it will be called using `params` as
* the list of arguments.
*
* @function Entities.callEntityServerMethod
* @param {EntityID} entityID The ID of the entity to call the method on.
* @param {string} method The name of the method to call.
* @param {string[]} params The list of parameters to call the specified method with.
*/
Q_INVOKABLE void callEntityServerMethod(QUuid entityID, const QString& method, const QStringList& params = QStringList());
/**jsdoc
* finds the closest model to the center point, within the radius
* will return a EntityItemID.isKnownID = false if no models are in the radius
* this function will not find any models in script engine contexts which don't have access to models
* @function Entities.findClosestEntity
* @param {vec3} center point
* @param {float} radius to search
* @return {EntityID} The EntityID of the entity that is closest and in the radius.
*/
Q_INVOKABLE QUuid findClosestEntity(const glm::vec3& center, float radius) const;

View file

@ -69,6 +69,30 @@ bool EntityScriptClient::reloadServerScript(QUuid entityID) {
return false;
}
void EntityScriptClient::callEntityServerMethod(QUuid entityID, const QString& method, const QStringList& params) {
// Send packet to entity script server
auto nodeList = DependencyManager::get<NodeList>();
SharedNodePointer entityScriptServer = nodeList->soloNodeOfType(NodeType::EntityScriptServer);
if (entityScriptServer) {
auto packetList = NLPacketList::create(PacketType::EntityScriptCallMethod, QByteArray(), true, true);
packetList->write(entityID.toRfc4122());
packetList->writeString(method);
quint16 paramCount = params.length();
packetList->writePrimitive(paramCount);
foreach(const QString& param, params) {
packetList->writeString(param);
}
nodeList->sendPacketList(std::move(packetList), *entityScriptServer);
}
}
MessageID EntityScriptClient::getEntityServerScriptStatus(QUuid entityID, GetScriptStatusCallback callback) {
auto nodeList = DependencyManager::get<NodeList>();
SharedNodePointer entityScriptServer = nodeList->soloNodeOfType(NodeType::EntityScriptServer);

View file

@ -58,6 +58,8 @@ public:
bool reloadServerScript(QUuid entityID);
MessageID getEntityServerScriptStatus(QUuid entityID, GetScriptStatusCallback callback);
void callEntityServerMethod(QUuid id, const QString& method, const QStringList& params);
private slots:
void handleNodeKilled(SharedNodePointer node);

View file

@ -123,6 +123,7 @@ public:
ReplicatedBulkAvatarData,
OctreeFileReplacementFromUrl,
ChallengeOwnership,
EntityScriptCallMethod,
NUM_PACKET_TYPE
};

View file

@ -2476,7 +2476,7 @@ void ScriptEngine::callWithEnvironment(const EntityItemID& entityID, const QUrl&
doWithEnvironment(entityID, sandboxURL, operation);
}
void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const QStringList& params) {
void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const QStringList& params, const QUuid& remoteCallerID) {
if (QThread::currentThread() != thread()) {
#ifdef THREAD_DEBUGGING
qCDebug(scriptengine) << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
@ -2486,7 +2486,8 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS
QMetaObject::invokeMethod(this, "callEntityScriptMethod",
Q_ARG(const EntityItemID&, entityID),
Q_ARG(const QString&, methodName),
Q_ARG(const QStringList&, params));
Q_ARG(const QStringList&, params),
Q_ARG(const QUuid&, remoteCallerID));
return;
}
#ifdef THREAD_DEBUGGING
@ -2500,13 +2501,41 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS
if (isEntityScriptRunning(entityID)) {
EntityScriptDetails details = _entityScripts[entityID];
QScriptValue entityScript = details.scriptObject; // previously loaded
if (entityScript.property(methodName).isFunction()) {
// If this is a remote call, we need to check to see if the function is remotely callable
// we do this by checking for the existance of the 'remotelyCallable' property on the
// entityScript. And we confirm that the method name is included. If this fails, the
// function will not be called.
bool callAllowed = false;
if (remoteCallerID == QUuid()) {
callAllowed = true;
} else {
if (entityScript.property("remotelyCallable").isArray()) {
auto callables = entityScript.property("remotelyCallable");
auto callableCount = callables.property("length").toInteger();
for (int i = 0; i < callableCount; i++) {
auto callable = callables.property(i).toString();
if (callable == methodName) {
callAllowed = true;
break;
}
}
}
if (!callAllowed) {
qDebug() << "Method [" << methodName << "] not remotely callable.";
}
}
if (callAllowed && entityScript.property(methodName).isFunction()) {
QScriptValueList args;
args << entityID.toScriptValue(this);
args << qScriptValueFromSequence(this, params);
callWithEnvironment(entityID, details.definingSandboxURL, entityScript.property(methodName), entityScript, args);
}
QScriptValue oldData = this->globalObject().property("Script").property("remoteCallerID");
this->globalObject().property("Script").setProperty("remoteCallerID", remoteCallerID.toString()); // Make the remoteCallerID available to javascript as a global.
callWithEnvironment(entityID, details.definingSandboxURL, entityScript.property(methodName), entityScript, args);
this->globalObject().property("Script").setProperty("remoteCallerID", oldData);
}
}
}

View file

@ -198,7 +198,8 @@ public:
Q_INVOKABLE void unloadEntityScript(const EntityItemID& entityID, bool shouldRemoveFromMap = false); // will call unload method
Q_INVOKABLE void unloadAllEntityScripts();
Q_INVOKABLE void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName,
const QStringList& params = QStringList()) override;
const QStringList& params = QStringList(),
const QUuid& remoteCallerID = QUuid()) override;
Q_INVOKABLE void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const PointerEvent& event);
Q_INVOKABLE void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const EntityItemID& otherID, const Collision& collision);