FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
instancetree.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_INSTANCETREE_H
23 #define FIFE_INSTANCETREE_H
24 
25 // Standard C++ library includes
26 #include <list>
27 
28 // 3rd party library includes
29 
30 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line
32 // First block: files included from the FIFE root src
33 #include "util/base/fifeclass.h"
34 
37 
38 namespace FIFE {
39 
40  class Instance;
41 
42  class InstanceTree: public FifeClass {
43  public:
44  static const int32_t MIN_TREE_SIZE = 2;
45 
46  typedef std::list<Instance*> InstanceList;
49 
53  InstanceTree();
54 
58  virtual ~InstanceTree();
59 
68  void addInstance(Instance* instance);
69 
77  void removeInstance(Instance* instance);
78 
89  void findInstances(const ModelCoordinate& point, int32_t w, int32_t h, InstanceList& list);
90 
93  template<typename Visitor> void applyVisitor(Visitor& visitor) {
94  m_tree.apply_visitor(visitor);
95  }
96 
97 
98  private:
99  InstanceQuadTree m_tree;
100  std::map<Instance*,InstanceTreeNode*> m_reverse;
101  };
102 
103 }
104 
105 #endif
void applyVisitor(Visitor &visitor)
See QuadNode::apply_visitor.
Definition: instancetree.h:93
static const int32_t MIN_TREE_SIZE
Definition: instancetree.h:44
std::map< Instance *, InstanceTreeNode * > m_reverse
Definition: instancetree.h:100
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
void findInstances(const ModelCoordinate &point, int32_t w, int32_t h, InstanceList &list)
Find all instances in a given area.
virtual ~InstanceTree()
Destructor.
InstanceQuadTree::Node InstanceTreeNode
Definition: instancetree.h:48
void removeInstance(Instance *instance)
Removes an instance from the quad tree.
QuadNode< InstanceList, MinimumSize > Node
Definition: quadtree.h:152
InstanceQuadTree m_tree
Definition: instancetree.h:99
void addInstance(Instance *instance)
Adds an instance to the quad tree.
QuadTree< InstanceList, MIN_TREE_SIZE > InstanceQuadTree
Definition: instancetree.h:47
A 3D Point.
Definition: point.h:205
std::list< Instance * > InstanceList
Definition: instancetree.h:46
InstanceTree()
Constructor.
Visitor & apply_visitor(Visitor &visitor)
Apply a visitor recursively to the QuadTree.
Definition: quadtree.h:190
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:94