Skip to content

Commit b3998f2

Browse files
committed
blocksDefinitions optimization & all es6 modules & better webpack build
1 parent 7e9d80d commit b3998f2

File tree

1,778 files changed

+1204
-723096
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,778 files changed

+1204
-723096
lines changed

coffee/client/js/AssetLoader.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as THREE from './build/three.module.js'
2-
import {FBXLoader} from './jsm/loaders/FBXLoader.js'
1+
import * as THREE from "three"
2+
import {FBXLoader} from "three/examples/jsm/loaders/FBXLoader.js"
33

44
class AssetLoader
55
constructor: (init)->

coffee/client/js/BlockBreak.coffee

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as THREE from './build/three.module.js'
1+
import * as THREE from "three"
22

33
class BlockBreak
44
constructor:(game)->
@@ -75,9 +75,8 @@ class BlockBreak
7575
pos=@game.world.getRayBlock().posBreak
7676
if pos isnt undefined
7777
block=@game.world.cellTerrain.getBlock pos...
78-
if block.diggable
79-
@game.socket.emit "dig", pos
80-
@done=false
78+
@game.socket.emit "dig", pos
79+
@done=false
8180
return
8281
startDigging:(time)->
8382
_this=@

coffee/client/js/Entities.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as THREE from './build/three.module.js'
1+
import * as THREE from 'three'
22
class Entities
33
constructor:(game)->
44
@game=game

coffee/client/js/FirstPersonControls.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as THREE from './build/three.module.js'
1+
import * as THREE from 'three'
22

33
class FirstPersonControls
44
constructor: (game)->
@@ -41,7 +41,7 @@ class FirstPersonControls
4141
_this.game.chat.chatGoBack()
4242
if z.keyCode is 40 and _this.gameState is "chat"
4343
_this.game.chat.chatGoForward()
44-
44+
4545
#Klawisz Enter
4646
if z.keyCode is 13 and _this.gameState is "chat"
4747
_this.game.chat.command $(".com_i").val()

coffee/client/js/PlayerInInventory.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as THREE from './build/three.module.js'
1+
import * as THREE from 'three'
22
class PlayerInInventory
33
constructor:(game)->
44
@game=game

coffee/client/js/World/AnimatedTextureAtlas.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as THREE from './../build/three.module.js'
1+
import * as THREE from 'three'
22

33
class TextureAtlasCreator
44
constructor: (options)->

coffee/client/js/World/CellTerrain.coffee

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {Block} from './../build/Block.js'
1+
22
class CellTerrain
33
constructor: (options)->
44
@cellSize=options.cellSize
55
@cells={}
6-
@loadedBlocks={}
6+
@blocksDef=options.blocksDef
77
vec3: (x,y,z)->
88
x=parseInt x
99
y=parseInt y
@@ -47,7 +47,18 @@ class CellTerrain
4747
setCell:(cellX,cellY,cellZ,buffer)->
4848
@cells[@vec3(cellX,cellY,cellZ)]=buffer
4949
getBlock:(blockX,blockY,blockZ)->
50-
if @loadedBlocks[@getVoxel(blockX,blockY,blockZ)] is undefined
51-
@loadedBlocks[@getVoxel(blockX,blockY,blockZ)]=new Block.fromStateId @getVoxel(blockX,blockY,blockZ)
52-
return @loadedBlocks[@getVoxel(blockX,blockY,blockZ)]
50+
stateId=@getVoxel(blockX,blockY,blockZ)
51+
def=@blocksDef[stateId]
52+
if def isnt undefined
53+
if def[1] is 1
54+
boundingBox="block"
55+
else
56+
boundingBox="empty"
57+
return {
58+
name:def[0]
59+
stateId
60+
boundingBox
61+
}
62+
else
63+
return false
5364
export {CellTerrain}

coffee/client/js/World/World.coffee

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as THREE from './../build/three.module.js'
1+
import * as THREE from 'three'
22
import {CellTerrain} from './CellTerrain.js'
33
import {AnimatedTextureAtlas} from './AnimatedTextureAtlas.js'
44

@@ -12,8 +12,9 @@ class World
1212
@cellBlackList={}
1313
@cellMesh={}
1414
@cellNeedsUpdate={}
15+
@blocksDef=@game.al.get "blocksDef"
1516
@models={}
16-
@cellTerrain=new CellTerrain {cellSize:@game.cellSize}
17+
@cellTerrain=new CellTerrain {cellSize:@game.cellSize,blocksDef:@blocksDef}
1718
@ATA=new AnimatedTextureAtlas {al:@game.al}
1819
@material=@ATA.material
1920
@cellUpdateTime=null
@@ -31,6 +32,7 @@ class World
3132
toxelSize: @game.toxelSize
3233
cellSize: @game.cellSize
3334
blocksTex: @game.al.get "blocksTex"
35+
blocksDef: @blocksDef
3436
}
3537
}
3638

