Use shared memory space for game data (#14727)

This commit is contained in:
Marcio Teixeira
2019-07-28 00:44:16 -06:00
committed by Scott Lahteine
parent 17abb94532
commit fec52e61ea
11 changed files with 458 additions and 287 deletions

View File

@@ -34,45 +34,37 @@
#define _BUZZ(D,F) BUZZ(D,F)
#endif
// Simple 8:8 fixed-point
typedef int16_t fixed_t;
#define FTOP(F) fixed_t((F)*256.0f)
#define PTOF(P) (float(P)*(1.0f/256.0f))
#define BTOF(X) (fixed_t(X)<<8)
#define FTOB(X) int8_t(fixed_t(X)>>8)
#define SCREEN_M ((LCD_PIXEL_WIDTH) / 2)
#if HAS_GAME_MENU
void menu_game();
#endif
class MarlinGame {
protected:
static int score;
static uint8_t game_state;
static millis_t next_frame;
static bool game_frame();
static void draw_game_over();
static void exit_game();
public:
static void init_game(const uint8_t init_state, const screenFunc_t screen);
};
#if ENABLED(MARLIN_BRICKOUT)
class BrickoutGame : MarlinGame { public: static void enter_game(); static void game_screen(); };
extern BrickoutGame brickout;
#include "brickout.h"
#endif
#if ENABLED(MARLIN_INVADERS)
class InvadersGame : MarlinGame { public: static void enter_game(); static void game_screen(); };
extern InvadersGame invaders;
#endif
#if ENABLED(MARLIN_SNAKE)
class SnakeGame : MarlinGame { public: static void enter_game(); static void game_screen(); };
extern SnakeGame snake;
#include "invaders.h"
#endif
#if ENABLED(MARLIN_MAZE)
class MazeGame : MarlinGame { public: static void enter_game(); static void game_screen(); };
extern MazeGame maze;
#include "maze.h"
#endif
#if ENABLED(MARLIN_SNAKE)
#include "snake.h"
#endif
// Pool game data to save SRAM
union MarlinGameData {
#if ENABLED(MARLIN_BRICKOUT)
brickout_data_t brickout;
#endif
#if ENABLED(MARLIN_INVADERS)
invaders_data_t invaders;
#endif
#if ENABLED(MARLIN_SNAKE)
snake_data_t snake;
#endif
#if ENABLED(MARLIN_MAZE)
maze_data_t maze;
#endif
};
extern MarlinGameData marlin_game_data;