Exemplo n.º 1
0
        def create_chunk(far):

            for our_level in our_levels:
                for chunk in self.chunks[our_level]:
                    if self.status_chunks.has_key(chunk):
                        if self.status_chunks[chunk]:
                            center, size, level = chunk
                            length = VBase2.length(
                                Vec2(center[0], center[1]) -
                                Vec2(self.chunks_map.charX,
                                     self.chunks_map.charY))
                            # hide mark, if distance for chunk too long
                            if length > far:
                                self.status_chunks[chunk] = False
                            if length <= far:
                                if not self.chunks_models.has_key(chunk):
                                    self.mutex.acquire()
                                    self.chunks_models[chunk] = ChunkModel(
                                        self.config, self.world.map3d,
                                        self.world.voxels, center[0],
                                        center[1], size,
                                        self.chunks_map.chunk_len,
                                        self.world.params.chunks_tex,
                                        self.world.params.water_tex)
                                    self.mutex.release()
                                    if not Force:
                                        time.sleep(self.config.chunk_sleep)
Exemplo n.º 2
0
    def remove_far(self):
        """Remove far chunk models
        """
        # TODO: add delete cube event

        # For get minimum size of visible chunks

        t = time.time()
        chunks = self.chunks_models.keys()

        # calculate distance for remove chunks - LOD
        remove_far = self.far * 3

        for chunk in chunks:
            # if chunk was marked for show
            length = VBase2.length(
                Vec2(chunk[0][0], chunk[0][1]) -
                Vec2(self.chunks_map.charX, self.chunks_map.charY))
            # hide mark, if distance for chunk too long
            if length >= remove_far:
                if self.chunks_models.has_key(chunk):
                    self.mutex.acquire()
                    self.chunks_models[chunk].removeNode()
                    del self.chunks_models[chunk]
                    del self.status_chunks[chunk]
                    self.mutex.release()

        print 'remove: ', time.time() - t
Exemplo n.º 3
0
        def create_chunk(far):

            for our_level in our_levels:
                for chunk in self.chunks[our_level]:
                    if self.status_chunks.has_key(chunk):
                        if self.status_chunks[chunk]:
                            center, size, level = chunk
                            length = VBase2.length(Vec2(center[0], center[1]) - Vec2(self.chunks_map.charX,
                                                                             self.chunks_map.charY
                                                                             ))
                            # hide mark, if distance for chunk too long
                            if length > far:
                                self.status_chunks[chunk] = False
                            if length <= far:
                                if not self.chunks_models.has_key(chunk):
                                    self.mutex.acquire()
                                    self.chunks_models[chunk] = ChunkModel(self.config, self.world.map3d,
                                                                   self.world.voxels,
                                                                   center[0], center[1], size,
                                                                   self.chunks_map.chunk_len,
                                                                   self.world.params.chunks_tex,
                                                                   self.world.params.water_tex
                                                                   )
                                    self.mutex.release()
                                    if not Force:
                                        time.sleep(self.config.chunk_sleep)
Exemplo n.º 4
0
    def remove_far(self):
        """Remove far chunk models
        """
        # TODO: add delete cube event

        # For get minimum size of visible chunks

        t = time.time()
        chunks = self.chunks_models.keys()

        # calculate distance for remove chunks - LOD
        remove_far = self.far * 3

        for chunk in chunks:
            # if chunk was marked for show
            length = VBase2.length(Vec2(chunk[0][0], chunk[0][1]) - Vec2(self.chunks_map.charX,
                                                             self.chunks_map.charY
                                                             ))
            # hide mark, if distance for chunk too long
            if length >= remove_far:
                if self.chunks_models.has_key(chunk):
                    self.mutex.acquire()
                    self.chunks_models[chunk].removeNode()
                    del self.chunks_models[chunk]
                    del self.status_chunks[chunk]
                    self.mutex.release()

        print 'remove: ', time.time() - t
