View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2016 Jeffrey Pfau
+/* Copyright (c) 2013-2017 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -12,6 +12,7 @@
#include <QTimer>
#include <functional>
+#include <memory>
#include <mgba/core/thread.h>
@@ -22,14 +23,17 @@ struct mArguments;
namespace QGBA {
+class AudioProcessor;
class ConfigController;
+class CoreController;
+class CoreManager;
class DebuggerConsoleController;
class Display;
-class GameController;
class GDBController;
class GIFView;
class LibraryController;
class LogView;
+class OverrideView;
class ShaderSelector;
class VideoView;
class WindowBackground;
@@ -38,10 +42,10 @@ class Window : public QMainWindow {
Q_OBJECT
public:
- Window(ConfigController* config, int playerId = 0, QWidget* parent = nullptr);
+ Window(CoreManager* manager, ConfigController* config, int playerId = 0, QWidget* parent = nullptr);
virtual ~Window();
- GameController* controller() { return m_controller; }
+ std::shared_ptr<CoreController> controller() { return m_controller; }
void setConfig(ConfigController*);
void argumentsPassed(mArguments*);
@@ -51,13 +55,12 @@ Q_OBJECT
void updateMultiplayerStatus(bool canOpenAnother) { m_multiWindow->setEnabled(canOpenAnother); }
signals:
- void startDrawing(mCoreThread*);
+ void startDrawing();
void shutdown();
- void audioBufferSamplesChanged(int samples);
- void sampleRateChanged(unsigned samples);
- void fpsTargetChanged(float target);
+ void paused(bool);
public slots:
+ void setController(CoreController* controller, const QString& fname);
void selectROM();
#ifdef USE_SQLITE3
void selectROMInArchive();
@@ -80,7 +83,6 @@ public slots:
void exportSharkport();
void openSettingsWindow();
- void openAboutScreen();
void startVideoLog();
@@ -113,12 +115,15 @@ public slots:
virtual void mouseReleaseEvent(QMouseEvent*) override;
private slots:
- void gameStarted(mCoreThread*, const QString&);
+ void gameStarted();
void gameStopped();
void gameCrashed(const QString&);
void gameFailed();
void unimplementedBiosCall(int);
+ void reloadAudioDriver();
+ void reloadDisplayDriver();
+
void tryMakePortable();
void mustRestart();
@@ -141,8 +146,8 @@ private slots:
void openView(QWidget* widget);
- template <typename T, typename A> std::function<void()> openTView(A arg);
- template <typename T> std::function<void()> openTView();
+ template <typename T, typename... A> std::function<void()> openTView(A... arg);
+ template <typename T, typename... A> std::function<void()> openControllerTView(A... arg);
QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
@@ -152,8 +157,11 @@ private slots:
QString getFilters() const;
QString getFiltersArchive() const;
- GameController* m_controller;
- Display* m_display;
+ CoreManager* m_manager;
+ std::shared_ptr<CoreController> m_controller;
+ std::unique_ptr<AudioProcessor> m_audioProcessor;
+
+ std::unique_ptr<Display> m_display;
int m_savedScale;
// TODO: Move these to a new class
QList<QAction*> m_gameActions;
@@ -177,14 +185,17 @@ private slots:
QMenu* m_mruMenu = nullptr;
QMenu* m_videoLayers;
QMenu* m_audioChannels;
- ShaderSelector* m_shaderView;
+ std::unique_ptr<ShaderSelector> m_shaderView;
bool m_fullscreenOnStart = false;
QTimer m_focusCheck;
bool m_autoresume = false;
bool m_wasOpened = false;
+ QString m_pendingPatch;
bool m_hitUnimplementedBiosCall;
+ OverrideView* m_overrideView = nullptr;
+
#ifdef USE_FFMPEG
VideoView* m_videoView = nullptr;
#endif
View
@@ -6,7 +6,7 @@
#include "InputController.h"
#include "ConfigController.h"
-#include "GameController.h"
+#include "CoreController.h"
#include "GamepadAxisEvent.h"
#include "GamepadButtonEvent.h"
#include "InputItem.h"
@@ -94,18 +94,42 @@ void InputController::addKey(const QString& name) {
return;
}
m_keyIndex.addItem(qMakePair([this, name]() {
- emit keyPressed(keyId(name));
+ m_activeKeys |= 1 << keyId(name);
}, [this, name]() {
- emit keyReleased(keyId(name));
+ m_activeKeys &= ~(1 << keyId(name));
}), name, QString("key%0").arg(name), m_bindings.get());
m_keyIndex.addItem(qMakePair([this, name]() {
- emit keyAutofire(keyId(name), true);
+ setAutofire(keyId(name), true);
}, [this, name]() {
- emit keyAutofire(keyId(name), false);
+ setAutofire(keyId(name), false);
}), name, QString("autofire%1").arg(name), m_autofire.get());
}
+void InputController::setAutofire(int key, bool enable) {
+ if (key >= 32 || key < 0) {
+ return;
+ }
+
+ m_autofireEnabled[key] = enable;
+ m_autofireStatus[key] = 0;
+}
+
+int InputController::updateAutofire() {
+ int active = 0;
+ for (int k = 0; k < 32; ++k) {
+ if (!m_autofireEnabled[k]) {
+ continue;
+ }
+ ++m_autofireStatus[k];
+ if (m_autofireStatus[k]) {
+ m_autofireStatus[k] = 0;
+ active |= 1 << k;
+ }
+ }
+ return active;
+}
+
void InputController::addPlatform(mPlatform platform, const mInputPlatformInfo* info) {
m_keyInfo[platform] = info;
for (size_t i = 0; i < info->nKeys; ++i) {
@@ -130,6 +154,20 @@ void InputController::setPlatform(mPlatform platform) {
rebuildKeyIndex();
restoreModel();
+
+#ifdef M_CORE_GBA
+ m_lux.p = this;
+ m_lux.sample = [](GBALuminanceSource* context) {
+ InputControllerLux* lux = static_cast<InputControllerLux*>(context);
+ lux->value = 0xFF - lux->p->m_luxValue;
+ };
+
+ m_lux.readLuminance = [](GBALuminanceSource* context) {
+ InputControllerLux* lux = static_cast<InputControllerLux*>(context);
+ return lux->value;
+ };
+ setLuminanceLevel(0);
+#endif
}
InputController::~InputController() {
@@ -167,7 +205,6 @@ void InputController::setConfiguration(ConfigController* config) {
m_config = config;
m_inputIndex.setConfigController(config);
m_keyIndex.setConfigController(config);
- setAllowOpposing(config->getOption("allowOpposingDirections").toInt());
loadConfiguration(KEYBOARD);
loadProfile(KEYBOARD, profileForType(KEYBOARD));
#ifdef BUILD_SDL
@@ -382,7 +419,7 @@ const mInputMap* InputController::map() {
}
int InputController::pollEvents() {
- int activeButtons = 0;
+ int activeButtons = m_activeKeys;
#ifdef BUILD_SDL
if (m_playerAttached && m_sdlPlayer.joystick) {
SDL_Joystick* joystick = m_sdlPlayer.joystick->joystick;
@@ -853,3 +890,34 @@ void InputController::rebindKey(const QString& key) {
bindAxis(SDL_BINDING_BUTTON, item->axis(), item->direction(), key);
#endif
}
+
+void InputController::increaseLuminanceLevel() {
+ setLuminanceLevel(m_luxLevel + 1);
+}
+
+void InputController::decreaseLuminanceLevel() {
+ setLuminanceLevel(m_luxLevel - 1);
+}
+
+void InputController::setLuminanceLevel(int level) {
+ int value = 0x16;
+ level = std::max(0, std::min(10, level));
+ if (level > 0) {
+ value += GBA_LUX_LEVELS[level - 1];
+ }
+ setLuminanceValue(value);
+}
+
+void InputController::setLuminanceValue(uint8_t value) {
+ m_luxValue = value;
+ value = std::max<int>(value - 0x16, 0);
+ m_luxLevel = 10;
+ for (int i = 0; i < 10; ++i) {
+ if (value < GBA_LUX_LEVELS[i]) {
+ m_luxLevel = i;
+ break;
+ }
+ }
+ emit luminanceValueChanged(m_luxValue);
+}
+
View
@@ -21,6 +21,8 @@
#include <mgba/core/core.h>
#include <mgba/core/input.h>
+#include <mgba/gba/interface.h>
+
#ifdef BUILD_SDL
#include "platform/sdl/sdl-events.h"
#endif
@@ -62,8 +64,9 @@ Q_OBJECT
void saveProfile(uint32_t type, const QString& profile);
const char* profileForType(uint32_t type);
- bool allowOpposing() const { return m_allowOpposing; }
- void setAllowOpposing(bool allowOpposing) { m_allowOpposing = allowOpposing; }
+ GBAKey mapKeyboard(int key) const;
+
+ void bindKey(uint32_t type, int key, GBAKey);
const mInputMap* map();
@@ -97,22 +100,29 @@ Q_OBJECT
mRumble* rumble();
mRotationSource* rotationSource();
+ GBALuminanceSource* luminance() { return &m_lux; }
signals:
void profileLoaded(const QString& profile);
- void keyPressed(int);
- void keyReleased(int);
- void keyAutofire(int, bool enabled);
+ void luminanceValueChanged(int value);
public slots:
void testGamepad(int type);
void updateJoysticks();
+ int updateAutofire();
+
+ void setAutofire(int key, bool enable);
// TODO: Move these to somewhere that makes sense
void suspendScreensaver();
void resumeScreensaver();
void setScreensaverSuspendable(bool);
+ void increaseLuminanceLevel();
+ void decreaseLuminanceLevel();
+ void setLuminanceLevel(int level);
+ void setLuminanceValue(uint8_t value);
+
protected:
bool eventFilter(QObject*, QEvent*) override;
@@ -129,10 +139,21 @@ public slots:
InputIndex m_inputIndex;
InputIndex m_keyIndex;
+
+ struct InputControllerLux : GBALuminanceSource {
+ InputController* p;
+ uint8_t value;
+ } m_lux;
+ uint8_t m_luxValue;
+ int m_luxLevel;
+
mInputMap m_inputMap;
+ int m_activeKeys;
+ bool m_autofireEnabled[32] = {};
+ int m_autofireStatus[32] = {};
+
ConfigController* m_config = nullptr;
int m_playerId;
- bool m_allowOpposing = false;
QWidget* m_topLevel;
QWidget* m_focusParent;
QMap<mPlatform, const mInputPlatformInfo*> m_keyInfo;
View
@@ -83,6 +83,9 @@ LibraryController::~LibraryController() {
}
void LibraryController::setViewStyle(LibraryStyle newStyle) {
+ if (m_currentStyle == newStyle) {
+ return;
+ }
m_currentStyle = newStyle;
AbstractGameList* newCurrentList = nullptr;