diff --git a/code/ryzom/common/src/game_share/camera_anim_type_parser.h b/code/ryzom/common/src/game_share/camera_anim_type_parser.h new file mode 100644 index 000000000..a30b32e46 --- /dev/null +++ b/code/ryzom/common/src/game_share/camera_anim_type_parser.h @@ -0,0 +1,104 @@ +// Ryzom - MMORPG Framework +// 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 . + +#ifndef RY_CAMERAANIMTYPEPARSER_H +#define RY_CAMERAANIMTYPEPARSER_H + +#include "nel/misc/vector.h" +#include "nel/misc/stream.h" +#include + +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 +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 +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 +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); + } +} + +} + +#endif /* RY_CAMERAANIMTYPEPARSER_H */ 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 0772662e3..dddd7a7a6 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 @@ -98,6 +98,11 @@ public: return _isPosition == 0; } + bool isPreviousPos() const + { + return false; + } + NLMISC::CVector getPosition() const { if (!isPosition()) @@ -117,7 +122,7 @@ public: return isPosition() || isEntityId(); } - void serial(NLMISC::IStream &f) + void serial(NLMISC::CBitMemStream &f) { f.serial(_isPosition); if (isPosition()) 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 a44d3c383..4323c05b6 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 @@ -18,23 +18,34 @@ #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 -/// - look_at_position -/// - text -/// - duration -class CCameraAnimationStepBasic : public ICameraAnimationStep +class CCameraAnimationStep : public ICameraAnimationStep { protected: - std::string LookAtPos; + std::string LookAtTarget; + float DirectionTransitionTime; + std::string PositionTarget; + float PositionTransitionTime; + float DistanceTo; + bool HasTurnAround; + float TurnAroundSpeed; + std::string Text; float Duration; public: - CCameraAnimationStepBasic() - { - LookAtPos = ""; + CCameraAnimationStep() + { + LookAtTarget = ""; + DirectionTransitionTime = 0.f; + PositionTarget = ""; + PositionTransitionTime = 0.f; + DistanceTo = 0.f; + HasTurnAround = false; + TurnAroundSpeed = 0.f; Text = ""; Duration = 0.f; } @@ -43,265 +54,99 @@ public: { std::string value; - // We get the look at position - if (!prim->getPropertyByName("look_at_position", value)) - { - nlwarning(" impossible to get the look_at_position property of the basic step in primitive : %s", filename.c_str()); - return false; - } - LookAtPos = value; - - // We get the text - if (!prim->getPropertyByName("text", value)) + // We get the look at target + if (!prim->getPropertyByName("look_at_target", value)) { - nlwarning(" impossible to get the text property of the basic step in primitive : %s", filename.c_str()); + nlwarning(" impossible to get the look_at_target property of the basic step in primitive : %s", filename.c_str()); return false; } - Text = value; + LookAtTarget = value; - // We get the duration - if (!prim->getPropertyByName("duration", value)) + // We get the direction_transition_time + if (!prim->getPropertyByName("direction_transition_time", value)) { - nlwarning(" impossible to get the duration property of the basic step in primitive : %s", filename.c_str()); + nlwarning(" impossible to get the direction_transition_time property of the basic step in primitive : %s", filename.c_str()); return false; } - if (!NLMISC::fromString(value, Duration)) + if (!NLMISC::fromString(value, DirectionTransitionTime)) { nlwarning(" 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) - { - TPositionOrEntity pos = CPositionOrEntityHelper::fromString(LookAtPos); - if (pos == CPositionOrEntityHelper::Invalid) + // We get the position_target + if (!prim->getPropertyByName("position_target", value)) { - nlerror(" invalid lookatpos %s", LookAtPos.c_str()); - } - - bms.serial(const_cast(pos)); - bms.serial(const_cast(Text)); - bms.serial(const_cast(Duration)); - } - - virtual float getDuration() const - { - return Duration; - } -}; // This class must not be registered because it's a base class - -///////////////////////////////////////////////////////////////////////////// -/// Static camera animation step (that does not have specific variables) -class CCameraAnimationStepStatic : public CCameraAnimationStepBasic -{ -public: - virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename) - { - if (!CCameraAnimationStepBasic::parseStep(prim, filename)) - { - nlwarning(" impossible to parse the basic part of the step in primitive : %s", filename.c_str()); + nlwarning(" impossible to get the position_target property of the basic step in primitive : %s", filename.c_str()); return false; } - return true; - } + PositionTarget = value; - virtual void sendAnimationStep(NLMISC::CBitMemStream& bms) - { - CCameraAnimationStepBasic::sendAnimationStep(bms); - - nldebug("CameraAnimation - step %s . Value: Duration: %f", getStepName().c_str(), Duration); - } - - CAMERA_ANIMATION_STEP_NAME("camera_animation_static"); -}; -CAMERA_ANIMATION_REGISTER_STEP(CCameraAnimationStepStatic, "camera_animation_static"); - -///////////////////////////////////////////////////////////////////////////// -/// Go to camera animation step -/// - end_position -class CCameraAnimationStepGoTo: public CCameraAnimationStepBasic -{ -protected: - std::string EndPos; - -public: - CCameraAnimationStepGoTo() - { - EndPos = ""; - } - - virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename) - { - if (!CCameraAnimationStepBasic::parseStep(prim, filename)) + // We get the position_transition_time + if (!prim->getPropertyByName("position_transition_time", value)) { - nlwarning(" impossible to parse the basic part of the step in primitive : %s", filename.c_str()); + nlwarning(" impossible to get the position_transition_time property of the basic step in primitive : %s", filename.c_str()); return false; } - - std::string value; - - // We get the end position - if (!prim->getPropertyByName("end_position", value)) + if (!NLMISC::fromString(value, PositionTransitionTime)) { - nlwarning(" impossible to get the end_position property of the basic step in primitive : %s", filename.c_str()); + nlwarning(" impossible to convert the string : %s, in float in the basic step in primitive : %s", value.c_str(), filename.c_str()); return false; } - EndPos = value; - - return true; - } - virtual void sendAnimationStep(NLMISC::CBitMemStream& bms) - { - CCameraAnimationStepBasic::sendAnimationStep(bms); - - TPositionOrEntity pos = CPositionOrEntityHelper::fromString(EndPos); - if (pos == CPositionOrEntityHelper::Invalid) + // We get the distance_to + if (!prim->getPropertyByName("distance_to", value)) { - nlerror(" invalid endpos %s", EndPos.c_str()); - } - - bms.serial(const_cast(pos)); - - nldebug("CameraAnimation - step %s . Value: Duration: %f", getStepName().c_str(), Duration); - } - - CAMERA_ANIMATION_STEP_NAME("camera_animation_go_to"); -}; -CAMERA_ANIMATION_REGISTER_STEP(CCameraAnimationStepGoTo, "camera_animation_go_to"); - -///////////////////////////////////////////////////////////////////////////// -/// Follow entity camera animation step -/// - entity_to_follow -/// - distance_to_entity -class CCameraAnimationStepFollowEntity: public CCameraAnimationStepBasic -{ -protected: - std::string EntityToFollow; - float DistanceToEntity; - -public: - CCameraAnimationStepFollowEntity() - { - EntityToFollow = ""; - DistanceToEntity = 0.f; - } - - virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename) - { - if (!CCameraAnimationStepBasic::parseStep(prim, filename)) - { - nlwarning(" impossible to parse the basic part of the step in primitive : %s", filename.c_str()); + nlwarning(" impossible to get the distance_to property of the basic step in primitive : %s", filename.c_str()); return false; } - - std::string value; - - // We get the entity to follow - if (!prim->getPropertyByName("entity_to_follow", value)) + if (!NLMISC::fromString(value, DistanceTo)) { - nlwarning(" impossible to get the entity_to_follow property of the basic step in primitive : %s", filename.c_str()); + nlwarning(" impossible to convert the string : %s, in float in the basic step in primitive : %s", value.c_str(), filename.c_str()); return false; } - EntityToFollow = value; - // We get the distance to the entity - if (!prim->getPropertyByName("distance_to_entity", value)) + // We get the has_turn_around + if (!prim->getPropertyByName("has_turn_around", value)) { - nlwarning(" impossible to get the distance_to_entity property of the basic step in primitive : %s", filename.c_str()); + nlwarning(" impossible to get the has_turn_around property of the basic step in primitive : %s", filename.c_str()); return false; } - if (!NLMISC::fromString(value, DistanceToEntity)) + if (!NLMISC::fromString(value, HasTurnAround)) { - nlwarning(" impossible to convert the string : %s, in float in the follow entity step in primitive : %s", value.c_str(), filename.c_str()); + nlwarning(" impossible to convert the string : %s, in bool in the basic step in primitive : %s", value.c_str(), filename.c_str()); return false; } - return true; - } - - virtual void sendAnimationStep(NLMISC::CBitMemStream& bms) - { - CCameraAnimationStepBasic::sendAnimationStep(bms); - - TPositionOrEntity pos = CPositionOrEntityHelper::fromString(EntityToFollow); - if (pos == CPositionOrEntityHelper::Invalid) - { - nlerror(" invalid entitytofollow %s", EntityToFollow.c_str()); - } - - bms.serial(const_cast(pos)); - bms.serial(const_cast(DistanceToEntity)); - - nldebug("CameraAnimation - step %s . Value: Duration: %f", getStepName().c_str(), Duration); - } - - CAMERA_ANIMATION_STEP_NAME("camera_animation_follow_entity"); -}; -CAMERA_ANIMATION_REGISTER_STEP(CCameraAnimationStepFollowEntity, "camera_animation_follow_entity"); - -///////////////////////////////////////////////////////////////////////////// -/// Turn around camera animation step -/// - point_to_turn_around -/// - distance_to_point -/// - speed -class CCameraAnimationStepTurnAround: public CCameraAnimationStepBasic -{ -protected: - std::string PointToTurnAround; - float DistanceToPoint; - float Speed; - -public: - CCameraAnimationStepTurnAround() - { - PointToTurnAround = ""; - DistanceToPoint = 0.f; - Speed = 0.f; - } - - virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename) - { - if (!CCameraAnimationStepBasic::parseStep(prim, filename)) + // We get the turn_around_speed + if (!prim->getPropertyByName("turn_around_speed", value)) { - nlwarning(" impossible to parse the basic part of the step in primitive : %s", filename.c_str()); + nlwarning(" impossible to get the turn_around_speed property of the basic step in primitive : %s", filename.c_str()); return false; } - - std::string value; - - // We get the point to turn around - if (!prim->getPropertyByName("point_to_turn_around", value)) + if (!NLMISC::fromString(value, TurnAroundSpeed)) { - nlwarning(" impossible to get the point_to_turn_around property of the basic step in primitive : %s", filename.c_str()); + nlwarning(" impossible to convert the string : %s, in float in the basic step in primitive : %s", value.c_str(), filename.c_str()); return false; } - PointToTurnAround = value; - // We get the distance to the point - if (!prim->getPropertyByName("distance_to_point", value)) - { - nlwarning(" impossible to get the distance_to_point property of the basic step in primitive : %s", filename.c_str()); - return false; - } - if (!NLMISC::fromString(value, DistanceToPoint)) + // We get the text + if (!prim->getPropertyByName("text", value)) { - nlwarning(" impossible to convert the string : %s, in float in the follow entity step in primitive : %s", value.c_str(), filename.c_str()); + nlwarning(" impossible to get the text property of the basic step in primitive : %s", filename.c_str()); return false; } + Text = value; - // We get the speed - if (!prim->getPropertyByName("speed", value)) + // We get the duration + if (!prim->getPropertyByName("duration", value)) { - nlwarning(" impossible to get the speed property of the basic step in primitive : %s", filename.c_str()); + nlwarning(" impossible to get the duration property of the basic step in primitive : %s", filename.c_str()); return false; } - if (!NLMISC::fromString(value, Speed)) + if (!NLMISC::fromString(value, Duration)) { - nlwarning(" impossible to convert the string : %s, in float in the follow entity step in primitive : %s", value.c_str(), filename.c_str()); + nlwarning(" impossible to convert the string : %s, in float in the basic step in primitive : %s", value.c_str(), filename.c_str()); return false; } @@ -310,64 +155,36 @@ public: virtual void sendAnimationStep(NLMISC::CBitMemStream& bms) { - CCameraAnimationStepBasic::sendAnimationStep(bms); - - TPositionOrEntity pos = CPositionOrEntityHelper::fromString(PointToTurnAround); - if (pos == CPositionOrEntityHelper::Invalid) + TPositionOrEntity posLookAtTarget = CPositionOrEntityHelper::fromString(LookAtTarget); + if (posLookAtTarget == CPositionOrEntityHelper::Invalid) { - nlerror(" invalidpointtoturnaround %s", PointToTurnAround.c_str()); + nlerror(" invalid LookAtTarget %s", LookAtTarget.c_str()); } - bms.serial(const_cast(pos)); - bms.serial(const_cast(DistanceToPoint)); - bms.serial(const_cast(Speed)); - - nldebug("CameraAnimation - step %s . Value: Duration: %f", getStepName().c_str(), Duration); - } - - CAMERA_ANIMATION_STEP_NAME("camera_animation_turn_around"); -}; -CAMERA_ANIMATION_REGISTER_STEP(CCameraAnimationStepTurnAround, "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 CCameraAnimationStepReturn : public ICameraAnimationStep -{ -protected: - float Duration; - -public: - CCameraAnimationStepReturn() - { - Duration = 0.f; - } - - virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename) - { - std::string value; - - // We get the duration - if (!prim->getPropertyByName("duration", value)) + bms.serial(const_cast(posLookAtTarget)); + if (!posLookAtTarget.isPreviousPos()) { - nlwarning(" impossible to get the duration property of the basic step in primitive : %s", filename.c_str()); - return false; + NLMISC::serialDuration(bms, DirectionTransitionTime); } - if (!NLMISC::fromString(value, Duration)) + + TPositionOrEntity posPosTarget = CPositionOrEntityHelper::fromString(PositionTarget); + if (posPosTarget == CPositionOrEntityHelper::Invalid) { - nlwarning(" impossible to convert the string : %s, in float in the basic step in primitive : %s", value.c_str(), filename.c_str()); - return false; + nlerror(" invalid PositionTarget %s", PositionTarget.c_str()); } - return true; - } - - virtual void sendAnimationStep(NLMISC::CBitMemStream& bms) - { - bms.serial(const_cast(Duration)); + bms.serial(const_cast(posPosTarget)); + if (!posPosTarget.isPreviousPos()) + { + NLMISC::serialDistance(bms, DistanceTo); + NLMISC::serialDuration(bms, PositionTransitionTime); + bms.serialBit(const_cast(HasTurnAround)); - nldebug("CameraAnimation - step %s . Value: Duration: %f", getStepName().c_str(), Duration); + if (HasTurnAround) + { + NLMISC::serialSpeed(bms, TurnAroundSpeed); + } + } } virtual float getDuration() const @@ -375,6 +192,6 @@ public: return Duration; } - CAMERA_ANIMATION_STEP_NAME("camera_animation_return"); + CAMERA_ANIMATION_STEP_NAME("camera_animation_step"); }; -CAMERA_ANIMATION_REGISTER_STEP(CCameraAnimationStepReturn, "camera_animation_return"); \ No newline at end of file +CAMERA_ANIMATION_REGISTER_STEP(CCameraAnimationStep, "camera_animation_step");