23static constexpr int POS_MIN = 55;
24static constexpr int POS_MAX = 325;
25static constexpr int POS_CENTER = 236;
26static constexpr int SCALE = 2;
33 ArkanoidState(EmuTime::param time_,
int delta_,
bool press_,
bool release_)
35 , delta(delta_), press(press_), release(release_) {}
36 [[nodiscard]]
int getDelta()
const {
return delta; }
37 [[nodiscard]]
bool getPress()
const {
return press; }
38 [[nodiscard]]
bool getRelease()
const {
return release; }
40 template<
typename Archive>
void serialize(Archive& ar,
unsigned )
42 ar.template serializeBase<StateChange>(*
this);
43 ar.serialize(
"delta", delta,
55 : eventDistributor(eventDistributor_)
56 , stateChangeDistributor(stateChangeDistributor_)
64 ArkanoidPad::unplugHelper(EmuTime::dummy());
70std::string_view ArkanoidPad::getName()
const
75std::string_view ArkanoidPad::getDescription()
const
77 return "Arkanoid pad";
80void ArkanoidPad::plugHelper(Connector& , EmuTime::param )
86void ArkanoidPad::unplugHelper(EmuTime::param )
93uint8_t ArkanoidPad::read(EmuTime::param )
95 return buttonStatus | ((shiftReg & 0x100) >> 8);
98void ArkanoidPad::write(uint8_t value, EmuTime::param )
100 uint8_t diff = lastValue ^ value;
103 if (diff & value & 0x4) {
107 if (diff & value & 0x1) {
109 shiftReg = (shiftReg << 1) | (shiftReg & 1);
114void ArkanoidPad::signalMSXEvent(
const Event& event,
115 EmuTime::param time)
noexcept
118 [&](
const MouseMotionEvent&
e) {
119 int newPos = std::min(POS_MAX,
121 dialPos +
e.getX() / SCALE));
122 int delta = newPos - dialPos;
124 stateChangeDistributor.distributeNew<ArkanoidState>(
125 time, delta,
false,
false);
128 [&](
const MouseButtonDownEvent& ) {
130 if (buttonStatus & 2) {
131 stateChangeDistributor.distributeNew<ArkanoidState>(
132 time, 0,
true,
false);
135 [&](
const MouseButtonUpEvent& ) {
137 if (!(buttonStatus & 2)) {
138 stateChangeDistributor.distributeNew<ArkanoidState>(
139 time, 0,
false,
true);
142 [](
const EventBase&) { }
147void ArkanoidPad::signalStateChange(
const StateChange& event)
149 const auto* as =
dynamic_cast<const ArkanoidState*
>(&event);
152 dialPos += as->getDelta();
153 if (as->getPress()) buttonStatus &= ~2;
154 if (as->getRelease()) buttonStatus |= 2;
157void ArkanoidPad::stopReplay(EmuTime::param time)
noexcept
160 int delta = POS_CENTER - dialPos;
161 bool release = (buttonStatus & 2) == 0;
162 if ((delta != 0) || release) {
163 stateChangeDistributor.distributeNew<ArkanoidState>(
164 time, delta,
false, release);
173template<
typename Archive>
176 ar.serialize(
"shiftreg", shiftReg,
177 "lastValue", lastValue);
178 if (ar.versionAtLeast(version, 2)) {
179 ar.serialize(
"dialpos", dialPos,
180 "buttonStatus", buttonStatus);
182 if constexpr (Archive::IS_LOADER) {
void serialize(Archive &ar, unsigned version)
ArkanoidPad(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor)
ArkanoidState(EmuTime::param time_, int delta_, bool press_, bool release_)
void serialize(Archive &ar, unsigned)
void registerEventListener(MSXEventListener &listener)
Registers a given object to receive certain events.
void unregisterEventListener(MSXEventListener &listener)
Unregisters a previously registered event listener.
bool isPluggedIn() const
Returns true if this pluggable is currently plugged into a connector.
Connector * getConnector() const
Get the connector this Pluggable is plugged into.
void registerListener(StateChangeListener &listener)
(Un)registers the given object to receive state change events.
void unregisterListener(StateChangeListener &listener)
Base class for all external MSX state changing events.
This file implemented 3 utility functions:
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)