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