本文整理汇总了Python中bravo.world.World.load_chunk方法的典型用法代码示例。如果您正苦于以下问题:Python World.load_chunk方法的具体用法?Python World.load_chunk怎么用?Python World.load_chunk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bravo.world.World
的用法示例。
在下文中一共展示了World.load_chunk方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: World
# 需要导入模块: from bravo.world import World [as 别名]
# 或者: from bravo.world.World import load_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)
示例2: BravoFactory
# 需要导入模块: from bravo.world import World [as 别名]
# 或者: from bravo.world.World import load_chunk [as 别名]
#.........这里部分代码省略.........
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.
"""
location = Location()
location.x = x
location.y = y
location.z = z
entity = entities[name](eid=0, location=location, **kwargs)
self.register_entity(entity)
bigx = entity.location.x // 16
bigz = entity.location.z // 16
chunk = self.world.load_chunk(bigx, bigz)
chunk.entities.add(entity)
log.msg("Created entity %s" % entity)
return entity
def register_entity(self, entity):
"""
Registers an entity with this factory.
Registration is perhaps too fancy of a name; this method merely makes
sure that the entity has a unique and usable entity ID.
"""
if not entity.eid:
self.eid += 1
entity.eid = self.eid
log.msg("Registered entity %s" % entity)
def destroy_entity(self, entity):
"""
Destroy an entity.
The factory doesn't have to know about entities, but it is a good
place to put this logic.
"""
bigx = entity.location.x // 16
bigz = entity.location.z // 16
chunk = self.world.load_chunk(bigx, bigz)