コード例 #1
0
ファイル: stack.c プロジェクト: gderecho/stack
int free_at(struct node *current)
{
    struct node *temp;
    if(!current)
        return EXIT_SUCCESS;
    temp = current->next;
    free(current);
    return free_at(temp);
}
コード例 #2
0
ファイル: stack.c プロジェクト: gderecho/stack
int free_stack_data(struct stack *stack_)
{
    struct node *temp;
    if(!stack_)
        return EXIT_FAILURE;
    temp = stack_->head;
    stack_->head = NULL;
    return free_at(temp);
}
コード例 #3
0
ファイル: parse.c プロジェクト: Reen/gnuplot
struct at_type *
temp_at()
{
    if (at != NULL)
	free_at(at);
    
    at = (struct at_type *) gp_alloc(sizeof(struct at_type), "action table");

    memset(at, 0, sizeof(*at));		/* reset action table !!! */
    at_size = MAX_AT_LEN;

    parse_recursion_level = 0;
    parse_expression();
    return (at);
}
コード例 #4
0
ファイル: parse.c プロジェクト: Reen/gnuplot
/*
 * Syntax: set link {x2|y2} {via <expression1> inverse <expression2>}
 * Create action code tables for the functions linking primary and secondary axes.
 * expression1 maps primary coordinates into the secondary coordinate space.
 * expression2 maps secondary coordinates into the primary coordinate space.
 */
void
parse_link_via( struct udft_entry *udf )
{
    int start_token;
    
    /* Caller left us pointing at "via" or "inverse" */
    c_token++;
    start_token = c_token;
    if (END_OF_COMMAND)
	int_error(c_token,"Missing expression");

    /* Save action table for the linkage mapping */
    strcpy(c_dummy_var[0], "x");
    strcpy(c_dummy_var[1], "y");
    dummy_func = udf;
    free_at(udf->at);
    udf->at = perm_at();
    dummy_func = NULL;

    /* Save the mapping expression itself */
    m_capture(&(udf->definition), start_token, c_token - 1);
}
コード例 #5
0
	void step()
	{
		double dT = p.dT; // time delta

		// GRAVITY
		if (free_at(x, y+1))
			speed.y = min(speed.y +gravity*dT, maxFallSpd);
		else
			djump_cur = true;

		// FRICTION
		if (speed.x > 0)
			speed.x = max(speed.x - deceleration*dT, 0);
		else if (speed.x < 0)
			speed.x = min(speed.x + deceleration*dT, 0);

		// JUMPING
		if (upressed)
		{
			if (!free_at(x, y+1))
				speed.y = -jump_height;
			else if (djump_cur)
			{
				djump_cur = false;
				speed.y = -djump_height;	
			}
		}

		int sign = rkey-lkey;
		if (sign != 0)
			speed.x = clamp(speed.x +acceleration*sign*dT, -maxSpd, maxSpd);

		// Precise collision checking....
		// Inefficient (could binary search at least) but it's just a demo
		sign = sign(speed.x);
		int xcur = abs((int) speed.x*dT);
		vfrac.x += abs(frac(speed.x*dT));
		if (vfrac.x >= 1)
		{
			vfrac.x -= 1.0;
			xcur++;
		}
		for (; xcur > 0; xcur--)
		{
			if (free_at(x+sign, y))
				x += sign;
			else
			{
				speed.x = 0;
				break;
			}
		}


		sign = sign(speed.y);
		int ycur = abs((int) speed.y*dT);
		vfrac.y += abs(frac(speed.y*dT));
		if (vfrac.y >= 1)
		{
			vfrac.y -= 1.0;
			ycur++;
		}
		for (; ycur > 0; ycur--)
		{
			if (free_at(x, y+sign))
				y += sign;
			else
			{
				speed.y = 0;
				break;
			}
		}

		// if (!free_at(p.mouseX, p.mouseY)) sprite = spr_left;
		// else sprite = spr_right;
		// draw::rect({p.mouseX, p.mouseY, bounds.w, bounds.h});

		upressed = false;


		// SPRITES
		if (speed.x < 0 && sprite != spr_left)
			sprite = spr_left;
		else if (speed.x > 0 && sprite != spr_right)
			sprite = spr_right;
	}