Skip to content

Commit a710060

Browse files
greggmanphemavax
authored andcommitted
add numFish query parameter
1 parent 368355b commit a710060

File tree

2 files changed

+54
-29
lines changed

2 files changed

+54
-29
lines changed

aquarium/README.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ <h2>Controls</h2>
2929
<li>Press SPACE to change the view.</li>
3030
<li>Press L for sharks with frikken lasers. Looks best from an outside view.</li>
3131
</ul>
32+
<h2>Options</h2>
33+
<ul>
34+
<li>
35+
<h3>numFish</h3>
36+
<p>set the number of fish</p>
37+
<pre>
38+
<a href="aquarium.html?numFish=1234">https://webglsamples.github.io/aquarium/aquarium.html?numFish=1234</a>
39+
</pre>
40+
</li>
41+
</ul>
3242
<h2>Running across multiple machines</h2>
3343
<p>The Aquarium demo can by run synchronized across multiple machines.</p>
3444

aquarium/aquarium.js

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use strict";
2+
13
tdl.require('tdl.buffers');
24
tdl.require('tdl.clock');
35
tdl.require('tdl.fast');
@@ -14,6 +16,7 @@ tdl.require('tdl.textures');
1416
tdl.require('tdl.webgl');
1517

1618
// globals
19+
const g_query = parseQueryString(window.location.search);
1720
var gl; // the gl context.
1821
var canvas; // the canvas
1922
var math; // the math lib.
@@ -30,6 +33,7 @@ var g_scenes = {}; // each of the models
3033
var g_sceneGroups = {}; // the placement of the models
3134
var g_fog = true;
3235
var g_requestId;
36+
var g_numFish = [1, 100, 500, 1000, 5000, 10000, 15000, 20000, 25000, 30000];
3337

3438
// added for benchmarking stuff
3539
var benchmarkMessageStarting = "Benchmark starts in: ";
@@ -62,7 +66,6 @@ var featureFlags = "featureFlags";
6266
//g_debug = true;
6367
//g_drawOnce = true;
6468

65-
var g_numSharks = 0;
6669
var g_tailOffsetMult = 1;
6770
var g_endOfDome = Math.PI / 8;
6871
var g_tankRadius = 74;
@@ -380,6 +383,15 @@ var g_skyBoxUrls = [
380383
// 'static_assets/skybox/InteriorCubeEnv_EM.png'
381384
]
382385

386+
function parseQueryString(s) {
387+
const q = {};
388+
(s.startsWith('?') ? s.substring(1) : s).split('&').forEach(pair => {
389+
const parts = pair.split('=').map(decodeURIComponent);
390+
q[parts[0]] = parts[1];
391+
});
392+
return q;
393+
}
394+
383395
function ValidateNoneOfTheArgsAreUndefined(functionName, args) {
384396
for (var ii = 0; ii < args.length; ++ii) {
385397
if (args[ii] === undefined) {
@@ -950,7 +962,10 @@ function handleContextRestored() {
950962
}
951963

952964
function initialize() {
953-
var maxViewportDims = gl.getParameter(gl.MAX_VIEWPORT_DIMS);
965+
const maxViewportDims = gl.getParameter(gl.MAX_VIEWPORT_DIMS);
966+
if (g_query.numFish) {
967+
g_numFish[0] = parseInt(g_query.numFish);
968+
}
954969

955970
gl.enable(gl.DEPTH_TEST);
956971
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
@@ -962,49 +977,47 @@ function initialize() {
962977
Log("--Setup Laser----------------------------------------");
963978
var laser = setupLaser();
964979

965-
var num = [1, 100, 500, 1000, 5000, 10000, 15000, 20000, 25000, 30000];
966980
var changeViewElem = document.getElementById("setSettingChangeView");
967981
var parentElem = changeViewElem.parentNode;
968-
for (var i = 0; i < num.length; ++i) {
982+
g_numFish.forEach((numFish, ndx) => {
969983
var div = document.createElement("div");
970984
div.className = "clickable";
971-
div.id = "setSetting" + i;
972-
div.innerHTML = num[i];
985+
div.id = "setSetting" + ndx;
986+
div.innerHTML = numFish;
973987
parentElem.insertBefore(div, changeViewElem);
974-
}
988+
});
975989

976-
for (var ff = 0; ff < g_fishTable.length; ++ff) {
977-
g_fishTable[ff].fishData = [];
978-
g_fishTable[ff].num = [];
979-
}
990+
g_fishTable.forEach(info => {
991+
info.fishData = [];
992+
info.num = [];
993+
});
980994

981-
var type = ["Big", "Medium", "Small"];
982-
for (var i = 0; i < num.length; ++i) {
983-
var numLeft = num[i];
984-
for (var j = 0; j < type.length; ++j) {
985-
for (var ff = 0; ff < g_fishTable.length; ++ff) {
986-
var fishInfo = g_fishTable[ff];
995+
var types = ["Big", "Medium", "Small"];
996+
g_numFish.forEach((totalFish) => {
997+
var numLeft = totalFish;
998+
types.forEach((type) => {
999+
g_fishTable.forEach((fishInfo) => {
9871000
var fishName = fishInfo.name;
988-
if (!fishName.startsWith(type[j])) {
989-
continue;
1001+
if (!fishName.startsWith(type)) {
1002+
return;
9901003
}
9911004
var numType = numLeft;
992-
if (type[j] == "Big") {
993-
numType = Math.min(numLeft, num[i] < 100 ? 1 : 2);
994-
} else if (type[j] == "Medium") {
995-
if (num[i] < 1000) {
996-
numType = Math.min(numLeft, num[i] / 10 | 0);
997-
} else if (num[i] < 10000) {
1005+
if (type == "Big") {
1006+
numType = Math.min(numLeft, totalFish < 100 ? 1 : 2);
1007+
} else if (type == "Medium") {
1008+
if (totalFish < 1000) {
1009+
numType = Math.min(numLeft, totalFish / 10 | 0);
1010+
} else if (totalFish < 10000) {
9981011
numType = Math.min(numLeft, 80);
9991012
} else {
10001013
numType = Math.min(numLeft, 160);
10011014
}
10021015
}
10031016
numLeft = numLeft - numType;
10041017
fishInfo.num.push(numType);
1005-
}
1006-
}
1007-
}
1018+
});
1019+
})
1020+
});
10081021

10091022
var particleSystem = new tdl.particles.ParticleSystem(
10101023
gl, null, math.pseudoRandom);
@@ -1806,7 +1819,9 @@ function setupCountButtons() {
18061819
}}(elem, ii);
18071820
}
18081821

1809-
if (g.net.sync) {
1822+
if (g_query.numFish) {
1823+
setSetting(document.getElementById("setSetting0"), 0);
1824+
} else if (g.net.sync) {
18101825
setSetting(document.getElementById("setSetting4"), 4);
18111826
} else {
18121827
setSetting(document.getElementById("setSetting2"), 2);

0 commit comments

Comments
 (0)