Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Random methods out of Stage class #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MotionMark/developer.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<link rel="stylesheet" href="resources/runner/motionmark.css">
<link rel="stylesheet" href="resources/debug-runner/motionmark.css">

<script src="extensions/random.js"></script>
<script src="resources/strings.js"></script>
<script src="resources/extensions.js"></script>
<script src="resources/statistics.js"></script>
Expand Down
1 change: 1 addition & 0 deletions MotionMark/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<link rel="stylesheet" href="resources/runner/motionmark.css">

<script src="extensions/random.js"></script>
<script src="resources/strings.js" defer></script>
<script src="resources/extensions.js" defer></script>
<script src="resources/statistics.js" defer></script>
Expand Down
23 changes: 0 additions & 23 deletions MotionMark/resources/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,6 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
Pseudo =
{
initialRandomSeed: 49734321,
randomSeed: 49734321,

resetRandomSeed: function()
{
Pseudo.randomSeed = Pseudo.initialRandomSeed;
},

random: function()
{
var randomSeed = Pseudo.randomSeed;
randomSeed = ((randomSeed + 0x7ed55d16) + (randomSeed << 12)) & 0xffffffff;
randomSeed = ((randomSeed ^ 0xc761c23c) ^ (randomSeed >>> 19)) & 0xffffffff;
randomSeed = ((randomSeed + 0x165667b1) + (randomSeed << 5)) & 0xffffffff;
randomSeed = ((randomSeed + 0xd3a2646c) ^ (randomSeed << 9)) & 0xffffffff;
randomSeed = ((randomSeed + 0xfd7046c5) + (randomSeed << 3)) & 0xffffffff;
randomSeed = ((randomSeed ^ 0xb55a4f09) ^ (randomSeed >>> 16)) & 0xffffffff;
Pseudo.randomSeed = randomSeed;
return (randomSeed & 0xfffffff) / 0x10000000;
}
};

