コード例 #1
0
ファイル: tag.c プロジェクト: raumzeitlabor/mpd
static void
tag_add_item_internal(struct tag *tag, enum tag_type type,
		      const char *value, size_t len)
{
	unsigned int i = tag->num_items;
	char *p;

	p = fix_tag_value(value, len);
	if (p != NULL) {
		value = p;
		len = strlen(value);
	}

	tag->num_items++;

	if (tag->items != bulk.items)
		/* bulk mode disabled */
		tag->items = g_realloc(tag->items, items_size(tag));
	else if (tag->num_items >= BULK_MAX) {
		/* bulk list already full - switch back to non-bulk */
		assert(bulk.busy);

		tag->items = g_malloc(items_size(tag));
		memcpy(tag->items, bulk.items,
		       items_size(tag) - sizeof(struct tag_item *));
	}

	g_mutex_lock(tag_pool_lock);
	tag->items[i] = tag_pool_get_item(type, value, len);
	g_mutex_unlock(tag_pool_lock);

	g_free(p);
}
コード例 #2
0
ファイル: ItemInfo.hpp プロジェクト: mambabin/GreatDragon
		inline ItemInfo * mutable_items(int index) {
			if(index < 0 || index >= items_size()) {
				Debug_LogCallStack();
				assert(0);
			}
			return &items_[index];
		}
コード例 #3
0
ファイル: ItemInfo.hpp プロジェクト: mambabin/GreatDragon
		inline const ItemInfo & items(int index) const {
			if(index < 0 || index >= items_size()) {
				Debug_LogCallStack();
				assert(0);
			}
			return items_[index];
		}
コード例 #4
0
ファイル: tag.c プロジェクト: raumzeitlabor/mpd
struct tag *
tag_merge(const struct tag *base, const struct tag *add)
{
	struct tag *ret;
	unsigned n;

	assert(base != NULL);
	assert(add != NULL);

	/* allocate new tag object */

	ret = tag_new();
	ret->time = add->time > 0 ? add->time : base->time;
	ret->num_items = base->num_items + add->num_items;
	ret->items = ret->num_items > 0 ? g_malloc(items_size(ret)) : NULL;

	g_mutex_lock(tag_pool_lock);

	/* copy all items from "add" */

	for (unsigned i = 0; i < add->num_items; ++i)
		ret->items[i] = tag_pool_dup_item(add->items[i]);

	n = add->num_items;

	/* copy additional items from "base" */

	for (unsigned i = 0; i < base->num_items; ++i)
		if (!tag_has_type(add, base->items[i]->type))
			ret->items[n++] = tag_pool_dup_item(base->items[i]);

	g_mutex_unlock(tag_pool_lock);

	assert(n <= ret->num_items);

	if (n < ret->num_items) {
		/* some tags were not copied - shrink ret->items */
		assert(n > 0);

		ret->num_items = n;
		ret->items = g_realloc(ret->items, items_size(ret));
	}

	return ret;
}
コード例 #5
0
ファイル: tag.c プロジェクト: raumzeitlabor/mpd
void tag_end_add(struct tag *tag)
{
	if (tag->items == bulk.items) {
		assert(tag->num_items <= BULK_MAX);

		if (tag->num_items > 0) {
			/* copy the tag items from the bulk list over
			   to a new list (which fits exactly) */
			tag->items = g_malloc(items_size(tag));
			memcpy(tag->items, bulk.items, items_size(tag));
		} else
			tag->items = NULL;
	}

#ifndef NDEBUG
	bulk.busy = false;
#endif
}
コード例 #6
0
ファイル: ItemInfo.hpp プロジェクト: mambabin/GreatDragon
		void ToPB(PB_ItemPackage *pb_) const {
			pb_->Clear();
			for(int i = 0; i < items_size(); i++)
				items_[i].ToPB(pb_->add_items());
			pb_->set_money(money_);
			pb_->set_rmb(rmb_);
			pb_->set_validNumEquipment(validNumEquipment_);
			pb_->set_validNumGoods(validNumGoods_);
			pb_->set_validNumGem(validNumGem_);
			pb_->set_soul(soul_);
			pb_->set_smallSoul(smallSoul_);
			pb_->set_mediumSoul(mediumSoul_);
			pb_->set_bigSoul(bigSoul_);
			pb_->set_perfectSoul(perfectSoul_);
			pb_->set_honor(honor_);
			pb_->set_durability(durability_);
			pb_->set_totalRMB(totalRMB_);
			pb_->set_soulStone(soulStone_);
			pb_->set_pkScore(pkScore_);
			pb_->set_vip(vip_);
			pb_->set_godScore(godScore_);
			pb_->set_subRMB(subRMB_);
			for(int i = 0; i < wings_size(); i++)
				pb_->add_wings(wings_[i]);
			for(int i = 0; i < fashions_size(); i++)
				fashions_[i].ToPB(pb_->add_fashions());
			pb_->set_lovePoint(lovePoint_);
			for(int i = 0; i < equips_size(); i++)
				equips_[i].ToPB(pb_->add_equips());
			pb_->set_pkScoreActive(pkScoreActive_);
			pb_->set_rmbActive(rmbActive_);
			pb_->set_totalCost(totalCost_);
			pb_->set_blessActive(blessActive_);
			for(int i = 0; i < transforms_size(); i++)
				transforms_[i].ToPB(pb_->add_transforms());
			pb_->set_activeCost(activeCost_);
			pb_->set_activeCostEndTime(activeCostEndTime_);
			for(int i = 0; i < rides_size(); i++)
				rides_[i].ToPB(pb_->add_rides());
			for(int i = 0; i < godShips_size(); i++)
				godShips_[i].ToPB(pb_->add_godShips());
			for(int i = 0; i < godShipsPackage_size(); i++)
				pb_->add_godShipsPackage(godShipsPackage_[i]);
			pb_->set_ridesFood(ridesFood_);
			pb_->set_openServerScore(openServerScore_);
			pb_->set_pkStatus(pkStatus_);
		}
