From 82b331decf2da3e30d3491917f4d6f38c19abba5 Mon Sep 17 00:00:00 2001 From: neuromancer Date: Sat, 20 Feb 2021 11:30:07 -0300 Subject: [PATCH] PRIVATE: remove more pointers --- engines/private/funcs.cpp | 155 +++++++++++++++++++----------------- engines/private/private.cpp | 114 +++++++++++++++----------- engines/private/private.h | 20 ++--- 3 files changed, 157 insertions(+), 132 deletions(-) diff --git a/engines/private/funcs.cpp b/engines/private/funcs.cpp index 2a185e5f488..0f32514288e 100644 --- a/engines/private/funcs.cpp +++ b/engines/private/funcs.cpp @@ -125,29 +125,33 @@ void fQuit(ArgArray args) { void fLoadGame(ArgArray args) { // assert types debugC(1, kPrivateDebugScript, "LoadGame(%s, %s)", args[0].u.str, args[2].u.sym->name->c_str()); - MaskInfo *m = (MaskInfo *)malloc(sizeof(MaskInfo)); - m->surf = g_private->loadMask(args[0].u.str, 0, 0, true); - m->cursor = args[2].u.sym->name; - m->nextSetting = NULL; - m->flag1 = NULL; - m->flag2 = NULL; - free(g_private->_loadGameMask); + MaskInfo m = {}; + m.surf = g_private->loadMask(args[0].u.str, 0, 0, true); + m.cursor = *args[2].u.sym->name; + m.nextSetting = ""; + m.flag1 = NULL; + m.flag2 = NULL; + if (g_private->_loadGameMask.surf) + g_private->_loadGameMask.surf->free(); + delete g_private->_loadGameMask.surf; g_private->_loadGameMask = m; - g_private->_masks.push_front(*m); + g_private->_masks.push_front(m); } void fSaveGame(ArgArray args) { // assert types debugC(1, kPrivateDebugScript, "SaveGame(%s, %s)", args[0].u.str, args[1].u.sym->name->c_str()); - MaskInfo *m = (MaskInfo *)malloc(sizeof(MaskInfo)); - m->surf = g_private->loadMask(args[0].u.str, 0, 0, true); - m->cursor = args[1].u.sym->name; - m->nextSetting = NULL; - m->flag1 = NULL; - m->flag2 = NULL; - free(g_private->_saveGameMask); + MaskInfo m = {}; + m.surf = g_private->loadMask(args[0].u.str, 0, 0, true); + m.cursor = *args[1].u.sym->name; + m.nextSetting = ""; + m.flag1 = NULL; + m.flag2 = NULL; + if (g_private->_saveGameMask.surf) + g_private->_saveGameMask.surf->free(); + delete g_private->_saveGameMask.surf; g_private->_saveGameMask = m; - g_private->_masks.push_front(*m); + g_private->_masks.push_front(m); } void fRestartGame(ArgArray args) { @@ -232,35 +236,35 @@ void fDossierChgSheet(ArgArray args) { void fDossierPrevSuspect(ArgArray args) { assert (args.size() == 3); Common::String s(args[0].u.str); - MaskInfo *m = (MaskInfo *)malloc(sizeof(MaskInfo)); + MaskInfo m = {}; int x = args[1].u.val; int y = args[2].u.val; - m->surf = g_private->loadMask(s, x, y, true); - m->cursor = new Common::String("kExit"); - m->nextSetting = NULL; - m->flag1 = NULL; - m->flag2 = NULL; + m.surf = g_private->loadMask(s, x, y, true); + m.cursor = "kExit"; + m.nextSetting = ""; + m.flag1 = NULL; + m.flag2 = NULL; g_private->_dossierPrevSuspectMask = m; - g_private->_masks.push_front(*m); + g_private->_masks.push_front(m); } void fDossierNextSuspect(ArgArray args) { assert (args.size() == 3); Common::String s(args[0].u.str); - MaskInfo *m = (MaskInfo *)malloc(sizeof(MaskInfo)); + MaskInfo m = {}; int x = args[1].u.val; int y = args[2].u.val; - m->surf = g_private->loadMask(s, x, y, true); - m->cursor = new Common::String("kExit"); - m->nextSetting = NULL; - m->flag1 = NULL; - m->flag2 = NULL; + m.surf = g_private->loadMask(s, x, y, true); + m.cursor = "kExit"; + m.nextSetting = ""; + m.flag1 = NULL; + m.flag2 = NULL; g_private->_dossierNextSuspectMask = m; - g_private->_masks.push_front(*m); + g_private->_masks.push_front(m); } void fNoStopSounds(ArgArray args) { @@ -300,28 +304,28 @@ void fInventory(ArgArray args) { debugC(1, kPrivateDebugScript, "Inventory(...)"); Common::String mask(b1.u.str); if (mask != "\"\"") { - MaskInfo *m = (MaskInfo *)malloc(sizeof(MaskInfo)); - m->surf = g_private->loadMask(mask, 0, 0, true); + MaskInfo m = {}; + m.surf = g_private->loadMask(mask, 0, 0, true); if (e.type == NUM) - m->nextSetting = NULL; + m.nextSetting = ""; else - m->nextSetting = new Common::String(e.u.str); + m.nextSetting = *e.u.str; - m->cursor = new Common::String("kInventory"); - m->point = new Common::Point(0,0); + m.cursor = "kInventory"; + m.point = Common::Point(0,0); if (v1.type == NAME) - m->flag1 = v1.u.sym; + m.flag1 = v1.u.sym; else - m->flag1 = NULL; + m.flag1 = NULL; if (v2.type == NAME) - m->flag2 = v2.u.sym; + m.flag2 = v2.u.sym; else - m->flag2 = NULL; + m.flag2 = NULL; - g_private->_masks.push_front(*m); + g_private->_masks.push_front(m); g_private->_toTake = true; Common::String sound(snd.u.str); @@ -531,14 +535,14 @@ void _fMask(ArgArray args, bool drawn) { debugC(1, kPrivateDebugScript, "Mask(%s, %s, %s, %d, %d)", f, e, c->c_str(), x, y); const Common::String s(f); - MaskInfo *m = (MaskInfo *)malloc(sizeof(MaskInfo)); - m->surf = g_private->loadMask(s, x, y, drawn); - m->nextSetting = new Common::String(e); - m->cursor = c; - m->flag1 = NULL; - m->flag2 = NULL; - m->point = new Common::Point(x,y); - g_private->_masks.push_front(*m); + MaskInfo m = {}; + m.surf = g_private->loadMask(s, x, y, drawn); + m.nextSetting = e; + m.cursor = *c; + m.flag1 = NULL; + m.flag2 = NULL; + m.point = Common::Point(x,y); + g_private->_masks.push_front(m); } @@ -615,37 +619,40 @@ void fSoundArea(ArgArray args) { debugC(1, kPrivateDebugScript, "SoundArea(%s, %s, ..)", args[0].u.str, n.c_str()); Common::String s = args[0].u.str; - + MaskInfo m = {}; if (n == "kAMRadio") { - MaskInfo *m = (MaskInfo *)malloc(sizeof(MaskInfo)); - m->surf = g_private->loadMask(s, 0, 0, true); - m->cursor = args[2].u.sym->name; - m->nextSetting = NULL; - m->flag1 = NULL; - m->flag2 = NULL; - free(g_private->_AMRadioArea); + m.surf = g_private->loadMask(s, 0, 0, true); + m.cursor = *args[2].u.sym->name; + m.nextSetting = ""; + m.flag1 = NULL; + m.flag2 = NULL; + if (g_private->_AMRadioArea.surf) + g_private->_AMRadioArea.surf->free(); + delete g_private->_AMRadioArea.surf; g_private->_AMRadioArea = m; - g_private->_masks.push_front(*m); + g_private->_masks.push_front(m); } else if (n == "kPoliceRadio") { - MaskInfo *m = (MaskInfo *)malloc(sizeof(MaskInfo)); - m->surf = g_private->loadMask(s, 0, 0, true); - m->cursor = args[2].u.sym->name; - m->nextSetting = NULL; - m->flag1 = NULL; - m->flag2 = NULL; - free(g_private->_policeRadioArea); + m.surf = g_private->loadMask(s, 0, 0, true); + m.cursor = *args[2].u.sym->name; + m.nextSetting = ""; + m.flag1 = NULL; + m.flag2 = NULL; + if (g_private->_policeRadioArea.surf) + g_private->_policeRadioArea.surf->free(); + delete g_private->_policeRadioArea.surf; g_private->_policeRadioArea = m; - g_private->_masks.push_front(*m); + g_private->_masks.push_front(m); } else if (n == "kPhone") { - MaskInfo *m = (MaskInfo *)malloc(sizeof(MaskInfo)); - m->surf = g_private->loadMask(s, 0, 0, true); - m->cursor = args[2].u.sym->name; - m->nextSetting = NULL; - m->flag1 = NULL; - m->flag2 = NULL; - free(g_private->_phoneArea); + m.surf = g_private->loadMask(s, 0, 0, true); + m.cursor = *args[2].u.sym->name; + m.nextSetting = ""; + m.flag1 = NULL; + m.flag2 = NULL; + if (g_private->_phoneArea.surf) + g_private->_phoneArea.surf->free(); + delete g_private->_phoneArea.surf; g_private->_phoneArea = m; - g_private->_masks.push_front(*m); + g_private->_masks.push_front(m); } } diff --git a/engines/private/private.cpp b/engines/private/private.cpp index 47d9aa2ac89..1fb026fe71c 100644 --- a/engines/private/private.cpp +++ b/engines/private/private.cpp @@ -73,8 +73,8 @@ PrivateEngine::PrivateEngine(OSystem *syst, const ADGameDescription *gd) _repeatedMovieExit = ""; // Save and load - _saveGameMask = NULL; - _loadGameMask = NULL; + _saveGameMask = {}; + _loadGameMask = {}; // Interface _framePath = "inface/general/inface2.bmp"; @@ -90,9 +90,9 @@ PrivateEngine::PrivateEngine(OSystem *syst, const ADGameDescription *gd) _noStopSounds = false; // Radios and phone - _policeRadioArea = NULL; - _AMRadioArea = NULL; - _phoneArea = NULL; + _policeRadioArea = {}; + _AMRadioArea = {}; + _phoneArea = {}; // TODO: use this as a default sound for radio _infaceRadioPath = "inface/radio/"; _phonePrefix = "inface/telephon/"; @@ -101,8 +101,8 @@ PrivateEngine::PrivateEngine(OSystem *syst, const ADGameDescription *gd) // Dossiers _dossierPage = 0; _dossierSuspect = 0; - _dossierNextSuspectMask = NULL; - _dossierPrevSuspectMask = NULL; + _dossierNextSuspectMask = {}; + _dossierPrevSuspectMask = {}; // Diary _diaryLocPrefix = "inface/diary/loclist/"; @@ -302,20 +302,40 @@ void PrivateEngine::clearAreas() { _exits.clear(); _masks.clear(); - free(_loadGameMask); - _loadGameMask = NULL; - free(_saveGameMask); - _saveGameMask = NULL; - free(_policeRadioArea); - _policeRadioArea = NULL; - free(_AMRadioArea); - _AMRadioArea = NULL; - free(_phoneArea); - _phoneArea = NULL; - free(_dossierNextSuspectMask); - _dossierNextSuspectMask = NULL; - free(_dossierPrevSuspectMask); - _dossierPrevSuspectMask = NULL; + if (_loadGameMask.surf) + _loadGameMask.surf->free(); + delete _loadGameMask.surf; + _loadGameMask = {}; + + if (_saveGameMask.surf) + _saveGameMask.surf->free(); + delete _saveGameMask.surf; + _saveGameMask = {}; + + if (_policeRadioArea.surf) + _policeRadioArea.surf->free(); + delete _policeRadioArea.surf; + _policeRadioArea = {}; + + if (_AMRadioArea.surf) + _AMRadioArea.surf->free(); + delete _AMRadioArea.surf; + _AMRadioArea = {}; + + if (_phoneArea.surf) + _phoneArea.surf->free(); + delete _phoneArea.surf; + _phoneArea = {}; + + if (_dossierNextSuspectMask.surf) + _dossierNextSuspectMask.surf->free(); + delete _dossierNextSuspectMask.surf; + _dossierNextSuspectMask = {}; + + if (_dossierPrevSuspectMask.surf) + _dossierPrevSuspectMask.surf->free(); + delete _dossierPrevSuspectMask.surf; + _dossierPrevSuspectMask = {}; } void PrivateEngine::startPoliceBust() { @@ -411,9 +431,9 @@ bool PrivateEngine::cursorMask(Common::Point mousePos) { m = *it; if (inMask(m.surf, mousePos)) { - if (m.cursor != NULL) { // TODO: check this + if (!m.cursor.empty()) { // TODO: check this inside = true; - changeCursor(*m.cursor); + changeCursor(m.cursor); break; } } @@ -478,14 +498,14 @@ void PrivateEngine::selectExit(Common::Point mousePos) { } void PrivateEngine::selectMask(Common::Point mousePos) { - Common::String *ns = NULL; + Common::String ns = ""; MaskInfo m; for (MaskList::iterator it = _masks.begin(); it != _masks.end(); ++it) { m = *it; //debug("Testing mask %s", m.nextSetting->c_str()); if (inMask(m.surf, mousePos)) { //debug("Inside!"); - if (m.nextSetting != NULL) { // TODO: check this + if (!m.nextSetting.empty()) { // TODO: check this //debug("Found Mask %s", m.nextSetting->c_str()); ns = m.nextSetting; } @@ -505,21 +525,20 @@ void PrivateEngine::selectMask(Common::Point mousePos) { break; } } - if (ns != NULL) { + if (!ns.empty()) { //debug("Mask selected %s", ns->c_str()); - _nextSetting = *ns; - //setNextSetting(new Common::String(*ns)); + _nextSetting = ns; } } void PrivateEngine::selectAMRadioArea(Common::Point mousePos) { - if (_AMRadioArea == NULL) + if (_AMRadioArea.surf == NULL) return; if (_AMRadio.empty()) return; - if (inMask(_AMRadioArea->surf, mousePos)) { + if (inMask(_AMRadioArea.surf, mousePos)) { Common::String sound = _infaceRadioPath + "comm_/" + _AMRadio.back() + ".wav"; playSound(sound, 1, false, false); _AMRadio.pop_back(); @@ -527,13 +546,13 @@ void PrivateEngine::selectAMRadioArea(Common::Point mousePos) { } void PrivateEngine::selectPoliceRadioArea(Common::Point mousePos) { - if (_policeRadioArea == NULL) + if (_policeRadioArea.surf == NULL) return; if (_policeRadio.empty()) return; - if (inMask(_policeRadioArea->surf, mousePos)) { + if (inMask(_policeRadioArea.surf, mousePos)) { Common::String sound = _infaceRadioPath + "police/" + _policeRadio.back() + ".wav"; playSound(sound, 1, false, false); _policeRadio.pop_back(); @@ -541,7 +560,7 @@ void PrivateEngine::selectPoliceRadioArea(Common::Point mousePos) { } void PrivateEngine::checkPhoneCall() { - if (_phoneArea == NULL) + if (_phoneArea.surf == NULL) return; if (_phone.empty()) @@ -552,13 +571,13 @@ void PrivateEngine::checkPhoneCall() { } void PrivateEngine::selectPhoneArea(Common::Point mousePos) { - if (_phoneArea == NULL) + if (_phoneArea.surf == NULL) return; if (_phone.empty()) return; - if (inMask(_phoneArea->surf, mousePos)) { + if (inMask(_phoneArea.surf, mousePos)) { PhoneInfo i = _phone.back(); setSymbol(i.flag, i.val); Common::String sound = _phonePrefix + i.sound + ".wav"; @@ -582,16 +601,16 @@ void PrivateEngine::loadDossier() { } bool PrivateEngine::selectDossierNextSuspect(Common::Point mousePos) { - if (_dossierNextSuspectMask == NULL) + if (_dossierNextSuspectMask.surf == NULL) return false; - if (inMask(_dossierNextSuspectMask->surf, mousePos)) { + if (inMask(_dossierNextSuspectMask.surf, mousePos)) { if ((_dossierSuspect + 1) < _dossiers.size()) { _dossierSuspect++; _dossierPage = 0; loadDossier(); - drawMask(_dossierNextSuspectMask->surf); - drawMask(_dossierPrevSuspectMask->surf); + drawMask(_dossierNextSuspectMask.surf); + drawMask(_dossierPrevSuspectMask.surf); drawScreen(); } return true; @@ -600,16 +619,16 @@ bool PrivateEngine::selectDossierNextSuspect(Common::Point mousePos) { } bool PrivateEngine::selectDossierPrevSuspect(Common::Point mousePos) { - if (_dossierPrevSuspectMask == NULL) + if (_dossierPrevSuspectMask.surf == NULL) return false; - if (inMask(_dossierPrevSuspectMask->surf, mousePos)) { + if (inMask(_dossierPrevSuspectMask.surf, mousePos)) { if (_dossierSuspect > 0) { _dossierSuspect--; _dossierPage = 0; loadDossier(); - drawMask(_dossierNextSuspectMask->surf); - drawMask(_dossierPrevSuspectMask->surf); + drawMask(_dossierNextSuspectMask.surf); + drawMask(_dossierPrevSuspectMask.surf); drawScreen(); } return true; @@ -618,22 +637,21 @@ bool PrivateEngine::selectDossierPrevSuspect(Common::Point mousePos) { } void PrivateEngine::selectLoadGame(Common::Point mousePos) { - if (_loadGameMask == NULL) + if (_loadGameMask.surf == NULL) return; - if (inMask(_loadGameMask->surf, mousePos)) { + if (inMask(_loadGameMask.surf, mousePos)) { loadGameDialog(); } } void PrivateEngine::selectSaveGame(Common::Point mousePos) { - if (_saveGameMask == NULL) + if (_saveGameMask.surf == NULL) return; - if (inMask(_saveGameMask->surf, mousePos)) { + if (inMask(_saveGameMask.surf, mousePos)) { saveGameDialog(); } - } bool PrivateEngine::hasFeature(EngineFeature f) const { diff --git a/engines/private/private.h b/engines/private/private.h index ba0d7baa679..421bbf50bf1 100644 --- a/engines/private/private.h +++ b/engines/private/private.h @@ -84,11 +84,11 @@ typedef struct ExitInfo { typedef struct MaskInfo { Graphics::ManagedSurface *surf; - Common::String *nextSetting; - Common::Point *point; + Common::String nextSetting; + Common::Point point; Symbol *flag1; Symbol *flag2; - Common::String *cursor; + Common::String cursor; } MaskInfo; typedef struct PhoneInfo { @@ -228,8 +228,8 @@ public: DossierArray _dossiers; unsigned int _dossierSuspect; unsigned int _dossierPage; - MaskInfo *_dossierNextSuspectMask; - MaskInfo *_dossierPrevSuspectMask; + MaskInfo _dossierNextSuspectMask; + MaskInfo _dossierPrevSuspectMask; bool selectDossierNextSuspect(Common::Point); bool selectDossierPrevSuspect(Common::Point); void loadDossier(); @@ -251,8 +251,8 @@ public: void loadInventory(uint32, Common::Rect *, Common::Rect *); // Save/Load games - MaskInfo *_saveGameMask; - MaskInfo *_loadGameMask; + MaskInfo _saveGameMask; + MaskInfo _loadGameMask; int _mode; bool _modified; @@ -280,9 +280,9 @@ public: // Radios Common::String _infaceRadioPath; - MaskInfo *_AMRadioArea; - MaskInfo *_policeRadioArea; - MaskInfo *_phoneArea; + MaskInfo _AMRadioArea; + MaskInfo _policeRadioArea; + MaskInfo _phoneArea; Common::String _phonePrefix; Common::String _phoneCallSound; SoundList _AMRadio;