diff --git a/lib-src/enigma-core/ecl_video.cc b/lib-src/enigma-core/ecl_video.cc index 4f35ab93e..a0da00ac3 100644 --- a/lib-src/enigma-core/ecl_video.cc +++ b/lib-src/enigma-core/ecl_video.cc @@ -367,16 +367,16 @@ ecl::Screen *ecl::Screen::get_instance() { ecl::Screen::Screen(SDL_Window *window, int surface_w, int surface_h) : m_window(window), - m_surface(Surface::make_surface( - SDL_CreateRGBSurface(0, surface_w, surface_h, 32, 0xff0000, 0xff00, 0xff, 0xff000000), - NO_ALPHA)), - m_sdlsurface(m_surface->get_surface()), update_all_p(false) { + m_surface.reset(Surface::make_surface( + SDL_CreateRGBSurface(0, surface_w, surface_h, 32, 0xff0000, 0xff00, 0xff, 0xff000000), + NO_ALPHA)); + m_sdlsurface = m_surface->get_surface(); assert(m_window); assert(m_surface); assert(m_instance == 0); m_instance = this; - m_scaler = new ecl::Scaler(m_surface->get_surface(), NULL, SDL_GetWindowSurface(m_window)); + m_scaler = std::make_unique(m_surface->get_surface(), nullptr, SDL_GetWindowSurface(m_window)); } ecl::Screen::~Screen() { @@ -750,6 +750,6 @@ Surface *ecl::MakeSurface(void *data, int w, int h, int bipp, int pitch, const R } void ecl::BlitScaled(SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect, ScalerMode mode) { - Scaler* scaler = new Scaler(src, srcrect, dst, mode); - scaler->blit_scaled(src, srcrect, dst, dstrect); + Scaler scaler{src, srcrect, dst, mode}; + scaler.blit_scaled(src, srcrect, dst, dstrect); } diff --git a/lib-src/enigma-core/ecl_video.hh b/lib-src/enigma-core/ecl_video.hh index 3521f1f08..6fdb62538 100644 --- a/lib-src/enigma-core/ecl_video.hh +++ b/lib-src/enigma-core/ecl_video.hh @@ -20,6 +20,7 @@ #define ECL_VIDEO_HH_INCLUDED #include "ecl_geom.hh" +#include #include "SDL.h" @@ -248,7 +249,7 @@ public: /* ---------- Accessors ---------- */ SDL_Window *window() const { return m_window; } - Surface *get_surface() const { return m_surface; } + Surface *get_surface() const { return m_surface.get(); } Rect size() const; int width() const; @@ -267,7 +268,7 @@ private: static Screen *m_instance; SDL_Window *m_window; - Surface *m_surface; + std::unique_ptr m_surface; SDL_Surface *m_sdlsurface; RectList m_dirtyrects; bool update_all_p; @@ -275,7 +276,7 @@ private: Screen(const Screen &); Screen &operator=(const Screen &); - Scaler *m_scaler; + std::unique_ptr m_scaler; }; /* -------------------- Graphics primitives -------------------- */ diff --git a/src/gui/InfoMenu.cc b/src/gui/InfoMenu.cc index 590a29526..a13f60d32 100644 --- a/src/gui/InfoMenu.cc +++ b/src/gui/InfoMenu.cc @@ -55,11 +55,11 @@ namespace enigma { namespace gui { numPages = process_infotext(false); but_ok = new StaticTextButton(N_("Ok"), this); - pgup = new ImageButton("ic-up", "ic-up1", this); - pgdown = new ImageButton("ic-down", "ic-down1", this); add(but_ok, Rect(vminfo.width-(vshrink?80:130), vminfo.height-(vshrink?30:60), vshrink?70:110, vshrink?20:40)); if (numPages > pInfo[vminfo.tt].columnsPerPage) { + pgup = new ImageButton("ic-up", "ic-up1", this); + pgdown = new ImageButton("ic-down", "ic-down1", this); add(pgup, Rect(vminfo.width-(vshrink?15:30), vminfo.height/2, vshrink?10:20, vshrink?25:50)); add(pgdown, Rect(vminfo.width-(vshrink?15:30), vminfo.height/2 +(vshrink?35:70), vshrink?10:20, vshrink?25:50)); } @@ -119,12 +119,12 @@ namespace enigma { namespace gui { void InfoMenu::on_action (gui::Widget *w) { if (w == but_ok) { Menu::quit(); - } else if (w == pgup) { + } else if (pgup && w == pgup) { if (curPage > 0) { curPage--; invalidate_all(); } - } else if (w == pgdown) { + } else if (pgdown && w == pgdown) { if (curPage < numPages - 1) { curPage++; invalidate_all(); diff --git a/src/gui/InfoMenu.hh b/src/gui/InfoMenu.hh index 5da11982e..88d12bed1 100644 --- a/src/gui/InfoMenu.hh +++ b/src/gui/InfoMenu.hh @@ -32,9 +32,9 @@ namespace enigma { namespace gui { const char **info; int curPage; int numPages; - Widget *but_ok; - Widget *pgup; - Widget *pgdown; + Widget *but_ok = nullptr; + Widget *pgup = nullptr; + Widget *pgdown = nullptr; ecl::GC *current_gc; int process_infotext(bool render); diff --git a/src/gui/LevelPackMenu.cc b/src/gui/LevelPackMenu.cc index 12eb395f0..0fa5e48ee 100644 --- a/src/gui/LevelPackMenu.cc +++ b/src/gui/LevelPackMenu.cc @@ -183,13 +183,16 @@ namespace enigma { namespace gui { } if (but_tutorial2 != NULL) { remove_child(but_tutorial2); - delete but_tutorial1; + delete but_tutorial2; but_tutorial2 = NULL; } - for (auto it = tutorialLines.begin(); it != tutorialLines.end(); it++) - if (*it != NULL) + for (auto it = tutorialLines.begin(); it != tutorialLines.end(); it++) { + if (*it != NULL) { remove_child(*it); + delete *it; + } + } tutorialLines.clear(); packButtons.clear(); diff --git a/src/lev/PersistentIndex.cc b/src/lev/PersistentIndex.cc index dbba41ad8..8e065e21e 100644 --- a/src/lev/PersistentIndex.cc +++ b/src/lev/PersistentIndex.cc @@ -65,6 +65,7 @@ namespace enigma { namespace lev { PersistentIndex * PersistentIndex::historyIndex = NULL; std::vector > PersistentIndex::indexCandidates; + std::vector > PersistentIndex::persistentIndices; void PersistentIndex::checkCandidate(std::string thePackPath, bool systemOnly, bool userOwned, bool isAuto, bool isSystemCross, bool isUserCross, double defaultLocation, @@ -151,6 +152,11 @@ namespace enigma { namespace lev { } } + void PersistentIndex::registerIndex(std::unique_ptr index) { + Index::registerIndex(index.get()); + persistentIndices.push_back(std::move(index)); + } + void PersistentIndex::registerPersistentIndices(bool onlySystemIndices) { DirIter * dirIter; DirEntry dirEntry; @@ -221,20 +227,18 @@ namespace enigma { namespace lev { // register index free auto folder // this needs to be done prior history registration to avoid outdated proxies - PersistentIndex * autoIndex = new PersistentIndex("auto", false, true, true, + std::unique_ptr autoIndex = std::make_unique("auto", false, true, true, INDEX_AUTO_PACK_LOCATION, INDEX_AUTO_PACK_NAME, INDEX_STD_FILENAME, INDEX_AUTO_PACK_DESCRIPTION); autoIndex->isEditable = false; - Index::registerIndex(autoIndex); + PersistentIndex::registerIndex(std::move(autoIndex)); // register team auto not yet registered new files - PersistentIndex * teamautoIndex = new PersistentIndex("team_test_new_api", false, true, true, + std::unique_ptr teamautoIndex = std::make_unique("team_test_new_api", false, true, true, 75000, "test_new_api"); if (teamautoIndex->size() > 0) { teamautoIndex->isEditable = false; - Index::registerIndex(teamautoIndex); - } else { - delete teamautoIndex; + PersistentIndex::registerIndex(std::move(teamautoIndex)); } // UserPath: register dirs and zips with xml-indices excl auto @@ -601,6 +605,7 @@ namespace enigma { namespace lev { // Must be called before XMLPlatformUtils::terminate void PersistentIndex::shutdown() { indexCandidates.clear(); + persistentIndices.clear(); } std::string PersistentIndex::getPackPath() { @@ -1210,7 +1215,7 @@ namespace enigma { namespace lev { std::string indexString; is >> indexString; std::stringstream indexStream(indexString); - Index::registerIndex(new PersistentIndex(indexStream, dir, false, indexName)); + PersistentIndex::registerIndex(std::make_unique(indexStream, dir, false, indexName)); } catch (const XLevelPackInit &e) { Log << e.get_string() << "\n"; } @@ -1246,7 +1251,8 @@ namespace enigma { namespace lev { indexName = line; // check if already loaded - Index::registerIndex(new PersistentIndex(inflatedContent, dir, true, indexName)); + PersistentIndex::registerIndex(std::make_unique( + inflatedContent, dir, true, indexName)); } else { throw XLevelPackInit ("Invalid level pack: " + indexName); } diff --git a/src/lev/PersistentIndex.hh b/src/lev/PersistentIndex.hh index 5a2fd2540..39652a83a 100644 --- a/src/lev/PersistentIndex.hh +++ b/src/lev/PersistentIndex.hh @@ -51,6 +51,7 @@ namespace enigma { namespace lev { class PersistentIndex : public Index { public: static void registerPersistentIndices(bool onlySystemIndices); + static void registerIndex(std::unique_ptr index); static PersistentIndex * historyIndex; static void addCurrentToHistory(); static void shutdown(); @@ -127,6 +128,7 @@ namespace enigma { namespace lev { std::string indexUrl; private: static std::vector > indexCandidates; + static std::vector > persistentIndices; std::string absIndexPath; XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc; XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *infoElem; diff --git a/src/stones/ShogunStone.cc b/src/stones/ShogunStone.cc index 4a789bb12..507b34606 100644 --- a/src/stones/ShogunStone.cc +++ b/src/stones/ShogunStone.cc @@ -23,7 +23,8 @@ #include "world.hh" namespace enigma { - ShogunStone::ShogunStone(int holes) : Stone () { + ShogunStone::ShogunStone(int holes) : + Stone (), subShogun(nullptr), superShogun(nullptr) { objFlags |= holes << 24; }