Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swadge Hero #301

Merged
merged 59 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
f80aa49
Add chart file processing
AEFeinstein Sep 16, 2024
1e675e8
Update submodules and make a target to do so automatically
AEFeinstein Sep 16, 2024
c3530cc
Write number of notes in compressed chart
AEFeinstein Sep 16, 2024
97f331e
Add basic SSR mode that barely works
AEFeinstein Sep 16, 2024
9735b88
Get what looks like a rhythm game running
AEFeinstein Sep 17, 2024
9662c3a
Fix crash at end of song
AEFeinstein Sep 17, 2024
cad8bc7
Fix firmware compilation
AEFeinstein Sep 18, 2024
c233f13
Add lead-in to SSR
AEFeinstein Sep 18, 2024
7bc2210
Start button input
AEFeinstein Sep 18, 2024
8e2e0f3
Draw hold notes
AEFeinstein Sep 18, 2024
d94802f
Add note hits and tail holds
AEFeinstein Sep 19, 2024
88df763
Add chart file processing
AEFeinstein Sep 16, 2024
18a6092
Update submodules and make a target to do so automatically
AEFeinstein Sep 16, 2024
be8391b
Write number of notes in compressed chart
AEFeinstein Sep 16, 2024
036e51a
Add basic SSR mode that barely works
AEFeinstein Sep 16, 2024
39e6e4a
Get what looks like a rhythm game running
AEFeinstein Sep 17, 2024
8247e48
Fix crash at end of song
AEFeinstein Sep 17, 2024
9b1046a
Fix firmware compilation
AEFeinstein Sep 18, 2024
1a9b35d
Add lead-in to SSR
AEFeinstein Sep 18, 2024
350f94a
Start button input
AEFeinstein Sep 18, 2024
784b6be
Draw hold notes
AEFeinstein Sep 18, 2024
8ecfe7b
Add note hits and tail holds
AEFeinstein Sep 19, 2024
ab7a62e
Merge branch 'ssr' of https://github.com/AEFeinstein/Super-2024-Swadg…
AEFeinstein Sep 19, 2024
9eedcf8
Merged main into SSR
AEFeinstein Sep 19, 2024
05538d2
Add SSR to emulator modes list
AEFeinstein Sep 19, 2024
a12d8fc
Rename to Swadge Hero
AEFeinstein Sep 19, 2024
1489823
Start work on difficulties
AEFeinstein Sep 20, 2024
c626ef8
Add Swadge Hero Menu
AEFeinstein Sep 20, 2024
981df96
Fix charts
AEFeinstein Sep 20, 2024
7c8e820
Use correct colors and buttons for difficulties
AEFeinstein Sep 21, 2024
5c2dd85
Increase CONFIG_ESP_MAIN_TASK_STACK_SIZE
AEFeinstein Sep 21, 2024
cbb3c88
Allocate SwadgeHero in SPIRAM
AEFeinstein Sep 21, 2024
baf0aec
Squash merge origin/main into ssr
AEFeinstein Sep 22, 2024
957d7b5
Squash merge origin/main into ssr
AEFeinstein Sep 22, 2024
3bd1e99
Add hardware type config
AEFeinstein Sep 23, 2024
d213798
Fix warnings
AEFeinstein Sep 23, 2024
7f1d8fb
Squashed commit of the following:
AEFeinstein Sep 23, 2024
9963510
Work on more precise timings
AEFeinstein Sep 26, 2024
ab3cc2a
Add fret lines based on MIDI tempo
AEFeinstein Sep 27, 2024
e2a4089
Squashed commit of the following:
AEFeinstein Sep 27, 2024
36cce30
Merge main into ssr
AEFeinstein Sep 27, 2024
777cde9
Replace circles with icons
AEFeinstein Sep 28, 2024
10f0e82
Add combo, score, and fail
AEFeinstein Sep 29, 2024
62e5e93
Add high score display to menu (not a separate view)
AEFeinstein Sep 29, 2024
b2962c1
Add skeleton for game end screen
AEFeinstein Sep 30, 2024
09fb79b
Added option to seek to end of midi
AEFeinstein Oct 1, 2024
45f01b5
Add fail meter charting
AEFeinstein Oct 1, 2024
e8e8c88
Fix bug when seeking to end of MIDI file (fixes fail meter chart)
AEFeinstein Oct 2, 2024
c41c925
Add ability to recolor the mania menu
AEFeinstein Oct 3, 2024
1bdf634
Merge remote-tracking branch 'origin/main' into ssr
AEFeinstein Oct 3, 2024
6ab0a46
Draw name, grade, combo, and histogram on game over screen
AEFeinstein Oct 3, 2024
2ce94da
Use a define for NUM_NOTE_TIMINGS
AEFeinstein Oct 5, 2024
0e5b70d
Style game end screen
AEFeinstein Oct 5, 2024
4f757a1
Draw a star on note hit
AEFeinstein Oct 5, 2024
0ac18cb
Add LED blink to tempo
AEFeinstein Oct 6, 2024
eb593b6
Adjust emulated LEDs to match hotdog
AEFeinstein Oct 6, 2024
a57530e
Recolor menu LEDs
AEFeinstein Oct 6, 2024
fd81b8e
Add LED effects on note hit
AEFeinstein Oct 6, 2024
d9fcbeb
Merge remote-tracking branch 'origin/main' into ssr
AEFeinstein Oct 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/swadgeHero/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 8 additions & 29 deletions components/hdw-led/hdw-led.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
// Variables
//==============================================================================

