Skip to content

Commit

Permalink
Update 3DS port
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHuu committed Oct 1, 2023
1 parent 0b94c61 commit 7767bc1
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 322 deletions.
2 changes: 1 addition & 1 deletion src/game/bmpdlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions src/game/editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 3 additions & 6 deletions src/game/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 14 additions & 3 deletions src/game/gdialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -913,7 +913,7 @@ int scr_dialogue_exit()

gdDialogWentOff = true;
#ifdef __3DS__
setPreviousAsCurrent();
ctr_display.active = ctr_display.previous;
#endif
return 0;
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
20 changes: 5 additions & 15 deletions src/game/gmovie.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/game/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 14 additions & 5 deletions src/game/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -414,13 +415,19 @@ 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;
}
break;
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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -466,7 +476,6 @@ setDisplay(ctr_display_t::DISPLAY_PAUSE);
sharedFpsLimiter.throttle();
}
#ifdef __3DS__
// currentDisplay = ctr_display_t::DISPLAY_FULL;
setPreviousAsCurrent();
#endif
OptnEnd();
Expand Down
1 change: 1 addition & 0 deletions src/game/skilldex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ static int skilldex_start()
}

win_draw(skldxwin);

return 0;
}

Expand Down
1 change: 0 additions & 1 deletion src/int/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
83 changes: 67 additions & 16 deletions src/platform/ctr/ctr_gfx.cc
Original file line number Diff line number Diff line change
@@ -1,39 +1,90 @@
#include <string.h>
#include <stdio.h>
#include <iostream>

#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<ctr_display_t::active_display_t, std::vector<DisplayRect>> displayRectMap;

void convertTouchToTextureCoordinates(int tmp_touchX, int tmp_touchY, ctr_display_t::active_display_t displayType, int* originalX, int* originalY) {
const std::vector<DisplayRect>& 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<int>((tmp_touchX - displayRect.dstRect.x) / static_cast<float>(displayRect.dstRect.w) * displayRect.srcRect.w + displayRect.srcRect.x);
*originalY = static_cast<int>((tmp_touchY - displayRect.dstRect.y) / static_cast<float>(displayRect.dstRect.h) * displayRect.srcRect.h + displayRect.srcRect.y);
return;
}
}
*originalX = tmp_touchX;
*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
Loading

0 comments on commit 7767bc1

Please sign in to comment.