9std::mutex WidgetState::m_mutex;
11WidgetState Widget::emptyState(0, 0, 0, 0, 0, 0);
19 snprintf(buf,
sizeof(buf),
"%lx",
WidgetPos(x, y, w, h).encoded());
20 m_data.set(
"p",
new rbjson::String(buf));
23 m_data.set(
"tab", tab);
31 std::lock_guard<std::mutex> lock(m_mutex);
33 const auto* old = m_data.get(key);
34 if (old !=
nullptr && old->equals(*value)) {
39 m_data.set(key, value);
40 markChangedLocked(key);
48 std::lock_guard<std::mutex> lock(m_mutex);
50 auto* obj = m_data.getObject(objectName);
52 obj =
new rbjson::Object;
53 m_data.set(objectName, obj);
55 const auto* old = obj->get(propertyName);
56 if (old !=
nullptr && old->equals(*value)) {
62 obj->set(propertyName, value);
63 markChangedLocked(objectName);
67bool WidgetState::popChanges(rbjson::Object& state) {
68 std::lock_guard<std::mutex> lock(m_mutex);
69 if (m_bloom_tick == 0)
72 const auto& m = m_data.members();
73 for (
auto itr = m.begin(); itr != m.end(); ++itr) {
74 if (wasChangedInTickLocked(itr->name, itr->name_len)) {
75 state.set(std::string(itr->name, itr->name_len), itr->value->copy());
82static inline uint32_t
murmur3_32(
const uint8_t* key,
size_t len, uint32_t seed) {
85 const uint32_t* key_x4 = (
const uint32_t*)key;
88 uint32_t k = *key_x4++;
90 k = (k << 15) | (k >> 17);
93 h = (h << 13) | (h >> 19);
94 h = (h * 5) + 0xe6546b64;
96 key = (
const uint8_t*)key_x4;
107 k = (k << 15) | (k >> 17);
126 std::lock_guard<std::mutex> lock(m_mutex);
127 markChangedLocked(key);
130void WidgetState::markChangedLocked(
const std::string& key) {
132 const auto bit =
murmur3_32((uint8_t*)key.c_str(), key.size(), i) % 16;
133 m_bloom_global |= (1 << bit);
134 m_bloom_tick |= (1 << bit);
137 UI.notifyStateChange();
140void WidgetState::markGlobalChangedLocked(
const std::string& key) {
142 const auto bit =
murmur3_32((uint8_t*)key.c_str(), key.size(), i) % 16;
143 m_bloom_global |= (1 << bit);
147bool WidgetState::wasChangedInTickLocked(
const char *key,
size_t key_len)
const {
149 const auto bit =
murmur3_32((uint8_t*)key, key_len, i) % 16;
150 if ((m_bloom_tick & (1 << bit)) == 0)
156bool WidgetState::remarkAllChanges() {
157 std::lock_guard<std::mutex> lock(m_mutex);
158 if (m_bloom_global == 0)
160 m_bloom_tick = m_bloom_global;
static uint32_t murmur3_32(const uint8_t *key, size_t len, uint32_t seed)
static constexpr int hash_count