Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for saving worlds #4

Open
traverseda opened this issue Apr 7, 2016 · 4 comments
Open

Support for saving worlds #4

traverseda opened this issue Apr 7, 2016 · 4 comments

Comments

@traverseda
Copy link
Owner

No description provided.

@traverseda
Copy link
Owner Author

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

@mrpudn
Copy link
Contributor

mrpudn commented Apr 17, 2016

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?

@traverseda
Copy link
Owner Author

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.

@r58Playz
Copy link

How about boskee's solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants