renderitem.cpp

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 "model/structures/instance.h"
00031 #include "model/metamodel/object.h"
00032 #include "model/metamodel/action.h"
00033 
00034 #include "visual.h"
00035 #include "renderitem.h"
00036 
00037 namespace FIFE {
00038     const int32_t STATIC_IMAGE_NOT_INITIALIZED = -2;
00039 
00040     RenderItem::RenderItem():
00041         screenpoint(),
00042         dimensions(),
00043         instance_z(0.0),
00044         m_cached_static_img_id(STATIC_IMAGE_NOT_INITIALIZED),
00045         m_cached_static_img_angle(0) {
00046     }
00047 
00048     int32_t RenderItem::getStaticImageIndexByAngle(uint32_t angle, Instance* instance) {
00049         if (static_cast<int32_t>(angle) != m_cached_static_img_angle) {
00050             m_cached_static_img_id = STATIC_IMAGE_NOT_INITIALIZED;
00051         }
00052         if (m_cached_static_img_id != STATIC_IMAGE_NOT_INITIALIZED) {
00053             return m_cached_static_img_id;
00054         }
00055         if(!instance->getObject()->getVisual<ObjectVisual>()) {
00056             return -1;
00057         }
00058 
00059         m_cached_static_img_id = instance->getObject()->getVisual<ObjectVisual>()->getStaticImageIndexByAngle(angle);
00060         m_cached_static_img_angle = angle;
00061         return m_cached_static_img_id;
00062     }
00063 }