From: <es...@us...> - 2010-07-17 10:06:22
|
Revision: 2944 http://ogreaddons.svn.sourceforge.net/ogreaddons/?rev=2944&view=rev Author: esuvs Date: 2010-07-17 10:06:15 +0000 (Sat, 17 Jul 2010) Log Message: ----------- Enabled creation of lights from initialisation script. Modified Paths: -------------- trunk/QtOgreFramework/EngineTest/include/EngineTestGameLogic.h trunk/QtOgreFramework/EngineTest/include/Light.h trunk/QtOgreFramework/EngineTest/source/EngineTestGameLogic.cpp Modified: trunk/QtOgreFramework/EngineTest/include/EngineTestGameLogic.h =================================================================== --- trunk/QtOgreFramework/EngineTest/include/EngineTestGameLogic.h 2010-07-17 09:07:54 UTC (rev 2943) +++ trunk/QtOgreFramework/EngineTest/include/EngineTestGameLogic.h 2010-07-17 10:06:15 UTC (rev 2944) @@ -94,6 +94,8 @@ QHash<QString, Light*> m_Lights; ObjectStore mObjectStore; + + QString mInitialiseScript; }; #endif /*ENGINETESTGAMELOGIC_H_*/ \ No newline at end of file Modified: trunk/QtOgreFramework/EngineTest/include/Light.h =================================================================== --- trunk/QtOgreFramework/EngineTest/include/Light.h 2010-07-17 09:07:54 UTC (rev 2943) +++ trunk/QtOgreFramework/EngineTest/include/Light.h 2010-07-17 10:06:15 UTC (rev 2944) @@ -26,4 +26,5 @@ QColor m_colColour; }; + #endif //LIGHT_H_ \ No newline at end of file Modified: trunk/QtOgreFramework/EngineTest/source/EngineTestGameLogic.cpp =================================================================== --- trunk/QtOgreFramework/EngineTest/source/EngineTestGameLogic.cpp 2010-07-17 09:07:54 UTC (rev 2943) +++ trunk/QtOgreFramework/EngineTest/source/EngineTestGameLogic.cpp 2010-07-17 10:06:15 UTC (rev 2944) @@ -49,10 +49,15 @@ } +Q_SCRIPT_DECLARE_QMETAOBJECT(Light, QObject*) + void EngineTestGameLogic::initialise(void) { - initScriptEngine(); + initScriptEngine(); + QScriptValue lightClass = scriptEngine->scriptValueFromQMetaObject<Light>(); + scriptEngine->globalObject().setProperty("Light", lightClass); + /*QScriptValue currentTimeScriptValue = scriptEngine->newVariant(mCurrentTimeVariant); scriptEngine->globalObject().setProperty("currentTime", currentTimeScriptValue);*/ @@ -144,7 +149,7 @@ pointLight->setPosition(Ogre::Vector3(0, 0, 0)); pointLight->setDiffuseColour(1.0, 0.0, 0.0);*/ - Light* redLight = new Light(); + /*Light* redLight = new Light(); redLight->setPosition(QVector3D(0.0,0.0,0.0)); redLight->setColour(QColor(255, 0, 0)); mObjectStore.setObject("RedLight", redLight); @@ -157,8 +162,35 @@ Light* blueLight = new Light(); blueLight->setPosition(QVector3D(0.0,0.0,0.0)); blueLight->setColour(QColor(0, 0, 255)); - mObjectStore.setObject("BlueLight", blueLight); + mObjectStore.setObject("BlueLight", blueLight);*/ + mInitialiseScript = + "print('QtScript Initialisation Begin');" + + "var redLight = new Light();" + "redLight.position = new QVector3D(100,100,100);" + "redLight.colour = new QColor(255,0,0);" + "objectStore.setObject('RedLight', redLight);" + + "var greenLight = new Light();" + "greenLight.position = new QVector3D(100,100,100);" + "greenLight.colour = new QColor(0,255,0);" + "objectStore.setObject('GreenLight', greenLight);" + + "var blueLight = new Light();" + "blueLight.position = new QVector3D(100,100,100);" + "blueLight.colour = new QColor(0,0,255);" + "objectStore.setObject('BlueLight', blueLight);" + + "print('QtScript Initialisation End');"; + + QScriptValue result = scriptEngine->evaluate(mInitialiseScript); + if (scriptEngine->hasUncaughtException()) + { + int line = scriptEngine->uncaughtExceptionLineNumber(); + qCritical() << "uncaught exception at line" << line << ":" << result.toString(); + } + } void EngineTestGameLogic::update(void) @@ -209,7 +241,9 @@ { lightIter.next(); - Light* light = dynamic_cast<Light*>(lightIter.value()); + QObject* pObj = lightIter.value(); + //qCritical() << pObj->objectName(); + Light* light = dynamic_cast<Light*>(pObj); if(light) { Ogre::Light* ogreLight = mSceneManager->createLight(lightIter.key().toStdString()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |