1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA8_KERNEL_USECODE_PROCESS_H
#define ULTIMA8_KERNEL_USECODE_PROCESS_H
#include "ultima/shared/std/containers.h"
#include "ultima/ultima8/misc/classtype.h"
#include "ultima/ultima8/misc/debugger.h"
namespace Ultima {
namespace Ultima8 {
class Debugger;
class Process {
friend class Kernel;
friend class Debugger;
public:
virtual void run() = 0;
Process(ObjId _itemNum = 0, uint16 type = 0);
virtual ~Process() { }
ENABLE_RUNTIME_CLASSTYPE_BASE()
uint32 getProcessFlags() const {
return _flags;
}
bool is_active() const {
return (_flags & PROC_ACTIVE);
}
bool is_terminated() const {
return (_flags & (PROC_TERMINATED |
PROC_TERM_DEFERRED)) != 0;
}
bool is_suspended() const {
return (_flags & PROC_SUSPENDED) != 0;
}
//! terminate the process and recursively fail all processes waiting for it
void fail();
//! terminate the process. This wakes up all processes waiting for it.
virtual void terminate();
//! terminate next frame
void terminateDeferred() {
_flags |= PROC_TERM_DEFERRED;
}
//! run even when paused
void setRunPaused() {
_flags |= PROC_RUNPAUSED;
};
//! suspend until process 'pid' returns. If pid is 0, suspend indefinitely
void waitFor(ProcId pid);
//! suspend until process returns. If proc is 0, suspend indefinitely
void waitFor(Process *proc);
//! suspend process
void suspend();
//! Wake up when the process we were waiting for has finished
void wakeUp(uint32 result);
//! A hook to add aditional behavior on wakeup, before anything else happens
virtual void onWakeUp() {};
void setItemNum(ObjId it) {
_itemNum = it;
}
void setType(uint16 ty) {
_type = ty;
}
void setTicksPerRun(uint32 val) {
_ticksPerRun = val;
}
ProcId getPid() const {
return _pid;
}
ObjId getItemNum() const {
return _itemNum;
}
uint16 getType() const {
return _type;
}
uint32 getTicksPerRun() const {
return _ticksPerRun;
}
//! dump some info about this process to a string
virtual Common::String dumpInfo() const;
//! load Process data
bool loadData(Common::ReadStream *rs, uint32 version);
//! save Process data
virtual void saveData(Common::WriteStream *ws);
//! Check the waiting processes. This is used after loading a game.
//! Ensures they are all valid processes and suspended. Can't be done in
//! loadData because the waiters may not be loaded yet at that point.
bool validateWaiters() const;
protected:
//! process id
ProcId _pid;
uint32 _flags;
//! how many kernel ticks between when this process should be run.
//! not saved because it's fixed by process type and game.
uint32 _ticksPerRun;
//! item we are assigned to
ObjId _itemNum;
uint16 _type;
//! process result
uint32 _result;
//! Processes waiting for this one to finish.
//! When this process terminates, awaken them and pass them the result val.
Std::vector<ProcId> _waiting;
public:
enum processflags {
PROC_ACTIVE = 0x0001, //!< is the process in the run-list?
PROC_SUSPENDED = 0x0002, //!< suspended? (because it's waiting)
PROC_TERMINATED = 0x0004,
PROC_TERM_DEFERRED = 0x0008, //!< automatically call terminate next frame
PROC_FAILED = 0x0010,
PROC_RUNPAUSED = 0x0020, //!< run even if game is paused
PROC_TERM_DISPOSE = 0x0040, //!< Dispose after termination
PROC_PREVENT_SAVE = 0x0080 //!< When set, prevent game from saving
};
};
} // End of namespace Ultima8
} // End of namespace Ultima
#endif
|