-
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.
Merge pull request #147 from JacobDomagala/144-consider-using-stdvect…
…or-or-stdarray-instead-of-stddeque-for-time-rewinding [#144]: Add StateList struct to replace using std::deque
- Loading branch information
Showing
14 changed files
with
149 additions
and
139 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
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,49 @@ | ||
#pragma once | ||
|
||
#include "common.hpp" | ||
|
||
namespace looper { | ||
|
||
template < typename StateT > struct StateList | ||
{ | ||
int32_t | ||
GetNumFrames() const | ||
{ | ||
return numFrames_; | ||
} | ||
|
||
const StateT& | ||
PeekLastState() const | ||
{ | ||
auto lastIdx = (lastIdx_ == 0) ? lastFrame_ : lastIdx_; | ||
return frames_.at(static_cast< uint32_t >(lastIdx - 1)); | ||
} | ||
|
||
const StateT& | ||
GetLastState() | ||
{ | ||
lastIdx_ = (lastIdx_ == 0) ? lastFrame_ : lastIdx_; | ||
const auto& frame = frames_.at(static_cast< uint32_t >(lastIdx_ - 1)); | ||
|
||
lastIdx_--; | ||
numFrames_--; | ||
return frame; | ||
} | ||
|
||
void | ||
PushState(const StateT& newState) | ||
{ | ||
frames_.at(static_cast< uint32_t >(lastIdx_++)) = newState; | ||
lastIdx_ = (lastIdx_ == lastFrame_) ? 0 : lastIdx_; | ||
numFrames_++; | ||
} | ||
|
||
private: | ||
std::array< StateT, NUM_FRAMES_TO_SAVE > frames_ = {}; | ||
int32_t numFrames_ = {}; | ||
int32_t firstIdx_ = {}; | ||
int32_t lastIdx_ = {}; | ||
const int32_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
Oops, something went wrong.