bn::affine_bg_map_ptr class

std::shared_ptr like smart pointer that retains shared ownership of an affine background map.

Several affine_bg_map_ptr objects may own the same affine background.

The affine background map is released when the last remaining affine_bg_map_ptr owning it is destroyed.

Public static functions

static auto find(const affine_bg_map_item& map_item, const affine_bg_tiles_ptr& tiles, const bg_palette_ptr& palette) -> optional<affine_bg_map_ptr>
Searches for an affine_bg_map_ptr which references the given information.
static auto find(const affine_bg_item& item) -> optional<affine_bg_map_ptr>
Searches for an affine_bg_map_ptr which references the given information.
static auto create(const affine_bg_map_item& map_item, affine_bg_tiles_ptr tiles, bg_palette_ptr palette) -> affine_bg_map_ptr
Searches for an affine_bg_map_ptr which references the given information. If it is not found, it creates an affine_bg_map_ptr which references it.
static auto create(const affine_bg_item& item) -> affine_bg_map_ptr
Searches for an affine_bg_map_ptr which references the given information. If it is not found, it creates an affine_bg_map_ptr which references it.
static auto create_new(const affine_bg_map_item& map_item, affine_bg_tiles_ptr tiles, bg_palette_ptr palette) -> affine_bg_map_ptr
Creates an affine_bg_map_ptr which references the given map cells.
static auto create_new(const affine_bg_item& item) -> affine_bg_map_ptr
Creates an affine_bg_map_ptr which references the given map cells.
static auto allocate(const size& dimensions, affine_bg_tiles_ptr tiles, bg_palette_ptr palette) -> affine_bg_map_ptr
Creates an affine_bg_map_ptr which references a chunk of VRAM map cells not visible on the screen.
static auto create_optional(const affine_bg_map_item& map_item, affine_bg_tiles_ptr tiles, bg_palette_ptr palette) -> optional<affine_bg_map_ptr>
Searches for an affine_bg_map_ptr which references the given information. If it is not found, it creates an affine_bg_map_ptr which references it.
static auto create_optional(const affine_bg_item& item) -> optional<affine_bg_map_ptr>
Searches for an affine_bg_map_ptr which references the given information. If it is not found, it creates an affine_bg_map_ptr which references it.
static auto create_new_optional(const affine_bg_map_item& map_item, affine_bg_tiles_ptr tiles, bg_palette_ptr palette) -> optional<affine_bg_map_ptr>
Creates an affine_bg_map_ptr which references the given map cells.
static auto create_new_optional(const affine_bg_item& item) -> optional<affine_bg_map_ptr>
Creates an affine_bg_map_ptr which references the given map cells.
static auto allocate_optional(const size& dimensions, affine_bg_tiles_ptr tiles, bg_palette_ptr palette) -> optional<affine_bg_map_ptr>
Creates an affine_bg_map_ptr which references a chunk of VRAM map cells not visible on the screen.

Constructors, destructors, conversion operators

affine_bg_map_ptr(const affine_bg_map_ptr& other)
Copy constructor.
affine_bg_map_ptr(affine_bg_map_ptr&& other) noexcept
Move constructor.
~affine_bg_map_ptr()
Releases the referenced map cells if no more affine_bg_map_ptr objects reference to them.

Public functions

