Skip to content

Commit b314f85

Browse files
committed
disposing unloaded Chunks
1 parent 996db0e commit b314f85

File tree

4 files changed

+65
-43
lines changed

4 files changed

+65
-43
lines changed

coffee/client/module/World/World.coffee

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {AnimatedTextureAtlas} from './AnimatedTextureAtlas.js'
55
class World
66
constructor: (options) ->
77
_this=@
8+
@cellBlackList={}
89
@cellMesh={}
910
@cellNeedsUpdate={}
1011
@models={}
@@ -18,6 +19,7 @@ class World
1819
@material=@ATA.material
1920
@cellUpdateTime=null
2021
@renderTime=100
22+
@renderer=options.renderer
2123
@neighbours=[[-1, 0, 0],[1, 0, 0],[0, -1, 0],[0, 1, 0],[0, 0, -1],[0, 0, 1]]
2224

2325
#Utworzenie Workera do obliczania geometrii chunków
@@ -66,16 +68,24 @@ class World
6668
#Updatowanie komórek wokół gracza w danym zasięgu
6769
_this=@
6870
if @cellUpdateTime isnt null and (performance.now()-@cellUpdateTime>@renderTime)
71+
#Ustawianie z defaultu, żeby każdy Mesh był wykasowywany
72+
cellBlackList={}
6973
for k,v of @cellMesh
70-
v.visible=false
74+
if v isnt "disposed"
75+
cellBlackList[k]=true
7176
cell=@cellTerrain.computeCellForVoxel (Math.floor pos.x),(Math.floor pos.y),(Math.floor pos.z)
7277
up=(x,y,z)->
7378
pcell=[cell[0]+x,cell[1]+y,cell[2]+z]
74-
if _this.cellMesh[_this.cellTerrain.vec3(pcell...)]
75-
_this.cellMesh[_this.cellTerrain.vec3(pcell...)].visible=true
76-
if _this.cellNeedsUpdate[_this.cellTerrain.vec3(pcell...)]
79+
cellId=_this.cellTerrain.vec3(pcell...)
80+
#Updatowanie mesha, jeśli był disposed lub potrzebuje updatu
81+
if _this.cellNeedsUpdate[cellId] or _this.cellMesh[cellId] is "disposed"
82+
83+
if _this.cellNeedsUpdate[cellId]
84+
delete _this.cellNeedsUpdate[cellId]
85+
if _this.cellMesh[cellId] is "disposed"
86+
_this.cellMesh[cellId]="disposedX"
7787
_this._genCellGeo pcell...
78-
delete _this.cellNeedsUpdate[_this.cellTerrain.vec3(pcell...)]
88+
cellBlackList[cellId]=false
7989
return
8090
odw={}
8191
for i in [0..radius]
@@ -85,6 +95,14 @@ class World
8595
if not odw["#{x}:#{y}:#{z}"]
8696
up(x,y,z)
8797
odw["#{x}:#{y}:#{z}"]=true
98+
#Kasowanie Meshy, które mają znacznik .todel
99+
for i of cellBlackList
100+
if cellBlackList[i] is true
101+
@cellMesh[i].geometry.dispose()
102+
@cellMesh[i].material.dispose()
103+
@scene.remove @cellMesh[i]
104+
@cellMesh[i]="disposed"
105+
@renderer.renderLists.dispose()
88106
updateCell: (data)->
89107
#Updatowanie komórki z już obliczoną geometrią
90108
cellId=@cellTerrain.vec3 data.info...
@@ -95,7 +113,7 @@ class World
95113
geometry.setAttribute 'normal',new THREE.BufferAttribute(new Float32Array(cell.normals), 3)
96114
geometry.setAttribute 'uv',new THREE.BufferAttribute(new Float32Array(cell.uvs), 2)
97115
geometry.setAttribute 'color',new THREE.BufferAttribute(new Float32Array(cell.colors), 3)
98-
if mesh is undefined
116+
if mesh is undefined or mesh is "disposedX"
99117
@cellMesh[cellId]=new THREE.Mesh geometry,@material
100118
@cellMesh[cellId].frustumCulled = false
101119
_this=@

coffee/client/module/index.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ init = ()->
5959
scene
6060
camera
6161
al
62+
renderer
6263
})
6364

6465
#Połączenie z serwerem i kontrolki gracza

src/client/module/World/World.js

Lines changed: 38 additions & 36 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: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)