Ejemplo n.º 1
0
def get_buffer(render_node, buff_size=None, clear_color=core.Vec4(0, 0, 0, 1)):
    buff_size = buff_size or core.ConfigVariableInt('portal-buffer-size',
                                                    1024).get_value()
    if _free_buffers:
        bobj = _free_buffers.pop()
        bobj.pipeline.render_node = render_node
        bobj.cam.reparent_to(render_node)
        return bobj
    basic = core.Filename.expand_from('$MAIN_DIR/assets/textures/basic_1.exr')
    basic = loader.load_texture(basic)
    buff = base.win.make_texture_buffer('Room Buffer', buff_size, buff_size)
    buff.set_clear_color(clear_color)
    buff.set_clear_color_active(True)
    buff.set_sort(-100)
    fog = core.Fog("Fog Name")
    fog.set_color(0, 0, 0)
    fog.set_exp_density(0.04)
    render_node.set_fog(fog)
    tex = buff.get_texture()
    cam = base.make_camera(buff)
    cam.reparent_to(render_node)
    pipeline = simplematcap.init(basic,
                                 render_node=render_node,
                                 light_dir=core.Vec3(-1, -1, 0.5).normalized(),
                                 hueshift=core.Vec3(random.uniform(-1.0, 1.0),
                                                    random.uniform(-1.0, 1.0),
                                                    20))
    return BufferObject(buff, tex, cam, pipeline)
Ejemplo n.º 2
0
 def __init__(self, name, bases, dct):
     if self.name is None:
         host = p3d.ConfigVariableString('pstats-host', 'localhost').value
         port = p3d.ConfigVariableInt('pstats-port', 5185).value
         if not self.client.connect(host, port):
             if p3d.ConfigVariableBool('pstats-required', False).value:
                 raise ConnectionError(f'failed to connect: {host}:{port}')
     else:
         self._trunk.setdefault(self.name, _PStatBranch(self))
Ejemplo n.º 3
0
def test_load_unload_page():
    var = core.ConfigVariableInt("test-var", 1)
    assert var.value == 1

    page = core.load_prc_file_data("test_load_unload_page", "test-var 2")
    assert page
    assert var.value == 2

    assert core.unload_prc_file(page)
    assert var.value == 1
Ejemplo n.º 4
0
 def __init__(self, queue_name, **kwargs):
     super().__init__()
     self.__queue_name = queue_name
     self.__poll_interval = kwargs.get(
         'interval',
         core.ConfigVariableInt('sqs-default-poll', 30).value)
     self.__message_attribute_names = kwargs.get('message_attribute_names',
                                                 [])
     self.__attribute_names = kwargs.get('attribute_names', [])
     self.__endpoint_url = kwargs.get('endpoint_url', None)
     self.__wait_time = kwargs.get(
         'wait_time',
         core.ConfigVariableInt('sqs-default-wait-time', 0).value)
     self.__ssl = kwargs.get('ssl', True)
     self.__max_number_of_messages = kwargs.get(
         'max_number_of_messages',
         core.ConfigVariableInt('sqs-default-max-msg', 1).value)
     self.__poll_task = None
     self.__session = boto3.session.Session()
     self.__region_name = kwargs.get('region_name',
                                     self.__session.region_name)
     self.__resource = None
     self.__queue = None
Ejemplo n.º 5
0
    def _set_use_330(self, use_330):
        if use_330 is not None:
            self.use_330 = use_330
        else:
            self.use_330 = False

            cvar = p3d.ConfigVariableInt('gl-version')
            gl_version = [
                cvar.get_word(i) for i in range(cvar.get_num_words())
            ]
            if len(gl_version
                   ) >= 2 and gl_version[0] >= 3 and gl_version[1] >= 2:
                # Not exactly accurate, but setting this variable to '3 2' is common for disabling
                # the fixed-function pipeline and 3.2 support likely means 3.3 support as well.
                self.use_330 = True