coffee/client/js/World/chunk.worker.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ class TerrainManager
77
@cellSize=options.cellSize
88
@cellTerrain=new CellTerrain {
99
cellSize:@cellSize
10+
blocksDef:options.blocksDef
1011
}
1112
@toxelSize=options.toxelSize
1213
@q=1/@toxelSize
1314
@blocksMapping=options.blocksMapping
1415
@blocksTex=options.blocksTex
15-
console.log @blocksTex
1616
genBlockFace: (type,block,pos)->
1717
if @blocksTex[block.name] isnt undefined or @blocksTex[String(block.stateId)] isnt undefined
1818
if @blocksTex[String(block.stateId)] isnt undefined
@@ -223,6 +223,7 @@ handlers={
223223
toxelSize:data.toxelSize
224224
cellSize:data.cellSize
225225
blocksTex:data.blocksTex
226+
blocksDef:data.blocksDef
226227
}
227228
return
228229
setVoxel:(data)->

coffee/client/js/index.coffee

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11

2-
import * as THREE from './build/three.module.js'
3-
import {SkeletonUtils} from './jsm/utils/SkeletonUtils.js'
4-
import Stats from './jsm/libs/stats.module.js'
5-
import {World} from './World/World.js'
6-
import {FirstPersonControls} from './FirstPersonControls.js'
7-
import {gpuInfo} from './gpuInfo.js'
8-
import {AssetLoader} from './AssetLoader.js'
9-
import {InventoryBar} from './InventoryBar.js'
10-
import {RandomNick} from './RandomNick.js'
11-
import {GUI} from './jsm/libs/dat.gui.module.js'
12-
import {Chat} from './Chat.js'
13-
import {Entities} from './Entities.js'
14-
import {PlayerInInventory} from './PlayerInInventory.js'
15-
import {BlockBreak} from './BlockBreak.js'
16-
import {BlockPlace} from './BlockPlace.js'
17-
import io from 'socket.io-client'
2+
import * as THREE from "three"
3+
import Stats from "stats-js"
4+
import * as dat from "dat.gui"
5+
import io from "socket.io-client"
186
import TWEEN from "@tweenjs/tween.js"
7+
import {World} from "./World/World.js"
8+
import {FirstPersonControls} from "./FirstPersonControls.js"
9+
import {gpuInfo} from "./gpuInfo.js"
10+
import {AssetLoader} from "./AssetLoader.js"
11+
import {InventoryBar} from "./InventoryBar.js"
12+
import {RandomNick} from "./RandomNick.js"
13+
import {Chat} from "./Chat.js"
14+
import {Entities} from "./Entities.js"
15+
import {PlayerInInventory} from "./PlayerInInventory.js"
16+
import {BlockBreak} from "./BlockBreak.js"
17+
import {BlockPlace} from "./BlockPlace.js"
1918

2019
class Game
2120
constructor:(options)->
@@ -29,8 +28,8 @@ class Game
2928
@fov=70
3029
@toxelSize=27
3130
@cellSize=16
32-
@canvas=document.querySelector '#c'
33-
@pcanvas=document.querySelector '#c_player'
31+
@canvas=document.querySelector "#c"
32+
@pcanvas=document.querySelector "#c_player"
3433

3534
@socket=io.connect ":8081"
3635

@@ -55,7 +54,7 @@ class Game
5554
document.location.href="\##{@nick}"
5655

5756
@stats=new Stats
58-
@drawcalls=@stats.addPanel new Stats.Panel( 'calls', '#ff8', '#221' )
57+
@drawcalls=@stats.addPanel new Stats.Panel( "calls", "#ff8", "#221" )
5958
@stats.showPanel 3
6059
document.body.appendChild @stats.dom
6160

@@ -71,7 +70,7 @@ class Game
7170
eventMap={
7271
"connect":()->
7372
console.log "Połączono z serverem!"
74-
$('.loadingText').text "Za chwilę dołączysz do gry..."
73+
$(".loadingText").text "Za chwilę dołączysz do gry..."
7574
console.log "User nick: #{_this.nick}"
7675
_this.socket.emit "initClient",
7776
nick:_this.nick
@@ -135,21 +134,21 @@ class Game
135134
@socket.on i,eventMap[i]
136135

137136

138-
gui = new GUI()
137+
gui = new dat.GUI
139138
@params=
140139
fog:false
141140
chunkdist:3
142141
color = new THREE.Color "#adc8ff"
143142
near = 0.5*16
144143
far = 2.5*16
145144
# scene.fog = new THREE.Fog color, near, far
146-
gui.add( @params, 'fog' ).name( 'Enable fog' ).listen().onChange ()->
145+
gui.add( @params, "fog" ).name( "Enable fog" ).listen().onChange ()->
147146
if _this.params.fog
148147
_this.scene.fog = new THREE.Fog color, near, far
149148
else
150149
_this.scene.fog = null
151-
gui.add( @world.material, 'wireframe' ).name( 'Wireframe' ).listen()
152-
gui.add( @params, 'chunkdist',0,10,1).name( 'Render distance' ).listen()
150+
gui.add( @world.material, "wireframe" ).name( "Wireframe" ).listen()
151+
gui.add( @params, "chunkdist",0,10,1).name( "Render distance" ).listen()
153152
@mouse=false
154153
$(document).mousedown (e)->
155154
if e.which is 1

0 commit comments

Comments
 (0)