00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CAELUM__CAELUM_SCRIPT_TRANSLATOR_H
00022 #define CAELUM__CAELUM_SCRIPT_TRANSLATOR_H
00023
00024 #if CAELUM_SCRIPT_SUPPORT
00025
00026 #include "CaelumPrerequisites.h"
00027 #include "OgreScriptTranslator.h"
00028 #include "TypeDescriptor.h"
00029
00030 namespace Caelum
00031 {
00048 class CAELUM_EXPORT PropScriptResource: public Ogre::Resource {
00049 protected:
00050 virtual void loadImpl () { }
00051 virtual void unloadImpl () { }
00052 virtual size_t calculateSize () const { return 0; }
00053
00054 public:
00055 PropScriptResource (
00056 Ogre::ResourceManager* creator, const Ogre::String& name, Ogre::ResourceHandle handle,
00057 const Ogre::String& group, bool isManual, Ogre::ManualResourceLoader* loader);
00058 ~PropScriptResource();
00059 };
00060
00063 class CAELUM_EXPORT PropScriptResourceManager: public Ogre::ResourceManager
00064 {
00065 public:
00066 PropScriptResourceManager();
00067
00068 virtual PropScriptResource* createImpl(
00069 const String& name, Ogre::ResourceHandle handle, const String& group,
00070 bool isManual, Ogre::ManualResourceLoader* loader, const Ogre::NameValuePairList* createParams);
00071 };
00072
00088 class CAELUM_EXPORT TypeDescriptorScriptTranslator: public Ogre::ScriptTranslator
00089 {
00090 public:
00094 static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, int& value);
00095 static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, float& value);
00096 static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, double& value);
00097 static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, bool& value);
00098 static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, Ogre::Degree& value);
00099 static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, Ogre::ColourValue& value);
00100 static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, Ogre::String& value);
00101 static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, Ogre::Vector3& value);
00102 static bool getPropValueOrAddError (Ogre::ScriptCompiler* compiler, Ogre::PropertyAbstractNode* prop, Ogre::Vector2& value);
00103
00106 static void translateProperty (
00107 Ogre::ScriptCompiler* compiler,
00108 Ogre::PropertyAbstractNode* prop,
00109 void* targetObject,
00110 const TypeDescriptor* typeDescriptor);
00111
00112 public:
00113 explicit TypeDescriptorScriptTranslator (TypeDescriptor* type = 0);
00114
00115 virtual void translate (Ogre::ScriptCompiler* compiler, const Ogre::AbstractNodePtr& node);
00116
00117 inline const TypeDescriptor* getTypeDescriptor () const { return mTypeDescriptor; }
00118 inline TypeDescriptor* getTypeDescriptor () { return mTypeDescriptor; }
00119
00120 private:
00121 TypeDescriptor* mTypeDescriptor;
00122 };
00123
00126 struct CAELUM_EXPORT CaelumSystemScriptTranslator: public Ogre::ScriptTranslator
00127 {
00128 public:
00129 CaelumSystemScriptTranslator();
00130
00131 virtual void translate (Ogre::ScriptCompiler* compiler, const Ogre::AbstractNodePtr& node);
00132
00133 void setTranslationTarget (CaelumSystem* target, const Ogre::String& name);
00134 void clearTranslationTarget ();
00135
00136 inline bool hasTranslationTarget () const { return mTranslationTarget != 0; }
00137 inline bool foundTranslationTarget () const { return mTranslationTargetFound; }
00138 inline CaelumSystem* getTranslationTarget () const { return mTranslationTarget; }
00139 inline const Ogre::String& getTranslationTargetName () const { return mTranslationTargetName; }
00140
00141 inline void setResourceManager (PropScriptResourceManager* value) { mResourceManager = value; }
00142 inline PropScriptResourceManager* getResourceManager () const { return mResourceManager; }
00143
00144 private:
00145 PropScriptResourceManager* mResourceManager;
00146 CaelumSystem* mTranslationTarget;
00147 Ogre::String mTranslationTargetName;
00148 bool mTranslationTargetFound;
00149
00150 public:
00155 inline const TypeDescriptor* getTypeDescriptor () const { return mTypeDescriptor; }
00156 inline void setTypeDescriptor (const TypeDescriptor* value) { mTypeDescriptor = value; }
00157
00158 private:
00159 const TypeDescriptor* mTypeDescriptor;
00160 };
00161
00172 struct CAELUM_EXPORT CloudSystemScriptTranslator: public Ogre::ScriptTranslator
00173 {
00174 public:
00175 virtual void translate (Ogre::ScriptCompiler* compiler, const Ogre::AbstractNodePtr& node);
00176 };
00177
00181 class CAELUM_EXPORT CaelumScriptTranslatorManager: public Ogre::ScriptTranslatorManager
00182 {
00183 public:
00184 explicit CaelumScriptTranslatorManager (CaelumDefaultTypeDescriptorData* typeData);
00185
00186 virtual size_t getNumTranslators () const;
00187
00189 virtual Ogre::ScriptTranslator* getTranslator (const Ogre::AbstractNodePtr& node);
00190
00191 void _setPropScriptResourceManager (PropScriptResourceManager* mgr);
00192
00193 inline CaelumSystemScriptTranslator* getCaelumSystemTranslator () { return &mCaelumSystemTranslator; }
00194
00195 private:
00196 CaelumSystemScriptTranslator mCaelumSystemTranslator;
00197 CloudSystemScriptTranslator mCloudSystemTranslator;
00198 TypeDescriptorScriptTranslator mFlatCloudLayerTranslator;
00199 TypeDescriptorScriptTranslator mSunTranslator;
00200 TypeDescriptorScriptTranslator mMoonTranslator;
00201 TypeDescriptorScriptTranslator mPointStarfieldTranslator;
00202 TypeDescriptorScriptTranslator mGroundFogTranslator;
00203 TypeDescriptorScriptTranslator mDepthComposerTranslator;
00204 TypeDescriptorScriptTranslator mPrecipitationTranslator;
00205 TypeDescriptorScriptTranslator mSkyDomeTranslator;
00206
00209 typedef std::map<Ogre::String, Ogre::ScriptTranslator*> ScriptTranslatorMap;
00210 ScriptTranslatorMap mTranslatorMap;
00211 };
00212 }
00213
00214 #endif // CAELUM_SCRIPT_SUPPORT
00215
00216 #endif // CAELUM__CAELUM_SCRIPT_TRANSLATOR_H