Skip to content

Commit

Permalink
Misc tweaks and fixes
Browse files Browse the repository at this point in the history
* Imagine: Remember scroll and selected cell state in FSPicker when going up a directory
* Imagine: Simplify iCade input code by mapping it to the system map, also fixes related device mapping issues from a previous update
* Imagine: Fix missing graphics in TableView and ToastView when the model matrix isn't reset before drawing
* EmuFramework: Fix time format in benchmark result text
* MSX.emu: Fix missing input key strings
  • Loading branch information
Robert Broglia committed Nov 14, 2023
1 parent 4cde6b1 commit 71bcd12
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 163 deletions.
23 changes: 0 additions & 23 deletions EmuFramework/include/emuframework/keyRemappingUtils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -185,27 +185,6 @@ constexpr Input::Key genericGamepadKeycodeToICP(Input::Key k)
}
}

constexpr Input::Key genericGamepadKeycodeToICade(Input::Key k)
{
using namespace Input;
switch(k)
{
case Keycode::UP: return ICade::UP;
case Keycode::RIGHT: return ICade::RIGHT;
case Keycode::DOWN: return ICade::DOWN;
case Keycode::LEFT: return ICade::LEFT;
case Keycode::GAME_A: return ICade::A;
case Keycode::GAME_B: return ICade::B;
case Keycode::GAME_X: return ICade::X;
case Keycode::GAME_Y: return ICade::Y;
case Keycode::GAME_SELECT: return ICade::SELECT;
case Keycode::GAME_START: return ICade::START;
case Keycode::GAME_L1: return ICade::Z;
case Keycode::GAME_R1: return ICade::C;
default: return 0;
}
}

constexpr Input::Key genericGamepadKeycodeToPS3(Input::Key k)
{
using namespace Input;
Expand Down Expand Up @@ -286,7 +265,6 @@ constexpr std::span<const KeyConfigDesc> genericKeyConfigs()
static constexpr std::array wiimoteMap = concatToArrayNow<genericWiimoteAppKeyCodeMap, wiimoteBaseMap>;
static constexpr std::array wiiCCMap = transformMappedKeys(genericGamepadMap, genericGamepadKeycodeToWiiCC);
static constexpr std::array icpMap = transformMappedKeys(genericGamepadMap, genericGamepadKeycodeToICP);
static constexpr std::array iCadeMap = transformMappedKeys(genericGamepadMap, genericGamepadKeycodeToICade);
static constexpr std::array ps3Map = transformMappedKeys(genericGamepadMap, genericGamepadKeycodeToPS3);
static constexpr std::array zeemoteMap = transformMappedKeys(wiimoteBaseMap, wiimoteKeycodeToZeemote);

Expand Down Expand Up @@ -315,7 +293,6 @@ constexpr std::span<const KeyConfigDesc> genericKeyConfigs()
KeyConfigDesc{Map::ICONTROLPAD, "Default", icpMap},
KeyConfigDesc{Map::ZEEMOTE, "Default", zeemoteMap},
#endif
KeyConfigDesc{Map::ICADE, "Default", iCadeMap},
#ifdef CONFIG_BLUETOOTH_SERVER
KeyConfigDesc{Map::PS3PAD, "Default", ps3Map},
#endif
Expand Down
5 changes: 3 additions & 2 deletions EmuFramework/src/EmuApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,9 @@ void EmuApp::runBenchmarkOneShot(EmuVideo &emuVideo)
auto time = system().benchmark(emuVideo);
autosaveManager_.resetSlot(noAutosaveName);
closeSystem();
log.info("done in:{}", duration_cast<FloatSeconds>(time));
postMessage(2, 0, std::format("{:.2f} fps", 180. / time.count()));
auto timeSecs = duration_cast<FloatSeconds>(time);
log.info("done in:{}", timeSecs);
postMessage(2, 0, std::format("{:.2f} fps", 180. / timeSecs.count()));
}

void EmuApp::showEmulation()
Expand Down
13 changes: 1 addition & 12 deletions EmuFramework/src/InputDeviceConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,9 @@ void InputDeviceConfig::deleteConf(InputManager &mgr)
savedConf = nullptr;
}

