mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Merge pull request #11967 from ctrlaltdavid/21638
Reduce communications load of making user connection
This commit is contained in:
commit
55ad42c40b
1 changed files with 69 additions and 38 deletions
|
@ -46,25 +46,26 @@
|
||||||
var PARTICLE_EFFECT_PROPS = {
|
var PARTICLE_EFFECT_PROPS = {
|
||||||
"alpha": 0.8,
|
"alpha": 0.8,
|
||||||
"azimuthFinish": Math.PI,
|
"azimuthFinish": Math.PI,
|
||||||
"azimuthStart": -1 * Math.PI,
|
"azimuthStart": -Math.PI,
|
||||||
"emitRate": 500,
|
"emitRate": 500,
|
||||||
"emitSpeed": 0.0,
|
|
||||||
"emitterShouldTrail": 1,
|
"emitterShouldTrail": 1,
|
||||||
"isEmitting": 1,
|
"isEmitting": 1,
|
||||||
"lifespan": 3,
|
"lifespan": 3,
|
||||||
"maxParticles": 1000,
|
"maxParticles": 1000,
|
||||||
"particleRadius": 0.003,
|
"particleRadius": 0.003,
|
||||||
"polarStart": 1,
|
"polarStart": Math.PI / 2,
|
||||||
"polarFinish": 1,
|
"polarFinish": Math.PI / 2,
|
||||||
"radiusFinish": 0.008,
|
"radiusFinish": 0.008,
|
||||||
"radiusStart": 0.0025,
|
"radiusStart": 0.0025,
|
||||||
"speedSpread": 0.025,
|
"emitSpeed": 0.02,
|
||||||
|
"speedSpread": 0.015,
|
||||||
"textures": "http://hifi-content.s3.amazonaws.com/alan/dev/Particles/Bokeh-Particle.png",
|
"textures": "http://hifi-content.s3.amazonaws.com/alan/dev/Particles/Bokeh-Particle.png",
|
||||||
"color": {"red": 255, "green": 255, "blue": 255},
|
"color": {"red": 255, "green": 255, "blue": 255},
|
||||||
"colorFinish": {"red": 0, "green": 164, "blue": 255},
|
"colorFinish": {"red": 0, "green": 164, "blue": 255},
|
||||||
"colorStart": {"red": 255, "green": 255, "blue": 255},
|
"colorStart": {"red": 255, "green": 255, "blue": 255},
|
||||||
"emitOrientation": {"w": -0.71, "x": 0.0, "y": 0.0, "z": 0.71},
|
"emitOrientation": {"w": -0.71, "x": 0.0, "y": 0.0, "z": 0.71},
|
||||||
"emitAcceleration": {"x": 0.0, "y": 0.0, "z": 0.0},
|
"emitAcceleration": {"x": 0.0, "y": 0.0, "z": 0.0},
|
||||||
|
"emitDimensions": { "x": 0.15, "y": 0.15, "z": 0.01 },
|
||||||
"accelerationSpread": {"x": 0.0, "y": 0.0, "z": 0.0},
|
"accelerationSpread": {"x": 0.0, "y": 0.0, "z": 0.0},
|
||||||
"dimensions": {"x": 0.05, "y": 0.05, "z": 0.05},
|
"dimensions": {"x": 0.05, "y": 0.05, "z": 0.05},
|
||||||
"type": "ParticleEffect"
|
"type": "ParticleEffect"
|
||||||
|
@ -111,10 +112,20 @@
|
||||||
var connectingHandJointIndex = -1;
|
var connectingHandJointIndex = -1;
|
||||||
var waitingList = {};
|
var waitingList = {};
|
||||||
var particleEffect;
|
var particleEffect;
|
||||||
var particleRotationAngle = 0.0;
|
var particleEmitRate;
|
||||||
|
var PARTICLE_INITIAL_EMIT_RATE = 250;
|
||||||
|
var PARTICLE_MINIMUM_EMIT_RATE = 50;
|
||||||
|
var PARTICLE_DECAY_RATE = 0.5;
|
||||||
|
var particleEffectUpdateTimer = null;
|
||||||
|
var PARTICLE_EFFECT_UPDATE_INTERVAL = 200;
|
||||||
var makingConnectionParticleEffect;
|
var makingConnectionParticleEffect;
|
||||||
var makingConnectionEmitRate = 2000;
|
var makingConnectionEmitRate;
|
||||||
var particleEmitRate = 500;
|
var isMakingConnectionEmitting;
|
||||||
|
var MAKING_CONNECTION_INITIAL_EMIT_RATE = 500;
|
||||||
|
var MAKING_CONNECTION_MINIMUM_EMIT_RATE = 20;
|
||||||
|
var MAKING_CONNECTION_DECAY_RATE = 0.5;
|
||||||
|
var makingConnectionUpdateTimer = null;
|
||||||
|
var MAKING_CONNECTION_UPDATE_INTERVAL = 200;
|
||||||
var handshakeInjector;
|
var handshakeInjector;
|
||||||
var successfulHandshakeInjector;
|
var successfulHandshakeInjector;
|
||||||
var handshakeSound;
|
var handshakeSound;
|
||||||
|
@ -239,12 +250,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteParticleEffect() {
|
function deleteParticleEffect() {
|
||||||
|
if (particleEffectUpdateTimer) {
|
||||||
|
Script.clearTimeout(particleEffectUpdateTimer);
|
||||||
|
particleEffectUpdateTimer = null;
|
||||||
|
}
|
||||||
if (particleEffect) {
|
if (particleEffect) {
|
||||||
particleEffect = Entities.deleteEntity(particleEffect);
|
particleEffect = Entities.deleteEntity(particleEffect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteMakeConnectionParticleEffect() {
|
function deleteMakeConnectionParticleEffect() {
|
||||||
|
if (makingConnectionUpdateTimer) {
|
||||||
|
Script.clearTimeout(makingConnectionUpdateTimer);
|
||||||
|
makingConnectionUpdateTimer = null;
|
||||||
|
}
|
||||||
if (makingConnectionParticleEffect) {
|
if (makingConnectionParticleEffect) {
|
||||||
makingConnectionParticleEffect = Entities.deleteEntity(makingConnectionParticleEffect);
|
makingConnectionParticleEffect = Entities.deleteEntity(makingConnectionParticleEffect);
|
||||||
}
|
}
|
||||||
|
@ -257,15 +276,31 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function calcParticlePos(myHandPosition, otherHandPosition, otherOrientation, reset) {
|
function updateMakingConnection() {
|
||||||
if (reset) {
|
makingConnectionEmitRate = Math.max(makingConnectionEmitRate * MAKING_CONNECTION_DECAY_RATE,
|
||||||
particleRotationAngle = 0.0;
|
MAKING_CONNECTION_MINIMUM_EMIT_RATE);
|
||||||
|
isMakingConnectionEmitting = true;
|
||||||
|
Entities.editEntity(makingConnectionParticleEffect, {
|
||||||
|
emitRate: makingConnectionEmitRate,
|
||||||
|
isEmitting: true
|
||||||
|
});
|
||||||
|
if (makingConnectionEmitRate > MAKING_CONNECTION_MINIMUM_EMIT_RATE) {
|
||||||
|
makingConnectionUpdateTimer = Script.setTimeout(makingConnectionUpdateTimer, MAKING_CONNECTION_UPDATE_INTERVAL);
|
||||||
|
} else {
|
||||||
|
makingConnectionUpdateTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateParticleEffect() {
|
||||||
|
particleEmitRate = Math.max(PARTICLE_MINIMUM_EMIT_RATE, particleEmitRate * PARTICLE_DECAY_RATE);
|
||||||
|
Entities.editEntity(particleEffect, {
|
||||||
|
emitRate: particleEmitRate
|
||||||
|
});
|
||||||
|
if (particleEmitRate > PARTICLE_MINIMUM_EMIT_RATE) {
|
||||||
|
particleEffectUpdateTimer = Script.setTimeout(updateParticleEffect, PARTICLE_EFFECT_UPDATE_INTERVAL);
|
||||||
|
} else {
|
||||||
|
particleEffectUpdateTimer = null;
|
||||||
}
|
}
|
||||||
var position = positionFractionallyTowards(myHandPosition, otherHandPosition, 0.5);
|
|
||||||
particleRotationAngle += PARTICLE_ANGLE_INCREMENT; // about 0.5 hz
|
|
||||||
var radius = Math.min(PARTICLE_RADIUS, PARTICLE_RADIUS * particleRotationAngle / 360);
|
|
||||||
var axis = Vec3.mix(Quat.getFront(MyAvatar.orientation), Quat.inverse(Quat.getFront(otherOrientation)), 0.5);
|
|
||||||
return Vec3.sum(position, Vec3.multiplyQbyV(Quat.angleAxis(particleRotationAngle, axis), {x: 0, y: radius, z: 0}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is called frequently, but usually does nothing
|
// this is called frequently, but usually does nothing
|
||||||
|
@ -301,41 +336,37 @@
|
||||||
positionFractionallyTowards(myHandPosition, otherHandPosition, 0.5);
|
positionFractionallyTowards(myHandPosition, otherHandPosition, 0.5);
|
||||||
// now manage the rest of the entity
|
// now manage the rest of the entity
|
||||||
if (!particleEffect) {
|
if (!particleEffect) {
|
||||||
particleRotationAngle = 0.0;
|
particleEmitRate = PARTICLE_INITIAL_EMIT_RATE;
|
||||||
particleEmitRate = 500;
|
|
||||||
particleProps = PARTICLE_EFFECT_PROPS;
|
particleProps = PARTICLE_EFFECT_PROPS;
|
||||||
particleProps.isEmitting = 0;
|
particleProps.position = positionFractionallyTowards(myHandPosition, otherHandPosition, 0.5);
|
||||||
particleProps.position = calcParticlePos(myHandPosition, otherHandPosition, otherOrientation);
|
particleProps.rotation = Vec3.mix(Quat.getFront(MyAvatar.orientation),
|
||||||
|
Quat.inverse(Quat.getFront(otherOrientation)), 0.5);
|
||||||
particleProps.parentID = MyAvatar.sessionUUID;
|
particleProps.parentID = MyAvatar.sessionUUID;
|
||||||
particleEffect = Entities.addEntity(particleProps, true);
|
particleEffect = Entities.addEntity(particleProps, true);
|
||||||
} else {
|
|
||||||
particleProps.position = calcParticlePos(myHandPosition, otherHandPosition, otherOrientation);
|
|
||||||
particleProps.isEmitting = 1;
|
|
||||||
Entities.editEntity(particleEffect, particleProps);
|
|
||||||
}
|
}
|
||||||
if (!makingConnectionParticleEffect) {
|
if (!makingConnectionParticleEffect) {
|
||||||
var props = MAKING_CONNECTION_PARTICLE_PROPS;
|
var props = MAKING_CONNECTION_PARTICLE_PROPS;
|
||||||
props.parentID = MyAvatar.sessionUUID;
|
props.parentID = MyAvatar.sessionUUID;
|
||||||
makingConnectionEmitRate = 2000;
|
makingConnectionEmitRate = MAKING_CONNECTION_INITIAL_EMIT_RATE;
|
||||||
props.emitRate = makingConnectionEmitRate;
|
props.emitRate = makingConnectionEmitRate;
|
||||||
|
props.isEmitting = false;
|
||||||
props.position = myHandPosition;
|
props.position = myHandPosition;
|
||||||
makingConnectionParticleEffect = Entities.addEntity(props, true);
|
makingConnectionParticleEffect = Entities.addEntity(props, true);
|
||||||
} else {
|
makingConnectionUpdateTimer = Script.setTimeout(updateMakingConnection, MAKING_CONNECTION_UPDATE_INTERVAL);
|
||||||
makingConnectionEmitRate *= 0.5;
|
|
||||||
Entities.editEntity(makingConnectionParticleEffect, {
|
|
||||||
emitRate: makingConnectionEmitRate,
|
|
||||||
position: myHandPosition,
|
|
||||||
isEmitting: true
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case STATES.MAKING_CONNECTION:
|
case STATES.MAKING_CONNECTION:
|
||||||
particleEmitRate = Math.max(50, particleEmitRate * 0.5);
|
if (makingConnectionUpdateTimer) {
|
||||||
Entities.editEntity(makingConnectionParticleEffect, {emitRate: 0, isEmitting: 0, position: myHandPosition});
|
Script.clearTimeout(makingConnectionUpdateTimer);
|
||||||
Entities.editEntity(particleEffect, {
|
makingConnectionUpdateTimer = null;
|
||||||
position: calcParticlePos(myHandPosition, otherHandPosition, otherOrientation),
|
}
|
||||||
emitRate: particleEmitRate
|
if (isMakingConnectionEmitting) {
|
||||||
});
|
Entities.editEntity(makingConnectionParticleEffect, { isEmitting: false });
|
||||||
|
isMakingConnectionEmitting = false;
|
||||||
|
}
|
||||||
|
if (!particleEffectUpdateTimer && particleEmitRate > PARTICLE_MINIMUM_EMIT_RATE) {
|
||||||
|
particleEffectUpdateTimer = Script.setTimeout(updateParticleEffect, PARTICLE_EFFECT_UPDATE_INTERVAL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debug("unexpected state", state);
|
debug("unexpected state", state);
|
||||||
|
|
Loading…
Reference in a new issue