void CRenderWorld::DrawWinLoseMessage(int shots, GameStateType state, int secs){
  const int BUFSIZE = 256;
  char buffer[BUFSIZE];
  switch(state){
    case WON_GAMESTATE:
      if(shots == 1)
        sprintf_s(buffer, BUFSIZE, "Win in 0:%d with 1 Shot!", secs, shots);
      else
        sprintf_s(buffer, BUFSIZE, "Win in 0:%d with %d Shots!", secs, shots);
        TextWrite(buffer, RGB(255, 255, 255));
      break;
    case LOST_GAMESTATE:
      TextWrite("Loser!", RGB(192, 0, 0));
      break;
  } //switch
} //DrawWinLoseMessage
Beispiel #2
0
int add_vector(GapIO *io, char *V, int level)
{
    int err;
    int vector;
    int freerec;
    GVectors v;

    /* allocate vector name */
    v.name = allocate(io,GT_Text);
    err = TextWrite(io,v.name,V,strlen(V));
    v.level = level;

    /* find new vector number */
    vector = ++io->db.Nvectors;
    ArrayRef(io->vectors,vector-1);

    /* add vector to list */
    arr(GCardinal,io->vectors,vector-1) = freerec = allocate(io,GT_Vectors);
    err = GT_Write(io,freerec,&v,sizeof(v),GT_Vectors);

    /* write array */
    err = ArrayDelay(io, io->db.vectors, io->db.Nvectors, io->vectors);

    /* write db */
    DBDelayWrite(io);

    return vector;
}
Beispiel #3
0
int add_clone(GapIO *io, char *CN, char *CV)
{
    int err;
    int clone;
    int freerec;
    GClones c;

    /* find vector record */
    c.vector = find_vector(io,CV);
    if (!c.vector) c.vector = add_vector(io,CV,1);

    /* allocate clone name */
    c.name = allocate(io,GT_Text);
    err = TextWrite(io,c.name,CN,strlen(CN));

    /* find new clone number */
    clone = ++io->db.Nclones;
    ArrayRef(io->clones,clone-1);

    /* add clone to list */
    arr(GCardinal,io->clones,clone-1) = freerec = allocate(io,GT_Clones);
    err = GT_Write(io,freerec,&c,sizeof(c),GT_Clones);

    /* write array */
    err = ArrayDelay(io, io->db.clones, io->db.Nclones, io->clones);

    /* write db */
    DBDelayWrite(io);

    return clone;
}
Beispiel #4
0
void OSD::render() {
    int line = 1;
    for(size_t i=0; i<lines.size(); i++) {
        TextWrite(this->width / 2 - 40, line * 13, lines[i].c_str());
        line++;
    }
    lines.clear();
}
Beispiel #5
0
comment_id put_comment(GapIO *io, char *c)
/*
 * Allocate a new record, write comment, return record number.
 */
{
    int r;

    r = allocate(io,GT_Text);

    (void) TextWrite(io,r,c,strlen(c)+1);

    return r;
}
Beispiel #6
0
void F_Drawer(void)
{
	switch(FinaleStage)
	{
		case 0: // Fade in initial finale screen
			DrawPic();
			break;
		case 1:
		case 2:
			TextWrite();
			break;
		case 3: // Fade screen out
			DrawPic();
			break;
		case 4: // Fade in chess screen
			DrawPic();
			break;
		case 5:
			TextWrite();
			break;
	}
	UpdateState |= I_FULLSCRN;	
}
Beispiel #7
0
/*
 * Adds a single reading to the database. No linking of neighbours or update
 * of contig lengths is done, however the contig needs to be known in
 * order to add any consensus tags.
 */
