text
stringlengths 1
93.6k
|
|---|
logger = logging.getLogger('%s' % 'client')
|
logger.info('connect failed...!')
|
time.sleep(10)
|
continue
|
gevent.spawn(HKClient, mainsocket, 0, 1)
|
# 发送心跳
|
if pingtime + 20 < time.time() and pingtime != 0:
|
sendpack(mainsocket, Ping())
|
pingtime = time.time()
|
time.sleep(1)
|
except socket.error:
|
pingtime = 0
|
except KeyboardInterrupt:
|
sys.exit()
|
# <FILESEP>
|
from settings import *
|
from meshes.chunk_mesh_builder import get_chunk_index
|
class VoxelHandler:
|
def __init__(self, world):
|
self.app = world.app
|
self.chunks = world.chunks
|
# ray casting result
|
self.chunk = None
|
self.voxel_id = None
|
self.voxel_index = None
|
self.voxel_local_pos = None
|
self.voxel_world_pos = None
|
self.voxel_normal = None
|
self.interaction_mode = 0 # 0: remove voxel 1: add voxel
|
self.new_voxel_id = DIRT
|
def add_voxel(self):
|
if self.voxel_id:
|
# check voxel id along normal
|
result = self.get_voxel_id(self.voxel_world_pos + self.voxel_normal)
|
# is the new place empty?
|
if not result[0]:
|
_, voxel_index, _, chunk = result
|
chunk.voxels[voxel_index] = self.new_voxel_id
|
chunk.mesh.rebuild()
|
# was it an empty chunk
|
if chunk.is_empty:
|
chunk.is_empty = False
|
def rebuild_adj_chunk(self, adj_voxel_pos):
|
index = get_chunk_index(adj_voxel_pos)
|
if index != -1:
|
self.chunks[index].mesh.rebuild()
|
def rebuild_adjacent_chunks(self):
|
lx, ly, lz = self.voxel_local_pos
|
wx, wy, wz = self.voxel_world_pos
|
if lx == 0:
|
self.rebuild_adj_chunk((wx - 1, wy, wz))
|
elif lx == CHUNK_SIZE - 1:
|
self.rebuild_adj_chunk((wx + 1, wy, wz))
|
if ly == 0:
|
self.rebuild_adj_chunk((wx, wy - 1, wz))
|
elif ly == CHUNK_SIZE - 1:
|
self.rebuild_adj_chunk((wx, wy + 1, wz))
|
if lz == 0:
|
self.rebuild_adj_chunk((wx, wy, wz - 1))
|
elif lz == CHUNK_SIZE - 1:
|
self.rebuild_adj_chunk((wx, wy, wz + 1))
|
def remove_voxel(self):
|
if self.voxel_id:
|
self.chunk.voxels[self.voxel_index] = 0
|
self.chunk.mesh.rebuild()
|
self.rebuild_adjacent_chunks()
|
def set_voxel(self):
|
if self.interaction_mode:
|
self.add_voxel()
|
else:
|
self.remove_voxel()
|
def switch_mode(self):
|
self.interaction_mode = not self.interaction_mode
|
def update(self):
|
self.ray_cast()
|
def ray_cast(self):
|
# start point
|
x1, y1, z1 = self.app.player.position
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.