From 64b1ba3752e23870e63cd6a4652ae4919da80db5 Mon Sep 17 00:00:00 2001 From: Fabien_HENON Date: Wed, 25 Jul 2012 23:06:26 +0200 Subject: [PATCH] Added: #1469 factory for step player --HG-- branch : gsoc2012-fabien --- .../camera_animation_player.h | 4 +- .../camera_animation_step_player_factory.cpp | 54 ++++++++++++ .../camera_animation_step_player_factory.h | 84 +++++++++++++++++++ 3 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.cpp create mode 100644 code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.h diff --git a/code/ryzom/client/src/camera_animation_manager/camera_animation_player.h b/code/ryzom/client/src/camera_animation_manager/camera_animation_player.h index 622557bba..921c388f2 100644 --- a/code/ryzom/client/src/camera_animation_manager/camera_animation_player.h +++ b/code/ryzom/client/src/camera_animation_manager/camera_animation_player.h @@ -24,9 +24,7 @@ /************************************************************************/ /* Class that manages the camera animations. (singleton). - * It's responsible of : - * - Parsing camera animations in primitives - * - Sending a specified animation to the client + * It's responsible of playing camera animations * * \author Fabien Henon * \date 2012 diff --git a/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.cpp b/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.cpp new file mode 100644 index 000000000..720c40cef --- /dev/null +++ b/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.cpp @@ -0,0 +1,54 @@ +// 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 . +// + +#include "camera_animation_manager/camera_animation_step_player_factory.h" + +std::vector >* ICameraAnimationStepPlayerFactory::Entries; + +ICameraAnimationStepPlayer* ICameraAnimationStepPlayerFactory::initStep(const std::string& name, NLMISC::CBitMemStream& impulse) +{ + // We search the correct step type in our entries + for (uint i = 0; i < Entries->size(); i++) + { + if (name == (*Entries)[i].first) + { + ICameraAnimationStepPlayer* ret = (*Entries)[i].second->instanciate(); + if (!ret) + { + nlerror("BUG IN CAMERA ANIMATION STEP PLAYER FACTORY : BAD INIT CODE"); + return NULL; + } + // We init the step + if (!ret->initStep(impulse)) + { + nlerror("building camera animation step player failed"); + delete ret; + return NULL; + } + + return ret; + } + } + return NULL; +} + +void ICameraAnimationStepPlayerFactory::init() +{ + if (!Entries) + Entries = new std::vector >; +} + diff --git a/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.h b/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.h new file mode 100644 index 000000000..daaa936f8 --- /dev/null +++ b/code/ryzom/client/src/camera_animation_manager/camera_animation_step_player_factory.h @@ -0,0 +1,84 @@ +// 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_CAMERAANIMATIONSTEPPLAYERFACTORY_H +#define RY_CAMERAANIMATIONSTEPPLAYERFACTORY_H + +#include +#include +#include "nel\misc\bit_mem_stream.h" + +/************************************************************************/ +/* Interface for camera animation steps. + * It has to be able to parse the step from an impulse and to play it + */ +/************************************************************************/ +class ICameraAnimationStepPlayer +{ +public: + /// This function is called when it's time to init the step from an impulse + virtual bool initStep(NLMISC::CBitMemStream& impulse) = 0; + + /// Function that plays the step + virtual void playStep() = 0; + +protected: +}; + +/************************************************************************/ +/* Factory class that can instanciate the correct camera animation step player. + * + * \author Fabien Henon + * \date 2012 + */ +/************************************************************************/ +class ICameraAnimationStepPlayerFactory +{ +public: + /// Function that will instanciate the correct camera animation step player in function of the step name + static ICameraAnimationStepPlayer* initStep(const std::string& name, NLMISC::CBitMemStream& impulse); +protected: + + /// Functions used to be able to create the camera animation steps players + static void init(); + virtual ICameraAnimationStepPlayer* instanciate() = 0; + static std::vector >* Entries; +}; + +// Define used to register the different types of camera animation steps players +#define CAMERA_ANIMATION_REGISTER_STEP_PLAYER(_class_,_name_) \ +class _class_##CameraAnimationStepPlayerFactory : public ICameraAnimationStepPlayerFactory \ +{\ +public:\ + _class_##CameraAnimationStepPlayerFactory()\ +{\ + init();\ + std::string str = std::string(_name_); \ + for (uint i = 0; i < (*Entries).size(); i++ ) \ +{\ + if ( (*Entries)[i].first == str || (*Entries)[i].second == this )nlstop;\ +}\ + (*Entries).push_back( std::make_pair( str, this ) );\ +}\ + ICameraAnimationStepPlayer* instanciate()\ +{ \ + return new _class_;\ +} \ +};\ + static _class_##CameraAnimationStepPlayerFactory* _class_##CameraAnimationStepPlayerFactoryInstance = new _class_##CameraAnimationStepPlayerFactory; + + +#endif /* RY_CAMERAANIMATIONSTEPPLAYERFACTORY_H */