mirror of https://github.com/bsnes-emu/bsnes.git
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.
This commit is contained in:
parent
2335bb0df8
commit
5d135b556d
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -5,6 +5,10 @@ auto mHorizontalLayout::alignment() const -> maybe<float> {
|
|||
}
|
||||
|
||||
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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -5,6 +5,10 @@ auto mVerticalLayout::alignment() const -> maybe<float> {
|
|||
}
|
||||
|
||||
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());
|
||||
|
|
|
@ -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<pComboButton&> {
|
||||
if(auto parent = self().parentComboButton()) {
|
||||
if(auto self = parent->self()) return *self;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ struct pComboButtonItem : pObject {
|
|||
auto setSelected() -> void;
|
||||
auto setText(const string& text) -> void;
|
||||
|
||||
auto _parent() -> pComboButton*;
|
||||
auto _parent() -> maybe<pComboButton&>;
|
||||
|
||||
GtkTreeIter gtkIter;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include <nall/serializer.hpp>
|
||||
#include <nall/set.hpp>
|
||||
#include <nall/shared-pointer.hpp>
|
||||
#include <nall/simd.hpp>
|
||||
#include <nall/sort.hpp>
|
||||
#include <nall/stdint.hpp>
|
||||
#include <nall/string.hpp>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
namespace nall {
|
||||
|
||||
#if defined(__AVX2__)
|
||||
#define SIMD 256
|
||||
#define SIMD_AVX2
|
||||
#include <immintrin.h>
|
||||
#endif
|
||||
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ struct AudioDriver {
|
|||
virtual auto hasDevices() -> vector<string> { return {"Default"}; }
|
||||
virtual auto hasBlocking() -> bool { return false; }
|
||||
virtual auto hasDynamic() -> bool { return false; }
|
||||
virtual auto hasChannels() -> vector<uint> { return {0}; }
|
||||
virtual auto hasFrequencies() -> vector<uint> { return {0}; }
|
||||
virtual auto hasChannels() -> vector<uint> { return {2}; }
|
||||
virtual auto hasFrequencies() -> vector<uint> { return {48000}; }
|
||||
virtual auto hasLatencies() -> vector<uint> { 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;
|
||||
};
|
||||
|
||||
|
|
|
@ -6,80 +6,52 @@
|
|||
#include <AL/alc.h>
|
||||
#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<string> override {
|
||||
auto hasDevices() -> vector<string> override {
|
||||
vector<string> 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<uint> override {
|
||||
auto hasChannels() -> vector<uint> override {
|
||||
return {2};
|
||||
}
|
||||
|
||||
auto availableFrequencies() -> vector<double> override {
|
||||
return {44100.0, 48000.0, 96000.0};
|
||||
auto hasFrequencies() -> vector<uint> override {
|
||||
return {44100, 48000, 96000};
|
||||
}
|
||||
|
||||
auto availableLatencies() -> vector<uint> override {
|
||||
auto hasLatencies() -> vector<uint> 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<shared_pointer<HID::Device>> override {
|
||||
vector<shared_pointer<HID::Device>> 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;
|
||||
};
|
||||
|
|
|
@ -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<shared_pointer<HID::Device>> override {
|
||||
vector<shared_pointer<HID::Device>> 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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<shared_pointer<HID::Device>> override {
|
||||
vector<shared_pointer<HID::Device>> 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;
|
||||
};
|
||||
|
|
|
@ -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<shared_pointer<HID::Device>> override {
|
||||
vector<shared_pointer<HID::Device>> 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;
|
||||
};
|
||||
|
|
|
@ -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<shared_pointer<HID::Device>> override {
|
||||
vector<shared_pointer<HID::Device>> 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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -9,9 +9,7 @@
|
|||
#include <X11/extensions/XShm.h>
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue