pycraft
pycraft copied to clipboard
Support for saving worlds
It would be nice to treat worlds as defaultDicts. If you haven't explicitly set a block to something, it passes it off to another function. That way we only save need to save changes to a world.
This could also, potentially, let us temporarily layer worlds together, which I think would be neat.
from collections import defaultdict
class WorldDict(dict):
def __init__(self, factory):
self.factory = factory
def __missing__(self, key):
self[key] = self.factory(key)
return self[key]
def foo(key):
print(key)
return None
testDict=WorldDict(foo)
testDict['0,0,0']
Hmm, so you're saying we'd save "layers" of a world using a defaultdict factory, rather than saving the whole world in one go? each change to the world would save a new layer, kind of like an auto-save feature.
I like the idea, but I think changes should be batched and saved at regular intervals, or even manually, to not impact performance.
Is my understanding correct?
Pretty much. It's all very vague.
We might use python3's async features for the periodic saving, so it doesn't effect performance in the main thread.
chainMap also looks useful.
Layers. One layer for initial worldgen, another for structures, and finally one for user changes to the world.
How about ?