mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 23:40:11 +02:00
Merge pull request #2630 from AndrewMeadows/scripting
Expose MyAvatar.sessionUUID to JS
This commit is contained in:
commit
973fb95c9d
9 changed files with 102 additions and 17 deletions
|
@ -232,6 +232,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
connect(nodeList, SIGNAL(nodeAdded(SharedNodePointer)), &_voxels, SLOT(nodeAdded(SharedNodePointer)));
|
connect(nodeList, SIGNAL(nodeAdded(SharedNodePointer)), &_voxels, SLOT(nodeAdded(SharedNodePointer)));
|
||||||
connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), &_voxels, SLOT(nodeKilled(SharedNodePointer)));
|
connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), &_voxels, SLOT(nodeKilled(SharedNodePointer)));
|
||||||
connect(nodeList, &NodeList::uuidChanged, this, &Application::updateWindowTitle);
|
connect(nodeList, &NodeList::uuidChanged, this, &Application::updateWindowTitle);
|
||||||
|
connect(nodeList, SIGNAL(uuidChanged(const QUuid&)), _myAvatar, SLOT(setSessionUUID(const QUuid&)));
|
||||||
connect(nodeList, &NodeList::limitOfSilentDomainCheckInsReached, nodeList, &NodeList::reset);
|
connect(nodeList, &NodeList::limitOfSilentDomainCheckInsReached, nodeList, &NodeList::reset);
|
||||||
|
|
||||||
// connect to appropriate slots on AccountManager
|
// connect to appropriate slots on AccountManager
|
||||||
|
@ -1216,8 +1217,6 @@ void Application::timer() {
|
||||||
|
|
||||||
// ask the node list to check in with the domain server
|
// ask the node list to check in with the domain server
|
||||||
NodeList::getInstance()->sendDomainServerCheckIn();
|
NodeList::getInstance()->sendDomainServerCheckIn();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::idle() {
|
void Application::idle() {
|
||||||
|
|
|
@ -123,8 +123,8 @@ void AvatarManager::renderAvatarFades(const glm::vec3& cameraPosition, Avatar::R
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AvatarSharedPointer AvatarManager::matchingOrNewAvatar(const QUuid& nodeUUID, const QWeakPointer<Node>& mixerWeakPointer) {
|
AvatarSharedPointer AvatarManager::matchingOrNewAvatar(const QUuid& sessionUUID, const QWeakPointer<Node>& mixerWeakPointer) {
|
||||||
AvatarSharedPointer matchingAvatar = _avatarHash.value(nodeUUID);
|
AvatarSharedPointer matchingAvatar = _avatarHash.value(sessionUUID);
|
||||||
|
|
||||||
if (!matchingAvatar) {
|
if (!matchingAvatar) {
|
||||||
// construct a new Avatar for this node
|
// construct a new Avatar for this node
|
||||||
|
@ -133,9 +133,9 @@ AvatarSharedPointer AvatarManager::matchingOrNewAvatar(const QUuid& nodeUUID, co
|
||||||
|
|
||||||
// insert the new avatar into our hash
|
// insert the new avatar into our hash
|
||||||
matchingAvatar = AvatarSharedPointer(avatar);
|
matchingAvatar = AvatarSharedPointer(avatar);
|
||||||
_avatarHash.insert(nodeUUID, matchingAvatar);
|
_avatarHash.insert(sessionUUID, matchingAvatar);
|
||||||
|
|
||||||
qDebug() << "Adding avatar with UUID" << nodeUUID << "to AvatarManager hash.";
|
qDebug() << "Adding avatar with sessionUUID " << sessionUUID << "to AvatarManager hash.";
|
||||||
}
|
}
|
||||||
|
|
||||||
return matchingAvatar;
|
return matchingAvatar;
|
||||||
|
@ -166,10 +166,10 @@ void AvatarManager::processAvatarDataPacket(const QByteArray &datagram, const QW
|
||||||
// enumerate over all of the avatars in this packet
|
// enumerate over all of the avatars in this packet
|
||||||
// only add them if mixerWeakPointer points to something (meaning that mixer is still around)
|
// only add them if mixerWeakPointer points to something (meaning that mixer is still around)
|
||||||
while (bytesRead < datagram.size() && mixerWeakPointer.data()) {
|
while (bytesRead < datagram.size() && mixerWeakPointer.data()) {
|
||||||
QUuid nodeUUID = QUuid::fromRfc4122(datagram.mid(bytesRead, NUM_BYTES_RFC4122_UUID));
|
QUuid sessionUUID = QUuid::fromRfc4122(datagram.mid(bytesRead, NUM_BYTES_RFC4122_UUID));
|
||||||
bytesRead += NUM_BYTES_RFC4122_UUID;
|
bytesRead += NUM_BYTES_RFC4122_UUID;
|
||||||
|
|
||||||
AvatarSharedPointer matchingAvatarData = matchingOrNewAvatar(nodeUUID, mixerWeakPointer);
|
AvatarSharedPointer matchingAvatarData = matchingOrNewAvatar(sessionUUID, mixerWeakPointer);
|
||||||
|
|
||||||
// have the matching (or new) avatar parse the data from the packet
|
// have the matching (or new) avatar parse the data from the packet
|
||||||
bytesRead += matchingAvatarData->parseDataAtOffset(datagram, bytesRead);
|
bytesRead += matchingAvatarData->parseDataAtOffset(datagram, bytesRead);
|
||||||
|
@ -188,16 +188,16 @@ void AvatarManager::processAvatarIdentityPacket(const QByteArray &packet, const
|
||||||
QDataStream identityStream(packet);
|
QDataStream identityStream(packet);
|
||||||
identityStream.skipRawData(numBytesForPacketHeader(packet));
|
identityStream.skipRawData(numBytesForPacketHeader(packet));
|
||||||
|
|
||||||
QUuid nodeUUID;
|
QUuid sessionUUID;
|
||||||
|
|
||||||
while (!identityStream.atEnd()) {
|
while (!identityStream.atEnd()) {
|
||||||
|
|
||||||
QUrl faceMeshURL, skeletonURL;
|
QUrl faceMeshURL, skeletonURL;
|
||||||
QString displayName;
|
QString displayName;
|
||||||
identityStream >> nodeUUID >> faceMeshURL >> skeletonURL >> displayName;
|
identityStream >> sessionUUID >> faceMeshURL >> skeletonURL >> displayName;
|
||||||
|
|
||||||
// mesh URL for a UUID, find avatar in our list
|
// mesh URL for a UUID, find avatar in our list
|
||||||
AvatarSharedPointer matchingAvatar = matchingOrNewAvatar(nodeUUID, mixerWeakPointer);
|
AvatarSharedPointer matchingAvatar = matchingOrNewAvatar(sessionUUID, mixerWeakPointer);
|
||||||
if (matchingAvatar) {
|
if (matchingAvatar) {
|
||||||
Avatar* avatar = static_cast<Avatar*>(matchingAvatar.data());
|
Avatar* avatar = static_cast<Avatar*>(matchingAvatar.data());
|
||||||
|
|
||||||
|
@ -218,9 +218,9 @@ void AvatarManager::processAvatarIdentityPacket(const QByteArray &packet, const
|
||||||
|
|
||||||
void AvatarManager::processAvatarBillboardPacket(const QByteArray& packet, const QWeakPointer<Node>& mixerWeakPointer) {
|
void AvatarManager::processAvatarBillboardPacket(const QByteArray& packet, const QWeakPointer<Node>& mixerWeakPointer) {
|
||||||
int headerSize = numBytesForPacketHeader(packet);
|
int headerSize = numBytesForPacketHeader(packet);
|
||||||
QUuid nodeUUID = QUuid::fromRfc4122(QByteArray::fromRawData(packet.constData() + headerSize, NUM_BYTES_RFC4122_UUID));
|
QUuid sessionUUID = QUuid::fromRfc4122(QByteArray::fromRawData(packet.constData() + headerSize, NUM_BYTES_RFC4122_UUID));
|
||||||
|
|
||||||
AvatarSharedPointer matchingAvatar = matchingOrNewAvatar(nodeUUID, mixerWeakPointer);
|
AvatarSharedPointer matchingAvatar = matchingOrNewAvatar(sessionUUID, mixerWeakPointer);
|
||||||
if (matchingAvatar) {
|
if (matchingAvatar) {
|
||||||
Avatar* avatar = static_cast<Avatar*>(matchingAvatar.data());
|
Avatar* avatar = static_cast<Avatar*>(matchingAvatar.data());
|
||||||
QByteArray billboard = packet.mid(headerSize + NUM_BYTES_RFC4122_UUID);
|
QByteArray billboard = packet.mid(headerSize + NUM_BYTES_RFC4122_UUID);
|
||||||
|
@ -232,10 +232,10 @@ void AvatarManager::processAvatarBillboardPacket(const QByteArray& packet, const
|
||||||
|
|
||||||
void AvatarManager::processKillAvatar(const QByteArray& datagram) {
|
void AvatarManager::processKillAvatar(const QByteArray& datagram) {
|
||||||
// read the node id
|
// read the node id
|
||||||
QUuid nodeUUID = QUuid::fromRfc4122(datagram.mid(numBytesForPacketHeader(datagram), NUM_BYTES_RFC4122_UUID));
|
QUuid sessionUUID = QUuid::fromRfc4122(datagram.mid(numBytesForPacketHeader(datagram), NUM_BYTES_RFC4122_UUID));
|
||||||
|
|
||||||
// remove the avatar with that UUID from our hash, if it exists
|
// remove the avatar with that UUID from our hash, if it exists
|
||||||
AvatarHash::iterator matchedAvatar = _avatarHash.find(nodeUUID);
|
AvatarHash::iterator matchedAvatar = _avatarHash.find(sessionUUID);
|
||||||
if (matchedAvatar != _avatarHash.end()) {
|
if (matchedAvatar != _avatarHash.end()) {
|
||||||
erase(matchedAvatar);
|
erase(matchedAvatar);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ using namespace std;
|
||||||
QNetworkAccessManager* AvatarData::networkAccessManager = NULL;
|
QNetworkAccessManager* AvatarData::networkAccessManager = NULL;
|
||||||
|
|
||||||
AvatarData::AvatarData() :
|
AvatarData::AvatarData() :
|
||||||
|
_sessionUUID(),
|
||||||
_handPosition(0,0,0),
|
_handPosition(0,0,0),
|
||||||
_bodyYaw(-90.f),
|
_bodyYaw(-90.f),
|
||||||
_bodyPitch(0.0f),
|
_bodyPitch(0.0f),
|
||||||
|
|
|
@ -37,6 +37,7 @@ typedef unsigned long long quint64;
|
||||||
#include <QtCore/QVector>
|
#include <QtCore/QVector>
|
||||||
#include <QtCore/QVariantMap>
|
#include <QtCore/QVariantMap>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
#include <CollisionInfo.h>
|
#include <CollisionInfo.h>
|
||||||
#include <RegisteredMetaTypes.h>
|
#include <RegisteredMetaTypes.h>
|
||||||
|
@ -94,10 +95,14 @@ class AvatarData : public QObject {
|
||||||
Q_PROPERTY(QString faceModelURL READ getFaceModelURLFromScript WRITE setFaceModelURLFromScript)
|
Q_PROPERTY(QString faceModelURL READ getFaceModelURLFromScript WRITE setFaceModelURLFromScript)
|
||||||
Q_PROPERTY(QString skeletonModelURL READ getSkeletonModelURLFromScript WRITE setSkeletonModelURLFromScript)
|
Q_PROPERTY(QString skeletonModelURL READ getSkeletonModelURLFromScript WRITE setSkeletonModelURLFromScript)
|
||||||
Q_PROPERTY(QString billboardURL READ getBillboardURL WRITE setBillboardFromURL)
|
Q_PROPERTY(QString billboardURL READ getBillboardURL WRITE setBillboardFromURL)
|
||||||
|
|
||||||
|
Q_PROPERTY(QUuid sessionUUID READ getSessionUUID);
|
||||||
public:
|
public:
|
||||||
AvatarData();
|
AvatarData();
|
||||||
virtual ~AvatarData();
|
virtual ~AvatarData();
|
||||||
|
|
||||||
|
const QUuid& getSessionUUID() { return _sessionUUID; }
|
||||||
|
|
||||||
const glm::vec3& getPosition() const { return _position; }
|
const glm::vec3& getPosition() const { return _position; }
|
||||||
void setPosition(const glm::vec3 position) { _position = position; }
|
void setPosition(const glm::vec3 position) { _position = position; }
|
||||||
|
|
||||||
|
@ -219,7 +224,9 @@ public slots:
|
||||||
void sendBillboardPacket();
|
void sendBillboardPacket();
|
||||||
void setBillboardFromNetworkReply();
|
void setBillboardFromNetworkReply();
|
||||||
void setJointMappingsFromNetworkReply();
|
void setJointMappingsFromNetworkReply();
|
||||||
|
void setSessionUUID(const QUuid& id) { _sessionUUID = id; }
|
||||||
protected:
|
protected:
|
||||||
|
QUuid _sessionUUID;
|
||||||
glm::vec3 _position;
|
glm::vec3 _position;
|
||||||
glm::vec3 _handPosition;
|
glm::vec3 _handPosition;
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ AvatarHashMap::AvatarHashMap() :
|
||||||
|
|
||||||
void AvatarHashMap::insert(const QUuid& id, AvatarSharedPointer avatar) {
|
void AvatarHashMap::insert(const QUuid& id, AvatarSharedPointer avatar) {
|
||||||
_avatarHash.insert(id, avatar);
|
_avatarHash.insert(id, avatar);
|
||||||
|
avatar->setSessionUUID(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
AvatarHash::iterator AvatarHashMap::erase(const AvatarHash::iterator& iterator) {
|
AvatarHash::iterator AvatarHashMap::erase(const AvatarHash::iterator& iterator) {
|
||||||
|
|
|
@ -60,7 +60,8 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam
|
||||||
_scriptName(),
|
_scriptName(),
|
||||||
_fileNameString(fileNameString),
|
_fileNameString(fileNameString),
|
||||||
_quatLibrary(),
|
_quatLibrary(),
|
||||||
_vec3Library()
|
_vec3Library(),
|
||||||
|
_uuidLibrary()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +84,8 @@ ScriptEngine::ScriptEngine(const QUrl& scriptURL,
|
||||||
_scriptName(),
|
_scriptName(),
|
||||||
_fileNameString(),
|
_fileNameString(),
|
||||||
_quatLibrary(),
|
_quatLibrary(),
|
||||||
_vec3Library()
|
_vec3Library(),
|
||||||
|
_uuidLibrary()
|
||||||
{
|
{
|
||||||
QString scriptURLString = scriptURL.toString();
|
QString scriptURLString = scriptURL.toString();
|
||||||
_fileNameString = scriptURLString;
|
_fileNameString = scriptURLString;
|
||||||
|
@ -197,6 +199,7 @@ void ScriptEngine::init() {
|
||||||
registerGlobalObject("Particles", &_particlesScriptingInterface);
|
registerGlobalObject("Particles", &_particlesScriptingInterface);
|
||||||
registerGlobalObject("Quat", &_quatLibrary);
|
registerGlobalObject("Quat", &_quatLibrary);
|
||||||
registerGlobalObject("Vec3", &_vec3Library);
|
registerGlobalObject("Vec3", &_vec3Library);
|
||||||
|
registerGlobalObject("Uuid", &_uuidLibrary);
|
||||||
|
|
||||||
registerGlobalObject("Voxels", &_voxelsScriptingInterface);
|
registerGlobalObject("Voxels", &_voxelsScriptingInterface);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "AbstractControllerScriptingInterface.h"
|
#include "AbstractControllerScriptingInterface.h"
|
||||||
#include "Quat.h"
|
#include "Quat.h"
|
||||||
|
#include "ScriptUUID.h"
|
||||||
#include "Vec3.h"
|
#include "Vec3.h"
|
||||||
|
|
||||||
class ParticlesScriptingInterface;
|
class ParticlesScriptingInterface;
|
||||||
|
@ -121,6 +122,7 @@ private:
|
||||||
QString _fileNameString;
|
QString _fileNameString;
|
||||||
Quat _quatLibrary;
|
Quat _quatLibrary;
|
||||||
Vec3 _vec3Library;
|
Vec3 _vec3Library;
|
||||||
|
ScriptUUID _uuidLibrary;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__ScriptEngine__) */
|
#endif /* defined(__hifi__ScriptEngine__) */
|
||||||
|
|
40
libraries/script-engine/src/ScriptUUID.cpp
Normal file
40
libraries/script-engine/src/ScriptUUID.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
//
|
||||||
|
// ScriptUUID.cpp
|
||||||
|
// libraries/script-engine/src/
|
||||||
|
//
|
||||||
|
// Created by Andrew Meadows on 2014-04-07
|
||||||
|
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Scriptable interface for a UUID helper class object. Used exclusively in the JavaScript API
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "ScriptUUID.h"
|
||||||
|
|
||||||
|
QUuid ScriptUUID::fromString(const QString& s) {
|
||||||
|
return QUuid(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ScriptUUID::toString(const QUuid& id) {
|
||||||
|
return id.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid ScriptUUID::generate() {
|
||||||
|
return QUuid::createUuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScriptUUID::isEqual(const QUuid& idA, const QUuid& idB) {
|
||||||
|
return idA == idB;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScriptUUID::isNull(const QUuid& id) {
|
||||||
|
return id.isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptUUID::print(const QString& lable, const QUuid& id) {
|
||||||
|
qDebug() << qPrintable(lable) << id.toString();
|
||||||
|
}
|
32
libraries/script-engine/src/ScriptUUID.h
Normal file
32
libraries/script-engine/src/ScriptUUID.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
//
|
||||||
|
// ScriptUUID.h
|
||||||
|
// libraries/script-engine/src/
|
||||||
|
//
|
||||||
|
// Created by Andrew Meadows on 2014-04-07
|
||||||
|
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Scriptable interface for a UUID helper class object. Used exclusively in the JavaScript API
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_ScriptUUID_h
|
||||||
|
#define hifi_ScriptUUID_h
|
||||||
|
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
/// Scriptable interface for a UUID helper class object. Used exclusively in the JavaScript API
|
||||||
|
class ScriptUUID : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
QUuid fromString(const QString& string);
|
||||||
|
QString toString(const QUuid& id);
|
||||||
|
QUuid generate();
|
||||||
|
bool isEqual(const QUuid& idA, const QUuid& idB);
|
||||||
|
bool isNull(const QUuid& id);
|
||||||
|
void print(const QString& lable, const QUuid& id);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_ScriptUUID_h
|
Loading…
Reference in a new issue