Added: #1469 use of class TPositionOrEntity in actions, steps, modifiers, etc... + added serial function for this class

--HG--
branch : gsoc2012-fabien
hg/feature/gsoc2012-fabien
Fabien_HENON 13 years ago
parent e0084d7f4b
commit f48f4d25aa

@ -88,6 +88,8 @@
// Std. // Std.
#include <vector> #include <vector>
#include "game_share/position_or_entity_type.h" #include "game_share/position_or_entity_type.h"
#include "nel/misc/vector.h"
#include "nel/misc/entity_id.h"
#define OLD_STRING_SYSTEM #define OLD_STRING_SYSTEM
@ -3565,7 +3567,22 @@ void impulsePlaySoundTrigger(NLMISC::CBitMemStream& impulse)
impulse.serial(SoundId); impulse.serial(SoundId);
impulse.serial(SoundPosition); impulse.serial(SoundPosition);
SoundMngr->spawnSource(SoundId, SoundPosition); if (!SoundPosition.isValid())
{
nlwarning("<impulsePlaySoundTrigger> invalid SoundPosition");
return;
}
if (SoundPosition.isPosition())
SoundMngr->spawnSource(SoundId, SoundPosition.getPosition());
else
{
NLMISC::CVector pos;
NLMISC::CEntityId eid = SoundPosition.getEntityId();
SoundMngr->spawnSource(SoundId, pos);
}
} }
void impulseCameraAnimationPlay(NLMISC::CBitMemStream& impulse) void impulseCameraAnimationPlay(NLMISC::CBitMemStream& impulse)

@ -19,6 +19,7 @@
#include "nel/misc/entity_id.h" #include "nel/misc/entity_id.h"
#include "nel/misc/vector.h" #include "nel/misc/vector.h"
#include "nel/misc/stream.h"
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/************************************************************************/ /************************************************************************/
@ -64,6 +65,17 @@ public:
return *this; return *this;
} }
bool operator==(const TPositionOrEntity& c)
{
if (_isPosition != c._isPosition)
return false;
if (isPosition())
return Position == c.getPosition();
else if (isEntityId())
return EntityId == c.getEntityId();
return true;
}
void setPosition(const NLMISC::CVector& position) void setPosition(const NLMISC::CVector& position)
{ {
_isPosition = 1; _isPosition = 1;
@ -105,6 +117,15 @@ public:
return isPosition() || isEntityId(); return isPosition() || isEntityId();
} }
void serial(NLMISC::IStream &f)
{
f.serial(_isPosition);
if (isPosition())
f.serial(Position);
else if (isEntityId())
f.serial(EntityId);
}
private: private:
char _isPosition; char _isPosition;
NLMISC::CVector Position; NLMISC::CVector Position;

@ -19,6 +19,7 @@
#include "game_share/position_or_entity_type.h" #include "game_share/position_or_entity_type.h"
#include "nel/misc/sheet_id.h" #include "nel/misc/sheet_id.h"
#include "position_or_entity_type_helper.h"
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
/// This animation modifier shakes the camera. The parameter is /// This animation modifier shakes the camera. The parameter is
@ -75,7 +76,7 @@ protected:
public: public:
CCameraAnimationModifierSoundTrigger() CCameraAnimationModifierSoundTrigger()
{ {
SoundPos = ""; SoundPos = CPositionOrEntityHelper::Invalid;
SoundId = NLMISC::CSheetId::Unknown; SoundId = NLMISC::CSheetId::Unknown;
} }
@ -101,7 +102,12 @@ public:
nlwarning("<CCameraAnimationModifierSoundTrigger parseModifier> impossible to get the sound_position property of the basic modifier in primitive : %s", filename.c_str()); nlwarning("<CCameraAnimationModifierSoundTrigger parseModifier> impossible to get the sound_position property of the basic modifier in primitive : %s", filename.c_str());
return false; return false;
} }
SoundPos = value; SoundPos = CPositionOrEntityHelper::fromString(value);
if (SoundPos == CPositionOrEntityHelper::Invalid)
{
nlwarning("<CCameraAnimationModifierSoundTrigger parseModifier> invalid soundpos in primitive : %s", filename.c_str());
return false;
}
return true; return true;
} }

