@@ -3,86 +3,89 @@ import TWEEN from "@tweenjs/tween.js";
33import Stats from "stats-js" ;
44import * as dat from "dat.gui" ;
55import io from "socket.io-client" ;
6- import { DistanceBasedFog } from "./DistanceBasedFog.js" ;
7- import { UrlParams } from "./UrlParams.js" ;
8- import { gpuInfo } from "./gpuInfo.js" ;
9- import { World } from "./World/World.js" ;
10- import { InventoryBar } from "./InventoryBar.js" ;
11- import { Chat } from "./Chat.js" ;
12- import { Entities } from "./Entities.js" ;
13- import { PlayerInInventory } from "./PlayerInInventory.js" ;
14- import { BlockBreak } from "./BlockBreak.js" ;
15- import { BlockPlace } from "./BlockPlace.js" ;
16- import { EventHandler } from "./EventHandler.js" ;
6+ import { DistanceBasedFog } from "./DistanceBasedFog.js" ;
7+ import { UrlParams } from "./UrlParams.js" ;
8+ import { gpuInfo } from "./gpuInfo.js" ;
9+ import { World } from "./World/World.js" ;
10+ import { InventoryBar } from "./InventoryBar.js" ;
11+ import { Chat } from "./Chat.js" ;
12+ import { Entities } from "./Entities.js" ;
13+ import { PlayerInInventory } from "./PlayerInInventory.js" ;
14+ import { BlockBreak } from "./BlockBreak.js" ;
15+ import { BlockPlace } from "./BlockPlace.js" ;
16+ import { EventHandler } from "./EventHandler.js" ;
1717
18- function Setup ( game , cb ) {
19- game . canvas = document . querySelector ( "#c" ) ;
20- game . pcanvas = document . querySelector ( "#c_player" ) ;
21- game . renderer = new THREE . WebGLRenderer ( {
22- canvas : game . canvas ,
23- PixelRatio : window . devicePixelRatio ,
24- } ) ;
25- game . renderer . sortObjects = true ;
26- game . scene = new THREE . Scene ( ) ;
27- game . camera = new THREE . PerspectiveCamera ( game . fov . normal , 2 , 0.1 , 1000 ) ;
28- game . camera . rotation . order = "YXZ" ;
29- game . camera . position . set ( 26 , 26 , 26 ) ;
30- game . scene . add ( new THREE . AmbientLight ( 0xdddddd ) ) ;
31- game . stats = new Stats ( ) ;
32- game . drawcalls = game . stats . addPanel (
33- new Stats . Panel ( "calls" , "#ff8" , "#221" )
34- ) ;
35- game . stats . showPanel ( 0 ) ;
36- document . body . appendChild ( game . stats . dom ) ;
37- game . distanceBasedFog = new DistanceBasedFog ( game ) ;
38- UrlParams ( game , ( password ) => {
39- console . warn ( gpuInfo ( ) ) ;
40- game . socket = io ( {
41- query : {
42- nick : game . nick ,
43- server : game . server ,
44- port : game . serverPort ,
45- password,
46- premium : game . premium ,
47- } ,
18+ async function Setup ( game , cb ) {
19+ return new Promise ( ( resolve ) => {
20+ game . canvas = document . querySelector ( "#c" ) ;
21+ game . pcanvas = document . querySelector ( "#c_player" ) ;
22+ game . renderer = new THREE . WebGLRenderer ( {
23+ canvas : game . canvas ,
24+ PixelRatio : window . devicePixelRatio ,
4825 } ) ;
49- game . pii = new PlayerInInventory ( game ) ;
50- game . bb = new BlockBreak ( game ) ;
51- game . bp = new BlockPlace ( game ) ;
52- game . world = new World ( game ) ;
53- game . ent = new Entities ( game ) ;
54- game . chat = new Chat ( game ) ;
55- game . inv_bar = new InventoryBar ( game ) ;
56- game . eh = new EventHandler ( game ) ;
57- game . distanceBasedFog . addShaderToMaterial ( game . world . material ) ;
58- var gui = new dat . GUI ( ) ;
59- game . params = {
60- chunkdist : 3 ,
61- } ;
62- game . distanceBasedFog . farnear . x = ( game . params . chunkdist - 1 ) * 16 ;
63- game . distanceBasedFog . farnear . y = game . params . chunkdist * 16 ;
64- gui . add ( game . world . material , "wireframe" ) . name ( "Wireframe" ) . listen ( ) ;
65- var chunkDist = gui
66- . add ( game . params , "chunkdist" , 0 , 10 , 1 )
67- . name ( "Render distance" )
68- . listen ( ) ;
69- chunkDist . onChange ( function ( val ) {
70- game . distanceBasedFog . farnear . x = ( val - 1 ) * 16 ;
71- game . distanceBasedFog . farnear . y = val * 16 ;
72- console . log ( val ) ;
73- } ) ;
74- game . playerImpulse = function ( ) {
75- var to = {
76- x : game . playerPos [ 0 ] ,
77- y : game . playerPos [ 1 ] + game . headHeight ,
78- z : game . playerPos [ 2 ] ,
26+ game . renderer . sortObjects = true ;
27+ game . scene = new THREE . Scene ( ) ;
28+ game . camera = new THREE . PerspectiveCamera ( game . fov . normal , 2 , 0.1 , 1000 ) ;
29+ game . camera . rotation . order = "YXZ" ;
30+ game . camera . position . set ( 26 , 26 , 26 ) ;
31+ game . scene . add ( new THREE . AmbientLight ( 0xdddddd ) ) ;
32+ game . stats = new Stats ( ) ;
33+ game . drawcalls = game . stats . addPanel (
34+ new Stats . Panel ( "calls" , "#ff8" , "#221" )
35+ ) ;
36+ game . stats . showPanel ( 0 ) ;
37+ document . body . appendChild ( game . stats . dom ) ;
38+ game . distanceBasedFog = new DistanceBasedFog ( game ) ;
39+ UrlParams ( game , ( password ) => {
40+ console . warn ( gpuInfo ( ) ) ;
41+ game . socket = io ( {
42+ query : {
43+ nick : game . nick ,
44+ server : game . server ,
45+ port : game . serverPort ,
46+ password,
47+ premium : game . premium ,
48+ } ,
49+ } ) ;
50+ game . pii = new PlayerInInventory ( game ) ;
51+ game . bb = new BlockBreak ( game ) ;
52+ game . bp = new BlockPlace ( game ) ;
53+ game . world = new World ( game ) ;
54+ game . ent = new Entities ( game ) ;
55+ game . chat = new Chat ( game ) ;
56+ game . inv_bar = new InventoryBar ( game ) ;
57+ game . eh = new EventHandler ( game ) ;
58+ game . distanceBasedFog . addShaderToMaterial ( game . world . material ) ;
59+ var gui = new dat . GUI ( ) ;
60+ game . params = {
61+ chunkdist : 3 ,
62+ } ;
63+ game . distanceBasedFog . farnear . x = ( game . params . chunkdist - 1 ) * 16 ;
64+ game . distanceBasedFog . farnear . y = game . params . chunkdist * 16 ;
65+ gui . add ( game . world . material , "wireframe" ) . name ( "Wireframe" ) . listen ( ) ;
66+ var chunkDist = gui
67+ . add ( game . params , "chunkdist" , 0 , 10 , 1 )
68+ . name ( "Render distance" )
69+ . listen ( ) ;
70+ chunkDist . onChange ( function ( val ) {
71+ game . distanceBasedFog . farnear . x = ( val - 1 ) * 16 ;
72+ game . distanceBasedFog . farnear . y = val * 16 ;
73+ console . log ( val ) ;
74+ } ) ;
75+ game . playerImpulse = function ( ) {
76+ var to = {
77+ x : game . playerPos [ 0 ] ,
78+ y : game . playerPos [ 1 ] + game . headHeight ,
79+ z : game . playerPos [ 2 ] ,
80+ } ;
81+ new TWEEN . Tween ( game . camera . position )
82+ . to ( to , 100 )
83+ . easing ( TWEEN . Easing . Quadratic . Out )
84+ . start ( ) ;
7985 } ;
80- new TWEEN . Tween ( game . camera . position )
81- . to ( to , 100 )
82- . easing ( TWEEN . Easing . Quadratic . Out )
83- . start ( ) ;
84- } ;
85- cb ( ) ;
86- } ) ;
86+ resolve ( ) ;
87+ } ) ;
88+ } )
8789}
88- export { Setup } ;
90+
91+ export { Setup } ;
0 commit comments