Skip to content

Commit

Permalink
Input and misc tweaks/fixes
Browse files Browse the repository at this point in the history
* Imagine: Use the mold linker on Linux builds
* EmuFramework: Add support for keys with toggle behavior
* EmuFramework: Add generic turbo and toggle options to ButtonElementConfigView
* EmuFramework: Color toggle virtual buttons green and turbo+toggle ones yellow
* EmuFramework: Draw all virtual control bounding boxes and then buttons for less render state changes
* EmuFramework: Fix fast/slow mode virtual control color issue from last update
* EmuFramework: Store the set of disabled keys in VController to update button states when added/changed
* EmuFramework: Fix missing deadzone in d-pad bounding image when first initialized
* Update files to new logger API
  • Loading branch information
Robert Broglia committed Aug 14, 2023
1 parent bc90499 commit 3dbac69
Show file tree
Hide file tree
Showing 20 changed files with 379 additions and 203 deletions.
1 change: 1 addition & 0 deletions EmuFramework/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ InputDeviceData.cc \
KeyConfig.cc \
OutputTimingManager.cc \
pathUtils.cc \
ToggleInput.cc \
TurboInput.cc \
VideoImageEffect.cc \
VideoImageOverlay.cc \
Expand Down
1 change: 0 additions & 1 deletion EmuFramework/include/emuframework/EmuApp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ public:
bool handleKeyInput(KeyInfo, const Input::Event &srcEvent);
bool handleAppActionKeyInput(InputAction, const Input::Event &srcEvent);
void handleSystemKeyInput(KeyInfo, Input::Action, uint32_t metaState = 0);
void handleSystemKeyInput(InputAction);
void runTurboInputEvents();
void resetInput();
void setRunSpeed(double speed);
Expand Down
2 changes: 2 additions & 0 deletions EmuFramework/include/emuframework/EmuInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <emuframework/config.hh>
#include <emuframework/VController.hh>
#include <emuframework/TurboInput.hh>
#include <emuframework/ToggleInput.hh>
#include <emuframework/inputDefs.hh>
#include <imagine/input/Input.hh>
#include <string>
Expand Down Expand Up @@ -145,6 +146,7 @@ public:
std::vector<std::unique_ptr<KeyConfig>> customKeyConfigs;
std::vector<std::unique_ptr<InputDeviceSavedConfig>> savedInputDevs;
TurboInput turboActions;
ToggleInput toggleInput;
DelegateFunc<void ()> onUpdateDevices;
bool turboModifierActive{};

Expand Down
1 change: 1 addition & 0 deletions EmuFramework/include/emuframework/EmuSystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct InputAction
uint32_t metaState{};

constexpr bool isPushed() const { return state == Input::Action::PUSHED; }
constexpr operator KeyInfo() const { return {code, flags}; }
};

enum class InputComponent : uint8_t
Expand Down
34 changes: 34 additions & 0 deletions EmuFramework/include/emuframework/ToggleInput.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

/* This file is part of EmuFramework.
Imagine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Imagine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with EmuFramework. If not, see <http://www.gnu.org/licenses/> */

#include <emuframework/inputDefs.hh>
#include <imagine/util/container/ArrayList.hh>

namespace EmuEx
{

class EmuApp;

struct ToggleInput
{
StaticArrayList<KeyInfo, 5> keys;

constexpr ToggleInput() = default;
void updateEvent(EmuApp &, KeyInfo, Input::Action);
};

}
2 changes: 1 addition & 1 deletion EmuFramework/include/emuframework/TurboInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EmuApp;

