// FCS Glass - src/core/state.cpp // // Implements: C2, C3. See src/core/state.h. #include "core/state.h" namespace fcs { namespace core { // REQ C2 / C3 - one roll per frame. Swap rather than copy: it is O(1) instead // of O(widgets), and it makes "previous" exactly the map that was current a // moment ago, with no chance of the two drifting apart. void StateStore::BeginFrame() { prev_.swap(cur_); cur_.clear(); ++frame_; } // REQ C2 - created on first sight, default-initialised. operator[] does the // insert; the map is the single owner of the state, so a widget cannot hold a // copy that outlives its key. WidgetState& StateStore::Get(Id id) { return cur_[id]; } // REQ C3 - the previous frame's copy. An id that did not exist last frame reads // as a default-constructed WidgetState, which is the honest answer: it was not // hovered, because it was not there to be hovered. const WidgetState& StateStore::prev(Id id) const { const auto it = prev_.find(id); return (it == prev_.end()) ? unknown_ : it->second; } // REQ T6 - surface rebuild. Deliberately wipes BOTH maps: keeping `prev_` would // leave widgets reporting hover against a surface that no longer exists. void StateStore::Clear() { cur_.clear(); prev_.clear(); unknown_ = WidgetState{}; } } // namespace core } // namespace fcs