| 127 | } |
| 128 | |
| 129 | bool sugoi::scheduler_t::sync_query(sugoi_query_t* query) |
| 130 | { |
| 131 | SKR_ASSERT(is_main_thread(query->storage)); |
| 132 | |
| 133 | SkrZoneScopedN("SyncQuery"); |
| 134 | |
| 135 | llvm_vecsmall::SmallVector<sugoi_group_t*, 64> groups; |
| 136 | auto add_group = [&](sugoi_group_t* group) { |
| 137 | groups.push_back(group); |
| 138 | }; |
| 139 | query->storage->query_groups(query->filter, query->meta, SUGOI_LAMBDA(add_group)); |
| 140 | skr::FlatHashSet<std::pair<sugoi::archetype_t*, sugoi_type_index_t>> syncedEntry; |
| 141 | |
| 142 | auto sync_entry_once = [&](sugoi::archetype_t* type, sugoi_type_index_t i, bool readonly, bool atomic) -> bool |
| 143 | { |
| 144 | if(i == kInvalidTypeIndex) |
| 145 | return false; |
| 146 | auto entry = std::make_pair(type, i); |
| 147 | if (syncedEntry.find(entry) != syncedEntry.end()) |
| 148 | return false; |
| 149 | auto result = sync_entry(type, i, readonly); |
| 150 | syncedEntry.insert(entry); |
| 151 | return result; |
| 152 | }; |
| 153 | |
| 154 | auto sync_type = [&](sugoi_type_index_t type, bool readonly, bool atomic) { |
| 155 | bool result = false; |
| 156 | for (auto& pair : query->storage->groups) |
| 157 | { |
| 158 | auto group = pair.second; |
| 159 | auto idx = group->archetype->index(type); |
| 160 | result = sync_entry_once(group->archetype, idx, readonly, atomic) || result; |
| 161 | } |
| 162 | return result; |
| 163 | }; |
| 164 | |
| 165 | bool result = false; |
| 166 | { |
| 167 | auto params = query->parameters; |
| 168 | forloop (i, 0, params.length) |
| 169 | { |
| 170 | if (type_index_t(params.types[i]).is_tag()) |
| 171 | continue; |
| 172 | if (params.accesses[i].randomAccess != DOS_SEQ) |
| 173 | { |
| 174 | result = sync_type(params.types[i], params.accesses[i].readonly, params.accesses[i].atomic) || result; |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | int groupIndex = 0;(void)groupIndex; |
| 179 | for (auto group : groups) |
| 180 | { |
| 181 | auto localType = group->archetype->index(params.types[i]); |
| 182 | if (localType == kInvalidTypeIndex) |
| 183 | { |
| 184 | auto g = group->get_owner(params.types[i]); |
| 185 | if (g) |
| 186 | { |
no test coverage detected