Revision: 1527
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1527&view=rev
Author:   rorthomas
Date:     2010-08-22 20:05:07 +0000 (Sun, 22 Aug 2010)

Log Message:
-----------
angelscript collisions working :)
WIP 

Modified Paths:
--------------
    trunk/source/main/RoRFrameListener.cpp
    trunk/source/main/ScriptEngine.cpp
    trunk/source/main/ScriptEngine.h
    trunk/source/main/collisions.cpp

Modified: trunk/source/main/RoRFrameListener.cpp
===================================================================
--- trunk/source/main/RoRFrameListener.cpp      2010-08-21 23:41:33 UTC (rev 
1526)
+++ trunk/source/main/RoRFrameListener.cpp      2010-08-22 20:05:07 UTC (rev 
1527)
@@ -4540,16 +4540,6 @@
        }
 #endif // MYGUI
 
-#ifdef USE_ANGELSCRIPT
-       if(!netmode)
-       {
-               LogManager::getSingleton().logMessage("Loading Angelscript 
Script engine." );
-               
if(ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(terrainfile+".as"))
-                       
ScriptEngine::getSingleton().loadTerrainScript(terrainfile+".as");
-       }
-#endif
-
-
 #ifdef USE_LUA
        //setup lua
        LogManager::getSingleton().logMessage("Loading LUA Script engine." );
@@ -4563,6 +4553,15 @@
        collisions=new Collisions(this, debugCollisions);
 #endif
 
+#ifdef USE_ANGELSCRIPT
+       if(!netmode)
+       {
+               LogManager::getSingleton().logMessage("Loading Angelscript 
Script engine." );
+               
if(ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(terrainfile+".as"))
+                       
ScriptEngine::getSingleton().loadTerrainScript(terrainfile+".as");
+       }
+#endif
+
        // update icollisions instance in factory
        BeamFactory::getSingleton().icollisions = collisions;
 

Modified: trunk/source/main/ScriptEngine.cpp
===================================================================
--- trunk/source/main/ScriptEngine.cpp  2010-08-21 23:41:33 UTC (rev 1526)
+++ trunk/source/main/ScriptEngine.cpp  2010-08-22 20:05:07 UTC (rev 1527)
@@ -112,7 +112,7 @@
 
        // get some other optional functions
        frameStepFunctionPtr = mod->GetFunctionIdByDecl("void 
frameStep(float)");
-       eventCallbackFunctionPtr = mod->GetFunctionIdByDecl("void 
eventCallback(int event, int value)");
+       eventCallbackFunctionPtr = mod->GetFunctionIdByDecl("void 
eventCallback(int, int)");
 
        // Create our context, prepare it, and then execute
        context = engine->CreateContext();
@@ -450,6 +450,7 @@
        result = engine->RegisterObjectMethod("GameScriptClass", "void 
log(const string &in)", asMETHOD(GameScript,log), asCALL_THISCALL); 
assert(result>=0);
        result = engine->RegisterObjectMethod("GameScriptClass", "double 
getTime()", asMETHOD(GameScript,getTime), asCALL_THISCALL); assert(result>=0);
        result = engine->RegisterObjectMethod("GameScriptClass", "void 
setPersonPosition(vector3)", asMETHOD(GameScript,setPersonPosition), 
asCALL_THISCALL); assert(result>=0);
+       result = engine->RegisterObjectMethod("GameScriptClass", "void 
loadTerrain(const string &in)", asMETHOD(GameScript,loadTerrain), 
asCALL_THISCALL); assert(result>=0);
        result = engine->RegisterObjectMethod("GameScriptClass", "vector3 
getPersonPosition()", asMETHOD(GameScript,getPersonPosition), asCALL_THISCALL); 
assert(result>=0);
        result = engine->RegisterObjectMethod("GameScriptClass", "void 
movePerson(float, float, float)", asMETHOD(GameScript,movePerson), 
asCALL_THISCALL); assert(result>=0);
        result = engine->RegisterObjectMethod("GameScriptClass", "float 
getCaelumTime()", asMETHOD(GameScript,getCaelumTime), asCALL_THISCALL); 
assert(result>=0);
@@ -604,6 +605,27 @@
        return 0;
 }
 
+int ScriptEngine::envokeCallback(int functionPtr, eventsource_t *source)
+{
+       if(functionPtr<=0) return 1;
+       if(!engine) return 0;
+       if(!context) context = engine->CreateContext();
+       context->Prepare(functionPtr);
+
+       // Set the function arguments
+       context->SetArgObject(0, &std::string(source->instancename));
+       context->SetArgObject(1, &std::string(source->boxname));
+
+       //LogManager::getSingleton().logMessage("SE| Executing framestep()");
+       int r = context->Execute();
+       if( r == asEXECUTION_FINISHED )
+       {
+         // The return value is only valid if the execution finished 
successfully
+         asDWORD ret = context->GetReturnDWord();
+       }
+       return 0;
+}
+
 int ScriptEngine::executeString(Ogre::String command)
 {
        // TOFIX: add proper error output
@@ -780,6 +802,11 @@
        if(mefl && mefl->person) mefl->person->setPosition(Ogre::Vector3(vec.x, 
vec.y, vec.z));
 }
 
+void GameScript::loadTerrain(std::string &terrain)
+{
+       if(mefl) mefl->loadTerrain(terrain);
+}
+
 Ogre::Vector3 GameScript::getPersonPosition()
 {
        if(mefl && mefl->person)

Modified: trunk/source/main/ScriptEngine.h
===================================================================
--- trunk/source/main/ScriptEngine.h    2010-08-21 23:41:33 UTC (rev 1526)
+++ trunk/source/main/ScriptEngine.h    2010-08-22 20:05:07 UTC (rev 1527)
@@ -32,6 +32,8 @@
 #include "Ogre.h"
 #include "rormemory.h"
 
+#include "collisions.h"
+
 //forward decl.
 class RoRFrameListener;
 class GameScript;
@@ -119,6 +121,8 @@
         */
        int executeString(Ogre::String command);
 
+       int envokeCallback(int functionPtr, eventsource_t *source);
+
        AngelScript::asIScriptEngine *getEngine() { return engine; };
 
 protected:
@@ -200,6 +204,7 @@
         */
        void setPersonPosition(Ogre::Vector3 vec);
 
+       void loadTerrain(std::string &terrain);
        /**
         * moves the person relative
         * @param x X translation

Modified: trunk/source/main/collisions.cpp
===================================================================
--- trunk/source/main/collisions.cpp    2010-08-21 23:41:33 UTC (rev 1526)
+++ trunk/source/main/collisions.cpp    2010-08-22 20:05:07 UTC (rev 1527)
@@ -23,6 +23,7 @@
 #include "approxmath.h"
 #include "errorutils.h"
 #include "language.h"
+#include "ScriptEngine.h"
 
 // some gcc fixes
 #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
@@ -741,8 +742,16 @@
                                                {
                                                        if 
(cbox->eventsourcenum!=-1 && permitEvent(cbox->event_filter))
                                                        {
+                                                               // prefer AS to 
LUA
+                                                               bool handled = 
false;
+#ifdef USE_ANGELSCRIPT
+                                                               int ret = 
ScriptEngine::getSingleton().envokeCallback(eventsources[cbox->eventsourcenum].luahandler,
 &eventsources[cbox->eventsourcenum]);
+                                                               if(ret == 0)
+                                                                       
handled=true;
+#endif
 #ifdef USE_LUA
-                                                               
lua->spawnEvent(cbox->eventsourcenum, &eventsources[cbox->eventsourcenum]);
+                                                               if(!handled)
+                                                                       
lua->spawnEvent(cbox->eventsourcenum, &eventsources[cbox->eventsourcenum]);
 #endif
                                                        }
                                                        if (cbox->camforced && 
!forcecam)
@@ -794,8 +803,16 @@
                                        {
                                                if (cbox->eventsourcenum!=-1 && 
permitEvent(cbox->event_filter))
                                                {
+                                                       // prefer AS to LUA
+                                                       bool handled = false;
+#ifdef USE_ANGELSCRIPT
+                                                       int ret = 
ScriptEngine::getSingleton().envokeCallback(eventsources[cbox->eventsourcenum].luahandler,
 &eventsources[cbox->eventsourcenum]);
+                                                       if(ret == 0)
+                                                               handled=true;
+#endif
 #ifdef USE_LUA
-                                                       
lua->spawnEvent(cbox->eventsourcenum, &eventsources[cbox->eventsourcenum]);
+                                                       if(!handled)
+                                                               
lua->spawnEvent(cbox->eventsourcenum, &eventsources[cbox->eventsourcenum]);
 #endif
                                                }
                                                if (cbox->camforced && 
!forcecam)
@@ -940,8 +957,16 @@
                                                {
                                                        if 
(cbox->eventsourcenum!=-1 && permitEvent(cbox->event_filter))
                                                        {
+                                                               // prefer AS to 
LUA
+                                                               bool handled = 
false;
+#ifdef USE_ANGELSCRIPT
+                                                               int ret = 
ScriptEngine::getSingleton().envokeCallback(eventsources[cbox->eventsourcenum].luahandler,
 &eventsources[cbox->eventsourcenum]);
+                                                               if(ret == 0)
+                                                                       
handled=true;
+#endif
 #ifdef USE_LUA
-                                                               
lua->spawnEvent(cbox->eventsourcenum, &eventsources[cbox->eventsourcenum]);
+                                                               if(!handled)
+                                                                       
lua->spawnEvent(cbox->eventsourcenum, &eventsources[cbox->eventsourcenum]);
 #endif
                                                        }
                                                        if (cbox->camforced && 
!forcecam)
@@ -988,8 +1013,16 @@
                                        {
                                                if (cbox->eventsourcenum!=-1 && 
permitEvent(cbox->event_filter))
                                                {
+                                                       // prefer AS to LUA
+                                                       bool handled = false;
+#ifdef USE_ANGELSCRIPT
+                                                       int ret = 
ScriptEngine::getSingleton().envokeCallback(eventsources[cbox->eventsourcenum].luahandler,
 &eventsources[cbox->eventsourcenum]);
+                                                       if(ret == 0)
+                                                               handled=true;
+#endif
 #ifdef USE_LUA
-                                                       
lua->spawnEvent(cbox->eventsourcenum, &eventsources[cbox->eventsourcenum]);
+                                                       if(!handled)
+                                                               
lua->spawnEvent(cbox->eventsourcenum, &eventsources[cbox->eventsourcenum]);
 #endif
                                                }
                                                if (cbox->camforced && 
!forcecam)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to