Example #1
0
from twisted.internet.defer import Deferred
from twisted.internet.protocol import ClientCreator
from twisted.internet.stdio import StandardIO
from twisted.internet.task import LoopingCall
from twisted.protocols.amp import AMP
from twisted.protocols.basic import LineReceiver

from bravo.amp import Version, Worlds, RunCommand
from bravo.config import configuration
from bravo.utilities import fancy_console_name

try:
    import termios
    import tty
    fancy_console = os.isatty(sys.__stdin__.fileno())
    fancy_console = fancy_console and configuration.getbooleandefault("bravo",
        "fancy_console", True)
except ImportError:
    fancy_console = False

typeToColor = {
    'identifier': '\x1b[31m',
    'keyword': '\x1b[32m',
    'parameter': '\x1b[33m',
    'variable': '\x1b[1;33m',
    'string': '\x1b[35m',
    'number': '\x1b[36m',
    'op': '\x1b[37m'
}

normalColor = '\x1b[0m'
Example #2
0
from twisted.internet import reactor
from twisted.internet.defer import succeed
from twisted.internet.task import coiterate, deferLater, LoopingCall
from twisted.python import log
from zope.interface.verify import verifyObject

from bravo.chunk import Chunk
from bravo.compat import product
from bravo.config import configuration
from bravo.entity import Player
from bravo.ibravo import ISerializer, ISerializerFactory
from bravo.plugin import retrieve_named_plugins
from bravo.utilities import fork_deferred, split_coords

async = configuration.getbooleandefault("bravo", "ampoule", False)

if async:
    try:
        from ampoule import deferToAMPProcess
        from bravo.remote import MakeChunk
    except ImportError:
        async = False


def coords_to_chunk(f):
    """
    Automatically look up the chunk for the coordinates, and convert world
    coordinates to chunk coordinates.
    """
    @wraps(f)
Example #3
0
from twisted.internet import reactor
from twisted.internet.defer import succeed
from twisted.internet.task import coiterate, deferLater, LoopingCall
from twisted.python import log
from zope.interface.verify import verifyObject

from bravo.chunk import Chunk
from bravo.compat import product
from bravo.config import configuration
from bravo.entity import Player
from bravo.ibravo import ISerializer, ISerializerFactory
from bravo.plugin import retrieve_named_plugins
from bravo.utilities import fork_deferred, split_coords

async = configuration.getbooleandefault("bravo", "ampoule", False)

if async:
    try:
        from ampoule import deferToAMPProcess
        from bravo.remote import MakeChunk
    except ImportError:
        async = False

def coords_to_chunk(f):
    """
    Automatically look up the chunk for the coordinates, and convert world
    coordinates to chunk coordinates.
    """

    @wraps(f)
Example #4
0
from twisted.internet.defer import Deferred
from twisted.internet.protocol import ClientCreator
from twisted.internet.stdio import StandardIO
from twisted.internet.task import LoopingCall
from twisted.protocols.amp import AMP
from twisted.protocols.basic import LineReceiver

from bravo.amp import Version, Worlds, RunCommand
from bravo.config import configuration
from bravo.utilities import fancy_console_name

try:
    import termios
    import tty
    fancy_console = os.isatty(sys.__stdin__.fileno())
    fancy_console = fancy_console and configuration.getbooleandefault(
        "bravo", "fancy_console", True)
except ImportError:
    fancy_console = False

typeToColor = {
    'identifier': '\x1b[31m',
    'keyword': '\x1b[32m',
    'parameter': '\x1b[33m',
    'variable': '\x1b[1;33m',
    'string': '\x1b[35m',
    'number': '\x1b[36m',
    'op': '\x1b[37m'
}

normalColor = '\x1b[0m'
Example #5
0
class World(object):
    """
    Object representing a world on disk.

    Worlds are composed of levels and chunks, each of which corresponds to
    exactly one file on disk. Worlds also contain saved player data.
    """

    season = None
    """
    The current `ISeason`.
    """

    saving = True
    """
    Whether objects belonging to this world may be written out to disk.
    """

    async = False
    """
    Whether this world is using multiprocessing methods to generate geometry.
    """

    dimension = 0
    """
    The world dimension.

    XXX Currently pegged to 0; change this when Nether work gets underway.
    """

    permanent_cache = None
    """
    A permanent cache of chunks which are never evicted from memory.

    This cache is used to speed up logins near the spawn point.
    """
    def __init__(self, name):
        """
        Load a world from disk.

        :Parameters:
            name : str
                The configuration key to use to look up configuration data.
        """

        self.config_name = "world %s" % name
        world_url = configuration.get(self.config_name, "url")
        world_sf_name = configuration.get(self.config_name, "serializer")

        try:
            sf = retrieve_named_plugins(ISerializerFactory, [world_sf_name])[0]
            self.serializer = verify_plugin(ISerializer, sf(world_url))
        except PluginException, pe:
            log.msg(pe)
            raise RuntimeError("Fatal error: Couldn't set up serializer!")

        self.chunk_cache = weakref.WeakValueDictionary()
        self.dirty_chunk_cache = dict()

        self._pending_chunks = dict()

        self.spawn = (0, 0, 0)
        self.seed = random.randint(0, sys.maxint)
        self.time = 0

        # Check if we should offload chunk requests to ampoule.
        if configuration.getbooleandefault("bravo", "ampoule", False):
            try:
                import ampoule
            except ImportError:
                pass
            else:
                self. async = True

        # First, try loading the level, to see if there's any data out there
        # which we can use. If not, don't worry about it.
        d = maybeDeferred(self.serializer.load_level, self)
        d.addCallback(lambda chaff: log.msg("Loaded level data!"))

        def sre(failure):
            failure.trap(SerializerReadException)
            log.msg("Had issues loading level data...")
            log.msg(failure)

        d.addErrback(sre)

        # And now save our level.
        if self.saving:
            self.serializer.save_level(self)

        self.chunk_management_loop = LoopingCall(self.sort_chunks)
        self.chunk_management_loop.start(1)

        log.msg("World started on %s, using serializer %s" %
                (world_url, self.serializer.name))
        log.msg("Using Ampoule: %s" % self. async)