yake-svn Mailing List for Yake Engine (Page 9)
Status: Beta
Brought to you by:
psyclonist
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(17) |
Sep
(51) |
Oct
(2) |
Nov
(18) |
Dec
(66) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(44) |
Feb
(13) |
Mar
(73) |
Apr
(61) |
May
|
Jun
(4) |
Jul
(19) |
Aug
(50) |
Sep
(47) |
Oct
(7) |
Nov
(7) |
Dec
(14) |
2008 |
Jan
(2) |
Feb
|
Mar
(4) |
Apr
(4) |
May
(5) |
Jun
(7) |
Jul
(4) |
Aug
|
Sep
(5) |
Oct
|
Nov
(1) |
Dec
(4) |
2009 |
Jan
|
Feb
(22) |
Mar
(12) |
Apr
(1) |
May
(1) |
Jun
(4) |
Jul
(4) |
Aug
|
Sep
|
Oct
(17) |
Nov
(3) |
Dec
|
2010 |
Jan
|
Feb
|
Mar
(12) |
Apr
(11) |
May
|
Jun
(5) |
Jul
(3) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <psy...@us...> - 2007-09-07 13:55:08
|
Revision: 1837 http://yake.svn.sourceforge.net/yake/?rev=1837&view=rev Author: psyclonist Date: 2007-09-07 06:55:12 -0700 (Fri, 07 Sep 2007) Log Message: ----------- * [Lua scripts] cleaned up entity scripts, introduced new property/event access syntax Modified Paths: -------------- trunk/yake/common/media/scripts/init_entity.lua trunk/yake/common/media/scripts/o_access.lua trunk/yake/common/media/scripts/o_entity.lua trunk/yake/common/media/scripts/o_trigger2.lua trunk/yake/common/media/scripts/raf2.lua Modified: trunk/yake/common/media/scripts/init_entity.lua =================================================================== --- trunk/yake/common/media/scripts/init_entity.lua 2007-09-05 22:59:19 UTC (rev 1836) +++ trunk/yake/common/media/scripts/init_entity.lua 2007-09-07 13:55:12 UTC (rev 1837) @@ -1,39 +1,3 @@ -print("> Starting init_entity.lua ..."); - --- replace loadfile and dofile with yake.loadfile and yake.dofile. --- the replacements use yake's resource system to locate the files. -yake.old_loadfile = loadfile -yake.old_dofile = dofile -loadfile = nil -dofile = nil -yake.dofile = function(path) - local locator = yake.res.global.sourceManager - assert( locator ~= nil, "global source manager not available" ) - local succ = locator:find(path) - print(succ) - assert( succ.valid, "could not locate file " .. tostring(path) ) - if succ.valid then - local f = yake.old_loadfile(succ.location) - assert( f ) - return f() -- execute! - end - return nil -end - - -print("* loading accessor scripts...") -yake.dofile("entitypropertyaccess.lua") -yake.dofile("entityeventaccess.lua") - -local no_implicit_creation = false - -properties = {} -wrapPropertiesTable(properties,this:properties(),no_implicit_creation) -assert( properties.accessor, "accessor not set" ) - -events = {} -wrapEventsTable(events,this:events(),no_implicit_creation) -assert( events.accessor, "accessor not set" ) - --- -print("> init_entity.lua done."); +--print("> Starting init_entity.lua ..."); +-- NOTHING TO DO +--print("> init_entity.lua done."); Modified: trunk/yake/common/media/scripts/o_access.lua =================================================================== --- trunk/yake/common/media/scripts/o_access.lua 2007-09-05 22:59:19 UTC (rev 1836) +++ trunk/yake/common/media/scripts/o_access.lua 2007-09-07 13:55:12 UTC (rev 1837) @@ -1,60 +1,5 @@ print("> Starting object script..."); -local vols = yake.VolumeContainer() -print("1") -local sphere = yake.Sphere(2) -print("2") -vols:add(sphere) -print("3") -local pt = yake.Point3(0,0,0) -print("4") -print(sphere:intersectsWith(pt)) -print("5") -print("numVols=",vols.size) -print("6") -print(vols:intersectsWith(pt)) -pt.x = 5 -print(vols:intersectsWith(pt)) -print("7") -print(sphere:intersectsWith(pt)) -print("done") --- replace loadfile and dofile with yake.loadfile and yake.dofile. --- the replacements use yake's resource system to locate the files. -yake.old_loadfile = loadfile -yake.old_dofile = dofile -loadfile = nil -dofile = nil -yake.dofile = function(path) - local locator = yake.res.global.sourceManager - assert( locator ~= nil, "global source manager not available" ) - local succ = locator:find(path) - print(succ) - assert( succ.valid, "could not locate file " .. tostring(path) ) - if succ.valid then - local f = yake.old_loadfile(succ.location) - assert( f ) - return f() -- execute! - end - return nil -end - - -print("* loading accessor scripts...") -yake.dofile("entitypropertyaccess.lua") -yake.dofile("entityeventaccess.lua") - ---local thisTrigger = yake.asTrigger(this) -local no_implicit_creation = false - -properties = {} -wrapPropertiesTable(properties,this:properties(),no_implicit_creation) -assert( properties.accessor, "accessor not set" ) - -events = {} -wrapEventsTable(events,this:events(),no_implicit_creation) -assert( events.accessor, "accessor not set" ) - --- function onTick() print(" script on_tick",properties.ticks) properties.ticks = properties.ticks + 1 @@ -71,17 +16,17 @@ end function startup() -- common ent::Object events - events.spawn:connect( function() print(" script on_spawn ") end ) - events.tick:connect( onTick ) - events.preDestroy:connect( function() print(" script on_preDestroy") end ) + this.events.spawn:connect( function() print(" script on_spawn ") end ) + this.events.tick:connect( onTick ) + this.events.preDestroy:connect( function() print(" script on_preDestroy") end ) -- ent::Trigger stuff - properties:create("ticks",0) -- create property of type 'number' + this.properties:create("ticks",0) -- create property of type 'number' this:setCondition(function() return (properties.ticks >= 1 and properties.ticks <= 3) end) - events.onTriggered:connect( function(a) print(" script on_triggered",a) end ) + this.events.onTriggered:connect( function(a) print(" script on_triggered",a) end ) -- VolumeTrigger stuff - properties:create("volumes", yake.VolumeContainer()) + this.properties:create("volumes", yake.VolumeContainer()) end print("> Object script up."); Modified: trunk/yake/common/media/scripts/o_entity.lua =================================================================== --- trunk/yake/common/media/scripts/o_entity.lua 2007-09-05 22:59:19 UTC (rev 1836) +++ trunk/yake/common/media/scripts/o_entity.lua 2007-09-07 13:55:12 UTC (rev 1837) @@ -1,47 +1,9 @@ print("> Starting object script..."); - --- replace loadfile and dofile with yake.loadfile and yake.dofile. --- the replacements use yake's resource system to locate the files. -yake.old_loadfile = loadfile -yake.old_dofile = dofile -loadfile = nil -dofile = nil -yake.dofile = function(path) - local locator = yake.res.global.sourceManager - assert( locator ~= nil, "global source manager not available" ) - local succ = locator:find(path) - print(succ) - assert( succ.valid, "could not locate file " .. tostring(path) ) - if succ.valid then - local f = yake.old_loadfile(succ.location) - assert( f ) - return f() -- execute! - end - return nil -end - - -print("* loading accessor scripts...") -yake.dofile("entitypropertyaccess.lua") -yake.dofile("entityeventaccess.lua") - ---local thisTrigger = yake.asTrigger(this) -local no_implicit_creation = false - -properties = {} -wrapPropertiesTable(properties,this:properties(),no_implicit_creation) -assert( properties.accessor, "accessor not set" ) - -events = {} -wrapEventsTable(events,this:events(),no_implicit_creation) -assert( events.accessor, "accessor not set" ) - --- function onTick() --this.position = this.position + yake.Vector3( 0, 0, 1 ) end function startup() - events.tick:connect( onTick ) + this.events.tick:connect( onTick ) end print("> Object script up."); Modified: trunk/yake/common/media/scripts/o_trigger2.lua =================================================================== --- trunk/yake/common/media/scripts/o_trigger2.lua 2007-09-05 22:59:19 UTC (rev 1836) +++ trunk/yake/common/media/scripts/o_trigger2.lua 2007-09-07 13:55:12 UTC (rev 1837) @@ -1,53 +1,17 @@ print("> Starting object script..."); --- replace loadfile and dofile with yake.loadfile and yake.dofile. --- the replacements use yake's resource system to locate the files. -yake.old_loadfile = loadfile -yake.old_dofile = dofile -loadfile = nil -dofile = nil -yake.dofile = function(path) - local locator = yake.res.global.sourceManager - assert( locator ~= nil, "global source manager not available" ) - local succ = locator:find(path) - print(succ) - assert( succ.valid, "could not locate file " .. tostring(path) ) - if succ.valid then - local f = yake.old_loadfile(succ.location) - assert( f ) - return f() -- execute! - end - return nil -end - - -print("* loading accessor scripts...") -yake.dofile("entitypropertyaccess.lua") -yake.dofile("entityeventaccess.lua") - ---local thisTrigger = yake.asTrigger(this) -local no_implicit_creation = false - -properties = {} -wrapPropertiesTable(properties,this:properties(),no_implicit_creation) -assert( properties.accessor, "accessor not set" ) - -events = {} -wrapEventsTable(events,this:events(),no_implicit_creation) -assert( events.accessor, "accessor not set" ) - --- +-- callback each simulation tick: function onTick() - --print(" script on_tick",properties.ticks) - - if properties.volumes and properties.volumes.size > 0 then + if this.volumes and this.volumes.size > 0 then + assert( objMgr, "no obj mgr" ) local objs = objMgr:getAllObjects() + for id,obj in pairs(objs) do --print(obj:isA()) local ent = yake.asEntity(obj) if ent and id ~= this.id then -- ignore self, and non-Entity objects - local intersects = properties.volumes:intersectsWith( ent.position ) + local intersects = this.volumes:intersectsWith( ent.position ) if not this.on and intersects then this:processFsmEvent("toggle") elseif this.on and not intersects then @@ -55,6 +19,7 @@ end end end + --if filter then -- local filter = yake.ObjectFilter() -- filter:add( filterByClass("Player") ) @@ -65,17 +30,16 @@ end function startup() -- common ent::Object events - events.tick:connect( onTick ) + this.events.tick:connect( onTick ) + + this.events:create("hey") -- ent::Trigger stuff this:setCondition(function() return (this.on) end) -- VolumeTrigger stuff - --properties:create("volumes", yake.VolumeContainer()) - properties:create("volumes", yake.VolumeContainerRef()) - - -- move this out: - properties.volumes:add(yake.Sphere(2)) + this.properties:create("volumes", yake.VolumeContainerRef()) + --this.createProperty("volumes", yake.VolumeContainerRef()) end print("> Object script up."); Modified: trunk/yake/common/media/scripts/raf2.lua =================================================================== --- trunk/yake/common/media/scripts/raf2.lua 2007-09-05 22:59:19 UTC (rev 1836) +++ trunk/yake/common/media/scripts/raf2.lua 2007-09-07 13:55:12 UTC (rev 1837) @@ -1,3 +1,4 @@ + -- -- raf/lua2 demo - main application script -- @@ -35,10 +36,10 @@ -- -> Adds (syntactic) sugar. Instant pleasure. function wrapEventsAndProperties(obj) assert( obj ) - obj.events = {} - wrapEventsTable(obj.events,obj:eventAccessor(),false) - obj.properties = {} - wrapPropertiesTable(obj.properties,obj:propertyAccessor(),false) + --obj.events = {} + --wrapEventsTable(obj.events,obj:eventAccessor(),false) + --obj.properties = {} + --wrapPropertiesTable(obj.properties,obj:propertyAccessor(),false) return obj end @@ -69,14 +70,14 @@ objMgr.old_makeObject = objMgr.makeObject objMgr.makeObject = function(self,clsid) local o = tryOpen( self:old_makeObject(clsid) ) - print("(lua)objMgr.makeObject created "..tostring(o.properties.id)) + print("(lua)objMgr.makeObject created "..tostring(o.id)) return o end -------------------------------------- -- demo methods which make creating various objects simpler -------------------------------------- -function makeProximityTrigger() +function makeProximityTrigger(radius) local trigger = objMgr:makeObject("Trigger") assert( trigger ) -- create DEBUG geometry @@ -86,10 +87,17 @@ m:add(g) local sn = gworld:createSceneNode() local e = gworld:createEntity("sphere_d1.mesh") + e:setMaterial("trigger_off") + + trigger.sphereEnt = e + sn.scale = yake.Vector3.UnitScale * radius * 2 + sn:attach(e) g:addSceneNode(sn) --ent:setPositionSource(sn) -- + trigger.volumes:add( yake.Sphere(radius or 2) ) + -- return trigger end yake.Entity.makeSimpleGraphical = function(self,meshname) @@ -109,7 +117,7 @@ self:setPositionSource(sn) end -function makeNinja() +function createBall() local ent = yake.asEntity( objMgr:makeObject("Entity") ) assert( ent ) ent.model = ent:makeSimpleGraphical("sphere_d1.mesh") @@ -141,35 +149,34 @@ local cam = scene.activeCamera assert(cam) cam.nearClipDistance = 0.1 -cam.position = yake.Point3(10,2,10) -cam:setFixedYawAxis( yake.Vector3.UnitY ) -- keep upwards direction constant +cam.position = yake.Point3(0,2,-10) +cam:setFixedYawAxis( yake.Vector3.UnitY ) -- keep upwards direction constant -------------------------------------- -- Create objects, entities etc -------------------------------------- --- create ninja -local ninja = makeNinja() -ninja.translate = function(self,delta) - ninja.position = ninja.position + delta +-- create ball +local ball = createBall() +ball.translate = function(self,delta) + ball.position = ball.position + delta end -cam:lookAt( ninja.position ) -- Now look at our ninja! +cam:lookAt( ball.position ) -- Now look at our ball! -- create trigger -local trigger = makeProximityTrigger() +local trigger = makeProximityTrigger(2) + function onTrigger(yes) if yes then - print("TRIGGERED") + print("TRIGGERED",trigger.id,trigger.on) + trigger.sphereEnt:setMaterial("trigger_on") else - print("UNtriggered") + print("UNtriggered",trigger.id,trigger.on) + trigger.sphereEnt:setMaterial("trigger_off") end - print(trigger.properties.id) - print(trigger.on) end trigger.events.onTriggered:connect(onTrigger) ---trigger:events().onTriggered:connect(onTrigger) ---trigger:events():get("onTriggered"):connect(onTrigger) -------------------------------------- -- Configure input @@ -226,20 +233,28 @@ activeKeys["reverse"] = true end) ------------------------------------ +----------------- F r a m e H a n d l e r --------------- +local currAngle = 0. function onFrame(timeElapsed) + -- Move our little ball on a spherical trajectory so + -- that it regularly passes the trigger volume boundary. + currAngle = currAngle + 1.2 * timeElapsed + ball.position = yake.Point3( math.cos(currAngle), math.sin(currAngle), 0 ) + yake.Vector3(-2,0,0) + + -- Handle user moving the camera: local distance = 25 * timeElapsed for k,v in pairs(activeKeys) do if k == "left" then - ninja:translate( -1 * yake.Vector3.UnitX * distance ) + cam:translate( -1 * yake.Vector3.UnitX * distance ) elseif k == "right" then - ninja:translate( 1 * yake.Vector3.UnitX * distance ) + cam:translate( 1 * yake.Vector3.UnitX * distance ) elseif k == "forward" then - ninja:translate( -1 * yake.Vector3.UnitZ * distance ) + cam:translate( -1 * yake.Vector3.UnitZ * distance ) elseif k == "reverse" then - ninja:translate( 1 * yake.Vector3.UnitZ * distance ) + cam:translate( 1 * yake.Vector3.UnitZ * distance ) end end + -- prepare for next frame: activeKeys = {} end \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-09-05 22:59:16
|
Revision: 1836 http://yake.svn.sourceforge.net/yake/?rev=1836&view=rev Author: psyclonist Date: 2007-09-05 15:59:19 -0700 (Wed, 05 Sep 2007) Log Message: ----------- * [property] try_set Modified Paths: -------------- trunk/yake/yake/property/detail/property.impl.h Modified: trunk/yake/yake/property/detail/property.impl.h =================================================================== --- trunk/yake/yake/property/detail/property.impl.h 2007-09-05 22:57:37 UTC (rev 1835) +++ trunk/yake/yake/property/detail/property.impl.h 2007-09-05 22:59:19 UTC (rev 1836) @@ -169,7 +169,7 @@ //prop.setAny(rhs); // from any //fast: - try_cast_set<T>(prop, boost::any_cast<T>(rhs)); // may throw! + try_set<T>(prop, boost::any_cast<T>(rhs)); // may throw! } } // namespace property } // namespace yake This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-09-05 22:57:36
|
Revision: 1835 http://yake.svn.sourceforge.net/yake/?rev=1835&view=rev Author: psyclonist Date: 2007-09-05 15:57:37 -0700 (Wed, 05 Sep 2007) Log Message: ----------- * [base,audioOpenAL] Vector3 -> Point3 fixes Modified Paths: -------------- trunk/yake/src/plugins/audioOpenAL/yakeAudioListenerOpenAL.cpp trunk/yake/src/plugins/audioOpenAL/yakeAudioSourceOpenAL.cpp trunk/yake/yake/base/math/yakeGeometry.h trunk/yake/yake/plugins/audioOpenAL/yakeAudioSystemOpenAL.h Modified: trunk/yake/src/plugins/audioOpenAL/yakeAudioListenerOpenAL.cpp =================================================================== --- trunk/yake/src/plugins/audioOpenAL/yakeAudioListenerOpenAL.cpp 2007-09-05 18:18:39 UTC (rev 1834) +++ trunk/yake/src/plugins/audioOpenAL/yakeAudioListenerOpenAL.cpp 2007-09-05 22:57:37 UTC (rev 1835) @@ -67,18 +67,18 @@ return orientation;*/ } - void ListenerOpenAL::setPosition( const Vector3 & position ) + void ListenerOpenAL::setPosition( const Point3 & position ) { YAKE_ASSERT( mListener.valid() ); mListener->setPosition( position.x, position.y, position.z ); } - Vector3 ListenerOpenAL::getPosition() const + Point3 ListenerOpenAL::getPosition() const { YAKE_ASSERT( mListener.valid() ); float x,y,z; mListener->getPosition( x, y, z ); - return Vector3( x, y, z ); + return Point3( x, y, z ); } void ListenerOpenAL::setVelocity( const Vector3 & velocity ) Modified: trunk/yake/src/plugins/audioOpenAL/yakeAudioSourceOpenAL.cpp =================================================================== --- trunk/yake/src/plugins/audioOpenAL/yakeAudioSourceOpenAL.cpp 2007-09-05 18:18:39 UTC (rev 1834) +++ trunk/yake/src/plugins/audioOpenAL/yakeAudioSourceOpenAL.cpp 2007-09-05 22:57:37 UTC (rev 1835) @@ -77,17 +77,17 @@ YAKE_ASSERT( mSource.valid() ); return mOrientation; } - void SourceOpenAL::setPosition( const Vector3 & position ) + void SourceOpenAL::setPosition( const Point3 & position ) { YAKE_ASSERT( mSource.valid() ); mSource->setPosition( position.x, position.y, position.z ); } - Vector3 SourceOpenAL::getPosition() const + Point3 SourceOpenAL::getPosition() const { YAKE_ASSERT( mSource.valid() ); float x,y,z; mSource->getPosition(x,y,z); - return Vector3(x,y,z); + return Point3(x,y,z); } void SourceOpenAL::setVelocity( const Vector3 & velocity ) Modified: trunk/yake/yake/base/math/yakeGeometry.h =================================================================== --- trunk/yake/yake/base/math/yakeGeometry.h 2007-09-05 18:18:39 UTC (rev 1834) +++ trunk/yake/yake/base/math/yakeGeometry.h 2007-09-05 22:57:37 UTC (rev 1835) @@ -118,6 +118,7 @@ }; } +using math::Rectangle; } #endif Modified: trunk/yake/yake/plugins/audioOpenAL/yakeAudioSystemOpenAL.h =================================================================== --- trunk/yake/yake/plugins/audioOpenAL/yakeAudioSystemOpenAL.h 2007-09-05 18:18:39 UTC (rev 1834) +++ trunk/yake/yake/plugins/audioOpenAL/yakeAudioSystemOpenAL.h 2007-09-05 22:57:37 UTC (rev 1835) @@ -107,8 +107,8 @@ virtual void setOrientation( const Quaternion & orientation ); virtual Quaternion getOrientation() const; - virtual void setPosition( const Vector3 & position ); - virtual Vector3 getPosition() const; + virtual void setPosition( const Point3 & position ); + virtual Point3 getPosition() const; protected: openalpp::ref_ptr<openalpp::SourceBase> mSource; SoundDataOpenALBase* mSoundData; @@ -126,8 +126,8 @@ virtual void setOrientation( const Quaternion & orientation ); virtual Quaternion getOrientation() const; - virtual void setPosition( const Vector3 & position ); - virtual Vector3 getPosition() const; + virtual void setPosition( const Point3 & position ); + virtual Point3 getPosition() const; protected: openalpp::ref_ptr<openalpp::Listener> mListener; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-09-05 18:18:36
|
Revision: 1834 http://yake.svn.sourceforge.net/yake/?rev=1834&view=rev Author: psyclonist Date: 2007-09-05 11:18:39 -0700 (Wed, 05 Sep 2007) Log Message: ----------- * [raf/lua] added sample 'lua2' Added Paths: ----------- trunk/yake/samples/raf/lua2/ trunk/yake/samples/raf/lua2/demo.cpp Added: trunk/yake/samples/raf/lua2/demo.cpp =================================================================== --- trunk/yake/samples/raf/lua2/demo.cpp (rev 0) +++ trunk/yake/samples/raf/lua2/demo.cpp 2007-09-05 18:18:39 UTC (rev 1834) @@ -0,0 +1,459 @@ +#include "yake/audio/yakeAudio.h" +#include "yake/input/yakeInput.h" +#include "yake/graphics/yakeGraphics.h" +#include "yake/physics/yakePhysics.h" +#include "yake/scripting/yakeScriptingSystem.h" +#include "yake/raf/yakeRaf.h" +#include "yake/ent/ent.h" + +#include "yake/plugins/scriptingLua/ScriptingSystemLua.h" +#include "yake/bindings.lua/bindings.lua.h" +#include "yake/bindings.lua/common/yake.lua.common.h" +#include "yake/bindings.lua/bindings.lua.ent.h" +#include "yake/res/res.h" + +using namespace yake; +void enable_res_loaders(scripting::IVM& vm) +{ + scripting::ScriptPtr script = vm.getCreator()->createScriptFromFile("bind_resource_loaders.lua"); + YAKE_ASSERT( script ); + vm.execute( script ); +} +void enable_entity_accessorwrappers(scripting::IVM& vm) +{ + scripting::ScriptPtr script = vm.getCreator()->createScriptFromFile("entityeventaccess.lua"); + YAKE_ASSERT( script ); + vm.execute( script ); + + script = vm.getCreator()->createScriptFromFile("entitypropertyaccess.lua"); + YAKE_ASSERT( script ); + vm.execute( script ); +} + +namespace env { + struct Environment : public noncopyable + { + Environment() : parent_(0) + { + } + Environment(Environment& parent) : parent_(&parent) + { + } + ~Environment() + { + } + private: + template<typename T> + static void doDelete(T* t) + { + delete t; + } + public: + + template<typename T> + void set(T* t) + { + InstanceEntry e; + e.px = t; + e.deleter =boost::bind(&Environment::doDelete<T>,t); + instances_[ TypeId<T>() ] = e; + } + template<typename T> + T* get() const + { + Instances::const_iterator it = instances_.find( TypeId<T>() ); + if (it == instances_.end()) + { + if (parent_) + return parent_->get<T>(); + return 0; + } + return reinterpret_cast<T*>(it->second.px); + } + private: + Environment* parent_; + struct InstanceEntry + { + void* px; + boost::function<void(void)> deleter; + }; + typedef std::map<TypeInfo,InstanceEntry> Instances; + Instances instances_; + }; +} // namespace env + +struct entObject_InstanceBinder_Traits +{ + typedef ent::Object base_type; + typedef RttiClass* index_type; + + template<class ConcreteT> + static index_type getIndex() + { + return ConcreteT::cls(); + } + + static index_type getIndex(const base_type& o) + { + return o.isA(); + } +}; + +template<class TraitsT> +struct ClassInstanceBinder +{ + typedef TraitsT traits_type; + typedef typename TraitsT::base_type base_type; + typedef typename TraitsT::index_type index_type; + typedef base_type* base_pointer; + + typedef boost::function<void(luabind::object,base_pointer)> BinderFn; + + template<class ConcreteT> + void registerBinder(BinderFn fn) + { + binders_[ traits_type::getIndex<ConcreteT>() ] = fn; + } + + void bind(luabind::object tbl, base_pointer obj) + { + YAKE_ASSERT( obj ); + YAKE_ASSERT( tbl.is_valid() ); + YAKE_ASSERT( luabind::type(tbl) == LUA_TTABLE ); + BinderMap::const_iterator it = binders_.find( traits_type::getIndex(*obj) ); + YAKE_ASSERT( it != binders_.end() ).debug("Cannot lookup ThisBinder through parents, at the moment!"); + it->second(tbl,obj); + } +private: + typedef std::map<index_type,BinderFn> BinderMap; + + BinderMap binders_; +}; +typedef ClassInstanceBinder<entObject_InstanceBinder_Traits> ObjectThisBinders; +ObjectThisBinders& thisBinders() +{ + static ObjectThisBinders s_instance; + return s_instance; +} + +template<class T> +void do_register_bindThis(luabind::object tbl, ent::Object* o) +{ + YAKE_ASSERT(o); + YAKE_ASSERT(tbl.is_valid()); + YAKE_ASSERT(luabind::type(tbl) == LUA_TTABLE); + T* t = T::cast(o); + YAKE_ASSERT(t)(o->isA()->name()).error("Type mismatch!"); + tbl["this"] = t; +} + +template<class T> +void register_bindThis() +{ + thisBinders().registerBinder<T>( boost::bind(&do_register_bindThis<T>,_1,_2) ); +} + +namespace { + struct RegisterThisBinders + { + RegisterThisBinders() + { + register_bindThis<ent::Object>(); + register_bindThis<ent::Entity>(); + register_bindThis<ent::Trigger>(); + } + } g_doRegister; +} // namespace + +/** Binds 'this' in object's Lua VMs. */ +struct My_ObjectListener : public ent::ObjectManagerListener +{ + My_ObjectListener(scripting::IScriptingSystem& scriptingSys, + const StringVector& startupScripts, + ent::ObjectManager* objMgr) : + scriptingSys_(scriptingSys), objMgr_(objMgr) + { + YAKE_ASSERT( objMgr_ ); + YAKE_FOR_EACH( StringVector::const_iterator, it, startupScripts ) + { + ScriptPtr script = scriptingSys_.createScriptFromFile( *it ); + YAKE_ASSERT( script != 0 ); + if (script) + startupScripts_.push_back( script ); + } + } +private: + scripting::IScriptingSystem& scriptingSys_; + typedef scripting::ScriptPtr ScriptPtr; + typedef std::deque<ScriptPtr> ScriptPtrList; + ScriptPtrList startupScripts_; + ent::ObjectManager* objMgr_; +private: + virtual void onObjectCreated(ent::Object* obj) + { + YAKE_ASSERT( obj ); + YAKE_LOG( "MOL", "onObjectCreated: class is '" + obj->isA()->name() + "'" ); + + ent::Entity* ent = ent::Entity::cast(obj); + YAKE_ASSERT( ent ); + if (!ent) + return; + + scripting::VMPtr vm = scriptingSys_.createVM(); + YAKE_ASSERT( vm ); + bind_all( vm.get() ); + + ent->attachVM(vm,"main"); + + lua_State* L = static_cast<scripting::LuaVM*>(vm.get())->getLuaState(); + YAKE_ASSERT(L); + + // + enable_entity_accessorwrappers( *vm ); + thisBinders().bind( luabind::globals(L), obj ); + + // + luabind::globals(L)["objMgr"] = objMgr_; + + String err; + try + { + ScriptPtr script; + if (ent::Trigger::cast(ent)) + script = scriptingSys_.createScriptFromFile("o_trigger2.lua"); + else + script = scriptingSys_.createScriptFromFile("o_entity.lua"); + vm->execute( script ); + } + catch (std::exception& ex) + { + err += "Failed to run startup script:"; + err += ex.what(); + } + if (!err.empty()) + YAKE_EXCEPT( err ); + + /*@todo + YAKE_FOR_EACH( ScriptPtrList::const_iterator, it, startupScripts_ ) + { + String err; + try + { + vm->execute( *it ); + } + catch (std::exception& ex) + { + err += "Failed to run startup script:"; + err += ex.what(); + } + if (!err.empty()) + YAKE_EXCEPT( err ); + } + */ + } + virtual void onDestroyObject(ent::Object* obj) + { + ent::Entity* ent = ent::Entity::cast(obj); + YAKE_ASSERT( ent ); + + scripting::VMPtr vm = ent->detachVM("main"); + YAKE_ASSERT( vm ); + // vm will destruct when scope is left. + } + virtual void onObjectInitialized(ent::Object* obj) + { + ent::Entity* ent = ent::Entity::cast(obj); + YAKE_ASSERT( ent ); + + ent->processFsmEvent("spawn"); + } +}; + +struct Simulation : public noncopyable +{ + Simulation(env::Environment& parentEnv) : env_(parentEnv) + { + scripting::IScriptingSystem* scriptSys = env_.get<scripting::IScriptingSystem>(); + YAKE_ASSERT( scriptSys ); + + // Register object class(es) that we may want to use in this simulation: + ent::RegistrationResult ret = objMgr_.registerClass<ent::Entity>("Entity"); + YAKE_ASSERT( ret.first == object::RC_OK ); + + ret = objMgr_.registerClass<ent::Trigger>("Trigger"); + YAKE_ASSERT( ret.first == object::RC_OK ); + + // + + // Create & attach the listener which handles the connection to the Lua VM and the bindings. + luaObjListener_.reset( new ent::LuaObjectManagerListener(*scriptSys) ); + objMgr_.attachListener( luaObjListener_.get(), "luaFsm", ent::ObjectManager::kKeepOwnership ); + + // Object listener for init'ing our objects + StringVector startupScripts; + startupScripts.push_back("o_trigger2.lua"); + myObjListener_.reset( new My_ObjectListener(*scriptSys,startupScripts,&this->objMgr_) ); + objMgr_.attachListener( myObjListener_.get(), "Simulation.myObjListener_", ent::ObjectManager::kKeepOwnership ); + } + void start() + { + // Create trigger + { + //ent::Trigger* trigger = ent::Trigger::cast(objMgr_.makeObject("Trigger")); + //YAKE_ASSERT( trigger ); + } + } + void stop() + { + objMgr_.destroyAllObjects(); + //luaObjListener_.reset(); + //myObjListener_.reset(); + } + void step() + { + objMgr_.tick(); + } + ent::ObjectManager* __getObjMgr() + { return &objMgr_; } +private: + env::Environment env_; + ent::ObjectManager objMgr_; + SharedPtr<My_ObjectListener> myObjListener_; + SharedPtr<ent::LuaObjectManagerListener> luaObjListener_; + //ent::LuaObjectManagerListener luaObjMgrListener_; +}; + +/** Main application state */ +class TheMainState : public raf::RtMainState +{ +public: + TheMainState(raf::Application& owner, + env::Environment& parentEnv) + : raf::RtMainState(owner), app_(owner), env_(parentEnv) + { + enableInstantQuitByKey( input::KC_ESCAPE ); + env_.set<scripting::IScriptingSystem>(app_.getScriptingSystem()); + env_.set<graphics::IWorld>(this->getGraphicalWorld()); + } +private: + SharedPtr<Simulation> sim_; +protected: + virtual void onEnter() + { + actionMap_.start(); + sim_.reset( new Simulation(env_) ); + + raf::RtMainState::onEnter(); // triggers onCreateScene() + } + virtual void onExit() + { + if (sim_) + sim_->stop(); + sim_.reset(); + + actionMap_.stop(); + + actionMap_.clear(); // Do NOT forget to clear this! Otherwise we keep references to + // the callback functions created from the Lua VM which is about to + // be destroyed, too! + // @todo find a nice solution to this + vm_.reset(); // destroy the VM *before* the ActionMap gets destroyed! + + raf::RtMainState::onExit(); + } + virtual void onCreateScene() + { + YAKE_LOG_INFORMATION("demo","Creating scene"); + + scripting::IScriptingSystem* sys = app_.getScriptingSystem(); + YAKE_ASSERT( sys ); + YAKE_ASSERT( !vm_ ); + vm_ = sys->createVM(); + bind_all(vm_.get()); + + //bind application vm + { + lua_State* L = static_cast<scripting::LuaVM*>(vm_.get())->getLuaState(); + luabind::globals(L)["app"] = &app_; + + luabind::globals(L)["app"]["actionMap"] = &actionMap_; + + luabind::object scene = luabind::newtable(L); + scene["gworld"] = this->getGraphicalWorld(); + scene["activeCamera"] = this->getDefaultCamera(); + luabind::globals(L)["scene"] = scene; + + luabind::module(L) + [ + luabind::class_<Simulation>("Simulation") + ]; + + luabind::globals(L)["sim"] = sim_.get(); + luabind::globals(L)["sim"]["objMgr"] = sim_->__getObjMgr(); + } + + // + enable_res_loaders( *vm_ ); + enable_entity_accessorwrappers( *vm_ ); + + // Create ninja model, position camera and look at the ninja: All done in Lua script: + scripting::ScriptPtr script = sys->createScriptFromFile("raf2.lua"); + vm_->execute( script ); + + // start sime + YAKE_ASSERT( sim_.get() ); + sim_->start(); + } + virtual void onFrame(const real timeElapsed) + { + actionMap_.update(); //@todo here OK? ... + sim_->step(); + + lua_State* L = static_cast<scripting::LuaVM*>(vm_.get())->getLuaState(); + try { + luabind::call_function<void>( L, "onFrame", timeElapsed ); + } + catch (std::exception& ex) + { + YAKE_LOG_ERROR("demo",ex.what()); + requestQuit(); + } + } +private: + raf::Application& app_; + input::ActionMap actionMap_; + scripting::VMPtr vm_; + + env::Environment env_; +}; + +/** The mighty application itself! */ +class TheApp : public raf::ExampleApplication<> +{ +public: + TheApp() + { + getConfiguration().get().load("sampleRafLua2.cfg"); + env_.set(&getConfiguration()); + } +private: + env::Environment env_; + virtual raf::MainState* createMainState() + { + return new TheMainState(*this,env_); + } +}; + +int main( int argc, char** argv ) +{ + // create and attach log listeners + typedef SharedPtr<logging::log_listener> log_listener_ptr; + log_listener_ptr toStdErr( new yake::logging::stderr_listener() ); + logging::addListener( toStdErr.get() ); + + // Use default executor for convenience. + // It's always possible to manually execute TheApp::initialise() etc. + TheApp app; + return (raf::runApplication( app )) ? 0 : 1; +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-09-04 21:41:10
|
Revision: 1833 http://yake.svn.sourceforge.net/yake/?rev=1833&view=rev Author: psyclonist Date: 2007-09-04 14:41:13 -0700 (Tue, 04 Sep 2007) Log Message: ----------- * [property] added try_get() * [base] pull in math types into yake namespace Modified Paths: -------------- trunk/yake/common/media/scripts/raf1.lua trunk/yake/src/bindings.lua/detail/ent.lua.cpp trunk/yake/yake/base/math/yakeColor.h trunk/yake/yake/base/math/yakeMatrix4.h trunk/yake/yake/base/math/yakePoint3.h trunk/yake/yake/base/math/yakeQuaternion.h trunk/yake/yake/base/math/yakeRay.h trunk/yake/yake/base/math/yakeVector3.h trunk/yake/yake/base/yakeMovable.h trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h trunk/yake/yake/property/detail/property.impl.h Modified: trunk/yake/common/media/scripts/raf1.lua =================================================================== --- trunk/yake/common/media/scripts/raf1.lua 2007-09-04 17:17:53 UTC (rev 1832) +++ trunk/yake/common/media/scripts/raf1.lua 2007-09-04 21:41:13 UTC (rev 1833) @@ -2,6 +2,7 @@ local defaultCam = scene.activeCamera local actionMap = app.actionMap local input = yake.input +local objMgr = sim.objMgr -------------------------------------- -- Configure graphics @@ -36,6 +37,12 @@ cam:lookAt( yake.Point3(0,100,0) ) -- look at our ninja! -------------------------------------- +-- Create objects +-------------------------------------- + +local ninja = objMgr:makeObject("Entity") + +-------------------------------------- -- Configure input -------------------------------------- Modified: trunk/yake/src/bindings.lua/detail/ent.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-09-04 17:17:53 UTC (rev 1832) +++ trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-09-04 21:41:13 UTC (rev 1833) @@ -117,6 +117,15 @@ evt.connect( o ); return true; } + template<typename T> + T getPropertyValue(Object& o, const PropertyId& id) + { + PropertyPtr p = o.properties().get(id); + YAKE_ASSERT( p )(id)(o.id()).debug("property not found"); + boost::optional<T> val = property::try_get<T>(*p); + YAKE_ASSERT( val ).debug("type mismatch"); + return val ? *val : T(); + } static property::PropertyBase* getPropertyOfObject(Object& o, const PropertyId& id) { return o.properties().get(id).get(); Modified: trunk/yake/yake/base/math/yakeColor.h =================================================================== --- trunk/yake/yake/base/math/yakeColor.h 2007-09-04 17:17:53 UTC (rev 1832) +++ trunk/yake/yake/base/math/yakeColor.h 2007-09-04 21:41:13 UTC (rev 1833) @@ -136,6 +136,7 @@ Color operator*( real fScalar, const Color& rColor ); } // math +using math::Color; } // yake // Fast Inline Implementation. Modified: trunk/yake/yake/base/math/yakeMatrix4.h =================================================================== --- trunk/yake/yake/base/math/yakeMatrix4.h 2007-09-04 17:17:53 UTC (rev 1832) +++ trunk/yake/yake/base/math/yakeMatrix4.h 2007-09-04 21:41:13 UTC (rev 1833) @@ -434,6 +434,7 @@ } } // math +using math::Matrix4; } // yake #endif Modified: trunk/yake/yake/base/math/yakePoint3.h =================================================================== --- trunk/yake/yake/base/math/yakePoint3.h 2007-09-04 17:17:53 UTC (rev 1832) +++ trunk/yake/yake/base/math/yakePoint3.h 2007-09-04 21:41:13 UTC (rev 1833) @@ -244,6 +244,7 @@ } } // math +using math::Point3; } // yake #endif // YAKE_BASE_MATH_POINT3_H Modified: trunk/yake/yake/base/math/yakeQuaternion.h =================================================================== --- trunk/yake/yake/base/math/yakeQuaternion.h 2007-09-04 17:17:53 UTC (rev 1832) +++ trunk/yake/yake/base/math/yakeQuaternion.h 2007-09-04 21:41:13 UTC (rev 1833) @@ -147,6 +147,7 @@ } } // math +using math::Quaternion; } // yake #endif // YAKE_MATH_QUATERNION_H Modified: trunk/yake/yake/base/math/yakeRay.h =================================================================== --- trunk/yake/yake/base/math/yakeRay.h 2007-09-04 17:17:53 UTC (rev 1832) +++ trunk/yake/yake/base/math/yakeRay.h 2007-09-04 21:41:13 UTC (rev 1833) @@ -76,6 +76,7 @@ }; } +using math::Ray; } #endif Modified: trunk/yake/yake/base/math/yakeVector3.h =================================================================== --- trunk/yake/yake/base/math/yakeVector3.h 2007-09-04 17:17:53 UTC (rev 1832) +++ trunk/yake/yake/base/math/yakeVector3.h 2007-09-04 21:41:13 UTC (rev 1833) @@ -426,6 +426,7 @@ } } // math +using math::Vector3; } // yake #endif // YAKE_BASE_MATH_VECTOR3_H Modified: trunk/yake/yake/base/yakeMovable.h =================================================================== --- trunk/yake/yake/base/yakeMovable.h 2007-09-04 17:17:53 UTC (rev 1832) +++ trunk/yake/yake/base/yakeMovable.h 2007-09-04 21:41:13 UTC (rev 1833) @@ -34,6 +34,7 @@ #include <yake/base/yakePrerequisites.h> #include <yake/base/math/yakeVector3.h> #include <yake/base/math/yakePoint3.h> +#include <yake/base/math/yakeQuaternion.h> // Yake //============================================================================ @@ -41,7 +42,6 @@ //============================================================================ namespace yake { - using namespace ::yake::math; /** Interface for movable objects and basic implementation of methods for convenience (like translate()). Modified: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-09-04 17:17:53 UTC (rev 1832) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-09-04 21:41:13 UTC (rev 1833) @@ -37,7 +37,7 @@ #define YAKE_LUA_ANY_CONVERTER_API YAKE_BINDINGS_LUA_API -#define YAKE_LUA_ANY_CONVERTER_POINTERS 1 +#define YAKE_LUA_ANY_CONVERTER_POINTERS 0 #if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: # include <yake/property/property.h> Modified: trunk/yake/yake/property/detail/property.impl.h =================================================================== --- trunk/yake/yake/property/detail/property.impl.h 2007-09-04 17:17:53 UTC (rev 1832) +++ trunk/yake/yake/property/detail/property.impl.h 2007-09-04 21:41:13 UTC (rev 1833) @@ -34,6 +34,7 @@ #include <yake/base/templates/yakeSignals.h> #include <yake/base/templates/yakePointer.h> #include <yake/base/templates/yakeSmartAssert.h> +#include <boost/optional.hpp> namespace yake { namespace property { @@ -139,12 +140,25 @@ return static_cast<to_t&>(prop); } template<typename T/*, template <typename> class AccT*/> - void try_cast_set(PropertyBase& prop, const T& newValue) + void try_set(PropertyBase& prop, const T& newValue) { typedef Property<T> to_t; to_t& propCasted = try_cast<T>(prop); propCasted.set( newValue ); } + template<typename T/*, template <typename> class AccT*/> + boost::optional<T> try_get(const PropertyBase& prop) + { + typedef Property<T> to_t; + try { + const to_t& propCasted = try_cast<T>(prop); + return propCasted.get(); + } + catch (BadCastException&) + { + return false; + } + } template<typename T> void try_cast_set_from_any(PropertyBase& prop, const boost::any& rhs) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-09-04 17:17:58
|
Revision: 1832 http://yake.svn.sourceforge.net/yake/?rev=1832&view=rev Author: psyclonist Date: 2007-09-04 10:17:53 -0700 (Tue, 04 Sep 2007) Log Message: ----------- * [bindings.lua] extensive additions to the bindings for yake.ent, yake.graphics, yake.model and yake.base * [ent/lua] added VolumeTrigger implementation completely scripted in Lua * major API break: introduction of type Point3 which replaces Vector3 in the API when positions (or points) are meant. * various API fixes * added yake.Volume and yake.VolumeContainer (+ bindings for Lua) Modified Paths: -------------- trunk/yake/common/media/scripts/entitypropertyaccess.lua trunk/yake/common/media/scripts/o_access.lua trunk/yake/common/media/scripts/raf1.lua trunk/yake/scripts/premake/samples.lua trunk/yake/scripts/premake/yake.lua trunk/yake/src/base/math/yakeMatrix3.cpp trunk/yake/src/base/math/yakeQuaternion.cpp trunk/yake/src/base/math/yakeRay.cpp trunk/yake/src/base/math/yakeVector3.cpp trunk/yake/src/bindings.lua/bindings.lua.cpp trunk/yake/src/bindings.lua/detail/base.lua.cpp trunk/yake/src/bindings.lua/detail/ent.lua.cpp trunk/yake/src/bindings.lua/detail/graphics.lua.cpp trunk/yake/src/bindings.lua/detail/model.lua.cpp trunk/yake/src/bindings.lua/detail/physics.lua.cpp trunk/yake/src/bindings.lua/detail/property.lua.cpp trunk/yake/src/ent/entity.cpp trunk/yake/src/ent/trigger.cpp trunk/yake/src/graphics/yakeGraphicsSystem.cpp trunk/yake/src/loader/yakeDotScene.cpp trunk/yake/src/loader/yakeXODEParser.cpp trunk/yake/src/model/yakeGraphicalDotSceneLoader.cpp trunk/yake/src/model/yakeModelMovableLink.cpp trunk/yake/src/plugins/graphicsOgre/graphicsOgreCamera.cpp trunk/yake/src/plugins/graphicsOgre/graphicsOgreNode.cpp trunk/yake/src/plugins/graphicsOgre/graphicsOgreParticleSystem.cpp trunk/yake/src/plugins/inputOgreOIS/InputSystemOgreOIS.cpp trunk/yake/src/plugins/physicsODE/OdeActor.cpp trunk/yake/src/plugins/physicsODE/OdeAvatar.cpp trunk/yake/src/plugins/physicsODE/OdeBallJoint.cpp trunk/yake/src/plugins/physicsODE/OdeBody.cpp trunk/yake/src/plugins/physicsODE/OdeFixedJoint.cpp trunk/yake/src/plugins/physicsODE/OdeHinge2Joint.cpp trunk/yake/src/plugins/physicsODE/OdeHingeJoint.cpp trunk/yake/src/plugins/physicsODE/OdeRay.cpp trunk/yake/src/plugins/physicsODE/OdeShapes.cpp trunk/yake/src/plugins/physicsODE/OdeSliderJoint.cpp trunk/yake/src/plugins/physicsODE/OdeUniversalJoint.cpp trunk/yake/src/raf/yakeApplication.cpp trunk/yake/yake/audio/yakeAudioSystem.h trunk/yake/yake/base/math/yakeGeometry.h trunk/yake/yake/base/math/yakeMatrix3.h trunk/yake/yake/base/math/yakeQuaternion.h trunk/yake/yake/base/math/yakeRay.h trunk/yake/yake/base/yake.h trunk/yake/yake/base/yakeMovable.h trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h trunk/yake/yake/ent/entity.h trunk/yake/yake/ent/trigger.h trunk/yake/yake/graphics/yakeGraphicalWorld.h trunk/yake/yake/input/yakeInputSystem.h trunk/yake/yake/loader/yakeDotScene.h trunk/yake/yake/loader/yakeXODEParser.h trunk/yake/yake/model/model_link.h trunk/yake/yake/physics/yakePhysicsAffectors.h trunk/yake/yake/physics/yakePhysicsAvatar.h trunk/yake/yake/physics/yakePhysicsBody.h trunk/yake/yake/physics/yakePhysicsJoint.h trunk/yake/yake/physics/yakePhysicsShape.h trunk/yake/yake/plugins/graphicsOgre/graphicsOgreCamera.h trunk/yake/yake/plugins/graphicsOgre/graphicsOgreNode.h trunk/yake/yake/plugins/graphicsOgre/yakePCH.h trunk/yake/yake/plugins/inputOgreOIS/InputSystemOgreOIS.h trunk/yake/yake/plugins/physicsODE/OdeActor.h trunk/yake/yake/plugins/physicsODE/OdeAvatar.h trunk/yake/yake/plugins/physicsODE/OdeBody.h trunk/yake/yake/plugins/physicsODE/OdeJoint.h trunk/yake/yake/plugins/physicsODE/OdeRay.h trunk/yake/yake/plugins/physicsODE/OdeShapes.h trunk/yake/yake/plugins/scriptingLua/ScriptingSystemLua.h trunk/yake/yake/prop/rtti_class.h trunk/yake/yake/scripting/yakeScriptingSystem.h Added Paths: ----------- trunk/yake/common/media/scripts/bind_resource_loaders.lua trunk/yake/common/media/scripts/init_entity.lua trunk/yake/common/media/scripts/o_entity.lua trunk/yake/common/media/scripts/o_trigger2.lua trunk/yake/common/media/scripts/raf2.lua trunk/yake/src/base/math/yakeVolume.cpp trunk/yake/yake/base/math/yakePoint3.h trunk/yake/yake/base/math/yakeVolume.h Added: trunk/yake/common/media/scripts/bind_resource_loaders.lua =================================================================== --- trunk/yake/common/media/scripts/bind_resource_loaders.lua (rev 0) +++ trunk/yake/common/media/scripts/bind_resource_loaders.lua 2007-09-04 17:17:53 UTC (rev 1832) @@ -0,0 +1,24 @@ + +if loadfile and dofile then + -- replace loadfile and dofile with yake.loadfile and yake.dofile. + -- the replacements use yake's resource system to locate the files. + yake.old_loadfile = loadfile + yake.old_dofile = dofile + loadfile = nil + dofile = nil + yake.dofile = function(path) + local locator = yake.res.global.sourceManager + assert( locator ~= nil, "global source manager not available" ) + local succ = locator:find(path) + print(succ) + assert( succ.valid, "could not locate file " .. tostring(path) ) + if succ.valid then + local f = yake.old_loadfile(succ.location) + assert( f ) + return f() -- execute! + end + return nil + end +else + assert( 1==0, "resource loaders already bound") +end Modified: trunk/yake/common/media/scripts/entitypropertyaccess.lua =================================================================== --- trunk/yake/common/media/scripts/entitypropertyaccess.lua 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/common/media/scripts/entitypropertyaccess.lua 2007-09-04 17:17:53 UTC (rev 1832) @@ -8,10 +8,10 @@ function wrapPropertiesTable(t,propAccess,implicitCreation) t.list = {} t.accessor = propAccess - assert( t.accessor ) + assert( t.accessor, "invalid accessor" ) t.create = function(self,k,v) local p = self.accessor:create(k,v) - assert( p ~= nil ) + assert( p ~= nil, "failed to create" ) -- @todo really provide this accessor a la __newindex and rawset below??? rawset(t.list,k,p) @@ -26,7 +26,7 @@ --print(propAccess.size) for k = 1, propAccess.size do local p = propAccess:get(k) - assert( p ~= nil ) + assert( p ~= nil, "could not get" ) --print("exist:",p.name) rawset(t.list,p.name,p) end @@ -36,12 +36,12 @@ --print("defaulting") implicitCreation = true end - assert( type(implicitCreation) == "boolean" ) + assert( type(implicitCreation) == "boolean", "type mismatch, boolean expected" ) --print(implicitCreation) setmetatable(t, { __index = function(t,k) - assert( t.accessor ~= nil ) + assert( t.accessor ~= nil, "no accessor available" ) --print("INDEX",t,k) if type(k) ~= "string" then print("properties __index -> ERROR: key is not of type 'string' but of type '"..type(k).."'!") @@ -70,7 +70,7 @@ print(implicitCreation) if implicitCreation then local p = t.accessor:create(k,v) - assert( p ~= nil ) + assert( p ~= nil, "failed to create" ) -- @todo really provide an accessor??? rawset(t.list,k,p) Added: trunk/yake/common/media/scripts/init_entity.lua =================================================================== --- trunk/yake/common/media/scripts/init_entity.lua (rev 0) +++ trunk/yake/common/media/scripts/init_entity.lua 2007-09-04 17:17:53 UTC (rev 1832) @@ -0,0 +1,39 @@ +print("> Starting init_entity.lua ..."); + +-- replace loadfile and dofile with yake.loadfile and yake.dofile. +-- the replacements use yake's resource system to locate the files. +yake.old_loadfile = loadfile +yake.old_dofile = dofile +loadfile = nil +dofile = nil +yake.dofile = function(path) + local locator = yake.res.global.sourceManager + assert( locator ~= nil, "global source manager not available" ) + local succ = locator:find(path) + print(succ) + assert( succ.valid, "could not locate file " .. tostring(path) ) + if succ.valid then + local f = yake.old_loadfile(succ.location) + assert( f ) + return f() -- execute! + end + return nil +end + + +print("* loading accessor scripts...") +yake.dofile("entitypropertyaccess.lua") +yake.dofile("entityeventaccess.lua") + +local no_implicit_creation = false + +properties = {} +wrapPropertiesTable(properties,this:properties(),no_implicit_creation) +assert( properties.accessor, "accessor not set" ) + +events = {} +wrapEventsTable(events,this:events(),no_implicit_creation) +assert( events.accessor, "accessor not set" ) + +-- +print("> init_entity.lua done."); Modified: trunk/yake/common/media/scripts/o_access.lua =================================================================== --- trunk/yake/common/media/scripts/o_access.lua 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/common/media/scripts/o_access.lua 2007-09-04 17:17:53 UTC (rev 1832) @@ -1,4 +1,22 @@ print("> Starting object script..."); +local vols = yake.VolumeContainer() +print("1") +local sphere = yake.Sphere(2) +print("2") +vols:add(sphere) +print("3") +local pt = yake.Point3(0,0,0) +print("4") +print(sphere:intersectsWith(pt)) +print("5") +print("numVols=",vols.size) +print("6") +print(vols:intersectsWith(pt)) +pt.x = 5 +print(vols:intersectsWith(pt)) +print("7") +print(sphere:intersectsWith(pt)) +print("done") -- replace loadfile and dofile with yake.loadfile and yake.dofile. -- the replacements use yake's resource system to locate the files. @@ -8,10 +26,10 @@ dofile = nil yake.dofile = function(path) local locator = yake.res.global.sourceManager - assert( locator ~= nil ) + assert( locator ~= nil, "global source manager not available" ) local succ = locator:find(path) print(succ) - assert( succ.valid ) + assert( succ.valid, "could not locate file " .. tostring(path) ) if succ.valid then local f = yake.old_loadfile(succ.location) assert( f ) @@ -30,17 +48,26 @@ properties = {} wrapPropertiesTable(properties,this:properties(),no_implicit_creation) -assert( properties.accessor ) +assert( properties.accessor, "accessor not set" ) events = {} wrapEventsTable(events,this:events(),no_implicit_creation) -assert( events.accessor ) +assert( events.accessor, "accessor not set" ) -- function onTick() print(" script on_tick",properties.ticks) properties.ticks = properties.ticks + 1 --properties.doesnotexist = properties.ticks -- <- results in Luabind exception if property does not exist + + if properties.volumes and properties.volumes.size > 0 then + --objMgr:getObjectsByClass(class) + local filter = yake.ObjectFilter() + filter:add( filterByClass("Player") ) + filter:add( filterByClass("Entity",IgnoreDerived) ) + filter.byClass("Player") + print(" - testing volumes") + end end function startup() -- common ent::Object events @@ -48,10 +75,13 @@ events.tick:connect( onTick ) events.preDestroy:connect( function() print(" script on_preDestroy") end ) - -- ent::Triggere stuff + -- ent::Trigger stuff properties:create("ticks",0) -- create property of type 'number' this:setCondition(function() return (properties.ticks >= 1 and properties.ticks <= 3) end) events.onTriggered:connect( function(a) print(" script on_triggered",a) end ) + + -- VolumeTrigger stuff + properties:create("volumes", yake.VolumeContainer()) end print("> Object script up."); Added: trunk/yake/common/media/scripts/o_entity.lua =================================================================== --- trunk/yake/common/media/scripts/o_entity.lua (rev 0) +++ trunk/yake/common/media/scripts/o_entity.lua 2007-09-04 17:17:53 UTC (rev 1832) @@ -0,0 +1,52 @@ +print("> Starting object script..."); + +-- replace loadfile and dofile with yake.loadfile and yake.dofile. +-- the replacements use yake's resource system to locate the files. +yake.old_loadfile = loadfile +yake.old_dofile = dofile +loadfile = nil +dofile = nil +yake.dofile = function(path) + local locator = yake.res.global.sourceManager + assert( locator ~= nil, "global source manager not available" ) + local succ = locator:find(path) + print(succ) + assert( succ.valid, "could not locate file " .. tostring(path) ) + if succ.valid then + local f = yake.old_loadfile(succ.location) + assert( f ) + return f() -- execute! + end + return nil +end + + +print("* loading accessor scripts...") +yake.dofile("entitypropertyaccess.lua") +yake.dofile("entityeventaccess.lua") + +--local thisTrigger = yake.asTrigger(this) +local no_implicit_creation = false + +properties = {} +wrapPropertiesTable(properties,this:properties(),no_implicit_creation) +assert( properties.accessor, "accessor not set" ) + +events = {} +wrapEventsTable(events,this:events(),no_implicit_creation) +assert( events.accessor, "accessor not set" ) + +-- +function onTick() + --this.position = this.position + yake.Vector3( 0, 0, 1 ) +end +function startup() + events.tick:connect( onTick ) +end +print("> Object script up."); + +function main() + print(" script main()") + startup() +end + Added: trunk/yake/common/media/scripts/o_trigger2.lua =================================================================== --- trunk/yake/common/media/scripts/o_trigger2.lua (rev 0) +++ trunk/yake/common/media/scripts/o_trigger2.lua 2007-09-04 17:17:53 UTC (rev 1832) @@ -0,0 +1,86 @@ +print("> Starting object script..."); + +-- replace loadfile and dofile with yake.loadfile and yake.dofile. +-- the replacements use yake's resource system to locate the files. +yake.old_loadfile = loadfile +yake.old_dofile = dofile +loadfile = nil +dofile = nil +yake.dofile = function(path) + local locator = yake.res.global.sourceManager + assert( locator ~= nil, "global source manager not available" ) + local succ = locator:find(path) + print(succ) + assert( succ.valid, "could not locate file " .. tostring(path) ) + if succ.valid then + local f = yake.old_loadfile(succ.location) + assert( f ) + return f() -- execute! + end + return nil +end + + +print("* loading accessor scripts...") +yake.dofile("entitypropertyaccess.lua") +yake.dofile("entityeventaccess.lua") + +--local thisTrigger = yake.asTrigger(this) +local no_implicit_creation = false + +properties = {} +wrapPropertiesTable(properties,this:properties(),no_implicit_creation) +assert( properties.accessor, "accessor not set" ) + +events = {} +wrapEventsTable(events,this:events(),no_implicit_creation) +assert( events.accessor, "accessor not set" ) + +-- +function onTick() + --print(" script on_tick",properties.ticks) + + if properties.volumes and properties.volumes.size > 0 then + assert( objMgr, "no obj mgr" ) + local objs = objMgr:getAllObjects() + for id,obj in pairs(objs) do + --print(obj:isA()) + local ent = yake.asEntity(obj) + if ent and id ~= this.id then -- ignore self, and non-Entity objects + local intersects = properties.volumes:intersectsWith( ent.position ) + if not this.on and intersects then + this:processFsmEvent("toggle") + elseif this.on and not intersects then + this:processFsmEvent("toggle") + end + end + end + --if filter then + -- local filter = yake.ObjectFilter() + -- filter:add( filterByClass("Player") ) + -- filter:add( filterByClass("Entity",IgnoreDerived) ) + -- filter.byClass("Player") + --end + end +end +function startup() + -- common ent::Object events + events.tick:connect( onTick ) + + -- ent::Trigger stuff + this:setCondition(function() return (this.on) end) + + -- VolumeTrigger stuff + --properties:create("volumes", yake.VolumeContainer()) + properties:create("volumes", yake.VolumeContainerRef()) + + -- move this out: + properties.volumes:add(yake.Sphere(2)) +end +print("> Object script up."); + +function main() + print(" script main()") + startup() +end + Modified: trunk/yake/common/media/scripts/raf1.lua =================================================================== --- trunk/yake/common/media/scripts/raf1.lua 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/common/media/scripts/raf1.lua 2007-09-04 17:17:53 UTC (rev 1832) @@ -31,9 +31,9 @@ local cam = scene.activeCamera assert(cam) -cam.position = yake.Vector3(100,20,-200) +cam.position = yake.Point3(100,20,-200) cam:setFixedYawAxis( yake.Vector3.UnitY ) -- keep upwards direction constant -cam:lookAt( yake.Vector3(0,100,0) ) -- look at our ninja! +cam:lookAt( yake.Point3(0,100,0) ) -- look at our ninja! -------------------------------------- -- Configure input Added: trunk/yake/common/media/scripts/raf2.lua =================================================================== --- trunk/yake/common/media/scripts/raf2.lua (rev 0) +++ trunk/yake/common/media/scripts/raf2.lua 2007-09-04 17:17:53 UTC (rev 1832) @@ -0,0 +1,245 @@ +-- +-- raf/lua2 demo - main application script +-- +-- available bindings: +-- * res (including loads, i.e. yake.dofile) +-- * graphics, ent, raf, and more +-- +-- + +local gworld = scene.gworld +local defaultCam = scene.activeCamera +local actionMap = app.actionMap +local input = yake.input + +print(type(sim)) +print(type(sim.objMgr)) +local objMgr = sim.objMgr + +-------------------------------------- +-- Syntactic sugar for objMgr and +-- objects / entities and their +-- properties and events +-- @todo do this on C++ side +-- (g_casters -> probably as part of ThisBinder mechanism...) +-------------------------------------- + +-- register "Entity" -> DerivedEntity casters +-- @todo lookup via "RtiiClass*" instead of string (-> faster...) +g_casters = {} +g_casters["Entity"] = yake.asEntity +g_casters["Trigger"] = yake.asTrigger + +-- makes accessing properties and events +-- syntactically simpler. +-- -> Adds (syntactic) sugar. Instant pleasure. +function wrapEventsAndProperties(obj) + assert( obj ) + obj.events = {} + wrapEventsTable(obj.events,obj:eventAccessor(),false) + obj.properties = {} + wrapPropertiesTable(obj.properties,obj:propertyAccessor(),false) + return obj +end + +-- Attempts to cast to most derived class. +-- Returns the input object on failure, so obj stays valid. +function tryCastToDerived(obj) + local caster = g_casters[obj:isA().name] + assert( caster, "no caster available - returning as-is "..tostring(obj:isA()) ) + if not caster then + return obj, false + end + obj = caster( obj ) + assert( obj, "cast failed" ) + return obj, true +end + +-- Attempts to cast to most derived class and +-- also wraps event and property access for syntactic sugar. +-- Returned obj is at least as valid as the original obj. :) +function tryOpen(obj) + local ok = false + obj,ok = tryCastToDerived(obj) + obj = wrapEventsAndProperties(obj) + return obj +end + +-- Redefine objMgr.makeObject() to take advantage of wrapEventsAndProperties() +objMgr.old_makeObject = objMgr.makeObject +objMgr.makeObject = function(self,clsid) + local o = tryOpen( self:old_makeObject(clsid) ) + print("(lua)objMgr.makeObject created "..tostring(o.properties.id)) + return o +end + +-------------------------------------- +-- demo methods which make creating various objects simpler +-------------------------------------- +function makeProximityTrigger() + local trigger = objMgr:makeObject("Trigger") + assert( trigger ) + -- create DEBUG geometry + local m = yake.Model() + trigger.model = m + local g = yake.Graphical() + m:add(g) + local sn = gworld:createSceneNode() + local e = gworld:createEntity("sphere_d1.mesh") + sn:attach(e) + g:addSceneNode(sn) + --ent:setPositionSource(sn) + -- + return trigger +end +yake.Entity.makeSimpleGraphical = function(self,meshname) + assert(self, "missing self") + assert(meshname, "missing mesh name") + + local m = yake.Model() + self.model = m + + local g = yake.Graphical() + m:add(g) + + local sn = gworld:createSceneNode() + g:addSceneNode( sn ) + local e = gworld:createEntity(meshname) + sn:attach(e) + + self:setPositionSource(sn) +end +function makeNinja() + local ent = yake.asEntity( objMgr:makeObject("Entity") ) + assert( ent ) + ent.model = ent:makeSimpleGraphical("sphere_d1.mesh") + return ent +end + + +-------------------------------------- +-- Configure graphics +-------------------------------------- + +-- configure basic scene properties +gworld:setShadowsEnabled(false) +gworld:setAmbientLight(yake.Color(0,0,0,1)) + +-- create directional light + +local light = gworld:createLight() -- create light + +local lightnode = gworld:createSceneNode() -- attach light to node +lightnode:attach(light) + +light.type = yake.graphics.Light.LT_DIRECTIONAL -- configure light +light:setDiffuseColour(yake.Color(1,1,1,1)) +light.direction = yake.Vector3(0,-1,1) + +-- configure active (=default) camera + +local cam = scene.activeCamera +assert(cam) +cam.nearClipDistance = 0.1 +cam.position = yake.Point3(10,2,10) +cam:setFixedYawAxis( yake.Vector3.UnitY ) -- keep upwards direction constant + +-------------------------------------- +-- Create objects, entities etc +-------------------------------------- + +-- create ninja +local ninja = makeNinja() +ninja.translate = function(self,delta) + ninja.position = ninja.position + delta +end +cam:lookAt( ninja.position ) -- Now look at our ninja! + +-- create trigger +local trigger = makeProximityTrigger() +function onTrigger(yes) + if yes then + print("TRIGGERED") + else + print("UNtriggered") + end + print(trigger.properties.id) + print(trigger.on) +end + +trigger.events.onTriggered:connect(onTrigger) +--trigger:events().onTriggered:connect(onTrigger) +--trigger:events():get("onTriggered"):connect(onTrigger) + +-------------------------------------- +-- Configure input +-------------------------------------- + +local activeKeys = {} -- Store the keys that are active in current frame. + +-- We demonstrate two ways to bind Lua callbacks to a keyboard action. +-- #1 demonstrates the details +-- #2 shows how to achieve the same thing fast and Lua-style + +------ #1: "The Long Way" + +--local idLeft = input.ActionId.fromName("left") -- look up ActionId by its name (useful for user-defined ones) +local idLeft = input.ACTIONID_LEFT -- using an ActionId constant + +-- Connect key "Cursor Left" to action "left": +local acLeft = input.KeyboardActionCondition(app.keyboard, input.KC_LEFT, input.KAM_CONTINUOUS) +actionMap:reg(idLeft,acLeft) + +-- Our Lua callback handler: +function onLeft() + activeKeys["left"] = true +end + +actionMap:connectToAction(idLeft,onLeft) -- by Action ID + +------ #2: "Shortcut" (using action names and anonymous Lua functions) + +actionMap:reg("right", input.KeyboardActionCondition(app.keyboard, input.KC_RIGHT, input.KAM_CONTINUOUS)) +actionMap:connectToAction("right", + function() + activeKeys["right"] = true + end) + +------- Let's define a few helper functions to make things easier: + +function createKeyAction(action, key, keymode) + return actionMap:reg(action, input.KeyboardActionCondition(app.keyboard, key, keymode )) +end +function bindAction(action, handler) + return actionMap:connectToAction(action, handler) +end + +------- Bind the rest of the keys to actions: + +createKeyAction("forward", input.KC_UP, input.KAM_CONTINUOUS) +bindAction("forward", function() + activeKeys["forward"] = true + end) + +createKeyAction("reverse", input.KC_DOWN, input.KAM_CONTINUOUS) +bindAction("reverse", function() + activeKeys["reverse"] = true + end) + +----------------------------------- +function onFrame(timeElapsed) + local distance = 25 * timeElapsed + for k,v in pairs(activeKeys) do + if k == "left" then + ninja:translate( -1 * yake.Vector3.UnitX * distance ) + elseif k == "right" then + ninja:translate( 1 * yake.Vector3.UnitX * distance ) + elseif k == "forward" then + ninja:translate( -1 * yake.Vector3.UnitZ * distance ) + elseif k == "reverse" then + ninja:translate( 1 * yake.Vector3.UnitZ * distance ) + end + end + -- prepare for next frame: + activeKeys = {} +end \ No newline at end of file Modified: trunk/yake/scripts/premake/samples.lua =================================================================== --- trunk/yake/scripts/premake/samples.lua 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/scripts/premake/samples.lua 2007-09-04 17:17:53 UTC (rev 1832) @@ -127,9 +127,16 @@ useComponent("base") useComponent("raf") useComponent("bindings.lua") - --useComponent("scriptingLua") useDep("lua") useDep("luabind") + + -------------------------------------- + makeSample("sampleRafLuaDemo2","samples/raf/lua2") + useComponent("base") + useComponent("raf") + useComponent("bindings.lua") + useDep("lua") + useDep("luabind") end end Modified: trunk/yake/scripts/premake/yake.lua =================================================================== --- trunk/yake/scripts/premake/yake.lua 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/scripts/premake/yake.lua 2007-09-04 17:17:53 UTC (rev 1832) @@ -97,8 +97,14 @@ addDefine("YAKE_BASE_EXPORTS") --package.pchheader = "yake/base/yakePCH.h" --package.pchsource = rootdir.."src/base/yakePCH.cpp" + addMatching("yake/base/*.h") addMatching("yake/base/*.inl") + addMatching("yake/base/math/*.h") + addMatching("yake/base/math/*.inl") + addMatching("yake/base/templates/*.h") + addMatching("yake/base/templates/*.inl") + addMatching("src/base/*.cpp") addMatching("src/base/math/*.cpp") addMatching("src/base/templates/*.cpp") Modified: trunk/yake/src/base/math/yakeMatrix3.cpp =================================================================== --- trunk/yake/src/base/math/yakeMatrix3.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/base/math/yakeMatrix3.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -153,7 +153,33 @@ } return kProd; } - //----------------------------------------------------------------------- + //----------------------------------------------------------------------- + Point3 Matrix3::operator* (const Point3& rkPoint) const + { + Point3 kProd; + for (int iRow = 0; iRow < 3; iRow++) + { + kProd[iRow] = + m[iRow][0]*rkPoint[0] + + m[iRow][1]*rkPoint[1] + + m[iRow][2]*rkPoint[2]; + } + return kProd; + } + //----------------------------------------------------------------------- + Point3 operator* (const Point3& rkPoint, const Matrix3& rkMatrix) + { + Point3 kProd; + for (int iRow = 0; iRow < 3; iRow++) + { + kProd[iRow] = + rkPoint[0]*rkMatrix.m[0][iRow] + + rkPoint[1]*rkMatrix.m[1][iRow] + + rkPoint[2]*rkMatrix.m[2][iRow]; + } + return kProd; + } + //----------------------------------------------------------------------- Matrix3 Matrix3::operator- () const { Matrix3 kNeg; Modified: trunk/yake/src/base/math/yakeQuaternion.cpp =================================================================== --- trunk/yake/src/base/math/yakeQuaternion.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/base/math/yakeQuaternion.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -30,6 +30,7 @@ #include <yake/base/yakePCH.h> #include <yake/base/math/yakeQuaternion.h> #include <yake/base/math/yakeMatrix3.h> +#include <yake/base/math/yakePoint3.h> //============================================================================ @@ -364,6 +365,12 @@ return v + uv + uuv; } + //----------------------------------------------------------------------- + Point3 Quaternion::operator* (const Point3& v) const + { + Vector3 ret = *this * v.asVector(); + return Point3(ret.x,ret.y,ret.z); + } //----------------------------------------------------------------------- Quaternion Quaternion::Slerp (real fT, const Quaternion& rkP, const Quaternion& rkQ, bool shortestPath) Modified: trunk/yake/src/base/math/yakeRay.cpp =================================================================== --- trunk/yake/src/base/math/yakeRay.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/base/math/yakeRay.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -41,7 +41,7 @@ } else { - real nom = plane.normal.dotProduct(mOrigin) + plane.d; + real nom = plane.normal.dotProduct(mOrigin.asVector()) + plane.d; real t = -(nom/denom); return std::pair<bool, real>(t >= 0, t); } Modified: trunk/yake/src/base/math/yakeVector3.cpp =================================================================== --- trunk/yake/src/base/math/yakeVector3.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/base/math/yakeVector3.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -29,6 +29,7 @@ //============================================================================ #include <yake/base/yakePCH.h> #include <yake/base/math/yakeVector3.h> +#include <yake/base/math/yakePoint3.h> //============================================================================ // INTERFACE STRUCTURES / UTILITY CLASSES @@ -36,6 +37,7 @@ namespace yake { namespace math { + const Point3 Point3::kZero( 0, 0, 0 ); const Vector3 Vector3::kZero( 0, 0, 0 ); const Vector3 Vector3::kUnitX( 1, 0, 0 ); const Vector3 Vector3::kUnitY( 0, 1, 0 ); Added: trunk/yake/src/base/math/yakeVolume.cpp =================================================================== --- trunk/yake/src/base/math/yakeVolume.cpp (rev 0) +++ trunk/yake/src/base/math/yakeVolume.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -0,0 +1,104 @@ +/* + ------------------------------------------------------------------------------------ + This file is part of YAKE + Copyright (c) 2004 - 2008 The YAKE Team + For the latest information visit http://www.yake.org + ------------------------------------------------------------------------------------ + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA, or go to + http://www.gnu.org/copyleft/lesser.txt. + ------------------------------------------------------------------------------------ + If you are interested in another license model contact the Yake Team via + E-Mail: te...@ya.... + For more information see the LICENSE file in the root directory of the + source code distribution. + ------------------------------------------------------------------------------------ +*/ + +#include <yake/base/yakePCH.h> +#include <yake/base/math/yakeVolume.h> + +namespace yake { + + Volume::~Volume() {} + + Sphere::Sphere(const real r, const Point3& pos) : radius(r), position(pos) + {} + bool Sphere::intersectsWith(const Sphere& other) const + { + const real dist = (position-other.position).length(); + return (dist <= (radius + other.radius)); + } + bool Sphere::intersectsWith(const Point3& other) const + { + const real dist = (position-other).squaredLength(); + return (dist < radius*radius); + } + + VolumeContainer::~VolumeContainer() + { + clear(); + } + void VolumeContainer::add(Volume* vol) + { + YAKE_ASSERT( vol ); + if (vol) + volumes_.insert( vol ); + } + void VolumeContainer::destroy(Volume* vol) + { + YAKE_ASSERT( vol ); + if (vol) + { + Volumes::iterator it = volumes_.find(vol); + if (it != volumes_.end()) + { + delete (*it); + volumes_.erase(it); + } + } + } + void VolumeContainer::clear() + { + YAKE_FOR_EACH(Volumes::iterator, it, volumes_) + { + delete (*it); + } + volumes_.clear(); + } + size_t VolumeContainer::size() const + { + return volumes_.size(); + } + bool VolumeContainer::intersectsWith(const Sphere& other) const + { + YAKE_FOR_EACH(Volumes::const_iterator, it, volumes_) + { + Volume* vol = *it; + if (vol->intersectsWith(other)) + return true; + } + return false; + } + bool VolumeContainer::intersectsWith(const Point3& other) const + { + YAKE_FOR_EACH(Volumes::const_iterator, it, volumes_) + { + Volume* vol = *it; + if (vol->intersectsWith(other)) + return true; + } + return false; + } + +} // yake Modified: trunk/yake/src/bindings.lua/bindings.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/bindings.lua.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/bindings.lua/bindings.lua.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -67,9 +67,6 @@ #if YAKE_ENABLE_LUA_TASK == 1 bind_task(L); #endif -#if YAKE_ENABLE_LUA_MODEL == 1 - bind_model(L); -#endif #if YAKE_ENABLE_LUA_PROPERTY == 1 bind_property(L); #endif @@ -85,6 +82,9 @@ #if YAKE_ENABLE_LUA_INPUT == 1 bind_input(L); #endif +#if YAKE_ENABLE_LUA_MODEL == 1 + bind_model(L); +#endif #if YAKE_ENABLE_LUA_RAF == 1 bind_raf(L); #endif Modified: trunk/yake/src/bindings.lua/detail/base.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/base.lua.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/bindings.lua/detail/base.lua.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -38,6 +38,7 @@ #include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <luabind/operator.hpp> +#include <luabind/adopt_policy.hpp> namespace yake { namespace math { @@ -49,7 +50,44 @@ { return rhs * lhs; } + inline Point3 operator * (const Point3& lhs, const Quaternion& rhs) + { + return rhs * lhs; + } + inline Point3 operator * (const Point3& lhs, const Matrix3& rhs) + { + return rhs * lhs; + } //------------------------------------------------------------------------- + struct VolumeContainerRef + { + VolumeContainerRef() : px_(new VolumeContainer()) + { + } + void add(Volume* vol) + { + YAKE_ASSERT( px_ ); + px_->add( vol ); + } + size_t size() const + { + YAKE_ASSERT( px_ ); + return px_->size(); + } + bool intersectsWith(const Point3& other) const + { + YAKE_ASSERT( px_ ); + return px_->intersectsWith(other); + } + bool intersectsWith(const Sphere& other) const + { + YAKE_ASSERT( px_ ); + return px_->intersectsWith(other); + } + typedef boost::shared_ptr<VolumeContainer> ctr_pointer; + ctr_pointer px_; + }; + //------------------------------------------------------------------------- namespace { struct AnyConverterIniter { @@ -57,8 +95,15 @@ { register_any_converter<Color>(); register_any_converter<Vector3>(); + register_any_converter<Point3>(); register_any_converter<Quaternion>(); register_any_converter<Matrix3>(); + + //register_any_converter<Sphere*>(); + //register_any_converter<VolumeContainer>(); + register_any_converter<VolumeContainerRef>(); + register_any_converter<VolumeContainer*>(); + //register_any_converter<boost::shared_ptr<VolumeContainer> >(); } } g_initer; } // namespace @@ -139,6 +184,31 @@ luabind::globals(L)["yake"]["Vector3"]["UnitY"] = Vector3::kUnitY; luabind::globals(L)["yake"]["Vector3"]["UnitZ"] = Vector3::kUnitZ; + // Point3 + module( YAKE_MATH_MODULE ) + [ + class_< Point3 >( "Point3" ) + .def_readwrite( "x", &Point3::x ) + .def_readwrite( "y", &Point3::y ) + .def_readwrite( "z", &Point3::z ) + .def( constructor<>() ) + .def( constructor< real, real, real >() ) + .def( constructor< const real* const >() ) + .def( constructor< Point3 const& >() ) + .def(const_self + other<Vector3>()) + .def(const_self - other<Vector3>()) + .def(const_self == other<Point3>()) + .def(const_self / real()) + .def(const_self * other<real>()) + .def(const_self * Quaternion()) + .def(const_self * Matrix3()) + .def(real() * const_self) + .def(Quaternion() * const_self) + .def(Matrix3() * const_self) + .def(tostring(const_self)) + ]; + luabind::globals(L)["yake"]["Point3"]["Zero"] = Point3::kZero; + // Vector4 module( YAKE_MATH_MODULE ) [ @@ -184,18 +254,51 @@ [ class_< Ray >( "Ray" ) .def( constructor<>() ) - .def( constructor<const Vector3&, const Vector3&>() ) + .def( constructor<const Point3&, const Vector3&>() ) .property( "origin", &Ray::getOrigin, &Ray::setOrigin ) .property( "direction", &Ray::getDirection, &Ray::setDirection ) .def("getPoint", &Ray::getPoint) ]; + // Volumes + module( YAKE_MATH_MODULE ) + [ + class_<Volume>("Volume") + .def( "intersectsWith", (bool(Volume::*)(const Sphere&)const)&Volume::intersectsWith) + .def( "intersectsWith", (bool(Volume::*)(const Point3&)const)&Volume::intersectsWith) + , + class_<Sphere,Volume>("Sphere") + .def_readwrite( "position", &Sphere::position ) + .def_readwrite( "radius", &Sphere::radius ) + .def( constructor<>() ) + .def( constructor<real>() ) + .def( constructor<real,Point3>() ) + .def( "intersectsWith", (bool(Sphere::*)(const Sphere&)const)&Volume::intersectsWith) + .def( "intersectsWith", (bool(Sphere::*)(const Point3&)const)&Volume::intersectsWith) + , + class_<VolumeContainer,boost::shared_ptr<VolumeContainer> >("VolumeContainer") + .def(constructor<>()) + .def("add",&VolumeContainer::add,adopt(_2)) + .def("destroy",&VolumeContainer::destroy) + .def("clear",&VolumeContainer::clear) + .property("size",&VolumeContainer::size) + .def( "intersectsWith", (bool(VolumeContainer::*)(const Sphere&)const)&VolumeContainer::intersectsWith) + .def( "intersectsWith", (bool(VolumeContainer::*)(const Point3&)const)&VolumeContainer::intersectsWith) + , + class_<VolumeContainerRef>("VolumeContainerRef") + .def(constructor<>()) + .def("add",&VolumeContainerRef::add,adopt(_2)) + .property("size",&VolumeContainerRef::size) + .def( "intersectsWith", (bool(VolumeContainerRef::*)(const Sphere&)const)&VolumeContainerRef::intersectsWith) + .def( "intersectsWith", (bool(VolumeContainerRef::*)(const Point3&)const)&VolumeContainerRef::intersectsWith) + ]; + // RandomNumberGenerator typedef RandomNumberGenerator rng_type; module( YAKE_MATH_MODULE ) [ class_< rng_type >( "RandomNumberGenerator" ) - .def( constructor<>() ) + .def( constructor<>() ) .def( "setSeed", &rng_type::setSeed ) .def( "getSeed", &rng_type::getSeed ) .def( "randInt", &rng_type::randInt ) Modified: trunk/yake/src/bindings.lua/detail/ent.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -56,6 +56,21 @@ } // namespace //------------------------------------------------------------------------- + luabind::object ObjectManager_getAllObjects(ObjectManager& objMgr, lua_State* L) + { + YAKE_ASSERT( L ); + const ObjectManager::const_object_iterator itEnd = objMgr.endObjects(); + ObjectManager::const_object_iterator it = objMgr.beginObjects(); + luabind::object o = luabind::newtable(L); + for (; it != itEnd; ++it) + { + Object* obj = *it; + //@todo luabind::object[ obj->id() ] = cast_to_this(obj->isA()); + o[ obj->id() ] = obj; + } + return o; + } + //------------------------------------------------------------------------- // For Lua's tostring(): // std::ostream& operator<<(std::ostream& out, const ObjectId& rhs) // { @@ -77,7 +92,7 @@ static Object_NameEventPair* Object_EventAccess_getByIndex(Object::EventAccess& acc, int index) { index -= 1; // Lua arrays usually start with 1, so convert to 0-offset-array. - if (index < 0 || index > acc.size()) + if (index < 0 || index > int(acc.size())) return 0; Object_NameEventPair ret = acc.__getByIndex(index); if (ret.first.empty()) @@ -106,6 +121,11 @@ { return o.properties().get(id).get(); } + static Object::PropertyAccess* getObjectPopertiesAccessor(Object& o) + { + Object::PropertyAccess& x = o.properties(); + return &x; + } static Object::PropertyAccess* getObjectPoperties(Object& o) { Object::PropertyAccess& x = o.properties(); @@ -118,7 +138,7 @@ static property::NamePropertyPair* Object_PropertyAccess_get_byIndex(Object::PropertyAccess& o, int index) { index -= 1; // Lua tables usually start with 1 - if (index >= o.size() || index < 0) + if (index >= int(o.size()) || index < 0) return 0; YAKE_ASSERT( o.owner().__properties() ).debug("invalid internal state"); const NamedProperties& props = *o.owner().__properties(); @@ -137,11 +157,22 @@ ret->prop = it->second.get(); return ret; } - static Object::EventAccess* getObjectEvents(Object& o) + static Object::EventAccess* getObjectEventsAccessor(Object& o) { Object::EventAccess& x = o.events(); return &x; } + static luabind::object getObjectEventsTable(Object& obj, lua_State* L) + { + YAKE_ASSERT(L); + luabind::object o = luabind::newtable(L); + for (size_t i=0; i<obj.events().size(); ++i) + { + std::pair<Object::Event::ID,Object::Event::pointer> succ = obj.events().__getByIndex( i ); + o[ succ.first ] = succ.second; + } + return o; + } struct TriggerConditionWrapper { luabind::object fn_; @@ -156,6 +187,16 @@ YAKE_LOG_ERROR("ent.lua",String("TriggerConditionWrapper: cast_failed: ") + ex.what()); return false; } + catch (luabind::error& ex) + { + YAKE_LOG_ERROR("ent.lua",String("TriggerConditionWrapper: error: ") + ex.what()); + return false; + } + catch (std::exception& ex) + { + YAKE_LOG_ERROR("ent.lua",String("TriggerConditionWrapper: unknown: ") + ex.what()); + return false; + } } }; static void Trigger_setCondition(Trigger& trigger, luabind::object o) @@ -287,6 +328,12 @@ .def( "add", &Object::EventAccess::add ) .def( "create", &Object::EventAccess::createAndAdd ) ]; + module(YAKE_MODEL_MODULE) + [ + class_<RttiClass>("RttiClass") + .property("name",&RttiClass::name) + .def(tostring(const_self)) + ]; LuabindClass_Object x_Object("Object"); x_Object @@ -294,9 +341,13 @@ //.def( "setId", &Object::setId ) //.def( "id", &Object::getId ) .property( "id", &Object::getId, &Object::setId ) - .def( "events", &getObjectEvents ) + .def( "isA", &Object::isA) + .def( "evts", &getObjectEventsTable, raw(_2) ) + .def( "events", &getObjectEventsAccessor ) + .def( "eventAccessor", &getObjectEventsAccessor ) .def( "property", &getPropertyOfObject ) .def( "properties", &getObjectPoperties ) + .def( "propertyAccessor", &getObjectPopertiesAccessor ) //.def( "properties", return_reference_to(_1) ) .def(tostring(const_self)) ; @@ -312,6 +363,9 @@ .def( "setModel", &Entity::setModel ) .def( "getModel", &Entity::getModel ) + .property( "position", &Entity::getPosition, &Entity::setPosition ) + .def( "setPositionSource", &Entity::setPositionSource ) + .def( "addFsmState", &Entity::addFsmState ) .def( "addFsmTransition", &Entity::addFsmTransition ) .def( "setFsmState", &Entity::setFsmState ) @@ -329,6 +383,11 @@ module( YAKE_MODEL_MODULE ) [ + class_<VolumeTrigger,Trigger>( "VolumeTrigger" ) + ]; + + module( YAKE_MODEL_MODULE ) + [ def( "asEntity", &Entity::cast ), def( "asTrigger", &Trigger::cast ) ]; @@ -340,6 +399,7 @@ .def( "getObject", &ObjectManager::getObject ) .def( "destroyObject", &ObjectManager::destroyObject ) .def( "getClassNamesAndIds", &ObjectManager::getClassNamesAndIds ) + .def( "getAllObjects", &ObjectManager_getAllObjects, raw(_2) ) ]; } @@ -397,8 +457,8 @@ LuaFsmObjectListener::LuaFsmObjectListener(scripting::IScriptingSystem& scriptingSystem) : scriptingSystem_(scriptingSystem) { - startScript_ = scriptingSystem_.createScriptFromFile("o_access.lua"); - YAKE_ASSERT( startScript_.get() ); + //startScript_ = scriptingSystem_.createScriptFromFile("o_access.lua"); + //YAKE_ASSERT( startScript_.get() ); } void LuaFsmObjectListener::onInit(Object& obj) { @@ -407,7 +467,8 @@ { YAKE_ASSERT( ent->getFsmVM() ); ent->getFsmVM()->execute("print('initializing...')"); - ent->getFsmVM()->execute( startScript_ ); + if (startScript_) + ent->getFsmVM()->execute( startScript_ ); scripting::LuaVM* vm = static_cast<scripting::LuaVM*>(ent->getFsmVM().get()); YAKE_ASSERT( vm ); Modified: trunk/yake/src/bindings.lua/detail/graphics.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/graphics.lua.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/bindings.lua/detail/graphics.lua.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -54,6 +54,7 @@ #include <luabind/discard_result_policy.hpp> #include <luabind/iterator_policy.hpp> #include <luabind/operator.hpp> +#include <luabind/adopt_policy.hpp> namespace yake { namespace graphics { @@ -190,13 +191,15 @@ //@todo ISkeleton etc pp // class_<IWorld>("World") - .def("createSceneNode", &IWorld::createSceneNode) - .def("createSceneNode", &IWorld_createSceneNode_NoName) - .def("createEntity", &IWorld::createEntity) - .def("createParticleSystem", &IWorld::createParticleSystem) - .def("createLight", &IWorld::createLight) - .def("createCamera", &IWorld::createCamera) - .def("createViewport", &IWorld::createViewport) + //.def("createSceneNode", &IWorld::createSceneNode, adopt(result)) + //.def("createSceneNode", &IWorld_createSceneNode_NoName, adopt(result)) + .def("createSceneNode", &IWorld::createSceneNode, dependency(result,_1)) + .def("createSceneNode", &IWorld_createSceneNode_NoName, dependency(result,_1)) + .def("createEntity", &IWorld::createEntity, dependency(result,_1)) + .def("createParticleSystem", &IWorld::createParticleSystem, dependency(result,_1)) + .def("createLight", &IWorld::createLight, dependency(result,_1)) + .def("createCamera", &IWorld::createCamera, dependency(result,_1)) + .def("createViewport", &IWorld::createViewport, dependency(result,_1)) .def("load", &IWorld::load) .def("setShadowsEnabled", &IWorld::setShadowsEnabled) .def("setAmbientLight", &IWorld::setAmbientLight) Modified: trunk/yake/src/bindings.lua/detail/model.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/model.lua.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/bindings.lua/detail/model.lua.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -38,9 +38,26 @@ #include <luabind/discard_result_policy.hpp> #include <luabind/iterator_policy.hpp> +#include <luabind/adopt_policy.hpp> namespace yake { namespace model { + Graphical* Model_createGraphical(Model& m) + { + Graphical* c = new Graphical(); + m.addComponent( c ); + return c; + } + void Graphical_addSceneNode(Graphical* g, graphics::ISceneNode* node) + { + YAKE_ASSERT(g); + g->addSceneNode( node, uniqueName::create("bindings.lua_model_sn") ); + } + void Graphical_addSceneNodeWithPath(Graphical* g, graphics::ISceneNode* node, const String& path) + { + YAKE_ASSERT(g); + g->addSceneNode( node, path ); + } Model* ModelManager_createModel(ModelManager* mgr, const String& modelName, const String& def) { return (mgr ? mgr->createModel(modelName,def).get() : 0); @@ -56,7 +73,7 @@ return false; if (!link) return false; - typedef boost::function<void(const Vector3&)> Fn; + typedef boost::function<void(const Point3&)> Fn; link->subscribeToPositionChanged( boost::bind(Fn(o),_1) ); return true; } @@ -87,7 +104,11 @@ [ class_<Graphical,ModelComponent>( "Graphical" ) .def( constructor<>() ) - .def( "addSceneNode", &Graphical::addSceneNode ) + //.def( "addSceneNode", &Graphical_addSceneNode, adopt(_2) ) + //.def( "addSceneNode", &Graphical_addSceneNodeWithPath, adopt(_2) ) + .def( "addSceneNode", &Graphical_addSceneNode ) + .def( "addSceneNode", &Graphical_addSceneNodeWithPath ) + //.def( "getSceneNodes", &Graphical::getSceneNodes ) .def( "getSceneNode", &Graphical::getSceneNode ) .def( "getEntity", &Graphical::getEntity ) @@ -133,6 +154,10 @@ .def( "createLink", &Model::createLink) .def( "createDirectLink", &Model::createDirectLink) .def( "createWorldSpaceLink", &Model::createWorldSpaceLink) + .def( "add", (void(Model::*)(ModelComponent*))&Model::addComponent, adopt(_2)) + .def( "add", (void(Model::*)(ModelComponent*,const String&))&Model::addComponent, adopt(_2)) + //---------- + .def( "createGraphical", &Model_createGraphical ) , class_<ModelManager>( "ModelManager" ) .def("clear", &ModelManager::clear) Modified: trunk/yake/src/bindings.lua/detail/physics.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/physics.lua.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/bindings.lua/detail/physics.lua.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -124,28 +124,28 @@ , class_<IShape::SphereDesc,IShape::Desc>("SphereDesc") .def(constructor<real>()) - .def(constructor<real,const Vector3&>()) - .def(constructor<real,const Vector3&,const Quaternion&>()) + .def(constructor<real,const Point3&>()) + .def(constructor<real,const Point3&,const Quaternion&>()) , class_<IShape::BoxDesc,IShape::Desc>("BoxDesc") .def(constructor<const Vector3&>()) - .def(constructor<const Vector3&,const Vector3&>()) - .def(constructor<const Vector3&,const Vector3&,const Quaternion&>()) + .def(constructor<const Vector3&,const Point3&>()) + .def(constructor<const Vector3&,const Point3&,const Quaternion&>()) , class_<IShape::PlaneDesc,IShape::Desc>("PlaneDesc") .def(constructor<const Vector3&,real>()) - .def(constructor<const Vector3&,real,const Vector3&>()) - .def(constructor<const Vector3&,real,const Vector3&,const Quaternion&>()) + .def(constructor<const Vector3&,real,const Point3&>()) + .def(constructor<const Vector3&,real,const Point3&,const Quaternion&>()) , class_<IShape::CapsuleDesc,IShape::Desc>("CapsuleDesc") .def(constructor<real,real>()) - .def(constructor<real,real,const Vector3&>()) - .def(constructor<real,real,const Vector3&,const Quaternion&>()) + .def(constructor<real,real,const Point3&>()) + .def(constructor<real,real,const Point3&,const Quaternion&>()) , class_<IShape::TriMeshDesc,IShape::Desc>("TriMeshDesc") .def(constructor<TriangleMeshId>()) - .def(constructor<TriangleMeshId,const Vector3&>()) - .def(constructor<TriangleMeshId,const Vector3&,const Quaternion&>()) + .def(constructor<TriangleMeshId,const Point3&>()) + .def(constructor<TriangleMeshId,const Point3&,const Quaternion&>()) ] , class_<IActor,Movable>("Actor") Modified: trunk/yake/src/bindings.lua/detail/property.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -97,10 +97,11 @@ // As a last resort try to convert to luabind::object property: // For details read the comments for register_any_converter<luabind::object>() // specialization. +#if 0 PropertyPtr prop( convert_any<luabind::object>::yake_createValuePropertyFromObject( o ) ); if (prop.get()) return prop; - +#endif //@todo use proper logging: std::cerr << "ERROR: bindings.lua:yake.property.createProperty: unhandled type\n"; return PropertyPtr(); Modified: trunk/yake/src/ent/entity.cpp =================================================================== --- trunk/yake/src/ent/entity.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/ent/entity.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -32,10 +32,30 @@ IMPL_OBJECT(Entity) - Entity::Entity() + Entity::Entity() : posSource_(0) { properties().add("model", property::makePointerProperty<ModelPtr>(&model_) ); } + void Entity::setPositionSource(PositionSource source) + { + posSource_ = source; + if (posSource_) + pos_ = posSource_->getDerivedPosition(); + } + Point3 Entity::getPosition() const + { + return (posSource_ ? posSource_->getDerivedPosition() : pos_); + } + void Entity::setPosition(const Point3& pos) + { + if (posSource_) + { + posSource_->setPosition( pos ); + pos_ = posSource_->getDerivedPosition(); + } + else + pos_ = pos; + } void Entity::processFsmEvent(const fsm_event_type& evt) { // On MSVC8 the following line of code works but fails miserable with GCC 3.4.2 (MinGW). Modified: trunk/yake/src/ent/trigger.cpp =================================================================== --- trunk/yake/src/ent/trigger.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/ent/trigger.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -79,5 +79,28 @@ this->events().get("onTriggered")->fire( (state=="on") ); } + + IMPL_OBJECT(VolumeTrigger) + + VolumeTrigger::VolumeTrigger() + { + } + const VolumeContainer& VolumeTrigger::volumes() const + { + return volumes_; + } + VolumeContainer& VolumeTrigger::volumes() + { + return volumes_; + } + void VolumeTrigger::onTick() + { + Trigger::onTick(); + } + void VolumeTrigger::onPreDestroy() + { + volumes_.clear(); + } + } // namespace ent } // namespace yake Modified: trunk/yake/src/graphics/yakeGraphicsSystem.cpp =================================================================== --- trunk/yake/src/graphics/yakeGraphicsSystem.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/graphics/yakeGraphicsSystem.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -94,18 +94,19 @@ } /** @Remarks Code has been taken more or less directly from Ogre's OgreCamera.cpp. */ - math::Ray ICamera::createCameraToViewportRay(const real screenX, const real screenY) const + Ray ICamera::createCameraToViewportRay(const real screenX, const real screenY) const { real centeredScreenX = (screenX - 0.5f); real centeredScreenY = (0.5f - screenY); const real nearDist = getNearClipDistance(); - real normalizedSlope = math::Math::Tan(getFOV() / 2); // getFOV() returns FOVy + real normalizedSlope = Math::Tan(getFOV() / 2); // getFOV() returns FOVy real viewportYToWorldY = normalizedSlope * nearDist * 2; real viewportXToWorldX = viewportYToWorldY * getAspectRatio(); - math::Vector3 rayOrigin, rayDirection; + Point3 rayOrigin; + Vector3 rayDirection; if (getProjectionType() == PT_PERSPECTIVE) { rayOrigin = getPosition(); //@todo fixme should be: getDerivedPosition() @@ -123,9 +124,9 @@ rayOrigin.z = 0.0f; rayOrigin = getOrientation() * rayOrigin; //@todo fixme should be: getDerivedOrientation() * rayOrigin; rayOrigin = getPosition() + rayOrigin; //@todo fixme should be: getDerivedPosition() + rayOrigin; - rayDirection = getOrientation() * math::Vector3::kUnitZ; //@todo fixme should be: getDerivedDirection(); + rayDirection = getOrientation() * Vector3::kUnitZ; //@todo fixme should be: getDerivedDirection(); } - return math::Ray( rayOrigin, rayDirection ); + return Ray( rayOrigin, rayDirection ); } } // graphics Modified: trunk/yake/src/loader/yakeDotScene.cpp =================================================================== --- trunk/yake/src/loader/yakeDotScene.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/loader/yakeDotScene.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -205,7 +205,7 @@ } //------------------------------------------------------ - void DotSceneParser::readVector( const SharedPtr<dom::INode>& pNode, math::Vector3& rVec ) + void DotSceneParser::readVector( const SharedPtr<dom::INode>& pNode, Vector3& rVec ) { YAKE_ASSERT( pNode ); rVec.x = StringUtil::parseReal( pNode->getAttributeValueAs<String>("x") ); @@ -214,19 +214,28 @@ } //------------------------------------------------------ - void DotSceneParser::readPosition( const SharedPtr<dom::INode> & pNode, math::Vector3 & position ) + void DotSceneParser::readPoint( const SharedPtr<dom::INode>& pNode, Point3& rVec ) { - readVector( pNode, position ); + YAKE_ASSERT( pNode ); + rVec.x = StringUtil::parseReal( pNode->getAttributeValueAs<String>("x") ); + rVec.y = StringUtil::parseReal( pNode->getAttributeValueAs<String>("y") ); + rVec.z = StringUtil::parseReal( pNode->getAttributeValueAs<String>("z") ); } //------------------------------------------------------ - void DotSceneParser::readScale( const SharedPtr<dom::INode>& pNode, math::Vector3& rScale ) + void DotSceneParser::readPosition( const SharedPtr<dom::INode> & pNode, Point3 & position ) { + readPoint( pNode, position ); + } + + //------------------------------------------------------ + void DotSceneParser::readScale( const SharedPtr<dom::INode>& pNode, Vector3& rScale ) + { readVector( pNode, rScale ); } //------------------------------------------------------ - void DotSceneParser::readRotation( const SharedPtr<dom::INode>& pNode, math::Quaternion& rotation ) + void DotSceneParser::readRotation( const SharedPtr<dom::INode>& pNode, Quaternion& rotation ) { YAKE_ASSERT( pNode ); if ( pNode->getAttributeValueAs<String>("qx") != "" ) @@ -238,7 +247,7 @@ } else if ( pNode->getAttributeValueAs<String>("axisX") != "" ) { - math::Vector3 axis; + Vector3 axis; axis.x = StringUtil::parseReal( pNode->getAttributeValueAs<String>("axisX") ); axis.y = StringUtil::parseReal( pNode->getAttributeValueAs<String>("axisY") ); axis.z = StringUtil::parseReal( pNode->getAttributeValueAs<String>("axisZ") ); @@ -246,7 +255,7 @@ } else if ( pNode->getAttributeValueAs<String>("angleX") != "" ) { - math::Vector3 axis; + Vector3 axis; axis.x = StringUtil::parseReal( pNode->getAttributeValueAs<String>("angleX") ); axis.y = StringUtil::parseReal( pNode->getAttributeValueAs<String>("angleY") ); axis.z = StringUtil::parseReal( pNode->getAttributeValueAs<String>("angleZ") ); @@ -255,7 +264,7 @@ } } //------------------------------------------------------ - void DotSceneParser::readColour( const SharedPtr<dom::INode>& pNode, math::Color& colour ) + void DotSceneParser::readColour( const SharedPtr<dom::INode>& pNode, Color& colour ) { YAKE_ASSERT( pNode ); Modified: trunk/yake/src/loader/yakeXODEParser.cpp =================================================================== --- trunk/yake/src/loader/yakeXODEParser.cpp 2007-08-31 03:36:26 UTC (rev 1831) +++ trunk/yake/src/loader/yakeXODEParser.cpp 2007-09-04 17:17:53 UTC (rev 1832) @@ -143,25 +143,35 @@ }; //------------------------------------------------------ - void XODEParser::readVector3( const NodeSharedPtr pVecNode, math::Vector3& rVec ) + void XODEParser::readVector3( const NodeSharedPtr pVecNode, Vector3& rVec ) { real x = StringUtil::parseReal( pVecNode->getAttributeValueAs<String>( "x" ) ); real y = StringUtil::parseReal( pVecNode->getAttributeValueAs<String>( "y" ) ); real z = StringUtil::parseReal( pVecNode->getAttributeValueAs<String>( "z" ) ); - rVec = math::Vector3( x, y, z ); + rVec = Vector3( x, y, z ); } - //------------------------------------------------------ - void XODEParser::readScale( const NodeSharedPtr pScaleNode, math::Vector3& rScale ) + //------------------------------------------------------ + void XODEParser::readPoint3( const NodeSharedPtr pVecNode, Point3& rVec ) + { + real x = StringUtil::parseReal( pVecNode->getAttributeValueAs<String>( "x" ) ); + real y = StringUtil::parseReal( pVecNode->getAttributeValueAs<String>( "y" ) ); + real z = StringUtil::parseReal( pVecNode->getAttributeValueAs<String>( "z" ) ); + + rVec = Point3( x, y, z ); + } + + //------------------------------------------------------ + void XODEParser::readScale( const NodeSharedPtr pScaleNode, Vector3& rScale ) { readVector3( pScaleNode, rScale ); } //------------------------------------------------------ - void XODEParser::readPosition( c... [truncated message content] |
From: <psy...@us...> - 2007-08-31 03:36:29
|
Revision: 1831 http://yake.svn.sourceforge.net/yake/?rev=1831&view=rev Author: psyclonist Date: 2007-08-30 20:36:26 -0700 (Thu, 30 Aug 2007) Log Message: ----------- * [luadocs] updates to parser and content Modified Paths: -------------- tools/luadocs/lua_bindings_2_rst.cmd tools/luadocs/lua_bindings_2_rst.lua tools/luadocs/project.txt Added Paths: ----------- tools/luadocs/index.html Removed Paths: ------------- tools/luadocs/project.html Added: tools/luadocs/index.html =================================================================== --- tools/luadocs/index.html (rev 0) +++ tools/luadocs/index.html 2007-08-31 03:36:26 UTC (rev 1831) @@ -0,0 +1,778 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" /> +<title>Yake's Lua Scripting Reference (for Yake 0.7.0)</title> +<meta name="author" content="LuaBindingsDoc" /> +<meta content="The official API documentation for the Yake Lua bindings." name="description" /> +<link rel="stylesheet" href="lua_bindings.css" type="text/css" /> +</head> +<body> +<div class="document" id="yake-s-lua-scripting-reference-for-yake-0-7-0"> +<h1 class="title">Yake's Lua Scripting Reference (for Yake 0.7.0)</h1> +<table class="docinfo" frame="void" rules="none"> +<col class="docinfo-name" /> +<col class="docinfo-content" /> +<tbody valign="top"> +<tr><th class="docinfo-name">Author:</th> +<td>LuaBindingsDoc</td></tr> +<tr class="field"><th class="docinfo-name">Generated on:</th><td class="field-body">31 Aug 2007</td> +</tr> +<tr><th class="docinfo-name">Status:</th> +<td>Draft</td></tr> +</tbody> +</table> +<div class="section" id="namespace-yake"> +<h1>1 namespace: yake</h1> +<div class="contents local topic" id="table-of-contents"> +<p class="topic-title first">Table of Contents</p> +<ul class="auto-toc simple"> +<li><a class="reference" href="#namespace-base" id="id4">1.1 namespace: base</a><ul> +<li><a class="reference" href="#color" id="id5">Color</a></li> +<li><a class="reference" href="#math" id="id6">Math</a></li> +<li><a class="reference" href="#vector3" id="id7">Vector3</a></li> +<li><a class="reference" href="#point3" id="id8">Point3</a></li> +<li><a class="reference" href="#vector4" id="id9">Vector4</a></li> +<li><a class="reference" href="#matrix3" id="id10">Matrix3</a></li> +<li><a class="reference" href="#quaternion" id="id11">Quaternion</a></li> +<li><a class="reference" href="#volume" id="id12">Volume</a></li> +<li><a class="reference" href="#volumecontainer" id="id13">VolumeContainer</a></li> +<li><a class="reference" href="#sphere" id="id14">Sphere</a></li> +</ul> +</li> +<li><a class="reference" href="#namespace-input" id="id15">1.2 namespace: input</a><ul> +<li><a class="reference" href="#device" id="id16">Device</a></li> +<li><a class="reference" href="#keyboarddevice" id="id17">KeyboardDevice</a></li> +<li><a class="reference" href="#whateverdevice" id="id18">WhateverDevice</a></li> +</ul> +</li> +<li><a class="reference" href="#namespace-ent" id="id19">1.3 namespace: ent</a><ul> +<li><a class="reference" href="#objectid" id="id20">ObjectId</a></li> +<li><a class="reference" href="#propertyaccess" id="id21">PropertyAccess</a></li> +<li><a class="reference" href="#object" id="id22">Object</a></li> +<li><a class="reference" href="#entity" id="id23">Entity</a></li> +<li><a class="reference" href="#trigger" id="id24">Trigger</a></li> +<li><a class="reference" href="#proximitytrigger" id="id25">ProximityTrigger</a></li> +</ul> +</li> +</ul> +</div> +<div class="section" id="namespace-base"> +<h2><a class="toc-backref" href="#id4">1.1 namespace: base</a></h2> +<div class="contents local topic" id="id1"> +<p class="topic-title first">Table of Contents</p> +<ul class="simple"> +<li><a class="reference" href="#color" id="id26">Color</a></li> +<li><a class="reference" href="#math" id="id27">Math</a></li> +<li><a class="reference" href="#vector3" id="id28">Vector3</a></li> +<li><a class="reference" href="#point3" id="id29">Point3</a></li> +<li><a class="reference" href="#vector4" id="id30">Vector4</a></li> +<li><a class="reference" href="#matrix3" id="id31">Matrix3</a></li> +<li><a class="reference" href="#quaternion" id="id32">Quaternion</a></li> +<li><a class="reference" href="#volume" id="id33">Volume</a></li> +<li><a class="reference" href="#volumecontainer" id="id34">VolumeContainer</a></li> +<li><a class="reference" href="#sphere" id="id35">Sphere</a></li> +</ul> +</div> +<div class="section" id="color"> +<h3><a class="toc-backref" href="#id26">Color</a></h3> +<p><strong>Code</strong></p> +<blockquote> +<p>Valid constructors::</p> +<pre class="literal-block"> +c = Color() -- all components set to zero (0) +c = Color(.5,.5,.5) -- middle gray +c = Color(0,0,0) -- opaque black, same as Color(0,0,0,1) +c = Color(1,0,0,.5) -- half-translucent black +</pre> +</blockquote> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>r</strong> of type <strong>real</strong></li> +<li><strong>g</strong> of type <strong>real</strong></li> +<li><strong>b</strong> of type <strong>real</strong></li> +<li><strong>a</strong> of type <strong>real</strong></li> +</ul> +</blockquote> +<p><strong>Constructors</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>Color()</strong></p> +</li> +<li><p class="first"><strong>Color(r,g,b)</strong></p> +<blockquote> +<p><strong>r</strong> of type <strong>real</strong> - red</p> +<p><strong>g</strong> of type <strong>real</strong> - green</p> +<p><strong>b</strong> of type <strong>real</strong> - blue</p> +</blockquote> +</li> +<li><p class="first"><strong>Color(r,g,b,a)</strong></p> +<blockquote> +<p><strong>r</strong> of type <strong>real</strong> - red</p> +<p><strong>g</strong> of type <strong>real</strong> - green</p> +<p><strong>b</strong> of type <strong>real</strong> - blue</p> +<p><strong>a</strong> of type <strong>real</strong> - alpha (opacity)</p> +</blockquote> +</li> +</ul> +</blockquote> +</div> +<div class="section" id="math"> +<h3><a class="toc-backref" href="#id27">Math</a></h3> +</div> +<div class="section" id="vector3"> +<h3><a class="toc-backref" href="#id28">Vector3</a></h3> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>x</strong> of type <strong>number</strong></li> +<li><strong>y</strong> of type <strong>real</strong></li> +<li><strong>z</strong> of type <strong>real</strong></li> +</ul> +</blockquote> +<p><strong>Constants</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>Zero</strong> of type <a class="reference" href="#vector3">Vector3</a> with value <strong>(0,0,0)</strong></li> +<li><strong>UnitScale</strong> of type <a class="reference" href="#vector3">Vector3</a></li> +<li><strong>UnitX</strong> of type <a class="reference" href="#vector3">Vector3</a> with value <strong>(1,0,0)</strong></li> +<li><strong>UnitY</strong> of type <a class="reference" href="#vector3">Vector3</a> with value <strong>(0,1,0)</strong></li> +<li><strong>UnitZ</strong> of type <a class="reference" href="#vector3">Vector3</a> with value <strong>(0,0,1)</strong></li> +</ul> +</blockquote> +<p><strong>Constructors</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>Vector3()</strong></p> +</li> +<li><p class="first"><strong>Vector3(x,y,z)</strong></p> +<blockquote> +<p><strong>x</strong> of type <strong>real</strong></p> +<p><strong>y</strong> of type <strong>real</strong></p> +<p><strong>z</strong> of type <strong>real</strong></p> +</blockquote> +</li> +</ul> +<blockquote> +<p>Valid constructors:</p> +<pre class="literal-block"> +v = Vector3() -- all components set to zero (0) +v = Vector3(1,2,0) -- custom values +v = Vector3.UnitZ -- set to constant +</pre> +</blockquote> +</blockquote> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>length()</strong></p> +<blockquote> +<p>returns <strong>real</strong> - length</p> +</blockquote> +</li> +<li><p class="first"><strong>normalise()</strong></p> +<blockquote> +<p>returns <strong>real</strong> - previous length of vector</p> +</blockquote> +</li> +<li><p class="first"><strong>crossProduct(other)</strong></p> +<blockquote> +<p><strong>other</strong> of type <a class="reference" href="#vector3">Vector3</a></p> +<p>returns <a class="reference" href="#vector3">Vector3</a></p> +</blockquote> +</li> +<li><p class="first"><strong>dotProduct(other)</strong></p> +<blockquote> +<p><strong>other</strong> of type <a class="reference" href="#vector3">Vector3</a></p> +<p>returns <strong>real</strong></p> +</blockquote> +</li> +<li><p class="first"><strong>reflect(normal)</strong></p> +<blockquote> +<p><strong>normal</strong> of type <a class="reference" href="#vector3">Vector3</a> - normal of reflection plane</p> +<p>returns <a class="reference" href="#vector3">Vector3</a> - reflected vector</p> +</blockquote> +</li> +<li><p class="first"><strong>perpendicular()</strong></p> +<blockquote> +<p>returns <a class="reference" href="#vector3">Vector3</a></p> +</blockquote> +</li> +<li><p class="first"><strong>getRotationTo(destination)</strong></p> +<blockquote> +<p><strong>destination</strong> of type <a class="reference" href="#vector3">Vector3</a></p> +<p>returns <a class="reference" href="#quaternion">Quaternion</a></p> +</blockquote> +</li> +<li><p class="first"><strong>*(factor)</strong></p> +<blockquote> +<p><strong>factor</strong> of type <strong>real</strong></p> +</blockquote> +</li> +</ul> +<blockquote> +<p>Example:</p> +<pre class="literal-block"> +v = Vector3(1,2,0) +v = v * 2 +print(v) -- prints "Vector3(2,4,0)" +</pre> +</blockquote> +<ul> +<li><p class="first"><strong>*(xform)</strong></p> +<blockquote> +<p><strong>xform</strong> of type <a class="reference" href="#matrix3">Matrix3</a></p> +</blockquote> +</li> +<li><p class="first"><strong>*(xform)</strong></p> +<blockquote> +<p><strong>xform</strong> of type <a class="reference" href="#quaternion">Quaternion</a></p> +</blockquote> +</li> +<li><p class="first"><strong>/(factor)</strong></p> +<blockquote> +<p><strong>factor</strong> of type <strong>real</strong></p> +</blockquote> +</li> +</ul> +<blockquote> +<p>Example:</p> +<pre class="literal-block"> +v = Vector3(2,4,0) +v = v / 2 +print(v) -- prints "Vector3(1,2,0)" +</pre> +</blockquote> +<ul> +<li><p class="first"><strong>+(other)</strong></p> +<blockquote> +<p><strong>other</strong> of type <a class="reference" href="#vector3">Vector3</a></p> +</blockquote> +</li> +<li><p class="first"><strong>-(other)</strong></p> +<blockquote> +<p><strong>other</strong> of type <a class="reference" href="#vector3">Vector3</a></p> +</blockquote> +</li> +</ul> +</blockquote> +</div> +<div class="section" id="point3"> +<h3><a class="toc-backref" href="#id29">Point3</a></h3> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>x</strong> of type <strong>number</strong></li> +<li><strong>y</strong> of type <strong>real</strong></li> +<li><strong>z</strong> of type <strong>real</strong></li> +</ul> +</blockquote> +<p><strong>Constants</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>Zero</strong> of type <a class="reference" href="#point3">Point3</a> with value <strong>(0,0,0)</strong></li> +</ul> +</blockquote> +<p><strong>Constructors</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>Point3()</strong></p> +</li> +<li><p class="first"><strong>Point3(x,y,z)</strong></p> +<blockquote> +<p><strong>x</strong> of type <strong>real</strong></p> +<p><strong>y</strong> of type <strong>real</strong></p> +<p><strong>z</strong> of type <strong>real</strong></p> +</blockquote> +</li> +</ul> +<blockquote> +<p>Valid constructors:</p> +<pre class="literal-block"> +v = Point3() -- all components set to zero (0) +v = Point3(1,2,0) -- custom values +v = Point3.Zero -- set to constant +</pre> +</blockquote> +</blockquote> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>asVector()</strong></p> +<blockquote> +<p>returns <a class="reference" href="#vector3">Vector3</a> - vector with the same component values</p> +</blockquote> +</li> +<li><p class="first"><strong>*(factor)</strong></p> +<blockquote> +<p><strong>factor</strong> of type <strong>real</strong></p> +</blockquote> +</li> +<li><p class="first"><strong>*(xform)</strong></p> +<blockquote> +<p><strong>xform</strong> of type <a class="reference" href="#matrix3">Matrix3</a></p> +</blockquote> +</li> +<li><p class="first"><strong>*(xform)</strong></p> +<blockquote> +<p><strong>xform</strong> of type <a class="reference" href="#quaternion">Quaternion</a></p> +</blockquote> +</li> +<li><p class="first"><strong>/(factor)</strong></p> +<blockquote> +<p><strong>factor</strong> of type <strong>real</strong></p> +</blockquote> +</li> +<li><p class="first"><strong>+(other)</strong></p> +<blockquote> +<p><strong>other</strong> of type <a class="reference" href="#vector3">Vector3</a></p> +</blockquote> +</li> +<li><p class="first"><strong>-(other)</strong></p> +<blockquote> +<p><strong>other</strong> of type <a class="reference" href="#vector3">Vector3</a></p> +</blockquote> +</li> +</ul> +</blockquote> +</div> +<div class="section" id="vector4"> +<h3><a class="toc-backref" href="#id30">Vector4</a></h3> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>Vector4()</strong></p> +</li> +<li><p class="first"><strong>Vector4(x,y,z,w)</strong></p> +<blockquote> +<p><strong>x</strong> of type <strong>real</strong></p> +<p><strong>y</strong> of type <strong>real</strong></p> +<p><strong>z</strong> of type <strong>real</strong></p> +<p><strong>w</strong> of type <strong>real</strong></p> +</blockquote> +</li> +</ul> +</blockquote> +</div> +<div class="section" id="matrix3"> +<h3><a class="toc-backref" href="#id31">Matrix3</a></h3> +<p><strong>Constants</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>Zero</strong> of type <a class="reference" href="#matrix3">Matrix3</a></li> +<li><strong>Identity</strong> of type <a class="reference" href="#matrix3">Matrix3</a></li> +</ul> +</blockquote> +<p><strong>Constructors</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>Matrix()</strong></li> +</ul> +</blockquote> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>getColumn()</strong></p> +</li> +<li><p class="first"><strong>fromAxes(x,y,z)</strong></p> +<blockquote> +<p><strong>x</strong> of type <a class="reference" href="#vector3">Vector3</a></p> +<p><strong>y</strong> of type <a class="reference" href="#vector3">Vector3</a></p> +<p><strong>z</strong> of type <a class="reference" href="#vector3">Vector3</a></p> +</blockquote> +</li> +<li><p class="first"><strong>*(Matrix3)</strong></p> +<blockquote> +<p><strong>Matrix3</strong> of type <strong>unknown</strong></p> +</blockquote> +</li> +</ul> +</blockquote> +</div> +<div class="section" id="quaternion"> +<h3><a class="toc-backref" href="#id32">Quaternion</a></h3> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>x</strong> of type <strong>real</strong></li> +<li><strong>y</strong> of type <strong>real</strong></li> +<li><strong>z</strong> of type <strong>real</strong></li> +<li><strong>w</strong> of type <strong>real</strong></li> +</ul> +</blockquote> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>inverse()</strong></p> +</li> +<li><p class="first"><strong>*(other)</strong></p> +<blockquote> +<p><strong>other</strong> of type <a class="reference" href="#quaternion">Quaternion</a></p> +<p>returns <a class="reference" href="#quaternion">Quaternion</a> - result of multiplication</p> +</blockquote> +</li> +</ul> +</blockquote> +</div> +<div class="section" id="volume"> +<h3><a class="toc-backref" href="#id33">Volume</a></h3> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>intersectsWith(point)</strong></p> +<blockquote> +<p><strong>point</strong> of type <a class="reference" href="#point3">Point3</a></p> +<p>returns <strong>bool</strong> - true if point is contained in the volume, false if not.</p> +</blockquote> +</li> +<li><p class="first"><strong>intersectsWith(volume)</strong></p> +<blockquote> +<p><strong>volume</strong> of type <a class="reference" href="#volume">Volume</a> - Any isntance of a derived class of Volume, e.g. Sphere.</p> +<p>returns <strong>bool</strong> - true if volumes intersect, false if they don't.</p> +</blockquote> +</li> +</ul> +</blockquote> +</div> +<div class="section" id="volumecontainer"> +<h3><a class="toc-backref" href="#id34">VolumeContainer</a></h3> +<p><strong>Code</strong></p> +<blockquote> +<p>Adding volumes:</p> +<pre class="literal-block"> +ctr = yake.VolumeContainer() +ctr:add( yake.Sphere(2) ) -- adds sphere with radius 2 at (0,0,0) +</pre> +</blockquote> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>add(volume)</strong></p> +<blockquote> +<p><strong>volume</strong> of type <a class="reference" href="#volume">Volume</a> - adds an instance of a derived class of Volume (like Sphere)</p> +</blockquote> +</li> +</ul> +</blockquote> +</div> +<div class="section" id="sphere"> +<h3><a class="toc-backref" href="#id35">Sphere</a></h3> +<p><strong>inherits</strong> <a class="reference" href="#volume">Volume</a></p> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>radius</strong> of type <strong>real</strong></li> +<li><strong>position</strong> of type <a class="reference" href="#point3">Point3</a></li> +</ul> +</blockquote> +<p><strong>Constructors</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>Sphere()</strong></p> +</li> +<li><p class="first"><strong>Sphere(radius)</strong></p> +<blockquote> +<p><strong>radius</strong> of type <strong>real</strong></p> +</blockquote> +</li> +<li><p class="first"><strong>Sphere(radius,position)</strong></p> +<blockquote> +<p><strong>radius</strong> of type <strong>real</strong></p> +<p><strong>position</strong> of type <a class="reference" href="#point3">Point3</a></p> +</blockquote> +</li> +</ul> +</blockquote> +</div> +</div> +<div class="section" id="namespace-input"> +<h2><a class="toc-backref" href="#id15">1.2 namespace: input</a></h2> +<div class="contents local topic" id="id2"> +<p class="topic-title first">Table of Contents</p> +<ul class="simple"> +<li><a class="reference" href="#device" id="id36">Device</a></li> +<li><a class="reference" href="#keyboarddevice" id="id37">KeyboardDevice</a></li> +<li><a class="reference" href="#whateverdevice" id="id38">WhateverDevice</a></li> +</ul> +</div> +<div class="section" id="device"> +<h3><a class="toc-backref" href="#id36">Device</a></h3> +</div> +<div class="section" id="keyboarddevice"> +<h3><a class="toc-backref" href="#id37">KeyboardDevice</a></h3> +<p><strong>inherits</strong> <a class="reference" href="#device">Device</a></p> +<p><strong>Code</strong></p> +<blockquote> +<p>Example #1:</p> +<pre class="literal-block"> +dev:poll(yeeha) +</pre> +</blockquote> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>enabled</strong> of type <strong>bool</strong></li> +<li><strong>name</strong> of type <strong>string</strong></li> +<li><strong>pseudo</strong> of type <a class="reference" href="#device">Device</a></li> +</ul> +</blockquote> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>poll(a,b,c,d)</strong></p> +<blockquote> +<p><strong>a</strong> of type <strong>string</strong> - ...</p> +<p><strong>b</strong> of type <strong>int</strong> - ...</p> +<p><strong>c</strong> of type <strong>whatever</strong></p> +<p><strong>d</strong> of type <a class="reference" href="#device">Device</a> - ...</p> +<p>returns <strong>bool</strong> - returns true on success</p> +</blockquote> +</li> +</ul> +<blockquote> +<p>Example for poll():</p> +<pre class="literal-block"> +dev:poll(yeeha) +</pre> +</blockquote> +</blockquote> +</div> +<div class="section" id="whateverdevice"> +<h3><a class="toc-backref" href="#id38">WhateverDevice</a></h3> +<p><strong>inherits</strong> <a class="reference" href="#device">Device</a>, Parent2</p> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>isOk</strong> of type <strong>bool|readonly</strong></li> +<li><strong>stuffOk</strong> of type <strong>bool</strong></li> +</ul> +</blockquote> +</div> +</div> +<div class="section" id="namespace-ent"> +<h2><a class="toc-backref" href="#id19">1.3 namespace: ent</a></h2> +<div class="contents local topic" id="id3"> +<p class="topic-title first">Table of Contents</p> +<ul class="simple"> +<li><a class="reference" href="#objectid" id="id39">ObjectId</a></li> +<li><a class="reference" href="#propertyaccess" id="id40">PropertyAccess</a></li> +<li><a class="reference" href="#object" id="id41">Object</a></li> +<li><a class="reference" href="#entity" id="id42">Entity</a></li> +<li><a class="reference" href="#trigger" id="id43">Trigger</a></li> +<li><a class="reference" href="#proximitytrigger" id="id44">ProximityTrigger</a></li> +</ul> +</div> +<div class="section" id="objectid"> +<h3><a class="toc-backref" href="#id39">ObjectId</a></h3> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>classId</strong> of type <strong>unknown</strong></li> +<li><strong>serialNo</strong> of type <strong>unknown</strong></li> +</ul> +</blockquote> +</div> +<div class="section" id="propertyaccess"> +<h3><a class="toc-backref" href="#id40">PropertyAccess</a></h3> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>operator[](name)</strong></p> +<blockquote> +<p><strong>name</strong> of type <strong>string</strong> - name of property</p> +<p>returns - value of property</p> +</blockquote> +</li> +</ul> +<pre class="literal-block"> +this = ... --assign Object instance to 'this' +myName = this.properties["name"] -- retrieve value +this.properties["name"] = myName .. " Meyes" -- set value +</pre> +<ul> +<li><p class="first"><strong>operator.(name)</strong></p> +<blockquote> +<p><strong>name</strong> of type <strong>string</strong> - name of property</p> +<p>returns - value of property</p> +</blockquote> +</li> +</ul> +<pre class="literal-block"> +myName = this.properties.name -- retrieve value +this.properties.name = "Jack" -- set value +</pre> +<ul> +<li><p class="first"><strong>create(name,value)</strong></p> +<blockquote> +<p><strong>name</strong> of type <strong>string</strong></p> +<p><strong>value</strong> of type <strong>any</strong> - The type of the property is deduced from value (true => boolean, 1 => number, ...)</p> +</blockquote> +</li> +</ul> +<pre class="literal-block"> +this.properties:create("name","Jack") -- constructs property of type 'string' +this.properties:create("health",10) -- constructs property of type 'number' +this.properties:create("model",yake.Model()) -- constructs custom typed property +</pre> +<ul> +<li><p class="first"><strong>foreach(op)</strong></p> +<blockquote> +<p><strong>op</strong> of type <strong>function</strong></p> +</blockquote> +</li> +</ul> +<pre class="literal-block"> +this.properties.each( function(name,value) + print("property " .. name .. " = " .. value) + end ) +</pre> +</blockquote> +</div> +<div class="section" id="object"> +<h3><a class="toc-backref" href="#id41">Object</a></h3> +<p><strong>Code</strong></p> +<blockquote> +<p>Accessing events::</p> +<pre class="literal-block"> +this = ... --assign Object instance to 'this' + +this.events:create("toggled") + +-- connect anonymous handler: +this.events.toggled:connect( function() print("TOGGLED!") end ) + +-- connect known function 'on_toggled' +this.events.toggled:connect( on_toggled ) + +-- fire event: +this.events.toggled(true) -- prints "TOGGLED!" to the console +</pre> +<p>Accessing properties::</p> +<pre class="literal-block"> +this = ... --assign Object instance to 'this' + +this.properties:create("name","Jack") +myName = this.properties["name"] +myName = this.properties.name +</pre> +</blockquote> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>id</strong> of type <a class="reference" href="#objectid">ObjectId</a></li> +<li><strong>properties</strong> of type <a class="reference" href="#propertyaccess">PropertyAccess</a></li> +<li><strong>events</strong> of type <strong>EventAccess</strong></li> +</ul> +</blockquote> +</div> +<div class="section" id="entity"> +<h3><a class="toc-backref" href="#id42">Entity</a></h3> +<p><strong>inherits</strong> <a class="reference" href="#object">Object</a></p> +</div> +<div class="section" id="trigger"> +<h3><a class="toc-backref" href="#id43">Trigger</a></h3> +<p><strong>inherits</strong> <a class="reference" href="#entity">Entity</a></p> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>condition</strong> of type <strong>function</strong></li> +</ul> +</blockquote> +<p><strong>Events</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>onTriggered(any)</strong></p> +<blockquote> +<p><strong>any</strong> of type <strong>any</strong> - The (optional) parameter that was passed the the Event's fire() method.</p> +</blockquote> +</li> +</ul> +</blockquote> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>setCondition(condition)</strong></p> +<blockquote> +<p><strong>condition</strong> of type <strong>function</strong> - Condition function that is called each tick to determine whether the trigger should be triggered. NB Set be 'nil' to clear the trigger condition.</p> +</blockquote> +</li> +</ul> +<blockquote> +<p>Example of a little Timeout Trigger:</p> +<pre class="literal-block"> +this = objectManager:create("Trigger") -- <- a little bit more complicated in real-life + +function onTimeout(isOn) -- <- The trigger handler. + if isOn then + print("Timeout!") -- 'isOn' is of type boolean representing the trigger state + else + print("Trigger restarted.") + end +end +function startup() -- <- called when an Object has been spawned (Object is in 'this') + this.properties:create("ticksUntilTimeout",10) + this.condition = function() + return this.properties.ticksUntilTimeout < 0 + end + this.events.onTriggered:connect( onTimeout ) +end + +function on_tick() + if ticksUntilTimeout > 0 then + this.properties.ticksUntilTimeout = this.properties.ticksUntilTimeout - 1 + end +end +</pre> +</blockquote> +</blockquote> +</div> +<div class="section" id="proximitytrigger"> +<h3><a class="toc-backref" href="#id44">ProximityTrigger</a></h3> +<p><strong>inherits</strong> <a class="reference" href="#trigger">Trigger</a></p> +<p><strong>Code</strong></p> +<blockquote> +<p>Example #1 - Adding volumes:</p> +<pre class="literal-block"> +trigger.volumes:add( yake.Sphere(2) ) -- adds a sphere at (0,0,0) +trigger.volumes:add( yake.Sphere(2, yake.Point3(10,12,0)) ) +</pre> +</blockquote> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>volumes</strong> of type <a class="reference" href="#volumecontainer">VolumeContainer</a></li> +</ul> +</blockquote> +<p><strong>Events</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>enters()</strong></li> +<li><strong>exits()</strong></li> +<li><strong>TODO_INHERITED_EVENTS()</strong></li> +<li><strong>TODO_SEEALSO_SPHERE()</strong></li> +</ul> +</blockquote> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>addVolume(volume)</strong></p> +<blockquote> +<p><strong>volume</strong> of type <strong>VolumeChecker</strong></p> +</blockquote> +</li> +</ul> +<pre class="literal-block"> +-- both of the following calls do the same +trigger:addVolume( yake.Sphere(5, this.properties.position ) ) +trigger.volumes:add( yake.Sphere(5, this.properties.position ) ) +</pre> +</blockquote> +</div> +</div> +</div> +</div> +</body> +</html> Modified: tools/luadocs/lua_bindings_2_rst.cmd =================================================================== --- tools/luadocs/lua_bindings_2_rst.cmd 2007-08-30 00:10:50 UTC (rev 1830) +++ tools/luadocs/lua_bindings_2_rst.cmd 2007-08-31 03:36:26 UTC (rev 1831) @@ -1,5 +1,5 @@ @echo off d:\tools\luabin\lua5.1 lua_bindings_2_rst.lua -d:\doc\docutils\tools\rst2html.py --link-stylesheet --stylesheet-path lua_bindings.css project.rst.txt project.html +d:\doc\docutils\tools\rst2html.py --link-stylesheet --stylesheet-path lua_bindings.css project.rst.txt index.html pause Modified: tools/luadocs/lua_bindings_2_rst.lua =================================================================== --- tools/luadocs/lua_bindings_2_rst.lua 2007-08-30 00:10:50 UTC (rev 1830) +++ tools/luadocs/lua_bindings_2_rst.lua 2007-08-31 03:36:26 UTC (rev 1831) @@ -8,14 +8,25 @@ return max end -- +function unique_insert(t,v) + for _,test in pairs(t) do + if test == v then + return + end + end + table.insert(t,v) +end +-- db = {} +db.project = {} db.scopeStack = {} db.pushScope = function(scope) db.scopeStack[ table.getn(db.scopeStack)+1 ] = scope end db.scopes = {} +db.scopeOrder = {} db.newScope = function(id,kind) db.currentFn = nil local parent = db.getCurrClass() @@ -27,10 +38,13 @@ parent.scopes[id] = {} parent.scopes[id].kind = kind parent.scopes[id].scopes = {} + parent.scopes[id].scopeOrder = {} parent.scopes[id].properties = {} parent.scopes[id].functions = {} + parent.scopes[id].functionOrder = {} parent.scopes[id].constants = {} parent.scopes[id].codes = {} + unique_insert(parent.scopeOrder,id) db.currScope = parent.scopes[id] db.pushScope( db.currScope ) @@ -66,15 +80,20 @@ assert(name) type = type or "unknown" assert(type) - db.getCurrClass().properties[name] = type + local p = {} + p.name = name + p.type = type + table.insert(db.getCurrClass().properties,p) end db.newConstant = function(name,type,value) assert(db.getCurrClass()) assert(name) assert(type) - db.getCurrClass().constants[name] = {} - db.getCurrClass().constants[name].type = type - db.getCurrClass().constants[name].value = value + local c = {} + c.name = name + c.type = type + c.value = value + table.insert(db.getCurrClass().constants,c) end db.newFunction = function(name,paramNames,tag) assert(name) @@ -94,6 +113,9 @@ if not scope.functions[name] then scope.functions[name] = {} scope.functions[name].overloads = {} + scope.functions[name].overloadOrder = {} + unique_insert(scope.functionOrder,name) + print("O->",name) end local fnBase = scope.functions[name] --print("SIG",signature) @@ -104,6 +126,7 @@ end assert( not fnBase.overloads[uniqueSignature] ) fnBase.overloads[uniqueSignature] = {} + table.insert(fnBase.overloadOrder,uniqueSignature) local fn = fnBase.overloads[uniqueSignature] fn.params = {} @@ -167,7 +190,7 @@ assert(db.currCodeScope) assert(line) - print("newCodeLine '" .. db.currCode .. "': '" .. line .. "'") + --print("newCodeLine '" .. db.currCode .. "': '" .. line .. "'") assert(db.currCodeScope) assert(db.currCodeScope[db.currCode]) @@ -182,6 +205,20 @@ end jump = {} +jump["project"] = function(line) + local name = string.gmatch(line,"%s*([%w%p%(%)%s]+)%s*") + if name then + local name = name() + assert(name) + print("PROJECT",name) + assert(db.project) + db.project.name = name + else + print("SYNTAX ERROR in @project:") + print("line:'"..tostring(line).."'") + exit() + end +end jump["class"] = function(line) local from,to = string.find(line,"%w+",1) if from and to then @@ -303,7 +340,7 @@ assert(type) type = type() - local patExtractValue = "([%w+])"; + local patExtractValue = "=([%w%(%)%p]+)%s*"; local value = string.gmatch(line,patName .. "%s*" .. patType .. "%s*" ..patExtractValue) assert(value) value = value() @@ -364,8 +401,12 @@ rst.currLevel = 0 rst.currScope = nil rst.underline = function(title) + assert(title) local s = "" - for i = 1,40 do + -- ensure that enough characters are printed (>=length of title) + local len = string.len(title) + if len < 40 then len = 40 end + for i = 1,len do s = s .. string.sub(rst.underlineChars,rst.currLevel,rst.currLevel) end if rst.currLevel > 1 then @@ -379,7 +420,7 @@ rst.f:write("\n"); rst.f:write(".. |date| date:: %d %b %Y\n"); rst.f:write("\n"); - rst.f:write(":Author: Stephan Kaiser's LuaBindingsAutoDoc\n"); + rst.f:write(":Author: LuaBindingsDoc\n"); rst.f:write("\n"); rst.f:write(":Generated on: |date|\n"); rst.f:write("\n"); @@ -659,9 +700,9 @@ -- properties if scope.properties and getn(scope.properties) > 0 then rst.onBeginProperties() - for propName,propType in pairs(scope.properties) do - print(lvl.." PROPERTY " .. propName,"(" .. propType .. ")") - rst.onProperty(propName,propType,typeLookup) + for i,prop in pairs(scope.properties) do + print(lvl.." PROPERTY " .. prop.name,"(" .. prop.type .. ")") + rst.onProperty(prop.name,prop.type,typeLookup) end rst.onEndProperties() end @@ -669,9 +710,9 @@ -- constants if scope.constants and getn(scope.constants) > 0 then rst.onBeginConstants() - for name,c in pairs(scope.constants) do - print(lvl.." CONSTANT " .. name,"(" .. c.type .. ")=...") - rst.onConstant(name,c.type,c.value,typeLookup) + for _,c in pairs(scope.constants) do + print(lvl.." CONSTANT " .. c.name,"(" .. c.type .. ")=...") + rst.onConstant(c.name,c.type,c.value,typeLookup) end rst.onEndConstants() end @@ -680,8 +721,13 @@ local function doFunctions(sectionName,scope,tag) if scope.functions and getn(scope.functions) > 0 then local bAtLeastOne = false - for fnName,fnBase in pairs(scope.functions) do - for _,fnObj in pairs(fnBase.overloads) do + assert(scope.functionOrder) + for _,fnName in pairs(scope.functionOrder) do + assert( scope.functions[fnName] ) + local fnBase = scope.functions[fnName] + for _,sig in pairs(fnBase.overloadOrder) do + local fnObj = fnBase.overloads[sig] + assert( fnObj ) if fnObj.tag == tag then if not bAtLeastOne then bAtLeastOne = true @@ -713,8 +759,10 @@ local parentsForChilds = parents table.insert(parentsForChilds,scope) - for k,v in pairs(scope.scopes) do - dumpScope(parentsForChilds,v,k,lvl) + assert( scope.scopeOrder ) + for _,scopeId in pairs(scope.scopeOrder) do + assert( scope.scopes[scopeId] ) + dumpScope(parentsForChilds,scope.scopes[scopeId],scopeId,lvl) end rst.onLeaveScope() @@ -723,5 +771,7 @@ local projName = "project" rst.open(projName .. ".rst.txt") local parents = {} -dumpScope(parents,db,projName) + +db.project.name = db.project.name or projName +dumpScope(parents,db,db.project.name) rst.close() Deleted: tools/luadocs/project.html =================================================================== --- tools/luadocs/project.html 2007-08-30 00:10:50 UTC (rev 1830) +++ tools/luadocs/project.html 2007-08-31 03:36:26 UTC (rev 1831) @@ -1,575 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> -<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" /> -<title>project</title> -<meta name="author" content="Stephan Kaiser's LuaBindingsAutoDoc" /> -<meta content="The official API documentation for the Yake Lua bindings." name="description" /> -<link rel="stylesheet" href="lua_bindings.css" type="text/css" /> -</head> -<body> -<div class="document" id="project"> -<h1 class="title">project</h1> -<table class="docinfo" frame="void" rules="none"> -<col class="docinfo-name" /> -<col class="docinfo-content" /> -<tbody valign="top"> -<tr><th class="docinfo-name">Author:</th> -<td>Stephan Kaiser's LuaBindingsAutoDoc</td></tr> -<tr class="field"><th class="docinfo-name">Generated on:</th><td class="field-body">30 Aug 2007</td> -</tr> -<tr><th class="docinfo-name">Status:</th> -<td>Draft</td></tr> -</tbody> -</table> -<div class="section" id="namespace-yake"> -<h1>1 namespace: yake</h1> -<div class="contents local topic" id="table-of-contents"> -<p class="topic-title first">Table of Contents</p> -<ul class="auto-toc simple"> -<li><a class="reference" href="#namespace-input" id="id4">1.1 namespace: input</a><ul> -<li><a class="reference" href="#device" id="id5">Device</a></li> -<li><a class="reference" href="#whateverdevice" id="id6">WhateverDevice</a></li> -<li><a class="reference" href="#keyboarddevice" id="id7">KeyboardDevice</a></li> -</ul> -</li> -<li><a class="reference" href="#namespace-base" id="id8">1.2 namespace: base</a><ul> -<li><a class="reference" href="#quaternion" id="id9">Quaternion</a></li> -<li><a class="reference" href="#math" id="id10">Math</a></li> -<li><a class="reference" href="#color" id="id11">Color</a></li> -<li><a class="reference" href="#matrix3" id="id12">Matrix3</a></li> -<li><a class="reference" href="#vector4" id="id13">Vector4</a></li> -<li><a class="reference" href="#vector3" id="id14">Vector3</a></li> -</ul> -</li> -<li><a class="reference" href="#namespace-ent" id="id15">1.3 namespace: ent</a><ul> -<li><a class="reference" href="#propertyaccess" id="id16">PropertyAccess</a></li> -<li><a class="reference" href="#object" id="id17">Object</a></li> -<li><a class="reference" href="#entity" id="id18">Entity</a></li> -<li><a class="reference" href="#proximitytrigger" id="id19">ProximityTrigger</a></li> -<li><a class="reference" href="#objectid" id="id20">ObjectId</a></li> -<li><a class="reference" href="#trigger" id="id21">Trigger</a></li> -</ul> -</li> -</ul> -</div> -<div class="section" id="namespace-input"> -<h2><a class="toc-backref" href="#id4">1.1 namespace: input</a></h2> -<div class="contents local topic" id="id1"> -<p class="topic-title first">Table of Contents</p> -<ul class="simple"> -<li><a class="reference" href="#device" id="id22">Device</a></li> -<li><a class="reference" href="#whateverdevice" id="id23">WhateverDevice</a></li> -<li><a class="reference" href="#keyboarddevice" id="id24">KeyboardDevice</a></li> -</ul> -</div> -<div class="section" id="device"> -<h3><a class="toc-backref" href="#id22">Device</a></h3> -</div> -<div class="section" id="whateverdevice"> -<h3><a class="toc-backref" href="#id23">WhateverDevice</a></h3> -<p><strong>inherits</strong> <a class="reference" href="#device">Device</a>, Parent2</p> -<p><strong>Properties</strong></p> -<blockquote> -<ul class="simple"> -<li><strong>stuffOk</strong> of type <strong>bool</strong></li> -<li><strong>isOk</strong> of type <strong>bool|readonly</strong></li> -</ul> -</blockquote> -</div> -<div class="section" id="keyboarddevice"> -<h3><a class="toc-backref" href="#id24">KeyboardDevice</a></h3> -<p><strong>inherits</strong> <a class="reference" href="#device">Device</a></p> -<p><strong>Code</strong></p> -<blockquote> -<p>Example #1:</p> -<pre class="literal-block"> -dev:poll(yeeha) -</pre> -</blockquote> -<p><strong>Properties</strong></p> -<blockquote> -<ul class="simple"> -<li><strong>enabled</strong> of type <strong>bool</strong></li> -<li><strong>name</strong> of type <strong>string</strong></li> -<li><strong>pseudo</strong> of type <a class="reference" href="#device">Device</a></li> -</ul> -</blockquote> -<p><strong>Functions</strong></p> -<blockquote> -<ul> -<li><p class="first"><strong>poll(a,b,c,d)</strong></p> -<blockquote> -<p><strong>a</strong> of type <strong>string</strong> - ...</p> -<p><strong>b</strong> of type <strong>int</strong> - ...</p> -<p><strong>c</strong> of type <strong>whatever</strong></p> -<p><strong>d</strong> of type <a class="reference" href="#device">Device</a> - ...</p> -<p>returns <strong>bool</strong> - returns true on success</p> -</blockquote> -</li> -</ul> -<blockquote> -<p>Example for poll():</p> -<pre class="literal-block"> -dev:poll(yeeha) -</pre> -</blockquote> -</blockquote> -</div> -</div> -<div class="section" id="namespace-base"> -<h2><a class="toc-backref" href="#id8">1.2 namespace: base</a></h2> -<div class="contents local topic" id="id2"> -<p class="topic-title first">Table of Contents</p> -<ul class="simple"> -<li><a class="reference" href="#quaternion" id="id25">Quaternion</a></li> -<li><a class="reference" href="#math" id="id26">Math</a></li> -<li><a class="reference" href="#color" id="id27">Color</a></li> -<li><a class="reference" href="#matrix3" id="id28">Matrix3</a></li> -<li><a class="reference" href="#vector4" id="id29">Vector4</a></li> -<li><a class="reference" href="#vector3" id="id30">Vector3</a></li> -</ul> -</div> -<div class="section" id="quaternion"> -<h3><a class="toc-backref" href="#id25">Quaternion</a></h3> -<p><strong>Properties</strong></p> -<blockquote> -<ul class="simple"> -<li><strong>y</strong> of type <strong>real</strong></li> -<li><strong>x</strong> of type <strong>real</strong></li> -<li><strong>w</strong> of type <strong>real</strong></li> -<li><strong>z</strong> of type <strong>real</strong></li> -</ul> -</blockquote> -<p><strong>Functions</strong></p> -<blockquote> -<ul> -<li><p class="first"><strong>inverse()</strong></p> -</li> -<li><p class="first"><strong>*(other)</strong></p> -<blockquote> -<p><strong>other</strong> of type <strong>Quaternion</strong></p> -<p>returns <strong>Quaternion</strong> - result of multiplication</p> -</blockquote> -</li> -</ul> -</blockquote> -</div> -<div class="section" id="math"> -<h3><a class="toc-backref" href="#id26">Math</a></h3> -</div> -<div class="section" id="color"> -<h3><a class="toc-backref" href="#id27">Color</a></h3> -<p><strong>Code</strong></p> -<blockquote> -<p>Valid constructors::</p> -<pre class="literal-block"> -c = Color() -- all components set to zero (0) -c = Color(.5,.5,.5) -- middle gray -c = Color(0,0,0) -- opaque black, same as Color(0,0,0,1) -c = Color(1,0,0,.5) -- half-translucent black -</pre> -</blockquote> -<p><strong>Properties</strong></p> -<blockquote> -<ul class="simple"> -<li><strong>a</strong> of type <strong>real</strong></li> -<li><strong>b</strong> of type <strong>real</strong></li> -<li><strong>g</strong> of type <strong>real</strong></li> -<li><strong>r</strong> of type <strong>real</strong></li> -</ul> -</blockquote> -<p><strong>Constructors</strong></p> -<blockquote> -<ul> -<li><p class="first"><strong>Color(r,g,b)</strong></p> -<blockquote> -<p><strong>r</strong> of type <strong>real</strong> - red</p> -<p><strong>g</strong> of type <strong>real</strong> - green</p> -<p><strong>b</strong> of type <strong>real</strong> - blue</p> -</blockquote> -</li> -<li><p class="first"><strong>Color(r,g,b,a)</strong></p> -<blockquote> -<p><strong>r</strong> of type <strong>real</strong> - red</p> -<p><strong>g</strong> of type <strong>real</strong> - green</p> -<p><strong>b</strong> of type <strong>real</strong> - blue</p> -<p><strong>a</strong> of type <strong>real</strong> - alpha (opacity)</p> -</blockquote> -</li> -<li><p class="first"><strong>Color()</strong></p> -</li> -</ul> -</blockquote> -</div> -<div class="section" id="matrix3"> -<h3><a class="toc-backref" href="#id28">Matrix3</a></h3> -<p><strong>Constants</strong></p> -<blockquote> -<ul class="simple"> -<li><strong>Zero</strong> of type <a class="reference" href="#matrix3">Matrix3</a></li> -<li><strong>Identity</strong> of type <a class="reference" href="#matrix3">Matrix3</a></li> -</ul> -</blockquote> -<p><strong>Constructors</strong></p> -<blockquote> -<ul class="simple"> -<li><strong>Matrix()</strong></li> -</ul> -</blockquote> -<p><strong>Functions</strong></p> -<blockquote> -<ul> -<li><p class="first"><strong>fromAxes(x,y,z)</strong></p> -<blockquote> -<p><strong>x</strong> of type <a class="reference" href="#vector3">Vector3</a></p> -<p><strong>y</strong> of type <a class="reference" href="#vector3">Vector3</a></p> -<p><strong>z</strong> of type <a class="reference" href="#vector3">Vector3</a></p> -</blockquote> -</li> -<li><p class="first"><strong>getColumn()</strong></p> -</li> -<li><p class="first"><strong>*(Matrix3)</strong></p> -<blockquote> -<p><strong>Matrix3</strong> of type <strong>unknown</strong></p> -</blockquote> -</li> -</ul> -</blockquote> -</div> -<div class="section" id="vector4"> -<h3><a class="toc-backref" href="#id29">Vector4</a></h3> -<p><strong>Functions</strong></p> -<blockquote> -<ul> -<li><p class="first"><strong>Vector4(x,y,z,w)</strong></p> -<blockquote> -<p><strong>x</strong> of type <strong>real</strong></p> -<p><strong>y</strong> of type <strong>real</strong></p> -<p><strong>z</strong> of type <strong>real</strong></p> -<p><strong>w</strong> of type <strong>real</strong></p> -</blockquote> -</li> -<li><p class="first"><strong>Vector4()</strong></p> -</li> -</ul> -</blockquote> -</div> -<div class="section" id="vector3"> -<h3><a class="toc-backref" href="#id30">Vector3</a></h3> -<p><strong>Properties</strong></p> -<blockquote> -<ul class="simple"> -<li><strong>y</strong> of type <strong>real</strong></li> -<li><strong>x</strong> of type <strong>number</strong></li> -<li><strong>z</strong> of type <strong>real</strong></li> -</ul> -</blockquote> -<p><strong>Constants</strong></p> -<blockquote> -<ul class="simple"> -<li><strong>UnitScale</strong> of type <a class="reference" href="#vector3">Vector3</a></li> -<li><strong>Zero</strong> of type <a class="reference" href="#vector3">Vector3</a></li> -<li><strong>UnitY</strong> of type <a class="reference" href="#vector3">Vector3</a></li> -<li><strong>UnitX</strong> of type <a class="reference" href="#vector3">Vector3</a></li> -<li><strong>UnitZ</strong> of type <a class="reference" href="#vector3">Vector3</a></li> -</ul> -</blockquote> -<p><strong>Constructors</strong></p> -<blockquote> -<ul> -<li><p class="first"><strong>Vector3(x,y,z)</strong></p> -<blockquote> -<p><strong>x</strong> of type <strong>real</strong></p> -<p><strong>y</strong> of type <strong>real</strong></p> -<p><strong>z</strong> of type <strong>real</strong></p> -</blockquote> -</li> -</ul> -<blockquote> -<p>Valid constructors:</p> -<pre class="literal-block"> -v = Vector3() -- all components set to zero (0) -v = Vector3(1,2,0) -- custom values -v = Vector3.UnitZ -- set to constant -</pre> -</blockquote> -<ul class="simple"> -<li><strong>Vector3()</strong></li> -</ul> -</blockquote> -<p><strong>Functions</strong></p> -<blockquote> -<ul> -<li><p class="first"><strong>getRotationTo(destination)</strong></p> -<blockquote> -<p><strong>destination</strong> of type <a class="reference" href="#vector3">Vector3</a></p> -<p>returns <a class="reference" href="#quaternion">Quaternion</a></p> -</blockquote> -</li> -<li><p class="first"><strong>dotProduct(other)</strong></p> -<blockquote> -<p><strong>other</strong> of type <a class="reference" href="#vector3">Vector3</a></p> -<p>returns <strong>real</strong></p> -</blockquote> -</li> -<li><p class="first"><strong>perpendicular()</strong></p> -<blockquote> -<p>returns <a class="reference" href="#vector3">Vector3</a></p> -</blockquote> -</li> -<li><p class="first"><strong>normalise()</strong></p> -<blockquote> -<p>returns <strong>real</strong> - previous length of vector</p> -</blockquote> -</li> -<li><p class="first"><strong>reflect(normal)</strong></p> -<blockquote> -<p><strong>normal</strong> of type <a class="reference" href="#vector3">Vector3</a> - normal of reflection plane</p> -<p>returns <a class="reference" href="#vector3">Vector3</a> - reflected vector</p> -</blockquote> -</li> -<li><p class="first"><strong>/(factor)</strong></p> -<blockquote> -<p><strong>factor</strong> of type <strong>real</strong></p> -</blockquote> -</li> -</ul> -<blockquote> -<p>Example:</p> -<pre class="literal-block"> -v = Vector3(2,4,0) -v = v / 2 -print(v) -- prints "Vector3(1,2,0)" -</pre> -</blockquote> -<ul> -<li><p class="first"><strong>+(other)</strong></p> -<blockquote> -<p><strong>other</strong> of type <a class="reference" href="#vector3">Vector3</a></p> -</blockquote> -</li> -<li><p class="first"><strong>*(xform)</strong></p> -<blockquote> -<p><strong>xform</strong> of type <a class="reference" href="#matrix3">Matrix3</a></p> -</blockquote> -</li> -<li><p class="first"><strong>*(xform)</strong></p> -<blockquote> -<p><strong>xform</strong> of type <a class="reference" href="#quaternion">Quaternion</a></p> -</blockquote> -</li> -<li><p class="first"><strong>*(factor)</strong></p> -<blockquote> -<p><strong>factor</strong> of type <strong>real</strong></p> -</blockquote> -</li> -</ul> -<blockquote> -<p>Example:</p> -<pre class="literal-block"> -v = Vector3(1,2,0) -v = v * 2 -print(v) -- prints "Vector3(2,4,0)" -</pre> -</blockquote> -<ul> -<li><p class="first"><strong>-(other)</strong></p> -<blockquote> -<p><strong>other</strong> of type <a class="reference" href="#vector3">Vector3</a></p> -</blockquote> -</li> -<li><p class="first"><strong>length()</strong></p> -<blockquote> -<p>returns <strong>real</strong> - length</p> -</blockquote> -</li> -<li><p class="first"><strong>crossProduct(other)</strong></p> -<blockquote> -<p><strong>other</strong> of type <a class="reference" href="#vector3">Vector3</a></p> -<p>returns <a class="reference" href="#vector3">Vector3</a></p> -</blockquote> -</li> -</ul> -</blockquote> -</div> -</div> -<div class="section" id="namespace-ent"> -<h2><a class="toc-backref" href="#id15">1.3 namespace: ent</a></h2> -<div class="contents local topic" id="id3"> -<p class="topic-title first">Table of Contents</p> -<ul class="simple"> -<li><a class="reference" href="#propertyaccess" id="id31">PropertyAccess</a></li> -<li><a class="reference" href="#object" id="id32">Object</a></li> -<li><a class="reference" href="#entity" id="id33">Entity</a></li> -<li><a class="reference" href="#proximitytrigger" id="id34">ProximityTrigger</a></li> -<li><a class="reference" href="#objectid" id="id35">ObjectId</a></li> -<li><a class="reference" href="#trigger" id="id36">Trigger</a></li> -</ul> -</div> -<div class="section" id="propertyaccess"> -<h3><a class="toc-backref" href="#id31">PropertyAccess</a></h3> -<p><strong>Functions</strong></p> -<blockquote> -<ul> -<li><p class="first"><strong>operator.(name)</strong></p> -<blockquote> -<p><strong>name</strong> of type <strong>string</strong> - name of property</p> -<p>returns - value of property</p> -</blockquote> -</li> -</ul> -<pre class="literal-block"> -myName = this.properties.name -</pre> -<ul> -<li><p class="first"><strong>create(name,value)</strong></p> -<blockquote> -<p><strong>name</strong> of type <strong>string</strong></p> -<p><strong>value</strong> of type <strong>any</strong> - The type of the property is deduced from value (true => boolean, 1 => number, ...)</p> -</blockquote> -</li> -<li><p class="first"><strong>operator[](name)</strong></p> -<blockquote> -<p><strong>name</strong> of type <strong>string</strong> - name of property</p> -<p>returns - value of property</p> -</blockquote> -</li> -</ul> -<pre class="literal-block"> -this = ... --assign Object instance to 'this' -myName = this.properties["name"] -</pre> -</blockquote> -</div> -<div class="section" id="object"> -<h3><a class="toc-backref" href="#id32">Object</a></h3> -<p><strong>Code</strong></p> -<blockquote> -<p>Accessing events::</p> -<pre class="literal-block"> -this = ... --assign Object instance to 'this' - -this.events:create("toggled") - --- connect anonymous handler: -this.events.toggled:connect( function() print("TOGGLED!") end ) - --- connect known function 'on_toggled' -this.events.toggled:connect( on_toggled ) - --- fire event: -this.events.toggled(true) -- prints "TOGGLED!" to the console -</pre> -<p>Accessing properties::</p> -<pre class="literal-block"> -this = ... --assign Object instance to 'this' - -this.properties:create("name","Jack") -myName = this.properties["name"] -myName = this.properties.name -</pre> -</blockquote> -<p><strong>Properties</strong></p> -<blockquote> -<ul class="simple"> -<li><strong>id</strong> of type <a class="reference" href="#objectid">ObjectId</a></li> -<li><strong>properties</strong> of type <a class="reference" href="#propertyaccess">PropertyAccess</a></li> -</ul> -</blockquote> -</div> -<div class="section" id="entity"> -<h3><a class="toc-backref" href="#id33">Entity</a></h3> -<p><strong>inherits</strong> <a class="reference" href="#object">Object</a></p> -</div> -<div class="section" id="proximitytrigger"> -<h3><a class="toc-backref" href="#id34">ProximityTrigger</a></h3> -<p><strong>inherits</strong> <a class="reference" href="#trigger">Trigger</a></p> -<p><strong>Functions</strong></p> -<blockquote> -<ul> -<li><p class="first"><strong>addVolume(volume)</strong></p> -<blockquote> -<p><strong>volume</strong> of type <strong>VolumeChecker</strong></p> -</blockquote> -</li> -</ul> -<pre class="literal-block"> -trigger:addVolume( volumecheck.Sphere(5, this.properties.position ) ) -</pre> -</blockquote> -</div> -<div class="section" id="objectid"> -<h3><a class="toc-backref" href="#id35">ObjectId</a></h3> -<p><strong>Properties</strong></p> -<blockquote> -<ul class="simple"> -<li><strong>serialNo</strong> of type <strong>unknown</strong></li> -<li><strong>classId</strong> of type <strong>unknown</strong></li> -</ul> -</blockquote> -</div> -<div class="section" id="trigger"> -<h3><a class="toc-backref" href="#id36">Trigger</a></h3> -<p><strong>inherits</strong> <a class="reference" href="#entity">Entity</a></p> -<p><strong>Properties</strong></p> -<blockquote> -<ul class="simple"> -<li><strong>condition</strong> of type <strong>function</strong></li> -</ul> -</blockquote> -<p><strong>Events</strong></p> -<blockquote> -<ul> -<li><p class="first"><strong>onTriggered(any)</strong></p> -<blockquote> -<p><strong>any</strong> of type <strong>any</strong> - The (optional) parameter that was passed the the Event's fire() method.</p> -</blockquote> -</li> -</ul> -</blockquote> -<p><strong>Functions</strong></p> -<blockquote> -<ul> -<li><p class="first"><strong>setCondition(condition)</strong></p> -<blockquote> -<p><strong>condition</strong> of type <strong>function</strong> - Condition function that is called each tick to determine whether the trigger should be triggered. NB Set be 'nil' to clear the trigger condition.</p> -</blockquote> -</li> -</ul> -<blockquote> -<p>Example of a little Timeout Trigger:</p> -<pre class="literal-block"> -this = objectManager:create("Trigger") -- <- a little bit more complicated in real-life - -function onTimeout(isOn) -- <- The trigger handler. - if isOn then - print("Timeout!") -- 'isOn' is of type boolean representing the trigger state - else - print("Trigger restarted.") - end -end -function startup() -- <- called when an Object has been spawned (Object is in 'this') - this.properties:create("ticksUntilTimeout",10) - this.condition = function() - return this.properties.ticksUntilTimeout < 0 - end - this.events.onTriggered:connect( onTimeout ) -end - -function on_tick() - if ticksUntilTimeout > 0 then - this.properties.ticksUntilTimeout = this.properties.ticksUntilTimeout - 1 - end -end -</pre> -</blockquote> -</blockquote> -</div> -</div> -</div> -</div> -</body> -</html> Modified: tools/luadocs/project.txt =================================================================== --- tools/luadocs/project.txt 2007-08-30 00:10:50 UTC (rev 1830) +++ tools/luadocs/project.txt 2007-08-31 03:36:26 UTC (rev 1831) @@ -1,4 +1,6 @@ +@project Yake's Lua Scripting Reference (for Yake 0.7.0) + @namespace yake @namespace base @@ -86,12 +88,44 @@ @function *(xform) @param xform (Quaternion) - @constant Zero (Vector3) + @constant Zero (Vector3) =(0,0,0) @constant UnitScale (Vector3) - @constant UnitX (Vector3) - @constant UnitY (Vector3) - @constant UnitZ (Vector3) + @constant UnitX (Vector3) =(1,0,0) + @constant UnitY (Vector3) =(0,1,0) + @constant UnitZ (Vector3) =(0,0,1) @end -- Vector3 + + @class Point3 + @property x (number) + @property y (real) + @property z (real) + @constructor Point3() + @constructor Point3(x,y,z) + @param x (real) + @param y (real) + @param z (real) + @code Valid constructors + v = Point3() -- all components set to zero (0) + v = Point3(1,2,0) -- custom values + v = Point3.Zero -- set to constant + @codeend + @function asVector() + @return (Vector3) vector with the same component values + @function *(factor) + @param factor (real) + @function /(factor) + @param factor (real) + @function +(other) + @param other (Vector3) + @function -(other) + @param other (Vector3) + @function *(xform) + @param xform (Matrix3) + @function *(xform) + @param xform (Quaternion) + + @constant Zero (Point3) =(0,0,0) + @end -- Point3 @class Vector4 @function Vector4() @@ -125,7 +159,37 @@ @param other(Quaternion) @return (Quaternion) result of multiplication @end -- Quaternion + + @class Volume + @function intersectsWith(point) + @param point (Point3) + @return (bool) true if point is contained in the volume, false if not. + @function intersectsWith(volume) + @param volume (Volume) Any isntance of a derived class of Volume, e.g. Sphere. + @return (bool) true if volumes intersect, false if they don't. + @end + @class VolumeContainer + @code Adding volumes + ctr = yake.VolumeContainer() + ctr:add( yake.Sphere(2) ) -- adds sphere with radius 2 at (0,0,0) + @codeend + @function add(volume) + @param volume (Volume) adds an instance of a derived class of Volume (like Sphere) + @end + + @class Sphere + @inherits Volume + @property radius (real) + @property position (Point3) + @constructor Sphere() + @constructor Sphere(radius) + @param radius (real) + @constructor Sphere(radius,position) + @param radius (real) + @param position (Point3) + @end + @end -- namespace base @namespace input @@ -184,17 +248,31 @@ @return () value of property @code this = ... --assign Object instance to 'this' - myName = this.properties["name"] + myName = this.properties["name"] -- retrieve value + this.properties["name"] = myName .. " Meyes" -- set value @codeend @function operator.(name) @param name (string) name of property @return () value of property @code - myName = this.properties.name + myName = this.properties.name -- retrieve value + this.properties.name = "Jack" -- set value @codeend @function create(name,value) @param name (string) @param value (any) The type of the property is deduced from value (true => boolean, 1 => number, ...) + @code + this.properties:create("name","Jack") -- constructs property of type 'string' + this.properties:create("health",10) -- constructs property of type 'number' + this.properties:create("model",yake.Model()) -- constructs custom typed property + @codeend + @function foreach(op) + @param op (function) + @code + this.properties.each( function(name,value) + print("property " .. name .. " = " .. value) + end ) + @codeend @end -- PropertyAccess @class Object @@ -222,6 +300,7 @@ @property id (Object... [truncated message content] |
From: <psy...@us...> - 2007-08-30 00:10:48
|
Revision: 1830 http://yake.svn.sourceforge.net/yake/?rev=1830&view=rev Author: psyclonist Date: 2007-08-29 17:10:50 -0700 (Wed, 29 Aug 2007) Log Message: ----------- * [luadocs] updated manual (yake.ent) * [luadocs] lua_bindings_2_rst now supports 'events' Modified Paths: -------------- tools/luadocs/lua_bindings_2_rst.lua tools/luadocs/project.html tools/luadocs/project.txt Modified: tools/luadocs/lua_bindings_2_rst.lua =================================================================== --- tools/luadocs/lua_bindings_2_rst.lua 2007-08-29 22:58:33 UTC (rev 1829) +++ tools/luadocs/lua_bindings_2_rst.lua 2007-08-30 00:10:50 UTC (rev 1830) @@ -64,6 +64,7 @@ db.newProperty = function(name,type) assert(db.getCurrClass()) assert(name) + type = type or "unknown" assert(type) db.getCurrClass().properties[name] = type end @@ -285,6 +286,11 @@ assert(db.currentFn) db.currentFn.tag = "constructor" end +jump["event"] = function(line) + jump["function"](line) + assert(db.currentFn) + db.currentFn.tag = "event" +end jump["constant"] = function(line) local patName = "[%w+]+"; local name = string.gmatch(line,patName) @@ -430,7 +436,7 @@ rst.f:write(v) end end - rst.f:write("\n") + rst.f:write("\n\n") end end rst.onBeginConstants = function() @@ -477,6 +483,30 @@ rst.onEndProperties = function() rst.f:write("\n") end +rst.onBeginEvents = function() + rst.f:write("\n") + rst.f:write("**Events**\n\n") +end +rst.onEvent = function(name,type,typeLookupFn) + assert( name and type ) + + local ti = type + if ti then + local custom,_ = typeLookupFn:exec(type) + if custom then + ti = "`"..custom.."`_" + end + end + + rst.f:write(" * **" .. name .. "**") + if ti then + rst.f:write(" ( " .. ti .. " ) ") + end + rst.f:write("\n") +end +rst.onEndEvents = function() + rst.f:write("\n") +end rst.onBeginCodes = function() rst.f:write("\n") rst.f:write("**Code**\n\n") @@ -649,10 +679,15 @@ -- functions local function doFunctions(sectionName,scope,tag) if scope.functions and getn(scope.functions) > 0 then - rst.onBeginFunctions(sectionName) + local bAtLeastOne = false for fnName,fnBase in pairs(scope.functions) do for _,fnObj in pairs(fnBase.overloads) do if fnObj.tag == tag then + if not bAtLeastOne then + bAtLeastOne = true + rst.onBeginFunctions(sectionName) + end + local params = "" for _,v in pairs(fnObj.params) do if string.len(params) > 0 then params = params .. "," end @@ -667,9 +702,12 @@ end end end - rst.onEndFunctions() + if bAtLeastOne then + rst.onEndFunctions() + end end end + doFunctions("Events",scope,"event") doFunctions("Constructors",scope,"constructor") doFunctions("Functions",scope) Modified: tools/luadocs/project.html =================================================================== --- tools/luadocs/project.html 2007-08-29 22:58:33 UTC (rev 1829) +++ tools/luadocs/project.html 2007-08-30 00:10:50 UTC (rev 1830) @@ -18,7 +18,7 @@ <tbody valign="top"> <tr><th class="docinfo-name">Author:</th> <td>Stephan Kaiser's LuaBindingsAutoDoc</td></tr> -<tr class="field"><th class="docinfo-name">Generated on:</th><td class="field-body">23 Aug 2007</td> +<tr class="field"><th class="docinfo-name">Generated on:</th><td class="field-body">30 Aug 2007</td> </tr> <tr><th class="docinfo-name">Status:</th> <td>Draft</td></tr> @@ -29,38 +29,111 @@ <div class="contents local topic" id="table-of-contents"> <p class="topic-title first">Table of Contents</p> <ul class="auto-toc simple"> -<li><a class="reference" href="#namespace-base" id="id3">1.1 namespace: base</a><ul> -<li><a class="reference" href="#quaternion" id="id4">Quaternion</a></li> -<li><a class="reference" href="#math" id="id5">Math</a></li> -<li><a class="reference" href="#color" id="id6">Color</a></li> -<li><a class="reference" href="#matrix3" id="id7">Matrix3</a></li> -<li><a class="reference" href="#vector4" id="id8">Vector4</a></li> -<li><a class="reference" href="#vector3" id="id9">Vector3</a></li> +<li><a class="reference" href="#namespace-input" id="id4">1.1 namespace: input</a><ul> +<li><a class="reference" href="#device" id="id5">Device</a></li> +<li><a class="reference" href="#whateverdevice" id="id6">WhateverDevice</a></li> +<li><a class="reference" href="#keyboarddevice" id="id7">KeyboardDevice</a></li> </ul> </li> -<li><a class="reference" href="#namespace-input" id="id10">1.2 namespace: input</a><ul> -<li><a class="reference" href="#device" id="id11">Device</a></li> -<li><a class="reference" href="#whateverdevice" id="id12">WhateverDevice</a></li> -<li><a class="reference" href="#keyboarddevice" id="id13">KeyboardDevice</a></li> +<li><a class="reference" href="#namespace-base" id="id8">1.2 namespace: base</a><ul> +<li><a class="reference" href="#quaternion" id="id9">Quaternion</a></li> +<li><a class="reference" href="#math" id="id10">Math</a></li> +<li><a class="reference" href="#color" id="id11">Color</a></li> +<li><a class="reference" href="#matrix3" id="id12">Matrix3</a></li> +<li><a class="reference" href="#vector4" id="id13">Vector4</a></li> +<li><a class="reference" href="#vector3" id="id14">Vector3</a></li> </ul> </li> +<li><a class="reference" href="#namespace-ent" id="id15">1.3 namespace: ent</a><ul> +<li><a class="reference" href="#propertyaccess" id="id16">PropertyAccess</a></li> +<li><a class="reference" href="#object" id="id17">Object</a></li> +<li><a class="reference" href="#entity" id="id18">Entity</a></li> +<li><a class="reference" href="#proximitytrigger" id="id19">ProximityTrigger</a></li> +<li><a class="reference" href="#objectid" id="id20">ObjectId</a></li> +<li><a class="reference" href="#trigger" id="id21">Trigger</a></li> </ul> +</li> +</ul> </div> -<div class="section" id="namespace-base"> -<h2><a class="toc-backref" href="#id3">1.1 namespace: base</a></h2> +<div class="section" id="namespace-input"> +<h2><a class="toc-backref" href="#id4">1.1 namespace: input</a></h2> <div class="contents local topic" id="id1"> <p class="topic-title first">Table of Contents</p> <ul class="simple"> -<li><a class="reference" href="#quaternion" id="id14">Quaternion</a></li> -<li><a class="reference" href="#math" id="id15">Math</a></li> -<li><a class="reference" href="#color" id="id16">Color</a></li> -<li><a class="reference" href="#matrix3" id="id17">Matrix3</a></li> -<li><a class="reference" href="#vector4" id="id18">Vector4</a></li> -<li><a class="reference" href="#vector3" id="id19">Vector3</a></li> +<li><a class="reference" href="#device" id="id22">Device</a></li> +<li><a class="reference" href="#whateverdevice" id="id23">WhateverDevice</a></li> +<li><a class="reference" href="#keyboarddevice" id="id24">KeyboardDevice</a></li> </ul> </div> +<div class="section" id="device"> +<h3><a class="toc-backref" href="#id22">Device</a></h3> +</div> +<div class="section" id="whateverdevice"> +<h3><a class="toc-backref" href="#id23">WhateverDevice</a></h3> +<p><strong>inherits</strong> <a class="reference" href="#device">Device</a>, Parent2</p> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>stuffOk</strong> of type <strong>bool</strong></li> +<li><strong>isOk</strong> of type <strong>bool|readonly</strong></li> +</ul> +</blockquote> +</div> +<div class="section" id="keyboarddevice"> +<h3><a class="toc-backref" href="#id24">KeyboardDevice</a></h3> +<p><strong>inherits</strong> <a class="reference" href="#device">Device</a></p> +<p><strong>Code</strong></p> +<blockquote> +<p>Example #1:</p> +<pre class="literal-block"> +dev:poll(yeeha) +</pre> +</blockquote> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>enabled</strong> of type <strong>bool</strong></li> +<li><strong>name</strong> of type <strong>string</strong></li> +<li><strong>pseudo</strong> of type <a class="reference" href="#device">Device</a></li> +</ul> +</blockquote> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>poll(a,b,c,d)</strong></p> +<blockquote> +<p><strong>a</strong> of type <strong>string</strong> - ...</p> +<p><strong>b</strong> of type <strong>int</strong> - ...</p> +<p><strong>c</strong> of type <strong>whatever</strong></p> +<p><strong>d</strong> of type <a class="reference" href="#device">Device</a> - ...</p> +<p>returns <strong>bool</strong> - returns true on success</p> +</blockquote> +</li> +</ul> +<blockquote> +<p>Example for poll():</p> +<pre class="literal-block"> +dev:poll(yeeha) +</pre> +</blockquote> +</blockquote> +</div> +</div> +<div class="section" id="namespace-base"> +<h2><a class="toc-backref" href="#id8">1.2 namespace: base</a></h2> +<div class="contents local topic" id="id2"> +<p class="topic-title first">Table of Contents</p> +<ul class="simple"> +<li><a class="reference" href="#quaternion" id="id25">Quaternion</a></li> +<li><a class="reference" href="#math" id="id26">Math</a></li> +<li><a class="reference" href="#color" id="id27">Color</a></li> +<li><a class="reference" href="#matrix3" id="id28">Matrix3</a></li> +<li><a class="reference" href="#vector4" id="id29">Vector4</a></li> +<li><a class="reference" href="#vector3" id="id30">Vector3</a></li> +</ul> +</div> <div class="section" id="quaternion"> -<h3><a class="toc-backref" href="#id14">Quaternion</a></h3> +<h3><a class="toc-backref" href="#id25">Quaternion</a></h3> <p><strong>Properties</strong></p> <blockquote> <ul class="simple"> @@ -70,7 +143,6 @@ <li><strong>z</strong> of type <strong>real</strong></li> </ul> </blockquote> -<p><strong>Constructors</strong></p> <p><strong>Functions</strong></p> <blockquote> <ul> @@ -86,10 +158,10 @@ </blockquote> </div> <div class="section" id="math"> -<h3><a class="toc-backref" href="#id15">Math</a></h3> +<h3><a class="toc-backref" href="#id26">Math</a></h3> </div> <div class="section" id="color"> -<h3><a class="toc-backref" href="#id16">Color</a></h3> +<h3><a class="toc-backref" href="#id27">Color</a></h3> <p><strong>Code</strong></p> <blockquote> <p>Valid constructors::</p> @@ -131,10 +203,9 @@ </li> </ul> </blockquote> -<p><strong>Functions</strong></p> </div> <div class="section" id="matrix3"> -<h3><a class="toc-backref" href="#id17">Matrix3</a></h3> +<h3><a class="toc-backref" href="#id28">Matrix3</a></h3> <p><strong>Constants</strong></p> <blockquote> <ul class="simple"> @@ -169,8 +240,7 @@ </blockquote> </div> <div class="section" id="vector4"> -<h3><a class="toc-backref" href="#id18">Vector4</a></h3> -<p><strong>Constructors</strong></p> +<h3><a class="toc-backref" href="#id29">Vector4</a></h3> <p><strong>Functions</strong></p> <blockquote> <ul> @@ -188,7 +258,7 @@ </blockquote> </div> <div class="section" id="vector3"> -<h3><a class="toc-backref" href="#id19">Vector3</a></h3> +<h3><a class="toc-backref" href="#id30">Vector3</a></h3> <p><strong>Properties</strong></p> <blockquote> <ul class="simple"> @@ -326,66 +396,174 @@ </blockquote> </div> </div> -<div class="section" id="namespace-input"> -<h2><a class="toc-backref" href="#id10">1.2 namespace: input</a></h2> -<div class="contents local topic" id="id2"> +<div class="section" id="namespace-ent"> +<h2><a class="toc-backref" href="#id15">1.3 namespace: ent</a></h2> +<div class="contents local topic" id="id3"> <p class="topic-title first">Table of Contents</p> <ul class="simple"> -<li><a class="reference" href="#device" id="id20">Device</a></li> -<li><a class="reference" href="#whateverdevice" id="id21">WhateverDevice</a></li> -<li><a class="reference" href="#keyboarddevice" id="id22">KeyboardDevice</a></li> +<li><a class="reference" href="#propertyaccess" id="id31">PropertyAccess</a></li> +<li><a class="reference" href="#object" id="id32">Object</a></li> +<li><a class="reference" href="#entity" id="id33">Entity</a></li> +<li><a class="reference" href="#proximitytrigger" id="id34">ProximityTrigger</a></li> +<li><a class="reference" href="#objectid" id="id35">ObjectId</a></li> +<li><a class="reference" href="#trigger" id="id36">Trigger</a></li> </ul> </div> -<div class="section" id="device"> -<h3><a class="toc-backref" href="#id20">Device</a></h3> +<div class="section" id="propertyaccess"> +<h3><a class="toc-backref" href="#id31">PropertyAccess</a></h3> +<p><strong>Functions</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>operator.(name)</strong></p> +<blockquote> +<p><strong>name</strong> of type <strong>string</strong> - name of property</p> +<p>returns - value of property</p> +</blockquote> +</li> +</ul> +<pre class="literal-block"> +myName = this.properties.name +</pre> +<ul> +<li><p class="first"><strong>create(name,value)</strong></p> +<blockquote> +<p><strong>name</strong> of type <strong>string</strong></p> +<p><strong>value</strong> of type <strong>any</strong> - The type of the property is deduced from value (true => boolean, 1 => number, ...)</p> +</blockquote> +</li> +<li><p class="first"><strong>operator[](name)</strong></p> +<blockquote> +<p><strong>name</strong> of type <strong>string</strong> - name of property</p> +<p>returns - value of property</p> +</blockquote> +</li> +</ul> +<pre class="literal-block"> +this = ... --assign Object instance to 'this' +myName = this.properties["name"] +</pre> +</blockquote> </div> -<div class="section" id="whateverdevice"> -<h3><a class="toc-backref" href="#id21">WhateverDevice</a></h3> -<p><strong>inherits</strong> <a class="reference" href="#device">Device</a>, Parent2</p> +<div class="section" id="object"> +<h3><a class="toc-backref" href="#id32">Object</a></h3> +<p><strong>Code</strong></p> +<blockquote> +<p>Accessing events::</p> +<pre class="literal-block"> +this = ... --assign Object instance to 'this' + +this.events:create("toggled") + +-- connect anonymous handler: +this.events.toggled:connect( function() print("TOGGLED!") end ) + +-- connect known function 'on_toggled' +this.events.toggled:connect( on_toggled ) + +-- fire event: +this.events.toggled(true) -- prints "TOGGLED!" to the console +</pre> +<p>Accessing properties::</p> +<pre class="literal-block"> +this = ... --assign Object instance to 'this' + +this.properties:create("name","Jack") +myName = this.properties["name"] +myName = this.properties.name +</pre> +</blockquote> <p><strong>Properties</strong></p> <blockquote> <ul class="simple"> -<li><strong>stuffOk</strong> of type <strong>bool</strong></li> -<li><strong>isOk</strong> of type <strong>bool|readonly</strong></li> +<li><strong>id</strong> of type <a class="reference" href="#objectid">ObjectId</a></li> +<li><strong>properties</strong> of type <a class="reference" href="#propertyaccess">PropertyAccess</a></li> </ul> </blockquote> </div> -<div class="section" id="keyboarddevice"> -<h3><a class="toc-backref" href="#id22">KeyboardDevice</a></h3> -<p><strong>inherits</strong> <a class="reference" href="#device">Device</a></p> -<p><strong>Code</strong></p> +<div class="section" id="entity"> +<h3><a class="toc-backref" href="#id33">Entity</a></h3> +<p><strong>inherits</strong> <a class="reference" href="#object">Object</a></p> +</div> +<div class="section" id="proximitytrigger"> +<h3><a class="toc-backref" href="#id34">ProximityTrigger</a></h3> +<p><strong>inherits</strong> <a class="reference" href="#trigger">Trigger</a></p> +<p><strong>Functions</strong></p> <blockquote> -<p>Example #1:</p> +<ul> +<li><p class="first"><strong>addVolume(volume)</strong></p> +<blockquote> +<p><strong>volume</strong> of type <strong>VolumeChecker</strong></p> +</blockquote> +</li> +</ul> <pre class="literal-block"> -dev:poll(yeeha) +trigger:addVolume( volumecheck.Sphere(5, this.properties.position ) ) </pre> </blockquote> +</div> +<div class="section" id="objectid"> +<h3><a class="toc-backref" href="#id35">ObjectId</a></h3> <p><strong>Properties</strong></p> <blockquote> <ul class="simple"> -<li><strong>enabled</strong> of type <strong>bool</strong></li> -<li><strong>name</strong> of type <strong>string</strong></li> -<li><strong>pseudo</strong> of type <a class="reference" href="#device">Device</a></li> +<li><strong>serialNo</strong> of type <strong>unknown</strong></li> +<li><strong>classId</strong> of type <strong>unknown</strong></li> </ul> </blockquote> -<p><strong>Constructors</strong></p> +</div> +<div class="section" id="trigger"> +<h3><a class="toc-backref" href="#id36">Trigger</a></h3> +<p><strong>inherits</strong> <a class="reference" href="#entity">Entity</a></p> +<p><strong>Properties</strong></p> +<blockquote> +<ul class="simple"> +<li><strong>condition</strong> of type <strong>function</strong></li> +</ul> +</blockquote> +<p><strong>Events</strong></p> +<blockquote> +<ul> +<li><p class="first"><strong>onTriggered(any)</strong></p> +<blockquote> +<p><strong>any</strong> of type <strong>any</strong> - The (optional) parameter that was passed the the Event's fire() method.</p> +</blockquote> +</li> +</ul> +</blockquote> <p><strong>Functions</strong></p> <blockquote> <ul> -<li><p class="first"><strong>poll(a,b,c,d)</strong></p> +<li><p class="first"><strong>setCondition(condition)</strong></p> <blockquote> -<p><strong>a</strong> of type <strong>string</strong> - ...</p> -<p><strong>b</strong> of type <strong>int</strong> - ...</p> -<p><strong>c</strong> of type <strong>whatever</strong></p> -<p><strong>d</strong> of type <a class="reference" href="#device">Device</a> - ...</p> -<p>returns <strong>bool</strong> - returns true on success</p> +<p><strong>condition</strong> of type <strong>function</strong> - Condition function that is called each tick to determine whether the trigger should be triggered. NB Set be 'nil' to clear the trigger condition.</p> </blockquote> </li> </ul> <blockquote> -<p>Example for poll():</p> +<p>Example of a little Timeout Trigger:</p> <pre class="literal-block"> -dev:poll(yeeha) +this = objectManager:create("Trigger") -- <- a little bit more complicated in real-life + +function onTimeout(isOn) -- <- The trigger handler. + if isOn then + print("Timeout!") -- 'isOn' is of type boolean representing the trigger state + else + print("Trigger restarted.") + end +end +function startup() -- <- called when an Object has been spawned (Object is in 'this') + this.properties:create("ticksUntilTimeout",10) + this.condition = function() + return this.properties.ticksUntilTimeout < 0 + end + this.events.onTriggered:connect( onTimeout ) +end + +function on_tick() + if ticksUntilTimeout > 0 then + this.properties.ticksUntilTimeout = this.properties.ticksUntilTimeout - 1 + end +end </pre> </blockquote> </blockquote> Modified: tools/luadocs/project.txt =================================================================== --- tools/luadocs/project.txt 2007-08-29 22:58:33 UTC (rev 1829) +++ tools/luadocs/project.txt 2007-08-30 00:10:50 UTC (rev 1830) @@ -169,3 +169,108 @@ @end @end -- input + + +@namespace ent + +@class ObjectId + @property classId + @property serialNo +@end -- ObjectId + +@class PropertyAccess + @function operator[](name) + @param name (string) name of property + @return () value of property + @code + this = ... --assign Object instance to 'this' + myName = this.properties["name"] + @codeend + @function operator.(name) + @param name (string) name of property + @return () value of property + @code + myName = this.properties.name + @codeend + @function create(name,value) + @param name (string) + @param value (any) The type of the property is deduced from value (true => boolean, 1 => number, ...) +@end -- PropertyAccess + +@class Object + @code Accessing properties: + this = ... --assign Object instance to 'this' + + this.properties:create("name","Jack") + myName = this.properties["name"] + myName = this.properties.name + @codeend + @code Accessing events: + this = ... --assign Object instance to 'this' + + this.events:create("toggled") + + -- connect anonymous handler: + this.events.toggled:connect( function() print("TOGGLED!") end ) + + -- connect known function 'on_toggled' + this.events.toggled:connect( on_toggled ) + + -- fire event: + this.events.toggled(true) -- prints "TOGGLED!" to the console + @codeend + + @property id (ObjectId) + @property properties (PropertyAccess) +@end -- Object + +@class Entity + @inherits Object +@end -- Entity + +@class Trigger + @inherits Entity + + @event onTriggered(any) Triggered when the evaluation of the condition function results in a change of state. + @param any (any) The (optional) parameter that was passed the the Event's fire() method. + + @property condition (function) read-write + @function setCondition(condition) + @param condition (function) Condition function that is called each tick to determine whether the trigger should be triggered. NB Set be 'nil' to clear the trigger condition. + @code Example of a little Timeout Trigger + this = objectManager:create("Trigger") -- <- a little bit more complicated in real-life + + function onTimeout(isOn) -- <- The trigger handler. + if isOn then + print("Timeout!") -- 'isOn' is of type boolean representing the trigger state + else + print("Trigger restarted.") + end + end + + function startup() -- <- called when an Object has been spawned (Object is in 'this') + this.properties:create("ticksUntilTimeout",10) + this.condition = function() + return this.properties.ticksUntilTimeout < 0 + end + this.events.onTriggered:connect( onTimeout ) + end + + function on_tick() + if ticksUntilTimeout > 0 then + this.properties.ticksUntilTimeout = this.properties.ticksUntilTimeout - 1 + end + end + @codeend +@end -- Trigger + +@class ProximityTrigger + @inherits Trigger + @function addVolume(volume) + @param volume (VolumeChecker) + @code + trigger:addVolume( volumecheck.Sphere(5, this.properties.position ) ) + @codeend +@end + +@end -- ent This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-29 22:58:31
|
Revision: 1829 http://yake.svn.sourceforge.net/yake/?rev=1829&view=rev Author: psyclonist Date: 2007-08-29 15:58:33 -0700 (Wed, 29 Aug 2007) Log Message: ----------- * [bindings.lua] added more bindings for yake.graphics and yake.graphicsOGRE * [bindings.lua] improved bindings for object/entity properties and events * various small improvements in bindings.lua, ent, property and premake scripts Modified Paths: -------------- trunk/yake/common/media/scripts/o_access.lua trunk/yake/samples/ent/sampleEntFsm/demo.cpp trunk/yake/scripts/premake/config.lua trunk/yake/scripts/premake/yake.lua trunk/yake/src/bindings.lua/detail/ent.lua.cpp trunk/yake/src/bindings.lua/detail/graphics.lua.cpp trunk/yake/src/bindings.lua/detail/res.lua.cpp trunk/yake/src/ent/object.cpp trunk/yake/src/ent/object_mgr.cpp trunk/yake/src/ent/trigger.cpp trunk/yake/yake/ent/object.h trunk/yake/yake/ent/object_mgr.h trunk/yake/yake/ent/trigger.h trunk/yake/yake/property/property_container.h Added Paths: ----------- trunk/yake/common/media/scripts/entityeventaccess.lua trunk/yake/common/media/scripts/entitypropertyaccess.lua Added: trunk/yake/common/media/scripts/entityeventaccess.lua =================================================================== --- trunk/yake/common/media/scripts/entityeventaccess.lua (rev 0) +++ trunk/yake/common/media/scripts/entityeventaccess.lua 2007-08-29 22:58:33 UTC (rev 1829) @@ -0,0 +1,91 @@ +--print("entityeventaccess.lua:START") + +-- @param t (table) table to wrap (can be empty) +-- @param access () object of type ent.Object.PropertyAccess (bindings.lua:ent) or +-- of type property.NamedPropertyContainer (bindings.lua:property). +-- @param implicitCreation (boolean) +-- @return nothing +function wrapEventsTable(t,access,implicitCreation) + t.list = {} + t.accessor = access + assert( t.accessor ) + t.create = function(self,k,v) + local p = self.accessor:create(k,v) + assert( p ~= nil ) + + -- @todo really provide this accessor a la __newindex and rawset below??? + rawset(t.list,k,p) + + return p + end + + --@todo loop through all existing properties in propAccess and + -- create an accessor (with rawset) in t.list for each key. + -- same as in t.create() or __newindex(). + --print(type(access.size)) + --print(access.size) + for k = 1, access.size do + local p = access:get(k) + assert( p ~= nil ) + --print("exist:",p.name) + rawset(t.list,p.name,p) + end + + -- + if implicitCreation == nil then + --print("defaulting") + implicitCreation = true + end + assert( type(implicitCreation) == "boolean" ) + print("events implicitCreation:",implicitCreation) + + setmetatable(t, { + __index = function(t,k) + assert( t.accessor ~= nil ) + --print("INDEX",t,k) + if type(k) ~= "string" then + print("events __index -> ERROR: key is not of type 'string' but of type '"..type(k).."'!") + return nil + end + --print("GET",k) + local p = t.accessor:get(k) + --print("=",type(p)) + assert( p~= nil ) + if p then + return p + end + return nil + end, + __newindex = function(t,k,v) + --print("NEWINDEX",t,"'"..tostring(k).."' ->",type(k),"value=",v) + + if type(k) ~= "string" then + --print("-> ERROR: key is not a string!") + return nil + end + local exists = t.accessor:get(k) + if exists then + --print("=> EXISTS") + exists:set(v) + return true + end + print(implicitCreation) + if implicitCreation then + local p = t.accessor:create(k,v) + assert( p ~= nil ) + + -- @todo really provide an accessor??? + rawset(t.list,k,p) + + return true + else + return false + end + end + }) +end +--local bool demo_uses_implicit_creation = true -- set to true/false to test the different policies +-- setup properties table +--wrapPropertiesTable(properties,props,demo_uses_implicit_creation) + +--print("entityeventaccess.lua:END") \ No newline at end of file Added: trunk/yake/common/media/scripts/entitypropertyaccess.lua =================================================================== --- trunk/yake/common/media/scripts/entitypropertyaccess.lua (rev 0) +++ trunk/yake/common/media/scripts/entitypropertyaccess.lua 2007-08-29 22:58:33 UTC (rev 1829) @@ -0,0 +1,89 @@ +--print("entitypropertyaccess.lua:START") + +-- @param t (table) table to wrap (can be empty) +-- @param propAccess () object of type ent.Object.PropertyAccess (bindings.lua:ent) or +-- of type property.NamedPropertyContainer (bindings.lua:property). +-- @param implicitCreation (boolean) +-- @return nothing +function wrapPropertiesTable(t,propAccess,implicitCreation) + t.list = {} + t.accessor = propAccess + assert( t.accessor ) + t.create = function(self,k,v) + local p = self.accessor:create(k,v) + assert( p ~= nil ) + + -- @todo really provide this accessor a la __newindex and rawset below??? + rawset(t.list,k,p) + + return p + end + + --@todo loop through all existing properties in propAccess and + -- create an accessor (with rawset) in t.list for each key. + -- same as in t.create() or __newindex(). + --print(type(propAccess.size)) + --print(propAccess.size) + for k = 1, propAccess.size do + local p = propAccess:get(k) + assert( p ~= nil ) + --print("exist:",p.name) + rawset(t.list,p.name,p) + end + + -- + if implicitCreation == nil then + --print("defaulting") + implicitCreation = true + end + assert( type(implicitCreation) == "boolean" ) + --print(implicitCreation) + + setmetatable(t, { + __index = function(t,k) + assert( t.accessor ~= nil ) + --print("INDEX",t,k) + if type(k) ~= "string" then + print("properties __index -> ERROR: key is not of type 'string' but of type '"..type(k).."'!") + return nil + end + local p = t.accessor:get(k) + assert( p ~= nil ) + if p then + return p:get() + end + return nil + end, + __newindex = function(t,k,v) + --print("NEWINDEX",t,"'"..tostring(k).."' ->",type(k),"value=",v) + + if type(k) ~= "string" then + --print("-> ERROR: key is not a string!") + return nil + end + local exists = t.accessor:get(k) + if exists then + --print("=> EXISTS") + exists:set(v) + return true + end + print(implicitCreation) + if implicitCreation then + local p = t.accessor:create(k,v) + assert( p ~= nil ) + + -- @todo really provide an accessor??? + rawset(t.list,k,p) + + return true + else + return false + end + end + }) +end +--local bool demo_uses_implicit_creation = true -- set to true/false to test the different policies +-- setup properties table +--wrapPropertiesTable(properties,props,demo_uses_implicit_creation) + +--print("entitypropertyaccess.lua:END") \ No newline at end of file Modified: trunk/yake/common/media/scripts/o_access.lua =================================================================== --- trunk/yake/common/media/scripts/o_access.lua 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/common/media/scripts/o_access.lua 2007-08-29 22:58:33 UTC (rev 1829) @@ -1,133 +1,62 @@ print("> Starting object script..."); -function startup() - --this:fsm("main"):connectTo("alive",fn) -- connects to 'enter', 'tick', 'exit' - --this:fsm("main"):connectToEnter("dead",fn) -- connects to 'enter' only - --this:fsm("main"):connect("alive", fnEnter, fnTick, fnExit) - this:events("spawn"):connect( - function() - - end - ) -end -properties = {} -properties_mt = {} - -properties_mt.__index = function(t,k) - print("INDEX",t,k) - --for u,v in pairs(t) do print(u,v) end - --return events[k] - return this:properties():get(k):get() -end -properties_mt.__newindex = function(t,k,v) - print("NEWINDEX",t,"'"..tostring(k).."'",v) - --rawset(t,k,v) - --for u,v in pairs(t) do print(u,v) end - local exists = this:properties():get(k) - if exists then - print("EXISTS") - exists:set(v) - return true +-- replace loadfile and dofile with yake.loadfile and yake.dofile. +-- the replacements use yake's resource system to locate the files. +yake.old_loadfile = loadfile +yake.old_dofile = dofile +loadfile = nil +dofile = nil +yake.dofile = function(path) + local locator = yake.res.global.sourceManager + assert( locator ~= nil ) + local succ = locator:find(path) + print(succ) + assert( succ.valid ) + if succ.valid then + local f = yake.old_loadfile(succ.location) + assert( f ) + return f() -- execute! end - this:properties():create(k,v) - return true + return nil end -setmetatable(properties, properties_mt) -properties.s = 1 -properties["s"] = 2 -print(properties["s"]) +print("* loading accessor scripts...") +yake.dofile("entitypropertyaccess.lua") +yake.dofile("entityeventaccess.lua") -event = { - on_spawn = function() - print(" script event.on_spawn") - this:properties():create("ticks",0) - end, - on_tick = function() - print(" script event.on_tick") - end, - on_die = function() - print(" script event.on_die") - end, - -- various: - onArrived = function() --triggered as a result of "go to" - end, - -- Trigger - on_toggle = function() - print("event.on_toggle") - end -} -fsm = { - main = { - states = { - awakening, - alive, - dead - }, - transitions = { - {awakening,"spawn",alive}, - {alive,"die",dead} - } - } -} -state = { - off = { - on_enter = function() - print("state.off.enter()") +--local thisTrigger = yake.asTrigger(this) +local no_implicit_creation = false - this:setCondition(function() return (this:property("ticks"):get() >= 1 and this:property("ticks"):get() <= 3) end) - this:events():get("onTriggered"):connect( function(a) print("TRIGGER:onTriggered:",a) end ) - end, - on_tick = function() - local ticks = this:property("ticks") - if ticks then - ticks:set( ticks:get() + 1 ) - end - print("state.off.tick()") --,ticks:get() - -- - --if (state.off.ticks == 1) then - -- this:processFsmEvent("trigger") - --end - -- - --this:events():get("onTriggered"):fire(42) - end, - on_exit = function() - print("state.off.exit()") - end - } - , - on = { - on_enter = function() - print("state.on.enter()") - end, - on_tick = function() - local ticks = this:property("ticks") - if ticks then - ticks:set( ticks:get() + 1 ) - end - print("state.on.tick()") --,ticks:get() - end, - on_exit = function() - print("state.on.exit()") - end - } - , - dead = { - on_enter = function() - print(" script state.dead.on_enter") - end, - on_tick = function() - print(" script state.dead.on_tick") - end, - on_exit = function() - print(" script state.dead.on_exit") - end - } -} +properties = {} +wrapPropertiesTable(properties,this:properties(),no_implicit_creation) +assert( properties.accessor ) + +events = {} +wrapEventsTable(events,this:events(),no_implicit_creation) +assert( events.accessor ) + +-- +function onTick() + print(" script on_tick",properties.ticks) + properties.ticks = properties.ticks + 1 + --properties.doesnotexist = properties.ticks -- <- results in Luabind exception if property does not exist +end +function startup() + -- common ent::Object events + events.spawn:connect( function() print(" script on_spawn ") end ) + events.tick:connect( onTick ) + events.preDestroy:connect( function() print(" script on_preDestroy") end ) + + -- ent::Triggere stuff + properties:create("ticks",0) -- create property of type 'number' + this:setCondition(function() return (properties.ticks >= 1 and properties.ticks <= 3) end) + events.onTriggered:connect( function(a) print(" script on_triggered",a) end ) +end print("> Object script up."); function main() - print("main()") + print(" script main()") + startup() end Modified: trunk/yake/samples/ent/sampleEntFsm/demo.cpp =================================================================== --- trunk/yake/samples/ent/sampleEntFsm/demo.cpp 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/samples/ent/sampleEntFsm/demo.cpp 2007-08-29 22:58:33 UTC (rev 1829) @@ -283,6 +283,7 @@ */ // clean up + objMgr.destroyAllObjects(); // <- may trigger Lua callbacks. exappObjInitializer.reset(); luaSys.reset(); } Modified: trunk/yake/scripts/premake/config.lua =================================================================== --- trunk/yake/scripts/premake/config.lua 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/scripts/premake/config.lua 2007-08-29 22:58:33 UTC (rev 1829) @@ -55,6 +55,7 @@ ENABLE_LUA_PROPERTY = true -- 'property' binder (with specialization for string based indexing) ENABLE_LUA_ENT = true -- 'ent' binder (requires BASE, MODEL and PROPERTY binders!) ENABLE_LUA_GRAPHICS = true +ENABLE_LUA_GRAPHICS_OGRE = true ENABLE_LUA_PHYSICS = true ENABLE_LUA_INPUT = true ENABLE_LUA_RAF = true -- example application framework Modified: trunk/yake/scripts/premake/yake.lua =================================================================== --- trunk/yake/scripts/premake/yake.lua 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/scripts/premake/yake.lua 2007-08-29 22:58:33 UTC (rev 1829) @@ -74,6 +74,7 @@ f:write("#define YAKE_ENABLE_LUA_ENT " .. bool_to_int(ENABLE_LUA_ENT) .. "\n") f:write("#define YAKE_ENABLE_LUA_PROPERTY " .. bool_to_int(ENABLE_LUA_PROPERTY) .. "\n") f:write("#define YAKE_ENABLE_LUA_GRAPHICS " .. bool_to_int(ENABLE_LUA_GRAPHICS) .. "\n") + f:write("#define YAKE_ENABLE_LUA_GRAPHICS_OGRE " .. bool_to_int(ENABLE_LUA_GRAPHICS_OGRE) .. "\n") f:write("#define YAKE_ENABLE_LUA_PHYSICS " .. bool_to_int(ENABLE_LUA_PHYSICS) .. "\n") f:write("#define YAKE_ENABLE_LUA_INPUT " .. bool_to_int(ENABLE_LUA_INPUT) .. "\n") f:write("#define YAKE_ENABLE_LUA_RAF " .. bool_to_int(ENABLE_LUA_RAF) .. "\n") Modified: trunk/yake/src/bindings.lua/detail/ent.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-08-29 22:58:33 UTC (rev 1829) @@ -73,6 +73,17 @@ typedef luabind::class_<Object::PropertyAccess> LuabindClass_Object_PropertyAccess; //------------------------------------------------------------------------- + typedef std::pair<Object::Event::ID,Object::Event::pointer> Object_NameEventPair; + static Object_NameEventPair* Object_EventAccess_getByIndex(Object::EventAccess& acc, int index) + { + index -= 1; // Lua arrays usually start with 1, so convert to 0-offset-array. + if (index < 0 || index > acc.size()) + return 0; + Object_NameEventPair ret = acc.__getByIndex(index); + if (ret.first.empty()) + return 0; + return new Object_NameEventPair(ret); + } static void Object_Event_fire_noparams(Object::Event& evt) { evt.fire(); @@ -264,9 +275,15 @@ //.def( "fire", &Object::Event::fire ) // with 1 param .def( "fire", &Object_Event_fire_1param ) , - class_<Object::EventAccess>("Object::PropertyAccess") + class_<Object_NameEventPair>("Object_NameEventPair") + .def_readonly( "name", &Object_NameEventPair::first) + .def_readonly( "event", &Object_NameEventPair::second) + , + class_<Object::EventAccess>("Object::EventAccess") + .property( "size", &Object::EventAccess::size ) .def( "has", &Object::EventAccess::has ) .def( "get", &Object::EventAccess::get ) + .def( "get", &Object_EventAccess_getByIndex, adopt(result) ) .def( "add", &Object::EventAccess::add ) .def( "create", &Object::EventAccess::createAndAdd ) ]; @@ -312,6 +329,12 @@ module( YAKE_MODEL_MODULE ) [ + def( "asEntity", &Entity::cast ), + def( "asTrigger", &Trigger::cast ) + ]; + + module( YAKE_MODEL_MODULE ) + [ class_<ObjectManager>( "ObjectManager" ) .def( "makeObject", (Object*(ObjectManager::*)(const String&))&ObjectManager::makeObject ) .def( "getObject", &ObjectManager::getObject ) @@ -386,30 +409,48 @@ ent->getFsmVM()->execute("print('initializing...')"); ent->getFsmVM()->execute( startScript_ ); - ent->getFsmVM()->execute("c = coroutine.create(main)\ncoroutine.resume(c,1)"); + scripting::LuaVM* vm = static_cast<scripting::LuaVM*>(ent->getFsmVM().get()); + YAKE_ASSERT( vm ); + //ent->getFsmVM()->execute("c = coroutine.create(main)\ncoroutine.resume(c,1)"); + String err; + try + { + luabind::call_function<void>(vm->getLuaState(),"main"); + } + catch (std::exception& ex) + { + err = ex.what(); + YAKE_LOG_ERROR("ent.lua",String("LuaFsmObjectListener.onInit:") + err); + } + if (!err.empty()) + YAKE_EXCEPT(err); } } void LuaFsmObjectListener::onTick(Object& obj) { +#if 0 Entity* ent = Entity::cast(&obj); if (ent) { scripting::VMPtr vm = ent->getFsmVM(); vm->execute("event.on_tick()"); - //vm->execute("state." + ent->getCurrentFsmState() + ".on_tick()"); detail::executeOfTable_2(*vm,"state",ent->getCurrentFsmState(),"on_tick"); } +#endif } void LuaFsmObjectListener::onFsmEventHandled(Object& obj, const object_fsm&, const object_fsm::event_type& evt) { +#if 0 Entity* ent = Entity::cast(&obj); if (ent) { ent->getFsmVM()->execute("event.on_" + evt + "()"); } +#endif } void LuaFsmObjectListener::onFsmEnterState(Object& obj,/*const std::string& fsmName, */const object_fsm&, const object_fsm::state_type& state) { +#if 0 Entity* ent = Entity::cast(&obj); if (ent) { @@ -417,9 +458,11 @@ YAKE_ASSERT( vm ); detail::executeOfTable_2(*vm,"state",state,"on_enter"); } +#endif } void LuaFsmObjectListener::onFsmExitState(Object& obj,/*const std::string& fsmName, */const object_fsm&, const object_fsm::state_type& state) { +#if 0 Entity* ent = Entity::cast(&obj); if (ent) { @@ -427,6 +470,7 @@ YAKE_ASSERT( vm ); detail::executeOfTable_2(*vm,"state",state,"on_exit"); } +#endif } } // namespace detail Modified: trunk/yake/src/bindings.lua/detail/graphics.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/graphics.lua.cpp 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/src/bindings.lua/detail/graphics.lua.cpp 2007-08-29 22:58:33 UTC (rev 1829) @@ -25,6 +25,8 @@ ------------------------------------------------------------------------------------ */ #include <yake/config.h> +#undef YAKE_ENABLE_LUA_GRAPHICS_OGRE +#define YAKE_ENABLE_LUA_GRAPHICS_OGRE 0 #if YAKE_ENABLE_LUA_GRAPHICS == 1 // See task.lua.cpp @@ -35,6 +37,16 @@ #include <yake/base/templates/yakeSmartAssert.h> #include <yake/base/yake.h> #include <yake/graphics/yakeGraphics.h> +#if YAKE_ENABLE_LUA_GRAPHICS_OGRE == 1 +#include <yake/plugins/graphicsOgre/yakeGraphicsSystem.h> +#include <yake/plugins/graphicsOgre/graphicsOgreNode.h> +#include <yake/plugins/graphicsOgre/graphicsOgreEntity.h> +#include <../../../dependencies/ogrenew/include/OgreNode.h> +#include <../../../dependencies/ogrenew/include/OgreSceneNode.h> +#include <../../../dependencies/ogrenew/include/OgreEntity.h> +#include <../../../dependencies/ogrenew/include/OgreSubEntity.h> +#include <../../../dependencies/ogrenew/include/OgreSceneManager.h> +#endif #include <yake/bindings.lua/detail/private.h> #include <yake/bindings.lua/common/yake.lua.any_converter.h> @@ -45,6 +57,33 @@ namespace yake { namespace graphics { +#if YAKE_ENABLE_LUA_GRAPHICS_OGRE == 1 + struct OgreSubEntityHolder + { + Ogre::SubEntity* subEntity_; + static bool isVisible(const OgreSubEntityHolder& holder) + { + return (holder.subEntity_ ? holder.subEntity_->isVisible() : false); + } + static void setVisible(const OgreSubEntityHolder& holder, const bool yes) + { + if (holder.subEntity_) + holder.subEntity_->setVisible( yes ); + } + }; + OgreSubEntityHolder OgreEntity_getSubEntity_byIndex(const Ogre::Entity& entity, unsigned int index) + { + OgreSubEntityHolder holder; + holder.subEntity_ = entity.getSubEntity(index); + return holder; + } + OgreSubEntityHolder OgreEntity_getSubEntity(const Ogre::Entity& entity, const Ogre::String& name) + { + OgreSubEntityHolder holder; + holder.subEntity_ = entity.getSubEntity(name); + return holder; + } +#endif ISceneNode* ISceneNode_getChildByName_NameOnly(ISceneNode* n, const String& name) { return (n ? n->getChildByName(name,false) : 0); @@ -142,6 +181,8 @@ .def("rotate", (void(ICamera::*)(const Quaternion&))&ICamera::rotate) .def("rotate", (void(ICamera::*)(const Vector3&,real))&ICamera::rotate) .property("aspectRatio", &ICamera::getAspectRatio, &ICamera::setAspectRatio) + .property("farClipDistance", &ICamera::getFarClipDistance, &ICamera::setFarClipDistance) + .property("nearClipDistance", &ICamera::getNearClipDistance, &ICamera::setNearClipDistance) , class_<IViewport>("Viewport") //@todo @@ -162,6 +203,50 @@ .def("pickEntity", &IWorld::pickEntity) ] ]; +#if YAKE_ENABLE_LUA_GRAPHICS_OGRE == 1 + module( YAKE_GRAPHICS_MODULE ) + [ + namespace_("ogre") + [ + class_<Ogre::SceneManager>("SceneManager") + , + class_<Ogre::Node>("Node") + , + class_<Ogre::SceneNode,Ogre::Node>("SceneNode") + .property("creator", &Ogre::SceneNode::getCreator) + .def("setVisible", &Ogre::SceneNode::setVisible) + , + class_<Ogre::MovableObject>("MovableObject") + , + class_<Ogre::Renderable>("Renderable") + , + //@todo fails due to protected d'tor: class_<Ogre::SubEntity,Ogre::Renderable>("SubEntity") + //, + class_<OgreSubEntityHolder>("OgreSubEntityHolder") + .property("visible", &OgreSubEntityHolder::isVisible, &OgreSubEntityHolder::setVisible) + , + class_<Ogre::Entity,Ogre::MovableObject>("Entity") + //.def("getSubEntity", (Ogre::SubEntity*(Ogre::Entity::*)(unsigned int)const)&Ogre::Entity::getSubEntity) + //.def("getSubEntity", (Ogre::SubEntity*(Ogre::Entity::*)(const Ogre::String& name)const)&Ogre::Entity::getSubEntity) + .def("getSubEntity", &OgreEntity_getSubEntity_byIndex) + .def("getSubEntity", &OgreEntity_getSubEntity) + ] + ]; +#endif +#if YAKE_ENABLE_LUA_GRAPHICS_OGRE == 1 + module( YAKE_GRAPHICS_MODULE ) + [ + namespace_("yake") + [ + class_<ogre3d::OgreNode,ISceneNode>("OgreNode") + .property("parent", &ogre3d::OgreNode::_getParent) + .def("asOgre", &ogre3d::OgreNode::getSceneNode_) + , + class_<ogre3d::OgreEntity,IEntity>("OgreEntity") + .def("asOgre", &ogre3d::OgreEntity::getEntity_) + ] + ]; +#endif } YAKE_WRAP_BINDER(graphics,::yake::graphics::bind); Modified: trunk/yake/src/bindings.lua/detail/res.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/res.lua.cpp 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/src/bindings.lua/detail/res.lua.cpp 2007-08-29 22:58:33 UTC (rev 1829) @@ -46,6 +46,11 @@ namespace yake { namespace res { + std::ostream& operator << (std::ostream& out, const FindResult& rhs) + { + out << "FindResult(valid=" << rhs.isValid() << ",location='" << rhs.location() << "')"; + return out; + } void bind( lua_State* L ) { @@ -85,6 +90,7 @@ .property("location",&FindResult::location) .property("source",&FindResult::source) .property("valid",&FindResult::isValid) + .def(tostring(const_self)) , class_<SourceManager>("SourceManager") .def(constructor<>()) Modified: trunk/yake/src/ent/object.cpp =================================================================== --- trunk/yake/src/ent/object.cpp 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/src/ent/object.cpp 2007-08-29 22:58:33 UTC (rev 1829) @@ -35,7 +35,22 @@ Object::Object() : propertyAcess_(*this,properties_) { properties().add("id", property::makePointerProperty<ObjectId>(&id_) ); + events().createAndAdd("spawn"); + events().createAndAdd("tick"); + events().createAndAdd("preDestroy"); } + void Object::init() + { + listeners_init(*this); + onInit(); + events().get("spawn")->fire(); + } + void Object::tick() + { + listeners_tick(*this); + onTick(); + events().get("tick")->fire(); + } void Object::setId(const ObjectId& id) { YAKE_ASSERT( id != MessageTraits::kNoSource )(MessageTraits::kNoSource)(id); @@ -75,6 +90,17 @@ } void Object::destroy() { + events().get("preDestroy")->fire(); + this->onPreDestroy(); + + /*YAKE_FOR_EACH(EventAccess::iterator,it,eventAccess_.events_) + { + EventAccess::storage evt = it->second; + evt->disconnectAll(); + }*/ + eventAccess_.events_.clear(); + properties_.clear(); + for (listenerconnetion_list::iterator it = listenerConnections_.begin(), itend = listenerConnections_.end(); it != itend; ++it) { @@ -101,6 +127,18 @@ Object::Event::Event() { } + Object::Event::~Event() + { + disconnectAll(); + } + void Object::Event::disconnectAll() + { + sig_.disconnect_all_slots(); + } + size_t Object::EventAccess::size() const + { + return events_.size(); + } bool Object::EventAccess::has(const Event::ID& id) const { return (events_.find(id) != events_.end()); @@ -110,6 +148,15 @@ EventMap::iterator it = events_.find(id); return (it == events_.end()) ? 0 : it->second.get(); } + std::pair<Object::Event::ID,Object::Event::pointer> Object::EventAccess::__getByIndex(const size_t index) + { + if (events_.empty() || index >= events_.size()) //@todo assert? + return std::pair<Object::Event::ID,Object::Event::pointer>(); + EventMap::iterator it = events_.begin(); + for (size_t i=0; i<index; ++i, ++it) + ; + return std::pair<Object::Event::ID,Object::Event::pointer>(it->first,it->second.get()); + } void Object::EventAccess::add(const Event::ID& id, Event::pointer evt) { YAKE_ASSERT( !has(id) ).debug("duplicate entry - replacing original"); Modified: trunk/yake/src/ent/object_mgr.cpp =================================================================== --- trunk/yake/src/ent/object_mgr.cpp 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/src/ent/object_mgr.cpp 2007-08-29 22:58:33 UTC (rev 1829) @@ -30,6 +30,13 @@ namespace yake { namespace ent { + ObjectManager::ObjectManager() + { + } + ObjectManager::~ObjectManager() + { + destroyAllObjects(); + } Object* ObjectManager::makeObject(const String& strClsId) { YAKE_ASSERT( !strClsId.empty() )(strClsId); @@ -69,6 +76,19 @@ return obj; } + void ObjectManager::destroyAllObjects() + { + YAKE_FOR_EACH(object_ptr_list::iterator, it, objs_) + { + Object* obj = *it; + YAKE_ASSERT( obj ); + + obj->destroy(); // <- triggers obj event 'preDestroy' + listeners_onDestroyObject( obj ); + objMgr_.destroyObject( obj ); + } + objs_.clear(); + } void ObjectManager::destroyObject(Object* obj) { YAKE_ASSERT( obj ); Modified: trunk/yake/src/ent/trigger.cpp =================================================================== --- trunk/yake/src/ent/trigger.cpp 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/src/ent/trigger.cpp 2007-08-29 22:58:33 UTC (rev 1829) @@ -36,6 +36,16 @@ { cond_ = fn; } + void Trigger::onPreDestroy() + { + // The reason we explicitely clear this condition here, is that + // the cond_ may be bound to certain objects (e.g. luabind::object) + // which need to be destroyed before (!) the object listeners are + // detached (e.g. the Lua object listener which manages the object's VMs). + // This can result in having a dangling object which tries to access resources + // (like the object's VMs) that have already been destroyed. + cond_.clear(); + } Trigger::Trigger() { this->attachListener( this, "this", ObjectListenerManager::kKeepOwnership ); Modified: trunk/yake/yake/ent/object.h =================================================================== --- trunk/yake/yake/ent/object.h 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/yake/ent/object.h 2007-08-29 22:58:33 UTC (rev 1829) @@ -81,16 +81,8 @@ { return id_; } // operations - void init() - { - listeners_init(*this); - onInit(); - } - void tick() - { - listeners_tick(*this); - onTick(); - } + void init(); + void tick(); void destroy(); void processMessage(const int&); @@ -128,8 +120,10 @@ struct YAKE_ENT_API Event : public noncopyable { friend struct EventAccess; + friend struct Object; //private: Event(); + ~Event(); public: typedef Event* pointer; typedef String ID; @@ -144,6 +138,8 @@ { this->sig_(a0); } void operator()(const param_type& a0 = param_type()) { this->fire(a0); } + + void disconnectAll(); private: EventFireSignal sig_; }; @@ -153,9 +149,17 @@ bool has(const Event::ID&) const; void add(const Event::ID&, Event::pointer); Event::pointer createAndAdd(const Event::ID&); + size_t size() const; + + /** @note Mainly intended for internal use by the Lua bindings. */ + std::pair<Event::ID,Event::pointer> __getByIndex(const size_t); + + friend struct Object; private: typedef SharedPtr<Event> storage; typedef std::map<Event::ID,storage> EventMap; + typedef EventMap::const_iterator const_iterator; + typedef EventMap::iterator iterator; EventMap events_; }; EventAccess& events(); @@ -163,6 +167,7 @@ protected: virtual void onInit() {} virtual void onTick() {} + virtual void onPreDestroy() {} private: ObjectId id_; typedef std::deque<detail::ListenerConnection> listenerconnetion_list; Modified: trunk/yake/yake/ent/object_mgr.h =================================================================== --- trunk/yake/yake/ent/object_mgr.h 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/yake/ent/object_mgr.h 2007-08-29 22:58:33 UTC (rev 1829) @@ -44,6 +44,8 @@ */ struct YAKE_ENT_API ObjectManager : public ListenerManager<ObjectManagerListener> { + ObjectManager(); + virtual ~ObjectManager(); // operations /** Creates an Object for the given clsId. @@ -62,9 +64,12 @@ */ Object* makeObject(const String& strClsId); - /** Destroys the given Object. */ + /** Destroys and removes the given Object. */ void destroyObject(Object*); + /** Do NOT call from within tick() ... */ + void destroyAllObjects(); + /** Returns the Object for the given id or ObjectId::kNull if the lookup failed. */ Object* getObject(const ObjectId objId) const; Modified: trunk/yake/yake/ent/trigger.h =================================================================== --- trunk/yake/yake/ent/trigger.h 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/yake/ent/trigger.h 2007-08-29 22:58:33 UTC (rev 1829) @@ -45,6 +45,7 @@ private: virtual void onTick(); + virtual void onPreDestroy(); private: virtual void onFsmEventHandled(Object&, const object_fsm&, const object_fsm::event_type&) {} virtual void onFsmEnterState(Object&,/*const String& fsmName, */const object_fsm&, const object_fsm::state_type& state); Modified: trunk/yake/yake/property/property_container.h =================================================================== --- trunk/yake/yake/property/property_container.h 2007-08-29 17:02:33 UTC (rev 1828) +++ trunk/yake/yake/property/property_container.h 2007-08-29 22:58:33 UTC (rev 1829) @@ -80,7 +80,8 @@ bool has(const key_type& id) const; size_t size() const { return properties_.size(); } - + void clear() + { properties_.clear(); } // private: typedef std::map<key_type,PropertyPtr> PropertyMap; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-29 17:02:37
|
Revision: 1828 http://yake.svn.sourceforge.net/yake/?rev=1828&view=rev Author: psyclonist Date: 2007-08-29 10:02:33 -0700 (Wed, 29 Aug 2007) Log Message: ----------- removed empty directory Removed Paths: ------------- trunk/yake/src/yake/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-29 17:01:48
|
Revision: 1827 http://yake.svn.sourceforge.net/yake/?rev=1827&view=rev Author: psyclonist Date: 2007-08-29 10:01:46 -0700 (Wed, 29 Aug 2007) Log Message: ----------- removed empty directory Removed Paths: ------------- trunk/yake/src/yake/ent/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-29 17:00:44
|
Revision: 1826 http://yake.svn.sourceforge.net/yake/?rev=1826&view=rev Author: psyclonist Date: 2007-08-29 10:00:46 -0700 (Wed, 29 Aug 2007) Log Message: ----------- * moved trigger.cpp to correct location Added Paths: ----------- trunk/yake/src/ent/trigger.cpp Removed Paths: ------------- trunk/yake/src/yake/ent/trigger.cpp Copied: trunk/yake/src/ent/trigger.cpp (from rev 1823, trunk/yake/src/yake/ent/trigger.cpp) =================================================================== --- trunk/yake/src/ent/trigger.cpp (rev 0) +++ trunk/yake/src/ent/trigger.cpp 2007-08-29 17:00:46 UTC (rev 1826) @@ -0,0 +1,73 @@ +/* + ------------------------------------------------------------------------------------ + This file is part of YAKE + Copyright (c) 2004 - 2008 The YAKE Team + For the latest information visit http://www.yake.org + ------------------------------------------------------------------------------------ + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA, or go to + http://www.gnu.org/copyleft/lesser.txt. + ------------------------------------------------------------------------------------ + If you are interested in another license model contact the Yake Team via + E-Mail: te...@ya.... + For more information see the LICENSE file in the root directory of the + source code distribution. + ------------------------------------------------------------------------------------ +*/ +#include "yake/ent/pch.h" +#include "yake/ent/ent.h" + +namespace yake { +namespace ent { + + IMPL_OBJECT(Trigger) + + void Trigger::setCondition(const ConditionFn& fn) + { + cond_ = fn; + } + Trigger::Trigger() + { + this->attachListener( this, "this", ObjectListenerManager::kKeepOwnership ); + + this->addFsmState("dead"); + this->addFsmState("off"); + this->addFsmState("on"); + this->addFsmTransition("dead","spawn","off"); + this->addFsmTransition("off","toggle","on"); + this->addFsmTransition("on","toggle","off"); + + this->setFsmState("dead"); + + this->events().createAndAdd("onTriggered"); + + //this->properties().add("condition",property::makePointerProperty<boost::function<bool(void)> >( &cond_ ) ); + //this->properties().add("condition",property::makePointerProperty<luabind::object>( &cond_ ) ); + } + void Trigger::onTick() + { + Entity::onTick(); + const bool condMet = cond_ ? cond_() : false; + if (condMet && getCurrentFsmState()=="off" || + !condMet && getCurrentFsmState()=="on") + { + this->processFsmEvent("toggle"); + } + } + void Trigger::onFsmEnterState(Object&,/*const String& fsmName, */const object_fsm&, const object_fsm::state_type& state) + { + this->events().get("onTriggered")->fire( (state=="on") ); + + } +} // namespace ent +} // namespace yake Deleted: trunk/yake/src/yake/ent/trigger.cpp =================================================================== --- trunk/yake/src/yake/ent/trigger.cpp 2007-08-28 23:34:11 UTC (rev 1825) +++ trunk/yake/src/yake/ent/trigger.cpp 2007-08-29 17:00:46 UTC (rev 1826) @@ -1,73 +0,0 @@ -/* - ------------------------------------------------------------------------------------ - This file is part of YAKE - Copyright (c) 2004 - 2008 The YAKE Team - For the latest information visit http://www.yake.org - ------------------------------------------------------------------------------------ - This program is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free Software - Foundation; either version 2 of the License, or (at your option) any later - version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with - this program; if not, write to the Free Software Foundation, Inc., 59 Temple - Place - Suite 330, Boston, MA 02111-1307, USA, or go to - http://www.gnu.org/copyleft/lesser.txt. - ------------------------------------------------------------------------------------ - If you are interested in another license model contact the Yake Team via - E-Mail: te...@ya.... - For more information see the LICENSE file in the root directory of the - source code distribution. - ------------------------------------------------------------------------------------ -*/ -#include "yake/ent/pch.h" -#include "yake/ent/ent.h" - -namespace yake { -namespace ent { - - IMPL_OBJECT(Trigger) - - void Trigger::setCondition(const ConditionFn& fn) - { - cond_ = fn; - } - Trigger::Trigger() - { - this->attachListener( this, "this", ObjectListenerManager::kKeepOwnership ); - - this->addFsmState("dead"); - this->addFsmState("off"); - this->addFsmState("on"); - this->addFsmTransition("dead","spawn","off"); - this->addFsmTransition("off","toggle","on"); - this->addFsmTransition("on","toggle","off"); - - this->setFsmState("dead"); - - this->events().createAndAdd("onTriggered"); - - //this->properties().add("condition",property::makePointerProperty<boost::function<bool(void)> >( &cond_ ) ); - //this->properties().add("condition",property::makePointerProperty<luabind::object>( &cond_ ) ); - } - void Trigger::onTick() - { - Entity::onTick(); - const bool condMet = cond_ ? cond_() : false; - if (condMet && getCurrentFsmState()=="off" || - !condMet && getCurrentFsmState()=="on") - { - this->processFsmEvent("toggle"); - } - } - void Trigger::onFsmEnterState(Object&,/*const String& fsmName, */const object_fsm&, const object_fsm::state_type& state) - { - this->events().get("onTriggered")->fire( (state=="on") ); - - } -} // namespace ent -} // namespace yake This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-28 23:34:23
|
Revision: 1825 http://yake.svn.sourceforge.net/yake/?rev=1825&view=rev Author: psyclonist Date: 2007-08-28 16:34:11 -0700 (Tue, 28 Aug 2007) Log Message: ----------- * [bindings.lua] improved yake.property bindings: no get() and set() accessors are necessary, anymore. Operators = and [] and . are enough. (Example: 'props.name = "jack"' instead of 'props:get("name"):set("jack")') Modified Paths: -------------- trunk/yake/common/media/samples/property/demo.lua trunk/yake/samples/property/lua1/demo.cpp trunk/yake/samples/raf/lua1/demo.cpp trunk/yake/src/bindings.lua/detail/ent.lua.cpp trunk/yake/src/bindings.lua/detail/property.lua.cpp trunk/yake/src/ent/object.cpp trunk/yake/yake/bindings.lua/detail/property.lua.h trunk/yake/yake/ent/object.h trunk/yake/yake/property/detail/property.impl.h Modified: trunk/yake/common/media/samples/property/demo.lua =================================================================== --- trunk/yake/common/media/samples/property/demo.lua 2007-08-28 17:53:02 UTC (rev 1824) +++ trunk/yake/common/media/samples/property/demo.lua 2007-08-28 23:34:11 UTC (rev 1825) @@ -55,4 +55,149 @@ assert( p:set( yake.Vector3(2,3,4) ) ); print(" value = (" .. p:get().x .. "," .. p:get().y .. "," .. p:get().z .. ")" ); +print("\n---- property access table (forwards to 'props') ----") +properties = {} +-- @param t (table) table to wrap (can be empty) +-- @param propAccess () object of type ent.Object.PropertyAccess (bindings.lua:ent) or +-- of type property.NamedPropertyContainer (bindings.lua:property). +-- @param implicitCreation (boolean) +-- @return nothing +function wrapPropertiesTable(t,propAccess,implicitCreation) + t.list = {} + t.accessor = propAccess + t.create = function(self,k,v) + local p = self.accessor:create(k,v) + assert( p ~= nil ) + + -- @todo really provide this accessor a la __newindex and rawset below??? + rawset(t.list,k,p) + + return p + end + + --@todo loop through all existing properties in propAccess and + -- create an accessor (with rawset) in t.list for each key. + -- same as in t.create() or __newindex(). + --print(type(propAccess.size)) + --print(propAccess.size) + for k = 1, propAccess.size do + local p = propAccess:get(k) + assert( p ~= nil ) + --print("exist:",p.name) + rawset(t.list,p.name,p) + end + + -- + if implicitCreation == nil then + --print("defaulting") + implicitCreation = true + end + assert( type(implicitCreation) == "boolean" ) + --print(implicitCreation) + + setmetatable(t, { + __index = function(t,k) + assert( t.accessor ~= nil ) + --print("INDEX",t,k) + if type(k) ~= "string" then + print("properties __index -> ERROR: key is not of type 'string' but of type '"..type(k).."'!") + return nil + end + local p = t.accessor:get(k) + if p then + return p:get() + end + return nil + end, + __newindex = function(t,k,v) + --print("NEWINDEX",t,"'"..tostring(k).."' ->",type(k),"value=",v) + + if type(k) ~= "string" then + --print("-> ERROR: key is not a string!") + return nil + end + local exists = t.accessor:get(k) + if exists then + --print("=> EXISTS") + exists:set(v) + return true + end + print(implicitCreation) + if implicitCreation then + local p = t.accessor:create(k,v) + assert( p ~= nil ) + + -- @todo really provide an accessor??? + rawset(t.list,k,p) + + return true + else + return false + end + end + }) +end + +local bool demo_uses_implicit_creation = true -- set to true/false to test the different policies + +-- setup properties table +wrapPropertiesTable(properties,props,demo_uses_implicit_creation) + +-- +print("> properties[\"sayHello\"]()") +properties["sayHello"]() + +print("> properties.sayHello()") +properties.sayHello() + +print("> print(properties[\"name\"])") +print(properties["name"]) +assert( properties["name"] == "waikiki" ) + +print("> print(properties.name)") +print(properties.name) +assert( properties.name == "waikiki" ) + +if not demo_uses_implicit_creation then + properties:create("s",1) +end + +print("> properties.s = 1") +properties.s = 1 +assert( properties.s == 1 ) + +print("> properties[42] = 1 => fails expectedly as key is not a string.") +properties[42] = 1 +assert( properties[42] == nil ) + +if not demo_uses_implicit_creation then + properties:create("42",1) +end + +print("> properties[\"42\"] = 14 => ok") +properties["42"] = 14 +assert( properties["42"] == 14 ) + +print("> properties[\"s\"] = 2") +properties["s"] = 2 +assert( properties["s"] == 2 ) + +print("> print(properties.s)") +print(properties.s) + +print("> properties[\"s\"] = 3") +properties["s"] = 3 +assert( properties["s"] == 3 ) + +--print("properties.list.n",#properties.list) +--for k,v in pairs(properties.list) do +-- print("PL",k) +--end +--for k,v in ipairs(properties) do +-- print("P",k) +--end +--for i = 1,3 do +-- print("I",properties[i]) +--end + print("\nAll tests done."); \ No newline at end of file Modified: trunk/yake/samples/property/lua1/demo.cpp =================================================================== --- trunk/yake/samples/property/lua1/demo.cpp 2007-08-28 17:53:02 UTC (rev 1824) +++ trunk/yake/samples/property/lua1/demo.cpp 2007-08-28 23:34:11 UTC (rev 1825) @@ -1,11 +1,23 @@ #include <yake/plugins/scriptingLua/ScriptingSystemLua.h> #include <yake/bindings.lua/bindings.lua.h> +#include "yake/res/res.h" +#include "yake/base/yakeLog.h" +#include "yake/base/yakeStderrLog.h" void main() { using namespace yake; try { + // create and attach log listeners + typedef SharedPtr<logging::log_listener> log_listener_ptr; + log_listener_ptr toStdErr( new yake::logging::stderr_listener() ); + logging::addListener( toStdErr.get() ); + + // Setup resources + res::SourceFactory::global().reg<res::FileSource>("file"); + res::SourceManager::global().addSource("file","../../common/media/samples/"); + // init scripting VM typedef scripting::ScriptingSystemLua scripting_t; scripting_t scriptingSys; @@ -20,7 +32,7 @@ YAKE_ASSERT( vm ); // run Lua script - scripting::ScriptPtr demoScript( scriptingSys.createScriptFromFile("../../../common/media/samples/property/demo.lua") ); + scripting::ScriptPtr demoScript( scriptingSys.createScriptFromFile("property/demo.lua") ); vm->execute( demoScript ); // clean up Modified: trunk/yake/samples/raf/lua1/demo.cpp =================================================================== --- trunk/yake/samples/raf/lua1/demo.cpp 2007-08-28 17:53:02 UTC (rev 1824) +++ trunk/yake/samples/raf/lua1/demo.cpp 2007-08-28 23:34:11 UTC (rev 1825) @@ -11,24 +11,6 @@ using namespace yake; -/** Configuration of the application */ -struct TheConfiguration : public raf::ApplicationConfiguration -{ - // Use "inputOgre" for Ogre 1.2/1.3, "inputOgreOIS" for Ogre 1.4+. - virtual StringVector getLibraries() - { return MakeStringVector() << YAKE_LIB("scriptingLua") << YAKE_LIB("graphicsOgre") << YAKE_LIB("inputOgreOIS"); } - - // Use "ogre" for Ogre 1.2/1.3, "ois" for Ogre 1.4+. - virtual StringVector getInputSystems() - { return MakeStringVector() << "ois"; } - - virtual StringVector getScriptingSystems() - { return MakeStringVector() << "lua"; } - - virtual StringVector getGraphicsSystems() - { return MakeStringVector() << "ogre3d"; } -}; - /** Main application state */ class TheMainState : public raf::RtMainState { @@ -87,7 +69,13 @@ actionMap_.update(); //@todo here OK? ... lua_State* L = static_cast<scripting::LuaVM*>(vm_.get())->getLuaState(); - luabind::call_function<void>( L, "onFrame", timeElapsed ); + try { + luabind::call_function<void>( L, "onFrame", timeElapsed ); + } catch (std::exception& ex) + { + YAKE_LOG_ERROR("demo",ex.what()); + requestQuit(); + } } private: raf::Application& app_; @@ -96,10 +84,13 @@ }; /** The mighty application itself! */ -class TheApp : public raf::ExampleApplication<TheConfiguration> +class TheApp : public raf::ExampleApplication<> { public: - TheApp() {} + TheApp() + { + getConfiguration().get().load("sampleRafLua1.cfg"); + } protected: virtual raf::MainState* createMainState() { @@ -110,7 +101,7 @@ int main( int argc, char** argv ) { // Use default executor for convenience. - // It's always possible to manually execute TheApp::initialise() etc. + // It's always possible to manually execute TheApp::initialise() etc. TheApp app; return (raf::runApplication( app )) ? 0 : 1; } Modified: trunk/yake/src/bindings.lua/detail/ent.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-08-28 17:53:02 UTC (rev 1824) +++ trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-08-28 23:34:11 UTC (rev 1825) @@ -39,6 +39,7 @@ #include <luabind/iterator_policy.hpp> #include <luabind/operator.hpp> +#include <luabind/adopt_policy.hpp> namespace yake { namespace ent { @@ -99,10 +100,32 @@ Object::PropertyAccess& x = o.properties(); return &x; } - static property::PropertyBase* Object_PropertyAccess_get(Object::PropertyAccess& o, const char* id) + static property::PropertyBase* Object_PropertyAccess_get(Object::PropertyAccess& o, const std::string& id) { return o.get( id ).get(); } + static property::NamePropertyPair* Object_PropertyAccess_get_byIndex(Object::PropertyAccess& o, int index) + { + index -= 1; // Lua tables usually start with 1 + if (index >= o.size() || index < 0) + return 0; + YAKE_ASSERT( o.owner().__properties() ).debug("invalid internal state"); + const NamedProperties& props = *o.owner().__properties(); + if (props.size() == 0) + return 0; + NamedProperties::const_iterator it = props.begin(); + for (size_t i=0;i<size_t(index);++i,++it) + { + if (it == props.end()) + return 0; + } + if (it == props.end()) + return 0; + property::NamePropertyPair* ret = new property::NamePropertyPair(); + ret->name = it->first; + ret->prop = it->second.get(); + return ret; + } static Object::EventAccess* getObjectEvents(Object& o) { Object::EventAccess& x = o.events(); @@ -213,7 +236,9 @@ LuabindClass_Object_PropertyAccess x_Object_PropertyAccess("Object::PropertyAccess"); x_Object_PropertyAccess + .property( "size", &Object::PropertyAccess::size ) .def( "get", &Object_PropertyAccess_get ) + .def( "get", &Object_PropertyAccess_get_byIndex, adopt(result) ) .def( "has", &Object::PropertyAccess::has ) // For native Lua types which can simply mapped to C++: @@ -349,7 +374,7 @@ LuaFsmObjectListener::LuaFsmObjectListener(scripting::IScriptingSystem& scriptingSystem) : scriptingSystem_(scriptingSystem) { - startScript_ = scriptingSystem_.createScriptFromFile("o_fsm_test.lua"); + startScript_ = scriptingSystem_.createScriptFromFile("o_access.lua"); YAKE_ASSERT( startScript_.get() ); } void LuaFsmObjectListener::onInit(Object& obj) Modified: trunk/yake/src/bindings.lua/detail/property.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-08-28 17:53:02 UTC (rev 1824) +++ trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-08-28 23:34:11 UTC (rev 1825) @@ -39,6 +39,8 @@ #include <yake/bindings.lua/detail/private.h> #include <yake/bindings.lua/detail/property.lua.h> +#include <luabind/adopt_policy.hpp> + namespace yake { namespace property { PropertyFromAnyMap& any_property_creators() @@ -125,6 +127,25 @@ PropertyPtr prop = ctr.getPtr(name); return prop.get(); } + NamePropertyPair* getPropertyByIndex(NamedPropertyContainer& ctr, int index) + { + index -= 1; // Lua tables usually start with 1 + if (index < 0 || index >= ctr.size() || ctr.size() == 0) + return 0; + NamedPropertyContainer::const_iterator it = ctr.begin(); + for (size_t i=0; i<index; ++i, ++it) + { + if (it == ctr.end()) + return 0; + } + if (it == ctr.end()) + return 0; + + NamePropertyPair* ret = new NamePropertyPair(); + ret->name = it->first; + ret->prop = it->second.get(); + return ret; + } bool setPropertyValue(PropertyBase& prop, const boost::any& value) { try { @@ -173,6 +194,10 @@ // module( YAKE_MODEL_MODULE ) [ + class_<NamePropertyPair>("NamePropertyPair") + .def_readonly("name", &NamePropertyPair::name) + .def_readonly("property", &NamePropertyPair::prop) + , class_<NamedPropertyContainer>( "NamedPropertyContainer" ) .def( constructor<>() ) //.def( "add", (void(NamedPropertyContainer::*)(const String&,PropertyPtr))&NamedPropertyContainer::add ) @@ -180,7 +205,10 @@ //.def( "get", (PropertyBase&(NamedPropertyContainer::*)(const String&))&NamedPropertyContainer::get ) //.def( "get", (PropertyPtr(NamedPropertyContainer::*)(const String&)const)&NamedPropertyContainer::getPtr ) .def( "get", &getProperty ) + .def( "get", &getPropertyByIndex, adopt(result) ) + .property("size", &NamedPropertyContainer::size) + // For native Lua types which can simply mapped to C++: .def( "create", (PropertyBase*(*)(NamedPropertyContainer&,const char*,const boost::any&))&createAndAddPropertyFromAny ) // For all other 'custom' registered and unknown types: Modified: trunk/yake/src/ent/object.cpp =================================================================== --- trunk/yake/src/ent/object.cpp 2007-08-28 17:53:02 UTC (rev 1824) +++ trunk/yake/src/ent/object.cpp 2007-08-28 23:34:11 UTC (rev 1825) @@ -32,7 +32,7 @@ IMPL_OBJECT(Object) - Object::Object() : propertyAcess_(properties_) + Object::Object() : propertyAcess_(*this,properties_) { properties().add("id", property::makePointerProperty<ObjectId>(&id_) ); } @@ -124,7 +124,8 @@ events_[ id ] = evt; return evt.get(); } - Object::PropertyAccess::PropertyAccess(NamedProperties& props) : properties_(props) + Object::PropertyAccess::PropertyAccess(Object& owner,NamedProperties& props) : + owner_(owner), properties_(props) { } PropertyPtr Object::PropertyAccess::get(const PropertyId& id) const @@ -143,6 +144,14 @@ { properties_.add( id, prop ); } + Object& Object::PropertyAccess::owner() + { + return owner_; + } + const Object& Object::PropertyAccess::owner() const + { + return owner_; + } } } Modified: trunk/yake/yake/bindings.lua/detail/property.lua.h =================================================================== --- trunk/yake/yake/bindings.lua/detail/property.lua.h 2007-08-28 17:53:02 UTC (rev 1824) +++ trunk/yake/yake/bindings.lua/detail/property.lua.h 2007-08-28 23:34:11 UTC (rev 1825) @@ -44,6 +44,11 @@ PropertyBase* createAndAddPropertyFromAny(NamedPropertyContainer& ctr, const char* name, const boost::any& o); PropertyBase* getProperty(NamedPropertyContainer& ctr, const char* name); bool setPropertyValue(PropertyBase& prop, const boost::any& value); + struct NamePropertyPair + { + std::string name; + property::PropertyBase* prop; + }; } // namespace property } // namespace yake Modified: trunk/yake/yake/ent/object.h =================================================================== --- trunk/yake/yake/ent/object.h 2007-08-28 17:53:02 UTC (rev 1824) +++ trunk/yake/yake/ent/object.h 2007-08-28 23:34:11 UTC (rev 1825) @@ -104,8 +104,9 @@ friend struct LuaBinder; friend struct Object; private: - PropertyAccess(NamedProperties&); + PropertyAccess(Object&,NamedProperties&); NamedProperties& properties_; + Object& owner_; public: PropertyPtr get(const PropertyId&) const; bool has(const PropertyId&) const; @@ -113,6 +114,8 @@ void add(const PropertyId&, PropertyPtr); // <- may throw on error! size_t size() const { return properties_.size(); } + Object& owner(); + const Object& owner() const; }; PropertyAccess& properties(); const PropertyAccess& properties() const; Modified: trunk/yake/yake/property/detail/property.impl.h =================================================================== --- trunk/yake/yake/property/detail/property.impl.h 2007-08-28 17:53:02 UTC (rev 1824) +++ trunk/yake/yake/property/detail/property.impl.h 2007-08-28 23:34:11 UTC (rev 1825) @@ -26,7 +26,7 @@ */ #ifndef YAKE_PROPERTY_IMPL_H #define YAKE_PROPERTY_IMPL_H - + #include <yake/base/type_info.h> #include "../prerequisites.h" #include "../accessors.h" @@ -44,9 +44,9 @@ /** */ struct PropertyBase : public boost::noncopyable { - PropertyBase( const String& type, - const std::type_info* typeInfo) : - typeName_(type), + PropertyBase( const String& type, + const std::type_info* typeInfo) : + typeName_(type), typeInfo_(typeInfo) { } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-28 17:53:02
|
Revision: 1824 http://yake.svn.sourceforge.net/yake/?rev=1824&view=rev Author: psyclonist Date: 2007-08-28 10:53:02 -0700 (Tue, 28 Aug 2007) Log Message: ----------- * intermediate work for new property access and improved entity scripting * src\bindings.lua\detail\property.lua.cpp needs more work! especially, the BindPropertySetFnList is disabled, at the moment. Modified Paths: -------------- trunk/yake/src/bindings.lua/detail/ent.lua.cpp trunk/yake/src/bindings.lua/detail/property.lua.cpp Added Paths: ----------- trunk/yake/common/media/scripts/o_access.lua Added: trunk/yake/common/media/scripts/o_access.lua =================================================================== --- trunk/yake/common/media/scripts/o_access.lua (rev 0) +++ trunk/yake/common/media/scripts/o_access.lua 2007-08-28 17:53:02 UTC (rev 1824) @@ -0,0 +1,133 @@ +print("> Starting object script..."); +function startup() + --this:fsm("main"):connectTo("alive",fn) -- connects to 'enter', 'tick', 'exit' + --this:fsm("main"):connectToEnter("dead",fn) -- connects to 'enter' only + --this:fsm("main"):connect("alive", fnEnter, fnTick, fnExit) + + this:events("spawn"):connect( + function() + + end + ) +end +properties = {} +properties_mt = {} + +properties_mt.__index = function(t,k) + print("INDEX",t,k) + --for u,v in pairs(t) do print(u,v) end + --return events[k] + return this:properties():get(k):get() +end +properties_mt.__newindex = function(t,k,v) + print("NEWINDEX",t,"'"..tostring(k).."'",v) + --rawset(t,k,v) + --for u,v in pairs(t) do print(u,v) end + local exists = this:properties():get(k) + if exists then + print("EXISTS") + exists:set(v) + return true + end + this:properties():create(k,v) + return true +end + +setmetatable(properties, properties_mt) + +properties.s = 1 +properties["s"] = 2 +print(properties["s"]) + +event = { + on_spawn = function() + print(" script event.on_spawn") + this:properties():create("ticks",0) + end, + on_tick = function() + print(" script event.on_tick") + end, + on_die = function() + print(" script event.on_die") + end, + -- various: + onArrived = function() --triggered as a result of "go to" + end, + -- Trigger + on_toggle = function() + print("event.on_toggle") + end +} +fsm = { + main = { + states = { + awakening, + alive, + dead + }, + transitions = { + {awakening,"spawn",alive}, + {alive,"die",dead} + } + } +} +state = { + off = { + on_enter = function() + print("state.off.enter()") + + this:setCondition(function() return (this:property("ticks"):get() >= 1 and this:property("ticks"):get() <= 3) end) + this:events():get("onTriggered"):connect( function(a) print("TRIGGER:onTriggered:",a) end ) + end, + on_tick = function() + local ticks = this:property("ticks") + if ticks then + ticks:set( ticks:get() + 1 ) + end + print("state.off.tick()") --,ticks:get() + -- + --if (state.off.ticks == 1) then + -- this:processFsmEvent("trigger") + --end + -- + --this:events():get("onTriggered"):fire(42) + end, + on_exit = function() + print("state.off.exit()") + end + } + , + on = { + on_enter = function() + print("state.on.enter()") + end, + on_tick = function() + local ticks = this:property("ticks") + if ticks then + ticks:set( ticks:get() + 1 ) + end + print("state.on.tick()") --,ticks:get() + end, + on_exit = function() + print("state.on.exit()") + end + } + , + dead = { + on_enter = function() + print(" script state.dead.on_enter") + end, + on_tick = function() + print(" script state.dead.on_tick") + end, + on_exit = function() + print(" script state.dead.on_exit") + end + } +} +print("> Object script up."); + +function main() + print("main()") +end + Modified: trunk/yake/src/bindings.lua/detail/ent.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-08-27 17:13:37 UTC (rev 1823) +++ trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-08-28 17:53:02 UTC (rev 1824) @@ -175,6 +175,10 @@ return 0; } } + static property::PropertyBase* createAndAddPropertyFromNumber(Object::PropertyAccess& access, const char* name, int number) + { + return createAndAddPropertyFromAny(access,name,boost::any(number)); + } }; //------------------------------------------------------------------------- void bind( lua_State* L ) @@ -216,6 +220,7 @@ .def( "create", (property::PropertyBase*(*)(Object::PropertyAccess&,const char*,const boost::any&))&LuaBinder::createAndAddPropertyFromAny ) // For all other 'custom' registered and unknown types: .def( "create", (property::PropertyBase*(*)(Object::PropertyAccess&,const char*,luabind::object))&LuaBinder::createAndAddProperty ) + //.def( "create", &LuaBinder::createAndAddPropertyFromNumber) ; module( YAKE_MODEL_MODULE ) [ x_Object_PropertyAccess ]; Modified: trunk/yake/src/bindings.lua/detail/property.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-08-27 17:13:37 UTC (rev 1823) +++ trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-08-28 17:53:02 UTC (rev 1824) @@ -156,15 +156,17 @@ LuabindClass_PropertyBase x( "PropertyBase" ); x .def( "type", &PropertyBase::type ) - //.def( "set", &setPropertyValue ) // for boost::any + .def( "set", &setPropertyValue ) // for boost::any .def( "get", (boost::any(PropertyBase::*)()const)&PropertyBase::getAny ) ; // register additional 'set' overloads: + /* for (BindSetPropertyFnList::const_iterator it = setPropertyValue_binders().begin(); it != setPropertyValue_binders().end(); ++it) { (*it)(x); } + */ // module( YAKE_MODEL_MODULE )[ x ] ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-27 17:13:48
|
Revision: 1823 http://yake.svn.sourceforge.net/yake/?rev=1823&view=rev Author: psyclonist Date: 2007-08-27 10:13:37 -0700 (Mon, 27 Aug 2007) Log Message: ----------- * [ent/bindings.lua] added Trigger Modified Paths: -------------- trunk/yake/samples/ent/sampleEntFsm/demo.cpp trunk/yake/scripts/premake/samples.lua trunk/yake/src/bindings.lua/detail/ent.lua.cpp trunk/yake/src/ent/entity.cpp trunk/yake/yake/ent/ent.h trunk/yake/yake/ent/object.h trunk/yake/yake/plugins/scriptingLua/ScriptingSystemLua.h Added Paths: ----------- trunk/yake/common/media/scripts/o_trigger.lua trunk/yake/src/yake/ trunk/yake/src/yake/ent/ trunk/yake/src/yake/ent/trigger.cpp trunk/yake/yake/ent/trigger.h Added: trunk/yake/common/media/scripts/o_trigger.lua =================================================================== --- trunk/yake/common/media/scripts/o_trigger.lua (rev 0) +++ trunk/yake/common/media/scripts/o_trigger.lua 2007-08-27 17:13:37 UTC (rev 1823) @@ -0,0 +1,99 @@ +print("> Starting object script..."); +function startup() + --this:fsm("main"):connectTo("alive",fn) -- connects to 'enter', 'tick', 'exit' + --this:fsm("main"):connectToEnter("dead",fn) -- connects to 'enter' only + --this:fsm("main"):connect("alive", fnEnter, fnTick, fnExit) + + this:events("spawn"):connect( + function() + + end + ) +end +event = { + on_spawn = function() + print(" script event.on_spawn") + end, + on_tick = function() + print(" script event.on_tick") + end, + on_die = function() + print(" script event.on_die") + end, + -- various: + onArrived = function() --triggered as a result of "go to" + end, + -- Trigger + on_toggle = function(a) + print("event.on_toggle") + end +} +fsm = { + main = { + states = { + awakening, + alive, + dead + }, + transitions = { + {awakening,"spawn",alive}, + {alive,"die",dead} + } + } +} +state = { + ticks = 0, + off = { + on_enter = function() + print("state.off.enter()") + + this:setCondition(function() return (state.ticks >= 1 and state.ticks <= 3) end) + this:events():get("onTriggered"):connect( function(a) print("TRIGGER:onTriggered:",a) end ) + end, + on_tick = function() + state.ticks = state.ticks + 1 + print("TRIGGER off.tick()",state.ticks) + -- + --if (state.off.ticks == 1) then + -- this:processFsmEvent("trigger") + --end + -- + end, + on_exit = function() + print("state.off.exit()") + end + } + , + on = { + on_enter = function() + print("state.on.enter()") + --this:processFsmEvent("trigger") + --this:events():get("onTriggered"):fire() + end, + on_tick = function() + state.ticks = state.ticks + 1 + print("TRIGGER on.tick()",state.ticks) + end, + on_exit = function() + print("state.on.exit()") + end + } + , + dead = { + on_enter = function() + print(" script state.dead.on_enter") + end, + on_tick = function() + print(" script state.dead.on_tick") + end, + on_exit = function() + print(" script state.dead.on_exit") + end + } +} +print("> Object script up."); + +function main() + print("main()") +end + Modified: trunk/yake/samples/ent/sampleEntFsm/demo.cpp =================================================================== --- trunk/yake/samples/ent/sampleEntFsm/demo.cpp 2007-08-27 13:45:58 UTC (rev 1822) +++ trunk/yake/samples/ent/sampleEntFsm/demo.cpp 2007-08-27 17:13:37 UTC (rev 1823) @@ -2,11 +2,13 @@ #include "yake/base/yake.h" #include "yake/ent/ent.h" #include "yake/scripting/scripting.h" +#include "yake/bindings.lua/common/yake.lua.common.h" +#include "yake/plugins/scriptingLua/ScriptingSystemLua.h" #include "yake/bindings.lua/bindings.lua.h" #include "yake/bindings.lua/bindings.lua.ent.h" +#include "yake/res/res.h" using namespace yake; - namespace exapp { // Commonly used states for this application's objects. const std::string ksAwakening = "awakening"; @@ -31,6 +33,11 @@ ent::Entity* ent = ent::Entity::cast(obj); YAKE_ASSERT( ent ); ent->attachVM(vm,"main"); + + if (ent::Trigger::cast(ent)) + luabind::globals( static_cast<scripting::LuaVM*>(vm.get())->getLuaState() )["this"] = ent::Trigger::cast(ent); + else + luabind::globals( static_cast<scripting::LuaVM*>(vm.get())->getLuaState() )["this"] = ent; } virtual void onDestroyObject(ent::Object* obj) { @@ -46,18 +53,7 @@ ent::Entity* ent = ent::Entity::cast(obj); YAKE_ASSERT( ent ); - // Add default FSM states and transitions: - - ent->addFsmState(ksAwakening); - ent->addFsmState(ksAlive); - ent->addFsmState(ksDead); - - ent->addFsmTransition(ksAwakening,"spawn",ksAlive); - ent->addFsmTransition(ksAlive,"die",ksDead); - - // Set initial state: - - ent->setFsmState(ksAwakening); + ent->processFsmEvent("spawn"); } private: scripting::IScriptingSystem& scriptingSys_; @@ -69,6 +65,7 @@ }; IMPL_CO_1(SimpleGraphicsCo,"Component") } // namespace exapp + #ifdef OOSTATE struct oostate { @@ -181,12 +178,19 @@ machine.processEvent("go"); } #endif -#include "yake/bindings.lua/common/yake.lua.common.h" -#include "yake/plugins/scriptingLua/ScriptingSystemLua.h" int main(int argc, char* argv[]) { try { + // create and attach log listeners + typedef SharedPtr<logging::log_listener> log_listener_ptr; + log_listener_ptr toStdErr( new yake::logging::stderr_listener() ); + logging::addListener( toStdErr.get() ); + + // Setup resources + res::SourceFactory::global().reg<res::FileSource>("file"); + res::SourceManager::global().addSource("file","../../common/media/scripts/"); + // Create the scripting system we want to use (Lua). SharedPtr<scripting::IScriptingSystem> luaSys = templates::create<scripting::IScriptingSystem>("lua"); YAKE_ASSERT( luaSys.get() ); @@ -203,33 +207,59 @@ SharedPtr<exapp::ExampleAppObjectMgrListener> exappObjInitializer( new exapp::ExampleAppObjectMgrListener(*luaSys) ); objMgr.attachListener( exappObjInitializer.get(), "exapp_listener", ent::ObjectManager::kKeepOwnership ); - // Register object class + // Register object class(es) ent::RegistrationResult ret = objMgr.registerClass<ent::Entity>("Entity"); YAKE_ASSERT( ret.first == object::RC_OK ); + ret = objMgr.registerClass<ent::Trigger>("Trigger"); + YAKE_ASSERT( ret.first == object::RC_OK ); + + // Create trigger + { + ent::Trigger* trigger = ent::Trigger::cast(objMgr.makeObject("Trigger")); + YAKE_ASSERT( trigger ); + } + + for (size_t i=0; i<10; ++i) + objMgr.tick(); + // Let's create an object. - //ent::Object* o = objMgr.makeObject(ret.second); // create by ClassId - ent::Object* o = objMgr.makeObject("Entity"); // create by class name - YAKE_ASSERT( o ); - ent::Entity* e = ent::Entity::cast(o); // cast to Entity* - YAKE_ASSERT( e ); - e->properties().add("location",property::makeValueProperty<String>("")); + if (false) + { + //ent::Object* o = objMgr.makeObject(ret.second); // create by ClassId + ent::Object* o = objMgr.makeObject("Entity"); // create by class name + YAKE_ASSERT( o ); + ent::Entity* e = ent::Entity::cast(o); // cast to Entity* + YAKE_ASSERT( e ); + e->properties().add("location",property::makeValueProperty<String>("")); - luabind::globals( static_cast<scripting::LuaVM*>(e->getFsmVM().get())->getLuaState() )["this"] = e; + // Add default FSM states and transitions: - // NB At this point the FSM has been set up by the exapp listener! - // Also the scripting VM has been initialized and is ready for use. + e->addFsmState(exapp::ksAwakening); + e->addFsmState(exapp::ksAlive); + e->addFsmState(exapp::ksDead); - // Do some message/event processing - objMgr.makeAndPostMessage( o, int(1) ); // to specific target - objMgr.makeAndBroadcastMessage( int(2) ); // to all objects + e->addFsmTransition(exapp::ksAwakening,"spawn",exapp::ksAlive); + e->addFsmTransition(exapp::ksAlive,"die",exapp::ksDead); - // Do some FSM event processing: - e->processFsmEvent("spawn"); - objMgr.tick(); // triggers o->tick(), also triggers message handling! - objMgr.tick(); - e->processFsmEvent("die"); + // Set initial state: + e->setFsmState(exapp::ksAwakening); + + // NB At this point the FSM has been set up by the exapp listener! + // Also the scripting VM has been initialized and is ready for use. + + // Do some message/event processing + objMgr.makeAndPostMessage( o, int(1) ); // to specific target + objMgr.makeAndBroadcastMessage( int(2) ); // to all objects + + // Do some FSM event processing: + e->processFsmEvent("spawn"); + objMgr.tick(); // triggers o->tick(), also triggers message handling! + objMgr.tick(); + e->processFsmEvent("die"); + } + //@todo use scheduler for yield/resume functionality. (code in prototype is in fsm2_lua.cpp) //e->getVM().resume(); Modified: trunk/yake/scripts/premake/samples.lua =================================================================== --- trunk/yake/scripts/premake/samples.lua 2007-08-27 13:45:58 UTC (rev 1822) +++ trunk/yake/scripts/premake/samples.lua 2007-08-27 17:13:37 UTC (rev 1823) @@ -47,6 +47,8 @@ useComponent("scripting") useComponent("ent") useComponent("bindings.lua") + useDep("lua") + useDep("luabind") end -------------------------------------- Modified: trunk/yake/src/bindings.lua/detail/ent.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-08-27 13:45:58 UTC (rev 1822) +++ trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-08-27 17:13:37 UTC (rev 1823) @@ -108,6 +108,38 @@ Object::EventAccess& x = o.events(); return &x; } + struct TriggerConditionWrapper + { + luabind::object fn_; + typedef boost::shared_ptr<TriggerConditionWrapper> pointer; + bool execute() + { + try { + return luabind::call_function<bool>(fn_); + } + catch (luabind::cast_failed& ex) + { + YAKE_LOG_ERROR("ent.lua",String("TriggerConditionWrapper: cast_failed: ") + ex.what()); + return false; + } + } + }; + static void Trigger_setCondition(Trigger& trigger, luabind::object o) + { + if (!o || luabind::type(o) != LUA_TFUNCTION) + return; + TriggerConditionWrapper::pointer p( new TriggerConditionWrapper() ); + p->fn_ = o; + trigger.setCondition( boost::bind(&TriggerConditionWrapper::execute,p) ); + } + static bool Trigger_isOn(const Trigger& trigger) + { + return (trigger.getCurrentFsmState() == "on"); + } + static bool Trigger_isOff(const Trigger& trigger) + { + return (trigger.getCurrentFsmState() == "off"); + } //------------------------------------------------------------------------- // Helper struct so that we gain access to the private member // "properties_" in Object::PropertyAccess: @@ -242,6 +274,14 @@ module( YAKE_MODEL_MODULE ) [ + class_<Trigger,Entity>( "Trigger" ) + .def( "setCondition", &Trigger_setCondition) + .property( "on", &Trigger_isOn) + .property( "off", &Trigger_isOff) + ]; + + module( YAKE_MODEL_MODULE ) + [ class_<ObjectManager>( "ObjectManager" ) .def( "makeObject", (Object*(ObjectManager::*)(const String&))&ObjectManager::makeObject ) .def( "getObject", &ObjectManager::getObject ) @@ -280,6 +320,8 @@ YAKE_ASSERT( luabind::type(tbl2) == LUA_TTABLE ); luabind::object fnObj = tbl2[fn.c_str()]; + if (luabind::type(fnObj) == LUA_TNIL) + return; YAKE_ASSERT( luabind::type(fnObj) == LUA_TFUNCTION ); fnObj(); @@ -302,7 +344,7 @@ LuaFsmObjectListener::LuaFsmObjectListener(scripting::IScriptingSystem& scriptingSystem) : scriptingSystem_(scriptingSystem) { - startScript_ = scriptingSystem_.createScriptFromFile("../../common/media/scripts/o_fsm_test.lua"); + startScript_ = scriptingSystem_.createScriptFromFile("o_fsm_test.lua"); YAKE_ASSERT( startScript_.get() ); } void LuaFsmObjectListener::onInit(Object& obj) @@ -322,8 +364,10 @@ Entity* ent = Entity::cast(&obj); if (ent) { - ent->getFsmVM()->execute("event.on_tick()"); - ent->getFsmVM()->execute("state." + ent->getCurrentFsmState() + ".on_tick()"); + scripting::VMPtr vm = ent->getFsmVM(); + vm->execute("event.on_tick()"); + //vm->execute("state." + ent->getCurrentFsmState() + ".on_tick()"); + detail::executeOfTable_2(*vm,"state",ent->getCurrentFsmState(),"on_tick"); } } void LuaFsmObjectListener::onFsmEventHandled(Object& obj, const object_fsm&, const object_fsm::event_type& evt) Modified: trunk/yake/src/ent/entity.cpp =================================================================== --- trunk/yake/src/ent/entity.cpp 2007-08-27 13:45:58 UTC (rev 1822) +++ trunk/yake/src/ent/entity.cpp 2007-08-27 17:13:37 UTC (rev 1823) @@ -60,7 +60,9 @@ } void Entity::setFsmState(const fsm_state_type& state) { + //@todo exit previous state? m_.setState(state); + //onEnter(m_,state); } void Entity::onEnter(const object_fsm& fsm, const object_fsm::state_type& state) { Added: trunk/yake/src/yake/ent/trigger.cpp =================================================================== --- trunk/yake/src/yake/ent/trigger.cpp (rev 0) +++ trunk/yake/src/yake/ent/trigger.cpp 2007-08-27 17:13:37 UTC (rev 1823) @@ -0,0 +1,73 @@ +/* + ------------------------------------------------------------------------------------ + This file is part of YAKE + Copyright (c) 2004 - 2008 The YAKE Team + For the latest information visit http://www.yake.org + ------------------------------------------------------------------------------------ + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA, or go to + http://www.gnu.org/copyleft/lesser.txt. + ------------------------------------------------------------------------------------ + If you are interested in another license model contact the Yake Team via + E-Mail: te...@ya.... + For more information see the LICENSE file in the root directory of the + source code distribution. + ------------------------------------------------------------------------------------ +*/ +#include "yake/ent/pch.h" +#include "yake/ent/ent.h" + +namespace yake { +namespace ent { + + IMPL_OBJECT(Trigger) + + void Trigger::setCondition(const ConditionFn& fn) + { + cond_ = fn; + } + Trigger::Trigger() + { + this->attachListener( this, "this", ObjectListenerManager::kKeepOwnership ); + + this->addFsmState("dead"); + this->addFsmState("off"); + this->addFsmState("on"); + this->addFsmTransition("dead","spawn","off"); + this->addFsmTransition("off","toggle","on"); + this->addFsmTransition("on","toggle","off"); + + this->setFsmState("dead"); + + this->events().createAndAdd("onTriggered"); + + //this->properties().add("condition",property::makePointerProperty<boost::function<bool(void)> >( &cond_ ) ); + //this->properties().add("condition",property::makePointerProperty<luabind::object>( &cond_ ) ); + } + void Trigger::onTick() + { + Entity::onTick(); + const bool condMet = cond_ ? cond_() : false; + if (condMet && getCurrentFsmState()=="off" || + !condMet && getCurrentFsmState()=="on") + { + this->processFsmEvent("toggle"); + } + } + void Trigger::onFsmEnterState(Object&,/*const String& fsmName, */const object_fsm&, const object_fsm::state_type& state) + { + this->events().get("onTriggered")->fire( (state=="on") ); + + } +} // namespace ent +} // namespace yake Modified: trunk/yake/yake/ent/ent.h =================================================================== --- trunk/yake/yake/ent/ent.h 2007-08-27 13:45:58 UTC (rev 1822) +++ trunk/yake/yake/ent/ent.h 2007-08-27 17:13:37 UTC (rev 1823) @@ -35,6 +35,7 @@ #include "yake/ent/object_mgr.h" #include "yake/ent/object_mgr_listener.h" #include "yake/ent/entity.h" +#include "yake/ent/trigger.h" #endif Modified: trunk/yake/yake/ent/object.h =================================================================== --- trunk/yake/yake/ent/object.h 2007-08-27 13:45:58 UTC (rev 1822) +++ trunk/yake/yake/ent/object.h 2007-08-27 17:13:37 UTC (rev 1823) @@ -57,9 +57,12 @@ IMPL_CLASS_RTTI(CLASS) \ CLASS* CLASS::cast(::yake::ent::Object* obj) \ { \ - return (obj ? ((obj->isA() == CLASS::cls()) ? dynamic_cast<CLASS*>(obj) : 0 ) : 0); \ + return dynamic_cast<CLASS*>(obj); \ } + // @todo This cast() implementaiton would have to use obj->isKondOf(CLASS::cls()) to be useful! + // return (obj ? ((obj->isA() == CLASS::cls()) ? dynamic_cast<CLASS*>(obj) : 0 ) : 0); \ + /** Base class for complex objects with unique ids, properties and default events. @note properties: id (ObjectId) */ Added: trunk/yake/yake/ent/trigger.h =================================================================== --- trunk/yake/yake/ent/trigger.h (rev 0) +++ trunk/yake/yake/ent/trigger.h 2007-08-27 17:13:37 UTC (rev 1823) @@ -0,0 +1,61 @@ +/* + ------------------------------------------------------------------------------------ + This file is part of YAKE + Copyright (c) 2004 - 2008 The YAKE Team + For the latest information visit http://www.yake.org + ------------------------------------------------------------------------------------ + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA, or go to + http://www.gnu.org/copyleft/lesser.txt. + ------------------------------------------------------------------------------------ + If you are interested in another license model contact the Yake Team via + E-Mail: te...@ya.... + For more information see the LICENSE file in the root directory of the + source code distribution. + ------------------------------------------------------------------------------------ +*/ +#ifndef YAKE_ENT_TRIGGER_H +#define YAKE_ENT_TRIGGER_H + +#include "yake/ent/prerequisites.h" +#include "yake/ent/entity.h" + +namespace yake { +namespace ent { + + struct YAKE_ENT_API Trigger : public Entity, public ObjectListener + { + DECL_OBJECT(Trigger,"Trigger") + + Trigger(); + //virtual ~Trigger() {} + + typedef boost::function<bool(void)> ConditionFn; + void setCondition(const ConditionFn&); + + private: + virtual void onTick(); + private: + virtual void onFsmEventHandled(Object&, const object_fsm&, const object_fsm::event_type&) {} + virtual void onFsmEnterState(Object&,/*const String& fsmName, */const object_fsm&, const object_fsm::state_type& state); + virtual void onFsmExitState(Object&,/*const String& fsmName, */const object_fsm&, const object_fsm::state_type& state) {} + + private: + ConditionFn cond_; + }; + +} // namespace ent +} // namespace yake + +#endif + Modified: trunk/yake/yake/plugins/scriptingLua/ScriptingSystemLua.h =================================================================== --- trunk/yake/yake/plugins/scriptingLua/ScriptingSystemLua.h 2007-08-27 13:45:58 UTC (rev 1822) +++ trunk/yake/yake/plugins/scriptingLua/ScriptingSystemLua.h 2007-08-27 17:13:37 UTC (rev 1823) @@ -31,6 +31,7 @@ #include <boost/enable_shared_from_this.hpp> #include <boost/shared_ptr.hpp> #include <boost/noncopyable.hpp> +#include <yake/scripting/yakeScriptingSystem.h> #include <yake/res/res.h> #if defined( YAKE_SCRIPTINGLUA_EXPORTS ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-27 14:24:55
|
Revision: 1822 http://yake.svn.sourceforge.net/yake/?rev=1822&view=rev Author: psyclonist Date: 2007-08-27 06:45:58 -0700 (Mon, 27 Aug 2007) Log Message: ----------- * set svn:eol-style to native for latest additions Modified Paths: -------------- trunk/yake/common/media/samples/property/demo.lua trunk/yake/common/media/samples/task/demo.lua trunk/yake/common/media/samples/task/events.lua trunk/yake/common/media/scripts/raf1.lua trunk/yake/common/media/scripts/res1.lua trunk/yake/src/base/templates/yakeSignals.cpp trunk/yake/src/base/yakeConfigFile.cpp trunk/yake/src/base/yakeFileLog.cpp trunk/yake/src/base/yakeStderrLog.cpp trunk/yake/src/bindings.lua/detail/graphics.lua.cpp trunk/yake/src/bindings.lua/detail/input.lua.cpp trunk/yake/src/bindings.lua/detail/physics.lua.cpp trunk/yake/src/bindings.lua/detail/property.lua.cpp trunk/yake/src/bindings.lua/detail/raf.lua.cpp trunk/yake/src/bindings.lua/detail/res.lua.cpp trunk/yake/src/plugins/inputOgreOIS/InputSystemOgreOIS.cpp trunk/yake/src/plugins/inputOgreOIS/yakePCH.cpp trunk/yake/src/res/datastream.cpp trunk/yake/src/res/res.cpp trunk/yake/src/res/resource_manager.cpp trunk/yake/yake/base/yakeFileLog.h trunk/yake/yake/base/yakeStderrLog.h trunk/yake/yake/bindings.lua/detail/input.lua.keycodes.inl trunk/yake/yake/bindings.lua/detail/property.lua.h trunk/yake/yake/net2/async_send.h trunk/yake/yake/net2/error.h trunk/yake/yake/net2/message_decoder.h trunk/yake/yake/net2/net.h trunk/yake/yake/net2/packet.h trunk/yake/yake/net2/packet_connection.h trunk/yake/yake/net2/packet_dispatcher.h trunk/yake/yake/net2/resolver.h trunk/yake/yake/net2/server.h trunk/yake/yake/net2/simple_serialization.h trunk/yake/yake/net2/stats.h trunk/yake/yake/net2/types.h trunk/yake/yake/net2/utils.h trunk/yake/yake/plugins/graphicsOgre/graphicsOgrePrerequisites.h trunk/yake/yake/plugins/inputOgreOIS/InputSystemOgreOIS.h trunk/yake/yake/plugins/inputOgreOIS/yakePCH.h trunk/yake/yake/property/accessors.h trunk/yake/yake/property/function_accessor.h trunk/yake/yake/property/prerequisites.h trunk/yake/yake/property/property.h trunk/yake/yake/property/property_container.h trunk/yake/yake/property/stream_operators.h trunk/yake/yake/res/async_loader.h trunk/yake/yake/res/datastream.h trunk/yake/yake/res/prerequisites.h trunk/yake/yake/res/res.h trunk/yake/yake/res/resource.h trunk/yake/yake/res/resource_manager.h trunk/yake/yake/res/source.h trunk/yake/yake/res/source_manager.h trunk/yake/yake/scripting/scripting.h Property Changed: ---------------- trunk/yake/common/media/samples/property/demo.lua trunk/yake/common/media/samples/task/demo.lua trunk/yake/common/media/samples/task/events.lua trunk/yake/common/media/scripts/raf1.lua trunk/yake/common/media/scripts/res1.lua trunk/yake/src/base/templates/yakeSignals.cpp trunk/yake/src/base/yakeConfigFile.cpp trunk/yake/src/base/yakeFileLog.cpp trunk/yake/src/base/yakeStderrLog.cpp trunk/yake/src/bindings.lua/detail/graphics.lua.cpp trunk/yake/src/bindings.lua/detail/input.lua.cpp trunk/yake/src/bindings.lua/detail/physics.lua.cpp trunk/yake/src/bindings.lua/detail/property.lua.cpp trunk/yake/src/bindings.lua/detail/raf.lua.cpp trunk/yake/src/bindings.lua/detail/res.lua.cpp trunk/yake/src/plugins/inputOgreOIS/InputSystemOgreOIS.cpp trunk/yake/src/plugins/inputOgreOIS/yakePCH.cpp trunk/yake/src/res/datastream.cpp trunk/yake/src/res/res.cpp trunk/yake/src/res/resource_manager.cpp trunk/yake/yake/base/yakeFileLog.h trunk/yake/yake/base/yakeStderrLog.h trunk/yake/yake/bindings.lua/detail/input.lua.keycodes.inl trunk/yake/yake/bindings.lua/detail/property.lua.h trunk/yake/yake/net2/async_send.h trunk/yake/yake/net2/error.h trunk/yake/yake/net2/message_decoder.h trunk/yake/yake/net2/net.h trunk/yake/yake/net2/packet.h trunk/yake/yake/net2/packet_connection.h trunk/yake/yake/net2/packet_dispatcher.h trunk/yake/yake/net2/resolver.h trunk/yake/yake/net2/server.h trunk/yake/yake/net2/simple_serialization.h trunk/yake/yake/net2/stats.h trunk/yake/yake/net2/types.h trunk/yake/yake/net2/utils.h trunk/yake/yake/plugins/graphicsOgre/graphicsOgrePrerequisites.h trunk/yake/yake/plugins/inputOgreOIS/InputSystemOgreOIS.h trunk/yake/yake/plugins/inputOgreOIS/yakePCH.h trunk/yake/yake/property/accessors.h trunk/yake/yake/property/function_accessor.h trunk/yake/yake/property/prerequisites.h trunk/yake/yake/property/property.h trunk/yake/yake/property/property_container.h trunk/yake/yake/property/stream_operators.h trunk/yake/yake/res/async_loader.h trunk/yake/yake/res/datastream.h trunk/yake/yake/res/prerequisites.h trunk/yake/yake/res/res.h trunk/yake/yake/res/resource.h trunk/yake/yake/res/resource_manager.h trunk/yake/yake/res/source.h trunk/yake/yake/res/source_manager.h trunk/yake/yake/scripting/scripting.h Modified: trunk/yake/common/media/samples/property/demo.lua =================================================================== --- trunk/yake/common/media/samples/property/demo.lua 2007-08-24 21:25:15 UTC (rev 1821) +++ trunk/yake/common/media/samples/property/demo.lua 2007-08-27 13:45:58 UTC (rev 1822) @@ -1,58 +1,58 @@ - -print("create yake.NamedPropertyContainer"); -props = yake.NamedPropertyContainer(); - -print("create property 'visible' of implicit type 'bool'"); -assert( not props:has("visible") ); ---props:add( "visible", yake.createProperty(true) ); -props:create("visible",true); -assert( props:has("visible") ); - -print("acquire property object 'visible'"); -p = props:get("visible"); -assert(p); -print(" type = " .. p:type()); - -print("read & modify property"); -print( " value of 'visible' = " .. tostring(p:get()) ); -assert( p:set( not p:get() ) ); -print( " value of 'visible' = " .. tostring(p:get()) ); - -print("test for type mismatch when setting the value") -assert( not p:set("aloha") ); - -print("create property 'name' of implicit type 'String'"); -p = props:create("name","aloha"); -assert( p ); -print(" type = " .. p:type()); -print(" value = " .. tostring(p:get()) ); -assert( p:get() == "aloha" ); -assert( p:set("waikiki") ); -print(" value = " .. tostring(p:get()) ); -assert( p:get() == "waikiki" ); - -print("store a function in a property 'sayHello'"); -p = props:create("sayHello",function() print("'hello, i'm property 'sayHello'!'"); end); -assert( p ); -print(" type = " .. p:type()); -print("running function stored in property 'sayHello'"); -assert( p:get() ); -p:get()(); - ---NB At the moment you can store ANY kind of Lua object in a property! --- On the C++ side any 'unknown' or unregistered property type will be stored --- as a luabind::object. Be careful! -print("attempt to create property of unsupported type 'thread'"); -p = props:create("thread", coroutine.create(function() print("thread"); end)); ---assert( not p ); - -print("attempt to create property of type 'Vector3'"); -p = props:create("position", yake.Vector3(1,2,3)); -print(" value = (" .. p:get().x .. "," .. p:get().y .. "," .. p:get().z .. ")" ); ---assert( p:get():isEqualTo( yake.Vector(1,2,3) ) ); -assert( p:get().x == 1 ); -assert( not p:set(yake.Quaternion(1,0,0,1)) ); --will fail because of type mismatch -assert( p:set( yake.Vector3(2,3,4) ) ); -print(" value = (" .. p:get().x .. "," .. p:get().y .. "," .. p:get().z .. ")" ); - + +print("create yake.NamedPropertyContainer"); +props = yake.NamedPropertyContainer(); + +print("create property 'visible' of implicit type 'bool'"); +assert( not props:has("visible") ); +--props:add( "visible", yake.createProperty(true) ); +props:create("visible",true); +assert( props:has("visible") ); + +print("acquire property object 'visible'"); +p = props:get("visible"); +assert(p); +print(" type = " .. p:type()); + +print("read & modify property"); +print( " value of 'visible' = " .. tostring(p:get()) ); +assert( p:set( not p:get() ) ); +print( " value of 'visible' = " .. tostring(p:get()) ); + +print("test for type mismatch when setting the value") +assert( not p:set("aloha") ); + +print("create property 'name' of implicit type 'String'"); +p = props:create("name","aloha"); +assert( p ); +print(" type = " .. p:type()); +print(" value = " .. tostring(p:get()) ); +assert( p:get() == "aloha" ); +assert( p:set("waikiki") ); +print(" value = " .. tostring(p:get()) ); +assert( p:get() == "waikiki" ); + +print("store a function in a property 'sayHello'"); +p = props:create("sayHello",function() print("'hello, i'm property 'sayHello'!'"); end); +assert( p ); +print(" type = " .. p:type()); +print("running function stored in property 'sayHello'"); +assert( p:get() ); +p:get()(); + +--NB At the moment you can store ANY kind of Lua object in a property! +-- On the C++ side any 'unknown' or unregistered property type will be stored +-- as a luabind::object. Be careful! +print("attempt to create property of unsupported type 'thread'"); +p = props:create("thread", coroutine.create(function() print("thread"); end)); +--assert( not p ); + +print("attempt to create property of type 'Vector3'"); +p = props:create("position", yake.Vector3(1,2,3)); +print(" value = (" .. p:get().x .. "," .. p:get().y .. "," .. p:get().z .. ")" ); +--assert( p:get():isEqualTo( yake.Vector(1,2,3) ) ); +assert( p:get().x == 1 ); +assert( not p:set(yake.Quaternion(1,0,0,1)) ); --will fail because of type mismatch +assert( p:set( yake.Vector3(2,3,4) ) ); +print(" value = (" .. p:get().x .. "," .. p:get().y .. "," .. p:get().z .. ")" ); + print("\nAll tests done."); \ No newline at end of file Property changes on: trunk/yake/common/media/samples/property/demo.lua ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/yake/common/media/samples/task/demo.lua =================================================================== --- trunk/yake/common/media/samples/task/demo.lua 2007-08-24 21:25:15 UTC (rev 1821) +++ trunk/yake/common/media/samples/task/demo.lua 2007-08-27 13:45:58 UTC (rev 1822) @@ -1,43 +1,43 @@ --- event callbacks/handlers -function onTick() - print("onTick() (time=" .. sched:time() .. ")") -end - -function test() - print("test: cancel task " .. " (current time: " .. sched:time() .. ")") - - -- schedule function to be called after 3 time steps: - sched:add(onTick,3) - - -- schedule anonymous function to be called after 3 time steps: - sched:add( - function() - print("hello from anonymous! (time=" .. sched:time() .. ")") - end, - 3) - - -- schedule task and cancel it before it can be executed - t = sched:add(onTick,3) - t:cancel() - - wait(4) --wait until tasks at time 3 have been executed... - - print("test done (time=" .. sched:time() ..")") - assert( sched:time() == 4 ) -end - -function test2() - --local waypoints = {"work", "the bar", "home"}; - local waypoints = {"work", "the bar"}; - - print("note: waiting 2 time steps between waypoints") - for i,next in pairs(waypoints) do - print(sched:time() .. " waypoint " .. tostring(i) .. ": going to " .. next) - wait(2) -- could be: walkTo(next) - - assert(i*2 == sched:time()) - end - print(tostring(sched:time()) .. " lua: staying some more...") - wait(1) - print(tostring(sched:time()) .. " lua: i'm dead :( no more waypoints") -end +-- event callbacks/handlers +function onTick() + print("onTick() (time=" .. sched:time() .. ")") +end + +function test() + print("test: cancel task " .. " (current time: " .. sched:time() .. ")") + + -- schedule function to be called after 3 time steps: + sched:add(onTick,3) + + -- schedule anonymous function to be called after 3 time steps: + sched:add( + function() + print("hello from anonymous! (time=" .. sched:time() .. ")") + end, + 3) + + -- schedule task and cancel it before it can be executed + t = sched:add(onTick,3) + t:cancel() + + wait(4) --wait until tasks at time 3 have been executed... + + print("test done (time=" .. sched:time() ..")") + assert( sched:time() == 4 ) +end + +function test2() + --local waypoints = {"work", "the bar", "home"}; + local waypoints = {"work", "the bar"}; + + print("note: waiting 2 time steps between waypoints") + for i,next in pairs(waypoints) do + print(sched:time() .. " waypoint " .. tostring(i) .. ": going to " .. next) + wait(2) -- could be: walkTo(next) + + assert(i*2 == sched:time()) + end + print(tostring(sched:time()) .. " lua: staying some more...") + wait(1) + print(tostring(sched:time()) .. " lua: i'm dead :( no more waypoints") +end Property changes on: trunk/yake/common/media/samples/task/demo.lua ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/yake/common/media/samples/task/events.lua =================================================================== --- trunk/yake/common/media/samples/task/events.lua 2007-08-24 21:25:15 UTC (rev 1821) +++ trunk/yake/common/media/samples/task/events.lua 2007-08-27 13:45:58 UTC (rev 1822) @@ -1,26 +1,26 @@ --- boiler plate code: -print("lua: init task adapter code...") - ---@todo move this code out into 'entity.bind.lua' -function events(id) -- alias for: self:get(id) - if not id then - return self:events() - else - return self:events():get(id) - end -end - -function wait(delay) - if not delay then - return nil - end - schedule_revive(sched, delay, function() end) - print("lua: wait.yield...") - coroutine.yield() -end -task = { - add = function(fn,delayMs) - return sched:add(fn,delayMs) - end -} +-- boiler plate code: +print("lua: init task adapter code...") + +--@todo move this code out into 'entity.bind.lua' +function events(id) -- alias for: self:get(id) + if not id then + return self:events() + else + return self:events():get(id) + end +end + +function wait(delay) + if not delay then + return nil + end + schedule_revive(sched, delay, function() end) + print("lua: wait.yield...") + coroutine.yield() +end +task = { + add = function(fn,delayMs) + return sched:add(fn,delayMs) + end +} print("lua: task adapter code initialised") \ No newline at end of file Property changes on: trunk/yake/common/media/samples/task/events.lua ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/yake/common/media/scripts/raf1.lua =================================================================== --- trunk/yake/common/media/scripts/raf1.lua 2007-08-24 21:25:15 UTC (rev 1821) +++ trunk/yake/common/media/scripts/raf1.lua 2007-08-27 13:45:58 UTC (rev 1822) @@ -1,109 +1,109 @@ -local gworld = scene.gworld -local defaultCam = scene.activeCamera -local actionMap = app.actionMap -local input = yake.input - --------------------------------------- --- Configure graphics --------------------------------------- - --- configure basic scene properties -gworld:setShadowsEnabled(false) -gworld:setAmbientLight(yake.Color(0,0,0,1)) - --- create ninja -local sn = gworld:createSceneNode() -local e = gworld:createEntity("ninja.mesh") -sn:attach(e) - --- create directional light - -local light = gworld:createLight() -- create light - -local lightnode = gworld:createSceneNode() -- attach light to node -lightnode:attach(light) - -light.type = yake.graphics.Light.LT_DIRECTIONAL -- configure light -light:setDiffuseColour(yake.Color(1,1,1,1)) -light.direction = yake.Vector3(0,-1,1) - --- configure active (=default) camera - -local cam = scene.activeCamera -assert(cam) -cam.position = yake.Vector3(100,20,-200) -cam:setFixedYawAxis( yake.Vector3.UnitY ) -- keep upwards direction constant -cam:lookAt( yake.Vector3(0,100,0) ) -- look at our ninja! - --------------------------------------- --- Configure input --------------------------------------- - -local activeKeys = {} -- Store the keys that are active in current frame. - --- We demonstrate two ways to bind Lua callbacks to a keyboard action. --- #1 demonstrates the details --- #2 shows how to achieve the same thing fast and Lua-style - ------- #1: "The Long Way" - ---local idLeft = input.ActionId.fromName("left") -- look up ActionId by its name (useful for user-defined ones) -local idLeft = input.ACTIONID_LEFT -- using an ActionId constant - --- Connect key "Cursor Left" to action "left": -local acLeft = input.KeyboardActionCondition(app.keyboard, input.KC_LEFT, input.KAM_CONTINUOUS) -actionMap:reg(idLeft,acLeft) - --- Our Lua callback handler: -function onLeft() - activeKeys["left"] = true -end - -actionMap:connectToAction(idLeft,onLeft) -- by Action ID - ------- #2: "Shortcut" (using action names and anonymous Lua functions) - -actionMap:reg("right", input.KeyboardActionCondition(app.keyboard, input.KC_RIGHT, input.KAM_CONTINUOUS)) -actionMap:connectToAction("right", - function() - activeKeys["right"] = true - end) - -------- Let's define a few helper functions to make things easier: - -function createKeyAction(action, key, keymode) - return actionMap:reg(action, input.KeyboardActionCondition(app.keyboard, key, keymode )) -end -function bindAction(action, handler) - return actionMap:connectToAction(action, handler) -end - -------- Bind the rest of the keys to actions: - -createKeyAction("forward", input.KC_UP, input.KAM_CONTINUOUS) -bindAction("forward", function() - activeKeys["forward"] = true - end) - -createKeyAction("reverse", input.KC_DOWN, input.KAM_CONTINUOUS) -bindAction("reverse", function() - activeKeys["reverse"] = true - end) - ------------------------------------ -function onFrame(timeElapsed) - local distance = 25 * timeElapsed - for k,v in pairs(activeKeys) do - if k == "left" then - cam:translate( -1 * yake.Vector3.UnitX * distance ) - elseif k == "right" then - cam:translate( 1 * yake.Vector3.UnitX * distance ) - elseif k == "forward" then - cam:translate( -1 * yake.Vector3.UnitZ * distance ) - elseif k == "reverse" then - cam:translate( 1 * yake.Vector3.UnitZ * distance ) - end - end - -- prepare for next frame: - activeKeys = {} +local gworld = scene.gworld +local defaultCam = scene.activeCamera +local actionMap = app.actionMap +local input = yake.input + +-------------------------------------- +-- Configure graphics +-------------------------------------- + +-- configure basic scene properties +gworld:setShadowsEnabled(false) +gworld:setAmbientLight(yake.Color(0,0,0,1)) + +-- create ninja +local sn = gworld:createSceneNode() +local e = gworld:createEntity("ninja.mesh") +sn:attach(e) + +-- create directional light + +local light = gworld:createLight() -- create light + +local lightnode = gworld:createSceneNode() -- attach light to node +lightnode:attach(light) + +light.type = yake.graphics.Light.LT_DIRECTIONAL -- configure light +light:setDiffuseColour(yake.Color(1,1,1,1)) +light.direction = yake.Vector3(0,-1,1) + +-- configure active (=default) camera + +local cam = scene.activeCamera +assert(cam) +cam.position = yake.Vector3(100,20,-200) +cam:setFixedYawAxis( yake.Vector3.UnitY ) -- keep upwards direction constant +cam:lookAt( yake.Vector3(0,100,0) ) -- look at our ninja! + +-------------------------------------- +-- Configure input +-------------------------------------- + +local activeKeys = {} -- Store the keys that are active in current frame. + +-- We demonstrate two ways to bind Lua callbacks to a keyboard action. +-- #1 demonstrates the details +-- #2 shows how to achieve the same thing fast and Lua-style + +------ #1: "The Long Way" + +--local idLeft = input.ActionId.fromName("left") -- look up ActionId by its name (useful for user-defined ones) +local idLeft = input.ACTIONID_LEFT -- using an ActionId constant + +-- Connect key "Cursor Left" to action "left": +local acLeft = input.KeyboardActionCondition(app.keyboard, input.KC_LEFT, input.KAM_CONTINUOUS) +actionMap:reg(idLeft,acLeft) + +-- Our Lua callback handler: +function onLeft() + activeKeys["left"] = true +end + +actionMap:connectToAction(idLeft,onLeft) -- by Action ID + +------ #2: "Shortcut" (using action names and anonymous Lua functions) + +actionMap:reg("right", input.KeyboardActionCondition(app.keyboard, input.KC_RIGHT, input.KAM_CONTINUOUS)) +actionMap:connectToAction("right", + function() + activeKeys["right"] = true + end) + +------- Let's define a few helper functions to make things easier: + +function createKeyAction(action, key, keymode) + return actionMap:reg(action, input.KeyboardActionCondition(app.keyboard, key, keymode )) +end +function bindAction(action, handler) + return actionMap:connectToAction(action, handler) +end + +------- Bind the rest of the keys to actions: + +createKeyAction("forward", input.KC_UP, input.KAM_CONTINUOUS) +bindAction("forward", function() + activeKeys["forward"] = true + end) + +createKeyAction("reverse", input.KC_DOWN, input.KAM_CONTINUOUS) +bindAction("reverse", function() + activeKeys["reverse"] = true + end) + +----------------------------------- +function onFrame(timeElapsed) + local distance = 25 * timeElapsed + for k,v in pairs(activeKeys) do + if k == "left" then + cam:translate( -1 * yake.Vector3.UnitX * distance ) + elseif k == "right" then + cam:translate( 1 * yake.Vector3.UnitX * distance ) + elseif k == "forward" then + cam:translate( -1 * yake.Vector3.UnitZ * distance ) + elseif k == "reverse" then + cam:translate( 1 * yake.Vector3.UnitZ * distance ) + end + end + -- prepare for next frame: + activeKeys = {} end \ No newline at end of file Property changes on: trunk/yake/common/media/scripts/raf1.lua ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/yake/common/media/scripts/res1.lua =================================================================== --- trunk/yake/common/media/scripts/res1.lua 2007-08-24 21:25:15 UTC (rev 1821) +++ trunk/yake/common/media/scripts/res1.lua 2007-08-27 13:45:58 UTC (rev 1822) @@ -1,20 +1,20 @@ --- acquire global res::SourceManager -print("acquire SourceManager") -assert( yake.res ) -local res = yake.res -assert( res.global.sourceManager ) -local sourceManager = res.global.sourceManager - --- add some sources -print("add sources") -sourceManager:addSource("file","./") -sourceManager:addSource("file","../../../scripts/tools/luadocs/") - --- find resource using sourceManager: -print("locate project.txt...") -local find = sourceManager:find("project.txt") -if find.valid then - print("found project.txt at: "..find.location) -else - print("could not find project.txt") +-- acquire global res::SourceManager +print("acquire SourceManager") +assert( yake.res ) +local res = yake.res +assert( res.global.sourceManager ) +local sourceManager = res.global.sourceManager + +-- add some sources +print("add sources") +sourceManager:addSource("file","./") +sourceManager:addSource("file","../../../scripts/tools/luadocs/") + +-- find resource using sourceManager: +print("locate project.txt...") +local find = sourceManager:find("project.txt") +if find.valid then + print("found project.txt at: "..find.location) +else + print("could not find project.txt") end \ No newline at end of file Property changes on: trunk/yake/common/media/scripts/res1.lua ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/yake/src/base/templates/yakeSignals.cpp =================================================================== --- trunk/yake/src/base/templates/yakeSignals.cpp 2007-08-24 21:25:15 UTC (rev 1821) +++ trunk/yake/src/base/templates/yakeSignals.cpp 2007-08-27 13:45:58 UTC (rev 1822) @@ -1,53 +1,53 @@ -/* - ------------------------------------------------------------------------------------ - This file is part of YAKE - Copyright (c) 2004 - 2008 The YAKE Team - For the latest information visit http://www.yake.org - ------------------------------------------------------------------------------------ - This program is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free Software - Foundation; either version 2 of the License, or (at your option) any later - version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with - this program; if not, write to the Free Software Foundation, Inc., 59 Temple - Place - Suite 330, Boston, MA 02111-1307, USA, or go to - http://www.gnu.org/copyleft/lesser.txt. - ------------------------------------------------------------------------------------ - If you are interested in another license model contact the Yake Team via - E-Mail: te...@ya.... - For more information see the LICENSE file in the root directory of the - source code distribution. - ------------------------------------------------------------------------------------ -*/ -#include <yake/base/yakePCH.h> -#include <yake/base/templates/yakeSignals.h> - -namespace yake { - - //----------------------------------------------------- - SignalConnectionGroup::SignalConnectionGroup() - { - } - SignalConnectionGroup::~SignalConnectionGroup() - { - this->clearAndDisconnectAll(); - } - void SignalConnectionGroup::clearAndDisconnectAll() - { - for (SignalConnectionList::const_iterator it = connections_.begin(); - it != connections_.end(); ++it) - (*it).disconnect(); - connections_.clear(); - } - SignalConnectionGroup& SignalConnectionGroup::operator += (const SignalConnection& connection) - { - connections_.push_back( connection ); - return *this; - } - -} // yake +/* + ------------------------------------------------------------------------------------ + This file is part of YAKE + Copyright (c) 2004 - 2008 The YAKE Team + For the latest information visit http://www.yake.org + ------------------------------------------------------------------------------------ + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA, or go to + http://www.gnu.org/copyleft/lesser.txt. + ------------------------------------------------------------------------------------ + If you are interested in another license model contact the Yake Team via + E-Mail: te...@ya.... + For more information see the LICENSE file in the root directory of the + source code distribution. + ------------------------------------------------------------------------------------ +*/ +#include <yake/base/yakePCH.h> +#include <yake/base/templates/yakeSignals.h> + +namespace yake { + + //----------------------------------------------------- + SignalConnectionGroup::SignalConnectionGroup() + { + } + SignalConnectionGroup::~SignalConnectionGroup() + { + this->clearAndDisconnectAll(); + } + void SignalConnectionGroup::clearAndDisconnectAll() + { + for (SignalConnectionList::const_iterator it = connections_.begin(); + it != connections_.end(); ++it) + (*it).disconnect(); + connections_.clear(); + } + SignalConnectionGroup& SignalConnectionGroup::operator += (const SignalConnection& connection) + { + connections_.push_back( connection ); + return *this; + } + +} // yake Property changes on: trunk/yake/src/base/templates/yakeSignals.cpp ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/yake/src/base/yakeConfigFile.cpp =================================================================== --- trunk/yake/src/base/yakeConfigFile.cpp 2007-08-24 21:25:15 UTC (rev 1821) +++ trunk/yake/src/base/yakeConfigFile.cpp 2007-08-27 13:45:58 UTC (rev 1822) @@ -1,279 +1,279 @@ -/* - ------------------------------------------------------------------------------------ - This file is part of YAKE - Copyright (c) 2004 - 2008 The YAKE Team - For the latest information visit http://www.yake.org - ------------------------------------------------------------------------------------ - This program is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free Software - Foundation; either version 2 of the License, or (at your option) any later - version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with - this program; if not, write to the Free Software Foundation, Inc., 59 Temple - Place - Suite 330, Boston, MA 02111-1307, USA, or go to - http://www.gnu.org/copyleft/lesser.txt. - ------------------------------------------------------------------------------------ - If you are interested in another license model contact the Yake Team via - E-Mail: te...@ya.... - For more information see the LICENSE file in the root directory of the - source code distribution. - ------------------------------------------------------------------------------------ -*/ - -#include <yake/base/yakePCH.h> -#include <yake/base/yakeConfigFile.h> - -namespace yake { - - namespace detail { - } // namespace detail - - Configuration::Configuration() : tree_( new tree_type() ) - { - } - Configuration::Configuration(const Configuration& other) : tree_(other.tree_), prefix_(other.prefix_) - { - } - const Configuration& Configuration::operator=(const Configuration& rhs) - { - if (this == &rhs) - return *this; - tree_ = rhs.tree_; - prefix_ = rhs.prefix_; - return *this; - } - Configuration::Configuration(const Configuration& cfg, const String& path) : tree_( cfg.tree_ ), prefix_(path) - { - if (!prefix_.empty()) - { - // make sure there's a trailing '/' - if (prefix_.at( prefix_.size() -1 ) != '/') - prefix_ += '/'; - } - } - void Configuration::copyFrom(const Configuration& other) - { - tree_.reset( new tree_type() ); - if (other.tree_) - *tree_ = *other.tree_; - prefix_ = other.prefix_; - } - Configuration::~Configuration() - { - } - Configuration::const_iterator Configuration::begin(const String& path) const - { - try { - return tree_->get_child('/',prefix_+path).begin(); - } - catch (boost::property_tree::ptree_error&) - { - return tree_->end(); - } - } - Configuration::const_iterator Configuration::end(const String& path) const - { - try { - return tree_->get_child('/',prefix_+path).end(); - } - catch (boost::property_tree::ptree_error&) - { - return tree_->end(); - } - } - bool Configuration::exists(const String& path) const - { - try { - tree_->get_child('/',prefix_+path); - return true; - } - catch (boost::property_tree::ptree_error&) - { - return false; - } - } - String Configuration::get(const String& pathToValue, const String& defaultValue) const - { - try { - return tree_->get<String>('/',prefix_+pathToValue); - } - catch (...) - { - return defaultValue; - } - } - void Configuration::readFromFile(const String& fn, const String& insertAt) - { - YAKE_ASSERT( insertAt.empty() && "not yet supported" ); - std::ifstream in(fn.c_str()); - if (!in.is_open()) - return; //@todo - boost::property_tree::read_info(in,*tree_); - } - void Configuration::readFromXML(const String& fn, const String& insertAt) - { - YAKE_ASSERT( insertAt.empty() && "not yet supported" ); - std::ifstream in(fn.c_str()); - if (!in.is_open()) - return; //@todo - boost::property_tree::read_xml(in,*tree_); - } - void Configuration::writeToFile(const String& fn, const String& startAt) - { - YAKE_ASSERT( startAt.empty() && "not yet supported" ); - //boost::property_tree::write_info(cout,*tree_); - - std::ofstream out(fn.c_str()); - if (!out.is_open()) - return; //@todo - boost::property_tree::write_info(out,*tree_); - } - void Configuration::writeToXML(const String& fn, const String& startAt) - { - YAKE_ASSERT( startAt.empty() && "not yet supported" ); - //boost::property_tree::write_xml(cout,*tree_); - - std::ofstream out(fn.c_str()); - if (!out.is_open()) - return; //@todo - boost::property_tree::write_xml(out,*tree_); - } - - //----------------------------------------------------- - - IniFile::IniFile() - { - } - /* - ini::const_key_iterator ini::begin(const String& section) const - { - Sections::const_iterator itSect = sections_.find(section); - if (itSect == sections_.end()) - return empty_.end(); - return itSect->second.begin(); - } - ini::const_key_iterator ini::end(const String& section) const - { - Sections::const_iterator itSect = sections_.find(section); - if (itSect == sections_.end()) - return empty_.end(); - return itSect->second.end(); - } - */ - StringVector IniFile::getKeys(const String& section) const - { - Sections::const_iterator itSect = sections_.find(section); - if (itSect == sections_.end()) - return StringVector(); - KeyValueMap::const_iterator it = itSect->second.begin(); - KeyValueMap::const_iterator itEnd = itSect->second.end(); - StringVector ret; - for (; it != itEnd; ++it) - ret.push_back( it->first ); - return ret; - } - StringPairVector IniFile::getKeysAndValues(const String& section) const - { - Sections::const_iterator itSect = sections_.find(section); - if (itSect == sections_.end()) - return StringPairVector(); - StringPairVector ret; - YAKE_FOR_EACH( KeyValueMap::const_iterator, itKey, itSect->second ) - { - const ValueList& values = itKey->second; - YAKE_FOR_EACH( ValueList::const_iterator, itValue, values ) - ret.push_back( StringPair( itKey->first, *itValue ) ); - } - return ret; - } - IniFile::KeyValueMap IniFile::getKeysAndValues2(const String& section) const - { - Sections::const_iterator itSect = sections_.find(section); - if (itSect == sections_.end()) - return IniFile::KeyValueMap(); - return itSect->second; - } - bool IniFile::hasSection(const String& section) const - { - Sections::const_iterator itSect = sections_.find(section); - return (itSect != sections_.end()); - } - IniFile::value IniFile::getFirstValue(const String& section, const String& key) const - { - Sections::const_iterator itSect = sections_.find(section); - if (itSect == sections_.end()) - return false; - KeyValueMap::const_iterator itKey = itSect->second.find(key); - if (itKey == itSect->second.end()) - return false; - const ValueList& values = itKey->second; - if (values.empty()) - return false; - return values.front(); - } - StringVector IniFile::getAllValues(const String& section, const String& key) const - { - Sections::const_iterator itSect = sections_.find(section); - if (itSect == sections_.end()) - return StringVector(); - KeyValueMap::const_iterator itKey = itSect->second.find(key); - if (itKey == itSect->second.end()) - return StringVector(); - const ValueList& values = itKey->second; - return values; - } - bool IniFile::load(const String& filename) - { - std::ifstream in(filename.c_str(), std::ios::in); - if (!in) - return false; - String currSection; - String line; - while (std::getline(in,line)) - { - StringUtil::trim( line, true, true ); // trim left and right - // skip comments (full line and trailing ones) - { - String::size_type commentStart = line.find("#"); - if (String::npos != commentStart) - { - line = line.substr(0,commentStart); - StringUtil::trim(line); - } - } - if (line.empty()) // skip empty lines - continue; - // - if (line[0] == '[') - { - String::size_type endMarker = line.find("]"); - YAKE_ASSERT( endMarker != String::npos ).debug("syntax error in section declaration: missing ']'."); - if (endMarker == String::npos) - continue; - currSection = line.substr(1,endMarker-1); - StringUtil::trim(currSection); - } - else - { - String key,value; - String::size_type splitAt = line.find("="); - if (splitAt != String::npos) - { - key = line.substr(0,splitAt); - value = line.substr(splitAt+1); - StringUtil::trim(key); - StringUtil::trim(value); - } - else - key = line; - sections_[currSection][key].push_back( value ); - } - } - return true; - } -} // yake +/* + ------------------------------------------------------------------------------------ + This file is part of YAKE + Copyright (c) 2004 - 2008 The YAKE Team + For the latest information visit http://www.yake.org + ------------------------------------------------------------------------------------ + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA, or go to + http://www.gnu.org/copyleft/lesser.txt. + ------------------------------------------------------------------------------------ + If you are interested in another license model contact the Yake Team via + E-Mail: te...@ya.... + For more information see the LICENSE file in the root directory of the + source code distribution. + ------------------------------------------------------------------------------------ +*/ + +#include <yake/base/yakePCH.h> +#include <yake/base/yakeConfigFile.h> + +namespace yake { + + namespace detail { + } // namespace detail + + Configuration::Configuration() : tree_( new tree_type() ) + { + } + Configuration::Configuration(const Configuration& other) : tree_(other.tree_), prefix_(other.prefix_) + { + } + const Configuration& Configuration::operator=(const Configuration& rhs) + { + if (this == &rhs) + return *this; + tree_ = rhs.tree_; + prefix_ = rhs.prefix_; + return *this; + } + Configuration::Configuration(const Configuration& cfg, const String& path) : tree_( cfg.tree_ ), prefix_(path) + { + if (!prefix_.empty()) + { + // make sure there's a trailing '/' + if (prefix_.at( prefix_.size() -1 ) != '/') + prefix_ += '/'; + } + } + void Configuration::copyFrom(const Configuration& other) + { + tree_.reset( new tree_type() ); + if (other.tree_) + *tree_ = *other.tree_; + prefix_ = other.prefix_; + } + Configuration::~Configuration() + { + } + Configuration::const_iterator Configuration::begin(const String& path) const + { + try { + return tree_->get_child('/',prefix_+path).begin(); + } + catch (boost::property_tree::ptree_error&) + { + return tree_->end(); + } + } + Configuration::const_iterator Configuration::end(const String& path) const + { + try { + return tree_->get_child('/',prefix_+path).end(); + } + catch (boost::property_tree::ptree_error&) + { + return tree_->end(); + } + } + bool Configuration::exists(const String& path) const + { + try { + tree_->get_child('/',prefix_+path); + return true; + } + catch (boost::property_tree::ptree_error&) + { + return false; + } + } + String Configuration::get(const String& pathToValue, const String& defaultValue) const + { + try { + return tree_->get<String>('/',prefix_+pathToValue); + } + catch (...) + { + return defaultValue; + } + } + void Configuration::readFromFile(const String& fn, const String& insertAt) + { + YAKE_ASSERT( insertAt.empty() && "not yet supported" ); + std::ifstream in(fn.c_str()); + if (!in.is_open()) + return; //@todo + boost::property_tree::read_info(in,*tree_); + } + void Configuration::readFromXML(const String& fn, const String& insertAt) + { + YAKE_ASSERT( insertAt.empty() && "not yet supported" ); + std::ifstream in(fn.c_str()); + if (!in.is_open()) + return; //@todo + boost::property_tree::read_xml(in,*tree_); + } + void Configuration::writeToFile(const String& fn, const String& startAt) + { + YAKE_ASSERT( startAt.empty() && "not yet supported" ); + //boost::property_tree::write_info(cout,*tree_); + + std::ofstream out(fn.c_str()); + if (!out.is_open()) + return; //@todo + boost::property_tree::write_info(out,*tree_); + } + void Configuration::writeToXML(const String& fn, const String& startAt) + { + YAKE_ASSERT( startAt.empty() && "not yet supported" ); + //boost::property_tree::write_xml(cout,*tree_); + + std::ofstream out(fn.c_str()); + if (!out.is_open()) + return; //@todo + boost::property_tree::write_xml(out,*tree_); + } + + //----------------------------------------------------- + + IniFile::IniFile() + { + } + /* + ini::const_key_iterator ini::begin(const String& section) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return empty_.end(); + return itSect->second.begin(); + } + ini::const_key_iterator ini::end(const String& section) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return empty_.end(); + return itSect->second.end(); + } + */ + StringVector IniFile::getKeys(const String& section) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return StringVector(); + KeyValueMap::const_iterator it = itSect->second.begin(); + KeyValueMap::const_iterator itEnd = itSect->second.end(); + StringVector ret; + for (; it != itEnd; ++it) + ret.push_back( it->first ); + return ret; + } + StringPairVector IniFile::getKeysAndValues(const String& section) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return StringPairVector(); + StringPairVector ret; + YAKE_FOR_EACH( KeyValueMap::const_iterator, itKey, itSect->second ) + { + const ValueList& values = itKey->second; + YAKE_FOR_EACH( ValueList::const_iterator, itValue, values ) + ret.push_back( StringPair( itKey->first, *itValue ) ); + } + return ret; + } + IniFile::KeyValueMap IniFile::getKeysAndValues2(const String& section) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return IniFile::KeyValueMap(); + return itSect->second; + } + bool IniFile::hasSection(const String& section) const + { + Sections::const_iterator itSect = sections_.find(section); + return (itSect != sections_.end()); + } + IniFile::value IniFile::getFirstValue(const String& section, const String& key) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return false; + KeyValueMap::const_iterator itKey = itSect->second.find(key); + if (itKey == itSect->second.end()) + return false; + const ValueList& values = itKey->second; + if (values.empty()) + return false; + return values.front(); + } + StringVector IniFile::getAllValues(const String& section, const String& key) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return StringVector(); + KeyValueMap::const_iterator itKey = itSect->second.find(key); + if (itKey == itSect->second.end()) + return StringVector(); + const ValueList& values = itKey->second; + return values; + } + bool IniFile::load(const String& filename) + { + std::ifstream in(filename.c_str(), std::ios::in); + if (!in) + return false; + String currSection; + String line; + while (std::getline(in,line)) + { + StringUtil::trim( line, true, true ); // trim left and right + // skip comments (full line and trailing ones) + { + String::size_type commentStart = line.find("#"); + if (String::npos != commentStart) + { + line = line.substr(0,commentStart); + StringUtil::trim(line); + } + } + if (line.empty()) // skip empty lines + continue; + // + if (line[0] == '[') + { + String::size_type endMarker = line.find("]"); + YAKE_ASSERT( endMarker != String::npos ).debug("syntax error in section declaration: missing ']'."); + if (endMarker == String::npos) + continue; + currSection = line.substr(1,endMarker-1); + StringUtil::trim(currSection); + } + else + { + String key,value; + String::size_type splitAt = line.find("="); + if (splitAt != String::npos) + { + key = line.substr(0,splitAt); + value = line.substr(splitAt+1); + StringUtil::trim(key); + StringUtil::trim(value); + } + else + key = line; + sections_[currSection][key].push_back( value ); + } + } + return true; + } +} // yake Property changes on: trunk/yake/src/base/yakeConfigFile.cpp ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/yake/src/base/yakeFileLog.cpp =================================================================== --- trunk/yake/src/base/yakeFileLog.cpp 2007-08-24 21:25:15 UTC (rev 1821) +++ trunk/yake/src/base/yakeFileLog.cpp 2007-08-27 13:45:58 UTC (rev 1822) @@ -1,59 +1,59 @@ -/* - ------------------------------------------------------------------------------------ - This file is part of YAKE - Copyright (c) 2004 - 2008 The YAKE Team - For the latest information visit http://www.yake.org - ------------------------------------------------------------------------------------ - This program is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free Software - Foundation; either version 2 of the License, or (at your option) any later - version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with - this program; if not, write to the Free Software Foundation, Inc., 59 Temple - Place - Suite 330, Boston, MA 02111-1307, USA, or go to - http://www.gnu.org/copyleft/lesser.txt. - ------------------------------------------------------------------------------------ - If you are interested in another license model contact the Yake Team via - E-Mail: te...@ya.... - For more information see the LICENSE file in the root directory of the - source code distribution. - ------------------------------------------------------------------------------------ -*/ -#include <yake/base/yakePCH.h> -#include <yake/base/yakeLog.h> -#include <yake/base/yakeFileLog.h> -#include <boost/lexical_cast.hpp> - -namespace yake { -namespace logging { - - file_listener::file_listener(const std::string& fileName) - { - fp_.open(fileName.c_str()); - fp_ << "// format:\n"; - fp_ << "// [processId][logId][threadId] [logLevel] message\n"; - fp_.flush(); - } - file_listener::~file_listener() - { - fp_.close(); - } - void file_listener::write(const severity_t sev, const char* msg, const char* logId, const char* procId, threadid_t threadId) - { - formatLogMessage(fp_, sev, msg, logId, procId, threadId ); - fp_.flush(); - } - log_listener_ptr file_listener::add(const std::string& fileName) - { - log_listener_ptr l( new file_listener(fileName) ); - addListener( l.get() ); - return l; - } - -} // logging -} // yake +/* + ------------------------------------------------------------------------------------ + This file is part of YAKE + Copyright (c) 2004 - 2008 The YAKE Team + For the latest information visit http://www.yake.org + ------------------------------------------------------------------------------------ + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA, or go to + http://www.gnu.org/copyleft/lesser.txt. + ------------------------------------------------------------------------------------ + If you are interested in another license model contact the Yake Team via + E-Mail: te...@ya.... + For more information see the LICENSE file in the root directory of the + source code distribution. + ------------------------------------------------------------------------------------ +*/ +#include <yake/base/yakePCH.h> +#include <yake/base/yakeLog.h> +#include <yake/base/yakeFileLog.h> +#include <boost/lexical_cast.hpp> + +namespace yake { +namespace logging { + + file_listener::file_listener(const std::string& fileName) + { + fp_.open(fileName.c_str()); + fp_ << "// format:\n"; + fp_ << "// [processId][logId][threadId] [logLevel] message\n"; + fp_.flush(); + } + file_listener::~file_listener() + { + fp_.close(); + } + void file_listener::write(const severity_t sev, const char* msg, const char* logId, const char* procId, threadid_t threadId) + { + formatLogMessage(fp_, sev, msg, logId, procId, threadId ); + fp_.flush(); + } + log_listener_ptr file_listener::add(const std::string& fileName) + { + log_listener_ptr l( new file_listener(fileName) ); + addListener( l.get() ); + return l; + } + +} // logging +} // yake Property changes on: trunk/yake/src/base/yakeFileLog.cpp ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/yake/src/base/yakeStderrLog.cpp =================================================================== --- trunk/yake/src/base/yakeStderrLog.cpp 2007-08-24 21:25:15 UTC (rev 1821) +++ trunk/yake/src/base/yakeStderrLog.cpp 2007-08-27 13:45:58 UTC (rev 1822) @@ -1,60 +1,60 @@ -/* - ------------------------------------------------------------------------------------ - This file is part of YAKE - Copyright (c) 2004 - 2008 The YAKE Team - For the latest information visit http://www.yake.org - ------------------------------------------------------------------------------------ - This program is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free Software - Foundation; either version 2 of the License, or (at your option) any later - version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with - this program; if not, write to the Free Software Foundation, Inc., 59 Temple - Place - Suite 330, Boston, MA 02111-1307, USA, or go to - http://www.gnu.org/copyleft/lesser.txt. - ------------------------------------------------------------------------------------ - If you are interested in another license model contact the Yake Team via - E-Mail: te...@ya.... - For more information see the LICENSE file in the root directory of the - source code distribution. - ------------------------------------------------------------------------------------ -*/ -#include <yake/base/yakePCH.h> -#include <yake/base/yakeLog.h> -#include <yake/base/yakeStderrLog.h> -#include <yake/base/native/yakeNative.h> -#include <boost/lexical_cast.hpp> - -namespace yake { -namespace logging { - - stderr_listener::stderr_listener() - { - } - stderr_listener::~stderr_listener() - { - } - void stderr_listener::write(const severity_t sev, const char* msg, const char* logId, const char* procId, threadid_t threadId) - { - std::ostringstream ss; - formatLogMessage(ss, sev, msg, logId, procId, threadId ); - - if (native::debug_Log_available()) //@todo potential performance problem - native::debug_Log( ss.str(), sev ); - else - std::cerr << ss.str(); - } - log_listener_ptr stderr_listener::add() - { - log_listener_ptr l( new stderr_listener() ); - addListener( l.get() ); - return l; - } - -} // logging -} // yake +/* + ------------------------------------------------------------------------------------ + This file is part of YAKE + Copyright (c) 2004 - 2008 The YAKE Team + For the latest information visit http://www.yake.org + ------------------------------------------------------------------------------------ + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA, or go to + http://www.gnu.org/copyleft/lesser.txt. + ------------------------------------------------------------------------------------ + If you are interested in another license model contact the Yake Team via + E-Mail: te...@ya.... + For more information see the LICENSE file in the root directory of the + source code distribution. + ------------------------------------------------------------------------------------ +*/ +#include <yake/base/yakePCH.h> +#include <yake/base/yakeLog.h> +#include <yake/base/yakeStderrLog.h> +#include <yake/base/native/yakeNative.h> +#include <boost/lexical_cast.hpp> + +namespace yake { +namespace logging { + + stderr_listener::stderr_listener() + { + } + stderr_listener::~stderr_listener() + { + } + void stderr_listener::write(const severity_t sev, const char* msg, const char* logId, const char* procId, threadid_t threadId) + { + std::ostringstream ss; + formatLogMessage(ss, sev, msg, logId, procId, threadId ); + + if (native::debug_Log_available()) //@todo potential performance problem + native::debug_Log( ss.str(), sev ); + else + std::cerr << ss.str(); + } + log_listener_ptr stderr_listener::add() + { + log_listener_ptr l( new stderr_listener() ); + addListener( l.get() ); + return l; + } + +} // logging +} // yake Property changes on: trunk/yake/src/base/yakeStderrLog.cpp ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/yake/src/bindings.lua/detail/graphics.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/graphics.lua.cpp 2007-08-24 21:25:15 UTC (rev 1821) +++ trunk/yake/src/bindings.lua/detail/graphics.lua.cpp 2007-08-27 13:45:58 UTC (rev 1822) @@ -1,182 +1,182 @@ -/* - ------------------------------------------------------------------------------------ - This file is part of YAKE - Copyright (c) 2004 - 2008 The YAKE Team - For the latest information visit http://www.yake.org - ------------------------------------------------------------------------------------ - This program is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free Software - Foundation; either version 2 of the License, or (at your option) any later - version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with - this program; if not, write to the Free Software Foundation, Inc., 59 Temple - Place - Suite 330, Boston, MA 02111-1307, USA, or go to - http://www.gnu.org/copyleft/lesser.txt. - ------------------------------------------------------------------------------------ - If you are interested in another license model contact the Yake Team via - E-Mail: te...@ya.... - For more information see the LICENSE file in the root directory of the - source code distribution. - ------------------------------------------------------------------------------------ -*/ -#include <yake/config.h> -#if YAKE_ENABLE_LUA_GRAPHICS == 1 - -// See task.lua.cpp -#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> - -#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! - -#include <yake/base/templates/yakeSmartAssert.h> -#include <yake/base/yake.h> -#include <yake/graphics/yakeGraphics.h> - -#include <yake/bindings.lua/detail/private.h> -#include <yake/bindings.lua/common/yake.lua.any_converter.h> - -#include <luabind/discard_result_policy.hpp> -#include <luabind/iterator_policy.hpp> -#include <luabind/operator.hpp> - -namespace yake { -namespace graphics { - ISceneNode* ISceneNode_getChildByName_NameOnly(ISceneNode* n, const String& name) - { - return (n ? n->getChildByName(name,false) : 0); - } - ISceneNode* IWorld_createSceneNode_NoName(IWorld* w) - { - return (w ? w->createSceneNode() : 0); - } - - void bind( lua_State* L ) - { - YAKE_ASSERT( L ); - if (!L) - return; - - using namespace luabind; - -#define YAKE_GRAPHICS_MODULE L, "yake" - - module( YAKE_GRAPHICS_MODULE ) - [ - namespace_("graphics") - [ - class_<ISceneNode,Movable>("SceneNode") - .enum_("TransformSpace") - [ - value("TS_LOCAL",ISceneNode::TS_LOCAL), - value("TS_PARENT",ISceneNode::TS_PARENT), - value("TS_WORLD",ISceneNode::TS_WORLD) - ] - .property("name", &ISceneNode::getName, &ISceneNode::setName) - .property("scale", &ISceneNode::getScale, &ISceneNode::setScale) - .property("parent", &ISceneNode::getParent) - .def("setInheritScale", &ISceneNode::setInheritScale) - .def("addChild", &ISceneNode::addChildNode) - .def("createChildNode", &ISceneNode::createChildNode) - .def("attach", &ISceneNode::attachEntity) - .def("attach", &ISceneNode::attachCamera) - .def("attach", &ISceneNode::attachLight) - .def("attach", &ISceneNode::attachParticleSystem) - .def("detach", (void(ISceneNode::*)(IEntity*))&ISceneNode::detach) - .def("detach", (void(ISceneNode::*)(ILight*))&ISceneNode::detach) - .def("detach", (void(ISceneNode::*)(ICamera*))&ISceneNode::detach) - .def("detach", (void(ISceneNode::*)(IParticleSystem*))&ISceneNode::detach) - .def("getChildByName", &ISceneNode::getChildByName) - .def("getChildByName", &ISceneNode_getChildByName_NameOnly) - .def("translate", &ISceneNode::translate) - .def("rotate", &ISceneNode::rotate) - , - cl... [truncated message content] |
From: <psy...@us...> - 2007-08-24 21:25:15
|
Revision: 1821 http://yake.svn.sourceforge.net/yake/?rev=1821&view=rev Author: psyclonist Date: 2007-08-24 14:25:15 -0700 (Fri, 24 Aug 2007) Log Message: ----------- [res] more detailed assertions Modified Paths: -------------- trunk/yake/src/res/source.cpp trunk/yake/src/res/source_manager.cpp Modified: trunk/yake/src/res/source.cpp =================================================================== --- trunk/yake/src/res/source.cpp 2007-08-24 21:24:14 UTC (rev 1820) +++ trunk/yake/src/res/source.cpp 2007-08-24 21:25:15 UTC (rev 1821) @@ -46,7 +46,8 @@ bool FileSource::exists(const Location& loc) const { struct stat s; - const int code = ::stat(loc.c_str(), &s); + const int code = ::stat(loc.c_str(), &s); + //debugging only: std::cout << "FileSource.exists(" << loc << "): " << code << "\n"; return (code == 0); } Modified: trunk/yake/src/res/source_manager.cpp =================================================================== --- trunk/yake/src/res/source_manager.cpp 2007-08-24 21:24:14 UTC (rev 1820) +++ trunk/yake/src/res/source_manager.cpp 2007-08-24 21:25:15 UTC (rev 1821) @@ -42,7 +42,7 @@ void SourceManager::addSource(const SourceId& id, const SourceFactory& factory, const Location& locBase) { SourcePtr source = factory.create( id ); - assert( source ); + YAKE_ASSERT( source )(id)(locBase).debug("failed to add source"); addSource( source, locBase ); } void SourceManager::addSource(const SourceId& id, const Location& locBase) @@ -58,7 +58,7 @@ const Location locToTest = locBase + loc; if (src->exists(locToTest)) { - assert( it->second ); + YAKE_ASSERT( it->second )(loc)(locBase)(locToTest).debug("source creator is invalid (0)"); return FindResult( locToTest, src ); } } @@ -66,17 +66,18 @@ } DataStreamPtr SourceManager::open(const FindResult& what) { - assert( what.isValid() ); + YAKE_ASSERT( what.isValid() )(what.location()); if (!what.isValid()) return DataStreamPtr(); - assert( what.source_ != 0 ); - assert( !what.location_.empty() ); + YAKE_ASSERT( what.source_ != 0 )(what.location()); + YAKE_ASSERT( !what.location_.empty() ); DataStreamPtr stream = what.source_->open( what.location_ ); - assert( stream && "failed to open data stream" ); + YAKE_ASSERT( stream )(what.location()).debug( "failed to open data stream" ); return stream; } DataStreamPtr SourceManager::open(const Location& loc) - { + { + YAKE_ASSERT( !sources_.empty() )(loc).debug("no sources to search in"); for (SourceMap::const_iterator it = sources_.begin(); it != sources_.end(); ++it) { const Location& locBase = it->first; @@ -84,12 +85,12 @@ const Location locToTest = locBase + loc; if (src->exists(locToTest)) { - assert( it->second ); + YAKE_ASSERT( it->second )(loc)(locBase)(locToTest); DataStreamPtr stream = it->second->open(locToTest); return stream; } } - assert( false && "failed to open data stream: could not locate" ); + YAKE_ASSERT( false )(loc).debug( "failed to open data stream: could not locate" ); return DataStreamPtr(); } SourceManager& SourceManager::global() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-24 21:24:21
|
Revision: 1820 http://yake.svn.sourceforge.net/yake/?rev=1820&view=rev Author: psyclonist Date: 2007-08-24 14:24:14 -0700 (Fri, 24 Aug 2007) Log Message: ----------- [base:Linux] fixed .so loading and debug output Modified Paths: -------------- trunk/yake/src/base/native/Linux/yakeDebug.cpp trunk/yake/src/base/native/Linux/yakeNativeLibrary.cpp Modified: trunk/yake/src/base/native/Linux/yakeDebug.cpp =================================================================== --- trunk/yake/src/base/native/Linux/yakeDebug.cpp 2007-08-24 21:22:03 UTC (rev 1819) +++ trunk/yake/src/base/native/Linux/yakeDebug.cpp 2007-08-24 21:24:14 UTC (rev 1820) @@ -62,7 +62,7 @@ void debug_Print( const char* string ) { - std::cout << string; + std::cout << string << "\n"; } bool debug_AssertFailed( const char* pszMessage, Modified: trunk/yake/src/base/native/Linux/yakeNativeLibrary.cpp =================================================================== --- trunk/yake/src/base/native/Linux/yakeNativeLibrary.cpp 2007-08-24 21:22:03 UTC (rev 1819) +++ trunk/yake/src/base/native/Linux/yakeNativeLibrary.cpp 2007-08-24 21:24:14 UTC (rev 1820) @@ -60,52 +60,42 @@ { assert( pFilename && "Invalid filename." ); - // Due to Linux libraries naming we decided to add some "brand" prefix - String yakeLibPrefix( "libyake" ); - String yappLibPrefix( "libyapp" ); + String name( pFilename ); - String yakeName( yakeLibPrefix + String( pFilename ) ); - String yappName( yappLibPrefix + String( pFilename ) ); - // dlopen() does not add .so to the filename, like windows does for .dll - if ( yakeName.substr( yakeName.length() - 3, 3 ) != ".so" ) - yakeName += ".so"; + if ( name.size() > 3 && name.substr( name.length() - 3, 3 ) != ".so" ) + name += ".so"; - // the same for other prefix - if ( yappName.substr( yappName.length() - 3, 3 ) != ".so" ) - yappName += ".so"; - - String name = yakeName; - #ifdef YAKE_DEBUG - debug_Print( String( "Trying to load " + name ).c_str() ); + debug_Print( String( "yake:Trying to load " + name ).c_str() ); #endif LibraryHandle handle = ( LibraryHandle )dlopen( name.c_str(), RTLD_LAZY ); - // trying to load library with libyapp prefix + // trying to load library with "lib" prefix if ( handle == NULL ) { #ifdef YAKE_DEBUG - debug_Print( String( "dlerror returned:" + String( dlerror() ) ).c_str() ); + debug_Print( String( "yake:dlerror returned:" + String( dlerror() ) ).c_str() ); #endif - - name = yappName; - + + name = "lib" + name; #ifdef YAKE_DEBUG - debug_Print( String( "Now trying to load " + name ).c_str() ); + debug_Print( String( "yake:Trying to load " + name ).c_str() ); #endif - handle = ( LibraryHandle )dlopen( name.c_str(), RTLD_LAZY ); - } - if ( handle == NULL ) - throw "Failed to load " + String( pFilename ) - + String( " with both libyake and libyapp prefixes due to " ) - + String( dlerror() ); + if ( handle == NULL ) + { + throw "Failed to load " + name + " (" + pFilename + ") due to " + String( dlerror() ); +#ifdef YAKE_DEBUG + debug_Print( String( "yake:dlerror returned:" + String( dlerror() ) ).c_str() ); +#endif + } + } #ifdef YAKE_DEBUG - debug_Print( String( "successfully loaded " + name ).c_str() ); + debug_Print( String( "yake:successfully loaded " + name ).c_str() ); #endif return handle; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-24 21:22:06
|
Revision: 1819 http://yake.svn.sourceforge.net/yake/?rev=1819&view=rev Author: psyclonist Date: 2007-08-24 14:22:03 -0700 (Fri, 24 Aug 2007) Log Message: ----------- [premake] add yake.res as dependency for yake.raf [raf] reconfigured raf::Application to use ini-style configuration 'raf_common.cfg' [sample:res/lua1] reconfigured to use custom configuration file to setup resource paths [base] added ini style configuration loader/holder/accessor: yake::IniFile [scriptingLua] use luaL_loadbuffer() instead of luaL_loadstring() Modified Paths: -------------- trunk/yake/samples/res/lua1/demo.cpp trunk/yake/scripts/premake/yake.lua trunk/yake/src/base/yakeConfigFile.cpp trunk/yake/src/plugins/scriptingLua/ScriptingSystemLua.cpp trunk/yake/src/raf/yakeApplication.cpp trunk/yake/yake/base/yakeConfigFile.h trunk/yake/yake/raf/yakeApplication.h Added Paths: ----------- trunk/yake/samples/bin/debug/raf_common.cfg trunk/yake/samples/bin/debug/sampleResLua1.cfg trunk/yake/samples/bin/release/raf_common.cfg trunk/yake/samples/bin/release/sampleResLua1.cfg Added: trunk/yake/samples/bin/debug/raf_common.cfg =================================================================== --- trunk/yake/samples/bin/debug/raf_common.cfg (rev 0) +++ trunk/yake/samples/bin/debug/raf_common.cfg 2007-08-24 21:22:03 UTC (rev 1819) @@ -0,0 +1,23 @@ +#----------------------------------- +[raf.options] +useCEGUI=no + +#----------------------------------- +[raf.startup.libraries] +# Libraries to be loaded automatically at startup + +scriptingLua + +#----------------------------------- +[raf.startup.systems] +# System to be created & initialized automatically + +scripting=lua + +#----------------------------------- +[raf.startup.scripts] +# Scripts to be run at startup + +# run = <scripting_system>,<filename> +run=lua,raf1_startup.lua +#run=ruby,raf1_startup.ruby Added: trunk/yake/samples/bin/debug/sampleResLua1.cfg =================================================================== --- trunk/yake/samples/bin/debug/sampleResLua1.cfg (rev 0) +++ trunk/yake/samples/bin/debug/sampleResLua1.cfg 2007-08-24 21:22:03 UTC (rev 1819) @@ -0,0 +1,2 @@ +[resource.sources] # <- evaluated by RAF +file=../../../common/media/scripts/ # <- do NOT forget trialing '/' !! Added: trunk/yake/samples/bin/release/raf_common.cfg =================================================================== --- trunk/yake/samples/bin/release/raf_common.cfg (rev 0) +++ trunk/yake/samples/bin/release/raf_common.cfg 2007-08-24 21:22:03 UTC (rev 1819) @@ -0,0 +1,14 @@ +[raf.options] +useCEGUI=no + +[raf.startup.libraries] +scriptingLua + +[raf.startup.systems] +scripting=lua + +[raf.startup.scripts] + +# run = <scripting_system>,<filename> +run=lua,raf1_startup.lua +#run=ruby,raf1_startup.ruby Added: trunk/yake/samples/bin/release/sampleResLua1.cfg =================================================================== --- trunk/yake/samples/bin/release/sampleResLua1.cfg (rev 0) +++ trunk/yake/samples/bin/release/sampleResLua1.cfg 2007-08-24 21:22:03 UTC (rev 1819) @@ -0,0 +1,2 @@ +[resource.sources] # <- evaluated by RAF +file=../../../common/media/scripts/ # <- do NOT forget trialing '/' !! Modified: trunk/yake/samples/res/lua1/demo.cpp =================================================================== --- trunk/yake/samples/res/lua1/demo.cpp 2007-08-24 17:55:44 UTC (rev 1818) +++ trunk/yake/samples/res/lua1/demo.cpp 2007-08-24 21:22:03 UTC (rev 1819) @@ -9,21 +9,14 @@ using namespace yake; -/** Configuration of the application */ -struct TheConfiguration : public raf::ApplicationConfiguration -{ - virtual StringVector getLibraries() - { return MakeStringVector() << YAKE_LIB("scriptingLua"); } - - virtual StringVector getScriptingSystems() - { return MakeStringVector() << "lua"; } -}; - /** The mighty application itself! */ -class TheApp : public raf::ExampleApplication<TheConfiguration> +class TheApp : public raf::ExampleApplication<> { public: - TheApp() {} + TheApp() + { + getConfiguration().get().load("sampleResLua1.cfg"); + } protected: virtual bool onRun() { @@ -41,13 +34,10 @@ luabind::globals(L)["app"] = &app_; */ } - // - res::SourceFactory::global().reg<res::FileSource>("file"); - res::SourceManager::global().addSource("file","../../../common/media/scripts/"); - //scripting::LuaScriptManager::global().create("res1.lua"); - //res::SourceManager::global().find("res1.lua"); - // + // NB Resource configuration is done in RAF application (via sampleResLua1.cfg). + + // Load & run script try { scripting::ScriptPtr script = sys->createScriptFromFile("res1.lua"); @@ -62,6 +52,7 @@ } }; +#include <yake/base/yakeConfigFile.h> int main( int argc, char** argv ) { // Use default executor for convenience. Modified: trunk/yake/scripts/premake/yake.lua =================================================================== --- trunk/yake/scripts/premake/yake.lua 2007-08-24 17:55:44 UTC (rev 1818) +++ trunk/yake/scripts/premake/yake.lua 2007-08-24 21:22:03 UTC (rev 1819) @@ -210,6 +210,7 @@ -------------------------------------- makeComponent("raf","YAKE_RAF_EXPORTS") addDependency("base") +addDependency("res") addDependency("audio") addDependency("input") addDependency("graphics") Modified: trunk/yake/src/base/yakeConfigFile.cpp =================================================================== --- trunk/yake/src/base/yakeConfigFile.cpp 2007-08-24 17:55:44 UTC (rev 1818) +++ trunk/yake/src/base/yakeConfigFile.cpp 2007-08-24 21:22:03 UTC (rev 1819) @@ -29,7 +29,6 @@ #include <yake/base/yakeConfigFile.h> namespace yake { -namespace base { namespace detail { } // namespace detail @@ -145,5 +144,136 @@ boost::property_tree::write_xml(out,*tree_); } -} // base + //----------------------------------------------------- + + IniFile::IniFile() + { + } + /* + ini::const_key_iterator ini::begin(const String& section) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return empty_.end(); + return itSect->second.begin(); + } + ini::const_key_iterator ini::end(const String& section) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return empty_.end(); + return itSect->second.end(); + } + */ + StringVector IniFile::getKeys(const String& section) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return StringVector(); + KeyValueMap::const_iterator it = itSect->second.begin(); + KeyValueMap::const_iterator itEnd = itSect->second.end(); + StringVector ret; + for (; it != itEnd; ++it) + ret.push_back( it->first ); + return ret; + } + StringPairVector IniFile::getKeysAndValues(const String& section) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return StringPairVector(); + StringPairVector ret; + YAKE_FOR_EACH( KeyValueMap::const_iterator, itKey, itSect->second ) + { + const ValueList& values = itKey->second; + YAKE_FOR_EACH( ValueList::const_iterator, itValue, values ) + ret.push_back( StringPair( itKey->first, *itValue ) ); + } + return ret; + } + IniFile::KeyValueMap IniFile::getKeysAndValues2(const String& section) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return IniFile::KeyValueMap(); + return itSect->second; + } + bool IniFile::hasSection(const String& section) const + { + Sections::const_iterator itSect = sections_.find(section); + return (itSect != sections_.end()); + } + IniFile::value IniFile::getFirstValue(const String& section, const String& key) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return false; + KeyValueMap::const_iterator itKey = itSect->second.find(key); + if (itKey == itSect->second.end()) + return false; + const ValueList& values = itKey->second; + if (values.empty()) + return false; + return values.front(); + } + StringVector IniFile::getAllValues(const String& section, const String& key) const + { + Sections::const_iterator itSect = sections_.find(section); + if (itSect == sections_.end()) + return StringVector(); + KeyValueMap::const_iterator itKey = itSect->second.find(key); + if (itKey == itSect->second.end()) + return StringVector(); + const ValueList& values = itKey->second; + return values; + } + bool IniFile::load(const String& filename) + { + std::ifstream in(filename.c_str(), std::ios::in); + if (!in) + return false; + String currSection; + String line; + while (std::getline(in,line)) + { + StringUtil::trim( line, true, true ); // trim left and right + // skip comments (full line and trailing ones) + { + String::size_type commentStart = line.find("#"); + if (String::npos != commentStart) + { + line = line.substr(0,commentStart); + StringUtil::trim(line); + } + } + if (line.empty()) // skip empty lines + continue; + // + if (line[0] == '[') + { + String::size_type endMarker = line.find("]"); + YAKE_ASSERT( endMarker != String::npos ).debug("syntax error in section declaration: missing ']'."); + if (endMarker == String::npos) + continue; + currSection = line.substr(1,endMarker-1); + StringUtil::trim(currSection); + } + else + { + String key,value; + String::size_type splitAt = line.find("="); + if (splitAt != String::npos) + { + key = line.substr(0,splitAt); + value = line.substr(splitAt+1); + StringUtil::trim(key); + StringUtil::trim(value); + } + else + key = line; + sections_[currSection][key].push_back( value ); + } + } + return true; + } } // yake Modified: trunk/yake/src/plugins/scriptingLua/ScriptingSystemLua.cpp =================================================================== --- trunk/yake/src/plugins/scriptingLua/ScriptingSystemLua.cpp 2007-08-24 17:55:44 UTC (rev 1818) +++ trunk/yake/src/plugins/scriptingLua/ScriptingSystemLua.cpp 2007-08-24 21:22:03 UTC (rev 1819) @@ -132,11 +132,13 @@ const LuaScript::CodeBuffer& code = pLuaScript->getData(); if (code.empty()) return; //nothing to do + const char* str_code = reinterpret_cast<const char*>(&code[0]); lua_pushcclosure(mLuaState, &pcall_handler, 0); + if (luaL_loadbuffer(mLuaState,str_code,std::strlen(str_code),"chunk_name")) //if (luaL_loadbuffer(mLuaState,(const char*)&code[0],code.size(),"buffer")) - if (luaL_loadstring(mLuaState,(const char*)&code[0])) + //if (luaL_loadstring(mLuaState,(const char*)&code[0])) //if (luaL_loadfile(mLuaState, rFileName.c_str())) { err = lua_tostring(mLuaState, -1); Modified: trunk/yake/src/raf/yakeApplication.cpp =================================================================== --- trunk/yake/src/raf/yakeApplication.cpp 2007-08-24 17:55:44 UTC (rev 1818) +++ trunk/yake/src/raf/yakeApplication.cpp 2007-08-24 21:22:03 UTC (rev 1819) @@ -39,6 +39,8 @@ //# pragma comment(lib,"CEGUIBase.lib") #endif #endif +#include <yake/base/yakeConfigFile.h> +#include <yake/res/res.h> namespace yake { namespace raf { @@ -343,29 +345,80 @@ // YAKE_LOG_INFORMATION("raf","loading configuration..."); - ApplicationConfiguration& cfg = getConfiguration(); - mUseExtGraphicsSystem = cfg.useExternalGraphicsSystem().get() != 0; + // + ApplicationConfiguration& cfg = this->getConfiguration(); - // load libs - YAKE_LOG_INFORMATION("raf","loading libraries..."); - StringVector libs = cfg.getLibraries(); - ConstVectorIterator<StringVector> itLib( libs ); - while (itLib.hasMoreElements()) + // load from file + IniFile& cfgfile = cfg.get(); + if (!cfgfile.load("raf_common.cfg")) { - loadLibrary(itLib.getNext()); + YAKE_LOG_ERROR("raf","failed to load raf_common.cfg"); + return false; } + // setup resource configuration + { // register global 'file' source + YAKE_LOG_INFORMATION("raf","registering (global) 'file' resource source"); + res::SourceFactory::global().reg<res::FileSource>("file"); + } + { // load global sources + StringPairVector sources = cfgfile.getKeysAndValues("resource.sources"); + YAKE_FOR_EACH( StringPairVector::const_iterator, it, sources ) + { + const String& id = it->first; + const String& locationBase = it->second; + YAKE_LOG_INFORMATION("raf","adding (global) '"+id+"' source '"+locationBase+"'..."); + res::SourceManager::global().addSource(id, locationBase); + } + } + + {// load libraries + StringVector plugins = cfgfile.getKeys("raf.startup.libraries"); + YAKE_FOR_EACH( StringVector::const_iterator, it, plugins ) + { + const String libname = YAKE_LIB(*it); + YAKE_LOG_INFORMATION("raf","loading '" + libname + "'..."); + loadLibrary(libname); + } + } + + // use external graphics system? + mUseExtGraphicsSystem = cfg.getExternalGraphicsSystem() != 0; + if (mUseExtGraphicsSystem) + mGraphicsSystems["default"] = cfg.getExternalGraphicsSystem(); + + { // create & init systems + // e.g. "scripting=lua" + IniFile::KeyValueMap systems = cfgfile.getKeysAndValues2("raf.startup.systems"); + YAKE_FOR_EACH( IniFile::KeyValueMap::const_iterator, it, systems ) + { + const String& systype = it->first; + const IniFile::ValueList& sysnames = it->second; + YAKE_LOG_INFORMATION("raf","creating and initialising systems of type '"+systype+"'..."); + if (systype == "scripting") + loadAndInitSystems<scripting::IScriptingSystem>( sysnames, mScriptingSystems ); + else if (systype == "audio") + loadAndInitSystems<audio::IAudioSystem>( sysnames, mAudioSystems ); + else if (systype == "graphics") + { + if (mUseExtGraphicsSystem) + { + YAKE_LOG_WARNING("raf","ignoring graphics systems as an external one has been specified"); + continue; + } + else + loadAndInitSystems<graphics::IGraphicsSystem>( sysnames, mGraphicsSystems ); + } + else if (systype == "physics") + loadAndInitSystems<physics::IPhysicsSystem>( sysnames, mPhysicsSystems ); + else if (systype == "input") + loadAndInitSystems<input::IInputSystem>( sysnames, mInputSystems ); + } + } + // load & init systems - YAKE_LOG_INFORMATION("raf","loading and initialising systems..."); - loadAndInitSystems<scripting::IScriptingSystem>( cfg.getScriptingSystems(), mScriptingSystems ); - loadAndInitSystems<audio::IAudioSystem>( cfg.getAudioSystems(), mAudioSystems ); - if (mUseExtGraphicsSystem) - mGraphicsSystems["default"] = cfg.useExternalGraphicsSystem(); - else - loadAndInitSystems<graphics::IGraphicsSystem>( cfg.getGraphicsSystems(), mGraphicsSystems ); - loadAndInitSystems<physics::IPhysicsSystem>( cfg.getPhysicsSystems(), mPhysicsSystems ); - loadAndInitSystems<input::IInputSystem>( cfg.getInputSystems(), mInputSystems ); + YAKE_LOG_INFORMATION("raf","2nd stage initialisations ..."); if (!mInputSystems.empty()) initInput(); if (!mPhysicsSystems.empty()) @@ -373,10 +426,9 @@ #if YAKE_RAF_USES_CEGUI == 1 // CEGUI - if (cfg.loadCEGUI()) - { + IniFile::value useCEGUI = cfgfile.getFirstValue("raf.options","useCEGUI"); + if (StringUtil::parseBool( *useCEGUI )) initCEGUI(); - } #endif // application state machine Modified: trunk/yake/yake/base/yakeConfigFile.h =================================================================== --- trunk/yake/yake/base/yakeConfigFile.h 2007-08-24 17:55:44 UTC (rev 1818) +++ trunk/yake/yake/base/yakeConfigFile.h 2007-08-24 21:22:03 UTC (rev 1819) @@ -32,6 +32,7 @@ # include <yake/base/yakePrerequisites.h> #endif #include <yake/base/templates/yakePointer.h> +#include <yake/base/yakeNoncopyable.h> // for Configuration #if YAKE_COMPILER == COMPILER_MSVC @@ -61,7 +62,6 @@ #endif namespace yake { -namespace base { struct YAKE_BASE_API Configuration { @@ -152,10 +152,36 @@ String prefix_; }; -} // base + /** NB Multiple keys in a single section allowed! */ + struct YAKE_BASE_API IniFile : public noncopyable + { + public: + typedef StringVector ValueList; + typedef std::map<String,ValueList> KeyValueMap; - // pull in type - typedef base::Configuration Configuration; + public: + typedef boost::optional<String> value; + IniFile(); + bool load(const String& filename); + + value getFirstValue(const String& section, const String& key) const; + StringVector getAllValues(const String& section, const String& key) const; + + bool hasSection(const String& section) const; + StringVector getKeys(const String& section) const; + StringPairVector getKeysAndValues(const String& section) const; + KeyValueMap getKeysAndValues2(const String& section) const; + + private: + typedef std::map<String,KeyValueMap> Sections; + public: + typedef KeyValueMap::const_iterator const_key_iterator; + //const_key_iterator begin(const String& section) const; + //const_key_iterator end(const String& section) const; + private: + Sections sections_; + KeyValueMap empty_; + }; } // yake #endif // YAKE_BASE_CONFIGFILE_H Modified: trunk/yake/yake/raf/yakeApplication.h =================================================================== --- trunk/yake/yake/raf/yakeApplication.h 2007-08-24 17:55:44 UTC (rev 1818) +++ trunk/yake/yake/raf/yakeApplication.h 2007-08-24 21:22:03 UTC (rev 1819) @@ -28,6 +28,7 @@ #define YAKE_RAF_APPLICATION_H #include <yake/base/yakeLibrary.h> +#include <yake/base/yakeConfigFile.h> namespace yake { namespace audio { @@ -60,34 +61,22 @@ struct ApplicationConfiguration { - virtual ~ApplicationConfiguration() {} + IniFile& get() + { return cfg_; } + const IniFile& get() const + { return cfg_; } - /** List the libraries to load. - For example, "graphicsOgre" for OGRE3D graphics or - "physicsNx" for the Novodex based physics plugin. - */ - virtual StringVector getLibraries() = 0; - - /** An empty list will not create any systems. - If the list contains an empty string, then the default system for the specific type will - be created! (using create_default<>()) - */ - virtual StringVector getGraphicsSystems() - { return MakeStringVector(); } - virtual StringVector getScriptingSystems() - { return MakeStringVector(); } - virtual StringVector getAudioSystems() - { return MakeStringVector(); } - virtual StringVector getPhysicsSystems() - { return MakeStringVector(); } - virtual StringVector getInputSystems() - { return MakeStringVector(); } - - virtual SharedPtr<graphics::IGraphicsSystem> useExternalGraphicsSystem() { return SharedPtr<graphics::IGraphicsSystem>(); } -#if YAKE_RAF_USES_CEGUI == 1 - /** I could need some Dihydrogendinatriumethylendiamintetraacetat. */ - virtual bool loadCEGUI() { return false; } -#endif + void setExternalGraphicsSystem(SharedPtr<graphics::IGraphicsSystem> gfx) + { + extGfx_ = gfx; + } + SharedPtr<graphics::IGraphicsSystem> getExternalGraphicsSystem() const + { + return extGfx_; + } + private: + IniFile cfg_; + SharedPtr<graphics::IGraphicsSystem> extGfx_; }; class YAKE_RAF_API Application @@ -210,7 +199,7 @@ One thing less to worry about. Usage: class MyApp : public ExampleApplication<MyConfig> {} */ - template<class ConfigType> + template<class ConfigType = raf::ApplicationConfiguration> class ExampleApplication : public raf::Application { public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-24 17:55:46
|
Revision: 1818 http://yake.svn.sourceforge.net/yake/?rev=1818&view=rev Author: psyclonist Date: 2007-08-24 10:55:44 -0700 (Fri, 24 Aug 2007) Log Message: ----------- [scripting] fixed smart pointer type (gcc) Modified Paths: -------------- trunk/yake/yake/scripting/yakeScriptingSystem.h Modified: trunk/yake/yake/scripting/yakeScriptingSystem.h =================================================================== --- trunk/yake/yake/scripting/yakeScriptingSystem.h 2007-08-24 17:49:39 UTC (rev 1817) +++ trunk/yake/yake/scripting/yakeScriptingSystem.h 2007-08-24 17:55:44 UTC (rev 1818) @@ -69,9 +69,9 @@ class IVM; class IScript; class IBinder; - typedef SharedPtr<IVM> VMPtr; - typedef SharedPtr<IScript> ScriptPtr; - typedef SharedPtr<IBinder> BinderPtr; + typedef boost::shared_ptr<IVM> VMPtr; + typedef boost::shared_ptr<IScript> ScriptPtr; + typedef boost::shared_ptr<IBinder> BinderPtr; class YAKE_SCRIPTING_API IBinder { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-24 17:49:37
|
Revision: 1817 http://yake.svn.sourceforge.net/yake/?rev=1817&view=rev Author: psyclonist Date: 2007-08-24 10:49:39 -0700 (Fri, 24 Aug 2007) Log Message: ----------- [res] fixed assertions and use of posix compliant stat() Modified Paths: -------------- trunk/yake/src/res/datastream.cpp trunk/yake/src/res/source.cpp trunk/yake/yake/res/source.h Modified: trunk/yake/src/res/datastream.cpp =================================================================== --- trunk/yake/src/res/datastream.cpp 2007-08-23 23:29:00 UTC (rev 1816) +++ trunk/yake/src/res/datastream.cpp 2007-08-24 17:49:39 UTC (rev 1817) @@ -40,15 +40,15 @@ { assert( in_.is_open() ); - struct _stat32 s; - const int code = _stat32(fn.c_str(), &s); - assert(code == 0); + struct stat s; + const int code = ::stat(fn.c_str(), &s); + YAKE_ASSERT(code == 0)(code); // @todo throw exception of ENOENT or ENOTDIR? size_ = s.st_size; } size_t FileDataStream::read(void * out, size_t size) { - assert( in_.is_open() ); - assert( !eof() ); + YAKE_ASSERT( in_.is_open() ); + YAKE_ASSERT( !eof() ); if (eof()) return 0; // NB use readsome() for async Modified: trunk/yake/src/res/source.cpp =================================================================== --- trunk/yake/src/res/source.cpp 2007-08-23 23:29:00 UTC (rev 1816) +++ trunk/yake/src/res/source.cpp 2007-08-24 17:49:39 UTC (rev 1817) @@ -28,6 +28,7 @@ #include "yake/res/source.h" #include <sys/stat.h> +#include <sys/types.h> namespace yake { namespace res { @@ -44,8 +45,8 @@ } bool FileSource::exists(const Location& loc) const { - struct _stat32 s; - const int code = _stat32(loc.c_str(), &s); + struct stat s; + const int code = ::stat(loc.c_str(), &s); return (code == 0); } @@ -53,10 +54,10 @@ void SourceFactory::reg(const SourceId& id, CreateSourceFn creator) { - assert( !id.empty() ); + YAKE_ASSERT( !id.empty() ); if (id.empty()) throw InvalidInputException("id is empty/null"); - assert( creator ); + YAKE_ASSERT( creator )(id); if (!creator) throw InvalidInputException("creator function is null"); creators_[ id ] = creator; @@ -64,13 +65,13 @@ SourcePtr SourceFactory::create(const SourceId& id) const { CreatorMap::const_iterator it = creators_.find(id); - //assert( it != creators_.end() ); + //YAKE_ASSERT( it != creators_.end() )(id); if (it == creators_.end()) { //return SourcePtr(); throw UnknownResourceSourceTypeException(id); } - assert( it->second ); + YAKE_ASSERT( it->second )(id); return SourcePtr(it->second()); } SourceFactory& SourceFactory::global() Modified: trunk/yake/yake/res/source.h =================================================================== --- trunk/yake/yake/res/source.h 2007-08-23 23:29:00 UTC (rev 1816) +++ trunk/yake/yake/res/source.h 2007-08-24 17:49:39 UTC (rev 1817) @@ -32,6 +32,7 @@ #include <deque> #include <boost/shared_ptr.hpp> #include <boost/function.hpp> +#include <boost/bind.hpp> namespace yake { namespace res { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-23 23:28:57
|
Revision: 1816 http://yake.svn.sourceforge.net/yake/?rev=1816&view=rev Author: psyclonist Date: 2007-08-23 16:29:00 -0700 (Thu, 23 Aug 2007) Log Message: ----------- updated .suo Modified Paths: -------------- trunk/yake/scripts/msvc80/yake.suo Modified: trunk/yake/scripts/msvc80/yake.suo =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-23 23:28:45
|
Revision: 1815 http://yake.svn.sourceforge.net/yake/?rev=1815&view=rev Author: psyclonist Date: 2007-08-23 16:28:48 -0700 (Thu, 23 Aug 2007) Log Message: ----------- * [demo] improved 'raf/lua1' (aka "ninja"): Lua movement handler now uses frame handler Modified Paths: -------------- trunk/yake/common/media/scripts/raf1.lua trunk/yake/samples/raf/lua1/demo.cpp Modified: trunk/yake/common/media/scripts/raf1.lua =================================================================== --- trunk/yake/common/media/scripts/raf1.lua 2007-08-23 23:27:11 UTC (rev 1814) +++ trunk/yake/common/media/scripts/raf1.lua 2007-08-23 23:28:48 UTC (rev 1815) @@ -39,6 +39,8 @@ -- Configure input -------------------------------------- +local activeKeys = {} -- Store the keys that are active in current frame. + -- We demonstrate two ways to bind Lua callbacks to a keyboard action. -- #1 demonstrates the details -- #2 shows how to achieve the same thing fast and Lua-style @@ -54,7 +56,7 @@ -- Our Lua callback handler: function onLeft() - cam:translate(yake.Vector3(-1,0,0)) + activeKeys["left"] = true end actionMap:connectToAction(idLeft,onLeft) -- by Action ID @@ -64,7 +66,7 @@ actionMap:reg("right", input.KeyboardActionCondition(app.keyboard, input.KC_RIGHT, input.KAM_CONTINUOUS)) actionMap:connectToAction("right", function() - cam:translate(yake.Vector3(1,0,0)) + activeKeys["right"] = true end) ------- Let's define a few helper functions to make things easier: @@ -80,10 +82,28 @@ createKeyAction("forward", input.KC_UP, input.KAM_CONTINUOUS) bindAction("forward", function() - cam:translate(yake.Vector3(0,0,-1)) + activeKeys["forward"] = true end) createKeyAction("reverse", input.KC_DOWN, input.KAM_CONTINUOUS) bindAction("reverse", function() - cam:translate(yake.Vector3(0,0,1)) + activeKeys["reverse"] = true end) + +----------------------------------- +function onFrame(timeElapsed) + local distance = 25 * timeElapsed + for k,v in pairs(activeKeys) do + if k == "left" then + cam:translate( -1 * yake.Vector3.UnitX * distance ) + elseif k == "right" then + cam:translate( 1 * yake.Vector3.UnitX * distance ) + elseif k == "forward" then + cam:translate( -1 * yake.Vector3.UnitZ * distance ) + elseif k == "reverse" then + cam:translate( 1 * yake.Vector3.UnitZ * distance ) + end + end + -- prepare for next frame: + activeKeys = {} +end \ No newline at end of file Modified: trunk/yake/samples/raf/lua1/demo.cpp =================================================================== --- trunk/yake/samples/raf/lua1/demo.cpp 2007-08-23 23:27:11 UTC (rev 1814) +++ trunk/yake/samples/raf/lua1/demo.cpp 2007-08-23 23:28:48 UTC (rev 1815) @@ -66,8 +66,7 @@ //bind { - scripting::LuaVM* lvm = static_cast<scripting::LuaVM*>(vm_.get()); - lua_State* L = lvm->getLuaState(); + lua_State* L = static_cast<scripting::LuaVM*>(vm_.get())->getLuaState(); luabind::globals(L)["app"] = &app_; luabind::globals(L)["app"]["actionMap"] = &actionMap_; @@ -86,6 +85,9 @@ virtual void onFrame(const real timeElapsed) { actionMap_.update(); //@todo here OK? ... + + lua_State* L = static_cast<scripting::LuaVM*>(vm_.get())->getLuaState(); + luabind::call_function<void>( L, "onFrame", timeElapsed ); } private: raf::Application& app_; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-23 23:27:11
|
Revision: 1814 http://yake.svn.sourceforge.net/yake/?rev=1814&view=rev Author: psyclonist Date: 2007-08-23 16:27:11 -0700 (Thu, 23 Aug 2007) Log Message: ----------- * [bindings.lua] added more bindings Modified Paths: -------------- trunk/yake/src/bindings.lua/detail/base.lua.cpp Modified: trunk/yake/src/bindings.lua/detail/base.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/base.lua.cpp 2007-08-23 23:26:41 UTC (rev 1813) +++ trunk/yake/src/bindings.lua/detail/base.lua.cpp 2007-08-23 23:27:11 UTC (rev 1814) @@ -128,6 +128,9 @@ .def(const_self * other<real>()) .def(const_self * Quaternion()) .def(const_self * Matrix3()) + .def(real() * const_self) + .def(Quaternion() * const_self) + .def(Matrix3() * const_self) .def(tostring(const_self)) ]; luabind::globals(L)["yake"]["Vector3"]["Zero"] = Vector3::kZero; @@ -153,6 +156,7 @@ .def( constructor<>() ) .def( constructor< Matrix3 const& >() ) .def( "getColumn", &Matrix3::GetColumn ) + .def( "fromAxes", &Matrix3::FromAxes ) .def(const_self * other<Matrix3>()) .def(tostring(const_self)) ]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-23 23:26:39
|
Revision: 1813 http://yake.svn.sourceforge.net/yake/?rev=1813&view=rev Author: psyclonist Date: 2007-08-23 16:26:41 -0700 (Thu, 23 Aug 2007) Log Message: ----------- * [raf] made code more reliable / avoid crashes :) * [base] removed references to deprecated IOutputStream * [various] fixed includes (added missing ones - under certain include conditions) Modified Paths: -------------- trunk/yake/src/raf/yakeRtApplicationState.cpp trunk/yake/yake/base/math/yakeColor.h trunk/yake/yake/base/math/yakeColor.inl trunk/yake/yake/graphics/yakeGraphicalWorld.h trunk/yake/yake/input/yakeInputSystem.h trunk/yake/yake/physics/yakePhysicsCommon.h Modified: trunk/yake/src/raf/yakeRtApplicationState.cpp =================================================================== --- trunk/yake/src/raf/yakeRtApplicationState.cpp 2007-08-23 23:25:11 UTC (rev 1812) +++ trunk/yake/src/raf/yakeRtApplicationState.cpp 2007-08-23 23:26:41 UTC (rev 1813) @@ -44,7 +44,8 @@ {} graphics::ICamera* RtMainState::onCreateDefaultCamera() { - return getGraphicalWorld()->createCamera(); + graphics::IWorld* w = getGraphicalWorld(); + return w ? w->createCamera() : 0; } graphics::IViewport* RtMainState::onCreateDefaultViewport() { @@ -185,7 +186,9 @@ if (!mGWorld.get()) { graphics::IGraphicsSystem* pSys = getApp().getGraphicsSystem(); - YAKE_ASSERT( pSys ); + YAKE_ASSERT( pSys ).debug("no graphics system available"); + if (!pSys) + return 0; mGWorld = pSys->createWorld(); } if (!mGWorld.get()) Modified: trunk/yake/yake/base/math/yakeColor.h =================================================================== --- trunk/yake/yake/base/math/yakeColor.h 2007-08-23 23:25:11 UTC (rev 1812) +++ trunk/yake/yake/base/math/yakeColor.h 2007-08-23 23:26:41 UTC (rev 1813) @@ -97,7 +97,7 @@ real getSquaredLength() const; // The Serialization Function. - base::IOutputStream& operator << (base::IOutputStream& rStream) const; + //base::IOutputStream& operator << (base::IOutputStream& rStream) const; // The Data. union Modified: trunk/yake/yake/base/math/yakeColor.inl =================================================================== --- trunk/yake/yake/base/math/yakeColor.inl 2007-08-23 23:25:11 UTC (rev 1812) +++ trunk/yake/yake/base/math/yakeColor.inl 2007-08-23 23:26:41 UTC (rev 1813) @@ -239,6 +239,7 @@ return ( r * r ) + ( g * g ) + ( b * b ) + ( a * a ); } +/* inline base::IOutputStream& Color::operator << (base::IOutputStream& rStream) const { rStream << r; @@ -247,6 +248,7 @@ rStream << a; return rStream; } +*/ } // math } // yake Modified: trunk/yake/yake/graphics/yakeGraphicalWorld.h =================================================================== --- trunk/yake/yake/graphics/yakeGraphicalWorld.h 2007-08-23 23:25:11 UTC (rev 1812) +++ trunk/yake/yake/graphics/yakeGraphicalWorld.h 2007-08-23 23:26:41 UTC (rev 1813) @@ -34,6 +34,10 @@ #include <yake/graphics/yakeGraphicsSystem.h> #include <yake/graphics/yakeEntity.h> #include <yake/base/templates/yakeSignals.h> +#include <yake/base/math/yakeColor.h> +#include <yake/base/math/yakeRay.h> +#include <yake/base/math/yakeMatrix4.h> +#include <yake/base/templates/yakeDeque.h> //============================================================================ // INTERFACE STRUCTURES / UTILITY CLASSES Modified: trunk/yake/yake/input/yakeInputSystem.h =================================================================== --- trunk/yake/yake/input/yakeInputSystem.h 2007-08-23 23:25:11 UTC (rev 1812) +++ trunk/yake/yake/input/yakeInputSystem.h 2007-08-23 23:26:41 UTC (rev 1813) @@ -30,6 +30,7 @@ #ifndef YAKE_INPUT_PREREQUISITES_H #include <yake/input/yakePrerequisites.h> #endif +#include <yake/base/math/yakeGeometry.h> namespace yake { namespace input { Modified: trunk/yake/yake/physics/yakePhysicsCommon.h =================================================================== --- trunk/yake/yake/physics/yakePhysicsCommon.h 2007-08-23 23:25:11 UTC (rev 1812) +++ trunk/yake/yake/physics/yakePhysicsCommon.h 2007-08-23 23:26:41 UTC (rev 1813) @@ -28,6 +28,7 @@ #define YAKE_PHYSICS_COMMON_H #include <yake/physics/yakePhysicsPrerequisites.h> +#include <yake/base/math/yakeVector3.h> namespace yake { namespace physics { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |