Skip to content

renderer

FreeBodyEngine.core.tilemap.renderer #

chunk_mesh_sig = types.Tuple((types.float32[:, :], types.float32[:, :], types.uint32[:]))(types.uint8[:], types.int32, types.int32) module-attribute #

TilemapInjector(chunk_size, tile_size) #

Bases: Injector

Bakes a tilemap's chunk/tile sizes as literal constants into the tilemap shader source, since the shader has no other way to know a given tilemap's fixed dimensions.

Args: chunk_size: Width/height of a chunk, in tiles. tile_size: Size of a tile, in world units.

chunk_size = chunk_size instance-attribute #

tile_size = tile_size instance-attribute #

source_inject(source) #

Replaces the _ENGINE_* placeholder tokens in source with this tilemap's actual chunk/tile sizes.

TilemapRenderer(position, rotation, scale) #

Bases: Node2D

Draws a Tilemap's chunks. Must be a direct child of a Tilemap node (see parental_requirement) - created and attached automatically by Tilemap.create_renderer, not meant to be added directly.

Args: position: Local position, relative to the parent Tilemap. rotation: Local rotation, relative to the parent Tilemap. scale: Local scale, relative to the parent Tilemap.

parent instance-attribute #

parental_requirement = 'Tilemap' instance-attribute #

texture_paths = [] instance-attribute #

draw(camera) #

Draws every visible chunk of every layer on the parent tilemap, one draw call per chunk - the chunk's mesh is rebuilt from its raw tile data every call rather than cached.

on_initialize() #

Creates the tilemap material, generating its shader source with this tilemap's chunk/tile sizes baked in via TilemapInjector.

generate_chunk_mesh(chunk_data, tile_size, chunk_size) #

Builds a quad mesh for one chunk from its flat tile data, skipping empty tiles (image_id < 0 and sprite_id == 0) entirely so they cost nothing to draw.

Each tile's vertices carry its image_id/sprite_id (not a UV) in the 3rd/4th vertex components - the actual texture lookup happens in the tilemap shader, which is why uv_array only ever holds the fixed (0,0)-(1,1) quad corners.

Parameters:

Name Type Description Default
chunk_data ndarray

The chunk's flat per-tile value array (see Chunk.tiles).

required
tile_size int

Size of a tile in world units.

required
chunk_size int

Width/height of the chunk in tiles.

required

Returns:

Type Description
ndarray

(vertices, uv_array, indices), each trimmed to just the tiles

ndarray

actually emitted.