-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#144]: Add StateList struct to replace using std::deque
- Loading branch information
1 parent
2ec6d15
commit fef43a3
Showing
13 changed files
with
144 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#pragma once | ||
|
||
#include "common.hpp" | ||
|
||
namespace looper { | ||
template < typename StateT > struct StateList | ||
{ | ||
const uint32_t | ||
GetNumFrames() const | ||
{ | ||
return numFrames_; | ||
} | ||
|
||
const StateT& | ||
PeekLastState() const | ||
{ | ||
return frames_.at(lastIdx_); | ||
} | ||
|
||
const StateT& | ||
GetLastState() | ||
{ | ||
lastIdx_ = (lastIdx_ == -1) ? lastFrame_ : lastIdx_; | ||
const auto& frame = frames_.at(lastIdx_-1); | ||
|
||
numFrames_--; | ||
return frame; | ||
} | ||
|
||
void | ||
PushState(const StateT& newState) | ||
{ | ||
frames_.at(lastIdx_++) = newState; | ||
lastIdx_ = (lastIdx_ == lastFrame_) ? 0 : lastIdx_; | ||
numFrames_++; | ||
} | ||
|
||
private: | ||
std::array< StateT, NUM_FRAMES_TO_SAVE > frames_ = {}; | ||
uint32_t numFrames_ = {}; | ||
uint32_t firstIdx_ = {}; | ||
uint32_t lastIdx_ = {}; | ||
const uint32_t lastFrame_ = NUM_FRAMES_TO_SAVE - 1; | ||
}; | ||
|
||
} // namespace looper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.