static rmt_channel_handle_t led_chan = NULL;
static rmt_encoder_handle_t led_encoder = NULL;
static uint8_t ledBrightness = 0;
static led_t localLeds[CONFIG_NUM_LEDS + 1] = {0};
static rmt_channel_handle_t led_chan = NULL;
static rmt_encoder_handle_t led_encoder = NULL;
static uint8_t ledBrightness = 0;
static led_t localLeds[CONFIG_NUM_LEDS] = {0};

//==============================================================================
// Functions
Expand Down Expand Up @@ -111,9 +111,9 @@ esp_err_t setLeds(led_t* leds, uint8_t numLeds)
};

// Make sure to not overflow
if (numLeds > CONFIG_NUM_LEDS + 1)
if (numLeds > CONFIG_NUM_LEDS)
{
numLeds = CONFIG_NUM_LEDS + 1;
numLeds = CONFIG_NUM_LEDS;
}

// Fill a local copy of LEDs with brightness applied
Expand All @@ -124,27 +124,6 @@ esp_err_t setLeds(led_t* leds, uint8_t numLeds)
localLeds[i].b = (leds[i].b >> ledBrightness);
}

// If all eight LEDs are being set, but not the 9th
if (CONFIG_NUM_LEDS == numLeds)
{
// Set the 9th LED to the average of the 6th, 7th, and 8th
int32_t avgR = 0;
int32_t avgG = 0;
int32_t avgB = 0;
for (int32_t lIdx = 5; lIdx < 8; lIdx++)
{
avgR += leds[lIdx].r;
avgG += leds[lIdx].g;
avgB += leds[lIdx].b;
}
localLeds[CONFIG_NUM_LEDS].r = (avgR / 3) >> ledBrightness;
localLeds[CONFIG_NUM_LEDS].g = (avgG / 3) >> ledBrightness;
localLeds[CONFIG_NUM_LEDS].b = (avgB / 3) >> ledBrightness;

// Set the 9th LED too
numLeds = CONFIG_NUM_LEDS + 1;
}

