示例#1
0
文件: tick.c 项目: F483/cleanspace
void spawn_tick_trash(Trash* t, Obj* o){

  Uint32 rand_a = rand();
  Uint32 rand_b = rand();

  tick_new_trash_x += trash_offset(rand_a);
  Uint32 new_tick_trash_y = rand_b % GAME_H;

  t->pos = vec_make_int(tick_new_trash_x, new_tick_trash_y);
  t->vec = vec_make_int(0,0);
  
  // cheap weighted random choice
  Uint32 tw = rand_a % (4 + 16 + (DIFFICULTY_SIZE - tick_difficulty)); 
  t->type = (tw < 4) ? TRASH_BIG : (tw < 20 ? TRASH_SMALL : POWER_CELL);

  // ok to update tick_trash obj because its off screen before and after
  Sint32 x = game_to_screen_x(vec_get_x_int(t->pos), trash_radius(t));
  Sint32 y = game_to_screen_y(vec_get_y_int(t->pos), trash_radius(t));
  Uint32 index = tick_trash_index(rand_b, t->type);
  Uint32 hflip = rand_a % 2 ? OBJ_A1_HFLIP : 0;
  Uint32 vflip = rand_b % 2 ? OBJ_A1_VFLIP : 0;
  Bool isbig = t->type == TRASH_BIG;
  Uint32 size = isbig ? OBJ_A1_SIZE_S_32x32 : OBJ_A1_SIZE_S_16x16;

  o->attr0 = obj_a0_build(
    y, OBJ_A0_MODE_REG, OBJ_A0_BLEND_NORMAL, 0, 
    OBJ_A0_8BPP, OBJ_A0_SHAPE_SQUARE
  );
  o->attr1 = obj_a1_build_reg(x, hflip, vflip, size);
  o->attr2 = obj_a2_build(index, 1, 0);

  if (obj_offscreen(*o, x, y)){
    *o = obj_hide(*o);
  }
}
示例#2
0
//! Unwind the object text-buffer
void obj_erase(int left, int top, int right, int bottom)
{	
	TTC *tc= tte_get_context();
	int ii=0, nn= tc->dst.pitch;
	OBJ_ATTR *obj= (OBJ_ATTR*)tc->dst.data;

	for(ii=0; ii<nn; ii++)
		obj_hide(obj--);

	tc->dst.pitch= 0;
}
示例#3
0
/*!	\param x	x-coordinate in pixels.
*	\param y	y-coordinate in pixels.
*	\param str	String indicating which area is used.
*/
void obj_clrs(int x, int y, const char *str)
{
	int c;
	OBJ_ATTR *obj= (OBJ_ATTR*)gptxt->dst0;

	while((c=*str++) != 0)
	{
		if(c != '\n' && c != ' ')
			obj_hide(obj++);
	}	
}
示例#4
0
/*
 * Match callback.
 * 'obj' is a match contained within the check assembly list.
 */
void *checkass_obj_func(int job, void *jdata, obj_checkass *obj,
			mobj_checkass *ca) {
    static char buf[80];
    obj_cs *cs;
    int cs_id;

    cs_id = type_to_result(ca->io, REG_TYPE_CONTIGSEL, 0);
    cs = result_data(ca->io, cs_id);

    switch(job) {
    case OBJ_LIST_OPERATIONS:
	return "Information\0Hide\0Invoke contig editor *\0"
	    "SEPARATOR\0Remove\0";

    case OBJ_INVOKE_OPERATION:
	switch(*((int *)jdata)) {
	case 0: /* Information */
	    vfuncgroup(1, "2D plot matches");
	case -1: /* Information from results manager */
	    start_message();
	    vmessage("check_assembly match:\n");
	    vmessage("    From contig %s(#%"PRIrec") at %d\n",
		     get_contig_name(ca->io, ABS(obj->c1)),
		     io_clnbr(ca->io, ABS(obj->c1)), obj->pos1);
	    vmessage("    With contig %s(#%"PRIrec") at %d\n",
		     get_contig_name(ca->io, ABS(obj->c2)),
		     io_clnbr(ca->io, ABS(obj->c2)), obj->pos2);
	    vmessage("    Length %d, mismatch %2.2f%%\n\n",
		     obj->length, ((float)obj->score)/10000);
	    end_message(cs->window);
	    break;

	case 1: /* Hide */
	    obj_hide(GetInterp(), cs->window, obj,
		     (mobj_repeat *)ca, csplot_hash);
	    break;

	case -2: /* default */
	case 2: /* Invoke contig editor */ {
	    tg_rec cnum, llino;
	    int pos;

	    obj->flags |= OBJ_FLAG_VISITED;
	    ca->current = obj - ca->match;
	    Tcl_VarEval(GetInterp(), "CSLastUsed ", CPtr2Tcl(ca), NULL);

	    cnum  = abs(obj->c1);
	    llino = obj->read;
	    pos   = obj->pos1 - io_relpos(ca->io, llino);
	    if (pos < 1)
		pos = 1;
	    if (pos > ABS(io_length(ca->io, llino)))
		pos = ABS(io_length(ca->io, llino));

//	    if ((id = editor_available(cnum, 1)) != -1) {
//		move_editor(id, llino, pos);
//	    } else {
		edit_contig(ca->io, cnum, llino, pos);
//	    }
	    break;
	}

	case 3: /* Remove */
	    obj_remove(GetInterp(), cs->window, obj,
		       (mobj_repeat *)ca, csplot_hash);
	    break;

        }
        break;

    case OBJ_GET_BRIEF:
	sprintf(buf,
		"check_assembly: #%"PRIrec"@%d len %d, mis %2.2f%%",
		obj->read, obj->pos1, obj->length, ((float)obj->score)/10000);
	return buf;
    }

    return NULL;
}
示例#5
0
/*
 * Match callback.
 * 'obj' is a match contained within the 'repeat' list.
 */
