2
// C++ Interface: EntityRecipe
7
// Author: Alexey Torkhov <atorkhov@gmail.com>, (C) 2008
9
// This program is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU General Public License as published by
11
// the Free Software Foundation; either version 2 of the License, or
12
// (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program; if not, write to the Free Software
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
23
#ifndef EMBEROGREENTITYRECIPE_H
24
#define EMBEROGREENTITYRECIPE_H
26
#include "components/ogre/EmberOgrePrerequisites.h"
27
#include "GUIAdapter.h"
28
#include "GUIAdapterBindings.h"
30
#include "framework/tinyxml/tinyxml.h"
31
#include <Atlas/Message/Element.h>
32
#include <sigc++/signal.h>
41
typedef std::map<std::string, GUIAdapter*> GUIAdaptersStore;
42
typedef std::map<std::string, GUIAdapterBindings*> BindingsStore;
45
* @brief Resource that stores entity recipes.
47
* This class is for storing and manipulating with entity recipe.
49
* @author Alexey Torkhov <atorkhov@gmail.com>
51
class EntityRecipe : public Ogre::Resource {
53
friend class XMLEntityRecipeSerializer;
59
EntityRecipe(Ogre::ResourceManager* creator, const Ogre::String& name, Ogre::ResourceHandle handle,
60
const Ogre::String& group, bool isManual = false, Ogre::ManualResourceLoader* loader = 0);
65
virtual ~EntityRecipe();
68
* Implemented from Ogre::Resource.
73
* Implemented from Ogre::Resource.
75
void unloadImpl(void);
78
* Implemented from Ogre::Resource.
80
size_t calculateSize(void) const;
83
* Returns entity type.
85
const std::string& getEntityType() const;
88
* Creates and returns GUI adapter. This used currently by entity recipes parser (XMLEntityRecipeSerializer) for populating entity recipes.
90
GUIAdapter* createGUIAdapter(const std::string& name, const std::string& type, const std::string& tooltip);
93
* Returns named GUI adapter.
95
GUIAdapter* getGUIAdapter(const std::string& name);
98
* Returns list of GUI adapters.
100
const GUIAdaptersStore& getGUIAdapters();
103
* Creates and returns GUI adapter bindings. This used currently by entity recipes parser (XMLEntityRecipeSerializer) for populating entity recipes.
105
GUIAdapterBindings* createGUIAdapterBindings(const std::string& name);
108
* Associate each binding with correspondent placeholders (entity spec nodes).
110
void associateBindings();
113
* @brief Composes an entity.
115
* Grabs current values from adapters, runs it through Lua function and composes resulting Atlas message.
116
* @param typeService The main eris type service, from which type info will be queried.
118
Atlas::Message::MapType createEntity(Eris::TypeService& typeService);
123
void setAuthor(const std::string& author);
128
const std::string& getAuthor() const;
133
void setDescription(const std::string& description);
138
const std::string& getDescription() const;
141
* Does some test checking.
146
* Emits when value of any of adapters is changed.
148
sigc::signal<void> EventValueChanged;
159
* Recipe description.
161
std::string mDescription;
164
* Stores semi-atlas entity spec.
166
TiXmlElement* mEntitySpec;
171
std::string mEntityType;
176
GUIAdaptersStore mGUIAdapters;
181
BindingsStore mBindings;
184
* String that contains Lua script.
189
* Helper iterator over TinyXml nodes for associateBindings()
191
class SpecIterator : public TiXmlVisitor
194
SpecIterator(EntityRecipe* recipe);
195
virtual bool Visit(const TiXmlText& elem);
197
EntityRecipe* mRecipe;
201
/** Specialisation of SharedPtr to allow SharedPtr to be assigned to EntityRecipePtr
202
@note Has to be a subclass since we need operator=.
203
We could templatise this instead of repeating per Resource subclass,
204
except to do so requires a form VC6 does not support i.e.
205
ResourceSubclassPtr<T> : public SharedPtr<T>
207
class EntityRecipePtr : public Ogre::SharedPtr<EntityRecipe>
210
EntityRecipePtr() : Ogre::SharedPtr<EntityRecipe>() {}
211
explicit EntityRecipePtr(EntityRecipe* rep) : Ogre::SharedPtr<EntityRecipe>(rep) {}
212
EntityRecipePtr(const EntityRecipePtr& r) : Ogre::SharedPtr<EntityRecipe>(r) {}
213
EntityRecipePtr(const Ogre::ResourcePtr& r) : Ogre::SharedPtr<EntityRecipe>()
215
// lock & copy other mutex pointer
216
OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
218
OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
219
OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
220
pRep = static_cast<EntityRecipe*>(r.getPointer());
221
pUseCount = r.useCountPointer();
229
/// Operator used to convert a ResourcePtr to a EntityRecipePtr
230
EntityRecipePtr& operator=(const Ogre::ResourcePtr& r)
232
if (pRep == static_cast<EntityRecipe*>(r.getPointer()))
235
// lock & copy other mutex pointer
236
OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
238
OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
239
OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
240
pRep = static_cast<EntityRecipe*>(r.getPointer());
241
pUseCount = r.useCountPointer();
249
// RHS must be a null pointer
250
assert(r.isNull() && "RHS must be null if it has no mutex!");