コード例 #1
0
ファイル: gdnet_host.cpp プロジェクト: jrimclean/gdnet
void GDNetHost::send_messages() {
	while (!_message_queue.is_empty()) {
		GDNetMessage* message = _message_queue.pop();

		int flags = 0;

		switch (message->get_type()) {
			case GDNetMessage::UNSEQUENCED:
				flags |= ENET_PACKET_FLAG_UNSEQUENCED;
				break;

			case GDNetMessage::RELIABLE:
				flags |= ENET_PACKET_FLAG_RELIABLE;
				break;

			default:
				break;
		}

		ByteArray::Read r = message->get_packet().read();
		ENetPacket * enet_packet = enet_packet_create(r.ptr(), message->get_packet().size(), flags);

		if (enet_packet != NULL) {
			if (message->is_broadcast()) {
				enet_host_broadcast(_host, message->get_channel_id(), enet_packet);
			} else {
				enet_peer_send(&_host->peers[message->get_peer_id()], message->get_channel_id(), enet_packet);
			}
		}

		memdelete(message);
	}
}
コード例 #2
0
ファイル: addon_editor_plugin.cpp プロジェクト: RYG81/godot
void EditorAddonLibrary::_http_request_completed(int p_status, int p_code, const StringArray& headers, const ByteArray& p_data) {


	String str;

	{
		int datalen=p_data.size();
		ByteArray::Read r = p_data.read();
		str.parse_utf8((const char*)r.ptr(),datalen);
	}

	print_line("response: "+itos(p_status)+" code: "+itos(p_code));
	Dictionary d;
	d.parse_json(str);

	print_line(Variant(d).get_construct_string());

	if (current_request=="api/configure") {

		categories->clear();
		categories->add_item("All");
		categories->set_item_metadata(0,0);
		if (d.has("categories")) {
			Array clist = d["categories"];
			for(int i=0;i<clist.size();i++) {
				Dictionary cat = clist[i];
				if (!cat.has("name") || !cat.has("id"))
					continue;
				String name=cat["name"];
				int id=cat["id"];
				categories->add_item(name);
				categories->set_item_metadata( categories->get_item_count() -1, id);
			}
		}

		_search();
	} else if (current_request=="api/search") {

		if (asset_items) {
			memdelete(asset_items);
		}

		if (asset_top_page) {
			memdelete(asset_top_page);
		}

		if (asset_bottom_page) {
			memdelete(asset_bottom_page);
		}

		int page=0;
		int pages=1;
		int page_len=10;
		int total_items=1;
		Array result;


		if (d.has("page")) {
			page=d["page"];
		}
		if (d.has("pages")) {
			pages=d["pages"];
		}
		if (d.has("page_length")) {
			page_len=d["page_length"];
		}
		if (d.has("total")) {
			total_items=d["total"];
		}
		if (d.has("result")) {
			result=d["result"];
		}

		asset_top_page = _make_pages(page,pages,page_len,total_items,result.size());
		library_vb->add_child(asset_top_page);

		asset_items = memnew( GridContainer );
		asset_items->set_columns(2);
		asset_items->add_constant_override("hseparation",10);
		asset_items->add_constant_override("vseparation",10);

		library_vb->add_child(asset_items);

		asset_bottom_page = _make_pages(page,pages,page_len,total_items,result.size());
		library_vb->add_child(asset_bottom_page);

		for(int i=0;i<result.size();i++) {

			Dictionary r = result[i];

			ERR_CONTINUE(!r.has("title"));
			ERR_CONTINUE(!r.has("asset_id"));
			ERR_CONTINUE(!r.has("author"));
			ERR_CONTINUE(!r.has("author_id"));
			ERR_CONTINUE(!r.has("category"));
			ERR_CONTINUE(!r.has("category_id"));
			ERR_CONTINUE(!r.has("rating"));
			ERR_CONTINUE(!r.has("cost"));


			EditorAssetLibraryItem *item = memnew( EditorAssetLibraryItem );
			asset_items->add_child(item);
			item->configure(r["title"],r["asset_id"],r["category"],r["category_id"],r["author"],r["author_id"],r["rating"],r["cost"]);
			item->connect("asset_selected",this,"_select_asset");
			item->connect("author_selected",this,"_select_author");
			item->connect("category_selected",this,"_category_selected");

			_request_image(item->get_instance_ID(),r["asset_id"],IMAGE_QUEUE_ICON,0);
		}
	} else if (current_request=="api/asset") {

		ERR_FAIL_COND(!d.has("info"));

		Dictionary r = d["info"];

		ERR_FAIL_COND(!r.has("title"));
		ERR_FAIL_COND(!r.has("asset_id"));
		ERR_FAIL_COND(!r.has("author"));
		ERR_FAIL_COND(!r.has("author_id"));
		ERR_FAIL_COND(!r.has("category"));
		ERR_FAIL_COND(!r.has("category_id"));
		ERR_FAIL_COND(!r.has("rating"));
		ERR_FAIL_COND(!r.has("cost"));
		ERR_FAIL_COND(!r.has("description"));

		if (description) {
			memdelete(description);
		}

		description = memnew( EditorAddonLibraryItemDescription );
		add_child(description);
		description->popup_centered_minsize();

		description->configure(r["title"],r["asset_id"],r["category"],r["category_id"],r["author"],r["author_id"],r["rating"],r["cost"],r["description"]);
		/*item->connect("asset_selected",this,"_select_asset");
		item->connect("author_selected",this,"_select_author");
		item->connect("category_selected",this,"_category_selected");*/

		_request_image(description->get_instance_ID(),r["asset_id"],IMAGE_QUEUE_ICON,0);

		if (d.has("previews")) {
			Array previews = d["previews"];

			for(int i=0;i<previews.size();i++) {


				Dictionary p=previews[i];

				ERR_CONTINUE(!p.has("id"));

				bool is_video=p.has("type") && String(p["type"])=="video";
				String video_url;
				if (is_video && p.has("link")) {
					video_url="link";
				}

				int id=p["id"];

				description->add_preview(id,is_video,video_url);

				_request_image(description->get_instance_ID(),r["asset_id"],IMAGE_QUEUE_THUMBNAIL,id);
				if (i==0) {
					_request_image(description->get_instance_ID(),r["asset_id"],IMAGE_QUEUE_SCREENSHOT,id);
				}

			}
		}
	}

}