def store(self, character, graph, node, branch, tick, is_avatar): if not is_avatar: is_avatar = None Cache.store(self, character, graph, node, branch, tick, is_avatar) self.user_order[graph][node][character][branch][tick] = is_avatar self.user_shallow[(graph, node, character, branch)][tick] = is_avatar self._forward_valcache(self.charavs[character], branch, tick) self._forward_valcache(self.graphavs[(character, graph)], branch, tick) self._forward_valcache(self.graphs[character], branch, tick) self._forward_valcache(self.soloav[(character, graph)], branch, tick, copy=False) self._forward_valcache(self.uniqav[character], branch, tick, copy=False) self._forward_valcache(self.uniqgraph[character], branch, tick, copy=False) charavs = self.charavs[character][branch] graphavs = self.graphavs[(character, graph)][branch] graphs = self.graphs[character][branch] uniqgraph = self.uniqgraph[character][branch] soloav = self.soloav[(character, graph)][branch] uniqav = self.uniqav[character][branch] for avmap in (charavs, graphavs, graphs): if not avmap.has_exact_rev(tick): try: avmap[tick] = avmap[tick].copy() except HistoryError: avmap[tick] = set() if is_avatar: if graphavs[tick]: soloav[tick] = None else: soloav[tick] = node if charavs[tick]: uniqav[tick] = None else: uniqav[tick] = (graph, node) if graphs[tick]: uniqgraph[tick] = None else: uniqgraph[tick] = graph graphavs[tick].add(node) charavs[tick].add((graph, node)) graphs[tick].add(graph) else: graphavs[tick].remove(node) charavs[tick].remove((graph, node)) soloav[tick] = singleton_get(graphavs[tick]) uniqav[tick] = singleton_get(charavs[tick]) if not graphavs[tick]: graphs[tick].remove(graph) if len(graphs[tick]) == 1: uniqgraph[tick] = next(iter(graphs[tick])) else: uniqgraph[tick] = None
def __init__(self, engine): Cache.__init__(self, engine) self.user_order = StructuredDefaultDict(3, FuturistWindowDict) self.user_shallow = PickyDefaultDict(FuturistWindowDict) self.graphs = StructuredDefaultDict(1, FuturistWindowDict) self.graphavs = StructuredDefaultDict(1, FuturistWindowDict) self.charavs = StructuredDefaultDict(1, FuturistWindowDict) self.soloav = StructuredDefaultDict(1, FuturistWindowDict) self.uniqav = StructuredDefaultDict(1, FuturistWindowDict) self.uniqgraph = StructuredDefaultDict(1, FuturistWindowDict)
def store(self, rulebook, rule, branch, tick, active): if not active: active = None Cache.store(self, rulebook, rule, branch, tick, active) auh = self.active_sets[rulebook][branch].setdefault(tick, set()) if self.active_sets[rulebook][branch].rev_before(tick) != tick: auh = self.active_sets[rulebook][branch][tick] = auh.copy() if active: auh.add(rule) else: auh.discard(rule)
def __init__(self, engine): Cache.__init__(self, engine) self.user_order = StructuredDefaultDict(3, TurnDict) self.user_shallow = PickyDefaultDict(TurnDict) self.graphs = StructuredDefaultDict(1, TurnDict) self.graphavs = StructuredDefaultDict(1, TurnDict) self.charavs = StructuredDefaultDict(1, TurnDict) self.soloav = StructuredDefaultDict(1, TurnDict) self.uniqav = StructuredDefaultDict(1, TurnDict) self.uniqgraph = StructuredDefaultDict(1, TurnDict) self.users = StructuredDefaultDict(1, TurnDict)
def __init__(self, db): Cache.__init__(self, db) self._make_node = db.thing_cls
def store(self, character, graph, node, branch, turn, tick, is_avatar, *, planning=False): if not is_avatar: is_avatar = None Cache.store(self, character, graph, node, branch, turn, tick, is_avatar, planning=False) userturns = self.user_order[graph][node][character][branch] if userturns.has_exact_rev(turn): userturns[turn][tick] = is_avatar else: userturns[turn] = {tick: is_avatar} usershal = self.user_shallow[(graph, node, character, branch)] if usershal.has_exact_rev(turn): usershal[turn][tick] = is_avatar else: usershal[turn] = {tick: is_avatar} charavs = self.charavs[character][branch] graphavs = self.graphavs[(character, graph)][branch] graphs = self.graphs[character][branch] uniqgraph = self.uniqgraph[character][branch] soloav = self.soloav[(character, graph)][branch] uniqav = self.uniqav[character][branch] users = self.users[graph, node][branch] def add_something(cache, what): if cache.has_exact_rev(turn): nucache = cache[turn][tick].copy() nucache.add(what) cache[turn][tick] = nucache elif turn in cache: cacheturn = cache[turn] nucache = cacheturn[cacheturn.end].copy() nucache.add(what) cache[turn] = {tick: nucache} else: cache[turn] = {tick: {what}} def remove_something(cache, what): if cache.has_exact_rev(turn): nucache = cache[turn][tick].copy() nucache.remove(what) cache[turn][tick] = nucache elif turn in cache: cacheturn = cache[turn] nucache = cacheturn[cacheturn.end].copy() nucache.remove(what) cache[turn] = {tick: nucache} else: raise ValueError if is_avatar: add_something(graphavs, node) add_something(charavs, (graph, node)) add_something(graphs, graph) add_something(users, character) else: remove_something(graphavs, node) remove_something(charavs, (graph, node)) if not graphavs[turn][tick]: remove_something(graphs, graph) if not charavs[turn][tick]: remove_something(users, character) graphav = singleton_get(graphavs[turn][tick]) if soloav.has_exact_rev(turn): soloav[turn][tick] = graphav else: soloav[turn] = {tick: graphav} charav = singleton_get(charavs[turn][tick]) if uniqav.has_exact_rev(turn): uniqav[turn][tick] = charav else: uniqav[turn] = {tick: charav} if not graphavs[turn][tick]: graphs[turn][tick].remove(graph) if len(graphs[turn][tick]) == 1: uniqgraph[turn][tick] = next(iter(graphs[turn][tick])) else: uniqgraph[turn][tick] = None if turn in graphavs and tick in graphavs[turn] and graphavs[turn][tick]: if soloav.has_exact_rev(turn): soloav[turn][tick] = None else: soloav[turn] = soloav.cls({tick: None}) else: if soloav.has_exact_rev(turn): soloav[turn][tick] = node else: soloav[turn] = soloav.cls({tick: None}) if turn in charavs and tick in charavs[turn] and charavs[turn][tick]: if uniqav.has_exact_rev(turn): uniqav[turn][tick] = None else: uniqav[turn] = uniqav.cls({tick: None}) elif uniqav.has_exact_rev(turn): uniqav[turn][tick] = (graph, node) else: uniqav[turn] = uniqav.cls({tick: (graph, node)}) if turn in graphs and tick in graphs[turn] and graphs[turn][tick]: if uniqgraph.has_exact_rev(turn): uniqgraph[turn][tick] = None else: uniqgraph[turn] = uniqgraph.cls({tick: None}) elif uniqgraph.has_exact_rev(turn): uniqgraph[turn][tick] = graph else: uniqgraph[turn] = uniqgraph.cls({tick: graph})
def __init__(self, engine): Cache.__init__(self, engine) self.active_sets = StructuredDefaultDict(1, FuturistWindowDict)