FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
visual.cpp
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
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 // Standard C++ library includes
23 
24 // 3rd party library includes
25 
26 // FIFE includes
27 // These includes are split up in two parts, separated by one empty line
28 // First block: files included from the FIFE root src directory
29 // Second block: files included from the same folder
30 #include "util/log/logger.h"
31 #include "util/base/exception.h"
32 
33 #include "model/structures/instance.h"
34 #include "model/metamodel/object.h"
35 #include "model/metamodel/action.h"
36 
37 #include "visual.h"
38 
39 
40 namespace FIFE {
41 
42  static Logger _log(LM_VIEW);
43 
44  Visual2DGfx::Visual2DGfx(): m_transparency(0), m_visible(true) {
45  }
46 
48  }
49 
50  ObjectVisual::ObjectVisual() {
51  }
52 
54  if (object->getVisual<ObjectVisual>()) {
55  throw Duplicate("Object already contains visualization");
56  }
57  ObjectVisual* v = new ObjectVisual();
58  object->adoptVisual(v);
59  return v;
60  }
61 
63  }
64 
65  void ObjectVisual::addStaticImage(unsigned int angle, int image_index) {
66  m_angle2img[angle % 360] = image_index;
67  }
68 
70  int closestMatch = 0;
71  return getIndexByAngle(angle, m_angle2img, closestMatch);
72  }
73 
75  int closestMatch = 0;
76  getIndexByAngle(angle, m_angle2img, closestMatch);
77  return closestMatch;
78  }
79 
80  void ObjectVisual::getStaticImageAngles(std::vector<int>& angles) {
81  angles.clear();
82  type_angle2id::const_iterator i(m_angle2img.begin());
83  while (i != m_angle2img.end()) {
84  angles.push_back(i->first);
85  ++i;
86  }
87  }
88 
89  InstanceVisual::InstanceVisual():
90  m_stackposition(0) {
91  }
92 
94  if (instance->getVisual<InstanceVisual>()) {
95  throw Duplicate("Instance already contains visualization");
96  }
97  InstanceVisual* v = new InstanceVisual();
98  instance->setVisual(v);
99  return v;
100  }
101 
103  }
104 
105  ActionVisual::ActionVisual(): m_animations() {
106  }
107 
109  if (action->getVisual<ActionVisual>()) {
110  throw Duplicate("Action already contains visualization");
111  }
112  ActionVisual* v = new ActionVisual();
113  action->adoptVisual(v);
114  return v;
115  }
116 
118  }
119 
120  void ActionVisual::addAnimation(unsigned int angle, int animation_index) {
121  m_animations[angle % 360] = animation_index;
122  }
123 
125  int closestMatch = 0;
126  return getIndexByAngle(angle, m_animations, closestMatch);
127  }
128 
129  void ActionVisual::getActionImageAngles(std::vector<int>& angles) {
130  angles.clear();
131  type_angle2id::const_iterator i(m_animations.begin());
132  while (i != m_animations.end()) {
133  angles.push_back(i->first);
134  ++i;
135  }
136  }
137 }