Dolphin State Code Optimizations

This commit is contained in:
RogueMaster
2022-12-26 15:44:05 -05:00
parent a1d293712c
commit 4db5f8e421
2 changed files with 29 additions and 229 deletions

View File

@@ -40,6 +40,7 @@ Thank you to all the supporters!
- AC Remote Update from OFW - AC Remote Update from OFW
- Primary/Secondary App Settings Label Fix [From ClaraCrazy](https://github.com/ClaraCrazy/Flipper-Xtreme/pull/32/files) - Primary/Secondary App Settings Label Fix [From ClaraCrazy](https://github.com/ClaraCrazy/Flipper-Xtreme/pull/32/files)
- Archive: Empty folder declaration [From ClaraCrazy](https://github.com/ClaraCrazy/Flipper-Xtreme/commit/dc8329704a72dc662586e70e196608fadbf26952) - Archive: Empty folder declaration [From ClaraCrazy](https://github.com/ClaraCrazy/Flipper-Xtreme/commit/dc8329704a72dc662586e70e196608fadbf26952)
- Dolphin State Code Optimizations [From ClaraCrazy](https://github.com/ClaraCrazy/Flipper-Xtreme/blob/main/applications/services/dolphin/helpers/dolphin_state.c) with corrections to the level thresholds that were too low.
## Install from Release ## Install from Release
FLASH STOCK FIRST BEFORE UPDATING TO CUSTOM FIRMWARE! FLASH STOCK FIRST BEFORE UPDATING TO CUSTOM FIRMWARE!

View File

@@ -14,35 +14,10 @@
#define DOLPHIN_STATE_PATH INT_PATH(DOLPHIN_STATE_FILE_NAME) #define DOLPHIN_STATE_PATH INT_PATH(DOLPHIN_STATE_FILE_NAME)
#define DOLPHIN_STATE_HEADER_MAGIC 0xD0 #define DOLPHIN_STATE_HEADER_MAGIC 0xD0
#define DOLPHIN_STATE_HEADER_VERSION 0x01 #define DOLPHIN_STATE_HEADER_VERSION 0x01
#define LEVEL2_THRESHOLD 450 int level_array[30] = {450, 700, 1100, 1800, 2300, 2900, 3900, 5000, 5900, 7200,
#define LEVEL3_THRESHOLD 700 8400, 10000, 11500, 13000, 15000, 18000, 20000, 22000, 25000, 33000,
#define LEVEL4_THRESHOLD 1100 41000, 50000, 62000, 75000, 90000, 105000, 120000, 135000, 155000};
#define LEVEL5_THRESHOLD 1800
#define LEVEL6_THRESHOLD 2300
#define LEVEL7_THRESHOLD 2900
#define LEVEL8_THRESHOLD 3900
#define LEVEL9_THRESHOLD 5000
#define LEVEL10_THRESHOLD 5900
#define LEVEL11_THRESHOLD 7200
#define LEVEL12_THRESHOLD 8400
#define LEVEL13_THRESHOLD 10000
#define LEVEL14_THRESHOLD 11500
#define LEVEL15_THRESHOLD 13000
#define LEVEL16_THRESHOLD 15000
#define LEVEL17_THRESHOLD 18000
#define LEVEL18_THRESHOLD 20000
#define LEVEL19_THRESHOLD 22000
#define LEVEL20_THRESHOLD 25000
#define LEVEL21_THRESHOLD 33000
#define LEVEL22_THRESHOLD 41000
#define LEVEL23_THRESHOLD 50000
#define LEVEL24_THRESHOLD 62000
#define LEVEL25_THRESHOLD 75000
#define LEVEL26_THRESHOLD 90000
#define LEVEL27_THRESHOLD 105000
#define LEVEL28_THRESHOLD 120000
#define LEVEL29_THRESHOLD 135000
#define LEVEL30_THRESHOLD 155000
#define BUTTHURT_MAX 14 #define BUTTHURT_MAX 14
#define BUTTHURT_MIN 0 #define BUTTHURT_MIN 0
@@ -107,217 +82,41 @@ uint64_t dolphin_state_timestamp() {
} }
bool dolphin_state_is_levelup(uint32_t icounter) { bool dolphin_state_is_levelup(uint32_t icounter) {
return (icounter == LEVEL2_THRESHOLD) || (icounter == LEVEL3_THRESHOLD) || for (int i = 0; i<30; ++i) {
(icounter == LEVEL4_THRESHOLD) || (icounter == LEVEL5_THRESHOLD) || if ((icounter == level_array[i])) {
(icounter == LEVEL6_THRESHOLD) || (icounter == LEVEL7_THRESHOLD) || return true;
(icounter == LEVEL8_THRESHOLD) || (icounter == LEVEL9_THRESHOLD) || }
(icounter == LEVEL10_THRESHOLD) || (icounter == LEVEL11_THRESHOLD) || };
(icounter == LEVEL12_THRESHOLD) || (icounter == LEVEL13_THRESHOLD) || return false;
(icounter == LEVEL14_THRESHOLD) || (icounter == LEVEL15_THRESHOLD) ||
(icounter == LEVEL16_THRESHOLD) || (icounter == LEVEL17_THRESHOLD) ||
(icounter == LEVEL18_THRESHOLD) || (icounter == LEVEL19_THRESHOLD) ||
(icounter == LEVEL20_THRESHOLD) || (icounter == LEVEL21_THRESHOLD) ||
(icounter == LEVEL22_THRESHOLD) || (icounter == LEVEL23_THRESHOLD) ||
(icounter == LEVEL24_THRESHOLD) || (icounter == LEVEL25_THRESHOLD) ||
(icounter == LEVEL26_THRESHOLD) || (icounter == LEVEL27_THRESHOLD) ||
(icounter == LEVEL28_THRESHOLD) || (icounter == LEVEL29_THRESHOLD) ||
(icounter == LEVEL30_THRESHOLD);
} }
uint8_t dolphin_get_level(uint32_t icounter) { uint8_t dolphin_get_level(uint32_t icounter) {
if(icounter <= LEVEL2_THRESHOLD) { for (int i = 0; i < 29; ++i) {
return 1; if (icounter <= level_array[i]) {
} else if(icounter <= LEVEL3_THRESHOLD) { return i + 1;
return 2;
} else if(icounter <= LEVEL4_THRESHOLD) {
return 3;
} else if(icounter <= LEVEL5_THRESHOLD) {
return 4;
} else if(icounter <= LEVEL6_THRESHOLD) {
return 5;
} else if(icounter <= LEVEL7_THRESHOLD) {
return 6;
} else if(icounter <= LEVEL8_THRESHOLD) {
return 7;
} else if(icounter <= LEVEL9_THRESHOLD) {
return 8;
} else if(icounter <= LEVEL10_THRESHOLD) {
return 9;
} else if(icounter <= LEVEL11_THRESHOLD) {
return 10;
} else if(icounter <= LEVEL12_THRESHOLD) {
return 11;
} else if(icounter <= LEVEL13_THRESHOLD) {
return 12;
} else if(icounter <= LEVEL14_THRESHOLD) {
return 13;
} else if(icounter <= LEVEL15_THRESHOLD) {
return 14;
} else if(icounter <= LEVEL16_THRESHOLD) {
return 15;
} else if(icounter <= LEVEL17_THRESHOLD) {
return 16;
} else if(icounter <= LEVEL18_THRESHOLD) {
return 16;
} else if(icounter <= LEVEL19_THRESHOLD) {
return 18;
} else if(icounter <= LEVEL20_THRESHOLD) {
return 19;
} else if(icounter <= LEVEL21_THRESHOLD) {
return 20;
} else if(icounter <= LEVEL22_THRESHOLD) {
return 21;
} else if(icounter <= LEVEL23_THRESHOLD) {
return 22;
} else if(icounter <= LEVEL24_THRESHOLD) {
return 23;
} else if(icounter <= LEVEL25_THRESHOLD) {
return 24;
} else if(icounter <= LEVEL26_THRESHOLD) {
return 25;
} else if(icounter <= LEVEL27_THRESHOLD) {
return 26;
} else if(icounter <= LEVEL28_THRESHOLD) {
return 27;
} else if(icounter <= LEVEL29_THRESHOLD) {
return 28;
} else if(icounter <= LEVEL30_THRESHOLD) {
return 29;
} else {
return 30;
} }
} }
return 30;
}
uint32_t dolphin_state_xp_above_last_levelup(uint32_t icounter) { uint32_t dolphin_state_xp_above_last_levelup(uint32_t icounter) {
uint32_t threshold = 0; if(level_array[0] > icounter) {
if(icounter <= LEVEL2_THRESHOLD) { for(int i = 1; i < 29; ++i) {
threshold = 0; if(icounter <= level_array[i]) {
} else if(icounter <= LEVEL3_THRESHOLD) { return level_array[i] - icounter + 1;
threshold = LEVEL2_THRESHOLD + 1; }
} else if(icounter <= LEVEL4_THRESHOLD) { }
threshold = LEVEL3_THRESHOLD + 1;
} else if(icounter <= LEVEL5_THRESHOLD) {
threshold = LEVEL4_THRESHOLD + 1;
} else if(icounter <= LEVEL6_THRESHOLD) {
threshold = LEVEL5_THRESHOLD + 1;
} else if(icounter <= LEVEL7_THRESHOLD) {
threshold = LEVEL6_THRESHOLD + 1;
} else if(icounter <= LEVEL8_THRESHOLD) {
threshold = LEVEL7_THRESHOLD + 1;
} else if(icounter <= LEVEL9_THRESHOLD) {
threshold = LEVEL8_THRESHOLD + 1;
} else if(icounter <= LEVEL10_THRESHOLD) {
threshold = LEVEL9_THRESHOLD + 1;
} else if(icounter <= LEVEL11_THRESHOLD) {
threshold = LEVEL10_THRESHOLD + 1;
} else if(icounter <= LEVEL12_THRESHOLD) {
threshold = LEVEL11_THRESHOLD + 1;
} else if(icounter <= LEVEL13_THRESHOLD) {
threshold = LEVEL12_THRESHOLD + 1;
} else if(icounter <= LEVEL14_THRESHOLD) {
threshold = LEVEL13_THRESHOLD + 1;
} else if(icounter <= LEVEL15_THRESHOLD) {
threshold = LEVEL14_THRESHOLD + 1;
} else if(icounter <= LEVEL16_THRESHOLD) {
threshold = LEVEL15_THRESHOLD + 1;
} else if(icounter <= LEVEL17_THRESHOLD) {
threshold = LEVEL16_THRESHOLD + 1;
} else if(icounter <= LEVEL18_THRESHOLD) {
threshold = LEVEL17_THRESHOLD + 1;
} else if(icounter <= LEVEL19_THRESHOLD) {
threshold = LEVEL18_THRESHOLD + 1;
} else if(icounter <= LEVEL20_THRESHOLD) {
threshold = LEVEL19_THRESHOLD + 1;
} else if(icounter <= LEVEL21_THRESHOLD) {
threshold = LEVEL20_THRESHOLD + 1;
} else if(icounter <= LEVEL22_THRESHOLD) {
threshold = LEVEL21_THRESHOLD + 1;
} else if(icounter <= LEVEL23_THRESHOLD) {
threshold = LEVEL22_THRESHOLD + 1;
} else if(icounter <= LEVEL24_THRESHOLD) {
threshold = LEVEL23_THRESHOLD + 1;
} else if(icounter <= LEVEL25_THRESHOLD) {
threshold = LEVEL24_THRESHOLD + 1;
} else if(icounter <= LEVEL26_THRESHOLD) {
threshold = LEVEL25_THRESHOLD + 1;
} else if(icounter <= LEVEL27_THRESHOLD) {
threshold = LEVEL26_THRESHOLD + 1;
} else if(icounter <= LEVEL28_THRESHOLD) {
threshold = LEVEL27_THRESHOLD + 1;
} else if(icounter <= LEVEL29_THRESHOLD) {
threshold = LEVEL28_THRESHOLD + 1;
} else if(icounter <= LEVEL30_THRESHOLD) {
threshold = LEVEL29_THRESHOLD + 1;
} else {
threshold = LEVEL30_THRESHOLD + 1;
} }
return icounter - threshold; return icounter;
} }
uint32_t dolphin_state_xp_to_levelup(uint32_t icounter) { uint32_t dolphin_state_xp_to_levelup(uint32_t icounter) {
uint32_t threshold = 0; for(int i = 0; i < 29; ++i) {
if(icounter <= LEVEL2_THRESHOLD) { if(icounter <= level_array[i]) {
threshold = LEVEL2_THRESHOLD; return level_array[i] - icounter;
} else if(icounter <= LEVEL3_THRESHOLD) { }
threshold = LEVEL3_THRESHOLD;
} else if(icounter <= LEVEL4_THRESHOLD) {
threshold = LEVEL4_THRESHOLD;
} else if(icounter <= LEVEL5_THRESHOLD) {
threshold = LEVEL5_THRESHOLD;
} else if(icounter <= LEVEL6_THRESHOLD) {
threshold = LEVEL6_THRESHOLD;
} else if(icounter <= LEVEL7_THRESHOLD) {
threshold = LEVEL7_THRESHOLD;
} else if(icounter <= LEVEL8_THRESHOLD) {
threshold = LEVEL8_THRESHOLD;
} else if(icounter <= LEVEL9_THRESHOLD) {
threshold = LEVEL9_THRESHOLD;
} else if(icounter <= LEVEL10_THRESHOLD) {
threshold = LEVEL10_THRESHOLD;
} else if(icounter <= LEVEL11_THRESHOLD) {
threshold = LEVEL11_THRESHOLD;
} else if(icounter <= LEVEL12_THRESHOLD) {
threshold = LEVEL12_THRESHOLD;
} else if(icounter <= LEVEL13_THRESHOLD) {
threshold = LEVEL13_THRESHOLD;
} else if(icounter <= LEVEL14_THRESHOLD) {
threshold = LEVEL14_THRESHOLD;
} else if(icounter <= LEVEL15_THRESHOLD) {
threshold = LEVEL15_THRESHOLD;
} else if(icounter <= LEVEL16_THRESHOLD) {
threshold = LEVEL16_THRESHOLD;
} else if(icounter <= LEVEL17_THRESHOLD) {
threshold = LEVEL17_THRESHOLD;
} else if(icounter <= LEVEL18_THRESHOLD) {
threshold = LEVEL18_THRESHOLD;
} else if(icounter <= LEVEL19_THRESHOLD) {
threshold = LEVEL19_THRESHOLD;
} else if(icounter <= LEVEL20_THRESHOLD) {
threshold = LEVEL20_THRESHOLD;
} else if(icounter <= LEVEL21_THRESHOLD) {
threshold = LEVEL21_THRESHOLD;
} else if(icounter <= LEVEL22_THRESHOLD) {
threshold = LEVEL22_THRESHOLD;
} else if(icounter <= LEVEL23_THRESHOLD) {
threshold = LEVEL23_THRESHOLD;
} else if(icounter <= LEVEL24_THRESHOLD) {
threshold = LEVEL24_THRESHOLD;
} else if(icounter <= LEVEL25_THRESHOLD) {
threshold = LEVEL25_THRESHOLD;
} else if(icounter <= LEVEL26_THRESHOLD) {
threshold = LEVEL26_THRESHOLD;
} else if(icounter <= LEVEL27_THRESHOLD) {
threshold = LEVEL27_THRESHOLD;
} else if(icounter <= LEVEL28_THRESHOLD) {
threshold = LEVEL28_THRESHOLD;
} else if(icounter <= LEVEL29_THRESHOLD) {
threshold = LEVEL29_THRESHOLD;
} else if(icounter <= LEVEL30_THRESHOLD) {
threshold = LEVEL30_THRESHOLD;
} else {
threshold = (uint32_t)-1;
} }
return threshold - icounter; return (uint32_t)-1 - icounter;
} }
void dolphin_state_on_deed(DolphinState* dolphin_state, DolphinDeed deed) { void dolphin_state_on_deed(DolphinState* dolphin_state, DolphinDeed deed) {
@@ -401,4 +200,4 @@ void dolphin_state_clear_limits(DolphinState* dolphin_state) {
} }
dolphin_state->data.butthurt_daily_limit = 0; dolphin_state->data.butthurt_daily_limit = 0;
dolphin_state->dirty = true; dolphin_state->dirty = true;
} }