auto operator=(const affine_bg_map_ptr& other) -> affine_bg_map_ptr&
Copy assignment operator.
auto operator=(affine_bg_map_ptr&& other) -> affine_bg_map_ptr& noexcept
Move assignment operator.
auto id() const -> int
Returns the internal id.
auto dimensions() const -> size
Returns the size in map cells of the referenced map.
auto big() const -> bool
Indicates if this map is big or not.
auto tiles_offset() const -> int
Returns how much tiles to offset in the cells of this map before writing them in VRAM.
auto compression() const -> compression_type
Returns the compression of the referenced map cells.
auto cells_ref() const -> optional<span<const affine_bg_map_cell>>
Returns the referenced map cells unless it was created with allocate or allocate_optional. In that case, it returns bn::nullopt.
void set_cells_ref(const affine_bg_map_item& map_item)
Sets the map cells to handle.
void reload_cells_ref()
Uploads the referenced map cells to VRAM again to make visible the possible changes in them.
auto tiles() const -> const affine_bg_tiles_ptr&
Returns the referenced tiles.
void set_tiles(const affine_bg_tiles_ptr& tiles)
Sets the referenced tiles.
void set_tiles(affine_bg_tiles_ptr&& tiles)
Sets the referenced tiles.
void set_tiles(const affine_bg_tiles_item& tiles_item)
Replaces the referenced tiles with a new tile set created with the given affine_bg_tiles_item.
auto palette() const -> const bg_palette_ptr&
Returns the referenced color palette.
void set_palette(const bg_palette_ptr& palette)
Sets the referenced color palette.
void set_palette(bg_palette_ptr&& palette)
Sets the referenced color palette.
void set_palette(const bg_palette_item& palette_item)
Replaces the referenced color palette with a new tile set created with the given bg_palette_item.
auto vram() -> optional<span<affine_bg_map_cell>>
Returns the allocated memory in VRAM if this affine_bg_map_cell was created with allocate or allocate_optional; bn::nullopt otherwise.
auto handle() const -> int
Returns the internal handle.
void swap(affine_bg_map_ptr& other)
Exchanges the contents of this affine_bg_map_ptr with those of the other one.

Friends

void swap(affine_bg_map_ptr& a, affine_bg_map_ptr& b)
Exchanges the contents of an affine_bg_map_ptr with those of another one.
auto operator==(const affine_bg_map_ptr& a, const affine_bg_map_ptr& b) -> bool defaulted
Default equal operator.

Function documentation

static optional<affine_bg_map_ptr> bn::affine_bg_map_ptr::find(const affine_bg_map_item& map_item, const affine_bg_tiles_ptr& tiles, const bg_palette_ptr& palette)

Searches for an affine_bg_map_ptr which references the given information.

Parameters
map_item affine_bg_map_item which references the map cells to search.
tiles Referenced tiles of the map to search.
palette Referenced color palette of the map to search.
Returns affine_bg_map_ptr which references the given information if it has been found; bn::nullopt otherwise.

static optional<affine_bg_map_ptr> bn::affine_bg_map_ptr::find(const affine_bg_item& item)

Searches for an affine_bg_map_ptr which references the given information.

Parameters
item affine_bg_item which references the tiles, the color palette and the map cells to search.
Returns affine_bg_map_ptr which references the given information if it has been found; bn::nullopt otherwise.

static affine_bg_map_ptr bn::affine_bg_map_ptr::create(const affine_bg_map_item& map_item, affine_bg_tiles_ptr tiles, bg_palette_ptr palette)

Searches for an affine_bg_map_ptr which references the given information. If it is not found, it creates an affine_bg_map_ptr which references it.

Parameters
map_item affine_bg_map_item which references the map cells to search or handle.
tiles Referenced tiles of the map to search or handle.
palette Referenced color palette of the map to search or handle.
Returns affine_bg_map_ptr which references the given information if it has been found; otherwise it returns an affine_bg_map_ptr which references it.

The map cells are not copied but referenced, so they should outlive the affine_bg_map_ptr to avoid dangling references.

static affine_bg_map_ptr bn::affine_bg_map_ptr::create(const affine_bg_item& item)

Searches for an affine_bg_map_ptr which references the given information. If it is not found, it creates an affine_bg_map_ptr which references it.

Parameters
item affine_bg_item which references the tiles, the color palette and the map cells to search or handle.
Returns affine_bg_map_ptr which references the given information if it has been found; otherwise it returns an affine_bg_map_ptr which references it.

The map cells are not copied but referenced, so they should outlive the affine_bg_map_ptr to avoid dangling references.

static affine_bg_map_ptr bn::affine_bg_map_ptr::create_new(const affine_bg_map_item& map_item, affine_bg_tiles_ptr tiles, bg_palette_ptr palette)

Creates an affine_bg_map_ptr which references the given map cells.

Parameters
map_item affine_bg_map_item which references the map cells to handle.
tiles Referenced tiles of the map to handle.
palette Referenced color palette of the map to handle.
Returns affine_bg_map_ptr which references the given information.

