Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

direct: Migrate legacy DConfig usage to modern configuration interface #1333

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contrib/src/sceneeditor/sceneEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,7 @@
try: import _tkinter
except: sys.exit("Please install python module 'Tkinter'")

from panda3d.core import ConfigVariableBool
from direct.showbase.ShowBase import ShowBase

ShowBase()
Expand Down Expand Up @@ -105,7 106,7 @@ def __init__(self, parent = None, **kw):
base.setBackgroundColor(0,0,0)
self.parent = parent
## Check TkTool is activated! ##
self.wantTK = config.GetBool('want-tk', 0)
self.wantTK = ConfigVariableBool('want-tk', False).getValue()
if self.wantTK:
pass
else:
Expand Down
5 changes: 1 addition & 4 deletions contrib/src/sceneeditor/seCameraControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 281,7 @@ def mouseRollTask(self, state):
angle = getCrankAngle(state.coaCenter)
deltaAngle = angle - state.lastAngle
state.lastAngle = angle
if base.config.GetBool('temp-hpr-fix',0):
self.camManipRef.setHpr(self.camManipRef, 0, 0, deltaAngle)
else:
self.camManipRef.setHpr(self.camManipRef, 0, 0, -deltaAngle)
self.camManipRef.setHpr(self.camManipRef, 0, 0, deltaAngle)
SEditor.camera.setTransform(self.camManipRef, wrt)
return Task.cont

Expand Down
10 changes: 2 additions & 8 deletions contrib/src/sceneeditor/seManipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 324,7 @@ def rotate1D(self, state):
if self.rotateAxis == 'x':
SEditor.widget.setP(SEditor.widget, deltaAngle)
elif self.rotateAxis == 'y':
if base.config.GetBool('temp-hpr-fix',0):
SEditor.widget.setR(SEditor.widget, deltaAngle)
else:
SEditor.widget.setR(SEditor.widget, -deltaAngle)
SEditor.widget.setR(SEditor.widget, deltaAngle)
elif self.rotateAxis == 'z':
SEditor.widget.setH(SEditor.widget, deltaAngle)
# Record crank angle for next time around
Expand Down Expand Up @@ -456,10 453,7 @@ def rotateAboutViewVector(self, state):
deltaAngle = angle - state.lastAngle
state.lastAngle = angle
# Mouse motion edge to edge of display region results in one full turn
if base.config.GetBool('temp-hpr-fix',0):
relHpr(SEditor.widget, SEditor.camera, 0, 0, -deltaAngle)
else:
relHpr(SEditor.widget, SEditor.camera, 0, 0, deltaAngle)
relHpr(SEditor.widget, SEditor.camera, 0, 0, -deltaAngle)

def scale3D(self, state):
# Scale the selected node based upon up down mouse motion
Expand Down
27 changes: 15 additions & 12 deletions direct/src/cluster/ClusterClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 19,14 @@ def __init__(self, configList, clusterSyncFlag):
self.__name__ = 'cluster'
# First start up servers using direct daemon
# What is the name of the client machine?
clusterClientDaemonHost = base.config.GetString(
'cluster-client-daemon', 'None')
clusterClientDaemonHost = ConfigVariableString(
'cluster-client-daemon', 'None').getValue()
if clusterClientDaemonHost == 'None':
clusterClientDaemonHost = os.popen('uname -n').read()
clusterClientDaemonHost = clusterClientDaemonHost.replace('\n', '')
# What daemon port are we using to communicate between client/servers
clusterClientDaemonPort = base.config.GetInt(
'cluster-client-daemon-port', CLUSTER_DAEMON_PORT)
clusterClientDaemonPort = ConfigVariableInt(
'cluster-client-daemon-port', CLUSTER_DAEMON_PORT).getValue()
# Create a daemon
self.daemon = DirectD()
# Start listening for the response
Expand Down Expand Up @@ -443,8 443,8 @@ def moveCamera(self, xyz, hpr):
class DisplayConnection:
def __init__(self, qcm, serverName, port, msgHandler):
self.msgHandler = msgHandler
gameServerTimeoutMs = base.config.GetInt(
"cluster-server-timeout-ms", 300000)
gameServerTimeoutMs = ConfigVariableInt(
"cluster-server-timeout-ms", 300000).getValue()
# A giant 300 second timeout.
self.tcpConn = qcm.openTCPClientConnection(
serverName, port, gameServerTimeoutMs)
Expand Down Expand Up @@ -593,7 593,7 @@ def setCamFrustum(self, focalLength, filmSize, filmOffset):

