mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 04:23:33 +02:00
moving EntityItemID from script-engine to shared
This commit is contained in:
parent
fce56f10d4
commit
dbf633d218
7 changed files with 80 additions and 90 deletions
|
@ -145,7 +145,7 @@ void EntityScriptingInterface::attachDefaultEventHandlers(ScriptManager* manager
|
||||||
using SingleEntityHandler = std::function<void(const EntityItemID&)>;
|
using SingleEntityHandler = std::function<void(const EntityItemID&)>;
|
||||||
auto makeSingleEntityHandler = [manager](QString eventName) -> SingleEntityHandler {
|
auto makeSingleEntityHandler = [manager](QString eventName) -> SingleEntityHandler {
|
||||||
return [manager, eventName](const EntityItemID& entityItemID) {
|
return [manager, eventName](const EntityItemID& entityItemID) {
|
||||||
manager->forwardHandlerCall(entityItemID, eventName, { entityItemID.toScriptValue(manager->engine().data()) });
|
manager->forwardHandlerCall(entityItemID, eventName, { EntityItemIDtoScriptValue(manager->engine().data(), entityItemID) });
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ void EntityScriptingInterface::attachDefaultEventHandlers(ScriptManager* manager
|
||||||
if (!EntityTree::areEntityClicksCaptured()) {
|
if (!EntityTree::areEntityClicksCaptured()) {
|
||||||
ScriptEngine* engine = manager->engine().data();
|
ScriptEngine* engine = manager->engine().data();
|
||||||
manager->forwardHandlerCall(entityItemID, eventName,
|
manager->forwardHandlerCall(entityItemID, eventName,
|
||||||
{ entityItemID.toScriptValue(engine), event.toScriptValue(engine) });
|
{ EntityItemIDtoScriptValue(engine, entityItemID), event.toScriptValue(engine) });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -178,7 +178,8 @@ void EntityScriptingInterface::attachDefaultEventHandlers(ScriptManager* manager
|
||||||
return [manager, eventName](const EntityItemID& idA, const EntityItemID& idB, const Collision& collision) {
|
return [manager, eventName](const EntityItemID& idA, const EntityItemID& idB, const Collision& collision) {
|
||||||
ScriptEngine* engine = manager->engine().data();
|
ScriptEngine* engine = manager->engine().data();
|
||||||
manager->forwardHandlerCall(idA, eventName,
|
manager->forwardHandlerCall(idA, eventName,
|
||||||
{ idA.toScriptValue(engine), idB.toScriptValue(engine),
|
{ EntityItemIDtoScriptValue(engine, idA),
|
||||||
|
EntityItemIDtoScriptValue(engine, idB),
|
||||||
collisionToScriptValue(engine, collision) });
|
collisionToScriptValue(engine, collision) });
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
//
|
|
||||||
// EntityItemID.cpp
|
|
||||||
// libraries/script-engine/src
|
|
||||||
//
|
|
||||||
// Created by Brad Hefta-Gaub on 12/4/13.
|
|
||||||
// Copyright 2013 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "EntityItemID.h"
|
|
||||||
#include <QtCore/QObject>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include <BufferParser.h>
|
|
||||||
#include <udt/PacketHeaders.h>
|
|
||||||
#include <UUID.h>
|
|
||||||
|
|
||||||
#include <RegisteredMetaTypes.h>
|
|
||||||
#include "ScriptValue.h"
|
|
||||||
#include "ScriptValueUtils.h"
|
|
||||||
|
|
||||||
int entityItemIDTypeID = qRegisterMetaType<EntityItemID>();
|
|
||||||
|
|
||||||
EntityItemID::EntityItemID() : QUuid()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
EntityItemID::EntityItemID(const QUuid& id) : QUuid(id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// EntityItemID::EntityItemID(const EntityItemID& other) : QUuid(other)
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
EntityItemID EntityItemID::readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead) {
|
|
||||||
EntityItemID result;
|
|
||||||
if (bytesLeftToRead >= NUM_BYTES_RFC4122_UUID) {
|
|
||||||
BufferParser(data, bytesLeftToRead).readUuid(result);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptValuePointer EntityItemID::toScriptValue(ScriptEngine* engine) const {
|
|
||||||
return EntityItemIDtoScriptValue(engine, *this);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptValuePointer EntityItemIDtoScriptValue(ScriptEngine* engine, const EntityItemID& id) {
|
|
||||||
return quuidToScriptValue(engine, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EntityItemIDfromScriptValue(const ScriptValuePointer &object, EntityItemID& id) {
|
|
||||||
quuidFromScriptValue(object, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const ScriptValuePointer& array) {
|
|
||||||
if (!array->isArray()) {
|
|
||||||
return QVector<EntityItemID>();
|
|
||||||
}
|
|
||||||
QVector<EntityItemID> newVector;
|
|
||||||
int length = array->property("length")->toInteger();
|
|
||||||
newVector.reserve(length);
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
QString uuidAsString = array->property(i)->toString();
|
|
||||||
EntityItemID fromString(uuidAsString);
|
|
||||||
newVector << fromString;
|
|
||||||
}
|
|
||||||
return newVector;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t std::hash<EntityItemID>::operator()(const EntityItemID& id) const { return qHash(id); }
|
|
|
@ -2340,7 +2340,7 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q
|
||||||
auto scriptEngine = engine().data();
|
auto scriptEngine = engine().data();
|
||||||
|
|
||||||
ScriptValueList args;
|
ScriptValueList args;
|
||||||
args << entityID.toScriptValue(scriptEngine);
|
args << EntityItemIDtoScriptValue(scriptEngine, entityID);
|
||||||
args << scriptValueFromSequence(scriptEngine, params);
|
args << scriptValueFromSequence(scriptEngine, params);
|
||||||
|
|
||||||
ScriptValuePointer oldData = scriptEngine->globalObject()->property("Script")->property("remoteCallerID");
|
ScriptValuePointer oldData = scriptEngine->globalObject()->property("Script")->property("remoteCallerID");
|
||||||
|
@ -2383,7 +2383,7 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q
|
||||||
auto scriptEngine = engine().data();
|
auto scriptEngine = engine().data();
|
||||||
|
|
||||||
ScriptValueList args;
|
ScriptValueList args;
|
||||||
args << entityID.toScriptValue(scriptEngine);
|
args << EntityItemIDtoScriptValue(scriptEngine, entityID);
|
||||||
args << event.toScriptValue(scriptEngine);
|
args << event.toScriptValue(scriptEngine);
|
||||||
callWithEnvironment(entityID, details.definingSandboxURL, entityScript->property(methodName), entityScript, args);
|
callWithEnvironment(entityID, details.definingSandboxURL, entityScript->property(methodName), entityScript, args);
|
||||||
}
|
}
|
||||||
|
@ -2423,8 +2423,8 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q
|
||||||
auto scriptEngine = engine().data();
|
auto scriptEngine = engine().data();
|
||||||
|
|
||||||
ScriptValueList args;
|
ScriptValueList args;
|
||||||
args << entityID.toScriptValue(scriptEngine);
|
args << EntityItemIDtoScriptValue(scriptEngine, entityID);
|
||||||
args << otherID.toScriptValue(scriptEngine);
|
args << EntityItemIDtoScriptValue(scriptEngine, otherID);
|
||||||
args << collisionToScriptValue(scriptEngine, collision);
|
args << collisionToScriptValue(scriptEngine, collision);
|
||||||
callWithEnvironment(entityID, details.definingSandboxURL, entityScript->property(methodName), entityScript, args);
|
callWithEnvironment(entityID, details.definingSandboxURL, entityScript->property(methodName), entityScript, args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <AACube.h>
|
#include <AACube.h>
|
||||||
#include <shared/MiniPromises.h>
|
#include <shared/MiniPromises.h>
|
||||||
#include <RegisteredMetaTypes.h>
|
#include <RegisteredMetaTypes.h>
|
||||||
|
#include <EntityItemID.h>
|
||||||
|
|
||||||
#include "ScriptEngine.h"
|
#include "ScriptEngine.h"
|
||||||
#include "ScriptEngineCast.h"
|
#include "ScriptEngineCast.h"
|
||||||
|
@ -885,3 +886,26 @@ void promiseFromScriptValue(const ScriptValuePointer& object, std::shared_ptr<Mi
|
||||||
ScriptValuePointer promiseToScriptValue(ScriptEngine* engine, const std::shared_ptr<MiniPromise>& promise) {
|
ScriptValuePointer promiseToScriptValue(ScriptEngine* engine, const std::shared_ptr<MiniPromise>& promise) {
|
||||||
return engine->newQObject(promise.get());
|
return engine->newQObject(promise.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScriptValuePointer EntityItemIDtoScriptValue(ScriptEngine* engine, const EntityItemID& id) {
|
||||||
|
return quuidToScriptValue(engine, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItemIDfromScriptValue(const ScriptValuePointer &object, EntityItemID& id) {
|
||||||
|
quuidFromScriptValue(object, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const ScriptValuePointer& array) {
|
||||||
|
if (!array->isArray()) {
|
||||||
|
return QVector<EntityItemID>();
|
||||||
|
}
|
||||||
|
QVector<EntityItemID> newVector;
|
||||||
|
int length = array->property("length")->toInteger();
|
||||||
|
newVector.reserve(length);
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
QString uuidAsString = array->property(i)->toString();
|
||||||
|
EntityItemID fromString(uuidAsString);
|
||||||
|
newVector << fromString;
|
||||||
|
}
|
||||||
|
return newVector;
|
||||||
|
}
|
||||||
|
|
|
@ -262,6 +262,11 @@ class MiniPromise;
|
||||||
void promiseFromScriptValue(const ScriptValuePointer& object, std::shared_ptr<MiniPromise>& promise);
|
void promiseFromScriptValue(const ScriptValuePointer& object, std::shared_ptr<MiniPromise>& promise);
|
||||||
ScriptValuePointer promiseToScriptValue(ScriptEngine* engine, const std::shared_ptr<MiniPromise>& promise);
|
ScriptValuePointer promiseToScriptValue(ScriptEngine* engine, const std::shared_ptr<MiniPromise>& promise);
|
||||||
|
|
||||||
|
class EntityItemID;
|
||||||
|
ScriptValuePointer EntityItemIDtoScriptValue(ScriptEngine* engine, const EntityItemID& properties);
|
||||||
|
void EntityItemIDfromScriptValue(const ScriptValuePointer& object, EntityItemID& properties);
|
||||||
|
QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const ScriptValuePointer& array);
|
||||||
|
|
||||||
#endif // #define hifi_ScriptValueUtils_h
|
#endif // #define hifi_ScriptValueUtils_h
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
42
libraries/shared/src/EntityItemID.cpp
Normal file
42
libraries/shared/src/EntityItemID.cpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
//
|
||||||
|
// EntityItemID.cpp
|
||||||
|
// libraries/shared/src
|
||||||
|
//
|
||||||
|
// Created by Brad Hefta-Gaub on 12/4/13.
|
||||||
|
// Copyright 2013 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "EntityItemID.h"
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "BufferParser.h"
|
||||||
|
#include "UUID.h"
|
||||||
|
|
||||||
|
int entityItemIDTypeID = qRegisterMetaType<EntityItemID>();
|
||||||
|
|
||||||
|
EntityItemID::EntityItemID() : QUuid()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EntityItemID::EntityItemID(const QUuid& id) : QUuid(id)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// EntityItemID::EntityItemID(const EntityItemID& other) : QUuid(other)
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
|
||||||
|
EntityItemID EntityItemID::readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead) {
|
||||||
|
EntityItemID result;
|
||||||
|
if (bytesLeftToRead >= NUM_BYTES_RFC4122_UUID) {
|
||||||
|
BufferParser(data, bytesLeftToRead).readUuid(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t std::hash<EntityItemID>::operator()(const EntityItemID& id) const { return qHash(id); }
|
|
@ -1,6 +1,6 @@
|
||||||
//
|
//
|
||||||
// EntityItemID.h
|
// EntityItemID.h
|
||||||
// libraries/script-engine/src
|
// libraries/shared/src
|
||||||
//
|
//
|
||||||
// Created by Brad Hefta-Gaub on 12/4/13.
|
// Created by Brad Hefta-Gaub on 12/4/13.
|
||||||
// Copyright 2013 High Fidelity, Inc.
|
// Copyright 2013 High Fidelity, Inc.
|
||||||
|
@ -20,10 +20,6 @@
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
class ScriptEngine;
|
|
||||||
class ScriptValue;
|
|
||||||
using ScriptValuePointer = QSharedPointer<ScriptValue>;
|
|
||||||
|
|
||||||
const QUuid UNKNOWN_ENTITY_ID; // null uuid
|
const QUuid UNKNOWN_ENTITY_ID; // null uuid
|
||||||
|
|
||||||
/// Abstract ID for editing model items. Used in EntityItem JS API.
|
/// Abstract ID for editing model items. Used in EntityItem JS API.
|
||||||
|
@ -33,7 +29,6 @@ public:
|
||||||
EntityItemID(const QUuid& id);
|
EntityItemID(const QUuid& id);
|
||||||
// EntityItemID(const EntityItemID& other);
|
// EntityItemID(const EntityItemID& other);
|
||||||
static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead);
|
static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead);
|
||||||
ScriptValuePointer toScriptValue(ScriptEngine* engine) const;
|
|
||||||
|
|
||||||
bool isInvalidID() const { return *this == UNKNOWN_ENTITY_ID; }
|
bool isInvalidID() const { return *this == UNKNOWN_ENTITY_ID; }
|
||||||
};
|
};
|
||||||
|
@ -45,9 +40,6 @@ inline QDebug operator<<(QDebug debug, const EntityItemID& id) {
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(EntityItemID);
|
Q_DECLARE_METATYPE(EntityItemID);
|
||||||
Q_DECLARE_METATYPE(QVector<EntityItemID>);
|
Q_DECLARE_METATYPE(QVector<EntityItemID>);
|
||||||
ScriptValuePointer EntityItemIDtoScriptValue(ScriptEngine* engine, const EntityItemID& properties);
|
|
||||||
void EntityItemIDfromScriptValue(const ScriptValuePointer &object, EntityItemID& properties);
|
|
||||||
QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const ScriptValuePointer& array);
|
|
||||||
|
|
||||||
// Allow the use of std::unordered_map with QUuid keys
|
// Allow the use of std::unordered_map with QUuid keys
|
||||||
namespace std { template<> struct hash<EntityItemID> { size_t operator()(const EntityItemID& id) const; }; }
|
namespace std { template<> struct hash<EntityItemID> { size_t operator()(const EntityItemID& id) const; }; }
|
Loading…
Reference in a new issue