Skip to content

Commit

Permalink
Misc updates and clean up
Browse files Browse the repository at this point in the history
* Convert various bit flag integers into struct types
* Imagine: Allow moving types in overloaded(...) visit utility function
* Imagine: Add modulo operators to Point2D
* Imagine: Add not and xor operators to BitSetClass
* Imagine: Rename Input.hh to Event.hh
* EmuFramework: Add option to set pixel snapping and add dedicated exit button in PlaceVControlsView
* EmuFramework: Split InputDeviceConfig and InputDeviceData into separate files
  • Loading branch information
Robert Broglia committed Sep 4, 2023
1 parent 44e5610 commit 256d5ec
Show file tree
Hide file tree
Showing 94 changed files with 673 additions and 625 deletions.
2 changes: 1 addition & 1 deletion EmuFramework/include/emuframework/EmuApp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <emuframework/AutosaveManager.hh>
#include <emuframework/OutputTimingManager.hh>
#include <emuframework/RecentContent.hh>
#include <imagine/input/Input.hh>
#include <imagine/input/inputDefs.hh>
#include <imagine/input/android/MogaManager.hh>
#include <imagine/gui/ViewManager.hh>
#include <imagine/gui/TextEntry.hh>
Expand Down
16 changes: 14 additions & 2 deletions EmuFramework/include/emuframework/EmuInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <emuframework/TurboInput.hh>
#include <emuframework/ToggleInput.hh>
#include <emuframework/inputDefs.hh>
#include <imagine/input/Input.hh>
#include <imagine/input/inputDefs.hh>
#include <string>
#include <string_view>
#include <memory>
Expand Down Expand Up @@ -117,6 +117,18 @@ private:
Input::DeviceSubtype devSubtype{};
};

struct AxisAsDpadFlags
{
uint8_t
stick1:1{},
unused1:1{},
stick2:1{},
unused2:3{},
hat:1{};

constexpr bool operator==(AxisAsDpadFlags const&) const = default;
};

struct InputDeviceSavedConfig
{
static constexpr uint8_t ENUM_ID_MASK = 0x1F;
Expand All @@ -127,7 +139,7 @@ struct InputDeviceSavedConfig
uint8_t enumId{};
int8_t player{};
bool enabled = true;
uint8_t joystickAxisAsDpadBits{};
AxisAsDpadFlags joystickAxisAsDpadFlags;
IG_UseMemberIf(hasICadeInput, bool, iCadeMode){};
IG_UseMemberIf(Config::envIsAndroid, bool, handleUnboundEvents){};

Expand Down
2 changes: 1 addition & 1 deletion EmuFramework/include/emuframework/InputManagerView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private:
TextHeadingMenuItem options;
std::vector<TextMenuItem> inputCategory;
std::vector<MenuItem*> item;
InputDeviceConfig *devConf{};
InputDeviceConfig &devConf;

void confirmICadeMode();
void loadItems();
Expand Down
30 changes: 19 additions & 11 deletions EmuFramework/include/emuframework/VController.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <emuframework/config.hh>
#include <emuframework/EmuAppHelper.hh>
#include <emuframework/inputDefs.hh>
#include <imagine/input/Input.hh>
#include <imagine/input/inputDefs.hh>
#include <imagine/input/DragTracker.hh>
#include <imagine/gfx/GfxSprite.hh>
#include <imagine/gfx/Texture.hh>
Expand Down Expand Up @@ -505,15 +505,23 @@ enum class VControllerVisibility : uint8_t
OFF, ON, AUTO
};

struct VControllerGamepadFlags
{
uint8_t
dpad:1{},
buttons:1{};

constexpr bool operator==(VControllerGamepadFlags const&) const = default;

static constexpr VControllerGamepadFlags all() { return {.dpad = true, .buttons = true}; }
};