bool InputDeviceConfig::setICadeMode(InputManager &mgr, bool on)
void InputDeviceConfig::setICadeMode(bool on)
{
// delete device's config since its properties will change with iCade mode switch
deleteConf(mgr);
dev->setICadeMode(on);
buildKeyMap(mgr);
save(mgr);
if(!savedConf)
{
log.error("can't save iCade mode");
return 0;
}
savedConf->iCadeMode = on;
return 1;
}

bool InputDeviceConfig::iCadeMode()
Expand Down
2 changes: 1 addition & 1 deletion EmuFramework/src/InputDeviceConfig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public:
player_{int8_t(dev.enumId() < EmuSystem::maxPlayers ? dev.enumId() : 0)} {}

void deleteConf(InputManager &);
bool setICadeMode(InputManager &, bool on);
void setICadeMode(bool on);
bool iCadeMode();
bool joystickAxesAsDpad(Input::AxisSetId);
void setJoystickAxesAsDpad(Input::AxisSetId, bool on);
Expand Down
7 changes: 3 additions & 4 deletions EmuFramework/src/gui/InputManagerView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ InputManagerView::InputManagerView(ViewAttachParams attach,
auto ctx = appContext();
for(auto &e : ctx.inputDevices())
{
if(e->map() == Input::Map::SYSTEM || e->map() == Input::Map::ICADE)
if(e->map() == Input::Map::SYSTEM)
devices++;
}
app().postMessage(2, false, std::format("{} OS devices present", devices));
Expand Down Expand Up @@ -738,8 +738,7 @@ void InputManagerDeviceView::loadItems()
item.emplace_back(&renameProfile);
item.emplace_back(&deleteProfile);
auto &dev = devConf.device();
if(hasICadeInput &&
((dev.map() == Input::Map::SYSTEM && dev.hasKeyboard()) || dev.map() == Input::Map::ICADE))
if(hasICadeInput && (dev.map() == Input::Map::SYSTEM && dev.hasKeyboard()))
{
item.emplace_back(&iCadeMode);
}
Expand Down Expand Up @@ -772,7 +771,7 @@ void InputManagerDeviceView::onShow()

void InputManagerDeviceView::confirmICadeMode()
{
devConf.setICadeMode(inputManager, iCadeMode.flipBoolValue(*this));
devConf.setICadeMode(iCadeMode.flipBoolValue(*this));
onShow();
app().defaultVController().setPhysicalControlsPresent(appContext().keyInputIsPresent());
}
Expand Down
13 changes: 13 additions & 0 deletions MSX.emu/src/main/input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ std::string_view MsxApp::systemKeyCodeToString(KeyCode c)
case EC_JOY1_LEFT: return "Left";
case EC_JOY1_BUTTON1: return "Button 1";
case EC_JOY1_BUTTON2: return "Button 2";
case EC_COLECO1_0: return "Coleco 0";
case EC_COLECO1_1: return "Coleco 1";
case EC_COLECO1_2: return "Coleco 2";
case EC_COLECO1_3: return "Coleco 3";
case EC_COLECO1_4: return "Coleco 4";
case EC_COLECO1_5: return "Coleco 5";
case EC_COLECO1_6: return "Coleco 6";
case EC_COLECO1_7: return "Coleco 7";
case EC_COLECO1_8: return "Coleco 8";
case EC_COLECO1_9: return "Coleco 9";
case EC_COLECO1_STAR: return "Coleco *";
case EC_COLECO1_HASH: return "Coleco #";
case EC_TOGGLE_KB: return "Toggle Keyboard";
case EC_F1: return "F1";
case EC_F2: return "F2";
Expand Down Expand Up @@ -304,6 +316,7 @@ std::string_view MsxApp::systemKeyCodeToString(KeyCode c)
case EC_NUMPER: return "Num Period";
case EC_NUMCOM: return "Num Comma";
case EC_NUMADD: return "Num Add";
case EC_PRINT: return "Print";
default: return "";
}
}
Expand Down
14 changes: 7 additions & 7 deletions imagine/include/imagine/gui/FSPicker.hh
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ protected:

FilterFunc filter{};
ViewStack controller;
OnChangePathDelegate onChangePath_{};
OnSelectPathDelegate onSelectPath_{};
std::vector<FileEntry> dir{};
FS::RootedPath root{};
Gfx::Text msgText{};
OnChangePathDelegate onChangePath_;
OnSelectPathDelegate onSelectPath_;
std::vector<FileEntry> dir;
std::vector<TableUIState> fileUIStates;
FS::RootedPath root;
Gfx::Text msgText;
CustomEvent dirListEvent{"FSPicker::dirListEvent", {}};
TableUIState newFileUIState{};
Mode mode_{};
bool showHiddenFiles_{};
bool highlightFirstDirEntry{};
WorkThread dirListThread{};
int8_t depthCount{};

void changeDirByInput(CStringView path, FS::RootPathInfo, const Input::Event &,
DepthMode depthMode = DepthMode::increment);
Expand Down
4 changes: 2 additions & 2 deletions imagine/include/imagine/gui/ScrollView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public:
bool isDoingScrollGesture() const;
bool isOverScrolled() const;
int overScroll() const;
void setScrollOffset(int);
int scrollOffset() const { return offset; }

protected:
using VelocityTrackerType = Input::VelocityTracker<float, 1>;
Expand All @@ -64,8 +66,6 @@ protected:
void setContentSize(WSize size);
void drawScrollContent(Gfx::RendererCommands &cmds);
bool scrollInputEvent(const Input::MotionEvent &);
void setScrollOffset(int o);
int scrollOffset() const;
void stopScrollAnimation();
};

Expand Down
3 changes: 3 additions & 0 deletions imagine/include/imagine/gui/TableView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public:
size_t cells() const;
WSize cellSize() const;
void highlightCell(int idx);
int highlightedCell() const { return selected; }
[[nodiscard]] TableUIState saveUIState() const;
void restoreUIState(TableUIState);
void setAlign(_2DOrigin align);
std::u16string_view name() const override;
void resetName(UTF16Convertible auto &&name) { nameStr = IG_forward(name); }
Expand Down
11 changes: 11 additions & 0 deletions imagine/include/imagine/gui/viewDefs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ constexpr bool needsBackControlIsMutable = !Config::envIsIOS;
constexpr auto imageSamplerConfig = Gfx::SamplerConfigs::nearestMipClamp;

}

namespace IG
{

struct TableUIState
{
int highlightedCell{-1};
int scrollOffset{};
};

}
8 changes: 7 additions & 1 deletion imagine/include/imagine/input/Device.hh
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ public:
void setEnumId(uint8_t id) { enumId_ = id; }
std::string_view name() const { return name_; }
Map map() const;
DeviceTypeFlags typeFlags() const { return iCadeMode() ? DeviceTypeFlags{.gamepad = true} : typeFlags_; }
DeviceTypeFlags typeFlags() const
{
auto flags = typeFlags_;
if(iCadeMode())
flags.gamepad = true;
return flags;
}
Subtype subtype() const { return subtype_; }
void setSubtype(Subtype s) { subtype_ = s; }
bool operator==(Device const&) const = default;
Expand Down
23 changes: 0 additions & 23 deletions imagine/include/imagine/input/bluetoothInputDefs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,4 @@ static constexpr uint8_t MAX_BLUETOOTH_DEVS_PER_TYPE = 5;
static const uint32_t COUNT = 9;
}

namespace ICade
{
// Due to lack of naming standard and for clarity,
// face buttons are labeled like a SEGA Saturn controller
// with E1 and E2 as SELECT and START respectively

static const uint32_t UP = Keycode::UP,
RIGHT = Keycode::RIGHT,
DOWN = Keycode::DOWN,
LEFT = Keycode::LEFT,
X = Keycode::GAME_X,
A = Keycode::GAME_A,
Y = Keycode::GAME_Y,
B = Keycode::GAME_B,
Z = Keycode::GAME_Z,
C = Keycode::GAME_C,
SELECT = Keycode::GAME_SELECT,
START = Keycode::GAME_START
;

static const uint32_t COUNT = Keycode::COUNT;
}

}
1 change: 0 additions & 1 deletion imagine/include/imagine/input/inputDefs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ enum class Map : uint8_t

ICONTROLPAD = 20,
ZEEMOTE = 21,
ICADE = 22,
PS3PAD = 23,

APPLE_GAME_CONTROLLER = 31
Expand Down

0 comments on commit 71bcd12

Please sign in to comment.