Skip to content

Commit 173718a

Browse files
committed
World modules
1 parent d6eaf76 commit 173718a

File tree

12 files changed

+109
-110
lines changed

12 files changed

+109
-110
lines changed

coffee/client/module/AnimatedTextureAtlas.coffee renamed to coffee/client/module/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 './../build/three.module.js'
22

33
class TextureAtlasCreator
44
constructor: (options)->
File renamed without changes.

coffee/client/module/TerrainWorker.coffee renamed to coffee/client/module/World/ChunkWorker.coffee

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {CellTerrain} from './CellTerrain.js'
22

3+
console.log "CHUNK WORKER STARTED!"
4+
35
class TerrainManager
46
constructor: (options)->
57
@toxelSize=options.toxelSize
@@ -11,7 +13,6 @@ class TerrainManager
1113
@cellTerrain=new CellTerrain {
1214
cellSize:@cellSize
1315
}
14-
console.log "WORKER: TerrainManager started!"
1516
getToxel: (x,y)->
1617
x-=1
1718
y-=1
@@ -180,16 +181,13 @@ handlers={
180181
setVoxel:(data)->
181182
terrain.setVoxel data...
182183
genCellGeo: (data)->
183-
184184
if ((terrain.cellTerrain.vec3 data...) of terrain.cellTerrain.cells) is true
185185
geo=terrain.genCellGeo data...
186186
# if terrain.cellTerrain.cells[terrain.cellTerrain.vec3 data...] isnt undefined
187187
postMessage {
188188
cell:geo
189189
info:data
190190
}
191-
else
192-
console.log 'xd'
193191
setCell: (data)->
194192
terrain.cellTerrain.cells["#{data[0]}:#{data[1]}:#{data[2]}"]=data[3]
195193
}

coffee/client/module/ChunkWorker.coffee renamed to coffee/client/module/World/SectionsWorker.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
console.log "SECTIONS WORKER STARTED!"
3+
14
class BitArray
25
constructor: (options)->
36
if options is null
Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import * as THREE from './build/three.module.js'
1+
import * as THREE from './../build/three.module.js'
22
import {CellTerrain} from './CellTerrain.js'
3+
import {AnimatedTextureAtlas} from './AnimatedTextureAtlas.js'
34

