Exemple #1
0
    def repaint(self, level):
        """divide or mark to show this chunk node, depend - distance to char coords
        """
        if self.level > level:
            #divide_dist = self.config.chunk_len * (3 ** (25 - self.level))
            #show_dist = self.chunks_map.far
            s2 = self.size * self.size
            s2 += s2
            divide_dist = math.sqrt(s2)
            length = VBase3.length(Vec3(self.center) - Vec3(self.chunks_map.charX,
                                                                self.chunks_map.charY,
                                                                self.chunks_map.charZ))
            #length = VBase2.length(Vec2(self.center[0], self.center[1]) - Vec2(self.chunks_map.charX,
                                                                #self.chunks_map.charY))

            if length <= divide_dist:
                #print 'Divide: ', divide_dist, self.size, self.level, length
                self.divide(level)
            else:
                self.mark_show()
        else:
            self.mark_show()
Exemple #2
0
    def repaint(self, level):
        """divide or mark to show this chunk node, depend - distance to char coords
        """
        if self.level > level:
            #divide_dist = self.config.chunk_len * (3 ** (25 - self.level))
            #show_dist = self.chunks_map.far
            s2 = self.size * self.size
            s2 += s2
            divide_dist = math.sqrt(s2)
            length = VBase3.length(
                Vec3(self.center) -
                Vec3(self.chunks_map.charX, self.chunks_map.charY,
                     self.chunks_map.charZ))
            #length = VBase2.length(Vec2(self.center[0], self.center[1]) - Vec2(self.chunks_map.charX,
            #self.chunks_map.charY))

            if length <= divide_dist:
                #print 'Divide: ', divide_dist, self.size, self.level, length
                self.divide(level)
            else:
                self.mark_show()
        else:
            self.mark_show()
Exemple #3
0
    def show_forest(self, DX, DY, char_far, far, charpos, Force=False):
        """Set to new X

        center X - self.size/2 - DX
        """

        tmp_node = NodePath('tmp')
        self.flatten_node.copyTo(tmp_node)
        self.mutex.acquire()
        tmp_node.reparentTo(self)
        self.flatten_node.removeNode()
        self.mutex.release()
        self.tree_nodes = []
        self.flatten_node = NodePath('flatten_nodes')

        t = time.time()
        count_trees = 0
        for tree_n in self.trees:
            # create or attach
            for coord in self.trees[tree_n]:
                #length_cam_2d = VBase2.length(Vec2(coord[0], coord[1]) - Vec2(charpos[0], charpos[1]))
                length_cam_3d = VBase3.length(Vec3(coord) - Vec3(charpos))
                if char_far >= length_cam_3d <= far:
                    tree = self.world.trees[tree_n]
                    self.tree_nodes.append(NodePath('TreeNode'))
                    tree.copyTo(self.tree_nodes[count_trees])
                    x, y, z = coord
                    self.tree_nodes[count_trees].setPos(x - DX, y - DY, z - 1)
                    count_trees += 1

        print 'Attach detach loop: ', time.time() - t

        if count_trees == 0:
            self.mutex.acquire()
            tmp_node.removeNode()
            self.mutex.release()
            return

        t = time.time()

        self.count_f_nodes = (count_trees / self.trees_in_node) + 1
        self.flatten_nodes = [
            NodePath('flatten_node') for i in xrange(self.count_f_nodes)
        ]
        s = 0
        e = self.trees_in_node
        added = 0
        for node in self.flatten_nodes:
            t_nodes = self.tree_nodes[s:e]
            s += self.trees_in_node
            e += self.trees_in_node
            for t_node in t_nodes:
                t_node.reparentTo(node)
                added += 1
            node.flattenStrong()
            if not Force:
                time.sleep(self.config.tree_sleep)
            node.reparentTo(self.flatten_node)
            if added == count_trees:
                break

        print 'Added: ', added, time.time() - t

        t = time.time()
        self.flatten_node.flattenStrong()
        self.mutex.acquire()
        self.flatten_node.reparentTo(self)
        tmp_node.removeNode()
        self.mutex.release()
        print 'flatten all trees: ', time.time() - t