@ -17,6 +17,7 @@
#include "camera_animation_manager/camera_animation_step_factory.h" #include "camera_animation_manager/camera_animation_step_factory.h"
#include "game_share/position_or_entity_type.h" #include "game_share/position_or_entity_type.h"
#include "position_or_entity_type_helper.h"
/// Basic camera animation step that has generic values /// Basic camera animation step that has generic values
@ -33,7 +34,7 @@ protected:
public: public:
CCameraAnimationStepBasic() CCameraAnimationStepBasic()
{ {
LookAtPos = ""; LookAtPos = CPositionOrEntityHelper::Invalid;
Text = ""; Text = "";
Duration = 0.f; Duration = 0.f;
} }
@ -48,7 +49,12 @@ public:
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the look_at_position property of the basic step in primitive : %s", filename.c_str()); nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the look_at_position property of the basic step in primitive : %s", filename.c_str());
return false; return false;
} }
LookAtPos = value; LookAtPos = CPositionOrEntityHelper::fromString(value);
if (LookAtPos == CPositionOrEntityHelper::Invalid)
{
nlwarning("<CCameraAnimationStepBasic parseStep> invalid lookatpos in primitive : %s", filename.c_str());
return false;
}
// We get the text // We get the text
if (!prim->getPropertyByName("text", value)) if (!prim->getPropertyByName("text", value))
@ -121,7 +127,7 @@ protected:
public: public:
CCameraAnimationStepGoTo() CCameraAnimationStepGoTo()
{ {
EndPos = ""; EndPos = CPositionOrEntityHelper::Invalid;
} }
virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename) virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename)
@ -140,7 +146,12 @@ public:
nlwarning("<CCameraAnimationStepGoTo parseStep> impossible to get the end_position property of the basic step in primitive : %s", filename.c_str()); nlwarning("<CCameraAnimationStepGoTo parseStep> impossible to get the end_position property of the basic step in primitive : %s", filename.c_str());
return false; return false;
} }
EndPos = value; EndPos = CPositionOrEntityHelper::fromString(value);
if (EndPos == CPositionOrEntityHelper::Invalid)
{
nlwarning("<CCameraAnimationStepGoTo parseStep> invalid endpos in primitive : %s", filename.c_str());
return false;
}
return true; return true;
} }
@ -169,7 +180,7 @@ protected:
public: public:
CCameraAnimationStepFollowEntity() CCameraAnimationStepFollowEntity()
{ {
EntityToFollow = ""; EntityToFollow = CPositionOrEntityHelper::Invalid;
DistanceToEntity = 0.f; DistanceToEntity = 0.f;
} }
@ -189,7 +200,12 @@ public:
nlwarning("<CCameraAnimationStepFollowEntity parseStep> impossible to get the entity_to_follow property of the basic step in primitive : %s", filename.c_str()); nlwarning("<CCameraAnimationStepFollowEntity parseStep> impossible to get the entity_to_follow property of the basic step in primitive : %s", filename.c_str());
return false; return false;
} }
EntityToFollow = value; EntityToFollow = CPositionOrEntityHelper::fromString(value);
if (EntityToFollow == CPositionOrEntityHelper::Invalid)
{
nlwarning("<CCameraAnimationStepFollowEntity parseStep> invalid entitytofollow in primitive : %s", filename.c_str());
return false;
}
// We get the distance to the entity // We get the distance to the entity
if (!prim->getPropertyByName("distance_to_entity", value)) if (!prim->getPropertyByName("distance_to_entity", value))
@ -233,7 +249,7 @@ protected:
public: public:
CCameraAnimationStepTurnAround() CCameraAnimationStepTurnAround()
{ {
PointToTurnAround = ""; PointToTurnAround = CPositionOrEntityHelper::Invalid;
DistanceToPoint = 0.f; DistanceToPoint = 0.f;
Speed = 0.f; Speed = 0.f;
} }
@ -254,7 +270,12 @@ public:
nlwarning("<CCameraAnimationStepTurnAround parseStep> impossible to get the point_to_turn_around property of the basic step in primitive : %s", filename.c_str()); nlwarning("<CCameraAnimationStepTurnAround parseStep> impossible to get the point_to_turn_around property of the basic step in primitive : %s", filename.c_str());
return false; return false;
} }
PointToTurnAround = value; PointToTurnAround = CPositionOrEntityHelper::fromString(value);
if (PointToTurnAround == CPositionOrEntityHelper::Invalid)
{
nlwarning("<CCameraAnimationStepTurnAround parseStep> invalidpointtoturnaround in primitive : %s", filename.c_str());
return false;
}
// We get the distance to the point // We get the distance to the point
if (!prim->getPropertyByName("distance_to_point", value)) if (!prim->getPropertyByName("distance_to_point", value))

