Skip to content

Commit 52451de

Browse files
committed
szybsze ładowanie chunków
1 parent 173718a commit 52451de

File tree

11 files changed

+113
-447
lines changed

11 files changed

+113
-447
lines changed

coffee/client/module/FirstPersonControls.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class FirstPersonControls
1515
@camera=options.camera
1616
@micromove=options.micromove
1717
@gameState="menu"
18+
@listen()
1819
ac: (qx, qy, qa, qf)->
1920
m_x = -Math.sin(qa) * qf;
2021
m_y = -Math.cos(qa) * qf;

coffee/client/module/InventoryBar.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ class InventoryBar
5454
_this.directBoxChange(z)
5555
return @
5656

57-
export {InventoryBar}
57+
export {InventoryBar}

coffee/client/module/World/CellTerrain.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ class CellTerrain
33
@cellSize=options.cellSize
44
@cells={}
55
vec3: (x,y,z)->
6+
x=parseInt x
7+
y=parseInt y
8+
z=parseInt z
69
return "#{x}:#{y}:#{z}"
710
computeVoxelOffset: (voxelX,voxelY,voxelZ) ->
811
x=voxelX %% @cellSize|0

coffee/client/module/World/ChunkWorker.coffee

Lines changed: 48 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -26,93 +26,65 @@ class TerrainManager
2626
[x2,y1]
2727
[x2,y2]
2828
]
29-
vec3: (x,y,z) ->
30-
if typeof x is "string"
31-
x=parseInt x
32-
if typeof y is "string"
33-
y=parseInt y
34-
if typeof z is "string"
35-
z=parseInt z
36-
return "#{x}:#{y}:#{z}"
37-
genBlockFace: (type,voxel)->
38-
39-
try
29+
genBlockFace: (type,voxel,pos)->
30+
# toxX=@blocksMapping["debug"]["x"]
31+
# toxY=28-@blocksMapping["debug"]["y"]
32+
if @blocks[voxel] is undefined
33+
toxX=@blocksMapping["debug"]["x"]
34+
toxY=28-@blocksMapping["debug"]["y"]
35+
else
4036
blockName=@blocks[voxel]["faces"][type]
4137
toxX=@blocksMapping[blockName]["x"]
4238
toxY=@blocksMapping[blockName]["y"]
43-
catch e
44-
toxX=@blocksMapping["debug"]["x"]
45-
toxY=28-@blocksMapping["debug"]["y"]
39+
4640
uv=@getToxel toxX,toxY
4741
switch type
4842
when "pz"
49-
return [
50-
{ pos: [-0.5, -0.5, 0.5], norm: [ 0, 0, 1], uv: uv[0], },
51-
{ pos: [ 0.5, -0.5, 0.5], norm: [ 0, 0, 1], uv: uv[2], },
52-
{ pos: [-0.5, 0.5, 0.5], norm: [ 0, 0, 1], uv: uv[1], },
53-
{ pos: [-0.5, 0.5, 0.5], norm: [ 0, 0, 1], uv: uv[1], },
54-
{ pos: [ 0.5, -0.5, 0.5], norm: [ 0, 0, 1], uv: uv[2], },
55-
{ pos: [ 0.5, 0.5, 0.5], norm: [ 0, 0, 1], uv: uv[3], }
56-
]
43+
return {
44+
pos:[-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], 0.5+pos[2],0.5+pos[0], 0.5+pos[1], 0.5+pos[2]]
45+
norm:[0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1]
46+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
47+
}
5748
when "nx"
58-
return [
59-
{ pos: [ 0.5, -0.5, 0.5], norm: [ 1, 0, 0], uv: uv[0], },
60-
{ pos: [ 0.5, -0.5, -0.5], norm: [ 1, 0, 0], uv: uv[2], },
61-
{ pos: [ 0.5, 0.5, 0.5], norm: [ 1, 0, 0], uv: uv[1], },
62-
{ pos: [ 0.5, 0.5, 0.5], norm: [ 1, 0, 0], uv: uv[1], },
63-
{ pos: [ 0.5, -0.5, -0.5], norm: [ 1, 0, 0], uv: uv[2], },
64-
{ pos: [ 0.5, 0.5, -0.5], norm: [ 1, 0, 0], uv: uv[3], }
65-
]
49+
return {
50+
pos:[ 0.5+pos[0], -0.5+pos[1], 0.5+pos[2], 0.5+pos[0], -0.5+pos[1], -0.5+pos[2],0.5+pos[0], 0.5+pos[1], 0.5+pos[2], 0.5+pos[0], 0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], -0.5+pos[2], 0.5+pos[0], 0.5+pos[1], -0.5+pos[2]]
51+
norm:[ 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]
52+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
53+
}
6654
when "nz"
67-
return [
68-
{ pos: [ 0.5, -0.5, -0.5], norm: [ 0, 0, -1], uv: uv[0], },
69-
{ pos: [-0.5, -0.5, -0.5], norm: [ 0, 0, -1], uv: uv[2], },
70-
{ pos: [ 0.5, 0.5, -0.5], norm: [ 0, 0, -1], uv: uv[1], },
71-
{ pos: [ 0.5, 0.5, -0.5], norm: [ 0, 0, -1], uv: uv[1], },
72-
{ pos: [-0.5, -0.5, -0.5], norm: [ 0, 0, -1], uv: uv[2], },
73-
{ pos: [-0.5, 0.5, -0.5], norm: [ 0, 0, -1], uv: uv[3], }
74-
]
55+
return {
56+
pos:[ 0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], -0.5+pos[2],0.5+pos[0], 0.5+pos[1], -0.5+pos[2], 0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2]]
57+
norm:[ 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1]
58+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
59+
}
7560
when "px"
76-
return [
77-
{ pos: [-0.5, -0.5, -0.5], norm: [-1, 0, 0], uv: uv[0], },
78-
{ pos: [-0.5, -0.5, 0.5], norm: [-1, 0, 0], uv: uv[2], },
79-
{ pos: [-0.5, 0.5, -0.5], norm: [-1, 0, 0], uv: uv[1], },
80-
{ pos: [-0.5, 0.5, -0.5], norm: [-1, 0, 0], uv: uv[1], },
81-
{ pos: [-0.5, -0.5, 0.5], norm: [-1, 0, 0], uv: uv[2], },
82-
{ pos: [-0.5, 0.5, 0.5], norm: [-1, 0, 0], uv: uv[3], },
83-
]
61+
return {
62+
pos:[-0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2]]
63+
norm:[-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0]
64+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
65+
}
8466
when "py"
85-
return [
86-
{ pos: [ 0.5, 0.5, -0.5], norm: [ 0, 1, 0], uv: uv[0], },
87-
{ pos: [-0.5, 0.5, -0.5], norm: [ 0, 1, 0], uv: uv[2], },
88-
{ pos: [ 0.5, 0.5, 0.5], norm: [ 0, 1, 0], uv: uv[1], },
89-
{ pos: [ 0.5, 0.5, 0.5], norm: [ 0, 1, 0], uv: uv[1], },
90-
{ pos: [-0.5, 0.5, -0.5], norm: [ 0, 1, 0], uv: uv[2], },
91-
{ pos: [-0.5, 0.5, 0.5], norm: [ 0, 1, 0], uv: uv[3], }
92-
]
67+
return {
68+
pos:[ 0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],0.5+pos[0], 0.5+pos[1], 0.5+pos[2], 0.5+pos[0], 0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2]]
69+
norm:[ 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]
70+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
71+
}
9372
when "ny"
94-
return [
95-
{ pos: [ 0.5, -0.5, 0.5], norm: [ 0, -1, 0], uv: uv[0], },
96-
{ pos: [-0.5, -0.5, 0.5], norm: [ 0, -1, 0], uv: uv[2], },
97-
{ pos: [ 0.5, -0.5, -0.5], norm: [ 0, -1, 0], uv: uv[1], },
98-
{ pos: [ 0.5, -0.5, -0.5], norm: [ 0, -1, 0], uv: uv[1], },
99-
{ pos: [-0.5, -0.5, 0.5], norm: [ 0, -1, 0], uv: uv[2], },
100-
{ pos: [-0.5, -0.5, -0.5], norm: [ 0, -1, 0], uv: uv[3], }
101-
]
73+
return {
74+
pos:[ 0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], -0.5+pos[2], 0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], -0.5+pos[1], -0.5+pos[2]]
75+
norm:[ 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0]
76+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
77+
}
10278
genCellGeo: (cellX,cellY,cellZ)->
10379
positions=[]
10480
normals=[]
10581
uvs=[]
10682
_this=@
10783
addFace=(type,pos,voxel)->
108-
faceVertex=_this.genBlockFace type,voxel
109-
for vertex in faceVertex
110-
vertex.pos[0]+=pos[0]
111-
vertex.pos[1]+=pos[1]
112-
vertex.pos[2]+=pos[2]
113-
positions.push vertex.pos...
114-
normals.push vertex.norm...
115-
uvs.push vertex.uv...
84+
faceVertex=_this.genBlockFace type,voxel,pos
85+
positions.push faceVertex.pos...
86+
normals.push faceVertex.norm...
87+
uvs.push faceVertex.uv...
11688
return
11789
addGeo=(geo,pos)->
11890
posi=geo.position.array
@@ -167,6 +139,7 @@ State={
167139
world:{}
168140
}
169141
terrain=null
142+
time=0
170143
handlers={
171144
init:(data)->
172145
State.init=data
@@ -182,12 +155,16 @@ handlers={
182155
terrain.setVoxel data...
183156
genCellGeo: (data)->
184157
if ((terrain.cellTerrain.vec3 data...) of terrain.cellTerrain.cells) is true
158+
t0 = performance.now()
185159
geo=terrain.genCellGeo data...
186-
# if terrain.cellTerrain.cells[terrain.cellTerrain.vec3 data...] isnt undefined
160+
t1 = performance.now()
161+
time+=(t1 - t0)
162+
console.log(time)
187163
postMessage {
188164
cell:geo
189165
info:data
190166
}
191167
setCell: (data)->
168+
console.log("Otrzymano komórkę")
192169
terrain.cellTerrain.cells["#{data[0]}:#{data[1]}:#{data[2]}"]=data[3]
193170
}

coffee/client/module/World/SectionsWorker.coffee

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class ChunkDecoder
8585
result.push(null)
8686
return result
8787

88-
8988
addEventListener "message", (e)->
9089
fn = handlers[e.data.type]
9190
if not fn

coffee/client/module/index.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ init = ()->
105105
]).setFocusOnly(1).listen()
106106

107107
#First Person Controls
108-
FPC = new FirstPersonControls({
108+
FPC = new FirstPersonControls {
109109
canvas
110110
camera
111111
micromove: 0.3
112-
}).listen()
112+
}
113113

114114
#Raycast cursor
115115
cursor=new THREE.LineSegments(

src/client/module/FirstPersonControls.js

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

src/client/module/World/CellTerrain.js

Lines changed: 3 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)