fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
ab1e4b7
gram
1#include "modes/MeleeLimits.hpp" 2//#include "modes/Fixed.h" 3 4#define HISTORYLEN 5//changes in target stick position 5 6#define ANALOG_STICK_MIN 48 7#define ANALOG_DEAD_MIN (128-22)/*this is in the deadzone*/ 8#define ANALOG_STICK_NEUTRAL 128 9#define ANALOG_DEAD_MAX (128+22)/*this is in the deadzone*/ 10#define ANALOG_STICK_MAX 208 11#define ANALOG_CROUCH (128-50)/*this y coordinate will hold a crouch*/ 12#define ANALOG_TAPJUMP (128+53)/*this Y coordinate will tap jump always (running is less)*/ 13#define ANALOG_DASH_LEFT (128-64)/*this x coordinate will dash left*/ 14#define ANALOG_DASH_RIGHT (128+64)/*this x coordinate will dash right*/ 15#define ANALOG_SDI_LEFT (128-56)/*this x coordinate will sdi left*/ 16#define ANALOG_SDI_RIGHT (128+56)/*this x coordinate will sdi right*/ 17#define ANALOG_UTILT_LEFT (128-44)/*this y coordinate will never uptilt*/ 18#define ANALOG_UTILT_RIGHT (128+44)/*this y coordinate will never uptilt*/ 19#define MELEE_SDI_RAD 3136/* if x^2+y^2 >= this, it's diagonal SDI*/ 20#define MELEE_RIM_RAD1 6185/*if x^2+y^2 >= this, it's on the rim and 6ms*/ 21#define MELEE_RIM_RAD2 6858/*if x^2+y^2 >= this, it's past the rim and 7ms*/ 22#define MELEE_RIM_RAD3 8979/*if x^2+y^2 >= this, it's past the rim and 8ms*/ 23 24#define TRAVELTIME_EASY1 6//ms 25#define TRAVELTIME_EASY2 7//ms 26#define TRAVELTIME_EASY3 8//ms for 112+cubic it takes 83% to get to dash, for 80+linear it takes 80% to get to dash 27#define TRAVELTIME_CROSS 12//ms to cross gate; unused 28#define TRAVELTIME_INTERNAL 12//ms for "easy" to "internal"; 2/3 frame 29#define TRAVELTIME_SLOW 88//(5.5*16)//ms for tap SDI nerfing, 5.5 frames 30 31#define TIMELIMIT_DOWNUP (16*3*250)//units of 4us; how long after a crouch to upward input should it begin a jump? 32#define JUMP_TIME (16*2*250)//units of 4us; after a recent crouch to upward input, always hold full up for 2 frames 33 34#define TIMELIMIT_FRAME 4167//(16.66...*250)//units of 4us; 1 frame, for reference 35#define TIMELIMIT_HALFFRAME 2083//(8.33...*250)//units of 4us; 1/2 frame 36#define TIMELIMIT_DEBOUNCE 1500//(6*250)//units of 4us; 6ms; 37#define TIMELIMIT_SIMUL 500//(2*250)//units of 4us; 2ms: if the latest inputs are less than 2 ms apart then don't nerf cardiag 38 39#define TIMELIMIT_TAPSHUTOFF 16000//4 frames for tap jump shutoff 40 41//not used #define TIMELIMIT_DASH 60000//(16*15*250)//units of 4us; last dash time prior to a pivot input; 15 frames 42 43//not used #define TIMELIMIT_QCIRC 24000//(16*6*250)//units of 4us; 6 frames 44 45#define TIMELIMIT_TAP 22000//(16*5.5*250)//units of 4us; 5.5 frames 46#define TIMELIMIT_TAP_PLUS 34000//(16*8.5*250)//units of 4us; 3 additional frames 47 48#define TIMELIMIT_CARDIAG 32000//(16*8*250)//units of 4us; 8 frames 49 50#define TIMELIMIT_WANK 22000//(16*5.5*250)//units of 4us; 5.5 frames 51 52#define TIMELIMIT_PIVOTTILT 32000//(16*8*250)//units of 4us; 8 frames 53 54#define TIMELIMIT_SDI_COUNTDOWN 16000//(16*4*250)//units of 4us; 4 frames 55 56enum pivotdir {P_None ,P_Leftright ,P_Rightleft }; 57enum travelType {T_Lin ,T_Quad ,T_Cubic ,T_Quart ,T_Delay }; 58 59#define ZONE_DIR 0b0000'1111 60#define ZONE_U 0b0000'0001 61#define ZONE_D 0b0000'0010 62#define ZONE_L 0b0000'0100 63#define ZONE_R 0b0000'1000 64 65#define BITS_SDI 0b1111'0000 66#define BITS_SDI_WANK 0b0001'0000 67#define BITS_SDI_TAP_CARD 0b0010'0000 68#define BITS_SDI_TAP_DIAG 0b0100'0000 69#define BITS_SDI_TAP_CRDG 0b1000'0000 70 71typedef struct { 72uint16_t timestamp ;//in samples 73uint8_t tt ;//travel time used in ms 74uint8_t x ; 75uint8_t y ; 76uint8_t x_start ; 77uint8_t y_start ; 78uint8_t x_end ; 79uint8_t y_end ; 80}shortstate ; 81 82//for sdi nerfs, we want to record only movement between sdi zones, ignoring movement within zones 83typedef struct { 84uint16_t timestamp ;//in samples 85uint8_t zone ; 86bool stale ; 87}sdizonestate ; 88 89//for pivot nerfs, we want to record only movement between dash zones, ignoring movement within zones 90typedef struct { 91uint16_t timestamp ;//in samples 92uint8_t zone ; 93bool stale ; 94}pivotzonestate ; 95 96uint8_t isEasy (const uint8_t x ,const uint8_t y ) { 97//is it on the rim? 98const uint8_t xnorm = (x > ANALOG_STICK_NEUTRAL ? (x - ANALOG_STICK_NEUTRAL ) : (ANALOG_STICK_NEUTRAL - x )); 99const uint8_t ynorm = (y > ANALOG_STICK_NEUTRAL ? (y - ANALOG_STICK_NEUTRAL ) : (ANALOG_STICK_NEUTRAL - y )); 100const uint16_t xsquared = xnorm * xnorm ; 101const uint16_t ysquared = ynorm * ynorm ; 102const uint16_t radSquared = xsquared + ysquared ; 103if ((radSquared ) >=MELEE_RIM_RAD1 ) { 104//is it within 3 units of the diagonal? or is it a cardinal? 105const uint8_t diagMax = max (xnorm ,ynorm ); 106const uint8_t diagMin = min (xnorm ,ynorm ); 107const uint8_t diff = diagMax - diagMin ; 108if (diff <=6 || xnorm == 0 || ynorm == 0 ) { 109//if so, yes 110if (radSquared >=MELEE_RIM_RAD3 ) { 111return 3 ; 112 }else if (radSquared >=MELEE_RIM_RAD2 ) { 113return 2 ; 114 }else { 115return 1 ; 116 } 117 }else { 118return 0 ; 119 } 120 }else { 121return 0 ; 122 } 123} 124 125uint8_t getRandom (uint16_t currentTime ) { 126// Use the time of the first directional input to initialize the LCG 127static uint16_t random = currentTime ; 128// Constant from https://arxiv.org/pdf/2001.05304.pdf 129random = 0xD9F5 * random + 1 ; 130// XOR all nibbles together, necessary to minimize patterns with a power of 2 LCG 131uint8_t xor1 = random ^ (random >>8 ); 132uint8_t xor2 = xor1 ^ (xor1 >>4 ); 133return xor2 %16 ; 134} 135// 1 2 1 //4 136// 2 4 2 //8 137// 1 2 1 //4 138// totals up to 16 139void randomizeCoord (uint8_t & x ,uint8_t & y ,uint16_t currentTime ) { 140const uint8_t random = getRandom (currentTime ); 141const uint8_t left = ((random ^0b0 )& 0b11 )== 0 ; 142//middle is when random & 0b01 or 0b10 143const uint8_t right = ((random ^0b11 )& 0b11 )== 0 ; 144const uint8_t up = ((random ^0b0000 )& 0b1100 )== 0 ; 145//middle is when random & 0b01xx or 0b10xx 146const uint8_t down = ((random ^0b1100 )& 0b1100 )== 0 ; 147 148//don't randomize when x or y are neutral 149x = (x != ANALOG_STICK_NEUTRAL ) ?x - left + right :x ; 150y = (y != ANALOG_STICK_NEUTRAL ) ?y - down + up :y ; 151} 152 153uint8_t lookback (const uint8_t currentIndex , 154const uint8_t samplesBack ) { 155if (samplesBack > currentIndex ) { 156return (HISTORYLEN - samplesBack )+ currentIndex ; 157 }else { 158return currentIndex - samplesBack ; 159 } 160} 161 162//the output will have the following bits set: 163//0b0000'0001 for up 164//0b0000'0010 for down 165//0b0000'0100 for left 166//0b0000'1000 for right 167//no bits set for neutral 168//thresholds are dash for cardinals, and deadzone for diagonals 169uint8_t sdiZone (const uint8_t x ,const uint8_t y ) { 170uint8_t result = 0b0000'0000 ; 171const uint8_t xnorm = (x > ANALOG_STICK_NEUTRAL ? (x - ANALOG_STICK_NEUTRAL ) : (ANALOG_STICK_NEUTRAL - x )); 172const uint8_t ynorm = (y > ANALOG_STICK_NEUTRAL ? (y - ANALOG_STICK_NEUTRAL ) : (ANALOG_STICK_NEUTRAL - y )); 173const uint16_t xsquared = xnorm * xnorm ; 174const uint16_t ysquared = ynorm * ynorm ; 175const uint16_t radSquared = xsquared + ysquared ; 176if (x >=ANALOG_DEAD_MIN && x <=ANALOG_DEAD_MAX ) { 177if (y < ANALOG_SDI_LEFT ) { 178result = result |ZONE_D ; 179 }else if (y > ANALOG_SDI_RIGHT ) { 180result = result |ZONE_U ; 181 } 182 }else if (x < ANALOG_DEAD_MIN ) { 183if (y < ANALOG_DEAD_MIN && radSquared >=MELEE_SDI_RAD ) { 184result = result |ZONE_D |ZONE_L ; 185 }else if (y > ANALOG_DEAD_MAX && radSquared >=MELEE_SDI_RAD ) { 186result = result |ZONE_U |ZONE_L ; 187 }else if (x <=ANALOG_SDI_LEFT ) { 188result = result |ZONE_L ; 189 } 190 }else /*if(x > ANALOG_DEAD_MAX)*/ { 191if (y < ANALOG_DEAD_MIN && radSquared >=MELEE_SDI_RAD ) { 192result = result |ZONE_D |ZONE_R ; 193 }else if (y > ANALOG_DEAD_MAX && radSquared >=MELEE_SDI_RAD ) { 194result = result |ZONE_U |ZONE_R ; 195 }else if (x >=ANALOG_SDI_RIGHT ) { 196result = result |ZONE_R ; 197 } 198 } 199return result ; 200} 201 202//the output will have the following bits set: 203//0b0000'0100 for left 204//0b0000'1000 for right 205//no bits set for neutral 206//thresholds are dash for the x-axis 207uint8_t pivotZone (const uint8_t x ) { 208uint8_t result = 0b0000'0000 ; 209if (x <=ANALOG_DASH_LEFT ) { 210result = result |ZONE_L ; 211 }else if (x >=ANALOG_DASH_RIGHT ) { 212result = result |ZONE_R ; 213 } 214return result ; 215} 216 217uint8_t uptiltShutoffZone (const uint8_t y ) { 218uint8_t result = 0b0000'0000 ; 219if (y > ANALOG_DEAD_MAX && y < ANALOG_TAPJUMP ) { 220result = result |ZONE_U ; 221 } 222return result ; 223} 224 225//not a general purpose popcount, this is specifically for zones 226uint8_t popcount_zone (const uint8_t bitsIn ) { 227uint8_t count = 0 ; 228for (uint8_t i = 0 ;i < 4 ;i ++ ) { 229if ((bitsIn >>i )& 0b0000'0001 ) { 230count ++ ; 231 } 232 } 233return count ; 234} 235 236uint8_t isTapSDI (const sdizonestate zoneHistory [HISTORYLEN ], 237const uint8_t currentIndex , 238const uint16_t currentTime , 239const uint16_t sampleSpacing ) { 240uint8_t output = 0 ; 241 242//grab the last five zones 243const uint8_t historyLength = min (5 ,HISTORYLEN ); 244uint8_t zoneList [historyLength ]; 245uint16_t timeList [historyLength ]; 246bool staleList [historyLength ]; 247for (int i = 0 ;i < historyLength ;i ++ ) { 248const uint8_t index = lookback (currentIndex ,i ); 249zoneList [i ]= zoneHistory [index ].zone ; 250timeList [i ]= zoneHistory [index ].timestamp ; 251staleList [i ]= zoneHistory [index ].stale ; 252 } 253const uint8_t popCur = popcount_zone (zoneList [0 ]); 254const uint8_t popOne = popcount_zone (zoneList [1 ]); 255 256//detect repeated center-cardinal sequences, or repeated cardinal-diagonal sequences 257// if we're changing zones back and forth 258if (zoneList [0 ]!= zoneList [1 ]&& (zoneList [0 ]== zoneList [2 ])&& (zoneList [1 ]== zoneList [3 ])) { 259//check the time duration 260const uint16_t timeDiff0 = (currentTime - timeList [2 ])* sampleSpacing ;//make sure things aren't reliant on long-past inputs 261const uint16_t timeDiff1 = (timeList [0 ]- timeList [2 ])* sampleSpacing ;//rising edge to rising edge, or falling edge to falling edge 262//const uint16_t timeDiff2 = (timeList[0] - timeList[1])*sampleSpacing;//rising to falling, or falling to rising 263//We want to nerf it if there is more than one press every 6 frames, but not if the previous press or release duration is less than 1 frame 264if (!staleList [2 ]&& (timeDiff0 < TIMELIMIT_TAP_PLUS && timeDiff1 < TIMELIMIT_TAP && timeDiff0 > TIMELIMIT_DEBOUNCE )) { 265if ((zoneList [0 ]== 0 )|| (zoneList [1 ]== 0 )) {//if one of the pairs of zones is zero, it's tapping a cardinal (or tapping a diagonal modifier) 266output = output |BITS_SDI_TAP_CARD ; 267 }else {//if(popCur != 0 && popOne != 0) { //one is cardinal and the other is diagonal 268output = output |BITS_SDI_TAP_DIAG ; 269 } 270 } 271 } 272//detect: 273// center-cardinal-diagonal-center-cardinal (-diagonal) 274//center-cardinal-diagonal-cardinal-center-cardinal (-diagonal) 275//where the the diagonals are the same 276//the cardinals don't have to be the same in case they're inputting 2365 etc 277 278//simpler: if the last 5 inputs are in the origin, one cardinal, and one diagonal 279//and that there was a recent return to center 280//at least one of each zone, and at least two diagonals 281uint8_t diagZone = 0b1111'1111 ; 282uint8_t origCount = 0 ; 283uint8_t cardCount = 0 ; 284uint8_t diagCount = 0 ; 285for (int i = 0 ;i < historyLength ;i ++ ) { 286const uint8_t popcnt = popcount_zone (zoneList [i ]); 287if (popcnt == 0 ) { 288origCount ++ ; 289 }else if (popcnt == 1 ) { 290cardCount ++ ; 291 }else { 292diagCount ++ ; 293diagZone = diagZone & zoneList [i ];//if two of these don't match, it'll have zero or one bits set 294 } 295 } 296 {//to limit scope of these vars 297//check the bit count of diagonal matching 298const bool diagMatch = popcount_zone (diagZone )== 2 ; 299//check whether it returned to center recently 300//const bool recentOrig = (zoneList[1] & zoneList[2]) == 0;//may be too lenient in case people throw in modifier taps? 301//check whether the input was fast enough 302const bool shortTime = ((timeList [0 ]- timeList [4 ])* sampleSpacing < TIMELIMIT_CARDIAG )&& 303 ((timeList [0 ]- timeList [1 ])* sampleSpacing > TIMELIMIT_SIMUL )&& 304 !staleList [4 ]; 305 306// if only the same diagonal was pressed 307// if the origin, cardinal, and two diagonals were all entered 308// within the time limit 309if (diagMatch && origCount && cardCount && diagCount > 1 && shortTime ) { 310output = output |BITS_SDI_TAP_CRDG ; 311 } 312 } 313 314//3 input sdi 315//center-cardinal-diagonal-diagonal 316//center-cardinal-diagonal-same cardinal-diagonal 317//all directions except center must be the same 318uint8_t cardZone = 0b1111'1111 ; 319diagZone = 0b1111'1111 ; 320origCount = 0 ; 321cardCount = 0 ; 322diagCount = 0 ; 323for (int i = 0 ;i < historyLength ;i ++ ) { 324const uint8_t popcnt = popcount_zone (zoneList [i ]); 325if (popcnt == 0 ) { 326origCount ++ ; 327break ;//stop counting once there's an origin 328 }else if (popcnt == 1 ) { 329cardCount ++ ; 330cardZone = cardZone & zoneList [i ];//if there are two different cardinals then it won't count 331 }else { 332diagCount ++ ; 333diagZone = diagZone & zoneList [i ];//if two of these don't match, it'll have zero or one bits set 334 } 335 } 336 {//to limit scope of these vars 337//check the bit count of diagonal matching 338const bool adjacentDiag = popcount_zone (diagZone & cardZone )== 1 ; 339const bool shortTime = ((timeList [0 ]- timeList [3 ])* sampleSpacing < TIMELIMIT_WANK )&& 340 !staleList [3 ]; 341//if it hit two different diagonals 342// hit origin, at least one cardinal, and two diagonals 343// within the time limit 344if (adjacentDiag && origCount && cardCount && diagCount > 1 && shortTime ) { 345output = output |BITS_SDI_WANK ; 346 } 347 } 348 349//wank sdi around a diagonal 350//7 8 9 351//4 5 6 352//1 2 3 353// 354//this would be 4 7 8 7 type deal 355 356//first check if another one isn't already triggered 357if (!output ) { 358//were there two of the same diagonal on alternating inputs? 359if ((zoneList [0 ]== zoneList [2 ])&& (popcount_zone (zoneList [0 ])== 2 )) { 360//check duration 361if ((timeList [0 ]- timeList [2 ])* sampleSpacing < TIMELIMIT_WANK && !staleList [2 ]) { 362output = output |BITS_SDI_WANK |BITS_SDI_TAP_CRDG ; 363 } 364 } 365 } 366 367//return the last cardinal in the zone list before the last diagonal, useful for SDI diagonal nerfs. 368bool lookNow = false; 369bool alreadyWritten = false; 370for (int i = 0 ;i < historyLength ;i ++ ) { 371if ((popcount_zone (zoneList [i ])== 2 )&& !alreadyWritten ) { 372lookNow = true; 373 } 374if ((popcount_zone (zoneList [i ])== 1 )&& !alreadyWritten && lookNow ) { 375output = output |zoneList [i ]; 376alreadyWritten = true; 377 } 378 } 379return output ; 380} 381 382/* 383Fixed88 quadraticEasing(Fixed88 i){ 384Fixed88 x2 = fixedMul(i,i); 385return x2; 386} 387Fixed88 cubicEasing(Fixed88 i){ 388Fixed88 x2 = fixedMul(i,i); 389Fixed88 x3 = fixedMul(x2,i); 390return x3; 391} 392Fixed88 quarticEasing(Fixed88 i){ 393Fixed88 x2 = fixedMul(i,i); 394Fixed88 x4 = fixedMul(x2,x2); 395return x4; 396} 397*/ 398 399void travelTimeCalc (const uint16_t currentTime , 400const uint16_t inputTime , 401const uint16_t sampleSpacing ,//units of 4us 402const uint8_t msTravel , 403const uint8_t startX , 404const uint8_t startY , 405const uint8_t destX , 406const uint8_t destY , 407const travelType type , 408bool & doneTraveling ,//apply tt if false; when travel time is done, set it to true 409uint8_t & outX , 410uint8_t & outY ) { 411const uint16_t samplesElapsed = currentTime - inputTime ; 412 413const uint16_t timeElapsed = samplesElapsed * sampleSpacing ;//units of 4 us 414if (type == T_Lin ) { 415const uint16_t travelTimeElapsed = timeElapsed /msTravel ;//250 times the fraction of the travel time elapsed 416 417//For the following 256s, they used to be 250, but AVR had division issues 418// and would only be able to reach a value of 6 when returning to neutral, 419// from the right only. 420//Switching to 256 fixed it somehow, at the expense of 2.4% greater travel time. 421const uint16_t cappedTT = min (256 ,travelTimeElapsed ); 422 423const int16_t dX = ((destX - startX )* cappedTT )/256 ; 424const int16_t dY = ((destY - startY )* cappedTT )/256 ; 425 426const uint16_t newX = startX + dX ; 427const uint16_t newY = startY + dY ; 428 429outX = (uint8_t )newX ; 430outY = (uint8_t )newY ; 431 }else if (type == T_Delay ) { 432if (timeElapsed <=msTravel * 250 ) { 433outX = startX ; 434outY = startY ; 435 }else { 436outX = destX ; 437outY = destY ; 438 } 439// } else{ 440// uint16_t usTravel4 = msTravel*250;//units of 4 us 441// const uint16_t clampedElapsed = min(usTravel4, timeElapsed); 442// if(clampedElapsed == usTravel4) { 443// doneTraveling = true; 444// } 445// const Fixed88 timeElapsedPercent = fastDiv(intToFixed(int8_t(timeElapsed>>6)), intToFixed(int8_t(usTravel4>>6))); 446// 447// Fixed88 interpolatedTime = max(min(timeElapsedPercent, intToFixed(int8_t(1))), intToFixed(int8_t(0))); 448// 449// /*if(type == T_Quad) { 450// * */ 451// interpolatedTime = quadraticEasing(interpolatedTime); 452// /* 453// } else if(type == T_Cubic) { 454// interpolatedTime = cubicEasing(interpolatedTime); 455// } else {//if(type == T_Quart) 456// interpolatedTime = quarticEasing(interpolatedTime); 457// } 458// */ 459// const Fixed88 x0 = intToFixed(int8_t(startX- 128)) >> 1; 460// const Fixed88 x1 = intToFixed(int8_t(destX - 128)) >> 1; 461// const Fixed88 y0 = intToFixed(int8_t(startY- 128)) >> 1; 462// const Fixed88 y1 = intToFixed(int8_t(destY - 128)) >> 1; 463// const Fixed88 fixedX = lerp(x0, x1, interpolatedTime) << 1; 464// const Fixed88 fixedY = lerp(y0, y1, interpolatedTime) << 1; 465// 466// outX = uint8_t(fixedToInt(fixedX) + 128); 467// outY = uint8_t(fixedToInt(fixedY) + 128); 468 } 469 470if (timeElapsed > msTravel * 250 && !doneTraveling ) { 471doneTraveling = true; 472 } 473if (doneTraveling ) { 474outX = destX ; 475outY = destY ; 476 } 477} 478 479void limitOutputs (const uint16_t sampleSpacing ,//in units of 4us 480const abtest whichAB , 481const InputState & inputs , 482const OutputState & rawOutputIn , 483OutputState & finalOutput ) { 484//First, we want to check if the raw output has changed. 485//If it has changed, then we need to store it with a timestamp in our buffer. 486//Also check whether it's an "easy" coordinate or not (rim+origin = easy) 487//Then, we need to parse the buffer and detect whether: 488// an empty pivot has likely occurred (0.5 to 1.5 frames?) ============ this depends on our travel time implementation unless we store the analog value history too 489// how? 490// (make you do a 2f jump input if you input an upward tilt coordinate within 10 frames) 491// (lock out the A press if you input a downward tilt coordinate for 3 frames) 492// the input is crouching 493// (make you do a 2f jump input if you input an upward tilt coordinate within 4 frames) 494// rapid quarter circling (wank di) 495// lock out second diagonal (opposite axis). May not be important with neutral SOCD. 496// rapid tapping (tap di) 497// Temporarily increase travel time to... 16 ms? 24ms? 498// rapid eighth-circling (cardinal diagonal neutral repeat) 499// Increase travel time on cardinal and lock out later diagonals. 500 501static bool doneTraveling = true; 502 503static uint16_t currentTime = 0 ; 504currentTime ++ ; 505 506static shortstate aHistory [HISTORYLEN ]; 507static sdizonestate sdiZoneHist [HISTORYLEN ]; 508static pivotzonestate pivotZoneHist [HISTORYLEN ]; 509 510static InputState prevInputs ; 511 512static bool initialized = false; 513if (!initialized ) { 514for (int i = 0 ;i < HISTORYLEN ;i ++ ) { 515aHistory [i ].timestamp = 0 ; 516aHistory [i ].tt = 6 ; 517aHistory [i ].x = ANALOG_STICK_NEUTRAL ; 518aHistory [i ].y = ANALOG_STICK_NEUTRAL ; 519aHistory [i ].x_start = ANALOG_STICK_NEUTRAL ; 520aHistory [i ].y_start = ANALOG_STICK_NEUTRAL ; 521aHistory [i ].x_end = ANALOG_STICK_NEUTRAL ; 522aHistory [i ].y_end = ANALOG_STICK_NEUTRAL ; 523sdiZoneHist [i ].timestamp = 0 ; 524sdiZoneHist [i ].zone = 0 ; 525sdiZoneHist [i ].stale = true; 526pivotZoneHist [i ].timestamp = 0 ; 527pivotZoneHist [i ].zone = 0 ; 528pivotZoneHist [i ].stale = true; 529 } 530//track the inputs that can cause changes to coordinates 531prevInputs .lf3 = inputs .lf3 ;//left; 532prevInputs .lf1 = inputs .lf1 ;//right; 533prevInputs .lf2 = inputs .lf2 ;//down; 534prevInputs .rf4 = inputs .rf4 ;//up; 535prevInputs .rt3 = inputs .rt3 ;//c_left; 536prevInputs .rt5 = inputs .rt5 ;//c_right; 537prevInputs .rt2 = inputs .rt2 ;//c_down; 538prevInputs .rt4 = inputs .rt4 ;//c_up; 539prevInputs .rf1 = inputs .rf1 ;//b; 540prevInputs .lf4 = inputs .lf4 ;//l;//we don't care about recording these 541prevInputs .rf5 = inputs .rf5 ;//r; 542prevInputs .rf7 = inputs .rf7 ;//lightshield; 543prevInputs .rf8 = inputs .rf8 ;//midshield; 544prevInputs .lt1 = inputs .lt1 ;//mod_x; 545prevInputs .lt2 = inputs .lt2 ;//mod_y; 546 547initialized = true; 548 } 549static uint8_t currentIndexA = 0 ; 550static uint8_t currentIndexSDI = 0 ; 551 552static travelType delayType = T_Lin ; 553 554//calculate whether to do a airdodge travel adjustment or not 555//we want to continue the previous travel time, but if it's an airdodge with a prohibited angle destination, we overwrite the angle. 556//this way the travel itself never skips straight to the destination. 557 558//if L or R has been pressed 559// if the coordinates changed 560// if they need to be nerfed 561// nerf them 562// else 563// if L or R caused the coordinate change 564// set the travel time destination to the new coordinate 565// if the coordinates are in a nerf region (but haven't been corrected yet) 566// nerf them 567//if L or R has just been released 568// if it was nerfing them, un-nerf them 569bool wavedashSkip = false; 570static bool wavedashWasNerfed = false; 571if (inputs .lf4 /*l*/ || inputs .rf5 /*r*/ ) { 572//check angles to see if it's in a shallow wavedash region 573//the trigger was the only input that changed, potentially causing a retargeting without restarting the travel time 574const uint8_t xIn = rawOutputIn .leftStickX ; 575const uint8_t yIn = rawOutputIn .leftStickY ; 576uint8_t x_end = xIn ; 577uint8_t y_end = yIn ; 578 579//calculate magnitudes 580const uint16_t xInMag = xIn > ANALOG_STICK_NEUTRAL ?xIn - ANALOG_STICK_NEUTRAL :ANALOG_STICK_NEUTRAL - xIn ; 581const uint16_t yInMag = yIn > ANALOG_STICK_NEUTRAL ?yIn - ANALOG_STICK_NEUTRAL :ANALOG_STICK_NEUTRAL - yIn ; 582 583//calculate radius (squared) 584const uint16_t xsquared = xInMag * xInMag ; 585const uint16_t ysquared = yInMag * yInMag ; 586const uint16_t radSquared = xsquared + ysquared ; 587 588//if the coordinates changed 589if (aHistory [currentIndexA ].x != rawOutputIn .leftStickX || aHistory [currentIndexA ].y != rawOutputIn .leftStickY ) { 590//if the angle moved, check whether the currently requested angle is too shallow 591//if so, nerf it, regardless of whether it was nerfed before. 592if (((yInMag * 157 < xInMag * 80 )|| (xInMag * 157 < yInMag * 80 ))&& xInMag && yInMag ) {//157 and 80 are the closest ratio to 27 degrees (27.0013) 593//the closest coordinate inside the melee unit circle to 27 degrees is 51 and 26 (27.0127) 594const uint8_t longCoord = radSquared > 5625 ?70 :51 ; 595const uint8_t shortCoord = radSquared > 5625 ?36 :26 ; 596const uint8_t xWavedash = xInMag > yInMag ?longCoord :shortCoord ; 597const uint8_t yWavedash = yInMag > xInMag ?longCoord :shortCoord ; 598//overwrite with a nerfed angle 599if (xIn < ANALOG_STICK_NEUTRAL ) { 600x_end = ANALOG_STICK_NEUTRAL - xWavedash ; 601 }else { 602x_end = ANALOG_STICK_NEUTRAL + xWavedash ; 603 } 604if (yIn < ANALOG_STICK_NEUTRAL ) { 605y_end = ANALOG_STICK_NEUTRAL - yWavedash ; 606 }else { 607y_end = ANALOG_STICK_NEUTRAL + yWavedash ; 608 } 609//fuzz it 610randomizeCoord (x_end ,y_end ,currentTime ); 611//write it back 612aHistory [currentIndexA ].x_end = x_end ; 613aHistory [currentIndexA ].y_end = y_end ; 614//also record the new requested coordinates 615aHistory [currentIndexA ].x = rawOutputIn .leftStickX ; 616aHistory [currentIndexA ].y = rawOutputIn .leftStickY ; 617//mark as having been nerfed so we can undo it later 618wavedashWasNerfed = true; 619 }else { 620wavedashWasNerfed = false; 621//only skip inputs if the L or R press caused the change in coordinates 622if (!(prevInputs .lf4 /*l*/ || prevInputs .rf5 /*r*/ )) { 623//check if the L/R press coincides with a change in coordinate, indicating L/R NDM 624if ( 625prevInputs .lf3 == inputs .lf3 /*left*/ && 626prevInputs .lf1 == inputs .lf1 /*right*/ && 627prevInputs .lf2 == inputs .lf2 /*down*/ && 628prevInputs .rf4 == inputs .rf4 /*up*/ && 629prevInputs .rt3 == inputs .rt3 /*c_left*/ && 630prevInputs .rt5 == inputs .rt5 /*c_right*/ && 631prevInputs .rt2 == inputs .rt2 /*c_down*/ && 632prevInputs .rt4 == inputs .rt4 /*c_up*/ && 633prevInputs .rf1 == inputs .rf1 /*b*/ && 634prevInputs .rf7 == inputs .rf7 /*lightshield*/ && 635prevInputs .rf8 == inputs .rf8 /*midshield*/ && 636prevInputs .lt1 == inputs .lt1 /*mod_x*/ && 637prevInputs .lt2 == inputs .lt2 /*mod_y*/ 638 ) { 639//then we need to skip to the new coordinate 640//fuzz it 641randomizeCoord (x_end ,y_end ,currentTime ); 642//write it back 643aHistory [currentIndexA ].x_end = x_end ; 644aHistory [currentIndexA ].y_end = y_end ; 645//also record the new requested coordinates 646aHistory [currentIndexA ].x = rawOutputIn .leftStickX ; 647aHistory [currentIndexA ].y = rawOutputIn .leftStickY ; 648//mark this change as having been skipped so we don't restart travel time later 649wavedashSkip = true; 650 } 651 } 652 } 653 } 654//even if pressing L or R didn't move the coordinate, but it is now illegal 655//nerf it 656if (((yInMag * 157 < xInMag * 80 )|| (xInMag * 157 < yInMag * 80 ))&& xInMag && yInMag && !wavedashWasNerfed ) {//157 and 80 are the closest ratio to 27 degrees (27.0013) 657//the closest coordinate inside the melee unit circle to 27 degrees is 51 and 26 (27.0127) 658const uint8_t xWavedash = xInMag > yInMag ?51 :26 ; 659const uint8_t yWavedash = yInMag > xInMag ?51 :26 ; 660//overwrite with a nerfed angle 661if (xIn < ANALOG_STICK_NEUTRAL ) { 662x_end = ANALOG_STICK_NEUTRAL - xWavedash ; 663 }else { 664x_end = ANALOG_STICK_NEUTRAL + xWavedash ; 665 } 666if (yIn < ANALOG_STICK_NEUTRAL ) { 667y_end = ANALOG_STICK_NEUTRAL - yWavedash ; 668 }else { 669y_end = ANALOG_STICK_NEUTRAL + yWavedash ; 670 } 671//fuzz it 672randomizeCoord (x_end ,y_end ,currentTime ); 673//write it back 674aHistory [currentIndexA ].x_end = x_end ; 675aHistory [currentIndexA ].y_end = y_end ; 676//mark as having been nerfed so we can undo it later 677wavedashWasNerfed = true; 678 } 679 }else if (!(inputs .lf4 /*l*/ || inputs .rf5 /*r*/ )&& (prevInputs .lf4 /*l*/ || prevInputs .rf5 /*r*/ )) { 680//if nerfed, then de-nerf once L and R are no longer pressed 681if (wavedashWasNerfed ) { 682const uint8_t xIn = rawOutputIn .leftStickX ; 683const uint8_t yIn = rawOutputIn .leftStickY ; 684uint8_t x_end = xIn ; 685uint8_t y_end = yIn ; 686//fuzz it again 687randomizeCoord (x_end ,y_end ,currentTime ); 688//write it back 689aHistory [currentIndexA ].x_end = x_end ; 690aHistory [currentIndexA ].y_end = y_end ; 691wavedashWasNerfed = false; 692 } 693 } 694//record previous inputs 695prevInputs .lf3 = inputs .lf3 ;//left; 696prevInputs .lf1 = inputs .lf1 ;//right; 697prevInputs .lf2 = inputs .lf2 ;//down; 698prevInputs .rf4 = inputs .rf4 ;//up; 699prevInputs .rt3 = inputs .rt3 ;//c_left; 700prevInputs .rt5 = inputs .rt5 ;//c_right; 701prevInputs .rt2 = inputs .rt2 ;//c_down; 702prevInputs .rt4 = inputs .rt4 ;//c_up; 703prevInputs .rf1 = inputs .rf1 ;//b; 704prevInputs .lf4 = inputs .lf4 ;//l;//we don't care about recording these 705prevInputs .rf5 = inputs .rf5 ;//r; 706prevInputs .rf7 = inputs .rf7 ;//lightshield; 707prevInputs .rf8 = inputs .rf8 ;//midshield; 708prevInputs .lt1 = inputs .lt1 ;//mod_x; 709prevInputs .lt2 = inputs .lt2 ;//mod_y; 710 711//calculate travel from the previous step 712uint8_t prelimAX = rawOutputIn .leftStickX ; 713uint8_t prelimAY = rawOutputIn .leftStickY ; 714uint8_t prelimCX = rawOutputIn .rightStickX ; 715uint8_t prelimCY = rawOutputIn .rightStickY ; 716 717//test for SDI in the raw inputs 718const uint8_t tapSDI = isTapSDI (sdiZoneHist ,currentIndexSDI ,currentTime ,sampleSpacing ); 719//if cardinal tap SDI 720if (tapSDI & BITS_SDI_TAP_CARD ) { 721aHistory [currentIndexA ].tt = max (aHistory [currentIndexA ].tt ,TRAVELTIME_SLOW ); 722delayType = T_Lin ; 723 } 724//if oscillating about a diagonal 725static uint16_t sdiCountdown = 0 ; 726if ((tapSDI & BITS_SDI_WANK )&& (tapSDI & BITS_SDI_TAP_CRDG )) { 727//both wank&cardiag indicates that it was oscillating about a diagonal 728//new destinations will have 5.5 frame travel time for a duration of 4 frames from the last sdi detection event 729sdiCountdown = TIMELIMIT_SDI_COUNTDOWN ; 730//prelimCX = ANALOG_STICK_NEUTRAL - 50; 731 } 732if (sdiCountdown > sampleSpacing ) { 733sdiCountdown = sdiCountdown - sampleSpacing ; 734aHistory [currentIndexA ].tt = max (aHistory [currentIndexA ].tt ,TRAVELTIME_SLOW ); 735 }else { 736sdiCountdown = 0 ; 737 } 738 739travelTimeCalc (currentTime , 740aHistory [currentIndexA ].timestamp , 741sampleSpacing , 742aHistory [currentIndexA ].tt , 743aHistory [currentIndexA ].x_start , 744aHistory [currentIndexA ].y_start , 745aHistory [currentIndexA ].x_end , 746aHistory [currentIndexA ].y_end , 747delayType , 748doneTraveling , 749prelimAX , 750prelimAY ); 751 752//detect an input that gives >50% pivot probability given travel time 753//if we are in a new pivot zone, record the new zone 754//we're keeping these in sequence so we copy them all 755if (pivotZoneHist [0 ].zone != pivotZone (prelimAX )) { 756for (int i = HISTORYLEN - 2 ;i >=0 ;i -- ) { 757pivotZoneHist [i + 1 ].timestamp = pivotZoneHist [i ].timestamp ; 758pivotZoneHist [i + 1 ].zone = pivotZoneHist [i ].zone ; 759pivotZoneHist [i + 1 ].stale = pivotZoneHist [i ].stale ; 760 } 761 762pivotZoneHist [0 ].timestamp = currentTime ; 763pivotZoneHist [0 ].zone = pivotZone (prelimAX ); 764pivotZoneHist [0 ].stale = false; 765 } 766for (int i = 0 ;i < HISTORYLEN ;i ++ ) { 767if ((currentTime - pivotZoneHist [i ].timestamp )* (sampleSpacing >>1 )> 15 * 16 * 125 ) {//15 frames 768pivotZoneHist [i ].stale = true; 769 } 770 } 771 772//pivot inputs: 773//current--------------------past 774//---neutral ----left ---neutral ---right 775//---neutral ----left ---right 776//---neutral ---right ---neutral ---left 777//---neutral ---right ---left 778//start time of neutral minus 779// start time of ^ between 0.5 and 1.5 frames 780//current time minus start time of neutral should be used to limit how long the nerf applies for 781pivotdir direction = P_None ; 782if (pivotZoneHist [0 ].zone == 0 ) { 783if (pivotZoneHist [1 ].zone == ZONE_L && (pivotZoneHist [2 ].zone == ZONE_R || pivotZoneHist [3 ].zone == ZONE_R )) { 784direction = P_Rightleft ; 785 }else if (pivotZoneHist [1 ].zone == ZONE_R && (pivotZoneHist [2 ].zone == ZONE_L || pivotZoneHist [3 ].zone == ZONE_L )) { 786direction = P_Leftright ; 787 } 788 } 789uint16_t pivotLength = (pivotZoneHist [0 ].timestamp - pivotZoneHist [1 ].timestamp )* sampleSpacing ; 790if (pivotLength < TIMELIMIT_HALFFRAME || pivotLength > TIMELIMIT_FRAME + TIMELIMIT_HALFFRAME ) { 791//less than 50% chance it was a successful pivot 792direction = P_None ; 793 } 794//check for staleness 795if (pivotZoneHist [3 ].stale || pivotZoneHist [2 ].stale || pivotZoneHist [1 ].stale || pivotZoneHist [0 ].stale ) { 796//if the previous movement was more than 15 frames earlier 797direction = P_None ; 798 } 799 800uint16_t pivotAge = (currentTime - pivotZoneHist [0 ].timestamp )* sampleSpacing ; 801if (pivotAge > TIMELIMIT_PIVOTTILT ) { 802direction = P_None ; 803 } 804 805//tap jump shutoff 806static uint8_t uptiltSamples = 0 ; 807if (prelimAY > ANALOG_DEAD_MAX ) { 808uptiltSamples = min (uptiltSamples + 1 ,254 ); 809 }else { 810uptiltSamples = 0 ; 811 } 812const uint16_t timeSinceNotUptilt = uptiltSamples * sampleSpacing ; 813 814//actually apply the nerfs 815//debug c-stick output 816/* 817if(direction != P_None) { 818prelimCY = 255; 819} 820*/ 821//if it's a downtilt coordinate... 822bool pivotTilt = false; 823bool upTilt = false; 824//if(direction != P_None && prelimAY < ANALOG_DEAD_MIN) { 825if (direction != P_None && aHistory [currentIndexA ].y_end < ANALOG_DEAD_MIN ) { 826pivotTilt = true; 827 } 828//if it's a uptilt coordinate... 829//if(direction != P_None && prelimAY > ANALOG_DEAD_MAX) { 830if (direction != P_None && aHistory [currentIndexA ].y_end > ANALOG_DEAD_MAX ) { 831pivotTilt = true; 832upTilt = true; 833 } 834if (pivotTilt ) { 835//If there's a pivot tilt, preserve the angle as best as possible but maximize the radius 836int8_t xCoord = prelimAX - ANALOG_STICK_NEUTRAL ; 837int8_t yCoord = prelimAY - ANALOG_STICK_NEUTRAL ; 838uint8_t xCoordAbs = abs (xCoord ); 839uint8_t yCoordAbs = abs (yCoord ); 840 841if (upTilt && xCoordAbs > yCoordAbs ) { 842//Force all upward angles to a minimum of 45deg to prevent pivot uftilt and ensure tap jump 843prelimAX = ANALOG_STICK_NEUTRAL + (xCoord >=0 ?127 :-127 ); 844prelimAY = ANALOG_STICK_NEUTRAL + 127 ; 845 }else { 846//Scale magnitude as close as we can get to 127 in increments of 0.5 847//Quick way to ensure we get above 80 magnitude with minimal rounding errors 848uint8_t stretchMult = (uint8_t )(127 * 2 ) /max (xCoordAbs ,yCoordAbs ); 849prelimAX = ANALOG_STICK_NEUTRAL + xCoord * stretchMult /2 ; 850prelimAY = ANALOG_STICK_NEUTRAL + yCoord * stretchMult /2 ; 851 } 852if (upTilt && timeSinceNotUptilt > TIMELIMIT_TAPSHUTOFF ) { 853//the x direction got flipped to avoid affecting diagonals 854if (direction == P_Leftright ) { 855prelimAX = ANALOG_STICK_NEUTRAL + 56 ; 856 }else if (direction == P_Rightleft ) { 857prelimAX = ANALOG_STICK_NEUTRAL - 56 ; 858 } 859prelimAY = ANALOG_STICK_NEUTRAL + 56 ; 860 } 861 } 862 863//if it's a crouch to upward coordinate too quickly, make Y jump even if a tilt was desired 864static uint16_t timeSinceCrouch = 100 ;//must be < 65535 when multiplied by 500, the longest possible sampleSpacing, but bigger than the (timelimit/250) 865static bool downUpJumping ; 866static uint16_t timeSinceJump = 100 ; 867 868//increment timeSinceCrouch unless you have crouched 869timeSinceCrouch = min (timeSinceCrouch + 1 ,100 ); 870if (prelimAY < ANALOG_CROUCH ) { 871timeSinceCrouch = 0 ; 872 } 873 874//increment timeSinceJump unless you want to trigger a jump 875timeSinceJump = min (timeSinceJump + 1 ,100 ); 876if (timeSinceCrouch * sampleSpacing < TIMELIMIT_DOWNUP 877&& prelimAY > ANALOG_DEAD_MAX 878&& prelimAY < ANALOG_TAPJUMP 879&& prelimAX > ANALOG_UTILT_LEFT 880&& prelimAX < ANALOG_UTILT_RIGHT 881&& !downUpJumping ) { 882downUpJumping = true; 883timeSinceJump = 0 ; 884 } 885 886if (timeSinceJump * sampleSpacing < JUMP_TIME && downUpJumping ) { 887prelimAY = 255 ; 888timeSinceCrouch = 100 ;//prevent an extra duration jump if the jump ends before the lockout window 889 }else { 890downUpJumping = false; 891 } 892 893//if it's wank sdi (TODO) or diagonal tap SDI, lock out the cross axis 894//we use the sdi variable from earlier 895static bool sdiIsNerfed = false;//only for lockouts, not travel time 896if (tapSDI & (BITS_SDI_TAP_DIAG |BITS_SDI_TAP_CRDG |BITS_SDI_WANK )){ 897if (tapSDI & (ZONE_L |ZONE_R )) { 898//lock the cross axis 899prelimAY = ANALOG_STICK_NEUTRAL ; 900//make sure future cross axis travel time begins at the origin 901aHistory [currentIndexA ].y_end = prelimAY ; 902//the following is disabled because the sdi threshold is actually 0.7 903//prevent the cardinal axis from dipping below the sdi threshold by preserving its coordinate 904//prelimAX = aHistory[currentIndexA].x_start; 905//make sure that future cardinal travel time begins where it was before 906//aHistory[currentIndexA].x_end = prelimAX; 907sdiIsNerfed = true; 908//prelimCX = ANALOG_STICK_NEUTRAL + 50; 909 }else if (tapSDI & (ZONE_U |ZONE_D )) { 910//lock the cross axis 911prelimAX = ANALOG_STICK_NEUTRAL ; 912//make sure future cross axis travel time begins at the origin 913aHistory [currentIndexA ].x_end = prelimAX ; 914//the following is disabled because the sdi threshold is actually 0.7 915//prevent the cardinal axis from dipping below the sdi threshold by preserving its coordinate 916//prelimAY = aHistory[currentIndexA].y_start; 917//make sure that future cardinal travel time begins where it was before 918//aHistory[currentIndexA].y_end = prelimAY; 919sdiIsNerfed = true; 920//prelimCX = ANALOG_STICK_NEUTRAL - 50; 921 }//one or the other should occur 922//debug to see if SDI was detected 923/* 924if(tapSDI & BITS_SDI_TAP_CARD) { 925prelimCY = ANALOG_STICK_NEUTRAL + 50; 926} 927if(tapSDI & BITS_SDI_TAP_CRDG) { 928prelimCY = ANALOG_STICK_NEUTRAL - 50; 929} 930if(tapSDI & BITS_SDI_WANK) { 931prelimCY = ANALOG_STICK_NEUTRAL + 120; 932} 933*/ 934 }else if (sdiIsNerfed ) { 935aHistory [currentIndexA ].x_end = aHistory [currentIndexA ].x ; 936aHistory [currentIndexA ].y_end = aHistory [currentIndexA ].y ; 937if (prelimAX == ANALOG_STICK_NEUTRAL && prelimAY == ANALOG_STICK_NEUTRAL ) { 938sdiIsNerfed = false; 939 } 940 } 941 942//==================================recording history======================================// 943 944//if we are in a new SDI zone, record the new zone 945if (sdiZoneHist [currentIndexSDI ].zone != sdiZone (rawOutputIn .leftStickX ,rawOutputIn .leftStickY )) { 946currentIndexSDI = (currentIndexSDI + 1 ) %HISTORYLEN ; 947 948sdiZoneHist [currentIndexSDI ].timestamp = currentTime ; 949sdiZoneHist [currentIndexSDI ].zone = sdiZone (rawOutputIn .leftStickX ,rawOutputIn .leftStickY ); 950sdiZoneHist [currentIndexSDI ].stale = false; 951 } 952for (int i = 0 ;i < HISTORYLEN ;i ++ ) { 953if (currentTime - sdiZoneHist [i ].timestamp > 8 * 16 * 2 ) {//8 frames * 16 ms * max 2 samples 954sdiZoneHist [i ].stale = true; 955 } 956 } 957 958//if we have a new coordinate, record the new info, the travel time'd locked out stick coordinate, and set travel time 959const uint8_t xIn = rawOutputIn .leftStickX ; 960const uint8_t yIn = rawOutputIn .leftStickY ; 961static uint8_t prevX = xIn ; 962static uint8_t prevY = yIn ; 963//prelimAY = 5*currentIndexA;//we found that there are no new inputs causing the jumps 964//prelimAY = currentTime % 256;//we found that time isn't jumping 965if (prevX != xIn || prevY != yIn ) { 966//don't update things if this is a wavedash in a banned region 967if (!wavedashSkip ) { 968doneTraveling = false; 969const uint8_t oldIndexA = currentIndexA ; 970currentIndexA = (currentIndexA + 1 ) %HISTORYLEN ; 971 972prevX = xIn ; 973prevY = yIn ; 974 975uint8_t xInRand = xIn ; 976uint8_t yInRand = yIn ; 977randomizeCoord (xInRand ,yInRand ,currentTime ); 978 979aHistory [currentIndexA ].timestamp = currentTime ; 980aHistory [currentIndexA ].x = xIn ; 981aHistory [currentIndexA ].y = yIn ; 982aHistory [currentIndexA ].x_end = xInRand ; 983aHistory [currentIndexA ].y_end = yInRand ; 984aHistory [currentIndexA ].x_start = prelimAX ; 985aHistory [currentIndexA ].y_start = prelimAY ; 986 987//make the initial travel begin instantly 1 unit towards the destination 988if (prelimAX == prevX ) { 989if (xInRand > prevX ) { 990aHistory [currentIndexA ].x_start ++ ; 991 } 992if (xInRand < prevX ) { 993aHistory [currentIndexA ].x_start -- ; 994 } 995 } 996if (prelimAY == prevY ) { 997if (yInRand > prevY ) { 998aHistory [currentIndexA ].y_start ++ ; 999 } 1000if (yInRand < prevY ) { 1001aHistory [currentIndexA ].y_start -- ; 1002 } 1003 } 1004 1005uint8_t prelimTT = TRAVELTIME_EASY3 ; 1006//if the destination is not an "easy" coordinate 1007const uint8_t easiness = isEasy (xIn ,yIn ); 1008if (easiness == 1 ) { 1009prelimTT = TRAVELTIME_EASY1 ; 1010delayType = T_Lin ; 1011 }else if (easiness == 2 ) { 1012prelimTT = TRAVELTIME_EASY2 ; 1013delayType = T_Lin ; 1014 }else if (easiness == 3 ) { 1015prelimTT = TRAVELTIME_EASY3 ; 1016delayType = T_Lin ; 1017 }else { 1018prelimTT = TRAVELTIME_INTERNAL ; 1019delayType = T_Lin ; 1020 } 1021//prelimTT = TRAVELTIME_SLOW;//========================debug 1022aHistory [currentIndexA ].tt = prelimTT ; 1023 } 1024 } 1025 1026//===============================applying the nerfed coords=================================// 1027finalOutput .a = rawOutputIn .a ; 1028finalOutput .b = rawOutputIn .b ; 1029finalOutput .x = rawOutputIn .x ; 1030finalOutput .y = rawOutputIn .y ; 1031finalOutput .buttonL = rawOutputIn .buttonL ; 1032finalOutput .buttonR = rawOutputIn .buttonR ; 1033finalOutput .triggerLDigital = rawOutputIn .triggerLDigital ; 1034finalOutput .triggerRDigital = rawOutputIn .triggerRDigital ; 1035finalOutput .start = rawOutputIn .start ; 1036finalOutput .select = rawOutputIn .select ; 1037finalOutput .home = rawOutputIn .home ; 1038finalOutput .dpadUp = rawOutputIn .dpadUp ; 1039finalOutput .dpadDown = rawOutputIn .dpadDown ; 1040finalOutput .dpadLeft = rawOutputIn .dpadLeft ; 1041finalOutput .dpadRight = rawOutputIn .dpadRight ; 1042finalOutput .leftStickClick = rawOutputIn .leftStickClick ; 1043finalOutput .rightStickClick = rawOutputIn .rightStickClick ; 1044finalOutput .leftStickX = prelimAX ; 1045finalOutput .leftStickY = prelimAY ; 1046finalOutput .rightStickX = prelimCX ; 1047finalOutput .rightStickY = prelimCY ; 1048finalOutput .triggerLAnalog = rawOutputIn .triggerLAnalog ; 1049finalOutput .triggerRAnalog = rawOutputIn .triggerRAnalog ; 1050}