1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "action_block.h"
22 #include "action_factory.h"
24 using namespace NLMISC
;
26 namespace CLFECOMMON
{
29 CActionBlock::~CActionBlock()
32 for (i
=0; i
<Actions
.size(); ++i
)
33 CActionFactory::getInstance()->remove(Actions
[i
]);
36 void CActionBlock::serial(CBitMemStream
&msg
)
38 if (!msg
.isReading() && Cycle
== 0)
39 nlwarning("Packing action block (%d actions) with unset date", Actions
.size());
45 uint8 num
= (uint8
)Actions
.size();
48 //static char buff[1024], cat[128];
52 //sprintf(buff, "Unpack[%d]:", Cycle);
55 CAction
*action
= CActionFactory::getInstance()->unpack(msg
, false);
58 Success
= false; // reject an incorrect block
62 //sprintf(cat, " %d(%d bits)", action->Code, action->size());
64 Actions
.push_back(action
);
70 //sprintf(buff, "Pack[%d]:", Cycle);
73 uint msgPosBefore
= msg
.getPosInBit();
74 CActionFactory::getInstance()->pack(Actions
[i
], msg
, false);
75 uint msgPosAfter
= msg
.getPosInBit();
77 uint actionSize
= CActionFactory::getInstance()->size(Actions
[i
]);
79 if (actionSize
< msgPosAfter
-msgPosBefore
)
80 nlwarning("Action %d declares a lower size (%d bits) from what it actually serialises (%d bits)", Actions
[i
]->Code
, actionSize
, msgPosAfter
-msgPosBefore
);
81 //sprintf(cat, " %d(%d bits)", Actions[i]->Code, Actions[i]->size());
85 //nlinfo("Block: %s", buff);