int add_reading(GapIO *io, SeqInfo *si, int contig, int position, int sense) {
    char *t, *seq;
    GReadings r;
    int length, start, end;
    int geln, i;
    int2 *opos = NULL;
    int1 *conf = NULL;


    /* ---- Check for existance already ---- */
    if (get_gel_num(io, read_sequence_name(si), GGN_NAME) > 0) {
	verror(ERR_WARN, "enter_preassembled",
	       "ERROR!!! Reading already exists in database");
	return -1;
    }

    /* ---- Size checks ---- */
    length = si->length;
    start = si->start;
    end = si->end;

    /* ---- Initialise the reading ---- */
    geln = NumReadings(io)+1;
    if (-1 == io_init_reading(io, geln))
	return -1;

    gel_read(io, geln, r);
    seq = exp_get_entry(si->e, EFLT_SQ);


    /* ---- Original positions & Confidence values ---- */
    opos = (int2 *)xmalloc(length * sizeof(int2));
    if (!opos)
	return -1;
    if (si->origpos) {
	memcpy(opos, si->origpos, sizeof(int2) * length);
    } else {
	int i;

	for (i = 0; i < length; i++)
	    opos[i] = i+1;
    }

    conf = (int1 *)xmalloc(length);
    if (!conf) {
	xfree(opos);
	return -1;
    }
    if (si->confidence) {
	memcpy(conf, si->confidence, sizeof(int1) * length);
    } else {
	/* Read from SCF, CTF or ZTR file */
	if (0 != get_read_conf(si->e, length, opos, conf)) {
	    int i;

	    for (i = 0; i < length; i++)
		conf[i] = 99;
	}
    }

    /* ---- Add the reading name ---- */
    if (t = read_sequence_name(si)) {
	if (-1 == (r.name = allocate(io, GT_Text))) {
	    freeSeqInfo(si);
	    xfree(opos);
	    xfree(conf);
	    return -1;
	}

	if (-1 == TextWrite(io, r.name, t, strlen(t)+1)) {
	    freeSeqInfo(si);
	    xfree(opos);
	    xfree(conf);
	    return -1;
	}
	io_wname(io, geln, t);
    }


    /* ---- Gel tags ---- */
    if (gel_write(io, geln, r)) {
	verror(ERR_FATAL, "enter_preassembled",
	       "Problem writing reading to database");
	freeSeqInfo(si);
	xfree(opos);
	xfree(conf);
	return -1;
    }

    for(i = 0; i < exp_Nentries(si->e, EFLT_TG); i++) {
	create_tag_for_gel(io, geln, si->length, 
			   arr(char *, si->e->entries[EFLT_TG], i),
			   NULL, 0, NULL);
    }


    /* ---- Consensus tags ---- */
    for (i=0; i < exp_Nentries(si->e, EFLT_TC); i++) {
	char *comment, *tag;
	char type[5];
	int start, end, strand;

	tag = arr(char *, si->e->entries[EFLT_TC], i);
	if (NULL == (comment = (char *)xmalloc(strlen(tag))))
	    continue;

	if (-1 == tag2values(tag, type, &start, &end, &strand, comment))
	    continue;

	if (sense == 0) {
	    start += position - si->start - 1;
	    end   += position - si->start - 1;
	} else {
	    int len = end - start;

	    start = position + si->end - end - 1;
	    end   = start + len;
	}

	type[4] = '\0';

	insert_NEW_tag(io, (tag_id)-contig, start, end-start+1, type, comment,
		       strand);

	xfree(comment);
    }


    /* ---- SVEC/CVEC tags derived from the SL, SR and CS lines ---- */
    if (exp_Nentries(si->e, EFLT_SL)) {
	int start = 1, len;
	
	len = atoi(exp_get_entry(si->e, EFLT_SL));

	insert_NEW_tag(io, (tag_id)geln, start, len, "SVEC", NULL, 0);
    }
    
    if (exp_Nentries(si->e, EFLT_SR)) {
	int start, end;
	
	/*
	 * Vepe is currently bugged and always creates an SR when we have an
	 * SL. Often this SR is simply the far right end of the reading, in
	 * which case we don't really have any right-end sequencing vector
	 */
	start = atoi(exp_get_entry(si->e, EFLT_SR));
	if (start < si->length) {
	    end = si->length;
	    
	    insert_NEW_tag(io, (tag_id)geln, start, end - start + 1, "SVEC",
			   NULL, 0);
	}
    }

    if (exp_Nentries(si->e, EFLT_CS)) {
	int start, end;
	
	exp_get_rng(si->e, EFLT_CS, &start, &end);

	insert_NEW_tag(io, (tag_id)geln, start, end - start + 1, "CVEC", NULL, 0);
    }

    if (gel_read(io, geln, r)) {
	verror(ERR_FATAL, "enter_preassembled",
	       "Problem loading reading from database");
	freeSeqInfo(si);
	xfree(opos);
	xfree(conf);
	return -1;
    }

    
    /* ---- Complement if needed ---- */
    r.sense = sense;
    if (sense == GAP_SENSE_REVERSE) {
	io_complement_seq(&length, &start, &end, seq, conf, opos);
    }

    
    /* ---- Reading positions and lengths ---- */
    r.position = position;
    r.sequence_length = end - start - 1;

    
    /* ---- Write GReadings structure once more ---- */
    if (gel_write(io, geln, r)) {
	verror(ERR_FATAL, "enter_preassembled",
	       "Problem writing reading to database");
	freeSeqInfo(si);
	xfree(opos);
	xfree(conf);
	return -1;
    }


    /* ---- Add sequence, length, start, end, opos, and conf ---- */
    if (io_write_seq(io, geln, &length, &start, &end, seq, conf, opos)) {
	verror(ERR_FATAL, "enter_preassembled",
	       "Problem writing sequence to database");
	freeSeqInfo(si);
	xfree(opos);
	xfree(conf);
	return -1;
    }


    /* ---- Trace information ---- */
    if (exp_Nentries(si->e,EFLT_LT) && exp_Nentries(si->e,EFLT_LN)) {
	i = io_write_rd(io, geln,
			exp_get_entry(si->e,EFLT_LN),
			strlen(exp_get_entry(si->e,EFLT_LN)),
			exp_get_entry(si->e,EFLT_LT),
			strlen(exp_get_entry(si->e,EFLT_LT)));
    } else {
	verror(ERR_WARN, "enter_preassembled",
	       "no trace filename and filetype information found");
	i = io_write_rd(io, geln,
			"unknown", strlen("unknown"),
			"unknown", strlen("unknown"));
    }

    if (i) {
	verror(ERR_FATAL, "enter_preassembled",
	       "Problem writing raw data information to database");
	freeSeqInfo(si);
	xfree(opos);
	xfree(conf);
	return -1;
    }

    /* ---- Everything else: clone & primer info ---- */
    add_seq_details(io, geln, si);

    xfree(opos);
    xfree(conf);

    return geln;
}
/*
 * Takes a multiple alignment and updates the on-disk data structures to
 * match. This needs to correct confidence values, original positions and
 * tags too.
 */
