V-Gears 0
Free Final Fantasy VII engine.
ParticlePoolMap.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 The V-Gears Team
3 *
4 * This file is part of V-Gears
5 *
6 * V-Gears is free software: you can redistribute it and/or modify it under
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, version 3.0 (GPLv3) of the License.
9 *
10 * V-Gears is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#pragma once
17
23template <typename T>
25
26 public:
27
28 typedef std::multimap<Ogre::String, T*> PoolMapMap;
29
30 // The 'typename' MUST be added, since T is not a fixed type.
31 typedef typename PoolMapMap::iterator PoolMapIterator;
32
37
41 virtual ~ParticlePoolMap(){};
42
51 bool IsEmpty(){return released_.empty();};
52
60 size_t GetSize(){return released_.size();};
61
66
78 if (End()) return NULL;
79 T* t = pool_map_iterator_->second;
80 return t;
81 };
82
92 T* GetNext(){
93 if (End()) return NULL;
95 if (End()) return NULL;
96 T* t = pool_map_iterator_->second;
97 return t;
98 };
99
108 bool End(){return pool_map_iterator_ == released_.end();};
109
115 void Clear(){
116 locked_.clear();
117 released_.clear();
118 };
119
128 void AddElement(const Ogre::String& key, T* element){
129 locked_.insert(make_pair(key, element));
130 };
131
140 // Return with 0 if no elements left
141 if (locked_.empty()) return NULL;
142
143 // Return the first element that is encountered
144 T* t = 0;
146 it = locked_.find(key);
147 if (it != locked_.end()){
148 // Get the element and move it to the released elements list
149 t = it->second;
150 released_.insert(make_pair(key, t));
151 locked_.erase(it);
152 }
153 return t;
154 };
155
162 // Move all elements from locked elements to released elements
164 for (it = locked_.begin(); it != locked_.end(); ++ it)
165 released_.insert(make_pair(it->first, it->second));
166 locked_.clear();
168 };
169
176 // Move element pointed by iterator from released elements to
177 // locked elements
178 locked_.insert(
179 make_pair(pool_map_iterator_->first, pool_map_iterator_->second)
180 );
181 // Watch the ++ at the end to set mPoolMapIterator to the next
182 // element
184 };
185
193 // Move all elements from release elements to locked elements
195 for (it = released_.begin(); it != released_.end(); ++ it)
196 locked_.insert(make_pair(it->first, it->second));
197 released_.clear();
199 };
200
201 protected:
208
215
223};
224
225
226
227
A particle pool map.
Definition: ParticlePoolMap.h:24
T * GetFirst()
Retrieves the first particle.
Definition: ParticlePoolMap.h:76
size_t GetSize()
Retrieves the pool map size.
Definition: ParticlePoolMap.h:60
T * ReleaseElement(const Ogre::String &key)
Releases a locked particle.
Definition: ParticlePoolMap.h:139
void AddElement(const Ogre::String &key, T *element)
Adds a particle to the pool map.
Definition: ParticlePoolMap.h:128
void LockLatestElement()
Locks the released particle pointed by the iterator.
Definition: ParticlePoolMap.h:175
bool End()
Checks if the iterator is at the end of the pool map.
Definition: ParticlePoolMap.h:108
void ReleaseAllElements()
Releases all locked particles.
Definition: ParticlePoolMap.h:161
PoolMapIterator pool_map_iterator_
The pool map iterator.
Definition: ParticlePoolMap.h:222
virtual ~ParticlePoolMap()
Destructor.
Definition: ParticlePoolMap.h:41
PoolMapMap locked_
List with locked particles.
Definition: ParticlePoolMap.h:214
T * GetNext()
Retrieves the next particle in the pool map.
Definition: ParticlePoolMap.h:92
std::multimap< Ogre::String, T * > PoolMapMap
Definition: ParticlePoolMap.h:28
void ResetIterator()
Resets the pool iterator.
Definition: ParticlePoolMap.h:65
ParticlePoolMap()
Constructor.
Definition: ParticlePoolMap.h:36
PoolMapMap released_
List with released particles.
Definition: ParticlePoolMap.h:207
void Clear()
Removes all particles.
Definition: ParticlePoolMap.h:115
void LockAllElements()
Locks all particles.
Definition: ParticlePoolMap.h:192
PoolMapMap::iterator PoolMapIterator
Definition: ParticlePoolMap.h:31
bool IsEmpty()
Checks if the pool map is empty.
Definition: ParticlePoolMap.h:51
Ogre::String String
Definition: TypeDefine.h:37