Skip to content

Commit cdd2bc3

Browse files
committed
dimension change event
1 parent c8b5401 commit cdd2bc3

File tree

6 files changed

+128
-88
lines changed

6 files changed

+128
-88
lines changed

coffee/client/js/World/World.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class World
108108
cellId=@cellTerrain.vec3 data.info...
109109
cell=data.cell
110110
mesh=@cellMesh[cellId]
111-
geometry=new THREE.BufferGeometry;
111+
geometry=new THREE.BufferGeometry
112112
geometry.setAttribute 'position',new THREE.BufferAttribute(new Float32Array(cell.positions), 3)
113113
geometry.setAttribute 'normal',new THREE.BufferAttribute(new Float32Array(cell.normals), 3)
114114
geometry.setAttribute 'uv',new THREE.BufferAttribute(new Float32Array(cell.uvs), 2)

coffee/client/js/World/sections.worker.coffee

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,80 +2,80 @@
22
console.log "SECTIONS WORKER STARTED!"
33

44
class BitArray
5-
constructor: (options)->
6-
if options is null
7-
return
8-
if not options.bitsPerValue > 0
9-
console.error 'bits per value must at least 1'
10-
if not (options.bitsPerValue <= 32)
11-
console.error 'bits per value exceeds 32'
12-
valuesPerLong = Math.floor 64 / options.bitsPerValue
13-
length = Math.ceil(options.capacity / valuesPerLong)
14-
if not options.data
15-
options.data = Array(length * 2).fill(0)
16-
valueMask = (1 << options.bitsPerValue) - 1
5+
constructor: (options)->
6+
if options is null
7+
return
8+
if not options.bitsPerValue > 0
9+
console.error 'bits per value must at least 1'
10+
if not (options.bitsPerValue <= 32)
11+
console.error 'bits per value exceeds 32'
12+
valuesPerLong = Math.floor 64 / options.bitsPerValue
13+
length = Math.ceil(options.capacity / valuesPerLong)
14+
if not options.data
15+
options.data = Array(length * 2).fill(0)
16+
valueMask = (1 << options.bitsPerValue) - 1
1717

18-
@data = options.data
19-
@capacity = options.capacity
20-
@bitsPerValue = options.bitsPerValue
21-
@valuesPerLong = valuesPerLong
22-
@valueMask = valueMask
23-
return
24-
get:(index)->
25-
if not (index >= 0 && index < @capacity)
26-
console.error 'index is out of bounds'
27-
startLongIndex = Math.floor index / @valuesPerLong
28-
indexInLong = (index - startLongIndex * @valuesPerLong) * @bitsPerValue
29-
if indexInLong >= 32
30-
indexInStartLong = indexInLong - 32
31-
startLong = @data[startLongIndex * 2 + 1]
32-
return (startLong >>> indexInStartLong) & @valueMask
33-
startLong = @data[startLongIndex * 2]
34-
indexInStartLong = indexInLong
35-
result = startLong >>> indexInStartLong
36-
endBitOffset = indexInStartLong + @bitsPerValue
37-
if endBitOffset > 32
38-
endLong = @data[startLongIndex * 2 + 1]
39-
result |= endLong << (32 - indexInStartLong)
40-
return result & @valueMask
18+
@data = options.data
19+
@capacity = options.capacity
20+
@bitsPerValue = options.bitsPerValue
21+
@valuesPerLong = valuesPerLong
22+
@valueMask = valueMask
23+
return
24+
get:(index)->
25+
if not (index >= 0 && index < @capacity)
26+
console.error 'index is out of bounds'
27+
startLongIndex = Math.floor index / @valuesPerLong
28+
indexInLong = (index - startLongIndex * @valuesPerLong) * @bitsPerValue
29+
if indexInLong >= 32
30+
indexInStartLong = indexInLong - 32
31+
startLong = @data[startLongIndex * 2 + 1]
32+
return (startLong >>> indexInStartLong) & @valueMask
33+
startLong = @data[startLongIndex * 2]
34+
indexInStartLong = indexInLong
35+
result = startLong >>> indexInStartLong
36+
endBitOffset = indexInStartLong + @bitsPerValue
37+
if endBitOffset > 32
38+
endLong = @data[startLongIndex * 2 + 1]
39+
result |= endLong << (32 - indexInStartLong)
40+
return result & @valueMask
4141

