|
|
@@ -1,36 +1,35 @@
|
|
|
"""Contains miscellaneous utility functions and classes."""
|
|
|
|
|
|
-__all__ = ['indent',
|
|
|
-'doc', 'adjust', 'difference', 'intersection', 'union',
|
|
|
-'sameElements', 'makeList', 'makeTuple', 'list2dict', 'invertDict',
|
|
|
-'invertDictLossless', 'uniqueElements', 'disjoint', 'contains',
|
|
|
-'replace', 'reduceAngle', 'fitSrcAngle2Dest', 'fitDestAngle2Src',
|
|
|
-'closestDestAngle2', 'closestDestAngle', 'getSetterName',
|
|
|
-'getSetter', 'Functor', 'Stack', 'Queue',
|
|
|
-'bound', 'clamp', 'lerp', 'average', 'addListsByValue',
|
|
|
-'boolEqual', 'lineupPos', 'formatElapsedSeconds', 'solveQuadratic',
|
|
|
-'findPythonModule', 'mostDerivedLast',
|
|
|
-'clampScalar', 'weightedChoice', 'randFloat', 'normalDistrib',
|
|
|
-'weightedRand', 'randUint31', 'randInt32',
|
|
|
-'SerialNumGen', 'serialNum', 'uniqueName', 'Enum', 'Singleton',
|
|
|
-'SingletonError', 'printListEnum', 'safeRepr',
|
|
|
-'fastRepr', 'isDefaultValue',
|
|
|
-'ScratchPad', 'Sync', 'itype', 'getNumberedTypedString',
|
|
|
-'getNumberedTypedSortedString',
|
|
|
-'printNumberedTyped', 'DelayedCall', 'DelayedFunctor',
|
|
|
-'FrameDelayedCall', 'SubframeCall', 'getBase', 'GoldenRatio',
|
|
|
-'GoldenRectangle', 'rad90', 'rad180', 'rad270', 'rad360',
|
|
|
-'nullGen', 'loopGen', 'makeFlywheelGen', 'flywheel',
|
|
|
-'listToIndex2item', 'listToItem2index',
|
|
|
-'formatTimeCompact','deeptype','StdoutCapture','StdoutPassthrough',
|
|
|
-'Averager', 'getRepository', 'formatTimeExact', 'startSuperLog', 'endSuperLog',
|
|
|
-'typeName', 'safeTypeName', 'histogramDict', 'unescapeHtmlString']
|
|
|
+__all__ = [
|
|
|
+
|
|
|
+ 'indent', 'doc', 'adjust', 'difference', 'intersection', 'union',
|
|
|
+ 'sameElements', 'makeList', 'makeTuple', 'list2dict', 'invertDict',
|
|
|
+ 'invertDictLossless', 'uniqueElements', 'disjoint', 'contains', 'replace',
|
|
|
+ 'reduceAngle', 'fitSrcAngle2Dest', 'fitDestAngle2Src', 'closestDestAngle2',
|
|
|
+ 'closestDestAngle', 'getSetterName', 'getSetter', 'Functor', 'Stack',
|
|
|
+ 'Queue', 'bound', 'clamp', 'lerp', 'average', 'addListsByValue',
|
|
|
+ 'boolEqual', 'lineupPos', 'formatElapsedSeconds', 'solveQuadratic',
|
|
|
+ 'findPythonModule', 'mostDerivedLast', 'clampScalar', 'weightedChoice',
|
|
|
+ 'randFloat', 'normalDistrib', 'weightedRand', 'randUint31', 'randInt32',
|
|
|
+ 'SerialNumGen', 'serialNum', 'uniqueName', 'Enum', 'Singleton',
|
|
|
+ 'SingletonError', 'printListEnum', 'safeRepr', 'fastRepr',
|
|
|
+ 'isDefaultValue', 'ScratchPad', 'Sync', 'itype', 'getNumberedTypedString',
|
|
|
+ 'getNumberedTypedSortedString', 'printNumberedTyped', 'DelayedCall',
|
|
|
+ 'DelayedFunctor', 'FrameDelayedCall', 'SubframeCall', 'getBase',
|
|
|
+ 'GoldenRatio', 'GoldenRectangle', 'rad90', 'rad180', 'rad270', 'rad360',
|
|
|
+ 'nullGen', 'loopGen', 'makeFlywheelGen', 'flywheel', 'listToIndex2item',
|
|
|
+ 'listToItem2index', 'formatTimeCompact', 'deeptype', 'StdoutCapture',
|
|
|
+ 'StdoutPassthrough', 'Averager', 'getRepository', 'formatTimeExact',
|
|
|
+ 'startSuperLog', 'endSuperLog', 'typeName', 'safeTypeName',
|
|
|
+ 'histogramDict', 'unescapeHtmlString',
|
|
|
+]
|
|
|
|
|
|
if __debug__:
|
|
|
- __all__ += ['StackTrace', 'traceFunctionCall', 'traceParentCall', 'printThisCall',
|
|
|
- 'stackEntryInfo', 'lineInfo', 'callerInfo', 'lineTag',
|
|
|
- 'profileFunc', 'profiled', 'startProfile', 'printProfile',
|
|
|
- 'getProfileResultString', 'printStack', 'printReverseStack']
|
|
|
+ __all__ += ['StackTrace', 'traceFunctionCall', 'traceParentCall',
|
|
|
+ 'printThisCall', 'stackEntryInfo', 'lineInfo', 'callerInfo',
|
|
|
+ 'lineTag', 'profileFunc', 'profiled', 'startProfile',
|
|
|
+ 'printProfile', 'getProfileResultString', 'printStack',
|
|
|
+ 'printReverseStack']
|
|
|
|
|
|
import types
|
|
|
import math
|
|
|
@@ -652,13 +651,15 @@ if __debug__:
|
|
|
""" decorator for profiling functions
|
|
|
turn categories on and off via "want-profile-categoryName 1"
|
|
|
|
|
|
- e.g.
|
|
|
+ e.g.::
|
|
|
+
|
|
|
+ @profiled('particles')
|
|
|
+ def loadParticles():
|
|
|
+ ...
|
|
|
|
|
|
- @profiled('particles')
|
|
|
- def loadParticles():
|
|
|
- ...
|
|
|
+ ::
|
|
|
|
|
|
- want-profile-particles 1
|
|
|
+ want-profile-particles 1
|
|
|
"""
|
|
|
assert type(category) in (str, type(None)), "must provide a category name for @profiled"
|
|
|
|
|
|
@@ -1195,13 +1196,14 @@ def normalDistrib(a, b, gauss=random.gauss):
|
|
|
|
|
|
def weightedRand(valDict, rng=random.random):
|
|
|
"""
|
|
|
- pass in a dictionary with a selection -> weight mapping. Eg.
|
|
|
- {"Choice 1": 10,
|
|
|
- "Choice 2": 30,
|
|
|
- "bear": 100}
|
|
|
+ pass in a dictionary with a selection -> weight mapping. E.g.::
|
|
|
+
|
|
|
+ {"Choice 1": 10,
|
|
|
+ "Choice 2": 30,
|
|
|
+ "bear": 100}
|
|
|
|
|
|
- -Weights need not add up to any particular value.
|
|
|
- -The actual selection will be returned.
|
|
|
+ - Weights need not add up to any particular value.
|
|
|
+ - The actual selection will be returned.
|
|
|
"""
|
|
|
selections = list(valDict.keys())
|
|
|
weights = list(valDict.values())
|
|
|
@@ -1997,42 +1999,42 @@ def report(types = [], prefix = '', xform = None, notifyFunc = None, dConfigPara
|
|
|
has no effect and no wrapping/transform occurs. So in production,
|
|
|
it's as if the report has been asserted out.
|
|
|
|
|
|
- Parameters::
|
|
|
- types : A subset list of ['timeStamp', 'frameCount', 'avLocation']
|
|
|
- This allows you to specify certain useful bits of info.
|
|
|
-
|
|
|
- module: Prints the module that this report statement
|
|
|
- can be found in.
|
|
|
- args: Prints the arguments as they were passed to
|
|
|
- this function.
|
|
|
- timeStamp: Adds the current frame time to the output.
|
|
|
- deltaStamp: Adds the current AI synched frame time to
|
|
|
- the output
|
|
|
- frameCount: Adds the current frame count to the output.
|
|
|
- Usually cleaner than the timeStamp output.
|
|
|
- avLocation: Adds the localAvatar's network location
|
|
|
- to the output. Useful for interest debugging.
|
|
|
- interests: Prints the current interest state after the
|
|
|
- report.
|
|
|
- stackTrace: Prints a stack trace after the report.
|
|
|
-
|
|
|
- prefix: Optional string to prepend to output, just before the function.
|
|
|
- Allows for easy grepping and is useful when merging AI/Client
|
|
|
- reports into a single file.
|
|
|
-
|
|
|
- xform: Optional callback that accepts a single parameter: argument 0 to
|
|
|
- the decorated function. (assumed to be 'self')
|
|
|
- It should return a value to be inserted into the report output string.
|
|
|
-
|
|
|
- notifyFunc: A notify function such as info, debug, warning, etc.
|
|
|
- By default the report will be printed to stdout. This
|
|
|
- will allow you send the report to a designated 'notify'
|
|
|
- output.
|
|
|
-
|
|
|
- dConfigParam: A list of Config.prc string variables.
|
|
|
- By default the report will always print. If you
|
|
|
- specify this param, it will only print if one of the
|
|
|
- specified config strings resolve to True.
|
|
|
+ Parameters:
|
|
|
+ types: A subset list of ['timeStamp', 'frameCount', 'avLocation']
|
|
|
+ This allows you to specify certain useful bits of info:
|
|
|
+
|
|
|
+ - *module*: Prints the module that this report statement
|
|
|
+ can be found in.
|
|
|
+ - *args*: Prints the arguments as they were passed to this
|
|
|
+ function.
|
|
|
+ - *timeStamp*: Adds the current frame time to the output.
|
|
|
+ - *deltaStamp*: Adds the current AI synched frame time to
|
|
|
+ the output
|
|
|
+ - *frameCount*: Adds the current frame count to the output.
|
|
|
+ Usually cleaner than the timeStamp output.
|
|
|
+ - *avLocation*: Adds the localAvatar's network location to
|
|
|
+ the output. Useful for interest debugging.
|
|
|
+ - *interests*: Prints the current interest state after the
|
|
|
+ report.
|
|
|
+ - *stackTrace*: Prints a stack trace after the report.
|
|
|
+
|
|
|
+ prefix: Optional string to prepend to output, just before the
|
|
|
+ function. Allows for easy grepping and is useful when
|
|
|
+ merging AI/Client reports into a single file.
|
|
|
+
|
|
|
+ xform: Optional callback that accepts a single parameter:
|
|
|
+ argument 0 to the decorated function. (assumed to be 'self')
|
|
|
+ It should return a value to be inserted into the report
|
|
|
+ output string.
|
|
|
+
|
|
|
+ notifyFunc: A notify function such as info, debug, warning, etc.
|
|
|
+ By default the report will be printed to stdout. This will
|
|
|
+ allow you send the report to a designated 'notify' output.
|
|
|
+
|
|
|
+ dConfigParam: A list of Config.prc string variables.
|
|
|
+ By default the report will always print. If you specify
|
|
|
+ this param, it will only print if one of the specified
|
|
|
+ config strings resolve to True.
|
|
|
"""
|
|
|
|
|
|
|