Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion include/core/configuration.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <Arduino.h>
#include <Preferences.h>
#include <cstdint>

Expand Down
3 changes: 3 additions & 0 deletions include/display/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#endif

#include "display/display-images.h"
#include "display/oled-serialization.h"

namespace SystemCore
{
Expand Down Expand Up @@ -37,6 +38,7 @@ namespace Display

char selectedOption(uint8_t index, uint8_t selectedOptionIndex) { return index == selectedOptionIndex ? '>' : ' '; };
int16_t calculateCenterText(const char *text);
void debugUpdateDisplay(const char *format, ...);

void drawHeader(const char *message);
void drawBootScreen();
Expand All @@ -46,6 +48,7 @@ namespace Display
void drawRecallGameHud();
void drawPhaseEvasionGameHud();
void drawChainReactionGameHud();
void drawReflexGameHud();
void drawDemoGameHud();
void drawCanvasSceneHud();
void drawUnconnectedControllerScreen();
Expand Down
13 changes: 13 additions & 0 deletions include/display/oled-serialization.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#ifdef VIRTUALIZATION

namespace Display
{
// Send OLED text update to serial port (only if content changed)
// Format: 0xBB 0x66 [2-byte length] [text data]
void sendOledUpdate(const char *text);
void serializeOledText(const char *text);
}

#endif
6 changes: 6 additions & 0 deletions include/engine/state-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "games/recall/state.h"
#include "games/phase-evasion/state.h"
#include "games/chain-reaction/state.h"
#include "games/reflex/state.h"
#include "games/demo/state.h"
#include "scenes/canvas/state.h"

Expand All @@ -23,6 +24,7 @@ namespace Engine
GameRecall,
GamePhaseEvasion,
GameChainReaction,
GameReflex,
GameDemo,
SceneCanvas,
NoControllerConnected,
Expand All @@ -41,6 +43,7 @@ namespace Engine
Recall,
PhaseEvasion,
ChainReaction,
Reflex,
Demo,
COUNT
};
Expand All @@ -64,6 +67,7 @@ namespace Engine
recallGameState{ctx},
phaseEvasionGameState{ctx},
chainReactionGameState{ctx},
reflexGameState{ctx},
systemState{SystemState::Initialize},
userMainMenuChoice{MainMenuSelection::Games},
userGameChoice{GameSelection::Recall},
Expand Down Expand Up @@ -95,6 +99,7 @@ namespace Engine
Games::Recall::GameState &getRecallGameState() { return recallGameState; }
Games::PhaseEvasion::GameState &getPhaseEvasionGameState() { return phaseEvasionGameState; }
Games::ChainReaction::GameState &getChainReactionGameState() { return chainReactionGameState; }
Games::Reflex::GameState &getReflexGameState() { return reflexGameState; }
Games::Demo::GameState &getDemoGameState() { return demoGameState; }

Scenes::Canvas::SceneState &getCanvasSceneState() { return canvasSceneState; }
Expand All @@ -110,6 +115,7 @@ namespace Engine
Games::Recall::GameState recallGameState;
Games::PhaseEvasion::GameState phaseEvasionGameState;
Games::ChainReaction::GameState chainReactionGameState;
Games::Reflex::GameState reflexGameState;
Games::Demo::GameState demoGameState;

Scenes::Canvas::SceneState canvasSceneState;
Expand Down
27 changes: 27 additions & 0 deletions include/games/reflex/driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "engine/layer.h"
#include "engine/timer.h"
#include "core/context-manager.h"
#include "games/reflex/signal.h"

namespace Games::Reflex
{
class Driver : public Engine::Layer, private Engine::Timer
{
public:
Driver(SystemCore::ContextManager *ctx);
~Driver() { state.reset(); }
static constexpr uint16_t signalWidth = 7;
static constexpr float signalSpeed = 1.0f;
void nextEvent() override;
void renderSignal();
void reset();

private:
SystemCore::ContextManager *contextManager;
GameState &state;

Signal signal;
};
}
19 changes: 19 additions & 0 deletions include/games/reflex/signal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "core/context-manager.h"
#include "player/player.h"

namespace Games::Reflex
{
class Signal : public ::Player::BasePlayer
{
public:
Signal(SystemCore::ContextManager *ctx, uint16_t width, float _speed);
~Signal() = default;

void advance() { setPosition(positionPrecise += speed); }

private:
float speed;
};
}
33 changes: 33 additions & 0 deletions include/games/reflex/state.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <cstdint>

namespace SystemCore
{
class ContextManager;
}

namespace Games::Reflex
{
enum class Actions
{
Startup,
Ready,
ActiveGame,
GameOver
};

class GameState
{
public:
GameState(SystemCore::ContextManager *ctx) : contextManager{ctx} {}

Actions current = Actions::Startup;
static constexpr const char *memoryKeyName = "high_reflex";

void reset() {}

private:
SystemCore::ContextManager *contextManager;
};
}
2 changes: 0 additions & 2 deletions include/logger.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <Arduino.h>

