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:
Tim Allen 2018-08-01 19:07:28 +10:00
parent 2335bb0df8
commit 5d135b556d
25 changed files with 231 additions and 228 deletions

View File

@ -147,6 +147,11 @@ auto Presentation::create() -> void {
setFocused(); setFocused();
}); });
iconLayout.setAlignment(0.0);
image icon{Resource::Icon};
icon.alphaBlend(0x000000);
iconCanvas.setIcon(icon);
if(!settings["UserInterface/ShowStatusBar"].boolean()) { if(!settings["UserInterface/ShowStatusBar"].boolean()) {
layout.remove(statusLayout); layout.remove(statusLayout);
} }

View File

@ -103,6 +103,9 @@ struct Presentation : Window {
VerticalLayout layout{this}; VerticalLayout layout{this};
HorizontalLayout viewportLayout{&layout, Size{~0, ~0}, 0}; HorizontalLayout viewportLayout{&layout, Size{~0, ~0}, 0};
Viewport viewport{&viewportLayout, 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}; HorizontalLayout statusLayout{&layout, Size{~0, StatusHeight}, 0};
Label spacerIcon{&statusLayout, Size{8, ~0}, 0}; Label spacerIcon{&statusLayout, Size{8, ~0}, 0};
Canvas statusIcon{&statusLayout, Size{16, ~0}, 0}; Canvas statusIcon{&statusLayout, Size{16, ~0}, 0};

View File

@ -41,6 +41,7 @@ auto Program::load() -> void {
presentation.speedNormal.setChecked(); presentation.speedNormal.setChecked();
presentation.pauseEmulation.setChecked(false); presentation.pauseEmulation.setChecked(false);
presentation.updateStatusIcon(); presentation.updateStatusIcon();
presentation.viewportLayout.remove(presentation.iconLayout);
presentation.resizeViewport(); presentation.resizeViewport();
cheatEditor.loadCheats(); cheatEditor.loadCheats();
stateManager.loadStates(); stateManager.loadStates();
@ -304,6 +305,7 @@ auto Program::unload() -> void {
presentation.toolsMenu.setVisible(false); presentation.toolsMenu.setVisible(false);
presentation.updateStatusIcon(); presentation.updateStatusIcon();
presentation.clearViewport(); 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 //a game is considered verified if the game plus its slot(s) are found in the games database

View File

@ -1,6 +1,10 @@
#if defined(Hiro_FixedLayout) #if defined(Hiro_FixedLayout)
auto mFixedLayout::append(sSizable sizable, Geometry geometry) -> type& { auto mFixedLayout::append(sSizable sizable, Geometry geometry) -> type& {
for(auto& cell : state.cells) {
if(cell->state.sizable == sizable) return *this;
}
FixedLayoutCell cell; FixedLayoutCell cell;
cell->setSizable(sizable); cell->setSizable(sizable);
cell->setGeometry(geometry); cell->setGeometry(geometry);

View File

@ -5,6 +5,10 @@ auto mHorizontalLayout::alignment() const -> maybe<float> {
} }
auto mHorizontalLayout::append(sSizable sizable, Size size, float spacing) -> type& { auto mHorizontalLayout::append(sSizable sizable, Size size, float spacing) -> type& {
for(auto& cell : state.cells) {
if(cell->state.sizable == sizable) return *this;
}
HorizontalLayoutCell cell; HorizontalLayoutCell cell;
cell->setSizable(sizable); cell->setSizable(sizable);
cell->setSize(size); cell->setSize(size);
@ -106,6 +110,7 @@ auto mHorizontalLayout::setFont(const Font& font) -> type& {
auto mHorizontalLayout::setGeometry(Geometry geometry) -> type& { auto mHorizontalLayout::setGeometry(Geometry geometry) -> type& {
mSizable::setGeometry(geometry); mSizable::setGeometry(geometry);
if(!visible(true)) return *this;
geometry.setX(geometry.x() + padding().x()); geometry.setX(geometry.x() + padding().x());
geometry.setY(geometry.y() + padding().y()); geometry.setY(geometry.y() + padding().y());

View File

@ -5,6 +5,10 @@ auto mTableLayout::alignment() const -> Alignment {
} }
auto mTableLayout::append(sSizable sizable, Size size) -> type& { auto mTableLayout::append(sSizable sizable, Size size) -> type& {
for(auto& cell : state.cells) {
if(cell->state.sizable == sizable) return *this;
}
TableLayoutCell cell; TableLayoutCell cell;
cell->setSizable(sizable); cell->setSizable(sizable);
cell->setSize(size); cell->setSize(size);
@ -141,6 +145,7 @@ auto mTableLayout::setFont(const Font& font) -> type& {
auto mTableLayout::setGeometry(Geometry geometry) -> type& { auto mTableLayout::setGeometry(Geometry geometry) -> type& {
mSizable::setGeometry(geometry); mSizable::setGeometry(geometry);
if(!visible(true)) return *this;
geometry.setX(geometry.x() + padding().x()); geometry.setX(geometry.x() + padding().x());
geometry.setY(geometry.y() + padding().y()); geometry.setY(geometry.y() + padding().y());

View File

@ -5,6 +5,10 @@ auto mVerticalLayout::alignment() const -> maybe<float> {
} }
auto mVerticalLayout::append(sSizable sizable, Size size, float spacing) -> type& { auto mVerticalLayout::append(sSizable sizable, Size size, float spacing) -> type& {
for(auto& cell : state.cells) {
if(cell->state.sizable == sizable) return *this;
}
VerticalLayoutCell cell; VerticalLayoutCell cell;
cell->setSizable(sizable); cell->setSizable(sizable);
cell->setSize(size); cell->setSize(size);
@ -106,6 +110,7 @@ auto mVerticalLayout::setFont(const Font& font) -> type& {
auto mVerticalLayout::setGeometry(Geometry geometry) -> type& { auto mVerticalLayout::setGeometry(Geometry geometry) -> type& {
mSizable::setGeometry(geometry); mSizable::setGeometry(geometry);
if(!visible(true)) return *this;
geometry.setX(geometry.x() + padding().x()); geometry.setX(geometry.x() + padding().x());
geometry.setY(geometry.y() + padding().y()); geometry.setY(geometry.y() + padding().y());

View File

@ -3,6 +3,7 @@
namespace hiro { namespace hiro {
auto pComboButtonItem::construct() -> void { auto pComboButtonItem::construct() -> void {
if(auto parent = _parent()) parent->_append(self());
} }
auto pComboButtonItem::destruct() -> void { auto pComboButtonItem::destruct() -> void {
@ -29,9 +30,11 @@ auto pComboButtonItem::setText(const string& text) -> void {
} }
} }
auto pComboButtonItem::_parent() -> pComboButton* { auto pComboButtonItem::_parent() -> maybe<pComboButton&> {
if(auto parent = self().parentComboButton()) return parent->self(); if(auto parent = self().parentComboButton()) {
return nullptr; if(auto self = parent->self()) return *self;
}
return {};
} }
} }

View File

@ -9,7 +9,7 @@ struct pComboButtonItem : pObject {
auto setSelected() -> void; auto setSelected() -> void;
auto setText(const string& text) -> void; auto setText(const string& text) -> void;
auto _parent() -> pComboButton*; auto _parent() -> maybe<pComboButton&>;
GtkTreeIter gtkIter; GtkTreeIter gtkIter;
}; };

View File

@ -17,8 +17,6 @@ auto pComboButton::construct() -> void {
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(gtkWidget), gtkCellText, true); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(gtkWidget), gtkCellText, true);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(gtkWidget), gtkCellText, "text", 1, nullptr); 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); g_signal_connect(G_OBJECT(gtkWidget), "changed", G_CALLBACK(ComboButton_change), (gpointer)this);
pWidget::construct(); pWidget::construct();
@ -29,15 +27,6 @@ auto pComboButton::destruct() -> void {
} }
auto pComboButton::append(sComboButtonItem item) -> 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 { 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); 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 { auto pComboButton::_updateSelected() -> void {
for(auto& item : state().items) item->state.selected = false; for(auto& item : state().items) item->state.selected = false;
signed selected = gtk_combo_box_get_active(gtkComboBox); signed selected = gtk_combo_box_get_active(gtkComboBox);

View File

@ -11,6 +11,7 @@ struct pComboButton : pWidget {
auto reset() -> void; auto reset() -> void;
auto setFont(const Font& font) -> void override; auto setFont(const Font& font) -> void override;
auto _append(sComboButtonItem item) -> void;
auto _updateSelected() -> void; auto _updateSelected() -> void;
GtkListStore* gtkListStore = nullptr; GtkListStore* gtkListStore = nullptr;

View File

@ -52,6 +52,7 @@
#include <nall/serializer.hpp> #include <nall/serializer.hpp>
#include <nall/set.hpp> #include <nall/set.hpp>
#include <nall/shared-pointer.hpp> #include <nall/shared-pointer.hpp>
#include <nall/simd.hpp>
#include <nall/sort.hpp> #include <nall/sort.hpp>
#include <nall/stdint.hpp> #include <nall/stdint.hpp>
#include <nall/string.hpp> #include <nall/string.hpp>

11
nall/simd.hpp Normal file
View File

@ -0,0 +1,11 @@
#pragma once
namespace nall {
#if defined(__AVX2__)
#define SIMD 256
#define SIMD_AVX2
#include <immintrin.h>
#endif
}

View File

@ -14,8 +14,8 @@ ifeq ($(ruby),)
else ifeq ($(platform),bsd) else ifeq ($(platform),bsd)
# ruby += video.glx video.glx2 video.xvideo video.xshm # ruby += video.glx video.glx2 video.xvideo video.xshm
ruby += video.glx2 video.xshm ruby += video.glx2 video.xshm
ruby += audio.oss #audio.openal ruby += audio.oss audio.openal
ruby += input.sdl #input.xlib ruby += input.sdl input.xlib
endif endif
endif endif

View File

@ -13,8 +13,8 @@ struct AudioDriver {
virtual auto hasDevices() -> vector<string> { return {"Default"}; } virtual auto hasDevices() -> vector<string> { return {"Default"}; }
virtual auto hasBlocking() -> bool { return false; } virtual auto hasBlocking() -> bool { return false; }
virtual auto hasDynamic() -> bool { return false; } virtual auto hasDynamic() -> bool { return false; }
virtual auto hasChannels() -> vector<uint> { return {0}; } virtual auto hasChannels() -> vector<uint> { return {2}; }
virtual auto hasFrequencies() -> vector<uint> { return {0}; } virtual auto hasFrequencies() -> vector<uint> { return {48000}; }
virtual auto hasLatencies() -> vector<uint> { return {0}; } virtual auto hasLatencies() -> vector<uint> { return {0}; }
auto hasDevice(string device) -> bool { return (bool)hasDevices().find(device); } auto hasDevice(string device) -> bool { return (bool)hasDevices().find(device); }
@ -44,8 +44,8 @@ protected:
string device = "Default"; string device = "Default";
bool blocking = false; bool blocking = false;
bool dynamic = false; bool dynamic = false;
uint channels = 0; uint channels = 2;
uint frequency = 0; uint frequency = 48000;
uint latency = 0; uint latency = 0;
}; };

View File

@ -6,80 +6,52 @@
#include <AL/alc.h> #include <AL/alc.h>
#endif #endif
struct AudioOpenAL : Audio { struct AudioOpenAL : AudioDriver {
AudioOpenAL() { AudioOpenAL(Audio& driver) : AudioDriver(super) {}
Audio::setDevice(availableDevices().first()); ~AudioOpenAL() { terminate(); }
Audio::setChannels(2);
Audio::setFrequency(48000.0);
Audio::setLatency(20);
initialize();
}
~AudioOpenAL() { auto create() -> bool override {
terminate(); super.setDevice(hasDevices().first());
super.setChannels(2);
super.setFrequency(48000);
super.setLatency(20);
return initialize();
} }
auto driver() -> string override { return "OpenAL"; } auto driver() -> string override { return "OpenAL"; }
auto ready() -> bool override { return _ready; } auto ready() -> bool override { return _ready; }
auto hasDevice() -> bool override { return true; }
auto hasBlocking() -> 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; vector<string> devices;
if(const char* list = alcGetString(nullptr, ALC_DEVICE_SPECIFIER)) { if(const char* list = alcGetString(nullptr, ALC_DEVICE_SPECIFIER)) {
while(list && *list) { while(list && *list) {
result.append(list); devices.append(list);
list += strlen(list) + 1; list += strlen(list) + 1;
} }
} }
return devices; return devices;
} }
auto availableChannels() -> vector<uint> override { auto hasChannels() -> vector<uint> override {
return {2}; return {2};
} }
auto availableFrequencies() -> vector<double> override { auto hasFrequencies() -> vector<uint> override {
return {44100.0, 48000.0, 96000.0}; return {44100, 48000, 96000};
} }
auto availableLatencies() -> vector<uint> override { auto hasLatencies() -> vector<uint> override {
return {20, 40, 60, 80, 100}; return {20, 40, 60, 80, 100};
} }
auto context() -> uintptr override { return 0; } auto setDevice(string device) -> bool override { return initialize(); }
auto dynamic() -> bool override { return false; } 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 { auto output(const double samples[]) -> void 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 {
_buffer[_bufferLength] = (uint16_t)sclamp<16>(samples[0] * 32767.0) << 0; _buffer[_bufferLength] = (uint16_t)sclamp<16>(samples[0] * 32767.0) << 0;
_buffer[_bufferLength] |= (uint16_t)sclamp<16>(samples[1] * 32767.0) << 16; _buffer[_bufferLength] |= (uint16_t)sclamp<16>(samples[1] * 32767.0) << 16;
if(++_bufferLength < _bufferSize) return; if(++_bufferLength < _bufferSize) return;
@ -94,12 +66,12 @@ struct AudioOpenAL : Audio {
_queueLength--; _queueLength--;
} }
//wait for buffer playback to catch up to sample generation if not synchronizing //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) { if(_queueLength < 3) {
alGenBuffers(1, &alBuffer); alGenBuffers(1, &alBuffer);
alBufferData(alBuffer, _format, _buffer, _bufferSize * 4, _frequency); alBufferData(alBuffer, _format, _buffer, _bufferSize * 4, self.frequency);
alSourceQueueBuffers(_source, 1, &alBuffer); alSourceQueueBuffers(_source, 1, &alBuffer);
_queueLength++; _queueLength++;
} }
@ -114,12 +86,12 @@ private:
auto initialize() -> bool { auto initialize() -> bool {
terminate(); terminate();
if(!queryDevices().find(_device)) _device = ""; if(!hasDevices().find(self.device)) self.device = hasDevices().first();
_queueLength = 0; _queueLength = 0;
updateLatency(); updateLatency();
bool success = false; bool success = false;
if(_openAL = alcOpenDevice(_device)) { if(_openAL = alcOpenDevice(self.device)) {
if(_context = alcCreateContext(_openAL, nullptr)) { if(_context = alcCreateContext(_openAL, nullptr)) {
alcMakeContextCurrent(_context); alcMakeContextCurrent(_context);
alGenSources(1, &_source); alGenSources(1, &_source);
@ -182,12 +154,15 @@ private:
_buffer = nullptr; _buffer = nullptr;
} }
auto updateLatency() -> void { auto updateLatency() -> bool {
delete[] _buffer; delete[] _buffer;
_bufferSize = _frequency * _latency / 1000.0 + 0.5; _bufferSize = self.frequency * self.latency / 1000.0 + 0.5;
_buffer = new uint32_t[_bufferSize](); _buffer = new uint32_t[_bufferSize]();
return true;
} }
AudioOpenAL& self = *this;
bool _ready = false; bool _ready = false;
ALCdevice* _openAL = nullptr; ALCdevice* _openAL = nullptr;

View File

@ -14,12 +14,10 @@
#endif #endif
struct AudioOSS : AudioDriver { struct AudioOSS : AudioDriver {
AudioOSS& self; AudioOSS(Audio& super) : AudioDriver(super) {}
AudioOSS(Audio& super) : AudioDriver(super), self(*this) {}
~AudioOSS() { terminate(); } ~AudioOSS() { terminate(); }
auto create() -> bool { auto create() -> bool override {
super.setDevice("/dev/dsp"); super.setDevice("/dev/dsp");
super.setChannels(2); super.setChannels(2);
super.setFrequency(48000); super.setFrequency(48000);
@ -120,6 +118,8 @@ private:
return true; return true;
} }
AudioOSS& self = *this;
int _fd = -1; int _fd = -1;
int _format = AFMT_S16_LE; int _format = AFMT_S16_LE;
int _bufferSize = 1; int _bufferSize = 1;

View File

@ -1,11 +1,15 @@
#include "keyboard/carbon.cpp" #include "keyboard/carbon.cpp"
struct InputCarbon : Input { struct InputCarbon : InputDriver {
InputCarbon() : _keyboard(*this) { initialize(); } InputCarbon(Input& super) : InputDriver(super), keyboard(super) {}
~InputCarbon() { terminate(); } ~InputCarbon() { terminate(); }
auto create() -> bool override {
return initialize();
}
auto driver() -> string override { return "Carbon"; } 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 acquired() -> bool override { return false; }
auto acquire() -> 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 { auto poll() -> vector<shared_pointer<HID::Device>> override {
vector<shared_pointer<HID::Device>> devices; vector<shared_pointer<HID::Device>> devices;
_keyboard.poll(devices); keyboard.poll(devices);
return devices; return devices;
} }
@ -24,16 +28,16 @@ struct InputCarbon : Input {
private: private:
auto initialize() -> bool { auto initialize() -> bool {
terminate(); terminate();
if(!_keyboard.initialize()) return false; if(!keyboard.initialize()) return false;
return _ready = true; return isReady = true;
} }
auto terminate() -> void { auto terminate() -> void {
_ready = false; isReady = false;
_keyboard.terminate(); keyboard.terminate();
} }
bool _ready = false; InputCarbon& self = *this;
bool isReady = false;
InputKeyboardCarbon _keyboard; InputKeyboardCarbon keyboard;
}; };

View File

@ -1,11 +1,15 @@
#include "keyboard/quartz.cpp" #include "keyboard/quartz.cpp"
struct InputQuartz : Input { struct InputQuartz : InputDriver {
InputQuartz() : _keyboard(*this) { initialize(); } InputQuartz(Input& super) : InputDriver(super), keyboard(super) {}
~InputQuartz() { terminate(); } ~InputQuartz() { terminate(); }
auto create() -> bool override {
return initialize();
}
auto driver() -> string override { return "Quartz"; } 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 acquired() -> bool override { return false; }
auto acquire() -> 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 { auto poll() -> vector<shared_pointer<HID::Device>> override {
vector<shared_pointer<HID::Device>> devices; vector<shared_pointer<HID::Device>> devices;
_keyboard.poll(devices); keyboard.poll(devices);
return devices; return devices;
} }
@ -24,16 +28,16 @@ struct InputQuartz : Input {
private: private:
auto initialize() -> bool { auto initialize() -> bool {
terminate(); terminate();
if(!_keyboard.initialize()) return false; if(!keyboard.initialize()) return false;
return _ready = true; return _ready = true;
} }
auto terminate() -> void { auto terminate() -> void {
_ready = false; isReady = false;
_keyboard.terminate(); keyboard.terminate();
} }
bool _ready = false; InputQuartz& self = *this;
bool isReady = false;
InputKeyboardQuartz _keyboard; InputKeyboardQuartz keyboard;
}; };

View File

@ -7,12 +7,10 @@
#include "joypad/sdl.cpp" #include "joypad/sdl.cpp"
struct InputSDL : InputDriver { struct InputSDL : InputDriver {
InputSDL& self; InputSDL(Input& super) : InputDriver(super), keyboard(super), mouse(super), joypad(super) {}
InputSDL(Input& super) : InputDriver(super), self(*this), keyboard(super), mouse(super), joypad(super) {}
~InputSDL() { terminate(); } ~InputSDL() { terminate(); }
auto create() -> bool { auto create() -> bool override {
return initialize(); return initialize();
} }
@ -56,8 +54,8 @@ private:
joypad.terminate(); joypad.terminate();
} }
InputSDL& self = *this;
bool isReady = false; bool isReady = false;
InputKeyboardXlib keyboard; InputKeyboardXlib keyboard;
InputMouseXlib mouse; InputMouseXlib mouse;
InputJoypadSDL joypad; InputJoypadSDL joypad;

View File

@ -12,65 +12,57 @@
#include "mouse/xlib.cpp" #include "mouse/xlib.cpp"
#include "joypad/udev.cpp" #include "joypad/udev.cpp"
struct InputUdev : Input { struct InputUdev : InputDriver {
InputUdev() : _keyboard(*this), _mouse(*this), _joypad(*this) { initialize(); } InputUdev(Input& super) : InputDriver(super), keyboard(super), mouse(super), joypad(super) {}
~InputUdev() { terminate(); } ~InputUdev() { terminate(); }
auto driver() -> string override { return "udev"; } auto create() -> bool override {
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;
return initialize(); return initialize();
} }
auto acquired() -> bool override { auto driver() -> string override { return "udev"; }
return _mouse.acquired(); auto ready() -> bool { return isReady; }
}
auto acquire() -> bool override { auto hasContext() -> bool override { return true; }
return _mouse.acquire();
}
auto release() -> bool override { auto setContext(uintptr context) -> bool override { return initialize(); }
return _mouse.release();
} 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 { auto poll() -> vector<shared_pointer<HID::Device>> override {
vector<shared_pointer<HID::Device>> devices; vector<shared_pointer<HID::Device>> devices;
_keyboard.poll(devices); keyboard.poll(devices);
_mouse.poll(devices); mouse.poll(devices);
_joypad.poll(devices); joypad.poll(devices);
return devices; return devices;
} }
auto rumble(uint64_t id, bool enable) -> bool override { auto rumble(uint64_t id, bool enable) -> bool override {
return _joypad.rumble(id, enable); return joypad.rumble(id, enable);
} }
private: private:
auto initialize() -> bool { auto initialize() -> bool {
terminate(); terminate();
if(!_context) return false; if(!self.context) return false;
if(!_keyboard.initialize()) return false; if(!keyboard.initialize()) return false;
if(!_mouse.initialize(_context)) return false; if(!mouse.initialize(self.context)) return false;
if(!_joypad.initialize()) return false; if(!joypad.initialize()) return false;
return _ready = true; return isReady = true;
} }
auto terminate() -> void { auto terminate() -> void {
_ready = false; isReady = false;
_keyboard.terminate(); keyboard.terminate();
_mouse.terminate(); mouse.terminate();
_joypad.terminate(); joypad.terminate();
} }
bool _ready = false; InputUdev& self = *this;
bool isReady = false;
InputKeyboardXlib _keyboard; InputKeyboardXlib keyboard;
InputMouseXlib _mouse; InputMouseXlib mouse;
InputJoypadUdev _joypad; InputJoypadUdev joypad;
}; };

View File

@ -8,52 +8,44 @@
#include "joypad/xinput.cpp" #include "joypad/xinput.cpp"
#include "joypad/directinput.cpp" #include "joypad/directinput.cpp"
struct InputWindows : Input { struct InputWindows : InputDriver {
InputWindows() : _keyboard(*this), _mouse(*this), _joypadXInput(*this), _joypadDirectInput(*this) { initialize(); } InputWindows(Input& driver) : InputDriver(super), keyboard(super), mouse(super), joypadXInput(super), joypadDirectInput(super) {}
~InputWindows() { terminate(); } ~InputWindows() { terminate(); }
auto driver() -> string override { return "Windows"; } auto create() -> bool override {
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;
return initialize(); return initialize();
} }
auto acquired() -> bool override { auto driver() -> string override { return "Windows"; }
return _mouse.acquired(); auto ready() -> bool override { return isReady; }
}
auto acquire() -> bool override { auto hasContext() -> bool override { return true; }
return _mouse.acquire();
}
auto release() -> bool override { auto setContext(uintptr context) -> bool override { return initialize(); }
return _mouse.release();
} 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 { auto poll() -> vector<shared_pointer<HID::Device>> override {
vector<shared_pointer<HID::Device>> devices; vector<shared_pointer<HID::Device>> devices;
_keyboard.poll(devices); keyboard.poll(devices);
_mouse.poll(devices); mouse.poll(devices);
_joypadXInput.poll(devices); joypadXInput.poll(devices);
_joypadDirectInput.poll(devices); joypadDirectInput.poll(devices);
return devices; return devices;
} }
auto rumble(uint64_t id, bool enable) -> bool override { auto rumble(uint64_t id, bool enable) -> bool override {
if(_joypadXInput.rumble(id, enable)) return true; if(joypadXInput.rumble(id, enable)) return true;
if(_joypadDirectInput.rumble(id, enable)) return true; if(joypadDirectInput.rumble(id, enable)) return true;
return false; return false;
} }
private: private:
auto initialize() -> bool { auto initialize() -> bool {
terminate(); terminate();
if(!_context) return false; if(!self.context) return false;
if(!rawinput.initialized) { if(!rawinput.initialized) {
rawinput.initialized = true; rawinput.initialized = true;
@ -67,35 +59,35 @@ private:
} while(!rawinput.ready); } while(!rawinput.ready);
} }
DirectInput8Create(GetModuleHandle(0), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&_directInputContext, 0); DirectInput8Create(GetModuleHandle(0), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&directInputContext, 0);
if(!_directInputContext) return false; if(!directInputContext) return false;
if(!_keyboard.initialize()) return false; if(!keyboard.initialize()) return false;
if(!_mouse.initialize(_context)) return false; if(!mouse.initialize(_context)) return false;
bool xinputAvailable = _joypadXInput.initialize(); bool xinputAvailable = _joypadXInput.initialize();
if(!_joypadDirectInput.initialize(_context, _directInputContext, xinputAvailable)) return false; if(!joypadDirectInput.initialize(self.context, directInputContext, xinputAvailable)) return false;
return _ready = true; return isReady = true;
} }
auto terminate() -> void { auto terminate() -> void {
_ready = false; isReady = false;
_keyboard.terminate(); keyboard.terminate();
_mouse.terminate(); mouse.terminate();
_joypadXInput.terminate(); joypadXInput.terminate();
_joypadDirectInput.terminate(); joypadDirectInput.terminate();
if(_directInputContext) { if(directInputContext) {
_directInputContext->Release(); directInputContext->Release();
_directInputContext = nullptr; directInputContext = nullptr;
} }
} }
bool _ready = false; InputWindows& self = *this;
bool isReady = false;
InputKeyboardRawInput _keyboard; InputKeyboardRawInput keyboard;
InputMouseRawInput _mouse; InputMouseRawInput mouse;
InputJoypadXInput _joypadXInput; InputJoypadXInput joypadXInput;
InputJoypadDirectInput _joypadDirectInput; InputJoypadDirectInput joypadDirectInput;
LPDIRECTINPUT8 _directInputContext = nullptr; LPDIRECTINPUT8 directInputContext = nullptr;
}; };

View File

@ -7,37 +7,29 @@
#include "keyboard/xlib.cpp" #include "keyboard/xlib.cpp"
#include "mouse/xlib.cpp" #include "mouse/xlib.cpp"
struct InputXlib : Input { struct InputXlib : InputDriver {
InputXlib() : _keyboard(*this), _mouse(*this) { initialize(); } InputXlib(Input& super) : InputDriver(super), keyboard(super), mouse(super) {}
~InputXlib() { terminate(); } ~InputXlib() { terminate(); }
auto driver() -> string override { return "Xlib"; } auto create() -> bool override {
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;
return initialize(); return initialize();
} }
auto acquired() -> bool override { auto driver() -> string override { return "Xlib"; }
return _mouse.acquired(); auto ready() -> bool override { return isReady; }
}
auto acquire() -> bool override { auto hasContext() -> bool override { return true; }
return _mouse.acquire();
}
auto release() -> bool override { auto setContext(uintptr context) -> bool override { return initialize(); }
return _mouse.release();
} 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 { auto poll() -> vector<shared_pointer<HID::Device>> override {
vector<shared_pointer<HID::Device>> devices; vector<shared_pointer<HID::Device>> devices;
_keyboard.poll(devices); keyboard.poll(devices);
_mouse.poll(devices); mouse.poll(devices);
return devices; return devices;
} }
@ -48,20 +40,20 @@ struct InputXlib : Input {
private: private:
auto initialize() -> bool { auto initialize() -> bool {
terminate(); terminate();
if(!_context) return false; if(!self.context) return false;
if(!_keyboard.initialize()) return false; if(!keyboard.initialize()) return false;
if(!_mouse.initialize(_context)) return false; if(!mouse.initialize(self.context)) return false;
return _ready = true; return isReady = true;
} }
auto terminate() -> void { auto terminate() -> void {
_ready = false; isReady = false;
_keyboard.terminate(); keyboard.terminate();
_mouse.terminate(); mouse.terminate();
} }
bool _ready = false; InputXlib& self = *this;
bool isReady = false;
InputKeyboardXlib _keyboard; InputKeyboardXlib keyboard;
InputMouseXlib _mouse; InputMouseXlib mouse;
}; };

View File

@ -22,9 +22,7 @@
#endif #endif
struct VideoGLX2 : VideoDriver { struct VideoGLX2 : VideoDriver {
VideoGLX2& self; VideoGLX2(Video& super) : VideoDriver(super) {}
VideoGLX2(Video& super) : VideoDriver(super), self(*this) {}
~VideoGLX2() { terminate(); } ~VideoGLX2() { terminate(); }
auto create() -> bool { auto create() -> bool {
@ -262,7 +260,7 @@ private:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _glWidth, _glHeight, 0, GL_BGRA, _glFormat, _glBuffer); 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; bool _ready = false;
@ -284,4 +282,6 @@ private:
uint _glWidth = 0; uint _glWidth = 0;
uint _glHeight = 0; uint _glHeight = 0;
uint _glFormat = GL_UNSIGNED_INT_8_8_8_8_REV; uint _glFormat = GL_UNSIGNED_INT_8_8_8_8_REV;
auto (*glXSwapInterval)(int) -> int = nullptr;
}; };

View File

@ -9,9 +9,7 @@
#include <X11/extensions/XShm.h> #include <X11/extensions/XShm.h>
struct VideoXShm : VideoDriver { struct VideoXShm : VideoDriver {
VideoXShm& self; VideoXShm(Video& super) : VideoDriver(super) {}
VideoXShm(Video& super) : VideoDriver(super), self(*this) {}
~VideoXShm() { terminate(); } ~VideoXShm() { terminate(); }
auto create() -> bool { auto create() -> bool {
@ -186,6 +184,8 @@ private:
return cr << 16 | cg << 8 | cb << 0; return cr << 16 | cg << 8 | cb << 0;
} }
VideoXShm& self = *this;
bool _ready = false; bool _ready = false;
uint32_t* _inputBuffer = nullptr; uint32_t* _inputBuffer = nullptr;