Skip to content

Commit a3e61b7

Browse files
committed
remove vec3
1 parent 61cd042 commit a3e61b7

File tree

8 files changed

+29
-48
lines changed

8 files changed

+29
-48
lines changed

package-lock.json

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

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"rimraf": "^3.0.2",
4848
"sweetalert": "^2.1.2",
4949
"three": "^0.125.0",
50-
"vec3": "^0.1.7",
5150
"webpack-dev-server": "^3.11.1",
5251
"webpack-merge": "^5.7.3",
5352
"worker-loader": "^3.0.7"

src/scripts/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class Game {
6969
$('.initLoading').css('display', 'block')
7070
$('.loadingText').html('Loading terrain...')
7171
})
72-
this.socket.on('mapChunk', (sections, x, z) => {
73-
this.world.computeSections(sections, x, z)
72+
this.socket.on('mapChunk', (sections, biomes, x, z) => {
73+
this.world.computeSections(sections, biomes, x, z)
7474
})
7575
this.socket.on('game', (gameData) => {
7676
this.inv_bar.updateGamemode(gameData.gameMode)

src/scripts/proxy/Proxy.worker.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-env worker */
2-
import vec3 from 'vec3'
2+
import { Vector3 } from 'three'
33
import Convert from 'ansi-to-html'
44
const convert = new Convert()
55

@@ -26,9 +26,11 @@ addEventListener('message', function (e) {
2626
})
2727
bot.heldItem = null
2828
bot.on('chunkColumnLoad', (p) => {
29+
const chunk = bot.world.getColumn(p.x / 16, p.z / 16)
2930
emit(
3031
'mapChunk',
31-
bot.world.getColumn(p.x / 16, p.z / 16).sections,
32+
chunk.sections,
33+
chunk.biomes,
3234
p.x / 16,
3335
p.z / 16
3436
)
@@ -152,7 +154,7 @@ addEventListener('message', function (e) {
152154
}
153155
break
154156
case 'dig':
155-
block = bot.blockAt(vec3(data[0][0], data[0][1] - 16, data[0][2]))
157+
block = bot.blockAt(new Vector3(data[0][0], data[0][1] - 16, data[0][2]))
156158
if (block !== null) {
157159
const digTime = bot.digTime(block)
158160
if (bot.targetDigBlock !== null) {
@@ -188,10 +190,10 @@ addEventListener('message', function (e) {
188190
}
189191
break
190192
case 'blockPlace':
191-
block = bot.blockAt(vec3(...data[0]))
193+
block = bot.blockAt(new Vector3(...data[0]))
192194
if (bot.heldItem !== undefined && bot.heldItem !== null) {
193195
// console.log(heldItem);
194-
bot.placeBlock(block, vec3(...data[1]))
196+
bot.placeBlock(block, new Vector3(...data[1]))
195197
}
196198
break
197199
}

src/scripts/world/ChunkManager.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import { BufferGeometry, BufferAttribute, Mesh } from 'three'
1+
import { BufferGeometry, BufferAttribute, Mesh, Vector3 } from 'three'
22

33
class ChunkManager {
44
constructor (game) {
55
this.game = game
6-
this.chunks = new Map()
76
this.cellMesh = new Map()
87
}
98

109
addChunk (cellId, vert) {
11-
this.chunks.set(cellId, vert)
12-
1310
const geometry = new BufferGeometry()
1411
geometry.setAttribute('position', new BufferAttribute(new Float32Array(vert.positions), 3))
1512
geometry.setAttribute('normal', new BufferAttribute(new Float32Array(vert.normals), 3))
@@ -29,23 +26,29 @@ class ChunkManager {
2926
this.cellMesh.set(cellId, newMesh)
3027
this.game.scene.add(newMesh)
3128
if (this.game.world.lastPlayerChunk !== null) {
32-
this.game.world.updateRenderOrder(JSON.parse(this.game.world.lastPlayerChunk))
29+
this.updateRenderOrder(JSON.parse(this.game.world.lastPlayerChunk))
3330
}
3431
} else {
3532
this.cellMesh.get(cellId).geometry = geometry
3633
}
3734
}
3835

3936
removeChunk (cellId) {
40-
if (this.chunks.get(cellId) !== undefined) {
41-
this.chunks.delete(cellId)
37+
if (this.cellMesh.get(cellId) !== undefined) {
4238
this.cellMesh.get(cellId).geometry.dispose()
4339
this.game.scene.remove(this.cellMesh.get(cellId))
4440
this.cellMesh.delete(cellId)
4541
this.game.renderer.renderLists.dispose()
4642
}
4743
}
4844

45+
updateRenderOrder (cell) {
46+
for (const [k, v] of this.cellMesh) {
47+
const x = new Vector3(this.game.world.chunkTerrain.strToVec(k))
48+
v.renderOrder = -new Vector3(...cell).distanceTo(x)
49+
}
50+
}
51+
4952
reset () {
5053
for (const i of this.cellMesh) {
5154
if (i[1].geometry !== undefined) {
@@ -54,7 +57,6 @@ class ChunkManager {
5457
}
5558
}
5659
this.cellMesh.clear()
57-
this.chunks.clear()
5860
}
5961
}
6062
export { ChunkManager }

src/scripts/world/SectionComputer.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ const ChunkDecoder = class ChunkDecoder {
7676
for (let x = 0; x < 16; x++) {
7777
for (let y = 0; y < 16; y++) {
7878
for (let z = 0; z < 16; z++) {
79-
cell[this.cvo(x, y, z)] =
80-
palette[
81-
data.get(this.getBlockIndex({ x, y, z }))
82-
]
79+
cell[this.cvo(x, y, z)] = palette[data.get(this.getBlockIndex({ x, y, z }))]
8380
}
8481
}
8582
}

src/scripts/world/World.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@ import { Vector3 } from 'three'
22
import { ChunkTerrain } from './ChunkTerrain.js'
33
import { AnimatedTextureAtlas } from './AnimatedTextureAtlas.js'
44
import { SectionComputer } from './SectionComputer.js'
5-
import vec3 from 'vec3'
6-
import ChunkWorker from './chunk.worker.js'
75
import { ChunkManager } from './ChunkManager.js'
6+
import ChunkWorker from './chunk.worker.js'
87

9-
const World = class World {
8+
class World {
109
constructor (game) {
1110
this.game = game
1211
this.blocksDef = this.game.al.get('blocksDef')
13-
this.models = {}
1412
this.chunkTerrain = new ChunkTerrain({
1513
blocksDef: this.blocksDef
1614
})
1715
this.ATA = new AnimatedTextureAtlas(this.game)
1816
this.material = this.ATA.material
1917
this.cellUpdateTime = null
20-
this.renderTime = 100
2118
this.lastPlayerChunk = null
2219
this.blocksUpdate = false
2320

@@ -44,13 +41,6 @@ const World = class World {
4441
})
4542
}
4643

47-
updateRenderOrder (cell) {
48-
for (const [k, v] of this.chunkManager.cellMesh) {
49-
const x = vec3(this.chunkTerrain.strToVec(k))
50-
v.renderOrder = -vec3(...cell).distanceTo(x)
51-
}
52-
}
53-
5444
setChunk (chunkX, chunkY, chunkZ, buffer) {
5545
this.cellUpdateTime = window.performance.now()
5646
this.chunkWorker.postMessage({
@@ -84,9 +74,7 @@ const World = class World {
8474
}
8575

8676
getRayBlock () {
87-
const start = new Vector3().setFromMatrixPosition(
88-
this.game.camera.matrixWorld
89-
)
77+
const start = new Vector3().setFromMatrixPosition(this.game.camera.matrixWorld)
9078
const end = new Vector3().set(0, 0, 1).unproject(this.game.camera)
9179
const intersection = this.chunkTerrain.intersectsRay(start, end)
9280
if (intersection) {
@@ -117,10 +105,9 @@ const World = class World {
117105
})
118106
} else if (this.lastPlayerChunk !== JSON.stringify(cell)) {
119107
if (
120-
this.cellUpdateTime !== null &&
121-
window.performance.now() - this.cellUpdateTime > this.renderTime
108+
this.cellUpdateTime !== null && window.performance.now() - this.cellUpdateTime > 100
122109
) {
123-
this.updateRenderOrder(cell)
110+
this.chunkManager.updateRenderOrder(cell)
124111
this.lastPlayerChunk = JSON.stringify(cell)
125112
this.chunkWorker.postMessage({
126113
type: 'updateChunksAroundPlayer',
@@ -130,9 +117,8 @@ const World = class World {
130117
}
131118
}
132119

133-
computeSections (sections, x, z) {
120+
computeSections (sections, biomes, x, z) {
134121
const result = SectionComputer({ sections, x, z })
135-
// console.log(result);
136122
const results = []
137123
for (const i in result) {
138124
const j = result[i]

src/scripts/world/chunk.worker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { ChunkTerrain } from './ChunkTerrain.js'
33
import { ChunkMesher } from './ChunkMesher.js'
44
import raf from 'raf'
5-
import vec3 from 'vec3'
5+
import { Vector3 } from 'three'
66

77
self.requestAnimationFrame = raf
88
let terrain = null
@@ -34,8 +34,8 @@ class TerrainManager {
3434

3535
distance (chunkId) {
3636
const data = this.chunkTerrain.strToVec(chunkId)
37-
const chunk = vec3(...data)
38-
const chunkP = vec3(...this.playerChunk)
37+
const chunk = new Vector3(...data)
38+
const chunkP = new Vector3(...this.playerChunk)
3939
return chunkP.distanceTo(chunk)
4040
}
4141

0 commit comments

Comments
 (0)