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
var g_frameData ;
34
38
var g_vrDisplay ;
35
39
@@ -349,6 +353,15 @@ var g_skyBoxUrls = [
349
353
// 'static_assets/skybox/InteriorCubeEnv_EM.png'
350
354
]
351
355
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
+
352
365
function ValidateNoneOfTheArgsAreUndefined ( functionName , args ) {
353
366
for ( var ii = 0 ; ii < args . length ; ++ ii ) {
354
367
if ( args [ ii ] === undefined ) {
@@ -831,7 +844,10 @@ function handleContextRestored() {
831
844
}
832
845
833
846
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
+ }
835
851
836
852
gl . enable ( gl . DEPTH_TEST ) ;
837
853
gl . blendFunc ( gl . SRC_ALPHA , gl . ONE_MINUS_SRC_ALPHA ) ;
@@ -846,47 +862,46 @@ function initialize() {
846
862
var num = [ 1 , 100 , 500 , 1000 , 5000 , 10000 , 15000 , 20000 , 25000 , 30000 ] ;
847
863
var changeViewElem = document . getElementById ( "setSettingChangeView" ) ;
848
864
var parentElem = changeViewElem . parentNode ;
849
- for ( var i = 0 ; i < num . length ; ++ i ) {
865
+ g_numFish . forEach ( ( numFish , ndx ) => {
850
866
var div = document . createElement ( "div" ) ;
851
867
div . className = "clickable" ;
852
- div . id = "setSetting" + i ;
853
- div . innerHTML = num [ i ] ;
868
+ div . id = "setSetting" + ndx ;
869
+ div . innerHTML = numFish ;
854
870
parentElem . insertBefore ( div , changeViewElem ) ;
855
- }
871
+ } ) ;
856
872
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
+ } ) ;
861
877
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 ) => {
868
883
var fishName = fishInfo . name ;
869
- if ( ! fishName . startsWith ( type [ j ] ) ) {
870
- continue ;
884
+ if ( ! fishName . startsWith ( type ) ) {
885
+ return ;
871
886
}
872
887
873
888
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 ) {
880
895
numType = Math . min ( numLeft , 80 ) ;
881
896
} else {
882
897
numType = Math . min ( numLeft , 160 ) ;
883
898
}
884
899
}
885
900
numLeft = numLeft - numType ;
886
901
fishInfo . num . push ( numType ) ;
887
- }
888
- }
889
- }
902
+ } ) ;
903
+ } )
904
+ } ) ;
890
905
891
906
var particleSystem = new tdl . particles . ParticleSystem (
892
907
gl , null , math . pseudoRandom ) ;
@@ -1742,7 +1757,9 @@ function setupCountButtons() {
1742
1757
} } ( elem , ii ) ;
1743
1758
}
1744
1759
1745
- if ( g . net . sync ) {
1760
+ if ( g_query . numFish ) {
1761
+ setSetting ( document . getElementById ( "setSetting0" ) , 0 ) ;
1762
+ } else if ( g . net . sync ) {
1746
1763
setSetting ( document . getElementById ( "setSetting4" ) , 4 ) ;
1747
1764
} else {
1748
1765
setSetting ( document . getElementById ( "setSetting2" ) , 2 ) ;
@@ -1861,7 +1878,7 @@ $(function(){
1861
1878
main ( ) ;
1862
1879
} ) ;
1863
1880
1864
- VR = ( function ( ) {
1881
+ var VR = ( function ( ) {
1865
1882
"use strict" ;
1866
1883
var vrButton ;
1867
1884
0 commit comments