Caelum
CaelumScriptTranslator.h
1 /*
2 This file is part of Caelum.
3 See http://www.ogre3d.org/wiki/index.php/Caelum
4 
5 Copyright (c) 2008 Caelum team. See Contributors.txt for details.
6 
7 Caelum is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Caelum is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License
18 along with Caelum. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef CAELUM__CAELUM_SCRIPT_TRANSLATOR_H
22 #define CAELUM__CAELUM_SCRIPT_TRANSLATOR_H
23 
24 #if CAELUM_SCRIPT_SUPPORT
25 
26 #include "CaelumPrerequisites.h"
27 #include "OgreScriptTranslator.h"
28 #include "TypeDescriptor.h"
29 
30 namespace Caelum
31 {
48  class CAELUM_EXPORT PropScriptResource: public Ogre::Resource {
49  protected:
50  virtual void loadImpl () { }
51  virtual void unloadImpl () { }
52  virtual size_t calculateSize () const { return 0; }
53 
54  public:
55  PropScriptResource (
56  Ogre::ResourceManager* creator, const Ogre::String& name, Ogre::ResourceHandle handle,
57  const Ogre::String& group, bool isManual, Ogre::ManualResourceLoader* loader);
58  ~PropScriptResource();
59  };
60 
63  class CAELUM_EXPORT PropScriptResourceManager: public Ogre::ResourceManager
64  {
65  public:
66  PropScriptResourceManager();
67 
68  virtual PropScriptResource* createImpl(
69  const String& name, Ogre::ResourceHandle handle, const String& group,
70  bool isManual, Ogre::ManualResourceLoader* loader, const Ogre::NameValuePairList* createParams);
71  };
72 
88  class CAELUM_EXPORT TypeDescriptorScriptTranslator: public Ogre::ScriptTranslator
89  {
90  public:
94  static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, int& value);
95  static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, float& value);
96  static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, double& value);
97  static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, bool& value);
98  static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, Ogre::Degree& value);
99  static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, Ogre::ColourValue& value);
100  static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, Ogre::String& value);
101  static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, Ogre::Vector3& value);
102  static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, Ogre::Vector2& value);
103 
106  static void translateProperty (
107  Ogre::ScriptCompiler* compiler,
108  Ogre::PropertyAbstractNode* prop,
109  void* targetObject,
110  const TypeDescriptor* typeDescriptor);
111 
112  public:
113  explicit TypeDescriptorScriptTranslator (TypeDescriptor* type = 0);
114 
115  virtual void translate (Ogre::ScriptCompiler* compiler, const Ogre::AbstractNodePtr& node);
116 
117  inline const TypeDescriptor* getTypeDescriptor () const { return mTypeDescriptor; }
118  inline TypeDescriptor* getTypeDescriptor () { return mTypeDescriptor; }
119 
120  private:
121  TypeDescriptor* mTypeDescriptor;
122  };
123 
126  struct CAELUM_EXPORT CaelumSystemScriptTranslator: public Ogre::ScriptTranslator
127  {
128  public:
129  CaelumSystemScriptTranslator();
130 
131  virtual void translate (Ogre::ScriptCompiler* compiler, const Ogre::AbstractNodePtr& node);
132 
133  void setTranslationTarget (CaelumSystem* target, const Ogre::String& name);
134  void clearTranslationTarget ();
135 
136  inline bool hasTranslationTarget () const { return mTranslationTarget != 0; }
137  inline bool foundTranslationTarget () const { return mTranslationTargetFound; }
138  inline CaelumSystem* getTranslationTarget () const { return mTranslationTarget; }
139  inline const Ogre::String& getTranslationTargetName () const { return mTranslationTargetName; }
140 
141  inline void setResourceManager (PropScriptResourceManager* value) { mResourceManager = value; }
142  inline PropScriptResourceManager* getResourceManager () const { return mResourceManager; }
143 
144  private:
145  PropScriptResourceManager* mResourceManager;
146  CaelumSystem* mTranslationTarget;
147  Ogre::String mTranslationTargetName;
148  bool mTranslationTargetFound;
149 
150  public:
155  inline const TypeDescriptor* getTypeDescriptor () const { return mTypeDescriptor; }
156  inline void setTypeDescriptor (const TypeDescriptor* value) { mTypeDescriptor = value; }
157 
158  private:
159  const TypeDescriptor* mTypeDescriptor;
160  };
161 
172  struct CAELUM_EXPORT CloudSystemScriptTranslator: public Ogre::ScriptTranslator
173  {
174  public:
175  virtual void translate (Ogre::ScriptCompiler* compiler, const Ogre::AbstractNodePtr& node);
176  };
177 
181  class CAELUM_EXPORT CaelumScriptTranslatorManager: public Ogre::ScriptTranslatorManager
182  {
183  public:
184  explicit CaelumScriptTranslatorManager (CaelumDefaultTypeDescriptorData* typeData);
185 
186  virtual size_t getNumTranslators () const;
187 
189  virtual Ogre::ScriptTranslator* getTranslator (const Ogre::AbstractNodePtr& node);
190 
191  void _setPropScriptResourceManager (PropScriptResourceManager* mgr);
192 
193  inline CaelumSystemScriptTranslator* getCaelumSystemTranslator () { return &mCaelumSystemTranslator; }
194 
195  private:
196  CaelumSystemScriptTranslator mCaelumSystemTranslator;
197  CloudSystemScriptTranslator mCloudSystemTranslator;
198  TypeDescriptorScriptTranslator mFlatCloudLayerTranslator;
199  TypeDescriptorScriptTranslator mSunTranslator;
200  TypeDescriptorScriptTranslator mMoonTranslator;
201  TypeDescriptorScriptTranslator mPointStarfieldTranslator;
202  TypeDescriptorScriptTranslator mGroundFogTranslator;
203  TypeDescriptorScriptTranslator mDepthComposerTranslator;
204  TypeDescriptorScriptTranslator mPrecipitationTranslator;
205  TypeDescriptorScriptTranslator mSkyDomeTranslator;
206 
209  typedef std::map<Ogre::String, Ogre::ScriptTranslator*> ScriptTranslatorMap;
210  ScriptTranslatorMap mTranslatorMap;
211  };
212 }
213 
214 #endif // CAELUM_SCRIPT_SUPPORT
215 
216 #endif // CAELUM__CAELUM_SCRIPT_TRANSLATOR_H
Caelum namespace.
Definition: Astronomy.cpp:24