FIFE
2008.0
|
00001 /*************************************************************************** 00002 * Copyright (C) 2005-2008 by the FIFE team * 00003 * http://www.fifengine.de * 00004 * This file is part of FIFE. * 00005 * * 00006 * FIFE is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Lesser General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2.1 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * Lesser General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with this library; if not, write to the * 00018 * Free Software Foundation, Inc., * 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 00020 ***************************************************************************/ 00021 00022 // Standard C++ library includes 00023 00024 // 3rd party library includes 00025 00026 // FIFE includes 00027 // These includes are split up in two parts, separated by one empty line 00028 // First block: files included from the FIFE root src directory 00029 // Second block: files included from the same folder 00030 #include "util/log/logger.h" 00031 #include "util/base/exception.h" 00032 00033 #include "model/structures/instance.h" 00034 #include "model/metamodel/object.h" 00035 #include "model/metamodel/action.h" 00036 00037 #include "visual.h" 00038 00039 00040 namespace FIFE { 00041 00042 static Logger _log(LM_VIEW); 00043 00044 Visual2DGfx::Visual2DGfx(): m_transparency(0), m_visible(true) { 00045 } 00046 00047 Visual2DGfx::~Visual2DGfx() { 00048 } 00049 00050 ObjectVisual::ObjectVisual() { 00051 } 00052 00053 ObjectVisual* ObjectVisual::create(Object* object) { 00054 if (object->getVisual<ObjectVisual>()) { 00055 throw Duplicate("Object already contains visualization"); 00056 } 00057 ObjectVisual* v = new ObjectVisual(); 00058 object->adoptVisual(v); 00059 return v; 00060 } 00061 00062 ObjectVisual::~ObjectVisual() { 00063 } 00064 00065 void ObjectVisual::addStaticImage(unsigned int angle, int image_index) { 00066 m_angle2img[angle % 360] = image_index; 00067 } 00068 00069 int ObjectVisual::getStaticImageIndexByAngle(int angle) { 00070 int closestMatch = 0; 00071 return getIndexByAngle(angle, m_angle2img, closestMatch); 00072 } 00073 00074 int ObjectVisual::getClosestMatchingAngle(int angle) { 00075 int closestMatch = 0; 00076 getIndexByAngle(angle, m_angle2img, closestMatch); 00077 return closestMatch; 00078 } 00079 00080 void ObjectVisual::getStaticImageAngles(std::vector<int>& angles) { 00081 angles.clear(); 00082 type_angle2id::const_iterator i(m_angle2img.begin()); 00083 while (i != m_angle2img.end()) { 00084 angles.push_back(i->first); 00085 ++i; 00086 } 00087 } 00088 00089 InstanceVisual::InstanceVisual(): 00090 m_stackposition(0) { 00091 } 00092 00093 InstanceVisual* InstanceVisual::create(Instance* instance) { 00094 if (instance->getVisual<InstanceVisual>()) { 00095 throw Duplicate("Instance already contains visualization"); 00096 } 00097 InstanceVisual* v = new InstanceVisual(); 00098 instance->setVisual(v); 00099 return v; 00100 } 00101 00102 InstanceVisual::~InstanceVisual() { 00103 } 00104 00105 ActionVisual::ActionVisual(): m_animations() { 00106 } 00107 00108 ActionVisual* ActionVisual::create(Action* action) { 00109 if (action->getVisual<ActionVisual>()) { 00110 throw Duplicate("Action already contains visualization"); 00111 } 00112 ActionVisual* v = new ActionVisual(); 00113 action->adoptVisual(v); 00114 return v; 00115 } 00116 00117 ActionVisual::~ActionVisual() { 00118 } 00119 00120 void ActionVisual::addAnimation(unsigned int angle, int animation_index) { 00121 m_animations[angle % 360] = animation_index; 00122 } 00123 00124 int ActionVisual::getAnimationIndexByAngle(int angle) { 00125 int closestMatch = 0; 00126 return getIndexByAngle(angle, m_animations, closestMatch); 00127 } 00128 00129 void ActionVisual::getActionImageAngles(std::vector<int>& angles) { 00130 angles.clear(); 00131 type_angle2id::const_iterator i(m_animations.begin()); 00132 while (i != m_animations.end()) { 00133 angles.push_back(i->first); 00134 ++i; 00135 } 00136 } 00137 }