Skip to content

Tick Repeat/Delay updates #156

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

Merged
merged 22 commits into from
Dec 4, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Infinity update
  • Loading branch information
Ayuto committed Nov 16, 2016
commit 9dd2cf8286af3d47afecbcd4a352dbaea14eb0a1
44 changes: 16 additions & 28 deletions addons/source-python/packages/source-python/listeners/tick.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ def __init__(
#: Delay in seconds.
self.delay = delay
self._start_time = time.time()

#: Time when the delay will be executed.
self.exec_time = self._start_time + delay

#: Callback to call when the delay expired.
self.callback = callback

#: Arguments to pass to the callback.
self.args = args

#: Keyword arguments to pass to the callback.
self.kwargs = kwargs if kwargs is not None else dict()

#: Whether or not to cancel the delay at the end of the map.
self.cancel_on_level_end = cancel_on_level_end
_delay_manager.add(self)
Expand Down Expand Up @@ -260,7 +260,7 @@ def __init__(

# Set up private attributes
self._interval = 0
self._total_loops = 0
self._total_loops = math.inf
self._loops_elapsed = 0
self._adjusted_loops = 0
self._status = RepeatStatus.STOPPED
Expand All @@ -274,8 +274,6 @@ def loops_remaining(self):

:rtype: int
"""
if not self.total_loops:
return math.inf
return self.total_loops - self.loops_elapsed

@property
Expand All @@ -292,8 +290,6 @@ def total_loops(self):

:rtype: int
"""
if not self._total_loops:
return self._total_loops
return self._total_loops + self._adjusted_loops

@property
Expand Down Expand Up @@ -321,8 +317,6 @@ def total_time(self):

:rtype: float
"""
if not self.total_loops:
return math.inf
return self.total_loops * self._interval

@property
Expand All @@ -349,14 +343,14 @@ def status(self):
"""
return self._status

def start(self, interval, limit, execute_on_start=False):
def start(self, interval, limit=math.inf, execute_on_start=False):
"""Start the repeat loop.

:param float interval:
The time (in seconds) for each loop.
:param int limit:
The maximum number of times to loop. If 0 is passed, there is no
limit, and the Repeat will loop indefinitely.
The maximum number of times to loop. If :data:`math.inf` is
passed, there is no limit, and the Repeat will loop indefinitely.
:param bool execute_on_start:
Whether to execute the callback when the Repeat is started. Note
that this does not affect the 'limit' as the number of loops will
Expand Down Expand Up @@ -439,10 +433,7 @@ def restart(self):
self.stop()

# Start the repeat
self.start(
self._interval,
self.total_loops if self.total_loops is not math.inf else 0
)
self.start(self._interval, self.total_loops)

def pause(self):
"""Pause the repeat.
Expand Down Expand Up @@ -521,7 +512,7 @@ def extend(self, adjustment):
listeners_tick_logger.log_debug('Repeat.extend')

# Is there no limit for this repeat?
if not self.total_loops:
if self.total_loops == math.inf:
listeners_tick_logger.log_debug(
'Unable to extend, Repeat instance has no limit.'
)
Expand All @@ -545,7 +536,7 @@ def reduce(self, adjustment):
listeners_tick_logger.log_debug('Repeat.reduce')

# Is there no limit for this repeat?
if not self.total_loops:
if self.total_loops == math.inf:
listeners_tick_logger.log_debug(
'Unable to reduce, Repeat instance has no limit.'
)
Expand Down Expand Up @@ -574,14 +565,11 @@ def _execute(self):

# Are any more loops to be made?
if self.loops_remaining > 0:
if not self.total_loops:
listeners_tick_logger.log_debug('Repeat._execute - No limit')
else:
listeners_tick_logger.log_debug(
'Repeat._execute - Remaining - {remaining}'.format(
remaining=self.loops_remaining
)
listeners_tick_logger.log_debug(
'Repeat._execute - Remaining - {remaining}'.format(
remaining=self.loops_remaining
)
)

# Call the delay again
self._delay = Delay(
Expand Down
2 changes: 1 addition & 1 deletion addons/source-python/packages/source-python/menus/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def __missing__(self, index):
if not self:

# If so, start the refresh repeat...
self._repeat.start(1, 0)
self._repeat.start(1)

obj = self[index] = self._cls(index)
return obj
Expand Down