Skip to content

Commit

Permalink
Animation - Fixed maps not supporting grid sizes larger than 255x255.
Browse files Browse the repository at this point in the history
CueController - Revised `read()` logic to avoid premature executions.
  • Loading branch information
8bitbuddhist committed Jun 28, 2019
1 parent a3cc425 commit 892a0a3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/animation/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ namespace PixelMaestro {
*/
void Animation::rebuild_map() {
// Regenerate the color-to-pixel mapping.
for (uint8_t y = 0; y < dimensions_.y; y++) {
for (uint16_t y = 0; y < dimensions_.y; y++) {
delete [] map_[y];
}
delete [] map_;

dimensions_ = section_.get_dimensions();

map_ = new uint8_t*[dimensions_.y];
for (uint8_t y = 0; y < dimensions_.y; y++) {
for (uint16_t y = 0; y < dimensions_.y; y++) {
map_[y] = new uint8_t[dimensions_.x] {0};
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@ namespace PixelMaestro {
* @param y Pixel's y coordinate.
* @param color_index Index of the color to set.
*/
void Animation::set_map_color_index(uint8_t x, uint8_t y, uint8_t color_index) {
void Animation::set_map_color_index(uint16_t x, uint16_t y, uint8_t color_index) {
if (orientation_ == Orientation::HorizontalFlipped || orientation_ == Orientation::VerticalFlipped) {
map_[(dimensions_.y - 1) - y][(dimensions_.x - 1) - x] = color_index;
}
Expand Down Expand Up @@ -253,7 +253,7 @@ namespace PixelMaestro {
delete timer_;

// Destroy the map
for (uint8_t y = 0; y < dimensions_.y; y++) {
for (uint16_t y = 0; y < dimensions_.y; y++) {
delete [] map_[y];
}
delete [] map_;
Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace PixelMaestro {
void rebuild_map();
void set_cycle_index(uint8_t index);
void set_fade(bool fade);
void set_map_color_index(uint8_t x, uint8_t y, uint8_t color_index);
void set_map_color_index(uint16_t x, uint16_t y, uint8_t color_index);
void set_orientation(Orientation orientation);
void set_palette(Palette& palette);
void set_reverse(bool reverse);
Expand Down
55 changes: 28 additions & 27 deletions src/cue/cuecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,37 +206,38 @@ namespace PixelMaestro {
read_index_++;

/*
* Check the current read index.
*
* If we've reached the end of the payload, run the Cue then reset the read index.
* If we haven't reached the end, we want to check to see if this is an actual Cue being read.
* We do this by looking for the ID bytes, and if we see them, we clear the buffer and reset the read index so the Cue has room to load.
* We do the following checks:
* 1) Is the read index past the last ID byte? If so, move to the next check.
* 2) Is this a `ShowCueHandler::set_events()` Cue? If so, don't reset the buffer. Otherwise, we'd try to load each Event Cue as its own.
* 3) Do the last 3 bytes match the ID characters? If so, clear the buffer and reset the read index.
*
* Check for the ID bytes.
* If it is, we know this is a new Cue.
* Move the read index back to the start of the buffer so the Cue has plenty of room to buffer.
*/
uint32_t buffered_cue_size = IntByteConvert::byte_to_uint32(&buffer_[(uint8_t)Byte::SizeByte1]);
if (buffered_cue_size > 0 && read_index_ >= buffered_cue_size) {
run(buffer_);
read_index_ = 0;
return true;
if (read_index_ >= (uint8_t)Byte::IDByte3 &&
(buffer_[(uint8_t)Byte::PayloadByte] == (uint8_t)Handler::ShowCueHandler &&
buffer_[(uint8_t)ShowCueHandler::Byte::ActionByte] != (uint8_t)ShowCueHandler::Action::SetEvents) &&
(buffer_[read_index_ - (uint8_t)Byte::IDByte3] == id_[(uint8_t)Byte::IDByte1] &&
buffer_[read_index_ - (uint8_t)Byte::IDByte2] == id_[(uint8_t)Byte::IDByte2] &&
buffer_[read_index_] == id_[(uint8_t)Byte::IDByte3])) {

buffer_[(uint8_t)Byte::IDByte1] = id_[(uint8_t)Byte::IDByte1];
buffer_[(uint8_t)Byte::IDByte2] = id_[(uint8_t)Byte::IDByte2];
buffer_[(uint8_t)Byte::IDByte3] = id_[(uint8_t)Byte::IDByte3];
read_index_ = (uint8_t)Byte::IDByte3 + 1;
return false;
}
else {
if (read_index_ > (uint8_t)Byte::IDByte3 &&
(buffer_[(uint8_t)Byte::PayloadByte] == (uint8_t)Handler::ShowCueHandler &&
buffer_[(uint8_t)ShowCueHandler::Byte::ActionByte] != (uint8_t)ShowCueHandler::Action::SetEvents) &&
(buffer_[read_index_ - (uint8_t)Byte::IDByte3] == id_[(uint8_t)Byte::IDByte1] &&
buffer_[read_index_ - (uint8_t)Byte::IDByte2] == id_[(uint8_t)Byte::IDByte2] &&
buffer_[read_index_] == id_[(uint8_t)Byte::IDByte3])) {

buffer_[(uint8_t)Byte::IDByte1] = id_[(uint8_t)Byte::IDByte1];
buffer_[(uint8_t)Byte::IDByte2] = id_[(uint8_t)Byte::IDByte2];
buffer_[(uint8_t)Byte::IDByte3] = id_[(uint8_t)Byte::IDByte3];
read_index_ = (uint8_t)Byte::IDByte3;

/*
* Check the size of the buffered Cue.
* If it's valid, we know how far to read the Cue.
* After reaching the end, run the Cue.
*/
if (read_index_ >= (uint8_t)Byte::SizeByte4) {
uint32_t buffered_cue_size = IntByteConvert::byte_to_uint32(&buffer_[(uint8_t)Byte::SizeByte1]);
if (buffered_cue_size > 0 && read_index_ >= buffered_cue_size) {
run(buffer_);
read_index_ = 0;
return true;
}
}

return false;
}

Expand Down

0 comments on commit 892a0a3

Please sign in to comment.