void update_io(GapIO *io, int cnum, MALIGN *malign) {
    GContigs c;
    GReadings r, lastr;
    CONTIGL *cl;
    int lastrnum = 0;
    int rnum;

    contig_read(io, cnum, c);
    for (cl = malign->contigl; cl; cl = cl->next) {
	char *seq;

	rnum = cl->id;
	gel_read(io, rnum, r);
	seq = TextAllocRead(io, r.sequence);

	/* Link this->left and this->left->right. Save this->left */
	io_lnbr(io, rnum) = lastrnum;
	r.left = lastrnum;
	if (lastrnum) {
	    io_rnbr(io, lastrnum) = rnum;
	    lastr.right = rnum;
	    gel_write(io, lastrnum, lastr);
	} else {
	    io_clnbr(io, cnum) = rnum;
	    c.left = rnum;
	}

	/* Check if sequence has changed. If so assign a new one */
	if (memcmp(seq+r.start, cl->mseg->seq, cl->mseg->length) != 0) {
	    int newlen = r.start + (r.length+1 - r.end) + cl->mseg->length;
	    int i, j, np;
	    int1 *conf;
	    int2 *opos;
	    char *newseq  = (char *)malloc(newlen+1);
	    int1 *newconf = (int1 *)malloc(newlen+1);
	    int2 *newopos = (int2 *)malloc((newlen+1)*2);

	    conf = DataAllocRead(io, r.confidence,     1);
	    opos = DataAllocRead(io, r.orig_positions, 2);

	    /* Copy from 1 to r.start (base coords) */
	    for (j = 0; j < r.start; j++) {
		newseq[j]  = seq[j];
		newconf[j] = conf[j];
		newopos[j] = opos[j];
	    }
	    memcpy(&newseq[j], cl->mseg->seq, cl->mseg->length);

	    /*
	     * Step through both old and new sequences working out how
	     * they differ. This will (*should*) be entire pad movements.
	     * i = index to old seq
	     * j = index to new seq
	     * np = number of pads added minus removed from old seq.
	     */
	    np = 0;
	    for (i = j; i < r.length && j < r.start + cl->mseg->length;) {
		if (toupper(newseq[j]) == toupper(seq[i]) ||
		    (seq[i] == '.' && newseq[j] == 'N')) {
		    newconf[j] = conf[i];
		    newopos[j] = opos[i];
		    i++, j++;
		    continue;
		}

		/* Pad removed */
		if (seq[i] == '*') {
		    i++;
		    if (io_length(io, rnum) < 0) {
			tag_shift_for_delete(io, rnum, r.length - i + 1);
		    } else {
			tag_shift_for_delete(io, rnum, i+np--);
		    }
		    continue;
		}

		/* Pad created */
		if (newseq[j] == '*') {
		    int k;
		    int cl = 0, cr = 0;
		    for (k = i-1; k >= 0; k--) {
			if (seq[k] != '*') {
			    cl = conf[k];
			    break;
			}
		    }
		    for (k = i+1; k < r.length; k++) {
			if (seq[k] != '*') {
			    cr = conf[k];
			    break;
			}
		    }
		    newconf[j] = MIN(cl, cr); /* min conf of neighbours */
		    newopos[j] = 0;
		    j++;
		    if (io_length(io, rnum) < 0) {
			tag_shift_for_insert(io, rnum, r.length - i + 1);
		    } else {
			tag_shift_for_insert(io, rnum, i+ ++np);
		    }
		    continue;
		}

		fprintf(stderr, "Alignment introduced non-pad character");
		abort();
	    }

	    /* Pads previously at the end of the reading & now removed */
	    for (; i < r.start + r.sequence_length;) {
		if (seq[i] == '*') {
		    i++;
		    if (io_length(io, rnum) < 0) {
			tag_shift_for_delete(io, rnum, r.length - i + 1);
		    } else {
			tag_shift_for_delete(io, rnum, i+np--);
		    }
		} else {
		    /* Error: clipped data that wasn't a pad */
		    abort();
		}
	    }

	    /* Should only be pads remaining in newseq, if anything */
	    for (; j < r.start + cl->mseg->length; j++) {
		if (newseq[j] != '*') {
		    fprintf(stderr, "Alignment introduced non-pad character");
		    abort();
		}
		newconf[j] = 0;
		newopos[j] = 0;
	    }

	    /* Same for remaining data in seq - only pads */
	    for (; i < r.end-1; i++) {
		if (seq[i] != '*') {
		    fprintf(stderr, "Alignment skipped non-pad character");
		    abort();
		}
	    }

	    /* Append on the right hand cutoff data */
	    for (; i < r.length; i++, j++) {
		newseq[j]  = seq[i];
		newconf[j] = conf[i];
		newopos[j] = opos[i];
	    }
	    if (j != newlen) {
		abort();
	    }
	    r.length = j;

	    TextWrite(io, r.sequence,       newseq,  r.length);
	    DataWrite(io, r.confidence,     newconf, r.length, 1);
	    DataWrite(io, r.orig_positions, newopos, r.length * 2, 2);

	    xfree(conf);
	    xfree(newconf);
	    xfree(opos);
	    xfree(newopos);
	    xfree(newseq);
	}

	r.position = cl->mseg->offset + 1;
	r.sequence_length = cl->mseg->length;
	r.end = r.start + r.sequence_length + 1;
	
	lastr = r;
	lastrnum = rnum;

	io_relpos(io, rnum) = r.position;
	io_length(io, rnum) = io_length(io, rnum) < 0 ? -r.sequence_length
	                                              : +r.sequence_length;
	xfree(seq);
    }

    if (lastrnum) {
	io_rnbr(io, lastrnum) = 0;
	lastr.right = 0;
	gel_write(io, lastrnum, lastr);
    }

    c.length = malign->length;
    c.right = lastrnum;
    io_clength(io, cnum) = c.left;
    io_crnbr(io, cnum) = c.right;
    contig_write(io, cnum, c);

    io_clength(io, cnum) = c.length;

    update_consensus_tags(io, cnum, malign);
}