static bool extract(XString str, party *p) { *p = party(); // not compatible with the normal extract()ors since it has // a variable-size element that uses the same separator std::vector<XString> bits; if (!extract(str, vrec<'\t'>(&bits))) return false; auto begin = bits.begin(); auto end = bits.end(); if (begin == end || !extract(*begin, &p->party_id)) return false; ++begin; if (begin == end || !extract(*begin, &p->name)) return false; ++begin; if (begin == end || !extract(*begin, record<','>(&p->exp, &p->item))) return false; ++begin; for (int i = 0; begin != end && i < MAX_PARTY; ++i) { struct party_member *m = &p->member[i]; if (begin == end || !extract(*begin, record<','>(&m->account_id, &m->leader))) return false; ++begin; if (begin == end || !extract(*begin, &m->name)) return false; ++begin; if (!m->account_id) --i; } return true; }
/* ** parties until the gradients settle down */ int tenGradientBalance(Nrrd *nout, const Nrrd *nin, tenGradientParm *tgparm) { static const char me[]="tenGradientBalance"; double len, lastLen, improv; airRandMTState *rstate; Nrrd *ncopy; unsigned int iter, maxIter; int done; airArray *mop; if (!nout || tenGradientCheck(nin, nrrdTypeUnknown, 2) || !tgparm) { biffAddf(TEN, "%s: got NULL pointer (%p,%p) or invalid nin", me, AIR_VOIDP(nout), AIR_VOIDP(tgparm)); return 1; } if (nrrdConvert(nout, nin, nrrdTypeDouble)) { biffMovef(TEN, NRRD, "%s: can't initialize output with input", me); return 1; } mop = airMopNew(); ncopy = nrrdNew(); airMopAdd(mop, ncopy, (airMopper)nrrdNuke, airMopAlways); rstate = airRandMTStateNew(tgparm->seed); airMopAdd(mop, rstate, (airMopper)airRandMTStateNix, airMopAlways); /* HEY: factor of 100 is an approximate hack */ maxIter = 100*tgparm->maxIteration; lastLen = 1.0; done = AIR_FALSE; do { iter = 0; do { iter++; len = party(nout, rstate); } while (len > lastLen && iter < maxIter); if (iter >= maxIter) { if (tgparm->verbose) { fprintf(stderr, "%s: stopping at max iter %u\n", me, maxIter); } if (nrrdCopy(nout, ncopy)) { biffMovef(TEN, NRRD, "%s: trouble copying", me); airMopError(mop); return 1; } done = AIR_TRUE; } else { if (nrrdCopy(ncopy, nout)) { biffMovef(TEN, NRRD, "%s: trouble copying", me); airMopError(mop); return 1; } improv = lastLen - len; lastLen = len; if (tgparm->verbose) { fprintf(stderr, "%s: (iter %u) improvement: %g (mean length = %g)\n", me, iter, improv, len); } done = (improv <= tgparm->minMeanImprovement || len < tgparm->minMean); } } while (!done); airMopOkay(mop); return 0; }
size_t JsonWriteRichPresenceObj(char* dest, size_t maxLen, int nonce, int pid, const DiscordRichPresence* presence) { JsonWriter writer(dest, maxLen); { WriteObject top(writer); JsonWriteNonce(writer, nonce); WriteKey(writer, "cmd"); writer.String("SET_ACTIVITY"); { WriteObject args(writer, "args"); WriteKey(writer, "pid"); writer.Int(pid); if (presence != nullptr) { WriteObject activity(writer, "activity"); WriteOptionalString(writer, "state", presence->state); WriteOptionalString(writer, "details", presence->details); if (presence->startTimestamp || presence->endTimestamp) { WriteObject timestamps(writer, "timestamps"); if (presence->startTimestamp) { WriteKey(writer, "start"); writer.Int64(presence->startTimestamp); } if (presence->endTimestamp) { WriteKey(writer, "end"); writer.Int64(presence->endTimestamp); } } if ((presence->largeImageKey && presence->largeImageKey[0]) || (presence->largeImageText && presence->largeImageText[0]) || (presence->smallImageKey && presence->smallImageKey[0]) || (presence->smallImageText && presence->smallImageText[0])) { WriteObject assets(writer, "assets"); WriteOptionalString(writer, "large_image", presence->largeImageKey); WriteOptionalString(writer, "large_text", presence->largeImageText); WriteOptionalString(writer, "small_image", presence->smallImageKey); WriteOptionalString(writer, "small_text", presence->smallImageText); } if ((presence->partyId && presence->partyId[0]) || presence->partySize || presence->partyMax) { WriteObject party(writer, "party"); WriteOptionalString(writer, "id", presence->partyId); if (presence->partySize && presence->partyMax) { WriteArray size(writer, "size"); writer.Int(presence->partySize); writer.Int(presence->partyMax); } } if ((presence->matchSecret && presence->matchSecret[0]) || (presence->joinSecret && presence->joinSecret[0]) || (presence->spectateSecret && presence->spectateSecret[0])) { WriteObject secrets(writer, "secrets"); WriteOptionalString(writer, "match", presence->matchSecret); WriteOptionalString(writer, "join", presence->joinSecret); WriteOptionalString(writer, "spectate", presence->spectateSecret); } writer.Key("instance"); writer.Bool(presence->instance != 0); } } } return writer.Size(); }