4242
class ChunkDecoder
43-
getBlockIndex: (pos)->
44-
return (pos.y << 8) | (pos.z << 4) | pos.x
45-
cvo: (voxelX,voxelY,voxelZ) ->
46-
x=voxelX %% 16|0
47-
y=voxelY %% 16|0
48-
z=voxelZ %% 16|0
49-
return y*16*16+z*16+x
50-
computeSections: (packet)->
51-
sections=packet.sections
52-
num=0
53-
result=[]
54-
for i in sections
55-
num+=1
56-
if i isnt null
57-
solidBlockCount=i.solidBlockCount
58-
palette=i.palette
59-
data=new BitArray i.data
60-
pos={
61-
x:0
62-
y:0
63-
z:0
64-
}
65-
cell=new Uint32Array 16*16*16
66-
for x in [0..15]
67-
for y in [0..15]
68-
for z in [0..15]
69-
cell[@cvo(x,y,z)]=palette[data.get(@getBlockIndex({x,y,z}))]
70-
result.push {
71-
x:packet.x
72-
y:num
73-
z:packet.z
74-
cell
75-
}
76-
else
77-
result.push(null)
78-
return result
43+
getBlockIndex: (pos)->
44+
return (pos.y << 8) | (pos.z << 4) | pos.x
45+
cvo: (voxelX,voxelY,voxelZ) ->
46+
x=voxelX %% 16|0
47+
y=voxelY %% 16|0
48+
z=voxelZ %% 16|0
49+
return y*16*16+z*16+x
50+
computeSections: (packet)->
51+
sections=packet.sections
52+
num=0
53+
result=[]
54+
for i in sections
55+
num+=1
56+
if i isnt null
57+
solidBlockCount=i.solidBlockCount
58+
palette=i.palette
59+
data=new BitArray i.data
60+
pos={
61+
x:0
62+
y:0
63+
z:0
64+
}
65+
cell=new Uint32Array 16*16*16
66+
for x in [0..15]
67+
for y in [0..15]
68+
for z in [0..15]
69+
cell[@cvo(x,y,z)]=palette[data.get(@getBlockIndex({x,y,z}))]
70+
result.push {
71+
x:packet.x
72+
y:num
73+
z:packet.z
74+
cell
75+
}
76+
else
77+
result.push(null)
78+
return result
7979

8080
addEventListener "message", (e)->
8181
fn = handlers[e.data.type]
@@ -87,8 +87,8 @@ addEventListener "message", (e)->
8787
cd=new ChunkDecoder
8888

8989
handlers={
90-
computeSections:(data)->
91-
postMessage {
92-
result:cd.computeSections data
93-
}
90+
computeSections:(data)->
91+
postMessage {
92+
result:cd.computeSections data
93+
}
9494
}

coffee/client/js/index.coffee

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {PlayerInInventory} from "./PlayerInInventory.js"
1616
import {BlockBreak} from "./BlockBreak.js"
1717
import {BlockPlace} from "./BlockPlace.js"
1818

19-
2019
class Game
2120
constructor:(options)->
2221
_this=@
@@ -31,7 +30,7 @@ class Game
3130
@cellSize=16
3231
@canvas=document.querySelector "#c"
3332
@pcanvas=document.querySelector "#c_player"
34-
33+
@dimension=null
3534
@socket=io.connect ":8081"
3635

3736
@renderer=new THREE.WebGLRenderer
@@ -85,8 +84,12 @@ class Game
8584
_this.camera.rotation.y=yaw
8685
_this.camera.rotation.x=pitch
8786
return
88-
"mapChunk":(sections,x,z,biomes)->
89-
_this.world._computeSections sections,x,z,biomes
87+
"dimension":(dim)->
88+
_this.dimension=dim
89+
console.log "Player dimension has been changed: #{dim}"
90+
return
91+
"mapChunk":(sections,x,z,biomes,dim)->
92+
_this.world._computeSections sections,x,z,biomes,dim
9093
return
9194
"hp":(points)->
9295
_this.inv_bar.setHp(points)

coffee/server/server.coffee

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,37 @@ io.sockets.on "connection", (socket)->
3939
username: socketInfo[socket.id].nick
4040
version: config.version
4141
}
42+
4243
bot=()->
4344
if socketInfo[socket.id] isnt undefined
4445
return socketInfo[socket.id].bot
4546
else
4647
return null
48+
4749
emit=(array)->
4850
io.to(socket.id).emit array...
51+
52+
4953
#Eventy otrzymywane z serwera minecraftowego
54+
war=true
5055
bot()._client.on "map_chunk",(packet)->
5156
cell=new Chunk()
52-
cell.load packet.chunkData,packet.bitMap,false,true
57+
cell.load packet.chunkData,packet.bitMap,true,true
58+
for i in [0..255]
59+
light=cell.getBlockLight 0, i, 0
60+
if light isnt 0
61+
console.log light
62+
break
63+
# emit ["dimension",bot().game.dimension]
5364
emit ["mapChunk", cell.sections,packet.x,packet.z,packet.biomes]
5465
return
66+
bot()._client.on "respawn",(packet)->
67+
emit ["dimension",packet.dimension.value.effects.value]
68+
return
5569
botEventMap={
70+
"login":()->
71+
emit ["dimension",bot().game.dimension]
72+
return
5673
"move":()->
5774
emit ["move",bot().entity.position]
5875
return
@@ -107,8 +124,8 @@ io.sockets.on "connection", (socket)->
107124
,10
108125
socketEventMap={
109126
"blockPlace":(pos,vec)->
110-
console.log pos,vec
111127
block=bot().blockAt(new vec3(pos...))
128+
console.log block
112129
vecx=[
113130
[1,0,0]
114131
[-1,0,0]

src/client/js/index.js

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

src/server/server.js

Lines changed: 19 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)