mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-12-22 16:18:50 -05:00
LUS Cleanup: Make ControlDeck a member of Window
This commit is contained in:
parent
d9443d98f0
commit
b3c3882b12
@ -152,3 +152,19 @@ void Ship::ControlDeck::SaveControllerSettings() {
|
||||
|
||||
Config->save();
|
||||
}
|
||||
|
||||
std::shared_ptr<Ship::Controller> Ship::ControlDeck::GetPhysicalDevice(int deviceSlot) {
|
||||
return physicalDevices[deviceSlot];
|
||||
}
|
||||
|
||||
size_t Ship::ControlDeck::GetNumPhysicalDevices() {
|
||||
return physicalDevices.size();
|
||||
}
|
||||
|
||||
int Ship::ControlDeck::GetVirtualDevice(int slot) {
|
||||
return virtualDevices[slot];
|
||||
}
|
||||
|
||||
size_t Ship::ControlDeck::GetNumVirtualDevices() {
|
||||
return virtualDevices.size();
|
||||
}
|
@ -8,13 +8,18 @@ namespace Ship {
|
||||
|
||||
class ControlDeck {
|
||||
public:
|
||||
std::vector<int> virtualDevices;
|
||||
std::vector<std::shared_ptr<Controller>> physicalDevices = {};
|
||||
void Init(uint8_t* controllerBits);
|
||||
void ScanPhysicalDevices();
|
||||
void WriteToPad(OSContPad* pad) const;
|
||||
void LoadControllerSettings();
|
||||
void SaveControllerSettings();
|
||||
void SetPhysicalDevice(int slot, int deviceSlot);
|
||||
std::shared_ptr<Ship::Controller> GetPhysicalDevice(int deviceSlot);
|
||||
size_t GetNumPhysicalDevices();
|
||||
int GetVirtualDevice(int slot);
|
||||
size_t GetNumVirtualDevices();
|
||||
private:
|
||||
std::vector<int> virtualDevices;
|
||||
std::vector<std::shared_ptr<Controller>> physicalDevices = {};
|
||||
};
|
||||
}
|
||||
|
@ -792,7 +792,7 @@ namespace SohImGui {
|
||||
bool menu_bar = CVar_GetS32("gOpenMenuBar", 0);
|
||||
CVar_SetS32("gOpenMenuBar", !menu_bar);
|
||||
needs_save = true;
|
||||
GlobalCtx2::GetInstance()->GetWindow()->dwMenubar = menu_bar;
|
||||
GlobalCtx2::GetInstance()->GetWindow()->SetMenuBar(menu_bar);
|
||||
ShowCursor(menu_bar, Dialogues::dMenubar);
|
||||
GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck()->SaveControllerSettings();
|
||||
if (CVar_GetS32("gControlNav", 0)) {
|
||||
|
@ -16,8 +16,8 @@ namespace Ship {
|
||||
}
|
||||
|
||||
std::shared_ptr<Controller> GetControllerPerSlot(int slot) {
|
||||
const std::vector<int> vDevices = Window::ControllerApi->virtualDevices;
|
||||
return Window::ControllerApi->physicalDevices[vDevices[slot]];
|
||||
auto controlDeck = Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
|
||||
return controlDeck->GetPhysicalDevice(controlDeck->GetVirtualDevice(slot));
|
||||
}
|
||||
|
||||
void InputEditor::DrawButton(const char* label, int n64Btn) {
|
||||
@ -82,20 +82,17 @@ namespace Ship {
|
||||
}
|
||||
|
||||
void InputEditor::DrawControllerSchema() {
|
||||
|
||||
const std::vector<int> vDevices = Window::ControllerApi->virtualDevices;
|
||||
const std::vector<std::shared_ptr<Controller>> devices = Window::ControllerApi->physicalDevices;
|
||||
|
||||
std::shared_ptr<Controller> Backend = devices[vDevices[CurrentPort]];
|
||||
DeviceProfile& profile =Backend->profiles[CurrentPort];
|
||||
auto controlDeck = Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
|
||||
auto Backend = controlDeck->GetPhysicalDevice(controlDeck->GetVirtualDevice(CurrentPort));
|
||||
DeviceProfile& profile = Backend->profiles[CurrentPort];
|
||||
float sensitivity = profile.Thresholds[SENSITIVITY];
|
||||
bool IsKeyboard = Backend->GetGuid() == "Keyboard" || Backend->GetGuid() == "Auto" || !Backend->Connected();
|
||||
const char* ControllerName = Backend->GetControllerName();
|
||||
|
||||
if (ControllerName != nullptr && ImGui::BeginCombo("##ControllerEntries", ControllerName)) {
|
||||
for (uint8_t i = 0; i < devices.size(); i++) {
|
||||
if (ImGui::Selectable(devices[i]->GetControllerName(), i == vDevices[CurrentPort])) {
|
||||
Window::ControllerApi->SetPhysicalDevice(CurrentPort, i);
|
||||
for (uint8_t i = 0; i < controlDeck->GetNumPhysicalDevices(); i++) {
|
||||
if (ImGui::Selectable(controlDeck->GetPhysicalDevice(i)->GetControllerName(), i == controlDeck->GetVirtualDevice(CurrentPort))) {
|
||||
controlDeck->SetPhysicalDevice(CurrentPort, i);
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
@ -104,7 +101,7 @@ namespace Ship {
|
||||
ImGui::SameLine();
|
||||
|
||||
if(ImGui::Button("Refresh")) {
|
||||
Window::ControllerApi->ScanPhysicalDevices();
|
||||
controlDeck->ScanPhysicalDevices();
|
||||
}
|
||||
|
||||
SohImGui::BeginGroupPanel("Buttons", ImVec2(150, 20));
|
||||
|
@ -57,7 +57,7 @@ extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
Ship::Window::ControllerApi->Init(controllerBits);
|
||||
Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck()->Init(controllerBits);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -77,7 +77,7 @@ extern "C" {
|
||||
pad->gyro_y = 0;
|
||||
|
||||
if (!CVar_GetS32("gOpenMenuBar", 0)) {
|
||||
Ship::Window::ControllerApi->WriteToPad(pad);
|
||||
Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck()->WriteToPad(pad);
|
||||
}
|
||||
|
||||
ModInternal::ExecuteHooks<ModInternal::ControllerRead>(pad);
|
||||
@ -221,7 +221,7 @@ namespace Ship {
|
||||
|
||||
int32_t Window::lastScancode;
|
||||
|
||||
Window::Window(std::shared_ptr<GlobalCtx2> Context) : Context(Context), APlayer(nullptr) {
|
||||
Window::Window(std::shared_ptr<GlobalCtx2> Context) : Context(Context), APlayer(nullptr), ControllerApi(nullptr) {
|
||||
WmApi = nullptr;
|
||||
RenderingApi = nullptr;
|
||||
bIsFullscreen = false;
|
||||
@ -259,8 +259,9 @@ namespace Ship {
|
||||
std::shared_ptr<Mercury> pConf = GlobalCtx2::GetInstance()->GetConfig();
|
||||
|
||||
CreateDefaults();
|
||||
InitializeAudioPlayer();
|
||||
InitializeControlDeck();
|
||||
|
||||
SetAudioPlayer();
|
||||
bIsFullscreen = pConf->getBool("Window.Fullscreen.Enabled", false);
|
||||
|
||||
if (bIsFullscreen) {
|
||||
@ -279,7 +280,7 @@ namespace Ship {
|
||||
WmApi->set_fullscreen_changed_callback(OnFullscreenChanged);
|
||||
WmApi->set_keyboard_callbacks(KeyDown, KeyUp, AllKeysUp);
|
||||
|
||||
ModInternal::RegisterHook<ModInternal::ExitGame>([]() {
|
||||
ModInternal::RegisterHook<ModInternal::ExitGame>([this]() {
|
||||
ControllerApi->SaveControllerSettings();
|
||||
});
|
||||
}
|
||||
@ -347,8 +348,9 @@ namespace Ship {
|
||||
lastScancode = -1;
|
||||
|
||||
bool bIsProcessed = false;
|
||||
const auto pad = dynamic_cast<KeyboardController*>(ControllerApi->physicalDevices[ControllerApi->physicalDevices.size() - 2].get());
|
||||
if (pad != nullptr) {
|
||||
auto controlDeck = GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
|
||||
const auto pad = dynamic_cast<KeyboardController*>(controlDeck->GetPhysicalDevice(controlDeck->GetNumPhysicalDevices() - 2).get());
|
||||
if (pad != nullptr) {
|
||||
if (pad->ReleaseButton(dwScancode)) {
|
||||
bIsProcessed = true;
|
||||
}
|
||||
@ -359,9 +361,9 @@ namespace Ship {
|
||||
|
||||
bool Window::KeyDown(int32_t dwScancode) {
|
||||
bool bIsProcessed = false;
|
||||
|
||||
const auto pad = dynamic_cast<KeyboardController*>(ControllerApi->physicalDevices[ControllerApi->physicalDevices.size() - 2].get());
|
||||
if (pad != nullptr) {
|
||||
auto controlDeck = GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
|
||||
const auto pad = dynamic_cast<KeyboardController*>(controlDeck->GetPhysicalDevice(controlDeck->GetNumPhysicalDevices() - 2).get());
|
||||
if (pad != nullptr) {
|
||||
if (pad->PressButton(dwScancode)) {
|
||||
bIsProcessed = true;
|
||||
}
|
||||
@ -374,7 +376,8 @@ namespace Ship {
|
||||
|
||||
|
||||
void Window::AllKeysUp(void) {
|
||||
const auto pad = dynamic_cast<KeyboardController*>(ControllerApi->physicalDevices[ControllerApi->physicalDevices.size() - 2].get());
|
||||
auto controlDeck = GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
|
||||
const auto pad = dynamic_cast<KeyboardController*>(controlDeck->GetPhysicalDevice(controlDeck->GetNumPhysicalDevices() - 2).get());
|
||||
if (pad != nullptr) {
|
||||
pad->ReleaseAllButtons();
|
||||
}
|
||||
@ -400,7 +403,7 @@ namespace Ship {
|
||||
return dwHeight;
|
||||
}
|
||||
|
||||
void Window::SetAudioPlayer() {
|
||||
void Window::InitializeAudioPlayer() {
|
||||
#ifdef _WIN32
|
||||
APlayer = std::make_shared<WasapiAudioPlayer>();
|
||||
#elif defined(__linux)
|
||||
@ -409,4 +412,8 @@ namespace Ship {
|
||||
APlayer = std::make_shared<SDLAudioPlayer>();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Window::InitializeControlDeck() {
|
||||
ControllerApi = std::make_shared<ControlDeck>();
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ namespace Ship {
|
||||
class Window {
|
||||
public:
|
||||
static int32_t lastScancode;
|
||||
inline static ControlDeck* ControllerApi = new ControlDeck;
|
||||
|
||||
Window(std::shared_ptr<GlobalCtx2> Context);
|
||||
~Window();
|
||||
@ -32,12 +31,12 @@ namespace Ship {
|
||||
void ToggleFullscreen();
|
||||
void SetFullscreen(bool bIsFullscreen);
|
||||
void ShowCursor(bool hide);
|
||||
|
||||
bool IsFullscreen() { return bIsFullscreen; }
|
||||
uint32_t GetCurrentWidth();
|
||||
uint32_t GetCurrentHeight();
|
||||
ControlDeck* GetControlDeck() { return ControllerApi; };
|
||||
uint32_t dwMenubar;
|
||||
uint32_t GetMenuBar() { return dwMenubar; }
|
||||
void SetMenuBar(uint32_t dwMenuBar) { this->dwMenubar = dwMenuBar; }
|
||||
std::shared_ptr<ControlDeck> GetControlDeck() { return ControllerApi; };
|
||||
std::shared_ptr<GlobalCtx2> GetContext() { return Context.lock(); }
|
||||
std::shared_ptr<AudioPlayer> GetAudioPlayer() { return APlayer; }
|
||||
const char* GetKeyName(int scancode) { return WmApi->get_key_name(scancode); }
|
||||
@ -48,15 +47,18 @@ namespace Ship {
|
||||
static bool KeyUp(int32_t dwScancode);
|
||||
static void AllKeysUp(void);
|
||||
static void OnFullscreenChanged(bool bIsNowFullscreen);
|
||||
void SetAudioPlayer();
|
||||
void InitializeControlDeck();
|
||||
void InitializeAudioPlayer();
|
||||
|
||||
std::weak_ptr<GlobalCtx2> Context;
|
||||
std::shared_ptr<AudioPlayer> APlayer;
|
||||
std::shared_ptr<ControlDeck> ControllerApi;
|
||||
|
||||
GfxRenderingAPI* RenderingApi;
|
||||
GfxWindowManagerAPI* WmApi;
|
||||
bool bIsFullscreen;
|
||||
uint32_t dwWidth;
|
||||
uint32_t dwHeight;
|
||||
uint32_t dwMenubar;
|
||||
};
|
||||
}
|
||||
|
@ -1306,10 +1306,11 @@ extern "C" uint32_t OTRGetCurrentHeight() {
|
||||
}
|
||||
|
||||
extern "C" void OTRControllerCallback(ControllerCallback* controller) {
|
||||
const auto controllers = Ship::Window::ControllerApi->virtualDevices;
|
||||
auto controlDeck = Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
|
||||
|
||||
for (int i = 0; i < controllers.size(); ++i) {
|
||||
Ship::Window::ControllerApi->physicalDevices[controllers[i]]->WriteToSource(i, controller);
|
||||
for (int i = 0; i < controlDeck->GetNumVirtualDevices(); ++i) {
|
||||
auto physicalDevice = controlDeck->GetPhysicalDevice(controlDeck->GetVirtualDevice(i));
|
||||
physicalDevice->WriteToSource(i, controller);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1363,11 +1364,11 @@ extern "C" void AudioPlayer_Play(const uint8_t* buf, uint32_t len) {
|
||||
}
|
||||
|
||||
extern "C" int Controller_ShouldRumble(size_t i) {
|
||||
auto controlDeck = Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
|
||||
|
||||
const auto controllers = Ship::Window::ControllerApi->virtualDevices;
|
||||
|
||||
for (const auto virtual_entry : controllers) {
|
||||
if (Ship::Window::ControllerApi->physicalDevices[virtual_entry]->CanRumble()) {
|
||||
for (int i = 0; i < controlDeck->GetNumVirtualDevices(); ++i) {
|
||||
auto physicalDevice = controlDeck->GetPhysicalDevice(controlDeck->GetVirtualDevice(i));
|
||||
if (physicalDevice->CanRumble()) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user