diff --git a/include/common/Exception.hpp b/include/common/Exception.hpp index ba931409..55cd0bef 100644 --- a/include/common/Exception.hpp +++ b/include/common/Exception.hpp @@ -28,7 +28,7 @@ namespace love std::string message; }; -#if __DEBUG__ +#if 1 #include // Macro to log to both stdout and a debug.log file diff --git a/include/modules/joystick/Joystick.tcc b/include/modules/joystick/Joystick.tcc index de910950..aa7fa307 100644 --- a/include/modules/joystick/Joystick.tcc +++ b/include/modules/joystick/Joystick.tcc @@ -55,6 +55,8 @@ namespace love GAMEPAD_BUTTON_DPAD_RIGHT, GAMEPAD_BUTTON_MISC1, GAMEPAD_BUTTON_MISC2, + GAMEPAD_BUTTON_Z, //< Nunchuk only + GAMEPAD_BUTTON_C, //< Nunchuk only GAMEPAD_BUTTON_MAX_ENUM }; @@ -190,23 +192,25 @@ namespace love // clang-format off STRINGMAP_DECLARE(GamepadButtons, GamepadButton, - { "a", GAMEPAD_BUTTON_A }, - { "b", GAMEPAD_BUTTON_B }, - { "x", GAMEPAD_BUTTON_X }, - { "y", GAMEPAD_BUTTON_Y }, - { "back", GAMEPAD_BUTTON_BACK }, - { "guide", GAMEPAD_BUTTON_GUIDE }, - { "start", GAMEPAD_BUTTON_START }, - { "leftstick", GAMEPAD_BUTTON_LEFTSTICK }, - { "rightstick", GAMEPAD_BUTTON_RIGHTSTICK }, - { "leftshoulder", GAMEPAD_BUTTON_LEFTSHOULDER }, - { "rightshoulder", GAMEPAD_BUTTON_RIGHTSHOULDER }, - { "dpup", GAMEPAD_BUTTON_DPAD_UP }, - { "dpdown", GAMEPAD_BUTTON_DPAD_DOWN }, - { "dpleft", GAMEPAD_BUTTON_DPAD_LEFT }, - { "dpright", GAMEPAD_BUTTON_DPAD_RIGHT }, - { "misc1", GAMEPAD_BUTTON_MISC1 }, - { "misc2", GAMEPAD_BUTTON_MISC2 } + { "a", GAMEPAD_BUTTON_A }, + { "b", GAMEPAD_BUTTON_B }, + { "x", GAMEPAD_BUTTON_X }, + { "y", GAMEPAD_BUTTON_Y }, + { "back", GAMEPAD_BUTTON_BACK }, + { "guide", GAMEPAD_BUTTON_GUIDE }, + { "start", GAMEPAD_BUTTON_START }, + { "leftstick", GAMEPAD_BUTTON_LEFTSTICK }, + { "rightstick", GAMEPAD_BUTTON_RIGHTSTICK }, + { "leftshoulder", GAMEPAD_BUTTON_LEFTSHOULDER }, + { "rightshoulder", GAMEPAD_BUTTON_RIGHTSHOULDER }, + { "dpup", GAMEPAD_BUTTON_DPAD_UP }, + { "dpdown", GAMEPAD_BUTTON_DPAD_DOWN }, + { "dpleft", GAMEPAD_BUTTON_DPAD_LEFT }, + { "dpright", GAMEPAD_BUTTON_DPAD_RIGHT }, + { "misc1", GAMEPAD_BUTTON_MISC1 }, + { "misc2", GAMEPAD_BUTTON_MISC2 }, + { "z", GAMEPAD_BUTTON_Z }, //< Nunchuk only + { "c", GAMEPAD_BUTTON_C } //< Nunchuk only ); STRINGMAP_DECLARE(GamepadAxes, GamepadAxis, @@ -219,29 +223,29 @@ namespace love ); STRINGMAP_DECLARE(InputTypes, InputType, - { "axis", INPUT_TYPE_AXIS }, - { "button", INPUT_TYPE_BUTTON }, - { "hat", INPUT_TYPE_HAT } + { "axis", INPUT_TYPE_AXIS }, + { "button", INPUT_TYPE_BUTTON }, + { "hat", INPUT_TYPE_HAT } ); STRINGMAP_DECLARE(GamepadTypes, GamepadType, - { "unknown", GAMEPAD_TYPE_UNKNOWN }, - { "3ds", GAMEPAD_TYPE_NINTENDO_3DS }, - { "3dsxl", GAMEPAD_TYPE_NINTENDO_3DS_XL }, - { "new3ds", GAMEPAD_TYPE_NEW_NINTENDO_3DS }, - { "new3dsxl", GAMEPAD_TYPE_NEW_NINTENDO_3DS_XL }, - { "2ds", GAMEPAD_TYPE_NINTENDO_2DS }, - { "new2dsxl", GAMEPAD_TYPE_NEW_NINTENDO_2DS_XL }, - { "wiiremote", GAMEPAD_TYPE_NINTENDO_WII_REMOTE }, - { "wiiremotenunchuck", GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK }, - { "wiiclassic", GAMEPAD_TYPE_NINTENDO_WII_CLASSIC }, - { "wiiugamepad", GAMEPAD_TYPE_NINTENDO_WII_U_GAMEPAD }, - { "wiiupro", GAMEPAD_TYPE_NINTENDO_WII_U_PRO }, - { "switchhandheld", GAMEPAD_TYPE_NINTENDO_SWITCH_HANDHELD }, - { "switchpro", GAMEPAD_TYPE_NINTENDO_SWITCH_PRO }, - { "joyconleft", GAMEPAD_TYPE_JOYCON_LEFT }, - { "joyconright", GAMEPAD_TYPE_JOYCON_RIGHT }, - { "joyconpair", GAMEPAD_TYPE_JOYCON_PAIR } + { "unknown", GAMEPAD_TYPE_UNKNOWN }, + { "3ds", GAMEPAD_TYPE_NINTENDO_3DS }, + { "3dsxl", GAMEPAD_TYPE_NINTENDO_3DS_XL }, + { "new3ds", GAMEPAD_TYPE_NEW_NINTENDO_3DS }, + { "new3dsxl", GAMEPAD_TYPE_NEW_NINTENDO_3DS_XL }, + { "2ds", GAMEPAD_TYPE_NINTENDO_2DS }, + { "new2dsxl", GAMEPAD_TYPE_NEW_NINTENDO_2DS_XL }, + { "wiiremote", GAMEPAD_TYPE_NINTENDO_WII_REMOTE }, + { "wiiremotenunchuk", GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK }, + { "wiiclassic", GAMEPAD_TYPE_NINTENDO_WII_CLASSIC }, + { "wiiugamepad", GAMEPAD_TYPE_NINTENDO_WII_U_GAMEPAD }, + { "wiiupro", GAMEPAD_TYPE_NINTENDO_WII_U_PRO }, + { "switchhandheld", GAMEPAD_TYPE_NINTENDO_SWITCH_HANDHELD }, + { "switchpro", GAMEPAD_TYPE_NINTENDO_SWITCH_PRO }, + { "joyconleft", GAMEPAD_TYPE_JOYCON_LEFT }, + { "joyconright", GAMEPAD_TYPE_JOYCON_RIGHT }, + { "joyconpair", GAMEPAD_TYPE_JOYCON_PAIR } ); STRINGMAP_DECLARE(JoystickTypes, JoystickType, diff --git a/include/utility/guid.hpp b/include/utility/guid.hpp index 0165e447..376d348b 100644 --- a/include/utility/guid.hpp +++ b/include/utility/guid.hpp @@ -24,7 +24,7 @@ namespace love GAMEPAD_TYPE_NINTENDO_2DS, GAMEPAD_TYPE_NEW_NINTENDO_2DS_XL, GAMEPAD_TYPE_NINTENDO_WII_REMOTE, - GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK, + GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK, GAMEPAD_TYPE_NINTENDO_WII_CLASSIC, GAMEPAD_TYPE_NINTENDO_WII_U_GAMEPAD, GAMEPAD_TYPE_NINTENDO_WII_U_PRO, diff --git a/platform/cafe/include/driver/display/Framebuffer.hpp b/platform/cafe/include/driver/display/Framebuffer.hpp index 0d8eda37..074aaf49 100644 --- a/platform/cafe/include/driver/display/Framebuffer.hpp +++ b/platform/cafe/include/driver/display/Framebuffer.hpp @@ -49,11 +49,6 @@ namespace love void copyScanBuffer(); - operator GX2ContextState*() - { - return this->state; - } - private: static constexpr auto FORMAT = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8; static constexpr auto BUFFER_MODE = GX2_BUFFERING_MODE_DOUBLE; @@ -66,11 +61,10 @@ namespace love uint8_t renderMode; GX2ScanTarget id; - Uniform* uniform; + Uniform* uniform = nullptr; + glm::mat4 tmpModel; void* scanBuffer; uint32_t scanBufferSize; - - GX2ContextState* state; }; } // namespace love diff --git a/platform/cafe/include/driver/display/Uniform.hpp b/platform/cafe/include/driver/display/Uniform.hpp index c4c835b0..40b57bfc 100644 --- a/platform/cafe/include/driver/display/Uniform.hpp +++ b/platform/cafe/include/driver/display/Uniform.hpp @@ -1,5 +1,6 @@ #pragma once +#include "common/Exception.hpp" #include "common/Matrix.hpp" #include @@ -11,32 +12,9 @@ namespace love { glm::mat4 modelView; glm::mat4 projection; - - void debug() - { - const auto count = sizeof(glm::mat4) / sizeof(uint32_t); - - uint32_t* model = (uint32_t*)glm::value_ptr(this->modelView); - for (size_t index = 0; index < count; index++) - std::printf("modelView[%zu] = %u\n", index, model[index]); - - uint32_t* projection = (uint32_t*)glm::value_ptr(this->projection); - for (size_t index = 0; index < count; index++) - std::printf("projection[%zu] = %u\n", index, projection[index]); - } - - void update(const Matrix4& matrix) - { - const auto count = sizeof(glm::mat4) / sizeof(uint32_t); - uint32_t* destination = (uint32_t*)glm::value_ptr(this->modelView); - - glm::mat4 sourceMatrix = glm::transpose(glm::make_mat4(matrix.getElements())); - uint32_t* source = (uint32_t*)glm::value_ptr(sourceMatrix); - - for (int i = 0; i < count; ++i) - destination[i] = __builtin_bswap32(source[i]); - } }; + void debugUniform(Uniform* uniform); + static constexpr auto UNIFORM_SIZE = sizeof(Uniform); } // namespace love diff --git a/platform/cafe/include/driver/graphics/StreamBuffer.hpp b/platform/cafe/include/driver/graphics/StreamBuffer.hpp index f5d81e97..4130480d 100644 --- a/platform/cafe/include/driver/graphics/StreamBuffer.hpp +++ b/platform/cafe/include/driver/graphics/StreamBuffer.hpp @@ -33,6 +33,10 @@ namespace love throw love::Exception("Failed to create StreamBuffer"); } + StreamBuffer(StreamBuffer&&) = delete; + + StreamBuffer& operator=(const StreamBuffer&) = delete; + ~StreamBuffer() { GX2RDestroyBufferEx(&this->buffer, GX2R_RESOURCE_BIND_NONE); diff --git a/platform/cafe/include/modules/joystick/kpad/Joystick.hpp b/platform/cafe/include/modules/joystick/kpad/Joystick.hpp index 8b13c5b7..9a62ac7f 100644 --- a/platform/cafe/include/modules/joystick/kpad/Joystick.hpp +++ b/platform/cafe/include/modules/joystick/kpad/Joystick.hpp @@ -94,7 +94,8 @@ namespace love // clang-format off ENUMMAP_DECLARE(NunchuckButtons, GamepadButton, WPADNunchukButton, - { GAMEPAD_BUTTON_LEFTSHOULDER, WPAD_NUNCHUK_BUTTON_C } + { GAMEPAD_BUTTON_C, WPAD_NUNCHUK_BUTTON_C }, + { GAMEPAD_BUTTON_Z, WPAD_NUNCHUK_BUTTON_Z } ); ENUMMAP_DECLARE(NunchuckAxes, GamepadAxis, NunchuckAxis, diff --git a/platform/cafe/source/driver/display/Framebuffer.cpp b/platform/cafe/source/driver/display/Framebuffer.cpp index 5e5a0369..c2aa60f5 100644 --- a/platform/cafe/source/driver/display/Framebuffer.cpp +++ b/platform/cafe/source/driver/display/Framebuffer.cpp @@ -15,11 +15,14 @@ namespace love this->uniform->modelView = glm::mat4(1.0f); this->uniform->projection = glm::mat4(1.0f); + + this->tmpModel = glm::mat4(1.0f); } void Framebuffer::destroy() { std::free(this->uniform); + this->uniform = nullptr; } bool Framebuffer::allocateScanBuffer(MEMHeapHandle handle) @@ -127,13 +130,18 @@ namespace love const size_t count = sizeof(glm::mat4) / sizeof(uint32_t); - uint32_t* model = (uint32_t*)glm::value_ptr(glm::mat4(1.0f)); + uint32_t* model = (uint32_t*)glm::value_ptr(this->tmpModel); for (size_t index = 0; index < count; index++) + { + LOG("%lu/%f", model[index], (float)(model[index])); dstModel[index] = __builtin_bswap32(model[index]); + } uint32_t* projection = (uint32_t*)glm::value_ptr(ortho); for (size_t index = 0; index < count; index++) dstProj[index] = __builtin_bswap32(projection[index]); + + love::debugUniform(this->uniform); } void Framebuffer::setScissor(const Rect& scissor) diff --git a/platform/cafe/source/driver/display/GX2.cpp b/platform/cafe/source/driver/display/GX2.cpp index 536d4e12..9074ea81 100644 --- a/platform/cafe/source/driver/display/GX2.cpp +++ b/platform/cafe/source/driver/display/GX2.cpp @@ -146,7 +146,10 @@ namespace love this->context.depthWrite = true; this->context.compareMode = GX2_COMPARE_FUNC_ALWAYS; - this->uniform = (Uniform*)memalign(GX2_UNIFORM_BLOCK_ALIGNMENT, sizeof(Uniform)); + this->uniform = (Uniform*)memalign(GX2_UNIFORM_BLOCK_ALIGNMENT, sizeof(Uniform)); + this->uniform->modelView = glm::mat4(1.0f); + this->uniform->projection = glm::mat4(1.0f); + this->bindFramebuffer(&this->targets[0].get()); this->initialized = true; diff --git a/platform/cafe/source/driver/display/Uniform.cpp b/platform/cafe/source/driver/display/Uniform.cpp index ed28100a..11830db0 100644 --- a/platform/cafe/source/driver/display/Uniform.cpp +++ b/platform/cafe/source/driver/display/Uniform.cpp @@ -2,21 +2,16 @@ namespace love { - glm::mat4 createTransposedSwappedMatrix(const Matrix4& matrix) + void debugUniform(Uniform* uniform) { - const uint32_t count = sizeof(glm::mat4) / sizeof(uint32_t); + const auto count = sizeof(glm::mat4) / sizeof(uint32_t); - // Transpose the input matrix to convert from row-major to column-major - glm::mat4 sourceMatrix = glm::transpose(glm::make_mat4(matrix.getElements())); + uint32_t* model = (uint32_t*)glm::value_ptr(uniform->modelView); + for (size_t index = 0; index < count; index++) + LOG("modelView[%zu] = %u\n", index, model[index]); - // Create a new matrix to hold the endian-swapped version - glm::mat4 resultMatrix; - uint32_t* destination = (uint32_t*)glm::value_ptr(resultMatrix); - const uint32_t* source = (const uint32_t*)glm::value_ptr(sourceMatrix); - - for (int i = 0; i < count; ++i) - destination[i] = __builtin_bswap32(source[i]); - - return resultMatrix; + uint32_t* projection = (uint32_t*)glm::value_ptr(uniform->projection); + for (size_t index = 0; index < count; index++) + LOG("projection[%zu] = %u\n", index, projection[index]); } } // namespace love diff --git a/platform/cafe/source/modules/joystick/kpad/Joystick.cpp b/platform/cafe/source/modules/joystick/kpad/Joystick.cpp index 53d784b7..6ac250da 100644 --- a/platform/cafe/source/modules/joystick/kpad/Joystick.cpp +++ b/platform/cafe/source/modules/joystick/kpad/Joystick.cpp @@ -76,7 +76,7 @@ namespace love } case WPAD_EXT_NUNCHUK: { - this->gamepadType = GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK; + this->gamepadType = GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK; break; } case WPAD_EXT_PRO_CONTROLLER: @@ -138,13 +138,17 @@ namespace love return clamp(this->status.classic.rightStick.y); else if (axis == GAMEPAD_AXIS_TRIGGERLEFT) return this->status.classic.hold & WPAD_CLASSIC_BUTTON_ZL ? 1.0f : 0.0f; + else if (axis == GAMEPAD_AXIS_TRIGGERRIGHT) + return this->status.classic.hold & WPAD_CLASSIC_BUTTON_ZR ? 1.0f : 0.0f; - return this->status.classic.hold & WPAD_CLASSIC_BUTTON_ZR ? 1.0f : 0.0f; + break; } - case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK: + case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK: { - if (axis == GAMEPAD_AXIS_TRIGGERLEFT) - return this->status.nunchuk.hold & WPAD_NUNCHUK_BUTTON_Z ? 1.0f : 0.0f; + if (axis == GAMEPAD_AXIS_LEFTX) + return clamp(this->status.nunchuk.stick.x); + else if (axis == GAMEPAD_AXIS_LEFTY) + return clamp(this->status.nunchuk.stick.y); break; } @@ -160,11 +164,13 @@ namespace love return clamp(this->status.pro.rightStick.y); else if (axis == GAMEPAD_AXIS_TRIGGERLEFT) return this->status.pro.hold & WPAD_PRO_TRIGGER_ZL ? 1.0f : 0.0f; + else if (axis == GAMEPAD_AXIS_TRIGGERRIGHT) + return this->status.pro.hold & WPAD_PRO_TRIGGER_ZR ? 1.0f : 0.0f; - return this->status.pro.hold & WPAD_PRO_TRIGGER_ZR ? 1.0f : 0.0f; + break; } default: - return 0.0f; + break; } return 0.0f; @@ -235,7 +241,7 @@ namespace love { case GAMEPAD_TYPE_NINTENDO_WII_REMOTE: return isButtonDown(buttons); - case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK: + case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK: return isButtonDown(buttons) || isButtonDown(buttons); case GAMEPAD_TYPE_NINTENDO_WII_CLASSIC: return isButtonDown(buttons); @@ -257,7 +263,7 @@ namespace love { case GAMEPAD_TYPE_NINTENDO_WII_REMOTE: return isButtonUp(buttons); - case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK: + case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK: return isButtonUp(buttons) || isButtonUp(buttons); case GAMEPAD_TYPE_NINTENDO_WII_CLASSIC: return isButtonUp(buttons); @@ -296,7 +302,7 @@ namespace love { case GAMEPAD_TYPE_NINTENDO_WII_REMOTE: break; - case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK: + case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK: return isAxisValueChanged(axis); case GAMEPAD_TYPE_NINTENDO_WII_CLASSIC: return isAxisValueChanged(axis); @@ -411,7 +417,7 @@ namespace love data.push_back(this->status.acc.z); break; } - case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK: + case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK: data.push_back(this->status.acc.x); data.push_back(this->status.acc.y); data.push_back(this->status.acc.z); @@ -436,7 +442,7 @@ namespace love switch (this->gamepadType) { case GAMEPAD_TYPE_NINTENDO_WII_REMOTE: - case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK: + case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK: { result[0] = this->status.pos.x; result[1] = this->status.pos.y; @@ -458,7 +464,7 @@ namespace love switch (this->gamepadType) { case GAMEPAD_TYPE_NINTENDO_WII_REMOTE: - case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK: + case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK: { result[0] = this->status.angle.x; result[1] = this->status.angle.y; diff --git a/source/utility/guid.cpp b/source/utility/guid.cpp index 034a1a73..8d11fda8 100644 --- a/source/utility/guid.cpp +++ b/source/utility/guid.cpp @@ -23,7 +23,7 @@ namespace love { 12, 2, 0, "{3846FA8C-25AB-44CB-91FD-D58FB1F572CC}", false, false, true, true }, // GAMEPAD_TYPE_NINTENDO_2DS { 12, 6, 0, "{560CDDB3-0594-4A52-A3D5-617060D2001B}", true, true, true, true }, // GAMEPAD_TYPE_NEW_NINTENDO_2DS_XL { 10, 0, 0, "{02DC4D7B-2480-4678-BB06-D9AEDC3DE29B}", false, false, false, true }, // GAMEPAD_TYPE_NINTENDO_WII_REMOTE - { 12, 2, 0, "{C0E2DDE5-25DF-4F7D-AEA6-4F25DE2FC385}", false, false, false, true }, // GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK + { 12, 2, 0, "{C0E2DDE5-25DF-4F7D-AEA6-4F25DE2FC385}", false, false, false, true }, // GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK { 12, 6, 0, "{B4F6A311-8228-477D-857B-B875D891C46D}", true, true, false, false }, // GAMEPAD_TYPE_NINTENDO_WII_CLASSIC { 14, 6, 0, "{62998927-C43D-41F5-B6B1-D22CBF031D91}", true, true, true, true }, // GAMEPAD_TYPE_WII_U_GAMEPAD { 14, 6, 0, "{36895D3B-A724-4F46-994C-64BCE736EBCB}", true, true, false, false }, // GAMEPAD_TYPE_WII_U_PRO