mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 12:16:18 +02:00
first cut at preload script behavior
This commit is contained in:
parent
22dbebbe09
commit
2bc7896dee
7 changed files with 65 additions and 10 deletions
|
@ -12,13 +12,23 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
(function(){
|
(function(){
|
||||||
var bird = new Sound("http://s3.amazonaws.com/hifi-public/sounds/Animals/bushtit_1.raw");
|
var bird;
|
||||||
|
|
||||||
|
function playSound(entityID) {
|
||||||
|
var options = new AudioInjectionOptions();
|
||||||
|
var position = MyAvatar.position;
|
||||||
|
options.position = position;
|
||||||
|
options.volume = 0.5;
|
||||||
|
Audio.playSound(bird, options);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.preload = function(entityID) {
|
||||||
|
print("preload("+entityID.id+")");
|
||||||
|
bird = new Sound("http://s3.amazonaws.com/hifi-public/sounds/Animals/bushtit_1.raw");
|
||||||
|
};
|
||||||
|
|
||||||
this.clickDownOnEntity = function(entityID, mouseEvent) {
|
this.clickDownOnEntity = function(entityID, mouseEvent) {
|
||||||
print("clickDownOnEntity()...");
|
print("clickDownOnEntity()...");
|
||||||
var options = new AudioInjectionOptions();
|
playSound();
|
||||||
var position = MyAvatar.position;
|
|
||||||
options.position = position;
|
|
||||||
options.volume = 0.5;
|
|
||||||
Audio.playSound(bird, options);
|
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
(function(){
|
(function(){
|
||||||
var bird = new Sound("http://s3.amazonaws.com/hifi-public/sounds/Animals/bushtit_1.raw");
|
var bird;
|
||||||
|
|
||||||
function playSound(entityID) {
|
function playSound() {
|
||||||
var options = new AudioInjectionOptions();
|
var options = new AudioInjectionOptions();
|
||||||
var position = MyAvatar.position;
|
var position = MyAvatar.position;
|
||||||
options.position = position;
|
options.position = position;
|
||||||
|
@ -22,6 +22,11 @@
|
||||||
Audio.playSound(bird, options);
|
Audio.playSound(bird, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.preload = function(entityID) {
|
||||||
|
print("preload("+entityID.id+")");
|
||||||
|
bird = new Sound("http://s3.amazonaws.com/hifi-public/sounds/Animals/bushtit_1.raw");
|
||||||
|
};
|
||||||
|
|
||||||
this.enterEntity = function(entityID) {
|
this.enterEntity = function(entityID) {
|
||||||
playSound();
|
playSound();
|
||||||
};
|
};
|
||||||
|
|
|
@ -81,6 +81,8 @@ void EntityTreeRenderer::init() {
|
||||||
_lastAvatarPosition = avatarPosition + glm::vec3(1.f, 1.f, 1.f);
|
_lastAvatarPosition = avatarPosition + glm::vec3(1.f, 1.f, 1.f);
|
||||||
|
|
||||||
connect(entityTree, &EntityTree::deletingEntity, this, &EntityTreeRenderer::deletingEntity);
|
connect(entityTree, &EntityTree::deletingEntity, this, &EntityTreeRenderer::deletingEntity);
|
||||||
|
connect(entityTree, &EntityTree::addingEntity, this, &EntityTreeRenderer::addingEntity);
|
||||||
|
connect(entityTree, &EntityTree::changingEntityID, this, &EntityTreeRenderer::changingEntityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue EntityTreeRenderer::loadEntityScript(const EntityItemID& entityItemID) {
|
QScriptValue EntityTreeRenderer::loadEntityScript(const EntityItemID& entityItemID) {
|
||||||
|
@ -770,3 +772,19 @@ void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) {
|
||||||
_entityScripts.remove(entityID);
|
_entityScripts.remove(entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityTreeRenderer::addingEntity(const EntityItemID& entityID) {
|
||||||
|
qDebug() << "addingEntity() entityID:" << entityID;
|
||||||
|
|
||||||
|
// load the entity script if needed...
|
||||||
|
QScriptValue entityScript = loadEntityScript(entityID);
|
||||||
|
if (entityScript.property("preload").isValid()) {
|
||||||
|
QScriptValueList entityArgs = createEntityArgs(entityID);
|
||||||
|
entityScript.property("preload").call(entityScript, entityArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityTreeRenderer::changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID) {
|
||||||
|
qDebug() << "changingEntityID() oldEntityID:" << oldEntityID << "newEntityID:" << newEntityID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,8 @@ signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void deletingEntity(const EntityItemID& entityID);
|
void deletingEntity(const EntityItemID& entityID);
|
||||||
|
void addingEntity(const EntityItemID& entityID);
|
||||||
|
void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Model*> _releasedModels;
|
QList<Model*> _releasedModels;
|
||||||
|
|
|
@ -168,6 +168,7 @@ EntityItem* EntityTree::addEntity(const EntityItemID& entityID, const EntityItem
|
||||||
if (result) {
|
if (result) {
|
||||||
// this does the actual adding of the entity
|
// this does the actual adding of the entity
|
||||||
addEntityItem(result);
|
addEntityItem(result);
|
||||||
|
emitAddingEntity(entityID);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -184,6 +185,14 @@ void EntityTree::trackDeletedEntity(const EntityItemID& entityID) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityTree::emitAddingEntity(const EntityItemID& entityItemID) {
|
||||||
|
emit addingEntity(entityItemID);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityTree::emitEntityScriptChanging(const EntityItemID& entityItemID) {
|
||||||
|
emit entityScriptChanging(entityItemID);
|
||||||
|
}
|
||||||
|
|
||||||
void EntityTree::deleteEntity(const EntityItemID& entityID) {
|
void EntityTree::deleteEntity(const EntityItemID& entityID) {
|
||||||
emit deletingEntity(entityID);
|
emit deletingEntity(entityID);
|
||||||
|
|
||||||
|
@ -290,6 +299,7 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) {
|
||||||
EntityItemID creatorTokenVersion = searchEntityID.convertToCreatorTokenVersion();
|
EntityItemID creatorTokenVersion = searchEntityID.convertToCreatorTokenVersion();
|
||||||
EntityItemID knownIDVersion = searchEntityID.convertToKnownIDVersion();
|
EntityItemID knownIDVersion = searchEntityID.convertToKnownIDVersion();
|
||||||
|
|
||||||
|
|
||||||
// First look for and find the "viewed version" of this entity... it's possible we got
|
// First look for and find the "viewed version" of this entity... it's possible we got
|
||||||
// the known ID version sent to us between us creating our local version, and getting this
|
// the known ID version sent to us between us creating our local version, and getting this
|
||||||
// remapping message. If this happened, we actually want to find and delete that version of
|
// remapping message. If this happened, we actually want to find and delete that version of
|
||||||
|
@ -310,6 +320,10 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) {
|
||||||
creatorTokenContainingElement->updateEntityItemID(creatorTokenVersion, knownIDVersion);
|
creatorTokenContainingElement->updateEntityItemID(creatorTokenVersion, knownIDVersion);
|
||||||
setContainingElement(creatorTokenVersion, NULL);
|
setContainingElement(creatorTokenVersion, NULL);
|
||||||
setContainingElement(knownIDVersion, creatorTokenContainingElement);
|
setContainingElement(knownIDVersion, creatorTokenContainingElement);
|
||||||
|
|
||||||
|
// because the ID of the entity is switching, we need to emit these signals for any
|
||||||
|
// listeners who care about the changing of IDs
|
||||||
|
emit changingEntityID(creatorTokenVersion, knownIDVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
|
@ -981,7 +995,6 @@ int EntityTree::processEraseMessageDetails(const QByteArray& dataByteArray, cons
|
||||||
return processedBytes;
|
return processedBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EntityTreeElement* EntityTree::getContainingElement(const EntityItemID& entityItemID) /*const*/ {
|
EntityTreeElement* EntityTree::getContainingElement(const EntityItemID& entityItemID) /*const*/ {
|
||||||
// TODO: do we need to make this thread safe? Or is it acceptable as is
|
// TODO: do we need to make this thread safe? Or is it acceptable as is
|
||||||
if (_entityToElementMap.contains(entityItemID)) {
|
if (_entityToElementMap.contains(entityItemID)) {
|
||||||
|
|
|
@ -140,10 +140,16 @@ public:
|
||||||
|
|
||||||
void trackDeletedEntity(const EntityItemID& entityID);
|
void trackDeletedEntity(const EntityItemID& entityID);
|
||||||
|
|
||||||
|
void emitAddingEntity(const EntityItemID& entityItemID);
|
||||||
|
void emitEntityScriptChanging(const EntityItemID& entityItemID);
|
||||||
|
|
||||||
QList<EntityItem*>& getMovingEntities() { return _movingEntities; }
|
QList<EntityItem*>& getMovingEntities() { return _movingEntities; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deletingEntity(const EntityItemID& entityID);
|
void deletingEntity(const EntityItemID& entityID);
|
||||||
|
void addingEntity(const EntityItemID& entityID);
|
||||||
|
void entityScriptChanging(const EntityItemID& entityItemID);
|
||||||
|
void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -762,6 +762,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
|
||||||
addEntityItem(entityItem); // add this new entity to this elements entities
|
addEntityItem(entityItem); // add this new entity to this elements entities
|
||||||
entityItemID = entityItem->getEntityItemID();
|
entityItemID = entityItem->getEntityItemID();
|
||||||
_myTree->setContainingElement(entityItemID, this);
|
_myTree->setContainingElement(entityItemID, this);
|
||||||
|
_myTree->emitAddingEntity(entityItemID); // we just added an entity
|
||||||
EntityItem::SimulationState newState = entityItem->getSimulationState();
|
EntityItem::SimulationState newState = entityItem->getSimulationState();
|
||||||
_myTree->changeEntityState(entityItem, EntityItem::Static, newState);
|
_myTree->changeEntityState(entityItem, EntityItem::Static, newState);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue