ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

renderentry.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/gfx/renderentry.h"
00024 #include "engines/stark/gfx/driver.h"
00025 
00026 #include "engines/stark/resources/item.h"
00027 
00028 #include "engines/stark/visual/actor.h"
00029 #include "engines/stark/visual/effects/bubbles.h"
00030 #include "engines/stark/visual/effects/fireflies.h"
00031 #include "engines/stark/visual/effects/fish.h"
00032 #include "engines/stark/visual/image.h"
00033 #include "engines/stark/visual/prop.h"
00034 #include "engines/stark/visual/smacker.h"
00035 #include "engines/stark/visual/text.h"
00036 #include "engines/stark/visual/visual.h"
00037 
00038 namespace Stark {
00039 namespace Gfx {
00040 
00041 RenderEntry::RenderEntry(Resources::ItemVisual *owner, const Common::String &name) :
00042         _visual(nullptr),
00043         _name(name),
00044         _owner(owner),
00045         _direction3D(0.0),
00046         _sortKey(0.0),
00047         _clickable(true) {
00048 }
00049 
00050 void RenderEntry::render(const LightEntryArray &lights) {
00051     if (!_visual) {
00052         // warning("No visual for render entry '%s'", _name.c_str());
00053         return;
00054     }
00055 
00056     VisualImageXMG *imageXMG = _visual->get<VisualImageXMG>();
00057     if (imageXMG) {
00058         imageXMG->render(_position, true);
00059     }
00060 
00061     VisualActor *actor = _visual->get<VisualActor>();
00062     if (actor) {
00063         actor->render(_position3D, _direction3D, lights);
00064     }
00065 
00066     VisualProp *prop = _visual->get<VisualProp>();
00067     if (prop) {
00068         prop->render(_position3D, _direction3D, lights);
00069     }
00070 
00071     VisualSmacker *smacker = _visual->get<VisualSmacker>();
00072     if (smacker) {
00073         smacker->render(_position);
00074     }
00075 
00076     VisualText *text = _visual->get<VisualText>();
00077     if (text) {
00078         text->render(_position);
00079     }
00080 
00081     VisualEffectBubbles *bubbles = _visual->get<VisualEffectBubbles>();
00082     if (bubbles) {
00083         bubbles->render(_position);
00084     }
00085 
00086     VisualEffectFireFlies *fireflies = _visual->get<VisualEffectFireFlies>();
00087     if (fireflies) {
00088         fireflies->render(_position);
00089     }
00090 
00091     VisualEffectFish *fish = _visual->get<VisualEffectFish>();
00092     if (fish) {
00093         fish->render(_position);
00094     }
00095 }
00096 
00097 void RenderEntry::setVisual(Visual *visual) {
00098     _visual = visual;
00099 }
00100 
00101 void RenderEntry::setPosition(const Common::Point &position) {
00102     _position = position;
00103 }
00104 
00105 void RenderEntry::setPosition3D(const Math::Vector3d &position, float direction) {
00106     _position3D = position;
00107     _direction3D = direction;
00108 }
00109 
00110 void RenderEntry::setSortKey(float sortKey) {
00111     _sortKey = sortKey;
00112 }
00113 
00114 void RenderEntry::setClickable(bool clickable) {
00115     _clickable = clickable;
00116 }
00117 
00118 bool RenderEntry::compare(const RenderEntry *x, const RenderEntry *y) {
00119     if (x->_sortKey != y->_sortKey) {
00120         return x->_sortKey < y->_sortKey;
00121     } else if (x->_owner && y->_owner) {
00122         // The original used a stable sort. Common::sort is not.
00123         // This should ensure the items remain in the same order if they have the same sort key
00124         return x->_owner->getIndex() < y->_owner->getIndex();
00125     } else {
00126         return -1;
00127     }
00128 }
00129 
00130 bool RenderEntry::containsPoint(const Common::Point &position, Common::Point &relativePosition, const Common::Rect &cursorRect) const {
00131     if (!_visual || !_clickable) {
00132         return false;
00133     }
00134 
00135     VisualImageXMG *image = _visual->get<VisualImageXMG>();
00136     if (image) {
00137         Common::Rect imageRect = Common::Rect(image->getWidth(), image->getHeight());
00138         imageRect.translate(_position.x, _position.y);
00139         imageRect.translate(-image->getHotspot().x, -image->getHotspot().y);
00140 
00141         relativePosition.x = position.x - imageRect.left;
00142         relativePosition.y = position.y - imageRect.top;
00143         if (imageRect.contains(position) && image->isPointSolid(relativePosition)) {
00144             return true;
00145         }
00146 
00147         if (imageRect.width() < 32 && imageRect.height() < 32
00148                 && !cursorRect.isEmpty() && cursorRect.intersects(imageRect)) {
00149             // If the item in the scene is way smaller than the cursor,
00150             // use the whole cursor as a hit rectangle.
00151             relativePosition.x = 1 - image->getHotspot().x;
00152             relativePosition.y = 1 - image->getHotspot().y;
00153 
00154             return true;
00155         }
00156     }
00157 
00158     VisualSmacker *smacker = _visual->get<VisualSmacker>();
00159     if (smacker) {
00160         Common::Point smackerPosition = smacker->getPosition();
00161         smackerPosition -= _position;
00162 
00163         Common::Rect smackerRect = Common::Rect(smacker->getWidth(), smacker->getHeight());
00164         smackerRect.translate(smackerPosition.x, smackerPosition.y);
00165 
00166         relativePosition.x = position.x - smackerRect.left;
00167         relativePosition.y = position.y - smackerRect.top;
00168         if (smackerRect.contains(position) && smacker->isPointSolid(relativePosition)) {
00169             return true;
00170         }
00171     }
00172 
00173     VisualText *text = _visual->get<VisualText>();
00174     if (text) {
00175         Common::Rect textRect = text->getRect();
00176         textRect.translate(_position.x, _position.y);
00177 
00178         relativePosition.x = position.x - textRect.left;
00179         relativePosition.y = position.y - textRect.top;
00180         if (textRect.contains(position)) {
00181             return true;
00182         }
00183     }
00184 
00185     return false;
00186 }
00187 
00188 bool RenderEntry::intersectRay(const Math::Ray &ray) const {
00189     if (!_visual || !_clickable) {
00190         return false;
00191     }
00192 
00193     VisualActor *actor = _visual->get<VisualActor>();
00194     if (actor) {
00195         return actor->intersectRay(ray, _position3D, _direction3D);
00196     }
00197 
00198     VisualProp *prop = _visual->get<VisualProp>();
00199     if (prop) {
00200         return prop->intersectRay(ray, _position3D, _direction3D);
00201     }
00202 
00203     return false;
00204 }
00205 
00206 VisualImageXMG *RenderEntry::getImage() const {
00207     if (!_visual) {
00208         return nullptr;
00209     }
00210     return _visual->get<VisualImageXMG>();
00211 }
00212 
00213 VisualText *RenderEntry::getText() const {
00214     if (!_visual) {
00215         return nullptr;
00216     }
00217     return _visual->get<VisualText>();
00218 }
00219 
00220 Common::Rect RenderEntry::getBoundingRect() const {
00221     if (!_visual) {
00222         return Common::Rect();
00223     }
00224 
00225     VisualActor *actor = _visual->get<VisualActor>();
00226     if (actor) {
00227         return actor->getBoundingRect(_position3D, _direction3D);
00228     }
00229 
00230     warning("RenderEntry::getBoundingRect is not implemented for '%s'", _name.c_str());
00231     return Common::Rect();
00232 }
00233 
00234 } // End of namespace Gfx
00235 } // End of namespace Stark


Generated on Sat Apr 20 2019 05:03:39 for ResidualVM by doxygen 1.7.1
curved edge   curved edge