[Feature] Implement seeded runs by adding a Seed selection menu (#482)
* initial commit * wip * WIP * WIP * clang format * Choose Seed navigation mostly done * seed input navigation done * seed input done * cleanup and clang format * Implement base 10 to 36 conversions * Enable seeded runs * clang format * show default deck sprite, name and description * Rename Deck enum to DeckType * Implement arbitrary 9-patch expand system * Make 9-patch example smaller in the docs * Improve NinePatchRect docs * fix Deck back side sprite palette * clang format * Add last deck description * clang format * Fix 'Z' in seed input keyboard * Fix rebase issue * fix deck sprite not updating * Documents static funcs in run_setup.c * more documentation * clang format * Move Play button to the left in its row * Tests WIP * removing tests for random.h * use the new StateMachine struct * First wave of fixes * Fix the 9-patch again * Changed the base 36 logic so it's in big endian * properly set end of base 36 string to '\0' * typos * fix cursor position after rolling a seed + fix random seed generation * Make keyboard more intuitive to use * static const var * Address more comment from @ricfehr3 * clang format * clang format * clang format * clang format * clang format * clang format * clang format * fix deck palette * create the `DEF_SEED_KEYBOARD_BUTTON_OBJECT` macro * Replace `expand_3x3` by a call to `expand_9-patch` * clang format * clang format * clang format * fix rebase iussue in state_machine.h --------- Co-authored-by: MathisMartin31 <mathis.martin31@gmail.com>
This commit is contained in:
+52
-3
@@ -17,6 +17,12 @@
|
||||
|
||||
#define UNDEFINED -1
|
||||
|
||||
/**
|
||||
* @def MAX_BASE36
|
||||
* @brief Hex value of "ZZZZZZ" in base 36
|
||||
*/
|
||||
#define MAX_BASE36 0x81BF0FFF
|
||||
|
||||
/**
|
||||
* @def SIGN
|
||||
* @brief Get the sign (signum) of an integer
|
||||
@@ -33,9 +39,10 @@
|
||||
*/
|
||||
#define NUM_ELEM_IN_ARR(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
#define INT_MAX_DIGITS 11 // strlen(str(INT_MAX)) = strlen("-2147483647")
|
||||
#define UINT_MAX_DIGITS 10 // strlen(str(UINT32_MAX)) = strlen("4294967295")
|
||||
#define UINT8_MAX_DIGITS 3 // strlen(str(UINT8_MAX)) = strlen("255")
|
||||
#define INT_MAX_DIGITS 11 // strlen(str(INT_MAX)) = strlen("-2147483647")
|
||||
#define UINT_MAX_DIGITS 10 // strlen(str(UINT32_MAX)) = strlen("4294967295")
|
||||
#define UINT8_MAX_DIGITS 3 // strlen(str(UINT8_MAX)) = strlen("255")
|
||||
#define BASE36_MAX_DIGITS 6 // strlen("ZZZZZZ")
|
||||
|
||||
#define ONE_K 1000
|
||||
#define ONE_M 1000000
|
||||
@@ -150,4 +157,46 @@ static inline int u32_get_digits(uint32_t n)
|
||||
return 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert a base-36 string representation to a 32-bit unsigned integer.
|
||||
* Since we are dealing with base-36 instead of decimal, the 32-bit decimal
|
||||
* value of a base-36 string representation `b36` is equal to:
|
||||
*
|
||||
* \f( b36[0] * 36^0 + b36[1] * 36^1 + b36[2] * 36^2 ... \f)
|
||||
*
|
||||
* @param b36_str input char[] to convert to decimal, must be of size `BASE36_MAX_DIGITS+1`
|
||||
*
|
||||
* @returns the 32-bit unsigned value of `b36_str`
|
||||
*/
|
||||
uint32_t base36_to_u32(const char b36_str[]);
|
||||
|
||||
/**
|
||||
* @brief Convert a 32-bit unsigned integer to its base-36 string representation.
|
||||
* This will perform 6 divisions, so it will be significantly more expensive
|
||||
* than its `base36_to_u32` counterpart.
|
||||
*
|
||||
* We will iterate over all digits from `BASE36_MAX_DIGITS-1` to 0 and determine
|
||||
* their values in base-36, to then construct the string representation `b36_str`
|
||||
* in base-36 or the integer `n`
|
||||
*
|
||||
* Initially set to `n`, the variable `acc` will contain any given stage `i`:
|
||||
* ```
|
||||
* b32[i] * 36^i + b32[i-1] * 36^(i-1) + ... + b32[0]
|
||||
* ```
|
||||
*
|
||||
* And we can thus extract the two following values:
|
||||
* ```
|
||||
* b32[i] = acc / 36^i
|
||||
* acc = acc mod 36^i = b32[i-1] * 36^(i-1) + ... + b32[0]
|
||||
* ```
|
||||
*
|
||||
* So that acc can now be used for the following step, until `i` hits 0
|
||||
*
|
||||
* @param n integer value to convert to a base-36 representation
|
||||
* @param b36_str output char[], representation of `n` in base-36
|
||||
*
|
||||
* @sa base36_to_u32
|
||||
*/
|
||||
void u32_to_base36(uint32_t n, char b36_str[]);
|
||||
|
||||
#endif // UTIL_H
|
||||
|
||||
Reference in New Issue
Block a user