bn::regular_bg_map_ptr class

std::shared_ptr like smart pointer that retains shared ownership of a regular background map.

Several regular_bg_map_ptr objects may own the same regular background.

The regular background map is released when the last remaining regular_bg_map_ptr owning it is destroyed.

Public static functions

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

Constructors, destructors, conversion operators

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

Public functions

auto operator=(const regular_bg_map_ptr& other) -> regular_bg_map_ptr&
Copy assignment operator.
auto operator=(regular_bg_map_ptr&& other) -> regular_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 bpp() const -> bpp_mode
Returns the bits per pixel of the referenced color palette.
auto tiles_offset() const -> int
Returns how much tiles to offset in the cells of this map before writing them in VRAM.
auto palette_banks_offset() const -> int
Returns how much palette banks 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 regular_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 regular_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 regular_bg_tiles_ptr&
Returns the referenced tiles.
void set_tiles(const regular_bg_tiles_ptr& tiles)
Sets the referenced tiles.
void set_tiles(regular_bg_tiles_ptr&& tiles)
Sets the referenced tiles.
void set_tiles(const regular_bg_tiles_item& tiles_item)
Replaces the referenced tiles with a new tile set created with the given regular_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.
void set_tiles_and_palette(regular_bg_tiles_ptr tiles, bg_palette_ptr palette)
Sets the tiles and the color palette to reference.
void set_tiles_and_palette(const regular_bg_tiles_item& tiles_item, const bg_palette_item& palette_item)
Replaces the referenced tiles and color palette with the created with the given regular_bg_tiles_item and bg_palette_item.
auto vram() -> optional<span<regular_bg_map_cell>>
Returns the allocated memory in VRAM if this regular_bg_map_cell was created with allocate or allocate_optional; bn::nullopt otherwise.
auto handle() const -> int
Returns the internal handle.
void swap(regular_bg_map_ptr& other)
Exchanges the contents of this regular_bg_map_ptr with those of the other one.

Friends

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

Function documentation

static optional<regular_bg_map_ptr> bn::regular_bg_map_ptr::find(const regular_bg_map_item& map_item, const regular_bg_tiles_ptr& tiles, const bg_palette_ptr& palette)

Searches for a regular_bg_map_ptr which references the given information.

Parameters
map_item regular_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 regular_bg_map_ptr which references the given information if it has been found; bn::nullopt otherwise.

static optional<regular_bg_map_ptr> bn::regular_bg_map_ptr::find(const regular_bg_item& item)

Searches for a regular_bg_map_ptr which references the given information.

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

static regular_bg_map_ptr bn::regular_bg_map_ptr::create(const regular_bg_map_item& map_item, regular_bg_tiles_ptr tiles, bg_palette_ptr palette)

Searches for a regular_bg_map_ptr which references the given information. If it is not found, it creates a regular_bg_map_ptr which references it.

Parameters
map_item regular_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 regular_bg_map_ptr which references the given information if it has been found; otherwise it returns a regular_bg_map_ptr which references it.

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

static regular_bg_map_ptr bn::regular_bg_map_ptr::create(const regular_bg_item& item)

Searches for a regular_bg_map_ptr which references the given information. If it is not found, it creates a regular_bg_map_ptr which references it.

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

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

static regular_bg_map_ptr bn::regular_bg_map_ptr::create_new(const regular_bg_map_item& map_item, regular_bg_tiles_ptr tiles, bg_palette_ptr palette)

Creates a regular_bg_map_ptr which references the given map cells.

Parameters
map_item regular_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 regular_bg_map_ptr which references the given information.

The map system does not support multiple regular_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 regular_bg_map_ptr to avoid dangling references.

static regular_bg_map_ptr bn::regular_bg_map_ptr::create_new(const regular_bg_item& item)

Creates a regular_bg_map_ptr which references the given map cells.

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

The map system does not support multiple regular_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 regular_bg_map_ptr to avoid dangling references.

static regular_bg_map_ptr bn::regular_bg_map_ptr::allocate(const size& dimensions, regular_bg_tiles_ptr tiles, bg_palette_ptr palette)

Creates a regular_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 regular_bg_map_ptr which references a chunk of VRAM map cells not visible on the screen.

static optional<regular_bg_map_ptr> bn::regular_bg_map_ptr::create_optional(const regular_bg_map_item& map_item, regular_bg_tiles_ptr tiles, bg_palette_ptr palette)

