def __init__(self, cost, diagonal=1.41): self.cost = cost self.diagonal = diagonal self._path_c = None self._callback = self._userdata = None if hasattr(self.cost, 'map_c'): self.width, self.height = self.cost.width, self.cost.height self._path_c = ffi.gc( self._path_new_using_map(self.cost.map_c, diagonal), self._path_delete, ) return if not hasattr(self.cost, 'get_tcod_path_ffi'): assert not callable(self.cost), \ "Any callback alone is missing width & height information. " \ "Wrap your callback in tcod.path.EdgeCostCallback" self.cost = NodeCostArray(self.cost) self._callback, self._userdata, self.width, self.height = \ self.cost.get_tcod_path_ffi() self._path_c = ffi.gc( self._path_new_using_function(self.width, self.height, self._callback, self._userdata, diagonal), self._path_delete, )
def __init__(self, cost: Any, diagonal: float = 1.41): self.cost = cost self.diagonal = diagonal self._path_c = None self._callback = self._userdata = None if hasattr(self.cost, "map_c"): self.shape = self.cost.width, self.cost.height self._path_c = ffi.gc( self._path_new_using_map(self.cost.map_c, diagonal), self._path_delete, ) return if not hasattr(self.cost, "get_tcod_path_ffi"): assert not callable(self.cost), ( "Any callback alone is missing shape information. " "Wrap your callback in tcod.path.EdgeCostCallback") self.cost = NodeCostArray(self.cost) self._callback, self._userdata, self.shape = ( self.cost.get_tcod_path_ffi()) self._path_c = ffi.gc( self._path_new_using_function( self.cost.shape[0], self.cost.shape[1], self._callback, self._userdata, diagonal, ), self._path_delete, )
def _claim(cls, cdata: Any) -> "Tileset": """Return a new Tileset that owns the provided TCOD_Tileset* object.""" self = object.__new__(cls) # type: Tileset if cdata == ffi.NULL: raise RuntimeError("Tileset initialized with nullptr.") self._tileset_p = ffi.gc(cdata, lib.TCOD_tileset_delete) return self
def __init__( self, dimensions: int, algorithm: int = 2, implementation: int = SIMPLE, hurst: float = 0.5, lacunarity: float = 2.0, octaves: float = 4, seed: Optional[tcod.random.Random] = None, ): if not 0 < dimensions <= 4: raise ValueError("dimensions must be in range 0 < n <= 4, got %r" % (dimensions, )) self._random = seed _random_c = seed.random_c if seed else ffi.NULL self._algorithm = algorithm self.noise_c = ffi.gc( ffi.cast( "struct TCOD_Noise*", lib.TCOD_noise_new(dimensions, hurst, lacunarity, _random_c), ), lib.TCOD_noise_delete, ) self._tdl_noise_c = ffi.new("TDLNoise*", (self.noise_c, dimensions, 0, octaves)) self.implementation = implementation # sanity check
def _as_cdata(self): cdata = ffi.gc( lib.TCOD_bsp_new_with_size(self.x, self.y, self.width, self.height), lib.TCOD_bsp_delete, ) cdata.level = self.level return cdata
def __init__(self, algorithm, seed=None): """Create a new instance using this algorithm and seed.""" if seed is None: seed = random.getrandbits(32) self.random_c = ffi.gc( ffi.cast('mersenne_data_t*', lib.TCOD_random_new_from_seed(algorithm, hash(seed) % (1 << 32))), lib.TCOD_random_delete)
def __init__( self, algorithm: int = MERSENNE_TWISTER, seed: Optional[Hashable] = None, ): """Create a new instance using this algorithm and seed.""" if seed is None: seed = random.getrandbits(32) self.random_c = ffi.gc( ffi.cast( "mersenne_data_t*", lib.TCOD_random_new_from_seed(algorithm, hash(seed) % (1 << 32)), ), lib.TCOD_random_delete, )
def __init__(self, dimensions, algorithm=2, implementation=SIMPLE, hurst=0.5, lacunarity=2.0, octaves=4, seed=None): if not 0 < dimensions <= 4: raise ValueError('dimensions must be in range 0 < n <= 4, got %r' % (dimensions,)) self._random = seed _random_c = seed.random_c if seed else ffi.NULL self._algorithm = algorithm self.noise_c = ffi.gc( ffi.cast( 'perlin_data_t*', lib.TCOD_noise_new(dimensions, hurst, lacunarity, _random_c), ), lib.TCOD_noise_delete) self._tdl_noise_c = ffi.new('TDLNoise*', (self.noise_c, dimensions, 0, octaves)) self.implementation = implementation # sanity check
def __init__(self, width, height): self.width, self.height = width, height self.image_c = ffi.gc(lib.TCOD_image_new(width, height), lib.TCOD_image_delete)
def __init__(self, tile_width: int, tile_height: int) -> None: self._tileset_p = ffi.gc( lib.TCOD_tileset_new(tile_width, tile_height), lib.TCOD_tileset_delete, )