added light gun position scaling (now it works with a mouse)

This commit is contained in:
Thomas Jentzsch 2022-01-30 23:42:19 +01:00
parent d43227444a
commit 6e896f1228
2 changed files with 14 additions and 3 deletions

View File

@ -60,7 +60,7 @@ class StellaLIBRETRO
void* getROM() const { return rom_image.get(); }
uInt32 getROMSize() const { return rom_size; }
constexpr uInt32 getROMMax() const { return Cartridge::maxSize(); }
constexpr uInt32 getROMMax() const { return uInt32(Cartridge::maxSize()); }
uInt8* getRAM() { return system_ram; }
constexpr uInt32 getRAMSize() const { return 128; }
@ -100,6 +100,10 @@ class StellaLIBRETRO
return myOSystem->console().tia().height() * getVideoZoom();
}
const Common::Rect& getImageRect() const {
return myOSystem->frameBuffer().imageRect();
}
float getAudioRate() const {
return getConsoleNTSC() ? (262 * 76 * 60) / 38.0 : (312 * 76 * 50) / 38.0;
}

View File

@ -129,11 +129,18 @@ static void update_input()
break;
case Controller::Type::Lightgun:
EVENT(Event::MouseAxisXValue, input_state_cb(pad, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X));
EVENT(Event::MouseAxisYValue, input_state_cb(pad, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y));
{
// scale from -0x8000..0x7fff to image rect
const Common::Rect& rect = stella.getImageRect();
const Int32 x = (input_state_cb(pad, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X) + 0x8000) * rect.w() / 0xffff;
const Int32 y = (input_state_cb(pad, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y) + 0x8000) * rect.h() / 0xffff;
EVENT(Event::MouseAxisXValue, x);
EVENT(Event::MouseAxisYValue, y);
EVENT(Event::MouseButtonLeftValue, input_state_cb(pad, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER));
EVENT(Event::MouseButtonRightValue, input_state_cb(pad, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER));
break;
}
default:
break;