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/>.
19 #ifndef NL_PROCESSING_SPREADER_H
20 #define NL_PROCESSING_SPREADER_H
22 #include "nel/misc/types_nl.h"
25 // Test with the least frequent period even at low load (define=yes/undef=no)
26 #undef TEST_WORSE_EXECUTION_PERIOD
30 * This class is aimed to spread an iterating process onto several game cycles,
31 * when it is too long to be executed in one game cycle.
32 * When mustProcessNow() returns true, call getProcessingBounds() to get the
33 * range, in the client map, of clients to process.
34 * After processing them, call endProcessing().
35 * After any cycle, call incCycle().
36 * When a client leaves the front-end, call notifyClientRemoval().
38 * \author Olivier Cado
39 * \author Nevrax France
42 class CProcessingSpreader
47 CProcessingSpreader();
52 /// Execution period in game cycle
53 sint32 ExecutionPeriod
;
55 /// Return true if the process must be executed at the current cycle
58 #ifdef TEST_WORSE_EXECUTION_PERIOD
65 /// Get the range (beginning iterator, index and outer bound) for the current processing
66 void getProcessingBounds( THostMap::iterator
& firstit
, sint
& firstindex
, sint
& outerboundindex
);
68 /// Method to call at the end of a processing
69 void endProcessing( THostMap::iterator icm
)
71 _ClientMapIterator
= icm
;
72 #ifdef TEST_WORSE_EXECUTION_PERIOD
73 _Count
= ExecutionPeriod
;
77 /// Method to call every cycle, possibly after processing
80 #ifdef TEST_WORSE_EXECUTION_PERIOD
85 /// Method to call after a new client is added into the clientmap (give it clientmap.end() before the addition!)
86 void notifyClientAddition( THostMap::iterator endBeforeAddition
);
88 /// Method to call when a client leaves
89 void notifyClientRemoval( THostMap::iterator icm
);
93 #ifdef TEST_WORSE_EXECUTION_PERIOD
99 sint32 _ClientMapIndex
;
101 /// Current map iterator
102 THostMap::iterator _ClientMapIterator
;
104 /// True if ClientMapIterator is invalid
109 #endif // NL_PROCESSING_SPREADER_H
111 /* End of processing_spreader.h */