SDGeometryHandle compile_geometry(SDRenderMode mode, SDVec2* vertices, SDuint numVertices, SDuint* indices, SDuint numIndices) { kglt::MeshID new_mesh = stage()->new_mesh(); { auto mesh = stage()->mesh(new_mesh); auto submesh = mesh->new_submesh( stage()->get_material_with_alias("diffuse_render"), (mode == SD_RENDER_MODE_TRIANGLES) ? kglt::MESH_ARRANGEMENT_TRIANGLES : kglt::MESH_ARRANGEMENT_LINES, true ); for(SDuint i = 0; i < numVertices; ++i) { mesh->shared_data().position(vertices[i]); mesh->shared_data().diffuse(kglt::Colour::WHITE); mesh->shared_data().move_next(); } for(SDuint i = 0; i < numIndices; ++i) { mesh->submesh(submesh).index_data().index(indices[i]); } mesh->submesh(submesh).index_data().done(); mesh->shared_data().done(); } kglt::ActorID new_actor = stage()->new_actor(new_mesh); return new_actor.value(); }
void ExpandableListTestFixture::testAddSharedPtr(){ ExpandableList<Datum> list; shared_ptr<Datum> shared_data(new Datum(10L)); list.addElement(shared_data); CPPUNIT_ASSERT( list.getNElements() == 1 ); CPPUNIT_ASSERT( *(list[0]) == Datum(10L) ); }
shared_data xcc_z::gunzip(data_ref s) { if (s.size() < 18) return shared_data(); shared_data d(read_int_le(4, s.end() - 4)); z_stream stream; stream.zalloc = NULL; stream.zfree = NULL; stream.opaque = NULL; stream.next_in = const_cast<unsigned char*>(s.begin()) + 10; stream.avail_in = s.size() - 18; stream.next_out = d.data(); stream.avail_out = d.size(); return stream.next_out && Z_OK == inflateInit2(&stream, -MAX_WBITS) && Z_STREAM_END == inflate(&stream, Z_FINISH) && Z_OK == inflateEnd(&stream) ? d : shared_data(); }
void Cxif_value::load_new(const byte*& data) { m_data.clear(); m_type = static_cast<t_vt>(*data++); switch (m_type) { case vt_bin32: case vt_int32: m_value_int = read_int(data); break; case vt_float: m_value_float = read_float(data); break; case vt_external_binary: m_data = shared_data(read_int(data)); break; default: { int size = read_int(data); m_data = make_shared_data(data, size); data += size; } } }
MeshID ResourceManagerImpl::new_mesh_from_vertices(const std::vector<Vec3> &vertices, MeshArrangement arrangement, bool garbage_collect) { //FIXME: THis is literally a copy/paste of the function above, we can templatize this MeshID m = new_mesh(garbage_collect); auto new_mesh = mesh(m); auto smi = new_mesh->new_submesh(arrangement); int i = 0; for(auto v: vertices) { new_mesh->shared_data().position(v); new_mesh->shared_data().diffuse(kglt::Colour::WHITE); new_mesh->shared_data().normal(kglt::Vec3()); new_mesh->shared_data().tex_coord0(kglt::Vec2()); new_mesh->shared_data().move_next(); new_mesh->submesh(smi)->index_data().index(i++); } new_mesh->shared_data().done(); new_mesh->submesh(smi)->index_data().done(); MeshManager::mark_as_uncollected(m); return m; }
void Cconnection::read(const std::string& v) { #ifndef NDEBUG std::cout << v << std::endl; #endif if (srv_config().m_log_access) { static std::ofstream f("xbt_tracker_raw.log"); f << srv_time() << '\t' << inet_ntoa(m_a.sin_addr) << '\t' << ntohs(m_a.sin_port) << '\t' << v << std::endl; } Ctracker_input ti; size_t e = v.find('?'); if (e == std::string::npos) e = v.size(); else { size_t a = e + 1; size_t b = v.find(' ', a); if (b == std::string::npos) return; while (a < b) { size_t c = v.find('=', a); if (c++ == std::string::npos) break; size_t d = v.find_first_of(" &", c); if (d == std::string::npos) break; ti.set(v.substr(a, c - a - 1), uri_decode(v.substr(c, d - c))); a = d + 1; } } if (!ti.m_ipa || !is_private_ipa(m_a.sin_addr.s_addr)) ti.m_ipa = m_a.sin_addr.s_addr; str_ref torrent_pass; size_t a = 4; if (a < e && v[a] == '/') { a++; if (a + 32 < e && v[a + 32] == '/') { torrent_pass.assign(&v[a], 32); a += 33; } } std::string h = "HTTP/1.0 200 OK\r\n"; std::string s; bool gzip = true; switch (a < v.size() ? v[a] : 0) { case 'a': if (ti.valid()) { gzip = false; std::string error = srv_insert_peer(ti, false, find_user_by_torrent_pass(torrent_pass, ti.m_info_hash)); s = error.empty() ? srv_select_peers(ti) : (boost::format("d14:failure reason%d:%se") % error.size() % error).str(); } break; case 'd': if (srv_config().m_debug) { h += "Content-Type: text/html; charset=us-ascii\r\n"; s = srv_debug(ti); } break; case 's': if (v.size() >= 7 && v[6] == 't') { h += "Content-Type: text/html; charset=us-ascii\r\n"; s = srv_statistics(); } else if (srv_config().m_full_scrape || !ti.m_info_hash.empty()) { gzip = srv_config().m_gzip_scrape && ti.m_info_hash.empty(); s = srv_scrape(ti, find_user_by_torrent_pass(torrent_pass, ti.m_info_hash)); } break; } if (s.empty()) { if (!ti.m_info_hash.empty() || srv_config().m_redirect_url.empty()) h = "HTTP/1.0 404 Not Found\r\n"; else { h = "HTTP/1.0 302 Found\r\n" "Location: " + srv_config().m_redirect_url + (ti.m_info_hash.empty() ? "" : "?info_hash=" + uri_encode(ti.m_info_hash)) + "\r\n"; } } else if (gzip) { shared_data s2 = xcc_z::gzip(s); #ifndef NDEBUG static std::ofstream f("xbt_tracker_gzip.log"); f << srv_time() << '\t' << v[5] << '\t' << s.size() << '\t' << s2.size() << std::endl; #endif if (s2.size() + 24 < s.size()) { h += "Content-Encoding: gzip\r\n"; s = to_string(s2); } } h += "\r\n"; #ifdef WIN32 m_write_b = shared_data(h.size() + s.size()); memcpy(m_write_b.data(), h); memcpy(m_write_b.data() + h.size(), s); int r = m_s.send(m_write_b); #else std::array<iovec, 2> d; d[0].iov_base = const_cast<char*>(h.data()); d[0].iov_len = h.size(); d[1].iov_base = const_cast<char*>(s.data()); d[1].iov_len = s.size(); msghdr m; m.msg_name = NULL; m.msg_namelen = 0; m.msg_iov = const_cast<iovec*>(d.data()); m.msg_iovlen = d.size(); m.msg_control = NULL; m.msg_controllen = 0; m.msg_flags = 0; int r = sendmsg(m_s, &m, MSG_NOSIGNAL); #endif if (r == SOCKET_ERROR) { if (WSAGetLastError() != WSAECONNRESET) std::cerr << "send failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; } else if (r != h.size() + s.size()) { #ifndef WIN32 if (r < h.size()) { m_write_b = shared_data(h.size() + s.size()); memcpy(m_write_b.data(), h); memcpy(m_write_b.data() + h.size(), s); } else { m_write_b = make_shared_data(s); r -= h.size(); } #endif m_r = m_write_b; m_r.advance_begin(r); } if (m_r.empty()) m_write_b.clear(); }