MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / sync_query

Method sync_query

modules/engine/runtime/src/ecs/scheduler.cpp:129–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127}
128
129bool 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 {

Callers 1

sugoiQ_syncFunction · 0.80

Calls 9

type_index_tClass · 0.85
query_groupsMethod · 0.80
is_tagMethod · 0.80
get_ownerMethod · 0.80
push_backMethod · 0.45
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected