dmuratshin 8 years ago
parent
commit
2579291f9c

+ 10 - 0
examples/Demo/src/test.cpp

@@ -136,6 +136,16 @@ spButton Test::addButton(std::string id, std::string txt)
 
     _y += button->getHeight() + 2.0f;
 
+    Sprite* ptr = button.get();
+    button->addEventListener(TouchEvent::OVER, [=](Event*) {
+        ptr->addTween(Sprite::TweenAddColor(Color(64, 64, 64, 0)), 300);
+    });
+
+
+    button->addEventListener(TouchEvent::OUT, [=](Event*) {
+        ptr->addTween(Sprite::TweenAddColor(Color(0,0,0,0)), 300);
+    });
+
     if (_y + button->getHeight() >= getHeight())
     {
         _y = 5;

+ 18 - 6
oxygine/src/oxygine/MaterialCache.cpp

@@ -36,21 +36,21 @@ namespace oxygine
             }
         }
 
+        _addCounter++;
+        if (_addCounter > 30)
+            removeUnusedNoLock();
 
         Material* copy = other.clone();
         copy->_hash = hash;
         copy->_compare = cm;
         _materials.insert(std::make_pair(hash, copy));
-
+        
         return copy;
     }
 
-    void MaterialCache::removeUnused()
+    void MaterialCache::removeUnusedNoLock()
     {
-        MutexAutoLock alock(_lock);
-
-        //std::pair<materials::iterator, materials::iterator> it = _materials.begin();
-
+        _addCounter = 0;
         materials fresh;
         for (auto it = _materials.begin(); it != _materials.end(); it++)
         {
@@ -63,9 +63,21 @@ namespace oxygine
         std::swap(fresh, _materials);
     }
 
+    void MaterialCache::removeUnused()
+    {
+        MutexAutoLock alock(_lock);
+        removeUnusedNoLock();
+    }
+
+    MaterialCache::MaterialCache():_addCounter(0)
+    {
+
+    }
+
     void MaterialCache::clear()
     {
         MutexAutoLock alock(_lock);
+        _addCounter = 0;
         _materials.clear();
     }
 

+ 4 - 0
oxygine/src/oxygine/MaterialCache.h

@@ -24,6 +24,8 @@ namespace oxygine
     class MaterialCache
     {
     public:
+        MaterialCache();
+
         template<class T>
         intrusive_ptr<T> cache(const T& other)
         {
@@ -39,8 +41,10 @@ namespace oxygine
         materials _materials;
 
         Mutex _lock;
+        int _addCounter;
 
         Material* clone_(const Material& other);
+        void removeUnusedNoLock();
     };
 
     MaterialCache& mc();