[Yake-svn] SF.net SVN: yake: [1876] trunk/yake
Status: Beta
Brought to you by:
psyclonist
From: <psy...@us...> - 2007-09-22 21:19:38
|
Revision: 1876 http://yake.svn.sourceforge.net/yake/?rev=1876&view=rev Author: psyclonist Date: 2007-09-22 14:19:42 -0700 (Sat, 22 Sep 2007) Log Message: ----------- * [bindings.lua] fixed issue with binding of 'Entity.model' property (reported by BartoloB) * [bindings.lua] fixed trigger script to handle more than one entity Modified Paths: -------------- trunk/yake/common/media/scripts/o_trigger2.lua trunk/yake/src/bindings.lua/detail/model.lua.cpp Modified: trunk/yake/common/media/scripts/o_trigger2.lua =================================================================== --- trunk/yake/common/media/scripts/o_trigger2.lua 2007-09-18 00:53:17 UTC (rev 1875) +++ trunk/yake/common/media/scripts/o_trigger2.lua 2007-09-22 21:19:42 UTC (rev 1876) @@ -4,23 +4,49 @@ assert( sim.objMgr, "no obj mgr" ) local objs = sim.objMgr:getAllObjects() + -- For each object with a 'position' property we check + -- whether it intersects the trigger's volume(s). + -- Note: We suppose that 'position' always means the same + -- thing, namely a point in space (yake.Point3). + -- The script will stop/crash if a position property + -- has a different type! + -- TODO: Check whether the object is derived from 'Entity' + -- because the position property in this case always + -- is of type 'yake.Point3'. + local numIntersects = 0 + local toggled = false for id,ent in pairs(objs) do - if ent and id ~= this.id then -- ignore self, and non-Entity objects - local intersects = this.volumes:intersectsWith( ent.position ) + --TODO: if .. and ent.isA()->isKindOf("Entity") + local pos = ent.position -- pos will be 'nil' if property 'position' does not exist. + if ent and id ~= this.id and pos ~= nil then -- ignore self, and non-positioned objects + local intersects = this.volumes:intersectsWith( pos ) + if intersects then + numIntersects = numIntersects + 1 + end + -- The trigger is switched to 'on' when at least + -- one entity is in its volume. if not this.on and intersects then this:processFsmEvent("toggle") - elseif this.on and not intersects then - this:processFsmEvent("toggle") + toggled = true + break end end end + -- If no entity is in the trigger's volume(s) and the + -- trigger state is currently 'on' then we switch to + -- state 'off'. + -- Note: We check 'not toggled' to not undo the work of the + -- intersection loop above. + if not toggled and this.on and (numIntersects == 0) then + this:processFsmEvent("toggle") + end - --if filter then -- local filter = yake.ObjectFilter() -- filter:add( filterByClass("Player") ) -- filter:add( filterByClass("Entity",IgnoreDerived) ) -- filter.byClass("Player") - --end + -- local objs = objMgr:getAllObjects() + -- filter:apply(objs) end end function main() Modified: trunk/yake/src/bindings.lua/detail/model.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/model.lua.cpp 2007-09-18 00:53:17 UTC (rev 1875) +++ trunk/yake/src/bindings.lua/detail/model.lua.cpp 2007-09-22 21:19:42 UTC (rev 1876) @@ -46,6 +46,16 @@ namespace yake { namespace model { + //------------------------------------------------------------------------- + namespace { + struct AnyConverterIniter + { + AnyConverterIniter() + { + register_any_converter<model::ModelPtr>(); + } + } g_initer; + } // namespace Graphical* Model_createGraphical(Model& m) { Graphical* c = new Graphical(); @@ -62,13 +72,13 @@ YAKE_ASSERT(g); g->addSceneNode( node, path ); } - Model* ModelManager_createModel(ModelManager* mgr, const String& modelName, const String& def) + ModelPtr ModelManager_createModel(ModelManager* mgr, const String& modelName, const String& def) { - return (mgr ? mgr->createModel(modelName,def).get() : 0); + return (mgr ? mgr->createModel(modelName,def) : ModelPtr()); } - Model* ModelManager_createModelFromTemplate(ModelManager* mgr, const String& modelName, const String& tplName) + ModelPtr ModelManager_createModelFromTemplate(ModelManager* mgr, const String& modelName, const String& tplName) { - return (mgr ? mgr->createModelFromTemplate(modelName,tplName).get() : 0); + return (mgr ? mgr->createModelFromTemplate(modelName,tplName) : ModelPtr()); } bool ModelMovableLink_subscribeToPositionChanged(ModelMovableLink* link, const luabind::object& o) { @@ -146,7 +156,7 @@ class_<ModelMovableLink,ModelLink>( "ModelMovableLink" ) .def( "subscribeToPositionChanged", &ModelMovableLink_subscribeToPositionChanged) , - class_<Model>( "Model" ) + class_<Model,ModelPtr>( "Model" ) .def( constructor<>() ) .property( "name", &Model::getName, &Model::setName ) .def( "getName", &Model::getName ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |