-
Notifications
You must be signed in to change notification settings - Fork 68
/
world.py
39 lines (30 loc) · 1.17 KB
/
world.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from settings import *
from world_objects.chunk import Chunk
from voxel_handler import VoxelHandler
class World:
def __init__(self, app):
self.app = app
self.chunks = [None for _ in range(WORLD_VOL)]
self.voxels = np.empty([WORLD_VOL, CHUNK_VOL], dtype='uint8')
self.build_chunks()
self.build_chunk_mesh()
self.voxel_handler = VoxelHandler(self)
def update(self):
self.voxel_handler.update()
def build_chunks(self):
for x in range(WORLD_W):
for y in range(WORLD_H):
for z in range(WORLD_D):
chunk = Chunk(self, position=(x, y, z))
chunk_index = x + WORLD_W * z + WORLD_AREA * y
self.chunks[chunk_index] = chunk
# put the chunk voxels in a separate array
self.voxels[chunk_index] = chunk.build_voxels()
# get pointer to voxels
chunk.voxels = self.voxels[chunk_index]
def build_chunk_mesh(self):
for chunk in self.chunks:
chunk.build_mesh()
def render(self):
for chunk in self.chunks:
chunk.render()