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
hg/feature/gsoc2012-fabien
Fabien_HENON 12 years ago
parent 666ff05c42
commit 55725c21b3

@ -0,0 +1,52 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// 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 <http://www.gnu.org/licenses/>.
#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 */

@ -20,6 +20,7 @@
#include <string>
#include <vector>
#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:
};

@ -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");

@ -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<ICameraAnimationStepPlayer*>::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;
}
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;
}

@ -21,6 +21,8 @@
#include <string>
#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<ICameraAnimationStepPlayer*> _Steps;
ICameraAnimationStepPlayer* _CurrStep;
float _ElapsedTimeForCurrStep;
};

@ -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<ICameraAnimationModifierPlayer*>::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);
}
return newInfo;
}
void ICameraAnimationStepPlayer::stopStepAndModifiers()
{
// Stops the step
stopStep();
// Stops the modifiers
for (std::vector<ICameraAnimationModifierPlayer*>::iterator it = Modifiers.begin(); it != Modifiers.end(); ++it)
{
ICameraAnimationModifierPlayer* modifier = *it;
// We stop the modifier
modifier->stopModifier();
}
}

@ -21,6 +21,7 @@
#include <vector>
#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

@ -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");
Loading…
Cancel
Save