void build_mmp_list(void) { int64_t j, eindex, index; //Build up the most-massive progenitor list //This simultaneously tags halos w/o progenitors for (j=0; j<evolved.num_halos; j++) evolved.halos[j].mmp_id = -1; for (j=0; j<now.num_halos; j++) { now.halos[j].flags -= (now.halos[j].flags & MMP_FLAG); if (now.halos[j].flags & DEAD_HALO_FLAG) { now.halos[j].flags |= MMP_FLAG; continue; } eindex = id_to_index(evolved, now.halos[j].descid); if (eindex < 0) { //Descendant halo no longer exists now.halos[j].flags |= MMP_FLAG | DEAD_HALO_FLAG; continue; } index = id_to_index(now, evolved.halos[eindex].mmp_id); if (index < 0) { //If no MMP already identified. evolved.halos[eindex].mmp_id = now.halos[j].id; now.halos[j].flags |= MMP_FLAG; continue; } //Otherwise, check to see if we're more massive than the previous MMP. if (now.halos[j].mvir >= now.halos[index].mvir) { evolved.halos[eindex].mmp_id = now.halos[j].id; now.halos[index].flags -= (now.halos[index].flags & MMP_FLAG); //Safer than &= ~MMP_FLAG now.halos[j].flags |= MMP_FLAG; } } }
/** * @brief Changes the id of a dialog. * * The index of multiple dialogs may change, since they are sorted alphabetically. * In this case, emits rowsAboutToBeRemoved(), removes the dialog, * emits rowsRemoved() and rowsAboutToBeInserted(), adds the new dialog * and then emits rowsInserted(), as required by QAbstractItemModel. * * Then, emits dialog_id_changed(), no matter if the index has also changed. * * The selection is preserved, though the index of many dialogs can change. * The selection is cleared before the operations and restored after, * updated with the new indexes. * * @param id Id of an existing dialog. * @param new_id The new id to set. * @return The new id of the dialog. * @throws EditorException in case of error. */ QString DialogsModel::set_dialog_id(const QString& id, const QString& new_id) { if (new_id == id) { // Nothing to do. return id; } // Make some checks first. if (!dialog_exists(id)) { throw EditorException(tr("Dialog '%1' no exists").arg(id)); } if (dialog_exists(new_id)) { throw EditorException(tr("Dialog '%1' already exists").arg(new_id)); } if (!is_valid_id(new_id)) { throw EditorException(tr("Invalid dialog id: %1").arg(new_id)); } // Save and clear the selection since a lot of indexes may change. QString old_selection = get_selected_id(); clear_selection(); // Change in to the strings file. resources.set_dialog_id(id.toStdString(), new_id.toStdString()); // Remove from the indexed tree. QString parent_id; int index; if (dialog_tree.can_remove_key(id, parent_id, index)) { // Call beginRemoveRows() as requested by QAbstractItemModel. beginRemoveRows(id_to_index(parent_id), index, index); dialog_tree.remove_key(id); endRemoveRows(); } else if (dialog_tree.remove_key(id)) { QModelIndex model_index = id_to_index(id); dataChanged(model_index, model_index); } // Add to the indexed tree. if (dialog_tree.add_key(new_id, parent_id, index)) { // Call beginInsertRows() as requested by QAbstractItemModel. beginInsertRows(id_to_index(parent_id), index, index); endInsertRows(); } else { QModelIndex model_index = id_to_index(id); dataChanged(model_index, model_index); } // Notify people. emit dialog_id_changed(id, new_id); // Restore the selection. set_selected_id(old_selection); return new_id; }
int EventHub::getKeycodeState(int32_t deviceId, int code) const { AutoMutex _l(mLock); device_t* device = getDevice(deviceId); if (device == NULL || device->layoutMap == NULL) return -1; Vector<int32_t> scanCodes; device->layoutMap->findScancodes(code, &scanCodes); uint8_t key_bitmask[(KEY_MAX+7)/8]; memset(key_bitmask, 0, sizeof(key_bitmask)); if (ioctl(mFDs[id_to_index(device->id)].fd, EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) { #if 0 for (size_t i=0; i<=KEY_MAX; i++) { LOGI("(Scan code %d: down=%d)", i, test_bit(i, key_bitmask)); } #endif const size_t N = scanCodes.size(); for (size_t i=0; i<N && i<=KEY_MAX; i++) { int32_t sc = scanCodes.itemAt(i); //LOGI("Code %d: down=%d", sc, test_bit(sc, key_bitmask)); if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, key_bitmask)) { return 1; } } } return 0; }
NidServerDevice *nidServer_findDevice(int devid) { int index; index = id_to_index(devid); if (index < 0 || index >= device_max) return NULL; return devices[index]; }
/** * @brief Selects a dialog and deselects all others. * @param id The id to select. */ void DialogsModel::set_selected_id(const QString& id) { if (!dialog_tree.key_exists(id)) { return clear_selection(); } selection_model.select(id_to_index(id), QItemSelectionModel::ClearAndSelect); }
/** * @brief Returns the parent of the dialog id in the indexed tree. * @param index Index to get the parent of. * @return The parent index, or an invalid index if the dialog id has no parent. */ QModelIndex DialogsModel::parent(const QModelIndex& model_index) const { if (!model_index.isValid()) { return QModelIndex(); } QString id = dialog_tree.get_parent(index_to_id(model_index)); return id_to_index(id); }
/** * @brief Returns the index of a dialog id in the indexed tree. * @param row Row of the string key. * @param column Column of the string key. * @param parent Parent of the string key. * @return The corresponding index. Returns an invalid index if there is no * such the dialog id. */ QModelIndex DialogsModel::index( int row, int column, const QModelIndex& parent) const { if (!hasIndex(row, column, parent)) { return QModelIndex(); } if (!parent.isValid()) { return id_to_index(dialog_tree.get_row_key(row)); } QString id = index_to_id(parent); if (row >= dialog_tree.get_row_count(id)) { return QModelIndex(); } return id_to_index(dialog_tree.get_row_key(row, id)); }
void print_tidal_forces(int64_t output_num, float a, struct halo_stash *h, struct halo_stash *evolved) { char buffer[1024]; FILE *mmp_out, *nmmp_out, *output; int64_t mmp, j, eindex, tidal_desc_id, nindex, bfnmmp; float tidal_mvir; snprintf(buffer, 1024, "%s/extended_tidal_forces_mmp_%"PRId64".list", OUTBASE, output_num); mmp_out = check_fopen(buffer, "w"); fprintf(mmp_out, "#ID DescID TidalId TidalDescId TidalForce Rvir Mvir TidalMvir Vmax\n"); fprintf(mmp_out, "#Scale factor: %f\n", a); snprintf(buffer, 1024, "%s/extended_tidal_forces_nmmp_%"PRId64".list", OUTBASE, output_num); nmmp_out = check_fopen(buffer, "w"); fprintf(nmmp_out, "#ID DescID TidalId TidalDescId TidalForce Rvir Mvir TidalMvir Vmax Confirmed_Nmmp\n"); fprintf(nmmp_out, "#Scale factor: %f\n", a); for (j=0; j<h->num_halos; j++) { if (h->halos[j].flags & DEAD_HALO_FLAG) continue; eindex = id_to_index(*evolved, h->halos[j].descid); if (eindex < 0) //Descendant halo no longer exists continue; bfnmmp = 1; mmp = (evolved->halos[eindex].mmp_id == h->halos[j].id) ? 1 : 0; if (mmp && really_beyond_mmp_ratio(h->halos[j], evolved->halos[eindex])) { mmp = 0; bfnmmp = 0; } output = (mmp) ? mmp_out : nmmp_out; nindex = id_to_index(*h, h->halos[j].tidal_id); if (nindex>-1) { tidal_desc_id = h->halos[nindex].descid; tidal_mvir = h->halos[nindex].mvir; } else { tidal_desc_id = -1; tidal_mvir = 0; } fprintf(output, "%"PRId64" %"PRId64" %"PRId64" %"PRId64" %.3e %f %.3e %.3e %f %"PRId64"\n", h->halos[j].id, h->halos[j].descid, h->halos[j].tidal_id, tidal_desc_id, h->halos[j].tidal_force, h->halos[j].rvir, h->halos[j].mvir, tidal_mvir, h->halos[j].vmax, bfnmmp); } fclose(mmp_out); fclose(nmmp_out); }
int EventHub::getAbsoluteInfo(int32_t deviceId, int axis, int *outMinValue, int* outMaxValue, int* outFlat, int* outFuzz) const { AutoMutex _l(mLock); device_t* device = getDevice(deviceId); if (device == NULL) return -1; struct input_absinfo info; if(ioctl(mFDs[id_to_index(device->id)].fd, EVIOCGABS(axis), &info)) { LOGE("Error reading absolute controller %d for device %s fd %d\n", axis, device->name.string(), mFDs[id_to_index(device->id)].fd); return -1; } *outMinValue = info.minimum; *outMaxValue = info.maximum; *outFlat = info.flat; *outFuzz = info.fuzz; return 0; }
/** * @brief Deletes a dialog. * * The index of multiple dialogs may change, since they are sorted alphabetically. * Emits rowsAboutToBeRemoved(), removes the dialog * and then emits rowsRemoved(), as required by QAbstractItemModel. * * Then, emits dialog_deleted(). * * Except for the deleted dialog, the existing selection is preserved, * though the index of many dialogs can change. * The selection is cleared before the operations and restored after, * updated with the new indexes. * * @param id Id of the dialog to delete. * @throws EditorException in case of error. */ void DialogsModel::delete_dialog(const QString& id) { // Make some checks first. if (!dialog_exists(id)) { throw EditorException(tr("Invalid dialog id: %1").arg(id)); } // Save and clear the selection since a lot of indexes may change. QString old_selection = get_selected_id(); clear_selection(); // Delete from the strings file resources.remove_dialog(id.toStdString()); // Remove from the indexed tree. QString parent_id; int index; if (dialog_tree.can_remove_key(id, parent_id, index)) { // Call beginRemoveRows() as requested by QAbstractItemModel. beginRemoveRows(id_to_index(parent_id), index, index); dialog_tree.remove_key(id); // Notify people before restoring the selection, so that they have a // chance to know new indexes before receiving selection signals. endRemoveRows(); } else if (dialog_tree.remove_key(id)) { QModelIndex model_index = id_to_index(id); dataChanged(model_index, model_index); } // Notify people. emit dialog_deleted(id); // Restore the selection. set_selected_id(old_selection); }
/** * @brief Creates a new dialog. * * The index of the selection may change, since dialog are sorted * alphabetically. * Emits rowsAboutToBeInserted(), adds the new dialog * and then emits rowsInserted(), as required by QAbstractItemModel. * * Then, emits dialog_created(). * * The newly created dialog is not initially selected. * The existing selection is preserved, though the index of many * dialogs can change. * The selection is cleared before the operations and restored after, * updated with the new index. * * @param id Id of the dialog to create. * @param data Data of the dialog to create. * @throws EditorException in case of error. */ void DialogsModel::create_dialog(const QString& id, const DialogData& data) { // Make some checks first. if (!is_valid_id(id)) { throw EditorException(tr("Invalid dialog id: %1").arg(id)); } if (dialog_exists(id)) { throw EditorException(tr("Dialog '%1' already exists").arg(id)); } // Save and clear the selection since a lot of indexes may change. QString old_selection = get_selected_id(); clear_selection(); // Add to the strings file. resources.add_dialog(id.toStdString(), data); // Update the indexed tree. QString parent_id; int index; if (dialog_tree.add_key(id, parent_id, index)) { // Notify people before restoring the selection, so that they have a // chance to know new indexes before receiving selection signals. beginInsertRows(id_to_index(parent_id), index, index); endInsertRows(); } else { QModelIndex model_index = id_to_index(id); dataChanged(model_index, model_index); } // Notify people. emit dialog_created(id); // Restore the selection. set_selected_id(old_selection); }
int EventHub::getScancodeState(int32_t deviceId, int code) const { AutoMutex _l(mLock); device_t* device = getDevice(deviceId); if (device == NULL) return -1; if (code >= 0 && code <= KEY_MAX) { uint8_t key_bitmask[(KEY_MAX+7)/8]; memset(key_bitmask, 0, sizeof(key_bitmask)); if (ioctl(mFDs[id_to_index(device->id)].fd, EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) { return test_bit(code, key_bitmask) ? 1 : 0; } } return -1; }
int EventHub::getSwitchState(int32_t deviceId, int sw) const { #ifdef EV_SW AutoMutex _l(mLock); device_t* device = getDevice(deviceId); if (device == NULL) return -1; if (sw >= 0 && sw <= SW_MAX) { uint8_t sw_bitmask[(SW_MAX+7)/8]; memset(sw_bitmask, 0, sizeof(sw_bitmask)); if (ioctl(mFDs[id_to_index(device->id)].fd, EVIOCGSW(sizeof(sw_bitmask)), sw_bitmask) >= 0) { return test_bit(sw, sw_bitmask) ? 1 : 0; } } #endif return -1; }
/** * @brief Removes all translated dialogs from the indexed tree. */ void DialogsModel::clear_translation_from_tree() { for (const auto& kvp : translation_resources.get_dialogs()) { QString id = QString::fromStdString(kvp.first); QString parent_id; int index; if (dialog_tree.can_remove_ref(id, parent_id, index)) { if (!dialog_exists(id)) { beginRemoveRows(id_to_index(parent_id), index, index); dialog_tree.remove_ref(id, false); endRemoveRows(); } else { dialog_tree.remove_ref(id, true); } } else { dialog_tree.remove_ref(id, dialog_exists(id)); } } }
/** * @brief Reload the current translation. */ void DialogsModel::reload_translation() { clear_translation_from_tree(); QString path = quest.get_dialogs_path(translation_id); translation_resources.clear(); if (!translation_resources.import_from_file(path.toStdString())) { translation_id = ""; throw EditorException(tr("Cannot open dialogs data file '%1'").arg(path)); } for (const auto& kvp : translation_resources.get_dialogs()) { QString id = QString::fromStdString(kvp.first); QString parent_id; int index; if (dialog_tree.add_ref(id, parent_id, index)) { beginInsertRows(id_to_index(parent_id), index, index); endInsertRows(); } } }