mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 09:24:00 +02:00
support changing scripts on the fly and reloading them accordningly
This commit is contained in:
parent
e8c694f02e
commit
87a5423b35
2 changed files with 29 additions and 11 deletions
|
@ -83,8 +83,19 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) {
|
|||
if (!entity) {
|
||||
return QScriptValue(); // no entity...
|
||||
}
|
||||
if (_entityScripts.contains(entity->getEntityItemID())) {
|
||||
return _entityScripts[entity->getEntityItemID()]; // already loaded
|
||||
|
||||
EntityItemID entityID = entity->getEntityItemID();
|
||||
if (_entityScripts.contains(entityID)) {
|
||||
EntityScriptDetails details = _entityScripts[entityID];
|
||||
|
||||
// check to make sure our script text hasn't changed on us since we last loaded it
|
||||
if (details.scriptText == entity->getScript()) {
|
||||
return details.scriptObject; // previously loaded
|
||||
}
|
||||
|
||||
// if we got here, then we previously loaded a script, but the entity's script value
|
||||
// has changed and so we need to reload it.
|
||||
_entityScripts.remove(entityID);
|
||||
}
|
||||
if (entity->getScript().isEmpty()) {
|
||||
return QScriptValue(); // no script
|
||||
|
@ -107,7 +118,8 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) {
|
|||
}
|
||||
|
||||
QScriptValue entityScriptObject = entityScriptConstructor.construct();
|
||||
_entityScripts[entity->getEntityItemID()] = entityScriptObject;
|
||||
EntityScriptDetails newDetails = { entity->getScript(), entityScriptObject };
|
||||
_entityScripts[entityID] = newDetails;
|
||||
|
||||
return entityScriptObject; // newly constructed
|
||||
}
|
||||
|
@ -487,6 +499,13 @@ void EntityTreeRenderer::connectSignalsToSlots(EntityScriptingInterface* entityS
|
|||
connect(this, &EntityTreeRenderer::hoverLeaveEntity, entityScriptingInterface, &EntityScriptingInterface::hoverLeaveEntity);
|
||||
}
|
||||
|
||||
QScriptValueList EntityTreeRenderer::createMouseEventArgs(const EntityItemID& entityID, QMouseEvent* event, unsigned int deviceID) {
|
||||
QScriptValueList args;
|
||||
args << entityID.toScriptValue(_entitiesScriptEngine);
|
||||
args << MouseEvent(*event, deviceID).toScriptValue(_entitiesScriptEngine);
|
||||
return args;
|
||||
}
|
||||
|
||||
void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||
PerformanceTimer perfTimer("EntityTreeRenderer::mousePressEvent");
|
||||
PickRay ray = computePickRay(event->x(), event->y());
|
||||
|
@ -540,13 +559,6 @@ void EntityTreeRenderer::mouseReleaseEvent(QMouseEvent* event, unsigned int devi
|
|||
_currentClickingOnEntityID = EntityItemID::createInvalidEntityID();
|
||||
}
|
||||
|
||||
QScriptValueList EntityTreeRenderer::createMouseEventArgs(const EntityItemID& entityID, QMouseEvent* event, unsigned int deviceID) {
|
||||
QScriptValueList args;
|
||||
args << entityID.toScriptValue(_entitiesScriptEngine);
|
||||
args << MouseEvent(*event, deviceID).toScriptValue(_entitiesScriptEngine);
|
||||
return args;
|
||||
}
|
||||
|
||||
void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||
PerformanceTimer perfTimer("EntityTreeRenderer::mouseMoveEvent");
|
||||
PickRay ray = computePickRay(event->x(), event->y());
|
||||
|
|
|
@ -27,6 +27,12 @@
|
|||
|
||||
#include "renderer/Model.h"
|
||||
|
||||
class EntityScriptDetails {
|
||||
public:
|
||||
QString scriptText;
|
||||
QScriptValue scriptObject;
|
||||
};
|
||||
|
||||
// Generic client side Octree renderer class.
|
||||
class EntityTreeRenderer : public OctreeRenderer, public EntityItemFBXService {
|
||||
Q_OBJECT
|
||||
|
@ -115,7 +121,7 @@ private:
|
|||
QScriptValue loadEntityScript(const EntityItemID& entityItemID);
|
||||
QScriptValueList createMouseEventArgs(const EntityItemID& entityID, QMouseEvent* event, unsigned int deviceID);
|
||||
|
||||
QHash<EntityItemID, QScriptValue> _entityScripts;
|
||||
QHash<EntityItemID, EntityScriptDetails> _entityScripts;
|
||||
};
|
||||
|
||||
#endif // hifi_EntityTreeRenderer_h
|
||||
|
|
Loading…
Reference in a new issue