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

followpathlight.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/movement/followpathlight.h"
00024 
00025 #include "engines/stark/services/global.h"
00026 #include "engines/stark/services/services.h"
00027 #include "engines/stark/services/stateprovider.h"
00028 
00029 #include "engines/stark/resources/anim.h"
00030 #include "engines/stark/resources/floor.h"
00031 #include "engines/stark/resources/item.h"
00032 #include "engines/stark/resources/light.h"
00033 #include "engines/stark/resources/path.h"
00034 
00035 namespace Stark {
00036 
00037 FollowPathLight::FollowPathLight(Resources::ItemVisual *item) :
00038         Movement(item),
00039         _light(nullptr),
00040         _path(nullptr),
00041         _speed(0.0),
00042         _position(0.0),
00043         _previouslyEnabled(true) {
00044 }
00045 
00046 FollowPathLight::~FollowPathLight() {
00047 }
00048 
00049 void FollowPathLight::start() {
00050     Movement::start();
00051 
00052     _previouslyEnabled = _item->isEnabled();
00053     _item->setEnabled(true);
00054 
00055     Math::Vector3d newPosition = _path->getWeightedPositionInEdge(0, 0);
00056     _light->setPosition(newPosition);
00057 }
00058 
00059 void FollowPathLight::stop(bool force) {
00060     Movement::stop(force);
00061 
00062     _item->setEnabled(_previouslyEnabled);
00063 }
00064 
00065 void FollowPathLight::onGameLoop() {
00066     // Compute the new position on the path
00067     _position += _speed * StarkGlobal->getMillisecondsPerGameloop();
00068 
00069     // Find the current path edge, and position on the path edge
00070     uint currentEdge = 0;
00071     float positionInEdge = _position;
00072     for (uint i = 0; i < _path->getEdgeCount(); i++) {
00073         float edgeLength = _path->getWeightedEdgeLength(i);
00074         if (positionInEdge < edgeLength) {
00075             break; // Found the current path edge
00076         }
00077 
00078         positionInEdge -= edgeLength;
00079         currentEdge++;
00080     }
00081 
00082     // Check if we went beyond the path's end
00083     if (currentEdge >= _path->getEdgeCount()) {
00084         stop();
00085         return;
00086     }
00087 
00088     // Set the new position for the light
00089     Math::Vector3d newPosition = _path->getWeightedPositionInEdge(currentEdge, positionInEdge);
00090     _light->setPosition(newPosition);
00091 }
00092 
00093 void FollowPathLight::setPath(Resources::Path *path) {
00094     _path = path;
00095 }
00096 
00097 void FollowPathLight::setSpeed(float speed) {
00098     _speed = speed;
00099 }
00100 
00101 void FollowPathLight::setLight(Resources::Light *light) {
00102     _light = light;
00103 }
00104 
00105 uint32 FollowPathLight::getType() const {
00106     return kTypeFollowPathLight;
00107 }
00108 
00109 void FollowPathLight::saveLoad(ResourceSerializer *serializer) {
00110     serializer->syncAsResourceReference(&_path);
00111     serializer->syncAsResourceReference(&_light);
00112     serializer->syncAsFloat(_position);
00113     serializer->syncAsFloat(_speed);
00114     serializer->syncAsUint32LE(_previouslyEnabled);
00115 }
00116 
00117 } // End of namespace Stark


Generated on Sat Feb 16 2019 05:00:51 for ResidualVM by doxygen 1.7.1
curved edge   curved edge