diff --git a/code/ryzom/common/src/game_share/position_or_entity_type.h b/code/ryzom/common/src/game_share/position_or_entity_type.h index 843c3fb0e..a0f910c06 100644 --- a/code/ryzom/common/src/game_share/position_or_entity_type.h +++ b/code/ryzom/common/src/game_share/position_or_entity_type.h @@ -26,7 +26,7 @@ /************************************************************************/ /* Class that can contain either an entity id or a position */ /************************************************************************/ -class TPositionOrEntity +class CPositionOrEntity { public: enum PositionOrEntityType @@ -38,29 +38,29 @@ public: EReturnPos }; - TPositionOrEntity() + CPositionOrEntity() { _type = EUnknown; } - TPositionOrEntity(const NLMISC::CVector& position) + CPositionOrEntity(const NLMISC::CVector& position) { _type = EPosition; Position = position; } - TPositionOrEntity(const TDataSetIndex& eid) + CPositionOrEntity(const TDataSetIndex& eid) { _type = EEntity; EntityId = eid; } - TPositionOrEntity(PositionOrEntityType type) + CPositionOrEntity(PositionOrEntityType type) { _type = type; } - TPositionOrEntity(const TPositionOrEntity& c) + CPositionOrEntity(const CPositionOrEntity& c) { _type = c._type; if (c.isPosition()) @@ -69,7 +69,7 @@ public: EntityId = c.getEntityId(); } - TPositionOrEntity& operator=(const TPositionOrEntity& c) + CPositionOrEntity& operator=(const CPositionOrEntity& c) { _type = c._type; if (c.isPosition()) @@ -80,7 +80,7 @@ public: return *this; } - bool operator==(const TPositionOrEntity& c) + bool operator==(const CPositionOrEntity& c) { if (_type != c._type) return false; @@ -140,15 +140,11 @@ public: return Position; } - NLMISC::CVector getDiffPos() const - { - return Position; // TODO => get the real position of the character - } + /// This function returns the difference between the player's position and the specified position + virtual NLMISC::CVector getDiffPos(const NLMISC::CVector& targetPos) const = 0; - NLMISC::CVector setPositionFromDiffPos(const NLMISC::CVector& diffPos) - { - // TODO => set the position from the character's position and the diffpos - } + /// 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 { @@ -185,7 +181,7 @@ public: } else { - NLMISC::CVector diffPos = getDiffPos(); + NLMISC::CVector diffPos = getDiffPos(getPosition()); NLMISC::serialPositionDifference(f, diffPos); } } @@ -193,7 +189,7 @@ public: f.serial(EntityId); } -private: +protected: PositionOrEntityType _type; NLMISC::CVector Position; TDataSetIndex EntityId; diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifiers.cpp b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifiers.cpp index 26862a4dd..da43be0a3 100644 --- a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifiers.cpp +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifiers.cpp @@ -110,13 +110,13 @@ public: virtual void sendCameraModifier(NLMISC::CBitMemStream& bms) { - TPositionOrEntity pos = CPositionOrEntityHelper::fromString(SoundPos); + CPositionOrEntityHelper pos = CPositionOrEntityHelper::fromString(SoundPos); if (pos == CPositionOrEntityHelper::Invalid) { nlerror(" invalid soundpos %s", SoundPos.c_str()); } - bms.serial(const_cast(pos)); + bms.serial(const_cast(pos)); bms.serial(const_cast(SoundId)); } diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_steps.cpp b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_steps.cpp index 4323c05b6..ab269ef84 100644 --- a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_steps.cpp +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_steps.cpp @@ -155,25 +155,25 @@ public: virtual void sendAnimationStep(NLMISC::CBitMemStream& bms) { - TPositionOrEntity posLookAtTarget = CPositionOrEntityHelper::fromString(LookAtTarget); + CPositionOrEntityHelper posLookAtTarget = CPositionOrEntityHelper::fromString(LookAtTarget); if (posLookAtTarget == CPositionOrEntityHelper::Invalid) { nlerror(" invalid LookAtTarget %s", LookAtTarget.c_str()); } - bms.serial(const_cast(posLookAtTarget)); + bms.serial(const_cast(posLookAtTarget)); if (!posLookAtTarget.isPreviousPos()) { NLMISC::serialDuration(bms, DirectionTransitionTime); } - TPositionOrEntity posPosTarget = CPositionOrEntityHelper::fromString(PositionTarget); + CPositionOrEntityHelper posPosTarget = CPositionOrEntityHelper::fromString(PositionTarget); if (posPosTarget == CPositionOrEntityHelper::Invalid) { nlerror(" invalid PositionTarget %s", PositionTarget.c_str()); } - bms.serial(const_cast(posPosTarget)); + bms.serial(const_cast(posPosTarget)); if (!posPosTarget.isPreviousPos()) { NLMISC::serialDistance(bms, DistanceTo); diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.cpp b/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.cpp index 2fe68b899..d7d7a5403 100644 --- a/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.cpp +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.cpp @@ -28,14 +28,14 @@ #define POS_OR_ENTITY_PREVIOUS_POS_VALUE "_PreviousPos_" #define POS_OR_ENTITY_RETURN_POS_VALUE "_ReturnPos_" -const TPositionOrEntity CPositionOrEntityHelper::Invalid = TPositionOrEntity(); +const CPositionOrEntityHelper CPositionOrEntityHelper::Invalid = CPositionOrEntityHelper(); -TPositionOrEntity CPositionOrEntityHelper::fromString(const std::string& s) +CPositionOrEntityHelper CPositionOrEntityHelper::fromString(const std::string& s) { // If the string is empty it's a previous pos if (s.empty()) { - return TPositionOrEntity(TPositionOrEntity::EPreviousPos); + return CPositionOrEntityHelper(CPositionOrEntity::EPreviousPos); } std::string str = s; @@ -44,11 +44,11 @@ TPositionOrEntity CPositionOrEntityHelper::fromString(const std::string& s) // We already check if it's a special position or entity object if (NLMISC::toLower(str) == POS_OR_ENTITY_PREVIOUS_POS_VALUE) { - return TPositionOrEntity(TPositionOrEntity::EPreviousPos); + return CPositionOrEntityHelper(CPositionOrEntity::EPreviousPos); } else if (NLMISC::toLower(str) == POS_OR_ENTITY_RETURN_POS_VALUE) { - return TPositionOrEntity(TPositionOrEntity::EReturnPos); + return CPositionOrEntityHelper(CPositionOrEntity::EReturnPos); } std::vector resS; @@ -61,23 +61,23 @@ TPositionOrEntity CPositionOrEntityHelper::fromString(const std::string& s) if (res.size() != 1) { nlerror("TPositionOrentityHelper : no alias for entity name %s", str.c_str()); - return TPositionOrEntity(); + return CPositionOrEntityHelper(); } TAIAlias alias = res[0]; if (alias == CAIAliasTranslator::Invalid) { nlerror("TPositionOrentityHelper : invalid alias for entity name %s", str.c_str()); - return TPositionOrEntity(); + return CPositionOrEntityHelper(); } NLMISC::CEntityId eid = CAIAliasTranslator::getInstance()->getEntityId(alias); if (eid == NLMISC::CEntityId::Unknown) { nlerror("TPositionOrentityHelper : invalid entity id from alias %d", alias); - return TPositionOrEntity(); + return CPositionOrEntityHelper(); } TDataSetIndex compressedId = TheDataset.getDataSetRow(eid).getCompressedIndex(); - return TPositionOrEntity(compressedId); + return CPositionOrEntityHelper(compressedId); } else { @@ -97,21 +97,31 @@ TPositionOrEntity CPositionOrEntityHelper::fromString(const std::string& s) if (!NLMISC::fromString(xStr, x)) { nlerror("TPositionOrentityHelper : invalid x component from string %s", xStr.c_str()); - return TPositionOrEntity(); + return CPositionOrEntityHelper(); } if (!NLMISC::fromString(yStr, y)) { nlerror("TPositionOrentityHelper : invalid y component from string %s", yStr.c_str()); - return TPositionOrEntity(); + return CPositionOrEntityHelper(); } if (!NLMISC::fromString(yStr, x)) { nlerror("TPositionOrentityHelper : invalid z component from string %s", zStr.c_str()); - return TPositionOrEntity(); + return CPositionOrEntityHelper(); } - return TPositionOrEntity(NLMISC::CVector(x, y, z)); + return CPositionOrEntityHelper(NLMISC::CVector(x, y, z)); } - return TPositionOrEntity(); + return CPositionOrEntityHelper(); +} + +NLMISC::CVector CPositionOrEntityHelper::getDiffPos(const NLMISC::CVector& targetPos) const +{ + return Position; +} + +NLMISC::CVector CPositionOrEntityHelper::setPositionFromDiffPos(const NLMISC::CVector& diffPos) +{ + return Position; } \ No newline at end of file diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.h b/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.h index fff02ad24..df0403a88 100644 --- a/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.h +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.h @@ -26,16 +26,43 @@ /************************************************************************/ /* Class that can contain either an entity id or a position */ /************************************************************************/ -class CPositionOrEntityHelper +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 TPositionOrEntity fromString(const std::string& s); + 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; - static const TPositionOrEntity Invalid; + /// 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); }; diff --git a/code/ryzom/server/src/entities_game_service/mission_manager/mission_action.cpp b/code/ryzom/server/src/entities_game_service/mission_manager/mission_action.cpp index 03100afe9..89157a1f3 100644 --- a/code/ryzom/server/src/entities_game_service/mission_manager/mission_action.cpp +++ b/code/ryzom/server/src/entities_game_service/mission_manager/mission_action.cpp @@ -5484,7 +5484,7 @@ class CMissionActionSoundTrigger : public IMissionAction instance->getEntities(entities); // We get the position or entity - TPositionOrEntity pos = CPositionOrEntityHelper::fromString(_SoundPosition); + CPositionOrEntityHelper pos = CPositionOrEntityHelper::fromString(_SoundPosition); if (pos == CPositionOrEntityHelper::Invalid) { nlerror(" invalid position or entity from %s", _SoundPosition.c_str());