Skip to content

Commit b5b466f

Browse files
committed
Move Random methods out of Stage class
WebKit#54 This is a step towards making Stage and its sub-classes be ES6 classes. To do this the Random methods will be moved out of Stage class. A new class Random will be added to hold the random methods as static methods. This class will be put in a separate file. A production script can be used later to merge all the JS files in a single file.
1 parent f1c7edb commit b5b466f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+198
-316
lines changed

MotionMark/developer.html

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<link rel="stylesheet" href="resources/runner/motionmark.css">
3434
<link rel="stylesheet" href="resources/debug-runner/motionmark.css">
3535

36+
<script src="extensions/random.js"></script>
3637
<script src="resources/strings.js"></script>
3738
<script src="resources/extensions.js"></script>
3839
<script src="resources/statistics.js"></script>

MotionMark/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

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

35+
<script src="extensions/random.js"></script>
3536
<script src="resources/strings.js" defer></script>
3637
<script src="resources/extensions.js" defer></script>
3738
<script src="resources/statistics.js" defer></script>

MotionMark/resources/statistics.js

-23
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,6 @@
2222
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
25-
Pseudo =
26-
{
27-
initialRandomSeed: 49734321,
28-
randomSeed: 49734321,
29-
30-
resetRandomSeed: function()
31-
{
32-
Pseudo.randomSeed = Pseudo.initialRandomSeed;
33-
},
34-
35-
random: function()
36-
{
37-
var randomSeed = Pseudo.randomSeed;
38-
randomSeed = ((randomSeed + 0x7ed55d16) + (randomSeed << 12)) & 0xffffffff;
39-
randomSeed = ((randomSeed ^ 0xc761c23c) ^ (randomSeed >>> 19)) & 0xffffffff;
40-
randomSeed = ((randomSeed + 0x165667b1) + (randomSeed << 5)) & 0xffffffff;
41-
randomSeed = ((randomSeed + 0xd3a2646c) ^ (randomSeed << 9)) & 0xffffffff;
42-
randomSeed = ((randomSeed + 0xfd7046c5) + (randomSeed << 3)) & 0xffffffff;
43-
randomSeed = ((randomSeed ^ 0xb55a4f09) ^ (randomSeed >>> 16)) & 0xffffffff;
44-
Pseudo.randomSeed = randomSeed;
45-
return (randomSeed & 0xfffffff) / 0x10000000;
46-
}
47-
};
4825

