Fix classique titles display
[ryzomcore.git] / ryzom / client / src / impulse_decoder.cpp
blobe71d13cb1476198f98444cf449964073c6c6f07f
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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/>.
19 #include "stdpch.h"
21 #include "impulse_decoder.h"
23 #include "game_share/action_factory.h"
25 using namespace std;
26 using namespace NLMISC;
27 using namespace CLFECOMMON;
30 * Constructor
32 CImpulseDecoder::CImpulseDecoder()
34 reset();
38 void CImpulseDecoder::decode(CBitMemStream &inbox, TPacketNumber receivedPacket, TPacketNumber receivedAck, TPacketNumber nextSentPacket, vector<CLFECOMMON::CAction *> &actions)
40 uint level;
42 for (level=0; level<3; ++level)
44 TPacketNumber *lAck;
45 uint channel;
47 switch (level)
49 case 0: lAck = _LastAck0; channel = 0; break;
50 case 1: lAck = _LastAck1; channel = receivedPacket&1; break;
51 case 2: lAck = _LastAck2; channel = receivedPacket&3; break;
54 bool keep = true;
55 bool checkOnce = false;
56 uint num = 0;
58 TPacketNumber lastAck = lAck[channel];
60 for(;;)
62 bool next;
63 inbox.serial(next);
65 if (!next)
66 break;
68 if (!checkOnce)
70 checkOnce = true;
71 keep = (receivedAck >= lAck[channel]);
72 if (keep)
73 lAck[channel] = nextSentPacket;
76 ++num;
77 CAction *action = CActionFactory::getInstance()->unpack(inbox, false);
79 if (keep)
81 actions.push_back(action);
82 nlinfo("CLIMPD: received new impulsion %d (len=%u) at level %d (channel %d)", action->Code, CActionFactory::getInstance()->size(action), level, channel, num, (keep) ? "" : " (discarded)", lastAck, nextSentPacket);
84 else
86 nlinfo("CLIMPD: discarded action %d (len=%u) at level %d (channel %d)", action->Code, CActionFactory::getInstance()->size(action), level, channel, num, (keep) ? "" : " (discarded)", lastAck, nextSentPacket);
87 CActionFactory::getInstance()->remove(action);
91 if (checkOnce)
93 nldebug("CLIMPD: at level %d (channel %d), %d actions%s (ReceivedAck=%d/lastAck=%d/nextSentPacket=%d)", level, channel, num, (keep) ? "" : " (discarded)", receivedAck, lastAck, nextSentPacket);
98 void CImpulseDecoder::reset()
100 uint i;
101 for (i=0; i<1; ++i) _LastAck0[i] = -1;
102 for (i=0; i<2; ++i) _LastAck1[i] = -1;
103 for (i=0; i<4; ++i) _LastAck2[i] = -1;