1
+ "use strict" ;
2
+
1
3
tdl . require ( 'tdl.buffers' ) ;
2
4
tdl . require ( 'tdl.clock' ) ;
3
5
tdl . require ( 'tdl.fast' ) ;
@@ -14,6 +16,7 @@ tdl.require('tdl.textures');
14
16
tdl . require ( 'tdl.webgl' ) ;
15
17
16
18
// globals
19
+ const g_query = parseQueryString ( window . location . search ) ;
17
20
var gl ; // the gl context.
18
21
var canvas ; // the canvas
19
22
var math ; // the math lib.
@@ -30,6 +33,7 @@ var g_scenes = {}; // each of the models
30
33
var g_sceneGroups = { } ; // the placement of the models
31
34
var g_fog = true ;
32
35
var g_requestId ;
36
+ var g_numFish = [ 1 , 100 , 500 , 1000 , 5000 , 10000 , 15000 , 20000 , 25000 , 30000 ] ;
33
37
34
38
// added for benchmarking stuff
35
39
var benchmarkMessageStarting = "Benchmark starts in: " ;
@@ -62,7 +66,6 @@ var featureFlags = "featureFlags";
62
66
//g_debug = true;
63
67
//g_drawOnce = true;
64
68
65
- var g_numSharks = 0 ;
66
69
var g_tailOffsetMult = 1 ;
67
70
var g_endOfDome = Math . PI / 8 ;
68
71
var g_tankRadius = 74 ;
@@ -380,6 +383,15 @@ var g_skyBoxUrls = [
380
383
// 'static_assets/skybox/InteriorCubeEnv_EM.png'
381
384
]
382
385
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
+
383
395
function ValidateNoneOfTheArgsAreUndefined ( functionName , args ) {
384
396
for ( var ii = 0 ; ii < args . length ; ++ ii ) {
385
397
if ( args [ ii ] === undefined ) {
@@ -950,7 +962,10 @@ function handleContextRestored() {
950
962
}
951
963
952
964
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
+ }
954
969
955
970
gl . enable ( gl . DEPTH_TEST ) ;
956
971
gl . blendFunc ( gl . SRC_ALPHA , gl . ONE_MINUS_SRC_ALPHA ) ;
@@ -962,49 +977,47 @@ function initialize() {
962
977
Log ( "--Setup Laser----------------------------------------" ) ;
963
978
var laser = setupLaser ( ) ;
964
979
965
- var num = [ 1 , 100 , 500 , 1000 , 5000 , 10000 , 15000 , 20000 , 25000 , 30000 ] ;
966
980
var changeViewElem = document . getElementById ( "setSettingChangeView" ) ;
967
981
var parentElem = changeViewElem . parentNode ;
968
- for ( var i = 0 ; i < num . length ; ++ i ) {
982
+ g_numFish . forEach ( ( numFish , ndx ) => {
969
983
var div = document . createElement ( "div" ) ;
970
984
div . className = "clickable" ;
971
- div . id = "setSetting" + i ;
972
- div . innerHTML = num [ i ] ;
985
+ div . id = "setSetting" + ndx ;
986
+ div . innerHTML = numFish ;
973
987
parentElem . insertBefore ( div , changeViewElem ) ;
974
- }
988
+ } ) ;
975
989
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
+ } ) ;
980
994
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 ) => {
987
1000
var fishName = fishInfo . name ;
988
- if ( ! fishName . startsWith ( type [ j ] ) ) {
989
- continue ;
1001
+ if ( ! fishName . startsWith ( type ) ) {
1002
+ return ;
990
1003
}
991
1004
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 ) {
998
1011
numType = Math . min ( numLeft , 80 ) ;
999
1012
} else {
1000
1013
numType = Math . min ( numLeft , 160 ) ;
1001
1014
}
1002
1015
}
1003
1016
numLeft = numLeft - numType ;
1004
1017
fishInfo . num . push ( numType ) ;
1005
- }
1006
- }
1007
- }
1018
+ } ) ;
1019
+ } )
1020
+ } ) ;
1008
1021
1009
1022
var particleSystem = new tdl . particles . ParticleSystem (
1010
1023
gl , null , math . pseudoRandom ) ;
@@ -1806,7 +1819,9 @@ function setupCountButtons() {
1806
1819
} } ( elem , ii ) ;
1807
1820
}
1808
1821
1809
- if ( g . net . sync ) {
1822
+ if ( g_query . numFish ) {
1823
+ setSetting ( document . getElementById ( "setSetting0" ) , 0 ) ;
1824
+ } else if ( g . net . sync ) {
1810
1825
setSetting ( document . getElementById ( "setSetting4" ) , 4 ) ;
1811
1826
} else {
1812
1827
setSetting ( document . getElementById ( "setSetting2" ) , 2 ) ;
0 commit comments