add 'dynamic' property as a load

This commit is contained in:
Howard Stearns 2016-07-06 16:15:02 -07:00
parent 8ef9f48221
commit 74ef82f800

View file

@ -40,7 +40,9 @@ var numberLeftRunning = scriptData.length - otherScripts.length;
print('initially running', otherScripts.length, 'scripts. Leaving', numberLeftRunning, 'and stopping', otherScripts); print('initially running', otherScripts.length, 'scripts. Leaving', numberLeftRunning, 'and stopping', otherScripts);
var typedEntities = {Light: [], ParticleEffect: []}; var typedEntities = {Light: [], ParticleEffect: []};
var interestingTypes = Object.keys(typedEntities); var interestingTypes = Object.keys(typedEntities);
var loads = ['ignore', 'baseline'].concat(otherScripts, interestingTypes); var propertiedEntities = {dynamic: []};
var interestingProperties = Object.keys(propertiedEntities);
var loads = ['ignore', 'baseline'].concat(otherScripts, interestingTypes, interestingProperties);
var loadIndex = 0, nLoads = loads.length, load; var loadIndex = 0, nLoads = loads.length, load;
var results = []; var results = [];
var initialLodIsAutomatic = LODManager.getAutomaticLODAdjust(); var initialLodIsAutomatic = LODManager.getAutomaticLODAdjust();
@ -51,21 +53,42 @@ LODManager.setOctreeSizeScale(DEFAULT_LOD);
// Fill the typedEnties with the entityIDs that are already visible. It would be nice if this were more efficient. // Fill the typedEnties with the entityIDs that are already visible. It would be nice if this were more efficient.
var allEntities = Entities.findEntities(MyAvatar.position, SEARCH_RADIUS); var allEntities = Entities.findEntities(MyAvatar.position, SEARCH_RADIUS);
print('Searching', allEntities.length, 'entities for', interestingTypes); print('Searching', allEntities.length, 'entities for', interestingTypes, 'and', interestingProperties);
var propertiesToGet = ['type', 'visible'].concat(interestingProperties);
allEntities.forEach(function (entityID) { allEntities.forEach(function (entityID) {
var properties = Entities.getEntityProperties(entityID, ['type', 'visible']); var properties = Entities.getEntityProperties(entityID, propertiesToGet);
if (properties.visible && (interestingTypes.indexOf(properties.type) >= 0)) { if (properties.visible) {
typedEntities[properties.type].push(entityID); if (interestingTypes.indexOf(properties.type) >= 0) {
typedEntities[properties.type].push(entityID);
} else {
interestingProperties.forEach(function (property) {
if (entityID && properties[property]) {
propertiedEntities[property].push(entityID);
entityID = false; // Put in only one bin
}
});
}
} }
}); });
allEntities = undefined; // free them
interestingTypes.forEach(function (type) { interestingTypes.forEach(function (type) {
print('There are', typedEntities[type].length, type, 'entities.'); print('There are', typedEntities[type].length, type, 'entities.');
}); });
interestingProperties.forEach(function (property) {
print('There are', propertiedEntities[property].length, property, 'entities.');
});
function toggleVisibility(type, on) { function toggleVisibility(type, on) {
typedEntities[type].forEach(function (entityID) { typedEntities[type].forEach(function (entityID) {
Entities.editEntity(entityID, {visible: on}); Entities.editEntity(entityID, {visible: on});
}); });
} }
function toggleProperty(property, on) {
propertiedEntities[property].forEach(function (entityID) {
var properties = {};
properties[property] = on;
Entities.editEntity(entityID, properties);
});
}
function restoreOneTest(load) { function restoreOneTest(load) {
print('restore', load); print('restore', load);
switch (load) { switch (load) {
@ -76,6 +99,9 @@ function restoreOneTest(load) {
case 'ParticleEffect': case 'ParticleEffect':
toggleVisibility(load, true); toggleVisibility(load, true);
break; break;
case 'dynamic':
toggleProperty(load, 1);
break;
default: default:
Script.load(load); Script.load(load);
} }
@ -90,6 +116,9 @@ function undoOneTest(load) {
case 'ParticleEffect': case 'ParticleEffect':
toggleVisibility(load, false); toggleVisibility(load, false);
break; break;
case 'dynamic':
toggleProperty(load, 0);
break;
default: default:
ScriptDiscoveryService.stopScript(load); ScriptDiscoveryService.stopScript(load);
} }