~keith-penguin/kdegames/trunk

« back to all changes in this revision

Viewing changes to ksirk/ksirk/Sprites/animspritespool.cpp

  • Committer: Keith Worrell
  • Date: 2009-03-18 05:35:28 UTC
  • Revision ID: keith.worrell@gmail.com-20090318053528-mx6x9c0ngmg0kg6p
imported project

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of KsirK.
 
2
   Copyright (C) 2007 Gael de Chalendar <kleag@free.fr>
 
3
 
 
4
   KsirK is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU General Public
 
6
   License as published by the Free Software Foundation, version 2.
 
7
 
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
   General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; if not, write to the Free Software
 
15
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
16
   02110-1301, USA
 
17
*/
 
18
 
 
19
/*  begin                : Thu Feb 22 2007  */
 
20
 
 
21
#include "animspritespool.h"
 
22
#include "animsprite.h"
 
23
 
 
24
#include <kdebug.h>
 
25
 
 
26
namespace Ksirk
 
27
{
 
28
 
 
29
 
 
30
AnimSpritePool* AnimSpritePool::m_pool = 0;
 
31
 
 
32
AnimSpritePool::AnimSpritePool() 
 
33
{
 
34
  connect(&m_timer,SIGNAL(timeout()),this,SLOT(update()));
 
35
  m_timer.setSingleShot(true);
 
36
  m_timer.start(200);
 
37
}
 
38
 
 
39
const AnimSpritePool& AnimSpritePool::single()
 
40
{
 
41
  if (m_pool == 0)
 
42
  {
 
43
    m_pool = new AnimSpritePool();
 
44
  }
 
45
  return *m_pool;
 
46
}
 
47
 
 
48
AnimSpritePool& AnimSpritePool::changeable() 
 
49
{
 
50
  if (m_pool == 0)
 
51
  {
 
52
    m_pool = new AnimSpritePool();
 
53
  }
 
54
  return *m_pool;
 
55
}
 
56
 
 
57
void AnimSpritePool::addSprite(AnimSprite* sprite)
 
58
{
 
59
  int index = m_sprites.indexOf(sprite);
 
60
  if (index == -1)
 
61
  {
 
62
    m_sprites.push_back(sprite);
 
63
  }
 
64
}
 
65
 
 
66
void AnimSpritePool::removeSprite(AnimSprite* sprite)
 
67
{
 
68
  int index = m_sprites.indexOf(sprite);
 
69
  if (index != -1)
 
70
  {
 
71
    m_sprites.removeAt(index);
 
72
  }
 
73
}
 
74
 
 
75
void AnimSpritePool::update() 
 
76
{
 
77
  kDebug() << "AnimSpritePool::update" << endl;
 
78
  QList<AnimSprite*>::iterator it, it_end;
 
79
  it = m_sprites.begin(); it_end = m_sprites.end();
 
80
  for (; it != it_end; it++)
 
81
  {
 
82
    (*it)->animate();
 
83
  }
 
84
  m_timer.start(200);
 
85
}
 
86
 
 
87
 
 
88
} // closing namespace Ksirk
 
89
 
 
90
#include "animspritespool.moc"