def loadMultifilePrcFiles(self, mf, root): """ Loads any prc files in the root of the indicated Multifile, which is presumed to have been mounted already under root. """ # We have to load these prc files explicitly, since the # ConfigPageManager can't directly look inside the vfs. Use # the Multifile interface to find the prc files, rather than # vfs.scanDirectory(), so we only pick up the files in this # particular multifile. cpMgr = ConfigPageManager.getGlobalPtr() for f in mf.getSubfileNames(): fn = Filename(f) if fn.getDirname() == '' and fn.getExtension() == 'prc': pathname = '%s/%s' % (root, f) alreadyLoaded = False for cpi in range(cpMgr.getNumImplicitPages()): if cpMgr.getImplicitPage(cpi).getName() == pathname: # No need to load this file twice. alreadyLoaded = True break if not alreadyLoaded: data = file.open(Filename(pathname), 'r').read() cp = loadPrcFileData(pathname, data) # Set it to sort value 20, behind the implicit pages. cp.setSort(20)
def WritePRCFile(self): page = None customConfigVariables = ["", "motd", "hostname", "tcp-port", "backlog", "udp-port", "isPersistent"] if os.path.exists(prcFile): # load the existing config file page = loadPrcFile(Filename.fromOsSpecific(prcFile)) removeDecls = [] for dec in range(page.getNumDeclarations()): # Check if our variables are given. # NOTE: This check has to be done to not loose our base or other # manual config changes by the user if page.getVariableName(dec) in customConfigVariables: decl = page.modifyDeclaration(dec) removeDecls.append(decl) for dec in removeDecls: page.deleteDeclaration(dec) else: # create a new config file cpMgr = ConfigPageManager.getGlobalPtr() page = cpMgr.makeExplicitPage("Net Core Pandaconfig") # config declarations page.makeDeclaration("motd", str(self.MOTD)) page.makeDeclaration("hostname", str(self.HOSTNAME)) page.makeDeclaration("tcp-port", str(self.TCPPORT)) page.makeDeclaration("backlog", str(self.BACKLOG)) page.makeDeclaration("udp-port", str(self.UDPPORT)) page.makeDeclaration("isPersistent", str(self.ISPERSISTENT)) # create a stream to the specified config file configfile = OFileStream(prcFile) # and now write it out page.write(configfile) # close the stream configfile.close()
def __writeConfig(self): """Save current config in the prc file or if no prc file exists create one. The prc file is set in the prcFile variable""" page = None # These TODO tags are as a reminder for to add any new config # variables that may occur in the future #TODO: get values of configurations here particles = "#f" if not base.particleMgrEnabled else "#t" volume = str(round(base.musicManager.getVolume(), 2)) mute = "#f" if base.AppHasAudioFocus else "#t" #TODO: add any configuration variable name that you have added customConfigVariables = [ "", "particles-enabled", "audio-mute", "audio-volume" ] if os.path.exists(prcFile): # open the config file and change values according to current # application settings page = loadPrcFile(Filename.fromOsSpecific(prcFile)) removeDecls = [] for dec in range(page.getNumDeclarations()): # Check if our variables are given. # NOTE: This check has to be done to not loose our base or other # manual config changes by the user if page.getVariableName(dec) in customConfigVariables: decl = page.modifyDeclaration(dec) removeDecls.append(decl) for dec in removeDecls: page.deleteDeclaration(dec) # NOTE: particles-enabled and audio-mute are custom variables and # have to be loaded by hand at startup # Particles page.makeDeclaration("particles-enabled", particles) # audio page.makeDeclaration("audio-volume", volume) page.makeDeclaration("audio-mute", mute) else: # Create a config file and set default values cpMgr = ConfigPageManager.getGlobalPtr() page = cpMgr.makeExplicitPage("{} Pandaconfig".format(appName)) # set OpenGL to be the default page.makeDeclaration("load-display", "pandagl") # get the displays width and height w = self.pipe.getDisplayWidth() h = self.pipe.getDisplayHeight() # set the window size in the config file page.makeDeclaration("win-size", "{} {}".format(w, h)) # set the default to fullscreen in the config file page.makeDeclaration("fullscreen", "1") # particles page.makeDeclaration("particles-enabled", "#t") # audio page.makeDeclaration("audio-volume", volume) page.makeDeclaration("audio-mute", "#f") # create a stream to the specified config file configfile = OFileStream(prcFile) # and now write it out page.write(configfile) # close the stream configfile.close()
def WritePRCFile(self): page = None customConfigVariables = ["", "tcp-port","udp-port", "server-port", "server-ip","timeout-in-ms"] if os.path.exists(prcFile): # load the existing config file page = loadPrcFile(Filename.fromOsSpecific(prcFile)) removeDecls = [] for dec in range(page.getNumDeclarations()): # Check if our variables are given. # NOTE: This check has to be done to not loose our base or other # manual config changes by the user if page.getVariableName(dec) in customConfigVariables: decl = page.modifyDeclaration(dec) removeDecls.append(decl) for dec in removeDecls: page.deleteDeclaration(dec) else: # create a new config file cpMgr = ConfigPageManager.getGlobalPtr() page = cpMgr.makeExplicitPage("Grim Net Pandaconfig") # config declarations page.makeDeclaration("udp-port", str(self.UDPPORT)) page.makeDeclaration("tcp-port", str(self.TCPPORT)) page.makeDeclaration("server-port", str(self.UDPPORTSERVER)) page.makeDeclaration("server-ip", str(self.SERVERIP)) page.makeDeclaration("timeout-in-ms", str(self.TIMEOUT)) # create a stream to the specified config file configfile = OFileStream(prcFile) # and now write it out page.write(configfile) # close the stream configfile.close()
def __writeConfig(self): """Save current config in the prc file or if no prc file exists create one. The prc file is set in the prcFile variable""" page = None # These TODO tags are as a reminder for to add any new config # variables that may occur in the future #TODO: get values of configurations here particles = "#f" if not base.particleMgrEnabled else "#t" volume = str(round(base.musicManager.getVolume(), 2)) mute = "#f" if base.AppHasAudioFocus else "#t" #TODO: add any configuration variable name that you have added customConfigVariables = [ "", "particles-enabled", "audio-mute", "audio-volume"] if os.path.exists(prcFile): # open the config file and change values according to current # application settings page = loadPrcFile(Filename.fromOsSpecific(prcFile)) removeDecls = [] for dec in range(page.getNumDeclarations()): # Check if our variables are given. # NOTE: This check has to be done to not loose our base or other # manual config changes by the user if page.getVariableName(dec) in customConfigVariables: decl = page.modifyDeclaration(dec) removeDecls.append(decl) for dec in removeDecls: page.deleteDeclaration(dec) # NOTE: particles-enabled and audio-mute are custom variables and # have to be loaded by hand at startup # Particles page.makeDeclaration("particles-enabled", particles) # audio page.makeDeclaration("audio-volume", volume) page.makeDeclaration("audio-mute", mute) else: # Create a config file and set default values cpMgr = ConfigPageManager.getGlobalPtr() page = cpMgr.makeExplicitPage("{} Pandaconfig".format(appName)) # set OpenGL to be the default page.makeDeclaration("load-display", "pandagl") # get the displays width and height w = self.pipe.getDisplayWidth() h = self.pipe.getDisplayHeight() # set the window size in the config file page.makeDeclaration("win-size", "{} {}".format(w, h)) # set the default to fullscreen in the config file page.makeDeclaration("fullscreen", "1") # particles page.makeDeclaration("particles-enabled", "#t") # audio page.makeDeclaration("audio-volume", volume) page.makeDeclaration("audio-mute", "#f") # create a stream to the specified config file configfile = OFileStream(prcFile) # and now write it out page.write(configfile) # close the stream configfile.close()
def WritePRCFile(self): page = None customConfigVariables = [ "", "motd", "hostname", "tcp-port", "backlog", "udp-port", "isPersistent" ] if os.path.exists(prcFile): # load the existing config file page = loadPrcFile(Filename.fromOsSpecific(prcFile)) removeDecls = [] for dec in range(page.getNumDeclarations()): # Check if our variables are given. # NOTE: This check has to be done to not loose our base or other # manual config changes by the user if page.getVariableName(dec) in customConfigVariables: decl = page.modifyDeclaration(dec) removeDecls.append(decl) for dec in removeDecls: page.deleteDeclaration(dec) else: # create a new config file cpMgr = ConfigPageManager.getGlobalPtr() page = cpMgr.makeExplicitPage("Net Core Pandaconfig") # config declarations page.makeDeclaration("motd", str(self.MOTD)) page.makeDeclaration("hostname", str(self.HOSTNAME)) page.makeDeclaration("tcp-port", str(self.TCPPORT)) page.makeDeclaration("backlog", str(self.BACKLOG)) page.makeDeclaration("udp-port", str(self.UDPPORT)) page.makeDeclaration("isPersistent", str(self.ISPERSISTENT)) # create a stream to the specified config file configfile = OFileStream(prcFile) # and now write it out page.write(configfile) # close the stream configfile.close()
def WritePRCFile(self): page = None customConfigVariables = [ "", "tcp-port", "udp-port", "server-port", "server-ip", "timeout-in-ms" ] if os.path.exists(prcFile): # load the existing config file page = loadPrcFile(Filename.fromOsSpecific(prcFile)) removeDecls = [] for dec in range(page.getNumDeclarations()): # Check if our variables are given. # NOTE: This check has to be done to not loose our base or other # manual config changes by the user if page.getVariableName(dec) in customConfigVariables: decl = page.modifyDeclaration(dec) removeDecls.append(decl) for dec in removeDecls: page.deleteDeclaration(dec) else: # create a new config file cpMgr = ConfigPageManager.getGlobalPtr() page = cpMgr.makeExplicitPage("Grim Net Pandaconfig") # config declarations page.makeDeclaration("udp-port", str(self.UDPPORT)) page.makeDeclaration("tcp-port", str(self.TCPPORT)) page.makeDeclaration("server-port", str(self.UDPPORTSERVER)) page.makeDeclaration("server-ip", str(self.SERVERIP)) page.makeDeclaration("timeout-in-ms", str(self.TIMEOUT)) # create a stream to the specified config file configfile = OFileStream(prcFile) # and now write it out page.write(configfile) # close the stream configfile.close()
def writeConfig(self): """Save current config in the prc file or if no prc file exists create one. The prc file is set in the prcFile variable""" page = None # #TODO: add any configuration variable names that you have added # to the dictionaries in the next lines. Set the current # configurations value as value in this dictionary and it's # name as key. configVariables = { # set the window size in the config file "win-size": ConfigVariableString( "win-size", "{} {}".format(self.dispWidth, self.dispHeight)).getValue(), # set the default to fullscreen in the config file "fullscreen": "#t" if ConfigVariableBool("fullscreen", True).getValue() else "#f", # particles "particles-enabled": "#t" if self.particleMgrEnabled else "#f", # audio "audio-volume": str(round(self.musicManager.getVolume(), 2)), "audio-music-active": "#t" if self.musicActive else "#f", "audio-sfx-active": "#t" if self.sfxActive else "#f", # logging "notify-output": os.path.join(basedir, "game.log"), # window "framebuffer-multisample": "#t" if ConfigVariableBool("framebuffer-multisample").getValue() else "#f", "multisamples": str(ConfigVariableInt("multisamples", 8).getValue()), "texture-anisotropic-degree": str(ConfigVariableInt("texture-anisotropic-degree").getValue()), "textures-auto-power-2": "#t" if ConfigVariableBool("textures-auto-power-2", True).getValue() else "#f", # server connection "server-host": base.serverHost.getValue(), } page = None # Check if we have an existing configuration file if os.path.exists(prcFile): # open the config file and change values according to current # application settings page = loadPrcFile(Filename.fromOsSpecific(prcFile)) removeDecls = [] for dec in range(page.getNumDeclarations()): # Check if our variables are given. # NOTE: This check has to be done to not loose our base # or other manual config changes by the user if page.getVariableName(dec) in configVariables.keys(): removeDecls.append(page.modifyDeclaration(dec)) for dec in removeDecls: page.deleteDeclaration(dec) else: # Create a config file and set default values cpMgr = ConfigPageManager.getGlobalPtr() page = cpMgr.makeExplicitPage("Application Config") # always write custom configurations for key, value in configVariables.items(): page.makeDeclaration(key, value) # create a stream to the specified config file configfile = OFileStream(prcFile) # and now write it out page.write(configfile) # close the stream configfile.close()
__all__ = [] from .ShowBase import ShowBase, WindowControls from direct.directnotify.DirectNotifyGlobal import directNotify, giveNotify from panda3d.core import VirtualFileSystem, Notify, ClockObject, PandaSystem from panda3d.core import ConfigPageManager, ConfigVariableManager from panda3d.core import NodePath, PGTop from . import DConfig as config __dev__ = config.GetBool('want-dev', __debug__) vfs = VirtualFileSystem.getGlobalPtr() ostream = Notify.out() globalClock = ClockObject.getGlobalClock() cpMgr = ConfigPageManager.getGlobalPtr() cvMgr = ConfigVariableManager.getGlobalPtr() pandaSystem = PandaSystem.getGlobalPtr() # This is defined here so GUI elements can be instantiated before ShowBase. aspect2d = NodePath(PGTop("aspect2d")) # Set direct notify categories now that we have config directNotify.setDconfigLevels() def run(): assert ShowBase.notify.warning( "run() is deprecated, use base.run() instead") base.run()
__all__ = [] from .ShowBase import ShowBase, WindowControls from direct.directnotify.DirectNotifyGlobal import directNotify, giveNotify from panda3d.core import VirtualFileSystem, Notify, ClockObject, PandaSystem from panda3d.core import ConfigPageManager, ConfigVariableManager from panda3d.core import NodePath, PGTop from panda3d.direct import get_config_showbase config = get_config_showbase() __dev__ = config.GetBool('want-dev', __debug__) vfs = VirtualFileSystem.getGlobalPtr() ostream = Notify.out() globalClock = ClockObject.getGlobalClock() cpMgr = ConfigPageManager.getGlobalPtr() cvMgr = ConfigVariableManager.getGlobalPtr() pandaSystem = PandaSystem.getGlobalPtr() # This is defined here so GUI elements can be instantiated before ShowBase. aspect2d = NodePath(PGTop("aspect2d")) # Set direct notify categories now that we have config directNotify.setDconfigLevels() def run(): assert ShowBase.notify.warning("run() is deprecated, use base.run() instead") base.run() def inspect(anObject): # Don't use a regular import, to prevent ModuleFinder from picking
def __writeConfig(self): """Save current config in the prc file or if no prc file exists create one. The prc file is set in the prcFile variable""" page = None particles = str(base.particleMgrEnabled) textSpeed = str(base.textWriteSpeed) volume = str(round(base.musicManager.getVolume(), 2)) mouseSens = str(base.mouseSensitivity) customConfigVariables = [ "", "particles-enabled", "text-write-speed", "audio-mute", "audio-volume", "control-type", "mouse-sensitivity"] if os.path.exists(prcFile): page = loadPrcFile(Filename.fromOsSpecific(prcFile)) removeDecls = [] for dec in range(page.getNumDeclarations()): # Check if our variables are given. # NOTE: This check has to be done to not loose our base or other # manual config changes by the user if page.getVariableName(dec) in customConfigVariables: decl = page.modifyDeclaration(dec) removeDecls.append(decl) for dec in removeDecls: page.deleteDeclaration(dec) # Particles particles = "#f" if not base.particleMgrEnabled else "#t" page.makeDeclaration("particles-enabled", particles) # speed of the textwriter page.makeDeclaration("text-write-speed", textSpeed) # audio page.makeDeclaration("audio-volume", volume) mute = "#f" if base.AppHasAudioFocus else "#t" page.makeDeclaration("audio-mute", mute) # controls page.makeDeclaration("control-type", base.controlType) page.makeDeclaration("mouse-sensitivity", mouseSens) else: cpMgr = ConfigPageManager.getGlobalPtr() page = cpMgr.makeExplicitPage("%s Pandaconfig"%appName) page.makeDeclaration("load-display", "pandagl") # get the displays width and height w = self.pipe.getDisplayWidth() h = self.pipe.getDisplayHeight() # set the window size in the config file page.makeDeclaration("win-size", "%d %d"%(w, h)) # set the default to fullscreen in the config file page.makeDeclaration("fullscreen", "1") # particles page.makeDeclaration("particles-enabled", "#t") # speed of the textwriter page.makeDeclaration("text-write-speed", textSpeed) # audio page.makeDeclaration("audio-volume", volume) page.makeDeclaration("audio-mute", "#f") # player controls page.makeDeclaration("control-type", base.controlType) page.makeDeclaration("mouse-sensitivity", mouseSens) # create a stream to the specified config file configfile = OFileStream(prcFile) # and now write it out page.write(configfile) # close the stream configfile.close()
import shutil import LoggerPlus from panda3d.core import loadPrcFile, ConfigPageManager from otp.ai.MagicWordGlobal import * logger = LoggerPlus.LoggerPlus() CONFIG_MGR = ConfigPageManager.getGlobalPtr() # Set primary config file (default is first explicitly loaded): CONFIG_FILE = None @magicWord(category=CATEGORY_ADMINISTRATOR, types=[str, str]) def config(var, val): """ Make config variables configurable in-game. Args: var (str): the config variable's name. val (str): the config variable's value. Examples: ~config want-game-tables t (enables tables) ~config want-game-tables f (disables tables) """ if CONFIG_FILE: fileSrc = CONFIG_FILE else: pageIndex = CONFIG_MGR.getNumExplicitPages() - 1 fileSrc = CONFIG_MGR.getExplicitPage(pageIndex).getName() found = False
def __writeConfig(self): """Save current config in the prc file or if no prc file exists create one. The prc file is set in the prcFile variable""" page = None volume = str(round(base.musicManager.getVolume(), 2)) volumeSfx = str(round(base.sfxManagerList[0].getVolume(), 2)) mute = "#f" if base.AppHasAudioFocus else "#t" difficuty = str(base.difficulty) customConfigVariables = [ "", "audio-mute", "audio-volume", "audio-volume-sfx", "difficulty" ] if os.path.exists(prcFile): # open the config file and change values according to current # application settings page = loadPrcFile(prcFile) removeDecls = [] for dec in range(page.getNumDeclarations()): # Check if our variables are given. # NOTE: This check has to be done to not loose our base or other # manual config changes by the user if page.getVariableName(dec) in customConfigVariables: decl = page.modifyDeclaration(dec) removeDecls.append(decl) for dec in removeDecls: page.deleteDeclaration(dec) # NOTE: audio-mute are custom variables and # have to be loaded by hand at startup # audio page.makeDeclaration("audio-volume", volume) page.makeDeclaration("audio-volume-sfx", volumeSfx) page.makeDeclaration("audio-mute", mute) page.makeDeclaration("difficulty", difficuty) else: # Create a config file and set default values cpMgr = ConfigPageManager.getGlobalPtr() page = cpMgr.makeExplicitPage("App Pandaconfig") # set OpenGL to be the default page.makeDeclaration("load-display", "pandagl") # get the displays width and height w = self.pipe.getDisplayWidth() h = self.pipe.getDisplayHeight() # set the window size in the config file page.makeDeclaration("win-size", "%d %d" % (w, h)) # set the default to fullscreen in the config file page.makeDeclaration("fullscreen", "1") # audio page.makeDeclaration("audio-volume", volume) page.makeDeclaration("audio-volume-sfx", volumeSfx) page.makeDeclaration("audio-mute", "#f") page.makeDeclaration("sync-video", "1") page.makeDeclaration("textures-auto-power-2", "1") page.makeDeclaration("framebuffer-multisample", "1") page.makeDeclaration("multisamples", "2") page.makeDeclaration("texture-anisotropic-degree", "0") page.makeDeclaration("difficulty", 0) # create a stream to the specified config file configfile = OFileStream(prcFile) # and now write it out page.write(configfile) # close the stream configfile.close()
import shutil import LoggerPlus from panda3d.core import loadPrcFile, ConfigPageManager from otp.ai.MagicWordGlobal import * logger = LoggerPlus.LoggerPlus() CONFIG_MGR = ConfigPageManager.getGlobalPtr() # Set primary config file (default is first explicitly loaded): CONFIG_FILE = None @magicWord(category=CATEGORY_ADMINISTRATOR, types=[str, str]) def config(var, val): """ Make config variables configurable in-game. Args: var (str): the config variable's name. val (str): the config variable's value. Examples: ~config want-game-tables t (enables tables) ~config want-game-tables f (disables tables) """ if CONFIG_FILE: fileSrc = CONFIG_FILE else: pageIndex = CONFIG_MGR.getNumExplicitPages() - 1 fileSrc = CONFIG_MGR.getExplicitPage(pageIndex).getName()
def __init__(self): #: The directory containing the main Python file of this application. self.mainDir = ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR") self.main_dir = self.mainDir self.wantStats = self.config.GetBool('want-pstats', 0) # Do you want to enable a fixed simulation timestep? Setting this true # only means that the builtin resetPrevTransform and collisionLoop # tasks are added onto the simTaskMgr instead of taskMgr, which runs at # a fixed time step. You can still add your own fixed timestep tasks # when this is false, it only has to do with builtin simulation tasks. self.fixedSimulationStep = self.config.GetBool( 'want-fixed-simulation-step', 0) #: The global event manager, as imported from `.EventManagerGlobal`. self.eventMgr = eventMgr #: The global messenger, as imported from `.MessengerGlobal`. self.messenger = messenger #: The global bulletin board, as imported from `.BulletinBoardGlobal`. self.bboard = bulletinBoard #: The global task manager, as imported from `.TaskManagerGlobal`. self.taskMgr = taskMgr self.task_mgr = taskMgr #: The global simulation task manager, as imported from `.TaskManagerGlobal` self.simTaskMgr = simTaskMgr self.sim_task_mgr = simTaskMgr #: The global job manager, as imported from `.JobManagerGlobal`. self.jobMgr = jobMgr #: `.Loader.Loader` object. self.loader = Loader(self) # Get a pointer to Panda's global ClockObject, used for # synchronizing events between Python and C. globalClock = ClockObject.getGlobalClock() # We will manually manage the clock globalClock.setMode(ClockObject.MSlave) self.globalClock = globalClock # Since we have already started up a TaskManager, and probably # a number of tasks; and since the TaskManager had to use the # TrueClock to tell time until this moment, make sure the # globalClock object is exactly in sync with the TrueClock. trueClock = TrueClock.getGlobalPtr() self.trueClock = trueClock globalClock.setRealTime(trueClock.getShortTime()) globalClock.tick() # Now we can make the TaskManager start using the new globalClock. taskMgr.globalClock = globalClock simTaskMgr.globalClock = globalClock vfs = VirtualFileSystem.getGlobalPtr() self.vfs = vfs # Make sure we're not making more than one HostBase. if hasattr(builtins, 'base'): raise Exception("Attempt to spawn multiple HostBase instances!") # DO NOT ADD TO THIS LIST. We're trying to phase out the use of # built-in variables by ShowBase. Use a Global module if necessary. builtins.base = self builtins.taskMgr = self.taskMgr builtins.simTaskMgr = self.simTaskMgr builtins.jobMgr = self.jobMgr builtins.eventMgr = self.eventMgr builtins.messenger = self.messenger builtins.bboard = self.bboard builtins.loader = self.loader # Config needs to be defined before ShowBase is constructed #builtins.config = self.config builtins.ostream = Notify.out() builtins.directNotify = directNotify builtins.giveNotify = giveNotify builtins.globalClock = globalClock builtins.vfs = vfs builtins.cpMgr = ConfigPageManager.getGlobalPtr() builtins.cvMgr = ConfigVariableManager.getGlobalPtr() builtins.pandaSystem = PandaSystem.getGlobalPtr() # Now add this instance to the ShowBaseGlobal module scope. from . import ShowBaseGlobal builtins.run = ShowBaseGlobal.run ShowBaseGlobal.base = self # What is the current frame number? self.frameCount = 0 # Time at beginning of current frame self.frameTime = self.globalClock.getRealTime() # How long did the last frame take. self.deltaTime = 0 # # Variables pertaining to simulation ticks. # self.prevRemainder = 0 self.remainder = 0 # What is the current overall simulation tick? self.tickCount = 0 # How many ticks are we going to run this frame? self.totalTicksThisFrame = 0 # How many ticks have we run so far this frame? self.currentTicksThisFrame = 0 # What tick are we currently on this frame? self.currentFrameTick = 0 # How many simulations ticks are we running per-second? self.ticksPerSec = 60 self.intervalPerTick = 1.0 / self.ticksPerSec self.taskMgr.finalInit()