struct TurboInput
{
IG::StaticArrayList<KeyInfo, 5> keys;
StaticArrayList<KeyInfo, 5> keys;
int clock{};

constexpr TurboInput() = default;
Expand Down
42 changes: 35 additions & 7 deletions EmuFramework/include/emuframework/VController.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public:
config{.keys{keys[0], keys[1], keys[2], keys[3]}} {}
constexpr VControllerDPad(const Config &config): config{config} {}
void setImage(Gfx::TextureSpan);
void draw(Gfx::RendererCommands &__restrict__) const;
void drawButtons(Gfx::RendererCommands &__restrict__) const;
void drawBounds(Gfx::RendererCommands &__restrict__) const;
void setShowBounds(Gfx::Renderer &r, bool on);
bool showBounds() const { return config.visualizeBounds; }
std::array<KeyInfo, 2> getInput(WPt c) const;
Expand Down Expand Up @@ -191,6 +192,12 @@ public:
bool overlaps(WPt windowPos) const { return enabled && realBounds().overlaps(windowPos); }
void setAlpha(float alpha);

void updateColor(Gfx::Color c, float alpha)
{
color = c;
setAlpha(alpha);
}

protected:
Gfx::LitSprite spr;
WRect bounds_{};
Expand Down Expand Up @@ -244,7 +251,8 @@ public:
WRect realBounds() const { return bounds() + paddingRect(); }
int rows() const;
std::array<KeyInfo, 2> findButtonIndices(WPt windowPos) const;
void draw(Gfx::RendererCommands &__restrict__) const;
void drawButtons(Gfx::RendererCommands &__restrict__) const;
void drawBounds(Gfx::RendererCommands &__restrict__) const;
std::string name(const EmuApp &) const;
void updateMeasurements(const Window &win);
void transposeKeysForPlayer(const EmuApp &, int player);
Expand Down Expand Up @@ -273,8 +281,6 @@ protected:
int spacingPixels{};
int16_t btnStagger{};
int16_t btnRowShift{};

void drawButtons(Gfx::RendererCommands &__restrict__) const;
public:
LayoutConfig layout{};
};
Expand Down Expand Up @@ -305,7 +311,7 @@ public:
auto bounds() const { return bounds_; }
WRect realBounds() const { return bounds(); }
int rows() const;
void draw(Gfx::RendererCommands &__restrict__) const;
void drawButtons(Gfx::RendererCommands &__restrict__) const;
std::string name(const EmuApp &) const;
void setAlpha(float alpha) { for(auto &b : buttons) { b.setAlpha(alpha); } }

Expand Down Expand Up @@ -362,11 +368,30 @@ public:
return state == VControllerState::SHOWN || (showHidden && state != VControllerState::OFF);
}

void draw(Gfx::RendererCommands &__restrict__ cmds, bool showHidden) const
void drawButtons(Gfx::RendererCommands &__restrict__ cmds, bool showHidden) const
{
if(!shouldDraw(state, showHidden))
return;
visit([&](auto &e){ e.draw(cmds); }, *this);
visit([&](auto &e){ e.drawButtons(cmds); }, *this);
}

void drawBounds(Gfx::RendererCommands &__restrict__ cmds, bool showHidden) const
{
if(!shouldDraw(state, showHidden))
return;
visit([&](auto &e)
{
if constexpr(requires {e.drawBounds(cmds);})
{
e.drawBounds(cmds);
}
}, *this);
}

void draw(Gfx::RendererCommands &__restrict__ cmds, bool showHidden) const
{
drawBounds(cmds, showHidden);
drawButtons(cmds, showHidden);
}

void place(WRect viewBounds, WRect windowBounds, int layoutIdx)
Expand Down Expand Up @@ -495,7 +520,9 @@ public:
int yMMSizeToPixel(const Window &win, float mm) const;
void setInputPlayer(int8_t player);
auto inputPlayer() const { return inputPlayer_; }
bool keyIsEnabled(KeyInfo) const;
void setDisabledInputKeys(std::span<const KeyCode> keys);
void updateEnabledButtons(VControllerButtonGroup &) const;
void updateKeyboardMapping();
void updateTextures();
void resetInput();
Expand Down Expand Up @@ -569,6 +596,7 @@ private:
VControllerKeyboard kb{};
std::vector<VControllerElement> gpElements{};
std::vector<VControllerElement> uiElements{};
std::span<const KeyCode> disabledKeys{};
float alphaF{};
Input::DragTracker<std::array<KeyInfo, 2>> dragTracker{};
int16_t defaultButtonSize{};
Expand Down
3 changes: 2 additions & 1 deletion EmuFramework/include/emuframework/inputDefs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ struct KeyFlags
uint8_t
appCode:1{},
turbo:1{},
unused:2{},
toggle:1{},
unused:1{},
deviceId:4{};

constexpr bool operator==(const KeyFlags &) const = default;
Expand Down
Loading

0 comments on commit 3dbac69

Please sign in to comment.