Exemple #1
0
    def run(self):
        """
		Preloads game data.

		Keeps releasing and acquiring lock, runs until lock can't be acquired.
		"""
        from horizons.entities import Entities

        try:
            # create own db reader instance, since it's not thread-safe
            from horizons.main import _create_main_db
            mydb = _create_main_db()

            preload_functions = [
                ActionSetLoader.load, TileSetLoader.load,
                Callback(Entities.load_grounds, mydb, load_now=True),
                Callback(Entities.load_buildings, mydb, load_now=True),
                Callback(Entities.load_units, load_now=True)
            ]

            for f in preload_functions:
                if not self.lock.acquire(False):
                    break
                log.debug("Preload: %s", f)
                f()
                log.debug("Preload: %s is done", f)
                self.lock.release()
            log.debug("Preloading done.")
        except Exception as e:
            log.warning("Exception occurred in preloading thread: %s", e)
        finally:
            if self.lock.locked():
                self.lock.release()
def generate_random_minimap(size, parameters):
    """Called as subprocess, calculates minimap data and passes it via string via stdout"""
    # called as standalone basically, so init everything we need
    from horizons.entities import Entities
    from horizons.main import _create_main_db

    if not VERSION.IS_DEV_VERSION:
        # Hack enable atlases.
        # Usually the minimap generator uses single tile files, but in release
        # mode these are not available. Therefor we have to hackenable atlases
        # for the minimap generation in this case. This forces the game to use
        # the correct imageloader
        # In normal dev mode + enabled atlases we ignore this and just continue
        # to use single tile files instead of atlases for the minimap generation.
        # These are always available in dev checkouts
        PATHS.DB_FILES = PATHS.DB_FILES + (PATHS.ATLAS_DB_PATH, )

    db = _create_main_db()
    horizons.globals.db = db
    horizons.globals.fife.init_animation_loader(not VERSION.IS_DEV_VERSION)
    Entities.load_grounds(db, load_now=False)  # create all references

    map_file = generate_random_map(*parameters)
    world = load_raw_world(map_file)
    location = Rect.init_from_topleft_and_size_tuples((0, 0), size)

    # communicate via stdout. Sometimes the process seems to print more information, therefore
    # we add markers around our data so it's easier for the caller to get to the data.
    args = (location, world, Minimap.COLORS['island'], Minimap.COLORS['water'])
    data = [(x, y, r, g, b)
            for (x, y), (r, g, b) in iter_minimap_points(*args)]
    print('DATA', json.dumps(data), 'ENDDATA')
def generate_random_minimap(size, parameters):
	"""Called as subprocess, calculates minimap data and passes it via string via stdout"""
	# called as standalone basically, so init everything we need
	from horizons.entities import Entities
	from horizons.main import _create_main_db

	if not VERSION.IS_DEV_VERSION:
		# Hack enable atlases.
		# Usually the minimap generator uses single tile files, but in release
		# mode these are not available. Therefor we have to hackenable atlases
		# for the minimap generation in this case. This forces the game to use
		# the correct imageloader
		# In normal dev mode + enabled atlases we ignore this and just continue
		# to use single tile files instead of atlases for the minimap generation.
		# These are always available in dev checkouts
		PATHS.DB_FILES = PATHS.DB_FILES + (PATHS.ATLAS_DB_PATH, )

	db = _create_main_db()
	horizons.globals.db = db
	horizons.globals.fife.init_animation_loader(not VERSION.IS_DEV_VERSION)
	Entities.load_grounds(db, load_now=False) # create all references

	map_file = generate_random_map(*parameters)
	world = load_raw_world(map_file)
	location = Rect.init_from_topleft_and_size_tuples((0, 0), size)

	# communicate via stdout. Sometimes the process seems to print more information, therefore
	# we add markers around our data so it's easier for the caller to get to the data.
	args = (location, world, Minimap.COLORS['island'], Minimap.COLORS['water'])
	data = [(x, y, r, g, b) for (x, y), (r, g, b) in iter_minimap_points_colors(*args)]
	print('DATA', json.dumps(data), 'ENDDATA')