The map system does not support multiple affine_bg_map_ptr items referencing to the same map cells. If you are not sure if the given map cells are already referenced or not, you should use the static create methods instead.

The map cells are not copied but referenced, so they should outlive the affine_bg_map_ptr to avoid dangling references.

static affine_bg_map_ptr bn::affine_bg_map_ptr::create_new(const affine_bg_item& item)

Creates an affine_bg_map_ptr which references the given map cells.

Parameters
item affine_bg_item which references the tiles, the color palette and the map cells to handle.
Returns affine_bg_map_ptr which references the given information.

The map system does not support multiple affine_bg_map_ptr items referencing to the same map cells. If you are not sure if the given map cells are already referenced or not, you should use the static create methods instead.

The map cells are not copied but referenced, so they should outlive the affine_bg_map_ptr to avoid dangling references.

static affine_bg_map_ptr bn::affine_bg_map_ptr::allocate(const size& dimensions, affine_bg_tiles_ptr tiles, bg_palette_ptr palette)

Creates an affine_bg_map_ptr which references a chunk of VRAM map cells not visible on the screen.

Parameters
dimensions Size in map cells of the map to allocate.
tiles Referenced tiles of the map to allocate.
palette Referenced color palette of the map to allocate.
Returns affine_bg_map_ptr which references a chunk of VRAM map cells not visible on the screen.

static optional<affine_bg_map_ptr> bn::affine_bg_map_ptr::create_optional(const affine_bg_map_item& map_item, affine_bg_tiles_ptr tiles, bg_palette_ptr palette)

Searches for an affine_bg_map_ptr which references the given information. If it is not found, it creates an affine_bg_map_ptr which references it.

Parameters
map_item affine_bg_map_item which references the map cells to search or handle.
tiles Referenced tiles of the map to search or handle.
palette Referenced color palette of the map to search or handle.
Returns affine_bg_map_ptr which references the given information if it has been found; otherwise it returns an affine_bg_map_ptr which references it if the affine_bg_map_ptr can be allocated; bn::nullopt otherwise.

The map cells are not copied but referenced, so they should outlive the affine_bg_map_ptr to avoid dangling references.

static optional<affine_bg_map_ptr> bn::affine_bg_map_ptr::create_optional(const affine_bg_item& item)

Searches for an affine_bg_map_ptr which references the given information. If it is not found, it creates an affine_bg_map_ptr which references it.

Parameters
item affine_bg_item which references the tiles, the color palette and the map cells to search or handle.
Returns affine_bg_map_ptr which references the given information if it has been found; otherwise it returns an affine_bg_map_ptr which references it if the affine_bg_map_ptr can be allocated; bn::nullopt otherwise.

The map cells are not copied but referenced, so they should outlive the affine_bg_map_ptr to avoid dangling references.

static optional<affine_bg_map_ptr> bn::affine_bg_map_ptr::create_new_optional(const affine_bg_map_item& map_item, affine_bg_tiles_ptr tiles, bg_palette_ptr palette)

Creates an affine_bg_map_ptr which references the given map cells.

Parameters
map_item affine_bg_map_item which references the map cells to handle.
tiles Referenced tiles of the map to handle.
palette Referenced color palette of the map to handle.
Returns affine_bg_map_ptr which references the given information if the affine_bg_map_ptr can be allocated; bn::nullopt otherwise.

The map system does not support multiple affine_bg_map_ptr items referencing to the same map cells. If you are not sure if the given map cells are already referenced or not, you should use the static create methods instead.

The map cells are not copied but referenced, so they should outlive the affine_bg_map_ptr to avoid dangling references.

static optional<affine_bg_map_ptr> bn::affine_bg_map_ptr::create_new_optional(const affine_bg_item& item)

Creates an affine_bg_map_ptr which references the given map cells.

Parameters
item affine_bg_item which references the tiles, the color palette and the map cells to handle.
Returns affine_bg_map_ptr which references the given information if the affine_bg_map_ptr can be allocated; bn::nullopt otherwise.

The map system does not support multiple affine_bg_map_ptr items referencing to the same map cells. If you are not sure if the given map cells are already referenced or not, you should use the static create methods instead.

