diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 99a8b77abf..af14d94de6 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -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): diff --git a/direct/src/showbase/ShowBaseGlobal.py b/direct/src/showbase/ShowBaseGlobal.py index cf601883cb..1f1c81af1a 100644 --- a/direct/src/showbase/ShowBaseGlobal.py +++ b/direct/src/showbase/ShowBaseGlobal.py @@ -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