cleanup bitmap and object renderer
This commit is contained in:
@@ -52,7 +52,7 @@ class Bitmap {
|
||||
if (pixel_data_ == nullptr) {
|
||||
pixel_data_ = data_.data();
|
||||
}
|
||||
this->pixel_data_[position] = value;
|
||||
pixel_data_[position] = value;
|
||||
modified_ = true;
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ class Bitmap {
|
||||
if (pixel_data_ == nullptr) {
|
||||
pixel_data_ = data_.data();
|
||||
}
|
||||
this->pixel_data_[position] = value & 0xFF;
|
||||
this->pixel_data_[position + 1] = (value >> 8) & 0xFF;
|
||||
pixel_data_[position] = value & 0xFF;
|
||||
pixel_data_[position + 1] = (value >> 8) & 0xFF;
|
||||
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) {
|
||||
// Convert ImVec4 (RGBA) to SDL_Color (RGBA)
|
||||
SDL_Color sdl_color;
|
||||
@@ -111,7 +94,7 @@ class Bitmap {
|
||||
SDL_MapRGB(surface_->format, sdl_color.r, sdl_color.g, sdl_color.b);
|
||||
|
||||
// Write the color index to the pixel data
|
||||
this->pixel_data_[position] = index;
|
||||
pixel_data_[position] = index;
|
||||
modified_ = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,11 +51,11 @@ class DungeonObjectRenderer : public SharedROM {
|
||||
|
||||
private:
|
||||
struct SubtypeInfo {
|
||||
uint32_t subtypePtr;
|
||||
uint32_t routinePtr;
|
||||
uint32_t subtype_ptr;
|
||||
uint32_t routine_ptr;
|
||||
};
|
||||
|
||||
SubtypeInfo FetchSubtypeInfo(uint16_t objectId) {
|
||||
SubtypeInfo FetchSubtypeInfo(uint16_t object_id) {
|
||||
SubtypeInfo info;
|
||||
|
||||
// Determine the subtype based on objectId
|
||||
@@ -64,32 +64,34 @@ class DungeonObjectRenderer : public SharedROM {
|
||||
// Based on the subtype, fetch the correct pointers
|
||||
switch (subtype) {
|
||||
case 1: // Subtype 1
|
||||
info.subtypePtr = core::subtype1_tiles + (objectId & 0xFF) * 2;
|
||||
info.routinePtr = core::subtype1_tiles + 0x200 + (objectId & 0xFF) * 2;
|
||||
std::cout << "Subtype 1 " << std::hex << info.subtypePtr << std::endl;
|
||||
std::cout << "Subtype 1 " << std::hex << info.routinePtr << std::endl;
|
||||
info.subtype_ptr = core::subtype1_tiles + (object_id & 0xFF) * 2;
|
||||
info.routine_ptr =
|
||||
core::subtype1_tiles + 0x200 + (object_id & 0xFF) * 2;
|
||||
std::cout << "Subtype 1 " << std::hex << info.subtype_ptr << std::endl;
|
||||
std::cout << "Subtype 1 " << std::hex << info.routine_ptr << std::endl;
|
||||
break;
|
||||
case 2: // Subtype 2
|
||||
info.subtypePtr = core::subtype2_tiles + (objectId & 0x7F) * 2;
|
||||
info.routinePtr = core::subtype2_tiles + 0x80 + (objectId & 0x7F) * 2;
|
||||
info.subtype_ptr = core::subtype2_tiles + (object_id & 0x7F) * 2;
|
||||
info.routine_ptr = core::subtype2_tiles + 0x80 + (object_id & 0x7F) * 2;
|
||||
break;
|
||||
case 3: // Subtype 3
|
||||
info.subtypePtr = core::subtype3_tiles + (objectId & 0xFF) * 2;
|
||||
info.routinePtr = core::subtype3_tiles + 0x100 + (objectId & 0xFF) * 2;
|
||||
info.subtype_ptr = core::subtype3_tiles + (object_id & 0xFF) * 2;
|
||||
info.routine_ptr =
|
||||
core::subtype3_tiles + 0x100 + (object_id & 0xFF) * 2;
|
||||
break;
|
||||
default:
|
||||
// Handle unknown subtype
|
||||
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
|
||||
while (true) {
|
||||
uint8_t opcode = memory_.ReadByte(info.routinePtr);
|
||||
uint8_t opcode = memory_.ReadByte(info.routine_ptr);
|
||||
if (opcode == 0x60) {
|
||||
break;
|
||||
}
|
||||
info.routinePtr++;
|
||||
info.routine_ptr++;
|
||||
}
|
||||
|
||||
return info;
|
||||
@@ -138,7 +140,7 @@ class DungeonObjectRenderer : public SharedROM {
|
||||
|
||||
void RenderObject(const SubtypeInfo& info) {
|
||||
cpu.PB = 0x01;
|
||||
cpu.PC = cpu.ReadWord(0x01 << 16 | info.routinePtr);
|
||||
cpu.PC = cpu.ReadWord(0x01 << 16 | info.routine_ptr);
|
||||
|
||||
int i = 0;
|
||||
while (true) {
|
||||
|
||||
Reference in New Issue
Block a user