QString QTime::toString() const { QString buf; buf.sprintf( "%.2d:%.2d:%.2d", hour(), minute(), second() ); return buf; }
void android::widget::CompoundButton::onCheckedChanged(int id,jobject sender,bool checked){ auto it=onCheckedMap.find(id); if(it != onCheckedMap.end()){ it->second(sender,checked); } }
static uintptr_t * apdns_getFQDN_MX_1 (Region rAddrLPairs, Region rAddrEPairs, Region rAddrString, char *str, uintptr_t *list, int depth, request_data *rd) { if (depth < 0) return list; // i,j are used as loop counters // the dnspackage returned from the resolver is scanned from top to buttom // next is the package pointer relative to the start of the package int j, next; char ans[NS_PACKETSZ + 1]; char dnsnamesa[NS_MAXDNAME]; char *dnsnames = dnsnamesa; char *input = str; uintptr_t *pair, *listpair; String rs; dnshead *head = (dnshead *) ans; // get the dns package int n = res_search (input, C_IN, T_MX, (unsigned char *) ans, NS_PACKETSZ + 1); input = 0; if (n == -1) return list; if (n < sizeof (dnshead)) return list; ntohhead (ans, head); if ((head->flags & 0xF) != 0) return list; if (head->anscount < 1) return list; // skip questions next = NS_HFIXEDSZ; for (j = 0; j < head->questcount; j++) { next = skipname (ans, next, n); next = iflessthan (next + 4, n); if (next < 0) return list; } // The answers int rv; for (j = 0; j < head->anscount; j++) { // int a_name = next; if (next >= n) return list; next = skipname (ans, next, n); if (next + NS_RRFIXEDSZ >= n || next < 0) return list; uint16_t a_type = twocharto16 (ans[next], ans[next + 1]); next += 4; uint32_t a_ttl = fourcharto32 (ans[next], ans[next + 1], ans[next + 2], ans[next + 3]); next += 4; uint16_t a_rdlength = twocharto16 (ans[next], ans[next + 1]); next += 2; if (a_type == T_MX) { // We got a mx record if (next + a_rdlength >= n || a_rdlength < 3) return list; uint16_t a_mx_pref = twocharto16 (ans[next], ans[next + 1]); rv = dumpname (dnsnames, NS_MAXDNAME, ans, next + 2, n); rs = convertStringToML (rAddrString, dnsnames); allocRecordML (rAddrEPairs, 3, pair); elemRecordML (pair, 0) = (uintptr_t) a_mx_pref; elemRecordML (pair, 1) = (uintptr_t) a_ttl; elemRecordML (pair, 2) = (uintptr_t) rs; allocRecordML (rAddrLPairs, 2, listpair); first (listpair) = (uintptr_t) pair; second (listpair) = (uintptr_t) list; makeCONS (listpair, list); ap_log_error (APLOG_MARK, LOG_DEBUG, 0, rd->server, "apdns_getFQDN_MX: pref %i, ttl %i, %s", a_mx_pref, a_ttl, dnsnames); } else if (a_type == T_CNAME) { // we got an alias (cononical name) rv = dumpname (dnsnames, NS_MAXDNAME, ans, next, n); input = dnsnames; break; } else { // we got something we did not ask for // or cannot handle at the momnet return list; } next += a_rdlength; } if (input) return apdns_getFQDN_MX_1 (rAddrLPairs, rAddrEPairs, rAddrString, input, list, depth - 1, rd); return list; }
State::Ptr StateStack::createState(States::ID stateID) { auto found = mFactories.find(stateID); assert(found!=mFactories.end()); return found->second(); }
CAxisRotation CAxisRotation::MergeInside(const CAxisRotation & oRot) const{ CLog oLog("math","CAxisRotation::MergeInside"); CQuaternion first(*this); CQuaternion second(oRot); return CAxisRotation(first * second); }
/*! This function computes the local density for each active SPH particle, * the number of neighbours in the current smoothing radius, and the * divergence and curl of the velocity field. The pressure is updated as * well. If a particle with its smoothing region is fully inside the * local domain, it is not exported to the other processors. The function * also detects particles that have a number of neighbours outside the * allowed tolerance range. For these particles, the smoothing length is * adjusted accordingly, and the density computation is executed again. * Note that the smoothing length is not allowed to fall below the lower * bound set by MinGasHsml. */ void density(void) { long long ntot, ntotleft; int *noffset, *nbuffer, *nsend, *nsend_local, *numlist, *ndonelist; int i, j, n, ndone, npleft, maxfill, source, iter = 0; int level, ngrp, sendTask, recvTask, place, nexport; double dt_entr, tstart, tend, tstart_ngb = 0, tend_ngb = 0; double sumt, sumcomm, timengb, sumtimengb; double timecomp = 0, timeimbalance = 0, timecommsumm = 0, sumimbalance; MPI_Status status; double a3; #ifdef METALS_TG int metal_disperse; long long ntotsave; double a, hubble_param, hubble_a, dt, exp_func, old_met, old_met_tot, new_met, new_met_tot, M_metals_local, M_metals_tot; if(All.ComovingIntegrationOn) { a = All.Time; hubble_param = All.HubbleParam; hubble_a = All.Omega0 / (All.Time * All.Time * All.Time) + (1 - All.Omega0 - All.OmegaLambda) / (All.Time * All.Time) + All.OmegaLambda; hubble_a = All.Hubble * sqrt(hubble_a); } else a = hubble_a = hubble_param = 1.0; #endif if(All.ComovingIntegrationOn) { a3 = All.Time * All.Time * All.Time; } else a3 = 1.0; #ifdef PERIODIC boxSize = All.BoxSize; boxHalf = 0.5 * All.BoxSize; #ifdef LONG_X boxHalf_X = boxHalf * LONG_X; boxSize_X = boxSize * LONG_X; #endif #ifdef LONG_Y boxHalf_Y = boxHalf * LONG_Y; boxSize_Y = boxSize * LONG_Y; #endif #ifdef LONG_Z boxHalf_Z = boxHalf * LONG_Z; boxSize_Z = boxSize * LONG_Z; #endif #endif noffset = malloc(sizeof(int) * NTask); /* offsets of bunches in common list */ nbuffer = malloc(sizeof(int) * NTask); nsend_local = malloc(sizeof(int) * NTask); nsend = malloc(sizeof(int) * NTask * NTask); ndonelist = malloc(sizeof(int) * NTask); for(n = 0, NumSphUpdate = 0; n < N_gas; n++) { if(P[n].ID < 0 || SphP[n].sink > 0.5) /*SINK*/ continue; SphP[n].Left = SphP[n].Right = 0; if(P[n].Ti_endstep == All.Ti_Current) NumSphUpdate++; } numlist = malloc(NTask * sizeof(int) * NTask); MPI_Allgather(&NumSphUpdate, 1, MPI_INT, numlist, 1, MPI_INT, MPI_COMM_WORLD); for(i = 0, ntot = 0; i < NTask; i++) ntot += numlist[i]; free(numlist); #ifdef METALS_TG ntotsave = ntot; M_metals_tot = M_metals_local = 0.0; for(metal_disperse = 0; metal_disperse < 2; metal_disperse++) { ntot = ntotsave; #endif /* we will repeat the whole thing for those particles where we didn't * find enough neighbours */ do { i = 0; /* begin with this index */ ntotleft = ntot; /* particles left for all tasks together */ while(ntotleft > 0) { for(j = 0; j < NTask; j++) nsend_local[j] = 0; /* do local particles and prepare export list */ tstart = second(); for(nexport = 0, ndone = 0; i < N_gas && nexport < All.BunchSizeDensity - NTask; i++) { if(P[i].ID < 0 || SphP[i].sink > 0.5) /*SINK*/ continue; if(P[i].Ti_endstep == All.Ti_Current) { ndone++; for(j = 0; j < NTask; j++) Exportflag[j] = 0; #ifdef METALS_TG density_evaluate(i, 0, metal_disperse); #else density_evaluate(i, 0); #endif for(j = 0; j < NTask; j++) { if(Exportflag[j]) { DensDataIn[nexport].Pos[0] = P[i].Pos[0]; DensDataIn[nexport].Pos[1] = P[i].Pos[1]; DensDataIn[nexport].Pos[2] = P[i].Pos[2]; DensDataIn[nexport].Vel[0] = SphP[i].VelPred[0]; DensDataIn[nexport].Vel[1] = SphP[i].VelPred[1]; DensDataIn[nexport].Vel[2] = SphP[i].VelPred[2]; DensDataIn[nexport].bfield[0] = SphP[i].bfield[0]; DensDataIn[nexport].bfield[1] = SphP[i].bfield[1]; DensDataIn[nexport].bfield[2] = SphP[i].bfield[2]; DensDataIn[nexport].Hsml = SphP[i].Hsml; DensDataIn[nexport].Sci = SphP[i].Sci; #ifdef METALS_TG DensDataIn[nexport].Sigma = SphP[i].Sigma; #endif DensDataIn[nexport].Index = i; DensDataIn[nexport].Task = j; nexport++; nsend_local[j]++; } } } } tend = second(); timecomp += timediff(tstart, tend); qsort(DensDataIn, nexport, sizeof(struct densdata_in), dens_compare_key); for(j = 1, noffset[0] = 0; j < NTask; j++) noffset[j] = noffset[j - 1] + nsend_local[j - 1]; tstart = second(); MPI_Allgather(nsend_local, NTask, MPI_INT, nsend, NTask, MPI_INT, MPI_COMM_WORLD); tend = second(); timeimbalance += timediff(tstart, tend); /* now do the particles that need to be exported */ for(level = 1; level < (1 << PTask); level++) { tstart = second(); for(j = 0; j < NTask; j++) nbuffer[j] = 0; for(ngrp = level; ngrp < (1 << PTask); ngrp++) { maxfill = 0; for(j = 0; j < NTask; j++) { if((j ^ ngrp) < NTask) if(maxfill < nbuffer[j] + nsend[(j ^ ngrp) * NTask + j]) maxfill = nbuffer[j] + nsend[(j ^ ngrp) * NTask + j]; } if(maxfill >= All.BunchSizeDensity) break; sendTask = ThisTask; recvTask = ThisTask ^ ngrp; if(recvTask < NTask) { if(nsend[ThisTask * NTask + recvTask] > 0 || nsend[recvTask * NTask + ThisTask] > 0) { /* get the particles */ MPI_Sendrecv(&DensDataIn[noffset[recvTask]], nsend_local[recvTask] * sizeof(struct densdata_in), MPI_BYTE, recvTask, TAG_DENS_A, &DensDataGet[nbuffer[ThisTask]], nsend[recvTask * NTask + ThisTask] * sizeof(struct densdata_in), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, &status); } } for(j = 0; j < NTask; j++) if((j ^ ngrp) < NTask) nbuffer[j] += nsend[(j ^ ngrp) * NTask + j]; } tend = second(); timecommsumm += timediff(tstart, tend); tstart = second(); for(j = 0; j < nbuffer[ThisTask]; j++) #ifdef METALS_TG density_evaluate(j, 1, metal_disperse); #else density_evaluate(j, 1); #endif tend = second(); timecomp += timediff(tstart, tend); /* do a block to explicitly measure imbalance */ tstart = second(); MPI_Barrier(MPI_COMM_WORLD); tend = second(); timeimbalance += timediff(tstart, tend); /* get the result */ tstart = second(); for(j = 0; j < NTask; j++) nbuffer[j] = 0; for(ngrp = level; ngrp < (1 << PTask); ngrp++) { maxfill = 0; for(j = 0; j < NTask; j++) { if((j ^ ngrp) < NTask) if(maxfill < nbuffer[j] + nsend[(j ^ ngrp) * NTask + j]) maxfill = nbuffer[j] + nsend[(j ^ ngrp) * NTask + j]; } if(maxfill >= All.BunchSizeDensity) break; sendTask = ThisTask; recvTask = ThisTask ^ ngrp; if(recvTask < NTask) { if(nsend[ThisTask * NTask + recvTask] > 0 || nsend[recvTask * NTask + ThisTask] > 0) { /* send the results */ MPI_Sendrecv(&DensDataResult[nbuffer[ThisTask]], nsend[recvTask * NTask + ThisTask] * sizeof(struct densdata_out), MPI_BYTE, recvTask, TAG_DENS_B, &DensDataPartialResult[noffset[recvTask]], nsend_local[recvTask] * sizeof(struct densdata_out), MPI_BYTE, recvTask, TAG_DENS_B, MPI_COMM_WORLD, &status); /* add the result to the particles */ for(j = 0; j < nsend_local[recvTask]; j++) { source = j + noffset[recvTask]; place = DensDataIn[source].Index; #ifdef METALS_TG if(metal_disperse == 1) { SphP[place].const_A += DensDataPartialResult[source].const_A; SphP[place].const_B += DensDataPartialResult[source].const_B; } else { #endif SphP[place].NumNgb += DensDataPartialResult[source].Ngb; SphP[place].Density += DensDataPartialResult[source].Rho; SphP[place].DivVel += DensDataPartialResult[source].Div; SphP[place].DivB += DensDataPartialResult[source].Div_B; SphP[place].DhsmlDensityFactor += DensDataPartialResult[source].DhsmlDensity; SphP[place].Rot[0] += DensDataPartialResult[source].Rot[0]; SphP[place].Rot[1] += DensDataPartialResult[source].Rot[1]; SphP[place].Rot[2] += DensDataPartialResult[source].Rot[2]; SphP[place].GradSci[0] += DensDataPartialResult[source].GSci[0]; SphP[place].GradSci[1] += DensDataPartialResult[source].GSci[1]; SphP[place].GradSci[2] += DensDataPartialResult[source].GSci[2]; SphP[place].VelRel[0] += DensDataPartialResult[source].VRel[0]; SphP[place].VelRel[1] += DensDataPartialResult[source].VRel[1]; SphP[place].VelRel[2] += DensDataPartialResult[source].VRel[2]; #ifdef METALS_TG SphP[place].Sigma += DensDataPartialResult[source].Sigma; } #endif } } } for(j = 0; j < NTask; j++) if((j ^ ngrp) < NTask) nbuffer[j] += nsend[(j ^ ngrp) * NTask + j]; } tend = second(); timecommsumm += timediff(tstart, tend); level = ngrp - 1; } MPI_Allgather(&ndone, 1, MPI_INT, ndonelist, 1, MPI_INT, MPI_COMM_WORLD); for(j = 0; j < NTask; j++) ntotleft -= ndonelist[j]; } /* do final operations on results */ tstart = second(); #ifdef METALS_TG if(metal_disperse == 0) { #endif for(i = 0, npleft = 0; i < N_gas; i++) { if(P[i].ID < 0 || SphP[i].sink > 0.5) /*SINK*/ continue; if(P[i].Ti_endstep == All.Ti_Current) { { SphP[i].DhsmlDensityFactor = 1.0 / (1.0 + SphP[i].Hsml * SphP[i].DhsmlDensityFactor / ((double)(NUMDIMS) * SphP[i].Density)); SphP[i].CurlVel = sqrt(SphP[i].Rot[0] * SphP[i].Rot[0] + SphP[i].Rot[1] * SphP[i].Rot[1] + SphP[i].Rot[2] * SphP[i].Rot[2]) / SphP[i].Density; SphP[i].DivVel /= SphP[i].Density; SphP[i].DivB /= SphP[i].Density; SphP[i].GradSci[0] /= SphP[i].Density; SphP[i].GradSci[1] /= SphP[i].Density; SphP[i].GradSci[2] /= SphP[i].Density; SphP[i].VelRel[0] /= SphP[i].Density; SphP[i].VelRel[1] /= SphP[i].Density; SphP[i].VelRel[2] /= SphP[i].Density; #ifdef POLYTROPE SphP[i].Pressure = get_pressure(SphP[i].Density); #else /* POLYTROPE */ dt_entr = (double)((All.Ti_Current - (P[i].Ti_begstep + P[i].Ti_endstep) / 2.0)) * All.Timebase_interval; #ifdef CHEMCOOL SphP[i].Pressure = (SphP[i].Entropy + SphP[i].DtEntropy * dt_entr) * pow(SphP[i].Density, SphP[i].Gamma); #else /* CHEMCOOL */ SphP[i].Pressure = (SphP[i].Entropy + SphP[i].DtEntropy * dt_entr) * pow(SphP[i].Density, GAMMA); #endif /* CHEMCOOL */ #endif /* POLYTROPE */ } /* now check whether we had enough neighbours */ if(SphP[i].NumNgb < (All.DesNumNgb - All.MaxNumNgbDeviation) || (SphP[i].NumNgb > (All.DesNumNgb + All.MaxNumNgbDeviation) && SphP[i].Hsml > (1.01 * All.MinGasHsml))) { /* need to redo this particle */ npleft++; if(SphP[i].Left > 0 && SphP[i].Right > 0) if((SphP[i].Right - SphP[i].Left) < 1.0e-3 * SphP[i].Left) { /* this one should be ok */ npleft--; P[i].Ti_endstep = -P[i].Ti_endstep - 1; /* Mark as inactive */ continue; } if(SphP[i].NumNgb < (All.DesNumNgb - All.MaxNumNgbDeviation)) SphP[i].Left = dmax(SphP[i].Hsml, SphP[i].Left); else { if(SphP[i].Right != 0) { if(SphP[i].Hsml < SphP[i].Right) SphP[i].Right = SphP[i].Hsml; } else SphP[i].Right = SphP[i].Hsml; } if(iter >= MAXITER - 10) { printf ("i=%d task=%d ID=%d Hsml=%g Left=%g Right=%g Ngbs=%g Right-Left=%g\n pos=(%g|%g|%g)\n", i, ThisTask, (int) P[i].ID, SphP[i].Hsml, SphP[i].Left, SphP[i].Right, (float) SphP[i].NumNgb, SphP[i].Right - SphP[i].Left, P[i].Pos[0], P[i].Pos[1], P[i].Pos[2]); fflush(stdout); } if(SphP[i].Right > 0 && SphP[i].Left > 0) SphP[i].Hsml = pow(0.5 * (pow(SphP[i].Left, 3) + pow(SphP[i].Right, 3)), 1.0 / 3.0); else { if(SphP[i].Right == 0 && SphP[i].Left == 0) endrun(8188); /* can't occur */ if(SphP[i].Right == 0 && SphP[i].Left > 0) { if(P[i].Type == 0 && fabs(SphP[i].NumNgb - All.DesNumNgb) < 0.5 * All.DesNumNgb) { SphP[i].Hsml *= 1.0 - (SphP[i].NumNgb - All.DesNumNgb) / ((double)(NUMDIMS) * SphP[i].NumNgb) * SphP[i].DhsmlDensityFactor; } else SphP[i].Hsml *= 1.26; } if(SphP[i].Right > 0 && SphP[i].Left == 0) { if(P[i].Type == 0 && fabs(SphP[i].NumNgb - All.DesNumNgb) < 0.5 * All.DesNumNgb) { SphP[i].Hsml *= 1.0 - (SphP[i].NumNgb - All.DesNumNgb) / ((double)(NUMDIMS) * SphP[i].NumNgb) * SphP[i].DhsmlDensityFactor; } else SphP[i].Hsml /= 1.26; } } if(SphP[i].Hsml < All.MinGasHsml) SphP[i].Hsml = All.MinGasHsml; } else P[i].Ti_endstep = -P[i].Ti_endstep - 1; /* Mark as inactive */ } } #ifdef METALS_TG } else { ntot = 0; } #endif tend = second(); timecomp += timediff(tstart, tend); #ifdef METALS_TG if(metal_disperse == 0) { #endif numlist = malloc(NTask * sizeof(int) * NTask); MPI_Allgather(&npleft, 1, MPI_INT, numlist, 1, MPI_INT, MPI_COMM_WORLD); for(i = 0, ntot = 0; i < NTask; i++) ntot += numlist[i]; free(numlist); if(ntot > 0) { if(iter == 0) tstart_ngb = second(); iter++; if(iter > 0 && ThisTask == 0) { printf("ngb iteration %d: need to repeat for %d%09d particles.\n", iter, (int) (ntot / 1000000000), (int) (ntot % 1000000000)); fflush(stdout); } if(iter > MAXITER) { printf("failed to converge in neighbour iteration in density()\n"); fflush(stdout); endrun(1155); } } else tend_ngb = second(); #ifdef METALS_TG } #endif } while(ntot > 0); /* mark as active again */ for(i = 0; i < NumPart; i++) { if(P[i].Type == 0 && P[i].ID < 0) /*ACCRETED*/ continue; if(P[i].Ti_endstep < 0) P[i].Ti_endstep = -P[i].Ti_endstep - 1; } #ifdef METALS_TG if(metal_disperse == 0) { for(n = 0; n < N_gas; n++) { if(P[n].ID < 0 || SphP[n].sink > 0.5) /*SINK*/ continue; if(P[n].Ti_endstep == All.Ti_Current) { SphP[n].Sigma = sqrt(a*SphP[n].Sigma/SphP[n].NumNgb); } } } } old_met = old_met_tot = new_met = new_met_tot = 0.0; for(n = 0; n < N_gas; n++) { if(P[n].ID < 0 || SphP[n].sink > 0.5) /*SINK*/ continue; if(P[n].Ti_endstep == All.Ti_Current) { dt = (All.Ti_Current-P[n].Ti_begstep)*All.Timebase_interval/hubble_a; old_met += SphP[n].Metallicity*P[n].Mass; exp_func = exp(-SphP[n].const_A*dt); SphP[n].Metallicity *= exp_func; SphP[n].Metallicity += SphP[n].const_B/SphP[n].const_A*(1.0-exp_func); new_met += SphP[n].Metallicity*P[n].Mass; } } MPI_Allreduce(&old_met, &old_met_tot, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); MPI_Allreduce(&new_met, &new_met_tot, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); for(n = 0; n < N_gas; n++) { if(P[n].ID < 0 || SphP[n].sink > 0.5) /*SINK*/ continue; if(P[n].Ti_endstep == All.Ti_Current && new_met_tot > 0.0) { SphP[n].Metallicity *= old_met_tot/new_met_tot; } M_metals_local += SphP[n].Metallicity*P[n].Mass; } MPI_Allreduce(&M_metals_local, &M_metals_tot, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); if(ThisTask == 0) printf("Metal mass = %g\n", M_metals_tot*All.UnitMass_in_g/SOLAR_MASS*Z_SOLAR/hubble_param); #endif free(ndonelist); free(nsend); free(nsend_local); free(nbuffer); free(noffset); /* collect some timing information */ if(iter > 0) timengb = timediff(tstart_ngb, tend_ngb); else timengb = 0; MPI_Reduce(&timengb, &sumtimengb, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Reduce(&timecomp, &sumt, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Reduce(&timecommsumm, &sumcomm, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Reduce(&timeimbalance, &sumimbalance, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); if(ThisTask == 0) { All.CPU_HydCompWalk += sumt / NTask; All.CPU_HydCommSumm += sumcomm / NTask; All.CPU_HydImbalance += sumimbalance / NTask; All.CPU_EnsureNgb += sumtimengb / NTask; } }
int second() { return second(now()); }
/* current seconds */ int TimeClass::second() { return second(now()); }
/*! This routine does the test of the gravitational tree force by computing * the force for a random subset of particles with direct summation. */ void gravity_forcetest(void) { int ntot, iter = 0, ntotleft, nthis; double tstart, tend, timetree = 0; int i, j, ndone, ngrp, maxfill, place, ndonetot; #ifndef NOGRAVITY int *noffset, *nbuffer, *nsend, *nsend_local; int k, nexport; int level, sendTask, recvTask; double fac1; #ifndef NOMPI MPI_Status status; #endif #endif double costtotal, *costtreelist; double maxt, sumt, *timetreelist; double fac; char buf[200]; #ifdef PMGRID if(All.PM_Ti_endstep != All.Ti_Current) return; #endif if(All.ComovingIntegrationOn) set_softenings(); /* set new softening lengths */ for(i = 0, NumForceUpdate = 0; i < NumPart; i++) { if(P[i].Ti_endstep == All.Ti_Current) { if(get_random_number(P[i].ID) < FORCETEST) { P[i].Ti_endstep = -P[i].Ti_endstep - 1; NumForceUpdate++; } } } /* NumForceUpdate is the number of particles on this processor that want a force update */ #ifndef NOMPI MPI_Allreduce(&NumForceUpdate, &ntot, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); #else ntot = NumForceUpdate; #endif costtotal = 0; noffset = malloc(sizeof(int) * NTask); /* offsets of bunches in common list */ nbuffer = malloc(sizeof(int) * NTask); nsend_local = malloc(sizeof(int) * NTask); nsend = malloc(sizeof(int) * NTask * NTask); i = 0; /* beginn with this index */ ntotleft = ntot; /* particles left for all tasks together */ while(ntotleft > 0) { iter++; for(j = 0; j < NTask; j++) nsend_local[j] = 0; /* do local particles and prepare export list */ tstart = second(); for(nexport = 0, ndone = 0; i < NumPart && nexport < All.BunchSizeForce - NTask; i++) if(P[i].Ti_endstep < 0) { ndone++; for(j = 0; j < NTask; j++) Exportflag[j] = 1; Exportflag[ThisTask] = 0; costtotal += force_treeevaluate_direct(i, 0); for(j = 0; j < NTask; j++) { if(Exportflag[j]) { for(k = 0; k < 3; k++) GravDataGet[nexport].u.Pos[k] = P[i].Pos[k]; #ifdef UNEQUALSOFTENINGS GravDataGet[nexport].Type = P[i].Type; #endif GravDataGet[nexport].w.OldAcc = P[i].OldAcc; GravDataIndexTable[nexport].Task = j; GravDataIndexTable[nexport].Index = i; GravDataIndexTable[nexport].SortIndex = nexport; nexport++; nsend_local[j]++; } } } tend = second(); timetree += timediff(tstart, tend); qsort(GravDataIndexTable, nexport, sizeof(struct gravdata_index), grav_tree_compare_key); for(j = 0; j < nexport; j++) GravDataIn[j] = GravDataGet[GravDataIndexTable[j].SortIndex]; for(j = 1, noffset[0] = 0; j < NTask; j++) noffset[j] = noffset[j - 1] + nsend_local[j - 1]; #ifndef NOMPI MPI_Allgather(nsend_local, NTask, MPI_INT, nsend, NTask, MPI_INT, MPI_COMM_WORLD); #else nsend[0] = nsend_local[i]; #endif /* now do the particles that need to be exported */ for(level = 1; level < (1 << PTask); level++) { for(j = 0; j < NTask; j++) nbuffer[j] = 0; for(ngrp = level; ngrp < (1 << PTask); ngrp++) { maxfill = 0; for(j = 0; j < NTask; j++) { if((j ^ ngrp) < NTask) if(maxfill < nbuffer[j] + nsend[(j ^ ngrp) * NTask + j]) maxfill = nbuffer[j] + nsend[(j ^ ngrp) * NTask + j]; } if(maxfill >= All.BunchSizeForce) break; sendTask = ThisTask; recvTask = ThisTask ^ ngrp; if(recvTask < NTask) { if(nsend[ThisTask * NTask + recvTask] > 0 || nsend[recvTask * NTask + ThisTask] > 0) { /* get the particles */ MPI_Sendrecv(&GravDataIn[noffset[recvTask]], nsend_local[recvTask] * sizeof(struct gravdata_in), MPI_BYTE, recvTask, TAG_DIRECT_A, &GravDataGet[nbuffer[ThisTask]], nsend[recvTask * NTask + ThisTask] * sizeof(struct gravdata_in), MPI_BYTE, recvTask, TAG_DIRECT_A, MPI_COMM_WORLD, &status); } } for(j = 0; j < NTask; j++) if((j ^ ngrp) < NTask) nbuffer[j] += nsend[(j ^ ngrp) * NTask + j]; } tstart = second(); for(j = 0; j < nbuffer[ThisTask]; j++) { costtotal += force_treeevaluate_direct(j, 1); } tend = second(); timetree += timediff(tstart, tend); /* get the result */ for(j = 0; j < NTask; j++) nbuffer[j] = 0; for(ngrp = level; ngrp < (1 << PTask); ngrp++) { maxfill = 0; for(j = 0; j < NTask; j++) { if((j ^ ngrp) < NTask) if(maxfill < nbuffer[j] + nsend[(j ^ ngrp) * NTask + j]) maxfill = nbuffer[j] + nsend[(j ^ ngrp) * NTask + j]; } if(maxfill >= All.BunchSizeForce) break; sendTask = ThisTask; recvTask = ThisTask ^ ngrp; if(recvTask < NTask) { if(nsend[ThisTask * NTask + recvTask] > 0 || nsend[recvTask * NTask + ThisTask] > 0) { /* send the results */ MPI_Sendrecv(&GravDataResult[nbuffer[ThisTask]], nsend[recvTask * NTask + ThisTask] * sizeof(struct gravdata_in), MPI_BYTE, recvTask, TAG_DIRECT_B, &GravDataOut[noffset[recvTask]], nsend_local[recvTask] * sizeof(struct gravdata_in), MPI_BYTE, recvTask, TAG_DIRECT_B, MPI_COMM_WORLD, &status); /* add the result to the particles */ for(j = 0; j < nsend_local[recvTask]; j++) { place = GravDataIndexTable[noffset[recvTask] + j].Index; for(k = 0; k < 3; k++) P[place].GravAccelDirect[k] += GravDataOut[j + noffset[recvTask]].u.Acc[k]; } } } for(j = 0; j < NTask; j++) if((j ^ ngrp) < NTask) nbuffer[j] += nsend[(j ^ ngrp) * NTask + j]; } level = ngrp - 1; } MPI_Allreduce(&ndone, &ndonetot, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); ntotleft -= ndonetot; } free(nsend); free(nsend_local); free(nbuffer); free(noffset); /* now add things for comoving integration */ if(All.ComovingIntegrationOn) { #ifndef PERIODIC fac1 = 0.5 * All.Hubble * All.Hubble * All.Omega0 / All.G; for(i = 0; i < NumPart; i++) if(P[i].Ti_endstep < 0) for(j = 0; j < 3; j++) P[i].GravAccelDirect[j] += fac1 * P[i].Pos[j]; #endif } /* muliply by G */ for(i = 0; i < NumPart; i++) if(P[i].Ti_endstep < 0) for(j = 0; j < 3; j++) P[i].GravAccelDirect[j] *= All.G; /* Finally, the following factor allows a computation of cosmological simulation with vacuum energy in physical coordinates */ if(All.ComovingIntegrationOn == 0) { fac1 = All.OmegaLambda * All.Hubble * All.Hubble; for(i = 0; i < NumPart; i++) if(P[i].Ti_endstep < 0) for(j = 0; j < 3; j++) P[i].GravAccelDirect[j] += fac1 * P[i].Pos[j]; } /* now output the forces to a file */ for(nthis = 0; nthis < NTask; nthis++) { if(nthis == ThisTask) { sprintf(buf, "%s%s", All.OutputDir, "forcetest.txt"); if(!(FdForceTest = fopen(buf, "a"))) { printf("error in opening file '%s'\n", buf); endrun(17); } for(i = 0; i < NumPart; i++) if(P[i].Ti_endstep < 0) { #ifndef PMGRID fprintf(FdForceTest, "%d %g %g %g %g %g %g %g %g %g %g %g\n", P[i].Type, All.Time, All.Time - TimeOfLastTreeConstruction, P[i].Pos[0], P[i].Pos[1], P[i].Pos[2], P[i].GravAccelDirect[0], P[i].GravAccelDirect[1], P[i].GravAccelDirect[2], P[i].GravAccel[0], P[i].GravAccel[1], P[i].GravAccel[2]); #else fprintf(FdForceTest, "%d %g %g %g %g %g %g %g %g %g %g %g %g %g %g\n", P[i].Type, All.Time, All.Time - TimeOfLastTreeConstruction, P[i].Pos[0], P[i].Pos[1], P[i].Pos[2], P[i].GravAccelDirect[0], P[i].GravAccelDirect[1], P[i].GravAccelDirect[2], P[i].GravAccel[0], P[i].GravAccel[1], P[i].GravAccel[2], P[i].GravPM[0] + P[i].GravAccel[0], P[i].GravPM[1] + P[i].GravAccel[1], P[i].GravPM[2] + P[i].GravAccel[2]); #endif } fclose(FdForceTest); } #ifndef NOMPI MPI_Barrier(MPI_COMM_WORLD); #endif } for(i = 0; i < NumPart; i++) if(P[i].Ti_endstep < 0) P[i].Ti_endstep = -P[i].Ti_endstep - 1; /* Now the force computation is finished */ timetreelist = malloc(sizeof(double) * NTask); costtreelist = malloc(sizeof(double) * NTask); MPI_Gather(&costtotal, 1, MPI_DOUBLE, costtreelist, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Gather(&timetree, 1, MPI_DOUBLE, timetreelist, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); if(ThisTask == 0) { fac = NTask / ((double) All.TotNumPart); for(i = 0, maxt = timetreelist[0], sumt = 0, costtotal = 0; i < NTask; i++) { costtotal += costtreelist[i]; if(maxt < timetreelist[i]) maxt = timetreelist[i]; sumt += timetreelist[i]; } fprintf(FdTimings, "DIRECT Nf= %d part/sec=%g | %g ia/part=%g \n", ntot, ntot / (sumt + 1.0e-20), ntot / (maxt * NTask), ((double) (costtotal)) / ntot); fprintf(FdTimings, "\n"); fflush(FdTimings); } free(costtreelist); free(timetreelist); }
// рисует интерфейс для игрока void CCamera::DrawInterface(void) { int step; if (type==CT_ALLSCREEN || type==CT_UP || type==CT_DOWN) { //самый красивый и полный интерфейс //return; step=50; } else step=10; //интерфейс в четверть экрана //черный "квадрат" //CL_Display::fill_rect(CL_Rect(x,y,w,15),CL_Color::black); int tx=step/2; int ty=h-5+y; ShadowFont(x+tx,y+5,pl->name,origin_top_left); for (int i=0;i<6;i++) { if (pl->features.all[i]) ficons[i]->draw(x+tx+i*32,y+35); } //жизни tx+=fnt_interface->get_width(CL_String::from_int(999)); ShadowFont(x+tx,ty,CL_String::from_int(pl->life),origin_bottom_right); spr_health->draw(x+tx,ty-30); //CL_Display::fill_rect(CL_Rect(x+tx,ty-30,x+tx+30,ty),CL_Color::red); tx+=step+20; //патроны tx+=fnt_interface->get_width(CL_String::from_int(999)); if (!pl->no_weapon) { ShadowFont(x+tx,ty,CL_String::from_int(pl->weapons[pl->cur_weapon]->GetBullets()),origin_bottom_right); wicons[pl->cur_weapon]->draw(x+tx,ty-30); } tx+=step+20; /*len=fnt_interface->get_width(CL_String::from_int(pl->life)); int len2=fnt_interface->get_width(CL_String::from_int(pl->armor)); int step=(right-left-len-len2)/3;*/ //броня tx+=fnt_interface->get_width(CL_String::from_int(999)); if (pl->armor) { ShadowFont(x+tx,ty,CL_String::from_int(pl->armor),origin_bottom_right); spr_armor->draw(x+tx,ty-30); } //CL_Display::fill_rect(CL_Rect(x+tx,ty-30,x+tx+30,ty),CL_Color::yellow); //фраги int frlim, tlim; pl->game->GetLimits(frlim, tlim); int frw=50; int frh=30; int left=w-step-frw*3; ty=y+h-frh-5; //CL_Display::fill_rect(CL_Rect(x+left,ty,x+left+frw,ty+25),CL_Color::white); CL_Rect first(x+left,ty,x+left+frw,ty+frh); CL_Rect second(x+left+frw,ty,x+left+frw*2,ty+frh); CL_Rect third(x+left+frw*2,ty,x+left+frw*3,ty+frh); CL_Display::fill_rect(second,CL_Color::darkblue); CL_Display::fill_rect(third,CL_Color::darkred); if (frlim) { CL_Display::draw_rect(first,CL_Color::white); ShadowFont(first,CL_String::from_int(frlim)); } CL_Display::draw_rect(second,CL_Color::white); CL_Display::draw_rect(third,CL_Color::white); int gt=pl->game->GetGameType(); if (gt==BGA_GAME_DEATHMATCH)//фраги гамера { ShadowFont(second,CL_String::from_int(pl->frags)); ShadowFont(third,CL_String::from_int(pl->game->GetMaxEnemyFrags(pl->id))); } if (gt==BGA_GAME_TEAMDEATHMATCH || gt==BGA_GAME_CAPTURETHEFLAG)//фраги/флаги команды { ShadowFont(second,CL_String::from_int(pl->game->GetBlueScore())); ShadowFont(third,CL_String::from_int(pl->game->GetRedScore())); } //лимит времени if (tlim) { ShadowFont(x+w/2,y+5,CL_String::from_int(pl->game->GetRemainTime())+" мин.",origin_top_center); } //прицел int ax=pl->cr_target.x+x-dx; int ay=pl->cr_target.y+y-dy; //CL_Display::draw_line(ax,ay-20,ax,ay+20,CL_Color::lightgreen); //CL_Display::draw_line(ax-20,ay,ax+20,ay,CL_Color::lightgreen); if (!pl->aimed) spr_aim->set_frame(0); else spr_aim->set_frame(1); spr_aim->draw(ax,ay); //CL_Display::draw_rect(CL_Rect(ax-100,ay-100,ax+100,ay+100),CL_Color::blueviolet); }
KJezzball::KJezzball() : m_gameWidget( 0 ) { // setup variables m_game.level = 1; m_game.score = 0; m_state = Idle; KConfig *config = kapp->config(); m_backgroundDir = config->readPathEntry( "BackgroundDir" ); m_showBackground = config->readBoolEntry( "ShowBackground", false ); statusBar(); initXMLUI(); m_soundAction -> setChecked((config->readBoolEntry( "PlaySounds", true ))); // create widgets m_view = new QWidget( this, "m_view" ); setCentralWidget( m_view ); m_layout = new QGridLayout( m_view, 1, 3 ); m_layout->setColStretch( 2, 1 ); QVBoxLayout *infoLayout = new QVBoxLayout; m_layout->addLayout( infoLayout, 0, 1 ); QLabel *label = new QLabel( i18n("Level:"), m_view ); infoLayout->addWidget( label ); m_levelLCD = new QLCDNumber( 5, m_view ); infoLayout->addWidget( m_levelLCD ); label = new QLabel( i18n("Score:"), m_view ); infoLayout->addWidget( label ); m_scoreLCD = new QLCDNumber( 5, m_view ); infoLayout->addWidget( m_scoreLCD ); infoLayout->addSpacing( 20 ); label = new QLabel( i18n("Filled area:"), m_view ); infoLayout->addWidget( label ); m_percentLCD = new QLCDNumber( 5, m_view ); infoLayout->addWidget( m_percentLCD ); label = new QLabel( i18n("Lives:"), m_view ); infoLayout->addWidget( label ); m_lifesLCD = new QLCDNumber( 5, m_view ); infoLayout->addWidget( m_lifesLCD ); label = new QLabel( i18n("Time:"), m_view ); infoLayout->addWidget( label ); m_timeLCD = new QLCDNumber( 5, m_view ); infoLayout->addWidget( m_timeLCD ); // create timers m_nextLevelTimer = new QTimer( this, "m_nextLevelTimer" ); connect( m_nextLevelTimer, SIGNAL(timeout()), this, SLOT(switchLevel()) ); m_gameOverTimer = new QTimer( this, "m_gameOverTimer" ); connect( m_gameOverTimer, SIGNAL(timeout()), this, SLOT(gameOverNow()) ); m_timer = new QTimer( this, "m_timer" ); connect( m_timer, SIGNAL(timeout()), this, SLOT(second()) ); // create demo game createLevel( 1 ); statusBar()->message( i18n("Press %1 to start a game!") .arg(m_newAction->shortcut().toString()) ); //m_gameWidget->display( i18n("Press <Space> to start a game!") ); setFocusPolicy(QWidget::StrongFocus); setFocus(); setupGUI(); }
//============================================================================== void BeatboxVoxAudioProcessor::parameterChanged(const String& paramID, float newValue) { auto callback = paramCallbacks.find(paramID); callback->second(newValue); }
tweener_t get_tweener(std::wstring name) { std::transform(name.begin(), name.end(), name.begin(), std::tolower); if(name == L"linear") return [](double t, double b, double c, double d) { return ease_none(t, b, c, d, std::vector<double>()); }; std::vector<double> params; static const boost::wregex expr(L"(?<NAME>\\w*)(:(?<V0>\\d+\\.?\\d?))?(:(?<V1>\\d+\\.?\\d?))?"); // boost::regex has no repeated captures? boost::wsmatch what; if(boost::regex_match(name, what, expr)) { name = what["NAME"].str(); if(what["V0"].matched) params.push_back(boost::lexical_cast<double>(what["V0"].str())); if(what["V1"].matched) params.push_back(boost::lexical_cast<double>(what["V1"].str())); } typedef std::function<double(double, double, double, double, const std::vector<double>&)> tween_t; static const std::unordered_map<std::wstring, tween_t> tweens = boost::assign::map_list_of (L"", ease_none ) (L"linear", ease_none ) (L"easenone", ease_none ) (L"easeinquad", ease_in_quad ) (L"easeoutquad", ease_out_quad ) (L"easeinoutquad", ease_in_out_quad ) (L"easeoutinquad", ease_out_in_quad ) (L"easeincubic", ease_in_cubic ) (L"easeoutcubic", ease_out_cubic ) (L"easeinoutcubic", ease_in_out_cubic ) (L"easeoutincubic", ease_out_in_cubic ) (L"easeinquart", ease_in_quart ) (L"easeoutquart", ease_out_quart ) (L"easeinoutquart", ease_in_out_quart ) (L"easeoutinquart", ease_out_in_quart ) (L"easeinquint", ease_in_quint ) (L"easeoutquint", ease_out_quint ) (L"easeinoutquint", ease_in_out_quint ) (L"easeoutinquint", ease_out_in_quint ) (L"easeinsine", ease_in_sine ) (L"easeoutsine", ease_out_sine ) (L"easeinoutsine", ease_in_out_sine ) (L"easeoutinsine", ease_out_in_sine ) (L"easeinexpo", ease_in_expo ) (L"easeoutexpo", ease_out_expo ) (L"easeinoutexpo", ease_in_out_expo ) (L"easeoutinexpo", ease_out_in_expo ) (L"easeincirc", ease_in_circ ) (L"easeoutcirc", ease_out_circ ) (L"easeinoutcirc", ease_in_out_circ ) (L"easeoutincirc", ease_out_in_circ ) (L"easeinelastic", ease_in_elastic ) (L"easeoutelastic", ease_out_elastic ) (L"easeinoutelastic", ease_in_out_elastic) (L"easeoutinelastic", ease_out_in_elastic) (L"easeinback", ease_in_back ) (L"easeoutback", ease_out_back ) (L"easeinoutback", ease_in_out_back ) (L"easeoutintback", ease_out_int_back ) (L"easeoutbounce", ease_out_bounce ) (L"easeinbounce", ease_in_bounce ) (L"easeinoutbounce", ease_in_out_bounce ) (L"easeoutinbounce", ease_out_in_bounce ); auto it = tweens.find(name); if(it == tweens.end()) it = tweens.find(L"linear"); return [=](double t, double b, double c, double d) { return it->second(t, b, c, d, params); }; };