Searches for a regular_bg_map_ptr which references the given information. If it is not found, it creates a regular_bg_map_ptr which references it.

Parameters
map_item regular_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 regular_bg_map_ptr which references the given information if it has been found; otherwise it returns a regular_bg_map_ptr which references it if the regular_bg_map_ptr can be allocated; bn::nullopt otherwise.

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

static optional<regular_bg_map_ptr> bn::regular_bg_map_ptr::create_optional(const regular_bg_item& item)

Searches for a regular_bg_map_ptr which references the given information. If it is not found, it creates a regular_bg_map_ptr which references it.

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

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

static optional<regular_bg_map_ptr> bn::regular_bg_map_ptr::create_new_optional(const regular_bg_map_item& map_item, regular_bg_tiles_ptr tiles, bg_palette_ptr palette)

Creates a regular_bg_map_ptr which references the given map cells.

Parameters
map_item regular_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 regular_bg_map_ptr which references the given information if the regular_bg_map_ptr can be allocated; bn::nullopt otherwise.

The map system does not support multiple regular_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 regular_bg_map_ptr to avoid dangling references.

static optional<regular_bg_map_ptr> bn::regular_bg_map_ptr::create_new_optional(const regular_bg_item& item)

Creates a regular_bg_map_ptr which references the given map cells.

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

The map system does not support multiple regular_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 regular_bg_map_ptr to avoid dangling references.

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

Creates a regular_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 regular_bg_map_ptr which references a chunk of VRAM map cells not visible on the screen if the regular_bg_map_ptr can be allocated; bn::nullopt otherwise.

bn::regular_bg_map_ptr::regular_bg_map_ptr(const regular_bg_map_ptr& other)

Copy constructor.

Parameters
other regular_bg_map_ptr to copy.

bn::regular_bg_map_ptr::regular_bg_map_ptr(regular_bg_map_ptr&& other) noexcept

Move constructor.

Parameters
other regular_bg_map_ptr to move.

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

Copy assignment operator.

Parameters
other regular_bg_map_ptr to copy.
Returns Reference to this.

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

Move assignment operator.

Parameters
other regular_bg_map_ptr to move.
Returns Reference to this.

bool bn::regular_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::regular_bg_map_ptr::set_cells_ref(const regular_bg_map_item& map_item)

Sets the map cells to handle.

Parameters
map_item regular_bg_map_item which references the map cells to search.

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

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

void bn::regular_bg_map_ptr::set_tiles(const regular_bg_tiles_ptr& tiles)

Sets the referenced tiles.

Parameters
tiles regular_bg_tiles_ptr to copy.

It must be compatible with the referenced color palette.

void bn::regular_bg_map_ptr::set_tiles(regular_bg_tiles_ptr&& tiles)

Sets the referenced tiles.

Parameters
tiles regular_bg_tiles_ptr to move.

It must be compatible with the referenced color palette.

void bn::regular_bg_map_ptr::set_tiles(const regular_bg_tiles_item& tiles_item)

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

Parameters
tiles_item It creates the new background tiles to reference.

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

The new background tiles must be compatible with the referenced color palette.

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

Sets the referenced color palette.

Parameters
palette bg_palette_ptr to copy.

It must be compatible with the referenced tiles.

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

Sets the referenced color palette.

Parameters
palette bg_palette_ptr to move.

It must be compatible with the referenced tiles.

void bn::regular_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.

The new color palette must be compatible with the referenced tiles.

void bn::regular_bg_map_ptr::set_tiles_and_palette(regular_bg_tiles_ptr tiles, bg_palette_ptr palette)

Sets the tiles and the color palette to reference.

Parameters
tiles regular_bg_tiles_ptr to reference.
palette bg_palette_ptr to reference.

void bn::regular_bg_map_ptr::set_tiles_and_palette(const regular_bg_tiles_item& tiles_item, const bg_palette_item& palette_item)

Replaces the referenced tiles and color palette with the created with the given regular_bg_tiles_item and bg_palette_item.

Parameters
tiles_item It creates the new background tiles to reference.
palette_item It creates the color palette to reference.

Before creating new resources, the resources referenced by this map are removed, so VRAM usage is reduced.

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

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

Parameters
other regular_bg_map_ptr to exchange the contents with.

void swap(regular_bg_map_ptr& a, regular_bg_map_ptr& b)

Exchanges the contents of a regular_bg_map_ptr with those of another one.

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