mirror of
https://github.com/overte-org/overte.git
synced 2025-04-16 13:56:24 +02:00
Merge pull request #6980 from howard-stearns/performance-stats-repro-scripts
Performance stats repro scripts
This commit is contained in:
commit
9361c1655e
5 changed files with 201 additions and 21 deletions
37
examples/entityScripts/simpleKeepAway.js
Normal file
37
examples/entityScripts/simpleKeepAway.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
(function () {
|
||||
// The attached entity will move away from you if you are too close, checking at distanceRate.
|
||||
// See tests/performance/simpleKeepAway.js
|
||||
var entityID,
|
||||
distanceRate = 1, // hertz
|
||||
distanceAllowance = 3, // meters
|
||||
distanceScale = 0.5, // meters/second
|
||||
distanceTimer;
|
||||
|
||||
function moveDistance() { // every user checks their distance and tries to claim if close enough.
|
||||
var me = MyAvatar.position,
|
||||
ball = Entities.getEntityProperties(entityID, ['position']).position;
|
||||
ball.y = me.y;
|
||||
var vector = Vec3.subtract(ball, me);
|
||||
|
||||
if (Vec3.length(vector) < distanceAllowance) {
|
||||
Entities.editEntity(entityID, {velocity: Vec3.multiply(distanceScale, Vec3.normalize(vector))});
|
||||
}
|
||||
}
|
||||
|
||||
this.preload = function (givenEntityID) {
|
||||
var properties = Entities.getEntityProperties(givenEntityID, ['userData']),
|
||||
userData = properties.userData && JSON.parse(properties.userData);
|
||||
entityID = givenEntityID;
|
||||
if (userData) {
|
||||
distanceRate = userData.distanceRate || distanceRate;
|
||||
distanceAllowance = userData.distanceAllowance || distanceAllowance;
|
||||
distanceScale = userData.distanceScale || distanceScale;
|
||||
}
|
||||
|
||||
// run all the time by everyone:
|
||||
distanceTimer = Script.setInterval(moveDistance, distanceRate);
|
||||
};
|
||||
this.unload = function () {
|
||||
Script.clearTimeout(distanceTimer);
|
||||
};
|
||||
})
|
|
@ -11,25 +11,56 @@ var Entities, Script, print, Vec3, MyAvatar, Camera, Quat;
|
|||
// Creates a rectangular matrix of objects with no physical or entity changes after creation.
|
||||
// Useful for testing the rendering, LOD, and octree storage aspects of the system.
|
||||
//
|
||||
// NOTE: to test the full rendering of the specified number of objects (as opposed to
|
||||
// testing LOD filtering), you may want to set LOD to manual maximum visibility.
|
||||
|
||||
var LIFETIME = 60;
|
||||
var LIFETIME = 20;
|
||||
var ROWS_X = 17;
|
||||
var ROWS_Y = 10;
|
||||
var ROWS_Z = 10;
|
||||
// Entities will be populated from this list set by the script writer for different tests.
|
||||
var TYPES_TO_USE = ['Box', 'Sphere'];
|
||||
switch ('primitives') { // Quickly override the above by putting here one of the following case strings.
|
||||
case 'particles':
|
||||
TYPES_TO_USE = ['ParticleEffect'];
|
||||
ROWS_X = ROWS_Z = 6;
|
||||
break;
|
||||
case 'lights':
|
||||
TYPES_TO_USE = ['Light'];
|
||||
ROWS_X = ROWS_Y = ROWS_Z = 5;
|
||||
break;
|
||||
case 'blocks': // 376 triangles/entity
|
||||
TYPES_TO_USE = ["http://s3.amazonaws.com/hifi-public/marketplace/hificontent/Games/blocks/block.fbx"];
|
||||
ROWS_X = ROWS_Y = ROWS_Z = 10;
|
||||
break;
|
||||
case 'ramp': // 1,002 triangles/entity
|
||||
TYPES_TO_USE = ["http://headache.hungry.com/~seth/hifi/curved-ramp.obj"];
|
||||
ROWS_X = ROWS_Y = 10;
|
||||
ROWS_Z = 9;
|
||||
break;
|
||||
case 'gun': // 2.1k triangles/entity
|
||||
TYPES_TO_USE = ["https://hifi-content.s3.amazonaws.com/ozan/dev/props/guns/nail_gun/nail_gun.fbx"];
|
||||
ROWS_X = ROWS_Y = 10;
|
||||
ROWS_Z = 7;
|
||||
break;
|
||||
case 'trees': // 12k triangles/entity
|
||||
TYPES_TO_USE = ["https://hifi-content.s3.amazonaws.com/ozan/dev/sets/lowpoly_island/CypressTreeGroup.fbx"];
|
||||
ROWS_X = ROWS_Z = 6;
|
||||
ROWS_Y = 1;
|
||||
break;
|
||||
case 'web':
|
||||
TYPES_TO_USE = ['Web'];
|
||||
ROWS_X = ROWS_Z = 5;
|
||||
ROWS_Y = 3;
|
||||
break;
|
||||
default:
|
||||
// Just using values from above.
|
||||
}
|
||||
// Matrix will be axis-aligned, approximately all in this field of view.
|
||||
// As special case, if zero, grid is centered above your head.
|
||||
var MINIMUM_VIEW_ANGLE_IN_RADIANS = 30 * Math.PI / 180; // 30 degrees
|
||||
var ROWS_X = 10;
|
||||
var ROWS_Y = 10;
|
||||
var ROWS_Z = 10;
|
||||
var SEPARATION = 10;
|
||||
var SIZE = 1;
|
||||
var TYPES_TO_USE = [ // Entities will be populated from this list set by the script writer for different tests.
|
||||
'Box',
|
||||
'Sphere',
|
||||
//'Light',
|
||||
//'ParticleEffect',
|
||||
//'Web',
|
||||
//"https://hifi-content.s3.amazonaws.com/ozan/dev/sets/lowpoly_island/CypressTreeGroup.fbx",
|
||||
//"http://s3.amazonaws.com/hifi-public/marketplace/hificontent/Games/blocks/block.fbx",
|
||||
];
|
||||
var MODEL_SCALE = { x: 1, y: 2, z: 3 }; // how to stretch out models proportionally to SIZE
|
||||
// Note that when creating things quickly, the entity server will ignore data if we send updates too quickly.
|
||||
// like Internet MTU, these rates are set by th domain operator, so in this script there is a RATE_PER_SECOND
|
||||
|
@ -55,7 +86,9 @@ var o = Vec3.sum(MyAvatar.position,
|
|||
var totalCreated = 0;
|
||||
var startTime = new Date();
|
||||
var totalToCreate = ROWS_X * ROWS_Y * ROWS_Z;
|
||||
print("Creating " + totalToCreate + " entities starting at " + startTime);
|
||||
print("Creating " + totalToCreate + " " + JSON.stringify(TYPES_TO_USE) +
|
||||
" entities extending in positive x/y/z from " + JSON.stringify(o) +
|
||||
", starting at " + startTime);
|
||||
|
||||
Script.setInterval(function () {
|
||||
if (!Entities.serversExist() || !Entities.canRez()) {
|
||||
|
|
113
examples/tests/performance/simpleKeepAway.js
Normal file
113
examples/tests/performance/simpleKeepAway.js
Normal file
|
@ -0,0 +1,113 @@
|
|||
"use strict";
|
||||
/*jslint nomen: true, plusplus: true, vars: true*/
|
||||
var Vec3, Quat, MyAvatar, Entities, Camera, Script, print;
|
||||
//
|
||||
// Created by Howard Stearns
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
// Drops a bunch of physical spheres which each run an entity script that moves away
|
||||
// from you once a second if you are within range.
|
||||
//
|
||||
// This is a test of how many physical, entity-scripted objects can be around if
|
||||
// they are mostly not doing anything -- i.e., just the basic overhead of such objects.
|
||||
// They do need a moment to settle out of active physics after being dropped, but only
|
||||
// a moment -- that's why they are in a sparse grid.
|
||||
|
||||
var USE_FLAT_FLOOR = true; // Give 'em a flat place to settle on.
|
||||
var ROWS_X = 30;
|
||||
var ROWS_Z = 30;
|
||||
var SEPARATION = 1; // meters
|
||||
var LIFETIME = 60; // seconds
|
||||
var DISTANCE_RATE = 1; // hz
|
||||
var DISTANCE_ALLOWANCE = 3; // meters. Must be this close to cause entity to move
|
||||
var DISTANCE_SCALE = 0.5; // velocity will be scale x vector from user to entity
|
||||
|
||||
var SIZE = 0.5;
|
||||
var TYPE = "Sphere";
|
||||
// Note that when creating things quickly, the entity server will ignore data if we send updates too quickly.
|
||||
// like Internet MTU, these rates are set by th domain operator, so in this script there is a RATE_PER_SECOND
|
||||
// variable letting you set this speed. If entities are missing from the grid after a relog, this number
|
||||
// being too high may be the reason.
|
||||
var RATE_PER_SECOND = 600; // The entity server will drop data if we create things too fast.
|
||||
var SCRIPT_INTERVAL = 100;
|
||||
|
||||
var GRAVITY = { x: 0, y: -9.8, z: 0 };
|
||||
var VELOCITY = { x: 0.0, y: 0.1, z: 0 };
|
||||
|
||||
var DAMPING = 0.75;
|
||||
var ANGULAR_DAMPING = 0.75;
|
||||
|
||||
var RANGE = 3;
|
||||
var HOW_FAR_UP = 2; // for uneven ground
|
||||
|
||||
var x = 0;
|
||||
var z = 0;
|
||||
var totalCreated = 0;
|
||||
var xDim = ROWS_X * SEPARATION;
|
||||
var zDim = ROWS_Z * SEPARATION;
|
||||
var totalToCreate = ROWS_X * ROWS_Z;
|
||||
var origin = Vec3.sum(MyAvatar.position, {x: xDim / -2, y: HOW_FAR_UP, z: zDim / -2});
|
||||
print("Creating " + totalToCreate + " origined on " + JSON.stringify(MyAvatar.position) +
|
||||
", starting at " + JSON.stringify(origin));
|
||||
var parameters = JSON.stringify({
|
||||
distanceRate: DISTANCE_RATE,
|
||||
distanceScale: DISTANCE_SCALE,
|
||||
distanceAllowance: DISTANCE_ALLOWANCE
|
||||
});
|
||||
|
||||
var startTime = new Date();
|
||||
if (USE_FLAT_FLOOR) {
|
||||
Entities.addEntity({
|
||||
type: 'Box',
|
||||
name: 'keepAwayFloor',
|
||||
lifetime: LIFETIME,
|
||||
collisionsWillMove: false,
|
||||
color: {red: 255, green: 0, blue: 0},
|
||||
position: Vec3.sum(origin, {x: xDim / 2, y: -1 - HOW_FAR_UP, z: zDim / 2}),
|
||||
dimensions: {x: xDim + SEPARATION, y: 0.2, z: zDim + SEPARATION}
|
||||
});
|
||||
}
|
||||
Script.setInterval(function () {
|
||||
if (!Entities.serversExist() || !Entities.canRez()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var i, properties, numToCreate = Math.min(RATE_PER_SECOND * (SCRIPT_INTERVAL / 1000.0), totalToCreate - totalCreated);
|
||||
for (i = 0; i < numToCreate; i++) {
|
||||
properties = {
|
||||
userData: parameters,
|
||||
type: TYPE,
|
||||
name: "keepAway-" + totalCreated,
|
||||
position: {
|
||||
x: origin.x + SIZE + (x * SEPARATION),
|
||||
y: origin.y,
|
||||
z: origin.z + SIZE + (z * SEPARATION)
|
||||
},
|
||||
dimensions: {x: SIZE, y: SIZE, z: SIZE},
|
||||
color: {red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255},
|
||||
velocity: VELOCITY,
|
||||
damping: DAMPING,
|
||||
angularDamping: ANGULAR_DAMPING,
|
||||
gravity: GRAVITY,
|
||||
collisionsWillMove: true,
|
||||
lifetime: LIFETIME,
|
||||
script: Script.resolvePath("../../entityScripts/simpleKeepAway.js")
|
||||
};
|
||||
Entities.addEntity(properties);
|
||||
totalCreated++;
|
||||
|
||||
x++;
|
||||
if (x === ROWS_X) {
|
||||
x = 0;
|
||||
z++;
|
||||
print("Created: " + totalCreated);
|
||||
}
|
||||
if (z === ROWS_Z) {
|
||||
print("Total: " + totalCreated + " entities in " + ((new Date() - startTime) / 1000.0) + " seconds.");
|
||||
Script.stop();
|
||||
}
|
||||
}
|
||||
}, SCRIPT_INTERVAL);
|
|
@ -13,9 +13,8 @@ var Entities, Script, print, Vec3, MyAvatar;
|
|||
// so that you can measure how many edits can be made.
|
||||
//
|
||||
var LIFETIME = 15;
|
||||
var EDIT_FREQUENCY_TARGET = 60; // hertz
|
||||
var ROWS_X = 10;
|
||||
var ROWS_Y = 1;
|
||||
var ROWS_Y = 2;
|
||||
var ROWS_Z = 10;
|
||||
var SEPARATION = 10.0;
|
||||
var SIZE = 1.0;
|
||||
|
@ -88,7 +87,7 @@ var creator = Script.setInterval(function () {
|
|||
if (z === ROWS_Z) {
|
||||
print("Total: " + totalCreated + " entities in " + ((new Date() - startTime) / 1000.0) + " seconds.");
|
||||
Script.clearTimeout(creator);
|
||||
flasher = Script.setInterval(doFlash, Math.ceil((1 / EDIT_FREQUENCY_TARGET) * 1000));
|
||||
flasher = Script.setInterval(doFlash, 1000 / 60); // I.e., spin as fast as we have time for.
|
||||
Script.setTimeout(stopFlash, LIFETIME * 1000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ var Vec3, Quat, MyAvatar, Entities, Camera, Script, print;
|
|||
// The _TIMEOUT parameters can be 0 for no activity, and -1 to be active indefinitely.
|
||||
//
|
||||
|
||||
var NUMBER_TO_CREATE = 120;
|
||||
var NUMBER_TO_CREATE = 200;
|
||||
var LIFETIME = 60; // seconds
|
||||
var EDIT_RATE = 60; // hz
|
||||
var EDIT_TIMEOUT = -1;
|
||||
|
@ -41,8 +41,6 @@ var RANGE = 3;
|
|||
var HOW_FAR_IN_FRONT_OF_ME = RANGE * 3;
|
||||
var HOW_FAR_UP = RANGE / 1.5; // higher (for uneven ground) above range/2 (for distribution)
|
||||
|
||||
var x = 0;
|
||||
var z = 0;
|
||||
var totalCreated = 0;
|
||||
var offset = Vec3.sum(Vec3.multiply(HOW_FAR_UP, Vec3.UNIT_Y),
|
||||
Vec3.multiply(HOW_FAR_IN_FRONT_OF_ME, Quat.getFront(Camera.orientation)));
|
||||
|
@ -87,7 +85,7 @@ Script.setInterval(function () {
|
|||
gravity: GRAVITY,
|
||||
collisionsWillMove: true,
|
||||
lifetime: LIFETIME,
|
||||
script: "https://s3.amazonaws.com/hifi-public/scripts/entityScripts/tribble.js"
|
||||
script: Script.resolvePath("../../entityScripts/tribble.js")
|
||||
});
|
||||
|
||||
totalCreated++;
|
||||
|
|
Loading…
Reference in a new issue