BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
ce55115
Branches
Tags
master
Blinker
src
common
Game.h
base class for games
Stefan Schuermans
commited
ce55115
at 2019-06-10 10:11:49
Game.h
Blame
History
Raw
/* Blinker Copyright 2011-2019 Stefan Schuermans <stefan@blinkenarea.org> Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html a blinkenarea.org project */ #ifndef BLINKER_GAME_H #define BLINKER_GAME_H #include <string> #include <vector> #include <BlinkenLib/BlinkenFrame.h> #include "Color.h" #include "ColorFile.h" #include "File.h" #include "Format.h" #include "FormatFile.h" #include "Mgrs.h" #include "Module.h" #include "OutStreamFile.h" namespace Blinker { /// base class for games class Game: public Module { protected: /// raw color data matching image buffer typedef std::vector<unsigned char> ColorData; public: /** * @brief constructor * @param[in] name module name * @param[in] mgrs managers * @param[in] dirBase base directory */ Game(const std::string &name, Mgrs &mgrs, const Directory &dirBase); /// virtual destructor virtual ~Game(); private: /// copy constructor disabled Game(const Game &that); /// assignment operator disabled const Game & operator=(const Game &that); public: /// check for update of configuration virtual void updateConfig(); protected: /// re-initialize game (e.g. due to config change) virtual void reinitialize() = 0; /// redraw current game image, expected to call sendFrame() at end virtual void redraw() = 0; /// activate game: set up image buffer, call redraw() void activate(); /// deactivate game: tear down image buffer, deactivate output void deactivate(); /// check if integer is between minimum and maximum values static bool checkLimitInt(int i, int min, int max) { return i >= min && i <= max; } /// limit integer to minimum and maximum values static void limitInt(int &i, int min, int max) { if (i < min) { i = min; } if (i > max) { i = max; } } /// check if range of two integers is nonEmpty and limit the integers static bool checkIntRangeLimit(int &i1, int &i2, int min, int max) { if (i1 > i2) { return false; } limitInt(i1, min, max); limitInt(i2, min, max); return true; } /// set pixel in image buffer void pixel(int y, int x, ColorData const &cd); /// draw horizontal line to image buffer void lineHor(int y, int x1, int x2, ColorData const &cd); /// draw vertical line to image buffer void lineVert(int y1, int y2, int x, ColorData const &cd); /// draw non-filled rectangle to image buffer void rect(int y1, int y2, int x1, int x2, ColorData const &cd); /// draw filled rectangle to image buffer void rectFill(int y1, int y2, int x1, int x2, ColorData const &cd); /// convert color to raw color data static void color2data(Format const &format, Color const &color, ColorData &data); /// send current image buffer as frame to output stream void sendFrame(); private: /// (re-)create image buffer void createImgBuf(); /// tear down image buffer void destroyImgBuf(); protected: FormatFile m_fileFormat; ///< format file for output ColorFile m_fileBackgroundColor; ///< color file for background color OutStreamFile m_fileOutStream; ///< output stream name file int m_height; ///< height of image buffer int m_width; ///< width of image buffer int m_channels; ///< number of channels of image buffer ColorData m_imgBuf; ///< image buffer (empty if none) ColorData m_backgroundColor; ///< background color }; // class Canvas } // namespace Blinker #endif // #ifndef BLINKER_GAME_H