00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "CaelumPrecompiled.h"
00022 #include "CaelumPlugin.h"
00023
00024 template<> Caelum::CaelumPlugin* Ogre::Singleton<Caelum::CaelumPlugin>::ms_Singleton = 0;
00025
00026 namespace Caelum
00027 {
00028 CaelumPlugin* CaelumPlugin::getSingletonPtr () {
00029 return ms_Singleton;
00030 }
00031
00032 CaelumPlugin& CaelumPlugin::getSingleton () {
00033 assert (ms_Singleton);
00034 return *ms_Singleton;
00035 }
00036
00037 extern "C" void CAELUM_EXPORT dllStartPlugin () {
00038 assert (CaelumPlugin::getSingletonPtr () == 0);
00039 CaelumPlugin* plugin = new CaelumPlugin();
00040 assert (CaelumPlugin::getSingletonPtr () == plugin);
00041 Ogre::Root::getSingleton ().installPlugin (CaelumPlugin::getSingletonPtr ());
00042 }
00043
00044 extern "C" void CAELUM_EXPORT dllStopPlugin () {
00045 assert (CaelumPlugin::getSingletonPtr () != 0);
00046 Ogre::Root::getSingleton ().uninstallPlugin (CaelumPlugin::getSingletonPtr ());
00047 delete CaelumPlugin::getSingletonPtr ();
00048 assert (CaelumPlugin::getSingletonPtr () == 0);
00049 }
00050
00051 #if CAELUM_SCRIPT_SUPPORT
00052 CaelumPlugin::CaelumPlugin(): mScriptTranslatorManager(&mTypeDescriptorData)
00053 #else
00054 CaelumPlugin::CaelumPlugin()
00055 #endif
00056 {
00057 mIsInstalled = false;
00058 }
00059
00060 CaelumPlugin::~CaelumPlugin() {
00061 }
00062
00063 const Ogre::String CaelumPlugin::CAELUM_PLUGIN_NAME = "Caelum";
00064
00065 const Ogre::String& CaelumPlugin::getName () const {
00066 return CAELUM_PLUGIN_NAME;
00067 }
00068
00069 void CaelumPlugin::install ()
00070 {
00071 assert(!mIsInstalled && "Already installed");
00072
00073 Ogre::LogManager::getSingleton ().logMessage("Caelum plugin version " +
00074 Ogre::StringConverter::toString (CAELUM_VERSION_MAIN) + "." +
00075 Ogre::StringConverter::toString (CAELUM_VERSION_SEC) + "." +
00076 Ogre::StringConverter::toString (CAELUM_VERSION_TER) + " "
00077 "installed");
00078
00079 #if CAELUM_SCRIPT_SUPPORT
00080 Ogre::ScriptCompilerManager::getSingleton ().addTranslatorManager (
00081 getScriptTranslatorManager ());
00082 Ogre::ResourceGroupManager::getSingleton()._registerResourceManager (
00083 getPropScriptResourceManager ()->getResourceType (),
00084 getPropScriptResourceManager ());
00085
00086 getScriptTranslatorManager()->_setPropScriptResourceManager (
00087 &mPropScriptResourceManager);
00088 #endif // CAELUM_SCRIPT_SUPPORT
00089
00090 mIsInstalled = true;
00091 }
00092
00093 void CaelumPlugin::initialise () {
00094 }
00095
00096 void CaelumPlugin::shutdown () {
00097 }
00098
00099 void CaelumPlugin::uninstall ()
00100 {
00101 assert(mIsInstalled && "Not installed");
00102
00103 #if CAELUM_SCRIPT_SUPPORT
00104 getScriptTranslatorManager()->_setPropScriptResourceManager (0);
00105
00106 Ogre::ResourceGroupManager::getSingleton ()._unregisterResourceManager (
00107 getPropScriptResourceManager ()->getResourceType ());
00108 Ogre::ScriptCompilerManager::getSingleton ().removeTranslatorManager (
00109 getScriptTranslatorManager ());
00110 #endif // CAELUM_SCRIPT_SUPPORT
00111
00112 Ogre::LogManager::getSingleton ().logMessage("Caelum plugin uninstalled");
00113
00114 mIsInstalled = false;
00115 }
00116
00117 #if CAELUM_SCRIPT_SUPPORT
00118 void CaelumPlugin::loadCaelumSystemFromScript (
00119 CaelumSystem* sys,
00120 const Ogre::String& objectName,
00121 const Ogre::String& groupName)
00122 {
00123 assert (sys);
00124 assert (this->isInstalled () && "Must install CaelumPlugin before loading scripts");
00125
00126
00127 #if OGRE_VERSION >= 0x00010700
00128 Ogre::ResourcePtr res = getPropScriptResourceManager ()->getByName (objectName, groupName);
00129 #else
00130 Ogre::ResourcePtr res = getPropScriptResourceManager ()->getByName (objectName);
00131 #endif
00132
00133
00134 PropScriptResource* propRes = static_cast<PropScriptResource*> (res.get ());
00135 if (!propRes) {
00136 OGRE_EXCEPT (Ogre::Exception::ERR_ITEM_NOT_FOUND,
00137 "Could not find caelum_sky_system " + objectName,
00138 "CaelumPlugin::loadCaelumSystemFromScript");
00139 }
00140
00141
00142 const Ogre::String& scriptFileName = propRes->getOrigin();
00143 const Ogre::String& scriptFileGroup = propRes->getGroup();
00144 Ogre::DataStreamPtr streamPtr = Ogre::ResourceGroupManager::getSingleton ().openResource (
00145 scriptFileName, scriptFileGroup, false);
00146
00147
00148 this->getScriptTranslatorManager()->getCaelumSystemTranslator()->setTranslationTarget (sys, objectName);
00149 Ogre::ScriptCompilerManager::getSingleton ().parseScript (streamPtr, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00150 bool found = this->getScriptTranslatorManager()->getCaelumSystemTranslator()->foundTranslationTarget ();
00151
00152
00153 if (!found) {
00154 OGRE_EXCEPT (Ogre::Exception::ERR_ITEM_NOT_FOUND,
00155 "Could not find caelum_sky_system " + objectName + " in file " + scriptFileName + " on reparsing. "
00156 "Perhaps information in PropScriptResourceManager is out of date?",
00157 "CaelumPlugin::loadCaelumSystemFromScript");
00158 }
00159 this->getScriptTranslatorManager()->getCaelumSystemTranslator()->clearTranslationTarget ();
00160 }
00161 #endif // CAELUM_SCRIPT_SUPPORT
00162 }