From 072d2e03850f30f47ff6519315c574f47d39325b Mon Sep 17 00:00:00 2001 From: Fabien_HENON Date: Fri, 8 Jun 2012 00:08:16 +0200 Subject: [PATCH] Added: #1469 Factory for camera animation steps --HG-- branch : gsoc2012-fabien --- .../camera_animation_manager.cpp | 1 + .../camera_animation_manager.h | 8 +- .../camera_animation_step_factory.cpp | 51 ++++++++++++ .../camera_animation_step_factory.h | 78 +++++++++++++++++++ 4 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_step_factory.cpp create mode 100644 code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_step_factory.h diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_manager.cpp b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_manager.cpp index e4b62e2e8..9056d7b9b 100644 --- a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_manager.cpp +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_manager.cpp @@ -20,6 +20,7 @@ #include "camera_animation_manager/camera_animation_manager.h" #include "primitives_parser.h" #include "nel/ligo/primitive.h" +#include "camera_animation_manager/camera_animation_step_factory.h" using namespace std; using namespace NLMISC; diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_manager.h b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_manager.h index 05b472bd5..a63214c71 100644 --- a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_manager.h +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_manager.h @@ -41,15 +41,15 @@ public: static void release(); private: - // Constructor + /// Constructor CCameraAnimationManager(); - // Destructor + /// Destructor ~CCameraAnimationManager(); - // Function that parses the camera animations + /// Function that parses the camera animations bool parseCameraAnimations(const NLLIGO::IPrimitive* prim, const std::string& filename); - // Instance of the manager + /// Instance of the manager static CCameraAnimationManager* _Instance; }; diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_step_factory.cpp b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_step_factory.cpp new file mode 100644 index 000000000..c74cd92d6 --- /dev/null +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_step_factory.cpp @@ -0,0 +1,51 @@ +// 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_factory.h" + +std::vector >* ICameraAnimationStepFactory::Entries; + +ICameraAnimationStep* ICameraAnimationStepFactory::parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename, const std::string& name) +{ + // We search the correct step type in our entries + for (uint i = 0; i < Entries->size(); i++) + { + if (name == (*Entries)[i].first) + { + ICameraAnimationStep * ret = (*Entries)[i].second->instanciate(); + if (!ret) + { + nlerror("BUG IN CAMERA ANIMATION STEP FACTORY : BAD INIT CODE"); + return NULL; + } + if (!ret->parseStep(prim, filename)) + { + nlerror("building camera animation step failed"); + delete ret; + return NULL; + } + return ret; + } + } + return NULL; +} + +void ICameraAnimationStepFactory::init() +{ + if (!Entries) + Entries = new std::vector >; +} \ No newline at end of file diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_step_factory.h b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_step_factory.h new file mode 100644 index 000000000..e193c134f --- /dev/null +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_step_factory.h @@ -0,0 +1,78 @@ +// 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_CAMERAANIMATIONSTEPFACTORY_H +#define RY_CAMERAANIMATIONSTEPFACTORY_H + +#include "nel/ligo/primitive.h" +#include + +/************************************************************************/ +/* Interface for camera animation steps. + * It has to be able to parse the step from the primitive. + * And also to generate a small script to send to the client + */ +/************************************************************************/ +class ICameraAnimationStep +{ +public: + /// This function is called when it's time to parse the primitive to load the camera animation step + virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename) = 0; +}; + +/************************************************************************/ +/* Factory class that can instanciate the correct camera animation step handler. + * + * \author Fabien Henon + * \date 2012 + */ +/************************************************************************/ +class ICameraAnimationStepFactory +{ +public: + /// Function that will instanciate the correct camera animation step + static ICameraAnimationStep* parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename, const std::string& name); +protected: + + /// Functions used to be able to create the camera animation steps + static void init(); + virtual ICameraAnimationStep * instanciate() = 0; + static std::vector >* Entries; +}; + +// Define used to register the different types of camera animation steps +#define MISSION_REGISTER_ACTION(_class_,_name_) \ +class _class_##CameraAnimationStepFactory : public ICameraAnimationStepFactory \ +{\ +public:\ + _class_##CameraAnimationStepFactory()\ +{\ + 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 ) );\ +}\ + ICameraAnimationStep * instanciate()\ +{ \ + return new _class_;\ +} \ +};\ + static _class_##ActionFactory* _class_##ActionFactoryInstance = new _class_##ActionFactory; + +#endif /* RY_CAMERAANIMATIONSTEPFACTORY_H */