class VController : public EmuAppHelper<VController>
{
public:
static constexpr KeyInfo TOGGLE_KEYBOARD = KeyInfo::appKey(254);
static constexpr KeyInfo CHANGE_KEYBOARD_MODE = KeyInfo::appKey(255);
using KbMap = VControllerKeyboard::KbMap;
static constexpr uint8_t GAMEPAD_DPAD_BIT = IG::bit(0);
static constexpr uint8_t GAMEPAD_BUTTONS_BIT = IG::bit(1);
static constexpr uint8_t GAMEPAD_BITS = GAMEPAD_DPAD_BIT | GAMEPAD_BUTTONS_BIT;

VController(ApplicationContext);
int xMMSizeToPixel(const Window &win, float mm) const;
Expand Down Expand Up @@ -569,12 +577,12 @@ public:
void resetEmulatedDeviceGroups();
void resetUIPositions();
void resetUIGroups();
void setGamepadIsEnabled(bool on) { gamepadDisabledFlags = on ? 0 : GAMEPAD_BITS; }
void setGamepadDPadIsEnabled(bool on) { gamepadDisabledFlags = IG::setOrClearBits(gamepadDisabledFlags, GAMEPAD_DPAD_BIT, !on); }
void setGamepadButtonsAreEnabled(bool on) { gamepadDisabledFlags = IG::setOrClearBits(gamepadDisabledFlags, GAMEPAD_BUTTONS_BIT, !on); }
bool gamepadIsEnabled() const { return gamepadDisabledFlags != GAMEPAD_BITS; }
bool gamepadDPadIsEnabled() const { return !(gamepadDisabledFlags & GAMEPAD_DPAD_BIT); }
bool gamepadButtonsAreEnabled() const { return !(gamepadDisabledFlags & GAMEPAD_BUTTONS_BIT); }
void setGamepadIsEnabled(bool on) { gamepadDisabledFlags = on ? VControllerGamepadFlags{} : VControllerGamepadFlags::all(); }
void setGamepadDPadIsEnabled(bool on) { gamepadDisabledFlags.dpad = !on; }
void setGamepadButtonsAreEnabled(bool on) { gamepadDisabledFlags.buttons = !on; }
bool gamepadIsEnabled() const { return gamepadDPadIsEnabled() || gamepadButtonsAreEnabled(); }
bool gamepadDPadIsEnabled() const { return !gamepadDisabledFlags.dpad; }
bool gamepadButtonsAreEnabled() const { return !gamepadDisabledFlags.buttons; }
bool gamepadIsActive() const;
bool allowButtonsPastContentBounds() const { return allowButtonsPastContentBounds_; }
bool setAllowButtonsPastContentBounds(bool on) { return allowButtonsPastContentBounds_ = on; }
Expand Down Expand Up @@ -607,7 +615,7 @@ private:
int8_t inputPlayer_{};
bool physicalControlsPresent{};
bool gamepadIsVisible{gamepadControlsVisibility_ != VControllerVisibility::OFF};
uint8_t gamepadDisabledFlags{};
VControllerGamepadFlags gamepadDisabledFlags{};
bool kbMode{};
uint8_t alpha{};
IG_UseMemberIf(Config::DISPLAY_CUTOUT, bool, allowButtonsPastContentBounds_){};
Expand Down
2 changes: 1 addition & 1 deletion EmuFramework/include/emuframework/inputDefs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
You should have received a copy of the GNU General Public License
along with EmuFramework. If not, see <http://www.gnu.org/licenses/> */

#include <imagine/input/Input.hh>
#include <imagine/input/inputDefs.hh>
#include <imagine/util/container/array.hh>
#include <array>
#include <cstdint>
Expand Down
1 change: 0 additions & 1 deletion EmuFramework/src/ConfigFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <emuframework/EmuApp.hh>
#include "EmuOptions.hh"
#include "privateInput.hh"
#include "configFile.hh"
#include <imagine/base/ApplicationContext.hh>
#include <imagine/io/FileIO.hh>
Expand Down
2 changes: 1 addition & 1 deletion EmuFramework/src/EmuApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <emuframework/FilePathOptionView.hh>
#include <emuframework/AppKeyCode.hh>
#include "gui/AutosaveSlotView.hh"
#include "privateInput.hh"
#include "InputDeviceData.hh"
#include "WindowData.hh"
#include "configFile.hh"
#include "EmuOptions.hh"
Expand Down
6 changes: 3 additions & 3 deletions EmuFramework/src/EmuInput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <emuframework/EmuSystem.hh>
#include <emuframework/EmuApp.hh>
#include <emuframework/AppKeyCode.hh>
#include "privateInput.hh"
#include "InputDeviceData.hh"
#include "EmuOptions.hh"

namespace EmuEx
Expand Down Expand Up @@ -136,7 +136,7 @@ void InputManager::writeSavedInputDevices(ApplicationContext ctx, FileIO &io) co
io.put(uint8_t(enumIdWithFlags));
io.put(uint8_t(e.enabled));
io.put(uint8_t(e.player));
io.put(uint8_t(e.joystickAxisAsDpadBits));
io.put(std::bit_cast<uint8_t>(e.joystickAxisAsDpadFlags));
if(hasICadeInput)
io.put(uint8_t(e.iCadeMode));
uint8_t nameLen = e.name.size();
Expand Down Expand Up @@ -181,7 +181,7 @@ bool InputManager::readSavedInputDevices(MapIO &io)
logWarn("player %d out of range", devConf.player);
devConf.player = 0;
}
devConf.joystickAxisAsDpadBits = io.get<uint8_t>();
devConf.joystickAxisAsDpadFlags = std::bit_cast<AxisAsDpadFlags>(io.get<uint8_t>());
if(hasICadeInput)
{
devConf.iCadeMode = io.get<uint8_t>();
Expand Down
1 change: 0 additions & 1 deletion EmuFramework/src/EmuOptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <emuframework/VideoImageEffect.hh>
#include <emuframework/VideoImageOverlay.hh>
#include <emuframework/VController.hh>
#include "privateInput.hh"
#include "WindowData.hh"
#include <imagine/base/ApplicationContext.hh>
#include <imagine/gfx/Renderer.hh>
Expand Down
17 changes: 9 additions & 8 deletions EmuFramework/src/EmuVideo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
You should have received a copy of the GNU General Public License
along with EmuFramework. If not, see <http://www.gnu.org/licenses/> */

#define LOGTAG "EmuVideo"
#include <emuframework/EmuVideo.hh>
#include <emuframework/EmuApp.hh>
#include <imagine/gfx/Renderer.hh>
Expand All @@ -24,6 +23,8 @@
namespace EmuEx
{

constexpr SystemLogger log{"EmuVideo"};

void EmuVideo::resetImage(IG::PixelFormat newFmt)
{
if(!vidImg)
Expand Down Expand Up @@ -76,7 +77,7 @@ bool EmuVideo::setFormat(IG::PixmapDesc desc, EmuSystemTaskContext taskCtx)
{
vidImg.setFormat(desc, colSpace, samplerConfig());
}
logMsg("resized to:%dx%d", desc.w(), desc.h());
log.info("resized to:{}x{}", desc.w(), desc.h());
if(taskCtx)
{
taskCtx.task().sendVideoFormatChangedReply(*this);
Expand Down Expand Up @@ -148,7 +149,7 @@ void EmuVideo::startUnchangedFrame(EmuSystemTaskContext taskCtx)

void EmuVideo::dispatchFrameFinished()
{
//logDMsg("frame finished");
//log.debug("frame finished");
onFrameFinished(*this);
}

Expand Down Expand Up @@ -179,7 +180,7 @@ void EmuVideo::finishFrame(EmuSystemTaskContext taskCtx, IG::PixmapView pix)
}
app().record(FrameTimeStatEvent::aboutToSubmitFrame);
syncImageAccess();
vidImg.write(pix, vidImg.WRITE_FLAG_ASYNC);
vidImg.write(pix, {.async = true});
postFrameFinished(taskCtx);
}

Expand Down Expand Up @@ -285,7 +286,7 @@ void EmuVideo::setOnFormatChanged(FormatChangedDelegate del)
void EmuVideo::updateNeedsFence()
{
needsFence = singleBuffer && renderer().maxSwapChainImages() > 2;
logMsg("%s fence for synchronization", needsFence ? "using" : "not using");
log.info("{} fence for synchronization", needsFence ? "using" : "not using");
}

void EmuVideo::setTextureBufferMode(EmuSystem &sys, Gfx::TextureBufferMode mode)
Expand Down Expand Up @@ -313,7 +314,7 @@ void EmuVideo::setImageBuffers(int num)
bool modeChanged = singleBuffer != useSingleBuffer;
singleBuffer = useSingleBuffer;
updateNeedsFence();
//logDMsg("image buffer count:%d fences:%s", num, needsFence ? "yes" : "no");
//log.debug("image buffer count:{} fences:{}", num, needsFence ? "yes" : "no");
if(modeChanged && vidImg)
resetImage();
}
Expand All @@ -334,7 +335,7 @@ bool EmuVideo::setRenderPixelFormat(EmuSystem &sys, IG::PixelFormat fmt, Gfx::Co
if(colorSpace != colSpace)
{
colSpace = colorSpace;
logMsg("set sRGB color space:%s", colorSpace == Gfx::ColorSpace::SRGB ? "on" : "off");
log.info("set sRGB color space:{}", colorSpace == Gfx::ColorSpace::SRGB ? "on" : "off");
renderFmt = {}; // reset image
if(colorSpace == Gfx::ColorSpace::SRGB)
{
Expand All @@ -347,7 +348,7 @@ bool EmuVideo::setRenderPixelFormat(EmuSystem &sys, IG::PixelFormat fmt, Gfx::Co
fmt = IG::PIXEL_BGRA8888;
if(renderFmt == fmt)
return false;
logMsg("setting render pixel format:%s", fmt.name());
log.info("setting render pixel format:{}", fmt.name());
renderFmt = fmt;
auto oldPixDesc = deleteImage();
if(!sys.onVideoRenderFormatChange(*this, fmt) && oldPixDesc.w())
Expand Down
41 changes: 24 additions & 17 deletions EmuFramework/src/InputDeviceConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@
You should have received a copy of the GNU General Public License
along with EmuFramework. If not, see <http://www.gnu.org/licenses/> */

#define LOGTAG "InputDevConf"
#include "privateInput.hh"
#include "InputDeviceConfig.hh"
#include "InputDeviceData.hh"
#include <emuframework/EmuApp.hh>
#include <imagine/util/format.hh>
#include <imagine/logger/logger.h>

namespace EmuEx
{

constexpr SystemLogger log{"InputDevConf"};

static StaticString<16> uniqueCustomConfigName(auto &customKeyConfigs)
{
for(auto i : iotaCount(100)) // Try up to "Custom 99"
{
auto name = format<StaticString<16>>("Custom {}", i+1);
// Check if this name is free
logMsg("checking:%s", name.data());
log.info("checking:{}", name);
bool exists{};
for(auto &ePtr : customKeyConfigs)
{
logMsg("against:%s", ePtr->name.data());
log.info("against:{}", ePtr->name);
if(ePtr->name == std::string_view{name})
{
exists = true;
Expand All @@ -41,7 +43,7 @@ static StaticString<16> uniqueCustomConfigName(auto &customKeyConfigs)
}
if(!exists)
{
logMsg("unique custom key config name: %s", name.data());
log.info("unique custom key config name:{}", name);
return name;
}
}
Expand All @@ -52,7 +54,7 @@ void InputDeviceConfig::deleteConf(InputManager &mgr)
{
if(!savedConf)
return;
logMsg("removing device config for %s", savedConf->name.data());
log.info("removing device config for {}", savedConf->name);
std::erase_if(mgr.savedInputDevs, [&](auto &ptr){ return ptr.get() == savedConf; });
savedConf = nullptr;
}
Expand All @@ -66,7 +68,7 @@ bool InputDeviceConfig::setICadeMode(InputManager &mgr, bool on)
save(mgr);
if(!savedConf)
{
logErr("can't save iCade mode");
log.error("can't save iCade mode");
return 0;
}
savedConf->iCadeMode = on;
Expand All @@ -78,14 +80,14 @@ bool InputDeviceConfig::iCadeMode()
return dev->iCadeMode();
}

unsigned InputDeviceConfig::joystickAxisAsDpadBits()
bool InputDeviceConfig::joystickAxesAsDpad(Input::AxisSetId id)
{
return dev->joystickAxisAsDpadBits();
return dev->joystickAxesAsDpad(id);
}

void InputDeviceConfig::setJoystickAxisAsDpadBits(unsigned axisMask)
void InputDeviceConfig::setJoystickAxesAsDpad(Input::AxisSetId id, bool on)
{
dev->setJoystickAxisAsDpadBits(axisMask);
dev->setJoystickAxesAsDpad(id, on);
}

void InputDeviceConfig::setKeyConfName(InputManager &mgr, std::string_view name)
Expand All @@ -104,7 +106,7 @@ KeyConfigDesc InputDeviceConfig::keyConf(const InputManager &mgr) const
assert(dev);
if(savedConf && savedConf->keyConfName.size())
{
//logMsg("has saved config:%s", savedConf->keyConfName.c_str());
//log.info("has saved config:{}", savedConf->keyConfName);
auto conf = mgr.keyConfig(savedConf->keyConfName, *dev);
if(conf)
return conf;
Expand Down Expand Up @@ -132,7 +134,7 @@ KeyConfig *InputDeviceConfig::makeMutableKeyConf(EmuApp &app)
auto conf = mutableKeyConf(mgr);
if(!conf)
{
logMsg("current config not mutable, creating one");
log.info("current config not mutable, creating one");
auto name = uniqueCustomConfigName(mgr.customKeyConfigs);
conf = setKeyConfCopiedFromExisting(mgr, name);
app.postMessage(3, false, std::format("Automatically created profile: {}", conf->name));
Expand All @@ -153,12 +155,14 @@ void InputDeviceConfig::save(InputManager &mgr)
if(!savedConf)
{
savedConf = mgr.savedInputDevs.emplace_back(std::make_unique<InputDeviceSavedConfig>()).get();
logMsg("allocated new device config, %d total", (int)mgr.savedInputDevs.size());
log.info("allocated new device config, {} total", mgr.savedInputDevs.size());
}
savedConf->player = player_;
savedConf->enabled = isEnabled;
savedConf->enumId = dev->enumId();
savedConf->joystickAxisAsDpadBits = dev->joystickAxisAsDpadBits();
savedConf->joystickAxisAsDpadFlags.stick1 = dev->joystickAxesAsDpad(Input::AxisSetId::stick1);
savedConf->joystickAxisAsDpadFlags.stick2 = dev->joystickAxesAsDpad(Input::AxisSetId::stick2);
savedConf->joystickAxisAsDpadFlags.hat = dev->joystickAxesAsDpad(Input::AxisSetId::hat);
savedConf->iCadeMode = dev->iCadeMode();
savedConf->handleUnboundEvents = shouldHandleUnboundKeys;
savedConf->name = dev->name();
Expand All @@ -171,15 +175,18 @@ void InputDeviceConfig::setSavedConf(const InputManager &mgr, InputDeviceSavedCo
{
player_ = savedConf->player;
isEnabled = savedConf->enabled;
dev->setJoystickAxisAsDpadBits(savedConf->joystickAxisAsDpadBits);
dev->setJoystickAxesAsDpad(Input::AxisSetId::stick1, savedConf->joystickAxisAsDpadFlags.stick1);
dev->setJoystickAxesAsDpad(Input::AxisSetId::stick2, savedConf->joystickAxisAsDpadFlags.stick2);
dev->setJoystickAxesAsDpad(Input::AxisSetId::hat, savedConf->joystickAxisAsDpadFlags.hat);
dev->setICadeMode(savedConf->iCadeMode);
shouldHandleUnboundKeys = savedConf->handleUnboundEvents;
}
else
{
player_ = dev->enumId() < EmuSystem::maxPlayers ? dev->enumId() : 0;
isEnabled = true;
dev->setJoystickAxisAsDpadBits(Input::Device::AXIS_BITS_STICK_1 | Input::Device::AXIS_BITS_HAT);
dev->setJoystickAxesAsDpad(Input::AxisSetId::stick1, true);
dev->setJoystickAxesAsDpad(Input::AxisSetId::hat, true);
dev->setICadeMode(false);
shouldHandleUnboundKeys = false;
}
Expand Down

0 comments on commit 256d5ec

Please sign in to comment.