diff --git a/src/game/bmpdlog.cc b/src/game/bmpdlog.cc index 2f68d61..121260a 100644 --- a/src/game/bmpdlog.cc +++ b/src/game/bmpdlog.cc @@ -152,7 +152,7 @@ int dialog_out(const char* title, const char** body, int bodyLength, int x, int } #ifdef __3DS__ - setDisplay(ctr_display_t::DISPLAY_PAUSE_CONFIRM); + setActiveDisplay(ctr_display_t::DISPLAY_PAUSE_CONFIRM); #endif int maximumLineWidth = 0; diff --git a/src/game/editor.cc b/src/game/editor.cc index 32c2058..96a86d9 100644 --- a/src/game/editor.cc +++ b/src/game/editor.cc @@ -1471,7 +1471,13 @@ int get_input_str(int win, int cancelKeyCode, char* text, int maxLength, int x, text_to_buf(windowBuffer + windowWidth * y + x, copy, windowWidth, windowWidth, textColor); win_draw(win); - +#ifdef __3DS__ + ctr_sys_swkbd("", copy, text); + buf_fill(windowBuffer + windowWidth * y + x, nameWidth, text_height(), windowWidth, backgroundColor); + text_to_buf(windowBuffer + windowWidth * y + x, copy, windowWidth, windowWidth, textColor); + renderPresent(); + int rc = 0; +#else beginTextInput(); int blinkingCounter = 3; @@ -1543,7 +1549,7 @@ int get_input_str(int win, int cancelKeyCode, char* text, int maxLength, int x, copy[nameLength] = '\0'; strcpy(text, copy); } - +#endif return rc; } diff --git a/src/game/game.cc b/src/game/game.cc index 17bbfa8..4fd0d18 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -585,8 +585,7 @@ int game_handle_input(int eventCode, bool isInCombatMode) int mode = -1; #ifdef __3DS__ -setDisplay(ctr_display_t::DISPLAY_SKILLDEX); -// currentDisplay = ctr_display_t::DISPLAY_SKILLDEX; + setActiveDisplay(ctr_display_t::DISPLAY_SKILLDEX); #endif // NOTE: There is an `inc` for this value to build jump table which // is not needed. @@ -627,15 +626,13 @@ setDisplay(ctr_display_t::DISPLAY_SKILLDEX); if (mode != -1) { #ifdef __3DS__ -setDisplay(ctr_display_t::DISPLAY_FIELD); -// currentDisplay = ctr_display_t::DISPLAY_FIELD; + setActiveDisplay(ctr_display_t::DISPLAY_FIELD); #endif gmouse_set_cursor(MOUSE_CURSOR_USE_CROSSHAIR); gmouse_3d_set_mode(mode); } #ifdef __3DS__ -setDisplay(ctr_display_t::DISPLAY_FULL); -// currentDisplay = ctr_display_t::DISPLAY_FULL; + setActiveDisplay(ctr_display_t::DISPLAY_FULL); #endif } break; diff --git a/src/game/gdialog.cc b/src/game/gdialog.cc index 545b7b8..0d287b0 100644 --- a/src/game/gdialog.cc +++ b/src/game/gdialog.cc @@ -835,7 +835,7 @@ int scr_dialogue_init(int headFid, int reaction) gdDialogWentOff = true; #ifdef __3DS__ - setDisplay(ctr_display_t::DISPLAY_DIALOG); + setActiveDisplay(ctr_display_t::DISPLAY_DIALOG); #endif return 0; @@ -913,7 +913,7 @@ int scr_dialogue_exit() gdDialogWentOff = true; #ifdef __3DS__ -setPreviousAsCurrent(); +ctr_display.active = ctr_display.previous; #endif return 0; } @@ -2052,7 +2052,9 @@ static void head_bk() dialogue_switch_mode = 0; talk_to_destroy_barter_win(); talk_to_create_dialogue_win(); - +#ifdef __3DS__ + setActiveDisplay(ctr_display_t::DISPLAY_DIALOG); // only when returning from barter +#endif // NOTE: Uninline. gdialog_unhide(); @@ -2893,6 +2895,9 @@ static void dialogue_barter_cleanup_tables() // 0x440EC4 static void talk_to_pressed_barter(int btn, int keyCode) { +#ifdef __3DS__ + setActiveDisplay(ctr_display_t::DISPLAY_FULL); +#endif if (PID_TYPE(dialog_target->pid) != OBJ_TYPE_CRITTER) { return; } @@ -2932,6 +2937,9 @@ static void talk_to_pressed_barter(int btn, int keyCode) // 0x440FB4 static void talk_to_pressed_about(int btn, int keyCode) { +#ifdef __3DS__ + setActiveDisplay(ctr_display_t::DISPLAY_FULL); +#endif MessageListItem mesg; int reaction; int reaction_level; @@ -2975,6 +2983,9 @@ static void talk_to_pressed_about(int btn, int keyCode) // NOTE: Uncollapsed 0x445CA0 with different signature. static void talk_to_pressed_review(int btn, int keyCode) { +#ifdef __3DS__ + setActiveDisplay(ctr_display_t::DISPLAY_FULL); +#endif gdialog_review(); } diff --git a/src/game/gmovie.cc b/src/game/gmovie.cc index a18aa6b..5867ea5 100644 --- a/src/game/gmovie.cc +++ b/src/game/gmovie.cc @@ -105,11 +105,6 @@ int gmovie_save(DB_FILE* stream) // 0x44E690 int gmovie_play(int game_movie, int game_movie_flags) { -#ifdef __3DS__ -// int previousDisplay = currentDisplay; -// currentDisplay = ctr_display_t::DISPLAY_MOVIE; -setDisplay(ctr_display_t::DISPLAY_MOVIE); -#endif dir_entry de; char movieFilePath[COMPAT_MAX_PATH]; @@ -119,9 +114,6 @@ setDisplay(ctr_display_t::DISPLAY_MOVIE); if (db_dir_entry(movieFilePath, &de) != 0) { debug_printf("\ngmovie_play() - Error: Unable to open %s\n", movie_list[game_movie]); -#ifdef __3DS__ -// currentDisplay = previousDisplay; -#endif return -1; } @@ -138,10 +130,6 @@ setDisplay(ctr_display_t::DISPLAY_MOVIE); 0, WINDOW_MODAL); if (win == -1) { -#ifdef __3DS__ -// currentDisplay = previousDisplay; -//setDisplay(ctr_display_t::DISPLAY_FULL); -#endif return -1; } @@ -151,6 +139,10 @@ setDisplay(ctr_display_t::DISPLAY_MOVIE); gsound_background_pause(); } +#ifdef __3DS__ + setActiveDisplay(ctr_display_t::DISPLAY_MOVIE); +#endif + win_draw(win); bool subtitlesEnabled = false; @@ -266,9 +258,7 @@ setDisplay(ctr_display_t::DISPLAY_MOVIE); palette_fade_to(cmap); } #ifdef __3DS__ -// currentDisplay = previousDisplay; -//currentDisplay = ctr_display_t::DISPLAY_FULL; -//setDisplay(ctr_display_t::DISPLAY_FULL); + ctr_display.active = ctr_display.previous; #endif return 0; } diff --git a/src/game/main.cc b/src/game/main.cc index dd811c8..beed0d9 100644 --- a/src/game/main.cc +++ b/src/game/main.cc @@ -111,8 +111,8 @@ int gnw_main(int argc, char** argv) while (!done) { #ifdef __3DS__ - if (ctr_display.active != ctr_display_t::DISPLAY_MAIN) - setDisplay(ctr_display_t::DISPLAY_MAIN); + if (ctr_display.active != ctr_display_t::DISPLAY_MAIN) + setActiveDisplay(ctr_display_t::DISPLAY_MAIN); #endif kb_clear(); gsound_background_play_level_music("07desert", 11); @@ -131,7 +131,7 @@ int gnw_main(int argc, char** argv) main_menu_hide(true); main_menu_destroy(); #ifdef __3DS__ - setDisplay(ctr_display_t::DISPLAY_FULL); + setActiveDisplay(ctr_display_t::DISPLAY_FULL); #endif if (select_character() == 2) { gmovie_play(MOVIE_OVRINTRO, GAME_MOVIE_STOP_MUSIC); @@ -162,7 +162,7 @@ int gnw_main(int argc, char** argv) main_menu_destroy(); gsound_background_stop(); #ifdef __3DS__ - setDisplay(ctr_display_t::DISPLAY_FULL); + setActiveDisplay(ctr_display_t::DISPLAY_FULL); #endif // NOTE: Uninline. main_loadgame_new(); diff --git a/src/game/options.cc b/src/game/options.cc index e75b43f..302d8cf 100644 --- a/src/game/options.cc +++ b/src/game/options.cc @@ -388,12 +388,13 @@ int do_options() debug_printf("\nOPTION MENU: Error loading option dialog data!\n"); return -1; } -#ifdef __3DS__ -setDisplay(ctr_display_t::DISPLAY_PAUSE); -// currentDisplay = ctr_display_t::DISPLAY_PAUSE; -#endif + int rc = -1; while (rc == -1) { +#ifdef __3DS__ + if (ctr_display.active != ctr_display_t::DISPLAY_PAUSE) + setActiveDisplay(ctr_display_t::DISPLAY_PAUSE); +#endif sharedFpsLimiter.mark(); int keyCode = get_input(); @@ -414,6 +415,9 @@ setDisplay(ctr_display_t::DISPLAY_PAUSE); case KEY_UPPERCASE_S: case KEY_LOWERCASE_S: case 500: +#ifdef __3DS__ +setActiveDisplay(ctr_display_t::DISPLAY_FULL); +#endif if (SaveGame(LOAD_SAVE_MODE_NORMAL) == 1) { rc = 1; } @@ -421,6 +425,9 @@ setDisplay(ctr_display_t::DISPLAY_PAUSE); case KEY_UPPERCASE_L: case KEY_LOWERCASE_L: case 501: +#ifdef __3DS__ +setActiveDisplay(ctr_display_t::DISPLAY_FULL); +#endif if (LoadGame(LOAD_SAVE_MODE_NORMAL) == 1) { rc = 1; } @@ -430,6 +437,9 @@ setDisplay(ctr_display_t::DISPLAY_PAUSE); gsound_play_sfx_file("ib1p1xx1"); // FALLTHROUGH case 502: +#ifdef __3DS__ +setActiveDisplay(ctr_display_t::DISPLAY_FULL); +#endif // PREFERENCES showPreferences = true; break; @@ -466,7 +476,6 @@ setDisplay(ctr_display_t::DISPLAY_PAUSE); sharedFpsLimiter.throttle(); } #ifdef __3DS__ -// currentDisplay = ctr_display_t::DISPLAY_FULL; setPreviousAsCurrent(); #endif OptnEnd(); diff --git a/src/game/skilldex.cc b/src/game/skilldex.cc index 4f0e9f2..2dfaac1 100644 --- a/src/game/skilldex.cc +++ b/src/game/skilldex.cc @@ -385,6 +385,7 @@ static int skilldex_start() } win_draw(skldxwin); + return 0; } diff --git a/src/int/window.cc b/src/int/window.cc index 65b8bc1..a4f396a 100644 --- a/src/int/window.cc +++ b/src/int/window.cc @@ -1601,7 +1601,6 @@ void initWindow(int resolution, int a2) for (int i = 0; i < MANAGED_WINDOW_COUNT; i++) { windows[i].window = -1; } - rc = win_init(gfx_init[resolution], GNW95_reset_mode, a2); if (rc != WINDOW_MANAGER_OK) { diff --git a/src/platform/ctr/ctr_gfx.cc b/src/platform/ctr/ctr_gfx.cc index f8636b7..112f5c4 100644 --- a/src/platform/ctr/ctr_gfx.cc +++ b/src/platform/ctr/ctr_gfx.cc @@ -1,23 +1,21 @@ -#include -#include #include #include "ctr_input.h" #include "ctr_gfx.h" -#include "plib/gnw/gnw.h" -#include "plib/gnw/svga.h" -#include "plib/gnw/mouse.h" namespace fallout { + ctr_display_t ctr_display; +std::map> displayRectMap; + +void convertTouchToTextureCoordinates(int tmp_touchX, int tmp_touchY, ctr_display_t::active_display_t displayType, int* originalX, int* originalY) { + const std::vector& displayRects = displayRectMap[displayType]; -void convertTouchToTextureCoordinates(int tmp_touchX, int tmp_touchY, const TextureInfo* textureInfos, int startTextureInfos, int numTextureInfos, int* originalX, int* originalY) { - for (int i = (startTextureInfos?startTextureInfos:0); i < (startTextureInfos+numTextureInfos); ++i) { - const TextureInfo* textureInfo = &textureInfos[i]; - if (tmp_touchX >= textureInfo->dstRect.x && tmp_touchX < (textureInfo->dstRect.x + textureInfo->dstRect.w) && - tmp_touchY >= textureInfo->dstRect.y && tmp_touchY < (textureInfo->dstRect.y + textureInfo->dstRect.h)) { - *originalX = (int)((tmp_touchX - textureInfo->dstRect.x) / (float)(textureInfo->dstRect.w) * textureInfo->srcRect.w + textureInfo->srcRect.x); - *originalY = (int)((tmp_touchY - textureInfo->dstRect.y) / (float)(textureInfo->dstRect.h) * textureInfo->srcRect.h + textureInfo->srcRect.y); + for (const DisplayRect& displayRect : displayRects) { + if (tmp_touchX >= displayRect.dstRect.x && tmp_touchX < (displayRect.dstRect.x + displayRect.dstRect.w) && + tmp_touchY >= displayRect.dstRect.y && tmp_touchY < (displayRect.dstRect.y + displayRect.dstRect.h)) { + *originalX = static_cast((tmp_touchX - displayRect.dstRect.x) / static_cast(displayRect.dstRect.w) * displayRect.srcRect.w + displayRect.srcRect.x); + *originalY = static_cast((tmp_touchY - displayRect.dstRect.y) / static_cast(displayRect.dstRect.h) * displayRect.srcRect.h + displayRect.srcRect.y); return; } } @@ -25,15 +23,68 @@ void convertTouchToTextureCoordinates(int tmp_touchX, int tmp_touchY, const Text *originalY = tmp_touchY; } -void setDisplay(ctr_display_t::active_display_t newActive) -{ +void initializeDisplayRectMap() { + displayRectMap[ctr_display_t::DISPLAY_FULL] = { + {{ 0, 0, 640, 480}, {40, 0, 320, 240}} + }; + + displayRectMap[ctr_display_t::DISPLAY_FIELD] = { + {{ 0, 0, 640, 380}, { 0, 0, 320, 190}} + }; + + displayRectMap[ctr_display_t::DISPLAY_GUI] = { + {{ 5, 380, 200, 100}, { 0, 10, 200, 100}}, + {{200, 380, 320, 100}, { 0, 140, 320, 100}}, + {{520, 380, 140, 100}, {200, 10, 120, 100}} + }; + + displayRectMap[ctr_display_t::DISPLAY_MOVIE] = { + {{ 0, 0, 640, 480}, { 0, 0, 320, 240}} + }; + + displayRectMap[ctr_display_t::DISPLAY_MAIN] = { + {{400, 25, 215, 220}, { 55, 0, 215, 240}} + }; + + displayRectMap[ctr_display_t::DISPLAY_PAUSE] = { + {{240, 72, 160, 215}, { 55, 0, 215, 240}} + }; + + displayRectMap[ctr_display_t::DISPLAY_PAUSE_CONFIRM] = { + {{170, 120, 300, 120}, { 0, 50, 320, 120}} + }; + + displayRectMap[ctr_display_t::DISPLAY_DIALOG_TOP] = { + {{ 80, 0, 480, 290}, { 0, 0, 397, 240}}, + {{130, 230, 390, 60}, { 10, 180, 380, 60}} // dialog + }; + + displayRectMap[ctr_display_t::DISPLAY_DIALOG_BACK] = { + {{560, 440, 80, 36}, { 0, 160, 320, 80}} + }; + + displayRectMap[ctr_display_t::DISPLAY_DIALOG] = { + {{130, 320, 385, 160}, { 0, 0, 320, 160}}, // bottom dialog + {{ 5, 410, 70, 70}, { 55, 160, 70, 70}}, // bottom review + {{565, 300, 70, 60}, {125, 175, 70, 60}}, // bottom barter + {{565, 360, 70, 80}, {195, 160, 70, 80}} // bottom about + + }; + + displayRectMap[ctr_display_t::DISPLAY_SKILLDEX] = { + {{452, 5, 240, 190}, { 0, 0, 160, 190}}, + {{452, 190, 240, 180}, {160, 40, 160, 180}} + }; +} + +void setActiveDisplay(ctr_display_t::active_display_t displayType) { ctr_display.previous = ctr_display.active; - ctr_display.active = newActive; + ctr_display.active = displayType; } void setPreviousAsCurrent() { - std::swap(ctr_display.active, ctr_display.previous); + ctr_display.active = ctr_display.previous; } } // namespace fallout diff --git a/src/platform/ctr/ctr_gfx.h b/src/platform/ctr/ctr_gfx.h index 0963885..bee2491 100644 --- a/src/platform/ctr/ctr_gfx.h +++ b/src/platform/ctr/ctr_gfx.h @@ -1,14 +1,15 @@ #ifndef FALLOUT_PLATFORM_CTR_GFX_H_ #define FALLOUT_PLATFORM_CTR_GFX_H_ -#include "plib/gnw/svga.h" +#include <3ds.h> -namespace fallout { +#include +#include +#include -#include <3ds.h> +#include "plib/gnw/svga.h" -//extern int currentDisplay; -//extern int currentInput; +namespace fallout { struct ctr_display_t { enum active_display_t { @@ -24,6 +25,8 @@ struct ctr_display_t { DISPLAY_PAUSE, DISPLAY_PAUSE_CONFIRM, DISPLAY_DIALOG, + DISPLAY_DIALOG_TOP, + DISPLAY_DIALOG_BACK, DISPLAY_LAST }; active_display_t active; @@ -31,8 +34,17 @@ struct ctr_display_t { }; extern ctr_display_t ctr_display; +struct DisplayRect { + SDL_Rect srcRect; + SDL_Rect dstRect; +}; +extern std::map> displayRectMap; + +void initializeDisplayRectMap(); +void addTextureInfo(TextureInfo** textureInfos, int* numTextureInfos, ctr_display_t::active_display_t displayType); +void setActiveDisplay(ctr_display_t::active_display_t displayType); -void convertTouchToTextureCoordinates(int tmp_touchX, int tmp_touchY, const TextureInfo* textureInfos, int startTextureInfos, int numTextureInfos, int* originalX, int* originalY); +void convertTouchToTextureCoordinates(int tmp_touchX, int tmp_touchY, ctr_display_t::active_display_t displayType, int* originalX, int* originalY); void setDisplay(ctr_display_t::active_display_t newActive); void setPreviousAsCurrent(); diff --git a/src/platform/ctr/ctr_input.cc b/src/platform/ctr/ctr_input.cc index 700ceb8..ef032a0 100644 --- a/src/platform/ctr/ctr_input.cc +++ b/src/platform/ctr/ctr_input.cc @@ -6,41 +6,39 @@ #include "plib/gnw/gnw.h" #include "plib/gnw/svga.h" #include "plib/gnw/mouse.h" +#include "game/map.h" namespace fallout { ctr_input_t ctr_input; -float touchX = 0.0f; -float touchY = 0.0f; - -int lastTouchX = 0; -int lastTouchY = 0; - int offsetX = 0; int offsetY = 0; u32 qtm_pos; u32 qtm_x, qtm_y; -Result ret; bool qtm_usable; QTM_HeadTrackingInfo qtminfo; -float qtm_offsetX; -float qtm_offsetY; - qtm_state_t qtm_state; int currentInput = ctr_input_t::INPUT_TOUCH; static uint32_t oldpad = 0; u32 kHeld; +int speedDivider = 2; +int deadzone = 15; +bool relativeMode = true; + +void resetCursorPosition(); void ctr_init_qtm() { qtmInit(); qtm_usable = qtmCheckInitialized(); if(!qtm_usable) currentInput = ctr_input_t::INPUT_TOUCH; + +resetCursorPosition(); } void ctr_exit_qtm() @@ -49,38 +47,118 @@ void ctr_exit_qtm() qtmExit(); } +struct CursorPosition { + int x; + int y; +}; + +CursorPosition absoluteCursorPosition; + +void resetCursorPosition() { + absoluteCursorPosition.x = 120; + absoluteCursorPosition.y = 120; +} + +void updateCursorPosition(s16 deltaX, s16 deltaY, int speedDivider, bool relativeMode, int deadzone) { + const int screenWidth = 240; + const int screenHeight = 240; + + int cursorX = absoluteCursorPosition.x; + int cursorY = absoluteCursorPosition.y; + + int moveX = static_cast(deltaX) / speedDivider; + int moveY = -static_cast(deltaY) / speedDivider; + + if (abs(moveX) < deadzone) { + moveX = 0; + } + if (abs(moveY) < deadzone) { + moveY = 0; + } + if (relativeMode) { + cursorX += moveX; + cursorY += moveY; + } else { + cursorX = moveX; + cursorY = moveY; + } + if (cursorX < 0) { + cursorX = 0; + } else if (cursorX >= screenWidth) { + cursorX = screenWidth - 1; + } + + if (cursorY < 0) { + cursorY = 0; + } else if (cursorY >= screenHeight) { + cursorY = screenHeight - 1; + } + + absoluteCursorPosition.x = cursorX; + absoluteCursorPosition.y = cursorY; +} void ctr_input_frame() { kHeld = hidKeysHeld(); - if (SINGLE_CLICK(KEY_A)) { + if ((SINGLE_CLICK(KEY_A)) || (SINGLE_CLICK(KEY_ZL))) { if (ctr_display.active == ctr_display_t::DISPLAY_GUI) - ctr_display.active = ctr_display_t::DISPLAY_FIELD; + setActiveDisplay(ctr_display_t::DISPLAY_FULL); else - ctr_display.active = ctr_display_t::DISPLAY_GUI; + setActiveDisplay(ctr_display_t::DISPLAY_GUI); } if (SINGLE_CLICK(KEY_B)) { - ctr_display.active = ctr_display_t::DISPLAY_FULL; + setActiveDisplay(ctr_display_t::DISPLAY_FULL); } if (SINGLE_CLICK(KEY_Y)) { - ctr_display.active = static_cast((ctr_display.active + 1) % ctr_display_t::DISPLAY_LAST); +// ctr_display.active = static_cast((ctr_display.active + 1) % ctr_display_t::DISPLAY_LAST); } if (SINGLE_CLICK(KEY_X)) { currentInput = static_cast((currentInput + 1) % (ctr_input_t::INPUT_LAST)); } + if(kHeld & KEY_DUP) + map_scroll(0, -1); + if(kHeld & KEY_DDOWN) + map_scroll(0, 1); + if(kHeld & KEY_DLEFT) + map_scroll(-1, 0); + if(kHeld & KEY_DRIGHT) + map_scroll(1, 0); + switch (currentInput) { case ctr_input_t::INPUT_TOUCH: + { if(qtm_usable) ctr_exit_qtm(); + break; + } + case ctr_input_t::INPUT_CPAD: + { + if(qtm_usable) + ctr_exit_qtm(); + + circlePosition circle; + hidCircleRead(&circle); + + circlePosition cstick; + hidCstickRead(&cstick); + + updateCursorPosition(circle.dx, circle.dy, speedDivider, relativeMode, deadzone); + + offsetX = absoluteCursorPosition.x; + offsetY = absoluteCursorPosition.y; + break; + } case ctr_input_t::INPUT_QTM: + { if(!qtm_usable) { ctr_init_qtm(); @@ -97,7 +175,7 @@ void ctr_input_frame() qtm_state.multiplier = 1; } - ret = QTM_GetHeadTrackingInfo(0, &qtminfo); + Result ret = QTM_GetHeadTrackingInfo(0, &qtminfo); if(ret==0) { if(qtmCheckHeadFullyDetected(&qtminfo)) { ret = qtmConvertCoordToScreen(&qtminfo.coords0[0], &range_x, &range_y, &qtm_x, &qtm_y); @@ -105,8 +183,7 @@ void ctr_input_frame() } } - if (SINGLE_CLICK(KEY_ZR)) - { + if (SINGLE_CLICK(KEY_ZR)) { qtm_state.multiplier += 1; if (qtm_state.multiplier > 10) qtm_state.multiplier = 1; @@ -130,17 +207,10 @@ void ctr_input_frame() textureY = -MAX_OFFSET_Y_QTM; } - qtm_offsetX = 120 + textureX; - qtm_offsetY = 120 + textureY; -/* - if (SINGLE_CLICK(KEY_ZL)) { - char inputBuffer[512] = ""; // Buffer to store input data - - snprintf(inputBuffer, 512, "qtm X: %ld, Y: %ld\noffset X: %f, Y: %f", qtm_x,qtm_y,qtm_offsetX, qtm_offsetY); - GNWSystemError(inputBuffer); - } -*/ + offsetX = 120 + textureX; + offsetY = 120 + textureY; break; + } } oldpad = kHeld; } diff --git a/src/platform/ctr/ctr_input.h b/src/platform/ctr/ctr_input.h index 07ddc5b..dcb72ae 100644 --- a/src/platform/ctr/ctr_input.h +++ b/src/platform/ctr/ctr_input.h @@ -1,12 +1,12 @@ #ifndef FALLOUT_PLATFORM_CTR_INPUT_H_ #define FALLOUT_PLATFORM_CTR_INPUT_H_ +#include <3ds.h> + #include "plib/gnw/svga.h" namespace fallout { -#include <3ds.h> - #define SINGLE_CLICK(x) kHeld & x && (!(oldpad & x)) #define MAX_OFFSET_X (640 - 400) @@ -18,23 +18,15 @@ namespace fallout { extern int offsetX; extern int offsetY; -extern float qtm_offsetX; -extern float qtm_offsetY; - -extern float touchX; -extern float touchY; - -extern int lastTouchX; -extern int lastTouchY; +extern int currentInput; extern u32 kHeld; -extern int currentInput; - typedef struct { enum active_input_t { INPUT_TOUCH = 0, + INPUT_CPAD, INPUT_QTM, INPUT_LAST }; @@ -52,7 +44,6 @@ typedef struct }qtm_state_t; extern qtm_state_t qtm_state; - void ctr_init_qtm(); void ctr_exit_qtm(); void ctr_input_frame(); diff --git a/src/plib/gnw/input.cc b/src/plib/gnw/input.cc index 7b466e1..11d52f9 100644 --- a/src/plib/gnw/input.cc +++ b/src/plib/gnw/input.cc @@ -1097,31 +1097,14 @@ void GNW95_process_message() KeyboardData keyboardData; SDL_Event e; while (SDL_PollEvent(&e)) { - #ifdef __3DS__ - if (e.type == SDL_FINGERDOWN || e.type == SDL_FINGERUP || e.type == SDL_FINGERMOTION) { - - touchX = e.tfinger.x * 320; - touchY = e.tfinger.y * 240; - - offsetX = (int)touchX * MAX_OFFSET_X / 320; - offsetY = (int)touchY * MAX_OFFSET_Y / 240; - - lastTouchX = -offsetX; - lastTouchY = -offsetY; + if ((e.type == SDL_FINGERDOWN || e.type == SDL_FINGERUP || e.type == SDL_FINGERMOTION) && (currentInput==ctr_input_t::INPUT_TOUCH) ){ + int touchX = e.tfinger.x * 320; + int touchY = e.tfinger.y * 240; - if (lastTouchX > 0) { - lastTouchX = 0; - } else if (lastTouchX - 400 < -640) { - lastTouchX = -640 + 400; + offsetX = (int)touchX * MAX_OFFSET_X / 320; + offsetY = (int)touchY * MAX_OFFSET_Y / 240; } - - if (lastTouchY > 0) { - lastTouchY = 0; - } else if (lastTouchY - 240 < -480) { - lastTouchY = -480 + 240; - } - } #endif switch (e.type) { diff --git a/src/plib/gnw/svga.cc b/src/plib/gnw/svga.cc index 0536c56..f1ab9a0 100644 --- a/src/plib/gnw/svga.cc +++ b/src/plib/gnw/svga.cc @@ -36,36 +36,10 @@ SDL_Surface* gSdlTextureSurface = NULL; SDL_Window* gSdlWindow2 = NULL; SDL_Renderer* gSdlRenderer2 = NULL; -SDL_Rect sourceRect1 = {0, 0, 640, 480}; SDL_Rect sourceRect2 = {0, 0, 640, 480}; - -SDL_Rect destRect1 = {0, 0, 400, 240}; SDL_Rect destRect2 = {0, 0, 320, 240}; SDL_Surface* surface2 = SDL_CreateRGBSurface(0, 640, 480, 32, 0, 0, 0, 0); - -TextureInfo* textureInfos = NULL; -int numTextureInfos = 0; - -void addTextureInfo(TextureInfo** textureInfos, int* numTextureInfos, const SDL_Rect* srcRect, const SDL_Rect* dstRect) { - *numTextureInfos += 1; - *textureInfos = (TextureInfo*)realloc(*textureInfos, (*numTextureInfos) * sizeof(TextureInfo)); - (*textureInfos)[*numTextureInfos - 1].srcRect = *srcRect; - (*textureInfos)[*numTextureInfos - 1].dstRect = *dstRect; -} - -void removeTextureInfo(TextureInfo** textureInfos, int* numTextureInfos, int index) { - if (index < 0 || index >= *numTextureInfos) { - return; - } - - for (int i = index; i < *numTextureInfos - 1; ++i) { - (*textureInfos)[i] = (*textureInfos)[i + 1]; - } - - *numTextureInfos -= 1; - *textureInfos = (TextureInfo*)realloc(*textureInfos, (*numTextureInfos) * sizeof(TextureInfo)); -} #endif // TODO: Remove once migration to update-render cycle is completed. @@ -222,6 +196,8 @@ int GNW95_init_window(int width, int height, bool fullscreen, int scale) } #ifdef __3DS__ + initializeDisplayRectMap(); + int numDisplays = SDL_GetNumVideoDisplays(); if (numDisplays < 2) { SDL_Quit(); @@ -425,83 +401,6 @@ static bool createRenderer(int width, int height) return false; } -#ifdef __3DS__ - numTextureInfos = 0; - - SDL_Rect srcRectTmp; - SDL_Rect dstRectTmp; - - // FIELD - srcRectTmp = { 0, 0, 640, 380 }; // x, y, w, h - dstRectTmp = { 0, 0, 320, 190 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // BOTTOM CONSOLE 1/3 - srcRectTmp = { 5, 380, 200, 100 }; - dstRectTmp = { 0, 10, 200, 100 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // BOTTOM WEAPON 2/3 - srcRectTmp = { 200, 380, 320, 100 }; - dstRectTmp = { 0, 140, 320, 100 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // BOTTOM PIP SKILLDEX 3/3 - srcRectTmp = { 520, 380, 140, 100 }; - dstRectTmp = { 200, 10, 120, 100 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // MOVIE - srcRectTmp = { 0, 0, 640, 480 }; - dstRectTmp = { 0, 0, 320, 240 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // SKILLDEX 1/2 - srcRectTmp = { 452, 5, 250, 190 }; - dstRectTmp = { 0, 0, 160, 190 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // SKILLDEX 2/2 - srcRectTmp = { 452, 190, 250, 180 }; - dstRectTmp = { 160, 40, 160, 180 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // MAIN - srcRectTmp = { 400, 25, 215, 220 }; - dstRectTmp = { 55, 0, 215, 240 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // PAUSE - srcRectTmp = { 240, 72, 160, 215 }; - dstRectTmp = { 55, 0, 215, 240 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // PAUSE CONFIRM - srcRectTmp = { 100, 120, 320, 215 }; - dstRectTmp = { 55, 0, 215, 215 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // DIALOG_TOP - srcRectTmp = { 80, 0, 480, 300 }; - dstRectTmp = { 0, 0, 400, 240 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // DIALOG_BOTTOM - srcRectTmp = { 80, 300, 480, 180 }; - dstRectTmp = { 0, 0, 320, 180 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // DIALOG_BOTTOM_LEFT - srcRectTmp = { 0, 260, 80, 220 }; - dstRectTmp = { 0, 0, 320, 240 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); - - // DIALOG_BOTTOM_RIGHT - srcRectTmp = { 560, 260, 80, 220 }; - dstRectTmp = { 0, 0, 320, 240 }; - addTextureInfo(&textureInfos, &numTextureInfos, &srcRectTmp, &dstRectTmp); -#endif - return true; } @@ -526,7 +425,6 @@ static void destroyRenderer() SDL_DestroyRenderer(gSdlRenderer2); gSdlRenderer2 = NULL; } - free(textureInfos); #endif } @@ -540,15 +438,12 @@ void renderPresent() { SDL_UpdateTexture(gSdlTexture, NULL, gSdlTextureSurface->pixels, gSdlTextureSurface->pitch); #ifdef __3DS__ - -// top screen - +/* top screen */ SDL_Rect sourceRect; SDL_Rect destRect; SDL_RenderClear(gSdlRenderer); - switch (ctr_display.active) { case ctr_display_t::DISPLAY_SPLASH: @@ -568,22 +463,27 @@ void renderPresent() } case ctr_display_t::DISPLAY_DIALOG: { - TextureInfo* textureInfo = &textureInfos[10]; - sourceRect = textureInfo->srcRect; - destRect = textureInfo->dstRect; + std::vector& dialogRects = displayRectMap[ctr_display_t::DISPLAY_DIALOG_TOP]; + if (!dialogRects.empty()) { + const DisplayRect& firstRect = dialogRects.front(); + sourceRect = firstRect.srcRect; + destRect = firstRect.dstRect; + SDL_RenderCopy(gSdlRenderer, gSdlTexture, &sourceRect, &destRect); + + const DisplayRect& secondRect = dialogRects[1]; + sourceRect = secondRect.srcRect; + destRect = secondRect.dstRect; + } break; } default: switch (currentInput) { case ctr_input_t::INPUT_TOUCH: - { - sourceRect = { offsetX, offsetY, 400, 240 }; - break; - } case ctr_input_t::INPUT_QTM: + case ctr_input_t::INPUT_CPAD: { - sourceRect = { qtm_offsetX, qtm_offsetY, 400, 240 }; + sourceRect = { offsetX, offsetY, 400, 240 }; break; } default: @@ -594,15 +494,14 @@ void renderPresent() destRect = { 0, 0, 400, 240 }; break; } + SDL_RenderCopy(gSdlRenderer, gSdlTexture, &sourceRect, &destRect); SDL_RenderPresent(gSdlRenderer); - -// bottom screen - SDL_RenderClear(gSdlRenderer2); +/* bottom screen */ SDL_BlitSurface(gSdlTextureSurface, &sourceRect2, surface2, &destRect2); - SDL_Texture* surfaceTexture2 = SDL_CreateTextureFromSurface(gSdlRenderer2, surface2); + SDL_RenderClear(gSdlRenderer2); switch (ctr_display.active) { @@ -611,69 +510,31 @@ void renderPresent() SDL_RenderCopy(gSdlRenderer2, surfaceTexture2, NULL, NULL); break; } - case ctr_display_t::DISPLAY_FIELD: - { - TextureInfo* textureInfo = &textureInfos[0]; - SDL_RenderCopy(gSdlRenderer2, surfaceTexture2, &textureInfo->srcRect, &textureInfo->dstRect); - break; - } - case ctr_display_t::DISPLAY_GUI: - { - for (int i = 1; i < 4; ++i) { - TextureInfo* textureInfo = &textureInfos[i]; - SDL_RenderCopy(gSdlRenderer2, surfaceTexture2, &textureInfo->srcRect, &textureInfo->dstRect); - } - break; - } case ctr_display_t::DISPLAY_SPLASH: case ctr_display_t::DISPLAY_MOVIE: { -// SDL_RenderCopy(gSdlRenderer2, surfaceTexture2, NULL, NULL); - break; - } - case ctr_display_t::DISPLAY_SKILLDEX: - { - for (int i = 5; i < 7; ++i) { - TextureInfo* textureInfo = &textureInfos[i]; - SDL_RenderCopy(gSdlRenderer2, surfaceTexture2, &textureInfo->srcRect, &textureInfo->dstRect); - } - break; - } - case ctr_display_t::DISPLAY_MAIN: - { - TextureInfo* textureInfo = &textureInfos[7]; - SDL_RenderCopy(gSdlRenderer2, surfaceTexture2, &textureInfo->srcRect, &textureInfo->dstRect); - break; - } - case ctr_display_t::DISPLAY_PAUSE: - { - TextureInfo* textureInfo = &textureInfos[8]; - SDL_RenderCopy(gSdlRenderer2, surfaceTexture2, &textureInfo->srcRect, &textureInfo->dstRect); - break; - } - case ctr_display_t::DISPLAY_PAUSE_CONFIRM: - { - TextureInfo* textureInfo = &textureInfos[9]; - SDL_RenderCopy(gSdlRenderer2, surfaceTexture2, &textureInfo->srcRect, &textureInfo->dstRect); break; } case ctr_display_t::DISPLAY_DIALOG: { - TextureInfo* textureInfo = &textureInfos[11]; - SDL_RenderCopy(gSdlRenderer2, surfaceTexture2, &textureInfo->srcRect, &textureInfo->dstRect); - break; + std::vector& dialogRects = displayRectMap[ctr_display_t::DISPLAY_DIALOG_BACK]; + if (!dialogRects.empty()) { + const DisplayRect& firstRect = dialogRects.front(); + sourceRect = firstRect.srcRect; + destRect = firstRect.dstRect; + SDL_RenderCopy(gSdlRenderer2, surfaceTexture2, &sourceRect, &destRect); + } } + default: - for (int i = 0; i < numTextureInfos; ++i) { - TextureInfo* textureInfo = &textureInfos[i]; - SDL_RenderCopy(gSdlRenderer2, surfaceTexture2, &textureInfo->srcRect, &textureInfo->dstRect); + std::vector& displayRects = displayRectMap[ctr_display.active]; + for (const DisplayRect& displayRect : displayRects) { + SDL_RenderCopy(gSdlRenderer2, surfaceTexture2, &displayRect.srcRect, &displayRect.dstRect); } break; } - SDL_RenderPresent(gSdlRenderer2); - - + SDL_RenderPresent(gSdlRenderer2); SDL_DestroyTexture(surfaceTexture2); #else SDL_RenderClear(gSdlRenderer); diff --git a/src/plib/gnw/touch.cc b/src/plib/gnw/touch.cc index 87c4197..0694609 100644 --- a/src/plib/gnw/touch.cc +++ b/src/plib/gnw/touch.cc @@ -287,46 +287,20 @@ void touch_process_gesture() switch (ctr_display.active) { - case ctr_display_t::DISPLAY_FIELD: - { - convertTouchToTextureCoordinates(touch.px, touch.py, textureInfos, 0, 1, &newX, &newY); - break; - } + case ctr_display_t::DISPLAY_MAIN: + case ctr_display_t::DISPLAY_FIELD: case ctr_display_t::DISPLAY_GUI: - { - convertTouchToTextureCoordinates(touch.px, touch.py, textureInfos, 1, 3, &newX, &newY); - break; - } case ctr_display_t::DISPLAY_SKILLDEX: - { - convertTouchToTextureCoordinates(touch.px, touch.py, textureInfos, 5, 2, &newX, &newY); - break; - } - case ctr_display_t::DISPLAY_MAIN: - { - convertTouchToTextureCoordinates(touch.px, touch.py, textureInfos, 7, 1, &newX, &newY); - break; - } case ctr_display_t::DISPLAY_PAUSE: - { - convertTouchToTextureCoordinates(touch.px, touch.py, textureInfos, 8, 1, &newX, &newY); - break; - } case ctr_display_t::DISPLAY_PAUSE_CONFIRM: - { - convertTouchToTextureCoordinates(touch.px, touch.py, textureInfos, 9, 1, &newX, &newY); - break; - } case ctr_display_t::DISPLAY_DIALOG: - { - convertTouchToTextureCoordinates(touch.px, touch.py, textureInfos, 11, 1, &newX, &newY); + convertTouchToTextureCoordinates(touch.px, touch.py, ctr_display.active, &newX, &newY); break; - } + default: newX = (touch.px * screenGetWidth()) / 320; newY = (touch.py * screenGetHeight()) / 240; - // hackey scrollling, the edge is hard to reach.. if (newX < 15) newX = 0; if (newY < 15) newY = 0;