void *repeat_obj_func(int job, void *jdata, obj_match *obj,
		      mobj_repeat *repeat) {
    static char buf[80];
    obj_cs *cs;
    int cs_id;

    cs_id = type_to_result(repeat->io, REG_TYPE_CONTIGSEL, 0);
    cs = result_data(repeat->io, cs_id, 0);

    switch(job) {
    case OBJ_LIST_OPERATIONS:
	if (io_rdonly(repeat->io) && ((obj->c1 > 0 && obj->c2 < 0) ||
				      (obj->c1 < 0 && obj->c2 > 0))) {
	    return "Information\0Hide\0IGNORE\0"
		"IGNORE\0SEPARATOR\0Remove\0";
	} else {
	    return "Information\0Hide\0Invoke join editor *\0"
		"Invoke contig editors\0SEPARATOR\0Remove\0";
	}

    case OBJ_INVOKE_OPERATION:
	switch(*((int *)jdata)) {
	case 0: /* Information */
	    vfuncgroup(1, "2D plot matches");
	case -1: /* Information from results manager */
	    start_message();
	    vmessage("Repeat match (%s)\n",
		     ((obj->c1 > 0) == (obj->c2 > 0)) ? "direct" : "inverted");
	    vmessage("    From contig %s(#%d) at %d\n",
		     get_contig_name(repeat->io, ABS(obj->c1)),
		     io_clnbr(repeat->io, ABS(obj->c1)), obj->pos1);
	    vmessage("    With contig %s(#%d) at %d\n",
		     get_contig_name(repeat->io, ABS(obj->c2)),
		     io_clnbr(repeat->io, ABS(obj->c2)), obj->pos2);
	    vmessage("    Length %d\n\n", obj->length);
	    end_message(cs->window);
	    break;

	case 1: /* Hide */
	    obj_hide(GetInterp(), cs->window, obj,
		     (mobj_repeat *)repeat, csplot_hash);
	    break;

	case -2: /* default */
	case 2: /* Invoke join editor */ {
	    int cnum[2], llino[2], pos[2];

	    obj->flags |= OBJ_FLAG_VISITED;
	    repeat->current = obj - repeat->match;
	    Tcl_VarEval(GetInterp(), "CSLastUsed ", CPtr2Tcl(repeat), NULL);

	    cnum[0] = ABS(obj->c1);
	    cnum[1] = ABS(obj->c2);

	    /* Complement a contig if needed */
	    if ((obj->c1 > 0) != (obj->c2 > 0)) {
		if (cnum[0] == cnum[1]) {
		    verror(ERR_WARN, "join_editor",
			   "cannot display the same contig in two "
			   "different orientations");
		    break;
		}
		if (io_rdonly(repeat->io)) {
		    bell();
		    break;
		}

		if (io_clength(repeat->io, ABS(obj->c1)) <
		    io_clength(repeat->io, ABS(obj->c2))) {
		    if (-1 == complement_contig(repeat->io, ABS(obj->c1)))
			if (-1 == complement_contig(repeat->io, ABS(obj->c2)))
			    return NULL;
		} else {
		    if (-1 == complement_contig(repeat->io, ABS(obj->c2)))
			if (-1 == complement_contig(repeat->io, ABS(obj->c1)))
			    return NULL;
		}
	    }

	    /*
	     * NB: obj->pos1 now may not be the same value as when this
	     * function was entered, due to the complementing!
	     */
	    pos[0] = obj->pos1;
	    pos[1] = obj->pos2;

	    llino[0] = io_clnbr(repeat->io, cnum[0]);
	    llino[1] = io_clnbr(repeat->io, cnum[1]);

	    join_contig(GetInterp(), repeat->io, cnum, llino, pos,
			consensus_cutoff, quality_cutoff);
	    break;
	}

	case 3: /* Invoke contig editors */ {
	    int cnum, llino, pos;

	    cnum  = ABS(obj->c1);
	    llino = io_clnbr(repeat->io, cnum);
	    pos   = obj->pos1;

	    edit_contig(GetInterp(), repeat->io, cnum, llino, pos,
			consensus_cutoff, quality_cutoff, 0, NULL);

	    cnum  = ABS(obj->c2);
	    llino = io_clnbr(repeat->io, cnum);
	    pos   = obj->pos2;

	    edit_contig(GetInterp(), repeat->io, cnum, llino, pos,
			consensus_cutoff, quality_cutoff, 0, NULL);
	    break;
	}

	case 4: /* Remove */
	    obj_remove(GetInterp(), cs->window, obj,
		     (mobj_repeat *)repeat, csplot_hash);
	    break;

	}
	break;

    case OBJ_GET_BRIEF:
	sprintf(buf, "Repeat: %c#%d@%d with %c#%d@%d, len %d",
		obj->c1 > 0 ? '+' : '-',
		io_clnbr(repeat->io, ABS(obj->c1)), obj->pos1,
		obj->c2 > 0 ? '+' : '-',
		io_clnbr(repeat->io, ABS(obj->c2)), obj->pos2,
		obj->length);
	return buf;
    }

    return NULL;
}
示例#6
0
/*
 * functions to act upon matches generated using TAGs
 */
