From ebf9a784a9f7f4148a669dbb39e7cd50df779a14 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Thu, 11 Jan 2018 19:21:20 -0700 Subject: Massive removal of unused modules --- src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | 177 ++++++++++++++++++++++++++++ src/yuzu_cmd/emu_window/emu_window_sdl2.h | 59 ++++++++++ 2 files changed, 236 insertions(+) create mode 100644 src/yuzu_cmd/emu_window/emu_window_sdl2.cpp create mode 100644 src/yuzu_cmd/emu_window/emu_window_sdl2.h (limited to 'src/yuzu_cmd/emu_window') diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp new file mode 100644 index 000000000..e65b04e4b --- /dev/null +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp @@ -0,0 +1,177 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include +#define SDL_MAIN_HANDLED +#include +#include +#include "citra/emu_window/emu_window_sdl2.h" +#include "common/logging/log.h" +#include "common/scm_rev.h" +#include "common/string_util.h" +#include "core/settings.h" +#include "input_common/keyboard.h" +#include "input_common/main.h" +#include "input_common/motion_emu.h" +#include "network/network.h" + +void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { + TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); + InputCommon::GetMotionEmu()->Tilt(x, y); +} + +void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { + if (button == SDL_BUTTON_LEFT) { + if (state == SDL_PRESSED) { + TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); + } else { + TouchReleased(); + } + } else if (button == SDL_BUTTON_RIGHT) { + if (state == SDL_PRESSED) { + InputCommon::GetMotionEmu()->BeginTilt(x, y); + } else { + InputCommon::GetMotionEmu()->EndTilt(); + } + } +} + +void EmuWindow_SDL2::OnKeyEvent(int key, u8 state) { + if (state == SDL_PRESSED) { + InputCommon::GetKeyboard()->PressKey(key); + } else if (state == SDL_RELEASED) { + InputCommon::GetKeyboard()->ReleaseKey(key); + } +} + +bool EmuWindow_SDL2::IsOpen() const { + return is_open; +} + +void EmuWindow_SDL2::OnResize() { + int width, height; + SDL_GetWindowSize(render_window, &width, &height); + UpdateCurrentFramebufferLayout(width, height); +} + +EmuWindow_SDL2::EmuWindow_SDL2() { + InputCommon::Init(); + Network::Init(); + + SDL_SetMainReady(); + + // Initialize the window + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + LOG_CRITICAL(Frontend, "Failed to initialize SDL2! Exiting..."); + exit(1); + } + + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); + + std::string window_title = Common::StringFromFormat("yuzu %s| %s-%s ", Common::g_build_name, + Common::g_scm_branch, Common::g_scm_desc); + render_window = + SDL_CreateWindow(window_title.c_str(), + SDL_WINDOWPOS_UNDEFINED, // x position + SDL_WINDOWPOS_UNDEFINED, // y position + Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height, + SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + + if (render_window == nullptr) { + LOG_CRITICAL(Frontend, "Failed to create SDL2 window! Exiting..."); + exit(1); + } + + gl_context = SDL_GL_CreateContext(render_window); + + if (gl_context == nullptr) { + LOG_CRITICAL(Frontend, "Failed to create SDL2 GL context! Exiting..."); + exit(1); + } + + if (!gladLoadGLLoader(static_cast(SDL_GL_GetProcAddress))) { + LOG_CRITICAL(Frontend, "Failed to initialize GL functions! Exiting..."); + exit(1); + } + + OnResize(); + OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size); + SDL_PumpEvents(); + SDL_GL_SetSwapInterval(Settings::values.use_vsync); + + DoneCurrent(); +} + +EmuWindow_SDL2::~EmuWindow_SDL2() { + SDL_GL_DeleteContext(gl_context); + SDL_Quit(); + + Network::Shutdown(); + InputCommon::Shutdown(); +} + +void EmuWindow_SDL2::SwapBuffers() { + SDL_GL_SwapWindow(render_window); +} + +void EmuWindow_SDL2::PollEvents() { + SDL_Event event; + + // SDL_PollEvent returns 0 when there are no more events in the event queue + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_WINDOWEVENT: + switch (event.window.event) { + case SDL_WINDOWEVENT_SIZE_CHANGED: + case SDL_WINDOWEVENT_RESIZED: + case SDL_WINDOWEVENT_MAXIMIZED: + case SDL_WINDOWEVENT_RESTORED: + case SDL_WINDOWEVENT_MINIMIZED: + OnResize(); + break; + case SDL_WINDOWEVENT_CLOSE: + is_open = false; + break; + } + break; + case SDL_KEYDOWN: + case SDL_KEYUP: + OnKeyEvent(static_cast(event.key.keysym.scancode), event.key.state); + break; + case SDL_MOUSEMOTION: + OnMouseMotion(event.motion.x, event.motion.y); + break; + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + OnMouseButton(event.button.button, event.button.state, event.button.x, event.button.y); + break; + case SDL_QUIT: + is_open = false; + break; + } + } +} + +void EmuWindow_SDL2::MakeCurrent() { + SDL_GL_MakeCurrent(render_window, gl_context); +} + +void EmuWindow_SDL2::DoneCurrent() { + SDL_GL_MakeCurrent(render_window, nullptr); +} + +void EmuWindow_SDL2::OnMinimalClientAreaChangeRequest( + const std::pair& minimal_size) { + + SDL_SetWindowMinimumSize(render_window, minimal_size.first, minimal_size.second); +} diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.h b/src/yuzu_cmd/emu_window/emu_window_sdl2.h new file mode 100644 index 000000000..3664d2fbe --- /dev/null +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.h @@ -0,0 +1,59 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include "core/frontend/emu_window.h" + +struct SDL_Window; + +class EmuWindow_SDL2 : public EmuWindow { +public: + EmuWindow_SDL2(); + ~EmuWindow_SDL2(); + + /// Swap buffers to display the next frame + void SwapBuffers() override; + + /// Polls window events + void PollEvents() override; + + /// Makes the graphics context current for the caller thread + void MakeCurrent() override; + + /// Releases the GL context from the caller thread + void DoneCurrent() override; + + /// Whether the window is still open, and a close request hasn't yet been sent + bool IsOpen() const; + +private: + /// Called by PollEvents when a key is pressed or released. + void OnKeyEvent(int key, u8 state); + + /// Called by PollEvents when the mouse moves. + void OnMouseMotion(s32 x, s32 y); + + /// Called by PollEvents when a mouse button is pressed or released + void OnMouseButton(u32 button, u8 state, s32 x, s32 y); + + /// Called by PollEvents when any event that may cause the window to be resized occurs + void OnResize(); + + /// Called when a configuration change affects the minimal size of the window + void OnMinimalClientAreaChangeRequest( + const std::pair& minimal_size) override; + + /// Is the window still open? + bool is_open = true; + + /// Internal SDL2 render window + SDL_Window* render_window; + + using SDL_GLContext = void*; + /// The OpenGL context associated with the window + SDL_GLContext gl_context; +}; -- cgit v1.2.3