Esempio n. 1
0
bool Tween::interpolate_property(Object *p_object
	, String p_property
	, Variant p_initial_val
	, Variant p_final_val
	, real_t p_times_in_sec
	, TransitionType p_trans_type
	, EaseType p_ease_type
	, real_t p_delay
) {
	if(pending_update != 0) {
		_add_pending_command("interpolate_property"
			, p_object
			, p_property
			, p_initial_val
			, p_final_val
			, p_times_in_sec
			, p_trans_type
			, p_ease_type
			, p_delay
		);
		return true;
	}
	// convert INT to REAL is better for interpolaters
	if(p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
	if(p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();

	ERR_FAIL_COND_V(p_object == NULL, false);
	ERR_FAIL_COND_V(!ObjectDB::instance_validate(p_object), false);
	ERR_FAIL_COND_V(p_initial_val.get_type() != p_final_val.get_type(), false);
	ERR_FAIL_COND_V(p_times_in_sec <= 0, false);
	ERR_FAIL_COND_V(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false);
	ERR_FAIL_COND_V(p_ease_type < 0 || p_ease_type >= EASE_COUNT, false);
	ERR_FAIL_COND_V(p_delay < 0, false);

	bool prop_valid = false;
	p_object->get(p_property,&prop_valid);
	ERR_FAIL_COND_V(!prop_valid, false);

	InterpolateData data;
	data.active = true;
	data.type = INTER_PROPERTY;
	data.finish = false;
	data.elapsed = 0;

	data.id = p_object->get_instance_ID();
	data.key = p_property;
	data.initial_val = p_initial_val;
	data.final_val = p_final_val;
	data.times_in_sec = p_times_in_sec;
	data.trans_type = p_trans_type;
	data.ease_type = p_ease_type;
	data.delay = p_delay;

	if(!_calc_delta_val(data.initial_val, data.final_val, data.delta_val))
		return false;

	interpolates.push_back(data);
	return true;
}
Esempio n. 2
0
bool Tween::interpolate_method(Object *p_object
	, String p_method
	, Variant p_initial_val
	, Variant p_final_val
	, real_t p_times_in_sec
	, TransitionType p_trans_type
	, EaseType p_ease_type
	, real_t p_delay
) {
	if(pending_update != 0) {
		_add_pending_command("interpolate_method"
			, p_object
			, p_method
			, p_initial_val
			, p_final_val
			, p_times_in_sec
			, p_trans_type
			, p_ease_type
			, p_delay
		);
		return true;
	}
	// convert INT to REAL is better for interpolaters
	if(p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
	if(p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();

	ERR_FAIL_COND_V(p_object == NULL, false);
	ERR_FAIL_COND_V(p_initial_val.get_type() != p_final_val.get_type(), false);
	ERR_FAIL_COND_V(p_times_in_sec <= 0, false);
	ERR_FAIL_COND_V(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false);
	ERR_FAIL_COND_V(p_ease_type < 0 || p_ease_type >= EASE_COUNT, false);
	ERR_FAIL_COND_V(p_delay < 0, false);

	ERR_EXPLAIN("Object has no method named: %s" + p_method);
	ERR_FAIL_COND_V(!p_object->has_method(p_method), false);

	InterpolateData data;
	data.active = true;
	data.type = INTER_METHOD;
	data.finish = false;
	data.elapsed = 0;

	data.id = p_object->get_instance_ID();
	data.key = p_method;
	data.initial_val = p_initial_val;
	data.final_val = p_final_val;
	data.times_in_sec = p_times_in_sec;
	data.trans_type = p_trans_type;
	data.ease_type = p_ease_type;
	data.delay = p_delay;

	if(!_calc_delta_val(data.initial_val, data.final_val, data.delta_val))
		return false;

	interpolates.push_back(data);
	return true;
}
Esempio n. 3
0
bool Tween::follow_method(Object *p_object
	, String p_method
	, Variant p_initial_val
	, Object *p_target
	, String p_target_method
	, real_t p_times_in_sec
	, TransitionType p_trans_type
	, EaseType p_ease_type
	, real_t p_delay
) {
	if(pending_update != 0) {
		_add_pending_command("follow_method"
			, p_object
			, p_method
			, p_initial_val
			, p_target
			, p_target_method
			, p_times_in_sec
			, p_trans_type
			, p_ease_type
			, p_delay
		);
		return true;
	}
	// convert INT to REAL is better for interpolaters
	if(p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();

	ERR_FAIL_COND_V(p_object == NULL, false);
	ERR_FAIL_COND_V(!ObjectDB::instance_validate(p_object), false);
	ERR_FAIL_COND_V(p_target == NULL, false);
	ERR_FAIL_COND_V(!ObjectDB::instance_validate(p_target), false);
	ERR_FAIL_COND_V(p_times_in_sec <= 0, false);
	ERR_FAIL_COND_V(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false);
	ERR_FAIL_COND_V(p_ease_type < 0 || p_ease_type >= EASE_COUNT, false);
	ERR_FAIL_COND_V(p_delay < 0, false);

	ERR_EXPLAIN("Object has no method named: %s" + p_method);
	ERR_FAIL_COND_V(!p_object->has_method(p_method), false);
	ERR_EXPLAIN("Target has no method named: %s" + p_target_method);
	ERR_FAIL_COND_V(!p_target->has_method(p_target_method), false);

	Variant::CallError error;
	Variant target_val = p_target->call(p_target_method, NULL, 0, error);
	ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK, false);

	// convert INT to REAL is better for interpolaters
	if(target_val.get_type() == Variant::INT) target_val = target_val.operator real_t();
	ERR_FAIL_COND_V(target_val.get_type() != p_initial_val.get_type(), false);

	InterpolateData data;
	data.active = true;
	data.type = FOLLOW_METHOD;
	data.finish = false;
	data.elapsed = 0;

	data.id = p_object->get_instance_ID();
	data.key = p_method;
	data.initial_val = p_initial_val;
	data.target_id = p_target->get_instance_ID();
	data.target_key = p_target_method;
	data.times_in_sec = p_times_in_sec;
	data.trans_type = p_trans_type;
	data.ease_type = p_ease_type;
	data.delay = p_delay;

	interpolates.push_back(data);
	return true;
}
Esempio n. 4
0
bool Tween::interpolate_deferred_callback(Object *p_object
	, real_t p_times_in_sec
	, String p_callback
	, VARIANT_ARG_DECLARE
) {

	if(pending_update != 0) {
		_add_pending_command("interpolate_deferred_callback"
			, p_object
			, p_times_in_sec
			, p_callback
			, p_arg1
			, p_arg2
			, p_arg3
			, p_arg4
			, p_arg5
		);
		return true;
	}
	ERR_FAIL_COND_V(p_object == NULL, false);
	ERR_FAIL_COND_V(!ObjectDB::instance_validate(p_object), false);
	ERR_FAIL_COND_V(p_times_in_sec < 0, false);

	ERR_EXPLAIN("Object has no callback named: %s" + p_callback);
	ERR_FAIL_COND_V(!p_object->has_method(p_callback), false);

	InterpolateData data;
	data.active = true;
	data.type = INTER_CALLBACK;
	data.finish = false;
	data.call_deferred = true;
	data.elapsed = 0;

	data.id = p_object->get_instance_ID();
	data.key = p_callback;
	data.times_in_sec = p_times_in_sec;
	data.delay = 0;

	int args=0;
	if (p_arg5.get_type()!=Variant::NIL)
		args=5;
	else if (p_arg4.get_type()!=Variant::NIL)
		args=4;
	else if (p_arg3.get_type()!=Variant::NIL)
		args=3;
	else if (p_arg2.get_type()!=Variant::NIL)
		args=2;
	else if (p_arg1.get_type()!=Variant::NIL)
		args=1;
	else
		args=0;

	data.args = args;
	data.arg[0] = p_arg1;
	data.arg[1] = p_arg2;
	data.arg[2] = p_arg3;
	data.arg[3] = p_arg4;
	data.arg[4] = p_arg5;

	pending_update ++;
	interpolates.push_back(data);
	pending_update --;
	return true;
}