コード例 #1
0
ファイル: verse_client.c プロジェクト: zdenek-perutka/verse
/**
 * \brief Callback function for receiving accept connect request.
 *
 * \param[in]	session_id	ID of session with the Verse server, because Verse
 * client could be connected to more Verse server.
 * \param[in]	user_id		unique ID of user.
 * \param[in]	avatar_id	unique ID of avatar.
 */
static void cb_receive_connect_accept(const uint8_t session_id,
      const uint16_t user_id,
      const uint32_t avatar_id)
{
	printf("%s() session_id: %d, user_id: %d, avatar_id: %d\n",
			__FUNCTION__, session_id, user_id, avatar_id);

	my_avatar_id = avatar_id;
	my_user_id = user_id;

	/* When client receive connect accept, then it is ready to subscribe
	 * to the root node of the node tree. Id of root node is still 0. This
	 * function is called with level 1. It means, that this client will be
	 * subscribed to the root node and its child nodes (1, 2, 3) */
	vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, 0, 0, 0);

	/* Check if server allow double subscribe? */
	vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, 1, 0, 0);

	/* Try to create new node */
	vrs_send_node_create(session_id, VRS_DEFAULT_PRIORITY, MY_TEST_NODE_CT);

	/* Change FPS value */
	vrs_send_fps(session_id, VRS_DEFAULT_PRIORITY+1, FPS);
}
コード例 #2
0
static void cb_receive_connect_accept(const uint8 session_id,
      const uint16 user_id,
      const uint32 avatar_id)
{
#if NO_DEBUG_PRINT != 1
	printf("%s() session_id: %d, user_id: %d, avatar_id: %d\n",
			__FUNCTION__, session_id, user_id, avatar_id);
#endif

	ctx->verse.avatar_id = avatar_id;
	ctx->verse.user_id = user_id;

	/* Subscribe to avatar node */
	vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, avatar_id, 0, 0);

	/* Subscribe to parent of scenes */
	vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, VRS_SCENE_PARENT_NODE_ID, 0, 0);

}
コード例 #3
0
static void cb_receive_connect_accept(const uint8 session_id,
      const uint16 user_id,
      const uint32 avatar_id)
{
#if NO_DEBUG_PRINT != 1
	printf("%s() session_id: %d, user_id: %d, avatar_id: %d\n",
			__FUNCTION__, session_id, user_id, avatar_id);
#endif

	ctx->verse.avatar_id = avatar_id;
	ctx->verse.user_id = user_id;

	/* Subscribe to avatar node */
	vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, avatar_id, 0, 0);

	/* TODO: Create new particle scene node only when there is no other particle scene node */
	vrs_send_node_create(session_id, VRS_DEFAULT_PRIORITY, PARTICLE_SCENE_NODE);

	/* Create new node (particle sender node) */
	vrs_send_node_create(session_id, VRS_DEFAULT_PRIORITY, PARTICLE_SENDER_NODE);
}
コード例 #4
0
static void cb_receive_node_create(const uint8 session_id,
		const uint32 node_id,
		const uint32 parent_id,
		const uint16 user_id,
		const uint16 custom_type)
{
#if NO_DEBUG_PRINT != 1
	printf("%s() session_id: %d, node_id: %d, parent_id: %d, user_id: %d, custom_type: %d\n",
			__FUNCTION__, session_id, node_id, parent_id, user_id, custom_type);
#endif

	if(user_id != ctx->verse.user_id) {
		return;
	}

	switch (custom_type) {
	case PARTICLE_SCENE_NODE:
		if(ctx->verse.particle_scene_node == NULL &&
				parent_id == VRS_SCENE_PARENT_NODE_ID ) {
			/* Create node of particle scene */
			ctx->verse.particle_scene_node = create_particle_scene_node(node_id);

			/* Add node to lookup table*/
			lu_add_item(ctx->verse.lu_table, node_id, ctx->verse.particle_scene_node);

			/* Subscribe to this node */
			vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0);
		}
		break;
	case PARTICLE_SENDER_NODE:
		if(parent_id == ctx->verse.particle_scene_node->node_id &&
			v_list_count_items(&ctx->verse.particle_scene_node->senders) < (int32)ctx->sender_count)
		{
			struct ParticleSenderNode *sender_node = create_particle_sender_node(ctx->verse.particle_scene_node, node_id);
			struct Particle_Sender *sender;

			/* Find unassigned sender */
			sender = ctx->senders.first;
			while(sender != NULL) {
				if(sender->sender_node == NULL) {
					break;
				}
				sender = sender->next;
			}

			/* Set up references */
			if(sender != NULL) {
				printf("Info: setting up references\n");
				sender_node->sender = sender;
				sender->sender_node = sender_node;
			} else {
				printf("Error: no remaining free sender\n");
			}

			/* Add node to lookup table*/
			lu_add_item(ctx->verse.lu_table, node_id, sender_node);

			v_list_add_tail(&ctx->verse.particle_scene_node->senders, sender_node);

			vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0);
		}
		break;
	}
}
コード例 #5
0
static void cb_receive_node_create(const uint8 session_id,
		const uint32 node_id,
		const uint32 parent_id,
		const uint16 user_id,
		const uint16 custom_type)
{
	struct ParticleSenderNode *sender_node;
	struct Particle_Sender *sender;

#if NO_DEBUG_PRINT != 1
	printf("%s() session_id: %d, node_id: %d, parent_id: %d, user_id: %d, custom_type: %d\n",
			__FUNCTION__, session_id, node_id, parent_id, user_id, custom_type);
#endif

	if(user_id != ctx->verse.user_id) {
		return;
	}

	if(parent_id == ctx->verse.avatar_id) {
		switch(custom_type) {
		case PARTICLE_SCENE_NODE:
			if(ctx->verse.particle_scene_node == NULL) {
				/* Create node of particle scene */
				ctx->verse.particle_scene_node = create_particle_scene_node(node_id);

				/* Add node to lookup table*/
				lu_add_item(ctx->verse.lu_table, node_id, ctx->verse.particle_scene_node);

				vrs_send_node_link(session_id, VRS_DEFAULT_PRIORITY, VRS_SCENE_PARENT_NODE_ID, node_id);
				vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0);
				vrs_send_taggroup_create(session_id, VRS_DEFAULT_PRIORITY, node_id, PARTICLE_SCENE_TG);
			}
			break;
		case PARTICLE_SENDER_NODE:
			if(v_list_count_items(&ctx->verse.particle_scene_node->senders) < (int32)ctx->sender_count) {
				sender_node = create_particle_sender_node(ctx->verse.particle_scene_node, node_id);

				/* Find unassigned sender */
				sender = ctx->senders.first;
				while(sender != NULL) {
					if(sender->sender_node == NULL) {
						break;
					}
					sender = sender->next;
				}

				/* Create reference */
				if(sender != NULL) {
					sender->sender_node = sender_node;
					sender_node->sender = sender;
				}

				/* Is it sender node created by this client */
				if(parent_id == ctx->verse.avatar_id) {
					ctx->sender = sender;
				}

				/* Add node to lookup table*/
				lu_add_item(ctx->verse.lu_table, node_id, sender_node);

				v_list_add_tail(&ctx->verse.particle_scene_node->senders, sender_node);

				vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY,
						node_id, 0, 0);
				vrs_send_node_link(session_id, VRS_DEFAULT_PRIORITY,
						ctx->verse.particle_scene_node->node_id, node_id);
				vrs_send_taggroup_create(session_id, VRS_DEFAULT_PRIORITY,
						node_id, PARTICLE_SENDER_TG);
				vrs_send_layer_create(session_id, VRS_DEFAULT_PRIORITY,
						node_id, 0xFFFF, VRS_VALUE_TYPE_REAL32, 3, PARTICLE_POS_LAYER);
			}
			break;
		}
	}
}
コード例 #6
0
ファイル: verse_client.c プロジェクト: zdenek-perutka/verse
/**
 * \brief This function is callback function for receiving of node_create
 * command. It means, that this function is called, when verse_callback_update
 * is executed and there are any data in appropriate incoming queue.
 *
 * \param[in]	session_id	The ID of session with some verse server
 * \param[in]	node_id		The ID of new node
 * \param[in]	parent_id	The ID of parent node
 * \param[in]	user_id		The User ID of the owner of this node
 */
