Revision: 1612
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1612&view=rev
Author:   rorthomas
Date:     2011-01-30 20:46:16 +0000 (Sun, 30 Jan 2011)

Log Message:
-----------
hack for AS dictionary to iterate over entries
improved online API for scripting mode
finally found and fixed engine bugs and crashes in "no sound" mode

Modified Paths:
--------------
    trunk/source/angelscript_addons/scriptdictionary/scriptdictionary.h
    trunk/source/main/BeamForcesEuler.cpp
    trunk/source/main/DustPool.cpp
    trunk/source/main/DustPool.h
    trunk/source/main/RoRFrameListener.h
    trunk/source/main/ScriptEngine.cpp
    trunk/source/main/ScriptEngine.h
    trunk/source/main/SoundScriptManager.cpp
    trunk/source/main/engine.cpp
    trunk/source/main/gui_manager.cpp

Modified: trunk/source/angelscript_addons/scriptdictionary/scriptdictionary.h
===================================================================
--- trunk/source/angelscript_addons/scriptdictionary/scriptdictionary.h 
2011-01-30 17:33:58 UTC (rev 1611)
+++ trunk/source/angelscript_addons/scriptdictionary/scriptdictionary.h 
2011-01-30 20:46:16 UTC (rev 1612)
@@ -55,7 +55,6 @@
        void EnumReferences(asIScriptEngine *engine);
        void ReleaseAllReferences(asIScriptEngine *engine);
 
-protected:
        // The structure for holding the values
     struct valueStruct
     {
@@ -67,6 +66,10 @@
         };
         int   typeId;
     };
+
+       // HACK so we can interate over the items in C++
+    std::map<std::string, valueStruct> dict;
+protected:
     
        // We don't want anyone to call the destructor directly, it should be 
called through the Release method
        virtual ~CScriptDictionary();
@@ -77,7 +80,6 @@
        // Our properties
     asIScriptEngine *engine;
     mutable int refCount;
-    std::map<std::string, valueStruct> dict;
 };
 
 // This function will determine the configuration of the engine

Modified: trunk/source/main/BeamForcesEuler.cpp
===================================================================
--- trunk/source/main/BeamForcesEuler.cpp       2011-01-30 17:33:58 UTC (rev 
1611)
+++ trunk/source/main/BeamForcesEuler.cpp       2011-01-30 20:46:16 UTC (rev 
1612)
@@ -764,8 +764,8 @@
                                                        {
                                                                if(dustp) 
dustp->allocSmoke(nodes[i].AbsPosition, nodes[i].Velocity);
 #ifdef USE_OPENAL
-                                                               
ssm->modulate(trucknum, SS_MOD_SCREETCH, (ns-thresold)/thresold);
-                                                               
ssm->trigOnce(trucknum, SS_TRIG_SCREETCH);
+                                                               if(ssm) 
ssm->modulate(trucknum, SS_MOD_SCREETCH, (ns-thresold)/thresold);
+                                                               if(ssm) 
ssm->trigOnce(trucknum, SS_TRIG_SCREETCH);
 #endif // USE_OPENAL
                                                        }
 

Modified: trunk/source/main/DustPool.cpp
===================================================================
--- trunk/source/main/DustPool.cpp      2011-01-30 17:33:58 UTC (rev 1611)
+++ trunk/source/main/DustPool.cpp      2011-01-30 20:46:16 UTC (rev 1612)
@@ -41,6 +41,8 @@
                }
        }
 
+       // hide after creation
+       setVisible(false);
 };
 
 void DustPool::setVisible(bool s)
@@ -48,7 +50,8 @@
        int i;
        for (i=0; i<size; i++) 
        {
-               pss[i]->setVisible(s ^ (types[i]==DUST_RIPPLE));
+               visible[i] = s;
+               pss[i]->setVisible(s);
        }
 }
 
@@ -60,6 +63,7 @@
        velocities[allocated]=vel;
        colours[allocated]=col;
        types[allocated]=DUST_NORMAL;
+       visible[allocated]=true;
        allocated++;
 }
 
@@ -71,6 +75,7 @@
        velocities[allocated]=vel;
        colours[allocated]=col;
        types[allocated]=DUST_CLUMP;
+       visible[allocated]=true;
        allocated++;
 }
 
@@ -81,6 +86,7 @@
        positions[allocated]=pos;
        velocities[allocated]=vel;
        types[allocated]=DUST_RUBBER;
+       visible[allocated]=true;
        allocated++;
 }
 
@@ -92,6 +98,7 @@
        positions[allocated]=pos;
        velocities[allocated]=vel;
        types[allocated]=DUST_SPARKS;
+       visible[allocated]=true;
        allocated++;
 }
 
@@ -103,6 +110,7 @@
        velocities[allocated]=vel;
        types[allocated]=DUST_VAPOUR;
        rates[allocated]=5.0-time;
+       visible[allocated]=true;
        allocated++;
 }
 
@@ -113,6 +121,7 @@
        velocities[allocated]=vel;
        types[allocated]=DUST_DRIP;
        rates[allocated]=5.0-time;
+       visible[allocated]=true;
        allocated++;
 }
 
@@ -122,6 +131,7 @@
        positions[allocated]=pos;
        velocities[allocated]=vel;
        types[allocated]=DUST_SPLASH;
+       visible[allocated]=true;
        allocated++;
 }
 
@@ -131,6 +141,7 @@
        positions[allocated]=pos;
        velocities[allocated]=vel;
        types[allocated]=DUST_RIPPLE;
+       visible[allocated]=true;
        allocated++;
 }
 
@@ -140,6 +151,9 @@
        gspeed=fabs(gspeed);
        for (i=0; i<allocated; i++)
        {
+               // show particle if requested
+               if(pss[i] && !pss[i]->isVisible() && visible[i]) 
pss[i]->setVisible(true);
+
                if (types[i]==DUST_NORMAL)
                {
                        ParticleEmitter *emit=pss[i]->getEmitter(0);

Modified: trunk/source/main/DustPool.h
===================================================================
--- trunk/source/main/DustPool.h        2011-01-30 17:33:58 UTC (rev 1611)
+++ trunk/source/main/DustPool.h        2011-01-30 20:46:16 UTC (rev 1612)
@@ -50,6 +50,7 @@
        int allocated;
        Vector3 positions[MAX_DUSTS];
        Vector3 velocities[MAX_DUSTS];
+       bool    visible[MAX_DUSTS];
        ColourValue colours[MAX_DUSTS];
        int types[MAX_DUSTS];
        float rates[MAX_DUSTS];

Modified: trunk/source/main/RoRFrameListener.h
===================================================================
--- trunk/source/main/RoRFrameListener.h        2011-01-30 17:33:58 UTC (rev 
1611)
+++ trunk/source/main/RoRFrameListener.h        2011-01-30 20:46:16 UTC (rev 
1612)
@@ -403,7 +403,9 @@
        OverlayWrapper *getOverlayWrapper() { return ow; };
 
        Water *w;
+       Ogre::String loadedTerrain;
 
+
 public:
        // mutex'ed data
        void setNetQuality(int q);
@@ -539,8 +541,6 @@
 //     GUI_TruckTool *truckToolGUI;
 //     GUI_MainMenu *mainmenu;
 
-       Ogre::String loadedTerrain;
-
        std::vector<animated_object_t> animatedObjects;
        bool updateAnimatedObjects(float dt);
 };

Modified: trunk/source/main/ScriptEngine.cpp
===================================================================
--- trunk/source/main/ScriptEngine.cpp  2011-01-30 17:33:58 UTC (rev 1611)
+++ trunk/source/main/ScriptEngine.cpp  2011-01-30 20:46:16 UTC (rev 1612)
@@ -32,7 +32,6 @@
 #include "scriptany/scriptany.h"
 #include "scriptarray/scriptarray.h"
 #include "scriptbuilder/scriptbuilder.h"
-#include "scriptdictionary/scriptdictionary.h"
 #include "scripthelper/scripthelper.h"
 #include "scriptstring/scriptstring.h"
 // AS addons end
@@ -512,8 +511,10 @@
        result = engine->RegisterObjectMethod("GameScriptClass", "void 
startTimer()", AngelScript::asMETHOD(GameScript,startTimer), 
AngelScript::asCALL_THISCALL); assert(result>=0);
        result = engine->RegisterObjectMethod("GameScriptClass", "void 
stopTimer()", AngelScript::asMETHOD(GameScript,stopTimer), 
AngelScript::asCALL_THISCALL); assert(result>=0);
        result = engine->RegisterObjectMethod("GameScriptClass", "float 
rangeRandom(float, float)", AngelScript::asMETHOD(GameScript,rangeRandom), 
AngelScript::asCALL_THISCALL); assert(result>=0);
-       result = engine->RegisterObjectMethod("GameScriptClass", "int 
useOnlineAPI(const string &in, string &out)", 
AngelScript::asMETHOD(GameScript,useOnlineAPI), AngelScript::asCALL_THISCALL); 
assert(result>=0);
+       result = engine->RegisterObjectMethod("GameScriptClass", "int 
useOnlineAPI(const string &in, const dictionary &in, string &out)", 
AngelScript::asMETHOD(GameScript,useOnlineAPI), AngelScript::asCALL_THISCALL); 
assert(result>=0);
+       result = engine->RegisterObjectMethod("GameScriptClass", "int 
getLoadedTerrain(string &out)", 
AngelScript::asMETHOD(GameScript,getLoadedTerrain), 
AngelScript::asCALL_THISCALL); assert(result>=0);
        
+       
 
        // class CacheSystem
        result = engine->RegisterObjectType("CacheSystemClass", 
sizeof(CacheSystem), AngelScript::asOBJ_REF | AngelScript::asOBJ_NOHANDLE);
@@ -1145,6 +1146,12 @@
        return Ogre::Math::RangeRandom(from, to);
 }
 
+int GameScript::getLoadedTerrain(std::string &result)
+{
+       result = mefl->loadedTerrain;
+       return 0;
+}
+
 //#ifdef USE_CURL
 //hacky hack to fill memory with data for curl
 // from: http://curl.haxx.se/libcurl/c/getinmemory.html
@@ -1168,7 +1175,7 @@
 }
 //#endif //USE_CURL
 
-int GameScript::useOnlineAPI(const std::string &apiquery, std::string &result)
+int GameScript::useOnlineAPI(const std::string &apiquery, const 
AngelScript::CScriptDictionary &d, std::string &result)
 {
 //#ifdef USE_CURL
        struct curlMemoryStruct chunk;
@@ -1176,6 +1183,45 @@
        chunk.memory = (char *)malloc(1);  /* will be grown as needed by the 
realloc above */ 
        chunk.size = 0;    /* no data at this point */ 
 
+       // construct post fields
+       struct curl_httppost *formpost=NULL;
+       struct curl_httppost *lastptr=NULL;
+       curl_global_init(CURL_GLOBAL_ALL);
+
+       std::map<std::string, 
AngelScript::CScriptDictionary::valueStruct>::const_iterator it;
+       for(it = d.dict.begin(); it != d.dict.end(); it++)
+       {
+               int typeId = it->second.typeId;
+               if(typeId == mse->getEngine()->GetTypeIdByDecl("string"))
+               {
+                       // its a string
+                       curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, 
it->first.c_str(), CURLFORM_COPYCONTENTS, ((std::string 
*)it->second.valueObj)->c_str(), CURLFORM_END);
+               }
+               else if(typeId == AngelScript::asTYPEID_INT8 \
+                       || typeId == AngelScript::asTYPEID_INT16 \
+                       || typeId == AngelScript::asTYPEID_INT32 \
+                       || typeId == AngelScript::asTYPEID_INT64)
+               {
+                       // its an integer
+                       curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, 
it->first.c_str(), CURLFORM_COPYCONTENTS, 
StringConverter::toString((int)it->second.valueInt).c_str(), CURLFORM_END);
+               }
+               else if(typeId == AngelScript::asTYPEID_UINT8 \
+                       || typeId == AngelScript::asTYPEID_UINT16 \
+                       || typeId == AngelScript::asTYPEID_UINT32 \
+                       || typeId == AngelScript::asTYPEID_UINT64)
+               {
+                       // its an unsigned integer
+                       curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, 
it->first.c_str(), CURLFORM_COPYCONTENTS, StringConverter::toString((unsigned 
int)it->second.valueInt).c_str(), CURLFORM_END);
+               }
+               else if(typeId == AngelScript::asTYPEID_FLOAT || typeId == 
AngelScript::asTYPEID_DOUBLE)
+               {
+                       // its a float or double
+                       curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, 
it->first.c_str(), CURLFORM_COPYCONTENTS, 
StringConverter::toString((float)it->second.valueFlt).c_str(), CURLFORM_END);
+               }
+       }
+
+ 
+
        CURLcode res;
        CURL *curl = curl_easy_init();
        if(!curl)
@@ -1196,6 +1242,8 @@
        /* we pass our 'chunk' struct to the callback function */ 
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
  
+       // set post options
+       curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
 
        // logging stuff
        //curl_easy_setopt(curl, CURLOPT_STDERR,           LogManager::getsin 
InstallerLog::getSingleton()->getLogFilePtr());
@@ -1217,6 +1265,7 @@
 
        //printf("%lu bytes retrieved\n", (long)chunk.size);
 
+       curl_formfree(formpost);
 
        if(chunk.memory)
        {

Modified: trunk/source/main/ScriptEngine.h
===================================================================
--- trunk/source/main/ScriptEngine.h    2011-01-30 17:33:58 UTC (rev 1611)
+++ trunk/source/main/ScriptEngine.h    2011-01-30 20:46:16 UTC (rev 1612)
@@ -32,6 +32,8 @@
 #include "Ogre.h"
 #include "rormemory.h"
 
+#include "scriptdictionary/scriptdictionary.h"
+
 #include "collisions.h"
 
 //forward decl.
@@ -39,7 +41,7 @@
 class GameScript;
 class Beam;
 
-#define AS_INTERFACE_VERSION "0.1.0" //!< versioning for the scripting 
interface
+#define AS_INTERFACE_VERSION "0.2.0" //!< versioning for the scripting 
interface
 
 #ifdef USE_CURL
 
@@ -335,7 +337,8 @@
        int setMaterialEmissive(const std::string &materialName, float red, 
float green, float blue);
        
        float rangeRandom(float from, float to);
-       int useOnlineAPI(const std::string &apiquery, std::string &result);
+       int useOnlineAPI(const std::string &apiquery, const 
AngelScript::CScriptDictionary &dict, std::string &result);
+       int getLoadedTerrain(std::string &result);
        Ogre::Vector3 getPersonPosition();
 };
 

Modified: trunk/source/main/SoundScriptManager.cpp
===================================================================
--- trunk/source/main/SoundScriptManager.cpp    2011-01-30 17:33:58 UTC (rev 
1611)
+++ trunk/source/main/SoundScriptManager.cpp    2011-01-30 20:46:16 UTC (rev 
1612)
@@ -99,6 +99,7 @@
        for (int i=0; i<free_gains[mod]; i++)
        {
                SoundScriptInstance* inst=gains[mod+i*SS_MAX_MOD];
+               if(!inst) continue;
                if (inst->truck==truck)
                {
                        //this one requires modulation
@@ -111,6 +112,7 @@
        for (int i=0; i<free_pitches[mod]; i++)
        {
                SoundScriptInstance* inst=pitches[mod+i*SS_MAX_MOD];
+               if(!inst) continue;
                if (inst->truck==truck)
                {
                        //this one requires modulation

Modified: trunk/source/main/engine.cpp
===================================================================
--- trunk/source/main/engine.cpp        2011-01-30 17:33:58 UTC (rev 1611)
+++ trunk/source/main/engine.cpp        2011-01-30 20:46:16 UTC (rev 1612)
@@ -120,9 +120,13 @@
        {
                //air pressure
                apressure+=dt*curEngineRPM;
+               if (apressure>50000.0 && ssm)
+               {
 #ifdef USE_OPENAL
-               if (apressure>50000.0 && ssm) {ssm->trigOnce(trucknum, 
SS_TRIG_AIR_PURGE); apressure=0;};
+                       ssm->trigOnce(trucknum, SS_TRIG_AIR_PURGE);
 #endif //OPENAL
+                       apressure=0;
+               };
        }
        if (hasturbo)
        {
@@ -267,39 +271,44 @@
        updateAudio(doUpdate);
 }
 
-void BeamEngine::updateAudio(int doUpdate)
+void BeamEngine::updateAudio(int doUpdate) // updates more, just not sound, 
misleading!
 {
 #ifdef USE_OPENAL
-       
-       // check if we have audio now instead of multiple places
-       if( !ssm ) return;
-       
-       if (hasturbo) ssm->modulate(trucknum, SS_MOD_TURBO, curTurboRPM);
+       if (hasturbo && ssm) ssm->modulate(trucknum, SS_MOD_TURBO, curTurboRPM);
+#endif //OPENAL
+
        if (doUpdate)
        {
-               ssm->modulate(trucknum, SS_MOD_ENGINE, curEngineRPM);
-               ssm->modulate(trucknum, SS_MOD_TORQUE, curClutchTorque);
-               ssm->modulate(trucknum, SS_MOD_GEARBOX, curGearboxRPM);
+#ifdef USE_OPENAL
+               if(ssm) ssm->modulate(trucknum, SS_MOD_ENGINE, curEngineRPM);
+               if(ssm) ssm->modulate(trucknum, SS_MOD_TORQUE, curClutchTorque);
+               if(ssm) ssm->modulate(trucknum, SS_MOD_GEARBOX, curGearboxRPM);
+#endif //OPENAL
                //gear hack
                if (curGear<0 || automode!=AUTOMATIC) return;
                
                if (!shifting && !postshifting && autoselect == DRIVE)
                {
-                       if(curEngineRPM > maxRPM-100.0 && curGear < numGears ) 
shift(1);
-                       else if(curEngineRPM < iddleRPM && curGear > 1 ) 
shift(-1);
+                       if(curEngineRPM > maxRPM-100.0 && curGear < numGears )
+                               shift(1);
+                       else if(curEngineRPM < iddleRPM && curGear > 1 )
+                               shift(-1);
                }
                
        }
        // reverse gear beep
        if (curGear==-1 && running) 
        {
-               ssm->trigStart(trucknum, SS_TRIG_REVERSE_GEAR);
+#ifdef USE_OPENAL
+               if(ssm) ssm->trigStart(trucknum, SS_TRIG_REVERSE_GEAR);
+#endif //OPENAL
        }
        else
        {
-               ssm->trigStop(trucknum, SS_TRIG_REVERSE_GEAR);
+#ifdef USE_OPENAL
+               if(ssm) ssm->trigStop(trucknum, SS_TRIG_REVERSE_GEAR);
+#endif //OPENAL
        }
-#endif //OPENAL
        
 }
 
@@ -412,8 +421,10 @@
 {
        contact=!contact;
 #ifdef USE_OPENAL
-       if (contact && ssm) ssm->trigStart(trucknum, SS_TRIG_IGNITION);
-       else if(ssm) ssm->trigStop(trucknum, SS_TRIG_IGNITION);
+       if (contact && ssm)
+               ssm->trigStart(trucknum, SS_TRIG_IGNITION);
+       else if(ssm)
+               ssm->trigStop(trucknum, SS_TRIG_IGNITION);
 #endif //OPENAL
 }
 
@@ -446,9 +457,11 @@
        running=1;
        contact=1;
 #ifdef USE_OPENAL
-       if(ssm) ssm->trigStart(trucknum, SS_TRIG_IGNITION);
+       if(ssm)
+               ssm->trigStart(trucknum, SS_TRIG_IGNITION);
        setAcc(0);
-       if(ssm) ssm->trigStart(trucknum, SS_TRIG_ENGINE);
+       if(ssm)
+               ssm->trigStart(trucknum, SS_TRIG_ENGINE);
 #endif //OPENAL
 }
 

Modified: trunk/source/main/gui_manager.cpp
===================================================================
--- trunk/source/main/gui_manager.cpp   2011-01-30 17:33:58 UTC (rev 1611)
+++ trunk/source/main/gui_manager.cpp   2011-01-30 20:46:16 UTC (rev 1612)
@@ -24,6 +24,7 @@
 #include "Settings.h"
 #include "language.h"
 #include <MyGUI_OgrePlatform.h>
+#include <MyGUI_LanguageManager.h>
 
 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
 #      include <windows.h>
@@ -128,7 +129,7 @@
 
 void GUIManager::eventRequestTag(const MyGUI::UString& _tag, MyGUI::UString& 
_result)
 {
-       _result = LanguageEngine::Instance().lookUp(_tag);
+       _result = MyGUI::LanguageManager::getInstance().getTag(_tag);
 }
 
 void GUIManager::injectMouseMove(int _absx, int _absy, int _absz)


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

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to