Compare commits
117 Commits
main/gingo
...
hg/feature
Author | SHA1 | Date |
---|---|---|
kaetemi | d2a267c531 | 10 years ago |
kaetemi | dd91970e9e | 11 years ago |
kaetemi | 804fe05b9d | 11 years ago |
kaetemi | cdb8646529 | 11 years ago |
kaetemi | 82fd552aaa | 11 years ago |
kaetemi | 72a647afb9 | 11 years ago |
kaetemi | f75ba5b5e3 | 11 years ago |
Fabien_HENON | ed54bcf00b | 12 years ago |
Fabien_HENON | c21fbc5a9f | 12 years ago |
Fabien_HENON | 55582b6d05 | 12 years ago |
Fabien_HENON | 7ab6ede55c | 12 years ago |
Fabien_HENON | 9d592fdc63 | 12 years ago |
Fabien_HENON | 716a7aedc7 | 12 years ago |
Fabien_HENON | 2e50568194 | 12 years ago |
Fabien_HENON | 2fd91e5277 | 12 years ago |
Fabien_HENON | 714b2bf86a | 12 years ago |
Fabien_HENON | d16b48632a | 13 years ago |
Fabien_HENON | 8252d36db8 | 13 years ago |
Fabien_HENON | 450204439a | 13 years ago |
Fabien_HENON | 9c838c39ed | 13 years ago |
Fabien_HENON | 1774ee7278 | 13 years ago |
Fabien_HENON | 9f4d2fea74 | 13 years ago |
Fabien_HENON | 0553079378 | 13 years ago |
Fabien_HENON | 3e6ffa8b43 | 13 years ago |
Fabien_HENON | e218106b3e | 13 years ago |
Fabien_HENON | 15ae25878f | 13 years ago |
Fabien_HENON | ce627c7923 | 13 years ago |
Fabien_HENON | 1fca8f4b6a | 13 years ago |
Fabien_HENON | 050f3f644a | 13 years ago |
Fabien_HENON | c2770d9ae5 | 13 years ago |
Fabien_HENON | f5912260b2 | 13 years ago |
Fabien_HENON | 39d4791628 | 13 years ago |
Fabien_HENON | c29dc1bf43 | 13 years ago |
Fabien_HENON | d833a222c5 | 13 years ago |
Fabien_HENON | bd69090057 | 13 years ago |
Fabien_HENON | 46a64b06b5 | 13 years ago |
Fabien_HENON | d638e71f79 | 13 years ago |
Fabien_HENON | 24461197d5 | 13 years ago |
Fabien_HENON | 55725c21b3 | 13 years ago |
Fabien_HENON | 666ff05c42 | 13 years ago |
Fabien_HENON | 16daae2b6e | 13 years ago |
Fabien_HENON | 4fecf73407 | 13 years ago |
Fabien_HENON | 162f63a6f4 | 13 years ago |
Fabien_HENON | a27c34c705 | 13 years ago |
Fabien_HENON | af59474d9c | 13 years ago |
Fabien_HENON | 160ec7ea91 | 13 years ago |
Fabien_HENON | 69545610b5 | 13 years ago |
Fabien_HENON | e61d13566e | 13 years ago |
Fabien_HENON | 64b1ba3752 | 13 years ago |
Fabien_HENON | 5f2b62c32c | 13 years ago |
Fabien_HENON | 29dca7b9d7 | 13 years ago |
Fabien_HENON | 448d822b4d | 13 years ago |
Fabien_HENON | 1ffab89cd1 | 13 years ago |
Fabien_HENON | b22e255762 | 13 years ago |
Fabien_HENON | b0858977e7 | 13 years ago |
Fabien_HENON | 55297dbe65 | 13 years ago |
Fabien_HENON | a66aa09e61 | 13 years ago |
Fabien_HENON | 0cb700b1bd | 13 years ago |
Fabien_HENON | 117379cae0 | 13 years ago |
Fabien_HENON | ea7a53b717 | 13 years ago |
Fabien_HENON | 1eadeb0ed5 | 13 years ago |
Fabien_HENON | a019880cbd | 13 years ago |
Fabien_HENON | bda94764fa | 13 years ago |
Fabien_HENON | f48f4d25aa | 13 years ago |
Fabien_HENON | e0084d7f4b | 13 years ago |
Fabien_HENON | a46165e97f | 13 years ago |
Fabien_HENON | e3edccf3ea | 13 years ago |
Fabien_HENON | fa194fa246 | 13 years ago |
Fabien_HENON | 95b28dc3bb | 13 years ago |
Fabien_HENON | a2acbb4988 | 13 years ago |
Fabien_HENON | 0451f31350 | 13 years ago |
Fabien_HENON | 2334512d63 | 13 years ago |
Fabien_HENON | 1095975a3f | 13 years ago |
Fabien_HENON | e584749c5a | 13 years ago |
Fabien_HENON | 73d578b764 | 13 years ago |
Fabien_HENON | 5075bc80ef | 13 years ago |
Fabien_HENON | f7a1e6cdbe | 13 years ago |
Fabien_HENON | 5b8c34b25e | 13 years ago |
Fabien_HENON | 027ec2ca98 | 13 years ago |
Fabien_HENON | eb5769e0ef | 13 years ago |
Fabien_HENON | b99cfc1557 | 13 years ago |
Fabien_HENON | 2d3b82ff57 | 13 years ago |
Fabien_HENON | 2629c3cf5f | 13 years ago |
Fabien_HENON | 2b954a23db | 13 years ago |
Fabien_HENON | e72956026a | 13 years ago |
Fabien_HENON | 5f51257a7d | 13 years ago |
Fabien_HENON | ec6af57aa6 | 13 years ago |
Fabien_HENON | a1c8c9dc8a | 13 years ago |
Fabien_HENON | be0fdfc666 | 13 years ago |
Fabien_HENON | ae6aeb5c22 | 13 years ago |
Fabien_HENON | c997a32bf0 | 13 years ago |
Fabien_HENON | 4973f33005 | 13 years ago |
Fabien_HENON | bb1740cfae | 13 years ago |
Fabien_HENON | 3bf06cb247 | 13 years ago |
Fabien_HENON | d89477ff21 | 13 years ago |
Fabien_HENON | 2f8696133a | 13 years ago |
Fabien_HENON | a1c8a2561e | 13 years ago |
Fabien_HENON | ed42786901 | 13 years ago |
Fabien_HENON | 4a153d8e55 | 13 years ago |
Fabien_HENON | 9df8440d38 | 13 years ago |
Fabien_HENON | 043437e9b1 | 13 years ago |
Fabien_HENON | 10fdd4d28c | 13 years ago |
Fabien_HENON | 94c3b7b47c | 13 years ago |
Fabien_HENON | 0af5c0518b | 13 years ago |
Fabien_HENON | 072d2e0385 | 13 years ago |
Fabien_HENON | a609fb6c4c | 13 years ago |
Fabien_HENON | 99b9ef33b8 | 13 years ago |
Fabien_HENON | 1e92233953 | 13 years ago |
Fabien_HENON | 7b8e98834d | 13 years ago |
Fabien_HENON | afbbced99b | 13 years ago |
Fabien_HENON | 477c53fd61 | 13 years ago |
Fabien_HENON | 012a9d1897 | 13 years ago |
Fabien_HENON | 8fd4987016 | 13 years ago |
Fabien_HENON | 49509937fe | 13 years ago |
Fabien_HENON | 128cf1c517 | 13 years ago |
Fabien_HENON | e9ace5fde1 | 13 years ago |
Fabien_HENON | 8d3d1fcfcf | 13 years ago |
@ -0,0 +1,102 @@
|
||||
// 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 new information about the camera
|
||||
*
|
||||
* \author Fabien Henon
|
||||
* \date 2012
|
||||
*/
|
||||
/************************************************************************/
|
||||
struct TCameraAnimationOutputInfo
|
||||
{
|
||||
TCameraAnimationOutputInfo() {}
|
||||
|
||||
NLMISC::CVector CamPos; /// Camera position
|
||||
NLMISC::CVector CamLookAtDir; /// Camera look at direction
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
/* Class that contains current information about the camera
|
||||
*
|
||||
* \author Fabien Henon
|
||||
* \date 2012
|
||||
*/
|
||||
/************************************************************************/
|
||||
struct TCameraAnimationInputInfo
|
||||
{
|
||||
TCameraAnimationInputInfo(const NLMISC::CVector& currCamPos, const NLMISC::CVector& currCamLookAtDir,
|
||||
const NLMISC::CVector& startCamPos, const NLMISC::CVector& startCamLookAtDir,
|
||||
const NLMISC::CVector& animStartCamPos, const NLMISC::CVector& animStartCamLookAtDir,
|
||||
float elapsedTimeSinceStartStep)
|
||||
{
|
||||
CamPos = currCamPos;
|
||||
CamLookAtDir = currCamLookAtDir;
|
||||
|
||||
StartCamPos = startCamPos;
|
||||
StartCamLookAtDir = startCamLookAtDir;
|
||||
|
||||
AnimStartCamPos = animStartCamPos;
|
||||
AnimStartCamLookAtDir = animStartCamLookAtDir;
|
||||
|
||||
ElapsedTimeSinceStartStep = elapsedTimeSinceStartStep;
|
||||
}
|
||||
|
||||
TCameraAnimationInputInfo(const TCameraAnimationOutputInfo& output, const TCameraAnimationInputInfo& input)
|
||||
{
|
||||
CamPos = output.CamPos;
|
||||
CamLookAtDir = output.CamLookAtDir;
|
||||
|
||||
StartCamPos = input.StartCamPos;
|
||||
StartCamLookAtDir = input.StartCamLookAtDir;
|
||||
|
||||
AnimStartCamPos = input.AnimStartCamPos;
|
||||
AnimStartCamLookAtDir = input.AnimStartCamLookAtDir;
|
||||
|
||||
ElapsedTimeSinceStartStep = input.ElapsedTimeSinceStartStep;
|
||||
}
|
||||
|
||||
TCameraAnimationOutputInfo toOutput() const
|
||||
{
|
||||
TCameraAnimationOutputInfo output;
|
||||
output.CamPos = CamPos;
|
||||
output.CamLookAtDir = CamLookAtDir;
|
||||
return output;
|
||||
}
|
||||
|
||||
NLMISC::CVector CamPos; /// Current camera position
|
||||
NLMISC::CVector CamLookAtDir; /// Current camera look at direction
|
||||
|
||||
NLMISC::CVector StartCamPos; /// Start camera position
|
||||
NLMISC::CVector StartCamLookAtDir; /// Start camera look at direction
|
||||
|
||||
NLMISC::CVector AnimStartCamPos; /// Camera position at animation start
|
||||
NLMISC::CVector AnimStartCamLookAtDir; /// Camera look at direction an animation start
|
||||
|
||||
float ElapsedTimeSinceStartStep; /// Elapsed time in second since the beginning of this step
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* RY_CAMERAANIMATIONINFO_H */
|
@ -0,0 +1,57 @@
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
#include "camera_animation_manager/camera_animation_modifier_player_factory.h"
|
||||
|
||||
std::vector<std::pair<std::string, ICameraAnimationModifierPlayerFactory*> >* ICameraAnimationModifierPlayerFactory::Entries;
|
||||
|
||||
ICameraAnimationModifierPlayer* ICameraAnimationModifierPlayerFactory::initModifier(const std::string& name, NLMISC::CBitMemStream& impulse)
|
||||
{
|
||||
if (!Entries)
|
||||
return NULL;
|
||||
|
||||
// We search the correct modifier type in our entries
|
||||
for (uint i = 0; i < Entries->size(); i++)
|
||||
{
|
||||
if (name == (*Entries)[i].first)
|
||||
{
|
||||
ICameraAnimationModifierPlayer* ret = (*Entries)[i].second->instanciate();
|
||||
if (!ret)
|
||||
{
|
||||
nlwarning("BUG IN CAMERA ANIMATION MODIFIER PLAYER FACTORY : BAD INIT CODE %s", name.c_str());
|
||||
return NULL;
|
||||
}
|
||||
// We init the modifier
|
||||
if (!ret->initModifier(impulse))
|
||||
{
|
||||
nlwarning("building camera animation modifier player failed %s", name.c_str());
|
||||
delete ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ICameraAnimationModifierPlayerFactory::init()
|
||||
{
|
||||
if (!Entries)
|
||||
Entries = new std::vector<std::pair<std::string, ICameraAnimationModifierPlayerFactory*> >;
|
||||
}
|
||||
|
@ -0,0 +1,90 @@
|
||||
// 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_CAMERAANIMATIONMODIFIERPLAYERFACTORY_H
|
||||
#define RY_CAMERAANIMATIONMODIFIERPLAYERFACTORY_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "nel/misc/bit_mem_stream.h"
|
||||
#include "camera_animation_manager/camera_animation_info.h"
|
||||
|
||||
/************************************************************************/
|
||||
/* Interface for camera animation modifiers.
|
||||
* It has to be able to parse the modifier from an impulse and to play it
|
||||
*/
|
||||
/************************************************************************/
|
||||
class ICameraAnimationModifierPlayer
|
||||
{
|
||||
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 updates the modifier
|
||||
/// currCamInfo contains information about the current camera position and look at position
|
||||
/// The function must return the new camera information
|
||||
virtual TCameraAnimationOutputInfo updateModifier(const TCameraAnimationInputInfo& currCamInfo) = 0;
|
||||
|
||||
/// Function called when the modifier is stopped
|
||||
virtual void stopModifier() = 0;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
/* Factory class that can instanciate the correct camera animation modifier player.
|
||||
*
|
||||
* \author Fabien Henon
|
||||
* \date 2012
|
||||
*/
|
||||
/************************************************************************/
|
||||
class ICameraAnimationModifierPlayerFactory
|
||||
{
|
||||
public:
|
||||
/// Function that will instanciate the correct camera animation modifier player in function of the modifier name
|
||||
static ICameraAnimationModifierPlayer* initModifier(const std::string& name, NLMISC::CBitMemStream& impulse);
|
||||
protected:
|
||||
|
||||
/// Functions used to be able to create the camera animation modifiers players
|
||||
static void init();
|
||||
virtual ICameraAnimationModifierPlayer* instanciate() = 0;
|
||||
static std::vector<std::pair<std::string, ICameraAnimationModifierPlayerFactory*> >* Entries;
|
||||
};
|
||||
|
||||
// Define used to register the different types of camera animation modifiers players
|
||||
#define CAMERA_ANIMATION_REGISTER_MODIFIER_PLAYER(_class_,_name_) \
|
||||
class _class_##CameraAnimationModifierPlayerFactory : public ICameraAnimationModifierPlayerFactory \
|
||||
{\
|
||||
public:\
|
||||
_class_##CameraAnimationModifierPlayerFactory()\
|
||||
{\
|
||||
init();\
|
||||
std::string str = std::string(_name_); \
|
||||
for (uint i = 0; i < (*Entries).size(); i++ ) \
|
||||
{\
|
||||
if ( (*Entries)[i].first == str || (*Entries)[i].second == this )nlstop;\
|
||||
}\
|
||||
(*Entries).push_back( std::make_pair( str, this ) );\
|
||||
}\
|
||||
ICameraAnimationModifierPlayer* instanciate()\
|
||||
{ \
|
||||
return new _class_;\
|
||||
} \
|
||||
};\
|
||||
static _class_##CameraAnimationModifierPlayerFactory* _class_##CameraAnimationModifierPlayerFactoryInstance = new _class_##CameraAnimationModifierPlayerFactory;
|
||||
|
||||
|
||||
#endif /* RY_CAMERAANIMATIONMODIFIERPLAYERFACTORY_H */
|
@ -0,0 +1,139 @@
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
#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"
|
||||
#include "camera_animation_manager/position_or_entity_pos_resolver.h"
|
||||
#include "global.h"
|
||||
#include "sound_manager.h"
|
||||
#include "nel/misc/random.h"
|
||||
#include "nel/misc/time_nl.h"
|
||||
#include "time_client.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// This animation modifier shakes the camera. The parameter is
|
||||
/// - strength
|
||||
class CCameraAnimationModifierPlayerShake : public ICameraAnimationModifierPlayer
|
||||
{
|
||||
protected:
|
||||
float Strength;
|
||||
|
||||
float _Dir;
|
||||
float _WaitTime;
|
||||
float _CurrTime;
|
||||
NLMISC::CVector _CurrVec;
|
||||
|
||||
public:
|
||||
CCameraAnimationModifierPlayerShake()
|
||||
{
|
||||
Strength = 0.f;
|
||||
|
||||
_Dir = 1.f;
|
||||
_CurrTime = 0.f;
|
||||
_WaitTime = 0.f;
|
||||
}
|
||||
|
||||
/// This function is called when it's time to init the modifier from an impulse
|
||||
virtual bool initModifier(NLMISC::CBitMemStream& impulse)
|
||||
{
|
||||
impulse.serial(const_cast<float&>(Strength));
|
||||
|
||||
_Dir = 1.f;
|
||||
_CurrTime = 0.f;
|
||||
_WaitTime = 0.f;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Function that plays the modifier
|
||||
virtual TCameraAnimationOutputInfo updateModifier(const TCameraAnimationInputInfo& currCamInfo)
|
||||
{
|
||||
TCameraAnimationOutputInfo output;
|
||||
|
||||
_CurrTime += DT;
|
||||
|
||||
if (_CurrTime >= _WaitTime)
|
||||
{
|
||||
/*NLMISC::CRandom rnd;
|
||||
rnd.srand((sint32)NLMISC::CTime::getLocalTime());*/
|
||||
|
||||
// We find a normal vector to the look at dir
|
||||
NLMISC::CVector newVec(currCamInfo.CamLookAtDir.y * -1.f, currCamInfo.CamLookAtDir.x, currCamInfo.CamLookAtDir.z);
|
||||
newVec.normalize();
|
||||
|
||||
newVec = newVec * (Strength * _Dir);
|
||||
_Dir *= -1.f;
|
||||
|
||||
_CurrVec = newVec;
|
||||
|
||||
_CurrTime = 0.f;
|
||||
_WaitTime = 0.05f;
|
||||
}
|
||||
|
||||
output.CamLookAtDir = currCamInfo.CamLookAtDir;
|
||||
output.CamPos = currCamInfo.CamPos + _CurrVec;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
virtual void stopModifier()
|
||||
{
|
||||
}
|
||||
};
|
||||
CAMERA_ANIMATION_REGISTER_MODIFIER_PLAYER(CCameraAnimationModifierPlayerShake, "camera_modifier_shake");
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// This animation modifier plays a sound. The parameters are
|
||||
/// - sound_name
|
||||
/// - sound_position
|
||||
class CCameraAnimationModifierPlayerSoundTrigger : public ICameraAnimationModifierPlayer
|
||||
{
|
||||
protected:
|
||||
CPositionOrEntity SoundPos;
|
||||
NLMISC::CSheetId SoundId;
|
||||
|
||||
public:
|
||||
CCameraAnimationModifierPlayerSoundTrigger()
|
||||
{
|
||||
SoundId = NLMISC::CSheetId::Unknown;
|
||||
}
|
||||
|
||||
/// This function is called when it's time to init the modifier from an impulse
|
||||
virtual bool initModifier(NLMISC::CBitMemStream& impulse)
|
||||
{
|
||||
impulse.serial(const_cast<CPositionOrEntity&>(SoundPos));
|
||||
impulse.serial(const_cast<NLMISC::CSheetId&>(SoundId));
|
||||
|
||||
// We play the sound once here
|
||||
NLMISC::CVector pos = resolvePositionOrEntityPosition(SoundPos);
|
||||
SoundMngr->spawnSource(SoundId, pos);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Function that plays the modifier
|
||||
virtual TCameraAnimationOutputInfo updateModifier(const TCameraAnimationInputInfo& currCamInfo)
|
||||
{
|
||||
return currCamInfo.toOutput();
|
||||
}
|
||||
|
||||
virtual void stopModifier()
|
||||
{
|
||||
}
|
||||
};
|
||||
CAMERA_ANIMATION_REGISTER_MODIFIER_PLAYER(CCameraAnimationModifierPlayerSoundTrigger, "sound_trigger");
|
@ -0,0 +1,163 @@
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
|
||||
#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"
|
||||
#include "motion/user_controls.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace NLMISC;
|
||||
using namespace NLLIGO;
|
||||
using namespace NLNET;
|
||||
|
||||
CCameraAnimationPlayer* CCameraAnimationPlayer::_Instance = NULL;
|
||||
|
||||
|
||||
CCameraAnimationPlayer::CCameraAnimationPlayer()
|
||||
{
|
||||
_IsPlaying = false;
|
||||
_CurrStep = NULL;
|
||||
_ElapsedTimeForCurrStep = 0.f;
|
||||
_HasLastViewInfo = false;
|
||||
}
|
||||
|
||||
CCameraAnimationPlayer::~CCameraAnimationPlayer()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
void CCameraAnimationPlayer::start()
|
||||
{
|
||||
if (isPlaying())
|
||||
stop();
|
||||
|
||||
// If the player is dead, we do nothing
|
||||
if (UserControls.mode() == CUserControls::DeathMode)
|
||||
return;
|
||||
|
||||
_IsPlaying = true;
|
||||
|
||||
// We set the user controls in camAnimMode and we remember the current view and viewPos
|
||||
_LastView = View.view();
|
||||
_LastViewPos = View.viewPos();
|
||||
|
||||
_AnimStartCamPos = View.currentViewPos();
|
||||
_AnimStartCamLookAtDir = View.currentView();
|
||||
|
||||
_LastMode = UserControls.mode();
|
||||
UserControls.mode(CUserControls::CamAnimMode);
|
||||
_HasLastViewInfo = true;
|
||||
|
||||
// We set the animation start views so that the camera begins at the real previous position
|
||||
View.view(_AnimStartCamLookAtDir);
|
||||
View.viewPos(_AnimStartCamPos);
|
||||
}
|
||||
|
||||
void CCameraAnimationPlayer::stop(bool interrupt)
|
||||
{
|
||||
if (!isPlaying())
|
||||
return;
|
||||
|
||||
_IsPlaying = false;
|
||||
|
||||
stopStep();
|
||||
|
||||
// We reset view and viewPos and the usercontrols mode
|
||||
if (_HasLastViewInfo)
|
||||
{
|
||||
if (!interrupt)
|
||||
UserControls.mode(_LastMode);
|
||||
View.view(_LastView);
|
||||
View.viewPos(_LastViewPos);
|
||||
_HasLastViewInfo = false;
|
||||
}
|
||||
}
|
||||
|
||||
void CCameraAnimationPlayer::stopStep()
|
||||
{
|
||||
// We release the step and modifiers
|
||||
if (_CurrStep)
|
||||
{
|
||||
// We first tell the step we stop it
|
||||
_CurrStep->stopStepAndModifiers();
|
||||
|
||||
delete _CurrStep;
|
||||
_CurrStep = NULL;
|
||||
|
||||
_ElapsedTimeForCurrStep = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
void CCameraAnimationPlayer::playStep(const std::string& stepName, NLMISC::CBitMemStream& impulse)
|
||||
{
|
||||
// We check if we are playing an animation
|
||||
if (!isPlaying())
|
||||
{
|
||||
nlwarning("CameraAnimationPlayer: animation not playing, cannot play step %s", stepName.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// We stop the current step if there is one
|
||||
stopStep();
|
||||
|
||||
// We initialize the step with the factory
|
||||
_CurrStep = ICameraAnimationStepPlayerFactory::initStep(stepName, impulse);
|
||||
if (_CurrStep == NULL)
|
||||
{
|
||||
nlwarning("CameraAnimationPlayer: cannot create step player %s", stepName.c_str());
|
||||
_IsPlaying = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_ElapsedTimeForCurrStep = 0.f;
|
||||
|
||||
// We get the current camera information
|
||||
_StartStepCamLookAtDir = View.currentView();
|
||||
_StartStepCamPos = View.currentViewPos();
|
||||
}
|
||||
|
||||
bool CCameraAnimationPlayer::isPlaying()
|
||||
{
|
||||
return _IsPlaying;
|
||||
}
|
||||
|
||||
TCameraAnimationOutputInfo CCameraAnimationPlayer::update()
|
||||
{
|
||||
// We update the elapsed time for this step
|
||||
_ElapsedTimeForCurrStep += DT;
|
||||
|
||||
NLMISC::CVector currCamPos = View.currentViewPos();
|
||||
NLMISC::CVector currLookAtDir = View.currentView();
|
||||
|
||||
TCameraAnimationInputInfo currCamInfo(currCamPos, currLookAtDir,
|
||||
_StartStepCamPos, _StartStepCamLookAtDir,
|
||||
_AnimStartCamPos, _AnimStartCamLookAtDir,
|
||||
_ElapsedTimeForCurrStep);
|
||||
|
||||
if (!isPlaying())
|
||||
return currCamInfo.toOutput();
|
||||
if (_CurrStep == NULL)
|
||||
return currCamInfo.toOutput();
|
||||
|
||||
// We update the current step
|
||||
TCameraAnimationOutputInfo newCamInfo = _CurrStep->updateStepAndModifiers(currCamInfo);
|
||||
|
||||
return newCamInfo;
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
// 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_CAMERAANIMATIONPLAYER_H
|
||||
#define RY_CAMERAANIMATIONPLAYER_H
|
||||
|
||||
|
||||
#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"
|
||||
#include "motion/user_controls.h"
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Class that manages the camera animations. (singleton).
|
||||
* It's responsible of playing camera animations
|
||||
*
|
||||
* \author Fabien Henon
|
||||
* \date 2012
|
||||
*/
|
||||
/************************************************************************/
|
||||
class CCameraAnimationPlayer
|
||||
{
|
||||
public:
|
||||
/// Gets the current instance of the manager
|
||||
static CCameraAnimationPlayer* getInstance()
|
||||
{
|
||||
if (_Instance == NULL)
|
||||
_Instance = new CCameraAnimationPlayer();
|
||||
return _Instance;
|
||||
}
|
||||
/// Releases the instance
|
||||
static void release()
|
||||
{
|
||||
if (_Instance != NULL)
|
||||
{
|
||||
delete _Instance;
|
||||
_Instance = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/// Starts playing an animation
|
||||
void start();
|
||||
|
||||
/// Stops an animation
|
||||
void stop(bool interrupt = false);
|
||||
|
||||
/// Loads and play the specified step
|
||||
void playStep(const std::string& stepName, NLMISC::CBitMemStream& impulse);
|
||||
|
||||
/// Checks if an animation is being played
|
||||
bool isPlaying();
|
||||
|
||||
/// Updates the camera by calling the update function of the current step and modifiers
|
||||
TCameraAnimationOutputInfo update();
|
||||
|
||||
private:
|
||||
/// Constructor
|
||||
CCameraAnimationPlayer();
|
||||
/// Destructor
|
||||
~CCameraAnimationPlayer();
|
||||
|
||||
/// Stops the current step
|
||||
void stopStep();
|
||||
|
||||
/// Instance of the manager
|
||||
static CCameraAnimationPlayer* _Instance;
|
||||
|
||||
|
||||
bool _IsPlaying;
|
||||
|
||||
ICameraAnimationStepPlayer* _CurrStep;
|
||||
float _ElapsedTimeForCurrStep;
|
||||
|
||||
NLMISC::CVector _LastView;
|
||||
NLMISC::CVector _LastViewPos;
|
||||
CUserControls::TMoveMode _LastMode;
|
||||
bool _HasLastViewInfo;
|
||||
|
||||
NLMISC::CVector _StartStepCamLookAtDir;
|
||||
NLMISC::CVector _StartStepCamPos;
|
||||
|
||||
NLMISC::CVector _AnimStartCamLookAtDir;
|
||||
NLMISC::CVector _AnimStartCamPos;
|
||||
};
|
||||
|
||||
|
||||
#endif /* RY_CAMERAANIMATIONPLAYER_H */
|
@ -0,0 +1,150 @@
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
#include "camera_animation_manager/camera_animation_step_player_factory.h"
|
||||
|
||||
std::vector<std::pair<std::string, ICameraAnimationStepPlayerFactory*> >* ICameraAnimationStepPlayerFactory::Entries;
|
||||
|
||||
ICameraAnimationStepPlayer* ICameraAnimationStepPlayerFactory::initStep(const std::string& name, NLMISC::CBitMemStream& impulse)
|
||||
{
|
||||
if (!Entries)
|
||||
return NULL;
|
||||
|
||||
// We search the correct step type in our entries
|
||||
for (uint i = 0; i < Entries->size(); i++)
|
||||
{
|
||||
if (name == (*Entries)[i].first)
|
||||
{
|
||||
ICameraAnimationStepPlayer* ret = (*Entries)[i].second->instanciate();
|
||||
if (!ret)
|
||||
{
|
||||
nlwarning("BUG IN CAMERA ANIMATION STEP PLAYER FACTORY : BAD INIT CODE %s", name.c_str());
|
||||
return NULL;
|
||||
}
|
||||
// We init the step
|
||||
if (!ret->initStep(impulse))
|
||||
{
|
||||
nlwarning("building camera animation step player failed %s", name.c_str());
|
||||
delete ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// We look for children (modifiers or sound triggers)
|
||||
uint8 nbModifiers = 0;
|
||||
impulse.serial(nbModifiers);
|
||||
for (uint8 i = 0; i < nbModifiers; i++)
|
||||
{
|
||||
// We get the modifier name
|
||||
std::string modifierName = "";
|
||||
impulse.serial(modifierName);
|
||||
|
||||
ICameraAnimationModifierPlayer* modifier = ICameraAnimationModifierPlayerFactory::initModifier(modifierName, impulse);
|
||||
// We add the modifier to the list
|
||||
if (modifier)
|
||||
{
|
||||
ret->addModifier(modifier);
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("impossible to init the modifier named %s in step named %s", modifierName.c_str(), name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ICameraAnimationStepPlayerFactory::init()
|
||||
{
|
||||
if (!Entries)
|
||||
Entries = new std::vector<std::pair<std::string, ICameraAnimationStepPlayerFactory*> >;
|
||||
}
|
||||
|
||||
ICameraAnimationStepPlayer::~ICameraAnimationStepPlayer()
|
||||
{
|
||||
// We release all the modifiers
|
||||
for (std::vector<ICameraAnimationModifierPlayer*>::iterator it = Modifiers.begin(); it != Modifiers.end(); ++it)
|
||||
{
|
||||
ICameraAnimationModifierPlayer* modifier = *it;
|
||||
delete modifier;
|
||||
}
|
||||
Modifiers.clear();
|
||||
}
|
||||
|
||||
void ICameraAnimationStepPlayer::addModifier(ICameraAnimationModifierPlayer* modifier)
|
||||
{
|
||||
Modifiers.push_back(modifier);
|
||||
}
|
||||
|
||||
TCameraAnimationOutputInfo ICameraAnimationStepPlayer::updateStepAndModifiers(const TCameraAnimationInputInfo& currCamInfo)
|
||||
{
|
||||
// Updates the step
|
||||
TCameraAnimationOutputInfo newInfo = updateStep(currCamInfo);
|
||||
|
||||
// Updates the modifiers
|
||||
for (std::vector<ICameraAnimationModifierPlayer*>::iterator it = Modifiers.begin(); it != Modifiers.end(); ++it)
|
||||
{
|
||||
ICameraAnimationModifierPlayer* modifier = *it;
|
||||
|
||||
TCameraAnimationInputInfo input(newInfo, currCamInfo);
|
||||
|
||||
// We update the modifier
|
||||
newInfo = modifier->updateModifier(input);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
NLMISC::CVector ICameraAnimationStepPlayer::computeCurrentLookAtDir(float ratio, const NLMISC::CVector& startLookAtDir,
|
||||
const NLMISC::CVector& endLookAtDir)
|
||||
{
|
||||
// We normalize the start look at direction
|
||||
NLMISC::CVector startDir = startLookAtDir;
|
||||
startDir.normalize();
|
||||
|
||||
// We normalize the final look at direction
|
||||
NLMISC::CVector finalDir = endLookAtDir;
|
||||
finalDir.normalize();
|
||||
|
||||
// We compute a vector that goes from the starting look at dir to the final look at dir
|
||||
NLMISC::CVector startToFinal = finalDir - startDir;
|
||||
|
||||
// We multiply this vector by the ratio so that we can have a vector that represent the current position we are looking at
|
||||
startToFinal = startToFinal * ratio;
|
||||
|
||||
// We compute the direction we are looking at
|
||||
NLMISC::CVector currLookAtDir = startDir + startToFinal;
|
||||
currLookAtDir.normalize();
|
||||
|
||||
return currLookAtDir;
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
// 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_CAMERAANIMATIONSTEPPLAYERFACTORY_H
|
||||
#define RY_CAMERAANIMATIONSTEPPLAYERFACTORY_H
|
||||
|
||||
#include <string>
|
||||
#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"
|
||||
#include "nel/misc/vector.h"
|
||||
|
||||
/************************************************************************/
|
||||
/* Interface for camera animation steps.
|
||||
* It has to be able to parse the step from an impulse and to play it
|
||||
*/
|
||||
/************************************************************************/
|
||||
class ICameraAnimationStepPlayer
|
||||
{
|
||||
public:
|
||||
virtual ~ICameraAnimationStepPlayer();
|
||||
|
||||
/// This function is called when it's time to init the step from an impulse
|
||||
virtual bool initStep(NLMISC::CBitMemStream& impulse) = 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 TCameraAnimationOutputInfo updateStep(const TCameraAnimationInputInfo& currCamInfo) = 0;
|
||||
|
||||
/// Function called when the step stops
|
||||
virtual void stopStep() = 0;
|
||||
|
||||
/// Function that adds a camera animation modifier to this step
|
||||
void addModifier(ICameraAnimationModifierPlayer* modifier);
|
||||
|
||||
// Plays the step and its modifiers
|
||||
TCameraAnimationOutputInfo updateStepAndModifiers(const TCameraAnimationInputInfo& currCamInfo);
|
||||
|
||||
// Stops the step and its modifiers
|
||||
void stopStepAndModifiers();
|
||||
|
||||
protected:
|
||||
|
||||
/// Compute the current look at direction depending on the starting look at direction,
|
||||
/// the ending look at direction and the progression expressed as a ratio (value between 0 and 1 that expresses the
|
||||
/// progression)
|
||||
NLMISC::CVector computeCurrentLookAtDir(float ratio, const NLMISC::CVector& startLookAtDir,
|
||||
const NLMISC::CVector& endLookAtDir);
|
||||
|
||||
// The list of modifiers
|
||||
std::vector<ICameraAnimationModifierPlayer*> Modifiers;
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
/* Factory class that can instanciate the correct camera animation step player.
|
||||
*
|
||||
* \author Fabien Henon
|
||||
* \date 2012
|
||||
*/
|
||||
/************************************************************************/
|
||||
class ICameraAnimationStepPlayerFactory
|
||||
{
|
||||
public:
|
||||
/// Function that will instanciate the correct camera animation step player in function of the step name
|
||||
static ICameraAnimationStepPlayer* initStep(const std::string& name, NLMISC::CBitMemStream& impulse);
|
||||
protected:
|
||||
|
||||
/// Functions used to be able to create the camera animation steps players
|
||||
static void init();
|
||||
virtual ICameraAnimationStepPlayer* instanciate() = 0;
|
||||
static std::vector<std::pair<std::string, ICameraAnimationStepPlayerFactory*> >* Entries;
|
||||
};
|
||||
|
||||
// Define used to register the different types of camera animation steps players
|
||||
#define CAMERA_ANIMATION_REGISTER_STEP_PLAYER(_class_,_name_) \
|
||||
class _class_##CameraAnimationStepPlayerFactory : public ICameraAnimationStepPlayerFactory \
|
||||
{\
|
||||
public:\
|
||||
_class_##CameraAnimationStepPlayerFactory()\
|
||||
{\
|
||||
init();\
|
||||
std::string str = std::string(_name_); \
|
||||
for (uint i = 0; i < (*Entries).size(); i++ ) \
|
||||
{\
|
||||
if ( (*Entries)[i].first == str || (*Entries)[i].second == this )nlstop;\
|
||||
}\
|
||||
(*Entries).push_back( std::make_pair( str, this ) );\
|
||||
}\
|
||||
ICameraAnimationStepPlayer* instanciate()\
|
||||
{ \
|
||||
return new _class_;\
|
||||
} \
|
||||
};\
|
||||
static _class_##CameraAnimationStepPlayerFactory* _class_##CameraAnimationStepPlayerFactoryInstance = new _class_##CameraAnimationStepPlayerFactory;
|
||||
|
||||
|
||||
#endif /* RY_CAMERAANIMATIONSTEPPLAYERFACTORY_H */
|
@ -0,0 +1,522 @@
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
#include "camera_animation_manager/camera_animation_step_player_factory.h"
|
||||
#include "game_share/position_or_entity_type.h"
|
||||
#include "camera_animation_manager/position_or_entity_helper.h"
|
||||
#include "camera_animation_manager/camera_animation_info.h"
|
||||
#include "camera_animation_manager/position_or_entity_pos_resolver.h"
|
||||
#include "client_cfg.h"
|
||||
#include "time_client.h"
|
||||
#include "game_share/camera_anim_type_parser.h"
|
||||
|
||||
/// Magic camera animation step
|
||||
class CCameraAnimationStepPlayerStep: public ICameraAnimationStepPlayer
|
||||
{
|
||||
protected:
|
||||
CPositionOrEntityHelper LookAtTarget;
|
||||
float DirectionTransitionTime;
|
||||
CPositionOrEntityHelper PositionTarget;
|
||||
float PositionTransitionTime;
|
||||
float DistanceTo;
|
||||
bool HasTurnAround;
|
||||
float TurnAroundSpeed;
|
||||
|
||||
public:
|
||||
CCameraAnimationStepPlayerStep()
|
||||
{
|
||||
DirectionTransitionTime = 0.f;
|
||||
PositionTransitionTime = 0.f;
|
||||
DistanceTo = 0.f;
|
||||
HasTurnAround = false;
|
||||
TurnAroundSpeed = 0.f;
|
||||
}
|
||||
|
||||
/// This function is called when it's time to init the step from an impulse
|
||||
virtual bool initStep(NLMISC::CBitMemStream& bms)
|
||||
{
|
||||
bms.serial(const_cast<CPositionOrEntityHelper&>(LookAtTarget));
|
||||
if (!LookAtTarget.isPreviousPos())
|
||||
{
|
||||
NLMISC::serialDuration(bms, DirectionTransitionTime);
|
||||
}
|
||||
|
||||
bms.serial(const_cast<CPositionOrEntityHelper&>(PositionTarget));
|
||||
if (!PositionTarget.isPreviousPos())
|
||||
{
|
||||
NLMISC::serialDistance(bms, DistanceTo);
|
||||
NLMISC::serialDuration(bms, PositionTransitionTime);
|
||||
bms.serialBit(const_cast<bool&>(HasTurnAround));
|
||||
|
||||
if (HasTurnAround)
|
||||
{
|
||||
NLMISC::serialSpeed(bms, TurnAroundSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Function that plays the step
|
||||
virtual TCameraAnimationOutputInfo updateStep(const TCameraAnimationInputInfo& currCamInfo)
|
||||
{
|
||||
TCameraAnimationOutputInfo camInfo;
|
||||
|
||||
NLMISC::CVector targetPos = resolvePositionOrEntityPosition(PositionTarget, currCamInfo);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Position
|
||||
{
|
||||
float ratio = 1.f;
|
||||
if (PositionTransitionTime > 0.f)
|
||||
ratio = currCamInfo.ElapsedTimeSinceStartStep / PositionTransitionTime;
|
||||
if (ratio > 1.f)
|
||||
ratio = 1.f;
|
||||
|
||||
// We compute the current position between the starting position and the final position
|
||||
NLMISC::CVector movementVector = targetPos - currCamInfo.StartCamPos;
|
||||
|
||||
// We substract the distance
|
||||
float currDist = movementVector.norm();
|
||||
float substractRatio = 0.f;
|
||||
if (currDist > 0.f)
|
||||
substractRatio = (currDist - DistanceTo) / currDist;
|
||||
if ((currDist - DistanceTo) < 0.f)
|
||||
substractRatio = 0.f;
|
||||
movementVector = movementVector * substractRatio;
|
||||
|
||||
// We current position is computed using the ratio and the starting position
|
||||
NLMISC::CVector offset = movementVector * ratio;
|
||||
camInfo.CamPos = currCamInfo.StartCamPos + offset;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Turn around
|
||||
if (HasTurnAround)
|
||||
{
|
||||
// Now we compute the current angle between our position and the target's position
|
||||
NLMISC::CVector2f currTopVector(camInfo.CamPos.x - targetPos.x, camInfo.CamPos.y - targetPos.y);
|
||||
float distance2D = currTopVector.norm();
|
||||
currTopVector.normalize();
|
||||
|
||||
float angle = acosf(currTopVector.x);
|
||||
if (currTopVector.y < 0)
|
||||
angle *= -1.f;
|
||||
|
||||
// We compute an angle to travail in function of the speed
|
||||
float angleOffset = DT * TurnAroundSpeed;
|
||||
|
||||
float newAngle = angle + angleOffset;
|
||||
|
||||
// We compute the new position for this angle
|
||||
NLMISC::CVector2f new2DPos(cosf(newAngle), sinf(newAngle));
|
||||
new2DPos = new2DPos * distance2D;
|
||||
|
||||
// We integrate this new position in the world
|
||||
NLMISC::CVector newDir(new2DPos.x, new2DPos.y, camInfo.CamPos.z - targetPos.z);
|
||||
|
||||
camInfo.CamPos = targetPos + newDir;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Look at target
|
||||
{
|
||||
float ratio = 1.f;
|
||||
if (DirectionTransitionTime > 0.f)
|
||||
ratio = currCamInfo.ElapsedTimeSinceStartStep / DirectionTransitionTime;
|
||||
if (ratio > 1.f)
|
||||
ratio = 1.f;
|
||||
|
||||
// We compute the final look at direction
|
||||
NLMISC::CVector finalDir = resolvePositionOrEntityTargetDir(LookAtTarget, currCamInfo, camInfo.CamPos);
|
||||
|
||||
// We get the current look at direction
|
||||
camInfo.CamLookAtDir = computeCurrentLookAtDir(ratio, currCamInfo.StartCamLookAtDir, finalDir);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
return camInfo;
|
||||
}
|
||||
|
||||
virtual void stopStep()
|
||||
{
|
||||
}
|
||||
};
|
||||
CAMERA_ANIMATION_REGISTER_STEP_PLAYER(CCameraAnimationStepPlayerStep, "camera_animation_step");
|
||||
|
||||
/*/// Basic camera animation step that has generic values
|
||||
/// - look_at_position
|
||||
/// - text
|
||||
/// - duration
|
||||
class CCameraAnimationStepPlayerBasic : public ICameraAnimationStepPlayer
|
||||
{
|
||||
protected:
|
||||
TPositionOrEntity LookAtPos;
|
||||
std::string Text;
|
||||
float Duration;
|
||||
|
||||
public:
|
||||
CCameraAnimationStepPlayerBasic()
|
||||
{
|
||||
Text = "";
|
||||
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)
|
||||
{
|
||||
impulse.serial(const_cast<TPositionOrEntity&>(LookAtPos));
|
||||
impulse.serial(const_cast<std::string&>(Text));
|
||||
impulse.serial(const_cast<float&>(Duration));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void stopStep()
|
||||
{
|
||||
}
|
||||
|
||||
}; // This class must not be registered because it's a base class
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// Static camera animation step (that does not have specific variables)
|
||||
class CCameraAnimationStepPlayerStatic : public CCameraAnimationStepPlayerBasic
|
||||
{
|
||||
public:
|
||||
/// This function is called when it's time to init the step from an impulse
|
||||
virtual bool initStep(NLMISC::CBitMemStream& impulse)
|
||||
{
|
||||
CCameraAnimationStepPlayerBasic::initStep(impulse);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Function that plays the step
|
||||
virtual TCameraAnimationOutputInfo updateStep(const TCameraAnimationInputInfo& currCamInfo)
|
||||
{
|
||||
TCameraAnimationOutputInfo camInfo;
|
||||
|
||||
// We don't change the position
|
||||
camInfo.CamPos = currCamInfo.StartCamPos;
|
||||
|
||||
float ratio = currCamInfo.ElapsedTimeSinceStartStep / getDuration();
|
||||
|
||||
// We compute the final look at direction
|
||||
NLMISC::CVector finalDir = resolvePositionOrEntityPosition(LookAtPos) - camInfo.CamPos;
|
||||
|
||||
// We get the current look at direction
|
||||
camInfo.CamLookAtDir = computeCurrentLookAtDir(ratio, currCamInfo.StartCamLookAtDir, finalDir);
|
||||
|
||||
return camInfo;
|
||||
}
|
||||
|
||||
virtual void stopStep()
|
||||
{
|
||||
}
|
||||
};
|
||||
CAMERA_ANIMATION_REGISTER_STEP_PLAYER(CCameraAnimationStepPlayerStatic, "camera_animation_static");
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// Go to camera animation step
|
||||
/// - end_position
|
||||
class CCameraAnimationStepPlayerGoTo: public CCameraAnimationStepPlayerBasic
|
||||
{
|
||||
protected:
|
||||
TPositionOrEntity EndPos;
|
||||
|
||||
public:
|
||||
CCameraAnimationStepPlayerGoTo()
|
||||
{
|
||||
}
|
||||
|
||||
/// This function is called when it's time to init the step from an impulse
|
||||
virtual bool initStep(NLMISC::CBitMemStream& impulse)
|
||||
{
|
||||
CCameraAnimationStepPlayerBasic::initStep(impulse);
|
||||
|
||||
impulse.serial(const_cast<TPositionOrEntity&>(EndPos));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Function that plays the step
|
||||
virtual TCameraAnimationOutputInfo updateStep(const TCameraAnimationInputInfo& currCamInfo)
|
||||
{
|
||||
TCameraAnimationOutputInfo camInfo;
|
||||
|
||||
float ratio = currCamInfo.ElapsedTimeSinceStartStep / getDuration();
|
||||
|
||||
// We compute the current position between the starting position and the final position
|
||||
NLMISC::CVector movementVector = resolvePositionOrEntityPosition(EndPos) - currCamInfo.StartCamPos;
|
||||
|
||||
// If the position is an entity, we substract a minimum distance to the entity
|
||||
if (EndPos.isEntityId())
|
||||
{
|
||||
float currDist = movementVector.norm();
|
||||
float substractRatio = (currDist - ClientCfg.CameraAnimMinEntityDistance) / currDist;
|
||||
if ((currDist - ClientCfg.CameraAnimMinEntityDistance) < 0.f)
|
||||
substractRatio = 0.f;
|
||||
movementVector = movementVector * substractRatio;
|
||||
}
|
||||
|
||||
// We current position is computed using the ratio and the starting position
|
||||
NLMISC::CVector offset = movementVector * ratio;
|
||||
camInfo.CamPos = currCamInfo.StartCamPos + offset;
|
||||
|
||||
// Now we compute the current look at direction
|
||||
NLMISC::CVector finalDir = resolvePositionOrEntityPosition(LookAtPos) - camInfo.CamPos;
|
||||
|
||||
// We get the current look at direction
|
||||
camInfo.CamLookAtDir = computeCurrentLookAtDir(ratio, currCamInfo.StartCamLookAtDir, finalDir);
|
||||
|
||||
return camInfo;
|
||||
}
|
||||
|
||||
virtual void stopStep()
|
||||
{
|
||||
}
|
||||
};
|
||||
CAMERA_ANIMATION_REGISTER_STEP_PLAYER(CCameraAnimationStepPlayerGoTo, "camera_animation_go_to");
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// Follow entity camera animation step
|
||||
/// - entity_to_follow
|
||||
/// - distance_to_entity
|
||||
class CCameraAnimationStepPlayerFollowEntity: public CCameraAnimationStepPlayerBasic
|
||||
{
|
||||
protected:
|
||||
TPositionOrEntity EntityToFollow;
|
||||
float DistanceToEntity;
|
||||
|
||||
public:
|
||||
CCameraAnimationStepPlayerFollowEntity()
|
||||
{
|
||||
DistanceToEntity = 0.f;
|
||||
}
|
||||
|
||||
/// This function is called when it's time to init the step from an impulse
|
||||
virtual bool initStep(NLMISC::CBitMemStream& impulse)
|
||||
{
|
||||
CCameraAnimationStepPlayerBasic::initStep(impulse);
|
||||
|
||||
impulse.serial(const_cast<TPositionOrEntity&>(EntityToFollow));
|
||||
impulse.serial(const_cast<float&>(DistanceToEntity));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Function that plays the step
|
||||
virtual TCameraAnimationOutputInfo updateStep(const TCameraAnimationInputInfo& currCamInfo)
|
||||
{
|
||||
TCameraAnimationOutputInfo camInfo;
|
||||
|
||||
// We compute the distance between the entity to follow and our current position
|
||||
NLMISC::CVector entityPos = resolvePositionOrEntityPosition(EntityToFollow);
|
||||
NLMISC::CVector distanceVec = entityPos - currCamInfo.CamPos;
|
||||
|
||||
float distance = distanceVec.norm();
|
||||
|
||||
// We compute the difference with the expected distance
|
||||
float difference = distance - DistanceToEntity;
|
||||
|
||||
// We compute the distance we can travel
|
||||
float travellingDistance = DT * ClientCfg.MaxCameraAnimationSpeed * (difference < 0.f ? -1.f : 1.f);
|
||||
|
||||
// We check if we are not going to far
|
||||
if (abs(travellingDistance) > abs(difference))
|
||||
travellingDistance = difference;
|
||||
|
||||
// We normalize the vector from our position to the entity
|
||||
distanceVec.normalize();
|
||||
// We multiply this vector with the distance to travel
|
||||
distanceVec = distanceVec * travellingDistance;
|
||||
|
||||
// We add this vector to our position to know our new position
|
||||
camInfo.CamPos = currCamInfo.CamPos + distanceVec;
|
||||
|
||||
// We compute the final look at direction
|
||||
NLMISC::CVector finalDir = resolvePositionOrEntityPosition(LookAtPos) - camInfo.CamPos;
|
||||
finalDir.normalize();
|
||||
|
||||
// We get the current look at direction
|
||||
camInfo.CamLookAtDir = finalDir;
|
||||
|
||||
return camInfo;
|
||||
}
|
||||
|
||||
virtual void stopStep()
|
||||
{
|
||||
}
|
||||
};
|
||||
CAMERA_ANIMATION_REGISTER_STEP_PLAYER(CCameraAnimationStepPlayerFollowEntity, "camera_animation_follow_entity");
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// Turn around camera animation step
|
||||
/// - point_to_turn_around
|
||||
/// - distance_to_point
|
||||
/// - speed
|
||||
class CCameraAnimationStepPlayerTurnAround: public CCameraAnimationStepPlayerBasic
|
||||
{
|
||||
protected:
|
||||
TPositionOrEntity PointToTurnAround;
|
||||
float DistanceToPoint;
|
||||
float Speed;
|
||||
|
||||
public:
|
||||
CCameraAnimationStepPlayerTurnAround()
|
||||
{
|
||||
DistanceToPoint = 0.f;
|
||||
Speed = 0.f;
|
||||
}
|
||||
|
||||
/// This function is called when it's time to init the step from an impulse
|
||||
virtual bool initStep(NLMISC::CBitMemStream& impulse)
|
||||
{
|
||||
CCameraAnimationStepPlayerBasic::initStep(impulse);
|
||||
|
||||
impulse.serial(const_cast<TPositionOrEntity&>(PointToTurnAround));
|
||||
impulse.serial(const_cast<float&>(DistanceToPoint));
|
||||
impulse.serial(const_cast<float&>(Speed));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Function that plays the step
|
||||
virtual TCameraAnimationOutputInfo updateStep(const TCameraAnimationInputInfo& currCamInfo)
|
||||
{
|
||||
TCameraAnimationOutputInfo camInfo;
|
||||
|
||||
// We compute the distance between the point to turn around and our current position
|
||||
NLMISC::CVector pointPos = resolvePositionOrEntityPosition(PointToTurnAround);
|
||||
NLMISC::CVector distanceVec = pointPos - currCamInfo.CamPos;
|
||||
|
||||
float distance = distanceVec.norm();
|
||||
|
||||
// We compute the difference with the expected distance
|
||||
float difference = distance - DistanceToPoint;
|
||||
|
||||
// We compute the distance we can travel
|
||||
float travellingDistance = DT * ClientCfg.MaxCameraAnimationSpeed * (difference < 0.f ? -1.f : 1.f);
|
||||
|
||||
// We check if we are not going to far
|
||||
if (abs(travellingDistance) > abs(difference))
|
||||
travellingDistance = difference;
|
||||
|
||||
// We normalize the vector from our position to the point
|
||||
distanceVec.normalize();
|
||||
// We multiply this vector with the distance to travel
|
||||
distanceVec = distanceVec * travellingDistance;
|
||||
|
||||
// We add this vector to our position to know our new position
|
||||
NLMISC::CVector newPos = currCamInfo.CamPos + distanceVec;
|
||||
|
||||
// Now we compute the current angle between our position and the point's position
|
||||
NLMISC::CVector2f currTopVector(newPos.x - pointPos.x, newPos.y - pointPos.y);
|
||||
float distance2D = currTopVector.norm();
|
||||
currTopVector.normalize();
|
||||
|
||||
float angle = acosf(currTopVector.x);
|
||||
if (currTopVector.y < 0)
|
||||
angle *= -1.f;
|
||||
|
||||
// We compute an angle to travail in function of the speed
|
||||
float angleOffset = DT * Speed;
|
||||
|
||||
float newAngle = angle + angleOffset;
|
||||
|
||||
// We compute the new position for this angle
|
||||
NLMISC::CVector2f new2DPos(cosf(newAngle), sinf(newAngle));
|
||||
new2DPos = new2DPos * distance2D;
|
||||
|
||||
// We integrate this new position in the world
|
||||
NLMISC::CVector newDir(new2DPos.x, new2DPos.y, newPos.z - pointPos.z);
|
||||
|
||||
camInfo.CamPos = pointPos + newDir;
|
||||
|
||||
// We compute the final look at direction
|
||||
NLMISC::CVector finalDir = resolvePositionOrEntityPosition(LookAtPos) - camInfo.CamPos;
|
||||
finalDir.normalize();
|
||||
|
||||
// We get the current look at direction
|
||||
camInfo.CamLookAtDir = finalDir;
|
||||
|
||||
return camInfo;
|
||||
}
|
||||
|
||||
virtual void stopStep()
|
||||
{
|
||||
}
|
||||
};
|
||||
CAMERA_ANIMATION_REGISTER_STEP_PLAYER(CCameraAnimationStepPlayerTurnAround, "camera_animation_turn_around");
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// Animation step that returns to the starting position. It directly inherits from the interface because it
|
||||
/// does not need all the parameters of a basic step
|
||||
/// - duration
|
||||
class CCameraAnimationStepPlayerReturn : public ICameraAnimationStepPlayer
|
||||
{
|
||||
protected:
|
||||
float Duration;
|
||||
|
||||
public:
|
||||
CCameraAnimationStepPlayerReturn()
|
||||
{
|
||||
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)
|
||||
{
|
||||
impulse.serial(const_cast<float&>(Duration));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Function that plays the step
|
||||
virtual TCameraAnimationOutputInfo updateStep(const TCameraAnimationInputInfo& currCamInfo)
|
||||
{
|
||||
TCameraAnimationOutputInfo camInfo;
|
||||
|
||||
float ratio = currCamInfo.ElapsedTimeSinceStartStep / getDuration();
|
||||
|
||||
// We compute the current position between the starting position and the final position
|
||||
NLMISC::CVector movementVector = resolvePositionOrEntityPosition(currCamInfo.AnimStartCamPos) - currCamInfo.StartCamPos;
|
||||
|
||||
// We current position is computed using the ratio and the starting position
|
||||
NLMISC::CVector offset = movementVector * ratio;
|
||||
camInfo.CamPos = currCamInfo.StartCamPos + offset;
|
||||
|
||||
// We get the current look at direction
|
||||
camInfo.CamLookAtDir = computeCurrentLookAtDir(ratio, currCamInfo.StartCamLookAtDir, currCamInfo.AnimStartCamLookAtDir);
|
||||
|
||||
return camInfo;
|
||||
}
|
||||
|
||||
virtual void stopStep()
|
||||
{
|
||||
}
|
||||
};
|
||||
CAMERA_ANIMATION_REGISTER_STEP_PLAYER(CCameraAnimationStepPlayerReturn, "camera_animation_return");*/
|
@ -0,0 +1,35 @@
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
|
||||
#include "camera_animation_manager/position_or_entity_helper.h"
|
||||
#include "game_share/mirror.h"
|
||||
#include "game_share/mirrored_data_set.h"
|
||||
#include "game_share/base_types.h"
|
||||
#include "user_entity.h"
|
||||
|
||||
|
||||
/*NLMISC::CVector CPositionOrEntityHelper::getDiffPos(const NLMISC::CVector& targetPos) const
|
||||
{
|
||||
return Position;
|
||||
}
|
||||
|
||||
NLMISC::CVector CPositionOrEntityHelper::setPositionFromDiffPos(const NLMISC::CVector& diffPos)
|
||||
{
|
||||
return Position;
|
||||
}
|
||||
*/
|
@ -0,0 +1,63 @@
|
||||
// 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_POSITIONORENTITYTYPEHELPER_H
|
||||
#define RY_POSITIONORENTITYTYPEHELPER_H
|
||||
|
||||
|
||||
#include "game_share/position_or_entity_type.h"
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/************************************************************************/
|
||||
/* Class that can contain either an entity id or a position */
|
||||
/************************************************************************/
|
||||
class CPositionOrEntityHelper: public CPositionOrEntity
|
||||
{
|
||||
public:
|
||||
|
||||
CPositionOrEntityHelper(): CPositionOrEntity()
|
||||
{
|
||||
}
|
||||
|
||||
CPositionOrEntityHelper(const NLMISC::CVector& position): CPositionOrEntity(position)
|
||||
{
|
||||
}
|
||||
|
||||
CPositionOrEntityHelper(const TDataSetIndex& eid): CPositionOrEntity(eid)
|
||||
{
|
||||
}
|
||||
|
||||
CPositionOrEntityHelper(PositionOrEntityType type): CPositionOrEntity(type)
|
||||
{
|
||||
}
|
||||
|
||||
CPositionOrEntityHelper(const CPositionOrEntity& c): CPositionOrEntity(c)
|
||||
{
|
||||
}
|
||||
|
||||
// Declares abstract methods
|
||||
/// This function returns the difference between the player's position and the specified position
|
||||
/*NLMISC::CVector getDiffPos(const NLMISC::CVector& targetPos) const;
|
||||
|
||||
/// This function returns the target position given the difference between the player's position and this target position
|
||||
NLMISC::CVector setPositionFromDiffPos(const NLMISC::CVector& diffPos);*/
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* RY_POSITIONORENTITYTYPEHELPER_H */
|
@ -0,0 +1,133 @@
|
||||
// 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/>.
|
||||
|
||||
#include "camera_animation_manager/position_or_entity_pos_resolver.h"
|
||||
#include "entity_cl.h"
|
||||
#include "game_share/position_or_entity_type.h"
|
||||
#include "entities.h"
|
||||
|
||||
NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEntity, const TCameraAnimationInputInfo& currCamInfo)
|
||||
{
|
||||
if (!posOrEntity.isValid())
|
||||
{
|
||||
nlwarning("<resolvePositionOrEntityPosition> invalid position or entity");
|
||||
return NLMISC::CVector();
|
||||
}
|
||||
|
||||
if (posOrEntity.isPosition())
|
||||
return posOrEntity.getPosition();
|
||||
else if (posOrEntity.isPreviousPos())
|
||||
{
|
||||
return currCamInfo.StartCamPos;
|
||||
}
|
||||
else if (posOrEntity.isReturnPos())
|
||||
{
|
||||
return currCamInfo.AnimStartCamPos;
|
||||
}
|
||||
else if (posOrEntity.isEntityId())
|
||||
{
|
||||
CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex(posOrEntity.getEntityId());
|
||||
if (!entity)
|
||||
{
|
||||
nlwarning("<resolvePositionOrEntityPosition> invalid entity with compressed id %d", posOrEntity.getEntityId());
|
||||
return NLMISC::CVector();
|
||||
}
|
||||
else
|
||||
{
|
||||
NLMISC::CVector pos;
|
||||
if (!entity->getHeadPos(pos))
|
||||
pos = entity->pos();
|
||||
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
return NLMISC::CVector();
|
||||
}
|
||||
|
||||
NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEntity)
|
||||
{
|
||||
if (!posOrEntity.isValid())
|
||||
{
|
||||
nlwarning("<resolvePositionOrEntityPosition> invalid position or entity");
|
||||
return NLMISC::CVector();
|
||||
}
|
||||
|
||||
if (posOrEntity.isPosition())
|
||||
return posOrEntity.getPosition();
|
||||
else if (posOrEntity.isEntityId())
|
||||
{
|
||||
CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex(posOrEntity.getEntityId());
|
||||
if (!entity)
|
||||
{
|
||||
nlwarning("<resolvePositionOrEntityPosition> invalid entity with compressed id %d", posOrEntity.getEntityId());
|
||||
return NLMISC::CVector();
|
||||
}
|
||||
else
|
||||
{
|
||||
NLMISC::CVector pos;
|
||||
if (!entity->getHeadPos(pos))
|
||||
pos = entity->pos();
|
||||
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
return NLMISC::CVector();
|
||||
}
|
||||
|
||||
NLMISC::CVector resolvePositionOrEntityTargetDir(const CPositionOrEntity& posOrEntity, const TCameraAnimationInputInfo& currCamInfo,
|
||||
const NLMISC::CVector& currCamPos)
|
||||
{
|
||||
if (!posOrEntity.isValid())
|
||||
{
|
||||
nlwarning("<resolvePositionOrEntityPosition> invalid position or entity");
|
||||
return NLMISC::CVector();
|
||||
}
|
||||
|
||||
if (posOrEntity.isPosition())
|
||||
{
|
||||
NLMISC::CVector dir = posOrEntity.getPosition() - currCamPos;
|
||||
dir.normalize();
|
||||
return dir;
|
||||
}
|
||||
else if (posOrEntity.isPreviousPos())
|
||||
{
|
||||
return currCamInfo.StartCamLookAtDir;
|
||||
}
|
||||
else if (posOrEntity.isReturnPos())
|
||||
{
|
||||
return currCamInfo.AnimStartCamLookAtDir;
|
||||
}
|
||||
else if (posOrEntity.isEntityId())
|
||||
{
|
||||
CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex(posOrEntity.getEntityId());
|
||||
if (!entity)
|
||||
{
|
||||
nlwarning("<resolvePositionOrEntityPosition> invalid entity with compressed id %d", posOrEntity.getEntityId());
|
||||
return NLMISC::CVector();
|
||||
}
|
||||
else
|
||||
{
|
||||
NLMISC::CVector pos;
|
||||
if (!entity->getHeadPos(pos))
|
||||
pos = entity->pos();
|
||||
|
||||
NLMISC::CVector dir = pos - currCamPos;
|
||||
dir.normalize();
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
return NLMISC::CVector();
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
// 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_POSITIONORENTITYPOSRESOLVER_H
|
||||
#define RY_POSITIONORENTITYPOSRESOLVER_H
|
||||
|
||||
#include "nel/misc/entity_id.h"
|
||||
#include "nel/misc/vector.h"
|
||||
#include "game_share/position_or_entity_type.h"
|
||||
#include "camera_animation_manager/position_or_entity_helper.h"
|
||||
#include "camera_animation_manager/camera_animation_info.h"
|
||||
|
||||
|
||||
/// Function that returns the stored position if it contains a position
|
||||
/// Or the current entity's position if it contains an entity
|
||||
NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEntity, const TCameraAnimationInputInfo& currCamInfo);
|
||||
NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEntity);
|
||||
|
||||
/// Functions that returns the stored look at target as a normalized direction vector
|
||||
NLMISC::CVector resolvePositionOrEntityTargetDir(const CPositionOrEntity& posOrEntity, const TCameraAnimationInputInfo& currCamInfo,
|
||||
const NLMISC::CVector& currCamPos);
|
||||
|
||||
#endif /* RY_POSITIONORENTITYPOSRESOLVER_H */
|
@ -0,0 +1,93 @@
|
||||
// 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/>.
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "stdpch.h"
|
||||
// Client.
|
||||
#include "../../input.h"
|
||||
#include "../user_controls.h"
|
||||
#include "../../user_entity.h"
|
||||
#include "../../view.h"
|
||||
#include "../../interface_v3/interface_manager.h"
|
||||
#include "../../entities.h"
|
||||
#include "camera_animation_manager/camera_animation_info.h"
|
||||
#include "camera_animation_manager/camera_animation_player.h"
|
||||
|
||||
|
||||
///////////
|
||||
// USING //
|
||||
///////////
|
||||
|
||||
|
||||
////////////
|
||||
// EXTERN //
|
||||
////////////
|
||||
|
||||
|
||||
///////////////
|
||||
// Functions //
|
||||
///////////////
|
||||
//-----------------------------------------------
|
||||
// camAnimModeStart :
|
||||
// Manage interactions in interactive mode (start).
|
||||
//-----------------------------------------------
|
||||
void CUserControls::camAnimModeStart()
|
||||
{
|
||||
// No more Velocity.
|
||||
UserEntity->frontVelocity(0);
|
||||
UserEntity->lateralVelocity(0);
|
||||
// No more autowalk
|
||||
_DirectionMove = none;
|
||||
// Third person view but player dead, user is not selectable.
|
||||
UserEntity->selectable(false);
|
||||
_InternalView = false;
|
||||
// Show/hide all or parts of the user body (after _InternaView is set).
|
||||
UserEntity->updateVisualDisplay();
|
||||
}// camAnimModeStart //
|
||||
|
||||
//-----------------------------------------------
|
||||
// camAnimModeStop :
|
||||
// Manage interactions in interactive mode (stop).
|
||||
//-----------------------------------------------
|
||||
void CUserControls::camAnimModeStop()
|
||||
{
|
||||
// We tell the camera animation player to stop (by interruption)
|
||||
// If the camera animation player was not playing any animation it will have no effect but this function
|
||||
// is usefull if the mode has changed (player is dead) to interrupt the animation
|
||||
CCameraAnimationPlayer::getInstance()->stop(true);
|
||||
}// camAnimModeStop //
|
||||
|
||||
//-----------------------------------------------
|
||||
// camAnimMode :
|
||||
// Manage interactions in free head mode.
|
||||
//-----------------------------------------------
|
||||
void CUserControls::camAnimMode()
|
||||
{
|
||||
// Call the camera animation update function to update the view
|
||||
TCameraAnimationOutputInfo newCamInfo = CCameraAnimationPlayer::getInstance()->update();
|
||||
|
||||
// We normalize the look at direction
|
||||
newCamInfo.CamLookAtDir.normalize();
|
||||
|
||||
// We udpate the view
|
||||
View.view(newCamInfo.CamLookAtDir);
|
||||
View.viewPos(newCamInfo.CamPos);
|
||||
}// camAnimMode //
|
@ -0,0 +1,135 @@
|
||||
// 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_CAMERAANIMTYPEPARSER_H
|
||||
#define RY_CAMERAANIMTYPEPARSER_H
|
||||
|
||||
#include "nel/misc/vector.h"
|
||||
#include "nel/misc/stream.h"
|
||||
#include <math.h>
|
||||
|
||||
namespace NLMISC
|
||||
{
|
||||
|
||||
/// Function that serializes durations (in seconds)
|
||||
/// Duration is converted to 1/100 second and cannot be greater than 2^12-1 = 4095
|
||||
/// Result is serialized in 12 bits
|
||||
inline void serialDuration(NLMISC::CBitMemStream &f, float& duration)
|
||||
{
|
||||
static uint32 maxVal = (uint32)pow((float)2, 12) - 1;
|
||||
|
||||
if (f.isReading())
|
||||
{
|
||||
uint32 d = 0;
|
||||
|
||||
f.serial(d, 12);
|
||||
|
||||
duration = (float)d / 100.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32 d = (uint32)(duration * 100);
|
||||
if (d > maxVal)
|
||||
d = maxVal;
|
||||
|
||||
f.serial(d, 12);
|
||||
}
|
||||
}
|
||||
|
||||
/// Function that serializes distances (in meters)
|
||||
/// Distance is converted to centimeters and cannot be greater than 2^16-1 = 65535
|
||||
/// Result is serialized in 2 bytes
|
||||
inline void serialDistance(NLMISC::CBitMemStream &f, float& distance)
|
||||
{
|
||||
static uint32 maxVal = (uint32)pow((float)2, 16) - 1;
|
||||
|
||||
if (f.isReading())
|
||||
{
|
||||
uint32 d = 0;
|
||||
|
||||
f.serial(d, 16);
|
||||
|
||||
distance = (float)d / 100.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32 d = (uint32)(distance * 100);
|
||||
if (d > maxVal)
|
||||
d = maxVal;
|
||||
|
||||
f.serial(d, 16);
|
||||
}
|
||||
}
|
||||
|
||||
/// Function that serializes speeds (in m/s)
|
||||
/// Speed is converted to cm/s and cannot be greater than 2^12-1 = 4095
|
||||
/// Result is serialized in 12 bits
|
||||
inline void serialSpeed(NLMISC::CBitMemStream &f, float& speed)
|
||||
{
|
||||
static uint32 maxVal = (uint32)pow((float)2, 12) - 1;
|
||||
|
||||
if (f.isReading())
|
||||
{
|
||||
uint32 d = 0;
|
||||
|
||||
f.serial(d, 12);
|
||||
|
||||
speed = (float)d / 100.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32 d = (uint32)(speed * 100);
|
||||
if (d > maxVal)
|
||||
d = maxVal;
|
||||
|
||||
f.serial(d, 12);
|
||||
}
|
||||
}
|
||||
|
||||
/// Serializes the difference between 2 positions
|
||||
/// The difference is converted in cm and cannot be greater than 2^15-1 = 32767
|
||||
/// Result is serialized in 3 x 2 bytes = 6 bytes
|
||||
inline void serialPositionDifference(NLMISC::CBitMemStream &f, NLMISC::CVector& diffPos)
|
||||
{
|
||||
if (f.isReading())
|
||||
{
|
||||
sint16 x = 0;
|
||||
sint16 y = 0;
|
||||
sint16 z = 0;
|
||||
|
||||
f.serial(x);
|
||||
f.serial(y);
|
||||
f.serial(z);
|
||||
|
||||
diffPos.x = (float)(x) / 100.f;
|
||||
diffPos.y = (float)(y) / 100.f;
|
||||
diffPos.z = (float)(z) / 100.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
sint16 x = (sint16)(diffPos.x * 100.f);
|
||||
sint16 y = (sint16)(diffPos.y * 100.f);
|
||||
sint16 z = (sint16)(diffPos.z * 100.f);
|
||||
|
||||
f.serial(x);
|
||||
f.serial(y);
|
||||
f.serial(z);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /* RY_CAMERAANIMTYPEPARSER_H */
|
@ -0,0 +1,201 @@
|
||||
// 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_POSITIONORENTITYTYPE_H
|
||||
#define RY_POSITIONORENTITYTYPE_H
|
||||
|
||||
#include "nel/misc/entity_id.h"
|
||||
#include "nel/misc/vector.h"
|
||||
#include "nel/misc/stream.h"
|
||||
#include "game_share/camera_anim_type_parser.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/************************************************************************/
|
||||
/* Class that can contain either an entity id or a position */
|
||||
/************************************************************************/
|
||||
class CPositionOrEntity
|
||||
{
|
||||
public:
|
||||
enum PositionOrEntityType
|
||||
{
|
||||
EUnknown = -1,
|
||||
EPosition = 0,
|
||||
EEntity,
|
||||
EPreviousPos,
|
||||
EReturnPos
|
||||
};
|
||||
|
||||
CPositionOrEntity()
|
||||
{
|
||||
_type = EUnknown;
|
||||
}
|
||||
|
||||
CPositionOrEntity(const NLMISC::CVector& position)
|
||||
{
|
||||
_type = EPosition;
|
||||
Position = position;
|
||||
}
|
||||
|
||||
CPositionOrEntity(const TDataSetIndex& eid)
|
||||
{
|
||||
_type = EEntity;
|
||||
EntityId = eid;
|
||||
}
|
||||
|
||||
CPositionOrEntity(PositionOrEntityType type)
|
||||
{
|
||||
_type = type;
|
||||
}
|
||||
|
||||
CPositionOrEntity(const CPositionOrEntity& c)
|
||||
{
|
||||
_type = c._type;
|
||||
if (c.isPosition())
|
||||
Position = c.getPosition();
|
||||
else
|
||||
EntityId = c.getEntityId();
|
||||
}
|
||||
|
||||
CPositionOrEntity& operator=(const CPositionOrEntity& c)
|
||||
{
|
||||
_type = c._type;
|
||||
if (c.isPosition())
|
||||
Position = c.getPosition();
|
||||
else if (c.isEntityId())
|
||||
EntityId = c.getEntityId();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const CPositionOrEntity& c)
|
||||
{
|
||||
if (_type != c._type)
|
||||
return false;
|
||||
if (isPosition())
|
||||
return Position == c.getPosition();
|
||||
else if (isEntityId())
|
||||
return EntityId == c.getEntityId();
|
||||
return true;
|
||||
}
|
||||
|
||||
void setPosition(const NLMISC::CVector& position)
|
||||
{
|
||||
_type = EPosition;
|
||||
Position = position;
|
||||
}
|
||||
|
||||
void setEntityId(const TDataSetIndex& eid)
|
||||
{
|
||||
_type = EEntity;
|
||||
EntityId = eid;
|
||||
}
|
||||
|
||||
void setPreviousPos()
|
||||
{
|
||||
_type = EPreviousPos;
|
||||
}
|
||||
|
||||
void setReturnPos()
|
||||
{
|
||||
_type = EReturnPos;
|
||||
}
|
||||
|
||||
bool isPosition() const
|
||||
{
|
||||
return _type == EPosition;
|
||||
}
|
||||
|
||||
bool isEntityId() const
|
||||
{
|
||||
return _type == EEntity;
|
||||
}
|
||||
|
||||
bool isPreviousPos() const
|
||||
{
|
||||
return _type == EPreviousPos;
|
||||
}
|
||||
|
||||
bool isReturnPos() const
|
||||
{
|
||||
return _type == EReturnPos;
|
||||
}
|
||||
|
||||
NLMISC::CVector getPosition() const
|
||||
{
|
||||
if (!isPosition())
|
||||
return NLMISC::CVector();
|
||||
return Position;
|
||||
}
|
||||
|
||||
/// This function returns the difference between the player's position and the specified position
|
||||
/*virtual NLMISC::CVector getDiffPos(const NLMISC::CVector& targetPos) const = 0;
|
||||
|
||||
/// This function returns the target position given the difference between the player's position and this target position
|
||||
virtual NLMISC::CVector setPositionFromDiffPos(const NLMISC::CVector& diffPos) = 0;*/
|
||||
|
||||
TDataSetIndex getEntityId() const
|
||||
{
|
||||
if (!isEntityId())
|
||||
return TDataSetIndex();
|
||||
return EntityId;
|
||||
}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return _type != EUnknown;
|
||||
}
|
||||
|
||||
void serial(NLMISC::CBitMemStream &f)
|
||||
{
|
||||
if (f.isReading())
|
||||
{
|
||||
uint32 t = 0;
|
||||
f.serial(t, 2);
|
||||
_type = (PositionOrEntityType)t;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32 t = (uint32)_type;
|
||||
f.serial(t, 2);
|
||||
}
|
||||
if (isPosition())
|
||||
{
|
||||
if (f.isReading())
|
||||
{
|
||||
/*NLMISC::CVector diffPos = NLMISC::CVector();
|
||||
NLMISC::serialPositionDifference(f, diffPos);
|
||||
setPositionFromDiffPos(diffPos);*/
|
||||
f.serial(Position);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*NLMISC::CVector diffPos = getDiffPos(getPosition());
|
||||
NLMISC::serialPositionDifference(f, diffPos);*/
|
||||
f.serial(Position);
|
||||
}
|
||||
}
|
||||
else if (isEntityId())
|
||||
f.serial(EntityId);
|
||||
}
|
||||
|
||||
protected:
|
||||
PositionOrEntityType _type;
|
||||
NLMISC::CVector Position;
|
||||
TDataSetIndex EntityId;
|
||||
};
|
||||
|
||||
|
||||
#endif /* RY_POSITIONORENTITYTYPE_H */
|
@ -0,0 +1,209 @@
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
#include "stdpch.h"
|
||||
|
||||
#include "camera_animation_manager/camera_animation_manager.h"
|
||||
#include "primitives_parser.h"
|
||||
#include "nel/ligo/primitive.h"
|
||||
#include "camera_animation_manager/camera_animation_step_factory.h"
|
||||
#include "player_manager/player_manager.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace NLMISC;
|
||||
using namespace NLLIGO;
|
||||
using namespace NLNET;
|
||||
|
||||
CCameraAnimationManager* CCameraAnimationManager::_Instance = NULL;
|
||||
|
||||
void CCameraAnimationManager::init()
|
||||
{
|
||||
// Just asserts the instance is not already created and we create the manager that will load the camera animations
|
||||
nlassert(_Instance == NULL);
|
||||
_Instance = new CCameraAnimationManager();
|
||||
}
|
||||
|
||||
void CCameraAnimationManager::release()
|
||||
{
|
||||
// We delete the instance of the manager which will delete the allocated resources
|
||||
delete _Instance;
|
||||
_Instance = NULL;
|
||||
}
|
||||
|
||||
CCameraAnimationManager::CCameraAnimationManager()
|
||||
{
|
||||
// We get the loaded primitives
|
||||
const CPrimitivesParser::TPrimitivesList & primsList = CPrimitivesParser::getInstance().getPrimitives();
|
||||
|
||||
nlinfo("parsing the camera animations");
|
||||
|
||||
// We begin to parse the camera animations
|
||||
CPrimitivesParser::TPrimitivesList::const_iterator first, last;
|
||||
for (first = primsList.begin(), last = primsList.end(); first != last; ++first)
|
||||
{
|
||||
// parse camera animations
|
||||
if (!parseCameraAnimations(first->Primitive.RootNode, first->FileName))
|
||||
{
|
||||
nlwarning("<CCameraAnimationManager constructor> Error while parsing the camera animations in primitive number '%s'", first->FileName.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CCameraAnimationManager::~CCameraAnimationManager()
|
||||
{
|
||||
// Delete the list of animations
|
||||
TCameraAnimationContainer::iterator first = Animations.begin();
|
||||
for (; first != Animations.end(); ++first)
|
||||
{
|
||||
first->second.release();
|
||||
}
|
||||
Animations.clear();
|
||||
}
|
||||
|
||||
bool CCameraAnimationManager::parseCameraAnimations(const IPrimitive* prim, const std::string& filename)
|
||||
{
|
||||
string value;
|
||||
|
||||
// if the node is a camera animation parse it
|
||||
if (prim->getPropertyByName("class", value) && !nlstricmp(value.c_str(), "camera_animation_tree"))
|
||||
{
|
||||
// We get the name of the mission
|
||||
prim->getPropertyByName("name", value);
|
||||
|
||||
string animName = value;
|
||||
|
||||
TCameraAnimInfo animInfo;
|
||||
animInfo.Name = animName;
|
||||
|
||||
// We now parse the instructions which are children of the camera animation
|
||||
for (uint i = 0; i < prim->getNumChildren(); i++)
|
||||
{
|
||||
const IPrimitive* child;
|
||||
prim->getChild(child, i);
|
||||
|
||||
// We tell the factory to load the instructions in function of the type of instruction we have
|
||||
string stepType;
|
||||
if (!child->getPropertyByName("class", stepType))
|
||||
{
|
||||
nlwarning("<CCameraAnimationManager parseCameraAnimations> Error while getting the class of a camera animation step in primitive number '%s'", filename.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
ICameraAnimationStep* step = ICameraAnimationStepFactory::parseStep(child, filename, stepType);
|
||||
// We add the instruction to the list
|
||||
if (step)
|
||||
{
|
||||
animInfo.Steps.push_back(step);
|
||||
}
|
||||
}
|
||||
|
||||
// We add the camera animation to the container
|
||||
Animations[animName] = animInfo;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// lookup recursively in the children
|
||||
bool ok = true;
|
||||
for (uint i = 0; i < prim->getNumChildren(); ++i)
|
||||
{
|
||||
const IPrimitive *child;
|
||||
if (!prim->getChild(child,i) || !parseCameraAnimations(child, filename))
|
||||
ok = false;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
void CCameraAnimationManager::sendAnimation(const NLMISC::CEntityId& eid, const std::string& animationName)
|
||||
{
|
||||
// We search for the correct camera animation
|
||||
TCameraAnimationContainer::iterator it;
|
||||
for (it = Animations.begin(); it != Animations.end(); ++it)
|
||||
{
|
||||
if (it->first == animationName)
|
||||
{
|
||||
it->second.sendAnimationSteps(eid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCameraAnimationManager::TCameraAnimInfo::sendAnimationSteps(const NLMISC::CEntityId& eid)
|
||||
{
|
||||
// We first send an impulse to the client to tell him an animation will start (this way he can remember its current position)
|
||||
nldebug("CameraAnimation sending impulse for starting anim, eidDynamicId: %d", (int)eid.getDynamicId());
|
||||
|
||||
PlayerManager.sendImpulseToClient(eid, "CAMERA_ANIMATION:PLAY");
|
||||
|
||||
// We send the first step, and then the others
|
||||
sendAnimationStepsFrom(eid, 0);
|
||||
}
|
||||
|
||||
bool CCameraAnimationManager::TCameraAnimInfo::sendAnimationStep(const NLMISC::CEntityId& eid, int currentStep)
|
||||
{
|
||||
// We can send the current step
|
||||
// We first check if the step exists
|
||||
if (currentStep < 0 || currentStep >= Steps.size())
|
||||
return false;
|
||||
|
||||
ICameraAnimationStep* step = Steps[currentStep];
|
||||
|
||||
// We send the animation step to the client
|
||||
NLNET::CMessage msgout("IMPULSION_ID");
|
||||
msgout.serial(const_cast<NLMISC::CEntityId&>(eid));
|
||||
NLMISC::CBitMemStream bms;
|
||||
GenericMsgManager.pushNameToStream("CAMERA_ANIMATION:STEP", bms);
|
||||
|
||||
// We tell the step to fill the message
|
||||
step->sendAnimationFullStep(bms);
|
||||
|
||||
// We add the buffer to the message
|
||||
msgout.serialBufferWithSize((uint8*)bms.buffer(), bms.length());
|
||||
|
||||
nldebug("CameraAnimation sending impulse for step %s, buffer length: %d, eidDynamicId: %d", step->getStepName().c_str(),
|
||||
bms.length(), (int)eid.getDynamicId());
|
||||
|
||||
NLNET::CUnifiedNetwork::getInstance()->send(NLNET::TServiceId(eid.getDynamicId()), msgout);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCameraAnimationManager::TCameraAnimInfo::sendAnimationStepsFrom(const NLMISC::CEntityId& eid, int firstStep, TCameraAnimTimerEvent* event)
|
||||
{
|
||||
// We send the current step
|
||||
if (sendAnimationStep(eid, firstStep))
|
||||
{
|
||||
if (event == 0)
|
||||
event = new TCameraAnimTimerEvent(this, firstStep + 1, eid);
|
||||
else
|
||||
event->nextStep();
|
||||
|
||||
// Now we send the other steps after the duration
|
||||
//_Timer->reset();
|
||||
NLMISC::TGameCycle duration = (NLMISC::TGameCycle)(Steps[firstStep]->getDuration() / CTickEventHandler::getGameTimeStep());
|
||||
_Timer->setRemaining(duration, event);
|
||||
}
|
||||
else
|
||||
{
|
||||
// There was no other step, so we send an impulse to tell the client it's finished
|
||||
nldebug("CameraAnimation sending impulse for finished anim, eidDynamicId: %d", (int)eid.getDynamicId());
|
||||
|
||||
PlayerManager.sendImpulseToClient(eid, "CAMERA_ANIMATION:FINISHED");
|
||||
}
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
// 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_CAMERAANIMATIONMANAGER_H
|
||||
#define RY_CAMERAANIMATIONMANAGER_H
|
||||
|
||||
#include "nel/ligo/primitive.h"
|
||||
#include <string>
|
||||
#include "camera_animation_manager/camera_animation_step_factory.h"
|
||||
#include "nel/misc/entity_id.h"
|
||||
#include "game_share/timer.h"
|
||||
|
||||
/************************************************************************/
|
||||
/* Class that manages the camera animations. (singleton).
|
||||
* It's responsible of :
|
||||
* - Parsing camera animations in primitives
|
||||
* - Sending a specified animation to the client
|
||||
*
|
||||
* \author Fabien Henon
|
||||
* \date 2012
|
||||
*/
|
||||
/************************************************************************/
|
||||
class CCameraAnimationManager
|
||||
{
|
||||
public:
|
||||
/// Gets the current instance of the manager
|
||||
static CCameraAnimationManager* getInstance() { return _Instance; }
|
||||
/// Creates the instance of the manager and parse the animations
|
||||
static void init();
|
||||
/// Releases the animations
|
||||
static void release();
|
||||
|
||||
/// Function that sends all the instructions of a camera animation to the specified entity
|
||||
void sendAnimation(const NLMISC::CEntityId& eid, const std::string& animationName);
|
||||
|
||||
private:
|
||||
/// Constructor
|
||||
CCameraAnimationManager();
|
||||
/// Destructor
|
||||
~CCameraAnimationManager();
|
||||
|
||||
/// Function that parses the camera animations
|
||||
bool parseCameraAnimations(const NLLIGO::IPrimitive* prim, const std::string& filename);
|
||||
|
||||
/// Instance of the manager
|
||||
static CCameraAnimationManager* _Instance;
|
||||
|
||||
/// Class that contains information about an animation
|
||||
class TCameraAnimInfo
|
||||
{
|
||||
private:
|
||||
class TCameraAnimTimerEvent;
|
||||
|
||||
public:
|
||||
TCameraAnimInfo()
|
||||
{
|
||||
Name = "";
|
||||
_Timer = new CTimer();
|
||||
}
|
||||
/// Function called to release the animations
|
||||
void release()
|
||||
{
|
||||
// We delete the camera animation steps
|
||||
for (std::vector<ICameraAnimationStep*>::iterator it = Steps.begin(); it != Steps.end(); ++it)
|
||||
{
|
||||
ICameraAnimationStep* step = *it;
|
||||
delete step;
|
||||
}
|
||||
Steps.clear();
|
||||
|
||||
Name = "";
|
||||
|
||||
delete _Timer;
|
||||
}
|
||||
|
||||
/// Function called to send the camera animation instruction specified by the current step to the client
|
||||
/// The function returns false if the animation step does not exist
|
||||
bool sendAnimationStep(const NLMISC::CEntityId& eid, int currentStep);
|
||||
/// Function called to send all the camera animation instructions to the client
|
||||
void sendAnimationSteps(const NLMISC::CEntityId& eid);
|
||||
/// Function that sends the animation steps from the specified one to the last one
|
||||
void sendAnimationStepsFrom(const NLMISC::CEntityId& eid, int firstStep, TCameraAnimTimerEvent* event = 0);
|
||||
|
||||
|
||||
std::string Name;
|
||||
std::vector<ICameraAnimationStep*> Steps;
|
||||
|
||||
private:
|
||||
CTimer* _Timer;
|
||||
|
||||
class TCameraAnimTimerEvent: public CTimerEvent
|
||||
{
|
||||
public:
|
||||
TCameraAnimTimerEvent(TCameraAnimInfo* info, int nextStep, const NLMISC::CEntityId& eid): _Eid(eid)
|
||||
{
|
||||
_Infos = info;
|
||||
_Next = nextStep;
|
||||
|
||||
nldebug("TCameraAnimTimerEvent constructor for step %s, eidDynamicId: %d", info->Name.c_str(),
|
||||
(int)eid.getDynamicId());
|
||||
}
|
||||
|
||||
~TCameraAnimTimerEvent()
|
||||
{
|
||||
nldebug("TCameraAnimTimerEvent destructor");
|
||||
}
|
||||
|
||||
// Callback called when the timer finished
|
||||
void timerCallback(CTimer* owner)
|
||||
{
|
||||
// We tell the camera anim info to send the current step and the next ones
|
||||
_Infos->sendAnimationStepsFrom(_Eid, _Next, this);
|
||||
}
|
||||
|
||||
void nextStep()
|
||||
{
|
||||
_Next++;
|
||||
}
|
||||
|
||||
private:
|
||||
TCameraAnimInfo* _Infos;
|
||||
int _Next;
|
||||
NLMISC::CEntityId _Eid;
|
||||
};
|
||||
};
|
||||
|
||||
typedef std::map<std::string, TCameraAnimInfo> TCameraAnimationContainer;
|
||||
|
||||
/// Variable that contains the animations
|
||||
TCameraAnimationContainer Animations;
|
||||
};
|
||||
|
||||
|
||||
#endif /* RY_CAMERAANIMATIONMANAGER_H */
|
@ -0,0 +1,62 @@
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
#include "camera_animation_manager/camera_animation_modifier_factory.h"
|
||||
|
||||
std::vector<std::pair<std::string, ICameraAnimationModifierFactory*> >* ICameraAnimationModifierFactory::Entries;
|
||||
|
||||
ICameraAnimationModifier* ICameraAnimationModifierFactory::parseModifier(const NLLIGO::IPrimitive* prim, const std::string& filename, const std::string& modifierType)
|
||||
{
|
||||
// We search the correct modifier type in our entries
|
||||
for (uint i = 0; i < Entries->size(); i++)
|
||||
{
|
||||
if (modifierType == (*Entries)[i].first)
|
||||
{
|
||||
ICameraAnimationModifier * ret = (*Entries)[i].second->instanciate();
|
||||
if (!ret)
|
||||
{
|
||||
nlerror("BUG IN CAMERA ANIMATION MODIFIER FACTORY : BAD INIT CODE");
|
||||
return NULL;
|
||||
}
|
||||
// We parse the modifier
|
||||
if (!ret->parseModifier(prim, filename))
|
||||
{
|
||||
nlerror("building camera animation modifier failed");
|
||||
delete ret;
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ICameraAnimationModifierFactory::init()
|
||||
{
|
||||
if (!Entries)
|
||||
Entries = new std::vector<std::pair<std::string, ICameraAnimationModifierFactory*> >;
|
||||
}
|
||||
|
||||
void ICameraAnimationModifier::sendCameraFullModifier(NLMISC::CBitMemStream& bms)
|
||||
{
|
||||
// We first add the name of the modifier
|
||||
std::string name = getModifierName();
|
||||
bms.serial(const_cast<std::string&>(name));
|
||||
|
||||
// We ask the modifier to add its information to the message
|
||||
sendCameraModifier(bms);
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
// 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_CAMERAANIMATIONMODIFIERFACTORY_H
|
||||
#define RY_CAMERAANIMATIONMODIFIERFACTORY_H
|
||||
|
||||
#include "nel/ligo/primitive.h"
|
||||
#include <string>
|
||||
|
||||
/************************************************************************/
|
||||
/* Interface for camera animation modifiers.
|
||||
* For simplicity, sounds triggers and considered like modifiers too.
|
||||
* It has to be able to parse it's parameters from the primitive.
|
||||
* And also to generate a small script to send to the client
|
||||
*/
|
||||
/************************************************************************/
|
||||
class ICameraAnimationModifier
|
||||
{
|
||||
public:
|
||||
/// This function is called when it's time to parse the primitive to load the camera animation modifier
|
||||
virtual bool parseModifier(const NLLIGO::IPrimitive* prim, const std::string& filename) = 0;
|
||||
|
||||
/// Function called to send the modifier to the client
|
||||
virtual void sendCameraModifier(NLMISC::CBitMemStream& bms) = 0;
|
||||
|
||||
/// Function to get the name of the modifier
|
||||
virtual std::string getModifierName() const = 0;
|
||||
|
||||
/// Function called to send the modifier to the client (including its name)
|
||||
void sendCameraFullModifier(NLMISC::CBitMemStream& bms);
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
/* Factory class that can instanciate the correct camera animation modifier handler.
|
||||
*
|
||||
* \author Fabien Henon
|
||||
* \date 2012
|
||||
*/
|
||||
/************************************************************************/
|
||||
class ICameraAnimationModifierFactory
|
||||
{
|
||||
public:
|
||||
/// Function that will instanciate the correct camera animation step
|
||||
static ICameraAnimationModifier* parseModifier(const NLLIGO::IPrimitive* prim, const std::string& filename, const std::string& modifierType);
|
||||
protected:
|
||||
|
||||
/// Functions used to be able to create the camera animation modifiers
|
||||
static void init();
|
||||
virtual ICameraAnimationModifier * instanciate() = 0;
|
||||
static std::vector<std::pair<std::string, ICameraAnimationModifierFactory*> >* Entries;
|
||||
};
|
||||
|
||||
// Define used to register the different types of camera animation modifiers
|
||||
#define CAMERA_ANIMATION_REGISTER_MODIFIER(_class_,_name_) \
|
||||
class _class_##CameraAnimationModifierFactory : public ICameraAnimationModifierFactory \
|
||||
{\
|
||||
public:\
|
||||
_class_##CameraAnimationModifierFactory()\
|
||||
{\
|
||||
init();\
|
||||
std::string str = std::string(_name_); \
|
||||
for (uint i = 0; i < (*Entries).size(); i++ ) \
|
||||
{\
|
||||
if ( (*Entries)[i].first == str || (*Entries)[i].second == this )nlstop;\
|
||||
}\
|
||||
(*Entries).push_back( std::make_pair( str, this ) );\
|
||||
}\
|
||||
ICameraAnimationModifier * instanciate()\
|
||||
{ \
|
||||
return new _class_;\
|
||||
} \
|
||||
};\
|
||||
static _class_##CameraAnimationModifierFactory* _class_##CameraAnimationModifierFactoryInstance = new _class_##CameraAnimationModifierFactory;
|
||||
|
||||
#define CAMERA_ANIMATION_MODIFIER_NAME(name) \
|
||||
std::string getModifierName() const \
|
||||
{ \
|
||||
return name; \
|
||||
}
|
||||
|
||||
#endif /* RY_CAMERAANIMATIONMODIFIERFACTORY_H */
|
@ -0,0 +1,125 @@
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
#include "camera_animation_manager/camera_animation_modifier_factory.h"
|
||||
#include "game_share/position_or_entity_type.h"
|
||||
|
||||
#include "nel/misc/sheet_id.h"
|
||||
#include "camera_animation_manager/position_or_entity_type_helper.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// This animation modifier shakes the camera. The parameter is
|
||||
/// - strength
|
||||
class CCameraAnimationModifierShake : public ICameraAnimationModifier
|
||||
{
|
||||
protected:
|
||||
float Strength;
|
||||
|
||||
public:
|
||||
CCameraAnimationModifierShake()
|
||||
{
|
||||
Strength = 0.f;
|
||||
}
|
||||
|
||||
virtual bool parseModifier(const NLLIGO::IPrimitive* prim, const std::string& filename)
|
||||
{
|
||||
std::string value;
|
||||
|
||||
// We get the strength
|
||||
if (!prim->getPropertyByName("strength", value))
|
||||
{
|
||||
nlwarning("<CCameraAnimationModifierShake parseModifier> impossible to get the strength property of the basic modifier in primitive : %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
if (!NLMISC::fromString(value, Strength))
|
||||
{
|
||||
nlwarning("<CCameraAnimationModifierShake parseModifier> impossible to convert the string : %s, in float in the basic modifier in primitive : %s", value.c_str(), filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void sendCameraModifier(NLMISC::CBitMemStream& bms)
|
||||
{
|
||||
bms.serial(const_cast<float&>(Strength));
|
||||
}
|
||||
|
||||
CAMERA_ANIMATION_MODIFIER_NAME("camera_modifier_shake");
|
||||
};
|
||||
CAMERA_ANIMATION_REGISTER_MODIFIER(CCameraAnimationModifierShake, "camera_modifier_shake");
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// This animation modifier plays a sound. The parameters are
|
||||
/// - sound_name
|
||||
/// - sound_position
|
||||
class CCameraAnimationModifierSoundTrigger : public ICameraAnimationModifier
|
||||
{
|
||||
protected:
|
||||
std::string SoundPos;
|
||||
NLMISC::CSheetId SoundId;
|
||||
|
||||
public:
|
||||
CCameraAnimationModifierSoundTrigger()
|
||||
{
|
||||
SoundPos = "";
|
||||
SoundId = NLMISC::CSheetId::Unknown;
|
||||
}
|
||||
|
||||
virtual bool parseModifier(const NLLIGO::IPrimitive* prim, const std::string& filename)
|
||||
{
|
||||
std::string value;
|
||||
|
||||
// We get the sound name
|
||||
if (!prim->getPropertyByName("sound_name", value))
|
||||
{
|
||||
nlwarning("<CCameraAnimationModifierSoundTrigger parseModifier> impossible to get the sound_name property of the basic modifier in primitive : %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
SoundId = NLMISC::CSheetId(value);
|
||||
if (SoundId == NLMISC::CSheetId::Unknown)
|
||||
{
|
||||
nlwarning("<CCameraAnimationModifierSoundTrigger parseModifier> sheetid not found for sound name %s in the basic modifier in primitive : %s", value.c_str(), filename.c_str());
|
||||
return false;
|
||||
}
|
||||
// We get the sound position
|
||||
if (!prim->getPropertyByName("sound_position", value))
|
||||
{
|
||||
nlwarning("<CCameraAnimationModifierSoundTrigger parseModifier> impossible to get the sound_position property of the basic modifier in primitive : %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
SoundPos = value;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void sendCameraModifier(NLMISC::CBitMemStream& bms)
|
||||
{
|
||||
CPositionOrEntityHelper pos = CPositionOrEntityHelper::fromString(SoundPos);
|
||||
if (pos == CPositionOrEntityHelper::Invalid)
|
||||
{
|
||||
nlerror("<CCameraAnimationModifierSoundTrigger parseModifier> invalid soundpos %s", SoundPos.c_str());
|
||||
}
|
||||
|
||||
bms.serial(const_cast<CPositionOrEntityHelper&>(pos));
|
||||
bms.serial(const_cast<NLMISC::CSheetId&>(SoundId));
|
||||
}
|
||||
|
||||
CAMERA_ANIMATION_MODIFIER_NAME("sound_trigger");
|
||||
};
|
||||
CAMERA_ANIMATION_REGISTER_MODIFIER(CCameraAnimationModifierSoundTrigger, "sound_trigger");
|
@ -0,0 +1,104 @@
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
#include "camera_animation_manager/camera_animation_step_factory.h"
|
||||
|
||||
std::vector<std::pair<std::string, ICameraAnimationStepFactory*> >* ICameraAnimationStepFactory::Entries;
|
||||
|
||||
ICameraAnimationStep* ICameraAnimationStepFactory::parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename, const std::string& stepType)
|
||||
{
|
||||
// We search the correct step type in our entries
|
||||
for (uint i = 0; i < Entries->size(); i++)
|
||||
{
|
||||
if (stepType == (*Entries)[i].first)
|
||||
{
|
||||
ICameraAnimationStep * ret = (*Entries)[i].second->instanciate();
|
||||
if (!ret)
|
||||
{
|
||||
nlerror("BUG IN CAMERA ANIMATION STEP FACTORY : BAD INIT CODE");
|
||||
return NULL;
|
||||
}
|
||||
// We parse the step
|
||||
if (!ret->parseStep(prim, filename))
|
||||
{
|
||||
nlerror("building camera animation step failed");
|
||||
delete ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// We look for children (modifiers or sound triggers)
|
||||
for (uint i = 0; i < prim->getNumChildren(); i++)
|
||||
{
|
||||
const NLLIGO::IPrimitive* child;
|
||||
prim->getChild(child, i);
|
||||
|
||||
// We tell the factory to load the modifier in function of its type
|
||||
std::string modifierType;
|
||||
if (!child->getPropertyByName("class", modifierType))
|
||||
{
|
||||
nlwarning("<ICameraAnimationStepFactory parseStep> Error while getting the class of a camera animation modifier in primitive number '%s'", filename.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
ICameraAnimationModifier* modifier = ICameraAnimationModifierFactory::parseModifier(child, filename, modifierType);
|
||||
// We add the modifier to the list
|
||||
if (modifier)
|
||||
{
|
||||
ret->addModifier(modifier);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ICameraAnimationStepFactory::init()
|
||||
{
|
||||
if (!Entries)
|
||||
Entries = new std::vector<std::pair<std::string, ICameraAnimationStepFactory*> >;
|
||||
}
|
||||
|
||||
void ICameraAnimationStep::addModifier(ICameraAnimationModifier* modifier)
|
||||
{
|
||||
Modifiers.push_back(modifier);
|
||||
}
|
||||
|
||||
void ICameraAnimationStep::sendAnimationFullStep(NLMISC::CBitMemStream& bms)
|
||||
{
|
||||
/*// We first add the name of the step
|
||||
std::string name = getStepName();
|
||||
bms.serial(const_cast<std::string&>(name));*/
|
||||
|
||||
// We ask the step to add its information to the message
|
||||
sendAnimationStep(bms);
|
||||
|
||||
// We finally send the modifiers instructions
|
||||
// We add a header to tell the number of modifiers
|
||||
uint8 nbModifiers = (uint8)Modifiers.size();
|
||||
bms.serial(const_cast<uint8&>(nbModifiers));
|
||||
|
||||
// We loop through the modifiers to add them
|
||||
std::vector<ICameraAnimationModifier*>::iterator it;
|
||||
for (it = Modifiers.begin(); it != Modifiers.end(); ++it)
|
||||
{
|
||||
ICameraAnimationModifier* modifier = *it;
|
||||
|
||||
modifier->sendCameraFullModifier(bms);
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
// 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_CAMERAANIMATIONSTEPFACTORY_H
|
||||
#define RY_CAMERAANIMATIONSTEPFACTORY_H
|
||||
|
||||
#include "nel/ligo/primitive.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "camera_animation_manager/camera_animation_modifier_factory.h"
|
||||
|
||||
/************************************************************************/
|
||||
/* Interface for camera animation steps.
|
||||
* It has to be able to parse the step from the primitive.
|
||||
* And also to generate a small script to send to the client
|
||||
*/
|
||||
/************************************************************************/
|
||||
class ICameraAnimationStep
|
||||
{
|
||||
public:
|
||||
/// This function is called when it's time to parse the primitive to load the camera animation step
|
||||
virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename) = 0;
|
||||
/// Function that adds a camera animation modifier to this step
|
||||
void addModifier(ICameraAnimationModifier* modifier);
|
||||
|
||||
/// Function that returns the duration of the step (in seconds)
|
||||
virtual float getDuration() const = 0;
|
||||
/// Function that returns the name of the step
|
||||
virtual std::string getStepName() const = 0;
|
||||
|
||||
/// Function that sends the animation step the to client
|
||||
virtual void sendAnimationStep(NLMISC::CBitMemStream& bms) = 0;
|
||||
|
||||
/// Function that send all information about a step to the client (this includes modifiers)
|
||||
void sendAnimationFullStep(NLMISC::CBitMemStream& bms);
|
||||
|
||||
protected:
|
||||
// The list of modifiers
|
||||
std::vector<ICameraAnimationModifier*> Modifiers;
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
/* Factory class that can instanciate the correct camera animation step handler.
|
||||
*
|
||||
* \author Fabien Henon
|
||||
* \date 2012
|
||||
*/
|
||||
/************************************************************************/
|
||||
class ICameraAnimationStepFactory
|
||||
{
|
||||
public:
|
||||
/// Function that will instanciate the correct camera animation step
|
||||
static ICameraAnimationStep* parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename, const std::string& stepType);
|
||||
protected:
|
||||
|
||||
/// Functions used to be able to create the camera animation steps
|
||||
static void init();
|
||||
virtual ICameraAnimationStep * instanciate() = 0;
|
||||
static std::vector<std::pair<std::string, ICameraAnimationStepFactory*> >* Entries;
|
||||
};
|
||||
|
||||
// Define used to register the different types of camera animation steps
|
||||
#define CAMERA_ANIMATION_REGISTER_STEP(_class_,_name_) \
|
||||
class _class_##CameraAnimationStepFactory : public ICameraAnimationStepFactory \
|
||||
{\
|
||||
public:\
|
||||
_class_##CameraAnimationStepFactory()\
|
||||
{\
|
||||
init();\
|
||||
std::string str = std::string(_name_); \
|
||||
for (uint i = 0; i < (*Entries).size(); i++ ) \
|
||||
{\
|
||||
if ( (*Entries)[i].first == str || (*Entries)[i].second == this )nlstop;\
|
||||
}\
|
||||
(*Entries).push_back( std::make_pair( str, this ) );\
|
||||
}\
|
||||
ICameraAnimationStep * instanciate()\
|
||||
{ \
|
||||
return new _class_;\
|
||||
} \
|
||||
};\
|
||||
static _class_##CameraAnimationStepFactory* _class_##CameraAnimationStepFactoryInstance = new _class_##CameraAnimationStepFactory;
|
||||
|
||||
#define CAMERA_ANIMATION_STEP_NAME(name) \
|
||||
std::string getStepName() const \
|
||||
{ \
|
||||
return name; \
|
||||
}
|
||||
|
||||
#endif /* RY_CAMERAANIMATIONSTEPFACTORY_H */
|
@ -0,0 +1,197 @@
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
#include "camera_animation_manager/camera_animation_step_factory.h"
|
||||
#include "game_share/position_or_entity_type.h"
|
||||
#include "camera_animation_manager/position_or_entity_type_helper.h"
|
||||
#include "game_share/camera_anim_type_parser.h"
|
||||
|
||||
|
||||
/// Basic camera animation step that has generic values
|
||||
class CCameraAnimationStep : public ICameraAnimationStep
|
||||
{
|
||||
protected:
|
||||
std::string LookAtTarget;
|
||||
float DirectionTransitionTime;
|
||||
std::string PositionTarget;
|
||||
float PositionTransitionTime;
|
||||
float DistanceTo;
|
||||
bool HasTurnAround;
|
||||
float TurnAroundSpeed;
|
||||
|
||||
std::string Text;
|
||||
float Duration;
|
||||
|
||||
public:
|
||||
CCameraAnimationStep()
|
||||
{
|
||||
LookAtTarget = "";
|
||||
DirectionTransitionTime = 0.f;
|
||||
PositionTarget = "";
|
||||
PositionTransitionTime = 0.f;
|
||||
DistanceTo = 0.f;
|
||||
HasTurnAround = false;
|
||||
TurnAroundSpeed = 0.f;
|
||||
Text = "";
|
||||
Duration = 0.f;
|
||||
}
|
||||
|
||||
virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename)
|
||||
{
|
||||
std::string value;
|
||||
|
||||
// We get the look at target
|
||||
if (!prim->getPropertyByName("look_at_target", value))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the look_at_target property of the basic step in primitive : %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
LookAtTarget = value;
|
||||
|
||||
// We get the direction_transition_time
|
||||
if (!prim->getPropertyByName("direction_transition_time", value))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the direction_transition_time property of the basic step in primitive : %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
if (!NLMISC::fromString(value, DirectionTransitionTime))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to convert the string : %s, in float in the basic step in primitive : %s", value.c_str(), filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// We get the position_target
|
||||
if (!prim->getPropertyByName("position_target", value))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the position_target property of the basic step in primitive : %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
PositionTarget = value;
|
||||
|
||||
// We get the position_transition_time
|
||||
if (!prim->getPropertyByName("position_transition_time", value))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the position_transition_time property of the basic step in primitive : %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
if (!NLMISC::fromString(value, PositionTransitionTime))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to convert the string : %s, in float in the basic step in primitive : %s", value.c_str(), filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// We get the distance_to
|
||||
if (!prim->getPropertyByName("distance_to", value))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the distance_to property of the basic step in primitive : %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
if (!NLMISC::fromString(value, DistanceTo))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to convert the string : %s, in float in the basic step in primitive : %s", value.c_str(), filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// We get the has_turn_around
|
||||
if (!prim->getPropertyByName("has_turn_around", value))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the has_turn_around property of the basic step in primitive : %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
if (!NLMISC::fromString(value, HasTurnAround))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to convert the string : %s, in bool in the basic step in primitive : %s", value.c_str(), filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// We get the turn_around_speed
|
||||
if (!prim->getPropertyByName("turn_around_speed", value))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the turn_around_speed property of the basic step in primitive : %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
if (!NLMISC::fromString(value, TurnAroundSpeed))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to convert the string : %s, in float in the basic step in primitive : %s", value.c_str(), filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// We get the text
|
||||
if (!prim->getPropertyByName("text", value))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the text property of the basic step in primitive : %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
Text = value;
|
||||
|
||||
// We get the duration
|
||||
if (!prim->getPropertyByName("duration", value))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the duration property of the basic step in primitive : %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
if (!NLMISC::fromString(value, Duration))
|
||||
{
|
||||
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to convert the string : %s, in float in the basic step in primitive : %s", value.c_str(), filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void sendAnimationStep(NLMISC::CBitMemStream& bms)
|
||||
{
|
||||
CPositionOrEntityHelper posLookAtTarget = CPositionOrEntityHelper::fromString(LookAtTarget);
|
||||
if (posLookAtTarget == CPositionOrEntityHelper::Invalid)
|
||||
{
|
||||
nlerror("<CCameraAnimationStepBasic parseStep> invalid LookAtTarget %s", LookAtTarget.c_str());
|
||||
}
|
||||
|
||||
bms.serial(const_cast<CPositionOrEntityHelper&>(posLookAtTarget));
|
||||
if (!posLookAtTarget.isPreviousPos())
|
||||
{
|
||||
NLMISC::serialDuration(bms, DirectionTransitionTime);
|
||||
}
|
||||
|
||||
CPositionOrEntityHelper posPosTarget = CPositionOrEntityHelper::fromString(PositionTarget);
|
||||
if (posPosTarget == CPositionOrEntityHelper::Invalid)
|
||||
{
|
||||
nlerror("<CCameraAnimationStepBasic parseStep> invalid PositionTarget %s", PositionTarget.c_str());
|
||||
}
|
||||
|
||||
bms.serial(const_cast<CPositionOrEntityHelper&>(posPosTarget));
|
||||
if (!posPosTarget.isPreviousPos())
|
||||
{
|
||||
NLMISC::serialDistance(bms, DistanceTo);
|
||||
NLMISC::serialDuration(bms, PositionTransitionTime);
|
||||
bms.serialBit(const_cast<bool&>(HasTurnAround));
|
||||
|
||||
if (HasTurnAround)
|
||||
{
|
||||
NLMISC::serialSpeed(bms, TurnAroundSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual float getDuration() const
|
||||
{
|
||||
return Duration;
|
||||
}
|
||||
|
||||
CAMERA_ANIMATION_STEP_NAME("camera_animation_step");
|
||||
};
|
||||
CAMERA_ANIMATION_REGISTER_STEP(CCameraAnimationStep, "camera_animation_step");
|
@ -0,0 +1,127 @@
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#include "camera_animation_manager/position_or_entity_type_helper.h"
|
||||
#include "game_share/mirror.h"
|
||||
#include "game_share/mirrored_data_set.h"
|
||||
#include "game_share/base_types.h"
|
||||
#include "mission_manager/ai_alias_translator.h"
|
||||
#include "mission_manager/mission_parser.h"
|
||||
#include "egs_mirror.h"
|
||||
|
||||
#define POS_OR_ENTITY_PREVIOUS_POS_VALUE "_PreviousPos_"
|
||||
#define POS_OR_ENTITY_RETURN_POS_VALUE "_ReturnPos_"
|
||||
|
||||
const CPositionOrEntityHelper CPositionOrEntityHelper::Invalid = CPositionOrEntityHelper();
|
||||
|
||||
CPositionOrEntityHelper CPositionOrEntityHelper::fromString(const std::string& s)
|
||||
{
|
||||
// If the string is empty it's a previous pos
|
||||
if (s.empty())
|
||||
{
|
||||
return CPositionOrEntityHelper(CPositionOrEntity::EPreviousPos);
|
||||
}
|
||||
|
||||
std::string str = s;
|
||||
CMissionParser::removeBlanks(str);
|
||||
|
||||
// We already check if it's a special position or entity object
|
||||
if (NLMISC::toLower(str) == POS_OR_ENTITY_PREVIOUS_POS_VALUE)
|
||||
{
|
||||
return CPositionOrEntityHelper(CPositionOrEntity::EPreviousPos);
|
||||
}
|
||||
else if (NLMISC::toLower(str) == POS_OR_ENTITY_RETURN_POS_VALUE)
|
||||
{
|
||||
return CPositionOrEntityHelper(CPositionOrEntity::EReturnPos);
|
||||
}
|
||||
|
||||
std::vector<std::string> resS;
|
||||
NLMISC::splitString(str, ";", resS);
|
||||
// If we don't have 3 components, it's an entity
|
||||
if (resS.size() != 3)
|
||||
{
|
||||
std::vector<TAIAlias> res;
|
||||
CAIAliasTranslator::getInstance()->getNPCAliasesFromName(str, res);
|
||||
if (res.size() != 1)
|
||||
{
|
||||
nlerror("TPositionOrentityHelper : no alias for entity name %s", str.c_str());
|
||||
return CPositionOrEntityHelper();
|
||||
}
|
||||
TAIAlias alias = res[0];
|
||||
if (alias == CAIAliasTranslator::Invalid)
|
||||
{
|
||||
nlerror("TPositionOrentityHelper : invalid alias for entity name %s", str.c_str());
|
||||
return CPositionOrEntityHelper();
|
||||
}
|
||||
NLMISC::CEntityId eid = CAIAliasTranslator::getInstance()->getEntityId(alias);
|
||||
if (eid == NLMISC::CEntityId::Unknown)
|
||||
{
|
||||
nlerror("TPositionOrentityHelper : invalid entity id from alias %d", alias);
|
||||
return CPositionOrEntityHelper();
|
||||
}
|
||||
TDataSetIndex compressedId = TheDataset.getDataSetRow(eid).getCompressedIndex();
|
||||
|
||||
return CPositionOrEntityHelper(compressedId);
|
||||
}
|
||||
else
|
||||
{
|
||||
// It's a position
|
||||
std::string xStr = resS[0];
|
||||
std::string yStr = resS[1];
|
||||
std::string zStr = resS[2];
|
||||
|
||||
CMissionParser::removeBlanks(xStr);
|
||||
CMissionParser::removeBlanks(yStr);
|
||||
CMissionParser::removeBlanks(zStr);
|
||||
|
||||
float x = 0.f;
|
||||
float y = 0.f;
|
||||
float z = 0.f;
|
||||
|
||||
if (!NLMISC::fromString(xStr, x))
|
||||
{
|
||||
nlerror("TPositionOrentityHelper : invalid x component from string %s", xStr.c_str());
|
||||
return CPositionOrEntityHelper();
|
||||
}
|
||||
if (!NLMISC::fromString(yStr, y))
|
||||
{
|
||||
nlerror("TPositionOrentityHelper : invalid y component from string %s", yStr.c_str());
|
||||
return CPositionOrEntityHelper();
|
||||
}
|
||||
if (!NLMISC::fromString(yStr, x))
|
||||
{
|
||||
nlerror("TPositionOrentityHelper : invalid z component from string %s", zStr.c_str());
|
||||
return CPositionOrEntityHelper();
|
||||
}
|
||||
|
||||
return CPositionOrEntityHelper(NLMISC::CVector(x, y, z));
|
||||
}
|
||||
|
||||
return CPositionOrEntityHelper();
|
||||
}
|
||||
|
||||
/*NLMISC::CVector CPositionOrEntityHelper::getDiffPos(const NLMISC::CVector& targetPos) const
|
||||
{
|
||||
return Position;
|
||||
}
|
||||
|
||||
NLMISC::CVector CPositionOrEntityHelper::setPositionFromDiffPos(const NLMISC::CVector& diffPos)
|
||||
{
|
||||
return Position;
|
||||
}*/
|
@ -0,0 +1,70 @@
|
||||
// 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_POSITIONORENTITYTYPEHELPER_H
|
||||
#define RY_POSITIONORENTITYTYPEHELPER_H
|
||||
|
||||
|
||||
#include "game_share/position_or_entity_type.h"
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/************************************************************************/
|
||||
/* Class that can contain either an entity id or a position */
|
||||
/************************************************************************/
|
||||
class CPositionOrEntityHelper: public CPositionOrEntity
|
||||
{
|
||||
public:
|
||||
|
||||
CPositionOrEntityHelper(): CPositionOrEntity()
|
||||
{
|
||||
}
|
||||
|
||||
CPositionOrEntityHelper(const NLMISC::CVector& position): CPositionOrEntity(position)
|
||||
{
|
||||
}
|
||||
|
||||
CPositionOrEntityHelper(const TDataSetIndex& eid): CPositionOrEntity(eid)
|
||||
{
|
||||
}
|
||||
|
||||
CPositionOrEntityHelper(PositionOrEntityType type): CPositionOrEntity(type)
|
||||
{
|
||||
}
|
||||
|
||||
CPositionOrEntityHelper(const CPositionOrEntity& c): CPositionOrEntity(c)
|
||||
{
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* Creates a PositionOrEntity instance from a string */
|
||||
/************************************************************************/
|
||||
static CPositionOrEntityHelper fromString(const std::string& s);
|
||||
|
||||
static const CPositionOrEntityHelper Invalid;
|
||||
|
||||
// Declares abstract methods
|
||||
/// This function returns the difference between the player's position and the specified position
|
||||
/*NLMISC::CVector getDiffPos(const NLMISC::CVector& targetPos) const;
|
||||
|
||||
/// This function returns the target position given the difference between the player's position and this target position
|
||||
NLMISC::CVector setPositionFromDiffPos(const NLMISC::CVector& diffPos);*/
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* RY_POSITIONORENTITYTYPEHELPER_H */
|
Loading…
Reference in New Issue