Skip to content

Commit 31ce2b0

Browse files
shaoboyangreggman
authored andcommitted
Rebase "add numFish query parameter" from aquarium
1 parent 8400f37 commit 31ce2b0

File tree

1 file changed

+45
-28
lines changed

1 file changed

+45
-28
lines changed

aquarium-vr/aquarium-vr.js

+45-28
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
var g_frameData;
3438
var g_vrDisplay;
3539

@@ -349,6 +353,15 @@ var g_skyBoxUrls = [
349353
// 'static_assets/skybox/InteriorCubeEnv_EM.png'
350354
]
351355

356+
function parseQueryString(s) {
357+
const q = {};
358+
(s.startsWith('?') ? s.substring(1) : s).split('&').forEach(pair => {
359+
const parts = pair.split('=').map(decodeURIComponent);
360+
q[parts[0]] = parts[1];
361+
});
362+
return q;
363+
}
364+
352365
function ValidateNoneOfTheArgsAreUndefined(functionName, args) {
353366
for (var ii = 0; ii < args.length; ++ii) {
354367
if (args[ii] === undefined) {
@@ -831,7 +844,10 @@ function handleContextRestored() {
831844
}
832845

833846
function initialize() {
834-
var maxViewportDims = gl.getParameter(gl.MAX_VIEWPORT_DIMS);
847+
const maxViewportDims = gl.getParameter(gl.MAX_VIEWPORT_DIMS);
848+
if (g_query.numFish) {
849+
g_numFish[0] = parseInt(g_query.numFish);
850+
}
835851

836852
gl.enable(gl.DEPTH_TEST);
837853
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
@@ -846,47 +862,46 @@ function initialize() {
846862
var num = [1, 100, 500, 1000, 5000, 10000, 15000, 20000, 25000, 30000];
847863
var changeViewElem = document.getElementById("setSettingChangeView");
848864
var parentElem = changeViewElem.parentNode;
849-
for (var i = 0; i < num.length; ++i) {
865+
g_numFish.forEach((numFish, ndx) => {
850866
var div = document.createElement("div");
851867
div.className = "clickable";
852-
div.id = "setSetting" + i;
853-
div.innerHTML = num[i];
868+
div.id = "setSetting" + ndx;
869+
div.innerHTML = numFish;
854870
parentElem.insertBefore(div, changeViewElem);
855-
}
871+
});
856872

857-
for (var ff = 0; ff < g_fishTable.length; ++ff) {
858-
g_fishTable[ff].fishData = [];
859-
g_fishTable[ff].num = [];
860-
}
873+
g_fishTable.forEach(info => {
874+
info.fishData = [];
875+
info.num = [];
876+
});
861877

862-
var type = ["Big", "Medium", "Small"];
863-
for (var i = 0; i < num.length; ++i) {
864-
var numLeft = num[i];
865-
for (var j = 0; j < type.length; ++j) {
866-
for (var ff = 0; ff < g_fishTable.length; ++ff) {
867-
var fishInfo = g_fishTable[ff];
878+
var types = ["Big", "Medium", "Small"];
879+
g_numFish.forEach((totalFish) => {
880+
var numLeft = totalFish;
881+
types.forEach((type) => {
882+
g_fishTable.forEach((fishInfo) => {
868883
var fishName = fishInfo.name;
869-
if (!fishName.startsWith(type[j])) {
870-
continue;
884+
if (!fishName.startsWith(type)) {
885+
return;
871886
}
872887

873888
var numType = numLeft;
874-
if (type[j] == "Big") {
875-
numType = Math.min(numLeft, num[i] < 100 ? 1 : 2);
876-
} else if (type[j] == "Medium") {
877-
if (num[i] < 1000) {
878-
numType = Math.min(numLeft, num[i] / 10 | 0);
879-
} else if (num[i] < 10000) {
889+
if (type == "Big") {
890+
numType = Math.min(numLeft, totalFish < 100 ? 1 : 2);
891+
} else if (type == "Medium") {
892+
if (totalFish < 1000) {
893+
numType = Math.min(numLeft, totalFish / 10 | 0);
894+
} else if (totalFish < 10000) {
880895
numType = Math.min(numLeft, 80);
881896
} else {
882897
numType = Math.min(numLeft, 160);
883898
}
884899
}
885900
numLeft = numLeft - numType;
886901
fishInfo.num.push(numType);
887-
}
888-
}
889-
}
902+
});
903+
})
904+
});
890905

891906
var particleSystem = new tdl.particles.ParticleSystem(
892907
gl, null, math.pseudoRandom);
@@ -1742,7 +1757,9 @@ function setupCountButtons() {
17421757
}}(elem, ii);
17431758
}
17441759

1745-
if (g.net.sync) {
1760+
if (g_query.numFish) {
1761+
setSetting(document.getElementById("setSetting0"), 0);
1762+
} else if (g.net.sync) {
17461763
setSetting(document.getElementById("setSetting4"), 4);
17471764
} else {
17481765
setSetting(document.getElementById("setSetting2"), 2);
@@ -1861,7 +1878,7 @@ $(function(){
18611878
main();
18621879
});
18631880

1864-
VR = (function() {
1881+
var VR = (function() {
18651882
"use strict";
18661883
var vrButton;
18671884

0 commit comments

Comments
 (0)