Esempio n. 1
0
    def reload_config(self):
        cvmgr = p3d.ConfigVariableManager.get_global_ptr()

        # Remove previous mappings
        self.clear_aliases()

        # Build mappings from ConfigVariables
        for cvar in cvmgr.variables:
            if cvar.name.startswith(self.event_map_item_prefix):
                cvar = p3d.ConfigVariableString(cvar.name, '')
                outevent = cvar.name.replace(self.event_map_item_prefix, '')

                for i in range(cvar.get_num_words()):
                    inevent = cvar.get_word(i)

                    if inevent == outevent:
                        # Prevent circular reference
                        self.notify.warning(
                            "skipping circular reference mapping {} to {}".
                            format(inevent, outevent))
                        continue

                    self.add_alias(inevent, outevent)

        self.notify.info("Loaded Event Map\n{}".format(
            pprint.pformat(self.input_map)))

        # Listen for events
        for trigger, events in self.input_map.items():
            self.accept(trigger, self.send, [events, ''])
            self.accept(trigger + '-up', self.send, [events, '-up'])
            self.accept(trigger + '-repeat', self.send, [events, '-repeat'])
Esempio 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))
Esempio n. 3
0
def get_path(name):
    return ROOT_PATH.joinpath(p3d.ConfigVariableString(name, "").get_value())
Esempio n. 4
0
import logging

# load panda configuration
ROOT_PATH = path(__path__[0]).joinpath("../../").abspath()
p3d.loadPrcFile(path.joinpath(ROOT_PATH, "Config.prc"))


def get_path(name):
    return ROOT_PATH.joinpath(p3d.ConfigVariableString(name, "").get_value())


CPO_PATH = get_path("cpo-path")
RENDER_PATH = get_path("render-path")
SIM_PATH = get_path("sim-path")
SIM_SCRIPT_PATH = get_path("sim-script-path")
RENDER_SCRIPT_PATH = get_path("render-script-path")
EXP_PATH = get_path("experiment-path")
DATA_PATH = get_path("data-path")
EGG_PATH = get_path("egg-path")
TEXTURE_PATH = get_path("texture-path")
BIN_PATH = get_path("bin-path")
FIG_PATH = get_path("figures-path")
RESULTS_PATH = get_path("results-path")

p3d.getModelPath().appendDirectory(EGG_PATH)
p3d.getModelPath().appendDirectory(TEXTURE_PATH)

LOGLEVEL = p3d.ConfigVariableString("loglevel", "warn").get_value().upper()
FORMAT = '%(levelname)s -- %(processName)s/%(filename)s -- %(message)s'
logging.basicConfig(level=LOGLEVEL, format=FORMAT)
Esempio n. 5
0
def get_saves_dir():
    savespath = p3d.ConfigVariableString('mercury-saves-dir', '$USER_APPDATA/saves')
    savesdir = parse_path(savespath)
    return savesdir
import pytest
from .conftest import simulate_until

# Skip these tests if we can't import bullet.
bullet = pytest.importorskip("panda3d.bullet")
from panda3d import core

bullet_filter_algorithm = core.ConfigVariableString('bullet-filter-algorithm')


def test_tick(world):
    fired = []

    def callback(cd):
        fired.append(isinstance(cd, bullet.BulletTickCallbackData))

    world.set_tick_callback(callback, False)

    assert fired == []

    world.do_physics(0.1)

    assert fired == [True]

    world.clear_tick_callback()

    world.do_physics(0.1)

    assert fired == [True]

Esempio n. 7
0
    def __init__(self):
        super().__init__()

        # Background Image
        bgnode.generate(self.root_node, 'arena')
        bgnode.generate(self.root_node, 'arena', True)

        # Background Music
        self.play_bg_music('the_last_encounter')

        # Arena
        self.arena = Arena(self.root_node, 10, 10)
        self.selected_tile = (0, 0)
        self.move_range_tiles = []
        self.ability_range_tiles = []

        self.player = base.blackboard['player']

        # Player Combatants
        self.player_combatants = [
            Combatant(mon, self.root_node) for mon in self.player.monsters
        ]
        random_placement = p3d.ConfigVariableBool(
            'mercury-random-combat-placement', True).get_value()
        possible_positions = [(x, y) for x in range(2)
                              for y in range(self.arena.sizey - 1)]
        if random_placement:
            placements = random.sample(possible_positions,
                                       len(self.player_combatants))
        else:
            placements = possible_positions
        for combatant, placement in zip(self.player_combatants, placements):
            self.move_combatant_to_tile(combatant, placement, True)
            combatant.set_h(90)
        self.starting_tile_position = (0, 0)

        # Enemy Combatants
        default_combat_type = p3d.ConfigVariableString(
            'mercury-default-combat-type', 'skirmish')
        self.combat_type = base.blackboard.get('combat_type',
                                               default_combat_type)
        if self.combat_type == 'tournament':
            num_enemies = {1: 3, 2: 5, 3: 8}.get(self.player.rank, 8)
        else:
            num_enemies = len(self.player_combatants)
        self.enemy_combatants = [
            Combatant(Monster.gen_random(f'combatant{i}', 1), self.root_node)
            for i in range(num_enemies)
        ]
        possible_positions = [
            (x, y)
            for x in range(self.arena.sizex - 1, self.arena.sizex - 3, -1)
            for y in range(self.arena.sizey - 1)
        ]
        placements = random.sample(possible_positions,
                                   len(self.enemy_combatants))
        for combatant, placement in zip(self.enemy_combatants, placements):
            self.move_combatant_to_tile(combatant, placement, True)
            combatant.set_h(-90)

        # Setup Lighting
        arena_world_center = self.arena.tile_coord_to_world(self.arena.center)
        CommonLighting(self.root_node, arena_world_center)

        # Setup Camera
        base.camera.set_pos(-15, -15, 15)
        lookat_offset = p3d.LVector3(-3, -3, 0)
        base.camera.look_at(
            self.arena.tile_coord_to_world(self.arena.center) + lookat_offset)

        # Setup UI
        self.load_ui('combat')

        # Setup AI
        self.aicontroller = AiController(self.arena, self, self.root_node)

        # Set initial input state
        self.input_state = 'END_TURN'
Esempio n. 8
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())