Selaa lähdekoodia

- added EVENT_DESTROY when scene deleted
- minor

dmuratshin 10 vuotta sitten
vanhempi
sitoutus
f0d17d2165
4 muutettua tiedostoa jossa 21 lisäystä ja 5 poistoa
  1. 4 1
      src/Scene.cpp
  2. 2 0
      src/Scene.h
  3. 14 4
      src/flow.cpp
  4. 1 0
      src/flow.h

+ 4 - 1
src/Scene.cpp

@@ -61,7 +61,10 @@ namespace oxygine
 
         Scene::~Scene()
         {
-
+            //workaround allows to convert this to sp from destructor
+            _ref_counter = 10000;
+            Event ev(EVENT_DESTROY);
+            EventDispatcher::dispatchEvent(&ev);
         }
 
         void Scene::setTransitionIn(spTransition t)

+ 2 - 0
src/Scene.h

@@ -62,6 +62,8 @@ namespace oxygine
                 //back button was pressed (android)
                 EVENT_BACK =            makefourcc('S', 'B', 'a', 'c'),
 
+                //fired from destructor
+                EVENT_DESTROY =         makefourcc('S', 'D', 'e', 's'),
 
                 EVENT_PRESHOWING = EVENT_PRE_SHOWING,
                 EVENT_POSTSHOWING = EVENT_POST_SHOWING,

+ 14 - 4
src/flow.cpp

@@ -36,6 +36,7 @@ namespace oxygine
         void free()
         {
             _touchBlocker = 0;
+            Flow::instance.free();
         }
 
 
@@ -52,13 +53,22 @@ namespace oxygine
             scenes.push_back(first);
         }
 
+        void Flow::free()
+        {
+            _trans = 0;
+            _current = 0;
+            _next = 0;
+            scenes.clear();
+            scenes2show.clear();
+        }
+
         void Flow::show(spScene scene, const resultCallback& cb)
         {
-			auto p = std::find(scenes.begin(), scenes.end(), scene);
-			if (p != scenes.end())			
-				log::error("you can't show scene '%s', it is already in the list", scene->getName().c_str());
+            auto p = std::find(scenes.begin(), scenes.end(), scene);
+            if (p != scenes.end())
+                log::error("you can't show scene '%s', it is already in the list", scene->getName().c_str());
 
-			OX_ASSERT(p == scenes.end());
+            OX_ASSERT(p == scenes.end());
             scene->_resultCB = cb;
             scenes2show.push_back(scene);
 

+ 1 - 0
src/flow.h

@@ -40,6 +40,7 @@ namespace oxygine
             Flow();
 
             void init();
+            void free();
 
             void show(spScene scene, const resultCallback& cb);
             void update();