From 40a028e5a10e0b83a44fc2365fd3c95ab95775e9 Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Thu, 20 Oct 2016 13:28:29 -0400 Subject: [PATCH] Remove Sprites class constructor parameter The Sprites class has been given direct access to the screen buffer so it doesn't need a pointer to been given to it. Also updated README.md and keywords.txt, and made minor indent changes in the .h files. --- README.md | 8 +++++++- keywords.txt | 12 ++++++++++++ src/Arduboy2.h | 10 ++++++---- src/ArduboyAudio.h | 4 ++-- src/ArduboyCore.h | 7 +++---- src/Sprites.cpp | 33 ++++++++++++++------------------- src/Sprites.h | 9 --------- 7 files changed, 44 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index d88ec70..c43460a 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Main differences between Arduboy2 and Arduboy V1.1 are: As of version 2.1.0 functionality from the [Team A.R.G.](http://www.team-arg.org/) *Arglib* library has been added: -- The sprite drawing functions, collision detection functions, and button handling functions that Team A.R.G. incorporated from the [ArduboyExtra](https://github.com/yyyc514/ArduboyExtra) project. The *poll()* function was renamed *pollButtons()* for clarity. +- The sprite drawing functions, collision detection functions, and button handling functions that Team A.R.G. incorporated from the [ArduboyExtra](https://github.com/yyyc514/ArduboyExtra) project. The *poll()* function was renamed *pollButtons()* for clarity. The *Sprites* class doesn't require a parameter for the constructor, whereas in *Arglib* a pointer to an Arduboy class object is required. - The *drawCompressed()* function, which allows compressed bitmaps to be drawn. Saving bitmaps in compressed form may reduce overall sketch size. ## Start up features @@ -98,6 +98,12 @@ void setup() { The rest of the Arduboy2 functions will now be available for use. +If you wish to use the Sprites class functions you must create a Sprites object: + +```cpp +Sprites sprites; +``` + Sample sketches have been included with the library as examples of how to use it. To load an example, for examination and uploading to the Arduboy, using the Arduino IDE menus select: `File > Examples > Arduboy2` diff --git a/keywords.txt b/keywords.txt index ecc0701..da31116 100644 --- a/keywords.txt +++ b/keywords.txt @@ -8,6 +8,7 @@ Arduboy2 KEYWORD1 Arduboy2Base KEYWORD1 +Sprites KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) @@ -20,6 +21,7 @@ boot KEYWORD2 bootLogo KEYWORD2 buttonsState KEYWORD2 clear KEYWORD2 +collide KEYWORD2 cpuLoad KEYWORD2 digitalWriteRGB KEYWORD2 display KEYWORD2 @@ -51,12 +53,15 @@ height KEYWORD2 idle KEYWORD2 initRandomSeed KEYWORD2 invert KEYWORD2 +justPressed KEYWORD2 +justReleased KEYWORD2 nextFrame KEYWORD2 notPressed KEYWORD2 off KEYWORD2 on KEYWORD2 paint8Pixels KEYWORD2 paintScreen KEYWORD2 +pollButtons KEYWORD2 pressed KEYWORD2 saveOnOff KEYWORD2 setCursor KEYWORD2 @@ -69,6 +74,13 @@ setTextWrap KEYWORD2 systemButtons KEYWORD2 width KEYWORD2 +# Sprites class +drawErase KEYWORD2 +drawExternalMask KEYWORD2 +drawOverwrite KEYWORD2 +drawPlusMask KEYWORD2 +drawSelfMasked KEYWORD2 + ####################################### # Constants (LITERAL1) ####################################### diff --git a/src/Arduboy2.h b/src/Arduboy2.h index 8851456..87f2211 100644 --- a/src/Arduboy2.h +++ b/src/Arduboy2.h @@ -59,7 +59,9 @@ struct Point class Arduboy2Base : public ArduboyCore { -public: + friend class Sprites; + + public: Arduboy2Base(); ArduboyAudio audio; @@ -285,7 +287,7 @@ public: */ bool collide(Rect rect1, Rect rect2); -protected: + protected: // helper function for sound enable/disable system control void sysCtrlSound(uint8_t buttons, uint8_t led, uint8_t eeVal); @@ -312,7 +314,7 @@ protected: class Arduboy2 : public Print, public Arduboy2Base { -public: + public: Arduboy2(); /// Writes a single ASCII character to the screen. @@ -350,7 +352,7 @@ public: /// Clears the display and sets the cursor to 0, 0 void clear(); -protected: + protected: int16_t cursor_x; int16_t cursor_y; uint8_t textColor; diff --git a/src/ArduboyAudio.h b/src/ArduboyAudio.h index 729b6d6..0b8ae9b 100644 --- a/src/ArduboyAudio.h +++ b/src/ArduboyAudio.h @@ -6,14 +6,14 @@ class ArduboyAudio { -public: + public: void static begin(); void static on(); void static off(); void static saveOnOff(); bool static enabled(); -protected: + protected: bool static audio_enabled; }; diff --git a/src/ArduboyCore.h b/src/ArduboyCore.h index 5baca75..0d68373 100644 --- a/src/ArduboyCore.h +++ b/src/ArduboyCore.h @@ -136,7 +136,7 @@ class ArduboyCore { -public: + public: ArduboyCore(); /// allows the CPU to idle between frames @@ -278,8 +278,7 @@ public: */ void static boot(); -protected: - + protected: /// Safe mode /** * Safe Mode is engaged by holding down both the LEFT button and UP button @@ -300,7 +299,7 @@ protected: void static inline bootPowerSaving() __attribute__((always_inline)); -private: + private: volatile static uint8_t *csport, *dcport; uint8_t static cspinmask, dcpinmask; diff --git a/src/Sprites.cpp b/src/Sprites.cpp index 0216294..e16538f 100644 --- a/src/Sprites.cpp +++ b/src/Sprites.cpp @@ -1,10 +1,5 @@ #include "Sprites.h" -Sprites::Sprites(uint8_t* buffer) -{ - sBuffer = buffer; -} - void Sprites::drawExternalMask(int16_t x, int16_t y, const uint8_t *bitmap, const uint8_t *mask, uint8_t frame, uint8_t mask_frame) { @@ -145,16 +140,16 @@ void Sprites::drawBitmap(int16_t x, int16_t y, bitmap_data = pgm_read_byte(bofs) * mul_amt; if (sRow >= 0) { - data = sBuffer[ofs]; + data = Arduboy2Base::sBuffer[ofs]; data &= (uint8_t)(mask_data); data |= (uint8_t)(bitmap_data); - sBuffer[ofs] = data; + Arduboy2Base::sBuffer[ofs] = data; } if (yOffset != 0 && sRow < 7) { - data = sBuffer[ofs + WIDTH]; + data = Arduboy2Base::sBuffer[ofs + WIDTH]; data &= (*((unsigned char *) (&mask_data) + 1)); data |= (*((unsigned char *) (&bitmap_data) + 1)); - sBuffer[ofs + WIDTH] = data; + Arduboy2Base::sBuffer[ofs + WIDTH] = data; } ofs++; bofs++; @@ -170,10 +165,10 @@ void Sprites::drawBitmap(int16_t x, int16_t y, for (uint8_t iCol = 0; iCol < rendered_width; iCol++) { bitmap_data = pgm_read_byte(bofs) * mul_amt; if (sRow >= 0) { - sBuffer[ofs] |= (uint8_t)(bitmap_data); + Arduboy2Base::sBuffer[ofs] |= (uint8_t)(bitmap_data); } if (yOffset != 0 && sRow < 7) { - sBuffer[ofs + WIDTH] |= (*((unsigned char *) (&bitmap_data) + 1)); + Arduboy2Base::sBuffer[ofs + WIDTH] |= (*((unsigned char *) (&bitmap_data) + 1)); } ofs++; bofs++; @@ -189,10 +184,10 @@ void Sprites::drawBitmap(int16_t x, int16_t y, for (uint8_t iCol = 0; iCol < rendered_width; iCol++) { bitmap_data = pgm_read_byte(bofs) * mul_amt; if (sRow >= 0) { - sBuffer[ofs] &= ~(uint8_t)(bitmap_data); + Arduboy2Base::sBuffer[ofs] &= ~(uint8_t)(bitmap_data); } if (yOffset != 0 && sRow < 7) { - sBuffer[ofs + WIDTH] &= ~(*((unsigned char *) (&bitmap_data) + 1)); + Arduboy2Base::sBuffer[ofs + WIDTH] &= ~(*((unsigned char *) (&bitmap_data) + 1)); } ofs++; bofs++; @@ -218,16 +213,16 @@ void Sprites::drawBitmap(int16_t x, int16_t y, bitmap_data = pgm_read_byte(bofs) * mul_amt; if (sRow >= 0) { - data = sBuffer[ofs]; + data = Arduboy2Base::sBuffer[ofs]; data &= (uint8_t)(mask_data); data |= (uint8_t)(bitmap_data); - sBuffer[ofs] = data; + Arduboy2Base::sBuffer[ofs] = data; } if (yOffset != 0 && sRow < 7) { - data = sBuffer[ofs + WIDTH]; + data = Arduboy2Base::sBuffer[ofs + WIDTH]; data &= (*((unsigned char *) (&mask_data) + 1)); data |= (*((unsigned char *) (&bitmap_data) + 1)); - sBuffer[ofs + WIDTH] = data; + Arduboy2Base::sBuffer[ofs + WIDTH] = data; } ofs++; mask_ofs++; @@ -340,8 +335,8 @@ void Sprites::drawBitmap(int16_t x, int16_t y, [x_count] "r" (rendered_width), [y_count] "r" (loop_h), [sprite_ofs] "z" (bofs), - [buffer_ofs] "x" (sBuffer+ofs), - [buffer_page2_ofs] "r" (sBuffer+ofs+WIDTH), // Y pointer + [buffer_ofs] "x" (Arduboy2Base::sBuffer+ofs), + [buffer_page2_ofs] "r" (Arduboy2Base::sBuffer+ofs+WIDTH), // Y pointer [buffer_ofs_jump] "r" (WIDTH-rendered_width), [sprite_ofs_jump] "r" ((w-rendered_width)*2), [yOffset] "r" (yOffset), diff --git a/src/Sprites.h b/src/Sprites.h index 9a24011..d9400fd 100644 --- a/src/Sprites.h +++ b/src/Sprites.h @@ -14,12 +14,6 @@ class Sprites { public: - /// The class constructor. - /// `buffer` is a pointer to the screen buffer where the draw functions - /// will write to. - /// - Sprites(uint8_t* buffer); - /// drawExternalMask() uses a separate mask to mask image (MASKED) /// /// image mask before after @@ -130,9 +124,6 @@ class Sprites void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, const uint8_t *mask, int8_t w, int8_t h, uint8_t draw_mode); - - private: - unsigned char *sBuffer; }; #endif