ScummVM API documentation
kernel.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 ULTIMA8_KERNEL_KERNEL_H
23 #define ULTIMA8_KERNEL_KERNEL_H
24 
25 #include "ultima/shared/std/containers.h"
26 #include "ultima/shared/std/string.h"
27 #include "ultima/ultima8/usecode/intrinsics.h"
28 
29 namespace Ultima {
30 namespace Ultima8 {
31 
32 class Debugger;
33 class Process;
34 class idMan;
35 
36 typedef Process *(*ProcessLoadFunc)(Common::ReadStream *rs, uint32 version);
37 typedef Std::list<Process *>::const_iterator ProcessIter;
38 typedef Std::list<Process *>::iterator ProcessIterator;
39 
40 
41 class Kernel {
42  friend class Debugger;
43 public:
44  Kernel();
45  ~Kernel();
46 
47  static Kernel *get_instance() {
48  return _kernel;
49  }
50 
51  void reset();
52 
53  // returns pid of new process
54  ProcId addProcess(Process *proc, bool dispose = true);
55 
58  ProcId addProcessExec(Process *proc, bool dispose = true);
59 
60  void runProcesses();
61  Process *getProcess(ProcId pid);
62 
63  ProcId assignPID(Process *proc);
64 
65  void setNextProcess(Process *proc);
66  Process *getRunningProcess() const {
67  return _runningProcess;
68  }
69 
70  // objid = 0 means any object, type = 6 means any type
71  uint32 getNumProcesses(ObjId objid, uint16 processtype);
72 
74  Process *findProcess(ObjId objid, uint16 processtype);
75 
80  void killProcesses(ObjId objid, uint16 processtype, bool fail);
81 
86  void killProcessesNotOfType(ObjId objid, uint16 processtype, bool fail);
87 
92  void killAllProcessesNotOfTypeExcludeCurrent(uint16 processtype, bool fail);
93 
95  ProcessIter getProcessBeginIterator() {
96  return _processes.begin();
97  }
98  ProcessIter getProcessEndIterator() {
99  return _processes.end();
100  }
101 
102  void kernelStats();
103  void processTypes();
104 
105  bool canSave();
106  void save(Common::WriteStream *ws);
107  bool load(Common::ReadStream *rs, uint32 version);
108 
109  void pause() {
110  _paused++;
111  }
112  void unpause() {
113  if (_paused > 0)
114  _paused--;
115  }
116  bool isPaused() const {
117  return _paused > 0;
118  }
119 
120  void setFrameByFrame(bool fbf) {
121  _frameByFrame = fbf;
122  }
123  bool isFrameByFrame() const {
124  return _frameByFrame;
125  }
126 
127  void addProcessLoader(Std::string classname, ProcessLoadFunc func) {
128  _processLoaders[classname] = func;
129  }
130 
131  uint32 getFrameNum() const {
132  return _tickNum / TICKS_PER_FRAME;
133  };
134  uint32 getTickNum() const {
135  return _tickNum;
136  };
137 
138  static const uint32 TICKS_PER_FRAME;
139  static const uint32 TICKS_PER_SECOND;
140  static const uint32 FRAMES_PER_SECOND;
141 
142  // A special process type which means kill all the processes.
143  static const uint16 PROC_TYPE_ALL;
144 
145  INTRINSIC(I_getNumProcesses);
146  INTRINSIC(I_resetRef);
147 private:
148  Process *loadProcess(Common::ReadStream *rs, uint32 version);
149 
150  Std::list<Process *> _processes;
151  idMan *_pIDs;
152 
153  Std::list<Process *>::iterator _currentProcess;
154 
156 
157  bool _loading;
158 
159  uint32 _tickNum;
160  unsigned int _paused;
161  bool _frameByFrame;
162 
163  Process *_runningProcess;
164 
165  static Kernel *_kernel;
166 };
167 
168 } // End of namespace Ultima8
169 } // End of namespace Ultima
170 
171 #endif
void killProcessesNotOfType(ObjId objid, uint16 processtype, bool fail)
void killProcesses(ObjId objid, uint16 processtype, bool fail)
Definition: stream.h:77
Definition: process.h:34
ProcId addProcessExec(Process *proc, bool dispose=true)
void killAllProcessesNotOfTypeExcludeCurrent(uint16 processtype, bool fail)
ProcessIter getProcessBeginIterator()
get an iterator of the process list.
Definition: kernel.h:95
Definition: detection.h:27
Definition: string.h:30
Process * findProcess(ObjId objid, uint16 processtype)
find a (any) process of the given objid, processtype
Definition: kernel.h:41
Definition: containers.h:200
Definition: id_man.h:43
Definition: list_intern.h:48
Definition: stream.h:385
Definition: list_intern.h:51
Definition: debugger.h:37