Skip to content

Commit

Permalink
Add support for overriding key input profiles per content and misc tw…
Browse files Browse the repository at this point in the history
…eaks

* Imagine: Improve find/find_if utility functions in algorithm.h
* Imagine: Clean up old/unused iOS code and add various wrapper functions for newer SDK headers
* EmuFramework: Add Input Overrides menu to SystemActionsView
* EmuFramework: Add EmuSystem::canRenderRGB565 boolean for systems that only render to RGBA8888 like Saturn.emu
* EmuFramework: Add utility functions for reading/writing resizable containers
* EmuFramework: Remove legacy code for reading recent content entries used in older app versions
* EmuFramework: Various code clean up
  • Loading branch information
Robert Broglia committed Jul 4, 2024
1 parent 9c09335 commit 5060e6d
Show file tree
Hide file tree
Showing 53 changed files with 1,011 additions and 579 deletions.
4 changes: 2 additions & 2 deletions C64.emu/src/main/EmuMenuViews.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class CustomVideoOptionView : public VideoOptionView, public MainAppHelper
MultiChoiceMenuItem defaultPalette
{
"Default Palette", attachParams(),
[this]()
[this]() -> int
{
if(system().defaultPaletteName.empty())
return 0;
Expand Down Expand Up @@ -1004,7 +1004,7 @@ class MachineOptionView : public TableView, public MainAppHelper
MultiChoiceMenuItem palette
{
"Palette", attachParams(),
[this]()
[this]() -> int
{
if(!system().usingExternalPalette())
return 0;
Expand Down
1 change: 1 addition & 0 deletions EmuFramework/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ gui/FilePicker.cc \
gui/FrameTimingView.cc \
gui/GUIOptionView.cc \
gui/InputManagerView.cc \
gui/InputOverridesView.cc \
gui/LoadProgressView.cc \
gui/MainMenuView.cc \
gui/PlaceVControlsView.cc \
Expand Down
44 changes: 36 additions & 8 deletions EmuFramework/include/emuframework/EmuApp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include <imagine/util/used.hh>
#include <imagine/util/enum.hh>
#include <cstring>
#include <optional>
#include <span>
#include <string>

Expand Down Expand Up @@ -118,6 +117,20 @@ WISE_ENUM_CLASS((CPUAffinityMode, uint8_t),
Auto, Any, Manual
);

struct DrawableConfig
{
Property<PixelFormat, CFGKEY_WINDOW_PIXEL_FORMAT> pixelFormat;
Property<Gfx::ColorSpace, CFGKEY_VIDEO_COLOR_SPACE> colorSpace;

constexpr DrawableConfig() = default;
constexpr DrawableConfig(Gfx::DrawableConfig c)
{
pixelFormat.setUnchecked(c.pixelFormat);
colorSpace.setUnchecked(c.colorSpace);
}
constexpr operator Gfx::DrawableConfig() const { return {.pixelFormat = pixelFormat, .colorSpace = colorSpace}; }
};

constexpr float menuVideoBrightnessScale = .25f;

class EmuApp : public IG::Application
Expand Down Expand Up @@ -203,6 +216,7 @@ public:
void saveSessionOptions();
void loadSessionOptions();
bool hasSavedSessionOptions();
void resetSessionOptions();
void deleteSessionOptions();
void syncEmulationThread();
void startAudio();
Expand Down Expand Up @@ -236,8 +250,6 @@ public:
void setMogaManagerActive(bool on, bool notify);
void closeBluetoothConnections();
ViewAttachParams attachParams();
auto &customKeyConfigList() { return inputManager.customKeyConfigs; };
auto &savedInputDeviceList() { return inputManager.savedInputDevs; };
IG::Viewport makeViewport(const Window &win) const;
void setEmuViewOnExtraWindow(bool on, IG::Screen &);
void record(FrameTimeStatEvent, SteadyClockTimePoint t = {});
Expand All @@ -256,7 +268,6 @@ public:

// Video Options
bool setWindowDrawableConfig(Gfx::DrawableConfig);
Gfx::DrawableConfig windowDrawableConfig() const { return windowDrawableConf; }
IG::PixelFormat windowPixelFormat() const;
void setRenderPixelFormat(IG::PixelFormat);
bool setVideoAspectRatio(float val);
Expand Down Expand Up @@ -330,6 +341,25 @@ public:
postMessage(secs, true, IG_forward(msg));
}

void forEachKeyConfig(Input::Map map, auto&& func) const
{
for(auto& confPtr : inputManager.customKeyConfigs)
{
auto& conf = *confPtr;
if(conf.desc().map == map)
{
func(conf);
}
}
for(const auto& conf : defaultKeyConfigs())
{
if(conf.map == map)
{
func(conf);
}
}
}

public:
IG::FontManager fontManager;
mutable Gfx::Renderer renderer;
Expand All @@ -352,10 +382,10 @@ protected:
[[no_unique_address]] PerformanceHintManager perfHintManager;
[[no_unique_address]] PerformanceHintSession perfHintSession;
ConditionalMember<MOGA_INPUT, std::unique_ptr<Input::MogaManager>> mogaManagerPtr;
Gfx::DrawableConfig windowDrawableConf;
ConditionalMember<Config::TRANSLUCENT_SYSTEM_UI, bool> layoutBehindSystemUI{};
bool enableBlankFrameInsertion{};
public:
DrawableConfig windowDrawableConfig;
BluetoothAdapter bluetoothAdapter;
RecentContent recentContent;
FS::PathString contentSearchPath;
Expand Down Expand Up @@ -419,7 +449,7 @@ public:
protected:
struct ConfigParams
{
Gfx::DrawableConfig windowDrawableConf{};
Gfx::DrawableConfig windowDrawableConf;
};

void onMainWindowCreated(ViewAttachParams, const Input::Event &);
Expand All @@ -428,8 +458,6 @@ protected:
void saveConfigFile(FileIO &);
void initOptions(IG::ApplicationContext);
void applyRenderPixelFormat();
std::optional<IG::PixelFormat> windowDrawablePixelFormatOption() const;
std::optional<Gfx::ColorSpace> windowDrawableColorSpaceOption() const;
FS::PathString sessionConfigPath();
void loadSystemOptions();
void saveSystemOptions();
Expand Down
32 changes: 29 additions & 3 deletions EmuFramework/include/emuframework/EmuInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ using namespace IG;
class InputDeviceConfig;
struct InputAction;

constexpr int8_t playerIndexMulti = -1;
constexpr int8_t playerIndexUnset = -2;

struct KeyCategory
{
std::string_view name;
Expand Down Expand Up @@ -146,12 +149,27 @@ struct InputDeviceSavedConfig
ConditionalMember<hasICadeInput, bool> iCadeMode{};
ConditionalMember<Config::envIsAndroid, bool> handleUnboundEvents{};

bool operator ==(InputDeviceSavedConfig const& rhs) const
constexpr bool operator ==(InputDeviceSavedConfig const& rhs) const
{
return enumId == rhs.enumId && name == rhs.name;
}

bool matchesDevice(const Input::Device& dev) const;
};

struct InputDeviceSavedSessionConfig
{
std::string keyConfName;
std::string name;
uint8_t enumId{};
int8_t player{};

constexpr bool operator ==(InputDeviceSavedSessionConfig const& rhs) const
{
return enumId == rhs.enumId && name == rhs.name;
}

bool matchesDevice(const Input::Device &dev) const;
bool matchesDevice(const Input::Device& dev) const;
};

struct SystemKeyInputFlags
Expand All @@ -164,7 +182,8 @@ class InputManager
public:
VController vController;
std::vector<std::unique_ptr<KeyConfig>> customKeyConfigs;
std::vector<std::unique_ptr<InputDeviceSavedConfig>> savedInputDevs;
std::vector<std::unique_ptr<InputDeviceSavedConfig>> savedDevConfigs;
std::vector<std::unique_ptr<InputDeviceSavedSessionConfig>> savedSessionDevConfigs;
TurboInput turboActions;
ToggleInput toggleInput;
DelegateFunc<void ()> onUpdateDevices;
Expand All @@ -179,6 +198,13 @@ public:
KeyConfig *customKeyConfig(std::string_view name, const Input::Device &) const;
KeyConfigDesc keyConfig(std::string_view name, const Input::Device &) const;
void deleteKeyProfile(ApplicationContext, KeyConfig *);
void deleteDeviceSavedConfig(ApplicationContext, const InputDeviceSavedConfig&);
void deleteDeviceSavedConfig(ApplicationContext, const InputDeviceSavedSessionConfig&);
void resetSessionOptions(ApplicationContext);
bool readSessionConfig(ApplicationContext, MapIO&, uint16_t);
void writeSessionConfig(FileIO &io) const;
bool readInputDeviceSessionConfigs(ApplicationContext, MapIO&);
void writeInputDeviceSessionConfigs(FileIO&) const;
void writeCustomKeyConfigs(FileIO &) const;
void writeSavedInputDevices(ApplicationContext, FileIO &) const;
bool readCustomKeyConfig(MapIO &);
Expand Down
2 changes: 1 addition & 1 deletion EmuFramework/include/emuframework/EmuOptions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ enum { CFGKEY_SOUND = 0, CFGKEY_TOUCH_CONTROL_DISPLAY = 1,
CFGKEY_INPUT_KEY_CONFIGS_V2 = 114, CFGKEY_VCONTROLLER_HIGHLIGHT_PUSHED_BUTTONS = 115,
CFGKEY_RECENT_CONTENT_V2 = 116, CFGKEY_MAX_RECENT_CONTENT = 117,
CFGKEY_REWIND_STATES = 118, CFGKEY_REWIND_TIMER_SECS = 119,
CFGKEY_FRAME_CLOCK = 120,
CFGKEY_FRAME_CLOCK = 120, CFGKEY_INPUT_DEVICE_CONTENT_CONFIGS = 121,
// 256+ is reserved
};

Expand Down
2 changes: 2 additions & 0 deletions EmuFramework/include/emuframework/EmuSystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public:
static bool inputHasKeyboard;
static bool hasBundledGames;
static bool hasPALVideoSystem;
static bool canRenderRGB565;
static bool canRenderRGBA8888;
static bool hasResetModes;
static bool handlesArchiveFiles;
Expand Down Expand Up @@ -233,6 +234,7 @@ public:
WSize multiresVideoBaseSize() const;
double videoAspectRatioScale() const;
bool onVideoRenderFormatChange(EmuVideo &, PixelFormat);
static bool canRenderMultipleFormats() {return canRenderRGBA8888 && canRenderRGB565;}
void loadBackupMemory(EmuApp &);
void onFlushBackupMemory(EmuApp &, BackupMemoryDirtyFlags);
WallClockTimePoint backupMemoryLastWriteTime(const EmuApp &) const;
Expand Down
26 changes: 26 additions & 0 deletions EmuFramework/include/emuframework/Option.hh
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,30 @@ inline void writeStringOptionValueIfNotDefault(Writable auto &io, uint16_t key,
writeStringOptionValueAllowEmpty(io, key, s);
}

template<class Size>
inline size_t sizedDataBytes(const ResizableContainer auto& c)
{
size_t bytes = sizeof(Size); // store array length
Size size = std::min(c.size(), size_t(std::numeric_limits<Size>::max()));
bytes += size * sizeof(c[0]);
return bytes;
}

template<class Size>
inline void writeSizedData(Writable auto& io, const ResizableContainer auto& c)
{
Size size = std::min(c.size(), size_t(std::numeric_limits<Size>::max()));
io.put(size);
if(size)
io.write(c.data(), size);
}

template<class Size>
inline ssize_t readSizedData(Readable auto& io, ResizableContainer auto& c)
{
auto size = io.template get<Size>();
return io.readSized(c, size);
}


}
1 change: 0 additions & 1 deletion EmuFramework/include/emuframework/RecentContent.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public:
void clear() { recentContentList.clear(); }
void writeConfig(FileIO &) const;
bool readConfig(MapIO &, unsigned key, const EmuSystem &);
bool readLegacyConfig(MapIO &, const EmuSystem &);

private:
std::vector<RecentContentInfo> recentContentList;
Expand Down
3 changes: 2 additions & 1 deletion EmuFramework/include/emuframework/SystemActionsView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public:
void onShow() override;
void loadStandardItems();

static constexpr int STANDARD_ITEMS = 10;
static constexpr int STANDARD_ITEMS = 11;
static constexpr int MAX_SYSTEM_ITEMS = 6;

protected:
Expand All @@ -42,6 +42,7 @@ protected:
TextMenuItem autosaveNow;
TextMenuItem revertAutosave;
TextMenuItem stateSlot;
TextMenuItem inputOverrides;
ConditionalMember<Config::envIsAndroid, TextMenuItem> addLauncherIcon;
TextMenuItem screenshot;
TextMenuItem resetSessionOptions;
Expand Down
9 changes: 4 additions & 5 deletions EmuFramework/src/ConfigFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ void EmuApp::saveConfigFile(FileIO &io)
writeOptionValue(io, CFGKEY_BACK_NAVIGATION, viewManager.needsBackControlOption());
writeOptionValue(io, CFGKEY_SWAPPED_GAMEPAD_CONFIM, swappedConfirmKeysOption());
writeOptionValue(io, CFGKEY_AUDIO_SOLO_MIX, audio.manager.soloMixOption());
writeOptionValue(io, CFGKEY_WINDOW_PIXEL_FORMAT, windowDrawablePixelFormatOption());
writeOptionValue(io, CFGKEY_VIDEO_COLOR_SPACE, windowDrawableColorSpaceOption());
writeOptionValueIfNotDefault(io, windowDrawableConfig.pixelFormat);
writeOptionValueIfNotDefault(io, windowDrawableConfig.colorSpace);
writeOptionValueIfNotDefault(io, renderPixelFormat);
writeOptionValueIfNotDefault(io, textureBufferMode);
writeOptionValueIfNotDefault(io, showOnSecondScreen);
Expand Down Expand Up @@ -178,8 +178,7 @@ EmuApp::ConfigParams EmuApp::loadConfigFile(IG::ApplicationContext ctx)
case CFGKEY_MENU_SCALE: return readOptionValue(io, menuScale);
case CFGKEY_SHOW_ON_2ND_SCREEN: return readOptionValue(io, showOnSecondScreen);
case CFGKEY_IMAGE_EFFECT_PIXEL_FORMAT: return readOptionValue(io, imageEffectPixelFormat);
case CFGKEY_RENDER_PIXEL_FORMAT: return EmuSystem::canRenderRGBA8888 ? readOptionValue(io, renderPixelFormat) : false;
case CFGKEY_RECENT_CONTENT: return recentContent.readLegacyConfig(io, system());
case CFGKEY_RENDER_PIXEL_FORMAT: return EmuSystem::canRenderMultipleFormats() ? readOptionValue(io, renderPixelFormat) : false;
case CFGKEY_SWAPPED_GAMEPAD_CONFIM:
setSwappedConfirmKeys(readOptionValue<bool>(io));
return true;
Expand Down Expand Up @@ -241,7 +240,7 @@ EmuApp::ConfigParams EmuApp::loadConfigFile(IG::ApplicationContext ctx)
{
if(pendingWindowDrawableConf.colorSpace != Gfx::ColorSpace{} && pendingWindowDrawableConf.pixelFormat != IG::PixelFmtRGBA8888)
pendingWindowDrawableConf.colorSpace = {};
windowDrawableConf = pendingWindowDrawableConf;
windowDrawableConfig = pendingWindowDrawableConf;
}

return appConfig;
Expand Down
Loading

0 comments on commit 5060e6d

Please sign in to comment.