ScummVM API documentation
updatefunctions.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ILLUSIONS_UPDATEFUNCTIONS_H
23 #define ILLUSIONS_UPDATEFUNCTIONS_H
24 
25 #include "common/func.h"
26 #include "common/list.h"
27 
28 namespace Illusions {
29 
30 enum {
31  kUFNext = 1, // Run next update funtion
32  kUFTerminate = 2 // Terminate update function
33 };
34 
35 typedef Common::Functor1<uint, int> UpdateFunctionCallback;
36 
38 public:
39  int _priority;
40  uint32 _sceneId;
41  uint _flags;
42  UpdateFunctionCallback *_callback;
43  UpdateFunction() : _priority(0), _sceneId(0), _flags(0), _callback(0) {}
44  ~UpdateFunction() { delete _callback; }
45  void terminate() { _flags |= 1; }
46  int run() { return (*_callback)(_flags); }
47 };
48 
50 public:
52  ~UpdateFunctions();
53  void add(int priority, uint32 sceneId, UpdateFunctionCallback *callback);
54  void update();
55  void terminateByScene(uint32 sceneId);
56 protected:
59 
60  struct FindInsertionPosition : public Common::UnaryFunction<const UpdateFunction*, bool> {
61  int _priority;
62  FindInsertionPosition(int priority) : _priority(priority) {}
63  bool operator()(const UpdateFunction *updateFunction) const {
64  return updateFunction->_priority > _priority;
65  }
66  };
67 
68  Common::List<UpdateFunction*> _updateFunctions;
69  uint32 _lastTimerUpdateTime;
70 };
71 
72 } // End of namespace Illusions
73 
74 #endif // ILLUSIONS_UPDATEFUNCTIONS_H
Definition: list.h:44
Definition: actor.h:34
Definition: updatefunctions.h:37
Definition: func.h:437
Definition: list_intern.h:51
Definition: func.h:43
Definition: updatefunctions.h:49