From 5d135b556dff841ff8487f9a56c7d58e7b879ee8 Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Wed, 1 Aug 2018 19:07:28 +1000 Subject: [PATCH] Update to v106r53 release. byuu says: Okay, so the WIPs-within-WIPs thing wasn't achieving its desired effect, and it ended up causing me to have to redo some work on hiro since my last local snapshot was of r52. So, heck it. I'll just do mostly non-functional WIPs for a bit, and worry about the fallout years later when I'm trying to find an emulation regression and cursing that the WIPs aren't compiling. I ported all of the ruby input drivers to the new syntax, as well as the OpenAL driver. If you patch the ruby drivers for Linux with this in mind, bsnes should compile and run there again. Also, the bsnes program icon has returned, now that the new hiro layout code is mature enough and I can simply add and remove the icon as a Canvas instead of having to try and render into a viewport. The icon shows up instantly with the main window. --- .../presentation/presentation.cpp | 5 ++ .../presentation/presentation.hpp | 3 + higan/target-bsnes/program/game.cpp | 2 + hiro/extension/fixed-layout.cpp | 4 + hiro/extension/horizontal-layout.cpp | 5 ++ hiro/extension/table-layout.cpp | 5 ++ hiro/extension/vertical-layout.cpp | 5 ++ hiro/gtk/widget/combo-button-item.cpp | 9 +- hiro/gtk/widget/combo-button-item.hpp | 2 +- hiro/gtk/widget/combo-button.cpp | 23 ++--- hiro/gtk/widget/combo-button.hpp | 1 + nall/nall.hpp | 1 + nall/simd.hpp | 11 +++ ruby/GNUmakefile | 4 +- ruby/audio/audio.hpp | 8 +- ruby/audio/openal.cpp | 83 +++++++----------- ruby/audio/oss.cpp | 8 +- ruby/input/carbon.cpp | 26 +++--- ruby/input/quartz.cpp | 24 +++--- ruby/input/sdl.cpp | 8 +- ruby/input/udev.cpp | 66 +++++++------- ruby/input/windows.cpp | 86 +++++++++---------- ruby/input/xlib.cpp | 56 ++++++------ ruby/video/glx2.cpp | 8 +- ruby/video/xshm.cpp | 6 +- 25 files changed, 231 insertions(+), 228 deletions(-) create mode 100644 nall/simd.hpp diff --git a/higan/target-bsnes/presentation/presentation.cpp b/higan/target-bsnes/presentation/presentation.cpp index 45c5c562..40961616 100644 --- a/higan/target-bsnes/presentation/presentation.cpp +++ b/higan/target-bsnes/presentation/presentation.cpp @@ -147,6 +147,11 @@ auto Presentation::create() -> void { setFocused(); }); + iconLayout.setAlignment(0.0); + image icon{Resource::Icon}; + icon.alphaBlend(0x000000); + iconCanvas.setIcon(icon); + if(!settings["UserInterface/ShowStatusBar"].boolean()) { layout.remove(statusLayout); } diff --git a/higan/target-bsnes/presentation/presentation.hpp b/higan/target-bsnes/presentation/presentation.hpp index fc8c8afb..0249d442 100644 --- a/higan/target-bsnes/presentation/presentation.hpp +++ b/higan/target-bsnes/presentation/presentation.hpp @@ -103,6 +103,9 @@ struct Presentation : Window { VerticalLayout layout{this}; HorizontalLayout viewportLayout{&layout, Size{~0, ~0}, 0}; Viewport viewport{&viewportLayout, Size{~0, ~0}, 0}; + VerticalLayout iconLayout{&viewportLayout, Size{0, ~0}}; + Widget iconSpacer{&iconLayout, Size{144, ~0}}; + Canvas iconCanvas{&iconLayout, Size{128, 128}, 0}; HorizontalLayout statusLayout{&layout, Size{~0, StatusHeight}, 0}; Label spacerIcon{&statusLayout, Size{8, ~0}, 0}; Canvas statusIcon{&statusLayout, Size{16, ~0}, 0}; diff --git a/higan/target-bsnes/program/game.cpp b/higan/target-bsnes/program/game.cpp index 560d70aa..eafd5bee 100644 --- a/higan/target-bsnes/program/game.cpp +++ b/higan/target-bsnes/program/game.cpp @@ -41,6 +41,7 @@ auto Program::load() -> void { presentation.speedNormal.setChecked(); presentation.pauseEmulation.setChecked(false); presentation.updateStatusIcon(); + presentation.viewportLayout.remove(presentation.iconLayout); presentation.resizeViewport(); cheatEditor.loadCheats(); stateManager.loadStates(); @@ -304,6 +305,7 @@ auto Program::unload() -> void { presentation.toolsMenu.setVisible(false); presentation.updateStatusIcon(); presentation.clearViewport(); + presentation.viewportLayout.append(presentation.iconLayout, Size{0, ~0}); } //a game is considered verified if the game plus its slot(s) are found in the games database diff --git a/hiro/extension/fixed-layout.cpp b/hiro/extension/fixed-layout.cpp index ef061536..102c33ff 100644 --- a/hiro/extension/fixed-layout.cpp +++ b/hiro/extension/fixed-layout.cpp @@ -1,6 +1,10 @@ #if defined(Hiro_FixedLayout) auto mFixedLayout::append(sSizable sizable, Geometry geometry) -> type& { + for(auto& cell : state.cells) { + if(cell->state.sizable == sizable) return *this; + } + FixedLayoutCell cell; cell->setSizable(sizable); cell->setGeometry(geometry); diff --git a/hiro/extension/horizontal-layout.cpp b/hiro/extension/horizontal-layout.cpp index a30ff306..28579def 100644 --- a/hiro/extension/horizontal-layout.cpp +++ b/hiro/extension/horizontal-layout.cpp @@ -5,6 +5,10 @@ auto mHorizontalLayout::alignment() const -> maybe { } auto mHorizontalLayout::append(sSizable sizable, Size size, float spacing) -> type& { + for(auto& cell : state.cells) { + if(cell->state.sizable == sizable) return *this; + } + HorizontalLayoutCell cell; cell->setSizable(sizable); cell->setSize(size); @@ -106,6 +110,7 @@ auto mHorizontalLayout::setFont(const Font& font) -> type& { auto mHorizontalLayout::setGeometry(Geometry geometry) -> type& { mSizable::setGeometry(geometry); + if(!visible(true)) return *this; geometry.setX(geometry.x() + padding().x()); geometry.setY(geometry.y() + padding().y()); diff --git a/hiro/extension/table-layout.cpp b/hiro/extension/table-layout.cpp index 973db6ce..d77c8519 100644 --- a/hiro/extension/table-layout.cpp +++ b/hiro/extension/table-layout.cpp @@ -5,6 +5,10 @@ auto mTableLayout::alignment() const -> Alignment { } auto mTableLayout::append(sSizable sizable, Size size) -> type& { + for(auto& cell : state.cells) { + if(cell->state.sizable == sizable) return *this; + } + TableLayoutCell cell; cell->setSizable(sizable); cell->setSize(size); @@ -141,6 +145,7 @@ auto mTableLayout::setFont(const Font& font) -> type& { auto mTableLayout::setGeometry(Geometry geometry) -> type& { mSizable::setGeometry(geometry); + if(!visible(true)) return *this; geometry.setX(geometry.x() + padding().x()); geometry.setY(geometry.y() + padding().y()); diff --git a/hiro/extension/vertical-layout.cpp b/hiro/extension/vertical-layout.cpp index 0bb6e79f..ec967da0 100644 --- a/hiro/extension/vertical-layout.cpp +++ b/hiro/extension/vertical-layout.cpp @@ -5,6 +5,10 @@ auto mVerticalLayout::alignment() const -> maybe { } auto mVerticalLayout::append(sSizable sizable, Size size, float spacing) -> type& { + for(auto& cell : state.cells) { + if(cell->state.sizable == sizable) return *this; + } + VerticalLayoutCell cell; cell->setSizable(sizable); cell->setSize(size); @@ -106,6 +110,7 @@ auto mVerticalLayout::setFont(const Font& font) -> type& { auto mVerticalLayout::setGeometry(Geometry geometry) -> type& { mSizable::setGeometry(geometry); + if(!visible(true)) return *this; geometry.setX(geometry.x() + padding().x()); geometry.setY(geometry.y() + padding().y()); diff --git a/hiro/gtk/widget/combo-button-item.cpp b/hiro/gtk/widget/combo-button-item.cpp index 1e81dbfb..564de6c3 100644 --- a/hiro/gtk/widget/combo-button-item.cpp +++ b/hiro/gtk/widget/combo-button-item.cpp @@ -3,6 +3,7 @@ namespace hiro { auto pComboButtonItem::construct() -> void { + if(auto parent = _parent()) parent->_append(self()); } auto pComboButtonItem::destruct() -> void { @@ -29,9 +30,11 @@ auto pComboButtonItem::setText(const string& text) -> void { } } -auto pComboButtonItem::_parent() -> pComboButton* { - if(auto parent = self().parentComboButton()) return parent->self(); - return nullptr; +auto pComboButtonItem::_parent() -> maybe { + if(auto parent = self().parentComboButton()) { + if(auto self = parent->self()) return *self; + } + return {}; } } diff --git a/hiro/gtk/widget/combo-button-item.hpp b/hiro/gtk/widget/combo-button-item.hpp index 3afd541f..db731e77 100644 --- a/hiro/gtk/widget/combo-button-item.hpp +++ b/hiro/gtk/widget/combo-button-item.hpp @@ -9,7 +9,7 @@ struct pComboButtonItem : pObject { auto setSelected() -> void; auto setText(const string& text) -> void; - auto _parent() -> pComboButton*; + auto _parent() -> maybe; GtkTreeIter gtkIter; }; diff --git a/hiro/gtk/widget/combo-button.cpp b/hiro/gtk/widget/combo-button.cpp index 1959e274..3c3071ee 100644 --- a/hiro/gtk/widget/combo-button.cpp +++ b/hiro/gtk/widget/combo-button.cpp @@ -17,8 +17,6 @@ auto pComboButton::construct() -> void { gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(gtkWidget), gtkCellText, true); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(gtkWidget), gtkCellText, "text", 1, nullptr); - for(auto& item : state().items) append(item); - g_signal_connect(G_OBJECT(gtkWidget), "changed", G_CALLBACK(ComboButton_change), (gpointer)this); pWidget::construct(); @@ -29,15 +27,6 @@ auto pComboButton::destruct() -> void { } auto pComboButton::append(sComboButtonItem item) -> void { - lock(); - if(auto self = item->self()) { - gtk_list_store_append(gtkListStore, &self->gtkIter); - self->setIcon(item->state.icon); - if(item->state.selected) self->setSelected(); - self->setText(item->state.text); - } - if(gtk_combo_box_get_active(gtkComboBox) < 0) item->setSelected(); - unlock(); } auto pComboButton::minimumSize() const -> Size { @@ -75,6 +64,18 @@ auto pComboButton::setFont(const Font& font) -> void { g_object_set(G_OBJECT(gtkCellText), "font-desc", fontDescription, nullptr); } +auto pComboButton::_append(sComboButtonItem item) -> void { + lock(); + if(auto self = item->self()) { + gtk_list_store_append(gtkListStore, &self->gtkIter); + self->setIcon(item->state.icon); + if(item->state.selected) self->setSelected(); + self->setText(item->state.text); + } + if(gtk_combo_box_get_active(gtkComboBox) < 0) item->setSelected(); + unlock(); +} + auto pComboButton::_updateSelected() -> void { for(auto& item : state().items) item->state.selected = false; signed selected = gtk_combo_box_get_active(gtkComboBox); diff --git a/hiro/gtk/widget/combo-button.hpp b/hiro/gtk/widget/combo-button.hpp index a81470e6..ad076ad8 100644 --- a/hiro/gtk/widget/combo-button.hpp +++ b/hiro/gtk/widget/combo-button.hpp @@ -11,6 +11,7 @@ struct pComboButton : pWidget { auto reset() -> void; auto setFont(const Font& font) -> void override; + auto _append(sComboButtonItem item) -> void; auto _updateSelected() -> void; GtkListStore* gtkListStore = nullptr; diff --git a/nall/nall.hpp b/nall/nall.hpp index b8680e46..011b8230 100644 --- a/nall/nall.hpp +++ b/nall/nall.hpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include diff --git a/nall/simd.hpp b/nall/simd.hpp new file mode 100644 index 00000000..b413ee80 --- /dev/null +++ b/nall/simd.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace nall { + +#if defined(__AVX2__) + #define SIMD 256 + #define SIMD_AVX2 + #include +#endif + +} diff --git a/ruby/GNUmakefile b/ruby/GNUmakefile index a010e73e..83d42583 100644 --- a/ruby/GNUmakefile +++ b/ruby/GNUmakefile @@ -14,8 +14,8 @@ ifeq ($(ruby),) else ifeq ($(platform),bsd) # ruby += video.glx video.glx2 video.xvideo video.xshm ruby += video.glx2 video.xshm - ruby += audio.oss #audio.openal - ruby += input.sdl #input.xlib + ruby += audio.oss audio.openal + ruby += input.sdl input.xlib endif endif diff --git a/ruby/audio/audio.hpp b/ruby/audio/audio.hpp index 7338472a..edd4eda1 100644 --- a/ruby/audio/audio.hpp +++ b/ruby/audio/audio.hpp @@ -13,8 +13,8 @@ struct AudioDriver { virtual auto hasDevices() -> vector { return {"Default"}; } virtual auto hasBlocking() -> bool { return false; } virtual auto hasDynamic() -> bool { return false; } - virtual auto hasChannels() -> vector { return {0}; } - virtual auto hasFrequencies() -> vector { return {0}; } + virtual auto hasChannels() -> vector { return {2}; } + virtual auto hasFrequencies() -> vector { return {48000}; } virtual auto hasLatencies() -> vector { return {0}; } auto hasDevice(string device) -> bool { return (bool)hasDevices().find(device); } @@ -44,8 +44,8 @@ protected: string device = "Default"; bool blocking = false; bool dynamic = false; - uint channels = 0; - uint frequency = 0; + uint channels = 2; + uint frequency = 48000; uint latency = 0; }; diff --git a/ruby/audio/openal.cpp b/ruby/audio/openal.cpp index 12b30e97..1393c009 100644 --- a/ruby/audio/openal.cpp +++ b/ruby/audio/openal.cpp @@ -6,80 +6,52 @@ #include #endif -struct AudioOpenAL : Audio { - AudioOpenAL() { - Audio::setDevice(availableDevices().first()); - Audio::setChannels(2); - Audio::setFrequency(48000.0); - Audio::setLatency(20); - initialize(); - } +struct AudioOpenAL : AudioDriver { + AudioOpenAL(Audio& driver) : AudioDriver(super) {} + ~AudioOpenAL() { terminate(); } - ~AudioOpenAL() { - terminate(); + auto create() -> bool override { + super.setDevice(hasDevices().first()); + super.setChannels(2); + super.setFrequency(48000); + super.setLatency(20); + return initialize(); } auto driver() -> string override { return "OpenAL"; } auto ready() -> bool override { return _ready; } - auto hasDevice() -> bool override { return true; } auto hasBlocking() -> bool override { return true; } - auto hasChannels() -> bool override { return true; } - auto hasFrequency() -> bool override { return true; } - auto hasLatency() -> bool override { return true; } - auto availableDevices() -> vector override { + auto hasDevices() -> vector override { vector devices; if(const char* list = alcGetString(nullptr, ALC_DEVICE_SPECIFIER)) { while(list && *list) { - result.append(list); + devices.append(list); list += strlen(list) + 1; } } return devices; } - auto availableChannels() -> vector override { + auto hasChannels() -> vector override { return {2}; } - auto availableFrequencies() -> vector override { - return {44100.0, 48000.0, 96000.0}; + auto hasFrequencies() -> vector override { + return {44100, 48000, 96000}; } - auto availableLatencies() -> vector override { + auto hasLatencies() -> vector override { return {20, 40, 60, 80, 100}; } - auto context() -> uintptr override { return 0; } - auto dynamic() -> bool override { return false; } + auto setDevice(string device) -> bool override { return initialize(); } + auto setBlocking(bool blocking) -> bool override { return true; } + auto setFrequency(uint frequency) -> bool override { return initialize(); } + auto setLatency(uint latency) -> bool override { return updateLatency(); } - auto setDevice(string device) -> bool override { - if(device == Audio::device()) return true; - if(!Audio::setDevice(device)) return false; - return initialize(); - } - - auto setBlocking(bool blocking) -> bool override { - if(blocking == Audio::blocking()) return true; - if(!Audio::setBlocking(blocking)) return false; - return true; - } - - auto setFrequency(double frequency) -> bool override { - if(frequency == Audio::frequency()) return true; - if(!Audio::setFrequency(frequency)) return false; - return initialize(); - } - - auto setLatency(uint latency) -> bool override { - if(latency == Audio::latency()) return true; - if(!Audio::setLatency(latency)) return false; - if(ready()) updateLatency(); - return true; - } - - auto write(const double samples[]) -> void override { + auto output(const double samples[]) -> void override { _buffer[_bufferLength] = (uint16_t)sclamp<16>(samples[0] * 32767.0) << 0; _buffer[_bufferLength] |= (uint16_t)sclamp<16>(samples[1] * 32767.0) << 16; if(++_bufferLength < _bufferSize) return; @@ -94,12 +66,12 @@ struct AudioOpenAL : Audio { _queueLength--; } //wait for buffer playback to catch up to sample generation if not synchronizing - if(!_blocking || _queueLength < 3) break; + if(!self.blocking || _queueLength < 3) break; } if(_queueLength < 3) { alGenBuffers(1, &alBuffer); - alBufferData(alBuffer, _format, _buffer, _bufferSize * 4, _frequency); + alBufferData(alBuffer, _format, _buffer, _bufferSize * 4, self.frequency); alSourceQueueBuffers(_source, 1, &alBuffer); _queueLength++; } @@ -114,12 +86,12 @@ private: auto initialize() -> bool { terminate(); - if(!queryDevices().find(_device)) _device = ""; + if(!hasDevices().find(self.device)) self.device = hasDevices().first(); _queueLength = 0; updateLatency(); bool success = false; - if(_openAL = alcOpenDevice(_device)) { + if(_openAL = alcOpenDevice(self.device)) { if(_context = alcCreateContext(_openAL, nullptr)) { alcMakeContextCurrent(_context); alGenSources(1, &_source); @@ -182,12 +154,15 @@ private: _buffer = nullptr; } - auto updateLatency() -> void { + auto updateLatency() -> bool { delete[] _buffer; - _bufferSize = _frequency * _latency / 1000.0 + 0.5; + _bufferSize = self.frequency * self.latency / 1000.0 + 0.5; _buffer = new uint32_t[_bufferSize](); + return true; } + AudioOpenAL& self = *this; + bool _ready = false; ALCdevice* _openAL = nullptr; diff --git a/ruby/audio/oss.cpp b/ruby/audio/oss.cpp index 5e7b2014..508ec458 100644 --- a/ruby/audio/oss.cpp +++ b/ruby/audio/oss.cpp @@ -14,12 +14,10 @@ #endif struct AudioOSS : AudioDriver { - AudioOSS& self; - - AudioOSS(Audio& super) : AudioDriver(super), self(*this) {} + AudioOSS(Audio& super) : AudioDriver(super) {} ~AudioOSS() { terminate(); } - auto create() -> bool { + auto create() -> bool override { super.setDevice("/dev/dsp"); super.setChannels(2); super.setFrequency(48000); @@ -120,6 +118,8 @@ private: return true; } + AudioOSS& self = *this; + int _fd = -1; int _format = AFMT_S16_LE; int _bufferSize = 1; diff --git a/ruby/input/carbon.cpp b/ruby/input/carbon.cpp index 1df09e18..cfcc0a24 100644 --- a/ruby/input/carbon.cpp +++ b/ruby/input/carbon.cpp @@ -1,11 +1,15 @@ #include "keyboard/carbon.cpp" -struct InputCarbon : Input { - InputCarbon() : _keyboard(*this) { initialize(); } +struct InputCarbon : InputDriver { + InputCarbon(Input& super) : InputDriver(super), keyboard(super) {} ~InputCarbon() { terminate(); } + auto create() -> bool override { + return initialize(); + } + auto driver() -> string override { return "Carbon"; } - auto ready() -> bool override { return _ready; } + auto ready() -> bool override { return isReady; } auto acquired() -> bool override { return false; } auto acquire() -> bool override { return false; } @@ -13,7 +17,7 @@ struct InputCarbon : Input { auto poll() -> vector> override { vector> devices; - _keyboard.poll(devices); + keyboard.poll(devices); return devices; } @@ -24,16 +28,16 @@ struct InputCarbon : Input { private: auto initialize() -> bool { terminate(); - if(!_keyboard.initialize()) return false; - return _ready = true; + if(!keyboard.initialize()) return false; + return isReady = true; } auto terminate() -> void { - _ready = false; - _keyboard.terminate(); + isReady = false; + keyboard.terminate(); } - bool _ready = false; - - InputKeyboardCarbon _keyboard; + InputCarbon& self = *this; + bool isReady = false; + InputKeyboardCarbon keyboard; }; diff --git a/ruby/input/quartz.cpp b/ruby/input/quartz.cpp index 6014f127..f7761b55 100644 --- a/ruby/input/quartz.cpp +++ b/ruby/input/quartz.cpp @@ -1,11 +1,15 @@ #include "keyboard/quartz.cpp" -struct InputQuartz : Input { - InputQuartz() : _keyboard(*this) { initialize(); } +struct InputQuartz : InputDriver { + InputQuartz(Input& super) : InputDriver(super), keyboard(super) {} ~InputQuartz() { terminate(); } + auto create() -> bool override { + return initialize(); + } + auto driver() -> string override { return "Quartz"; } - auto ready() -> bool override { return _ready; } + auto ready() -> bool override { return isReady; } auto acquired() -> bool override { return false; } auto acquire() -> bool override { return false; } @@ -13,7 +17,7 @@ struct InputQuartz : Input { auto poll() -> vector> override { vector> devices; - _keyboard.poll(devices); + keyboard.poll(devices); return devices; } @@ -24,16 +28,16 @@ struct InputQuartz : Input { private: auto initialize() -> bool { terminate(); - if(!_keyboard.initialize()) return false; + if(!keyboard.initialize()) return false; return _ready = true; } auto terminate() -> void { - _ready = false; - _keyboard.terminate(); + isReady = false; + keyboard.terminate(); } - bool _ready = false; - - InputKeyboardQuartz _keyboard; + InputQuartz& self = *this; + bool isReady = false; + InputKeyboardQuartz keyboard; }; diff --git a/ruby/input/sdl.cpp b/ruby/input/sdl.cpp index 834493f5..3d03d811 100644 --- a/ruby/input/sdl.cpp +++ b/ruby/input/sdl.cpp @@ -7,12 +7,10 @@ #include "joypad/sdl.cpp" struct InputSDL : InputDriver { - InputSDL& self; - - InputSDL(Input& super) : InputDriver(super), self(*this), keyboard(super), mouse(super), joypad(super) {} + InputSDL(Input& super) : InputDriver(super), keyboard(super), mouse(super), joypad(super) {} ~InputSDL() { terminate(); } - auto create() -> bool { + auto create() -> bool override { return initialize(); } @@ -56,8 +54,8 @@ private: joypad.terminate(); } + InputSDL& self = *this; bool isReady = false; - InputKeyboardXlib keyboard; InputMouseXlib mouse; InputJoypadSDL joypad; diff --git a/ruby/input/udev.cpp b/ruby/input/udev.cpp index 139e3d0f..82d15af9 100644 --- a/ruby/input/udev.cpp +++ b/ruby/input/udev.cpp @@ -12,65 +12,57 @@ #include "mouse/xlib.cpp" #include "joypad/udev.cpp" -struct InputUdev : Input { - InputUdev() : _keyboard(*this), _mouse(*this), _joypad(*this) { initialize(); } +struct InputUdev : InputDriver { + InputUdev(Input& super) : InputDriver(super), keyboard(super), mouse(super), joypad(super) {} ~InputUdev() { terminate(); } - auto driver() -> string override { return "udev"; } - auto ready() -> bool { return _ready; } - - auto hasContext() -> bool override { return true; } - - auto setContext(uintptr context) -> bool override { - if(context == Input::context()) return true; - if(!Input::setContext(context)) return false; + auto create() -> bool override { return initialize(); } - auto acquired() -> bool override { - return _mouse.acquired(); - } + auto driver() -> string override { return "udev"; } + auto ready() -> bool { return isReady; } - auto acquire() -> bool override { - return _mouse.acquire(); - } + auto hasContext() -> bool override { return true; } - auto release() -> bool override { - return _mouse.release(); - } + auto setContext(uintptr context) -> bool override { return initialize(); } + + auto acquired() -> bool override { return mouse.acquired(); } + auto acquire() -> bool override { return mouse.acquire(); } + auto release() -> bool override { return mouse.release(); } auto poll() -> vector> override { vector> devices; - _keyboard.poll(devices); - _mouse.poll(devices); - _joypad.poll(devices); + keyboard.poll(devices); + mouse.poll(devices); + joypad.poll(devices); return devices; } auto rumble(uint64_t id, bool enable) -> bool override { - return _joypad.rumble(id, enable); + return joypad.rumble(id, enable); } private: auto initialize() -> bool { terminate(); - if(!_context) return false; - if(!_keyboard.initialize()) return false; - if(!_mouse.initialize(_context)) return false; - if(!_joypad.initialize()) return false; - return _ready = true; + if(!self.context) return false; + if(!keyboard.initialize()) return false; + if(!mouse.initialize(self.context)) return false; + if(!joypad.initialize()) return false; + return isReady = true; } auto terminate() -> void { - _ready = false; - _keyboard.terminate(); - _mouse.terminate(); - _joypad.terminate(); + isReady = false; + keyboard.terminate(); + mouse.terminate(); + joypad.terminate(); } - bool _ready = false; - - InputKeyboardXlib _keyboard; - InputMouseXlib _mouse; - InputJoypadUdev _joypad; + InputUdev& self = *this; + bool isReady = false; + InputKeyboardXlib keyboard; + InputMouseXlib mouse; + InputJoypadUdev joypad; }; diff --git a/ruby/input/windows.cpp b/ruby/input/windows.cpp index 475270e0..46471479 100644 --- a/ruby/input/windows.cpp +++ b/ruby/input/windows.cpp @@ -8,52 +8,44 @@ #include "joypad/xinput.cpp" #include "joypad/directinput.cpp" -struct InputWindows : Input { - InputWindows() : _keyboard(*this), _mouse(*this), _joypadXInput(*this), _joypadDirectInput(*this) { initialize(); } +struct InputWindows : InputDriver { + InputWindows(Input& driver) : InputDriver(super), keyboard(super), mouse(super), joypadXInput(super), joypadDirectInput(super) {} ~InputWindows() { terminate(); } - auto driver() -> string override { return "Windows"; } - auto ready() -> bool override { return _ready; } - - auto hasContext() -> bool override { return true; } - - auto setContext(uintptr context) -> bool override { - if(context == Input::context()) return true; - if(!Input::setContext(context)) return false; + auto create() -> bool override { return initialize(); } - auto acquired() -> bool override { - return _mouse.acquired(); - } + auto driver() -> string override { return "Windows"; } + auto ready() -> bool override { return isReady; } - auto acquire() -> bool override { - return _mouse.acquire(); - } + auto hasContext() -> bool override { return true; } - auto release() -> bool override { - return _mouse.release(); - } + auto setContext(uintptr context) -> bool override { return initialize(); } + + auto acquired() -> bool override { return mouse.acquired(); } + auto acquire() -> bool override { return mouse.acquire(); } + auto release() -> bool override { return mouse.release(); } auto poll() -> vector> override { vector> devices; - _keyboard.poll(devices); - _mouse.poll(devices); - _joypadXInput.poll(devices); - _joypadDirectInput.poll(devices); + keyboard.poll(devices); + mouse.poll(devices); + joypadXInput.poll(devices); + joypadDirectInput.poll(devices); return devices; } auto rumble(uint64_t id, bool enable) -> bool override { - if(_joypadXInput.rumble(id, enable)) return true; - if(_joypadDirectInput.rumble(id, enable)) return true; + if(joypadXInput.rumble(id, enable)) return true; + if(joypadDirectInput.rumble(id, enable)) return true; return false; } private: auto initialize() -> bool { terminate(); - if(!_context) return false; + if(!self.context) return false; if(!rawinput.initialized) { rawinput.initialized = true; @@ -67,35 +59,35 @@ private: } while(!rawinput.ready); } - DirectInput8Create(GetModuleHandle(0), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&_directInputContext, 0); - if(!_directInputContext) return false; + DirectInput8Create(GetModuleHandle(0), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&directInputContext, 0); + if(!directInputContext) return false; - if(!_keyboard.initialize()) return false; - if(!_mouse.initialize(_context)) return false; + if(!keyboard.initialize()) return false; + if(!mouse.initialize(_context)) return false; bool xinputAvailable = _joypadXInput.initialize(); - if(!_joypadDirectInput.initialize(_context, _directInputContext, xinputAvailable)) return false; - return _ready = true; + if(!joypadDirectInput.initialize(self.context, directInputContext, xinputAvailable)) return false; + return isReady = true; } auto terminate() -> void { - _ready = false; + isReady = false; - _keyboard.terminate(); - _mouse.terminate(); - _joypadXInput.terminate(); - _joypadDirectInput.terminate(); + keyboard.terminate(); + mouse.terminate(); + joypadXInput.terminate(); + joypadDirectInput.terminate(); - if(_directInputContext) { - _directInputContext->Release(); - _directInputContext = nullptr; + if(directInputContext) { + directInputContext->Release(); + directInputContext = nullptr; } } - bool _ready = false; - - InputKeyboardRawInput _keyboard; - InputMouseRawInput _mouse; - InputJoypadXInput _joypadXInput; - InputJoypadDirectInput _joypadDirectInput; - LPDIRECTINPUT8 _directInputContext = nullptr; + InputWindows& self = *this; + bool isReady = false; + InputKeyboardRawInput keyboard; + InputMouseRawInput mouse; + InputJoypadXInput joypadXInput; + InputJoypadDirectInput joypadDirectInput; + LPDIRECTINPUT8 directInputContext = nullptr; }; diff --git a/ruby/input/xlib.cpp b/ruby/input/xlib.cpp index b88d4df9..8f0938fc 100644 --- a/ruby/input/xlib.cpp +++ b/ruby/input/xlib.cpp @@ -7,37 +7,29 @@ #include "keyboard/xlib.cpp" #include "mouse/xlib.cpp" -struct InputXlib : Input { - InputXlib() : _keyboard(*this), _mouse(*this) { initialize(); } +struct InputXlib : InputDriver { + InputXlib(Input& super) : InputDriver(super), keyboard(super), mouse(super) {} ~InputXlib() { terminate(); } - auto driver() -> string override { return "Xlib"; } - auto ready() -> bool override { return _ready; } - - auto hasContext() -> bool override { return true; } - - auto setContext(uintptr context) -> bool override { - if(context == Input::context()) return true; - if(!Input::setContext(context)) return false; + auto create() -> bool override { return initialize(); } - auto acquired() -> bool override { - return _mouse.acquired(); - } + auto driver() -> string override { return "Xlib"; } + auto ready() -> bool override { return isReady; } - auto acquire() -> bool override { - return _mouse.acquire(); - } + auto hasContext() -> bool override { return true; } - auto release() -> bool override { - return _mouse.release(); - } + auto setContext(uintptr context) -> bool override { return initialize(); } + + auto acquired() -> bool override { return mouse.acquired(); } + auto acquire() -> bool override { return mouse.acquire(); } + auto release() -> bool override { return mouse.release(); } auto poll() -> vector> override { vector> devices; - _keyboard.poll(devices); - _mouse.poll(devices); + keyboard.poll(devices); + mouse.poll(devices); return devices; } @@ -48,20 +40,20 @@ struct InputXlib : Input { private: auto initialize() -> bool { terminate(); - if(!_context) return false; - if(!_keyboard.initialize()) return false; - if(!_mouse.initialize(_context)) return false; - return _ready = true; + if(!self.context) return false; + if(!keyboard.initialize()) return false; + if(!mouse.initialize(self.context)) return false; + return isReady = true; } auto terminate() -> void { - _ready = false; - _keyboard.terminate(); - _mouse.terminate(); + isReady = false; + keyboard.terminate(); + mouse.terminate(); } - bool _ready = false; - - InputKeyboardXlib _keyboard; - InputMouseXlib _mouse; + InputXlib& self = *this; + bool isReady = false; + InputKeyboardXlib keyboard; + InputMouseXlib mouse; }; diff --git a/ruby/video/glx2.cpp b/ruby/video/glx2.cpp index cf6a4e86..b09addc7 100644 --- a/ruby/video/glx2.cpp +++ b/ruby/video/glx2.cpp @@ -22,9 +22,7 @@ #endif struct VideoGLX2 : VideoDriver { - VideoGLX2& self; - - VideoGLX2(Video& super) : VideoDriver(super), self(*this) {} + VideoGLX2(Video& super) : VideoDriver(super) {} ~VideoGLX2() { terminate(); } auto create() -> bool { @@ -262,7 +260,7 @@ private: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _glWidth, _glHeight, 0, GL_BGRA, _glFormat, _glBuffer); } - auto (*glXSwapInterval)(int) -> int = nullptr; + VideoGLX2& self = *this; bool _ready = false; @@ -284,4 +282,6 @@ private: uint _glWidth = 0; uint _glHeight = 0; uint _glFormat = GL_UNSIGNED_INT_8_8_8_8_REV; + + auto (*glXSwapInterval)(int) -> int = nullptr; }; diff --git a/ruby/video/xshm.cpp b/ruby/video/xshm.cpp index 4f84890f..bddcd454 100644 --- a/ruby/video/xshm.cpp +++ b/ruby/video/xshm.cpp @@ -9,9 +9,7 @@ #include struct VideoXShm : VideoDriver { - VideoXShm& self; - - VideoXShm(Video& super) : VideoDriver(super), self(*this) {} + VideoXShm(Video& super) : VideoDriver(super) {} ~VideoXShm() { terminate(); } auto create() -> bool { @@ -186,6 +184,8 @@ private: return cr << 16 | cg << 8 | cb << 0; } + VideoXShm& self = *this; + bool _ready = false; uint32_t* _inputBuffer = nullptr;