void *find_oligo_obj_func1(int job,
			  void *jdata,
			  obj_match *obj,
			  mobj_find_oligo *find_oligo)
{
    static char buf[80];
    obj_cs *cs;
    int cs_id;

    cs_id = type_to_result(find_oligo->io, REG_TYPE_CONTIGSEL, 0);
    cs = result_data(find_oligo->io, cs_id);

    switch(job) {
    case OBJ_LIST_OPERATIONS:
	return "Information\0Hide\0Invoke join editor *\0"
	    "Invoke contig editors\0SEPARATOR\0Remove\0";

    case OBJ_INVOKE_OPERATION:
	switch(*((int *)jdata)) {
	case 0: /* Information */
	    vfuncgroup(1, "2D plot matches");
	case -1: /* Information from results manager */

	    start_message();
	    vmessage("Sequence search:\n");
	    vmessage("    From contig %s(#%"PRIrec") at %d\n",
		     get_contig_name(find_oligo->io, ABS(obj->c1)),
		     io_clnbr(find_oligo->io, ABS(obj->c1)), obj->pos1);
	    vmessage("    With contig %s(#%"PRIrec") at %d\n",
		     get_contig_name(find_oligo->io, ABS(obj->c2)),
		     io_clnbr(find_oligo->io, ABS(obj->c2)), obj->pos2);
	    vmessage("    Length %d, match %2.2f%%\n\n",
		     obj->length,
		     (float)obj->score / obj->length * 100.0 );
	    end_message(cs->window);
	    break;

	case 1: /* Hide */
	    obj_hide(GetInterp(), cs->window, obj,
		     (mobj_find_oligo *)find_oligo, csplot_hash);
	    break;

	case -2: /* default */
        case 2: /* Invoke join editor */ {
	    tg_rec cnum[2], llino[2];
	    int pos[2];

	    obj->flags |= OBJ_FLAG_VISITED;
	    find_oligo->current = obj - find_oligo->match;
	    Tcl_VarEval(GetInterp(), "CSLastUsed ", CPtr2Tcl(find_oligo), NULL);

	    cnum[0] = ABS(obj->c1);
	    cnum[1] = ABS(obj->c2);

	    /* Complement a contig if needed */
	    if ((obj->c1 > 0) != (obj->c2 > 0)) {
		if (cnum[0] == cnum[1]) {
		    verror(ERR_WARN, "join_editor",
			   "cannot display the same contig in two "
			   "different orientations");
		    break;
		}

		if (find_oligo->io->read_only) {
		    bell();
		    break;
		}

		if (io_clength(find_oligo->io, ABS(obj->c1)) <
		    io_clength(find_oligo->io, ABS(obj->c2))) {
		    if (-1 == complement_contig(find_oligo->io, ABS(obj->c1)))
			if (-1 == complement_contig(find_oligo->io,
						    ABS(obj->c2)))
			    return NULL;
		} else {
		    if (-1 == complement_contig(find_oligo->io, ABS(obj->c2)))
			if (-1 == complement_contig(find_oligo->io,
						    ABS(obj->c1)))
			    return NULL;
		}
	    }

	    /*
	     * NB: obj->pos1 now may not be the same value as when this
	     * function was entered, due to the complementing!
	     */
	    pos[0] = obj->pos1;
	    pos[1] = obj->pos2;

	    llino[0] = io_clnbr(find_oligo->io, cnum[0]);
	    llino[1] = io_clnbr(find_oligo->io, cnum[1]);

	    join_contig(find_oligo->io, cnum, llino, pos);

	    break;
	}

	case 3: /* Invoke contig editors */ {
	    tg_rec cnum, llino;
	    int pos;
	    
	    cnum  = ABS(obj->c1);
	    llino = io_clnbr(find_oligo->io, cnum);
	    pos   = obj->pos1;

	    edit_contig(find_oligo->io, cnum, llino, pos);

	    cnum  = ABS(obj->c2);
	    llino = io_clnbr(find_oligo->io, cnum);
	    pos   = obj->pos2;

	    edit_contig(find_oligo->io, cnum, llino, pos);
	    break;
	}

	case 4: /* Remove */
	    obj_remove(GetInterp(), cs->window, obj,
		       (mobj_find_oligo *)find_oligo, csplot_hash);
	    break;

        }
        break;

    case OBJ_GET_BRIEF:
	sprintf(buf,
		"Oligo: %c#%"PRIrec"@%d with %c#%"PRIrec"@%d, "
		"len %d, match %2.2f%%",
		obj->c1 > 0 ? '+' : '-',
		io_clnbr(find_oligo->io, ABS(obj->c1)), obj->pos1,
		obj->c2 > 0 ? '+' : '-',
		io_clnbr(find_oligo->io, ABS(obj->c2)), obj->pos2,
		obj->length, (float)obj->score / obj->length * 100.0);
	return buf;
    }

    return NULL;
}
示例#7
0
/*
 * functions to act upon matches generated using SEQUENCE
 */
