Difference between revisions of "IC Python API:RLPy RTime"
Chuck (RL) (Talk | contribs) m (→SetValue) |
Chuck (RL) (Talk | contribs) m |
||
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{TOC}} | {{TOC}} | ||
− | {{Parent|IC_Python_API:RL_Python_Modules | + | {{Parent|IC_Python_API:RL_Python_Modules|Modules}} |
− | + | == Detailed Description == | |
− | + | ||
− | + | ||
− | == Description == | + | |
− | + | ||
This class is used to hold and manipulate timing information. | This class is used to hold and manipulate timing information. | ||
− | + | Time is stored internally in system as milliseconds. Most API methods | |
− | Time is stored internally in system as milliseconds. Most API methods that require or return timing information do so through variables of this type. This class also provide methods to convert between Frame and RTime, such as GetFrameIndex() and IndexedFrameTime(). Use | + | that require or return timing information do so through variables of |
− | + | this type. This class also provide methods to convert between Frame and RTime, such as GetFrameIndex() and IndexedFrameTime(). Use GetFrameTime() can ensure that RTime is on the correct frame. <syntaxhighlight lang="Python"> | |
− | + | time = RLPy.RGlobal.GetTime() | |
− | + | ||
− | + | # compare time | |
− | + | if time == RLPy.RGlobal.SetTime(RLPy.RTime(1000)): | |
− | < | + | print("equal") |
− | + | else if time > RLPy.RGlobal.SetTime(RLPy.RTime(1000)): | |
− | + | print("greater") | |
− | + | else if time < RLPy.RGlobal.SetTime(RLPy.RTime(1000)): | |
− | + | print("less") | |
− | + | ||
− | time | + | # operator |
time += RLPy.RTime(1000) | time += RLPy.RTime(1000) | ||
time -= RLPy.RTime(1000) | time -= RLPy.RTime(1000) | ||
− | + | time *= 2 | |
− | # | + | time /= 2 |
− | time | + | |
− | time | + | # convert between Frame |
− | + | time = RLPy.RTime(3000) | |
− | print(time.GetValue()) | + | print(RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps())) # 180 |
− | + | ||
− | # 3000 | + | time = RLPy.RTime.IndexedFrameTime(180, RLPy.RGlobal.GetFps()) |
+ | print(time.GetValue()) # 3000 | ||
+ | |||
+ | time = RLPy.RTime(3005) | ||
+ | frame_time = RLPy.RTime.GetFrameTime(time, RLPy.RGlobal.GetFps()) | ||
+ | print(frame_time.GetValue()) # 3000 | ||
+ | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ==Constructor & Destructors== | |
− | + | ===__init__=== | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
<syntaxhighlight lang="Python"> | <syntaxhighlight lang="Python"> | ||
− | + | RLPy.RTime.__init__ ( self, args ) | |
+ | </syntaxhighlight> | ||
+ | Constructor, Initialize a new RTime object with a float value and an unit. | ||
+ | ====Parameters==== | ||
+ | <div style="margin-left: 2em;"> | ||
− | time | + | '''fValue''' [IN] a float value representing a time - float |
− | + | ||
− | + | ||
− | + | '''eUnit''' [IN] a time unit - RLPy.Unit | |
− | + | *'''RLPy.kInvalid''' | |
− | + | *'''RLPy.kHours not support | |
− | + | *'''RLPy.kMinutes not support | |
− | + | *'''RLPy.kSeconds not support | |
− | + | *'''RLPy.kMilliseconds 1/1000 of a second | |
− | + | *'''RLPy.k30FPS not support | |
− | + | *'''RLPy.k60FPS 60 frames per second | |
+ | *'''RLPy.kUserDef not support | ||
</div> | </div> | ||
− | + | ==Operators== | |
− | + | This class supports the following operators: | |
− | + | {| class="wikitable" | |
− | + | !Member | |
− | < | + | !Operation |
− | + | !Syntax | |
+ | !Description | ||
+ | !Example | ||
+ | |- | ||
+ | ! scope="row"|__add__ | ||
+ | |Addition | ||
+ | |a + b | ||
+ | |Adds values on either side of the operator. | ||
+ | |a + b = 30 | ||
+ | |- | ||
+ | ! scope="row"|__sub__ | ||
+ | |Subtraction | ||
+ | |a - b | ||
+ | |Subtracts right hand operand from left hand operand. | ||
+ | |a – b = -10 | ||
+ | |- | ||
+ | ! scope="row"|__mul__ | ||
+ | |Multiplication | ||
+ | |a * b | ||
+ | |Multiplies values on either side of the operator. | ||
+ | |a * b = 200 | ||
+ | |- | ||
+ | ! scope="row"|__truediv__ | ||
+ | |Division | ||
+ | |a / b | ||
+ | |Divides left hand operand by right hand operand. | ||
+ | |b / a = 2 | ||
+ | |- | ||
+ | ! scope="row"|__eq__ | ||
+ | |Equality | ||
+ | |a == b | ||
+ | |If the values of two operands are equal, then the condition becomes true. | ||
+ | |(a == b) is not true. | ||
+ | |- | ||
+ | ! scope="row"|__ne__ | ||
+ | |Difference | ||
+ | |a != b | ||
+ | |If values of two operands are not equal, then condition becomes true. | ||
+ | |(a != b) is true. | ||
+ | |- | ||
+ | ! scope="row"|__gt__ | ||
+ | |Greater Than | ||
+ | |a > b | ||
+ | |If the value of left operand is greater than the value of right operand, then condition becomes true. | ||
+ | |(a > b) is not true. | ||
+ | |- | ||
+ | ! scope="row"|__lt__ | ||
+ | |Less Than | ||
+ | |a < b | ||
+ | |If the value of left operand is less than the value of right operand, then condition becomes true. | ||
+ | |(a < b) is true. | ||
+ | |- | ||
+ | ! scope="row"|__ge__ | ||
+ | |Greater Than or Equal | ||
+ | |a >= b | ||
+ | |If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. | ||
+ | |(a >= b) is not true. | ||
+ | |- | ||
+ | ! scope="row"|__le__ | ||
+ | |Less or Equal | ||
+ | |a <= b | ||
+ | |If the value of left operand is less than or equal to the value of right operand, then condition becomes true. | ||
+ | |(a <= b) is true. | ||
+ | |- | ||
+ | ! scope="row"|__iadd__ | ||
+ | |Addition (Inplace) | ||
+ | |a += b | ||
+ | |It adds right operand to the left operand and assign the result to left operand. | ||
+ | |c += a is equivalent to c = c + a | ||
+ | |- | ||
+ | ! scope="row"|__isub__ | ||
+ | |Subtraction (Inplace) | ||
+ | |a -= b | ||
+ | |It subtracts right operand from the left operand and assign the result to left operand. | ||
+ | |c -= a is equivalent to c = c - a | ||
+ | |- | ||
+ | ! scope="row"|__imul__ | ||
+ | |Multiply (Inplace) | ||
+ | |a *= b | ||
+ | |It multiplies right operand with the left operand and assign the result to left operand. | ||
+ | |c *= a is equivalent to c = c * a | ||
+ | |- | ||
+ | ! scope="row"|__itruediv__ | ||
+ | |Divide (Inplace) | ||
+ | |a /= b | ||
+ | |It divides left operand with the right operand and assign the result to left operand. | ||
+ | |c /= a is equivalent to c = c / ac /= a is equivalent to c = c / a | ||
+ | |} | ||
+ | ==Member Functions== | ||
+ | ===AsUnits=== | ||
<syntaxhighlight lang="Python"> | <syntaxhighlight lang="Python"> | ||
− | + | RLPy.RTime.AsUnits ( self, eUnit ) | |
+ | </syntaxhighlight> | ||
+ | Returns the current time value in the given units. | ||
+ | This does not affect the current units for the instance. | ||
+ | ====Parameters==== | ||
+ | <div style="margin-left: 2em;"> | ||
− | time | + | '''eUnit''' [IN] a time unit - RLPy.Unit |
− | + | *'''RLPy.kInvalid''' | |
− | + | *'''RLPy.kHours not support | |
− | + | *'''RLPy.kMinutes not support | |
− | + | *'''RLPy.kSeconds not support | |
− | + | *'''RLPy.kMilliseconds 1/1000 of a second | |
− | + | *'''RLPy.k30FPS not support | |
− | + | *'''RLPy.k60FPS 60 frames per second | |
− | + | *'''RLPy.kUserDef not support | |
− | + | ||
− | + | ||
</div> | </div> | ||
+ | ====Returns==== | ||
+ | <div style="margin-left: 2em;">The current time value in the given units - float | ||
</div> | </div> | ||
− | + | ----- | |
− | == | + | ===GetFrameIndex=== |
− | + | ||
− | == | + | |
− | + | ||
<syntaxhighlight lang="Python"> | <syntaxhighlight lang="Python"> | ||
− | + | RLPy.RTime.GetFrameIndex ( kTime, nFps ) | |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | Get frame index from frame time. | ||
+ | ====Parameters==== | ||
+ | <div style="margin-left: 2em;"> | ||
− | + | '''kTime''' [IN] the time for this frame - RLPy.RTime | |
− | + | '''nFps''' [IN] frames per second - int | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</div> | </div> | ||
+ | ====Returns==== | ||
+ | <div style="margin-left: 2em;">The frame index - int | ||
</div> | </div> | ||
− | + | ----- | |
− | === | + | ===GetFrameTime=== |
− | + | ||
<syntaxhighlight lang="Python"> | <syntaxhighlight lang="Python"> | ||
− | + | RLPy.RTime.GetFrameTime ( kTime, nFps ) | |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | Get frame time from a time. | ||
+ | The time of a RTime object may not located exactly on a frame. Call this function to get the closest frame time for this RTime object. | ||
+ | ====Parameters==== | ||
+ | <div style="margin-left: 2em;"> | ||
− | + | '''kTime''' [IN] the time in an animation - RLPy.RTime | |
− | + | '''nFps''' [IN] frames per second - int | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</div> | </div> | ||
+ | ====Returns==== | ||
+ | <div style="margin-left: 2em;">The frame time - RLPy.RTime | ||
</div> | </div> | ||
− | + | ----- | |
− | === | + | ===GetUnit=== |
− | + | ||
<syntaxhighlight lang="Python"> | <syntaxhighlight lang="Python"> | ||
− | + | RLPy.RTime.GetUnit ( self ) | |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Get the unit of this RTime object. | |
− | + | ====Returns==== | |
− | + | <div style="margin-left: 2em;">The unit of this RTime object - RLPy.Unit | |
− | <div | + | *'''RLPy.kInvalid''' |
− | The | + | *'''RLPy.kHours not support |
− | <div | + | *'''RLPy.kMinutes not support |
+ | *'''RLPy.kSeconds not support | ||
+ | *'''RLPy.kMilliseconds 1/1000 of a second | ||
+ | *'''RLPy.k30FPS not support | ||
+ | *'''RLPy.k60FPS 60 frames per second | ||
+ | *'''RLPy.kUserDef not support | ||
+ | </div> | ||
+ | ----- | ||
+ | ===GetValue=== | ||
<syntaxhighlight lang="Python"> | <syntaxhighlight lang="Python"> | ||
− | + | RLPy.RTime.GetValue ( self ) | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | Get the float value of this RTime object. | ||
+ | ====Returns==== | ||
+ | <div style="margin-left: 2em;">The float value of this RTime object - float | ||
</div> | </div> | ||
− | + | ----- | |
− | + | ===IndexedFrameTime=== | |
− | === | + | |
− | + | ||
<syntaxhighlight lang="Python"> | <syntaxhighlight lang="Python"> | ||
− | + | RLPy.RTime.IndexedFrameTime ( nFrameIndex, nFps ) | |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | Get frame time from frame index. | ||
+ | ====Parameters==== | ||
+ | <div style="margin-left: 2em;"> | ||
− | + | '''nFrameIndex''' [IN] the frame index for this frame time - int | |
− | + | '''nFps''' [IN] frames per second - int | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</div> | </div> | ||
+ | ====Returns==== | ||
+ | <div style="margin-left: 2em;">The frame time - RLPy.RTime | ||
</div> | </div> | ||
− | + | ----- | |
− | === | + | ===SetUnit=== |
− | + | ||
<syntaxhighlight lang="Python"> | <syntaxhighlight lang="Python"> | ||
− | + | RLPy.RTime.SetUnit ( self, eUnit ) | |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | Set time unit. | ||
+ | ====Parameters==== | ||
+ | <div style="margin-left: 2em;"> | ||
− | + | '''eUnit''' [IN] a time unit - RLPy.Unit | |
− | + | *'''RLPy.kInvalid''' | |
− | + | *'''RLPy.kHours not support | |
− | + | *'''RLPy.kMinutes not support | |
− | <div | + | *'''RLPy.kSeconds not support |
− | + | *'''RLPy.kMilliseconds 1/1000 of a second | |
− | + | *'''RLPy.k30FPS not support | |
+ | *'''RLPy.k60FPS 60 frames per second | ||
+ | *'''RLPy.kUserDef not support | ||
+ | </div> | ||
+ | ----- | ||
+ | ===SetValue=== | ||
<syntaxhighlight lang="Python"> | <syntaxhighlight lang="Python"> | ||
− | + | RLPy.RTime.SetValue ( self, fValue ) | |
+ | </syntaxhighlight> | ||
+ | Set the float value of a time. | ||
+ | ====Parameters==== | ||
+ | <div style="margin-left: 2em;"> | ||
− | + | '''fValue''' [IN] a float value of a time - float | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</div> | </div> |
Revision as of 00:36, 27 March 2019
- Main article: Modules.
Detailed Description
This class is used to hold and manipulate timing information. Time is stored internally in system as milliseconds. Most API methods that require or return timing information do so through variables of
this type. This class also provide methods to convert between Frame and RTime, such as GetFrameIndex() and IndexedFrameTime(). Use GetFrameTime() can ensure that RTime is on the correct frame.time = RLPy.RGlobal.GetTime()
# compare time
if time == RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
print("equal")
else if time > RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
print("greater")
else if time < RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
print("less")
# operator
time += RLPy.RTime(1000)
time -= RLPy.RTime(1000)
time *= 2
time /= 2
# convert between Frame
time = RLPy.RTime(3000)
print(RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps())) # 180
time = RLPy.RTime.IndexedFrameTime(180, RLPy.RGlobal.GetFps())
print(time.GetValue()) # 3000
time = RLPy.RTime(3005)
frame_time = RLPy.RTime.GetFrameTime(time, RLPy.RGlobal.GetFps())
print(frame_time.GetValue()) # 3000
Constructor & Destructors
__init__
RLPy.RTime.__init__ ( self, args )
Constructor, Initialize a new RTime object with a float value and an unit.
Parameters
fValue [IN] a float value representing a time - float
eUnit [IN] a time unit - RLPy.Unit
- RLPy.kInvalid
- RLPy.kHours not support
- RLPy.kMinutes not support
- RLPy.kSeconds not support
- RLPy.kMilliseconds 1/1000 of a second
- RLPy.k30FPS not support
- RLPy.k60FPS 60 frames per second
- RLPy.kUserDef not support
Operators
This class supports the following operators:
Member | Operation | Syntax | Description | Example |
---|---|---|---|---|
__add__ | Addition | a + b | Adds values on either side of the operator. | a + b = 30 |
__sub__ | Subtraction | a - b | Subtracts right hand operand from left hand operand. | a – b = -10 |
__mul__ | Multiplication | a * b | Multiplies values on either side of the operator. | a * b = 200 |
__truediv__ | Division | a / b | Divides left hand operand by right hand operand. | b / a = 2 |
__eq__ | Equality | a == b | If the values of two operands are equal, then the condition becomes true. | (a == b) is not true. |
__ne__ | Difference | a != b | If values of two operands are not equal, then condition becomes true. | (a != b) is true. |
__gt__ | Greater Than | a > b | If the value of left operand is greater than the value of right operand, then condition becomes true. | (a > b) is not true. |
__lt__ | Less Than | a < b | If the value of left operand is less than the value of right operand, then condition becomes true. | (a < b) is true. |
__ge__ | Greater Than or Equal | a >= b | If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. | (a >= b) is not true. |
__le__ | Less or Equal | a <= b | If the value of left operand is less than or equal to the value of right operand, then condition becomes true. | (a <= b) is true. |
__iadd__ | Addition (Inplace) | a += b | It adds right operand to the left operand and assign the result to left operand. | c += a is equivalent to c = c + a |
__isub__ | Subtraction (Inplace) | a -= b | It subtracts right operand from the left operand and assign the result to left operand. | c -= a is equivalent to c = c - a |
__imul__ | Multiply (Inplace) | a *= b | It multiplies right operand with the left operand and assign the result to left operand. | c *= a is equivalent to c = c * a |
__itruediv__ | Divide (Inplace) | a /= b | It divides left operand with the right operand and assign the result to left operand. | c /= a is equivalent to c = c / ac /= a is equivalent to c = c / a |
Member Functions
AsUnits
RLPy.RTime.AsUnits ( self, eUnit )
Returns the current time value in the given units. This does not affect the current units for the instance.
Parameters
eUnit [IN] a time unit - RLPy.Unit
- RLPy.kInvalid
- RLPy.kHours not support
- RLPy.kMinutes not support
- RLPy.kSeconds not support
- RLPy.kMilliseconds 1/1000 of a second
- RLPy.k30FPS not support
- RLPy.k60FPS 60 frames per second
- RLPy.kUserDef not support
Returns
GetFrameIndex
RLPy.RTime.GetFrameIndex ( kTime, nFps )
Get frame index from frame time.
Parameters
kTime [IN] the time for this frame - RLPy.RTime
nFps [IN] frames per second - int
Returns
GetFrameTime
RLPy.RTime.GetFrameTime ( kTime, nFps )
Get frame time from a time. The time of a RTime object may not located exactly on a frame. Call this function to get the closest frame time for this RTime object.
Parameters
kTime [IN] the time in an animation - RLPy.RTime
nFps [IN] frames per second - int
Returns
GetUnit
RLPy.RTime.GetUnit ( self )
Get the unit of this RTime object.
Returns
- RLPy.kInvalid
- RLPy.kHours not support
- RLPy.kMinutes not support
- RLPy.kSeconds not support
- RLPy.kMilliseconds 1/1000 of a second
- RLPy.k30FPS not support
- RLPy.k60FPS 60 frames per second
- RLPy.kUserDef not support
GetValue
RLPy.RTime.GetValue ( self )
Get the float value of this RTime object.
Returns
IndexedFrameTime
RLPy.RTime.IndexedFrameTime ( nFrameIndex, nFps )
Get frame time from frame index.
Parameters
nFrameIndex [IN] the frame index for this frame time - int
nFps [IN] frames per second - int
Returns
SetUnit
RLPy.RTime.SetUnit ( self, eUnit )
Set time unit.
Parameters
eUnit [IN] a time unit - RLPy.Unit
- RLPy.kInvalid
- RLPy.kHours not support
- RLPy.kMinutes not support
- RLPy.kSeconds not support
- RLPy.kMilliseconds 1/1000 of a second
- RLPy.k30FPS not support
- RLPy.k60FPS 60 frames per second
- RLPy.kUserDef not support
SetValue
RLPy.RTime.SetValue ( self, fValue )
Set the float value of a time.
Parameters
fValue [IN] a float value of a time - float