mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
showbase: use ShowBaseGlobal module as alternative to builtin scope
Allows accessing `base` object and several other builtins from the ShowBaseGlobal module. It doesn't bother with builtins that are available as members of the base object such as `render` and `loader`. Fixes #182
This commit is contained in:
parent
9065f2e16e
commit
4f50f6abd0
@ -389,6 +389,10 @@ class ShowBase(DirectObject.DirectObject):
|
||||
builtins.aspect2dp = self.aspect2dp
|
||||
builtins.pixel2dp = self.pixel2dp
|
||||
|
||||
# Now add this instance to the ShowBaseGlobal module scope.
|
||||
from . import ShowBaseGlobal
|
||||
ShowBaseGlobal.base = self
|
||||
|
||||
if self.__dev__:
|
||||
ShowBase.notify.debug('__dev__ == %s' % self.__dev__)
|
||||
else:
|
||||
@ -514,6 +518,9 @@ class ShowBase(DirectObject.DirectObject):
|
||||
del builtins.base
|
||||
del builtins.loader
|
||||
del builtins.taskMgr
|
||||
ShowBaseGlobal = sys.modules.get('direct.showbase.ShowBaseGlobal', None)
|
||||
if ShowBaseGlobal:
|
||||
del ShowBaseGlobal.base
|
||||
|
||||
# [gjeon] restore sticky key settings
|
||||
if self.config.GetBool('disable-sticky-keys', 0):
|
||||
|
@ -1,14 +1,26 @@
|
||||
"""instantiate global ShowBase object"""
|
||||
"""This module serves as a container to hold the global ShowBase instance, as
|
||||
an alternative to using the builtin scope.
|
||||
|
||||
Note that you cannot directly import `base` from this module since ShowBase
|
||||
may not have been created yet; instead, ShowBase dynamically adds itself to
|
||||
this module's scope when instantiated."""
|
||||
|
||||
__all__ = []
|
||||
|
||||
from .ShowBase import *
|
||||
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.direct import get_config_showbase
|
||||
|
||||
# Create the showbase instance
|
||||
# This should be created by the game specific "start" file
|
||||
#ShowBase()
|
||||
# Instead of creating a show base, assert that one has already been created
|
||||
assert base
|
||||
config = get_config_showbase()
|
||||
|
||||
vfs = VirtualFileSystem.getGlobalPtr()
|
||||
ostream = Notify.out()
|
||||
globalClock = ClockObject.getGlobalClock()
|
||||
cpMgr = ConfigPageManager.getGlobalPtr()
|
||||
cvMgr = ConfigVariableManager.getGlobalPtr()
|
||||
pandaSystem = PandaSystem.getGlobalPtr()
|
||||
|
||||
# Set direct notify categories now that we have config
|
||||
directNotify.setDconfigLevels()
|
||||
@ -31,3 +43,4 @@ builtins.inspect = inspect
|
||||
if (not __debug__) and __dev__:
|
||||
notify = directNotify.newCategory('ShowBaseGlobal')
|
||||
notify.error("You must set 'want-dev' to false in non-debug mode.")
|
||||
del notify
|
||||
|
Loading…
x
Reference in New Issue
Block a user