本文整理汇总了Python中bravo.world.World.save_chunk方法的典型用法代码示例。如果您正苦于以下问题:Python World.save_chunk方法的具体用法?Python World.save_chunk怎么用?Python World.save_chunk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bravo.world.World
的用法示例。
在下文中一共展示了World.save_chunk方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestWorldChunks
# 需要导入模块: from bravo.world import World [as 别名]
# 或者: from bravo.world.World import save_chunk [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: World
# 需要导入模块: from bravo.world import World [as 别名]
# 或者: from bravo.world.World import save_chunk [as 别名]
os.makedirs(target)
print "Making map of %dx%d chunks in %s" % (size, size, target)
print "Using pipeline: %s" % ", ".join(plugin.name for plugin in pipeline)
world = World(target)
world.pipeline = pipeline
world.season = None
counts = [1, 2, 4, 5, 8]
count = 0
total = size ** 2
cpu = 0
before = time.time()
for i, j in product(xrange(size), repeat=2):
start = time.time()
chunk = world.load_chunk(i, j)
cpu += (time.time() - start)
world.save_chunk(chunk)
count += 1
if count >= counts[0]:
print "Status: %d/%d (%.2f%%)" % (count, total, count * 100 / total)
counts.append(counts.pop(0) * 10)
taken = time.time() - before
print "Finished!"
print "Took %.2f seconds to generate (%dms/chunk)" % (taken,
taken * 1000 / size)
print "Spent %.2f seconds on CPU (%dms/chunk)" % (cpu, cpu * 1000 / size)
示例3: BravoFactory
# 需要导入模块: from bravo.world import World [as 别名]
# 或者: from bravo.world.World import save_chunk [as 别名]
#.........这里部分代码省略.........
"""
Broadcast a packet to all players except the originating player.
Useful for certain packets like player entity spawns which should
never be reflexive.
"""
for player in self.protocols.itervalues():
if player is not protocol:
player.transport.write(packet)
def broadcast_for_chunk(self, packet, x, z):
"""
Broadcast a packet to all players that have a certain chunk loaded.
`x` and `z` are chunk coordinates, not block coordinates.
"""
for player in self.protocols.itervalues():
if (x, z) in player.chunks:
player.transport.write(packet)
def flush_chunk(self, chunk):
"""
Flush a damaged chunk to all players that have it loaded.
"""
if chunk.is_damaged():
packet = chunk.get_damage_packet()
for player in self.protocols.itervalues():
if (chunk.x, chunk.z) in player.chunks:
player.transport.write(packet)
chunk.clear_damage()
def give(self, coords, block, quantity):
"""
Spawn a pickup at the specified coordinates.
The coordinates need to be in pixels, not blocks.
If the size of the stack is too big, multiple stacks will be dropped.
:param tuple coords: coordinates, in pixels
:param tuple block: key of block or item to drop
:param int quantity: number of blocks to drop in the stack
"""
x, y, z = coords
while quantity > 0:
entity = self.create_entity(x // 32, y // 32, z // 32, "Item",
item=block, quantity=min(quantity, 64))
packet = entity.save_to_packet()
packet += make_packet("create", eid=entity.eid)
self.broadcast(packet)
quantity -= 64
def players_near(self, player, radius):
"""
Obtain other players within a radius of a given player.
Radius is measured in blocks.
"""
for i in (p for p in self.protocols.itervalues()
if player.location.distance(p.location) <= radius and
p.player != player):
yield i.player
def stopFactory(self):
"""
Called before factory stops listening on ports. Used to perform
shutdown tasks.
"""
if not self.world.saving:
return
log.msg("Shutting down; flushing world data...")
# Flush all dirty chunks to disk.
for chunk in self.world.dirty_chunk_cache.itervalues():
self.world.save_chunk(chunk)
# Write back current world time.
self.world.time = self.time
self.world.serializer.save_level(self.world)
log.msg("World data saved!")
def pauseProducing(self):
pass
def resumeProducing(self):
pass
def stopProducing(self):
pass
示例4: TestWorldChunks
# 需要导入模块: from bravo.world import World [as 别名]
# 或者: from bravo.world.World import save_chunk [as 别名]
class TestWorldChunks(unittest.TestCase):
def setUp(self):
self.name = "unittest"
self.d = tempfile.mkdtemp()
bravo.config.configuration.add_section("world unittest")
bravo.config.configuration.set("world unittest", "url", "file://%s" % self.d)
bravo.config.configuration.set("world unittest", "serializer",
"alpha")
self.w = World(self.name)
self.w.pipeline = []
self.w.start()
def tearDown(self):
self.w.stop()
del self.w
shutil.rmtree(self.d)
bravo.config.configuration.remove_section("world unittest")
def test_trivial(self):
pass
@inlineCallbacks
def test_get_block(self):
chunk = yield self.w.request_chunk(0, 0)
# Fill the chunk with random stuff.
chunk.blocks = numpy.fromstring(numpy.random.bytes(chunk.blocks.size),
dtype=numpy.uint8)
chunk.blocks.shape = (16, 16, 128)
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 = numpy.fromstring(numpy.random.bytes(chunk.blocks.size),
dtype=numpy.uint8)
chunk.metadata.shape = (16, 16, 128)
for x, y, z in product(xrange(2), xrange(2), xrange(2)):
# 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 = numpy.fromstring(numpy.random.bytes(chunk.blocks.size),
dtype=numpy.uint8)
chunk.blocks.shape = (16, 16, 128)
# Evict the chunk and grab it again.
self.w.save_chunk(chunk)
del chunk
self.w.chunk_cache.clear()
self.w.dirty_chunk_cache.clear()
chunk = yield self.w.request_chunk(0, 0)
for x, y, z in product(xrange(2), xrange(2), xrange(2)):
# 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 = numpy.fromstring(numpy.random.bytes(chunk.blocks.size),
dtype=numpy.uint8)
chunk.blocks.shape = (16, 16, 128)
# Evict the chunk and grab it again.
self.w.save_chunk(chunk)
del chunk
self.w.chunk_cache.clear()
self.w.dirty_chunk_cache.clear()
chunk = yield self.w.request_chunk(-1, -1)
for x, y, z in product(xrange(2), xrange(2), xrange(2)):
block = yield self.w.get_block((x - 16, y, z - 16))
self.assertEqual(block, chunk.get_block((x, y, z)))
@inlineCallbacks
def test_get_metadata_readback(self):
chunk = yield self.w.request_chunk(0, 0)
#.........这里部分代码省略.........