def createClusterClient():
# setup camera offsets based on cluster-config
clusterConfig = base.config.GetString('cluster-config', 'single-server')
clusterConfig = ConfigVariableString('cluster-config', 'single-server').getValue()
# No cluster config specified!
if clusterConfig not in ClientConfigs:
base.notify.warning(
Expand Down Expand Up @@ -628,7 628,7 @@ def createClusterClient():
lens.setFilmOffset(fo[0], fo[1])
else:
serverConfigName = 'cluster-server-%s' % displayName
serverName = base.config.GetString(serverConfigName, '')
serverName = ConfigVariableString(serverConfigName, '').getValue()
if serverName == '':
base.notify.warning(
'%s undefined in Configrc: expected by %s display client.'%
Expand All @@ -638,14 638,17 @@ def createClusterClient():
# Daemon port
serverDaemonPortConfigName = (
'cluster-server-daemon-port-%s' % displayName)
serverDaemonPort = base.config.GetInt(
serverDaemonPort = ConfigVariableInt(
serverDaemonPortConfigName,
CLUSTER_DAEMON_PORT)
CLUSTER_DAEMON_PORT
).getValue()
# TCP Server port
serverMsgPortConfigName = (
'cluster-server-msg-port-%s' % displayName)
serverMsgPort = base.config.GetInt(serverMsgPortConfigName,
CLUSTER_SERVER_PORT)
serverMsgPort = ConfigVariableInt(
serverMsgPortConfigName,
CLUSTER_SERVER_PORT
).getValue()
cci = ClusterConfigItem(
serverConfigName,
serverName,
Expand Down
2 changes: 1 addition & 1 deletion direct/src/controls/GravityWalker.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 144,7 @@ def setupWallSphere(self, bitmask, avatarRadius):
cSphereNode.setIntoCollideMask(BitMask32.allOff())

# set up collision mechanism
if ConfigVariableBool('want-fluid-pusher', 0):
if ConfigVariableBool('want-fluid-pusher', False).getValue():
self.pusher = CollisionHandlerFluidPusher()
else:
self.pusher = CollisionHandlerPusher()
Expand Down
8 changes: 4 additions & 4 deletions direct/src/directtools/DirectSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 101,9 @@ def __init__(self):
from direct.directdevices import DirectDeviceManager
self.deviceManager = DirectDeviceManager.DirectDeviceManager()
# Automatically create any devices specified in config file
joybox = ConfigVariableString('vrpn-joybox-device', '').value
radamec = ConfigVariableString('vrpn-radamec-device', '').value
fastrak = ConfigVariableString('vrpn-fastrak-device', '').value
joybox = ConfigVariableString('vrpn-joybox-device', '').getValue()
radamec = ConfigVariableString('vrpn-radamec-device', '').getValue()
fastrak = ConfigVariableString('vrpn-fastrak-device', '').getValue()
if joybox:
from direct.directdevices import DirectJoybox
self.joybox = DirectJoybox.DirectJoybox(joybox)
Expand Down Expand Up @@ -300,7 300,7 @@ def addShift(a):
self.clusterMode = clusterMode
except NameError:
# Has the clusterMode been set via a config variable?
self.clusterMode = ConfigVariableString("cluster-mode", '').value
self.clusterMode = ConfigVariableString("cluster-mode", '').getValue()

if self.clusterMode == 'client':
self.cluster = createClusterClient()
Expand Down
4 changes: 3 additions & 1 deletion direct/src/directutil/LargeBlobSenderConsts.py
Original file line number Diff line number Diff line change
@@ -1,5 1,7 @@
"""LargeBlobSenderConsts module"""

from panda3d.core import ConfigVariableString

USE_DISK = 0x01

ChunkSize = 100
Expand All @@ -9,4 11,4 @@
def getLargeBlobPath():
# this folder needs to be accessible by everyone that is going to level edit
# an area as a group
return config.GetString('large-blob-path', 'i:\\toontown_in_game_editor_temp')
return ConfigVariableString('large-blob-path', 'i:\\toontown_in_game_editor_temp').getValue()
4 changes: 2 additions & 2 deletions direct/src/distributed/ClientRepositoryBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 42,7 @@ def __init__(self, dcFileNames = None, dcSuffix = '',
self.deferredGenerates = []
self.deferredDoIds = {}
self.lastGenerate = 0
self.setDeferInterval(ConfigVariableDouble('deferred-generate-interval', 0.2).value)
self.setDeferInterval(ConfigVariableDouble('deferred-generate-interval', 0.2).getValue())
self.noDefer = False # Set this True to temporarily disable deferring.

self.recorder = base.recorder
Expand All @@ -69,7 69,7 @@ def __init__(self, dcFileNames = None, dcSuffix = '',

# Keep track of how recently we last sent a heartbeat message.
# We want to keep these coming at heartbeatInterval seconds.
self.heartbeatInterval = ConfigVariableDouble('heartbeat-interval', 10).value
self.heartbeatInterval = ConfigVariableDouble('heartbeat-interval', 10).getValue()
self.heartbeatStarted = 0
self.lastHeartbeat = 0

Expand Down
17 changes: 9 additions & 8 deletions direct/src/distributed/ConnectionRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 39,14 @@ def __init__(self, connectMethod, config, hasOwnerView = False,
assert self.notify.debugCall()
if threadedNet is None:
# Default value.
threadedNet = config.GetBool('threaded-net', False)
threadedNet = ConfigVariableBool('threaded-net', False).getValue()

# let the C connection repository know whether we're supporting
# 'owner' views of distributed objects (i.e. 'receives ownrecv',
# 'I own this object and have a separate view of it regardless of
# where it currently is located')
CConnectionRepository.__init__(self, hasOwnerView, threadedNet)
self.setWantMessageBundling(config.GetBool('want-message-bundling', 1))
self.setWantMessageBundling(ConfigVariableBool('want-message-bundling', True).getValue())
# DoInterestManager.__init__ relies on CConnectionRepository being
# initialized
DoInterestManager.__init__(self)
Expand All @@ -64,7 64,7 @@ def __init__(self, connectMethod, config, hasOwnerView = False,

self.config = config

if self.config.GetBool('verbose-repository'):
if ConfigVariableBool('verbose-repository', False).getValue():
self.setVerbose(1)

# Set this to 'http' to establish a connection to the server
Expand All @@ -89,7 89,7 @@ def __init__(self, connectMethod, config, hasOwnerView = False,
# Set it to 'default' to use an appropriate interface
# according to the type of ConnectionRepository we are
# creating.
userConnectMethod = self.config.GetString('connect-method', 'default')
userConnectMethod = ConfigVariableString('connect-method', 'default').getValue()
if userConnectMethod == 'http':
connectMethod = self.CM_HTTP
elif userConnectMethod == 'net':
Expand Down Expand Up @@ -121,20 121,21 @@ def __init__(self, connectMethod, config, hasOwnerView = False,

self._serverAddress = ''

if self.config.GetBool('gc-save-all', 1):
if ConfigVariableBool('gc-save-all', True).getValue():
# set gc to preserve every object involved in a cycle, even ones that
# would normally be freed automatically during garbage collect
# allows us to find and fix these cycles, reducing or eliminating the
# need to run garbage collects
# garbage collection CPU usage is O(n), n = number of Python objects
gc.set_debug(gc.DEBUG_SAVEALL)

if self.config.GetBool('want-garbage-collect-task', 1):
if ConfigVariableBool('want-garbage-collect-task', True).getValue():
delay = ConfigVariableDouble('garbage-threshold-adjust-delay', 5 * 60.).getValue()

# manual garbage-collect task
taskMgr.add(self._garbageCollect, self.GarbageCollectTaskName, 200)
# periodically increase gc threshold if there is no garbage
taskMgr.doMethodLater(self.config.GetFloat('garbage-threshold-adjust-delay', 5 * 60.),
self._adjustGcThreshold, self.GarbageThresholdTaskName)
taskMgr.doMethodLater(delay, self._adjustGcThreshold, self.GarbageThresholdTaskName)

self._gcDefaultThreshold = gc.get_threshold()

Expand Down
2 changes: 1 addition & 1 deletion direct/src/distributed/ServerRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 88,7 @@ def __init__(self, tcpPort, serverAddress = None,
threadedNet = None):
if threadedNet is None:
# Default value.
threadedNet = ConfigVariableBool('threaded-net', False).value
threadedNet = ConfigVariableBool('threaded-net', False).getValue()

# Set up networking interfaces.
numThreads = 0
Expand Down
2 changes: 1 addition & 1 deletion direct/src/gui/DirectEntry.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 27,7 @@ class DirectEntry(DirectFrame):
to keyboard buttons
"""

directWtext = ConfigVariableBool('direct-wtext', 1)
directWtext = ConfigVariableBool('direct-wtext', True)

AllowCapNamePrefixes = ("Al", "Ap", "Ben", "De", "Del", "Della", "Delle", "Der", "Di", "Du",
"El", "Fitz", "La", "Las", "Le", "Les", "Lo", "Los",
Expand Down
2 changes: 1 addition & 1 deletion direct/src/interval/AnimControlInterval.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 51,7 @@ def __init__(self, controls, loop=0, constrainedLoop=0,

if isinstance(controls, AnimControlCollection):
self.controls = controls
if ConfigVariableBool("strict-anim-ival", 0):
if ConfigVariableBool("strict-anim-ival", False).getValue():
checkSz = self.controls.getAnim(0).getNumFrames()
for i in range(1,self.controls.getNumAnims()):
if checkSz != self.controls.getAnim(i).getNumFrames():
Expand Down
2 changes: 1 addition & 1 deletion direct/src/leveleditor/ObjectMgrBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 64,7 @@ def genUniqueId(self):
# [gjeon] to solve the problem of unproper $USERNAME
userId = os.path.basename(os.path.expandvars('$USERNAME'))
if userId == '':
userId = ConfigVariableString("le-user-id").value
userId = ConfigVariableString("le-user-id").getValue()
if userId == '':
userId = 'unknown'
newUid = str(time.time()) userId
Expand Down
6 changes: 3 additions & 3 deletions direct/src/particles/SpriteParticleRendererExt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 20,7 @@ class SpriteParticleRendererExt(SpriteParticleRenderer):
def getSourceTextureName(self):
if self.sourceTextureName is None:
SpriteParticleRendererExt.sourceTextureName = ConfigVariableString(
'particle-sprite-texture', 'maps/lightbulb.rgb').value
'particle-sprite-texture', 'maps/lightbulb.rgb').getValue()
# Return instance copy of class variable
return self.sourceTextureName

Expand Down Expand Up @@ -59,7 59,7 @@ def addTextureFromFile(self, fileName = None):
def getSourceFileName(self):
if self.sourceFileName is None:
SpriteParticleRendererExt.sourceFileName = ConfigVariableString(
'particle-sprite-model', 'models/misc/smiley').value
'particle-sprite-model', 'models/misc/smiley').getValue()
# Return instance copy of class variable
return self.sourceFileName

Expand All @@ -70,7 70,7 @@ def setSourceFileName(self, name):
def getSourceNodeName(self):
if self.sourceNodeName is None:
SpriteParticleRendererExt.sourceNodeName = ConfigVariableString(
'particle-sprite-node', '**/*').value
'particle-sprite-node', '**/*').getValue()
# Return instance copy of class variable
return self.sourceNodeName

Expand Down
2 changes: 1 addition & 1 deletion direct/src/showbase/BufferViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 47,7 @@ def __init__(self, win, parent):
self.task = 0
self.dirty = 1
self.accept("render-texture-targets-changed", self.refreshReadout)
if ConfigVariableBool("show-buffers", 0):
if ConfigVariableBool("show-buffers", False).getValue():
self.enable(1)

def refreshReadout(self):
Expand Down
12 changes: 6 additions & 6 deletions direct/src/showbase/ContainerLeakDetector.py
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
from panda3d.core import ConfigVariableBool
from direct.directnotify.DirectNotifyGlobal import directNotify
import direct.showbase.DConfig as config
from direct.showbase.PythonUtil import makeFlywheelGen
from direct.showbase.PythonUtil import itype, serialNum, safeRepr, fastRepr
from direct.showbase.Job import Job
Expand Down Expand Up @@ -805,7 805,7 @@ def run(self):
self.notify.warning(msg)
yield None
messenger.send(self._leakDetector.getLeakEvent(), [container, name])
if config.GetBool('pdb-on-leak-detect', 0):
if ConfigVariableBool('pdb-on-leak-detect', False).getValue():
import pdb;pdb.set_trace()
pass
except Exception as e:
Expand Down Expand Up @@ -1008,18 1008,18 @@ def __init__(self, name, firstCheckDelay = None):
# divide by two, since the first check just takes length measurements and
# doesn't check for leaks
self._nextCheckDelay = firstCheckDelay/2.
self._checkDelayScale = config.GetFloat('leak-detector-check-delay-scale', 1.5)
self._pruneTaskPeriod = config.GetFloat('leak-detector-prune-period', 60. * 30.)
self._checkDelayScale = ConfigVariableDouble('leak-detector-check-delay-scale', 1.5).getValue()
self._pruneTaskPeriod = ConfigVariableDouble('leak-detector-prune-period', 60. * 30.).getValue()

# main dict of id(container)->containerRef
self._id2ref = {}
# storage for results of check-container job
self._index2containerId2len = {}
self._index2delay = {}

if config.GetBool('leak-container', 0):
if ConfigVariableBool('leak-container', False).getValue():
_createContainerLeak()
if config.GetBool('leak-tasks', 0):
if ConfigVariableBool('leak-tasks', False).getValue():
_createTaskLeak()

# don't check our own tables for leaks
Expand Down
8 changes: 4 additions & 4 deletions direct/src/showbase/DConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 10,25 @@
def GetBool(sym, default=False):
if __debug__:
warnings.warn("This is deprecated. Use ConfigVariableBool instead", DeprecationWarning, stacklevel=2)
return ConfigVariableBool(sym, default, "DConfig", ConfigFlags.F_dconfig).value
return ConfigVariableBool(sym, default, "DConfig", ConfigFlags.F_dconfig).getValue()


def GetInt(sym, default=0):
if __debug__:
warnings.warn("This is deprecated. Use ConfigVariableInt instead", DeprecationWarning, stacklevel=2)
return ConfigVariableInt(sym, default, "DConfig", ConfigFlags.F_dconfig).value
return ConfigVariableInt(sym, default, "DConfig", ConfigFlags.F_dconfig).getValue()


def GetDouble(sym, default=0.0):
if __debug__:
warnings.warn("This is deprecated. Use ConfigVariableDouble instead", DeprecationWarning, stacklevel=2)
return ConfigVariableDouble(sym, default, "DConfig", ConfigFlags.F_dconfig).value
return ConfigVariableDouble(sym, default, "DConfig", ConfigFlags.F_dconfig).getValue()


def GetString(sym, default=""):
if __debug__:
warnings.warn("This is deprecated. Use ConfigVariableString instead", DeprecationWarning, stacklevel=2)
return ConfigVariableString(sym, default, "DConfig", ConfigFlags.F_dconfig).value
return ConfigVariableString(sym, default, "DConfig", ConfigFlags.F_dconfig).getValue()


GetFloat = GetDouble
Loading