void *find_oligo_obj_func2(int job,
			  void *jdata,
			  obj_match *obj,
			  mobj_find_oligo *find_oligo)
{
    static char buf[80];
    obj_cs *cs;
    int cs_id;

    cs_id = type_to_result(find_oligo->io, REG_TYPE_CONTIGSEL, 0);
    cs = result_data(find_oligo->io, cs_id);

    switch(job) {
    case OBJ_LIST_OPERATIONS:
	return "Information\0Hide\0Invoke contig editor *\0"
	    "SEPARATOR\0Remove\0";

    case OBJ_INVOKE_OPERATION:
	switch(*((int *)jdata)) {
	case 0: /* Information */
	    vfuncgroup(1, "2D plot matches");
	case -1: /* Information from results manager */

	    start_message();
	    vmessage("Sequence search\n");
	    vmessage("    Contig %s(#%"PRIrec") at %d\n",
		     get_contig_name(find_oligo->io, ABS(obj->c1)),
		     io_clnbr(find_oligo->io, ABS(obj->c1)), obj->pos1);
	    vmessage("    Length %d, match %2.2f%%\n\n",
		   obj->length, (float)obj->score / obj->length * 100.0 );
	    end_message(cs->window);
	    break;

	case 1: /* Hide */
	    obj_hide(GetInterp(), cs->window, obj,
		     (mobj_find_oligo *)find_oligo, csplot_hash);
	    break;

	case -2: /* default */
	case 2: /* Invoke contig editor */ {
	    tg_rec cnum, llino;
	    int pos;

	    obj->flags |= OBJ_FLAG_VISITED;
	    find_oligo->current = (int)(obj - find_oligo->match);

	    cnum  = ABS(obj->c1);
	    llino = 0;
	    pos   = obj->pos1;

	    /* FIXME
	    if ((id = editor_available(cnum, 1)) == -1) {
		edit_contig(GetInterp(), find_oligo->io, cnum, llino, pos,
			    consensus_cutoff, quality_cutoff, 0, NULL);
	    }
	    if ((id = editor_available(cnum, 1)) != -1) {
		move_editor(id, llino, pos);
		editor_select_region(id, llino, pos, obj->length);
	    }
	    */

	    edit_contig(find_oligo->io, cnum, llino, pos);

	    break;
	}

	case 3: /* Remove */
	    obj_remove(GetInterp(), cs->window, obj,
		       (mobj_find_oligo *)find_oligo, csplot_hash);
	    break;

        }
        break;

    case OBJ_GET_BRIEF:
	sprintf(buf,
		"Oligo: %c#%"PRIrec"@%d with %c#%"PRIrec"@%d, "
		"len %d, match %2.2f%%",
		obj->c1 > 0 ? '+' : '-',
		io_clnbr(find_oligo->io, ABS(obj->c1)), obj->pos1,
		obj->c2 > 0 ? '+' : '-',
		io_clnbr(find_oligo->io, ABS(obj->c2)), obj->pos2,
		obj->length, (float)obj->score / obj->length * 100.0);
	return buf;
    }

    return NULL;
}