Skip to content

Commit

Permalink
Misc tweaks
Browse files Browse the repository at this point in the history
* Imagine: Merge bitset.hh into bit.hh
* Imagine: Add utility functions for bit set classes
* Imagine: Convert all bit set enums into classes with bit fields for easier usage
* Imagine: Allow null BufferDeleter
* EmuFramework: Store recent content items as separate entries in config file
* EmuFramework: Add option to set max recent content items
  • Loading branch information
Robert Broglia committed Aug 21, 2023
1 parent 3dbac69 commit 43f5c8e
Show file tree
Hide file tree
Showing 107 changed files with 655 additions and 531 deletions.
4 changes: 2 additions & 2 deletions 2600.emu/src/main/input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,10 @@ SystemInputDeviceDesc A2600System::inputDeviceDesc(int idx) const
{
InputComponentDesc{"D-Pad", dpadKeyInfo, InputComponent::dPad, LB2DO},
InputComponentDesc{"Joystick Buttons", triggerKeyInfo, InputComponent::button, RB2DO},
InputComponentDesc{"Keyboard Buttons", kbKeyInfo, InputComponent::button, RB2DO, InputComponentFlagsMask::altConfig | InputComponentFlagsMask::rowSize3},
InputComponentDesc{"Keyboard Buttons", kbKeyInfo, InputComponent::button, RB2DO, {.altConfig = true, .rowSize = 3}},
InputComponentDesc{"Select", {&consoleKeyInfo[0], 1}, InputComponent::button, LB2DO},
InputComponentDesc{"Reset", {&consoleKeyInfo[1], 1}, InputComponent::button, RB2DO},
InputComponentDesc{"Console Buttons", consoleKeyInfo, InputComponent::button, RB2DO, InputComponentFlagsMask::altConfig},
InputComponentDesc{"Console Buttons", consoleKeyInfo, InputComponent::button, RB2DO, {.altConfig = true}},
};

