pycraft icon indicating copy to clipboard operation
pycraft copied to clipboard

Support for saving worlds

Open traverseda opened this issue 9 years ago • 4 comments

traverseda avatar Apr 07 '16 12:04 traverseda

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']

traverseda avatar Apr 08 '16 17:04 traverseda

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?

mrpudn avatar Apr 17 '16 17:04 mrpudn

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.

traverseda avatar Apr 17 '16 17:04 traverseda

How about boskee's solution?

r58Playz avatar Jun 17 '19 18:06 r58Playz