Last active
November 7, 2016 22:57
-
-
Save birarda/258623664a9976613f1f to your computer and use it in GitHub Desktop.
loadTestServers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// loadTestServers.js | |
// examples/utilities/diagnostics | |
// | |
// Created by Stephen Birarda on 05/08/15. | |
// Copyright 2015 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 | |
// | |
// This script is made for load testing HF servers. It connects to the HF servers and sends/receives data. | |
// Run this on an assignment-client. | |
// | |
var count = 0; | |
var yawDirection = -1; | |
var yaw = 45; | |
var yawMax = 70; | |
var yawMin = 20; | |
var vantagePoint = {x: 10, y: 0.5, z: -5}; | |
var isLocal = false; | |
// set up our EntityViewer with a position and orientation | |
var orientation = Quat.fromPitchYawRollDegrees(0, yaw, 0); | |
var ANIMATION_DATA = { | |
"url": "http://howard-stearns.github.io/models/resources/avatar/animations/walk_fwd.fbx", | |
// "url": "http://howard-stearns.github.io/models/resources/avatar/animations/walk_fwd.fbx", // alternative example | |
"startFrame": 0.0, | |
"endFrame": 300.0, | |
"timeScale": 1.0, | |
"loopFlag": true | |
}; | |
var pianoInjector = null; | |
Avatar.position = vantagePoint; | |
Avatar.orientation = orientation; | |
Avatar.skeletonModelURL = "http://howard-stearns.github.io/models/resources/meshes/defaultAvatar_full.fst" | |
Agent.isAvatar = true; | |
Avatar.startAnimation(ANIMATION_DATA.url, 30, 1.0, ANIMATION_DATA.loopFlag, false, ANIMATION_DATA.startFrame, ANIMATION_DATA.endFrame); | |
function getRandomInt(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
function randFloat(low, high) { | |
return low + Math.random() * (high - low); | |
} | |
function keepLooking(deltaTime) { | |
count++; | |
if (count % getRandomInt(5, 15) == 0) { | |
yaw += yawDirection; | |
orientation = Quat.fromPitchYawRollDegrees(0, yaw, 0); | |
if (yaw > yawMax || yaw < yawMin) { | |
yawDirection = yawDirection * -1; | |
} | |
Avatar.position = { x: randFloat(5, 10), y: 0.5, z: randFloat(0, 5) - 6 }; | |
Avatar.orientation = orientation; | |
} | |
// approximately every 5s, consider stopping | |
if (count % 600 == 0) { | |
print("considering stop...."); | |
var stopProbability = 0.25; // 50% chance of stopping | |
if (Math.random() < stopProbability) { | |
print("stopping...."); | |
Script.stop(); | |
} | |
} | |
} | |
// register the call back so it fires before each data send | |
Script.update.connect(keepLooking); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment