def convert_pos(x, y, f): print('Generating', x, y) data = tgen.generate(x, y) for index, entity in enumerate(data.dynamic_entities): scale = entity.appearance.scale print('Dynamic entity %s: %s, level %s, scale %s' % (index, entity.get_type(), entity.level, scale))
def test_static_entities(self): with open('./tests/tgen_static.dat', 'rb') as fp: data = zlib.decompress(fp.read()) reader = ByteReader(data) source = [] while reader.get_left() > 0: entity = StaticEntityHeader() entity.read(reader) source.append(entity) chunk = tgen.generate(32803, 32803) self.assertEqual(len(chunk.static_entities), len(source)) for index, entity in enumerate(chunk.static_entities): header1 = entity.header header2 = source[index] self.assertEqual(header1.entity_type, header2.entity_type) self.assertEqual(header1.pos, header2.pos) self.assertEqual(header1.orientation, header2.orientation) self.assertEqual(header1.size, header2.size) self.assertEqual(header1.closed, header2.closed) self.assertEqual(header1.time_offset, header2.time_offset) self.assertEqual(header1.something8, header2.something8) self.assertEqual(header1.user_id, header2.user_id)
def test_static_entities(self): with open('./tests/tgen_static.dat', 'rb') as fp: data = zlib.decompress(fp.read()) reader = ByteReader(data) source = [] while reader.get_left() > 0: entity = StaticEntityHeader() entity.read(reader) source.append(entity) chunk = tgen.generate(32803, 32803) self.assertEqual(len(chunk.static_entities), len(source)) for index, entity in enumerate(chunk.static_entities): header1 = entity.header header2 = source[index] self.assertEqual(header1.entity_type, header2.entity_type) self.assertEqual(header1.pos, header2.pos) self.assertEqual(header1.orientation, header2.orientation) self.assertEqual(header1.size, header2.size) self.assertEqual(header1.closed, header2.closed) self.assertEqual(header1.time_offset, header2.time_offset) self.assertEqual(header1.something8, header2.something8) self.assertEqual(header1.user_id, header2.user_id) events = [ ('generate', (1007, 4974)), ('generate', (1007, 4973)), ('generate', (1007, 4972)), ('generate', (1007, 4971)), ('destroy', (1007, 4973)), ('generate', (1007, 4970)), ('destroy', (1007, 4972)), ('generate', (1007, 4969)) ] chunks = {} for (event, chunk) in events: if event == 'generate': chunks[chunk] = tgen.generate(*chunk) elif event == 'destroy': chunks[chunk].destroy()
def run_gen(self, seed): tgen.initialize(seed, self.data_path) while True: data = self.gen_queue.get() if data is None: break pos, f = data res = tgen.generate(*pos) self.loop.call_soon_threadsafe(f.set_result, res)
def run_gen(self, seed): tgen.initialize(seed) while True: data = self.gen_queue.get() if data is None: break key = (data.x, data.y) res = self.cache.get(key, None) if res is None: res = tgen.generate(data.x, data.y) self.cache[key] = res reactor.callFromThread(data.d.callback, res)
def run(self): print('Initializing tgen...') tgen.initialize(self.parent.seed, './data/') while self.running: key = self.gen_queue.get() x, y = key # print 'Generating chunk', x, y off_x = (x - self.parent.chunk_x) * 256.0 off_y = (y - self.parent.chunk_y) * 256.0 data = tgen.generate(x, y).get_render(off_x, off_y) res = ChunkData(data) self.cache[key] = res
def test_static_entities(self): with open('./tests/tgen_static.dat', 'rb') as fp: data = zlib.decompress(fp.read()) reader = ByteReader(data) source = [] while reader.get_left() > 0: entity = StaticEntityHeader() entity.read(reader) source.append(entity) chunk = tgen.generate(32803, 32803) self.assertEqual(len(chunk.static_entities), len(source)) for index, entity in enumerate(chunk.static_entities): header1 = entity.header header2 = source[index] self.assertEqual(header1.entity_type, header2.entity_type) self.assertEqual(header1.pos, header2.pos) self.assertEqual(header1.orientation, header2.orientation) self.assertEqual(header1.size, header2.size) self.assertEqual(header1.closed, header2.closed) self.assertEqual(header1.time_offset, header2.time_offset) self.assertEqual(header1.something8, header2.something8) self.assertEqual(header1.user_id, header2.user_id) events = [('generate', (1007, 4974)), ('generate', (1007, 4973)), ('generate', (1007, 4972)), ('generate', (1007, 4971)), ('destroy', (1007, 4973)), ('generate', (1007, 4970)), ('destroy', (1007, 4972)), ('generate', (1007, 4969))] chunks = {} for (event, chunk) in events: if event == 'generate': chunks[chunk] = tgen.generate(*chunk) elif event == 'destroy': chunks[chunk].destroy()
def run_gen(self, seed): tgen.initialize(seed, self.data_path) self.tgen_init = True while True: data = self.gen_queue.get() if data is None: break pos, f = data res = tgen.generate(*pos) def set_result(): try: f.set_result(res) except asyncio.InvalidStateError: return self.loop.call_soon_threadsafe(set_result)
# Copyright (c) Mathias Kaerlev 2013-2017. # # This file is part of cuwo. # # cuwo is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # cuwo is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with cuwo. If not, see <http://www.gnu.org/licenses/>. import sys sys.path.append('.') from cuwo import tgen tgen.initialize(123456, './data/') tgen.generate(5000, 5000)