static constexpr SystemInputDeviceDesc jsDesc{"Joystick", jsComponents};
Expand Down
2 changes: 1 addition & 1 deletion 2600.emu/src/stella/emucore/Serializer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Serializer::Serializer(const string& filename, Mode m)
ios_base::openmode stream_mode = ios::in | ios::out | ios::binary;
if(m == Mode::ReadWriteTrunc)
stream_mode |= ios::trunc;
auto str = make_unique<IG::FStream>(EmuEx::gAppContext().openFileUri(filename, IG::OpenFlagsMask::New), stream_mode);
auto str = make_unique<IG::FStream>(EmuEx::gAppContext().openFileUri(filename, IG::OpenFlags::newFile()), stream_mode);
if(str && str->is_open())
{
myStream = std::move(str);
Expand Down
2 changes: 1 addition & 1 deletion C64.emu/src/main/VicePlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ VicePlugin loadVicePlugin(ViceSystem system, const char *libBasePath)
};
auto libPath = makePluginLibPath(libName[std::to_underlying(system)], libBasePath);
logMsg("loading VICE plugin:%s", libPath.data());
auto lib = IG::openSharedLibrary(libPath.data(), IG::RESOLVE_ALL_SYMBOLS_FLAG);
auto lib = IG::openSharedLibrary(libPath.data(), {.resolveAllSymbols = true});
if(!lib)
{
return {};
Expand Down
2 changes: 1 addition & 1 deletion C64.emu/src/main/input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ SystemInputDeviceDesc C64System::inputDeviceDesc(int idx) const
{
InputComponentDesc{"D-Pad", dpadKeyInfo, InputComponent::dPad, LB2DO},
InputComponentDesc{"Joystick Button", triggerKeyInfo, InputComponent::button, RB2DO},
InputComponentDesc{"F1 & Keyboard Toggle", shortcutKeyInfo, InputComponent::button, RB2DO, InputComponentFlagsMask::rowSize1},
InputComponentDesc{"F1 & Keyboard Toggle", shortcutKeyInfo, InputComponent::button, RB2DO, {.rowSize = 1}},
};

static constexpr SystemInputDeviceDesc jsDesc{"Joystick", jsComponents};
Expand Down
4 changes: 2 additions & 2 deletions C64.emu/src/main/sysfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static ArchiveIO archiveIOForSysFile(IG::CStringView archivePath, std::string_vi
static AssetIO assetIOForSysFile(IG::ApplicationContext ctx, std::string_view sysFileName, std::string_view subPath, char **complete_path_return)
{
auto fullPath = FS::pathString(subPath, sysFileName);
auto file = ctx.openAsset(fullPath, IOAccessHint::All, OpenFlagsMask::Test);
auto file = ctx.openAsset(fullPath, IOAccessHint::All, {.test = true});
if(!file)
return {};
if(complete_path_return)
Expand Down Expand Up @@ -309,7 +309,7 @@ CLINK int sysfile_load(const char *name, const char *subPath, uint8_t *dest, int
}
else
{
auto file = appContext.openFileUri(FS::uriString(basePath, subPath, name), IOAccessHint::All, OpenFlagsMask::Test);
auto file = appContext.openFileUri(FS::uriString(basePath, subPath, name), IOAccessHint::All, {.test = true});
if(!file)
continue;
//logMsg("loading system file: %s", complete_path);
Expand Down
3 changes: 2 additions & 1 deletion 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 \
RecentContent.cc \
ToggleInput.cc \
TurboInput.cc \
VideoImageEffect.cc \
Expand All @@ -39,7 +40,7 @@ gui/LoadProgressView.cc \
gui/MainMenuView.cc \
gui/PlaceVControlsView.cc \
gui/PlaceVideoView.cc \
gui/RecentGameView.cc \
gui/RecentContentView.cc \
gui/StateSlotView.cc \
gui/SystemActionsView.cc \
gui/SystemOptionView.cc \
Expand Down
22 changes: 2 additions & 20 deletions EmuFramework/include/emuframework/EmuApp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <emuframework/Option.hh>
#include <emuframework/AutosaveManager.hh>
#include <emuframework/OutputTimingManager.hh>
#include <emuframework/RecentContent.hh>
#include <imagine/input/Input.hh>
#include <imagine/input/android/MogaManager.hh>
#include <imagine/gui/ViewManager.hh>
Expand All @@ -44,7 +45,6 @@
#include <imagine/data-type/image/PixmapWriter.hh>
#include <imagine/font/Font.hh>
#include <imagine/util/used.hh>
#include <imagine/util/container/ArrayList.hh>
#include <imagine/util/enum.hh>
#include <cstring>
#include <optional>
Expand All @@ -64,17 +64,6 @@ namespace EmuEx
struct MainWindowData;
class EmuMainMenuView;

struct RecentContentInfo
{
FS::PathString path{};
FS::FileString name{};

constexpr bool operator ==(RecentContentInfo const& rhs) const
{
return path == rhs.path;
}
};

enum class Tristate : uint8_t
{
OFF, IN_EMU, ON
Expand Down Expand Up @@ -148,8 +137,6 @@ class EmuApp : public IG::Application
public:
using CreateSystemCompleteDelegate = DelegateFunc<void (const Input::Event &)>;
using NavView = BasicNavView;
static constexpr int MAX_RECENT = 10;
using RecentContentList = StaticArrayList<RecentContentInfo, MAX_RECENT>;

enum class ViewID
{
Expand Down Expand Up @@ -265,11 +252,6 @@ public:
BluetoothAdapter *bluetoothAdapter();
void closeBluetoothConnections();
ViewAttachParams attachParams();
void addRecentContent(std::string_view path, std::string_view name);
void addCurrentContentToRecent();
RecentContentList &recentContent() { return recentContentList; };
void writeRecentContent(FileIO &);
bool readRecentContent(IG::ApplicationContext, MapIO &, size_t readSize_);
auto &customKeyConfigList() { return inputManager.customKeyConfigs; };
auto &savedInputDeviceList() { return inputManager.savedInputDevs; };
IG::Viewport makeViewport(const Window &win) const;
Expand Down Expand Up @@ -531,8 +513,8 @@ protected:
[[no_unique_address]] PerformanceHintSession perfHintSession;
BluetoothAdapter *bta{};
IG_UseMemberIf(MOGA_INPUT, std::unique_ptr<Input::MogaManager>, mogaManagerPtr);
RecentContentList recentContentList;
public:
RecentContent recentContent;
std::string userScreenshotPath;
protected:
IG_UseMemberIf(Config::cpuAffinity, CPUMask, cpuAffinityMask){};
Expand Down
16 changes: 8 additions & 8 deletions EmuFramework/include/emuframework/EmuAudio.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include <imagine/time/Time.hh>
#include <imagine/vmem/RingBuffer.hh>
#include <imagine/util/used.hh>
#include <imagine/util/bitset.hh>
#include <imagine/util/enum.hh>
#include <memory>
#include <atomic>

Expand All @@ -35,14 +33,16 @@ namespace EmuEx

using namespace IG;

enum class AudioFlagsMask: uint8_t
struct AudioFlags
{
enabled = bit(0),
enabledDuringAltSpeed = bit(1),
defaultMask = enabled | enabledDuringAltSpeed,
uint8_t
enabled{},
enabledDuringAltSpeed{};

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

IG_DEFINE_ENUM_BIT_FLAG_FUNCTIONS(AudioFlagsMask);
constexpr AudioFlags defaultAudioFlags{.enabled = 1, .enabledDuringAltSpeed = 1};

class EmuAudio
{
Expand Down Expand Up @@ -95,7 +95,7 @@ protected:
float currentVolume{1.};
std::atomic<AudioWriteState> audioWriteState{AudioWriteState::BUFFER};
int8_t channels{2};
AudioFlagsMask flagsMask{AudioFlagsMask::defaultMask};
AudioFlags flags{defaultAudioFlags};
IG_UseMemberIf(IG::Audio::Config::MULTIPLE_SYSTEM_APIS, IG::Audio::Api, audioAPI){};
bool addSoundBuffersOnUnderrun{};
public:
Expand Down
21 changes: 6 additions & 15 deletions EmuFramework/include/emuframework/EmuSystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include <imagine/time/Time.hh>
#include <imagine/audio/SampleFormat.hh>
#include <imagine/util/rectangle2.h>
#include <imagine/util/enum.hh>
#include <imagine/util/bitset.hh>
#include <emuframework/EmuTiming.hh>
#include <emuframework/VController.hh>
#include <emuframework/EmuInput.hh>
Expand Down Expand Up @@ -101,28 +99,21 @@ enum class InputComponent : uint8_t
ui, dPad, button, trigger
};

enum class InputComponentFlagsMask: uint8_t
struct InputComponentFlags
{
altConfig = bit(0),
rowSizeBit1 = bit(1),
rowSizeBit2 = bit(2),
rowSizeBits = rowSizeBit1 | rowSizeBit2,
rowSizeAuto = 0,
rowSize1 = rowSizeBit1,
rowSize2 = rowSizeBit2,
rowSize3 = rowSizeBit1 | rowSizeBit2,
staggeredLayout = bit(3),
uint8_t
altConfig:1{},
rowSize:2{},
staggeredLayout:1{};
};

IG_DEFINE_ENUM_BIT_FLAG_FUNCTIONS(InputComponentFlagsMask);

struct InputComponentDesc
{
const char *name{};
std::span<const KeyInfo> keyCodes{};
InputComponent type{};
_2DOrigin layoutOrigin{};
InputComponentFlagsMask flags{};
InputComponentFlags flags{};
};

struct SystemInputDeviceDesc
Expand Down
3 changes: 2 additions & 1 deletion EmuFramework/include/emuframework/GUIOptionView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected:
BoolMenuItem showBundledGames;
BoolMenuItem showBluetoothScan;
BoolMenuItem showHiddenFiles;
DualTextMenuItem maxRecentContent;
TextHeadingMenuItem orientationHeading;
TextMenuItem menuOrientationItem[5];
MultiChoiceMenuItem menuOrientation;
Expand All @@ -57,7 +58,7 @@ protected:
IG_UseMemberIf(Config::TRANSLUCENT_SYSTEM_UI, BoolMenuItem, layoutBehindSystemUI);
IG_UseMemberIf(Config::freeformWindows, TextMenuItem, setWindowSize);
IG_UseMemberIf(Config::freeformWindows, TextMenuItem, toggleFullScreen);
StaticArrayList<MenuItem*, 22> item;
StaticArrayList<MenuItem*, 23> item;
};

}
67 changes: 67 additions & 0 deletions EmuFramework/include/emuframework/RecentContent.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#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 <imagine/fs/FSDefs.hh>
#include <vector>
#include <string_view>

namespace IG
{
class ApplicationContext;
class FileIO;
class MapIO;
}

namespace EmuEx
{

class EmuSystem;

using namespace IG;

struct RecentContentInfo
{
FS::PathString path;
FS::FileString name;

constexpr bool operator==(RecentContentInfo const& rhs) const
{
return path == rhs.path;
}
};

class RecentContent
{
public:
void add(std::string_view path, std::string_view name);
void add(const EmuSystem &);
size_t size() const { return recentContentList.size(); }
auto begin() const { return recentContentList.begin(); }
auto end() const { return recentContentList.end(); }
void clear() { recentContentList.clear(); }
void writeConfig(FileIO &) const;
bool readConfig(MapIO &, unsigned key, size_t size, const EmuSystem &);
bool readLegacyConfig(MapIO &, const EmuSystem &);

private:
std::vector<RecentContentInfo> recentContentList;
public:
static constexpr uint8_t defaultMaxRecentContent{20};
uint8_t maxRecentContent{defaultMaxRecentContent};
};

}
2 changes: 0 additions & 2 deletions EmuFramework/include/emuframework/inputDefs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
along with EmuFramework. If not, see <http://www.gnu.org/licenses/> */

#include <imagine/input/Input.hh>
#include <imagine/util/enum.hh>
#include <imagine/util/bitset.hh>
#include <imagine/util/container/array.hh>
#include <array>
#include <cstdint>
Expand Down
2 changes: 1 addition & 1 deletion EmuFramework/src/AutosaveManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bool AutosaveManager::deleteSlot(std::string_view name)
{
ctx.removeFileUri(e.path());
return true;
}, FS::DirOpenFlagsMask::Test))
}, {.test = true}))
{
return false;
}
Expand Down
10 changes: 6 additions & 4 deletions EmuFramework/src/ConfigFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void EmuApp::saveConfigFile(FileIO &io)

