Added: #1469 class TPositionOrEntity and TPositionOrEntityHelper to contain either an entityId or a vector (DOES NOT COMPILE YET)

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

@ -3564,6 +3564,8 @@ void impulsePlaySoundTrigger(NLMISC::CBitMemStream& impulse)
impulse.serial(SoundId);
impulse.serial(SoundPosition);
SoundMngr->spawnSource(SoundId, SoundPosition);
}
void impulseCameraAnimationPlay(NLMISC::CBitMemStream& impulse)

@ -17,6 +17,99 @@
#ifndef RY_POSITIONORENTITYTYPE_H
#define RY_POSITIONORENTITYTYPE_H
typedef std::string TPositionOrEntity;
#include "nel/misc/entity_id.h"
#include "nel/misc/vector.h"
//////////////////////////////////////////////////////////////////////////
/************************************************************************/
/* Class that can contain either an entity id or a position */
/************************************************************************/
class TPositionOrEntity
{
public:
TPositionOrEntity()
{
_isPosition = -1;
}
TPositionOrEntity(const NLMISC::CVector& position)
{
_isPosition = 1;
Position = position;
}
TPositionOrEntity(const NLMISC::CEntityId& eid)
{
_isPosition = 0;
EntityId = eid;
}
TPositionOrEntity(const TPositionOrEntity& c)
{
_isPosition = c._isPosition;
if (c.isPosition())
Position = c.getPosition();
else
EntityId = c.getEntityId();
}
TPositionOrEntity& operator=(const TPositionOrEntity& c)
{
_isPosition = c._isPosition;
if (c.isPosition())
Position = c.getPosition();
else if (c.isEntityId())
EntityId = c.getEntityId();
return *this;
}
void setPosition(const NLMISC::CVector& position)
{
_isPosition = 1;
Position = position;
}
void setEntityId(const NLMISC::CEntityId& eid)
{
_isPosition = 0;
EntityId = eid;
}
bool isPosition() const
{
return _isPosition == 1;
}
bool isEntityId() const
{
return _isPosition == 0;
}
NLMISC::CVector getPosition() const
{
if (!isPosition())
return NLMISC::CVector();
return Position;
}
NLMISC::CEntityId getEntityId() const
{
if (!isEntityId())
return NLMISC::CEntityId();
return EntityId;
}
bool isValid() const
{
return isPosition() || isEntityId();
}
private:
char _isPosition;
NLMISC::CVector Position;
NLMISC::CEntityId EntityId;
};
#endif /* RY_POSITIONORENTITYTYPE_H */

@ -0,0 +1,108 @@
// 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 "pd_support_service\stat_character.h"
#include "mission_manager\ai_alias_translator.h"
#include "nel\misc\entity_id.h"
#include "game_share\position_or_entity_type.h"
#include "mission_manager\mission_parser.h"
#include "nel\misc\string_mapper.h"
//////////////////////////////////////////////////////////////////////////
/************************************************************************/
/* Class that can contain either an entity id or a position */
/************************************************************************/
class CPositionOrEntityHelper
{
public:
TPositionOrEntity 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();
}
};
#endif /* RY_POSITIONORENTITYTYPEHELPER_H */
Loading…
Cancel
Save