Ejemplo n.º 6
0
    def __buildInstallPlans(self):
        """ Sets up self.installPlans, a list of one or more "plans"
        to download and install the package. """

        pc = PStatCollector(':App:PackageInstaller:buildInstallPlans')
        pc.start()

        self.hasPackage = False

        if self.host.appRunner and self.host.appRunner.verifyContents == self.host.appRunner.P3DVCNever:
            # We're not allowed to download anything.
            self.installPlans = []
            pc.stop()
            return

        if self.asMirror:
            # If we're just downloading a mirror archive, we only need
            # to get the compressed archive file.

            # Build a one-item install plan to download the compressed
            # archive.
            downloadSize = self.compressedArchive.size
            func = lambda step, fileSpec=self.compressedArchive: self.__downloadFile(
                step, fileSpec, allowPartial=True)

            step = self.InstallStep(func, downloadSize, self.downloadFactor,
                                    'download')
            installPlan = [step]
            self.installPlans = [installPlan]
            pc.stop()
            return

        # The normal download process.  Determine what we will need to
        # download, and build a plan (or two) to download it all.
        self.installPlans = None

        # We know we will at least need to unpack the archive contents
        # at the end.
        unpackSize = 0
        for file in self.extracts:
            unpackSize += file.size
        step = self.InstallStep(self.__unpackArchive, unpackSize,
                                self.unpackFactor, 'unpack')
        planA = [step]

        # If the uncompressed archive file is good, that's all we'll
        # need to do.
        self.uncompressedArchive.actualFile = None
        if self.uncompressedArchive.quickVerify(self.getPackageDir(),
                                                notify=self.notify):
            self.installPlans = [planA]
            pc.stop()
            return

        # Maybe the compressed archive file is good.
        if self.compressedArchive.quickVerify(self.getPackageDir(),
                                              notify=self.notify):
            uncompressSize = self.uncompressedArchive.size
            step = self.InstallStep(self.__uncompressArchive, uncompressSize,
                                    self.uncompressFactor, 'uncompress')
            planA = [step] + planA
            self.installPlans = [planA]
            pc.stop()
            return

        # Maybe we can download one or more patches.  We'll come back
        # to that in a minute as plan A.  For now, construct plan B,
        # which will be to download the whole archive.
        planB = planA[:]

        uncompressSize = self.uncompressedArchive.size
        step = self.InstallStep(self.__uncompressArchive, uncompressSize,
                                self.uncompressFactor, 'uncompress')
        planB = [step] + planB

        downloadSize = self.compressedArchive.size
        func = lambda step, fileSpec=self.compressedArchive: self.__downloadFile(
            step, fileSpec, allowPartial=True)

        step = self.InstallStep(func, downloadSize, self.downloadFactor,
                                'download')
        planB = [step] + planB

        # Now look for patches.  Start with the md5 hash from the
        # uncompressedArchive file we have on disk, and see if we can
        # find a patch chain from this file to our target.
        pathname = Filename(self.getPackageDir(),
                            self.uncompressedArchive.filename)
        fileSpec = self.uncompressedArchive.actualFile
        if fileSpec is None and pathname.exists():
            fileSpec = FileSpec()
            fileSpec.fromFile(self.getPackageDir(),
                              self.uncompressedArchive.filename)
        plan = None
        if fileSpec:
            plan = self.__findPatchChain(fileSpec)
        if plan:
            # We can download patches.  Great!  That means this is
            # plan A, and the full download is plan B (in case
            # something goes wrong with the patching).
            planA = plan + planA
            self.installPlans = [planA, planB]
        else:
            # There are no patches to download, oh well.  Stick with
            # plan B as the only plan.
            self.installPlans = [planB]

        # In case of unexpected failures on the internet, we will retry
        # the full download instead of just giving up.
        retries = core.ConfigVariableInt('package-full-dl-retries',
                                         1).getValue()
        for retry in range(retries):
            self.installPlans.append(planB[:])

        pc.stop()
Ejemplo n.º 7
0
    def __init__(self):
        ShowBase.__init__(self)
        pman.shim.init(self)
        base.enable_particles()
        gdb = gamedb.get_instance()

        # Render pipeline
        self.set_background_color((0, 0, 0, 1))
        self.render.set_antialias(p3d.AntialiasAttrib.MAuto)
        self.render_pipeline = simplepbr.init(
            max_lights=4,
            msaa_samples=p3d.ConfigVariableInt('msaa-samples', 4).get_value(),
            enable_shadows=p3d.ConfigVariableBool('enable-shadows',
                                                  True).get_value(),
            exposure=5,
        )

        # Controls
        self.event_mapper = eventmapper.EventMapper()
        self.disable_mouse()
        self.accept('quit', sys.exit)
        self.accept('toggle-buffer-viewer', self.bufferViewer.toggleEnable)
        self.accept('toggle-oobe', self.oobe)
        self.accept('save-screenshot', self.screenshot)

        # Global storage
        self.blackboard = {}
        default_save = p3d.ConfigVariableString('mercury-default-save',
                                                '').get_value()
        if default_save:
            saveloc = os.path.join(
                pathutils.get_saves_dir(),
                default_save,
            )
            if not saveloc.endswith('.sav'):
                saveloc += '.sav'
            if os.path.exists(saveloc):
                with open(saveloc) as savefile:
                    self.blackboard['player'] = PlayerData.load(savefile)
        default_monster_id = p3d.ConfigVariableString(
            'mercury-default-monster', '').get_value()
        if default_monster_id:
            default_monster = Monster(gdb['monsters'][default_monster_id])
        else:
            default_form = p3d.ConfigVariableString('mercury-default-form',
                                                    'mine').get_value()
            default_monster = Monster.make_new('player_monster',
                                               form_id=default_form)

        if 'player' not in self.blackboard:
            self.blackboard['player'] = PlayerData()
            self.blackboard['player'].monsters = [default_monster]

        # UI
        default_font = self.loader.load_font('fonts/BalooThambi2-Medium.ttf',
                                             pixelsPerUnit=90)
        p3d.TextNode.set_default_font(default_font)

        # Game states
        initial_state = p3d.ConfigVariableString('mercury-initial-state',
                                                 'Title').get_value()
        self.gman = gamestates.StateManager(initial_state)

        def update_state(task):
            self.gman.update()
            return task.cont

        self.taskMgr.add(update_state, 'GameState Update')

        # Get volume levels from config
        self.musicManager.set_volume(
            p3d.ConfigVariableDouble('audio-music-volume', 1.0).get_value())
        self.sfxManagerList[0].set_volume(
            p3d.ConfigVariableDouble('audio-sfx-volume', 1.0).get_value())