bool AP_Compass_PX4::read(void) { // try to accumulate one more sample, so we have the latest data accumulate(); // consider the compass healthy if we got a reading in the last 0.2s for (uint8_t i=0; i<_num_instances; i++) { _healthy[i] = (hal.scheduler->micros64() - _last_timestamp[i] < 200000); } for (uint8_t i=0; i<_num_instances; i++) { // avoid division by zero if we haven't received any mag reports if (_count[i] == 0) continue; _sum[i] /= _count[i]; _sum[i] *= 1000; // apply default board orientation for this compass type. This is // a noop on most boards _sum[i].rotate(MAG_BOARD_ORIENTATION); // override any user setting of COMPASS_EXTERNAL _external.set(_is_external[0]); if (_is_external[i]) { // add user selectable orientation _sum[i].rotate((enum Rotation)_orientation.get()); } else { // add in board orientation from AHRS _sum[i].rotate(_board_orientation); } _sum[i] += _offset[i].get(); // apply motor compensation if (_motor_comp_type != AP_COMPASS_MOT_COMP_DISABLED && _thr_or_curr != 0.0f) { _motor_offset[i] = _motor_compensation[i].get() * _thr_or_curr; _sum[i] += _motor_offset[i]; } else { _motor_offset[i].zero(); } _field[i] = _sum[i]; _sum[i].zero(); _count[i] = 0; } last_update = _last_timestamp[get_primary()]; return _healthy[get_primary()]; }
/** * Base damage and absorb is 0 * Plus an optional bonus_per_[base stat] */ void StatBlock::calcBase() { // bonuses are skipped for the default level 1 of a stat int lev0 = std::max(level - 1, 0); for (size_t i = 0; i < Stats::COUNT + eset->damage_types.count; ++i) { base[i] = starting[i]; base[i] += lev0 * per_level[i]; for (size_t j = 0; j < per_primary.size(); ++j) { base[i] += std::max(get_primary(j) - 1, 0) * per_primary[j][i]; } } // add damage from equipment and increase to minimum amounts for (size_t i = 0; i < eset->damage_types.list.size(); ++i) { base[Stats::COUNT + (i*2)] += dmg_min_add[i]; base[Stats::COUNT + (i*2) + 1] += dmg_max_add[i]; base[Stats::COUNT + (i*2)] = std::max(base[Stats::COUNT + (i*2)], 0); base[Stats::COUNT + (i*2) + 1] = std::max(base[Stats::COUNT + (i*2) + 1], base[Stats::COUNT + (i*2)]); } // add absorb from equipment and increase to minimum amounts base[Stats::ABS_MIN] += absorb_min_add; base[Stats::ABS_MAX] += absorb_max_add; base[Stats::ABS_MIN] = std::max(base[Stats::ABS_MIN], 0); base[Stats::ABS_MAX] = std::max(base[Stats::ABS_MAX], base[Stats::ABS_MIN]); }
/** * Recalc derived stats from base stats + effect bonuses */ void StatBlock::applyEffects() { // preserve hp/mp states prev_maxhp = get(STAT_HP_MAX); prev_maxmp = get(STAT_MP_MAX); pres_hp = hp; pres_mp = mp; // calculate primary stats // refresh the character menu if there has been a change for (size_t i = 0; i < primary.size(); ++i) { if (get_primary(i) != primary[i] + effects.bonus_primary[i]) refresh_stats = true; primary_additional[i] = effects.bonus_primary[i]; } calcBase(); for (size_t i=0; i<STAT_COUNT + DAMAGE_TYPES_COUNT; i++) { current[i] = base[i] + effects.bonus[i]; } for (unsigned i=0; i<effects.bonus_resist.size(); i++) { vulnerable[i] = vulnerable_base[i] - effects.bonus_resist[i]; } current[STAT_HP_MAX] += (current[STAT_HP_MAX] * current[STAT_HP_PERCENT]) / 100; current[STAT_MP_MAX] += (current[STAT_MP_MAX] * current[STAT_MP_PERCENT]) / 100; if (hp > get(STAT_HP_MAX)) hp = get(STAT_HP_MAX); if (mp > get(STAT_MP_MAX)) mp = get(STAT_MP_MAX); speed = speed_default; }
bool AP_Compass_PX4::read(void) { // try to accumulate one more sample, so we have the latest data accumulate(); // consider the compass healthy if we got a reading in the last 0.2s for (uint8_t i=0; i<_num_instances; i++) { _healthy[i] = (hal.scheduler->micros64() - _last_timestamp[i] < 200000); } for (uint8_t i=0; i<_num_instances; i++) { // avoid division by zero if we haven't received any mag reports if (_count[i] == 0) continue; _sum[i] /= _count[i]; _sum[i] *= 1000; // apply default board orientation for this compass type. This is // a noop on most boards _sum[i].rotate(MAG_BOARD_ORIENTATION); if (_external[i]) { // add user selectable orientation _sum[i].rotate((enum Rotation)_orientation[i].get()); } else { // add in board orientation from AHRS _sum[i].rotate(_board_orientation); } _field[i] = _sum[i]; apply_corrections(_field[i],i); _sum[i].zero(); _count[i] = 0; } last_update = _last_timestamp[get_primary()]; return _healthy[get_primary()]; }
static int query_screens(void) { int i, count, event_base, error_base; XineramaScreenInfo *screens; RECT rc_work = {0, 0, 0, 0}; if (!monitors) /* first time around */ load_xinerama(); query_work_area( &rc_work ); if (!pXineramaQueryExtension || !pXineramaQueryScreens || !pXineramaQueryExtension( gdi_display, &event_base, &error_base ) || !(screens = pXineramaQueryScreens( gdi_display, &count ))) return 0; if (monitors != &default_monitor) HeapFree( GetProcessHeap(), 0, monitors ); if ((monitors = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*monitors) ))) { int device = 2; /* 1 is reserved for primary */ nb_monitors = count; for (i = 0; i < nb_monitors; i++) { monitors[i].cbSize = sizeof( monitors[i] ); monitors[i].rcMonitor.left = screens[i].x_org; monitors[i].rcMonitor.top = screens[i].y_org; monitors[i].rcMonitor.right = screens[i].x_org + screens[i].width; monitors[i].rcMonitor.bottom = screens[i].y_org + screens[i].height; monitors[i].dwFlags = 0; if (!IntersectRect( &monitors[i].rcWork, &rc_work, &monitors[i].rcMonitor )) monitors[i].rcWork = monitors[i].rcMonitor; } get_primary()->dwFlags |= MONITORINFOF_PRIMARY; for (i = 0; i < nb_monitors; i++) { snprintfW( monitors[i].szDevice, sizeof(monitors[i].szDevice) / sizeof(WCHAR), monitor_deviceW, (monitors[i].dwFlags & MONITORINFOF_PRIMARY) ? 1 : device++ ); } } else count = 0; XFree( screens ); return count; }
bool Compass::start_calibration(uint8_t i, bool retry, bool autosave, float delay) { if (healthy(i)) { if (!is_calibrating() && delay > 0.5f) { AP_Notify::events.initiated_compass_cal = 1; } if (i == get_primary()) { _calibrator[i].set_tolerance(8); } else { _calibrator[i].set_tolerance(16); } _calibrator[i].start(retry, autosave, delay); return true; } else { return false; } }
void xinerama_init( unsigned int width, unsigned int height ) { MONITORINFOEXW *primary; int i; RECT rect; wine_tsx11_lock(); SetRect( &rect, 0, 0, width, height ); if (root_window != DefaultRootWindow( gdi_display ) || !query_screens()) { default_monitor.rcWork = default_monitor.rcMonitor = rect; if (root_window == DefaultRootWindow( gdi_display )) query_work_area( &default_monitor.rcWork ); nb_monitors = 1; monitors = &default_monitor; } primary = get_primary(); /* coordinates (0,0) have to point to the primary monitor origin */ OffsetRect( &rect, -primary->rcMonitor.left, -primary->rcMonitor.top ); for (i = 0; i < nb_monitors; i++) { OffsetRect( &monitors[i].rcMonitor, rect.left, rect.top ); OffsetRect( &monitors[i].rcWork, rect.left, rect.top ); TRACE( "monitor %p: %s work %s%s\n", index_to_monitor(i), wine_dbgstr_rect(&monitors[i].rcMonitor), wine_dbgstr_rect(&monitors[i].rcWork), (monitors[i].dwFlags & MONITORINFOF_PRIMARY) ? " (primary)" : "" ); } virtual_screen_rect = rect; screen_width = primary->rcMonitor.right - primary->rcMonitor.left; screen_height = primary->rcMonitor.bottom - primary->rcMonitor.top; TRACE( "virtual size: %s primary size: %dx%d\n", wine_dbgstr_rect(&rect), screen_width, screen_height ); wine_tsx11_unlock(); }
/** * Recalc derived stats from base stats + effect bonuses */ void StatBlock::applyEffects() { // preserve hp/mp states // max HP and MP can't drop below 1 prev_maxhp = std::max(get(Stats::HP_MAX), 1); prev_maxmp = std::max(get(Stats::MP_MAX), 1); prev_hp = hp; prev_mp = mp; // calculate primary stats // refresh the character menu if there has been a change for (size_t i = 0; i < primary.size(); ++i) { if (get_primary(i) != primary[i] + effects.bonus_primary[i]) refresh_stats = true; primary_additional[i] = effects.bonus_primary[i]; } calcBase(); for (size_t i=0; i<Stats::COUNT + eset->damage_types.count; i++) { current[i] = base[i] + effects.bonus[i]; } for (unsigned i=0; i<effects.bonus_resist.size(); i++) { vulnerable[i] = vulnerable_base[i] - effects.bonus_resist[i]; } current[Stats::HP_MAX] += (current[Stats::HP_MAX] * current[Stats::HP_PERCENT]) / 100; current[Stats::MP_MAX] += (current[Stats::MP_MAX] * current[Stats::MP_PERCENT]) / 100; // max HP and MP can't drop below 1 current[Stats::HP_MAX] = std::max(get(Stats::HP_MAX), 1); current[Stats::MP_MAX] = std::max(get(Stats::MP_MAX), 1); if (hp > get(Stats::HP_MAX)) hp = get(Stats::HP_MAX); if (mp > get(Stats::MP_MAX)) mp = get(Stats::MP_MAX); speed = speed_default; }
bool StatBlock::summonLimitReached(int power_id) const { //find the limit Power *spawn_power = &powers->powers[power_id]; int max_summons = 0; if(spawn_power->spawn_limit_mode == Power::SPAWN_LIMIT_MODE_FIXED) max_summons = spawn_power->spawn_limit_qty; else if(spawn_power->spawn_limit_mode == Power::SPAWN_LIMIT_MODE_STAT) { int stat_val = 1; for (size_t i = 0; i < eset->primary_stats.list.size(); ++i) { if (spawn_power->spawn_limit_stat == i) { stat_val = get_primary(i); break; } } max_summons = (stat_val / (spawn_power->spawn_limit_every == 0 ? 1 : spawn_power->spawn_limit_every)) * spawn_power->spawn_limit_qty; } else return false;//unlimited or unknown mode //if the power is available, there should be at least 1 allowed summon if(max_summons < 1) max_summons = 1; //find out how many there are currently int qty_summons = 0; for (unsigned int i=0; i < summons.size(); i++) { if(!summons[i]->corpse && summons[i]->summoned_power_index == power_id && summons[i]->cur_state != ENEMY_SPAWN && summons[i]->cur_state != ENEMY_DEAD && summons[i]->cur_state != ENEMY_CRITDEAD) { qty_summons++; } } return qty_summons >= max_summons; }
void meta_server_failure_detector::on_ping(const fd::beacon_msg& beacon, ::dsn::rpc_replier<fd::beacon_ack>& reply) { fd::beacon_ack ack; ack.time = beacon.time; ack.this_node = beacon.to; ack.allowed = true; if ( !is_primary() ) { ack.is_master = false; ack.primary_node = get_primary(); } else { ack.is_master = true; ack.primary_node = beacon.to; failure_detector::on_ping_internal(beacon, ack); } dinfo("on_ping, is_master(%s), this_node(%s), primary_node(%s)", ack.is_master?"true":"false", ack.this_node.to_string(), ack.primary_node.to_string()); reply(ack); }
/** * Base damage and absorb is 0 * Plus an optional bonus_per_[base stat] */ void StatBlock::calcBase() { // bonuses are skipped for the default level 1 of a stat int lev0 = std::max(level - 1, 0); for (size_t i = 0; i < STAT_COUNT + DAMAGE_TYPES_COUNT; ++i) { base[i] = starting[i]; base[i] += lev0 * per_level[i]; for (size_t j = 0; j < per_primary.size(); ++j) { base[i] += std::max(get_primary(j) - 1, 0) * per_primary[j][i]; } } // add damage from equipment and increase to minimum amounts // for (size_t i = 0; i < DAMAGE_TYPES_COUNT; ++i) { // size_t dmg_id = i / 2; // // if (i % 2 == 0) { // base[STAT_COUNT + i] += dmg_min_add[dmg_id]; // } // else { // base[STAT_COUNT + i] += dmg_max_add[dmg_id]; // } // } for (size_t i = 0; i < DAMAGE_TYPES.size(); ++i) { base[STAT_COUNT + (i*2)] += dmg_min_add[i]; base[STAT_COUNT + (i*2) + 1] += dmg_max_add[i]; base[STAT_COUNT + (i*2)] = std::max(base[STAT_COUNT + (i*2)], 0); base[STAT_COUNT + (i*2) + 1] = std::max(base[STAT_COUNT + (i*2) + 1], base[STAT_COUNT + (i*2)]); } // add absorb from equipment and increase to minimum amounts base[STAT_ABS_MIN] += absorb_min_add; base[STAT_ABS_MAX] += absorb_max_add; base[STAT_ABS_MIN] = std::max(base[STAT_ABS_MIN], 0); base[STAT_ABS_MAX] = std::max(base[STAT_ABS_MAX], base[STAT_ABS_MIN]); }
/// return true if the compass should be used for yaw calculations bool Compass::use_for_yaw(void) const { uint8_t prim = get_primary(); return healthy(prim) && use_for_yaw(prim); }
RECT get_primary_monitor_rect(void) { return get_primary()->rcMonitor; }
errno_t select_principal_from_keytab(TALLOC_CTX *mem_ctx, const char *hostname, const char *desired_realm, const char *keytab_name, char **_principal, char **_primary, char **_realm) { krb5_error_code kerr = 0; krb5_context krb_ctx = NULL; krb5_keytab keytab = NULL; krb5_principal client_princ = NULL; TALLOC_CTX *tmp_ctx; char *primary = NULL; char *realm = NULL; int i = 0; errno_t ret; char *principal_string; const char *realm_name; int realm_len; /** * The %s conversion is passed as-is, the %S conversion is translated to * "short host name" * * Priority of lookup: * - our.hostname@REALM or host/our.hostname@REALM depending on the input * - SHORT.HOSTNAME$@REALM (AD domain) * - host/our.hostname@REALM * - foobar$@REALM (AD domain) * - host/foobar@REALM * - host/foo@BAR * - pick the first principal in the keytab */ const char *primary_patterns[] = {"%s", "%S$", "host/%s", "*$", "host/*", "host/*", NULL}; const char *realm_patterns[] = {"%s", "%s", "%s", "%s", "%s", NULL, NULL}; DEBUG(5, ("trying to select the most appropriate principal from keytab\n")); tmp_ctx = talloc_new(NULL); if (!tmp_ctx) { DEBUG(1, ("talloc_new failed\n")); return ENOMEM; } kerr = krb5_init_context(&krb_ctx); if (kerr) { DEBUG(2, ("Failed to init kerberos context\n")); ret = EFAULT; goto done; } if (keytab_name != NULL) { kerr = krb5_kt_resolve(krb_ctx, keytab_name, &keytab); } else { kerr = krb5_kt_default(krb_ctx, &keytab); } if (kerr) { DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to read keytab [%s]: %s\n", KEYTAB_CLEAN_NAME, sss_krb5_get_error_message(krb_ctx, kerr))); ret = EFAULT; goto done; } if (!desired_realm) { desired_realm = "*"; } if (!hostname) { hostname = "*"; } do { if (primary_patterns[i]) { primary = get_primary(tmp_ctx, primary_patterns[i], hostname); if (primary == NULL) { ret = ENOMEM; goto done; } } else { primary = NULL; } if (realm_patterns[i]) { realm = talloc_asprintf(tmp_ctx, realm_patterns[i], desired_realm); if (realm == NULL) { ret = ENOMEM; goto done; } } else { realm = NULL; } kerr = find_principal_in_keytab(krb_ctx, keytab, primary, realm, &client_princ); talloc_zfree(primary); talloc_zfree(realm); if (kerr == 0) { break; } if (client_princ != NULL) { krb5_free_principal(krb_ctx, client_princ); client_princ = NULL; } i++; } while(primary_patterns[i-1] != NULL || realm_patterns[i-1] != NULL); if (kerr == 0) { if (_principal) { kerr = krb5_unparse_name(krb_ctx, client_princ, &principal_string); if (kerr) { DEBUG(1, ("krb5_unparse_name failed")); ret = EFAULT; goto done; } *_principal = talloc_strdup(mem_ctx, principal_string); free(principal_string); if (!*_principal) { DEBUG(1, ("talloc_strdup failed")); ret = ENOMEM; goto done; } DEBUG(5, ("Selected principal: %s\n", *_principal)); } if (_primary) { kerr = sss_krb5_unparse_name_flags(krb_ctx, client_princ, KRB5_PRINCIPAL_UNPARSE_NO_REALM, &principal_string); if (kerr) { DEBUG(1, ("krb5_unparse_name failed")); ret = EFAULT; goto done; } *_primary = talloc_strdup(mem_ctx, principal_string); free(principal_string); if (!*_primary) { DEBUG(1, ("talloc_strdup failed")); if (_principal) talloc_zfree(*_principal); ret = ENOMEM; goto done; } DEBUG(5, ("Selected primary: %s\n", *_primary)); } if (_realm) { sss_krb5_princ_realm(krb_ctx, client_princ, &realm_name, &realm_len); *_realm = talloc_asprintf(mem_ctx, "%.*s", realm_len, realm_name); if (!*_realm) { DEBUG(1, ("talloc_asprintf failed")); if (_principal) talloc_zfree(*_principal); if (_primary) talloc_zfree(*_primary); ret = ENOMEM; goto done; } DEBUG(5, ("Selected realm: %s\n", *_realm)); } ret = EOK; } else { DEBUG(3, ("No suitable principal found in keytab\n")); ret = ENOENT; } done: if (keytab) krb5_kt_close(krb_ctx, keytab); if (krb_ctx) krb5_free_context(krb_ctx); if (client_princ != NULL) { krb5_free_principal(krb_ctx, client_princ); client_princ = NULL; } talloc_free(tmp_ctx); return ret; }