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 "impulse_decoder.h"
23 #include "game_share/action_factory.h"
26 using namespace NLMISC
;
27 using namespace CLFECOMMON
;
32 CImpulseDecoder::CImpulseDecoder()
38 void CImpulseDecoder::decode(CBitMemStream
&inbox
, TPacketNumber receivedPacket
, TPacketNumber receivedAck
, TPacketNumber nextSentPacket
, vector
<CLFECOMMON::CAction
*> &actions
)
42 for (level
=0; level
<3; ++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;
55 bool checkOnce
= false;
58 TPacketNumber lastAck
= lAck
[channel
];
71 keep
= (receivedAck
>= lAck
[channel
]);
73 lAck
[channel
] = nextSentPacket
;
77 CAction
*action
= CActionFactory::getInstance()->unpack(inbox
, false);
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
);
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
);
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()
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;