The map cells are not copied but referenced, so they should outlive the affine_bg_map_ptr to avoid dangling references.

static optional<affine_bg_map_ptr> bn::affine_bg_map_ptr::allocate_optional(const size& dimensions, affine_bg_tiles_ptr tiles, bg_palette_ptr palette)

Creates an affine_bg_map_ptr which references a chunk of VRAM map cells not visible on the screen.

Parameters
dimensions Size in map cells of the map to allocate.
tiles Referenced tiles of the map to allocate.
palette Referenced color palette of the map to allocate.
Returns affine_bg_map_ptr which references a chunk of VRAM map cells not visible on the screen if the affine_bg_map_ptr can be allocated; bn::nullopt otherwise.

bn::affine_bg_map_ptr::affine_bg_map_ptr(const affine_bg_map_ptr& other)

Copy constructor.

Parameters
other affine_bg_map_ptr to copy.

bn::affine_bg_map_ptr::affine_bg_map_ptr(affine_bg_map_ptr&& other) noexcept

Move constructor.

Parameters
other affine_bg_map_ptr to move.

affine_bg_map_ptr& bn::affine_bg_map_ptr::operator=(const affine_bg_map_ptr& other)

Copy assignment operator.

Parameters
other affine_bg_map_ptr to copy.
Returns Reference to this.

affine_bg_map_ptr& bn::affine_bg_map_ptr::operator=(affine_bg_map_ptr&& other) noexcept

Move assignment operator.

Parameters
other affine_bg_map_ptr to move.
Returns Reference to this.

bool bn::affine_bg_map_ptr::big() const

Indicates if this map is big or not.

Big backgrounds are slower CPU wise and don't support wrapping (they can't be moved beyond their boundaries), but can have any width or height multiple of 256 pixels.

void bn::affine_bg_map_ptr::set_cells_ref(const affine_bg_map_item& map_item)

Sets the map cells to handle.

Parameters
map_item affine_bg_map_item which references the map cells to search.

The map system does not support multiple affine_bg_map_ptr items referencing to the same map cells.

The map cells are not copied but referenced, so they should outlive the affine_bg_map_ptr to avoid dangling references.

void bn::affine_bg_map_ptr::set_tiles(const affine_bg_tiles_ptr& tiles)

Sets the referenced tiles.

Parameters
tiles affine_bg_tiles_ptr to copy.

void bn::affine_bg_map_ptr::set_tiles(affine_bg_tiles_ptr&& tiles)

Sets the referenced tiles.

Parameters
tiles affine_bg_tiles_ptr to move.

void bn::affine_bg_map_ptr::set_tiles(const affine_bg_tiles_item& tiles_item)

Replaces the referenced tiles with a new tile set created with the given affine_bg_tiles_item.

Parameters
tiles_item It creates the new background tiles to reference.

Before creating a new background tile set, the affine_bg_tiles_ptr referenced by this map is removed, so VRAM usage is reduced.

void bn::affine_bg_map_ptr::set_palette(const bg_palette_ptr& palette)

Sets the referenced color palette.

Parameters
palette bg_palette_ptr to copy.

void bn::affine_bg_map_ptr::set_palette(bg_palette_ptr&& palette)

Sets the referenced color palette.

Parameters
palette bg_palette_ptr to move.

void bn::affine_bg_map_ptr::set_palette(const bg_palette_item& palette_item)

Replaces the referenced color palette with a new tile set created with the given bg_palette_item.

Parameters
palette_item It creates the new color palette to reference.

Before creating a new color palette, the bg_palette_ptr referenced by this map is removed, so VRAM usage is reduced.

void bn::affine_bg_map_ptr::swap(affine_bg_map_ptr& other)

Exchanges the contents of this affine_bg_map_ptr with those of the other one.

Parameters
other affine_bg_map_ptr to exchange the contents with.

void swap(affine_bg_map_ptr& a, affine_bg_map_ptr& b)

Exchanges the contents of an affine_bg_map_ptr with those of another one.

Parameters
a First affine_bg_map_ptr to exchange the contents with.
b Second affine_bg_map_ptr to exchange the contents with.