Revision: 1529
http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1529&view=rev
Author: rorthomas
Date: 2010-08-22 22:17:15 +0000 (Sun, 22 Aug 2010)
Log Message:
-----------
scriptengine improved
Modified Paths:
--------------
trunk/source/main/RoRFrameListener.cpp
trunk/source/main/RoRFrameListener.h
trunk/source/main/ScriptEngine.cpp
trunk/source/main/ScriptEngine.h
Modified: trunk/source/main/RoRFrameListener.cpp
===================================================================
--- trunk/source/main/RoRFrameListener.cpp 2010-08-22 20:06:24 UTC (rev
1528)
+++ trunk/source/main/RoRFrameListener.cpp 2010-08-22 22:17:15 UTC (rev
1529)
@@ -1642,7 +1642,21 @@
return mfilename;
}
+void RoRFrameListener::unloadObject(const char* instancename)
+{
+ if(loadedObjects.find(std::string(instancename)) == loadedObjects.end())
+ {
+ LogManager::getSingleton().logMessage("unable to unload object:
" + std::string(instancename));
+ return;
+ }
+ // TODO: proper unloading with unloading of the collision things
+
+ Ogre::SceneNode *node = loadedObjects[std::string(instancename)];
+ node->detachAllObjects();
+ node->setVisible(false);
+}
+
void RoRFrameListener::loadObject(const char* name, float px, float py, float
pz, float rx, float ry, float rz, SceneNode * bakeNode, const char*
instancename, bool enable_collisions, int luahandler, const char *type, bool
uniquifyMaterial)
{
ScopeLog log("object_"+String(name));
@@ -1731,6 +1745,7 @@
sprintf(oname,"object%i(%s)", objcounter,name);
objcounter++;
+
SceneNode *tenode =
mSceneMgr->getRootSceneNode()->createChildSceneNode();
MeshObject *mo = new MeshObject(mScene, mesh, oname, tenode);
//mo->setQueryFlags(OBJECTS_MASK);
@@ -1741,6 +1756,10 @@
tenode->pitch(Degree(-90));
tenode->setVisible(true);
+ // register in map
+ loadedObjects[std::string(instancename)] = tenode;
+
+
if(uniquifyMaterial && instancename)
{
for(unsigned int i = 0; i <
mo->getEntity()->getNumSubEntities(); i++)
Modified: trunk/source/main/RoRFrameListener.h
===================================================================
--- trunk/source/main/RoRFrameListener.h 2010-08-22 20:06:24 UTC (rev
1528)
+++ trunk/source/main/RoRFrameListener.h 2010-08-22 22:17:15 UTC (rev
1529)
@@ -218,6 +218,7 @@
int loading_state;
+ std::map< std::string, Ogre::SceneNode *> loadedObjects;
DOFManager *mDOF;
bool mDOFDebug;
int mouseX;
@@ -312,6 +313,7 @@
void removeBeam(Beam *);
void removeTruck(int truck);
void loadObject(const char* name, float px, float py, float pz, float
rx, float ry, float rz, SceneNode * bakeNode, const char* instancename, bool
enable_collisions=true, int luahandler=-1, const char *type=0, bool
uniquifyMaterial=false);
+ void unloadObject(const char* name);
void repairTruck(char* inst, char* box);
void removeTruck(char* inst, char* box);
bool updateEvents(float dt);
Modified: trunk/source/main/ScriptEngine.cpp
===================================================================
--- trunk/source/main/ScriptEngine.cpp 2010-08-22 20:06:24 UTC (rev 1528)
+++ trunk/source/main/ScriptEngine.cpp 2010-08-22 22:17:15 UTC (rev 1529)
@@ -457,6 +457,7 @@
result = engine->RegisterObjectMethod("GameScriptClass", "void
setCaelumTime(float)", asMETHOD(GameScript,setCaelumTime), asCALL_THISCALL);
assert(result>=0);
result = engine->RegisterObjectMethod("GameScriptClass", "void
setWaterHeight(float)", asMETHOD(GameScript,setWaterHeight), asCALL_THISCALL);
assert(result>=0);
result = engine->RegisterObjectMethod("GameScriptClass", "float
getWaterHeight()", asMETHOD(GameScript,getWaterHeight), asCALL_THISCALL);
assert(result>=0);
+ result = engine->RegisterObjectMethod("GameScriptClass", "float
getGroundHeight(vector3)", asMETHOD(GameScript,getGroundHeight),
asCALL_THISCALL); assert(result>=0);
result = engine->RegisterObjectMethod("GameScriptClass", "int
getCurrentTruckNumber()", asMETHOD(GameScript,getCurrentTruckNumber),
asCALL_THISCALL); assert(result>=0);
result = engine->RegisterObjectMethod("GameScriptClass", "int
getNumTrucks()", asMETHOD(GameScript,getNumTrucks), asCALL_THISCALL);
assert(result>=0);
result = engine->RegisterObjectMethod("GameScriptClass", "float
getGravity()", asMETHOD(GameScript,getGravity), asCALL_THISCALL);
assert(result>=0);
@@ -471,7 +472,8 @@
result = engine->RegisterObjectMethod("GameScriptClass", "void
setChatFontSize(int)", asMETHOD(GameScript,setChatFontSize), asCALL_THISCALL);
assert(result>=0);
result = engine->RegisterObjectMethod("GameScriptClass", "void
showChooser(const string &in, const string &in, const string &in)",
asMETHOD(GameScript,showChooser), asCALL_THISCALL); assert(result>=0);
result = engine->RegisterObjectMethod("GameScriptClass", "void
repairVehicle(const string &in, const string &in)",
asMETHOD(GameScript,repairVehicle), asCALL_THISCALL); assert(result>=0);
- result = engine->RegisterObjectMethod("GameScriptClass", "void
spawnObject(const string &in, const string &in, float, float, float, float,
float, float, const string &in, bool)", asMETHOD(GameScript,spawnObject),
asCALL_THISCALL); assert(result>=0);
+ result = engine->RegisterObjectMethod("GameScriptClass", "void
spawnObject(const string &in, const string &in, vector3, vector3, const string
&in, bool)", asMETHOD(GameScript,spawnObject), asCALL_THISCALL);
assert(result>=0);
+ result = engine->RegisterObjectMethod("GameScriptClass", "void
destroyObject(const string &in)", asMETHOD(GameScript,destroyObject),
asCALL_THISCALL); assert(result>=0);
result = engine->RegisterObjectMethod("GameScriptClass", "int
setMaterialAmbient(const string &in, float, float, float)",
asMETHOD(GameScript,setMaterialAmbient), asCALL_THISCALL); assert(result>=0);
result = engine->RegisterObjectMethod("GameScriptClass", "int
setMaterialDiffuse(const string &in, float, float, float, float)",
asMETHOD(GameScript,setMaterialDiffuse), asCALL_THISCALL); assert(result>=0);
result = engine->RegisterObjectMethod("GameScriptClass", "int
setMaterialSpecular(const string &in, float, float, float, float)",
asMETHOD(GameScript,setMaterialSpecular), asCALL_THISCALL); assert(result>=0);
@@ -854,6 +856,13 @@
if(mefl && mefl->w) mefl->w->setHeight(value);
}
+float GameScript::getGroundHeight(Ogre::Vector3 v)
+{
+ if(RoRFrameListener::hfinder)
+ return RoRFrameListener::hfinder->getHeightAt(v.x, v.z);
+ return -1;
+}
+
float GameScript::getWaterHeight()
{
if(mefl && mefl->w) return mefl->w->getHeight();
@@ -960,8 +969,12 @@
mefl->repairTruck(const_cast<char*>(instance.c_str()),
const_cast<char*>(box.c_str()));
}
+void GameScript::destroyObject(const std::string &instanceName)
+{
+ mefl->unloadObject(const_cast<char*>(instanceName.c_str()));
+}
-void GameScript::spawnObject(const std::string &objectName, const std::string
&instanceName, float px, float py, float pz, float rx, float ry, float rz,
const std::string &eventhandler, bool uniquifyMaterials)
+void GameScript::spawnObject(const std::string &objectName, const std::string
&instanceName, Ogre::Vector3 pos, Ogre::Vector3 rot, const std::string
&eventhandler, bool uniquifyMaterials)
{
asIScriptModule *mod=0;
try
@@ -976,7 +989,7 @@
// trying to create the new object
SceneNode
*bakeNode=mefl->getSceneMgr()->getRootSceneNode()->createChildSceneNode();
- mefl->loadObject(const_cast<char*>(objectName.c_str()), px, py, pz, rx,
ry, rz, bakeNode, const_cast<char*>(instanceName.c_str()), true, functionPtr,
const_cast<char*>(objectName.c_str()), uniquifyMaterials);
+ mefl->loadObject(const_cast<char*>(objectName.c_str()), pos.x, pos.y,
pos.z, rot.x, rot.y, rot.z, bakeNode, const_cast<char*>(instanceName.c_str()),
true, functionPtr, const_cast<char*>(objectName.c_str()), uniquifyMaterials);
}
void GameScript::hideDirectionArrow()
Modified: trunk/source/main/ScriptEngine.h
===================================================================
--- trunk/source/main/ScriptEngine.h 2010-08-22 20:06:24 UTC (rev 1528)
+++ trunk/source/main/ScriptEngine.h 2010-08-22 22:17:15 UTC (rev 1529)
@@ -231,6 +231,8 @@
*/
float getWaterHeight();
+ float getGroundHeight(Ogre::Vector3 v);
+
/**
* sets the base water height
* @param value base height in meters
@@ -307,7 +309,8 @@
// new things, not documented yet
void showChooser(std::string &type, std::string &instance, std::string
&box);
void repairVehicle(std::string &instance, std::string &box);
- void spawnObject(const std::string &objectName, const std::string
&instanceName, float px, float py, float pz, float rx, float ry, float rz,
const std::string &eventhandler, bool uniquifyMaterials);
+ void spawnObject(const std::string &objectName, const std::string
&instanceName, Ogre::Vector3 pos, Ogre::Vector3 rot, const std::string
&eventhandler, bool uniquifyMaterials);
+ void destroyObject(const std::string &instanceName);
int getNumTrucksByFlag(int flag);
bool getCaelumAvailable();
void stopTimer();
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