cMobile::~cMobile() { freeSequence(); if (this == Player) { Player = 0; // Reset player to null -> important } }
void scanFile(FILE *fp, Args *args) { Sequence *seq = NULL; char *oldChr; int start, end; FILE *snp; oldChr = (char *)emalloc(sizeof(char)); oldChr[0] = '\0'; while (tabGetLine(fp) != NULL) { /* read chromosome, start, and end of hotspot from line */ if (tabField(0)[0] == '#') continue; if (strcmp(oldChr, hotSpotGetChr()) != 0) { if (seq) freeSequence(seq); seq = hotSpotSeq(args); free(oldChr); oldChr = estrdup(hotSpotGetChr()); } start = atoi(tabField(START_FIELD)); end = atoi(tabField(END_FIELD)); if (args->r) { /* reverse primers are downstream of hotspot */ start = end; end += args->f; snp = hotSpotSnp(args, start, end); if(args->u) reversePuniv(args, seq, snp, start, end); else reverseP(args, seq, snp); } else { /* forward primers are upstream of hotspot */ end = start; start -= args->f; snp = hotSpotSnp(args, start, end); if(args->u) forwardPuniv(args, seq, snp, start, end); else forwardP(args, seq, snp); } pclose(snp); } freeSequence(seq); free(oldChr); }
void cMobile::playAction(unsigned char action, unsigned int duration) { if (currentAction_ != action) { freeSequence(); // Free old sequence if the actions dont match } // Set the action and the duration currentAction_ = action; currentActionEnd_ = Utilities::getTicks() + duration; }
/* deallocate memory for an array of sequence */ void freeSequenceArray(Int64 n, Sequence *seqArray[]) { Int64 i; for (i = 0; i < n; i++) { if (seqArray[i]) { freeSequence(seqArray[i]); } } free(seqArray); }
void cMobile::setWarmode(bool data) { if (data != warmode) { warmode = data; if (currentActionEnd_ == 0) { freeSequence(); currentAction_ = getIdleAction(); } Network->emitWarmodeChanged(data); } }
void LKH::LKHAlg::freeAll() { freeERXT(); freeGain23(); freeSequence(); freeCreateDelaunay(); freeCreateQuadrant(); freeGreedyTour(); freePatchCycle(); freeReadPenalties(); }
cMobile::~cMobile() { deleting = true; freeSequence(); if (this == Player) { Player = 0; // Reset player to null -> important } clearEquipment(); delete status_; }
void cMobile::draw(int cellx, int celly, int leftClip, int topClip, int rightClip, int bottomClip) { //return; // Don't draw yet // See if the current action expired if (currentActionEnd_ != 0 && currentActionEnd_ < Utilities::getTicks()) { freeSequence(); // Free current surface currentActionEnd_ = 0; // Reset end time currentAction_ = getIdleAction(); } // Refresh the sequence if (!sequence_) { refreshSequence(); } // Modify cellx/celly based on the smooth move settings // Smooth move handling. if (smoothMoveEnd != 0) { int moveProgress = smoothMoveTime - (smoothMoveEnd - Utilities::getTicks()); if (moveProgress < 0 || moveProgress >= (int)smoothMoveTime) { smoothMoveEnd = 0; } else { if (moveProgress <= 0) { cellx += drawxoffset; celly += drawyoffset; frame = 0; } else { float factor = 1.0f - (float)moveProgress / (float)smoothMoveTime; cellx += (int)(factor * (float)drawxoffset); celly += (int)(factor * (float)drawyoffset); if (sequence_) { frame = (int)(sequence_->frameCount() * factor); } } } } // Draw if (sequence_) { // Skip to next frame if (smoothMoveEnd == 0 && nextFrame < Utilities::getTicks()) { if (++frame >= sequence_->frameCount()) { frame = 0; } nextFrame = Utilities::getTicks() + getFrameDelay(); } // The anims facing right are generated by flipping the ones facing left bool flip = (direction_ > 0 && direction_ < 4); sequence_->draw(frame, cellx, celly, flip); } }
/* deallocates memory for a seqArray */ void freeSequenceUnion(SequenceUnion *seqUnion, Int64 n) { int i; freeSequence(seqUnion->seqUnion); free(seqUnion->seqBorders); //for (i = 0; i < seqUnion->numOfSubjects + 1; i ++) { for (i = 0; i < n; i ++) { free(seqUnion->bordersWithinSeq[i]); } free(seqUnion->bordersWithinSeq); free(seqUnion->gc); free(seqUnion); }
/* prepareSeq: prepares sequence string for analysis by shustring-type programs. * Does the following: 1) set all residues to upper case * 2) generate reverse complement * 3) concatenate reverse complement to end of forward strand * e.g. if the string of the original seq. is ACCGZ\0, (Z for the border) * then the new one which includes the reversed complement seq. looks like this: ACCGZCGGTZ\0 * */ void prepareSeq(Sequence *sequence){ Sequence *rstrand; Int64 i, j; char *nuc = "TCAGtcag"; strtoupper(sequence->seq); /* take care of reverse strand */ rstrand = revcomp(sequence); /* reverse and complement a sequence */ rstrand->headers = (char **)emalloc(sizeof(char *)); rstrand->headers[0] = (char *)emalloc(sizeof(char)); rstrand->borders = (Int64 *)emalloc(sizeof(Int64)); rstrand->freqTab = NULL; rstrand->numSeq = 1; sequence->seq[sequence->len] = '\0'; sequence->len += sequence->len; /* new seq. length = 2 x original size */ sequence->seq = (char *)erealloc(sequence->seq,(size_t)(sequence->len+1)*sizeof(char)); /* number of borders = 2 x original size */ sequence->borders = (Int64 *)erealloc(sequence->borders, 2*(size_t)sequence->numSeq * sizeof(Int64)); /* adjust the border values */ for(i=1;i<sequence->numSeq;i++){ /* seq. looks like this: F1 F2 .. Fn Rn .. R2 R1 */ sequence->borders[2*sequence->numSeq-i-1] = sequence->len - sequence->borders[i-1] - 2; } sequence->borders[2*sequence->numSeq-1] = sequence->len - 1; /* move first border of reverted sequences to the end */ rstrand->seq++; /* since the last border of the original seq is the first char of the reversed seq */ //strncat(sequence->seq,rstrand->seq,(size_t)sequence->len); ?? strncat(sequence->seq,rstrand->seq,(size_t)sequence->len / 2); rstrand->seq--; /* return the pointer */ sequence->seq[sequence->len-1] = BORDER; sequence->seq[sequence->len] = '\0'; freeSequence(rstrand); sequence->numNuc = 0; for(i = 0; i < 8; i++) { //sequence->numNuc += sequence->freqTab[(int)nuc[i]]; for (j = 0; j < sequence->numNuc; j ++) { sequence->numNuc += sequence->freqTab[j][(Int64)nuc[i]]; sequence->freqTab[j][(Int64)nuc[i]] *= 2; /* fwd and rev strand */ } } sequence->numNuc *= 2; sequence->numSbjctNuc *= 2; }
void cMobile::draw(int cellx, int celly, int leftClip, int topClip, int rightClip, int bottomClip) { // Save the original cellx, celly for the greyed out stuff int orgCellX = cellx; int orgCellY = celly; static int cellXOffset = 0; static int cellYOffset = 0; if (Config->gameHideMobiles()) { return; } // Test for smoother player movement if (this == Player) { cellx = WorldView->x() + WorldView->width() / 2; celly = WorldView->y() + WorldView->height() / 2; } cellx += cellXOffset; celly += cellYOffset; // See if the current action expired if (currentActionEnd_ != 0 && currentActionEnd_ < Utilities::getTicks()) { // Don't cancel the movement action while we're still moving -or- have movement requests left if (this != Player || ((!WorldView->isMoving() || WorldView->isMovementBlocked()) && (!UoSocket || UoSocket->sequenceQueueLength() == 0))) { freeSequence(); // Free current surface currentActionEnd_ = 0; // Reset end time currentAction_ = getIdleAction(); } } // Refresh the sequence if (!sequence_) { refreshSequence(); } float alpha = 1.0f; // Modify cellx/celly based on the smooth move settings // Smooth move handling. if (smoothMoveEnd != 0) { int moveProgress = smoothMoveTime - (smoothMoveEnd - Utilities::getTicks()); if (moveProgress < 0 || moveProgress >= (int)smoothMoveTime) { smoothMoveEnd = 0; World->removeEntity(this); World->addEntity(this); } else if (this != Player) { if (moveProgress <= 0) { cellx += drawxoffset; celly += drawyoffset; } else { float factor = 1.0f - (float)moveProgress / (float)smoothMoveTime; cellx += (int)(factor * (float)drawxoffset); celly += (int)(factor * (float)drawyoffset); } } } static bool inGreyDraw = false; static bool inBlurDraw = false; if (isHidden()) { glPushAttrib(GL_ENABLE_BIT); glEnable(GL_ALPHA_TEST); // Make sure that transparent pixels wont touch our stencil buffer glAlphaFunc(GL_GREATER, 0.0f); glEnable(GL_STENCIL_TEST); // Enable per-pixel stencil testing glStencilFunc(GL_EQUAL, 1, 1); // Draw if stencil buffer is not zero glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO); if (!inGreyDraw) { glClearStencil(1); glClear(GL_STENCIL_BUFFER_BIT); } static uint nextPeak = 0; static uint lastPeak = 0; static bool peakDirection = false; uint time = Utilities::getTicks(); if (time >= nextPeak) { lastPeak = Utilities::getTicks(); nextPeak = lastPeak + 1500 + Random->randInt(1000); peakDirection = !peakDirection; } alpha = (nextPeak - Utilities::getTicks()) / (float)(nextPeak - lastPeak); if (peakDirection) { alpha = 1.0f - alpha; } if (inGreyDraw) { if (inBlurDraw) { alpha *= 0.5f; } else { alpha *= 0.8f; } } else { GLWidget->enableGrayShader(); alpha = 0.8 * (1.0f - alpha); // Invert alpha value } } // Draw if (sequence_) { // Only advance to the next frame if we're not beyond the end of this action if (currentActionEnd_ != 0 && currentActionEnd_ >= Utilities::getTicks()) { // Skip to next frame if (nextFrame < Utilities::getTicks()) { if (++frame >= sequence_->frameCount()) { frame = 0; } nextFrame = Utilities::getTicks() + getFrameDelay(); } } // The anims facing right are generated by flipping the ones facing left bool flip = (direction_ >= 0 && direction_ < 4); // Mounts come always first if (!isHidden()) { if ((bodyType() == HUMAN || bodyType() == EQUIPMENT) && equipment[LAYER_MOUNT] && equipmentSequences[LAYER_MOUNT]) { // Only advance to the next frame if we're not beyond the end of this action if (currentActionEnd_ != 0 && currentActionEnd_ >= Utilities::getTicks()) { // Skip to next frame if (nextMountFrame < Utilities::getTicks()) { if (++mountFrame >= equipmentSequences[LAYER_MOUNT]->frameCount()) { mountFrame = 0; } nextMountFrame = Utilities::getTicks() + getMountFrameDelay(); } } mountFrame = frame; // Until something better is found equipmentSequences[LAYER_MOUNT]->draw(mountFrame, cellx, celly, flip, alpha); } sequence_->draw(frame, cellx, celly, flip, alpha); } // Draw the equipment if (bodyType() == HUMAN || bodyType() == EQUIPMENT) { // Reverse the draw order if hidden if (isHidden()) { uint count = 0; const int *order = drawOrder[direction_ % 8]; while (order[count] != -1) { count++; } for (int i = count - 1; i >= 0; --i) { enLayer layer = (enLayer)order[i]; if (layer < LAYER_VISIBLECOUNT && equipmentSequences[layer]) { // Oh great OSI... Another exception from the rule *sigh* // Don't draw Hair if we're wearing a gm robe if (layer != LAYER_HAIR || !equipmentSequences[LAYER_OUTERTORSO] || equipmentSequences[LAYER_OUTERTORSO]->body() != 0x3db) { equipmentSequences[layer]->draw(frame, cellx, celly, flip, alpha); } } } } else { const int *order = drawOrder[direction_ % 8]; while (*order != -1) { enLayer layer = (enLayer)*order; if (layer < LAYER_VISIBLECOUNT && equipmentSequences[layer]) { // Oh great OSI... Another exception from the rule *sigh* // Don't draw Hair if we're wearing a gm robe if (layer != LAYER_HAIR || !equipmentSequences[LAYER_OUTERTORSO] || equipmentSequences[LAYER_OUTERTORSO]->body() != 0x3db) { equipmentSequences[layer]->draw(frame, cellx, celly, flip, alpha); } } ++order; // Next layer } } } // If we're hidden, mount+body come last if (isHidden()) { sequence_->draw(frame, cellx, celly, flip, alpha); if ((bodyType() == HUMAN || bodyType() == EQUIPMENT) && equipment[LAYER_MOUNT] && equipmentSequences[LAYER_MOUNT]) { // Only advance to the next frame if we're not beyond the end of this action if (currentActionEnd_ != 0 && currentActionEnd_ >= Utilities::getTicks()) { // Skip to next frame if (nextMountFrame < Utilities::getTicks()) { if (++mountFrame >= equipmentSequences[LAYER_MOUNT]->frameCount()) { mountFrame = 0; } nextMountFrame = Utilities::getTicks() + getMountFrameDelay(); } } mountFrame = frame; // Until something better is found equipmentSequences[LAYER_MOUNT]->draw(mountFrame, cellx, celly, flip, alpha); } } } if (isHidden()) { glPopAttrib(); if (!inGreyDraw) { GLWidget->disableGrayShader(); } } drawx_ = cellx; drawy_ = celly; if (isHidden() && !inGreyDraw) { glClearStencil(1); glClear(GL_STENCIL_BUFFER_BIT); inGreyDraw = true; inBlurDraw = true; cellXOffset = 1; draw(orgCellX, orgCellY, leftClip, topClip, rightClip, bottomClip); cellXOffset = -1; draw(orgCellX, orgCellY, leftClip, topClip, rightClip, bottomClip); cellXOffset = 0; cellYOffset = 1; draw(orgCellX, orgCellY, leftClip, topClip, rightClip, bottomClip); cellYOffset = -1; draw(orgCellX, orgCellY, leftClip, topClip, rightClip, bottomClip); cellYOffset = 0; inBlurDraw = false; draw(orgCellX, orgCellY, leftClip, topClip, rightClip, bottomClip); inGreyDraw = false; } }