Exemple #4
0
    def generate_minimap(cls, size, parameters):
        """Called as subprocess, calculates minimap data and passes it via string via stdout"""
        # called as standalone basically, so init everything we need
        from horizons.main import _create_main_db
        from horizons.entities import Entities
        from horizons.ext.dummy import Dummy

        db = _create_main_db()
        Entities.load_grounds(db, load_now=False)  # create all references
        map_file = SingleplayerMenu._generate_random_map(parameters)
        world = cls._load_raw_world(map_file)
        location = Rect.init_from_topleft_and_size_tuples((0, 0), size)
        minimap = Minimap(
            location,
            session=None,
            view=None,
            world=world,
            targetrenderer=Dummy(),
            imagemanager=Dummy(),
            cam_border=False,
            use_rotation=False,
            preview=True,
        )
        # communicate via stdout
        print minimap.dump_data()
	def run(self):
		"""
		Preloads game data.

		Keeps releasing and acquiring lock, runs until lock can't be acquired.
		"""
		from horizons.entities import Entities

		try:
			# create own db reader instance, since it's not thread-safe
			from horizons.main import _create_main_db
			mydb = _create_main_db()

			preload_functions = [
				ActionSetLoader.load,
				TileSetLoader.load,
				Callback(Entities.load_grounds, mydb, load_now=True),
				Callback(Entities.load_buildings, mydb, load_now=True),
				Callback(Entities.load_units, load_now=True)
			]

			for f in preload_functions:
				if not self.lock.acquire(False):
					break
				log.debug("Preload: %s", f)
				f()
				log.debug("Preload: %s is done", f)
				self.lock.release()
			log.debug("Preloading done.")
		except Exception as e:
			log.warning("Exception occurred in preloading thread: %s", e)
		finally:
			if self.lock.locked():
				self.lock.release()
def generate_random_minimap(size, parameters):
	"""Called as subprocess, calculates minimap data and passes it via string via stdout"""
	# called as standalone basically, so init everything we need
	from horizons.entities import Entities
	from horizons.ext.dummy import Dummy
	from horizons.main import _create_main_db

	if not VERSION.IS_DEV_VERSION:
		# Hack enable atlases.
		# Usually the minimap generator uses single tile files, but in release
		# mode these are not available. Therefor we have to hackenable atlases
		# for the minimap generation in this case. This forces the game to use
		# the correct imageloader
		# In normal dev mode + enabled atlases we ignore this and just continue
		# to use single tile files instead of atlases for the minimap generation.
		# These are always available in dev checkouts
		PATHS.DB_FILES = PATHS.DB_FILES + (PATHS.ATLAS_DB_PATH, )

	db = _create_main_db()
	horizons.globals.db = db
	horizons.globals.fife.init_animation_loader(not VERSION.IS_DEV_VERSION)
	Entities.load_grounds(db, load_now=False) # create all references

	map_file = generate_random_map(*parameters)
	world = load_raw_world(map_file)
	location = Rect.init_from_topleft_and_size_tuples((0, 0), size)
	minimap = Minimap(
		location,
		session=None,
		view=None,
		world=world,
		targetrenderer=Dummy(),
		imagemanager=Dummy(),
		cam_border=False,
		use_rotation=False,
		preview=True)

	# communicate via stdout
	print minimap.dump_data()
 def generate_minimap(cls, size, parameters):
     """Called as subprocess, calculates minimap data and passes it via string via stdout"""
     # called as standalone basically, so init everything we need
     from horizons.main import _create_main_db
     from horizons.entities import Entities
     from horizons.ext.dummy import Dummy
     db = _create_main_db()
     Entities.load_grounds(db, load_now=False)  # create all references
     map_file = SingleplayerMenu._generate_random_map(parameters)
     world = cls._load_raw_world(map_file)
     location = Rect.init_from_topleft_and_size_tuples((0, 0), size)
     minimap = Minimap(location,
                       session=None,
                       view=None,
                       world=world,
                       targetrenderer=Dummy(),
                       imagemanager=Dummy(),
                       cam_border=False,
                       use_rotation=False,
                       preview=True)
     # communicate via stdout
     print minimap.dump_data()
def generate_random_minimap(size, parameters):
	"""Called as subprocess, calculates minimap data and passes it via string via stdout"""
	# called as standalone basically, so init everything we need
	from horizons.entities import Entities
	from horizons.ext.dummy import Dummy
	from horizons.main import _create_main_db

	if not VERSION.IS_DEV_VERSION:
		# Hack enable atlases.
		# Usually the minimap generator uses single tile files, but in release
		# mode these are not available. Therefor we have to hackenable atlases
		# for the minimap generation in this case. This forces the game to use
		# the correct imageloader
		# In normal dev mode + enabled atlases we ignore this and just continue
		# to use single tile files instead of atlases for the minimap generation.
		# These are always available in dev checkouts
		PATHS.DB_FILES = PATHS.DB_FILES + (PATHS.ATLAS_DB_PATH, )

	db = _create_main_db()
	horizons.globals.db = db
	horizons.globals.fife.init_animation_loader(not VERSION.IS_DEV_VERSION)
	Entities.load_grounds(db, load_now=False) # create all references

	map_file = generate_random_map(*parameters)
	world = load_raw_world(map_file)
	location = Rect.init_from_topleft_and_size_tuples((0, 0), size)
	minimap = Minimap(
		location,
		session=None,
		view=None,
		world=world,
		targetrenderer=Dummy(),
		imagemanager=Dummy(),
		cam_border=False,
		use_rotation=False,
		preview=True)

	# communicate via stdout
	print minimap.dump_data()