本文整理汇总了Python中bravo.world.World.enable_cache方法的典型用法代码示例。如果您正苦于以下问题:Python World.enable_cache方法的具体用法?Python World.enable_cache怎么用?Python World.enable_cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bravo.world.World
的用法示例。
在下文中一共展示了World.enable_cache方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestWorldChunks
# 需要导入模块: from bravo.world import World [as 别名]
# 或者: from bravo.world.World import enable_cache [as 别名]
class TestWorldChunks(unittest.TestCase):
def setUp(self):
self.name = "unittest"
self.bcp = BravoConfigParser()
self.bcp.add_section("world unittest")
self.bcp.set("world unittest", "url", "")
self.bcp.set("world unittest", "serializer", "memory")
self.w = World(self.bcp, self.name)
self.w.pipeline = []
self.w.start()
def tearDown(self):
self.w.stop()
def test_trivial(self):
pass
@inlineCallbacks
def test_request_chunk_identity(self):
first = yield self.w.request_chunk(0, 0)
second = yield self.w.request_chunk(0, 0)
self.assertIs(first, second)
@inlineCallbacks
def test_request_chunk_cached_identity(self):
# Turn on the cache and get a few chunks in there, then request a
# chunk that is in the cache.
yield self.w.enable_cache(1)
first = yield self.w.request_chunk(0, 0)
second = yield self.w.request_chunk(0, 0)
self.assertIs(first, second)
@inlineCallbacks
def test_get_block(self):
chunk = yield self.w.request_chunk(0, 0)
# Fill the chunk with random stuff.
chunk.blocks = array("B")
chunk.blocks.fromstring(os.urandom(32768))
for x, y, z in product(xrange(2), repeat=3):
# This works because the chunk is at (0, 0) so the coords don't
# need to be adjusted.
block = yield self.w.get_block((x, y, z))
self.assertEqual(block, chunk.get_block((x, y, z)))
@inlineCallbacks
def test_get_metadata(self):
chunk = yield self.w.request_chunk(0, 0)
# Fill the chunk with random stuff.
chunk.metadata = array("B")
chunk.metadata.fromstring(os.urandom(32768))
for x, y, z in product(xrange(2), repeat=3):
# This works because the chunk is at (0, 0) so the coords don't
# need to be adjusted.
metadata = yield self.w.get_metadata((x, y, z))
self.assertEqual(metadata, chunk.get_metadata((x, y, z)))
@inlineCallbacks
def test_get_block_readback(self):
chunk = yield self.w.request_chunk(0, 0)
# Fill the chunk with random stuff.
chunk.blocks = array("B")
chunk.blocks.fromstring(os.urandom(32768))
# Evict the chunk and grab it again.
yield self.w.save_chunk(chunk)
del chunk
chunk = yield self.w.request_chunk(0, 0)
for x, y, z in product(xrange(2), repeat=3):
# This works because the chunk is at (0, 0) so the coords don't
# need to be adjusted.
block = yield self.w.get_block((x, y, z))
self.assertEqual(block, chunk.get_block((x, y, z)))
@inlineCallbacks
def test_get_block_readback_negative(self):
chunk = yield self.w.request_chunk(-1, -1)
# Fill the chunk with random stuff.
chunk.blocks = array("B")
chunk.blocks.fromstring(os.urandom(32768))
# Evict the chunk and grab it again.
yield self.w.save_chunk(chunk)
del chunk
chunk = yield self.w.request_chunk(-1, -1)
for x, y, z in product(xrange(2), repeat=3):
block = yield self.w.get_block((x - 16, y, z - 16))
self.assertEqual(block, chunk.get_block((x, y, z)))
@inlineCallbacks
#.........这里部分代码省略.........
示例2: BravoFactory
# 需要导入模块: from bravo.world import World [as 别名]
# 或者: from bravo.world.World import enable_cache [as 别名]
class BravoFactory(Factory):
"""
A ``Factory`` that creates ``BravoProtocol`` objects when connected to.
"""
implements(IPushProducer)
protocol = BravoProtocol
timestamp = None
time = 0
day = 0
eid = 1
handshake_hook = None
login_hook = None
interfaces = []
def __init__(self, config, name):
"""
Create a factory and world.
``name`` is the string used to look up factory-specific settings from
the configuration.
:param str name: internal name of this factory
"""
self.name = name
self.config = config
self.config_name = "world %s" % name
self.world = World(self.config, self.name)
self.world.factory = self
self.protocols = dict()
self.connectedIPs = defaultdict(int)
self.mode = self.config.get(self.config_name, "mode")
if self.mode not in ("creative", "survival"):
raise Exception("Unsupported mode %s" % self.mode)
self.limitConnections = self.config.getintdefault(self.config_name,
"limitConnections",
0)
self.limitPerIP = self.config.getintdefault(self.config_name,
"limitPerIP", 0)
self.vane = WeatherVane(self)
def startFactory(self):
log.msg("Initializing factory for world '%s'..." % self.name)
authenticator = self.config.get(self.config_name, "authenticator")
selected = retrieve_named_plugins(IAuthenticator, [authenticator])[0]
log.msg("Using authenticator %s" % selected.name)
self.handshake_hook = selected.handshake
self.login_hook = selected.login
# Get our plugins set up.
self.register_plugins()
log.msg("Starting world...")
self.world.start()
# Start up the permanent cache.
# has_option() is not exactly desirable, but it's appropriate here
# because we don't want to take any action if the key is unset.
if self.config.has_option(self.config_name, "perm_cache"):
cache_level = self.config.getint(self.config_name, "perm_cache")
self.world.enable_cache(cache_level)
log.msg("Starting timekeeping...")
self.timestamp = reactor.seconds()
self.time = self.world.time
self.update_season()
self.time_loop = LoopingCall(self.update_time)
self.time_loop.start(2)
log.msg("Starting entity updates...")
# Start automatons.
for automaton in self.automatons:
automaton.start()
self.chat_consumers = set()
log.msg("Factory successfully initialized for world '%s'!" % self.name)
def stopFactory(self):
"""
Called before factory stops listening on ports. Used to perform
shutdown tasks.
"""
log.msg("Shutting down world...")
# Stop automatons. Technically, they may not actually halt until their
#.........这里部分代码省略.........
示例3: BravoFactory
# 需要导入模块: from bravo.world import World [as 别名]
# 或者: from bravo.world.World import enable_cache [as 别名]
class BravoFactory(Factory):
"""
A ``Factory`` that creates ``BravoProtocol`` objects when connected to.
"""
implements(IPushProducer)
protocol = BravoProtocol
timestamp = None
time = 0
day = 0
handshake_hook = None
login_hook = None
interface = ""
def __init__(self, name):
"""
Create a factory and world.
``name`` is the string used to look up factory-specific settings from
the configuration.
:param str name: internal name of this factory
"""
log.msg("Initializing factory for world '%s'..." % name)
self.name = name
self.port = configuration.getint("world %s" % name, "port")
if configuration.has_option("world %s" % name, "host"):
self.interface = configuration.get("world %s" % name, "host")
world_folder = configuration.get("world %s" % name, "path")
self.world = World(world_folder)
self.world.factory = self
if configuration.has_option("world %s" % name, "perm_cache"):
cache_level = configuration.getint("world %s" % name, "perm_cache")
self.world.enable_cache(cache_level)
self.protocols = dict()
self.eid = 1
self.entities = set()
self.time_loop = LoopingCall(self.update_time)
self.time_loop.start(2)
authenticator = configuration.get("world %s" % name, "authenticator")
selected = retrieve_named_plugins(IAuthenticator, [authenticator])[0]
log.msg("Using authenticator %s" % selected.name)
self.handshake_hook = selected.handshake
self.login_hook = selected.login
generators = configuration.getlist("bravo", "generators")
generators = retrieve_sorted_plugins(ITerrainGenerator, generators)
log.msg("Using generators %s" % ", ".join(i.name for i in generators))
self.world.pipeline = generators
self.chat_consumers = set()
log.msg("Factory successfully initialized for world '%s'!" % name)
def create_entity(self, x, y, z, name, **kwargs):
self.eid += 1
entity = entities_by_name[name](self.eid, **kwargs)
entity.location.x = x
entity.location.y = y
entity.location.z = z
self.entities.add(entity)
return entity
def destroy_entity(self, entity):
self.entities.discard(entity)
def update_time(self):
"""
Update the in-game timer.
The timer goes from 0 to 24000, both of which are high noon. The clock
increments by 20 every second. Days are 20 minutes long.
The day clock is incremented every in-game day, which is every 20
minutes. The day clock goes from 0 to 360, which works out to a reset
once every 5 days. This is a Babylonian in-game year.
"""
if self.timestamp is None:
# First run since the start of the factory; re-init everything.
self.timestamp = time()
self.update_season()
t = time()
self.time += 20 * (t - self.timestamp)
self.timestamp = t
#.........这里部分代码省略.........
示例4: BravoFactory
# 需要导入模块: from bravo.world import World [as 别名]
# 或者: from bravo.world.World import enable_cache [as 别名]
class BravoFactory(Factory):
"""
A ``Factory`` that creates ``BravoProtocol`` objects when connected to.
"""
implements(IPushProducer)
protocol = BravoProtocol
timestamp = None
time = 0
day = 0
handshake_hook = None
login_hook = None
interface = ""
def __init__(self, name):
"""
Create a factory and world.
``name`` is the string used to look up factory-specific settings from
the configuration.
:param str name: internal name of this factory
"""
log.msg("Initializing factory for world '%s'..." % name)
self.name = name
self.config_name = "world %s" % name
self.port = configuration.getint(self.config_name, "port")
self.interface = configuration.getdefault(self.config_name, "host",
"")
self.world = World(name)
self.world.factory = self
if configuration.has_option(self.config_name, "perm_cache"):
cache_level = configuration.getint(self.config_name, "perm_cache")
self.world.enable_cache(cache_level)
self.protocols = dict()
self.eid = 1
self.time = self.world.time
self.time_loop = LoopingCall(self.update_time)
self.time_loop.start(2)
authenticator = configuration.get(self.config_name, "authenticator")
selected = retrieve_named_plugins(IAuthenticator, [authenticator])[0]
log.msg("Using authenticator %s" % selected.name)
self.handshake_hook = selected.handshake
self.login_hook = selected.login
generators = configuration.getlist(self.config_name, "generators")
generators = retrieve_sorted_plugins(ITerrainGenerator, generators)
log.msg("Using generators %s" % ", ".join(i.name for i in generators))
self.world.pipeline = generators
self.chat_consumers = set()
log.msg("Factory successfully initialized for world '%s'!" % name)
def buildProtocol(self, addr):
"""
Create a protocol.
This overriden method provides early player entity registration, as a
solution to the username/entity race that occurs on login.
"""
banned = self.world.serializer.load_plugin_data("banned_ips")
for ip in banned.split():
if addr.host == ip:
# Use BannedProtocol with extreme prejudice.
log.msg("Kicking banned IP %s" % addr)
p = BannedProtocol()
p.factory = self
return p
log.msg("Starting connection for %s" % addr)
p = self.protocol(self.name)
p.factory = self
self.register_entity(p)
return p
def create_entity(self, x, y, z, name, **kwargs):
"""
Spawn an entirely new entity.
Handles entity registration as well as instantiation.
"""
#.........这里部分代码省略.........
示例5: BravoFactory
# 需要导入模块: from bravo.world import World [as 别名]
# 或者: from bravo.world.World import enable_cache [as 别名]
class BravoFactory(Factory):
"""
A ``Factory`` that creates ``BravoProtocol`` objects when connected to.
"""
implements(IPushProducer)
protocol = BravoProtocol
timestamp = None
time = 0
day = 0
eid = 1
handshake_hook = None
login_hook = None
interfaces = []
def __init__(self, config, name):
"""
Create a factory and world.
``name`` is the string used to look up factory-specific settings from
the configuration.
:param str name: internal name of this factory
"""
self.name = name
self.config = config
self.config_name = "world %s" % name
self.world = World(self.config, self.name)
self.world.factory = self
self.protocols = dict()
self.connectedIPs = defaultdict(int)
self.mode = self.config.get(self.config_name, "mode")
if self.mode not in ("creative", "survival"):
raise Exception("Unsupported mode %s" % self.mode)
self.limitConnections = self.config.getintdefault(self.config_name,
"limitConnections",
0)
self.limitPerIP = self.config.getintdefault(self.config_name,
"limitPerIP", 0)
self.vane = WeatherVane(self)
def startFactory(self):
log.msg("Initializing factory for world '%s'..." % self.name)
authenticator = self.config.get(self.config_name, "authenticator")
selected = retrieve_named_plugins(IAuthenticator, [authenticator])[0]
log.msg("Using authenticator %s" % selected.name)
self.handshake_hook = selected.handshake
self.login_hook = selected.login
# Get our plugins set up.
self.register_plugins()
log.msg("Starting world...")
self.world.start()
# Start up the permanent cache.
# has_option() is not exactly desirable, but it's appropriate here
# because we don't want to take any action if the key is unset.
if self.config.has_option(self.config_name, "perm_cache"):
cache_level = self.config.getint(self.config_name, "perm_cache")
self.world.enable_cache(cache_level)
log.msg("Starting timekeeping...")
self.timestamp = reactor.seconds()
self.time = self.world.time
self.update_season()
self.time_loop = LoopingCall(self.update_time)
self.time_loop.start(2)
log.msg("Starting entity updates...")
# Start automatons.
for automaton in self.automatons:
automaton.start()
self.chat_consumers = set()
log.msg("Factory successfully initialized for world '%s'!" % self.name)
def stopFactory(self):
"""
Called before factory stops listening on ports. Used to perform
shutdown tasks.
"""
log.msg("Shutting down world...")
# Stop automatons. Technically, they may not actually halt until their
#.........这里部分代码省略.........