std::apply([&](auto &...opt){ (writeOptionValue(io, opt), ...); }, cfgFileOptions);

writeRecentContent(io);
recentContent.writeConfig(io);
writeOptionValueIfNotDefault(io, CFGKEY_GAME_ORIENTATION, optionEmuOrientation, Orientations{});
writeOptionValueIfNotDefault(io, CFGKEY_MENU_ORIENTATION, optionMenuOrientation, Orientations{});
writeOptionValue(io, CFGKEY_BACK_NAVIGATION, viewManager.needsBackControlOption());
Expand Down Expand Up @@ -193,7 +193,7 @@ EmuApp::ConfigParams EmuApp::loadConfigFile(IG::ApplicationContext ctx)
#endif
ConfigParams appConfig{};
Gfx::DrawableConfig pendingWindowDrawableConf{};
readConfigKeys(FileUtils::bufferFromPath(configFilePath, OpenFlagsMask::Test),
readConfigKeys(FileUtils::bufferFromPath(configFilePath, {.test = true}),
[&](auto key, auto size, auto &io) -> bool
{
switch(key)
Expand All @@ -208,6 +208,8 @@ EmuApp::ConfigParams EmuApp::loadConfigFile(IG::ApplicationContext ctx)
return true;
if(emuAudio.readConfig(io, key, size))
return true;
if(recentContent.readConfig(io, key, size, system()))
return true;
logMsg("skipping key %u", (unsigned)key);
return false;
}
Expand All @@ -233,7 +235,7 @@ EmuApp::ConfigParams EmuApp::loadConfigFile(IG::ApplicationContext ctx)
case CFGKEY_VIDEO_IMAGE_BUFFERS: return optionVideoImageBuffers.readFromIO(io, size);
case CFGKEY_OVERLAY_EFFECT: return optionOverlayEffect.readFromIO(io, size);
case CFGKEY_OVERLAY_EFFECT_LEVEL: return optionOverlayEffectLevel.readFromIO(io, size);
case CFGKEY_RECENT_GAMES: return readRecentContent(ctx, io, size);
case CFGKEY_RECENT_CONTENT: return recentContent.readLegacyConfig(io, system());
case CFGKEY_SWAPPED_GAMEPAD_CONFIM:
setSwappedConfirmKeys(readOptionValue<bool>(io, size));
return true;
Expand Down Expand Up @@ -317,7 +319,7 @@ void EmuApp::saveConfigFile(IG::ApplicationContext ctx)
auto configFilePath = FS::pathString(ctx.supportPath(), "config");
try
{
FileIO file{configFilePath, OpenFlagsMask::New};
FileIO file{configFilePath, OpenFlags::newFile()};
saveConfigFile(file);
}
catch(...)
Expand Down

0 comments on commit 43f5c8e

Please sign in to comment.