Draws dungeon objects to background buffers using game patterns. More...
#include <object_drawer.h>
Public Member Functions | |
ObjectDrawer (Rom *rom, const uint8_t *room_gfx_buffer=nullptr) | |
absl::Status | DrawObject (const RoomObject &object, gfx::BackgroundBuffer &bg1, gfx::BackgroundBuffer &bg2, const gfx::PaletteGroup &palette_group) |
Draw a room object to background buffers. | |
absl::Status | DrawObjectList (const std::vector< RoomObject > &objects, gfx::BackgroundBuffer &bg1, gfx::BackgroundBuffer &bg2, const gfx::PaletteGroup &palette_group) |
Draw all objects in a room. | |
int | GetDrawRoutineId (int16_t object_id) const |
Get draw routine ID for an object. | |
void | InitializeDrawRoutines () |
Initialize draw routine registry Must be called before drawing objects. | |
void | DrawTileToBitmap (gfx::Bitmap &bitmap, const gfx::TileInfo &tile_info, int pixel_x, int pixel_y, const uint8_t *tiledata) |
Draw a single tile directly to bitmap. | |
Private Types | |
using | DrawRoutine = std::function< void(ObjectDrawer *, const RoomObject &, gfx::BackgroundBuffer &, std::span< const gfx::TileInfo >)> |
Private Attributes | |
std::unordered_map< int16_t, int > | object_to_routine_map_ |
std::vector< DrawRoutine > | draw_routines_ |
bool | routines_initialized_ = false |
Rom * | rom_ |
const uint8_t * | room_gfx_buffer_ |
Static Private Attributes | |
static constexpr int | kMaxTilesX = 64 |
static constexpr int | kMaxTilesY = 64 |
Draws dungeon objects to background buffers using game patterns.
This class interprets object IDs and draws them to BG1/BG2 buffers using the patterns extracted from the game's drawing routines. Based on ZScream's DungeonObjectData.cs and Subtype1_Draw.cs patterns.
Architecture:
Definition at line 32 of file object_drawer.h.
|
private |
Definition at line 88 of file object_drawer.h.
|
explicit |
Definition at line 12 of file object_drawer.cc.
References InitializeDrawRoutines().
absl::Status yaze::zelda3::ObjectDrawer::DrawObject | ( | const RoomObject & | object, |
gfx::BackgroundBuffer & | bg1, | ||
gfx::BackgroundBuffer & | bg2, | ||
const gfx::PaletteGroup & | palette_group | ||
) |
Draw a room object to background buffers.
object | The object to draw |
bg1 | Background layer 1 buffer |
bg2 | Background layer 2 buffer |
palette_group | Current palette group for color mapping |
Definition at line 17 of file object_drawer.cc.
References yaze::zelda3::RoomObject::BG2, draw_routines_, GetDrawRoutineId(), yaze::Rom::is_loaded(), LOG_DEBUG, rom_, routines_initialized_, yaze::zelda3::RoomObject::set_rom(), yaze::zelda3::RoomObject::tiles(), and WriteTile8().
Referenced by DrawObjectList(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), and yaze::zelda3::TEST_F().
absl::Status yaze::zelda3::ObjectDrawer::DrawObjectList | ( | const std::vector< RoomObject > & | objects, |
gfx::BackgroundBuffer & | bg1, | ||
gfx::BackgroundBuffer & | bg2, | ||
const gfx::PaletteGroup & | palette_group | ||
) |
Draw all objects in a room.
objects | Vector of room objects |
bg1 | Background layer 1 buffer |
bg2 | Background layer 2 buffer |
palette_group | Current palette group for color mapping |
Definition at line 67 of file object_drawer.cc.
References yaze::gfx::BackgroundBuffer::bitmap(), and DrawObject().
Referenced by yaze::zelda3::Room::RenderObjectsToBackground(), yaze::test::TEST_F(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), yaze::zelda3::TEST_F(), and yaze::zelda3::TEST_F().
int yaze::zelda3::ObjectDrawer::GetDrawRoutineId | ( | int16_t | object_id | ) | const |
Get draw routine ID for an object.
object_id | The object ID to look up |
Definition at line 213 of file object_drawer.cc.
References object_to_routine_map_.
Referenced by DrawObject().
void yaze::zelda3::ObjectDrawer::InitializeDrawRoutines | ( | ) |
Initialize draw routine registry Must be called before drawing objects.
Definition at line 103 of file object_drawer.cc.
References draw_routines_, DrawDiagonalAcute_1to16(), DrawDiagonalGrave_1to16(), DrawDownwards2x2_1to15or32(), DrawDownwards2x2_1to16(), DrawDownwards4x2_1to15or26(), DrawDownwards4x2_1to16_BothBG(), DrawDownwardsDecor4x2spaced4_1to16(), DrawDownwardsEdge1x1_1to16(), DrawDownwardsHasEdge1x1_1to16_plus3(), DrawDownwardsLeftCorners2x1_1to16_plus12(), DrawDownwardsRightCorners2x1_1to16_plus12(), DrawRightwards2x2_1to15or32(), DrawRightwards2x2_1to16(), DrawRightwards2x4_1to15or26(), DrawRightwards2x4spaced4_1to16(), DrawRightwards2x4spaced4_1to16_BothBG(), DrawRightwards4x4_1to16(), object_to_routine_map_, and routines_initialized_.
Referenced by ObjectDrawer().
void yaze::zelda3::ObjectDrawer::DrawTileToBitmap | ( | gfx::Bitmap & | bitmap, |
const gfx::TileInfo & | tile_info, | ||
int | pixel_x, | ||
int | pixel_y, | ||
const uint8_t * | tiledata | ||
) |
Draw a single tile directly to bitmap.
bitmap | Target bitmap to draw to |
tile_info | Tile information (ID, palette, mirroring) |
pixel_x | X pixel coordinate in bitmap |
pixel_y | Y pixel coordinate in bitmap |
tiledata | Source graphics data from ROM |
Definition at line 760 of file object_drawer.cc.
References yaze::gfx::Bitmap::height(), yaze::gfx::TileInfo::horizontal_mirror_, yaze::gfx::TileInfo::id_, yaze::gfx::Bitmap::is_active(), LOG_DEBUG, yaze::gfx::Bitmap::mutable_data(), yaze::gfx::TileInfo::palette_, yaze::gfx::Bitmap::set_modified(), yaze::gfx::TileInfo::vertical_mirror_, and yaze::gfx::Bitmap::width().
Referenced by WriteTile8().
|
private |
Definition at line 227 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 245 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 266 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by DrawRightwards2x4spaced4_1to16_BothBG(), and InitializeDrawRoutines().
|
private |
Definition at line 286 of file object_drawer.cc.
References DrawRightwards2x4spaced4_1to16().
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 293 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 309 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by DrawDiagonalAcute_1to16_BothBG(), and InitializeDrawRoutines().
|
private |
Definition at line 326 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by DrawDiagonalGrave_1to16_BothBG(), and InitializeDrawRoutines().
|
private |
Definition at line 343 of file object_drawer.cc.
References DrawDiagonalAcute_1to16().
|
private |
Definition at line 349 of file object_drawer.cc.
References DrawDiagonalGrave_1to16().
|
private |
Definition at line 355 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 369 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 382 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 395 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 409 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 423 of file object_drawer.cc.
References WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 433 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 450 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 463 of file object_drawer.cc.
References WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 473 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 490 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 507 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 524 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 541 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 558 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
|
private |
Definition at line 578 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 596 of file object_drawer.cc.
References yaze::zelda3::RoomObject::id_, LOG_DEBUG, yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by DrawDownwards4x2_1to16_BothBG(), and InitializeDrawRoutines().
|
private |
Definition at line 633 of file object_drawer.cc.
References DrawDownwards4x2_1to15or26().
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 640 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 660 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 676 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 689 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 702 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 716 of file object_drawer.cc.
References yaze::zelda3::RoomObject::size_, WriteTile8(), yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by InitializeDrawRoutines().
|
private |
Definition at line 734 of file object_drawer.cc.
References yaze::gfx::BackgroundBuffer::bitmap(), DrawTileToBitmap(), LOG_DEBUG, and room_gfx_buffer_.
Referenced by CustomDraw(), DrawDiagonalAcute_1to16(), DrawDiagonalGrave_1to16(), DrawDoorSwitcherer(), DrawDownwards2x2_1to15or32(), DrawDownwards2x2_1to16(), DrawDownwards4x2_1to15or26(), DrawDownwardsDecor4x2spaced4_1to16(), DrawDownwardsEdge1x1_1to16(), DrawDownwardsHasEdge1x1_1to16_plus3(), DrawDownwardsLeftCorners2x1_1to16_plus12(), DrawDownwardsRightCorners2x1_1to16_plus12(), DrawObject(), DrawRightwards1x1Solid_1to16_plus3(), DrawRightwards1x2_1to16_plus2(), DrawRightwards2x2_1to15or32(), DrawRightwards2x2_1to16(), DrawRightwards2x4_1to15or26(), DrawRightwards2x4spaced4_1to16(), DrawRightwards4x4_1to16(), DrawRightwardsBottomCorners1x2_1to16_plus13(), DrawRightwardsDecor2x2spaced12_1to16(), DrawRightwardsDecor4x3spaced4_1to16(), DrawRightwardsDecor4x4spaced2_1to16(), DrawRightwardsDoubled2x2spaced2_1to16(), DrawRightwardsHasEdge1x1_1to16_plus2(), DrawRightwardsHasEdge1x1_1to16_plus3(), DrawRightwardsPillar2x4spaced4_1to16(), DrawRightwardsStatue2x3spaced2_1to16(), and DrawRightwardsTopCorners1x2_1to16_plus13().
|
private |
Definition at line 755 of file object_drawer.cc.
References kMaxTilesX, and kMaxTilesY.
|
private |
Definition at line 167 of file object_drawer.h.
Referenced by GetDrawRoutineId(), and InitializeDrawRoutines().
|
private |
Definition at line 168 of file object_drawer.h.
Referenced by DrawObject(), and InitializeDrawRoutines().
|
private |
Definition at line 169 of file object_drawer.h.
Referenced by DrawObject(), and InitializeDrawRoutines().
|
private |
Definition at line 171 of file object_drawer.h.
Referenced by DrawObject().
|
private |
Definition at line 172 of file object_drawer.h.
Referenced by WriteTile8().
|
staticconstexprprivate |
Definition at line 175 of file object_drawer.h.
Referenced by IsValidTilePosition().
|
staticconstexprprivate |
Definition at line 176 of file object_drawer.h.
Referenced by IsValidTilePosition().