From 2f8696133a5e12afc367e25f9626bdb1a7090520 Mon Sep 17 00:00:00 2001 From: Fabien_HENON Date: Mon, 11 Jun 2012 23:28:05 +0200 Subject: [PATCH] Added: #1469 Base factory implementation for camera animation modifiers --HG-- branch : gsoc2012-fabien --- .../camera_animation_modifier_factory.cpp | 52 ++++++++++++ .../camera_animation_modifier_factory.h | 79 +++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifier_factory.cpp create mode 100644 code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifier_factory.h diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifier_factory.cpp b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifier_factory.cpp new file mode 100644 index 000000000..977380c14 --- /dev/null +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifier_factory.cpp @@ -0,0 +1,52 @@ +// 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_modifier_factory.h" + +std::vector >* ICameraAnimationModifierFactory::Entries; + +ICameraAnimationModifier* ICameraAnimationModifierFactory::parseModifier(const NLLIGO::IPrimitive* prim, const std::string& filename, const std::string& modifierType) +{ + // We search the correct modifier type in our entries + for (uint i = 0; i < Entries->size(); i++) + { + if (modifierType == (*Entries)[i].first) + { + ICameraAnimationModifier * ret = (*Entries)[i].second->instanciate(); + if (!ret) + { + nlerror("BUG IN CAMERA ANIMATION MODIFIER FACTORY : BAD INIT CODE"); + return NULL; + } + // We parse the modifier + if (!ret->parseModifier(prim, filename)) + { + nlerror("building camera animation modifier failed"); + delete ret; + return NULL; + } + return ret; + } + } + return NULL; +} + +void ICameraAnimationModifierFactory::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_modifier_factory.h b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifier_factory.h new file mode 100644 index 000000000..e08d1d416 --- /dev/null +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifier_factory.h @@ -0,0 +1,79 @@ +// 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_CAMERAANIMATIONMODIFIERFACTORY_H +#define RY_CAMERAANIMATIONMODIFIERFACTORY_H + +#include "nel/ligo/primitive.h" +#include + +/************************************************************************/ +/* Interface for camera animation modifiers. + * For simplicity, sounds triggers and considered like modifiers too. + * It has to be able to parse it's parameters from the primitive. + * And also to generate a small script to send to the client + */ +/************************************************************************/ +class ICameraAnimationModifier +{ +public: + /// This function is called when it's time to parse the primitive to load the camera animation modifier + virtual bool parseModifier(const NLLIGO::IPrimitive* prim, const std::string& filename) = 0; +}; + +/************************************************************************/ +/* Factory class that can instanciate the correct camera animation modifier handler. + * + * \author Fabien Henon + * \date 2012 + */ +/************************************************************************/ +class ICameraAnimationModifierFactory +{ +public: + /// Function that will instanciate the correct camera animation step + static ICameraAnimationModifier* parseModifier(const NLLIGO::IPrimitive* prim, const std::string& filename, const std::string& modifierType); +protected: + + /// Functions used to be able to create the camera animation modifiers + static void init(); + virtual ICameraAnimationModifier * instanciate() = 0; + static std::vector >* Entries; +}; + +// Define used to register the different types of camera animation modifiers +#define CAMERA_ANIMATION_REGISTR_MODIFIER(_class_,_name_) \ +class _class_##CameraAnimationModifierFactory : public ICameraAnimationModifierFactory \ +{\ +public:\ + _class_##CameraAnimationModifierFactory()\ +{\ + 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 ) );\ +}\ + ICameraAnimationModifier * instanciate()\ +{ \ + return new _class_;\ +} \ +};\ + static _class_##CameraAnimationModifierFactory* _class_##CameraAnimationModifierFactoryInstance = new _class_##CameraAnimationModifierFactory; + +#endif /* RY_CAMERAANIMATIONMODIFIERFACTORY_H */