RayCastModelHit Model::castRay(const Vec3& origin, const Vec3& dir, const Matrix& model_transform, const Pose* pose) { RayCastModelHit hit; hit.m_is_hit = false; if (!isReady()) return hit; Matrix inv = model_transform; inv.inverse(); Vec3 local_origin = inv.transformPoint(origin); Vec3 local_dir = (inv * Vec4(dir.x, dir.y, dir.z, 0)).xyz(); Matrix matrices[256]; ASSERT(!pose || pose->count <= lengthOf(matrices)); bool is_skinned = false; for (int mesh_index = m_lods[0].from_mesh; mesh_index <= m_lods[0].to_mesh; ++mesh_index) { Mesh& mesh = m_meshes[mesh_index]; is_skinned = pose && !mesh.skin.empty() && pose->count <= lengthOf(matrices); } if (is_skinned) { computeSkinMatrices(*pose, *this, matrices); } for (int mesh_index = m_lods[0].from_mesh; mesh_index <= m_lods[0].to_mesh; ++mesh_index) { Mesh& mesh = m_meshes[mesh_index]; bool is_mesh_skinned = !mesh.skin.empty(); u16* indices16 = (u16*)&mesh.indices[0]; u32* indices32 = (u32*)&mesh.indices[0]; bool is16 = mesh.flags.isSet(Mesh::Flags::INDICES_16_BIT); int index_size = is16 ? 2 : 4; for(int i = 0, c = mesh.indices.size() / index_size; i < c; i += 3) { Vec3 p0, p1, p2; if (is16) { p0 = mesh.vertices[indices16[i]]; p1 = mesh.vertices[indices16[i + 1]]; p2 = mesh.vertices[indices16[i + 2]]; if (is_mesh_skinned) { p0 = evaluateSkin(p0, mesh.skin[indices16[i]], matrices); p1 = evaluateSkin(p1, mesh.skin[indices16[i + 1]], matrices); p2 = evaluateSkin(p2, mesh.skin[indices16[i + 2]], matrices); } } else { p0 = mesh.vertices[indices32[i]]; p1 = mesh.vertices[indices32[i + 1]]; p2 = mesh.vertices[indices32[i + 2]]; if (is_mesh_skinned) { p0 = evaluateSkin(p0, mesh.skin[indices32[i]], matrices); p1 = evaluateSkin(p1, mesh.skin[indices32[i + 1]], matrices); p2 = evaluateSkin(p2, mesh.skin[indices32[i + 2]], matrices); } } Vec3 normal = crossProduct(p1 - p0, p2 - p0); float q = dotProduct(normal, local_dir); if (q == 0) continue; float d = -dotProduct(normal, p0); float t = -(dotProduct(normal, local_origin) + d) / q; if (t < 0) continue; Vec3 hit_point = local_origin + local_dir * t; Vec3 edge0 = p1 - p0; Vec3 VP0 = hit_point - p0; if (dotProduct(normal, crossProduct(edge0, VP0)) < 0) continue; Vec3 edge1 = p2 - p1; Vec3 VP1 = hit_point - p1; if (dotProduct(normal, crossProduct(edge1, VP1)) < 0) continue; Vec3 edge2 = p0 - p2; Vec3 VP2 = hit_point - p2; if (dotProduct(normal, crossProduct(edge2, VP2)) < 0) continue; if (!hit.m_is_hit || hit.m_t > t) { hit.m_is_hit = true; hit.m_t = t; hit.m_mesh = &m_meshes[mesh_index]; } } } hit.m_origin = origin; hit.m_dir = dir; return hit; }
void Array<T>::eval() const { if (isReady()) return; const_cast<Array<T> *>(this)->eval(); }
/** * @brief Initializes the core, must be called before anything else */ void Core::start(const QByteArray& savedata) { bool isNewProfile = profile.isNewProfile(); if (isNewProfile) { qDebug() << "Creating a new profile"; makeTox(QByteArray()); makeAv(); setStatusMessage(tr("Toxing on qTox")); setUsername(profile.getName()); } else { qDebug() << "Loading user profile"; if (savedata.isEmpty()) { emit failedToStart(); return; } makeTox(savedata); makeAv(); } qsrand(time(nullptr)); if (!tox) { ready = true; GUI::setEnabled(true); return; } // set GUI with user and statusmsg QString name = getUsername(); if (!name.isEmpty()) { emit usernameSet(name); } QString msg = getStatusMessage(); if (!msg.isEmpty()) { emit statusMessageSet(msg); } ToxId id = getSelfId(); // TODO: probably useless check, comes basically directly from toxcore if (id.isValid()) { emit idSet(id); } loadFriends(); tox_callback_friend_request(tox, onFriendRequest); tox_callback_friend_message(tox, onFriendMessage); tox_callback_friend_name(tox, onFriendNameChange); tox_callback_friend_typing(tox, onFriendTypingChange); tox_callback_friend_status_message(tox, onStatusMessageChanged); tox_callback_friend_status(tox, onUserStatusChanged); tox_callback_friend_connection_status(tox, onConnectionStatusChanged); tox_callback_friend_read_receipt(tox, onReadReceiptCallback); tox_callback_conference_invite(tox, onGroupInvite); tox_callback_conference_message(tox, onGroupMessage); tox_callback_conference_namelist_change(tox, onGroupNamelistChange); tox_callback_conference_title(tox, onGroupTitleChange); tox_callback_file_chunk_request(tox, CoreFile::onFileDataCallback); tox_callback_file_recv(tox, CoreFile::onFileReceiveCallback); tox_callback_file_recv_chunk(tox, CoreFile::onFileRecvChunkCallback); tox_callback_file_recv_control(tox, CoreFile::onFileControlCallback); QByteArray data = profile.loadAvatarData(getSelfPublicKey().toString()); if (data.isEmpty()) { qDebug() << "Self avatar not found, will broadcast empty avatar to friends"; } setAvatar(data); ready = true; if (isNewProfile) { profile.saveToxSave(); } if (isReady()) { GUI::setEnabled(true); } process(); // starts its own timer av->start(); }
//FIXME: implement withOffset parameter const T* get(bool withOffset = true) const { if (!isReady()) eval(); return data.get() + (withOffset ? getOffset() : 0); }
int useCount() const { if (!isReady()) eval(); return data.use_count(); }
/** * Returns the next socket ready for communications as indicated by select * @param more_work flag to indicate more work is waiting, and thus a timeout value of 0 should * be used for the select * @param tp the timeout to be used for the select, unless overridden * @return the socket next ready, or 0 if none is ready */ int Socket_getReadySocket(int more_work, struct timeval *tp) { int rc = 0; static struct timeval zero = {0L, 0L}; /* 0 seconds */ static struct timeval one = {1L, 0L}; /* 1 second */ struct timeval timeout = one; FUNC_ENTRY; if (s.clientsds->count == 0) goto exit; if (more_work) timeout = zero; else if (tp) timeout = *tp; while (s.cur_clientsds != NULL) { if (isReady(*((int*)(s.cur_clientsds->content)), &(s.rset), &wset)) break; ListNextElement(s.clientsds, &s.cur_clientsds); } if (s.cur_clientsds == NULL) { int rc1; fd_set pwset; memcpy((void*)&(s.rset), (void*)&(s.rset_saved), sizeof(s.rset)); memcpy((void*)&(pwset), (void*)&(s.pending_wset), sizeof(pwset)); if ((rc = select(s.maxfdp1, &(s.rset), &pwset, NULL, &timeout)) == SOCKET_ERROR) { Socket_error("read select", 0); goto exit; } Log(TRACE_MAX, -1, "Return code %d from read select", rc); if (Socket_continueWrites(&pwset) == SOCKET_ERROR) { rc = 0; goto exit; } memcpy((void*)&wset, (void*)&(s.rset_saved), sizeof(wset)); if ((rc1 = select(s.maxfdp1, NULL, &(wset), NULL, &zero)) == SOCKET_ERROR) { Socket_error("write select", 0); rc = rc1; goto exit; } Log(TRACE_MAX, -1, "Return code %d from write select", rc1); if (rc == 0 && rc1 == 0) goto exit; /* no work to do */ s.cur_clientsds = s.clientsds->first; while (s.cur_clientsds != NULL) { int cursock = *((int*)(s.cur_clientsds->content)); if (isReady(cursock, &(s.rset), &wset)) break; ListNextElement(s.clientsds, &s.cur_clientsds); } } if (s.cur_clientsds == NULL) rc = 0; else { rc = *((int*)(s.cur_clientsds->content)); ListNextElement(s.clientsds, &s.cur_clientsds); } exit: FUNC_EXIT_RC(rc); return rc; } /* end getReadySocket */
T* get(bool withOffset = true) { if (!isReady()) eval(); return const_cast<T*>(static_cast<const Array<T>*>(this)->get(withOffset)); }
RayCastModelHit Model::castRay(const Vec3& origin, const Vec3& dir, const Matrix& model_transform) { RayCastModelHit hit; hit.m_is_hit = false; if (!isReady()) { return hit; } Matrix inv = model_transform; inv.inverse(); Vec3 local_origin = inv.multiplyPosition(origin); Vec3 local_dir = static_cast<Vec3>(inv * Vec4(dir.x, dir.y, dir.z, 0)); const Array<Vec3>& vertices = m_vertices; const Array<int32_t>& indices = m_indices; int vertex_offset = 0; for (int mesh_index = 0; mesh_index < m_meshes.size(); ++mesh_index) { int indices_end = m_meshes[mesh_index].getIndicesOffset() + m_meshes[mesh_index].getIndexCount(); for (int i = m_meshes[mesh_index].getIndicesOffset(); i < indices_end; i += 3) { Vec3 p0 = vertices[vertex_offset + indices[i]]; Vec3 p1 = vertices[vertex_offset + indices[i + 1]]; Vec3 p2 = vertices[vertex_offset + indices[i + 2]]; Vec3 normal = crossProduct(p1 - p0, p2 - p0); float q = dotProduct(normal, local_dir); if (q == 0) { continue; } float d = -dotProduct(normal, p0); float t = -(dotProduct(normal, local_origin) + d) / q; if (t < 0) { continue; } Vec3 hit_point = local_origin + local_dir * t; Vec3 edge0 = p1 - p0; Vec3 VP0 = hit_point - p0; if (dotProduct(normal, crossProduct(edge0, VP0)) < 0) { continue; } Vec3 edge1 = p2 - p1; Vec3 VP1 = hit_point - p1; if (dotProduct(normal, crossProduct(edge1, VP1)) < 0) { continue; } Vec3 edge2 = p0 - p2; Vec3 VP2 = hit_point - p2; if (dotProduct(normal, crossProduct(edge2, VP2)) < 0) { continue; } if (!hit.m_is_hit || hit.m_t > t) { hit.m_is_hit = true; hit.m_t = t; hit.m_mesh = &m_meshes[mesh_index]; } } vertex_offset += m_meshes[mesh_index].getAttributeArraySize() / m_meshes[mesh_index].getVertexDefinition().getStride(); } hit.m_origin = origin; hit.m_dir = dir; return hit; }
void QOfonoMessageWaiting::modemInterfacesChanged(const QStringList &interfaces) { bool haveIface = interfaces.contains("org.ofono.MessageWaiting"); if (haveIface != (isValid() && isReady())) connectOfono(); }
void Core::start() { bool isNewProfile = profile.isNewProfile(); if (isNewProfile) { qDebug() << "Creating a new profile"; makeTox(QByteArray()); setStatusMessage(tr("Toxing on qTox")); setUsername(profile.getName()); } else { qDebug() << "Loading user profile"; QByteArray savedata = profile.loadToxSave(); if (savedata.isEmpty()) { emit failedToStart(); return; } makeTox(savedata); } qsrand(time(nullptr)); if (!tox) { ready = true; GUI::setEnabled(true); return; } // set GUI with user and statusmsg QString name = getUsername(); if (!name.isEmpty()) emit usernameSet(name); QString msg = getStatusMessage(); if (!msg.isEmpty()) emit statusMessageSet(msg); QString id = getSelfId().toString(); if (!id.isEmpty()) emit idSet(id); /// TODO: NOTE: This is a backwards compatibility check, /// once most people have been upgraded away from the old HistoryKeeper, remove this if (Nexus::getProfile()->isEncrypted()) checkEncryptedHistory(); loadFriends(); tox_callback_friend_request(tox, onFriendRequest, this); tox_callback_friend_message(tox, onFriendMessage, this); tox_callback_friend_name(tox, onFriendNameChange, this); tox_callback_friend_typing(tox, onFriendTypingChange, this); tox_callback_friend_status_message(tox, onStatusMessageChanged, this); tox_callback_friend_status(tox, onUserStatusChanged, this); tox_callback_friend_connection_status(tox, onConnectionStatusChanged, this); tox_callback_friend_read_receipt(tox, onReadReceiptCallback, this); tox_callback_group_invite(tox, onGroupInvite, this); tox_callback_group_message(tox, onGroupMessage, this); tox_callback_group_namelist_change(tox, onGroupNamelistChange, this); tox_callback_group_title(tox, onGroupTitleChange, this); tox_callback_group_action(tox, onGroupAction, this); tox_callback_file_chunk_request(tox, CoreFile::onFileDataCallback, this); tox_callback_file_recv(tox, CoreFile::onFileReceiveCallback, this); tox_callback_file_recv_chunk(tox, CoreFile::onFileRecvChunkCallback, this); tox_callback_file_recv_control(tox, CoreFile::onFileControlCallback, this); QPixmap pic = profile.loadAvatar(); if (!pic.isNull() && !pic.size().isEmpty()) { QByteArray data; QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); pic.save(&buffer, "PNG"); buffer.close(); setAvatar(data); } else { qDebug() << "Self avatar not found, will broadcast empty avatar to friends"; setAvatar({}); } ready = true; // If we created a new profile earlier, // now that we're ready save it and ONLY THEN broadcast the new ID. // This is useful for e.g. the profileForm that searches for saves. if (isNewProfile) { profile.saveToxSave(); emit idSet(getSelfId().toString()); } if (isReady()) GUI::setEnabled(true); process(); // starts its own timer av->start(); }
void Core::start() { qDebug() << "Core: Starting up"; QByteArray savedata = loadToxSave(loadPath); make_tox(savedata); // Do we need to create a new save & profile? if (savedata.isNull()) { qDebug() << "Save file not found, creating a new profile"; Settings::getInstance().load(); setStatusMessage(tr("Toxing on qTox")); setUsername(tr("qTox User")); } qsrand(time(nullptr)); // set GUI with user and statusmsg QString name = getUsername(); if (!name.isEmpty()) emit usernameSet(name); QString msg = getStatusMessage(); if (!msg.isEmpty()) emit statusMessageSet(msg); QString id = getSelfId().toString(); if (!id.isEmpty()) emit idSet(id); // tox core is already decrypted if (Settings::getInstance().getEnableLogging() && Settings::getInstance().getEncryptLogs()) checkEncryptedHistory(); loadFriends(); tox_callback_friend_request(tox, onFriendRequest, this); tox_callback_friend_message(tox, onFriendMessage, this); tox_callback_friend_name(tox, onFriendNameChange, this); tox_callback_friend_typing(tox, onFriendTypingChange, this); tox_callback_friend_status_message(tox, onStatusMessageChanged, this); tox_callback_friend_status(tox, onUserStatusChanged, this); tox_callback_friend_connection_status(tox, onConnectionStatusChanged, this); tox_callback_friend_read_receipt(tox, onReadReceiptCallback, this); tox_callback_group_invite(tox, onGroupInvite, this); tox_callback_group_message(tox, onGroupMessage, this); tox_callback_group_namelist_change(tox, onGroupNamelistChange, this); tox_callback_group_title(tox, onGroupTitleChange, this); tox_callback_group_action(tox, onGroupAction, this); tox_callback_file_chunk_request(tox, CoreFile::onFileDataCallback, this); tox_callback_file_recv(tox, CoreFile::onFileReceiveCallback, this); tox_callback_file_recv_chunk(tox, CoreFile::onFileRecvChunkCallback, this); tox_callback_file_recv_control(tox, CoreFile::onFileControlCallback, this); toxav_register_callstate_callback(toxav, onAvInvite, av_OnInvite, this); toxav_register_callstate_callback(toxav, onAvStart, av_OnStart, this); toxav_register_callstate_callback(toxav, onAvCancel, av_OnCancel, this); toxav_register_callstate_callback(toxav, onAvReject, av_OnReject, this); toxav_register_callstate_callback(toxav, onAvEnd, av_OnEnd, this); toxav_register_callstate_callback(toxav, onAvRinging, av_OnRinging, this); toxav_register_callstate_callback(toxav, onAvMediaChange, av_OnPeerCSChange, this); toxav_register_callstate_callback(toxav, onAvMediaChange, av_OnSelfCSChange, this); toxav_register_callstate_callback(toxav, onAvRequestTimeout, av_OnRequestTimeout, this); toxav_register_callstate_callback(toxav, onAvPeerTimeout, av_OnPeerTimeout, this); toxav_register_audio_callback(toxav, playCallAudio, this); toxav_register_video_callback(toxav, playCallVideo, this); QPixmap pic = Settings::getInstance().getSavedAvatar(getSelfId().toString()); if (!pic.isNull() && !pic.size().isEmpty()) { QByteArray data; QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); pic.save(&buffer, "PNG"); buffer.close(); setAvatar(data); } else { qDebug() << "Core: Error loading self avatar"; } ready = true; // If we created a new profile earlier, // now that we're ready save it and ONLY THEN broadcast the new ID. // This is useful for e.g. the profileForm that searches for saves. if (savedata.isNull()) { saveConfiguration(); emit idSet(getSelfId().toString()); } if (isReady()) GUI::setEnabled(true); process(); // starts its own timer }
sfBool sfSocketSelector_isUdpSocketReady(const sfSocketSelector* selector, sfUdpSocket* socket) { CSFML_CHECK_RETURN(socket, sfFalse); CSFML_CALL_RETURN(selector, isReady(socket->This), sfFalse); }
sfBool sfSocketSelector_isTcpListenerReady(const sfSocketSelector* selector, sfTcpListener* socket) { CSFML_CHECK_RETURN(socket, sfFalse); CSFML_CALL_RETURN(selector, isReady(socket->This), sfFalse); }
std::string ChatBot::chatToken() const { return isReady() ? *oauthAccessToken_ : std::string(); }