Skip to content

Commit

Permalink
Merge pull request #10 from overte-org/fix/doppelganger
Browse files Browse the repository at this point in the history
Fix doppelganger app to work with new scripting engine PR
  • Loading branch information
JulianGro authored May 18, 2023
2 parents 5b0dfd5 + eb4c63f commit 060ca36
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
6 changes: 3 additions & 3 deletions applications/doppelganger-mirror/app-doppleganger.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ Script.scriptEnding.connect(function() {
var doppleganger = new DopplegangerClass({
avatar: MyAvatar,
mirrored: false,
autoUpdate: true
autoUpdate: true,
});

// hide the doppleganger if this client script is unloaded
Script.scriptEnding.connect(doppleganger, 'stop');
Script.scriptEnding.connect(doppleganger, doppleganger.stop);

// hide the doppleganger if the user switches domains (which might place them arbitrarily far away in world space)
function onDomainChanged() {
Expand All @@ -53,7 +53,7 @@ Script.scriptEnding.connect(function() {
});

// toggle on/off via tablet button
button.clicked.connect(doppleganger, 'toggle');
button.clicked.connect(doppleganger, doppleganger.toggle);

// highlight tablet button based on current doppleganger state
doppleganger.activeChanged.connect(function(active, reason) {
Expand Down
36 changes: 18 additions & 18 deletions applications/doppelganger-mirror/doppleganger.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//
// Created by Timothy Dedischew on 04/21/2017.
// Copyright 2017 High Fidelity, Inc.
// Copyright 2022 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
Expand Down Expand Up @@ -62,9 +63,10 @@ Doppleganger.getMirroredJointNames = function(jointNames) {
// @param {bool} [options.autoUpdate=true] - Automatically sync joint data.
function Doppleganger(options) {
options = options || {};
this.avatar = options.avatar || MyAvatar;
this.avatar = MyAvatar;
this.mirrored = 'mirrored' in options ? options.mirrored : false;
this.autoUpdate = 'autoUpdate' in options ? options.autoUpdate : true;
this.testValue = options.testValue;

// @public
this.active = false; // whether doppleganger is currently being displayed/updated
Expand Down Expand Up @@ -159,8 +161,6 @@ Doppleganger.prototype = {
// @param {vec3} [options.position=(in front of avatar)] - starting position
// @param {quat} [options.orientation=avatar.orientation] - starting orientation
start: function(options) {


options = options || {};
if (this.entityID) {
//log('start() called but entity model already exists', this.entityID);
Expand Down Expand Up @@ -215,7 +215,7 @@ Doppleganger.prototype = {
this._createUpdateThread();
}
};
this.addingEntity.connect(this, 'onAddingEntity');
this.addingEntity.connect(this, this.onAddingEntity);

log('doppleganger created; entityID =', this.entityID);

Expand All @@ -226,7 +226,7 @@ Doppleganger.prototype = {
this.stop('entity_deleted');
}
};
Entities.deletingEntity.connect(this, 'onDeletedEntity');
Entities.deletingEntity.connect(this, this.onDeletedEntity);

if ('onLoadComplete' in avatar) {
// stop the current doppleganger if Avatar loads a different model URL
Expand All @@ -235,7 +235,7 @@ Doppleganger.prototype = {
this.stop('avatar_changed_load');
}
};
avatar.onLoadComplete.connect(this, 'onLoadComplete');
avatar.onLoadComplete.connect(this, this.onLoadComplete);
}

this.activeChanged(this.active = true, 'start');
Expand All @@ -247,23 +247,23 @@ Doppleganger.prototype = {
stop: function(reason) {
reason = reason || 'stop';
if (this.onUpdate) {
Script.update.disconnect(this, 'onUpdate');
Script.update.disconnect(this, this.onUpdate);
delete this.onUpdate;
}
if (this._interval) {
Script.clearInterval(this._interval);
this._interval = undefined;
}
if (this.onDeletedEntity) {
Entities.deletingEntity.disconnect(this, 'onDeletedEntity');
Entities.deletingEntity.disconnect(this, this.onDeletedEntity);
delete this.onDeletedEntity;
}
if (this.onLoadComplete) {
this.avatar.onLoadComplete.disconnect(this, 'onLoadComplete');
this.avatar.onLoadComplete.disconnect(this, this.onLoadComplete);
delete this.onLoadComplete;
}
if (this.onAddingEntity) {
this.addingEntity.disconnect(this, 'onAddingEntity');
this.addingEntity.disconnect(this, this.onAddingEntity);
}
if (this.entityID) {
Entities.deleteEntity(this.entityID);
Expand Down Expand Up @@ -303,11 +303,11 @@ Doppleganger.prototype = {
if (Doppleganger.USE_SCRIPT_UPDATE) {
log('creating Script.update thread');
this.onUpdate = this.update;
Script.update.connect(this, 'onUpdate');
Script.update.connect(this, this.onUpdate);
} else {
log('creating Script.setInterval thread @ ~', Doppleganger.TARGET_FPS +'fps');
var timeout = 1000 / Doppleganger.TARGET_FPS;
this._interval = Script.setInterval(bind(this, 'update'), timeout);
this._interval = Script.setInterval(bind(this, this.update), timeout);
}
},

Expand All @@ -321,7 +321,7 @@ Doppleganger.prototype = {
function waitForJointNames() {
var error = null, result = null;
if (!watchdogTimer) {
error = 'joints_unavailable';
error = 'joints_unavailable_watchodog_fail';
} else if (resource.state === Resource.State.FAILED) {
error = 'prefetch_failed';
} else if (resource.state === Resource.State.FINISHED) {
Expand Down Expand Up @@ -408,14 +408,14 @@ Doppleganger.addDebugControls = function(doppleganger) {
start: function() {
if (!this.onMousePressEvent) {
this.onMousePressEvent = this._onMousePressEvent;
Controller.mousePressEvent.connect(this, 'onMousePressEvent');
Controller.mousePressEvent.connect(this, this.onMousePressEvent);
}
},

stop: function() {
this.removeIndicators();
if (this.onMousePressEvent) {
Controller.mousePressEvent.disconnect(this, 'onMousePressEvent');
Controller.mousePressEvent.disconnect(this, this.onMousePressEvent);
delete this.onMousePressEvent;
}
},
Expand Down Expand Up @@ -502,11 +502,11 @@ Doppleganger.addDebugControls = function(doppleganger) {
doppleganger.activeChanged.connect(function(active) {
if (active) {
debugControls.start();
doppleganger.jointsUpdated.connect(debugControls, 'onJointsUpdated');
doppleganger.jointsUpdated.connect(debugControls, this.onJointsUpdated);
Controller.mousePressEvent.connect(onMousePressEvent);
} else {
Controller.mousePressEvent.disconnect(onMousePressEvent);
doppleganger.jointsUpdated.disconnect(debugControls, 'onJointsUpdated');
doppleganger.jointsUpdated.disconnect(debugControls, this.onJointsUpdated);
debugControls.stop();
}
});
Expand All @@ -520,7 +520,7 @@ Doppleganger.addDebugControls = function(doppleganger) {
log('selected joint:', JSON.stringify(hit, 0, 2));
});

Script.scriptEnding.connect(debugControls, 'removeIndicators');
Script.scriptEnding.connect(debugControls, debugControls.removeIndicators);

return doppleganger;
};
26 changes: 13 additions & 13 deletions tutorial/doppleganger.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Doppleganger.prototype = {
this._createUpdateThread();
}
};
this.addingEntity.connect(this, 'onAddingEntity');
this.addingEntity.connect(this, this.onAddingEntity);

log('doppleganger created; entityID =', this.entityID);

Expand All @@ -226,7 +226,7 @@ Doppleganger.prototype = {
this.stop('entity_deleted');
}
};
Entities.deletingEntity.connect(this, 'onDeletedEntity');
Entities.deletingEntity.connect(this, this.onDeletedEntity);

if ('onLoadComplete' in avatar) {
// stop the current doppleganger if Avatar loads a different model URL
Expand All @@ -235,7 +235,7 @@ Doppleganger.prototype = {
//this.stop('avatar_changed_load');
}
};
avatar.onLoadComplete.connect(this, 'onLoadComplete');
avatar.onLoadComplete.connect(this, this.onLoadComplete);
}

this.activeChanged(this.active = true, 'start');
Expand All @@ -247,23 +247,23 @@ Doppleganger.prototype = {
stop: function(reason) {
reason = reason || 'stop';
if (this.onUpdate) {
Script.update.disconnect(this, 'onUpdate');
Script.update.disconnect(this, this.onUpdate);
delete this.onUpdate;
}
if (this._interval) {
Script.clearInterval(this._interval);
this._interval = undefined;
}
if (this.onDeletedEntity) {
Entities.deletingEntity.disconnect(this, 'onDeletedEntity');
Entities.deletingEntity.disconnect(this, this.onDeletedEntity);
delete this.onDeletedEntity;
}
if (this.onLoadComplete) {
this.avatar.onLoadComplete.disconnect(this, 'onLoadComplete');
this.avatar.onLoadComplete.disconnect(this, this.onLoadComplete);
delete this.onLoadComplete;
}
if (this.onAddingEntity) {
this.addingEntity.disconnect(this, 'onAddingEntity');
this.addingEntity.disconnect(this, this.onAddingEntity);
}
if (this.entityID) {
Entities.deleteEntity(this.entityID);
Expand Down Expand Up @@ -303,7 +303,7 @@ Doppleganger.prototype = {
if (Doppleganger.USE_SCRIPT_UPDATE) {
log('creating Script.update thread');
this.onUpdate = this.update;
Script.update.connect(this, 'onUpdate');
Script.update.connect(this, this.onUpdate);
} else {
log('creating Script.setInterval thread @ ~', Doppleganger.TARGET_FPS +'fps');
var timeout = 1000 / Doppleganger.TARGET_FPS;
Expand Down Expand Up @@ -408,14 +408,14 @@ Doppleganger.addDebugControls = function(doppleganger) {
start: function() {
if (!this.onMousePressEvent) {
this.onMousePressEvent = this._onMousePressEvent;
Controller.mousePressEvent.connect(this, 'onMousePressEvent');
Controller.mousePressEvent.connect(this, this.onMousePressEvent);
}
},

stop: function() {
this.removeIndicators();
if (this.onMousePressEvent) {
Controller.mousePressEvent.disconnect(this, 'onMousePressEvent');
Controller.mousePressEvent.disconnect(this, this.onMousePressEvent);
delete this.onMousePressEvent;
}
},
Expand Down Expand Up @@ -502,11 +502,11 @@ Doppleganger.addDebugControls = function(doppleganger) {
doppleganger.activeChanged.connect(function(active) {
if (active) {
debugControls.start();
doppleganger.jointsUpdated.connect(debugControls, 'onJointsUpdated');
doppleganger.jointsUpdated.connect(debugControls, debugControls.onJointsUpdated);
Controller.mousePressEvent.connect(onMousePressEvent);
} else {
Controller.mousePressEvent.disconnect(onMousePressEvent);
doppleganger.jointsUpdated.disconnect(debugControls, 'onJointsUpdated');
doppleganger.jointsUpdated.disconnect(debugControls, debugControls.onJointsUpdated);
debugControls.stop();
}
});
Expand All @@ -520,7 +520,7 @@ Doppleganger.addDebugControls = function(doppleganger) {
log('selected joint:', JSON.stringify(hit, 0, 2));
});

Script.scriptEnding.connect(debugControls, 'removeIndicators');
Script.scriptEnding.connect(debugControls, debugControls.removeIndicators);

return doppleganger;
};

0 comments on commit 060ca36

Please sign in to comment.