increased set state speed

This commit is contained in:
Richard Feistenauer 2019-01-05 15:45:09 +01:00
parent c519f11990
commit 68ac036203
2 changed files with 9 additions and 6 deletions

View File

@ -35,7 +35,7 @@ class MyStatus(CellState):
def get_state_draw_color(self, iteration):
red = 0
if self._state[iteration % 2][0]:
if self._state_slots[iteration % 2][0]:
red = 255
return [red, 0, 0]

View File

@ -5,7 +5,7 @@ class CellState:
"""
def __init__(self, initial_state, state_save_slot_count=2):
self._state_save_slot_count = state_save_slot_count
self._state = [[initial_state]] * state_save_slot_count
self._state_slots = [[initial_state]] * state_save_slot_count
def set_status_of_iteration(self, new_status, iteration):
""" Will set the new status for the iteration modulo number of saved states.
@ -13,17 +13,20 @@ class CellState:
:param iteration: Uses the iteration index, to differ between concurrent states.
:return True if status has changed.
"""
self._state[iteration % self._state_save_slot_count] = new_status
slot_count = self._state_save_slot_count
states = self._state_slots
return self._state[(iteration - 1) % self._state_save_slot_count] \
!= self._state[iteration % self._state_save_slot_count]
states[iteration % slot_count] = new_status
return states[(iteration - 1) % slot_count] \
!= states[iteration % slot_count]
def get_status_of_iteration(self, iteration):
""" Will return the status for the iteration modulo number of saved states.
:param iteration: Uses the iteration index, to differ between concurrent states.
:return The status for this iteration.
"""
return self._state[iteration % self._state_save_slot_count]
return self._state_slots[iteration % self._state_save_slot_count]
def get_state_draw_color(self, iteration):
raise NotImplementedError