Skip to content

Commit

Permalink
3rdParty: wip changes to implement mouse tracking in rt64
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed May 28, 2024
1 parent 7092859 commit a55f3fc
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 deletions.
1 change: 1 addition & 0 deletions Source/3rdParty/rt64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ if (RT64_BUILD_PLUGIN)
target_sources(rt64 PRIVATE
"${PROJECT_SOURCE_DIR}/src/api/rt64_api_common.cpp"
"${PROJECT_SOURCE_DIR}/src/api/rt64_api_plugin.cpp"
"${PROJECT_SOURCE_DIR}/src/contrib/imgui/backends/imgui_impl_sdl2.cpp"
)
if (WIN32)
target_sources(rt64 PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion Source/3rdParty/rt64/src/api/rt64_api_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ DLLEXPORT void CALL UpdateScreen(void) {

DLLEXPORT void CALL ChangeWindow(void) {
const bool isPJ64 = (RT64::API.apiType == RT64::APIType::Project64);
if (isPJ64) {
if (!isPJ64) {
CoreVideo_ToggleFullScreen();
} else {
RT64::ApplicationWindow *appWindow = RT64::API.app->appWindow.get();
Expand Down
83 changes: 80 additions & 3 deletions Source/3rdParty/rt64/src/api/rt64_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "rt64_api_common.h"

#include <SDL.h>
#include "imgui/backends/imgui_impl_sdl2.h"

#define PLUGIN_NAME "RT64 Video Plugin"
#define PLUGIN_VERSION 0x020509
#define VIDEO_PLUGIN_API_VERSION 0x020200
Expand Down Expand Up @@ -71,9 +74,7 @@ DLLEXPORT m64p_error CALL PluginGetVersion(m64p_plugin_type *PluginType, int *Pl
*PluginNamePtr = PLUGIN_NAME;

if (Capabilities != NULL)
{
*Capabilities = 0;
}

return M64ERR_SUCCESS;
}
Expand Down Expand Up @@ -151,7 +152,7 @@ int window_width = 640;
int window_height = 480;

DLLEXPORT void CALL ResizeVideoOutput(int width, int height) {
window_width = width;
window_width = width;
window_height = height;
}

Expand Down Expand Up @@ -183,3 +184,79 @@ DLLEXPORT void CALL CaptureScreen(const char *Directory) {
// Unused.
}

// TODO: PR this to mupen64plus....
DLLEXPORT void CALL SDL_KeyDown(int keymod, int keysym)
{
SDL_Event event;
event.type = SDL_KEYDOWN;
event.key.keysym.mod = keymod;
event.key.keysym.sym = keysym;
if (RT64::API.app->presentQueue->inspector != nullptr) {
ImGui_ImplSDL2_ProcessEvent(&event);
}
}

DLLEXPORT void CALL SDL_KeyUp(int keymod, int keysym)
{
SDL_Event event;
event.type = SDL_KEYUP;
event.key.keysym.mod = SDL_SCANCODE_TO_KEYCODE(keymod);
event.key.keysym.sym = SDL_SCANCODE_TO_KEYCODE(keysym);

if (keysym == SDL_SCANCODE_F10)
{
if (RT64::API.app->userConfig.developerMode) {
fprintf(stderr, "creating inspector...\n");
const std::lock_guard<std::mutex> lock(RT64::API.app->presentQueue->inspectorMutex);
if (RT64::API.app->presentQueue->inspector == nullptr) {
RT64::API.app->presentQueue->inspector = std::make_unique<RT64::Inspector>(RT64::API.app->device.get(), RT64::API.app->swapChain.get(), RT64::API.app->createdGraphicsAPI);
if (!RT64::API.app->userPaths.isEmpty()) {
RT64::API.app->presentQueue->inspector->setIniPath(RT64::API.app->userPaths.imguiPath);
}

RT64::API.app->freeCamClearQueued = true;
ImGui_ImplSDL2_InitForVulkan(nullptr); // TODO: move this elsewhere...
//appWindow->blockSdlKeyboard();
}
else if (RT64::API.app->presentQueue->inspector != nullptr) {
RT64::API.app->presentQueue->inspector.reset(nullptr);
//appWindow->unblockSdlKeyboard();
}
}
else {
fprintf(stdout, "Inspector is not available: developer mode is not enabled in the configuration.\n");
}
return;
}

if (RT64::API.app->presentQueue->inspector != nullptr) {
ImGui_ImplSDL2_ProcessEvent(&event);
}
}

DLLEXPORT void CALL MouseMove(int x, int y)
{
SDL_Event event;
event.type = SDL_MOUSEMOTION;
event.motion.which = 1;
event.motion.x = x;
event.motion.y = y;

if (RT64::API.app->presentQueue->inspector != nullptr) {
printf("MouseMove x = %i, y = %i\n", x,y);
ImGui_ImplSDL2_ProcessEvent(&event);
}
}

DLLEXPORT void CALL MouseButton(int left, int right)
{
if (RT64::API.app->presentQueue->inspector != nullptr) {
printf("MouseButton left = %i\n", left);
SDL_Event event;
event.type = left ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
event.button.button = SDL_BUTTON_LEFT;
ImGui_ImplSDL2_ProcessEvent(&event);
}
}


13 changes: 11 additions & 2 deletions Source/3rdParty/rt64/src/gui/rt64_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
# include "d3d12/rt64_d3d12.h"
#endif

#if defined(RT64_BUILD_PLUGIN)
# include "api/rt64_api_common.h"
#endif

// Volk must be included before the ImGui Vulkan backend.
#include "vulkan/rt64_vulkan.h"
#include "imgui/backends/imgui_impl_vulkan.h"
Expand Down Expand Up @@ -156,7 +160,8 @@ namespace RT64 {
# ifdef _WIN32
ImGui_ImplWin32_Shutdown();
# else
assert(false && "Unimplemented.");
// if mupen64plus, dont assert...
//assert(false && "Unimplemented.");
# endif

ImPlot::DestroyContext();
Expand All @@ -177,7 +182,11 @@ namespace RT64 {
# ifdef _WIN32
ImGui_ImplWin32_NewFrame();
# else
assert(false && "Unimplemented.");
// ????????
// if mupen64plus == true, dont assert....
ImGuiIO &io = ImGui::GetIO();
io.DisplaySize = ImVec2((float)window_width, (float)window_height);
//assert(false && "Unimplemented.");
# endif

switch (graphicsAPI) {
Expand Down
2 changes: 1 addition & 1 deletion Source/3rdParty/rt64/src/hle/rt64_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ namespace RT64 {
// Check the debugger popup regardless of the active inspector mode.
bool debuggerSelected = debuggerInspector.checkPopup(workload);

if (ImGui::Begin("Game editor")) {
if (ImGui::Begin("Game editor", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::BeginTabBar("##tabs", ImGuiTabBarFlags_None)) {
if (ImGui::BeginTabItem("Configuration")) {
// General configuration.
Expand Down

0 comments on commit a55f3fc

Please sign in to comment.