Skip to content

Commit 2141432

Browse files
committed
revert to Client side raycasting
1 parent 2449f25 commit 2141432

File tree

6 files changed

+55
-80
lines changed

6 files changed

+55
-80
lines changed

coffee/client/module/World/World.coffee

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ class World
157157
tzMax = if tzDelta < Infinity then tzDelta * zDist else Infinity
158158
steppedIndex = -1
159159
while t <= len
160-
voxel = @cellTerrain.getVoxel ix, iy, iz
160+
block = @cellTerrain.getBlock ix, iy, iz
161+
if block.name is "air" or block.name is "cave_air" or block.name is "void_air"
162+
voxel=0
163+
else
164+
voxel=1
161165
if voxel
162166
return {
163167
position: [

coffee/client/module/index.coffee

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
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;params=null
32
import * as THREE from './build/three.module.js'
43
import {SkeletonUtils} from './jsm/utils/SkeletonUtils.js'
@@ -80,17 +79,6 @@ init = ()->
8079
inv_bar = new InventoryBar()
8180
inv_bar.listen()
8281

83-
#Kursor raycastowania
84-
cursor=new THREE.LineSegments(
85-
new THREE.EdgesGeometry(
86-
new THREE.BoxGeometry 1, 1, 1
87-
),
88-
new THREE.LineBasicMaterial {
89-
color: 0x000000,
90-
linewidth: 0.5
91-
}
92-
)
93-
scene.add cursor
9482

9583
#Komunikacja z serwerem websocket
9684
eventMap={
@@ -141,17 +129,22 @@ init = ()->
141129
return
142130
"entities":(entities)->
143131
ent.update entities
144-
"rayBlock":(block)->
145-
if block isnt false
146-
pos=block.position
147-
cursor.position.set pos.x,pos.y+16,pos.z
148-
cursor.visible=true
149-
else
150-
cursor.visible=false
151132
}
152133
for i of eventMap
153134
socket.on i,eventMap[i]
154135

136+
#Kursor raycastowania
137+
cursor=new THREE.LineSegments(
138+
new THREE.EdgesGeometry(
139+
new THREE.BoxGeometry 1, 1, 1
140+
),
141+
new THREE.LineBasicMaterial {
142+
color: 0x000000,
143+
linewidth: 0.5
144+
}
145+
)
146+
scene.add cursor
147+
155148
#Interfejs dat.gui
156149
gui = new GUI()
157150
params={
@@ -172,7 +165,8 @@ init = ()->
172165
gui.add( params, 'chunkdist',0,10,1).name( 'Render distance' ).listen()
173166

174167
$(document).mousedown (e)->
175-
console.log world.cellTerrain.getBlock world.getRayBlock().posBreak...
168+
if FPC.gameState is "gameLock"
169+
console.log world.cellTerrain.getBlock world.getRayBlock().posBreak...
176170
return
177171

178172
#Wprawienie w ruch funkcji animate
@@ -191,6 +185,15 @@ render = ->
191185
camera.aspect = width / height
192186
camera.updateProjectionMatrix()
193187

188+
#Raycastowany block
189+
rayBlock=world.getRayBlock()
190+
if rayBlock
191+
pos=rayBlock.posBreak
192+
cursor.position.set pos...
193+
cursor.visible=true
194+
else
195+
cursor.visible=false
196+
194197
#Updatowanie komórek wokół gracza
195198
world.updateCellsAroundPlayer camera.position,params.chunkdist
196199

coffee/server.coffee

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,6 @@ module.exports=(type)->
3535
console.log "Server is running on \x1b[34m*:#{config["port"]}\x1b[0m"
3636
# opn("http://#{config.host}:#{config['express-port']}")
3737

38-
#Raytracing
39-
rayTraceBlock=(b)->
40-
maxSteps = 20
41-
vectorLength=5/16
42-
cursor=b.entity.position.offset 0,b.entity.height,0
43-
x = -Math.sin(b.entity.yaw) * Math.cos(b.entity.pitch)
44-
y = Math.sin(b.entity.pitch)
45-
z = -Math.cos(b.entity.yaw) * Math.cos(b.entity.pitch)
46-
step=vec3(x,y,z).scaled(vectorLength)
47-
for i in [0..maxSteps-1]
48-
cursor.add(step)
49-
block=b.blockAt(cursor)
50-
if block and block.type isnt 0 and block.name isnt "cave_air"
51-
return block
52-
return false
5338
#websocket
5439
io.sockets.on "connection", (socket)->
5540
socketInfo[socket.id]={}
@@ -121,14 +106,12 @@ module.exports=(type)->
121106
socketEventMap={
122107
"move":(state,toggle)->
123108
bot().setControlState(state,toggle)
124-
emit ["rayBlock",rayTraceBlock bot()]
125109
return
126110
"command":(com)->
127111
bot().chat(com)
128112
return
129113
"rotate":(data)->
130114
bot().look data...
131-
emit ["rayBlock",rayTraceBlock bot()]
132115
return
133116
"disconnect":()->
134117
try

src/client/module/World/World.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/client/module/index.js

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

src/server.js

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

0 commit comments

Comments
 (0)