From 55725c21b36795955153d1a700f9d587c7d87763 Mon Sep 17 00:00:00 2001 From: Fabien_HENON Date: Tue, 7 Aug 2012 22:12:06 +0200 Subject: [PATCH] Added: #1469 Basic update mechanics implemented for the camera animation player with a changement of the prototypes from steps and modifiers --HG-- branch : gsoc2012-fabien --- .../camera_animation_info.h | 52 ++++++++++++++++ ...camera_animation_modifier_player_factory.h | 10 +++- .../camera_animation_modifiers_players.cpp | 13 +++- .../camera_animation_player.cpp | 60 +++++++++++++++---- .../camera_animation_player.h | 11 +++- .../camera_animation_step_player_factory.cpp | 30 +++++++--- .../camera_animation_step_player_factory.h | 18 +++++- .../camera_animation_steps_players.cpp | 46 +++++++++++--- 8 files changed, 204 insertions(+), 36 deletions(-) create mode 100644 code/ryzom/client/src/camera_animation_manager/camera_animation_info.h diff --git a/code/ryzom/client/src/camera_animation_manager/camera_animation_info.h b/code/ryzom/client/src/camera_animation_manager/camera_animation_info.h new file mode 100644 index 000000000..98a5cfa75 --- /dev/null +++ b/code/ryzom/client/src/camera_animation_manager/camera_animation_info.h @@ -0,0 +1,52 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef RY_CAMERAANIMATIONINFO_H +#define RY_CAMERAANIMATIONINFO_H + + +#include "nel/misc/vector.h" + + +/************************************************************************/ +/* Class that contains information about the camera + * + * \author Fabien Henon + * \date 2012 + */ +/************************************************************************/ +struct TCameraAnimationInfo +{ + TCameraAnimationInfo(const NLMISC::CVector& camPos, + const NLMISC::CVector& camLookAt, + float elapsedTimeSinceStartStep) + { + CamPos = camPos; + CamLookAt = camLookAt; + ElapsedTimeSinceStartStep = elapsedTimeSinceStartStep; + } + + TCameraAnimationInfo() {} + + NLMISC::CVector CamPos; /// Camera position + NLMISC::CVector CamLookAt; /// Camera look at position + + float ElapsedTimeSinceStartStep; /// Elapsed time in second since the beginning of this step +}; + + + +#endif /* RY_CAMERAANIMATIONINFO_H */ diff --git a/code/ryzom/client/src/camera_animation_manager/camera_animation_modifier_player_factory.h b/code/ryzom/client/src/camera_animation_manager/camera_animation_modifier_player_factory.h index 006d71c0d..9cdf32393 100644 --- a/code/ryzom/client/src/camera_animation_manager/camera_animation_modifier_player_factory.h +++ b/code/ryzom/client/src/camera_animation_manager/camera_animation_modifier_player_factory.h @@ -20,6 +20,7 @@ #include #include #include "nel\misc\bit_mem_stream.h" +#include "camera_animation_manager\camera_animation_info.h" /************************************************************************/ /* Interface for camera animation modifiers. @@ -32,8 +33,13 @@ public: /// This function is called when it's time to init the modifier from an impulse virtual bool initModifier(NLMISC::CBitMemStream& impulse) = 0; - /// Function that plays the modifier - virtual void playModifier() = 0; + /// Function that updates the modifier + /// currCamInfo contains information about the current camera position and look at position + /// The function must return the new camera information + virtual TCameraAnimationInfo updateModifier(const TCameraAnimationInfo& currCamInfo) = 0; + + /// Function called when the modifier is stopped + virtual void stopModifier() = 0; protected: }; diff --git a/code/ryzom/client/src/camera_animation_manager/camera_animation_modifiers_players.cpp b/code/ryzom/client/src/camera_animation_manager/camera_animation_modifiers_players.cpp index bc66187e0..055506ce4 100644 --- a/code/ryzom/client/src/camera_animation_manager/camera_animation_modifiers_players.cpp +++ b/code/ryzom/client/src/camera_animation_manager/camera_animation_modifiers_players.cpp @@ -17,6 +17,7 @@ #include "camera_animation_manager/camera_animation_modifier_player_factory.h" #include "game_share/position_or_entity_type.h" +#include "camera_animation_manager\camera_animation_info.h" ///////////////////////////////////////////////////////////////////////////// /// This animation modifier shakes the camera. The parameter is @@ -41,9 +42,13 @@ public: } /// Function that plays the modifier - virtual void playModifier() + virtual TCameraAnimationInfo updateModifier(const TCameraAnimationInfo& currCamInfo) { + return currCamInfo; + } + virtual void stopModifier() + { } }; CAMERA_ANIMATION_REGISTER_MODIFIER_PLAYER(CCameraAnimationModifierPlayerShake, "camera_modifier_shake"); @@ -74,9 +79,13 @@ public: } /// Function that plays the modifier - virtual void playModifier() + virtual TCameraAnimationInfo updateModifier(const TCameraAnimationInfo& currCamInfo) { + return currCamInfo; + } + virtual void stopModifier() + { } }; CAMERA_ANIMATION_REGISTER_MODIFIER_PLAYER(CCameraAnimationModifierPlayerSoundTrigger, "sound_trigger"); \ No newline at end of file diff --git a/code/ryzom/client/src/camera_animation_manager/camera_animation_player.cpp b/code/ryzom/client/src/camera_animation_manager/camera_animation_player.cpp index 95a61e009..0ec699f34 100644 --- a/code/ryzom/client/src/camera_animation_manager/camera_animation_player.cpp +++ b/code/ryzom/client/src/camera_animation_manager/camera_animation_player.cpp @@ -18,6 +18,8 @@ #include "camera_animation_manager/camera_animation_player.h" #include "camera_animation_manager/camera_animation_step_player_factory.h" +#include "time_client.h" +#include "view.h" using namespace std; using namespace NLMISC; @@ -30,6 +32,8 @@ CCameraAnimationPlayer* CCameraAnimationPlayer::_Instance = NULL; CCameraAnimationPlayer::CCameraAnimationPlayer() { _IsPlaying = false; + _CurrStep = NULL; + _ElapsedTimeForCurrStep = 0.f; } CCameraAnimationPlayer::~CCameraAnimationPlayer() @@ -49,13 +53,22 @@ void CCameraAnimationPlayer::stop() { _IsPlaying = false; - // We release the steps and modifiers - for (std::vector::iterator it = _Steps.begin(); it != _Steps.end(); ++it) + stopStep(); +} + +void CCameraAnimationPlayer::stopStep() +{ + // We release the step and modifiers + if (_CurrStep) { - ICameraAnimationStepPlayer* step = *it; - delete step; + // We first tell the step we stop it + _CurrStep->stopStepAndModifiers(); + + delete _CurrStep; + _CurrStep = NULL; + + _ElapsedTimeForCurrStep = 0.f; } - _Steps.clear(); } void CCameraAnimationPlayer::playStep(const std::string& stepName, NLMISC::CBitMemStream& impulse) @@ -67,21 +80,44 @@ void CCameraAnimationPlayer::playStep(const std::string& stepName, NLMISC::CBitM return; } + // We stop the current step if there is one + stopStep(); + // We initialize the step with the factory - ICameraAnimationStepPlayer* step = ICameraAnimationStepPlayerFactory::initStep(stepName, impulse); - if (step == NULL) + _CurrStep = ICameraAnimationStepPlayerFactory::initStep(stepName, impulse); + if (_CurrStep == NULL) { nlwarning("CameraAnimationPlayer: cannot create step player %s", stepName.c_str()); + _IsPlaying = false; return; } - // We add the step to our list - _Steps.push_back(step); - // We start playing the step - step->playStepAndModifiers(); + _ElapsedTimeForCurrStep = 0.f; } bool CCameraAnimationPlayer::isPlaying() { return _IsPlaying; -} \ No newline at end of file +} + +TCameraAnimationInfo CCameraAnimationPlayer::update() +{ + // We get the current camera information + NLMISC::CVector camLookAt = View.view(); + NLMISC::CVector camPos = View.viewPos(); + + // We update the elapsed time for this step + _ElapsedTimeForCurrStep += DT; + + TCameraAnimationInfo currCamInfo(camPos, camLookAt, _ElapsedTimeForCurrStep); + + if (!isPlaying()) + return currCamInfo; + if (_CurrStep == NULL) + return currCamInfo; + + // We update the current step + currCamInfo = _CurrStep->updateStepAndModifiers(currCamInfo); + + return currCamInfo; +} diff --git a/code/ryzom/client/src/camera_animation_manager/camera_animation_player.h b/code/ryzom/client/src/camera_animation_manager/camera_animation_player.h index 4bc64a4eb..a7a3f253b 100644 --- a/code/ryzom/client/src/camera_animation_manager/camera_animation_player.h +++ b/code/ryzom/client/src/camera_animation_manager/camera_animation_player.h @@ -21,6 +21,8 @@ #include #include "nel\misc\bit_mem_stream.h" #include "camera_animation_manager/camera_animation_step_player_factory.h" +#include "nel/misc/vector.h" +#include "camera_animation_manager\camera_animation_info.h" /************************************************************************/ @@ -63,19 +65,26 @@ public: /// Checks if an animation is being played bool isPlaying(); + /// Updates the camera by calling the update function of the current step and modifiers + TCameraAnimationInfo update(); + private: /// Constructor CCameraAnimationPlayer(); /// Destructor ~CCameraAnimationPlayer(); + /// Stops the current step + void stopStep(); + /// Instance of the manager static CCameraAnimationPlayer* _Instance; bool _IsPlaying; - std::vector _Steps; + ICameraAnimationStepPlayer* _CurrStep; + float _ElapsedTimeForCurrStep; }; diff --git a/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.cpp b/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.cpp index 36b07d4b2..b5791b50c 100644 --- a/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.cpp +++ b/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.cpp @@ -92,17 +92,33 @@ void ICameraAnimationStepPlayer::addModifier(ICameraAnimationModifierPlayer* mod Modifiers.push_back(modifier); } -void ICameraAnimationStepPlayer::playStepAndModifiers() +TCameraAnimationInfo ICameraAnimationStepPlayer::updateStepAndModifiers(const TCameraAnimationInfo& currCamInfo) { - // Play the step - playStep(); + // Updates the step + TCameraAnimationInfo newInfo = updateStep(currCamInfo); - // Play the modifiers + // Updates the modifiers for (std::vector::iterator it = Modifiers.begin(); it != Modifiers.end(); ++it) { ICameraAnimationModifierPlayer* modifier = *it; - // We play the modifier - modifier->playModifier(); + // We update the modifier + newInfo = modifier->updateModifier(newInfo); } -} \ No newline at end of file + return newInfo; +} + +void ICameraAnimationStepPlayer::stopStepAndModifiers() +{ + // Stops the step + stopStep(); + + // Stops the modifiers + for (std::vector::iterator it = Modifiers.begin(); it != Modifiers.end(); ++it) + { + ICameraAnimationModifierPlayer* modifier = *it; + + // We stop the modifier + modifier->stopModifier(); + } +} diff --git a/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.h b/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.h index 81d5379d9..c4fb77d2d 100644 --- a/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.h +++ b/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.h @@ -21,6 +21,7 @@ #include #include "nel\misc\bit_mem_stream.h" #include "camera_animation_manager\camera_animation_modifier_player_factory.h" +#include "camera_animation_manager\camera_animation_info.h" /************************************************************************/ /* Interface for camera animation steps. @@ -35,14 +36,25 @@ public: /// This function is called when it's time to init the step from an impulse virtual bool initStep(NLMISC::CBitMemStream& impulse) = 0; - /// Function that plays the step - virtual void playStep() = 0; + /// Function that updates the camera with the step + /// currCamInfo contains information about the current camera position and look at position + /// The function must return the new camera information + virtual TCameraAnimationInfo updateStep(const TCameraAnimationInfo& currCamInfo) = 0; + + /// Function called when the step stops + virtual void stopStep() = 0; + + /// Gets the duration in seconds of this step + virtual float getDuration() const = 0; /// Function that adds a camera animation modifier to this step void addModifier(ICameraAnimationModifierPlayer* modifier); // Plays the step and its modifiers - void playStepAndModifiers(); + TCameraAnimationInfo updateStepAndModifiers(const TCameraAnimationInfo& currCamInfo); + + // Stops the step and its modifiers + void stopStepAndModifiers(); protected: // The list of modifiers diff --git a/code/ryzom/client/src/camera_animation_manager/camera_animation_steps_players.cpp b/code/ryzom/client/src/camera_animation_manager/camera_animation_steps_players.cpp index a742ebdd6..6453e0f9c 100644 --- a/code/ryzom/client/src/camera_animation_manager/camera_animation_steps_players.cpp +++ b/code/ryzom/client/src/camera_animation_manager/camera_animation_steps_players.cpp @@ -17,7 +17,7 @@ #include "camera_animation_manager/camera_animation_step_player_factory.h" #include "game_share/position_or_entity_type.h" - +#include "camera_animation_manager\camera_animation_info.h" /// Basic camera animation step that has generic values @@ -38,6 +38,11 @@ public: Duration = 0.f; } + virtual float getDuration() const + { + return Duration; + } + /// This function is called when it's time to init the step from an impulse virtual bool initStep(NLMISC::CBitMemStream& impulse) { @@ -48,10 +53,8 @@ public: return true; } - /// Function that plays the step - virtual void playStep() + virtual void stopStep() { - } }; // This class must not be registered because it's a base class @@ -69,9 +72,13 @@ public: } /// Function that plays the step - virtual void playStep() + virtual TCameraAnimationInfo updateStep(const TCameraAnimationInfo& currCamInfo) { + return currCamInfo; + } + virtual void stopStep() + { } }; CAMERA_ANIMATION_REGISTER_STEP_PLAYER(CCameraAnimationStepPlayerStatic, "camera_animation_static"); @@ -100,9 +107,13 @@ public: } /// Function that plays the step - virtual void playStep() + virtual TCameraAnimationInfo updateStep(const TCameraAnimationInfo& currCamInfo) { + return currCamInfo; + } + virtual void stopStep() + { } }; CAMERA_ANIMATION_REGISTER_STEP_PLAYER(CCameraAnimationStepPlayerGoTo, "camera_animation_go_to"); @@ -135,9 +146,13 @@ public: } /// Function that plays the step - virtual void playStep() + virtual TCameraAnimationInfo updateStep(const TCameraAnimationInfo& currCamInfo) { + return currCamInfo; + } + virtual void stopStep() + { } }; CAMERA_ANIMATION_REGISTER_STEP_PLAYER(CCameraAnimationStepPlayerFollowEntity, "camera_animation_follow_entity"); @@ -174,9 +189,13 @@ public: } /// Function that plays the step - virtual void playStep() + virtual TCameraAnimationInfo updateStep(const TCameraAnimationInfo& currCamInfo) { + return currCamInfo; + } + virtual void stopStep() + { } }; CAMERA_ANIMATION_REGISTER_STEP_PLAYER(CCameraAnimationStepPlayerTurnAround, "camera_animation_turn_around"); @@ -196,6 +215,11 @@ public: Duration = 0.f; } + virtual float getDuration() const + { + return Duration; + } + /// This function is called when it's time to init the step from an impulse virtual bool initStep(NLMISC::CBitMemStream& impulse) { @@ -205,9 +229,13 @@ public: } /// Function that plays the step - virtual void playStep() + virtual TCameraAnimationInfo updateStep(const TCameraAnimationInfo& currCamInfo) { + return currCamInfo; + } + virtual void stopStep() + { } }; CAMERA_ANIMATION_REGISTER_STEP_PLAYER(CCameraAnimationStepPlayerReturn, "camera_animation_return"); \ No newline at end of file