コード例 #7
0
ファイル: tag.c プロジェクト: raumzeitlabor/mpd
struct tag *tag_dup(const struct tag *tag)
{
	struct tag *ret;

	if (!tag)
		return NULL;

	ret = tag_new();
	ret->time = tag->time;
	ret->num_items = tag->num_items;
	ret->items = ret->num_items > 0 ? g_malloc(items_size(tag)) : NULL;

	g_mutex_lock(tag_pool_lock);
	for (unsigned i = 0; i < tag->num_items; i++)
		ret->items[i] = tag_pool_dup_item(tag->items[i]);
	g_mutex_unlock(tag_pool_lock);

	return ret;
}
コード例 #8
0
ファイル: tag.c プロジェクト: raumzeitlabor/mpd
static void tag_delete_item(struct tag *tag, unsigned idx)
{
	assert(idx < tag->num_items);
	tag->num_items--;

	g_mutex_lock(tag_pool_lock);
	tag_pool_put_item(tag->items[idx]);
	g_mutex_unlock(tag_pool_lock);

	if (tag->num_items - idx > 0) {
		memmove(tag->items + idx, tag->items + idx + 1,
			(tag->num_items - idx) * sizeof(tag->items[0]));
	}

	if (tag->num_items > 0) {
		tag->items = g_realloc(tag->items, items_size(tag));
	} else {
		g_free(tag->items);
		tag->items = NULL;
	}
}
コード例 #9
0
ファイル: ItemInfo.hpp プロジェクト: mambabin/GreatDragon
		void FromPB(const PB_ItemPackage *pb_) {
			for(int i = 0; i < pb_->items_size(); i++) {
				if(i < items_size())
					items_[i].FromPB(&pb_->items(i));
			}
			money_ = pb_->money();
			rmb_ = pb_->rmb();
			validNumEquipment_ = pb_->validNumEquipment();
			validNumGoods_ = pb_->validNumGoods();
			validNumGem_ = pb_->validNumGem();
			soul_ = pb_->soul();
			smallSoul_ = pb_->smallSoul();
			mediumSoul_ = pb_->mediumSoul();
			bigSoul_ = pb_->bigSoul();
			perfectSoul_ = pb_->perfectSoul();
			honor_ = pb_->honor();
			durability_ = pb_->durability();
			totalRMB_ = pb_->totalRMB();
			soulStone_ = pb_->soulStone();
			pkScore_ = pb_->pkScore();
			vip_ = pb_->vip();
			godScore_ = pb_->godScore();
			subRMB_ = pb_->subRMB();
			for(int i = 0; i < pb_->wings_size(); i++) {
				if(i < wings_size())
					wings_[i] = pb_->wings(i);
			}
			for(int i = 0; i < pb_->fashions_size(); i++) {
				if(i < fashions_size())
					fashions_[i].FromPB(&pb_->fashions(i));
			}
			lovePoint_ = pb_->lovePoint();
			for(int i = 0; i < pb_->equips_size(); i++) {
				if(i < equips_size())
					equips_[i].FromPB(&pb_->equips(i));
			}
			pkScoreActive_ = pb_->pkScoreActive();
			rmbActive_ = pb_->rmbActive();
			totalCost_ = pb_->totalCost();
			blessActive_ = pb_->blessActive();
			for(int i = 0; i < pb_->transforms_size(); i++) {
				if(i < transforms_size())
					transforms_[i].FromPB(&pb_->transforms(i));
			}
			activeCost_ = pb_->activeCost();
			activeCostEndTime_ = pb_->activeCostEndTime();
			for(int i = 0; i < pb_->rides_size(); i++) {
				if(i < rides_size())
					rides_[i].FromPB(&pb_->rides(i));
			}
			for(int i = 0; i < pb_->godShips_size(); i++) {
				if(i < godShips_size())
					godShips_[i].FromPB(&pb_->godShips(i));
			}
			for(int i = 0; i < pb_->godShipsPackage_size(); i++) {
				if(i < godShipsPackage_size())
					godShipsPackage_[i] = pb_->godShipsPackage(i);
			}
			ridesFood_ = pb_->ridesFood();
			openServerScore_ = pb_->openServerScore();
			pkStatus_ = pb_->pkStatus();
		}