/**
 * When receiver set up trigger, then sender sends particle position
 * each frame.
 */
static void verse_send_data(void)
{
	if(ctx->sender == NULL) return;

	pthread_mutex_lock(&ctx->sender->timer->mutex);

	if(ctx->sender->timer->run == 1) {
		uint16 item_id;

		/* Send position for current frame */
		if(ctx->sender->timer->frame >=0 &&
				ctx->sender->timer->frame < ctx->pd->frame_count)
		{

			/* Send current frame */
			vrs_send_tag_set_value(ctx->verse.session_id,
					VRS_DEFAULT_PRIORITY,
					ctx->sender->sender_node->node_id,
					ctx->sender->sender_node->particle_taggroup_id,
					ctx->sender->sender_node->particle_frame_tag_id,
					VRS_VALUE_TYPE_UINT16,
					1,
					&ctx->sender->timer->frame);

			/* For all particles of sender ... */
			for(item_id = 0; item_id < ctx->pd->particle_count; item_id++) {
				/* Send all active particles */
				if(ctx->pd->particles[item_id].states[ctx->sender->timer->frame].state == PARTICLE_STATE_ACTIVE) {
					vrs_send_layer_set_value(ctx->verse.session_id,
							VRS_DEFAULT_PRIORITY,
							ctx->sender->sender_node->node_id,
							ctx->sender->sender_node->particle_layer_id,
							item_id,
							VRS_VALUE_TYPE_REAL32,
							3,
							ctx->pd->particles[item_id].states[ctx->sender->timer->frame].pos);
				}
			}
		}

		/* When animation is at the end, then "delete" particles */
		if(ctx->sender->timer->tot_frame >=0 &&
				ctx->sender->timer->frame == 0)
		{
			/* For all particles of sender ... */
			for(item_id = 0; item_id < ctx->pd->particle_count; item_id++) {
				/* Unset value (delete position) */
				vrs_send_layer_unset_value(ctx->verse.session_id,
						VRS_DEFAULT_PRIORITY,
						ctx->sender->sender_node->node_id,
						ctx->sender->sender_node->particle_layer_id,
						item_id);
			}
		}
	}

	pthread_mutex_unlock(&ctx->sender->timer->mutex);
}
Example #2
0
static void cb_receive_tag_create(const uint8_t session_id,
		const uint32_t node_id,
		const uint16_t taggroup_id,
		const uint16_t tag_id,
		const uint8_t data_type,
		const uint8_t count,
		const uint16_t custom_type)
{
	printf("%s() session_id: %d, node_id: %d, taggroup_id: %d, tag_id: %d, data_type: %d, count: %d, custom_type: %d\n",
				__FUNCTION__, session_id, node_id, taggroup_id, tag_id, data_type, count, custom_type);

	if(node_id == my_test_node_id && taggroup_id == my_test_taggroup_id) {
		void *value = NULL;
		uint8_t uint8_t_val[4] = {123, 124, 125, 126};
		uint16_t uint16_t_val[4] = {1234, 456, 7890, 4321};
		uint32_t uint32_t_val[4] = {12345, 67890, 98765, 43210};
		uint64_t uint64_t_val[4] = {123456, 789012, 345678, 9012345};
		float real16_t_val[4] = {123.45, 678.90, -123.45, -678.90};
		float real32_t_val[4] = {1234.567, -8901.234, 5678.901, -2345.678};
		double real64_t_val[4] = {-1234567.890, 0.1234, 100000.9999, -0.000001234};
		char *string8_t_val = "Ahoj";

		/* Test sending some values of tag types */
		switch(data_type) {
		case VRS_VALUE_TYPE_UINT8:
			value = uint8_t_val;
			break;
		case VRS_VALUE_TYPE_UINT16:
			value = uint16_t_val;
			break;
		case VRS_VALUE_TYPE_UINT32:
			value = uint32_t_val;
			break;
		case VRS_VALUE_TYPE_UINT64:
			value = uint64_t_val;
			break;
		case VRS_VALUE_TYPE_REAL16:
			/* TODO: convert float values to half-float values */
			value = real16_t_val;
			break;
		case VRS_VALUE_TYPE_REAL32:
			value = real32_t_val;
			break;
		case VRS_VALUE_TYPE_REAL64:
			value = real64_t_val;
			break;
		case VRS_VALUE_TYPE_STRING8:
			value = string8_t_val;
			break;
		default:
			value = NULL;
			break;
		}

		vrs_send_tag_set_value(session_id, my_test_node_prio, node_id,
				taggroup_id, tag_id, data_type, count, value);
	}
}
static void cb_receive_tag_create(const uint8 session_id,
		const uint32 node_id,
		const uint16 taggroup_id,
		const uint16 tag_id,
		const uint8 data_type,
		const uint8 count,
		const uint16 custom_type)
{
	struct Node *node;
	struct ParticleSceneNode *scene_node;
	struct ParticleSenderNode *sender_node;

#if NO_DEBUG_PRINT != 1
	printf("%s() session_id: %d, node_id: %d, taggroup_id: %d, tag_id: %d, data_type: %d, count: %d, custom_type: %d\n",
				__FUNCTION__, session_id, node_id, taggroup_id, tag_id, data_type, count, custom_type);
#endif

	node = lu_find(ctx->verse.lu_table, node_id);

	if(node != NULL) {
		switch(node->type) {
		case PARTICLE_SCENE_NODE:
			scene_node = (struct ParticleSceneNode *)node;

			if(scene_node->particle_taggroup_id == taggroup_id) {
				if(data_type == VRS_VALUE_TYPE_UINT16 &&
						count == 1 &&
						custom_type == SENDER_COUNT_TAG)
				{
					scene_node->sender_count_tag_id = tag_id;
				}
			}
			break;
		case PARTICLE_SENDER_NODE:
			sender_node = (struct ParticleSenderNode*)node;

			if(sender_node->particle_taggroup_id == taggroup_id) {
				if(data_type == VRS_VALUE_TYPE_UINT16 &&
						count == 1 &&
						custom_type == PARTICLE_FRAME_TAG)
				{
					/* Save ID of Tag containing Frame */
					sender_node->particle_frame_tag_id = tag_id;
					/* Start sending of particles */
					pthread_mutex_lock(&sender_node->sender->timer->mutex);
					if(sender_node->sender->timer->run == 0) {
						sender_node->sender->timer->run = 1;
						sender_node->sender->timer->tot_frame = -25;
					}
					pthread_mutex_unlock(&sender_node->sender->timer->mutex);
				}
				else if(data_type == VRS_VALUE_TYPE_REAL32 &&
						count == 3 &&
						custom_type == POSITION_TAG)
				{
					/* Save ID of Tag containing position of sender */
					sender_node->pos_tag_id = tag_id;
					if(sender_node->sender != NULL) {
						vrs_send_tag_set_value(session_id, VRS_DEFAULT_PRIORITY,
								node_id, taggroup_id, tag_id, data_type, count, sender_node->sender->pos);
					}
				}
				else if(data_type == VRS_VALUE_TYPE_UINT16 &&
						count == 1 &&
						custom_type == PARTICLE_COUNT_TAG)
				{
					/* Save ID of Tag containing count of particles of this sender */
					sender_node->count_tag_id = tag_id;
					vrs_send_tag_set_value(session_id, VRS_DEFAULT_PRIORITY, node_id,
							taggroup_id, tag_id, data_type, count, &ctx->pd->particle_count);
				}
				else if(data_type == VRS_VALUE_TYPE_UINT16 && count == 1
						&& custom_type == SENDER_ID_TAG)
				{
					/* Save ID of Tag containing ID od Sender */
					sender_node->sender_id_tag_id = tag_id;
					if(sender_node->sender != NULL) {
						vrs_send_tag_set_value(session_id, VRS_DEFAULT_PRIORITY,
								node_id, taggroup_id, tag_id, data_type, count, &sender_node->sender->id);
					}
				}
			}
			break;
		}
	}

}