From b9303ab13a447a6ff1307d3ee5827aa78ea6ecbf Mon Sep 17 00:00:00 2001 From: NarrikSynthfox <80410683+NarrikSynthfox@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:22:49 -0400 Subject: [PATCH] Controller works mostly now Weird issue if using the same axis on 2 bindings for the same set causes only one to work (left stick x - and + for lane 1 and 2 for example, even though doing that is not a sane way to play this with a controller) --- Encore/include/game/keybinds.h | 198 +++++++++- Encore/include/game/player.h | 4 + Encore/include/game/settings.h | 334 ++++++++++++++++- Encore/src/main.cpp | 652 +++++++++++++++++++++------------ 4 files changed, 928 insertions(+), 260 deletions(-) diff --git a/Encore/include/game/keybinds.h b/Encore/include/game/keybinds.h index 837c7288..493b0a7e 100644 --- a/Encore/include/game/keybinds.h +++ b/Encore/include/game/keybinds.h @@ -1,5 +1,7 @@ #pragma once #include "raylib.h" +#include "GLFW/glfw3.h" +#include "game/settings.h" #include #include @@ -81,5 +83,199 @@ static std::string getKeyStr(int keycode) return keycode == -1 ? "" : "UNK"; } } - +} + +std::unordered_map GenericNames{ + {GLFW_GAMEPAD_BUTTON_CROSS, "A/X"}, + {GLFW_GAMEPAD_BUTTON_CIRCLE, "B/Circle"}, + {GLFW_GAMEPAD_BUTTON_SQUARE, "X/Square"}, + {GLFW_GAMEPAD_BUTTON_TRIANGLE, "Y/Triangle"}, + {GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, "LB"}, + {GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, "RB"}, + {GLFW_GAMEPAD_BUTTON_BACK, "Select"}, + {GLFW_GAMEPAD_BUTTON_START, "Start"}, + {GLFW_GAMEPAD_BUTTON_GUIDE, "Home"}, + {GLFW_GAMEPAD_BUTTON_LEFT_THUMB, "LS"}, + {GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, "RS"}, + {GLFW_GAMEPAD_BUTTON_DPAD_UP, "Up"}, + {GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, "Right"}, + {GLFW_GAMEPAD_BUTTON_DPAD_DOWN, "Down"}, + {GLFW_GAMEPAD_BUTTON_DPAD_LEFT, "Left"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_X),"LS X"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_Y),"LS Y"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_X),"RS X"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_Y),"RS Y"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_TRIGGER),"LT"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER),"RT"} +}; + +std::unordered_map XBOXNames{ + {GLFW_GAMEPAD_BUTTON_A, "A"}, + {GLFW_GAMEPAD_BUTTON_B, "B"}, + {GLFW_GAMEPAD_BUTTON_X, "X"}, + {GLFW_GAMEPAD_BUTTON_Y, "Y"}, + {GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, "LB"}, + {GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, "RB"}, + {GLFW_GAMEPAD_BUTTON_BACK, "Back"}, + {GLFW_GAMEPAD_BUTTON_START, "Start"}, + {GLFW_GAMEPAD_BUTTON_GUIDE, "Guide"}, + {GLFW_GAMEPAD_BUTTON_LEFT_THUMB, "LS"}, + {GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, "RS"}, + {GLFW_GAMEPAD_BUTTON_DPAD_UP, "Up"}, + {GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, "Right"}, + {GLFW_GAMEPAD_BUTTON_DPAD_DOWN, "Down"}, + {GLFW_GAMEPAD_BUTTON_DPAD_LEFT, "Left"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_X),"LS X"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_Y),"LS Y"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_X),"RS X"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_Y),"RS Y"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_TRIGGER),"LT"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER),"RT"} +}; + +std::unordered_map PS1PS2Names{ + {GLFW_GAMEPAD_BUTTON_CROSS, "X"}, + {GLFW_GAMEPAD_BUTTON_CIRCLE, "Circle"}, + {GLFW_GAMEPAD_BUTTON_SQUARE, "Square"}, + {GLFW_GAMEPAD_BUTTON_TRIANGLE, "Triangle"}, + {GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, "L1"}, + {GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, "R1"}, + {GLFW_GAMEPAD_BUTTON_BACK, "Select"}, + {GLFW_GAMEPAD_BUTTON_START, "Start"}, + {GLFW_GAMEPAD_BUTTON_GUIDE, "Analog"}, + {GLFW_GAMEPAD_BUTTON_LEFT_THUMB, "L3"}, + {GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, "R3"}, + {GLFW_GAMEPAD_BUTTON_DPAD_UP, "Up"}, + {GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, "Right"}, + {GLFW_GAMEPAD_BUTTON_DPAD_DOWN, "Down"}, + {GLFW_GAMEPAD_BUTTON_DPAD_LEFT, "Left"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_X),"LS X"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_Y),"LS Y"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_X),"RS X"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_Y),"RS Y"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_TRIGGER),"L2"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER),"R2"} +}; + +std::unordered_map PS3Names{ + {GLFW_GAMEPAD_BUTTON_CROSS, "X"}, + {GLFW_GAMEPAD_BUTTON_CIRCLE, "Circle"}, + {GLFW_GAMEPAD_BUTTON_SQUARE, "Square"}, + {GLFW_GAMEPAD_BUTTON_TRIANGLE, "Triangle"}, + {GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, "L1"}, + {GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, "R1"}, + {GLFW_GAMEPAD_BUTTON_BACK, "Select"}, + {GLFW_GAMEPAD_BUTTON_START, "Start"}, + {GLFW_GAMEPAD_BUTTON_GUIDE, "Home"}, + {GLFW_GAMEPAD_BUTTON_LEFT_THUMB, "L3"}, + {GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, "R3"}, + {GLFW_GAMEPAD_BUTTON_DPAD_UP, "Up"}, + {GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, "Right"}, + {GLFW_GAMEPAD_BUTTON_DPAD_DOWN, "Down"}, + {GLFW_GAMEPAD_BUTTON_DPAD_LEFT, "Left"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_X),"LS X"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_Y),"LS Y"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_X),"RS X"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_Y),"RS Y"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_TRIGGER),"L2"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER),"R2"} +}; + +std::unordered_map PS4Names{ + {GLFW_GAMEPAD_BUTTON_CROSS, "X"}, + {GLFW_GAMEPAD_BUTTON_CIRCLE, "Circle"}, + {GLFW_GAMEPAD_BUTTON_SQUARE, "Square"}, + {GLFW_GAMEPAD_BUTTON_TRIANGLE, "Triangle"}, + {GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, "L1"}, + {GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, "R1"}, + {GLFW_GAMEPAD_BUTTON_BACK, "Share"}, + {GLFW_GAMEPAD_BUTTON_START, "Options"}, + {GLFW_GAMEPAD_BUTTON_GUIDE, "Home"}, + {GLFW_GAMEPAD_BUTTON_LEFT_THUMB, "L3"}, + {GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, "R3"}, + {GLFW_GAMEPAD_BUTTON_DPAD_UP, "Up"}, + {GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, "Right"}, + {GLFW_GAMEPAD_BUTTON_DPAD_DOWN, "Down"}, + {GLFW_GAMEPAD_BUTTON_DPAD_LEFT, "Left"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_X),"LS X"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_Y),"LS Y"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_X),"RS X"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_Y),"RS Y"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_TRIGGER),"L2"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER),"R2"} +}; + +std::unordered_map PS5Names{ + {GLFW_GAMEPAD_BUTTON_CROSS, "X"}, + {GLFW_GAMEPAD_BUTTON_CIRCLE, "Circle"}, + {GLFW_GAMEPAD_BUTTON_SQUARE, "Square"}, + {GLFW_GAMEPAD_BUTTON_TRIANGLE, "Triangle"}, + {GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, "L1"}, + {GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, "R1"}, + {GLFW_GAMEPAD_BUTTON_BACK, "Create"}, + {GLFW_GAMEPAD_BUTTON_START, "Options"}, + {GLFW_GAMEPAD_BUTTON_GUIDE, "Home"}, + {GLFW_GAMEPAD_BUTTON_LEFT_THUMB, "L3"}, + {GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, "R3"}, + {GLFW_GAMEPAD_BUTTON_DPAD_UP, "Up"}, + {GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, "Right"}, + {GLFW_GAMEPAD_BUTTON_DPAD_DOWN, "Down"}, + {GLFW_GAMEPAD_BUTTON_DPAD_LEFT, "Left"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_X),"LS X"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_Y),"LS Y"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_X),"RS X"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_Y),"RS Y"}, + {-(1 + GLFW_GAMEPAD_AXIS_LEFT_TRIGGER),"L2"}, + {-(1 + GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER),"R2"} +}; +std::vector> controllerTypeNames{ + {}, + {"Controller (XBOX 360 For Windows)", + "Controller (Xbox 360 Wireless Receiver for Windows)", + "Controller (Xbox One For Windows) - Wired", + "Controller (Xbox One For Windows) - Wireless", + "Xbox Adaptive Controller", + "Xbox Series Controller"}, + {"PS Controller","PS1 Controller","PS2 Controller"}, + {"PS3 Controller"}, + {"PS4 Controller"}, + {"PS5 Controller"} +}; + +int getControllerType(const std::string& searchString) { + for (size_t i = 0; i < controllerTypeNames.size(); ++i) { + for (size_t j = 0; j < controllerTypeNames[i].size(); ++j) { + if (controllerTypeNames[i][j] == searchString) { + return i; + } + } + } + return 0; //Generic type if not found +} +static std::string getControllerStr(int jid, int input, int type, int direction) +{ + std::unordered_map &map = GenericNames; + if (type == 1) map = XBOXNames; //xbox + else if (type == 2) map = PS1PS2Names; //PS1/2 + else if (type == 3) map = PS3Names; //PS3 + else if (type == 4) map = PS4Names; //PS4 + else if (type == 5) map = PS5Names; //PS5 + + auto it = map.find(input); + if (it != map.end()) + { + if (input < 0) { + if (input > -5) { + return it->second + (direction==-1?"-":"+"); + } + else return it->second; + } + else { + return it->second; + } + } + else + { + return "UNK"; + } } \ No newline at end of file diff --git a/Encore/include/game/player.h b/Encore/include/game/player.h index 01367502..c1799921 100644 --- a/Encore/include/game/player.h +++ b/Encore/include/game/player.h @@ -1,6 +1,10 @@ #pragma once #include + +int instrument = 0; +int diff = 0; + int notesHit = 0; int notesMissed = 0; int perfectHit = 0; diff --git a/Encore/include/game/settings.h b/Encore/include/game/settings.h index 6158da5d..456ef71f 100644 --- a/Encore/include/game/settings.h +++ b/Encore/include/game/settings.h @@ -2,6 +2,7 @@ #include "rapidjson/document.h" #include "rapidjson/filewritestream.h" #include "rapidjson/prettywriter.h" +#include "GLFW/glfw3.h" #include "keybinds.h" #include "raylib.h" #include @@ -26,6 +27,8 @@ class Settings { settings.AddMember("avOffset", rapidjson::Value(), allocator); if (!settings.HasMember("inputOffset")) settings.AddMember("inputOffset", rapidjson::Value(), allocator); + if (!settings.HasMember("mirror")) + settings.AddMember("mirror", rapidjson::Value(), allocator); if (!settings.HasMember("keybinds")) settings.AddMember("keybinds", rapidjson::kObjectType, allocator); if (!settings["keybinds"].HasMember("4k")) @@ -40,6 +43,22 @@ class Settings { settings["keybinds"].AddMember("overdrive", rapidjson::Value(), allocator); if (!settings["keybinds"].HasMember("overdriveAlt")) settings["keybinds"].AddMember("overdriveAlt", rapidjson::Value(), allocator); + if (!settings.HasMember("controllerbinds")) + settings.AddMember("controllerbinds", rapidjson::kObjectType, allocator); + if (!settings["controllerbinds"].HasMember("4k")) + settings["controllerbinds"].AddMember("4k", rapidjson::kArrayType, allocator); + if (!settings["controllerbinds"].HasMember("5k")) + settings["controllerbinds"].AddMember("5k", rapidjson::kArrayType, allocator); + if (!settings["controllerbinds"].HasMember("overdrive")) + settings["controllerbinds"].AddMember("overdrive", rapidjson::Value(), allocator); + if (!settings["controllerbinds"].HasMember("4k_direction")) + settings["controllerbinds"].AddMember("4k_direction", rapidjson::kArrayType, allocator); + if (!settings["controllerbinds"].HasMember("5k_direction")) + settings["controllerbinds"].AddMember("5k_direction", rapidjson::kArrayType, allocator); + if (!settings["controllerbinds"].HasMember("overdrive")) + settings["controllerbinds"].AddMember("overdrive", rapidjson::Value(), allocator); + if (!settings["controllerbinds"].HasMember("type")) + settings["controllerbinds"].AddMember("type", rapidjson::Value(), allocator); } public: rapidjson::Document settings; @@ -47,20 +66,41 @@ class Settings { std::vector defaultKeybinds5K{ KEY_D,KEY_F,KEY_J,KEY_K,KEY_L }; std::vector defaultKeybinds4KAlt{ -1,-1,-1,-1 }; std::vector defaultKeybinds5KAlt{ -1,-1,-1,-1,-1 }; - int defaultKeybindOverdrive = 32; + int defaultKeybindOverdrive = KEY_SPACE; int defaultKeybindOverdriveAlt = -1; + std::vector defaultController4K{ GLFW_GAMEPAD_BUTTON_DPAD_LEFT,GLFW_GAMEPAD_BUTTON_DPAD_RIGHT,GLFW_GAMEPAD_BUTTON_X,GLFW_GAMEPAD_BUTTON_B }; + std::vector defaultController5K{ GLFW_GAMEPAD_BUTTON_DPAD_LEFT,GLFW_GAMEPAD_BUTTON_DPAD_RIGHT,GLFW_GAMEPAD_BUTTON_X,GLFW_GAMEPAD_BUTTON_Y, GLFW_GAMEPAD_BUTTON_B }; + std::vector defaultController5KAxisDirection{ 0,0,0,0,0 }; + std::vector defaultController4KAxisDirection{ 0,0,0,0 }; + int defaultControllerOverdrive = -1-GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER; + int defaultControllerOverdriveAxisDirection = 1; + int defaultControllerType = 0; std::vector keybinds4K = defaultKeybinds4K; std::vector keybinds5K = defaultKeybinds5K; std::vector keybinds4KAlt = defaultKeybinds4KAlt; std::vector keybinds5KAlt = defaultKeybinds5KAlt; + std::vector controller4K = defaultController4K; + std::vector controller5K = defaultController5K; + std::vector controller4KAxisDirection = defaultController4KAxisDirection; + std::vector controller5KAxisDirection = defaultController5KAxisDirection; + int controllerType = defaultControllerType; int keybindOverdrive = defaultKeybindOverdrive; int keybindOverdriveAlt = defaultKeybindOverdriveAlt; - std::vector prev4k = keybinds4K; - std::vector prev5k = keybinds5K; - std::vector prev4kAlt = keybinds4KAlt; - std::vector prev5kAlt = keybinds5KAlt; + int controllerOverdrive = defaultControllerOverdrive; + int controllerOverdriveAxisDirection = defaultControllerOverdriveAxisDirection; + std::vector prev4K = keybinds4K; + std::vector prev5K = keybinds5K; + std::vector prevController4K = controller4K; + std::vector prevController5K = controller5K; + std::vector prevController4KAxisDirection = controller4KAxisDirection; + std::vector prevController5KAxisDirection = controller5KAxisDirection; + std::vector prev4KAlt = keybinds4KAlt; + std::vector prev5KAlt = keybinds5KAlt; int prevOverdrive = keybindOverdrive; int prevOverdriveAlt = keybindOverdriveAlt; + int prevControllerOverdrive = controllerOverdrive; + int prevControllerOverdriveAxisDirection = controllerOverdriveAxisDirection; + int prevControllerType = controllerType; std::vector defaultTrackSpeedOptions = { 0.5f,0.75f,1.0f,1.25f,1.5f,1.75f,2.0f }; std::vector trackSpeedOptions = defaultTrackSpeedOptions; int trackSpeed = 4; @@ -69,6 +109,9 @@ class Settings { int prevAvOffsetMS = avOffsetMS; int inputOffsetMS = 0; int prevInputOffsetMS = inputOffsetMS; + bool defaultMirrorMode = false; + bool mirrorMode = defaultMirrorMode; + bool prevMirrorMode = mirrorMode; bool changing4k = false; bool changingAlt = false; bool missHighwayDefault = false; @@ -105,11 +148,34 @@ class Settings { rapidjson::Value overdrive(keybindOverdrive); rapidjson::Value overdriveAlt(keybindOverdriveAlt); settings["keybinds"].AddMember("overdrive", overdrive, allocator); - settings["keybinds"].AddMember("overdriveAlt", overdriveAlt, allocator); + settings["keybinds"].AddMember("overdriveAlt", overdriveAlt, allocator); + rapidjson::Value arrayController4K(rapidjson::kArrayType); + rapidjson::Value arrayController5K(rapidjson::kArrayType); + rapidjson::Value arrayController4KDirection(rapidjson::kArrayType); + rapidjson::Value arrayController5KDirection(rapidjson::kArrayType); + for (int& key : defaultController4K) + arrayController4K.PushBack(rapidjson::Value().SetInt(key), allocator); + for (int& key : defaultController5K) + arrayController5K.PushBack(rapidjson::Value().SetInt(key), allocator); + for (int& key : defaultController4KAxisDirection) + arrayController4KDirection.PushBack(rapidjson::Value().SetInt(key), allocator); + for (int& key : defaultController5KAxisDirection) + arrayController5KDirection.PushBack(rapidjson::Value().SetInt(key), allocator); + settings.AddMember("controllerbinds", rapidjson::Value(rapidjson::kObjectType), allocator); + + settings["controllerbinds"].AddMember("type", rapidjson::Value().SetInt(defaultControllerType), allocator); + settings["controllerbinds"].AddMember("4k", arrayController4K, allocator); + settings["controllerbinds"].AddMember("4k_direction", arrayController4KDirection, allocator); + settings["controllerbinds"].AddMember("5k", arrayController5K, allocator); + settings["controllerbinds"].AddMember("5k_direction", arrayController5KDirection, allocator); + settings["controllerbinds"].AddMember("overdrive", rapidjson::Value().SetInt(defaultControllerOverdrive), allocator); + settings["controllerbinds"].AddMember("overdrive_direction", rapidjson::Value().SetInt(defaultControllerOverdriveAxisDirection), allocator); rapidjson::Value avOffset(avOffsetMS); settings.AddMember("avOffset", avOffset, allocator); rapidjson::Value inputOffset(inputOffsetMS); settings.AddMember("inputOffset", inputOffset, allocator); + rapidjson::Value mirrorValue(defaultMirrorMode); + settings.AddMember("mirror",mirrorValue, allocator); rapidjson::Value trackSpeedVal(4); settings.AddMember("trackSpeed", trackSpeedVal, allocator); rapidjson::Value arrayTrackSpeedOptions(rapidjson::kArrayType); @@ -128,8 +194,17 @@ class Settings { bool keybinds5KAltError = false; bool keybindsOverdriveError = false; bool keybindsOverdriveAltError = false; + bool controllerError = false; + bool controllerTypeError = false; + bool controller4KError = false; + bool controller4KDirectionError = false; + bool controller5KError = false; + bool controller5KDirectionError = false; + bool controllerOverdriveError = false; + bool controllerOverdriveDirectionError = false; bool avError = false; bool inputError = false; + bool mirrorError = false; bool trackSpeedOptionsError = false; bool trackSpeedError = false; bool MissHighwayError = false; @@ -156,7 +231,7 @@ class Settings { keybinds4KError = true; } } - prev4k = keybinds4K; + prev4K = keybinds4K; } else { keybinds4KError = true; @@ -173,7 +248,7 @@ class Settings { keybinds5KError = true; } } - prev5k = keybinds5K; + prev5K = keybinds5K; } else { keybinds5KError = true; @@ -190,7 +265,7 @@ class Settings { keybinds4KAltError = true; } } - prev4kAlt = keybinds4KAlt; + prev4KAlt = keybinds4KAlt; } else { keybinds4KAltError = true; @@ -207,7 +282,7 @@ class Settings { keybinds5KAltError = true; } } - prev5kAlt = keybinds5KAlt; + prev5KAlt = keybinds5KAlt; } else { keybinds5KAltError = true; @@ -232,6 +307,101 @@ class Settings { else { keybindsError = true; } + if (settings.HasMember("controllerbinds") && settings["controllerbinds"].IsObject()) { + if (settings["controllerbinds"].HasMember("type") && settings["controllerbinds"]["type"].IsInt()) { + controllerType = settings["controllerbinds"]["type"].GetInt(); + prevControllerType = controllerType; + } + else { + controllerTypeError = true; + } + + if (settings["controllerbinds"].HasMember("4k") && settings["controllerbinds"]["4k"].IsArray()) { + const rapidjson::Value& arr = settings["controllerbinds"]["4k"]; + if (arr.Size() == 4) { + for (int i = 0; i < 4; i++) { + if (arr[i].IsInt()) { + controller4K[i] = arr[i].GetInt(); + } + else { + controller4KError = true; + } + } + prevController4K = controller4K; + } + else { + controller4KError = true; + } + } + if (settings["controllerbinds"].HasMember("4k_direction") && settings["controllerbinds"]["4k_direction"].IsArray()) { + const rapidjson::Value& arr = settings["controllerbinds"]["4k_direction"]; + if (arr.Size() == 4) { + for (int i = 0; i < 4; i++) { + if (arr[i].IsInt()) { + controller4KAxisDirection[i] = arr[i].GetInt(); + } + else { + controller4KDirectionError = true; + } + } + prevController4KAxisDirection = controller4KAxisDirection; + } + else { + controller4KDirectionError = true; + } + } + if (settings["controllerbinds"].HasMember("5k") && settings["controllerbinds"]["5k"].IsArray()) { + const rapidjson::Value& arr = settings["controllerbinds"]["5k"]; + if (arr.Size() == 5) { + for (int i = 0; i < 5; i++) { + if (arr[i].IsInt()) { + controller5K[i] = arr[i].GetInt(); + } + else { + controller5KError = true; + } + } + prevController5K = controller5K; + } + else { + controller5KError = true; + } + } + if (settings["controllerbinds"].HasMember("5k_direction") && settings["controllerbinds"]["5k_direction"].IsArray()) { + const rapidjson::Value& arr = settings["controllerbinds"]["5k_direction"]; + if (arr.Size() == 5) { + for (int i = 0; i < 5; i++) { + if (arr[i].IsInt()) { + controller5KAxisDirection[i] = arr[i].GetInt(); + } + else { + controller5KDirectionError = true; + } + } + prevController5KAxisDirection = controller5KAxisDirection; + } + else { + controller5KDirectionError = true; + } + } + if (settings["controllerbinds"].HasMember("overdrive") && settings["controllerbinds"]["overdrive"].IsInt()) { + controllerOverdrive = settings["controllerbinds"]["overdrive"].GetInt(); + prevControllerOverdrive = controllerOverdrive; + } + else { + controllerOverdriveError = true; + } + if (settings["controllerbinds"].HasMember("overdrive_direction") && settings["controllerbinds"]["overdrive_direction"].IsInt()) { + controllerOverdriveAxisDirection = settings["controllerbinds"]["overdrive_direction"].GetInt(); + prevControllerOverdriveAxisDirection = controllerOverdriveAxisDirection; + } + else { + controllerOverdriveDirectionError = true; + } + } + else { + controllerError = true; + } if (settings.HasMember("avOffset") && settings["avOffset"].IsInt()) { avOffsetMS = settings["avOffset"].GetInt(); @@ -275,7 +445,13 @@ class Settings { MissHighwayColor = settings["missHighwayColor"].GetBool(); } else { MissHighwayError = true; - } + } + if (settings.HasMember("mirror") && settings["mirror"].IsBool()) { + mirrorMode = settings["mirror"].GetBool(); + } + else { + mirrorError = true; + } } } else { @@ -292,10 +468,21 @@ class Settings { rapidjson::Value array5K(rapidjson::kArrayType); for (int& key :defaultKeybinds5K) array5K.PushBack(rapidjson::Value().SetInt(key), allocator); + rapidjson::Value array4KAlt (rapidjson::kArrayType); + for (int& key : defaultKeybinds4KAlt) + array4KAlt.PushBack(rapidjson::Value().SetInt(key), allocator); + rapidjson::Value array5KAlt (rapidjson::kArrayType); + for (int& key : defaultKeybinds5KAlt) + array5KAlt.PushBack(rapidjson::Value().SetInt(key), allocator); settings.AddMember("keybinds", rapidjson::Value(rapidjson::kObjectType), allocator); settings["keybinds"].AddMember("4k", array4K, allocator); settings["keybinds"].AddMember("5k", array5K, allocator); - + settings["keybinds"].AddMember("4kAlt", array4KAlt, allocator); + settings["keybinds"].AddMember("5kAlt", array5KAlt, allocator); + rapidjson::Value overdriveKey(defaultKeybindOverdrive); + settings["keybinds"].AddMember("overdrive", overdriveKey, allocator); + rapidjson::Value overdriveKeyAlt(defaultKeybindOverdriveAlt); + settings["keybinds"].AddMember("overdriveAlt", overdriveKeyAlt, allocator); } if (keybinds4KError) { if(settings["keybinds"].HasMember("4k")) @@ -337,7 +524,7 @@ class Settings { if (settings["keybinds"].HasMember("overdrive")) settings["keybinds"].EraseMember("overdrive"); rapidjson::Document::AllocatorType& allocator = settings.GetAllocator(); - rapidjson::Value overdriveKey(KEY_SPACE); + rapidjson::Value overdriveKey(defaultKeybindOverdrive); settings["keybinds"].AddMember("overdrive", overdriveKey, allocator); } if (keybindsOverdriveAltError){ @@ -347,6 +534,89 @@ class Settings { rapidjson::Value overdriveKeyAlt(defaultKeybindOverdriveAlt); settings["keybinds"].AddMember("overdriveAlt", overdriveKeyAlt, allocator); } + if (controllerError) { + if (settings.HasMember("controllerbinds")) + settings.EraseMember("controllerbinds"); + rapidjson::Document::AllocatorType& allocator = settings.GetAllocator(); + rapidjson::Value array4K(rapidjson::kArrayType); + for (int& key : defaultController4K) + array4K.PushBack(rapidjson::Value().SetInt(key), allocator); + rapidjson::Value array5K(rapidjson::kArrayType); + for (int& key : defaultController5K) + array5K.PushBack(rapidjson::Value().SetInt(key), allocator); + rapidjson::Value array4KDirection(rapidjson::kArrayType); + for (int& key : defaultController4KAxisDirection) + array4KDirection.PushBack(rapidjson::Value().SetInt(key), allocator); + rapidjson::Value array5KDirection(rapidjson::kArrayType); + for (int& key : defaultController5KAxisDirection) + array5KDirection.PushBack(rapidjson::Value().SetInt(key), allocator); + settings.AddMember("controllerbinds", rapidjson::Value(rapidjson::kObjectType), allocator); + settings["controllerbinds"].AddMember("4k", array4K, allocator); + settings["controllerbinds"].AddMember("4k_direction", array4KDirection, allocator); + settings["controllerbinds"].AddMember("5k", array5K, allocator); + settings["controllerbinds"].AddMember("5k_direction", array4KDirection, allocator); + rapidjson::Value overdriveKey(defaultControllerOverdrive); + settings["controllerbinds"].AddMember("overdrive", overdriveKey, allocator); + rapidjson::Value overdriveDirection(defaultControllerOverdriveAxisDirection); + settings["controllerbinds"].AddMember("overdrive_direction", overdriveDirection, allocator); + } + if (controllerTypeError) { + if (settings["controllerbinds"].HasMember("type")) + settings["controllerbinds"].EraseMember("type"); + rapidjson::Document::AllocatorType& allocator = settings.GetAllocator(); + rapidjson::Value controllerTypeValue(defaultControllerType); + settings["controllerbinds"].AddMember("type", controllerTypeValue, allocator); + } + if (controller4KError) { + if (settings["controllerbinds"].HasMember("4k")) + settings["controllerbinds"].EraseMember("4k"); + rapidjson::Document::AllocatorType& allocator = settings.GetAllocator(); + rapidjson::Value array4K(rapidjson::kArrayType); + for (int& key : defaultController4K) + array4K.PushBack(rapidjson::Value().SetInt(key), allocator); + settings["controllerbinds"].AddMember("4k", array4K, allocator); + } + if (controller5KError) { + if (settings["controllerbinds"].HasMember("5k")) + settings["controllerbinds"].EraseMember("5k"); + rapidjson::Document::AllocatorType& allocator = settings.GetAllocator(); + rapidjson::Value array5K(rapidjson::kArrayType); + for (int& key : defaultController5K) + array5K.PushBack(rapidjson::Value().SetInt(key), allocator); + settings["controllerbinds"].AddMember("5k", array5K, allocator); + } + if (controllerOverdriveError) { + if (settings["controllerbinds"].HasMember("overdrive")) + settings["controllerbinds"].EraseMember("overdrive"); + rapidjson::Document::AllocatorType& allocator = settings.GetAllocator(); + rapidjson::Value overdriveKey(defaultControllerOverdrive); + settings["controllerbinds"].AddMember("overdrive", overdriveKey, allocator); + } + if (controller4KDirectionError) { + if (settings["controllerbinds"].HasMember("4k_direction")) + settings["controllerbinds"].EraseMember("4k_direction"); + rapidjson::Document::AllocatorType& allocator = settings.GetAllocator(); + rapidjson::Value array4K(rapidjson::kArrayType); + for (int& key : defaultController4KAxisDirection) + array4K.PushBack(rapidjson::Value().SetInt(key), allocator); + settings["controllerbinds"].AddMember("4k_direction", array4K, allocator); + } + if (controller5KDirectionError) { + if (settings["controllerbinds"].HasMember("5k_direction")) + settings["controllerbinds"].EraseMember("5k_direction"); + rapidjson::Document::AllocatorType& allocator = settings.GetAllocator(); + rapidjson::Value array5K(rapidjson::kArrayType); + for (int& key : defaultController5KAxisDirection) + array5K.PushBack(rapidjson::Value().SetInt(key), allocator); + settings["controllerbinds"].AddMember("5k_direction", array5K, allocator); + } + if (controllerOverdriveDirectionError) { + if (settings["controllerbinds"].HasMember("overdrive_direction")) + settings["controllerbinds"].EraseMember("overdrive_direction"); + rapidjson::Document::AllocatorType& allocator = settings.GetAllocator(); + rapidjson::Value overdriveKey(defaultControllerOverdriveAxisDirection); + settings["controllerbinds"].AddMember("overdrive_direction", overdriveKey, allocator); + } if (avError) { if (settings.HasMember("avOffset")) settings.EraseMember("avOffset"); @@ -389,7 +659,15 @@ class Settings { missHighwayColor.SetBool(false); settings.AddMember("missHighwayColor", missHighwayColor, allocator); } - if (MissHighwayError||keybindsError || keybinds4KError || keybinds5KError || keybinds4KAltError || keybinds5KAltError|| keybindsOverdriveError || keybindsOverdriveAltError || avError || inputError|| trackSpeedError || trackSpeedOptionsError) { + if (mirrorError) { + if (settings.HasMember("mirror")) + settings.EraseMember("mirror"); + rapidjson::Document::AllocatorType& allocator = settings.GetAllocator(); + rapidjson::Value mirrorValue; + mirrorValue .SetBool(defaultMirrorMode); + settings.AddMember("mirror", mirrorValue, allocator); + } + if (mirrorError|| MissHighwayError || keybindsError || keybinds4KError || keybinds5KError || keybinds4KAltError || keybinds5KAltError|| keybindsOverdriveError || keybindsOverdriveAltError || controllerError || controllerTypeError || controller4KError || controller5KError || controllerOverdriveError || controller4KDirectionError || controller5KDirectionError || controllerOverdriveDirectionError || avError || inputError|| trackSpeedError || trackSpeedOptionsError) { ensureValuesExist(); saveSettings(settingsFile); } @@ -421,7 +699,7 @@ class Settings { keybinds4KError = true; } } - prev4k = keybinds4K; + prev4K = keybinds4K; } else { keybinds4KError = true; @@ -438,7 +716,7 @@ class Settings { keybinds5KError = true; } } - prev5k = keybinds5K; + prev5K = keybinds5K; } else { keybinds5KError = true; @@ -494,6 +772,8 @@ class Settings { inputOffsetMember->value.SetInt(inputOffsetMS); rapidjson::Value::MemberIterator missHighwayColorMember = settings.FindMember("missHighwayColor"); missHighwayColorMember->value.SetBool(missHighwayDefault); + rapidjson::Value::MemberIterator mirrorMember = settings.FindMember("mirror"); + mirrorMember->value.SetBool(mirrorMode); rapidjson::Value::MemberIterator keybinds4KMember = settings["keybinds"].FindMember("4k"); keybinds4KMember->value.Clear(); for (int& key : keybinds4K) @@ -514,6 +794,28 @@ class Settings { overdriveKeyMember->value.SetInt(keybindOverdrive); rapidjson::Value::MemberIterator overdriveKeyAltMember = settings["keybinds"].FindMember("overdriveAlt"); overdriveKeyAltMember->value.SetInt(keybindOverdriveAlt); + + rapidjson::Value::MemberIterator controller4KMember = settings["controllerbinds"].FindMember("4k"); + controller4KMember->value.Clear(); + for (int& key : controller4K) + controller4KMember->value.PushBack(rapidjson::Value().SetInt(key), allocator); + rapidjson::Value::MemberIterator controller5KMember = settings["controllerbinds"].FindMember("5k"); + controller5KMember->value.Clear(); + for (int& key : controller5K) + controller5KMember->value.PushBack(rapidjson::Value().SetInt(key), allocator); + rapidjson::Value::MemberIterator controller4KDirMember = settings["controllerbinds"].FindMember("4k_direction"); + controller4KDirMember->value.Clear(); + for (int& key : controller4KAxisDirection) + controller4KDirMember->value.PushBack(rapidjson::Value().SetInt(key), allocator); + rapidjson::Value::MemberIterator controller5KDirMember = settings["controllerbinds"].FindMember("5k_direction"); + controller5KDirMember->value.Clear(); + for (int& key : controller5KAxisDirection) + controller5KDirMember->value.PushBack(rapidjson::Value().SetInt(key), allocator); + rapidjson::Value::MemberIterator overdriveControllerMember = settings["controllerbinds"].FindMember("overdrive"); + overdriveControllerMember->value.SetInt(controllerOverdrive); + rapidjson::Value::MemberIterator overdriveControllerDirMember = settings["controllerbinds"].FindMember("overdrive_direction"); + overdriveControllerDirMember->value.SetInt(controllerOverdriveAxisDirection); + char writeBuffer[8192]; FILE* fp = fopen(settingsFile.string().c_str(), "wb"); rapidjson::FileWriteStream os(fp, writeBuffer, sizeof(writeBuffer)); diff --git a/Encore/src/main.cpp b/Encore/src/main.cpp index 5155e6c9..bde9a8f6 100644 --- a/Encore/src/main.cpp +++ b/Encore/src/main.cpp @@ -24,12 +24,11 @@ #include vector ArgumentList::arguments; -bool compareNotes(const Note& a, const Note& b) { +static bool compareNotes(const Note& a, const Note& b) { return a.time < b.time; } -int instrument = 0; -int diff = 0; + bool midiLoaded = false; bool isPlaying = false; bool streamsLoaded = false; @@ -65,259 +64,347 @@ double overdriveHitTime = 0.0; SongList songList; Settings settings; Assets assets; -std::vector>> lastState; double lastAxesTime = 0.0; -std::vector axesValues{0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f}; +std::vector axesValues{0.0f,0.0f,0.0f,0.0f,0.0f,0.0f}; std::vector buttonValues{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; -static void notesCallback(GLFWwindow* wind, int key, int scancode, int action, int mods) { - // if (selectStage == 2) { - if (action < 2) { - Chart& curChart = songList.songs[curPlayingSong].parts[instrument]->charts[diff]; - float eventTime = GetMusicTimePlayed(loadedStreams[0].first); - if (action==GLFW_PRESS && (key == settings.keybindOverdrive || key == settings.keybindOverdriveAlt) && overdriveFill > 0 && !overdrive) { - overdriveActiveTime = eventTime; - overdriveActiveFill = overdriveFill; - overdrive = true; - overdriveHitAvailable = true; - } - int lane = -1; - if (diff == 3) { - for (int i = 0; i < 5; i++) { - if (key == settings.keybinds5K[i] && !heldFretsAlt[i]) { - if (action == GLFW_PRESS) { - heldFrets[i] = true; - } - else if (action == GLFW_RELEASE) { - heldFrets[i] = false; - overhitFrets[i] = false; - } - lane = i; - } - else if (key == settings.keybinds5KAlt[i] && !heldFrets[i]) { - if (action == GLFW_PRESS) { - heldFretsAlt[i] = true; +std::vector axesValues2{ 0.0f,0.0f,0.0f,0.0f,0.0f,0.0f }; +int pressedGamepadInput = -999; +int axisDirection = -1; +int controllerID = -1; +static void handleInputs(int lane, int action){ + if (settings.mirrorMode) { + lane = (diff == 3 ? 4 : 3) - lane; + } + if (!streamsLoaded) { + return; + } + Chart& curChart = songList.songs[curPlayingSong].parts[instrument]->charts[diff]; + float eventTime = GetMusicTimePlayed(loadedStreams[0].first); + if (action == GLFW_PRESS && (lane == -1) && overdriveFill > 0 && !overdrive) { + overdriveActiveTime = eventTime; + overdriveActiveFill = overdriveFill; + overdrive = true; + overdriveHitAvailable = true; + } + for (int i = curNoteIdx; i < curChart.notes.size(); i++) { + Note& curNote = curChart.notes[i]; + + // if (curNote.time > eventTime + 0.1) break; + + if (lane!=-1) { + if (lane != curNote.lane) continue; + if ((curNote.lift && action == GLFW_RELEASE) || action == GLFW_PRESS) { + if ((curNote.time) - (action == GLFW_RELEASE ? goodBackend * liftTimingMult : goodBackend) + InputOffset < eventTime && + (curNote.time) + ((action == GLFW_RELEASE ? goodFrontend * liftTimingMult : goodFrontend) + InputOffset) > eventTime && + !curNote.hit) { + curNote.hit = true; + curNote.hitTime = eventTime; + if ((curNote.len) > 0 && !curNote.lift) { + curNote.held = true; } - else if (action == GLFW_RELEASE) { - heldFretsAlt[i] = false; - overhitFrets[i] = false; + if ((curNote.time) - perfectBackend + InputOffset < eventTime && curNote.time + perfectFrontend + InputOffset > eventTime) { + curNote.perfect = true; } - lane = i; + if (curNote.perfect) lastNotePerfect = true; + else lastNotePerfect = false; + player::HitNote(curNote.perfect, instrument); + curNote.accounted = true; + break; } + if (curNote.miss) lastNotePerfect = false; + } + if (action == GLFW_RELEASE && curNote.held && (curNote.len) > 0) { + curNote.held = false; + score += sustainScoreBuffer[curNote.lane]; + sustainScoreBuffer[curNote.lane] = 0; + mute = true; + // SetAudioStreamVolume(loadedStreams[instrument].stream, missVolume); + } + + if (action == GLFW_PRESS && + eventTime > songList.songs[curPlayingSong].music_start && + !curNote.hit && + !curNote.accounted && + ((curNote.time) - perfectBackend) + InputOffset > eventTime && + eventTime > overdriveHitTime + 0.025 + && !overhitFrets[lane]) { + player::OverHit(); + if (curChart.odPhrases.size() >= 1 && eventTime >= curChart.odPhrases[curODPhrase].start && eventTime < curChart.odPhrases[curODPhrase].end) curChart.odPhrases[curODPhrase].missed = true; + overhitFrets[lane] = true; } } else { - for (int i = 0; i < 4; i++) { - if (key == settings.keybinds4K[i] && !heldFretsAlt[i]) { - if (action == GLFW_PRESS) { - heldFrets[i] = true; - } - else if (action == GLFW_RELEASE) { - heldFrets[i] = false; - overhitFrets[i] = false; - } - lane = i; - } - else if (key == settings.keybinds4KAlt[i] && !heldFrets[i]) { - if (action == GLFW_PRESS) { - heldFretsAlt[i] = true; - } - else if (action == GLFW_RELEASE) { - heldFretsAlt[i] = false; - overhitFrets[i] = false; - } - lane = i; - } + if (action == GLFW_PRESS && !overdriveHeld) { + overdriveHeld = true; } - } - - - for (int i = curNoteIdx; i < curChart.notes.size(); i++) { - Note& curNote = curChart.notes[i]; - - // if (curNote.time > eventTime + 0.1) break; - - if (key != settings.keybindOverdrive && key != settings.keybindOverdriveAlt) { - if (lane != curNote.lane) continue; - if ((curNote.lift && action == GLFW_RELEASE) || action == GLFW_PRESS) { - if ((curNote.time) - (action == GLFW_RELEASE ? goodBackend * liftTimingMult : goodBackend) + InputOffset < eventTime && - (curNote.time) + ((action == GLFW_RELEASE ? goodFrontend * liftTimingMult : goodFrontend) + InputOffset) > eventTime && - !curNote.hit) { - curNote.hit = true; - curNote.hitTime = eventTime; - if ((curNote.len) > 0 && !curNote.lift) { - curNote.held = true; - } - if ((curNote.time) - perfectBackend + InputOffset < eventTime && curNote.time + perfectFrontend + InputOffset > eventTime) { - curNote.perfect = true; + else if (action == GLFW_RELEASE && overdriveHeld) { + overdriveHeld = false; + } + if (action == GLFW_PRESS && overdriveHitAvailable == true) { + if ((curNote.time) - (goodBackend)+InputOffset < eventTime && + (curNote.time) + (goodFrontend)+InputOffset > eventTime && + !curNote.hit) { + for (int lane = 0; lane < 5; lane++) { + int chordLane = curChart.findNoteIdx(curNote.time, lane); + if (chordLane != -1) { + Note& chordNote = curChart.notes[chordLane]; + if ((chordNote.time) - (goodBackend)+InputOffset < eventTime && + (chordNote.time) + (goodFrontend)+InputOffset > eventTime && + !chordNote.hit) { + chordNote.hit = true; + overdriveLanesHit[lane] = true; + chordNote.hitTime = eventTime; + + if ((chordNote.len) > 0 && !chordNote.lift) { + chordNote.held = true; + } + if ((chordNote.time) - perfectBackend + InputOffset < eventTime && chordNote.time + perfectFrontend + InputOffset > eventTime) { + chordNote.perfect = true; + } + if (chordNote.perfect) lastNotePerfect = true; + else lastNotePerfect = false; + player::HitNote(curNote.perfect, instrument); + curNote.accounted = true; + } } - if (curNote.perfect) lastNotePerfect = true; - else lastNotePerfect = false; - player::HitNote(curNote.perfect, instrument); - curNote.accounted = true; - break; } - if (curNote.miss) lastNotePerfect = false; - } - if (action == GLFW_RELEASE && curNote.held && (curNote.len) > 0) { - curNote.held = false; - score += sustainScoreBuffer[curNote.lane]; - sustainScoreBuffer[curNote.lane] = 0; - mute = true; - // SetAudioStreamVolume(loadedStreams[instrument].stream, missVolume); - } - - if (action == GLFW_PRESS && - eventTime > songList.songs[curPlayingSong].music_start && - !curNote.hit && - !curNote.accounted && - ((curNote.time) - perfectBackend) + InputOffset > eventTime && - eventTime > overdriveHitTime+0.025 - && !overhitFrets[lane]) { - player::OverHit(); - if (curChart.odPhrases.size() >= 1 && eventTime >= curChart.odPhrases[curODPhrase].start && eventTime < curChart.odPhrases[curODPhrase].end) curChart.odPhrases[curODPhrase].missed = true; - overhitFrets[lane] = true; + overdriveHitAvailable = false; + overdriveLiftAvailable = true; } } - else if(key == settings.keybindOverdrive || key == settings.keybindOverdriveAlt){ - if (action == GLFW_PRESS && !overdriveHeld) { - overdriveHeld = true; - } - else if (action == GLFW_RELEASE && overdriveHeld) { - overdriveHeld = false; - } - if (action == GLFW_PRESS && overdriveHitAvailable==true) { - if ((curNote.time) - (goodBackend)+InputOffset < eventTime && - (curNote.time) + (goodFrontend)+InputOffset > eventTime && - !curNote.hit) { - for (int lane = 0; lane < 5; lane++) { + else if (action == GLFW_RELEASE && overdriveLiftAvailable) { + if ((curNote.time) - (goodBackend * liftTimingMult) + InputOffset < eventTime && + (curNote.time) + (goodFrontend * liftTimingMult) + InputOffset > eventTime && + !curNote.hit) { + for (int lane = 0; lane < 5; lane++) { + if (overdriveLanesHit[lane]) { int chordLane = curChart.findNoteIdx(curNote.time, lane); if (chordLane != -1) { Note& chordNote = curChart.notes[chordLane]; - if ((chordNote.time) - (goodBackend)+InputOffset < eventTime && - (chordNote.time) + (goodFrontend)+InputOffset > eventTime && - !chordNote.hit) { + if (chordNote.lift) { chordNote.hit = true; - overdriveLanesHit[lane] = true; + overdriveLanesHit[lane] = false; chordNote.hitTime = eventTime; - if ((chordNote.len) > 0 && !chordNote.lift) { - chordNote.held = true; - } if ((chordNote.time) - perfectBackend + InputOffset < eventTime && chordNote.time + perfectFrontend + InputOffset > eventTime) { chordNote.perfect = true; } if (chordNote.perfect) lastNotePerfect = true; else lastNotePerfect = false; - player::HitNote(curNote.perfect, instrument); - curNote.accounted = true; } + } } - overdriveHitAvailable = false; - overdriveLiftAvailable = true; } + overdriveLiftAvailable = false; } - else if (action == GLFW_RELEASE && overdriveLiftAvailable) { - if ((curNote.time) - (goodBackend * liftTimingMult) + InputOffset < eventTime && - (curNote.time) + (goodFrontend * liftTimingMult) + InputOffset > eventTime && - !curNote.hit) { - for (int lane = 0; lane < 5; lane++) { - if (overdriveLanesHit[lane]) { - int chordLane = curChart.findNoteIdx(curNote.time, lane); - if (chordLane != -1) { - Note& chordNote = curChart.notes[chordLane]; - if (chordNote.lift) { - chordNote.hit = true; - overdriveLanesHit[lane] = false; - chordNote.hitTime = eventTime; - - if ((chordNote.time) - perfectBackend + InputOffset < eventTime && chordNote.time + perfectFrontend + InputOffset > eventTime) { - chordNote.perfect = true; - - } - if (chordNote.perfect) lastNotePerfect = true; - else lastNotePerfect = false; - } - + } + if (action == GLFW_RELEASE && curNote.held && (curNote.len) > 0 && overdriveLiftAvailable) { + for (int lane = 0; lane < 5; lane++) { + if (overdriveLanesHit[lane]) { + int chordLane = curChart.findNoteIdx(curNote.time, lane); + if (chordLane != -1) { + Note& chordNote = curChart.notes[chordLane]; + if (chordNote.held && chordNote.len > 0) { + if (!((diff == 3 && settings.keybinds5K[chordNote.lane]) || (diff != 3 && settings.keybinds4K[chordNote.lane]))) { + chordNote.held = false; + score += sustainScoreBuffer[chordNote.lane]; + sustainScoreBuffer[chordNote.lane] = 0; + mute = true; } } } - overdriveLiftAvailable = false; - } + } } - if (action == GLFW_RELEASE && curNote.held && (curNote.len) > 0 && overdriveLiftAvailable) { - for (int lane = 0; lane < 5; lane++) { - if (overdriveLanesHit[lane]) { - int chordLane = curChart.findNoteIdx(curNote.time, lane); - if (chordLane != -1) { - Note& chordNote = curChart.notes[chordLane]; - if (chordNote.held && chordNote.len > 0) { - if (!((diff == 3 && settings.keybinds5K[chordNote.lane]) || (diff != 3 && settings.keybinds4K[chordNote.lane]))) { - chordNote.held = false; - score += sustainScoreBuffer[chordNote.lane]; - sustainScoreBuffer[chordNote.lane] = 0; - mute = true; - } - } - } + } + } + } +} + +static void keyCallback(GLFWwindow* wind, int key, int scancode, int action, int mods) { + if (!streamsLoaded) { + return; + } + if (action < 2) { + int lane = -1; + if (key == settings.keybindOverdrive || key == settings.keybindOverdriveAlt) { + handleInputs(-1, action); + } + else { + if (diff == 3) { + for (int i = 0; i < 5; i++) { + if (key == settings.keybinds5K[i] && !heldFretsAlt[i]) { + if (action == GLFW_PRESS) { + heldFrets[i] = true; } + else if (action == GLFW_RELEASE) { + heldFrets[i] = false; + overhitFrets[i] = false; + } + lane = i; + } + else if (key == settings.keybinds5KAlt[i] && !heldFrets[i]) { + if (action == GLFW_PRESS) { + heldFretsAlt[i] = true; + } + else if (action == GLFW_RELEASE) { + heldFretsAlt[i] = false; + overhitFrets[i] = false; + } + lane = i; } } } - - // if (curNote.time + 0.1 < GetMusicTimePlayed(loadedStreams[0]) && !curNote.hit) { - // curNote.miss = true; - // } - + else { + for (int i = 0; i < 4; i++) { + if (key == settings.keybinds4K[i] && !heldFretsAlt[i]) { + if (action == GLFW_PRESS) { + heldFrets[i] = true; + } + else if (action == GLFW_RELEASE) { + heldFrets[i] = false; + overhitFrets[i] = false; + } + lane = i; + } + else if (key == settings.keybinds4KAlt[i] && !heldFrets[i]) { + if (action == GLFW_PRESS) { + heldFretsAlt[i] = true; + } + else if (action == GLFW_RELEASE) { + heldFretsAlt[i] = false; + overhitFrets[i] = false; + } + lane = i; + } + } + } + handleInputs(lane, action); } + } - //} } -std::vector gamepadButtonNames{"A/X","B/O","X/Square","Y/Triangle","Left Shoulder","Right Shoulder","Back","Start", "Guide", "Left Stick","Right Stick","DPad Up","DPad Right","DPad Down","DPad Left"}; -std::vector gamepadAxisNames{"LS X","LS Y", "RS X","RS Y","LT", "RT"}; + static void gamepadStateCallback(int jid, GLFWgamepadstate state) { - bool buttonsUpdated = false; - bool axesUpdated = false; - double eventTime = GetTime(); - auto it = std::find_if(lastState.begin(), lastState.end(), [jid](std::pair>& pair) { - return pair.first == jid; - }); - - if (it == lastState.end()) { - std::cout << "Initial state for gamepad "<= 0) { + if (state.buttons[settings.controllerOverdrive] != buttonValues[settings.controllerOverdrive]) { + buttonValues[settings.controllerOverdrive] = state.buttons[settings.controllerOverdrive]; + handleInputs(-1, state.buttons[settings.controllerOverdrive]); + } } else { - if (memcmp(&it->second.second.buttons, &state.buttons, sizeof(state.buttons)) != 0) { - buttonsUpdated = true; - for (int i = 0; i < 15; i++) { - buttonValues[i] = (int)state.buttons[i]; + if (state.axes[-(settings.controllerOverdrive+1)] != axesValues[-(settings.controllerOverdrive + 1)]) { + axesValues[-(settings.controllerOverdrive + 1)] = state.axes[-(settings.controllerOverdrive + 1)]; + if (state.axes[-(settings.controllerOverdrive + 1)] == 1.0f*settings.controllerOverdriveAxisDirection) { + handleInputs(-1, GLFW_PRESS); + } + else { + handleInputs(-1, GLFW_RELEASE); } } - if (memcmp(&it->second.second.axes, &state.axes, sizeof(state.axes)) != 0) { - axesUpdated = true; - for (int i = 0; i < 6; i++) { - axesValues[i] = state.axes[i]; + } + if (diff == 3) { + for (int i = 0; i < 5; i++) { + if (settings.controller5K[i] >= 0) { + if (state.buttons[settings.controller5K[i]] != buttonValues[settings.controller5K[i]]) { + if (state.buttons[settings.controller5K[i]] == 1) + heldFrets[i] = true; + else + heldFrets[i] = false; + handleInputs(i, state.buttons[settings.controller5K[i]]); + buttonValues[settings.controller5K[i]] = state.buttons[settings.controller5K[i]]; + } + } + else { + if (state.axes[-(settings.controller5K[i] + 1)] != axesValues[-(settings.controller5K[i]+1)]) { + if (state.axes[-(settings.controller5K[i] + 1)] == 1.0f * (float)settings.controller5KAxisDirection[i]) { + heldFrets[i] = true; + handleInputs(i, GLFW_PRESS); + } + else { + heldFrets[i] = false; + handleInputs(i, GLFW_RELEASE); + } + axesValues[-(settings.controller5K[i] + 1)] = state.axes[-(settings.controller5K[i] + 1)]; + } } } - it->second.second = state; } - /*if (buttonsUpdated) { - std::string buttonsState = "Buttons: "; - for (int i = 0; i < sizeof(state.buttons); i++) { - buttonsState = buttonsState += gamepadButtonNames[i] + ": " + std::to_string(state.buttons[i]) + (i==sizeof(state.buttons-1)?"":", "); + else { + for (int i = 0; i < 4; i++) { + if (settings.controller4K[i] >= 0) { + if (state.buttons[settings.controller4K[i]] != buttonValues[settings.controller4K[i]]) { + if (state.buttons[settings.controller4K[i]] == 1) + heldFrets[i] = true; + else + heldFrets[i] = false; + handleInputs(i, state.buttons[settings.controller4K[i]]); + buttonValues[settings.controller4K[i]] = state.buttons[settings.controller4K[i]]; + } + } + else { + if (state.axes[-(settings.controller4K[i] + 1)] != axesValues[-(settings.controller4K[i] + 1)]) { + if (state.axes[-(settings.controller4K[i] + 1)] == 1.0f * (float)settings.controller4KAxisDirection[i]) { + heldFrets[i] = true; + handleInputs(i, GLFW_PRESS); + } + else { + heldFrets[i] = false; + handleInputs(i, GLFW_RELEASE); + } + axesValues[-(settings.controller4K[i] + 1)] = state.axes[-(settings.controller4K[i] + 1)]; + } + } } - std::cout << buttonsState << std::endl; - }*/ - + } +} +static void gamepadStateCallbackSetControls(int jid, GLFWgamepadstate state) { + for (int i = 0; i < 6; i++) { + axesValues2[i] = state.axes[i]; + } + if (changingKey || changingOverdrive) { + for (int i = 0; i < 15; i++) { + if (state.buttons[i] == 1) { + if (buttonValues[i] == 0) { + controllerID = jid; + pressedGamepadInput = i; + return; + } + else { + buttonValues[i] = state.buttons[i]; + } + } + } + for (int i = 0; i < 6; i++) { + if (state.axes[i] == 1.0f || (i <= 3 && state.axes[i] == -1.0f)) { + axesValues[i] = 0.0f; + if (state.axes[i] == 1.0f) axisDirection = 1; + else axisDirection = -1; + controllerID = jid; + pressedGamepadInput = -(1 + i); + return; + } + else { + axesValues[i] = 0.0f; + } + } + } + else { + for (int i = 0; i < 15; i++) { + buttonValues[i] = state.buttons[i]; + } + for (int i = 0; i < 6; i++) { + axesValues[i] = state.axes[i]; + } + pressedGamepadInput = -999; + } } - - int main(int argc, char* argv[]) { SetConfigFlags(FLAG_MSAA_4X_HINT); @@ -327,7 +414,6 @@ int main(int argc, char* argv[]) // 800 , 600 InitWindow(1, 1, "Encore"); - glfwSetGamepadStateCallback(gamepadStateCallback); SetWindowPosition(50, 50); SetWindowSize(GetMonitorWidth(GetCurrentMonitor()) * 0.75, GetMonitorHeight(GetCurrentMonitor()) * 0.75); bool windowToggle = true; @@ -399,8 +485,10 @@ int main(int argc, char* argv[]) ChangeDirectory(GetApplicationDirectory()); assets.loadAssets(directory); - GLFWkeyfun origCallback = glfwSetKeyCallback(glfwGetCurrentContext(), notesCallback); - glfwSetKeyCallback(glfwGetCurrentContext(), origCallback); + GLFWkeyfun origKeyCallback = glfwSetKeyCallback(glfwGetCurrentContext(), keyCallback); + GLFWgamepadstatefun origGamepadCallback = glfwSetGamepadStateCallback(gamepadStateCallback); + glfwSetKeyCallback(glfwGetCurrentContext(), origKeyCallback); + glfwSetGamepadStateCallback(origGamepadCallback); GuiSetStyle(DEFAULT, BACKGROUND_COLOR, 0x505050ff); GuiSetStyle(DEFAULT, TEXT_SIZE, 20); while (!WindowShouldClose()) @@ -413,45 +501,113 @@ int main(int argc, char* argv[]) if (!isPlaying) { if (selectStage == -2) { - if (GuiButton({ 0,0,60,60 }, "<")) { - midiLoaded = false; + if (GuiButton({ ((float)GetScreenWidth() / 2) - 350,((float)GetScreenHeight() - 60),100,60 }, "Cancel") && !(changingKey||changingOverdrive)) { + glfwSetGamepadStateCallback(origGamepadCallback); + selectStage = 0; + settings.controller4K = settings.prevController4K; + settings.controller4KAxisDirection = settings.prevController4KAxisDirection; + settings.controller5K = settings.prevController5K; + settings.controller5KAxisDirection = settings.prevController5KAxisDirection; + settings.controllerOverdrive = settings.prevControllerOverdrive; + settings.controllerOverdriveAxisDirection = settings.prevControllerOverdriveAxisDirection; + settings.controllerType = settings.prevControllerType; + } + if (GuiButton({ ((float)GetScreenWidth() / 2) + 250,((float)GetScreenHeight() - 60),100,60 }, "Apply") && !(changingKey || changingOverdrive)) { + glfwSetGamepadStateCallback(origGamepadCallback); selectStage = 0; + settings.prevController4K = settings.controller4K; + settings.prevController4KAxisDirection = settings.controller4KAxisDirection; + settings.prevController5K = settings.controller5K; + settings.prevController5KAxisDirection = settings.controller5KAxisDirection; + settings.prevControllerOverdrive = settings.controllerOverdrive; + settings.prevControllerOverdriveAxisDirection = settings.controllerOverdriveAxisDirection; + settings.prevControllerType = settings.controllerType; + settings.saveSettings(directory / "settings.json"); + } + if (settings.controllerType == -1 && controllerID != -1) { + std::string gamepadName = std::string(glfwGetGamepadName(controllerID)); + settings.controllerType = getControllerType(gamepadName); + } + for (int i = 0; i < 5; i++) { + float j = i - 2.0f; + if (GuiButton({ ((float)GetScreenWidth() / 2) - 40 + (80 * j),(float)GetScreenHeight() / 2,80,60 }, getControllerStr(controllerID, settings.controller5K[i], settings.controllerType, settings.controller5KAxisDirection[i]).c_str())) { + settings.changing4k = false; + selLane = i; + changingKey = true; + } + } + for (int i = 0; i < 4; i++) { + float j = i - 1.5f; + if (GuiButton({ ((float)GetScreenWidth() / 2) - 40 + (80 * j),(float)GetScreenHeight() / 2 + 140,80,60 }, getControllerStr(controllerID, settings.controller4K[i], settings.controllerType, settings.controller4KAxisDirection[i]).c_str())) { + settings.changing4k = true; + selLane = i; + changingKey = true; + } + } + if (GuiButton({ ((float)GetScreenWidth() / 2) - 40,(float)GetScreenHeight() / 2 + 280,80,60 }, getControllerStr(controllerID, settings.controllerOverdrive,settings.controllerType, settings.controllerOverdriveAxisDirection).c_str())) { + changingKey = false; + changingOverdrive = true; + } + if (changingKey) { + std::vector& bindsToChange = (settings.changing4k ? settings.controller4K : settings.controller5K); + std::vector& directionToChange = (settings.changing4k ? settings.controller4KAxisDirection : settings.controller5KAxisDirection); + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), { 0,0,0,200 }); + std::string keyString = (settings.changing4k ? "4k" : "5k"); + std::string changeString = "Press a button/axis for controller " + keyString + " lane " + std::to_string(selLane + 1); + DrawText(changeString.c_str(), (GetScreenWidth() - MeasureText(changeString.c_str(), 20)) / 2, GetScreenHeight() / 2 - 10, 20, WHITE); + if (pressedGamepadInput != -999) { + bindsToChange[selLane] = pressedGamepadInput; + if (pressedGamepadInput < 0) { + directionToChange[selLane] = axisDirection; + } + selLane = 0; + changingKey = false; + pressedGamepadInput = -999; + } } - for (int i = 0; i < lastState.size(); i++) { - DrawText(lastState[i].second.first.c_str(), 200 * i, 60, 20, WHITE); - for (int j = 0; j < 6; j++) { - DrawText(std::string(gamepadAxisNames[j]+": " + std::to_string(axesValues[j])).c_str(), 200*i, 90 + (30 * j), 20, WHITE); - }for (int j = 0; j < 15; j++) { - DrawText(std::string(gamepadButtonNames[j]+ ": " + std::to_string(buttonValues[j])).c_str(), 200 * i, 270 + (20 * j), 20, WHITE); + if (changingOverdrive) { + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), { 0,0,0,200 }); + std::string changeString = "Press a button/axis for controller overdrive"; + DrawText(changeString.c_str(), (GetScreenWidth() - MeasureText(changeString.c_str(), 20)) / 2, GetScreenHeight() / 2 - 10, 20, WHITE); + + if (pressedGamepadInput != -999) { + settings.controllerOverdrive = pressedGamepadInput; + if (pressedGamepadInput < 0) { + settings.controllerOverdriveAxisDirection = axisDirection; + } + changingOverdrive = false; + pressedGamepadInput = -999; } } } else if (selectStage == -1) { - if (GuiButton({ ((float)GetScreenWidth() / 2) - 350,((float)GetScreenHeight() - 60),100,60 }, "Cancel")) { + if (GuiButton({ ((float)GetScreenWidth() / 2) - 350,((float)GetScreenHeight() - 60),100,60 }, "Cancel") && !(changingKey || changingOverdrive)) { selectStage = 0; - settings.keybinds4K = settings.prev4k; - settings.keybinds5K = settings.prev5k; - settings.keybinds4KAlt = settings.prev4kAlt; - settings.keybinds5KAlt = settings.prev5kAlt; + settings.keybinds4K = settings.prev4K; + settings.keybinds5K = settings.prev5K; + settings.keybinds4KAlt = settings.prev4KAlt; + settings.keybinds5KAlt = settings.prev5KAlt; settings.keybindOverdrive = settings.prevOverdrive; settings.keybindOverdriveAlt = settings.prevOverdriveAlt; settings.trackSpeed = settings.prevTrackSpeed; settings.inputOffsetMS = settings.prevInputOffsetMS; settings.avOffsetMS = settings.prevAvOffsetMS; settings.missHighwayDefault = settings.prevMissHighwayColor; + settings.mirrorMode = settings.prevMirrorMode; } - if (GuiButton({ ((float)GetScreenWidth() / 2) + 250,((float)GetScreenHeight() - 60),100,60 }, "Apply")) { + if (GuiButton({ ((float)GetScreenWidth() / 2) + 250,((float)GetScreenHeight() - 60),100,60 }, "Apply") && !(changingKey || changingOverdrive)) { selectStage = 0; - settings.prev4k = settings.keybinds4K; - settings.prev5k = settings.keybinds5K; - settings.prev4kAlt = settings.keybinds4KAlt; - settings.prev5kAlt = settings.keybinds5KAlt; + settings.prev4K = settings.keybinds4K; + settings.prev5K = settings.keybinds5K; + settings.prev4KAlt = settings.keybinds4KAlt; + settings.prev5KAlt = settings.keybinds5KAlt; settings.prevOverdrive = settings.keybindOverdrive; settings.prevOverdriveAlt = settings.keybindOverdriveAlt; settings.prevTrackSpeed = settings.trackSpeed; settings.prevInputOffsetMS = settings.inputOffsetMS; settings.prevAvOffsetMS = settings.avOffsetMS; settings.prevMissHighwayColor = settings.missHighwayDefault; + settings.prevMirrorMode = settings.mirrorMode; settings.saveSettings(directory / "settings.json"); } if (GuiButton({ (float)GetScreenWidth() / 2 - 125,(float)GetScreenHeight() / 2 - 320,250,60 }, "")) { @@ -478,7 +634,9 @@ int main(int argc, char* argv[]) settings.missHighwayDefault = !settings.missHighwayDefault; MissHighwayColor = settings.missHighwayDefault; }; - + if (GuiButton({ (float)GetScreenWidth() / 2 + 250, (float)GetScreenHeight() / 2+90,250,60 }, TextFormat("Mirror mode: %s", settings.mirrorMode ? "True" : "False"))) { + settings.mirrorMode = !settings.mirrorMode; + }; float inputOffsetFloat = (float)settings.inputOffsetMS; DrawText("Input Offset", (float)GetScreenWidth() / 2 - MeasureText("Input Offset", 20) / 2, (float)GetScreenHeight() / 2 - 160, 20, WHITE); DrawText(" -500 ", (float)GetScreenWidth() / 2 - 125 - MeasureText(" -500 ", 20), (float)GetScreenHeight() / 2 - 130, 20, WHITE); @@ -597,7 +755,8 @@ int main(int argc, char* argv[]) SetWindowSize(GetMonitorWidth(GetCurrentMonitor()), GetMonitorHeight(GetCurrentMonitor())); }; } - if (GuiButton({ (float)GetScreenWidth() - 200,120,200,60 }, "Controller Test")) { + if (GuiButton({ (float)GetScreenWidth() - 200,120,200,60 }, "Controller Binds")) { + glfwSetGamepadStateCallback(gamepadStateCallbackSetControls); selectStage = -2; } GuiScrollPanel({ 0, 0, (float)GetScreenWidth() * (3.0f / 5.0f) + 15, (float)GetScreenHeight() }, NULL, { 0, 0, (float)GetScreenWidth() * (3.0f / 5.0f), 60.0f * songList.songs.size() }, &viewScroll, &view); @@ -690,7 +849,8 @@ int main(int argc, char* argv[]) selectStage = 3; isPlaying = true; startedPlayingSong = GetTime(); - glfwSetKeyCallback(glfwGetCurrentContext(), notesCallback); + glfwSetKeyCallback(glfwGetCurrentContext(), keyCallback); + glfwSetGamepadStateCallback(gamepadStateCallback); } DrawText(diffList[i].c_str(), 150 - (MeasureText(diffList[i].c_str(), 30) / 2), 75 + (60 * (float)i), 30, BLACK); } @@ -782,7 +942,8 @@ int main(int argc, char* argv[]) note.perfect = false; note.countedForODPhrase = false; } - glfwSetKeyCallback(glfwGetCurrentContext(), origCallback); + glfwSetKeyCallback(glfwGetCurrentContext(), origKeyCallback); + glfwSetGamepadStateCallback(origGamepadCallback); // notes = songList.songs[curPlayingSong].parts[instrument]->charts[diff].notes.size(); // notes = songList.songs[curPlayingSong].parts[instrument]->charts[diff]; for (odPhrase& phrase : songList.songs[curPlayingSong].parts[instrument]->charts[diff].odPhrases) { @@ -828,7 +989,8 @@ int main(int argc, char* argv[]) note.countedForODPhrase = false; // notes += 1; } - glfwSetKeyCallback(glfwGetCurrentContext(), origCallback); + glfwSetKeyCallback(glfwGetCurrentContext(), origKeyCallback); + glfwSetGamepadStateCallback(origGamepadCallback); // notes = (int)songList.songs[curPlayingSong].parts[instrument]->charts[diff].notes.size(); for (odPhrase& phrase : songList.songs[curPlayingSong].parts[instrument]->charts[diff].odPhrases) { phrase.missed = false; @@ -908,7 +1070,7 @@ int main(int argc, char* argv[]) } } for (int i = 0; i < 4; i++) { - float radius = (i == 1) ? 0.05 : 0.02; + float radius = (i == (settings.mirrorMode?2:1)) ? 0.05 : 0.02; DrawCylinderEx(Vector3{ lineDistance - i, 0, smasherPos + 0.5f }, Vector3{ lineDistance - i, 0, 20 }, radius, radius, 15, Color{ 128,128,128,128 }); } @@ -1001,11 +1163,15 @@ int main(int argc, char* argv[]) if (!curNote.hit && !curNote.accounted && curNote.time + 0.1 < musicTime) { curNote.miss = true; player::MissNote(); + if (curChart.odPhrases.size() > 0) { + curChart.odPhrases[curODPhrase].missed = true; + } curNote.accounted = true; } double relTime = ((curNote.time - musicTime) + VideoOffset) * settings.trackSpeedOptions[settings.trackSpeed]; double relEnd = (((curNote.time + curNote.len) - musicTime) + VideoOffset) * settings.trackSpeedOptions[settings.trackSpeed]; + float notePosX = diffDistance - (1.0f * (settings.mirrorMode ? (diff == 3 ? 4 : 3) - curNote.lane : curNote.lane)); if (relTime > 1.5) { break; } @@ -1014,10 +1180,10 @@ int main(int argc, char* argv[]) // lifts // distance between notes // (furthest left - lane distance) if (curNote.renderAsOD) // 1.6f 0.8 - DrawModel(assets.liftModelOD, Vector3{ diffDistance - (1.0f * curNote.lane),0,smasherPos + (highwayLength * (float)relTime) }, 1.1f, WHITE); + DrawModel(assets.liftModelOD, Vector3{ notePosX,0,smasherPos + (highwayLength * (float)relTime) }, 1.1f, WHITE); // energy phrase else - DrawModel(assets.liftModel, Vector3{ diffDistance - (1.0f * curNote.lane),0,smasherPos + (highwayLength * (float)relTime) }, 1.1f, WHITE); + DrawModel(assets.liftModel, Vector3{ notePosX,0,smasherPos + (highwayLength * (float)relTime) }, 1.1f, WHITE); // regular } else { @@ -1049,22 +1215,22 @@ int main(int argc, char* argv[]) }*/ if (curNote.held && !curNote.renderAsOD) { - DrawCylinderEx(Vector3{ diffDistance - (1.0f * curNote.lane), 0.05f, smasherPos + (highwayLength * (float)relTime) }, Vector3{ diffDistance - (1.0f * curNote.lane),0.05f, smasherPos + (highwayLength * (float)relEnd) }, 0.1f, 0.1f, 15, Color{ 230,100,230,255 }); + DrawCylinderEx(Vector3{ notePosX, 0.05f, smasherPos + (highwayLength * (float)relTime) }, Vector3{ notePosX,0.05f, smasherPos + (highwayLength * (float)relEnd) }, 0.1f, 0.1f, 15, Color{ 230,100,230,255 }); } if (curNote.renderAsOD && curNote.held) { - DrawCylinderEx(Vector3{ diffDistance - (1.0f * curNote.lane), 0.05f, smasherPos + (highwayLength * (float)relTime) }, Vector3{ diffDistance - (1.0f * curNote.lane),0.05f, smasherPos + (highwayLength * (float)relEnd) }, 0.1f, 0.1f, 15, Color{ 255, 255, 180 ,255 }); + DrawCylinderEx(Vector3{ notePosX, 0.05f, smasherPos + (highwayLength * (float)relTime) }, Vector3{ notePosX,0.05f, smasherPos + (highwayLength * (float)relEnd) }, 0.1f, 0.1f, 15, Color{ 255, 255, 180 ,255 }); } if (!curNote.held && curNote.hit || curNote.miss) { - DrawCylinderEx(Vector3{ diffDistance - (1.0f * curNote.lane), 0.05f, smasherPos + (highwayLength * (float)relTime) }, Vector3{ diffDistance - (1.0f * curNote.lane),0.05f, smasherPos + (highwayLength * (float)relEnd) }, 0.1f, 0.1f, 15, Color{ 69,69,69,255 }); + DrawCylinderEx(Vector3{ notePosX, 0.05f, smasherPos + (highwayLength * (float)relTime) }, Vector3{ notePosX,0.05f, smasherPos + (highwayLength * (float)relEnd) }, 0.1f, 0.1f, 15, Color{ 69,69,69,255 }); } if (!curNote.hit && !curNote.accounted && !curNote.miss) { if (curNote.renderAsOD) { - DrawCylinderEx(Vector3{ diffDistance - (1.0f * curNote.lane), 0.05f, smasherPos + (highwayLength * (float)relTime) }, Vector3{ diffDistance - (1.0f * curNote.lane),0.05f, smasherPos + (highwayLength * (float)relEnd) }, 0.1f, 0.1f, 15, Color{ 200, 170, 70 ,255 }); + DrawCylinderEx(Vector3{ notePosX, 0.05f, smasherPos + (highwayLength * (float)relTime) }, Vector3{ notePosX,0.05f, smasherPos + (highwayLength * (float)relEnd) }, 0.1f, 0.1f, 15, Color{ 200, 170, 70 ,255 }); } else { - DrawCylinderEx(Vector3{ diffDistance - (1.0f * curNote.lane), 0.05f, + DrawCylinderEx(Vector3{ notePosX, 0.05f, smasherPos + (highwayLength * (float)relTime) }, - Vector3{ diffDistance - (1.0f * curNote.lane), 0.05f, + Vector3{ notePosX, 0.05f, smasherPos + (highwayLength * (float)relEnd) }, 0.1f, 0.1f, 15, Color{ 150, 19, 150, 255 }); } @@ -1077,13 +1243,13 @@ int main(int argc, char* argv[]) if (((curNote.len) > 0 && (curNote.held || !curNote.hit)) || ((curNote.len) == 0 && !curNote.hit)) { if (curNote.renderAsOD) { if ((!curNote.held && !curNote.miss) || !curNote.hit) { - DrawModel(assets.noteModelOD, Vector3{ diffDistance - (1.0f * curNote.lane),0,smasherPos + (highwayLength * (float)relTime) }, 1.1f, WHITE); + DrawModel(assets.noteModelOD, Vector3{ notePosX,0,smasherPos + (highwayLength * (float)relTime) }, 1.1f, WHITE); }; } else { if ((!curNote.held && !curNote.miss) || !curNote.hit) { - DrawModel(assets.noteModel, Vector3{ diffDistance - (1.0f * curNote.lane),0,smasherPos + (highwayLength * (float)relTime) }, 1.1f, WHITE); + DrawModel(assets.noteModel, Vector3{ notePosX,0,smasherPos + (highwayLength * (float)relTime) }, 1.1f, WHITE); }; } @@ -1091,7 +1257,7 @@ int main(int argc, char* argv[]) } } if (curNote.miss) { - DrawModel(curNote.lift ? assets.liftModel : assets.noteModel, Vector3{ diffDistance - (1.0f * curNote.lane),0,smasherPos + (highwayLength * (float)relTime) }, 1.0f, RED); + DrawModel(curNote.lift ? assets.liftModel : assets.noteModel, Vector3{ notePosX,0,smasherPos + (highwayLength * (float)relTime) }, 1.0f, RED); if (GetMusicTimePlayed(loadedStreams[0].first) < curNote.time + 0.4 && MissHighwayColor) { assets.expertHighway.materials[0].maps[MATERIAL_MAP_ALBEDO].color = RED; } else { @@ -1099,7 +1265,7 @@ int main(int argc, char* argv[]) } } if (curNote.hit && GetMusicTimePlayed(loadedStreams[0].first) < curNote.hitTime + 0.15f) { - DrawCube(Vector3{ diffDistance - (1.0f * curNote.lane), 0, smasherPos }, 1.0f, 0.5f, 0.5f, curNote.perfect ? Color{ 255,215,0,64 } : Color{ 255,255,255,64 }); + DrawCube(Vector3{ notePosX, 0, smasherPos }, 1.0f, 0.5f, 0.5f, curNote.perfect ? Color{ 255,215,0,64 } : Color{ 255,255,255,64 }); if (curNote.perfect) { DrawCube(Vector3{ 3.25, 0, smasherPos }, 1.0f, 0.01f, 0.5f, ORANGE);