PRIVATE: fix memory leaks and added more stuff into the main class
This commit is contained in:
parent
4d8144f32d
commit
020aa0a867
5 changed files with 38 additions and 54 deletions
|
@ -60,32 +60,6 @@ Inst *prog = NULL; /* the machine */
|
|||
Inst *progp = NULL; /* next free spot for code generation */
|
||||
Inst *pc = NULL; /* program counter during execution */
|
||||
|
||||
|
||||
static struct InstDescr {
|
||||
const Inst func;
|
||||
const char *name;
|
||||
} instDescr[] = {
|
||||
{ 0, "STOP", },
|
||||
{ constpush,"constpush" },
|
||||
{ strpush, "strpush", },
|
||||
{ varpush, "varpush", },
|
||||
{ funcpush, "funcpush", },
|
||||
{ eval, "eval", },
|
||||
{ ifcode, "ifcode", },
|
||||
{ add, "add", },
|
||||
{ negate, "negate", },
|
||||
|
||||
{ 0, 0}
|
||||
};
|
||||
|
||||
PtrToName _insts;
|
||||
|
||||
void initInsts() {
|
||||
for (InstDescr *fnc = instDescr; fnc->name; fnc++) {
|
||||
_insts[(void *)fnc->func] = new Common::String(fnc->name);
|
||||
}
|
||||
}
|
||||
|
||||
/* initialize setting for code generation */
|
||||
void SettingMaps::init() {
|
||||
setting = (Setting *)malloc(sizeof(Setting));
|
||||
|
|
|
@ -201,8 +201,7 @@ void fBustMovie(ArgArray args) {
|
|||
g_private->playSound(s, 1, false, false);
|
||||
}
|
||||
|
||||
delete g_private->_nextMovie;
|
||||
g_private->_nextMovie = new Common::String(pv);
|
||||
g_private->setNextMovie(new Common::String(pv));
|
||||
g_private->setNextSetting(new Common::String(args[0].u.str));
|
||||
}
|
||||
|
||||
|
@ -455,8 +454,7 @@ void fViewScreen(ArgArray args) {
|
|||
void fTransition(ArgArray args) {
|
||||
// assert types
|
||||
debugC(1, kPrivateDebugScript, "Transition(%s, %s)", args[0].u.str, args[1].u.str);
|
||||
delete g_private->_nextMovie;
|
||||
g_private->_nextMovie = new Common::String(args[0].u.str);
|
||||
g_private->setNextMovie(new Common::String(args[0].u.str));
|
||||
g_private->setNextSetting(new Common::String(args[1].u.str));
|
||||
}
|
||||
|
||||
|
@ -476,8 +474,7 @@ void fMovie(ArgArray args) {
|
|||
Common::String *nextSetting = new Common::String(args[1].u.str);
|
||||
|
||||
if (!g_private->_playedMovies.contains(*movie) && *movie != "\"\"") {
|
||||
delete g_private->_nextMovie;
|
||||
g_private->_nextMovie = movie;
|
||||
g_private->setNextMovie(movie);
|
||||
g_private->_playedMovies.setVal(*movie, true);
|
||||
g_private->setNextSetting(nextSetting);
|
||||
|
||||
|
@ -689,10 +686,7 @@ void fTimer(ArgArray args) {
|
|||
}
|
||||
}
|
||||
|
||||
static struct FuncTable {
|
||||
void (*func)(Private::ArgArray);
|
||||
const char *name;
|
||||
} funcTable[] = {
|
||||
FuncTable funcTable[] = {
|
||||
|
||||
// Control flow
|
||||
{ fChgMode, "ChgMode"},
|
||||
|
@ -762,22 +756,13 @@ static struct FuncTable {
|
|||
{ 0, 0}
|
||||
};
|
||||
|
||||
NameToPtr _functions;
|
||||
|
||||
void initFuncs() {
|
||||
for (Private::FuncTable *fnc = funcTable; fnc->name; fnc++) {
|
||||
Common::String *name = new Common::String(fnc->name);
|
||||
_functions.setVal(*name, (void *)fnc->func);
|
||||
}
|
||||
}
|
||||
|
||||
void call(char *name, ArgArray args) {
|
||||
Common::String n(name);
|
||||
if (!_functions.contains(n)) {
|
||||
if (!g_private->_functions.contains(n)) {
|
||||
error("I don't know how to execute %s", name);
|
||||
}
|
||||
|
||||
void (*func)(ArgArray) = (void (*)(ArgArray)) _functions.getVal(n);
|
||||
void (*func)(ArgArray) = (void (*)(ArgArray)) g_private->_functions.getVal(n);
|
||||
func(args);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,6 @@ typedef int (* Inst)(); /* machine instruction */
|
|||
#define STOP (Inst) 0
|
||||
|
||||
typedef Common::HashMap<void *, Common::String *> PtrToName;
|
||||
typedef Common::HashMap<Common::String, void *> NameToPtr;
|
||||
|
||||
void initInsts();
|
||||
void initFuncs();
|
||||
|
@ -99,7 +98,7 @@ Datum pop();
|
|||
int push(Datum);
|
||||
extern Inst *progp;
|
||||
|
||||
extern Inst *code(Inst);
|
||||
Inst *code(Inst);
|
||||
extern Inst *prog;
|
||||
int eval();
|
||||
int add();
|
||||
|
@ -124,7 +123,6 @@ int randbool();
|
|||
|
||||
// Code Execution
|
||||
|
||||
|
||||
void execute(Inst *);
|
||||
|
||||
} // End of namespace Private
|
||||
|
|
|
@ -126,6 +126,11 @@ void PrivateEngine::setNextSetting(Common::String *_ns) {
|
|||
_nextSetting = _ns;
|
||||
}
|
||||
|
||||
void PrivateEngine::setNextMovie(Common::String *_nm) {
|
||||
delete _nextMovie;
|
||||
_nextMovie = _nm;
|
||||
}
|
||||
|
||||
void PrivateEngine::setOrigin(const int point[2]) {
|
||||
delete _origin;
|
||||
_origin = new Common::Point(point[0], point[1]);;
|
||||
|
@ -157,7 +162,6 @@ Common::Error PrivateEngine::run() {
|
|||
file->read(buf, file->size()+1);
|
||||
|
||||
// Initialize stuff
|
||||
initInsts();
|
||||
initFuncs();
|
||||
initCursors();
|
||||
parse(buf);
|
||||
|
@ -256,8 +260,7 @@ Common::Error PrivateEngine::run() {
|
|||
removeTimer();
|
||||
_videoDecoder = new Video::SmackerDecoder();
|
||||
playVideo(*_nextMovie);
|
||||
delete(_nextMovie);
|
||||
_nextMovie = NULL;
|
||||
setNextMovie(NULL);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -299,6 +302,13 @@ Common::Error PrivateEngine::run() {
|
|||
return Common::kNoError;
|
||||
}
|
||||
|
||||
void PrivateEngine::initFuncs() {
|
||||
for (Private::FuncTable *fnc = funcTable; fnc->name; fnc++) {
|
||||
Common::String *name = new Common::String(fnc->name);
|
||||
_functions.setVal(*name, (void *)fnc->func);
|
||||
}
|
||||
}
|
||||
|
||||
void PrivateEngine::clearAreas() {
|
||||
_exits.clear();
|
||||
_masks.clear();
|
||||
|
|
|
@ -102,6 +102,16 @@ typedef struct DossierInfo {
|
|||
Common::String *page2;
|
||||
} DossierInfo;
|
||||
|
||||
// funcs
|
||||
|
||||
typedef struct FuncTable {
|
||||
void (*func)(Private::ArgArray);
|
||||
const char *name;
|
||||
} FunctTable;
|
||||
|
||||
typedef Common::HashMap<Common::String, void *> NameToPtr;
|
||||
extern FuncTable funcTable[];
|
||||
|
||||
// lists
|
||||
|
||||
typedef Common::List<ExitInfo> ExitList;
|
||||
|
@ -122,6 +132,7 @@ class PrivateEngine : public Engine {
|
|||
private:
|
||||
Common::RandomSource *_rnd;
|
||||
Common::String *_nextSetting;
|
||||
Common::String *_nextMovie;
|
||||
Graphics::PixelFormat _pixelFormat;
|
||||
Image::ImageDecoder *_image;
|
||||
int _screenW, _screenH;
|
||||
|
@ -146,6 +157,11 @@ public:
|
|||
void clearAreas();
|
||||
void initializePath(const Common::FSNode &gamePath) override;
|
||||
|
||||
// Functions
|
||||
|
||||
NameToPtr _functions;
|
||||
void initFuncs();
|
||||
|
||||
// User input
|
||||
void selectPauseMovie(Common::Point);
|
||||
void selectMask(Common::Point);
|
||||
|
@ -200,6 +216,7 @@ public:
|
|||
void setOrigin(const int[2]);
|
||||
|
||||
void setNextSetting(Common::String *);
|
||||
void setNextMovie(Common::String *);
|
||||
|
||||
Common::String *_currentSetting;
|
||||
bool _toTake;
|
||||
|
@ -236,7 +253,7 @@ public:
|
|||
|
||||
int _mode;
|
||||
bool _modified;
|
||||
Common::String *_nextMovie;
|
||||
|
||||
PlayedMediaTable _playedMovies;
|
||||
PlayedMediaTable _playedPhoneClips;
|
||||
Common::String _repeatedMovieExit;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue