mirror of https://github.com/encounter/aurora.git
Input: Fix bad assumption about init
If we try and initialize anything controller related before the event subsystem is initialized we lose all controllers detected on startup. To solve this we simply wait until the first frame is about to be rendered *then* initialize the controller subsystems
This commit is contained in:
parent
b91c2739c9
commit
ca822a7679
|
@ -2,10 +2,12 @@
|
||||||
|
|
||||||
#include "gfx/common.hpp"
|
#include "gfx/common.hpp"
|
||||||
#include "imgui.hpp"
|
#include "imgui.hpp"
|
||||||
|
#include "input.hpp"
|
||||||
#include "internal.hpp"
|
#include "internal.hpp"
|
||||||
#include "webgpu/gpu.hpp"
|
#include "webgpu/gpu.hpp"
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
#include <SDL_filesystem.h>
|
#include <SDL_filesystem.h>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
|
@ -95,6 +97,7 @@ static AuroraInfo initialize(int argc, char* argv[], const AuroraConfig& config)
|
||||||
}
|
}
|
||||||
|
|
||||||
window::show_window();
|
window::show_window();
|
||||||
|
|
||||||
gfx::initialize();
|
gfx::initialize();
|
||||||
|
|
||||||
imgui::create_context();
|
imgui::create_context();
|
||||||
|
@ -135,6 +138,7 @@ static const AuroraEvent* update() noexcept {
|
||||||
if (g_initialFrame) {
|
if (g_initialFrame) {
|
||||||
aurora_end_frame();
|
aurora_end_frame();
|
||||||
g_initialFrame = false;
|
g_initialFrame = false;
|
||||||
|
input::initialize();
|
||||||
}
|
}
|
||||||
const auto* events = window::poll_events();
|
const auto* events = window::poll_events();
|
||||||
imgui::new_frame(window::get_window_size());
|
imgui::new_frame(window::get_window_size());
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <SDL_haptic.h>
|
#include <SDL_haptic.h>
|
||||||
#include <SDL_version.h>
|
#include <SDL_version.h>
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
#include <absl/container/btree_map.h>
|
#include <absl/container/btree_map.h>
|
||||||
#include <absl/container/flat_hash_map.h>
|
#include <absl/container/flat_hash_map.h>
|
||||||
|
@ -226,6 +227,11 @@ void controller_rumble(uint32_t instance, uint16_t low_freq_intensity, uint16_t
|
||||||
|
|
||||||
uint32_t controller_count() noexcept { return g_GameControllers.size(); }
|
uint32_t controller_count() noexcept { return g_GameControllers.size(); }
|
||||||
|
|
||||||
|
void initialize() noexcept {
|
||||||
|
/* Make sure we initialize everything input related now, this will automatically add all of the connected controllers
|
||||||
|
* as expected */
|
||||||
|
SDL_Init(SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
|
||||||
|
}
|
||||||
} // namespace aurora::input
|
} // namespace aurora::input
|
||||||
|
|
||||||
static const std::array<PADButtonMapping, 12> mDefaultButtons{{
|
static const std::array<PADButtonMapping, 12> mDefaultButtons{{
|
||||||
|
|
|
@ -19,4 +19,5 @@ bool controller_has_rumble(Uint32 instance) noexcept;
|
||||||
void controller_rumble(uint32_t instance, uint16_t low_freq_intensity, uint16_t high_freq_intensity,
|
void controller_rumble(uint32_t instance, uint16_t low_freq_intensity, uint16_t high_freq_intensity,
|
||||||
uint16_t duration_ms) noexcept;
|
uint16_t duration_ms) noexcept;
|
||||||
uint32_t controller_count() noexcept;
|
uint32_t controller_count() noexcept;
|
||||||
|
void initialize() noexcept;
|
||||||
} // namespace aurora::input
|
} // namespace aurora::input
|
||||||
|
|
|
@ -195,7 +195,8 @@ void show_window() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool initialize() {
|
bool initialize() {
|
||||||
ASSERT(SDL_Init(SDL_INIT_EVERYTHING & ~SDL_INIT_HAPTIC) == 0, "Error initializing SDL: {}", SDL_GetError());
|
/* We don't want to initialize anything input related here, otherwise the add events will get lost to the void */
|
||||||
|
ASSERT(SDL_Init(SDL_INIT_EVERYTHING & ~(SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER)) == 0, "Error initializing SDL: {}", SDL_GetError());
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||||
SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
|
SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
|
||||||
|
|
Loading…
Reference in New Issue