Revision: 1532
http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1532&view=rev
Author: rorthomas
Date: 2010-08-24 01:01:39 +0000 (Tue, 24 Aug 2010)
Log Message:
-----------
scripting improvements:
http://wiki.rigsofrods.com/pages/Introduction_to_Event_Scripting
Modified Paths:
--------------
trunk/source/main/RoRFrameListener.cpp
trunk/source/main/RoRFrameListener.h
trunk/source/main/ScriptEngine.cpp
trunk/source/main/ScriptEngine.h
trunk/source/main/collisions.cpp
trunk/source/main/collisions.h
Modified: trunk/source/main/RoRFrameListener.cpp
===================================================================
--- trunk/source/main/RoRFrameListener.cpp 2010-08-23 11:03:41 UTC (rev
1531)
+++ trunk/source/main/RoRFrameListener.cpp 2010-08-24 01:01:39 UTC (rev
1532)
@@ -1835,7 +1835,7 @@
rotating=false;
virt=false;
forcecam=false;
- event_filter=EVENT_ALL;
+ event_filter=EVENT_NONE;
eventname[0]=0;
collmesh[0]=0;
gm = collisions->getGroundModelByString("concrete");
@@ -1843,7 +1843,7 @@
};
if (!strncmp("boxcoords", ptline, 9))
{
- sscanf(ptline, "boxcoords %f, %f, %f, %f, %f,
%f",&lx,&hx,&ly, &hy,&lz, &hz);
+ sscanf(ptline, "boxcoords %f, %f, %f, %f, %f,
%f",&lx,&hx,&ly,&hy,&lz, &hz);
continue;
}
if (!strncmp("mesh", ptline, 4))
@@ -1904,12 +1904,38 @@
}
if (!strcmp("endmesh", ptline))
{
- //oookay
- static int colmeshcounter = 0;
- colmeshcounter++;
- char colmeshname[255]="";
- sprintf(colmeshname, "collision_mesh_%d",
colmeshcounter);
- Entity *ent = mSceneMgr->createEntity(colmeshname,
collmesh);
+ // check if this is an event box:
+ if((SETTINGS.getSetting("Debug Event Boxes") == "Yes")
&& virt && event_filter != EVENT_NONE)
+ {
+ // load mesh, find bounds, add collision box,
discard mesh
+ Entity *ent = mSceneMgr->createEntity(collmesh);
+ AxisAlignedBox bounds = ent->getBoundingBox();
+
+ Vector3 min = bounds.getMinimum();
+ Vector3 max = bounds.getMaximum();
+
+ // add event box
+ collisions->addCollisionBox(tenode, rotating,
virt,
px,py,pz,rx,ry,rz,min.x,max.x,min.y,max.y,min.z,max.z,srx,sry,srz,eventname,
instancename, forcecam, Vector3(fcx, fcy, fcz), scx, scy, scz, drx, dry, drz,
event_filter, luahandler);
+
+ if(debugCollisions)
+ {
+ ent->setMaterialName("tracks/transred");
+ SceneNode
*colbakenode=mSceneMgr->getRootSceneNode()->createChildSceneNode();
+ colbakenode->attachObject(ent);
+
colbakenode->setPosition(Vector3(px,py,pz));
+
colbakenode->setOrientation(tenode->getOrientation());
+ colbakenode->showBoundingBox(true);
+ } else
+ {
+ mSceneMgr->destroyEntity(ent);
+ }
+
+
+
+
+ }
+ // normal, non virtual collision box
+ Entity *ent = mSceneMgr->createEntity(collmesh);
ent->setMaterialName("tracks/transred");
size_t vertex_count,index_count;
@@ -1929,7 +1955,7 @@
delete[] indices;
if(!debugCollisions)
{
- mSceneMgr->destroyEntity(colmeshname);
+ mSceneMgr->destroyEntity(ent);
} else
{
SceneNode
*colbakenode=mSceneMgr->getRootSceneNode()->createChildSceneNode();
Modified: trunk/source/main/RoRFrameListener.h
===================================================================
--- trunk/source/main/RoRFrameListener.h 2010-08-23 11:03:41 UTC (rev
1531)
+++ trunk/source/main/RoRFrameListener.h 2010-08-24 01:01:39 UTC (rev
1532)
@@ -104,11 +104,12 @@
#define RELOADING 5
#define EDITOR_PAUSE 6
-#define EVENT_ALL 0
-#define EVENT_AVATAR 1
-#define EVENT_TRUCK 2
-#define EVENT_AIRPLANE 3
-#define EVENT_DELETE 4
+#define EVENT_NONE 0
+#define EVENT_ALL 1
+#define EVENT_AVATAR 2
+#define EVENT_TRUCK 3
+#define EVENT_AIRPLANE 4
+#define EVENT_DELETE 5
#define DEFAULT_INTERNAL_CAM_PITCH Degree(-15)
Modified: trunk/source/main/ScriptEngine.cpp
===================================================================
--- trunk/source/main/ScriptEngine.cpp 2010-08-23 11:03:41 UTC (rev 1531)
+++ trunk/source/main/ScriptEngine.cpp 2010-08-24 01:01:39 UTC (rev 1532)
@@ -113,7 +113,7 @@
// get some other optional functions
frameStepFunctionPtr = mod->GetFunctionIdByDecl("void
frameStep(float)");
- wheelEventFunctionPtr = mod->GetFunctionIdByDecl("void wheelEvents(int,
string, string)");
+ wheelEventFunctionPtr = mod->GetFunctionIdByDecl("void wheelEvents(int,
string, string, string)");
eventCallbackFunctionPtr = mod->GetFunctionIdByDecl("void
eventCallback(int, int)");
@@ -123,7 +123,7 @@
//context->SetLineCallback(asMETHOD(ScriptEngine,LineCallback), this,
asCALL_THISCALL);
// this does not work :(
-
//context->SetExceptionCallback(asMETHOD(ScriptEngine,ExceptionCallback), this,
asCALL_THISCALL);
+ context->SetExceptionCallback(asMETHOD(ScriptEngine,ExceptionCallback),
this, asCALL_THISCALL);
context->Prepare(funcId);
LogManager::getSingleton().logMessage("SE| Executing main()");
@@ -593,7 +593,7 @@
int ScriptEngine::framestep(Ogre::Real dt, Beam **trucks, int free_truck)
{
// check for all truck wheels
- if(coll && wheelEventFunctionPtr != -1)
+ if(coll && wheelEventFunctionPtr >= 0)
{
for(int t = 0; t < free_truck; t++)
{
@@ -626,8 +626,9 @@
// Set the function arguments
context->SetArgFloat (0, t);
- context->SetArgObject(1,
&std::string(source->instancename));
- context->SetArgObject(2,
&std::string(source->boxname));
+ context->SetArgObject(1,
&std::string("wheels"));
+ context->SetArgObject(2,
&std::string(source->instancename));
+ context->SetArgObject(3,
&std::string(source->boxname));
//LogManager::getSingleton().logMessage("SE|
Executing framestep()");
int r = context->Execute();
@@ -640,6 +641,13 @@
}
}
+ // check if current truck is in an event box
+ Beam *truck = mefl->getCurrentTruck();
+ if(truck)
+ {
+ eventsource_t *source = coll->isTruckInEventBox(truck);
+ if(source) envokeCallback(source->luahandler, source, 0, 1);
+ }
// framestep stuff below
if(frameStepFunctionPtr<0) return 1;
@@ -661,7 +669,7 @@
}
-int ScriptEngine::envokeCallback(int functionPtr, eventsource_t *source,
node_t *node)
+int ScriptEngine::envokeCallback(int functionPtr, eventsource_t *source,
node_t *node, int type)
{
if(functionPtr<=0) return 1;
if(!engine) return 0;
@@ -669,14 +677,14 @@
context->Prepare(functionPtr);
// Set the function arguments
- context->SetArgObject(0, &std::string(source->instancename));
- context->SetArgObject(1, &std::string(source->boxname));
+ context->SetArgDWord (0, type);
+ context->SetArgObject(1, &std::string(source->instancename));
+ context->SetArgObject(2, &std::string(source->boxname));
if(node)
- context->SetArgDWord (2, node->id);
+ context->SetArgDWord (3, node->id);
else
- context->SetArgDWord (2, -1);
+ context->SetArgDWord (3, -1);
- //LogManager::getSingleton().logMessage("SE| Executing framestep()");
int r = context->Execute();
if( r == asEXECUTION_FINISHED )
{
Modified: trunk/source/main/ScriptEngine.h
===================================================================
--- trunk/source/main/ScriptEngine.h 2010-08-23 11:03:41 UTC (rev 1531)
+++ trunk/source/main/ScriptEngine.h 2010-08-24 01:01:39 UTC (rev 1532)
@@ -122,7 +122,7 @@
*/
int executeString(Ogre::String command);
- int envokeCallback(int functionPtr, eventsource_t *source, node_t
*node);
+ int envokeCallback(int functionPtr, eventsource_t *source, node_t
*node=0, int type=0);
AngelScript::asIScriptEngine *getEngine() { return engine; };
Modified: trunk/source/main/collisions.cpp
===================================================================
--- trunk/source/main/collisions.cpp 2010-08-23 11:03:41 UTC (rev 1531)
+++ trunk/source/main/collisions.cpp 2010-08-24 01:01:39 UTC (rev 1532)
@@ -108,6 +108,7 @@
{
landuse=0;
debugMode=_debugMode;
+ debugModeEvents = SETTINGS.getSetting("Debug Event Boxes") == "Yes";
last_used_ground_model=0;
#ifdef USE_LUA
lua=mlua;
@@ -619,6 +620,67 @@
collision_boxes[free_collision_box].lo_z=pz+lz*scz;
collision_boxes[free_collision_box].hi_z=pz+hz*scz;
}
+
+ if(debugModeEvents && virt)
+ {
+ collision_box_t *cb = &collision_boxes[free_collision_box];
+ Entity *ent = mefl->getSceneMgr()->createEntity("beam.mesh");
+ SceneNode *n =
mefl->getSceneMgr()->getRootSceneNode()->createChildSceneNode();
+ n->attachObject(ent);
+ if(luahandler == -1)
+ ent->setMaterialName("tracks/transred");
+ else
+ ent->setMaterialName("tracks/transgreen");
+ // since beam.mesh origin is in its middle ...
+ n->setPosition(
+ cb->lo_x + (cb->hi_x - cb->lo_x) * 0.5f,
+ cb->lo_y + (cb->hi_y - cb->lo_y) * 0.5f,
+ cb->lo_z + (cb->hi_z - cb->lo_z) * 0.5f
+ );
+ n->setScale(
+ (cb->hi_x - cb->lo_x),
+ (cb->hi_y - cb->lo_y),
+ (cb->hi_z - cb->lo_z)
+ );
+ n->setVisible(true);
+ n->showBoundingBox(true);
+
+ // setup the label
+ String labelName =
"collision_box_label_"+StringConverter::toString(free_collision_box);
+ String labelCaption = String(eventname) + " / " +
String(instancename) + " / " + StringConverter::toString(luahandler);
+ MovableText *mt = new MovableText(labelName, labelCaption);
+ mt->setFontName("highcontrast_black");
+ mt->setTextAlignment(MovableText::H_CENTER,
MovableText::V_ABOVE);
+ mt->setAdditionalHeight(1);
+ mt->showOnTop(false);
+ mt->setCharacterHeight(0.3);
+ mt->setColor(ColourValue::White);
+ SceneNode *n2 =
mefl->getSceneMgr()->getRootSceneNode()->createChildSceneNode();
+ n2->attachObject(mt);
+ n2->setPosition(
+ cb->lo_x + (cb->hi_x - cb->lo_x) * 0.5f,
+ cb->lo_y + (cb->hi_y - cb->lo_y) * 0.5f,
+ cb->lo_z + (cb->hi_z - cb->lo_z) * 0.5f
+ );
+
+ ManualObject* manual =
mefl->getSceneMgr()->createManualObject("collision_boxes_debug_"+StringConverter::toString(free_collision_box));
+ manual->setDynamic(false);
+ if(luahandler == -1)
+ manual->begin("tracks/transred",
RenderOperation::OT_LINE_LIST);
+ else
+ manual->begin("tracks/transgreen",
RenderOperation::OT_LINE_LIST);
+
+ // specify indexes now
+ manual->position(Vector3::ZERO);
+ manual->position(Vector3((cb->hi_x - cb->lo_x), (cb->hi_y -
cb->lo_y), (cb->hi_z - cb->lo_z)));
+ manual->index(0);
+ manual->index(1);
+ manual->end();
+ SceneNode *n3 =
mefl->getSceneMgr()->getRootSceneNode()->createChildSceneNode();
+ n3->attachObject(manual);
+ n3->setPosition(Vector3(cb->lo_x, cb->lo_y, cb->lo_z));
+ }
+
//
collision_boxes[free_collision_box].camerapos+=Vector3(px,py,pz);
//register this collision box in the index
int ilox, ihix, iloz, ihiz;
@@ -1198,6 +1260,34 @@
return NULL;
}
+eventsource_t *Collisions::isTruckInEventBox(Beam *truck)
+{
+ if(!truck) return 0;
+ // check all boxes
+ for (int i=0; i<free_eventsource; i++)
+ {
+ collision_box_t *cb = &collision_boxes[eventsources[i].cbox];
+ // check all nodes
+
+ bool allInside = true;
+ for (int i=0; i < truck->free_node; i++)
+ {
+ if (!isInside(truck->nodes[i].AbsPosition, cb))
+ {
+ // node not in box, no need to check the rest
+ allInside=false;
+ break;
+ }
+ }
+ if(allInside && cb->eventsourcenum != -1)
+ {
+ return &eventsources[cb->eventsourcenum];
+ }
+
+ }
+ return 0;
+}
+
bool Collisions::isInside(Vector3 pos, char* instance, char* box, float border)
{
Modified: trunk/source/main/collisions.h
===================================================================
--- trunk/source/main/collisions.h 2010-08-23 11:03:41 UTC (rev 1531)
+++ trunk/source/main/collisions.h 2010-08-24 01:01:39 UTC (rev 1532)
@@ -133,6 +133,7 @@
int collision_count;
int largest_cellcount;
bool debugMode;
+ bool debugModeEvents;
Landusemap *landuse;
private:
@@ -166,6 +167,7 @@
Vector3 getPosition(char* instance, char* box);
Quaternion getDirection(char* instance, char* box);
collision_box_t *getBox(char* instance, char* box);
+ eventsource_t *Collisions::isTruckInEventBox(Beam *truck);
bool isInside(Vector3 pos, char* instance, char* box, float border=0);
bool isInside(Vector3 pos, collision_box_t *cbox, float border=0);
bool groundCollision(node_t *node, float dt, ground_model_t** gm, float
*nso=0);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel