cleanup bitmap and object renderer

This commit is contained in:
scawful
2023-12-29 22:43:40 -05:00
parent 196de8b87c
commit 27098a7917
2 changed files with 21 additions and 36 deletions

View File

@@ -52,7 +52,7 @@ class Bitmap {
if (pixel_data_ == nullptr) { if (pixel_data_ == nullptr) {
pixel_data_ = data_.data(); pixel_data_ = data_.data();
} }
this->pixel_data_[position] = value; pixel_data_[position] = value;
modified_ = true; modified_ = true;
} }
@@ -60,8 +60,8 @@ class Bitmap {
if (pixel_data_ == nullptr) { if (pixel_data_ == nullptr) {
pixel_data_ = data_.data(); pixel_data_ = data_.data();
} }
this->pixel_data_[position] = value & 0xFF; pixel_data_[position] = value & 0xFF;
this->pixel_data_[position + 1] = (value >> 8) & 0xFF; pixel_data_[position + 1] = (value >> 8) & 0xFF;
modified_ = true; modified_ = true;
} }
@@ -81,23 +81,6 @@ class Bitmap {
} }
} }
Uint8 ConvertImVec4ToIndex8(const ImVec4 &color, SDL_Surface *surface) {
if (surface->format->format != SDL_PIXELFORMAT_INDEX8) {
throw std::runtime_error(
"Surface is not in SDL_PIXELFORMAT_INDEX8 format.");
}
// Convert ImVec4 (RGBA) to SDL_Color (RGBA)
SDL_Color sdl_color;
sdl_color.r = static_cast<Uint8>(color.x * 255);
sdl_color.g = static_cast<Uint8>(color.y * 255);
sdl_color.b = static_cast<Uint8>(color.z * 255);
sdl_color.a = static_cast<Uint8>(color.w * 255);
// Map SDL_Color to the nearest color index in the surface's palette
return SDL_MapRGB(surface->format, sdl_color.r, sdl_color.g, sdl_color.b);
}
void WriteColor(int position, const ImVec4 &color) { void WriteColor(int position, const ImVec4 &color) {
// Convert ImVec4 (RGBA) to SDL_Color (RGBA) // Convert ImVec4 (RGBA) to SDL_Color (RGBA)
SDL_Color sdl_color; SDL_Color sdl_color;
@@ -111,7 +94,7 @@ class Bitmap {
SDL_MapRGB(surface_->format, sdl_color.r, sdl_color.g, sdl_color.b); SDL_MapRGB(surface_->format, sdl_color.r, sdl_color.g, sdl_color.b);
// Write the color index to the pixel data // Write the color index to the pixel data
this->pixel_data_[position] = index; pixel_data_[position] = index;
modified_ = true; modified_ = true;
} }

View File

@@ -51,11 +51,11 @@ class DungeonObjectRenderer : public SharedROM {
private: private:
struct SubtypeInfo { struct SubtypeInfo {
uint32_t subtypePtr; uint32_t subtype_ptr;
uint32_t routinePtr; uint32_t routine_ptr;
}; };
SubtypeInfo FetchSubtypeInfo(uint16_t objectId) { SubtypeInfo FetchSubtypeInfo(uint16_t object_id) {
SubtypeInfo info; SubtypeInfo info;
// Determine the subtype based on objectId // Determine the subtype based on objectId
@@ -64,32 +64,34 @@ class DungeonObjectRenderer : public SharedROM {
// Based on the subtype, fetch the correct pointers // Based on the subtype, fetch the correct pointers
switch (subtype) { switch (subtype) {
case 1: // Subtype 1 case 1: // Subtype 1
info.subtypePtr = core::subtype1_tiles + (objectId & 0xFF) * 2; info.subtype_ptr = core::subtype1_tiles + (object_id & 0xFF) * 2;
info.routinePtr = core::subtype1_tiles + 0x200 + (objectId & 0xFF) * 2; info.routine_ptr =
std::cout << "Subtype 1 " << std::hex << info.subtypePtr << std::endl; core::subtype1_tiles + 0x200 + (object_id & 0xFF) * 2;
std::cout << "Subtype 1 " << std::hex << info.routinePtr << std::endl; std::cout << "Subtype 1 " << std::hex << info.subtype_ptr << std::endl;
std::cout << "Subtype 1 " << std::hex << info.routine_ptr << std::endl;
break; break;
case 2: // Subtype 2 case 2: // Subtype 2
info.subtypePtr = core::subtype2_tiles + (objectId & 0x7F) * 2; info.subtype_ptr = core::subtype2_tiles + (object_id & 0x7F) * 2;
info.routinePtr = core::subtype2_tiles + 0x80 + (objectId & 0x7F) * 2; info.routine_ptr = core::subtype2_tiles + 0x80 + (object_id & 0x7F) * 2;
break; break;
case 3: // Subtype 3 case 3: // Subtype 3
info.subtypePtr = core::subtype3_tiles + (objectId & 0xFF) * 2; info.subtype_ptr = core::subtype3_tiles + (object_id & 0xFF) * 2;
info.routinePtr = core::subtype3_tiles + 0x100 + (objectId & 0xFF) * 2; info.routine_ptr =
core::subtype3_tiles + 0x100 + (object_id & 0xFF) * 2;
break; break;
default: default:
// Handle unknown subtype // Handle unknown subtype
throw std::runtime_error("Unknown subtype for object ID: " + throw std::runtime_error("Unknown subtype for object ID: " +
std::to_string(objectId)); std::to_string(object_id));
} }
// Find the RTS of the subtype routine // Find the RTS of the subtype routine
while (true) { while (true) {
uint8_t opcode = memory_.ReadByte(info.routinePtr); uint8_t opcode = memory_.ReadByte(info.routine_ptr);
if (opcode == 0x60) { if (opcode == 0x60) {
break; break;
} }
info.routinePtr++; info.routine_ptr++;
} }
return info; return info;
@@ -138,7 +140,7 @@ class DungeonObjectRenderer : public SharedROM {
void RenderObject(const SubtypeInfo& info) { void RenderObject(const SubtypeInfo& info) {
cpu.PB = 0x01; cpu.PB = 0x01;
cpu.PC = cpu.ReadWord(0x01 << 16 | info.routinePtr); cpu.PC = cpu.ReadWord(0x01 << 16 | info.routine_ptr);
int i = 0; int i = 0;
while (true) { while (true) {