TTailHairpin::TTailHairpin(const Tuple &tuple, const Tuple &size) { int len = size[1]; Tuple t = tuple; std::sort(t.begin(), t.end(), std::less<int>{}); Frag frag; for (int i = t[0]; i <= t[1]; i++) { frag.push_back(i); } d_frags.push_back(std::move(frag)); for (int i = t[2]; i < len; i++) { frag.push_back(i); } d_frags.push_back(std::move(frag)); d_max_len = std::max(t[1] - t[0] - 1, len - t[2] - 1); d_indices = std::make_unique<Mati>(d_max_len, 3); for (int i = 0; i < d_max_len; i++) for (int j = 0; j < 3; j++) (*d_indices)(i, j) = -1; set_indices(0, d_frags[0].front() + 1, d_frags[0].back() - 1); set_indices(1, d_frags[1].front() + 1, len - 1); }
void RenderThread::getCube(Key<Vertices> &v, Key<Painter> &p) { static const std::vector<glm::vec3> positions = { glm::vec3(-1.0f, 1.0f, 1.0f), glm::vec3(-1.0f, -1.0f, 1.0f), glm::vec3(1.0f, -1.0f, 1.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(-1.0f, 1.0f, -1.0f), glm::vec3(-1.0f, -1.0f, -1.0f), glm::vec3(1.0f, -1.0f, -1.0f), glm::vec3(1.0f, 1.0f, -1.0f) }; static const std::vector<unsigned int> indices = { 0, 1, 2, 3, 0, 3, 7, 4, 4, 7, 6, 5, 6, 5, 1, 2, 2, 3, 7, 6, 4, 0, 1, 5 }; // to be sure that this function is only called in render thread AGE_ASSERT(CurrentThread() == (AGE::Thread*)GetRenderThread()); if (SimpleGeometry::cubeMesh.verticesKey.isValid() && SimpleGeometry::cubeMesh.painterKey.isValid()) { v = SimpleGeometry::cubeMesh.verticesKey; p = SimpleGeometry::cubeMesh.painterKey; return; } auto type = std::make_pair<GLenum, StringID>(GL_FLOAT_VEC3, StringID("position", 0x4cbf3a26fca1d74a)); std::vector<std::pair < GLenum, StringID > > types; types.push_back(type); if (!paintingManager->has_painter(types)) { SimpleGeometry::cubeMesh.painterKey = paintingManager->add_painter(std::move(types)); } else { SimpleGeometry::cubeMesh.painterKey = paintingManager->get_painter(types); } auto &painterPtr = paintingManager->get_painter(SimpleGeometry::cubeMesh.painterKey); SimpleGeometry::cubeMesh.verticesKey = painterPtr->add_vertices(positions.size(), indices.size()); auto vertices = painterPtr->get_vertices(SimpleGeometry::cubeMesh.verticesKey); vertices->set_data<glm::vec3>(positions, StringID("position", 0x4cbf3a26fca1d74a)); vertices->set_indices(indices); v = SimpleGeometry::cubeMesh.verticesKey; p = SimpleGeometry::cubeMesh.painterKey; }
HeadHairpin::HeadHairpin(const Tuple &head, const Tuple &tail, int len) { int i; Frag frag; for (i = 0; i < head[0]; i++) { frag.push_back(i); } d_frags.push_back(std::move(frag)); if (head[1] >= tail[1]) { if (head[2] < tail[2]) { for (i = head[1]+1; i < head[2]; i++) { frag.push_back(i); } } else { for (i = head[1]+1; i < tail[2]; i++) { frag.push_back(i); } } } d_frags.push_back(std::move(frag)); if (head[2] >= tail[2]) { if (head[3] < tail[3]) { for (i = head[2]+1; i < head[3]; i++) { frag.push_back(i); } } else { for (i = head[2]+1; i < tail[3]; i++) { frag.push_back(i); } } } d_frags.push_back(std::move(frag)); if (head[3] >= tail[3]) { for (i = head[3]+1; i < len; i++) { frag.push_back(i); } } d_frags.push_back(std::move(frag)); d_max_len = std::accumulate(d_frags.begin(), d_frags.end(), 0, [&](int l, auto && frag){return std::max(l, int(frag.size()));}); // Set indices d_indices = Mati::Constant(d_max_len, 4, -1); for (int i = 0; i < 4; i++) { set_indices(i, d_frags[i], head[i] <= tail[i]); } }
Loop::Loop(const Tuple &t1, const Tuple &t2, int len) { Tuple s1 = t1, s2 = t2; Frag frag; std::pair<int, int> p[4]; for (int i = 0; i < 4; i++) { p[i] = std::minmax(s1[i], s2[i]); for (int j = p[i].first+1; j < p[i].second; j++) { frag.push_back(j); } d_frags.push_back(std::move(frag)); } d_max_len = std::accumulate(d_frags.begin(), d_frags.end(), 0, [](int n, auto &&frag){ return std::max(n, int(frag.size())); }); d_indices = Mati::Constant(d_max_len, 4, -1); for (int i = 0; i < 4; i++) { set_indices(i, d_frags[i], t1[i] <= t2[i]); } }
void RenderThread::getIcoSphereGeometry(Key<Vertices> &v, Key<Painter> &p, uint32_t recursion) { std::vector<glm::vec3> positions; std::vector<unsigned int> indices; // to be sure that this function is only called in render thread AGE_ASSERT(CurrentThread() == (AGE::Thread*)GetRenderThread()); if (SimpleGeometry::icosphereMeshes[recursion].verticesKey.isValid() && SimpleGeometry::icosphereMeshes[recursion].painterKey.isValid()) { v = SimpleGeometry::icosphereMeshes[recursion].verticesKey; p = SimpleGeometry::icosphereMeshes[recursion].painterKey; return; } SimpleGeometry::generateIcoSphere(recursion, positions, indices); auto type = std::make_pair<GLenum, StringID>(GL_FLOAT_VEC3, StringID("position", 0x4cbf3a26fca1d74a)); std::vector<std::pair < GLenum, StringID > > types; types.push_back(type); if (!paintingManager->has_painter(types)) { SimpleGeometry::icosphereMeshes[recursion].painterKey = paintingManager->add_painter(std::move(types)); } else { SimpleGeometry::icosphereMeshes[recursion].painterKey = paintingManager->get_painter(types); } auto &painterPtr = paintingManager->get_painter(SimpleGeometry::icosphereMeshes[recursion].painterKey); SimpleGeometry::icosphereMeshes[recursion].verticesKey = painterPtr->add_vertices(positions.size(), indices.size()); auto vertices = painterPtr->get_vertices(SimpleGeometry::icosphereMeshes[recursion].verticesKey); vertices->set_data<glm::vec3>(positions, StringID("position", 0x4cbf3a26fca1d74a)); vertices->set_indices(indices); v = SimpleGeometry::icosphereMeshes[recursion].verticesKey; p = SimpleGeometry::icosphereMeshes[recursion].painterKey; }
box::box() { set_indices ( { // Front 0, 1, 2, 2, 3, 0, // Back 4, 5, 6, 6, 7, 4, // Left 8, 9, 10, 10, 11, 8, // Right 12, 13, 14, 14, 15, 12, // Up 16, 17, 18, 18, 19, 16, // Down 20, 21, 22, 22, 23, 20 } ); }
int send_data(void) { static time_t delay, now, last_hbeat = 0; int i, j, k, nsent, done, have_data; static char *fid = "send_data"; /* Loop over all channels looking for data to send */ nsent = 0; do { /* start off assuming we don't have, and won't have, anything */ done = 1; have_data = 0; /* now loop through all channels to see if this is true */ for (i = 0; i < edes->nsys; i++) { for (j = 0; j < SYS->nsta; j++) { for (k = 0; k < SSTA->nchn; k++) { /* if waiting for data, see if any are ready */ if (ICHN->status == EDES_WAITING) { set_indices(edes,i,j,k,buffer); } /* send anything we have to send */ if (ICHN->status == EDES_READY) { transfer(cnf,FORM,COMP,edes,i,j,k,buffer,peer); ++nsent; } /* if we have more to do, set appropriate flag(s) */ if (ICHN->status == EDES_READY) { have_data = 1; done = 0; } else if (ICHN->status == EDES_WAITING) { done = 0; } } } } } while (have_data); /* Quit if we have sent all requested data */ if (done) { util_log(2, "%s: waveform request processing complete", fid); return EDES_DONE; } /* If we didn't send anything, send a heartbeat */ if (nsent == 0) { now = time(NULL); delay = now - last_hbeat; if (delay > HeartbeatInterval) { util_log(2, "send HEARTBEAT (delay = %ld)", now - last_hbeat); Xfer_Ack(edes->osd, XFER_HEARTBEAT); last_hbeat = now; } } return EDES_WAITING; }
void TypeRegistry::define_properties() { for (TypeMap::iterator j=tfmap_.begin(); j!=tfmap_.end(); ++j) { for (TypeList::iterator i=j->second.begin(); i!=j->second.end(); ++i) { typedef std::map<std::string, FunctionList> NameFunctionMap; typedef std::map<std::string, NameFunctionMap> FunctionMap; typedef std::map<std::size_t, FunctionMap> IndexFunctionMap; typedef std::map<std::string, PropertyList> PropertyMap; PropertyMap newprops; NameFunctionMap count_candidates; FunctionMap add_candidates; FunctionMap insert_candidates; IndexFunctionMap remove_candidates; IndexFunctionMap get_candidates; IndexFunctionMap set_candidates; typedef std::map<std::string, StringSet> NameTypeMap; NameTypeMap nameTypeMap; std::size_t max_indices = 0; for (FunctionList::const_iterator k=i->methods.begin(); k!=i->methods.end(); ++k) { if (!k->is_constructor(*i) && !k->is_destructor() && !k->is_static) { if (begins_with(k->name, "getOr") && k->name.size() > 5 && std::isupper(k->name[5], std::locale())) continue; if (begins_with(k->name, "getNum") && k->name.size() > 6 && std::isupper(k->name[6], std::locale())) { if (k->params.empty()) { std::string name(k->name.substr(6)); count_candidates[name].push_back(*k); continue; } } if (begins_with(k->name, "get") && ((k->name.size() > 3 && std::isupper(k->name[3], std::locale())) || (k->name.size() == 3))) { std::string name(k->name.substr(3)); std::size_t indices = k->params.size(); get_candidates[indices][k->return_type_specifier][name].push_back(*k); if (indices > max_indices) max_indices = indices; nameTypeMap[name].insert(k->return_type_specifier); continue; } if (begins_with(k->name, "set") && k->name.size() > 3 && std::isupper(k->name[3], std::locale())) { if (!k->params.empty()) { std::string name(k->name.substr(3)); std::size_t indices = k->params.size() - 1; set_candidates[indices][k->params.back().type_specifier][name].push_back(*k); if (indices > max_indices) max_indices = indices; nameTypeMap[name].insert(k->params.back().type_specifier); } continue; } if (begins_with(k->name, "add") && k->name.size() > 3 && std::isupper(k->name[3], std::locale())) { if (k->params.size() == 1) { std::string name(k->name.substr(3)); add_candidates[k->params.front().type_specifier][name].push_back(*k); nameTypeMap[name].insert(k->params.front().type_specifier); } continue; } if (begins_with(k->name, "remove") && k->name.size() > 6 && std::isupper(k->name[6], std::locale())) { if (!k->params.empty()) { std::string name(k->name.substr(6)); std::size_t indices = k->params.size(); remove_candidates[indices][k->params.front().type_specifier][name].push_back(*k); } continue; } if (begins_with(k->name, "insert") && k->name.size() > 6 && std::isupper(k->name[6], std::locale())) { if (k->params.size() >= 2) { std::string name(k->name.substr(6)); insert_candidates[k->params.front().type_specifier][name].push_back(*k); } continue; } } } for (NameTypeMap::const_iterator k=nameTypeMap.begin(); k!=nameTypeMap.end(); ++k) { StringSet::const_iterator endIt = k->second.end(); for (StringSet::const_iterator h=k->second.begin(); h!=endIt; ++h) { PropertyDesc pd; pd.name = k->first; pd.type_name = *h; // simple property { const FunctionList &fl_get = get_candidates[0][*h][k->first]; FunctionList fl_set; fl_set.insert(fl_set.end(), set_candidates[0][*h][k->first].begin(), set_candidates[0][*h][k->first].end()); fl_set.insert(fl_set.end(), set_candidates[0]["const " + *h + " &"][k->first].begin(), set_candidates[0]["const " + *h + " &"][k->first].end()); if (!fl_get.empty()) pd.get_method = fl_get.front().name_signature; if (!fl_set.empty()) pd.set_method = fl_set.front().name_signature; if (!pd.get_method.empty() || !pd.set_method.empty()) { pd.type = PropertyDesc::SIMPLE; newprops[pd.name].push_back(pd); continue; } } // array property { FunctionList fl_count; fl_count.insert(fl_count.end(), count_candidates[k->first].begin(), count_candidates[k->first].end()); fl_count.insert(fl_count.end(), count_candidates[k->first + "s"].begin(), count_candidates[k->first + "s"].end()); fl_count.insert(fl_count.end(), count_candidates[k->first + "es"].begin(), count_candidates[k->first + "es"].end()); fl_count.insert(fl_count.end(), count_candidates[k->first + "ren"].begin(), count_candidates[k->first + "ren"].end()); if (fl_count.size()) { std::string& return_type_specifier = fl_count.front().return_type_specifier; const FunctionList &fl_get = get_candidates[1][*h][k->first]; FunctionList fl_set; fl_set.insert(fl_set.end(), set_candidates[1][*h][k->first].begin(), set_candidates[1][*h][k->first].end()); fl_set.insert(fl_set.end(), set_candidates[1]["const " + *h + " &"][k->first].begin(), set_candidates[1]["const " + *h + " &"][k->first].end()); const FunctionList &fl_add = add_candidates[*h][k->first]; FunctionList fl_remove; fl_remove.insert(fl_remove.end(), remove_candidates[1][return_type_specifier][k->first].begin(), remove_candidates[1][return_type_specifier][k->first].end()); fl_remove.insert(fl_remove.end(), remove_candidates[1][return_type_specifier][k->first + "s"].begin(), remove_candidates[1][return_type_specifier][k->first + "s"].end()); fl_remove.insert(fl_remove.end(), remove_candidates[1][return_type_specifier][k->first + "es"].begin(), remove_candidates[1][return_type_specifier][k->first + "es"].end()); fl_remove.insert(fl_remove.end(), remove_candidates[1][return_type_specifier][k->first + "ren"].begin(), remove_candidates[1][return_type_specifier][k->first + "ren"].end()); fl_remove.insert(fl_remove.end(), remove_candidates[2][return_type_specifier][k->first].begin(), remove_candidates[2][return_type_specifier][k->first].end()); fl_remove.insert(fl_remove.end(), remove_candidates[2][return_type_specifier][k->first + "s"].begin(), remove_candidates[2][return_type_specifier][k->first + "s"].end()); fl_remove.insert(fl_remove.end(), remove_candidates[2][return_type_specifier][k->first + "es"].begin(), remove_candidates[2][return_type_specifier][k->first + "es"].end()); fl_remove.insert(fl_remove.end(), remove_candidates[2][return_type_specifier][k->first + "ren"].begin(), remove_candidates[2][return_type_specifier][k->first + "ren"].end()); FunctionList fl_insert = insert_candidates[return_type_specifier][k->first]; fl_insert.erase(std::remove_if(fl_insert.begin(), fl_insert.end(), PropertyFunctionFirstParameterNameFilter<2>(fl_count.front().return_type_specifier)), fl_insert.end()); fl_remove.erase(std::remove_if(fl_remove.begin(), fl_remove.end(), PropertyFunctionFirstParameterNameFilter<1>(fl_count.front().return_type_specifier)), fl_remove.end()); if (!fl_get.empty()) pd.get_method = fl_get.front().name_signature; if (!fl_set.empty()) pd.set_method = fl_set.front().name_signature; if (!fl_add.empty()) pd.add_method = fl_add.front().name_signature; if (!fl_insert.empty()) pd.insert_method = fl_insert.front().name_signature; if (!fl_remove.empty()) pd.remove_method = fl_remove.front().name_signature; if (!fl_count.empty()) pd.count_method = fl_count.front().name_signature; if (!pd.get_method.empty() || !pd.set_method.empty()) { pd.type = PropertyDesc::ARRAY; newprops[pd.name].push_back(pd); continue; } } } // indexed property for (std::size_t u=1; u<=max_indices; ++u) { const FunctionList &fl_get = get_candidates[u][*h][k->first]; FunctionList fl_set; fl_set.insert(fl_set.end(), set_candidates[u][*h][k->first].begin(), set_candidates[u][*h][k->first].end()); fl_set.insert(fl_set.end(), set_candidates[u]["const " + *h + " &"][k->first].begin(), set_candidates[u]["const " + *h + " &"][k->first].end()); if (!fl_get.empty()) pd.get_method = fl_get.front().name_signature; if (!fl_set.empty()) pd.set_method = fl_set.front().name_signature; for (FunctionList::const_iterator x=fl_get.begin(); x!=fl_get.end(); ++x) { ParameterList get_indices(x->params.begin(), x->params.end()); for (FunctionList::const_iterator y=fl_set.begin(); y!=fl_set.end(); ++y) { ParameterList set_indices(y->params.begin(), y->params.end()); set_indices.pop_back(); if (same_parameters(get_indices, set_indices)) { pd.type = PropertyDesc::INDEXED; pd.get_method = x->name_signature; pd.set_method = y->name_signature; newprops[pd.name].push_back(pd); break; } } } } } } for (PropertyMap::iterator k=newprops.begin(); k!=newprops.end(); ++k) { if (!k->second.empty()) { std::sort(k->second.begin(), k->second.end(), PropertySorter()); PropertyDesc & pd = k->second.front(); const PropertyOptions *opt = cfg_.getPropertyOptions(i->type_name, pd.name); if (opt) { if (!opt->get_method.empty()) pd.get_method = opt->get_method; if (!opt->set_method.empty()) pd.set_method = opt->set_method; if (!opt->remove_method.empty()) pd.remove_method = opt->remove_method; if (!opt->add_method.empty()) pd.add_method = opt->add_method; if (!opt->insert_method.empty()) pd.insert_method = opt->insert_method; if (!opt->count_method.empty()) { Notify::info("define count method of property `" + pd.name + "' in type `" + i->type_name + "' on user request"); pd.type = PropertyDesc::ARRAY; pd.count_method = opt->count_method; } } i->properties.push_back(k->second.front()); } } } } }