diff --git a/build-windows-visual-studio/sm64ex.vcxproj b/build-windows-visual-studio/sm64ex.vcxproj index 44599c174..419c30e53 100644 --- a/build-windows-visual-studio/sm64ex.vcxproj +++ b/build-windows-visual-studio/sm64ex.vcxproj @@ -99,7 +99,7 @@ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;DEBUG;%(PreprocessorDefinitions) true @@ -3930,6 +3930,7 @@ + @@ -4305,6 +4306,7 @@ + diff --git a/build-windows-visual-studio/sm64ex.vcxproj.filters b/build-windows-visual-studio/sm64ex.vcxproj.filters index e81a80252..2579529df 100644 --- a/build-windows-visual-studio/sm64ex.vcxproj.filters +++ b/build-windows-visual-studio/sm64ex.vcxproj.filters @@ -15012,6 +15012,9 @@ Source Files\src\pc\network\packets + + Source Files\src\pc\controller + @@ -15931,5 +15934,8 @@ Source Files\src\pc + + Source Files\src\pc\controller + \ No newline at end of file diff --git a/src/pc/controller/controller_keyboard.c b/src/pc/controller/controller_keyboard.c index 08d0676c0..f4692a92b 100644 --- a/src/pc/controller/controller_keyboard.c +++ b/src/pc/controller/controller_keyboard.c @@ -10,16 +10,24 @@ #include "../configfile.h" #include "controller_keyboard.h" +#include "controller_keyboard_debug.h" #include "pc/gfx/gfx_window_manager_api.h" #include "pc/pc_main.h" #include "engine/math_util.h" +// TODO: use some common lookup header #define SCANCODE_BACKSPACE 0x0E -#define SCANCODE_ESCAPE 0x01 -#define SCANCODE_ENTER 0x1C -#define SCANCODE_V 0x2F -#define SCANCODE_INSERT 0x152 +#define SCANCODE_ESCAPE 0x01 +#define SCANCODE_ENTER 0x1C +#define SCANCODE_V 0x2F +#define SCANCODE_INSERT 0x152 +#define SCANCODE_CTRL1 0x1D +#define SCANCODE_CTRL2 0x11D +#define SCANCODE_SHIFT1 0x2A +#define SCANCODE_SHIFT2 0x36 +#define SCANCODE_ALT1 0x38 +#define SCANCODE_ALT2 0x138 static int keyboard_buttons_down; @@ -50,26 +58,29 @@ static int keyboard_map_scancode(int scancode) { static void keyboard_alter_text_input_modifier(int scancode, bool down) { if (down) { switch (scancode) { - case 0x1D: held_ctrl |= (1 << 0); break; - case 0x11D: held_ctrl |= (1 << 1); break; - case 0x2A: held_shift |= (1 << 0); break; - case 0x36: held_shift |= (1 << 1); break; - case 0x38: held_alt |= (1 << 0); break; - case 0x138: held_alt |= (1 << 1); break; + case SCANCODE_CTRL1: held_ctrl |= (1 << 0); break; + case SCANCODE_CTRL2: held_ctrl |= (1 << 1); break; + case SCANCODE_SHIFT1: held_shift |= (1 << 0); break; + case SCANCODE_SHIFT2: held_shift |= (1 << 1); break; + case SCANCODE_ALT1: held_alt |= (1 << 0); break; + case SCANCODE_ALT2: held_alt |= (1 << 1); break; } } else { switch (scancode) { - case 0x1D: held_ctrl &= ~(1 << 0); break; - case 0x11D: held_ctrl &= ~(1 << 1); break; - case 0x2A: held_shift &= ~(1 << 0); break; - case 0x36: held_shift &= ~(1 << 1); break; - case 0x38: held_alt &= ~(1 << 0); break; - case 0x138: held_alt &= ~(1 << 1); break; + case SCANCODE_CTRL1: held_ctrl &= ~(1 << 0); break; + case SCANCODE_CTRL2: held_ctrl &= ~(1 << 1); break; + case SCANCODE_SHIFT1: held_shift &= ~(1 << 0); break; + case SCANCODE_SHIFT2: held_shift &= ~(1 << 1); break; + case SCANCODE_ALT1: held_alt &= ~(1 << 0); break; + case SCANCODE_ALT2: held_alt &= ~(1 << 1); break; } } } bool keyboard_on_key_down(int scancode) { +#ifdef DEBUG + debug_keyboard_on_key_down(scancode); +#endif if (inTextInput) { // alter the held value of modifier keys keyboard_alter_text_input_modifier(scancode, true); @@ -234,16 +245,7 @@ static void keyboard_init(void) { #endif } -static void debug_breakpoint_here(void) { - // create easy breakpoint position for debugging -} - static void keyboard_read(OSContPad *pad) { - // create easy breakpoint position for debugging - if (keyboard_buttons_down & L_TRIG) { - debug_breakpoint_here(); - } - pad->button |= keyboard_buttons_down; const u32 xstick = keyboard_buttons_down & STICK_XMASK; const u32 ystick = keyboard_buttons_down & STICK_YMASK; diff --git a/src/pc/controller/controller_keyboard_debug.c b/src/pc/controller/controller_keyboard_debug.c new file mode 100644 index 000000000..f623b2e48 --- /dev/null +++ b/src/pc/controller/controller_keyboard_debug.c @@ -0,0 +1,101 @@ +#include "controller_keyboard_debug.h" +#include "game/level_update.h" +#include "game/camera.h" +#include "pc/network/network.h" + +#ifdef DEBUG + +static u8 warpToLevel = LEVEL_BITDW; + +#define SCANCODE_3 0x04 +#define SCANCODE_6 0x07 +#define SCANCODE_7 0x08 + +static void debug_breakpoint_here(void) { + // create easy breakpoint position for debugging +} + +static void debug_warp_level(u8 level) { + if (sCurrPlayMode == PLAY_MODE_CHANGE_LEVEL) { return; } + if (sCurrPlayMode == PLAY_MODE_SYNC_LEVEL) { return; } + + // find level from painting + for (int i = 0; i < 45; i++) { + struct WarpNode* node = &gCurrentArea->paintingWarpNodes[i]; + if (node == NULL) { break; } + if (node->destLevel == level) { + sWarpDest.type = WARP_TYPE_CHANGE_LEVEL; + sWarpDest.levelNum = node->destLevel; + sWarpDest.areaIdx = node->destArea; + sWarpDest.nodeId = node->destNode; + sWarpDest.arg = 0; + + sCurrPlayMode = (gNetworkType != NT_NONE) ? PLAY_MODE_SYNC_LEVEL : PLAY_MODE_CHANGE_LEVEL; + network_send_level_warp_begin(); + return; + } + } + + struct ObjectWarpNode* objectNode = gCurrentArea->warpNodes; + while (objectNode != NULL) { + struct WarpNode* node = &objectNode->node; + if (node->destLevel == level) { + sWarpDest.type = WARP_TYPE_CHANGE_LEVEL; + sWarpDest.levelNum = node->destLevel; + sWarpDest.areaIdx = node->destArea; + sWarpDest.nodeId = node->destNode; + sWarpDest.arg = 0; + + sCurrPlayMode = (gNetworkType != NT_NONE) ? PLAY_MODE_SYNC_LEVEL : PLAY_MODE_CHANGE_LEVEL; + network_send_level_warp_begin(); + return; + } + objectNode = objectNode->next; + } + + // failed, go to main castle area + sWarpDest.type = WARP_TYPE_CHANGE_LEVEL; + sWarpDest.levelNum = LEVEL_CASTLE; + sWarpDest.areaIdx = 1; + sWarpDest.nodeId = 0x1F; + sWarpDest.arg = 0; + sCurrPlayMode = PLAY_MODE_SYNC_LEVEL; + D_80339ECA = 0; + D_80339EE0 = 0; + extern s16 gSavedCourseNum; + gSavedCourseNum = 0; + network_send_level_warp_begin(); +} + +static void debug_warp_area() { + if (sCurrPlayMode == PLAY_MODE_CHANGE_LEVEL) { return; } + if (sCurrPlayMode == PLAY_MODE_SYNC_LEVEL) { return; } + + struct ObjectWarpNode* objectNode = gCurrentArea->warpNodes; + while (objectNode != NULL) { + struct WarpNode* node = &objectNode->node; + if (node->destLevel == gCurrLevelNum && node->destArea != gCurrAreaIndex) { + sWarpDest.type = WARP_TYPE_CHANGE_AREA; + sWarpDest.levelNum = node->destLevel; + sWarpDest.areaIdx = node->destArea; + sWarpDest.nodeId = node->destNode; + sWarpDest.arg = 0; + + sCurrPlayMode = (gNetworkType != NT_NONE) ? PLAY_MODE_SYNC_LEVEL : PLAY_MODE_CHANGE_LEVEL; + network_send_level_warp_begin(); + return; + } + objectNode = objectNode->next; + } +} + +void debug_keyboard_on_key_down(int scancode) { + scancode = scancode; + switch (scancode) { + case SCANCODE_3: debug_breakpoint_here(); break; + case SCANCODE_6: debug_warp_level(warpToLevel); break; + case SCANCODE_7: debug_warp_area(); break; + } +} + +#endif \ No newline at end of file diff --git a/src/pc/controller/controller_keyboard_debug.h b/src/pc/controller/controller_keyboard_debug.h new file mode 100644 index 000000000..ad0458e0e --- /dev/null +++ b/src/pc/controller/controller_keyboard_debug.h @@ -0,0 +1,8 @@ +#ifndef CONTROLLER_KEYBOARD_DEBUG_H +#define CONTROLLER_KEYBOARD_DEBUG_H +#ifdef DEBUG + +void debug_keyboard_on_key_down(int scancode); + +#endif +#endif diff --git a/src/pc/network/packets/packet_level_warp.c b/src/pc/network/packets/packet_level_warp.c index 45d7df58b..16aa628b9 100644 --- a/src/pc/network/packets/packet_level_warp.c +++ b/src/pc/network/packets/packet_level_warp.c @@ -44,7 +44,6 @@ static void populate_packet_data(struct PacketLevelWarpData* data, bool done, u8 } void network_send_level_warp_begin(void) { - assert(!isInWarp); isInWarp = TRUE; savedWarpNode = sWarpDest; saved_D_80339EE0 = D_80339EE0;