@ -0,0 +1,89 @@
// 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"
const TPositionOrEntity CPositionOrEntityHelper::Invalid = TPositionOrEntity();
TPositionOrEntity CPositionOrEntityHelper::fromString(const std::string& s)
{
std::string str = s;
CMissionParser::removeBlanks(str);
std::vector<std::string> res;
NLMISC::splitString(str, ";", res);
// If we don't have 3 components, it's an entityid
if (res.size() != 3)
{
std::vector<TAIAlias> res;
CAIAliasTranslator::getInstance()->getNPCAliasesFromName(str, res);
if (res.size() != 1)
{
nlerror("TPositionOrentityHelper : no alias for entity name %s", str);
return TPositionOrEntity();
}
TAIAlias alias = res[0];
if (alias == CAIAliasTranslator::Invalid)
{
nlerror("TPositionOrentityHelper : invalid alias for entity name %s", str);
return TPositionOrEntity();
}
NLMISC::CEntityId eid = CAIAliasTranslator::getInstance()->getEntityId(alias);
if (eid == NLMISC::CEntityId::Unknown)
{
nlerror("TPositionOrentityHelper : invalid entity id from alias %d", alias);
return TPositionOrEntity();
}
return TPositionOrEntity(eid);
}
else
{
// It's a position
std::string xStr = res[0];
std::string yStr = res[1];
std::string zStr = res[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);
return TPositionOrEntity();
}
if (!NLMISC::fromString(yStr, y))
{
nlerror("TPositionOrentityHelper : invalid y component from string %s", yStr);
return TPositionOrEntity();
}
if (!NLMISC::fromString(yStr, x))
{
nlerror("TPositionOrentityHelper : invalid z component from string %s", zStr);
return TPositionOrEntity();
}
return TPositionOrEntity(NLMISC::CVector(x, y, z));
}
return TPositionOrEntity();
}

@ -33,74 +33,12 @@ class CPositionOrEntityHelper
{ {
public: public:
TPositionOrEntity fromString(const std::string& s) /************************************************************************/
{ /* Creates a PositionOrEntity instance from a string */
std::string str = s; /************************************************************************/
CMissionParser::removeBlanks(str); static TPositionOrEntity fromString(const std::string& s);
std::vector<std::string> res; static const TPositionOrEntity Invalid;
NLMISC::splitString(str, ";", res);
// If we don't have 3 components, it's an entityid
if (res.size() != 3)
{
std::vector<TAIAlias> res;
CAIAliasTranslator::getInstance()->getNPCAliasesFromName(str, res);
if (res.size() != 1)
{
nlerror("TPositionOrentityHelper : no alias for entity name %s", str);
return TPositionOrEntity();
}
TAIAlias alias = res[0];
if (alias == CAIAliasTranslator::Invalid)
{
nlerror("TPositionOrentityHelper : invalid alias for entity name %s", str);
return TPositionOrEntity();
}
NLMISC::CEntityId eid = CAIAliasTranslator::getInstance()->getEntityId(alias);
if (eid == NLMISC::CEntityId::Unknown)
{
nlerror("TPositionOrentityHelper : invalid entity id from alias %d", alias);
return TPositionOrEntity();
}
return TPositionOrEntity(eid);
}
else
{
// It's a position
std::string xStr = res[0];
std::string yStr = res[1];
std::string zStr = res[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);
return TPositionOrEntity();
}
if (!NLMISC::fromString(yStr, y))
{
nlerror("TPositionOrentityHelper : invalid y component from string %s", yStr);
return TPositionOrEntity();
}
if (!NLMISC::fromString(yStr, x))
{
nlerror("TPositionOrentityHelper : invalid z component from string %s", zStr);
return TPositionOrEntity();
}
return TPositionOrEntity(NLMISC::CVector(x, y, z));
}
return TPositionOrEntity();
}
}; };

@ -58,6 +58,7 @@
#include "server_share/log_character_gen.h" #include "server_share/log_character_gen.h"
#include "camera_animation_manager/camera_animation_manager.h" #include "camera_animation_manager/camera_animation_manager.h"
#include "game_share/position_or_entity_type.h" #include "game_share/position_or_entity_type.h"
#include "camera_animation_manager/position_or_entity_type_helper.h"
using namespace std; using namespace std;
@ -5458,9 +5459,9 @@ class CMissionActionSoundTrigger : public IMissionAction
std::string SoundName = script[1]; std::string SoundName = script[1];
if (script.size() >= 3) if (script.size() >= 3)
_SoundPosition = script[2]; _SoundPosition = CPositionOrEntityHelper::fromString(script[2]);
else else
_SoundPosition = ""; _SoundPosition = CPositionOrEntityHelper::Invalid;
_SoundId = NLMISC::CSheetId(SoundName); _SoundId = NLMISC::CSheetId(SoundName);
if (_SoundId == NLMISC::CSheetId::Unknown) if (_SoundId == NLMISC::CSheetId::Unknown)

Loading…
Cancel
Save