// Write RGB values to LEDs
return rmt_transmit(led_chan, led_encoder, (uint8_t*)localLeds, numLeds * sizeof(led_t), &tx_config);
}
Expand All @@ -160,9 +139,9 @@ uint8_t getLedState(led_t* leds, uint8_t numLeds)
{
if (NULL != leds && numLeds > 0)
{
if (numLeds > CONFIG_NUM_LEDS + 1)
if (numLeds > CONFIG_NUM_LEDS)
{
numLeds = CONFIG_NUM_LEDS + 1;
numLeds = CONFIG_NUM_LEDS;
}

memcpy(leds, localLeds, sizeof(led_t) * numLeds);
Expand Down
4 changes: 0 additions & 4 deletions components/hdw-led/include/hdw-led.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
* must be flushed before entering light sleep. If they are not, garbage data may be sent after light sleep begins,
* resulting in indeterminate LED behavior.
*
* Even though \c CONFIG_NUM_LEDS declares eight LEDs, there is a ninth LED which is controllable. By default, setting
* \c CONFIG_NUM_LEDS LEDs will automatically set the ninth to the average of the sixth, seventh, and eighth, which
* surround it on the PCB. To set the ninth LED, set `CONFIG_NUM_LEDS + 1` LEDs.
*
* \section led_example Example
*
* Set the LEDs to a rough rainbow:
Expand Down
8 changes: 4 additions & 4 deletions emulator/src/components/hdw-led/hdw-led.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// Variables
//==============================================================================

static led_t rdLeds[CONFIG_NUM_LEDS + 1] = {0};
static uint8_t ledBrightness = 0;
static led_t rdLeds[CONFIG_NUM_LEDS] = {0};
static uint8_t ledBrightness = 0;

//==============================================================================
// Functions
Expand Down Expand Up @@ -82,9 +82,9 @@ uint8_t getLedState(led_t* leds, uint8_t numLeds)
{
if (NULL != leds && numLeds > 0)
{
if (numLeds > CONFIG_NUM_LEDS + 1)
if (numLeds > CONFIG_NUM_LEDS)
{
numLeds = CONFIG_NUM_LEDS + 1;
numLeds = CONFIG_NUM_LEDS;
}

memcpy(leds, rdLeds, sizeof(led_t) * numLeds);
Expand Down
44 changes: 27 additions & 17 deletions emulator/src/extensions/leds/ext_leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#include "hdw-led.h"
#include "hdw-led_emu.h"
#include "macros.h"
#include "vector2d.h"

#include "rawdraw_sf.h"

//==============================================================================
// Defines
//==============================================================================

#define MIN_LED_WIDTH 64
#define MIN_LED_HEIGHT 64

//==============================================================================
// Static Function Prototypes
Expand All @@ -37,17 +38,17 @@ emuExtension_t ledEmuExtension = {
// Where LEDs are drawn, kinda
// first value is the LED column (top-to-bottom(?))
// second value is the row
static const int16_t ledOffsets[8][2] = {
{1, 2}, {0, 3}, {0, 1}, {1, 0}, // Left side LEDs
{2, 0}, {3, 1}, {3, 3}, {2, 2}, // Right side LEDs
static const vec_t ledOffsets[CONFIG_NUM_LEDS] = {
{.x = 4, .y = 1}, {.x = 5, .y = 0}, {.x = 3, .y = 0}, {.x = 1, .y = 0}, {.x = 2, .y = 1},
{.x = 0, .y = 2}, {.x = 2, .y = 2}, {.x = 4, .y = 2}, {.x = 6, .y = 2},
};

//==============================================================================
// Functions
//==============================================================================

/**
* @brief Initializes the
* @brief Initializes the LED panes
*
* @param args
* @return true if the extension is enabled
Expand All @@ -57,8 +58,8 @@ static bool ledsExtInit(emuArgs_t* args)
{
if (!args->hideLeds)
{
requestPane(&ledEmuExtension, PANE_LEFT, MIN_LED_WIDTH * 2, 1);
requestPane(&ledEmuExtension, PANE_RIGHT, MIN_LED_WIDTH * 2, 1);
requestPane(&ledEmuExtension, PANE_TOP, 1, MIN_LED_HEIGHT);
requestPane(&ledEmuExtension, PANE_BOTTOM, 1, MIN_LED_HEIGHT * 2);
return true;
}

Expand Down Expand Up @@ -91,17 +92,26 @@ static void drawLeds(uint32_t winW, uint32_t winH, const emuPane_t* panes, uint8
{
for (int i = 0; i < MIN(numLeds, ARRAY_SIZE(ledOffsets)); i++)
{
// Use left pane for offsets 0 and 1, right for offsets 2 and 3
const emuPane_t* pane = (ledOffsets[i][0] < 2) ? (panes + 0) : (panes + 1);

int16_t ledH = pane->paneH / (numLeds / 2);
int16_t ledW = pane->paneW / 2;

int16_t xOffset = pane->paneX + (ledOffsets[i][0] % 2) * (ledW / 2);
int16_t yOffset = ledOffsets[i][1] * ledH;

int16_t xOffset, yOffset, ledW, ledH;
// Use top pane for offset 0, bottom for offsets 1 & 2
if (0 == ledOffsets[i].y)
{
ledH = panes[0].paneH;
ledW = panes[0].paneW / 4;

xOffset = panes[0].paneX + (ledOffsets[i].x * ledW) / 2;
yOffset = panes[0].paneY + (ledOffsets[i].y * ledH);
}
else
{
ledH = panes[1].paneH / 2;
ledW = panes[1].paneW / 4;

xOffset = panes[1].paneX + (ledOffsets[i].x * ledW) / 2;
yOffset = panes[1].paneY + ((ledOffsets[i].y - 1) * ledH);
}
CNFGColor((leds[i].r << 24) | (leds[i].g << 16) | (leds[i].b << 8) | 0xFF);
CNFGTackRectangle(xOffset, yOffset, xOffset + ledW * 3 / 2, yOffset + ledH);
CNFGTackRectangle(xOffset, yOffset, xOffset + ledW, yOffset + ledH);
}
}
}
21 changes: 13 additions & 8 deletions main/menu/menuManiaRenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ menuManiaRenderer_t* initMenuManiaRenderer(font_t* titleFont, font_t* titleFontO
renderer->shadowColors = defaultShadowColors;
renderer->shadowColorsLen = ARRAY_SIZE(defaultShadowColors);

// LED color
uint32_t ledColor = paletteToRGB(renderer->bgColor);
renderer->baseLedColor.r = ((ledColor >> 16) & 0xFF) / 2;
renderer->baseLedColor.g = ((ledColor >> 8) & 0xFF) / 2;
renderer->baseLedColor.b = ((ledColor >> 0) & 0xFF) / 2;

// Save or allocate title font
if (NULL == titleFont)
{
Expand Down Expand Up @@ -379,14 +385,11 @@ void drawMenuMania(menu_t* menu, menuManiaRenderer_t* renderer, int64_t elapsedU
{
// Run timer for LED excitation
renderer->ledExciteTimer += elapsedUs;
while (renderer->ledExciteTimer >= 40000 * 8)
while (renderer->ledExciteTimer >= 40000 * CONFIG_NUM_LEDS)
{
renderer->ledExciteTimer -= 40000 * 8;
uint32_t ledColor = paletteToRGB(renderer->bgColor);
renderer->leds[renderer->currentLed].r = ((ledColor >> 16) & 0xFF) / 2;
renderer->leds[renderer->currentLed].g = ((ledColor >> 8) & 0xFF) / 2;
renderer->leds[renderer->currentLed].b = ((ledColor >> 0) & 0xFF) / 2;
renderer->currentLed = (renderer->currentLed + 1) % CONFIG_NUM_LEDS;
renderer->ledExciteTimer -= 40000 * CONFIG_NUM_LEDS;
renderer->leds[renderer->currentLed] = renderer->baseLedColor;
renderer->currentLed = (renderer->currentLed + 1) % CONFIG_NUM_LEDS;
}

// Run timer for LED decay
Expand Down Expand Up @@ -662,11 +665,12 @@ void setManiaLedsOn(menuManiaRenderer_t* renderer, bool ledsOn)
* @param rowTextColor The color of the row text
* @param shadowColors The colors cycled through as the selected shadow
* @param shadowColorsLen The number of selected shadow colors to cycle through
* @param baseLedColor The color of the LED illumination
*/
void recolorMenuManiaRenderer(menuManiaRenderer_t* renderer, paletteColor_t titleBgColor, paletteColor_t titleTextColor,
paletteColor_t textOutlineColor, paletteColor_t bgColor, paletteColor_t outerRingColor,
paletteColor_t innerRingColor, paletteColor_t rowColor, paletteColor_t rowTextColor,
const paletteColor_t* shadowColors, int32_t shadowColorsLen)
const paletteColor_t* shadowColors, int32_t shadowColorsLen, led_t baseLedColor)
{
renderer->titleBgColor = titleBgColor;
renderer->titleTextColor = titleTextColor;
Expand All @@ -681,4 +685,5 @@ void recolorMenuManiaRenderer(menuManiaRenderer_t* renderer, paletteColor_t titl
renderer->shadowColors = shadowColors;
renderer->shadowColorsLen = shadowColorsLen;
renderer->selectedShadowIdx = 0;
renderer->baseLedColor = baseLedColor;
}
3 changes: 2 additions & 1 deletion main/menu/menuManiaRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ typedef struct
paletteColor_t rowTextColor; ///< The color of the row text
const paletteColor_t* shadowColors; ///< The colors cycled through as the selected shadow
int32_t shadowColorsLen; ///< The number of selected shadow colors to cycle through
led_t baseLedColor; ///< The base color of the LED rotation
} menuManiaRenderer_t;

menuManiaRenderer_t* initMenuManiaRenderer(font_t* titleFont, font_t* titleFontOutline, font_t* menuFont);
Expand All @@ -103,6 +104,6 @@ void setManiaLedsOn(menuManiaRenderer_t* renderer, bool ledsOn);
void recolorMenuManiaRenderer(menuManiaRenderer_t* renderer, paletteColor_t titleBgColor, paletteColor_t titleTextColor,
paletteColor_t textOutlineColor, paletteColor_t bgColor, paletteColor_t outerRingColor,
paletteColor_t innerRingColor, paletteColor_t rowColor, paletteColor_t rowTextColor,
const paletteColor_t* shadowColors, int32_t shadowColorsLen);
const paletteColor_t* shadowColors, int32_t shadowColorsLen, led_t baseLedColor);

#endif
6 changes: 6 additions & 0 deletions main/modes/games/swadgeHero/mode_swadgeHero.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static void shEnterMode(void)
{
loadWsg(icons[i], &shv->icons[i], true);
}
loadWsg("star.wsg", &shv->star, true);

// Show initial menu
shChangeScreen(shv, SH_MENU);
Expand All @@ -103,6 +104,7 @@ static void shExitMode(void)
{
freeWsg(&shv->icons[i]);
}
freeWsg(&shv->star);

// Free mode memory
free(shv);
Expand Down Expand Up @@ -226,6 +228,10 @@ void shChangeScreen(shVars_t* sh, shScreen_t newScreen)
{
free(val);
}
while ((val = pop(&shv->starList)))
{
free(val);
}
break;
}
case SH_GAME_END:
Expand Down
9 changes: 9 additions & 0 deletions main/modes/games/swadgeHero/mode_swadgeHero.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ typedef struct
list_t fretLines;
int32_t lastFretLineUs;

// LED data
int32_t nextBlinkUs;
int8_t ledBaseVal;
int32_t ledDecayTimer;
int32_t usPerLedDecay;
led_t ledHitVal;

// Drawing data
list_t gameNotes;
buttonBit_t btnState;
Expand All @@ -130,6 +137,8 @@ typedef struct
const char* timingText;
int32_t textTimerUs;
wsg_t icons[6];
wsg_t star;
list_t starList;

// High score display
list_t hsStrs;
Expand Down
Loading
Loading