Ejemplo 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)
Ejemplo 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
Ejemplo 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)
Ejemplo 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
Ejemplo n.º 5
0
    def drawTriangle(self, node, submap_center, submap_xel, triangle_index,
                     nodes_ZTH, open_simplex):
        global god
        center_map = submap_xel
        for d in range(1, Map.radius +
                       1):  # distance from center moving along triangle side t
            center_map = center_map.link[dirs[triangle_index]]
            tmp_map = center_map
            for n in range(
                    0, d
            ):  # each cell from triangle_index triangle edge (included) to next triangle edge (excluded)
                if d == Map.radius and n == 0:
                    cell_z = nodes_ZTH[0][triangle_index]
                    cell_t = nodes_ZTH[1][triangle_index]
                    cell_h = nodes_ZTH[2][triangle_index]
                else:
                    interna = ((nodes_ZTH[0][6], nodes_ZTH[0][triangle_index],
                                nodes_ZTH[0][(triangle_index + 1) % 6]),
                               (nodes_ZTH[1][6], nodes_ZTH[1][triangle_index],
                                nodes_ZTH[1][(triangle_index + 1) % 6]),
                               (nodes_ZTH[2][6], nodes_ZTH[2][triangle_index],
                                nodes_ZTH[2][(triangle_index + 1) % 6]))
                    res = ExaRandom.interpolate(
                        self, interna, Map.radius,
                        (tmp_map.exa.e, tmp_map.exa.x, tmp_map.exa.a))

                    (cell_z, cell_t, cell_h) = res
                cell_z += open_simplex.noise2d(tmp_map.exa.x,
                                               tmp_map.exa.e) / 5

                esterna = god.creation(
                    submap_center,
                    (tmp_map.exa.e, tmp_map.exa.x, tmp_map.exa.a), cell_t,
                    cell_h)  #animale, vegetale, terreno

                #load models

                dx, dy = submap_center
                (q, r) = tmp_map.exa.x, tmp_map.exa.e
                v_center = VBase2(s3 * q, v3s * 2 * (q / 2 + r))

                if esterna[0] != None:
                    self.model.loadAnimal(node, v_center[0] + dx,
                                          v_center[1] + dy, cell_z,
                                          esterna[0].nome)
                if esterna[1] != None:
                    self.model.loadPlant(node, v_center[0] - side + dx,
                                         v_center[1] + dy, cell_z,
                                         esterna[1].nome)

                if esterna[2] != None:
                    terrain_name = esterna[2].nome
                else:
                    terrain_name = "rock"

                self.insertTile(node, submap_center, tmp_map, cell_z,
                                terrain_name)

                tmp_map = tmp_map.link[dirs[(triangle_index + 2) % 6]]
Ejemplo n.º 6
0
 def resetProperties(self):
     self.seaLevel = 0
     self.center = 0
     self.anchor = None
     self.overallSpeed = 0
     self.uvSpeed = Vec2(0, 0)
     self.threshold = 0
     self.radius = 0
     self.uvScale = VBase2(0, 0)
     self.waveEnabled = 0
     self.high = Vec4(0, 0, 0, 0)
     self.mid = VBase4(0, 0, 0, 0)
     self.low = Vec4(0, 0, 0, 0)
Ejemplo n.º 7
0
 def __init__(self):
     self.seaLevel = 0
     self.center = 0
     self.anchor = None
     self.overallSpeed = 0
     self.uvSpeed = Vec2(0, 0)
     self.thresfold = 0
     self.radius = 0
     self.uvScale = VBase2(0, 0)
     self.waveEnabled = 0
     self.high = VBase4(0, 0, 0, 0)
     self.mid = VBase4(0, 0, 0, 0)
     self.low = VBase4(0, 0, 0, 0)
