/**
 * 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_layer_create(const uint8_t session_id,
		const uint32_t node_id,
		const uint16_t parent_layer_id,
		const uint16_t layer_id,
		const uint8_t data_type,
		const uint8_t count,
		const uint16_t custom_type)
{
	printf("%s(): session_id: %u, node_id: %u, parent_layer_id: %d, layer_id: %d, data_type: %d, count: %d, custom_type: %d\n",
			__FUNCTION__, session_id, node_id, parent_layer_id, layer_id, data_type, count, custom_type);

	if(node_id == my_test_node_id && custom_type == MY_TEST_LAYER_CT) {
		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};
		void *value;

		my_test_layer_id = layer_id;

		/* Test of subscribing to layer */
		vrs_send_layer_subscribe(session_id, my_test_node_prio, node_id, layer_id, 0, 0);

		/* Test of creating child layer */
		vrs_send_layer_create(session_id, my_test_node_prio,
				node_id, layer_id, VRS_VALUE_TYPE_REAL32, 2, MY_TEST_CHILD_LAYER_CT);

		/* 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;
		default:
			value = NULL;
			break;
		}

		/* Test of sending set value */
		vrs_send_layer_set_value(session_id, my_test_node_prio,
				node_id, layer_id, 10, data_type, count, value);

	}

	if(node_id == my_test_node_id &&
			parent_layer_id == my_test_layer_id &&
			custom_type == MY_TEST_CHILD_LAYER_CT) {
		/* Test of destroying parent layer */
		vrs_send_layer_destroy(session_id, my_test_node_prio, node_id, parent_layer_id);
	}
}