static void cb_receive_node_create(const uint8_t session_id,
		const uint32_t node_id,
		const uint32_t parent_id,
		const uint16_t user_id,
		const uint16_t custom_type)
{
	printf("%s() session_id: %d, node_id: %d, parent_id: %d, user_id: %d, custom_type: %d\n",
			__FUNCTION__, session_id, node_id, parent_id, user_id, custom_type);

	/* Is node special node? */
	if(node_id==VRS_ROOT_NODE_ID) {
		printf("\tRoot Node\n");
	} else if(node_id==VRS_AVATAR_PARENT_NODE_ID) {
		printf("\tParent of Avatar Nodes\n");
		/* Try to delete node, that could not be deleted */
		vrs_send_node_destroy(session_id, VRS_DEFAULT_PRIORITY, node_id);
	} else if(node_id==VRS_USERS_PARENT_NODE_ID) {
		printf("\tParent of User Nodes\n");
		/* Example of node subscribe command */
		vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0);
	} else if(node_id==VRS_SCENE_PARENT_NODE_ID) {
		printf("\tParent of Scene Nodes\n");
		/* Example of node un-subscribe command */
		vrs_send_node_unsubscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0);
	} else if(node_id==VRS_ROOT_NODE_ID) {
		printf("\tUser Node of SuperUser\n");
	} else if(parent_id==VRS_USERS_PARENT_NODE_ID) {
		printf("\tUser Node\n");
	} else if(node_id==VRS_RESERVED_NODE_ID) {
		printf("\tReservered Node ID (should never be received by client from server)\n");
	} else if(node_id>=VRS_FIRST_COMMON_NODE_ID) {
		printf("\tCommon Node\n");
	}

	/* My Avatar Node */
	if(node_id == my_avatar_id) {
		/* Client should subscribe to his avarat node to be able receive information
		 * about nodes, that was created by this client */
		printf("\tMy Avatar Node\n");
		vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0);

		/* Test of sending wrong node_perm command (client doesn't own this node) */
		vrs_send_node_perm(session_id, VRS_DEFAULT_PRIORITY, node_id, my_user_id, VRS_PERM_NODE_READ | VRS_PERM_NODE_WRITE);
	}

	/* Who is owner of this node? */
	if(my_user_id != -1 && my_user_id == user_id) {
		printf("\tNode owned by me\n");
	} else if(user_id==VRS_SUPER_USER_UID) {
		printf("\tNode owned by super user (server)\n");
	} else {
		printf("\tNode owned by someone else\n");
	}

	/* Who created this node? */
	if(my_avatar_id != -1 && my_avatar_id == parent_id) {
		printf("\tNode created from this client\n");
		printf("\tParent of this node is my avatar node: %d\n", parent_id);
	} else {
		printf("\tNode created by somebody else\n");
		printf("\tParent of this node is: %d\n", parent_id);
	}

	/* Example of subscribing to node created from this client */
	if((my_user_id != -1 && my_user_id == user_id) &&
			(my_avatar_id != -1 && my_avatar_id == parent_id))
	{
		my_test_node_id = node_id;

		/* Test of subscribing to my own node */
		vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0);

		/* Test of changing priority of my node */
		vrs_send_node_prio(session_id, VRS_DEFAULT_PRIORITY, node_id, my_test_node_prio);

		/* Test of changing parent of my node */
		vrs_send_node_link(session_id, VRS_DEFAULT_PRIORITY, VRS_SCENE_PARENT_NODE_ID, node_id);

		/* Test of adding new node permission */
		vrs_send_node_perm(session_id, VRS_DEFAULT_PRIORITY, node_id, 100, VRS_PERM_NODE_READ | VRS_PERM_NODE_WRITE);
	}
}