Skip to content

Commit

Permalink
SM: Prevent unnecessary deep copies
Browse files Browse the repository at this point in the history
  • Loading branch information
Zannick committed Nov 1, 2024
1 parent 931e335 commit bccfb99
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions worlds/sm/variaRandomizer/logic/smboolmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..utils.doorsmanager import DoorsManager
from ..utils.objectives import Objectives
from ..utils.parameters import Knows, isKnows
import copy
import logging
import sys

Expand Down Expand Up @@ -240,6 +241,17 @@ def energyReserveCountOk(self, count, difficulty=0):
return SMBool(True, difficulty, items = [items])
else:
return smboolFalse

def __deepcopy__(self, memo=None):
cls = self.__class__
cp = cls.__new__(cls)
if memo is None:
memo = {}
memo[id(self)] = cp
for k, v in self.__dict__.items():
setattr(cp, k, copy.deepcopy(v, memo))
return cp


class SMBoolManagerPlando(SMBoolManager):
def __init__(self):
Expand Down
10 changes: 10 additions & 0 deletions worlds/sm/variaRandomizer/utils/objectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,3 +804,13 @@ def writeChar(c, frameDelay=2):
# write trailer, see intro_text.asm
rom.writeWord(0xAE5B)
rom.writeWord(0x9698)

def __deepcopy__(self, memo=None):
cls = self.__class__
cp = cls.__new__(cls)
if memo is None:
memo = {}
memo[id(self.graph)] = self.graph
for k, v in self.__dict__.items():
setattr(cp, k, copy.deepcopy(v, memo))
return cp

0 comments on commit bccfb99

Please sign in to comment.