From: <es...@us...> - 2010-07-17 21:33:07
|
Revision: 2945 http://ogreaddons.svn.sourceforge.net/ogreaddons/?rev=2945&view=rev Author: esuvs Date: 2010-07-17 21:33:01 +0000 (Sat, 17 Jul 2010) Log Message: ----------- Added globals class for globals script values. Modified Paths: -------------- trunk/QtOgreFramework/EngineTest/CMakeLists.txt trunk/QtOgreFramework/EngineTest/include/EngineTestGameLogic.h trunk/QtOgreFramework/EngineTest/include/Light.h trunk/QtOgreFramework/EngineTest/media/scripts/update.js trunk/QtOgreFramework/EngineTest/source/EngineTestGameLogic.cpp Added Paths: ----------- trunk/QtOgreFramework/EngineTest/include/Globals.h trunk/QtOgreFramework/EngineTest/source/Globals.cpp Modified: trunk/QtOgreFramework/EngineTest/CMakeLists.txt =================================================================== --- trunk/QtOgreFramework/EngineTest/CMakeLists.txt 2010-07-17 10:06:15 UTC (rev 2944) +++ trunk/QtOgreFramework/EngineTest/CMakeLists.txt 2010-07-17 21:33:01 UTC (rev 2945) @@ -4,6 +4,7 @@ SET(SRC_FILES source/CameraWrapper.cpp + source/Globals.cpp source/Light.cpp source/main.cpp source/Mouse.cpp @@ -16,6 +17,7 @@ SET(INC_FILES include/CameraWrapper.h include/EngineTestGameLogic.h + include/Globals.h include/Keyboard.h include/Light.h include/Mouse.h Modified: trunk/QtOgreFramework/EngineTest/include/EngineTestGameLogic.h =================================================================== --- trunk/QtOgreFramework/EngineTest/include/EngineTestGameLogic.h 2010-07-17 10:06:15 UTC (rev 2944) +++ trunk/QtOgreFramework/EngineTest/include/EngineTestGameLogic.h 2010-07-17 21:33:01 UTC (rev 2945) @@ -3,6 +3,7 @@ #include "CameraWrapper.h" #include "GameLogic.h" +#include "Globals.h" #include "Keyboard.h" #include "Light.h" #include "Log.h" @@ -62,8 +63,8 @@ int mCurrentWheelPos;*/ QTime* mTime; - int mLastFrameTime; - int mCurrentTime; + //int mLastFrameTime; + //int mCurrentTime; QVariant mCurrentTimeVariant; bool mIsFirstFrame; @@ -96,6 +97,8 @@ ObjectStore mObjectStore; QString mInitialiseScript; + + Globals* mGlobals; }; #endif /*ENGINETESTGAMELOGIC_H_*/ \ No newline at end of file Added: trunk/QtOgreFramework/EngineTest/include/Globals.h =================================================================== --- trunk/QtOgreFramework/EngineTest/include/Globals.h (rev 0) +++ trunk/QtOgreFramework/EngineTest/include/Globals.h 2010-07-17 21:33:01 UTC (rev 2945) @@ -0,0 +1,30 @@ +#ifndef GLOBALS_H_ +#define GLOBALS_H_ + +#include <QColor> +#include <QObject> +#include <QScriptEngine> +#include <QVector3D> + +class Globals : public QObject +{ + Q_OBJECT + +public: + Globals(QObject* parent = 0); + + Q_PROPERTY(quint32 currentFrameTime READ getCurrentFrameTime) + Q_PROPERTY(quint32 previousFrameTime READ getPreviousFrameTime) + +public slots: + quint32 getCurrentFrameTime(void) const; + void setCurrentFrameTime(const quint32 uCurrentFrameTime); + + quint32 getPreviousFrameTime(void) const; + void setPreviousFrameTime(const quint32 uPreviousFrameTime); +private: + quint32 m_uCurrentFrameTime; + quint32 m_uPreviousFrameTime; +}; + +#endif //GLOBALS_H_ \ No newline at end of file Modified: trunk/QtOgreFramework/EngineTest/include/Light.h =================================================================== --- trunk/QtOgreFramework/EngineTest/include/Light.h 2010-07-17 10:06:15 UTC (rev 2944) +++ trunk/QtOgreFramework/EngineTest/include/Light.h 2010-07-17 21:33:01 UTC (rev 2945) @@ -3,6 +3,7 @@ #include <QColor> #include <QObject> +#include <QScriptEngine> #include <QVector3D> class Light : public QObject @@ -26,5 +27,7 @@ QColor m_colColour; }; +Q_SCRIPT_DECLARE_QMETAOBJECT(Light, QObject*) + #endif //LIGHT_H_ \ No newline at end of file Modified: trunk/QtOgreFramework/EngineTest/media/scripts/update.js =================================================================== --- trunk/QtOgreFramework/EngineTest/media/scripts/update.js 2010-07-17 10:06:15 UTC (rev 2944) +++ trunk/QtOgreFramework/EngineTest/media/scripts/update.js 2010-07-17 21:33:01 UTC (rev 2945) @@ -14,9 +14,9 @@ function updateLights() { - objectStore.getObject('RedLight').position = torusKnotValue(2.0, 5.0, currentTime / 500); - objectStore.getObject('GreenLight').position = torusKnotValue(3.0, 7.0, currentTime / 420); - objectStore.getObject('BlueLight').position = torusKnotValue(3.5, 4.4, currentTime / 830); + objectStore.getObject('RedLight').position = torusKnotValue(2.0, 5.0, globals.currentFrameTime / 500); + objectStore.getObject('GreenLight').position = torusKnotValue(3.0, 7.0, globals.currentFrameTime / 420); + objectStore.getObject('BlueLight').position = torusKnotValue(3.5, 4.4, globals.currentFrameTime / 830); } function processInput() Modified: trunk/QtOgreFramework/EngineTest/source/EngineTestGameLogic.cpp =================================================================== --- trunk/QtOgreFramework/EngineTest/source/EngineTestGameLogic.cpp 2010-07-17 10:06:15 UTC (rev 2944) +++ trunk/QtOgreFramework/EngineTest/source/EngineTestGameLogic.cpp 2010-07-17 21:33:01 UTC (rev 2945) @@ -49,17 +49,17 @@ } -Q_SCRIPT_DECLARE_QMETAOBJECT(Light, QObject*) - void EngineTestGameLogic::initialise(void) { initScriptEngine(); + mGlobals = new Globals(this); + QScriptValue lightClass = scriptEngine->scriptValueFromQMetaObject<Light>(); scriptEngine->globalObject().setProperty("Light", lightClass); - /*QScriptValue currentTimeScriptValue = scriptEngine->newVariant(mCurrentTimeVariant); - scriptEngine->globalObject().setProperty("currentTime", currentTimeScriptValue);*/ + QScriptValue globalsScriptValue = scriptEngine->newQObject(mGlobals); + scriptEngine->globalObject().setProperty("globals", globalsScriptValue); QScriptValue keyboardScriptValue = scriptEngine->newQObject(&keyboard); scriptEngine->globalObject().setProperty("keyboard", keyboardScriptValue); @@ -143,27 +143,7 @@ connect(m_pScriptEditorWidget, SIGNAL(start(void)), this, SLOT(startScriptingEngine(void))); connect(m_pScriptEditorWidget, SIGNAL(stop(void)), this, SLOT(stopScriptingEngine(void))); - - /*Ogre::Light* pointLight = mSceneManager->createLight("pointLight"); - pointLight->setType(Ogre::Light::LT_POINT); - pointLight->setPosition(Ogre::Vector3(0, 0, 0)); - pointLight->setDiffuseColour(1.0, 0.0, 0.0);*/ - /*Light* redLight = new Light(); - redLight->setPosition(QVector3D(0.0,0.0,0.0)); - redLight->setColour(QColor(255, 0, 0)); - mObjectStore.setObject("RedLight", redLight); - - Light* greenLight = new Light(); - greenLight->setPosition(QVector3D(0.0,0.0,0.0)); - greenLight->setColour(QColor(0, 255, 0)); - mObjectStore.setObject("GreenLight", greenLight); - - Light* blueLight = new Light(); - blueLight->setPosition(QVector3D(0.0,0.0,0.0)); - blueLight->setColour(QColor(0, 0, 255)); - mObjectStore.setObject("BlueLight", blueLight);*/ - mInitialiseScript = "print('QtScript Initialisation Begin');" @@ -195,16 +175,11 @@ void EngineTestGameLogic::update(void) { - mLastFrameTime = mCurrentTime; - mCurrentTime = mTime->elapsed(); + mGlobals->setPreviousFrameTime(mGlobals->getCurrentFrameTime()); + mGlobals->setCurrentFrameTime(mTime->elapsed()); - mCurrentTimeVariant = mCurrentTime; + float timeElapsedInSeconds = (mGlobals->getCurrentFrameTime() - mGlobals->getPreviousFrameTime()) / 1000.0f; - QScriptValue currentTimeScriptValue = scriptEngine->newVariant(mCurrentTimeVariant); - scriptEngine->globalObject().setProperty("currentTime", currentTimeScriptValue); - - float timeElapsedInSeconds = (mCurrentTime - mLastFrameTime) / 1000.0f; - for (Ogre::SceneManager::MovableObjectIterator moi = mSceneManager->getMovableObjectIterator("Entity"); moi.hasMoreElements(); moi.moveNext()) { Ogre::Entity *entity = static_cast<Ogre::Entity*>(moi.peekNextValue()); Added: trunk/QtOgreFramework/EngineTest/source/Globals.cpp =================================================================== --- trunk/QtOgreFramework/EngineTest/source/Globals.cpp (rev 0) +++ trunk/QtOgreFramework/EngineTest/source/Globals.cpp 2010-07-17 21:33:01 UTC (rev 2945) @@ -0,0 +1,26 @@ +#include "Globals.h" + +Globals::Globals(QObject* parent) + :QObject(parent) +{ +} + +quint32 Globals::getCurrentFrameTime(void) const +{ + return m_uCurrentFrameTime; +} + +void Globals::setCurrentFrameTime(const quint32 uCurrentFrameTime) +{ + m_uCurrentFrameTime = uCurrentFrameTime; +} + +quint32 Globals::getPreviousFrameTime(void) const +{ + return m_uPreviousFrameTime; +} + +void Globals::setPreviousFrameTime(const quint32 uPreviousFrameTime) +{ + m_uPreviousFrameTime = uPreviousFrameTime; +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |