Revision: 1610
http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1610&view=rev
Author: rorthomas
Date: 2011-01-30 15:38:18 +0000 (Sun, 30 Jan 2011)
Log Message:
-----------
fixed major performance problem with scripted eventboxes, no more FPS loss now
:)
Modified Paths:
--------------
trunk/source/main/collisions.cpp
trunk/source/main/collisions.h
Modified: trunk/source/main/collisions.cpp
===================================================================
--- trunk/source/main/collisions.cpp 2011-01-30 15:30:13 UTC (rev 1609)
+++ trunk/source/main/collisions.cpp 2011-01-30 15:38:18 UTC (rev 1610)
@@ -122,6 +122,7 @@
, landuse(0)
, forcecam(false)
, last_used_ground_model(0)
+, last_called_cbox(0)
{
for (int i=0; i<HASH_SIZE; i++) {hashmask=hashmask<<1; hashmask++;};
for (int i=0; i<(1<<HASH_SIZE); i++) hashtable[i].cellid=UNUSED_CELLID;
@@ -717,7 +718,28 @@
}
+bool Collisions::envokeScriptCallback(collision_box_t *cbox, node_t *node)
+{
+ bool handled = false;
+
+ // this prevents that the same callback gets called at 2k FPS all the
time, serious hit on FPS ...
+ if(last_called_cbox != cbox)
+ {
+ // prefer AS to LUA
+#ifdef USE_ANGELSCRIPT
+ int ret =
ScriptEngine::getSingleton().envokeCallback(eventsources[cbox->eventsourcenum].luahandler,
&eventsources[cbox->eventsourcenum], node);
+ if(ret == 0)
+ handled=true;
+#endif //USE_ANGELSCRIPT
+#ifdef USE_LUA
+ if(!handled)
+ lua->spawnEvent(cbox->eventsourcenum,
&eventsources[cbox->eventsourcenum]);
+#endif // USE_LUA
+ last_called_cbox = cbox;
+ }
+ return handled;
+}
bool Collisions::collisionCorrect(Vector3 *refpos)
{
//find the correct cell
@@ -759,17 +781,8 @@
{
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], 0);
- if(ret == 0)
- handled=true;
-#endif
-#ifdef USE_LUA
- if(!handled)
-
lua->spawnEvent(cbox->eventsourcenum, &eventsources[cbox->eventsourcenum]);
-#endif
+
+
}
if (cbox->camforced && !forcecam)
{
@@ -800,17 +813,7 @@
{
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], 0);
- if(ret == 0)
- handled=true;
-#endif
-#ifdef USE_LUA
- if(!handled)
-
lua->spawnEvent(cbox->eventsourcenum, &eventsources[cbox->eventsourcenum]);
-#endif
+ envokeScriptCallback(cbox);
}
if (cbox->camforced && !forcecam)
{
@@ -927,18 +930,7 @@
{
if
(cbox->eventsourcenum!=-1 && permitEvent(cbox->event_filter))
{
- // prefer AS to
LUA
- bool handled =
false;
- if(handlernum)
*handlernum = cbox->eventsourcenum;
-#ifdef USE_ANGELSCRIPT
- int ret =
ScriptEngine::getSingleton().envokeCallback(eventsources[cbox->eventsourcenum].luahandler,
&eventsources[cbox->eventsourcenum], node);
- if(ret == 0)
-
handled=true;
-#endif
-#ifdef USE_LUA
- if(!handled)
-
lua->spawnEvent(cbox->eventsourcenum, &eventsources[cbox->eventsourcenum]);
-#endif
+
envokeScriptCallback(cbox, node);
}
if (cbox->camforced &&
!forcecam)
{
@@ -983,18 +975,7 @@
{
if (cbox->eventsourcenum!=-1 &&
permitEvent(cbox->event_filter))
{
- // prefer AS to LUA
- bool handled = false;
- if(handlernum)
*handlernum = cbox->eventsourcenum;
-#ifdef USE_ANGELSCRIPT
- int ret =
ScriptEngine::getSingleton().envokeCallback(eventsources[cbox->eventsourcenum].luahandler,
&eventsources[cbox->eventsourcenum], node);
- if(ret == 0)
- handled=true;
-#endif
-#ifdef USE_LUA
- if(!handled)
-
lua->spawnEvent(cbox->eventsourcenum, &eventsources[cbox->eventsourcenum]);
-#endif
+
envokeScriptCallback(cbox, node);
}
if (cbox->camforced &&
!forcecam)
{
Modified: trunk/source/main/collisions.h
===================================================================
--- trunk/source/main/collisions.h 2011-01-30 15:30:13 UTC (rev 1609)
+++ trunk/source/main/collisions.h 2011-01-30 15:38:18 UTC (rev 1610)
@@ -119,10 +119,13 @@
std::vector<cell_t*> cells;//[MAX_CELLS];
int free_cell;
+ collision_box_t *last_called_cbox;
+
eventsource_t eventsources[MAX_EVENTSOURCE];
int free_eventsource;
bool permitEvent(int filter);
+ bool envokeScriptCallback(collision_box_t *cbox, node_t *node=0);
#ifdef USE_LUA
LuaSystem *lua;
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