4926
Statistics =
5027
{

MotionMark/tests/3d/resources/webgl.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ WebGLStage = Utilities.createSubclass(Stage,
136136

137137
this._uniformData = new Float32Array(this._bufferSize * 6);
138138
for (var i = 0; i < this._bufferSize; ++i) {
139-
this._uniformData[i * 6 + 0] = Stage.random(0.2, 0.4);
139+
this._uniformData[i * 6 + 0] = Random.number(0.2, 0.4);
140140
this._uniformData[i * 6 + 1] = 0;
141-
this._uniformData[i * 6 + 2] = Stage.random(-0.9, 0.9);
142-
this._uniformData[i * 6 + 3] = Stage.random(-0.9, 0.9);
143-
this._uniformData[i * 6 + 4] = Stage.random(0.5, 2);
144-
this._uniformData[i * 6 + 5] = Stage.random(0, 10);
141+
this._uniformData[i * 6 + 2] = Random.number(-0.9, 0.9);
142+
this._uniformData[i * 6 + 3] = Random.number(-0.9, 0.9);
143+
this._uniformData[i * 6 + 4] = Random.number(0.5, 2);
144+
this._uniformData[i * 6 + 5] = Random.number(0, 10);
145145
}
146146
},
147147

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

165165
if (!this._startTime)
166-
this._startTime = Stage.dateCounterValue(1000);
167-
var elapsedTime = Stage.dateCounterValue(1000) - this._startTime;
166+
this._startTime = Random.dateCounterValue(1000);
167+
var elapsedTime = Random.dateCounterValue(1000) - this._startTime;
168168

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

MotionMark/tests/3d/resources/webgpu.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ WebGLStage = Utilities.createSubclass(Stage,
206206

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

215215
this._bindGroups[i] = device.createBindGroup({
216216
layout: this._bindGroupLayout,
@@ -259,9 +259,9 @@ WebGLStage = Utilities.createSubclass(Stage,
259259
const device = this._device;
260260

261261
if (!this._startTime)
262-
this._startTime = Stage.dateCounterValue(1000);
262+
this._startTime = Random.dateCounterValue(1000);
263263

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

266266
// Update time uniform
267267
let mappedBuffer;

MotionMark/tests/3d/triangles-webgl.html

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
gl_FragColor = v_color;
8484
}
8585
</script>
86+
<script src="../../extensions/random.js"></script>
8687
<script src="../../resources/strings.js"></script>
8788
<script src="../../resources/extensions.js"></script>
8889
<script src="../../resources/statistics.js"></script>

MotionMark/tests/3d/triangles-webgpu.html

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
</head>
3636
<body>
3737
<canvas id="stage"></canvas>
38+
<script src="../../extensions/random.js"></script>
3839
<script src="../../resources/strings.js"></script>
3940
<script src="../../resources/extensions.js"></script>
4041
<script src="../../resources/statistics.js"></script>

MotionMark/tests/bouncing-particles/bouncing-canvas-images.html

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<img class="hidden" src="../resources/yin-yang.svg">
3939
<img class="hidden" src="../resources/yin-yang.png">
4040
<canvas id="stage"></canvas>
41+
<script src="../../extensions/random.js"></script>
4142
<script src="../../resources/strings.js"></script>
4243
<script src="../../resources/extensions.js"></script>
4344
<script src="../../resources/statistics.js"></script>

MotionMark/tests/bouncing-particles/bouncing-canvas-shapes.html

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
</head>
3131
<body>
3232
<canvas id="stage"></canvas>
33+
<script src="../../extensions/random.js"></script>
3334
<script src="../../resources/strings.js"></script>
3435
<script src="../../resources/extensions.js"></script>
3536
<script src="../../resources/statistics.js"></script>

MotionMark/tests/bouncing-particles/bouncing-css-images.html

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
</head>
3636
<body>
3737
<div id="stage"></div>
38+
<script src="../../extensions/random.js"></script>
3839
<script src="../../resources/strings.js"></script>
3940
<script src="../../resources/extensions.js"></script>
4041
<script src="../../resources/statistics.js"></script>

MotionMark/tests/bouncing-particles/bouncing-css-shapes.html

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
</head>
4747
<body>
4848
<div id="stage"></div>
49+
<script src="../../extensions/random.js"></script>
4950
<script src="../../resources/strings.js"></script>
5051
<script src="../../resources/extensions.js"></script>
5152
<script src="../../resources/statistics.js"></script>

MotionMark/tests/bouncing-particles/bouncing-svg-images.html

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
</head>
3131
<body>
3232
<svg id="stage"></svg>
33+
<script src="../../extensions/random.js"></script>
3334
<script src="../../resources/strings.js"></script>
3435
<script src="../../resources/extensions.js"></script>
3536
<script src="../../resources/statistics.js"></script>

MotionMark/tests/bouncing-particles/bouncing-svg-shapes.html

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
</head>
3131
<body>
3232
<svg id="stage"></svg>
33+
<script src="../../extensions/random.js"></script>
3334
<script src="../../resources/strings.js"></script>
3435
<script src="../../resources/extensions.js"></script>
3536
<script src="../../resources/statistics.js"></script>

MotionMark/tests/bouncing-particles/bouncing-tagged-images.html

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
</style>
3333
<link rel="stylesheet" type="text/css" href="../resources/stage.css">
3434

35+
<script src="../../extensions/random.js"></script>
3536
<script src="../../resources/strings.js"></script>
3637
<script src="../../resources/extensions.js"></script>
3738
<script src="../../resources/statistics.js"></script>

MotionMark/tests/bouncing-particles/resources/bouncing-canvas-particles.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ BouncingCanvasParticle = Utilities.createSubclass(BouncingParticle,
3737
return;
3838

3939
this.context.translate(this.size.x / 2, this.size.y / 2);
40-
this.context.rotate(this.rotater.degree() * Math.PI / 180);
40+
this.context.rotate(this.rotator.degree() * Math.PI / 180);
4141
this.context.translate(-this.size.x / 2, -this.size.y / 2);
4242
},
4343

MotionMark/tests/bouncing-particles/resources/bouncing-canvas-shapes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ BouncingCanvasShape = Utilities.createSubclass(BouncingCanvasParticle,
2929
{
3030
BouncingCanvasParticle.call(this, stage, stage.shape);
3131
this._fill = stage.fill;
32-
this._color0 = Stage.randomColor();
33-
this._color1 = Stage.randomColor();
32+
this._color0 = Random.color();
33+
this._color1 = Random.color();
3434
}, {
3535

3636
_applyFill: function()

MotionMark/tests/bouncing-particles/resources/bouncing-css-images.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ BouncingCssImage = Utilities.createSubclass(BouncingParticle,
4040

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

4646
animate: function(timeDelta)

MotionMark/tests/bouncing-particles/resources/bouncing-css-shapes.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ BouncingCssShape = Utilities.createSubclass(BouncingParticle,
3434
switch (stage.fill) {
3535
case "solid":
3636
default:
37-
this.element.style.backgroundColor = Stage.randomColor();
37+
this.element.style.backgroundColor = Random.color();
3838
break;
3939

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

4545
if (stage.blend)
46-
this.element.style.mixBlendMode = Stage.randomStyleMixBlendMode();
46+
this.element.style.mixBlendMode = Random.styleMixBlendMode();
4747

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

5252
this._move();
5353
}, {
@@ -64,13 +64,13 @@ BouncingCssShape = Utilities.createSubclass(BouncingParticle,
6464

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

7070
animate: function(timeDelta)
7171
{
7272
BouncingParticle.prototype.animate.call(this, timeDelta);
73-
this.rotater.next(timeDelta);
73+
this.rotator.next(timeDelta);
7474
this._move();
7575
}
7676
});

MotionMark/tests/bouncing-particles/resources/bouncing-particles.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ function BouncingParticle(stage)
2727
this._stageSize = stage.size;
2828
this.size = stage.particleSize;
2929

30-
this.position = Stage.randomPosition(stage.size.subtract(stage.particleSize));
31-
this._angle = Stage.randomAngle();
32-
this._velocity = Stage.randomVelocity(stage.maxVelocity);
33-
this.rotater = Stage.randomRotater();
30+
this.position = Random.position(stage.size.subtract(stage.particleSize));
31+
this._angle = Random.angle();
32+
this._velocity = Random.velocity(stage.maxVelocity);
33+
this.rotator = Random.rotator();
3434
}
3535

3636
BouncingParticle.prototype =
@@ -43,7 +43,7 @@ BouncingParticle.prototype =
4343
animate: function(timeDelta)
4444
{
4545
this.position = this.position.move(this._angle, this._velocity, timeDelta);
46-
this.rotater.next(timeDelta);
46+
this.rotator.next(timeDelta);
4747

4848
// If particle is going to move off right side
4949
if (this.position.x + this.size.x > this._stageSize.x) {

MotionMark/tests/bouncing-particles/resources/bouncing-svg-particles.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ BouncingSvgParticle = Utilities.createSubclass(BouncingParticle,
4242
{
4343
var transform = "translate(" + this.position.x + ", " + this.position.y + ")";
4444
if (this._shape != "circle")
45-
transform += this.rotater.rotate(this.size.center);
45+
transform += this.rotator.rotate(this.size.center);
4646
this.element.setAttribute("transform", transform);
4747
},
4848

MotionMark/tests/bouncing-particles/resources/bouncing-svg-shapes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ BouncingSvgShape = Utilities.createSubclass(BouncingSvgParticle,
6363

6464
case "solid":
6565
default:
66-
this.element.setAttribute("fill", Stage.randomColor());
66+
this.element.setAttribute("fill", Random.color());
6767
break;
6868
}
6969
}
@@ -88,7 +88,7 @@ BouncingSvgShapesStage = Utilities.createSubclass(BouncingSvgParticlesStage,
8888
var gradient = Utilities.createSVGElement("linearGradient", attrs, {}, this._ensureDefsIsCreated());
8989

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

MotionMark/tests/bouncing-particles/resources/bouncing-tagged-images.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ BouncingTaggedImage = Utilities.createSubclass(BouncingParticle,
3232
this.element = document.createElement("img");
3333
this.element.style.width = this.size.x + "px";
3434
this.element.style.height = this.size.y + "px";
35-
this.element.setAttribute("src", Stage.randomElementInArray(stage.images).src);
35+
this.element.setAttribute("src", Random.itemInArray(stage.images).src);
3636

3737
stage.element.appendChild(this.element);
3838
this._move();
3939
}, {
4040

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

4646
animate: function(timeDelta)

MotionMark/tests/core/canvas-stage.html

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
</head>
3131
<body>
3232
<canvas id="stage"></canvas>
33+
<script src="../../extensions/random.js"></script>
3334
<script src="../../resources/strings.js"></script>
3435
<script src="../../resources/extensions.js"></script>
3536
<script src="../../resources/statistics.js"></script>

MotionMark/tests/core/design.html

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
</table>
9898
</div>
9999
</div>
100+
<script src="../../extensions/random.js"></script>
100101
<script src="../../resources/strings.js"></script>
101102
<script src="../../resources/extensions.js"></script>
102103
<script src="../../resources/statistics.js"></script>

MotionMark/tests/core/image-data.html

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
</head>
4343
<body>
4444
<div id="stage"></div>
45+
<script src="../../extensions/random.js"></script>
4546
<script src="../../resources/strings.js"></script>
4647
<script src="../../resources/extensions.js"></script>
4748
<script src="../../resources/statistics.js"></script>

MotionMark/tests/core/leaves.html

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
</head>
3939
<body>
4040
<div id="stage"></div>
41+
<script src="../../extensions/random.js"></script>
4142
<script src="../../resources/strings.js"></script>
4243
<script src="../../resources/extensions.js"></script>
4344
<script src="../../resources/statistics.js"></script>

MotionMark/tests/core/multiply.html

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<body>
6868
<div id="stage">
6969
</div>
70+
<script src="../../extensions/random.js"></script>
7071
<script src="../../resources/strings.js"></script>
7172
<script src="../../resources/extensions.js"></script>
7273
<script src="../../resources/statistics.js"></script>

MotionMark/tests/core/resources/canvas-stage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ SimpleCanvasStage = Utilities.createSubclass(Stage,
5353
newIndex = -newIndex;
5454
for (var i = 0; i < newIndex; ++i) {
5555
if (this._canvasObject.constructor === Array)
56-
this.objects.push(new (Stage.randomElementInArray(this._canvasObject))(this));
56+
this.objects.push(new (Random.itemInArray(this._canvasObject))(this));
5757
else
5858
this.objects.push(new this._canvasObject(this));
5959
}

0 commit comments

Comments
 (0)