Statistics =
{
Expand Down
14 changes: 7 additions & 7 deletions MotionMark/tests/3d/resources/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ WebGLStage = Utilities.createSubclass(Stage,

this._uniformData = new Float32Array(this._bufferSize * 6);
for (var i = 0; i < this._bufferSize; ++i) {
this._uniformData[i * 6 + 0] = Stage.random(0.2, 0.4);
this._uniformData[i * 6 + 0] = Random.number(0.2, 0.4);
this._uniformData[i * 6 + 1] = 0;
this._uniformData[i * 6 + 2] = Stage.random(-0.9, 0.9);
this._uniformData[i * 6 + 3] = Stage.random(-0.9, 0.9);
this._uniformData[i * 6 + 4] = Stage.random(0.5, 2);
this._uniformData[i * 6 + 5] = Stage.random(0, 10);
this._uniformData[i * 6 + 2] = Random.number(-0.9, 0.9);
this._uniformData[i * 6 + 3] = Random.number(-0.9, 0.9);
this._uniformData[i * 6 + 4] = Random.number(0.5, 2);
this._uniformData[i * 6 + 5] = Random.number(0, 10);
}
},

Expand All @@ -163,8 +163,8 @@ WebGLStage = Utilities.createSubclass(Stage,
gl.clear(gl.COLOR_BUFFER_BIT);

if (!this._startTime)
this._startTime = Stage.dateCounterValue(1000);
var elapsedTime = Stage.dateCounterValue(1000) - this._startTime;
this._startTime = Random.dateCounterValue(1000);
var elapsedTime = Random.dateCounterValue(1000) - this._startTime;

for (var i = 0; i < this._numTriangles; ++i) {

Expand Down
14 changes: 7 additions & 7 deletions MotionMark/tests/3d/resources/webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ WebGLStage = Utilities.createSubclass(Stage,

this._bindGroups = new Array(numTriangles);
for (let i = 0; i < numTriangles; ++i) {
uniformWriteArray[alignedUniformFloats * i + 0] = Stage.random(0.2, 0.4); // scale
uniformWriteArray[alignedUniformFloats * i + 1] = Stage.random(-0.9, 0.9); // offsetX
uniformWriteArray[alignedUniformFloats * i + 2] = Stage.random(-0.9, 0.9); // offsetY
uniformWriteArray[alignedUniformFloats * i + 3] = Stage.random(0.5, 2); // scalar
uniformWriteArray[alignedUniformFloats * i + 4] = Stage.random(0, 10); // scalarOffset
uniformWriteArray[alignedUniformFloats * i + 0] = Random.number(0.2, 0.4); // scale
uniformWriteArray[alignedUniformFloats * i + 1] = Random.number(-0.9, 0.9); // offsetX
uniformWriteArray[alignedUniformFloats * i + 2] = Random.number(-0.9, 0.9); // offsetY
uniformWriteArray[alignedUniformFloats * i + 3] = Random.number(0.5, 2); // scalar
uniformWriteArray[alignedUniformFloats * i + 4] = Random.number(0, 10); // scalarOffset

this._bindGroups[i] = device.createBindGroup({
layout: this._bindGroupLayout,
Expand Down Expand Up @@ -259,9 +259,9 @@ WebGLStage = Utilities.createSubclass(Stage,
const device = this._device;

if (!this._startTime)
this._startTime = Stage.dateCounterValue(1000);
this._startTime = Random.dateCounterValue(1000);

const elapsedTimeData = new Float32Array([Stage.dateCounterValue(1000) - this._startTime]);
const elapsedTimeData = new Float32Array([Random.dateCounterValue(1000) - this._startTime]);

// Update time uniform
let mappedBuffer;
Expand Down
1 change: 1 addition & 0 deletions MotionMark/tests/3d/triangles-webgl.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
gl_FragColor = v_color;
}
</script>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
1 change: 1 addition & 0 deletions MotionMark/tests/3d/triangles-webgpu.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
</head>
<body>
<canvas id="stage"></canvas>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<img class="hidden" src="../resources/yin-yang.svg">
<img class="hidden" src="../resources/yin-yang.png">
<canvas id="stage"></canvas>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</head>
<body>
<canvas id="stage"></canvas>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
</head>
<body>
<div id="stage"></div>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
</head>
<body>
<div id="stage"></div>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</head>
<body>
<svg id="stage"></svg>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</head>
<body>
<svg id="stage"></svg>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
</style>
<link rel="stylesheet" type="text/css" href="../resources/stage.css">

<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ BouncingCanvasParticle = Utilities.createSubclass(BouncingParticle,
return;

this.context.translate(this.size.x / 2, this.size.y / 2);
this.context.rotate(this.rotater.degree() * Math.PI / 180);
this.context.rotate(this.rotator.degree() * Math.PI / 180);
this.context.translate(-this.size.x / 2, -this.size.y / 2);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ BouncingCanvasShape = Utilities.createSubclass(BouncingCanvasParticle,
{
BouncingCanvasParticle.call(this, stage, stage.shape);
this._fill = stage.fill;
this._color0 = Stage.randomColor();
this._color1 = Stage.randomColor();
this._color0 = Random.color();
this._color1 = Random.color();
}, {

_applyFill: function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ BouncingCssImage = Utilities.createSubclass(BouncingParticle,

_move: function()
{
this.element.style.transform = "translate(" + this.position.x + "px," + this.position.y + "px) " + this.rotater.rotateZ();
this.element.style.transform = "translate(" + this.position.x + "px," + this.position.y + "px) " + this.rotator.rotateZ();
},

animate: function(timeDelta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ BouncingCssShape = Utilities.createSubclass(BouncingParticle,
switch (stage.fill) {
case "solid":
default:
this.element.style.backgroundColor = Stage.randomColor();
this.element.style.backgroundColor = Random.color();
break;

case "gradient":
this.element.style.background = "linear-gradient(" + Stage.randomColor() + ", " + Stage.randomColor() + ")";
this.element.style.background = "linear-gradient(" + Random.color() + ", " + Random.color() + ")";
break;
}

if (stage.blend)
this.element.style.mixBlendMode = Stage.randomStyleMixBlendMode();
this.element.style.mixBlendMode = Random.styleMixBlendMode();

// Some browsers have not un-prefixed the css filter yet.
if (stage.filter)
Utilities.setElementPrefixedProperty(this.element, "filter", Stage.randomStyleFilter());
Utilities.setElementPrefixedProperty(this.element, "filter", Random.styleFilter());

this._move();
}, {
Expand All @@ -64,13 +64,13 @@ BouncingCssShape = Utilities.createSubclass(BouncingParticle,

_move: function()
{
this.element.style.transform = "translate(" + this.position.x + "px," + this.position.y + "px)" + this.rotater.rotateZ();
this.element.style.transform = "translate(" + this.position.x + "px," + this.position.y + "px)" + this.rotator.rotateZ();
},

animate: function(timeDelta)
{
BouncingParticle.prototype.animate.call(this, timeDelta);
this.rotater.next(timeDelta);
this.rotator.next(timeDelta);
this._move();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ function BouncingParticle(stage)
this._stageSize = stage.size;
this.size = stage.particleSize;

this.position = Stage.randomPosition(stage.size.subtract(stage.particleSize));
this._angle = Stage.randomAngle();
this._velocity = Stage.randomVelocity(stage.maxVelocity);
this.rotater = Stage.randomRotater();
this.position = Random.position(stage.size.subtract(stage.particleSize));
this._angle = Random.angle();
this._velocity = Random.velocity(stage.maxVelocity);
this.rotator = Random.rotator();
}

BouncingParticle.prototype =
Expand All @@ -43,7 +43,7 @@ BouncingParticle.prototype =
animate: function(timeDelta)
{
this.position = this.position.move(this._angle, this._velocity, timeDelta);
this.rotater.next(timeDelta);
this.rotator.next(timeDelta);

// If particle is going to move off right side
if (this.position.x + this.size.x > this._stageSize.x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BouncingSvgParticle = Utilities.createSubclass(BouncingParticle,
{
var transform = "translate(" + this.position.x + ", " + this.position.y + ")";
if (this._shape != "circle")
transform += this.rotater.rotate(this.size.center);
transform += this.rotator.rotate(this.size.center);
this.element.setAttribute("transform", transform);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ BouncingSvgShape = Utilities.createSubclass(BouncingSvgParticle,

case "solid":
default:
this.element.setAttribute("fill", Stage.randomColor());
this.element.setAttribute("fill", Random.color());
break;
}
}
Expand All @@ -88,7 +88,7 @@ BouncingSvgShapesStage = Utilities.createSubclass(BouncingSvgParticlesStage,
var gradient = Utilities.createSVGElement("linearGradient", attrs, {}, this._ensureDefsIsCreated());

for (var i = 0; i < stops; ++i) {
attrs = { offset: i * 100 / (stops - 1) + "%", 'stop-color': Stage.randomColor() };
attrs = { offset: i * 100 / (stops - 1) + "%", 'stop-color': Random.color() };
Utilities.createSVGElement("stop", attrs, {}, gradient);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ BouncingTaggedImage = Utilities.createSubclass(BouncingParticle,
this.element = document.createElement("img");
this.element.style.width = this.size.x + "px";
this.element.style.height = this.size.y + "px";
this.element.setAttribute("src", Stage.randomElementInArray(stage.images).src);
this.element.setAttribute("src", Random.itemInArray(stage.images).src);

stage.element.appendChild(this.element);
this._move();
}, {

_move: function()
{
this.element.style.transform = "translate(" + this.position.x + "px," + this.position.y + "px) " + this.rotater.rotateZ();
this.element.style.transform = "translate(" + this.position.x + "px," + this.position.y + "px) " + this.rotator.rotateZ();
},

animate: function(timeDelta)
Expand Down
1 change: 1 addition & 0 deletions MotionMark/tests/core/canvas-stage.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</head>
<body>
<canvas id="stage"></canvas>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
1 change: 1 addition & 0 deletions MotionMark/tests/core/design.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
</table>
</div>
</div>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
1 change: 1 addition & 0 deletions MotionMark/tests/core/image-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
</head>
<body>
<div id="stage"></div>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
1 change: 1 addition & 0 deletions MotionMark/tests/core/leaves.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</head>
<body>
<div id="stage"></div>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
1 change: 1 addition & 0 deletions MotionMark/tests/core/multiply.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<body>
<div id="stage">
</div>
<script src="../../extensions/random.js"></script>
<script src="../../resources/strings.js"></script>
<script src="../../resources/extensions.js"></script>
<script src="../../resources/statistics.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion MotionMark/tests/core/resources/canvas-stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SimpleCanvasStage = Utilities.createSubclass(Stage,
newIndex = -newIndex;
for (var i = 0; i < newIndex; ++i) {
if (this._canvasObject.constructor === Array)
this.objects.push(new (Stage.randomElementInArray(this._canvasObject))(this));
this.objects.push(new (Random.itemInArray(this._canvasObject))(this));
else
this.objects.push(new this._canvasObject(this));
}
Expand Down
Loading