GLFW: Added glfw key support. Fixed a runtime error on windows. Style fixes
This commit is contained in:
		| @@ -5,12 +5,33 @@ | |||||||
| #include "common/common.h" | #include "common/common.h" | ||||||
|  |  | ||||||
| #include "video_core/video_core.h" | #include "video_core/video_core.h" | ||||||
|  | #include "core/hw/hid.h" | ||||||
|  |  | ||||||
|  | #include <map> | ||||||
|  |  | ||||||
| #include "citra/citra.h" | #include "citra/citra.h" | ||||||
| #include "citra/emu_window/emu_window_glfw.h" | #include "citra/emu_window/emu_window_glfw.h" | ||||||
|  |  | ||||||
| static void OnKeyEvent(GLFWwindow* win, int key, int action) { | typedef std::map<int, HID::PAD> GLFWKeyMapping; | ||||||
|     // TODO(bunnei): ImplementMe |  | ||||||
|  | GLFWKeyMapping g_key_mapping; | ||||||
|  |  | ||||||
|  | u32 g_button_reg; | ||||||
|  |  | ||||||
|  | static void OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods ) { | ||||||
|  |     try { | ||||||
|  |         HID::PAD button = g_key_mapping.at(key); | ||||||
|  |         if (action == GLFW_RELEASE) { | ||||||
|  |             g_button_reg &= 0xffffffff ^ button; | ||||||
|  |         } | ||||||
|  |         else if (action == GLFW_PRESS){ | ||||||
|  |             g_button_reg |= button; | ||||||
|  |         } | ||||||
|  |         HID::SetButtonReg(g_button_reg); | ||||||
|  |     } | ||||||
|  |     catch (std::out_of_range& e){ | ||||||
|  |  | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| static void OnWindowSizeEvent(GLFWwindow* win, int width, int height) { | static void OnWindowSizeEvent(GLFWwindow* win, int width, int height) { | ||||||
| @@ -19,6 +40,24 @@ static void OnWindowSizeEvent(GLFWwindow* win, int width, int height) { | |||||||
|     emu_window->SetClientAreaHeight(height); |     emu_window->SetClientAreaHeight(height); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void SetKeyDefaults() { | ||||||
|  |     g_key_mapping['Y'] = HID::PAD::PAD_A; | ||||||
|  |     g_key_mapping['H'] = HID::PAD::PAD_B; | ||||||
|  |     g_key_mapping['Z'] = HID::PAD::PAD_START; | ||||||
|  |     g_key_mapping['X'] = HID::PAD::PAD_SELECT; | ||||||
|  |  | ||||||
|  |     g_key_mapping['W'] = HID::PAD::PAD_UP; | ||||||
|  |     g_key_mapping['A'] = HID::PAD::PAD_LEFT; | ||||||
|  |     g_key_mapping['S'] = HID::PAD::PAD_DOWN; | ||||||
|  |     g_key_mapping['D'] = HID::PAD::PAD_RIGHT; | ||||||
|  |  | ||||||
|  |     g_key_mapping['6'] = HID::PAD::PAD_R; | ||||||
|  |     g_key_mapping['7'] = HID::PAD::PAD_L; | ||||||
|  |     g_key_mapping['U'] = HID::PAD::PAD_X; | ||||||
|  |     g_key_mapping['J'] = HID::PAD::PAD_Y; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| /// EmuWindow_GLFW constructor | /// EmuWindow_GLFW constructor | ||||||
| EmuWindow_GLFW::EmuWindow_GLFW() { | EmuWindow_GLFW::EmuWindow_GLFW() { | ||||||
|     // Initialize the window |     // Initialize the window | ||||||
| @@ -46,9 +85,11 @@ EmuWindow_GLFW::EmuWindow_GLFW() { | |||||||
|      |      | ||||||
|     // Setup callbacks |     // Setup callbacks | ||||||
|     glfwSetWindowUserPointer(m_render_window, this); |     glfwSetWindowUserPointer(m_render_window, this); | ||||||
|     //glfwSetKeyCallback(m_render_window, OnKeyEvent); |     glfwSetKeyCallback(m_render_window, (GLFWkeyfun)OnKeyEvent); | ||||||
|     //glfwSetWindowSizeCallback(m_render_window, OnWindowSizeEvent); |     //glfwSetWindowSizeCallback(m_render_window, OnWindowSizeEvent); | ||||||
|  |  | ||||||
|  |     SetKeyDefaults(); | ||||||
|  |  | ||||||
|     DoneCurrent(); |     DoneCurrent(); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,3 +1,7 @@ | |||||||
|  | // Copyright 2014 Citra Emulator Project | ||||||
|  | // Licensed under GPLv2 | ||||||
|  | // Refer to the license.txt file included. | ||||||
|  |  | ||||||
| #include <QKeySequence> | #include <QKeySequence> | ||||||
| #include <QStyledItemDelegate> | #include <QStyledItemDelegate> | ||||||
| #include <QSettings> | #include <QSettings> | ||||||
| @@ -64,7 +68,7 @@ void RegisterKeyBinding(const QKeySequence keySeq, const HID::PAD pad) | |||||||
| } | } | ||||||
|  |  | ||||||
| void createNameMap() { | void createNameMap() { | ||||||
| 	for (int i = 0; i < HID::numPadItems; i++){ | 	for (int i = 0; i < HID::g_num_pad_items; i++){ | ||||||
| 		names[(HID::PAD)(1 << i)] = QString(HID::PAD_NAMES[i]); | 		names[(HID::PAD)(1 << i)] = QString(HID::PAD_NAMES[i]); | ||||||
|         reverseNames[QString(HID::PAD_NAMES[i])] = (HID::PAD)(1 << i); |         reverseNames[QString(HID::PAD_NAMES[i])] = (HID::PAD)(1 << i); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -1,3 +1,7 @@ | |||||||
|  | // Copyright 2014 Citra Emulator Project | ||||||
|  | // Licensed under GPLv2 | ||||||
|  | // Refer to the license.txt file included. | ||||||
|  |  | ||||||
| #include <QDialog> | #include <QDialog> | ||||||
| #include "ui_key_bindings.h" | #include "ui_key_bindings.h" | ||||||
| #include "core/hw/hid.h" | #include "core/hw/hid.h" | ||||||
|   | |||||||
| @@ -167,11 +167,13 @@ | |||||||
|     </ClCompile> |     </ClCompile> | ||||||
|     <ClCompile Include="hle\kernel\event.cpp"> |     <ClCompile Include="hle\kernel\event.cpp"> | ||||||
|       <Filter>hle\kernel</Filter> |       <Filter>hle\kernel</Filter> | ||||||
| 	</ClCompile> |  | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|     <ClCompile Include="hle\kernel\shared_memory.cpp"> |     <ClCompile Include="hle\kernel\shared_memory.cpp"> | ||||||
|       <Filter>hle\kernel</Filter> |       <Filter>hle\kernel</Filter> | ||||||
| 	</ClCompile> |     </ClCompile> | ||||||
|  |     <ClCompile Include="hle\service\ndm.cpp" /> | ||||||
|  |     <ClCompile Include="hw\hid.cpp"> | ||||||
|  |       <Filter>hw</Filter> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
| @@ -319,4 +321,4 @@ | |||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <Text Include="CMakeLists.txt" /> |     <Text Include="CMakeLists.txt" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| </Project> | </Project> | ||||||
|   | |||||||
| @@ -22,7 +22,7 @@ | |||||||
| GraphicsDebugger g_debugger; | GraphicsDebugger g_debugger; | ||||||
|  |  | ||||||
| //Handle to irq memory | //Handle to irq memory | ||||||
| Handle memIRQ; | Handle g_mem_irq; | ||||||
|  |  | ||||||
|  |  | ||||||
| /// GSP shared memory GX command buffer header | /// GSP shared memory GX command buffer header | ||||||
| @@ -126,8 +126,8 @@ void RegisterInterruptRelayQueue(Service::Interface* self) { | |||||||
|     Kernel::SetPermanentLock(event_handle, true); |     Kernel::SetPermanentLock(event_handle, true); | ||||||
|  |  | ||||||
|     cmd_buff[2] = g_thread_id;          // ThreadID |     cmd_buff[2] = g_thread_id;          // ThreadID | ||||||
|     memIRQ = Kernel::CreateSharedMemory(0x1000); //page size for now |     g_mem_irq = Kernel::CreateSharedMemory(0x1000); //page size for now | ||||||
|     cmd_buff[4] = memIRQ; |     cmd_buff[4] = g_mem_irq; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,3 +1,7 @@ | |||||||
|  | // Copyright 2014 Citra Emulator Project | ||||||
|  | // Licensed under GPLv2 | ||||||
|  | // Refer to the license.txt file included. | ||||||
|  |  | ||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
| #include "common/common_types.h" | #include "common/common_types.h" | ||||||
| @@ -13,15 +17,10 @@ struct Registers { | |||||||
| extern Registers g_regs; | extern Registers g_regs; | ||||||
|  |  | ||||||
| enum { | enum { | ||||||
|     OFFSET_BUTTONS = 0x1c,  //TODO: it works using the shared mem mapping with all homebrew tested, however the wiki states 0x10146000 as the paddr |     OFFSET_BUTTONS = 0x1c, | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | const int g_num_pad_items = 12;  | ||||||
| enum { |  | ||||||
|     REG_BUTTONS = 0x1EC46000   //does not work due to confusion between shared mem and hardware IO |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| const int numPadItems = 12; // figure out a better way :( |  | ||||||
|  |  | ||||||
| enum PAD { | enum PAD { | ||||||
|     PAD_A = (1 << 0), |     PAD_A = (1 << 0), | ||||||
| @@ -38,7 +37,7 @@ enum PAD { | |||||||
|     PAD_Y = (1 << 11), |     PAD_Y = (1 << 11), | ||||||
| }; | }; | ||||||
|  |  | ||||||
| char * const PAD_NAMES[] = { | const char * const PAD_NAMES[] = { | ||||||
|     "PAD_A", |     "PAD_A", | ||||||
|     "PAD_B", |     "PAD_B", | ||||||
|     "PAD_SELECT", |     "PAD_SELECT", | ||||||
| @@ -53,7 +52,7 @@ char * const PAD_NAMES[] = { | |||||||
|     "PAD_Y" |     "PAD_Y" | ||||||
| }; | }; | ||||||
|  |  | ||||||
| void SetButtonReg(u32 buttonData); | void SetButtonReg(u32 button_data); | ||||||
|  |  | ||||||
| /// Update hardware | /// Update hardware | ||||||
| void Update(); | void Update(); | ||||||
|   | |||||||
| @@ -107,4 +107,4 @@ void Shutdown() { | |||||||
|     NOTICE_LOG(HW, "shutdown OK"); |     NOTICE_LOG(HW, "shutdown OK"); | ||||||
| } | } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -261,7 +261,6 @@ void RendererOpenGL::Init() { | |||||||
|  |  | ||||||
|     glScissor(0, 0, m_resolution_width, m_resolution_height); |     glScissor(0, 0, m_resolution_width, m_resolution_height); | ||||||
|     glClearDepth(1.0f); |     glClearDepth(1.0f); | ||||||
|  |  | ||||||
|     GLenum err = glewInit(); |     GLenum err = glewInit(); | ||||||
|     if (GLEW_OK != err) { |     if (GLEW_OK != err) { | ||||||
|         ERROR_LOG(RENDER, "Failed to initialize GLEW! Error message: \"%s\". Exiting...",  |         ERROR_LOG(RENDER, "Failed to initialize GLEW! Error message: \"%s\". Exiting...",  | ||||||
|   | |||||||
| @@ -35,6 +35,10 @@ void Init(EmuWindow* emu_window) { | |||||||
|     // Known problem with GLEW prevents contexts above 2.x on OSX unless glewExperimental is enabled. |     // Known problem with GLEW prevents contexts above 2.x on OSX unless glewExperimental is enabled. | ||||||
|     glewExperimental = GL_TRUE; |     glewExperimental = GL_TRUE; | ||||||
| #endif | #endif | ||||||
|  | #if EMU_PLATFORM == PLATFORM_WINDOWS | ||||||
|  |     glewExperimental = GL_TRUE; | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  |  | ||||||
|     g_emu_window = emu_window; |     g_emu_window = emu_window; | ||||||
|     g_emu_window->MakeCurrent(); |     g_emu_window->MakeCurrent(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 inspuration
					inspuration