Changed: #1469 Only one magic step that parses the primitive and send optimized packets

--HG--
branch : gsoc2012-fabien
hg/feature/gsoc2012-fabien
Fabien_HENON 12 years ago
parent 2fd91e5277
commit 2e50568194

@ -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_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
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 */

@ -98,6 +98,11 @@ public:
return _isPosition == 0; return _isPosition == 0;
} }
bool isPreviousPos() const
{
return false;
}
NLMISC::CVector getPosition() const NLMISC::CVector getPosition() const
{ {
if (!isPosition()) if (!isPosition())
@ -117,7 +122,7 @@ public:
return isPosition() || isEntityId(); return isPosition() || isEntityId();
} }
void serial(NLMISC::IStream &f) void serial(NLMISC::CBitMemStream &f)
{ {
f.serial(_isPosition); f.serial(_isPosition);
if (isPosition()) if (isPosition())

@ -18,23 +18,34 @@
#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 "camera_animation_manager/position_or_entity_type_helper.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 /// Basic camera animation step that has generic values
/// - look_at_position class CCameraAnimationStep : public ICameraAnimationStep
/// - text
/// - duration
class CCameraAnimationStepBasic : public ICameraAnimationStep
{ {
protected: protected:
std::string LookAtPos; std::string LookAtTarget;
float DirectionTransitionTime;
std::string PositionTarget;
float PositionTransitionTime;
float DistanceTo;
bool HasTurnAround;
float TurnAroundSpeed;
std::string Text; std::string Text;
float Duration; float Duration;
public: public:
CCameraAnimationStepBasic() CCameraAnimationStep()
{ {
LookAtPos = ""; LookAtTarget = "";
DirectionTransitionTime = 0.f;
PositionTarget = "";
PositionTransitionTime = 0.f;
DistanceTo = 0.f;
HasTurnAround = false;
TurnAroundSpeed = 0.f;
Text = ""; Text = "";
Duration = 0.f; Duration = 0.f;
} }
@ -43,265 +54,99 @@ public:
{ {
std::string value; std::string value;
// We get the look at position // We get the look at target
if (!prim->getPropertyByName("look_at_position", value)) if (!prim->getPropertyByName("look_at_target", value))
{ {
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_target property of the basic step in primitive : %s", filename.c_str());
return false; return false;
} }
LookAtPos = value; LookAtTarget = value;
// We get the text // We get the direction_transition_time
if (!prim->getPropertyByName("text", value)) if (!prim->getPropertyByName("direction_transition_time", value))
{ {
nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the text property of the basic step in primitive : %s", filename.c_str()); nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the direction_transition_time property of the basic step in primitive : %s", filename.c_str());
return false; return false;
} }
Text = value; if (!NLMISC::fromString(value, DirectionTransitionTime))
// 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()); 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 false;
} }
return true; // We get the position_target
} if (!prim->getPropertyByName("position_target", value))
virtual void sendAnimationStep(NLMISC::CBitMemStream& bms)
{
TPositionOrEntity pos = CPositionOrEntityHelper::fromString(LookAtPos);
if (pos == CPositionOrEntityHelper::Invalid)
{ {
nlerror("<CCameraAnimationStepBasic parseStep> invalid lookatpos %s", LookAtPos.c_str()); nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the position_target property of the basic step in primitive : %s", filename.c_str());
}
bms.serial(const_cast<TPositionOrEntity&>(pos));
bms.serial(const_cast<std::string&>(Text));
bms.serial(const_cast<float&>(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("<CCameraAnimationStepStatic parseStep> impossible to parse the basic part of the step in primitive : %s", filename.c_str());
return false; 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");
///////////////////////////////////////////////////////////////////////////// // We get the position_transition_time
/// Go to camera animation step if (!prim->getPropertyByName("position_transition_time", value))
/// - end_position
class CCameraAnimationStepGoTo: public CCameraAnimationStepBasic
{
protected:
std::string EndPos;
public:
CCameraAnimationStepGoTo()
{ {
EndPos = ""; nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the position_transition_time property of the basic step in primitive : %s", filename.c_str());
}
virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename)
{
if (!CCameraAnimationStepBasic::parseStep(prim, filename))
{
nlwarning("<CCameraAnimationStepGoTo parseStep> impossible to parse the basic part of the step in primitive : %s", filename.c_str());
return false; return false;
} }
if (!NLMISC::fromString(value, PositionTransitionTime))
std::string value;
// We get the end position
if (!prim->getPropertyByName("end_position", value))
{ {
nlwarning("<CCameraAnimationStepGoTo parseStep> impossible to get the end_position property of the basic step in primitive : %s", filename.c_str()); 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 false;
} }
EndPos = value;
return true; // We get the distance_to
} if (!prim->getPropertyByName("distance_to", value))
virtual void sendAnimationStep(NLMISC::CBitMemStream& bms)
{
CCameraAnimationStepBasic::sendAnimationStep(bms);
TPositionOrEntity pos = CPositionOrEntityHelper::fromString(EndPos);
if (pos == CPositionOrEntityHelper::Invalid)
{
nlerror("<CCameraAnimationStepGoTo parseStep> invalid endpos %s", EndPos.c_str());
}
bms.serial(const_cast<TPositionOrEntity&>(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 = ""; nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the distance_to property of the basic step in primitive : %s", filename.c_str());
DistanceToEntity = 0.f;
}
virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename)
{
if (!CCameraAnimationStepBasic::parseStep(prim, filename))
{
nlwarning("<CCameraAnimationStepFollowEntity parseStep> impossible to parse the basic part of the step in primitive : %s", filename.c_str());
return false; return false;
} }
if (!NLMISC::fromString(value, DistanceTo))
std::string value;
// We get the entity to follow
if (!prim->getPropertyByName("entity_to_follow", value))
{ {
nlwarning("<CCameraAnimationStepFollowEntity parseStep> impossible to get the entity_to_follow property of the basic step in primitive : %s", filename.c_str()); 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 false;
} }
EntityToFollow = value;
// We get the distance to the entity // We get the has_turn_around
if (!prim->getPropertyByName("distance_to_entity", value)) if (!prim->getPropertyByName("has_turn_around", value))
{ {
nlwarning("<CCameraAnimationStepFollowEntity parseStep> impossible to get the distance_to_entity property of the basic step in primitive : %s", filename.c_str()); nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the has_turn_around property of the basic step in primitive : %s", filename.c_str());
return false; return false;
} }
if (!NLMISC::fromString(value, DistanceToEntity)) if (!NLMISC::fromString(value, HasTurnAround))
{ {
nlwarning("<CCameraAnimationStepFollowEntity parseStep> impossible to convert the string : %s, in float in the follow entity step in primitive : %s", value.c_str(), filename.c_str()); 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; return false;
} }
return true; // We get the turn_around_speed
} if (!prim->getPropertyByName("turn_around_speed", value))
virtual void sendAnimationStep(NLMISC::CBitMemStream& bms)
{ {
CCameraAnimationStepBasic::sendAnimationStep(bms); nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the turn_around_speed property of the basic step in primitive : %s", filename.c_str());
TPositionOrEntity pos = CPositionOrEntityHelper::fromString(EntityToFollow);
if (pos == CPositionOrEntityHelper::Invalid)
{
nlerror("<CCameraAnimationStepFollowEntity parseStep> invalid entitytofollow %s", EntityToFollow.c_str());
}
bms.serial(const_cast<TPositionOrEntity&>(pos));
bms.serial(const_cast<float&>(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))
{
nlwarning("<CCameraAnimationStepTurnAround parseStep> impossible to parse the basic part of the step in primitive : %s", filename.c_str());
return false; return false;
} }
if (!NLMISC::fromString(value, TurnAroundSpeed))
std::string value;
// We get the point to turn around
if (!prim->getPropertyByName("point_to_turn_around", value))
{ {
nlwarning("<CCameraAnimationStepTurnAround parseStep> impossible to get the point_to_turn_around property of the basic step in primitive : %s", filename.c_str()); 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 false;
} }
PointToTurnAround = value;
// We get the distance to the point // We get the text
if (!prim->getPropertyByName("distance_to_point", value)) if (!prim->getPropertyByName("text", value))
{
nlwarning("<CCameraAnimationStepTurnAround parseStep> 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))
{ {
nlwarning("<CCameraAnimationStepTurnAround parseStep> impossible to convert the string : %s, in float in the follow entity step in primitive : %s", value.c_str(), filename.c_str()); nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the text property of the basic step in primitive : %s", filename.c_str());
return false; return false;
} }
Text = value;
// We get the speed // We get the duration
if (!prim->getPropertyByName("speed", value)) if (!prim->getPropertyByName("duration", value))
{ {
nlwarning("<CCameraAnimationStepTurnAround parseStep> impossible to get the speed property of the basic step in primitive : %s", filename.c_str()); nlwarning("<CCameraAnimationStepBasic parseStep> impossible to get the duration property of the basic step in primitive : %s", filename.c_str());
return false; return false;
} }
if (!NLMISC::fromString(value, Speed)) if (!NLMISC::fromString(value, Duration))
{ {
nlwarning("<CCameraAnimationStepTurnAround parseStep> impossible to convert the string : %s, in float in the follow entity step in primitive : %s", value.c_str(), filename.c_str()); 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 false;
} }
@ -310,64 +155,36 @@ public:
virtual void sendAnimationStep(NLMISC::CBitMemStream& bms) virtual void sendAnimationStep(NLMISC::CBitMemStream& bms)
{ {
CCameraAnimationStepBasic::sendAnimationStep(bms); TPositionOrEntity posLookAtTarget = CPositionOrEntityHelper::fromString(LookAtTarget);
if (posLookAtTarget == CPositionOrEntityHelper::Invalid)
TPositionOrEntity pos = CPositionOrEntityHelper::fromString(PointToTurnAround);
if (pos == CPositionOrEntityHelper::Invalid)
{ {
nlerror("<CCameraAnimationStepTurnAround parseStep> invalidpointtoturnaround %s", PointToTurnAround.c_str()); nlerror("<CCameraAnimationStepBasic parseStep> invalid LookAtTarget %s", LookAtTarget.c_str());
} }
bms.serial(const_cast<TPositionOrEntity&>(pos)); bms.serial(const_cast<TPositionOrEntity&>(posLookAtTarget));
bms.serial(const_cast<float&>(DistanceToPoint)); if (!posLookAtTarget.isPreviousPos())
bms.serial(const_cast<float&>(Speed)); {
NLMISC::serialDuration(bms, DirectionTransitionTime);
nldebug("CameraAnimation - step %s . Value: Duration: %f", getStepName().c_str(), Duration);
} }
CAMERA_ANIMATION_STEP_NAME("camera_animation_turn_around"); TPositionOrEntity posPosTarget = CPositionOrEntityHelper::fromString(PositionTarget);
}; if (posPosTarget == CPositionOrEntityHelper::Invalid)
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; nlerror("<CCameraAnimationStepBasic parseStep> invalid PositionTarget %s", PositionTarget.c_str());
} }
virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename) bms.serial(const_cast<TPositionOrEntity&>(posPosTarget));
if (!posPosTarget.isPreviousPos())
{ {
std::string value; NLMISC::serialDistance(bms, DistanceTo);
NLMISC::serialDuration(bms, PositionTransitionTime);
bms.serialBit(const_cast<bool&>(HasTurnAround));
// We get the duration if (HasTurnAround)
if (!prim->getPropertyByName("duration", value))
{
nlwarning("<CCameraAnimationStepReturn 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("<CCameraAnimationStepReturn parseStep> impossible to convert the string : %s, in float in the basic step in primitive : %s", value.c_str(), filename.c_str()); NLMISC::serialSpeed(bms, TurnAroundSpeed);
return false;
} }
return true;
} }
virtual void sendAnimationStep(NLMISC::CBitMemStream& bms)
{
bms.serial(const_cast<float&>(Duration));
nldebug("CameraAnimation - step %s . Value: Duration: %f", getStepName().c_str(), Duration);
} }
virtual float getDuration() const virtual float getDuration() const
@ -375,6 +192,6 @@ public:
return Duration; return Duration;
} }
CAMERA_ANIMATION_STEP_NAME("camera_animation_return"); CAMERA_ANIMATION_STEP_NAME("camera_animation_step");
}; };
CAMERA_ANIMATION_REGISTER_STEP(CCameraAnimationStepReturn, "camera_animation_return"); CAMERA_ANIMATION_REGISTER_STEP(CCameraAnimationStep, "camera_animation_step");

Loading…
Cancel
Save