浏览代码

Added move constructors for minimum required Bonus system`s classes

AlexVinS 9 年之前
父节点
当前提交
629922f43e
共有 4 个文件被更改,包括 53 次插入1 次删除
  1. 28 0
      lib/CGameState.cpp
  2. 3 0
      lib/CPlayerState.h
  3. 20 0
      lib/HeroBonus.cpp
  4. 2 1
      lib/HeroBonus.h

+ 28 - 0
lib/CGameState.cpp

@@ -2924,6 +2924,25 @@ PlayerState::PlayerState()
 	setNodeType(PLAYER);
 }
 
+PlayerState::PlayerState(PlayerState && other):
+	CBonusSystemNode(std::move(other)),
+	color(other.color),
+	human(other.human),
+	team(other.team),
+	resources(other.resources),
+	enteredWinningCheatCode(other.enteredWinningCheatCode),
+	enteredLosingCheatCode(other.enteredLosingCheatCode),
+	status(other.status),
+	daysWithoutCastle(other.daysWithoutCastle)
+{
+	std::swap(visitedObjects, other.visitedObjects);
+	std::swap(heroes, other.heroes);
+	std::swap(towns, other.towns);
+	std::swap(availableHeroes, other.availableHeroes);
+	std::swap(dwellings, other.dwellings);
+	std::swap(quests, other.quests);
+}
+
 std::string PlayerState::nodeName() const
 {
 	return "Player " + (color.getNum() < VLC->generaltexth->capColors.size() ? VLC->generaltexth->capColors[color.getNum()] : boost::lexical_cast<std::string>(color));
@@ -3223,6 +3242,15 @@ TeamState::TeamState()
 	setNodeType(TEAM);
 }
 
+TeamState::TeamState(TeamState && other):
+	CBonusSystemNode(std::move(other)),
+	id(other.id)
+{
+	std::swap(players, other.players);
+	std::swap(fogOfWarMap, other.fogOfWarMap);
+}
+
+
 CRandomGenerator & CGameState::getRandomGenerator()
 {
 	//logGlobal->traceStream() << "Fetching CGameState::rand with seed " << rand.nextInt();

+ 3 - 0
lib/CPlayerState.h

@@ -35,6 +35,8 @@ public:
 	boost::optional<ui8> daysWithoutCastle;
 
 	PlayerState();
+	PlayerState(PlayerState && other);
+
 	std::string nodeName() const override;
 
 	template <typename Handler> void serialize(Handler &h, const int version)
@@ -56,6 +58,7 @@ public:
 	std::vector<std::vector<std::vector<ui8> > >  fogOfWarMap; //true - visible, false - hidden
 
 	TeamState();
+	TeamState(TeamState && other);
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{

+ 20 - 0
lib/HeroBonus.cpp

@@ -709,6 +709,26 @@ CBonusSystemNode::CBonusSystemNode() : bonuses(true), exportedBonuses(true), nod
 {
 }
 
+CBonusSystemNode::CBonusSystemNode(CBonusSystemNode && other):
+	bonuses(other.bonuses),
+	exportedBonuses(other.exportedBonuses),
+	nodeType(other.nodeType),
+	description(other.description),
+	cachedLast(0)
+{
+	//todo: move constructor for bonuslist
+	bonuses.belongsToTree = true;
+	exportedBonuses.belongsToTree = true;
+
+	std::swap(parents, other.parents);
+	std::swap(children, other.children);
+
+	//TODO: move cache
+
+	//cachedBonuses
+	//cachedRequests
+}
+
 CBonusSystemNode::~CBonusSystemNode()
 {
 	detachFromAll();

+ 2 - 1
lib/HeroBonus.h

@@ -495,6 +495,7 @@ public:
 		return bonuses.end();
 	}
 
+	friend class CBonusSystemNode;
 	//friend inline std::vector<Bonus*>::iterator range_begin(BonusList & x);
 	//friend inline std::vector<Bonus*>::iterator range_end(BonusList & x);
 };
@@ -647,8 +648,8 @@ private:
 	const TBonusListPtr getAllBonusesWithoutCaching(const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root = nullptr) const;
 
 public:
-
 	explicit CBonusSystemNode();
+	CBonusSystemNode(CBonusSystemNode && other);
 	virtual ~CBonusSystemNode();
 
 	void limitBonuses(const BonusList &allBonuses, BonusList &out) const; //out will bo populed with bonuses that are not limited here