File indexing completed on 2025-03-16 03:51:21
0001 /* This file is part of KsirK. 0002 Copyright (C) 2007 Gael de Chalendar <kleag@free.fr> 0003 0004 KsirK is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, either version 2 0007 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0017 02110-1301, USA 0018 */ 0019 0020 /* begin : Thu Feb 22 2007 */ 0021 0022 #include "animspritespool.h" 0023 #include "animsprite.h" 0024 0025 #include "ksirk_debug.h" 0026 0027 namespace Ksirk 0028 { 0029 0030 0031 AnimSpritePool* AnimSpritePool::m_pool = nullptr; 0032 0033 AnimSpritePool::AnimSpritePool() 0034 { 0035 connect(&m_timer,&QTimer::timeout,this,&AnimSpritePool::update); 0036 m_timer.setSingleShot(true); 0037 m_timer.start(200); 0038 } 0039 0040 const AnimSpritePool& AnimSpritePool::single() 0041 { 0042 if (m_pool == nullptr) 0043 { 0044 m_pool = new AnimSpritePool(); 0045 } 0046 return *m_pool; 0047 } 0048 0049 AnimSpritePool& AnimSpritePool::changeable() 0050 { 0051 if (m_pool == nullptr) 0052 { 0053 m_pool = new AnimSpritePool(); 0054 } 0055 return *m_pool; 0056 } 0057 0058 void AnimSpritePool::addSprite(AnimSprite* sprite) 0059 { 0060 int index = m_sprites.indexOf(sprite); 0061 if (index == -1) 0062 { 0063 m_sprites.push_back(sprite); 0064 } 0065 } 0066 0067 void AnimSpritePool::removeSprite(AnimSprite* sprite) 0068 { 0069 int index = m_sprites.indexOf(sprite); 0070 if (index != -1) 0071 { 0072 m_sprites.removeAt(index); 0073 } 0074 } 0075 0076 void AnimSpritePool::update() 0077 { 0078 qCDebug(KSIRK_LOG) << "AnimSpritePool::update"; 0079 QList<AnimSprite*>::iterator it, it_end; 0080 it = m_sprites.begin(); it_end = m_sprites.end(); 0081 for (; it != it_end; it++) 0082 { 0083 (*it)->animate(); 0084 } 0085 m_timer.start(200); 0086 } 0087 0088 0089 } // closing namespace Ksirk 0090 0091 #include "moc_animspritespool.cpp"