4-
class Terrain
5+
class World
56
constructor: (options) ->
67
_this=@
78
@cellMesh={}
89
@cellNeedsUpdate={}
910
@models={}
1011
@cellSize=options.cellSize
11-
@material=options.material
1212
@camera=options.camera
1313
@scene=options.scene
1414
@toxelSize=options.toxelSize
1515
@al=options.al
16-
@cellTerrain=new CellTerrain {
17-
cellSize:@cellSize
18-
}
16+
@cellTerrain=new CellTerrain {cellSize:@cellSize}
17+
@ATA=new AnimatedTextureAtlas {al:@al}
18+
@material=@ATA.material
1919
@neighbours=[[-1, 0, 0],[1, 0, 0],[0, -1, 0],[0, 1, 0],[0, 0, -1],[0, 0, 1]]
20-
@worker=new Worker "/module/TerrainWorker.js", {type:'module'}
21-
@worker.onmessage=(message)->
20+
@chunkWorker=new Worker "/module/World/ChunkWorker.js", {type:'module'}
21+
@chunkWorker.onmessage=(message)->
2222
_this.updateCell message.data
23-
@worker.postMessage {
23+
@chunkWorker.postMessage {
2424
type:'init'
2525
data:{
2626
models:{
@@ -34,6 +34,12 @@ class Terrain
3434
cellSize: @cellSize
3535
}
3636
}
37+
@sectionsWorker=new Worker "/module/World/SectionsWorker.js", {type:'module'}
38+
@sectionsWorker.onmessage=(data)->
39+
result=data.data.result
40+
for i in result
41+
if i isnt null
42+
_this.setCell i.x,i.y,i.z,i.data
3743
setCell: (cellX,cellY,cellZ,buffer)->
3844
@_setCell cellX,cellY,cellZ,buffer
3945
@cellTerrain.cells[@cellTerrain.vec3(cellX,cellY,cellZ)]=buffer
@@ -166,21 +172,28 @@ class Terrain
166172
else
167173
return false
168174
_setCell: (cellX,cellY,cellZ,buffer)->
169-
@worker.postMessage {
175+
@chunkWorker.postMessage {
170176
type:"setCell"
171177
data:[cellX,cellY,cellZ,buffer]
172178
}
173179
_setVoxel: (voxelX,voxelY,voxelZ,value)->
174-
@worker.postMessage {
180+
@chunkWorker.postMessage {
175181
type:"setVoxel"
176182
data:[voxelX,voxelY,voxelZ,value]
177183
}
178184
_genCellGeo: (cellX,cellY,cellZ)->
179185
cellX=parseInt cellX
180186
cellY=parseInt cellY
181187
cellZ=parseInt cellZ
182-
@worker.postMessage {
188+
@chunkWorker.postMessage {
183189
type:"genCellGeo"
184190
data:[cellX,cellY,cellZ]
185191
}
186-
export {Terrain}
192+
_computeSections: (sections,x,z)->
193+
@sectionsWorker.postMessage {
194+
type:"computeSections"
195+
data:{
196+
sections,x,z
197+
}
198+
}
199+
export {World}

coffee/client/module/index.coffee

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11

2-
scene=null;materials=null;parameters=null;canvas=null;renderer=null;camera=null;terrain=null;cursor=null;FPC=null;socket=null;stats=null;worker=null;playerObject=null;inv_bar=null
2+
scene=null;materials=null;parameters=null;canvas=null;renderer=null;camera=null;world=null;cursor=null;FPC=null;socket=null;stats=null;worker=null;playerObject=null;inv_bar=null
33
import * as THREE from './build/three.module.js'
44
import {SkeletonUtils} from './jsm/utils/SkeletonUtils.js'
55
import Stats from './jsm/libs/stats.module.js'
6-
import {Terrain} from './Terrain.js'
6+
import {World} from './World/World.js'
77
import {FirstPersonControls} from './FirstPersonControls.js'
88
import {gpuInfo} from './gpuInfo.js'
99
import {AssetLoader} from './AssetLoader.js'
1010
import {InventoryBar} from './InventoryBar.js'
11-
import {AnimatedTextureAtlas} from './AnimatedTextureAtlas.js'
1211
import {Players} from './Players.js'
1312
import {RandomNick} from './RandomNick.js'
1413

15-
init = ()->
16-
17-
chunkWorker=new Worker "/module/ChunkWorker.js", {type:'module'}
18-
chunkWorker.onmessage=(data)->
19-
20-
result=data.data.result
21-
for i in result
22-
if i isnt null
23-
terrain.setCell(i.x,i.y,i.z,i.data)
2414

15+
init = ()->
2516
#canvas,renderer,camera,lights
2617
canvas=document.querySelector '#c'
2718
renderer=new THREE.WebGLRenderer {
@@ -55,16 +46,10 @@ init = ()->
5546
clouds.position.y=170
5647
scene.add clouds
5748

58-
#Animated Material
59-
ATA=new AnimatedTextureAtlas {
60-
al
61-
}
62-
63-
#setup terrain
64-
terrain=new Terrain({
49+
#setup world
50+
world=new World({
6551
toxelSize:27
6652
cellSize:16
67-
material:ATA.material
6853
scene
6954
camera
7055
al
@@ -85,22 +70,17 @@ init = ()->
8570
}
8671
return
8772
socket.on "blockUpdate",(block)->
88-
terrain.setBlock block...
73+
world.setBlock block...
8974
return
9075
socket.on "mapChunk", (sections,x,z)->
91-
chunkWorker.postMessage {
92-
type:"computeSections"
93-
data:{
94-
sections,x,z
95-
}
96-
}
76+
world._computeSections sections,x,z
9777
players=new Players {socket,scene,al}
9878
socket.on "playerUpdate",(data)->
9979
players.update data
10080
return
10181
socket.on "firstLoad",(v)->
10282
console.log "First Load packet recieved!"
103-
terrain.replaceWorld v
83+
world.replaceWorld v
10484
$(".initLoading").css "display","none"
10585
stats = new Stats();
10686
stats.showPanel(0);
@@ -146,7 +126,7 @@ init = ()->
146126
#jquery events
147127
$(document).mousedown (e)->
148128
if FPC.gameState is "game"
149-
rayBlock=terrain.getRayBlock()
129+
rayBlock=world.getRayBlock()
150130
if rayBlock
151131
if e.which is 1
152132
voxelId=0
@@ -185,7 +165,7 @@ render = ->
185165
FPC.camMicroMove()
186166

187167
#Update cursor
188-
rayBlock=terrain.getRayBlock()
168+
rayBlock=world.getRayBlock()
189169
if rayBlock
190170
pos=rayBlock.posBreak
191171
pos[0]=Math.floor pos[0]
@@ -197,7 +177,7 @@ render = ->
197177
cursor.visible=false
198178

199179
#Rendering
200-
terrain.updateCells()
180+
world.updateCells()
201181
renderer.render scene, camera
202182
return
203183
animate = ->

src/client/module/AnimatedTextureAtlas.js renamed to src/client/module/World/AnimatedTextureAtlas.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)