Ejemplo n.º 8
0
    def insertTile(self, node, submap_center, xel: Xel.Xel, tile_z, terrain):
        dx, dy = submap_center
        (q, r) = xel.exa.x, xel.exa.e
        v_center = VBase2(s3 * q, v3s * 2 * (q / 2 + r))

        tile_color = "rock"  #TODO
        #if abs(q) == Map.radius or abs(r) == Map.radius or abs(xel.exa.a) == Map.radius:
        #    tile_color = "yellow"
        #else:  #temporary
        if terrain == "water":
            tile_z = 0
        tile_color = terrain

        return self.model.loadExaTile(node, v_center[0] + dx, v_center[1] + dy,
                                      tile_z, tile_color)
Ejemplo n.º 9
0
    def setup(self):
        # Store current values
        self.entry_background_color = VBase4(base.win.get_clear_color())
        self.entry_cam_pos = VBase3(base.cam.get_pos())
        self.entry_cam_hpr = VBase3(base.cam.get_hpr())
        self.entry_cam_scale = VBase3(base.cam.get_scale())
        self.entry_cam_fov = VBase2(base.cam.node().get_lens().get_fov())

        # Set values for splash
        base.win.set_clear_color((0,0,0,1))
        cam_dist = 2
        base.cam.set_pos(0, -2.2 * cam_dist, 0)
        base.cam.set_hpr(0, 0, 0)
        base.cam.set_scale(1)
        base.cam.node().get_lens().set_fov(45/cam_dist)

        # Set up the splash itself
        self.logo_animation = Actor(asset_path / "panda3d_logo.bam")
        self.logo_animation.reparent_to(render)
        self.logo_animation.set_two_sided(True)

        shader = Shader.load(
            Shader.SL_GLSL,
            vertex=asset_path / "panda3d_logo.vert",
            fragment=asset_path / "panda3d_logo.frag",
        )
        self.logo_animation.set_shader(shader)
        self.logo_animation.set_shader_input("fade", 0.0)
        self.logo_animation.set_shader_input("pattern", self.pattern.value)
        self.logo_animation.set_shader_input("colors", self.colors.value)
        self.logo_animation.set_shader_input("pattern_freq", self.pattern_freq)
        self.logo_animation.set_shader_input("cycle_freq", self.cycle_freq)
        self.logo_sound = base.loader.loadSfx(asset_path / "panda3d_logo.wav")

        # Build interval
        def shader_time(t):
            self.logo_animation.set_shader_input("time", t)
        def fade_background_to_white(t):
            base.win.set_clear_color((t,t,t,1))
            self.logo_animation.set_shader_input("time", t/3.878)
            self.logo_animation.set_shader_input("fade", t)
        def fade_to_black(t):
            base.win.set_clear_color((1-t,1-t,1-t,1))
            #self.logo_animation.set_shader_input("time", t/3.878)
            #self.logo_animation.set_shader_input("fade", t)

        # Timing:
        # 0.000     Start
        # 3.878     Logo is assembled, fade to black-on-whitey
        # 4.878     Black on white achieved
        # <+1.500>  Begin fade to black
        # <+1.741>  Black on black achieved
        # 8.119 Sound ends
        effects = Parallel(
            self.logo_animation.actorInterval(
                "splash",
                loop=False,
            ),
            SoundInterval(
                self.logo_sound,
                loop=False,
            ),
            Sequence(
                LerpFunc(
                    shader_time,
                    fromData=0,
                    toData=1,
                    duration=3.878,
                ),
                LerpFunc(
                    fade_background_to_white,
                    fromData=0,
                    toData=1,
                    duration=1.0,
                ),
                Wait(1.5),
                LerpFunc(
                    fade_to_black,
                    fromData=0,
                    toData=1,
                    duration=1.741,
                ),
            ),
        )
        return effects
Ejemplo n.º 10
0
 def obj_translate(self, value):
     self._obj_translate = VBase2(*value)
Ejemplo n.º 11
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
Ejemplo n.º 12
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