Add infos into target window
[ryzomcore.git] / ryzom / server / src / frontend_service / processing_spreader.h
blob870a17b5910d7a1347d063e8e09447dc1e1371de
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 #ifndef NL_PROCESSING_SPREADER_H
20 #define NL_PROCESSING_SPREADER_H
22 #include "nel/misc/types_nl.h"
23 #include "fe_types.h"
25 // Test with the least frequent period even at low load (define=yes/undef=no)
26 #undef TEST_WORSE_EXECUTION_PERIOD
29 /**
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
40 * \date 2002
42 class CProcessingSpreader
44 public:
46 /// Constructor
47 CProcessingSpreader();
49 /// Initialization
50 void init();
52 /// Execution period in game cycle
53 sint32 ExecutionPeriod;
55 /// Return true if the process must be executed at the current cycle
56 bool mustProcessNow()
58 #ifdef TEST_WORSE_EXECUTION_PERIOD
59 return (_Count == 0);
60 #else
61 return true;
62 #endif
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;
74 #endif
77 /// Method to call every cycle, possibly after processing
78 void incCycle()
80 #ifdef TEST_WORSE_EXECUTION_PERIOD
81 --_Count;
82 #endif
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 );
91 private:
93 #ifdef TEST_WORSE_EXECUTION_PERIOD
94 /// Execution counter
95 sint32 _Count;
96 #endif
98 /// Current map index
99 sint32 _ClientMapIndex;
101 /// Current map iterator
102 THostMap::iterator _ClientMapIterator;
104 /// True if ClientMapIterator is invalid
105 bool _Invalidated;
109 #endif // NL_PROCESSING_SPREADER_H
111 /* End of processing_spreader.h */