Exemplo n.º 5
0
    def update(self, Force=False):
        """Create and show chunk models
        """
        # TODO: add delete cube event

        # For get minimum size of visible chunks

        t = time.time()

        our_height = abs(self.chunks_map.charZ - self.chunks_map.land_z)
        for i in xrange(self.config.min_level, self.config.size_mod):
            if our_height <= 2**i:
                our_level = i
                break

        def create_chunk(far):

            for our_level in our_levels:
                for chunk in self.chunks[our_level]:
                    if self.status_chunks.has_key(chunk):
                        if self.status_chunks[chunk]:
                            center, size, level = chunk
                            length = VBase2.length(
                                Vec2(center[0], center[1]) -
                                Vec2(self.chunks_map.charX,
                                     self.chunks_map.charY))
                            # hide mark, if distance for chunk too long
                            if length > far:
                                self.status_chunks[chunk] = False
                            if length <= far:
                                if not self.chunks_models.has_key(chunk):
                                    self.mutex.acquire()
                                    self.chunks_models[chunk] = ChunkModel(
                                        self.config, self.world.map3d,
                                        self.world.voxels, center[0],
                                        center[1], size,
                                        self.chunks_map.chunk_len,
                                        self.world.params.chunks_tex,
                                        self.world.params.water_tex)
                                    self.mutex.release()
                                    if not Force:
                                        time.sleep(self.config.chunk_sleep)

        for chunk in self.status_chunks:
            self.status_chunks[chunk] = False

        self.generate(our_level)
        land_level = 0

        if self.config.low_mount_level[
                1] >= self.chunks_map.land_z >= self.config.low_mount_level[0]:
            land_level = 1

        if self.config.mid_mount_level[
                1] >= self.chunks_map.land_z >= self.config.mid_mount_level[0]:
            land_level = 2

        if self.config.high_mount_level[
                1] >= self.chunks_map.land_z >= self.config.high_mount_level[0]:
            land_level = 3

        lim_level = our_level + self.config.count_levels[land_level]

        if lim_level > self.config.size_mod:
            lim_level = self.config.size_mod

        our_levels = range(our_level, lim_level)

        # calculate distance for show or hide chunks - LOD
        self.far = (2**max(our_levels)) * 2
        self.world.params.fog.setLinearRange(0, self.far)
        self.world.gui.camLens.setFar(self.far * 2)

        t = time.time()
        try:
            tree_chunks = self.chunks[self.config.tree_level]
            for chunk in tree_chunks:
                center, size, level = chunk
                length = VBase2.length(
                    Vec2(center[0], center[1]) -
                    Vec2(self.chunks_map.charX, self.chunks_map.charY))
                # hide mark, if distance for chunk too long
                if length <= size:
                    self.world.forest.add_trees(chunk)
        except KeyError, e:
            pass
Exemplo n.º 6
0
    def update(self, Force = False):
        """Create and show chunk models
        """
        # TODO: add delete cube event

        # For get minimum size of visible chunks

        t = time.time()

        our_height = abs(self.chunks_map.charZ - self.chunks_map.land_z)
        for i in xrange(self.config.min_level, self.config.size_mod):
            if our_height <= 2 ** i:
                our_level = i
                break


        def create_chunk(far):

            for our_level in our_levels:
                for chunk in self.chunks[our_level]:
                    if self.status_chunks.has_key(chunk):
                        if self.status_chunks[chunk]:
                            center, size, level = chunk
                            length = VBase2.length(Vec2(center[0], center[1]) - Vec2(self.chunks_map.charX,
                                                                             self.chunks_map.charY
                                                                             ))
                            # hide mark, if distance for chunk too long
                            if length > far:
                                self.status_chunks[chunk] = False
                            if length <= far:
                                if not self.chunks_models.has_key(chunk):
                                    self.mutex.acquire()
                                    self.chunks_models[chunk] = ChunkModel(self.config, self.world.map3d,
                                                                   self.world.voxels,
                                                                   center[0], center[1], size,
                                                                   self.chunks_map.chunk_len,
                                                                   self.world.params.chunks_tex,
                                                                   self.world.params.water_tex
                                                                   )
                                    self.mutex.release()
                                    if not Force:
                                        time.sleep(self.config.chunk_sleep)

        for chunk in self.status_chunks:
            self.status_chunks[chunk] = False

        self.generate(our_level)
        land_level = 0

        if self.config.low_mount_level[1] >= self.chunks_map.land_z >= self.config.low_mount_level[0]:
            land_level = 1

        if self.config.mid_mount_level[1] >= self.chunks_map.land_z >= self.config.mid_mount_level[0]:
            land_level = 2

        if self.config.high_mount_level[1] >= self.chunks_map.land_z >= self.config.high_mount_level[0]:
            land_level = 3

        lim_level = our_level + self.config.count_levels[land_level]

        if lim_level > self.config.size_mod:
            lim_level = self.config.size_mod

        our_levels = range(our_level, lim_level)

        # calculate distance for show or hide chunks - LOD
        self.far = (2 ** max(our_levels)) * 2
        self.world.params.fog.setLinearRange(0, self.far)
        self.world.gui.camLens.setFar(self.far * 2)

        t = time.time()
        try:
            tree_chunks = self.chunks[self.config.tree_level]
            for chunk in tree_chunks:
                center, size, level = chunk
                length = VBase2.length(Vec2(center[0], center[1]) - Vec2(self.chunks_map.charX,
                                                                 self.chunks_map.charY
                                                                 ))
                # hide mark, if distance for chunk too long
                if length <= size:
                    self.world.forest.add_trees(chunk)
        except KeyError, e:
            pass