/*
Interesting compiler optimization below, when building with the DEBUG flag
on it prints to the serial monitor as normal, but when building in RELEASE
Expand Down
8 changes: 8 additions & 0 deletions src/core/context-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "games/recall/driver.h"
#include "games/phase-evasion/driver.h"
#include "games/chain-reaction/driver.h"
#include "games/reflex/driver.h"
#include "games/demo/driver.h"
#include "scenes/canvas/driver.h"
#include "logger.h"
Expand Down Expand Up @@ -116,6 +117,9 @@ namespace SystemCore
case Engine::GameSelection::ChainReaction:
stateManager.setNext(Engine::SystemState::GameChainReaction);
break;
case Engine::GameSelection::Reflex:
stateManager.setNext(Engine::SystemState::GameReflex);
break;
case Engine::GameSelection::Demo:
stateManager.setNext(Engine::SystemState::GameDemo);
break;
Expand Down Expand Up @@ -185,6 +189,10 @@ namespace SystemCore
application = new Games::ChainReaction::Driver{this};
logf("Transitioning to Chain Reaction (Game)");
break;
case Engine::SystemState::GameReflex:
application = new Games::Reflex::Driver{this};
logf("Transitioning to Reflex (Game)");
break;
case Engine::SystemState::GameDemo:
application = new Games::Demo::Driver{this};
logf("Transitioning to Demo (Game)");
Expand Down
57 changes: 57 additions & 0 deletions src/display/display.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <Wire.h>
#include <cstdarg>

#include "display/display.h"
#include "core/context-manager.h"
Expand Down Expand Up @@ -52,6 +53,9 @@ namespace Display
case Engine::SystemState::GameChainReaction:
drawChainReactionGameHud();
break;
case Engine::SystemState::GameReflex:
drawReflexGameHud();
break;
case Engine::SystemState::SceneCanvas:
drawCanvasSceneHud();
break;
Expand Down Expand Up @@ -85,6 +89,18 @@ namespace Display
display.print(message);
}

void OledDisplay::debugUpdateDisplay(const char *format, ...)
{
#ifdef VIRTUALIZATION
char oledBuffer[256] = "";
va_list args;
va_start(args, format);
vsnprintf(oledBuffer, sizeof(oledBuffer), format, args);
va_end(args);
Display::sendOledUpdate(oledBuffer);
#endif
}

void OledDisplay::drawBootScreen()
{
display.clearDisplay();
Expand Down Expand Up @@ -115,6 +131,9 @@ namespace Display
display.print(selectedOption(1, selectedOptionIndex));
display.print(" Scenes");

debugUpdateDisplay(" Main Menu\n%c Games\n%c Scenes",
selectedOption(0, selectedOptionIndex), selectedOption(1, selectedOptionIndex));

display.display();
}

Expand All @@ -140,6 +159,15 @@ namespace Display
display.print(nameBuffer);
}

char oledBuffer[256] = "";
int offset = snprintf(oledBuffer, sizeof(oledBuffer), "Games Menu (%d/%d)", currentPage + 1, (numGames + itemsPerPage - 1) / itemsPerPage);
for (int i = startIndex; i < endIndex; ++i)
{
offset += snprintf(oledBuffer + offset, sizeof(oledBuffer) - offset, "\n%c %s",
selectedOption(i, selectedOptionIndex), contextManager->stateManager.printGameName(i));
}
debugUpdateDisplay("%s", oledBuffer);

display.display();
}

Expand All @@ -155,6 +183,9 @@ namespace Display
sprintf(nameBuffer, "%c %s", selectedOption(0, selectedOptionIndex), contextManager->stateManager.printSceneName(0));
display.print(nameBuffer);

debugUpdateDisplay(" Scenes Menu\n%c %s",
selectedOption(0, selectedOptionIndex), contextManager->stateManager.printSceneName(0));

display.display();
}

Expand All @@ -169,6 +200,9 @@ namespace Display
display.setCursor(0, 24);
display.print("High Score: -");

debugUpdateDisplay(" Demo\nCurrent Score: %u\nHigh Score: -",
contextManager->stateManager.getDemoGameState().currentScore);

display.display();
}

Expand All @@ -186,6 +220,8 @@ namespace Display
display.setCursor(0, 24);
display.printf("High Score: %u", highScore + 1);

debugUpdateDisplay(" Recall\nRound: %u\nHigh Score: %u", round + 1, highScore + 1);

display.display();
}

Expand All @@ -210,6 +246,9 @@ namespace Display
display.setCursor(DISPLAY_WIDTH / 2 + 4, 24);
display.printf(" High: %u", highScore);

debugUpdateDisplay(" Phase Evasion\nFlares: %u Total: %u\nGems: %u High: %u",
flaresEvaded, totalScore, gemsCaptured, highScore);

display.display();
}

Expand All @@ -226,6 +265,20 @@ namespace Display
display.setCursor(0, 24);
display.printf("Total: %u", reactions);

debugUpdateDisplay(" Chain Reaction\nReactions: %u\nTotal: %u", reactions, reactions);

display.display();
}

void OledDisplay::drawReflexGameHud()
{
display.clearDisplay();
drawHeader("Reflex");

const auto reflexState = contextManager->stateManager.getReflexGameState();

debugUpdateDisplay(" Reflex");

display.display();
}

Expand All @@ -240,6 +293,8 @@ namespace Display
display.setCursor(0, 24);
display.print(colorBuffer);

debugUpdateDisplay(" Canvas\nRGB: (%u, %u, %u)", color.r, color.g, color.b);

display.display();
}

Expand All @@ -259,6 +314,8 @@ namespace Display
display.setCursor(startingX, 16);
display.print("not connected");

debugUpdateDisplay(" LumenLab\n%s controller\nnot connected", SystemCore::Configuration::psControllerType().c_str());

display.display();
}
}
Loading
Loading