yake-svn Mailing List for Yake Engine (Page 11)
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-08-10 15:26:28
|
Revision: 1787 http://yake.svn.sourceforge.net/yake/?rev=1787&view=rev Author: psyclonist Date: 2007-08-10 08:26:25 -0700 (Fri, 10 Aug 2007) Log Message: ----------- * [scripting] added bindings for graphics, physics and raf * [scripting] extended bindings for base,math,model * [model] added missing implementations of a few member functions * [physics,*] improved/cleaned-up interfaces Modified Paths: -------------- trunk/yake/scripts/premake/config.lua trunk/yake/scripts/premake/yake.lua trunk/yake/src/bindings.lua/detail/base.lua.cpp trunk/yake/src/bindings.lua/detail/model.lua.cpp trunk/yake/src/loader/yakeXODEParser.cpp trunk/yake/src/model/yakeModel.cpp trunk/yake/src/model/yakeModelComponentContainer.cpp trunk/yake/src/model/yakeModelMovableLink.cpp trunk/yake/src/physics/yakePhysicsCommon.cpp trunk/yake/src/raf/yakeApplicationState.cpp trunk/yake/yake/base/math/yakeRay.h trunk/yake/yake/bindings.lua/bindings.lua.h trunk/yake/yake/model/model_component.h trunk/yake/yake/physics/yakePhysicsCommon.h trunk/yake/yake/physics/yakePhysicsJoint.h trunk/yake/yake/physics/yakePhysicsShape.h trunk/yake/yake/physics/yakePhysicsWorld.h trunk/yake/yake/raf/yakeApplicationState.h Added Paths: ----------- trunk/yake/src/bindings.lua/detail/graphics.lua.cpp trunk/yake/src/bindings.lua/detail/physics.lua.cpp trunk/yake/src/bindings.lua/detail/raf.lua.cpp Modified: trunk/yake/scripts/premake/config.lua =================================================================== --- trunk/yake/scripts/premake/config.lua 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/scripts/premake/config.lua 2007-08-10 15:26:25 UTC (rev 1787) @@ -49,11 +49,14 @@ -- For example, if you do *not* use yake::model then you can disable -- the compilation of the binding code for this component and thereby -- save compilation time. -ENABLE_LUA_BASE = true -- includes 'base' and 'math' binders -ENABLE_LUA_MODEL = true -- 'model' binder +ENABLE_LUA_BASE = true -- also includes 'math' binders +ENABLE_LUA_MODEL = true ENABLE_LUA_TASK = true -- 'task' binder (+executor) -ENABLE_LUA_PROPERTY = true -- 'property' binder +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_PHYSICS = true +ENABLE_LUA_RAF = true -------------------------------------- -- Samples Modified: trunk/yake/scripts/premake/yake.lua =================================================================== --- trunk/yake/scripts/premake/yake.lua 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/scripts/premake/yake.lua 2007-08-10 15:26:25 UTC (rev 1787) @@ -73,6 +73,9 @@ f:write("#define YAKE_ENABLE_LUA_TASK " .. bool_to_int(ENABLE_LUA_TASK) .. "\n") 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_PHYSICS " .. bool_to_int(ENABLE_LUA_PHYSICS) .. "\n") + f:write("#define YAKE_ENABLE_LUA_RAF " .. bool_to_int(ENABLE_LUA_RAF) .. "\n") f:write("\n") f:write("#endif\n") io.close(f) Modified: trunk/yake/src/bindings.lua/detail/base.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/base.lua.cpp 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/src/bindings.lua/detail/base.lua.cpp 2007-08-10 15:26:25 UTC (rev 1787) @@ -37,8 +37,18 @@ #include <yake/bindings.lua/common/yake.lua.shared_ptr.h> #include <yake/bindings.lua/common/yake.lua.any_converter.h> +#include <luabind/operator.hpp> + namespace yake { namespace math { + Vector3 operator * (const Vector3& lhs, const Quaternion& rhs) + { + return rhs * lhs; + } + Vector3 operator * (const Vector3& lhs, const Matrix3& rhs) + { + return rhs * lhs; + } //------------------------------------------------------------------------- namespace { struct AnyConverterIniter @@ -89,27 +99,34 @@ value( "AU_RADIAN", 1 ) ] .def( constructor< unsigned int >() ) - //,def( "IAbs", &yake::math::Math::IAbs ) + //,def( "IAbs", &Math::IAbs ) ]; // Vector3 module( YAKE_MATH_MODULE ) [ class_< Vector3 >( "Vector3" ) - .def_readwrite( "x", &yake::math::Vector3::x ) - .def_readwrite( "y", &yake::math::Vector3::y ) - .def_readwrite( "z", &yake::math::Vector3::z ) + .def_readwrite( "x", &Vector3::x ) + .def_readwrite( "y", &Vector3::y ) + .def_readwrite( "z", &Vector3::z ) .def( constructor<>() ) .def( constructor< real, real, real >() ) .def( constructor< const real* const >() ) .def( constructor< Vector3 const& >() ) - .def( "length", &yake::math::Vector3::length ) - .def( "normalise", &yake::math::Vector3::normalise ) - .def( "crossProduct", &yake::math::Vector3::crossProduct ) - .def( "dotProduct", &yake::math::Vector3::dotProduct ) - .def( "reflect", &yake::math::Vector3::reflect ) - .def( "perpendicular", &yake::math::Vector3::perpendicular ) - .def( "getRotationTo", &yake::math::Vector3::getRotationTo ) + .def( "length", &Vector3::length ) + .def( "normalise", &Vector3::normalise ) + .def( "crossProduct", &Vector3::crossProduct ) + .def( "dotProduct", &Vector3::dotProduct ) + .def( "reflect", &Vector3::reflect ) + .def( "perpendicular", &Vector3::perpendicular ) + .def( "getRotationTo", &Vector3::getRotationTo ) + .def(const_self + other<Vector3>()) + .def(const_self - other<Vector3>()) + .def(const_self == other<Vector3>()) + .def(const_self / real()) + .def(const_self * other<real>()) + .def(const_self * Quaternion()) + .def(const_self * Matrix3()) ]; // Vector4 @@ -128,21 +145,35 @@ class_< Matrix3 >( "Matrix3" ) .def( constructor<>() ) .def( constructor< Matrix3 const& >() ) - .def( "getColumn", &yake::math::Matrix3::GetColumn ) + .def( "getColumn", &Matrix3::GetColumn ) + .def(const_self * other<Matrix3>()) ]; // Quaternion module( YAKE_MATH_MODULE ) [ class_< Quaternion >( "Quaternion" ) - .def_readwrite( "x", &yake::math::Quaternion::x ) - .def_readwrite( "y", &yake::math::Quaternion::y ) - .def_readwrite( "z", &yake::math::Quaternion::z ) - .def_readwrite( "w", &yake::math::Quaternion::w ) + .def_readwrite( "x", &Quaternion::x ) + .def_readwrite( "y", &Quaternion::y ) + .def_readwrite( "z", &Quaternion::z ) + .def_readwrite( "w", &Quaternion::w ) .def( constructor< real, real, real, real >() ) .def( constructor< Quaternion const& >() ) + .def("inverse", &Quaternion::Inverse) + .def(const_self * other<Quaternion>()) ]; + // Ray + module( YAKE_MATH_MODULE ) + [ + class_< Ray >( "Ray" ) + .def( constructor<>() ) + .def( constructor<const Vector3&, const Vector3&>() ) + .property( "origin", &Ray::getOrigin, &Ray::setOrigin ) + .property( "direction", &Ray::getDirection, &Ray::setDirection ) + .def("getPoint", &Ray::getPoint) + ]; + // RandomNumberGenerator typedef RandomNumberGenerator rng_type; module( YAKE_MATH_MODULE ) @@ -195,6 +226,10 @@ .def( "getPosition", &Movable::getPosition ) .def( "getOrientation", &Movable::getOrientation ) .def( "translate", &Movable::translate ) + .property("position", &Movable::getPosition, &Movable::setPosition) + .property("derived_position", &Movable::getDerivedPosition) + .property("orientation", &Movable::getOrientation, &Movable::setOrientation) + .property("derived_orientation", &Movable::getDerivedOrientation) ]; module( YAKE_BASE_MODULE ) Added: trunk/yake/src/bindings.lua/detail/graphics.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/graphics.lua.cpp (rev 0) +++ trunk/yake/src/bindings.lua/detail/graphics.lua.cpp 2007-08-10 15:26:25 UTC (rev 1787) @@ -0,0 +1,170 @@ +/* + ------------------------------------------------------------------------------------ + 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) + , + class_<IEntity>("Entity") + .property("name", &IEntity::getName) + .def("setVisible", &IEntity::setVisible) + .def("setMaterial", &IEntity::setMaterial) + .def("setSubEntityMaterial", &IEntity::setSubEntityMaterial) + .def("setCastsShadow", &IEntity::setCastsShadow) + , + class_<ILight>("Light") + .enum_("LightType") + [ + value("LT_POINT",ILight::LT_POINT), + value("LT_DIRECTIONAL",ILight::LT_DIRECTIONAL), + value("LT_SPOT",ILight::LT_SPOT) + ] + .property("name", &ILight::getName) + .property("type", &ILight::getType, &ILight::setType) + .property("direction", &ILight::getDirection, &ILight::setDirection) + //@todo property "enabled" + .def("setEnabled", &ILight::setEnabled) + .def("setCastsShadows", &ILight::setCastsShadows) + .def("setDiffuseColour", &ILight::setDiffuseColour) + .def("setSpecularColour", &ILight::setSpecularColour) + .def("setAttenuation", &ILight::setAttenuation) + .property("attenuationRange", &ILight::getAttenuationRange) + .property("attenuationConstFactor", &ILight::getAttenuationConstFactor) + .property("attenuationLinearFactor", &ILight::getAttenuationLinearFactor) + .property("attenuationQuadraticFactor", &ILight::getAttenuationQuadraticFactor) + .def("setSpotlightRange", &ILight::setSpotlightRange) + .property("spotInnerAngle", &ILight::getSpotlightInnerAngle) + .property("spotOuterAngle", &ILight::getSpotlightOuterAngle) + .property("spotFalloff", &ILight::getSpotlightFalloff) + , + class_<IParticleSystem>("ParticleSystem") + //@todo + , + class_<ICamera,Movable>("Camera") + //@todo + , + class_<IViewport>("Viewport") + //@todo + , + //@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("createCamera", &IWorld::createCamera) + .def("createViewport", &IWorld::createViewport) + .def("load", &IWorld::load) + .def("setShadowsEnabled", &IWorld::setShadowsEnabled) + .def("setAmbientLight", &IWorld::setAmbientLight) + .def("pickEntity", &IWorld::pickEntity) + ] + ]; + } + + YAKE_WRAP_BINDER(graphics,::yake::graphics::bind); + +} // namespace graphics + void bind_graphics(lua_State* L) + { + YAKE_ASSERT(L); + graphics::bind(L); + } + void bind_graphics(scripting::IVM* vm) + { + scripting::LuaVM* luavm = static_cast<scripting::LuaVM*>(vm); + YAKE_ASSERT( luavm ); + bind_graphics(luavm->getLuaState()); + } +} // namespace yake +#endif // YAKE_ENABLE_LUA_MODEL Modified: trunk/yake/src/bindings.lua/detail/model.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/model.lua.cpp 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/src/bindings.lua/detail/model.lua.cpp 2007-08-10 15:26:25 UTC (rev 1787) @@ -36,8 +36,30 @@ #include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <yake/bindings.lua/detail/private.h> +#include <luabind/discard_result_policy.hpp> +#include <luabind/iterator_policy.hpp> + namespace yake { namespace model { + Model* ModelManager_createModel(ModelManager* mgr, const String& modelName, const String& def) + { + return (mgr ? mgr->createModel(modelName,def).get() : 0); + } + Model* ModelManager_createModelFromTemplate(ModelManager* mgr, const String& modelName, const String& tplName) + { + return (mgr ? mgr->createModelFromTemplate(modelName,tplName).get() : 0); + } + bool ModelMovableLink_subscribeToPositionChanged(ModelMovableLink* link, const luabind::object& o) + { + YAKE_ASSERT( luabind::type(o) == LUA_TFUNCTION ); + if (luabind::type(o) != LUA_TFUNCTION) + return false; + if (!link) + return false; + typedef boost::function<void(const Vector3&)> Fn; + link->subscribeToPositionChanged( boost::bind(Fn(o),_1) ); + return true; + } void bind( lua_State* L ) { @@ -52,6 +74,11 @@ module( YAKE_MODEL_MODULE ) [ + class_<ModelComponent::Desc>( "ModelComponentDesc" ) + .def_readwrite("name", &ModelComponent::Desc::name) + .def_readwrite("type", &ModelComponent::Desc::type) + .def_readwrite("params", &ModelComponent::Desc::params, return_stl_iterator) + , class_<ModelComponent>( "ModelComponent" ) //.def( constructor<>() ) ]; @@ -86,6 +113,33 @@ //.def( "translate", &Physical::translate ) .def( "updateAffectors", &Physical::updateAffectors ) ]; + + module( YAKE_MODEL_MODULE ) + [ + class_<ModelLink>( "ModelLink" ) + , + class_<ModelMovableLink,ModelLink>( "ModelMovableLink" ) + .def( "subscribeToPositionChanged", &ModelMovableLink_subscribeToPositionChanged) + , + class_<Model>( "Model" ) + .def( constructor<>() ) + .property( "name", &Model::getName, &Model::setName ) + .def( "getName", &Model::getName ) + .def( "setName", &Model::setName ) + .def( "getComponentByTag", &Model::getComponentByTag) + //@todo .def( "getComponentByIndex", &Model::getComponentByIndex) + .def( "removeComponent", &Model::removeComponent, discard_result) + .def( "numComponents", &Model::numComponents) + .def( "createLink", &Model::createLink) + .def( "createDirectLink", &Model::createDirectLink) + .def( "createWorldSpaceLink", &Model::createWorldSpaceLink) + , + class_<ModelManager>( "ModelManager" ) + .def("clear", &ModelManager::clear) + .def("loadTemplates", &ModelManager::loadTemplatesFromDotModel) + .def("createModel", &ModelManager_createModel) + .def("createModelFromTemplate", &ModelManager_createModelFromTemplate) + ]; } YAKE_WRAP_BINDER(model,::yake::model::bind); Added: trunk/yake/src/bindings.lua/detail/physics.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/physics.lua.cpp (rev 0) +++ trunk/yake/src/bindings.lua/detail/physics.lua.cpp 2007-08-10 15:26:25 UTC (rev 1787) @@ -0,0 +1,286 @@ +/* + ------------------------------------------------------------------------------------ + 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_PHYSICS == 1 + +#pragma warning(disable:4267) // VC8-32Bit: conversion from 'size_t' to 'unsigned int', possible loss of data + +// 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/physics/yakePhysics.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 physics { + IShape* IActor_createShape(IActor* actor, const IShape::Desc& desc) + { + return (actor ? actor->createShape(desc) : 0); + } + IAvatar* IWorld_createAvatar(IWorld* world) + { + return (world ? world->createAvatar(IAvatar::Desc()) : 0); + } + + void bind( lua_State* L ) + { + YAKE_ASSERT( L ); + if (!L) + return; + + using namespace luabind; + +#define YAKE_PHYSICS_MODULE L, "yake" + + module( YAKE_PHYSICS_MODULE ) + [ + class_<Force>("Force") + .enum_("ReferenceFrame") + [ + value("LOCAL", RF_LOCAL), + value("GLOBAL", RF_GLOBAL) + ] + .def_readwrite("value", &Force::value_) + .def_readwrite("position", &Force::pos_) + .def_readwrite("duration", &Force::duration_) + .def_readwrite("posref", &Force::posRef_) + .def_readwrite("valref", &Force::valueRef_) + .def(const_self + other<Force>()) + .def(const_self * real()) + .def(const_self == Force()) + .def(constructor<const Vector3&,const ReferenceFrame,const Point3&, const ReferenceFrame,const real>()) + .def(constructor<const Vector3&,const ReferenceFrame,const Point3&, const ReferenceFrame>()) + .def(constructor<const Vector3&,const ReferenceFrame,const real>()) + .def(constructor<const Vector3&,const ReferenceFrame>()) + , + namespace_("physics") + [ + class_<IBody>("Body") + .property("mass", &IBody::getMass) + .def("addForce", &IBody::addForce) + .def("addTorque", &IBody::addTorque) + .def("setMass", (void(IBody::*)(const real))&IBody::setMass) + .def("translateMass", &IBody::translateMass) + .def("setLinearVelocity", &IBody::setLinearVelocity) + .def("getLinearVelocity", &IBody::getLinearVelocity) + .def("setAngularVelocity", &IBody::setAngularVelocity) + .def("getAngularVelocity", &IBody::getAngularVelocity) + , + class_<IShape,Movable>("Shape") + .enum_("ShapeType") + [ + value("ST_PLANE", ST_PLANE), + value("ST_BOX", ST_BOX), + value("ST_SPHERE", ST_SPHERE), + value("ST_CAPSULE", ST_CAPSULE), + value("ST_CYLINDER", ST_CYLINDER), + value("ST_TRIANGLE_MESH", ST_TRIANGLE_MESH), + value("ST_VOXEL_SET", ST_VOXEL_SET), + value("ST_OTHER", ST_OTHER) + ] + .property("type", &IShape::getType) + .property("material", &IShape::getMaterial, &IShape::setMaterial) + .scope + [ + class_<IShape::Desc>("Desc") + .def_readonly("type", &IShape::Desc::type) + .def_readwrite("material", &IShape::Desc::material) + .def_readwrite("position", &IShape::Desc::position) + .def_readwrite("orientation", &IShape::Desc::orientation) + , + class_<IShape::SphereDesc,IShape::Desc>("SphereDesc") + .def(constructor<real>()) + .def(constructor<real,const Vector3&>()) + .def(constructor<real,const Vector3&,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&>()) + , + 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&>()) + , + class_<IShape::CapsuleDesc,IShape::Desc>("CapsuleDesc") + .def(constructor<real,real>()) + .def(constructor<real,real,const Vector3&>()) + .def(constructor<real,real,const Vector3&,const Quaternion&>()) + , + class_<IShape::TriMeshDesc,IShape::Desc>("TriMeshDesc") + .def(constructor<TriangleMeshId>()) + .def(constructor<TriangleMeshId,const Vector3&>()) + .def(constructor<TriangleMeshId,const Vector3&,const Quaternion&>()) + ] + , + class_<IActor,Movable>("Actor") + .enum_("ActorType") + [ + value("ACTOR_STATIC",ACTOR_STATIC), + value("ACTOR_MOVABLE",ACTOR_MOVABLE), + value("ACTOR_DYNAMIC",ACTOR_DYNAMIC) + ] + .property("creator", &IActor::getCreator) + .property("enabled", &IActor::isEnabled, &IActor::setEnabled) + .property("type", &IActor::getType) + .property("body", &IActor::getBodyPtr) + .def("createShape", &IActor_createShape) + .def("destroyShape", &IActor::destroyShape) + //@todo signals CollisionEntered, CollisionExited + , + class_<IAvatar,Movable>("Avatar") + .property("creator", &IActor::getCreator) + .property("speed", &IAvatar::getSpeed, &IAvatar::setSpeed) + .property("acceleration", &IAvatar::getAcceleration, &IAvatar::setAcceleration) + .def("move", &IAvatar::move) // takes normalized vector + .def("jump", &IAvatar::jump) + .def("duck", &IAvatar::duck) + .property("jumping", &IAvatar::isJumping) + .property("ducking", &IAvatar::isDucking) + .def("setGravityDirection", &IAvatar::setGravityDirection) + //@todo signals + , + class_<IJoint>("Joint") + .enum_("JointType") + [ + value("JT_BALL",JT_BALL), + value("JT_HINGE",JT_HINGE), + value("JT_HINGE2",JT_HINGE2), + value("JT_FIXED",JT_FIXED), + value("JT_SLIDER",JT_SLIDER), + value("JT_UNIVERSAL",JT_UNIVERSAL), + value("JT_ANGULAR_MOTOR",JT_ANGULAR_MOTOR), + value("JT_OTHER",JT_OTHER) + ] + .scope + [ + class_<Limit>("JointLimit") + .def(constructor<>()) + .def(constructor<size_t,real,real>()) + .def_readwrite("axis",&Limit::axis) + .def_readwrite("low",&Limit::low) + .def_readwrite("high",&Limit::high) + , + class_<IJoint::DescBase>("JointDesc") + .def_readonly("type", &IJoint::DescBase::type) + .def_readwrite("actor0", &IJoint::DescBase::actor0) + .def_readwrite("actor1", &IJoint::DescBase::actor1) + .def_readwrite("breakable", &IJoint::DescBase::breakable) + .def_readwrite("breakingForce", &IJoint::DescBase::breakingForce) + .def_readwrite("breakingTorque", &IJoint::DescBase::breakingTorque) + // @todo LimitList + , + class_<IJoint::DescFixed,IJoint::DescBase>("DescFixed") + .def(constructor<IActor*,IActor*>()) + , + class_<IJoint::DescHinge,IJoint::DescBase>("DescHinge") + .def(constructor<IActor*,IActor*>()) + .def_readwrite("axis", &IJoint::DescHinge::axis) + .def_readwrite("anchor", &IJoint::DescHinge::anchor) + , + class_<IJoint::DescHinge2,IJoint::DescBase>("DescHinge2") + .def(constructor<IActor*,IActor*>()) + .def_readwrite("axis0", &IJoint::DescHinge2::axis0) + .def_readwrite("axis1", &IJoint::DescHinge2::axis1) + .def_readwrite("anchor", &IJoint::DescHinge2::anchor) + , + class_<IJoint::DescUniversal,IJoint::DescBase>("DescUniversal") + .def(constructor<IActor*,IActor*>()) + .def_readwrite("axis0", &IJoint::DescUniversal::axis0) + .def_readwrite("axis1", &IJoint::DescUniversal::axis1) + .def_readwrite("anchor", &IJoint::DescUniversal::anchor) + , + class_<IJoint::DescBall,IJoint::DescBase>("DescBall") + .def(constructor<IActor*,IActor*>()) + .def_readwrite("anchor", &IJoint::DescBall::anchor) + , + class_<IJoint::DescSlider,IJoint::DescBase>("DescSlider") + .def(constructor<IActor*,IActor*>()) + .def_readwrite("axis", &IJoint::DescSlider::axis) + ] + .property("creator", &IJoint::getCreator) + .property("type", &IJoint::getType) + .property("spring", &IJoint::getSpring, &IJoint::setSpring) + .property("damping", &IJoint::getDamping, &IJoint::setDamping) + .def("setAnchor", &IJoint::setAnchor) + .def("getNumAnchors", &IJoint::getNumAnchors) + .def("setAxis", &IJoint::setAxis) + .def("getNumAxis", &IJoint::getNumAxis) + .def("setMotor", &IJoint::setMotor) + .def("setMotorEnabled", &IJoint::setMotorEnabled) + .def("setLimit", &IJoint::setLimits) + .def("setBreakable", &IJoint::setBreakable) + .def("setBreakableForce", &IJoint::setBreakableForce) + .def("setBreakableTorque", &IJoint::setBreakableTorque) + .def("setConnectedBodiesCollide", &IJoint::setConnectedBodiesCollide) + //@todo signals OnBreaking + , + class_<IWorld>("World") + .property("gravity", &IWorld::getGlobalGravity, &IWorld::setGlobalGravity) + .property("stepsize", &IWorld::getStepSize) + .property("solver", &IWorld::getCurrentSolver) + // + .def("createActor", (IActorPtr(IWorld::*)(const ActorType))&IWorld::createActor) + .def("destroyActor", &IWorld::destroyActor) + .def("createAvatar", &IWorld_createAvatar) + .def("destroyAvatar", &IWorld::destroyAvatar) + .def("createJoint", &IWorld::createJoint) + .def("destroyJoint", &IWorld::destroyJoint) + // createAvatar + // createTriangleMesh + // createMaterial + ] + ]; + } + + YAKE_WRAP_BINDER(physics,::yake::physics::bind); + +} // namespace physics + void bind_physics(lua_State* L) + { + YAKE_ASSERT(L); + physics::bind(L); + } + void bind_physics(scripting::IVM* vm) + { + scripting::LuaVM* luavm = static_cast<scripting::LuaVM*>(vm); + YAKE_ASSERT( luavm ); + bind_physics(luavm->getLuaState()); + } +} // namespace yake +#endif // YAKE_ENABLE_LUA_MODEL Added: trunk/yake/src/bindings.lua/detail/raf.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/raf.lua.cpp (rev 0) +++ trunk/yake/src/bindings.lua/detail/raf.lua.cpp 2007-08-10 15:26:25 UTC (rev 1787) @@ -0,0 +1,118 @@ +/* + ------------------------------------------------------------------------------------ + 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_RAF == 1 + +#include <yake/base/yake.h> +#include <yake/raf/yakeRaf.h> + +#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! + +#include <yake/bindings.lua/detail/private.h> +#include <yake/bindings.lua/common/lua.helpers.h> +#include <yake/bindings.lua/common/vminfo.lua.h> +#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.h> + +namespace yake { +namespace raf { + //------------------------------------------------------------------------- + namespace { + struct AnyConverterIniter + { + /* + AnyConverterIniter() + { + register_any_converter<Color>(); + register_any_converter<Vector3>(); + register_any_converter<Quaternion>(); + register_any_converter<Matrix3>(); + } + */ + } g_initer; + } // namespace + input::KeyboardDevice* getAppKeyboard(raf::Application* app) + { + return app ? app->getKeyboard() : 0; + } + graphics::IGraphicsSystem* getAppDefaultGraphics(raf::Application* app) + { + return app ? app->getGraphicsSystem() : 0; + } + physics::IPhysicsSystem* getAppDefaultPhysics(raf::Application* app) + { + return app ? app->getPhysicsSystem() : 0; + } + audio::IAudioSystem* getAppDefaultAudio(raf::Application* app) + { + return app ? app->getAudioSystem(): 0; + } + //------------------------------------------------------------------------- + void bind(lua_State* L) + { + YAKE_ASSERT(L); + if (!L) + return; + // + using namespace luabind; +#define YAKE_RAF_MODULE L, "yake" + + + module( YAKE_RAF_MODULE ) + [ + namespace_("raf") + [ + class_<raf::Application>("Application") + .property("keyboard", &getAppKeyboard) + .property("graphics", &getAppDefaultGraphics) + .property("physics", &getAppDefaultPhysics) + .property("audio", &getAppDefaultAudio) + , + class_<raf::AppMachine>("AppMachine") + .property("currentState", &raf::AppMachine::currentState) + ] + ]; + + } + + YAKE_WRAP_BINDER(raf,::yake::raf::bind); + +} // namespace raf + void bind_raf(lua_State* L) + { + YAKE_ASSERT( L ); + raf::bind(L); + } + void bind_raf(scripting::IVM* vm) + { + scripting::LuaVM* luavm = static_cast<scripting::LuaVM*>(vm); + YAKE_ASSERT( luavm ); + bind_raf(luavm->getLuaState()); + } +} // namespace yake + +#endif // YAKE_ENABLE_LUA_RAF Modified: trunk/yake/src/loader/yakeXODEParser.cpp =================================================================== --- trunk/yake/src/loader/yakeXODEParser.cpp 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/src/loader/yakeXODEParser.cpp 2007-08-10 15:26:25 UTC (rev 1787) @@ -651,7 +651,7 @@ YAKE_LOG("xode", "XODE: box with sizes: " + strSizeX + ", " + strSizeY + ", " + strSizeZ ); - shapeDesc = new IShape::BoxDesc( math::Vector3( sizeX, sizeY, sizeZ ), "", + shapeDesc = new IShape::BoxDesc( math::Vector3( sizeX, sizeY, sizeZ ), geomTransform.position_, geomTransform.rotation_ ); } else if ( nodeName == "cappedCylinder" ) @@ -668,7 +668,6 @@ shapeDesc = new IShape::CapsuleDesc( length, radius, - "", geomTransform.position_, geomTransform.rotation_ ); } @@ -700,7 +699,6 @@ shapeDesc = new IShape::CapsuleDesc( length, radius, - "", geomTransform.position_, geomTransform.rotation_ ); } @@ -710,7 +708,6 @@ readPlane( *it, a, b, c, d ); shapeDesc = new IShape::PlaneDesc( math::Vector3( a, b, c ), d, - "", geomTransform.position_, geomTransform.rotation_ ); } @@ -740,7 +737,6 @@ shapeDesc = new IShape::SphereDesc( radius, - "", geomTransform.position_, geomTransform.rotation_ ); } Modified: trunk/yake/src/model/yakeModel.cpp =================================================================== --- trunk/yake/src/model/yakeModel.cpp 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/src/model/yakeModel.cpp 2007-08-10 15:26:25 UTC (rev 1787) @@ -53,6 +53,14 @@ { return components_.getComponentByTag(tag); } + size_t Model::numComponents() const + { + return components_.numComponents(); + } + ModelComponent* Model::removeComponent(ModelComponent* c) + { + return components_.removeComponent(c); + } ModelMovableLink* Model::createLink(yake::Movable* from, yake::Movable* to, const yake::String &linkType) { //SharedPtr<ModelMovableLink> link = create<ModelMovableLink>(linkType); //@todo USE FACTORY! Modified: trunk/yake/src/model/yakeModelComponentContainer.cpp =================================================================== --- trunk/yake/src/model/yakeModelComponentContainer.cpp 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/src/model/yakeModelComponentContainer.cpp 2007-08-10 15:26:25 UTC (rev 1787) @@ -86,6 +86,23 @@ #endif tag2components_[ tag ] = c; } + ModelComponent* ModelComponentContainer::removeComponent(ModelComponent* c) + { + if (!c) + return 0; + ModelComponentList::iterator it = std::find(components_.begin(),components_.end(),c); + if (it != components_.end()) + components_.erase(it); + YAKE_FOR_EACH( TagModelComponentMap::iterator, it, tag2components_ ) + { + if (it->second == c) + { + tag2components_.erase( it ); + break; + } + } + return c; + } ModelComponent* ModelComponentContainer::getComponentByTag(const ComponentTag& tag) const { TagModelComponentMap::const_iterator it = tag2components_.find(tag); Modified: trunk/yake/src/model/yakeModelMovableLink.cpp =================================================================== --- trunk/yake/src/model/yakeModelMovableLink.cpp 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/src/model/yakeModelMovableLink.cpp 2007-08-10 15:26:25 UTC (rev 1787) @@ -41,6 +41,10 @@ { return mSource; } + SignalConnection ModelMovableLink::subscribeToPositionChanged(const PositionSignal::slot_type& slot) + { + return mPositionSignal.connect( slot ); + } SignalConnection ModelMovableLink::subscribeToPositionChanged( Movable* pMovable ) { const Vector3 srcPos = getSource()->getPosition(); @@ -56,6 +60,10 @@ return mOrientationSignal.connect( Bind1( &Movable::setOrientation, pMovable ) ); } + SignalConnection ModelMovableLink::subscribeToOrientationChanged(const OrientationSignal::slot_type& slot) + { + return mOrientationSignal.connect( slot ); + } YAKE_REGISTER_CONCRETE(ModelMovableDirectLink) ModelMovableDirectLink::ModelMovableDirectLink() Modified: trunk/yake/src/physics/yakePhysicsCommon.cpp =================================================================== --- trunk/yake/src/physics/yakePhysicsCommon.cpp 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/src/physics/yakePhysicsCommon.cpp 2007-08-10 15:26:25 UTC (rev 1787) @@ -115,7 +115,7 @@ value_ *= rhs; return *this; } - Force Force::operator * (const real rhs) + Force Force::operator * (const real rhs) const { Force tmp(*this); tmp *= rhs; @@ -137,7 +137,7 @@ } return *this; } - Force Force::operator + (const Force& rhs) + Force Force::operator + (const Force& rhs) const { Force tmp(*this); tmp += rhs; Modified: trunk/yake/src/raf/yakeApplicationState.cpp =================================================================== --- trunk/yake/src/raf/yakeApplicationState.cpp 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/src/raf/yakeApplicationState.cpp 2007-08-10 15:26:25 UTC (rev 1787) @@ -76,6 +76,10 @@ {} AppMachine::~AppMachine() {} + ApplicationState* AppMachine::currentState() const + { + return machine_.current(); + } void AppMachine::addState(const String& stateId, ApplicationState* state) { YAKE_ASSERT( !stateId.empty() ); Modified: trunk/yake/yake/base/math/yakeRay.h =================================================================== --- trunk/yake/yake/base/math/yakeRay.h 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/yake/base/math/yakeRay.h 2007-08-10 15:26:25 UTC (rev 1787) @@ -41,6 +41,9 @@ class YAKE_BASE_API Ray { public: + Ray() : mOrigin(0,0,0), mDirection(1,0,0) + { + } Ray( const Vector3 & rOrigin, const Vector3 & rDirection ) : mOrigin( rOrigin ), mDirection( rDirection ) { } Modified: trunk/yake/yake/bindings.lua/bindings.lua.h =================================================================== --- trunk/yake/yake/bindings.lua/bindings.lua.h 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/yake/bindings.lua/bindings.lua.h 2007-08-10 15:26:25 UTC (rev 1787) @@ -56,6 +56,18 @@ YAKE_BINDINGS_LUA_API void bind_property(lua_State*); YAKE_BINDINGS_LUA_API void bind_property(scripting::IVM*); #endif +#if YAKE_ENABLE_LUA_PHYSICS == 1 + YAKE_BINDINGS_LUA_API void bind_physics(lua_State*); + YAKE_BINDINGS_LUA_API void bind_physics(scripting::IVM*); +#endif +#if YAKE_ENABLE_LUA_GRAPHICS == 1 + YAKE_BINDINGS_LUA_API void bind_graphics(lua_State*); + YAKE_BINDINGS_LUA_API void bind_graphics(scripting::IVM*); +#endif +#if YAKE_ENABLE_LUA_RAF == 1 + YAKE_BINDINGS_LUA_API void bind_raf(lua_State*); + YAKE_BINDINGS_LUA_API void bind_raf(scripting::IVM*); +#endif } // namespace yake #endif Modified: trunk/yake/yake/model/model_component.h =================================================================== --- trunk/yake/yake/model/model_component.h 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/yake/model/model_component.h 2007-08-10 15:26:25 UTC (rev 1787) @@ -159,6 +159,7 @@ //@{ void addComponent(ModelComponent*); void addComponent(ModelComponent*, const ComponentTag&); + ModelComponent* removeComponent(ModelComponent*); ModelComponent* getComponentByTag(const ComponentTag&) const; ModelComponent* getComponentByIndex(const size_t) const; size_t numComponents() const; Modified: trunk/yake/yake/physics/yakePhysicsCommon.h =================================================================== --- trunk/yake/yake/physics/yakePhysicsCommon.h 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/yake/physics/yakePhysicsCommon.h 2007-08-10 15:26:25 UTC (rev 1787) @@ -58,13 +58,13 @@ bool operator != (const Force&) const; Force& operator *= (const real); - Force operator * (const real); + Force operator * (const real) const; /** @note The frames of reference for the value and position have to be the same! */ Force& operator += (const Force&); /** @note The frames of reference for the value and position have to be the same! */ - Force operator + (const Force&); + Force operator + (const Force&) const; //private: Vector3 value_; Modified: trunk/yake/yake/physics/yakePhysicsJoint.h =================================================================== --- trunk/yake/yake/physics/yakePhysicsJoint.h 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/yake/physics/yakePhysicsJoint.h 2007-08-10 15:26:25 UTC (rev 1787) @@ -117,6 +117,9 @@ struct DescHinge : DescBase { + DescHinge(IActor* pFirst, IActor* pSecond) : + DescBase( JT_HINGE, pFirst, pSecond ) + {} DescHinge( IActor* pFirst, IActor* pSecond, const math::Vector3& rAxis, @@ -131,6 +134,9 @@ struct DescHinge2 : DescBase { + DescHinge2(IActor* pFirst, IActor* pSecond) : + DescBase( JT_HINGE2, pFirst, pSecond ) + {} DescHinge2( IActor* pFirst, IActor* pSecond, const math::Vector3& rAxis0, @@ -148,6 +154,9 @@ struct DescBall : DescBase { + DescBall(IActor* pFirst, IActor* pSecond) : + DescBase( JT_BALL, pFirst, pSecond ) + {} DescBall( IActor* pFirst, IActor* pSecond, const math::Vector3& rAnchor ) : @@ -159,6 +168,9 @@ struct DescSlider : DescBase { + DescSlider(IActor* pFirst, IActor* pSecond) : + DescBase( JT_SLIDER, pFirst, pSecond ) + {} DescSlider( IActor* pFirst, IActor* pSecond, const math::Vector3& rAxis ) : @@ -170,6 +182,9 @@ struct DescUniversal : DescBase { + DescUniversal(IActor* pFirst, IActor* pSecond) : + DescBase( JT_UNIVERSAL, pFirst, pSecond ) + {} DescUniversal( IActor* pFirst, IActor* pSecond, const math::Vector3& rAxis0, Modified: trunk/yake/yake/physics/yakePhysicsShape.h =================================================================== --- trunk/yake/yake/physics/yakePhysicsShape.h 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/yake/physics/yakePhysicsShape.h 2007-08-10 15:26:25 UTC (rev 1787) @@ -65,8 +65,8 @@ struct Desc { Desc( const ShapeType type_, - const math::Vector3& rPosition = math::Vector3::kZero, - const math::Quaternion& rOrientation = math::Quaternion::kIdentity, + const Vector3& rPosition = Vector3::kZero, + const Quaternion& rOrientation = Quaternion::kIdentity, const String& material_ = "" ) : type( type_ ), position( rPosition ), @@ -78,8 +78,8 @@ //virtual Desc* clone() const = 0; ShapeType type; // superfluous as shape type is determined by dynamic_cast on Desc struct... - math::Vector3 position; - math::Quaternion orientation; + Vector3 position; + Quaternion orientation; String material; }; @@ -87,11 +87,10 @@ { SphereDesc( real radius_ = real(1.), // base class: - const String& material_ = "", - const math::Vector3& rPosition = math::Vector3::kZero, - const math::Quaternion& rOrientation = math::Quaternion::kIdentity + const Vector3& rPosition = Vector3::kZero, + const Quaternion& rOrientation = Quaternion::kIdentity ) : - Desc( ST_SPHERE, rPosition, rOrientation, material_ ), + Desc( ST_SPHERE, rPosition, rOrientation ), radius( radius_ ) {} real radius; @@ -99,32 +98,29 @@ struct BoxDesc : Desc { - BoxDesc( const math::Vector3& rDimensions = math::Vector3(1,1,1), - // base class: - const String& material_ = "", - const math::Vector3& rPosition = math::Vector3::kZero, - const math::Quaternion& rOrientation = math::Quaternion::kIdentity - ) : - Desc( ST_BOX, rPosition, rOrientation, material_ ), - dimensions( rDimensions ) - {} - math::Vector3 dimensions; + BoxDesc( const Vector3& rDimensions = Vector3(1,1,1), + const Vector3& rPosition = Vector3::kZero, + const Quaternion& rOrientation = Quaternion::kIdentity + ) : + Desc( ST_BOX, rPosition, rOrientation ), + dimensions( rDimensions ) + {} + Vector3 dimensions; }; struct PlaneDesc : Desc { - PlaneDesc( const math::Vector3& rNormal = math::Vector3(0,1,0), + PlaneDesc( const Vector3& rNormal = Vector3(0,1,0), const real d_ = real(1.), // base class: - const String& material_ = "", - const math::Vector3& rPosition = math::Vector3::kZero, - const math::Quaternion& rOrientation = math::Quaternion::kIdentity + const Vector3& rPosition = Vector3::kZero, + const Quaternion& rOrientation = Quaternion::kIdentity ) : - Desc( ST_PLANE, rPosition, rOrientation, material_ ), + Desc( ST_PLANE, rPosition, rOrientation ), normal( rNormal ), d( d_ ) {} - math::Vector3 normal; + Vector3 normal; real d; }; @@ -133,11 +129,10 @@ CapsuleDesc(const real height_ = real(2.), const real radius_ = real(1.), // base class: - const String& material_ = "", - const math::Vector3& rPosition = math::Vector3::kZero, - const math::Quaternion& rOrientation = math::Quaternion::kIdentity + const Vector3& rPosition = Vector3::kZero, + const Quaternion& rOrientation = Quaternion::kIdentity ) : - Desc( ST_CAPSULE, rPosition, rOrientation, material_ ), + Desc( ST_CAPSULE, rPosition, rOrientation ), height( height_ ), radius( radius_ ) {} @@ -150,8 +145,8 @@ TriMeshDesc( const TriangleMeshDesc trimesh, // base class: const String& material_ = "", - const math::Vector3& rPosition = math::Vector3::kZero, - const math::Quaternion& rOrientation = math::Quaternion::kIdentity + const Vector3& rPosition = Vector3::kZero, + const Quaternion& rOrientation = Quaternion::kIdentity ) : Desc( ST_TRIANGLE_MESH, rPosition, rOrientation, material_ ), trimesh_( trimesh ), @@ -159,11 +154,10 @@ {} TriMeshDesc( const TriangleMeshId trimeshId, // base class: - const String& material_ = "", - const math::Vector3& rPosition = math::Vector3::kZero, - const math::Quaternion& rOrientation = math::Quaternion::kIdentity + const Vector3& rPosition = Vector3::kZero, + const Quaternion& rOrientation = Quaternion::kIdentity ) : - Desc( ST_TRIANGLE_MESH, rPosition, rOrientation, material_ ), + Desc( ST_TRIANGLE_MESH, rPosition, rOrientation ), trimeshId_( trimeshId ) {} TriangleMeshDesc trimesh_; @@ -177,10 +171,10 @@ virtual void setMaterial( IMaterial* pMaterial ) = 0; virtual IMaterial* getMaterial() const = 0; - //virtual math::Vector3 getDerivedPosition() const = 0; - //virtual math::Quaternion getDerivedOrientation() const = 0; + //virtual Vector3 getDerivedPosition() const = 0; + //virtual Quaternion getDerivedOrientation() const = 0; - virtual math::Vector3 getPropertyVector3(const String&) const = 0; + virtual Vector3 getPropertyVector3(const String&) const = 0; virtual real getPropertyReal(const String&) const = 0; }; YAKE_PHYSICS_COMMON_POINTERS( IShape ); Modified: trunk/yake/yake/physics/yakePhysicsWorld.h =================================================================== --- trunk/yake/yake/physics/yakePhysicsWorld.h 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/yake/physics/yakePhysicsWorld.h 2007-08-10 15:26:25 UTC (rev 1787) @@ -79,8 +79,8 @@ virtual const StringVector getCurrentSolverParams() const = 0; virtual void setCurrentSolverParam( const String& rName, const boost::any& rValue ) = 0; - virtual void setGlobalGravity( const math::Vector3& g ) = 0; - virtual math::Vector3 getGlobalGravity() const = 0; + virtual void setGlobalGravity( const Vector3& g ) = 0; + virtual Vector3 getGlobalGravity() const = 0; virtual void step(const real timeElapsed) = 0; virtual real getStepSize() const = 0; Modified: trunk/yake/yake/raf/yakeApplicationState.h =================================================================== --- trunk/yake/yake/raf/yakeApplicationState.h 2007-08-06 22:21:06 UTC (rev 1786) +++ trunk/yake/yake/raf/yakeApplicationState.h 2007-08-10 15:26:25 UTC (rev 1787) @@ -72,6 +72,8 @@ //const String& currentName() const; void step(); + + ApplicationState* currentState() const; private: typedef fsm::oomachine<ApplicationState,String> fsm_type; fsm_type machine_; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-06 22:21:03
|
Revision: 1786 http://yake.svn.sourceforge.net/yake/?rev=1786&view=rev Author: psyclonist Date: 2007-08-06 15:21:06 -0700 (Mon, 06 Aug 2007) Log Message: ----------- added missing eol Modified Paths: -------------- trunk/yake/src/bindings.lua/detail/property.lua.cpp Modified: trunk/yake/src/bindings.lua/detail/property.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-08-06 22:19:37 UTC (rev 1785) +++ trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-08-06 22:21:06 UTC (rev 1786) @@ -201,4 +201,4 @@ bind_property(luavm->getLuaState()); } } // namespace yake -#endif // YAKE_ENABLE_LUA_PROPERTY \ No newline at end of file +#endif // YAKE_ENABLE_LUA_PROPERTY This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-06 22:19:36
|
Revision: 1785 http://yake.svn.sourceforge.net/yake/?rev=1785&view=rev Author: psyclonist Date: 2007-08-06 15:19:37 -0700 (Mon, 06 Aug 2007) Log Message: ----------- [build/premake] various fixes for Linux/GCC Modified Paths: -------------- trunk/yake/scripts/premake/deps.lua trunk/yake/scripts/premake/samples.lua trunk/yake/scripts/premake/tools.lua Modified: trunk/yake/scripts/premake/deps.lua =================================================================== --- trunk/yake/scripts/premake/deps.lua 2007-08-06 20:31:00 UTC (rev 1784) +++ trunk/yake/scripts/premake/deps.lua 2007-08-06 22:19:37 UTC (rev 1785) @@ -3,7 +3,11 @@ -------------------------------------- defDep("boost") defDepIncludePath("boost","dependencies/boost") -defDepLibraryPath("boost","dependencies/boost/stage/lib") +defDepLibraryPath("boost","dependencies/boost/stage/lib") +if linux then + defDepLibrary("boost","boost_signals") + defDepLibrary("boost","boost_thread") +end -------------------------------------- -- Dependency package OGRE @@ -83,24 +87,32 @@ -------------------------------------- defDep("lua") defDepIncludePath("lua", "dependencies/lua/src") -defDepLibraryPath("lua","dependencies/lua/lib") -defDepLibrary("lua","lua","Release") -defDepLibrary("lua","lua","ReleaseWithSymbols") -defDepLibrary("lua","lua","ReleaseLib") -defDepLibrary("lua","luad","Debug") -defDepLibrary("lua","luad","DebugLib") +defDepLibraryPath("lua","dependencies/lua/lib") +if windows then + defDepLibrary("lua","lua","Release") + defDepLibrary("lua","lua","ReleaseWithSymbols") + defDepLibrary("lua","lua","ReleaseLib") + defDepLibrary("lua","luad","Debug") + defDepLibrary("lua","luad","DebugLib") +else + defDepLibrary("lua","lua") +end -------------------------------------- -- Dependency package Luabind -------------------------------------- defDep("luabind") defDepIncludePath("luabind", "dependencies/luabind") -defDepLibraryPath("luabind","dependencies/luabind/lib") -defDepLibrary("luabind","luabind","Release") -defDepLibrary("luabind","luabind","ReleaseLib") -defDepLibrary("luabind","luabind","ReleaseWithSymbols") -defDepLibrary("luabind","luabindd","Debug") -defDepLibrary("luabind","luabindd","DebugLib") +defDepLibraryPath("luabind","dependencies/luabind/lib") +if windows then + defDepLibrary("luabind","luabind","Release") + defDepLibrary("luabind","luabind","ReleaseLib") + defDepLibrary("luabind","luabind","ReleaseWithSymbols") + defDepLibrary("luabind","luabindd","Debug") + defDepLibrary("luabind","luabindd","DebugLib") +else + defDepLibrary("luabind","luabind") +end -------------------------------------- -- Dependency package OpenAL++ Modified: trunk/yake/scripts/premake/samples.lua =================================================================== --- trunk/yake/scripts/premake/samples.lua 2007-08-06 20:31:00 UTC (rev 1784) +++ trunk/yake/scripts/premake/samples.lua 2007-08-06 22:19:37 UTC (rev 1785) @@ -214,7 +214,7 @@ useComponent("base") useComponent("task") useComponent("scripting") - useComponent("bindings.lua") + useComponent("bindings.lua") -- <- This resolved all deps of bindings.lua, too! useComponent("scriptingLua") useDep("lua") useDep("luabind") Modified: trunk/yake/scripts/premake/tools.lua =================================================================== --- trunk/yake/scripts/premake/tools.lua 2007-08-06 20:31:00 UTC (rev 1784) +++ trunk/yake/scripts/premake/tools.lua 2007-08-06 22:19:37 UTC (rev 1785) @@ -332,6 +332,38 @@ end end +function priv_finishSample_lib(target,linksdone,lib) + --print("lib="..lib) + if g_libs[lib] then -- it's a Yake library + if g_libs[lib].config[target] and g_libs[lib].config[target].links then + for a,b in g_libs[lib].config[target].links do + if not g_libs[b] and not linksdone[b] and not package.config[target].links[b] then -- only non-Yake libraries as Yake libraries are already bound. + --print(" dep " .. b) + --addDependency(b,target) + linksdone[b] = true + end + end + end + for a,b in g_libs[lib].links do + local shouldLink = not package.links[b] and not linksdone[b] + if windows then + -- only non-Yake libraries as Yake libraries are already bound. + shouldLink = shouldLink and not g_libs[b] + end + if shouldLink then + --print(" dep " .. b) + addDependency(b,target) + -- follow the dep's deps... + priv_finishSample_lib(target,linksdone,b) + linksdone[b] = true + end + end + else -- it's an external lib + --print(" depx " .. lib) + addDependency(lib,target) + linksdone[lib] = true + end +end -- In case of static EXE targets we have to link to the -- dependencies of the immediate dependencies, too. -- For example, it's necessary to link to lua.lib if the @@ -360,28 +392,7 @@ --print(" applying " .. lib) linksdone[lib] = true - if g_libs[lib] then -- it's a Yake library - if g_libs[lib].config[target] and g_libs[lib].config[target].links then - for a,b in g_libs[lib].config[target].links do - if not g_libs[b] and not linksdone[b] then -- only non-Yake libraries as Yake libraries are already bound. - --print(" dep " .. b) - --addDependency(b,target) - linksdone[b] = true - end - end - end - for a,b in g_libs[lib].links do - if not g_libs[b] and not linksdone[b] then -- only non-Yake libraries as Yake libraries are already bound. - --print(" dep " .. b) - addDependency(b,target) - linksdone[b] = true - end - end - else -- it's an external lib - --print(" depx " .. lib) - addDependency(lib,target) - linksdone[lib] = true - end + priv_finishSample_lib(target,linksdone,lib) end end end @@ -389,6 +400,11 @@ -- for static link targets only priv_finishSample_Target("DebugLib") priv_finishSample_Target("ReleaseLib") + if linux then -- for dynamic link targets only on Linux/GCC: + priv_finishSample_Target("Debug") + priv_finishSample_Target("Release") + priv_finishSample_Target("ReleaseWithSymbols") + end end local g_first_sample = true This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-06 20:30:57
|
Revision: 1784 http://yake.svn.sourceforge.net/yake/?rev=1784&view=rev Author: psyclonist Date: 2007-08-06 13:31:00 -0700 (Mon, 06 Aug 2007) Log Message: ----------- [property] fixed several standard compliance issues Modified Paths: -------------- trunk/yake/yake/property/detail/property.impl.h trunk/yake/yake/property/property_container.h trunk/yake/yake/property/stream_operators.h Modified: trunk/yake/yake/property/detail/property.impl.h =================================================================== --- trunk/yake/yake/property/detail/property.impl.h 2007-08-06 20:30:19 UTC (rev 1783) +++ trunk/yake/yake/property/detail/property.impl.h 2007-08-06 20:31:00 UTC (rev 1784) @@ -26,7 +26,8 @@ */ #ifndef YAKE_PROPERTY_IMPL_H #define YAKE_PROPERTY_IMPL_H - + +#include <yake/base/type_info.h> #include "../prerequisites.h" #include "../accessors.h" #include "../function_accessor.h" @@ -43,7 +44,10 @@ /** */ struct PropertyBase : public boost::noncopyable { - PropertyBase(const String& type, const type_info* typeInfo) : typeName_(type), typeInfo_(typeInfo) + PropertyBase( const String& type, + const std::type_info* typeInfo) : + typeName_(type), + typeInfo_(typeInfo) { } virtual ~PropertyBase() @@ -54,7 +58,7 @@ { return typeName_; } - const type_info* typeinfo() const + const std::type_info* typeinfo() const { return typeInfo_; } @@ -81,7 +85,7 @@ private: String typeName_; //property_def_base& def_; - const type_info* typeInfo_; + const std::type_info* typeInfo_; }; /** */ @@ -145,7 +149,7 @@ void try_cast_set_from_any(PropertyBase& prop, const boost::any& rhs) { //YAKE_ASSERT( &typeid(T) == rhs.typeinfo() ); - if (&typeid(T) != rhs.typeinfo()) + if (YAKE_TYPEID_EQ(YAKE_TYPEID(T),rhs.type())) throw BadCastException(String("try_cast_set_from_any<> failed: bad cast")); //safe: //prop.setAny(rhs); // from any Modified: trunk/yake/yake/property/property_container.h =================================================================== --- trunk/yake/yake/property/property_container.h 2007-08-06 20:30:19 UTC (rev 1783) +++ trunk/yake/yake/property/property_container.h 2007-08-06 20:31:00 UTC (rev 1784) @@ -112,7 +112,7 @@ this->onInvalidInput("null pointer"); return; } - PropertyMap::const_iterator it = properties_.find( id ); + typename PropertyMap::const_iterator it = properties_.find( id ); if (it != properties_.end()) { this->onAlreadyExists(id); //@todo possible memory leak if client doesn't clean up "prop" @@ -128,7 +128,7 @@ this->onInvalidInput("null pointer"); return; } - PropertyMap::const_iterator it = properties_.find( id ); + typename PropertyMap::const_iterator it = properties_.find( id ); if (it != properties_.end()) { this->onAlreadyExists(id); //@todo possible memory leak if client doesn't clean up "prop" @@ -139,7 +139,7 @@ template<typename Kt, template <typename> class ErrorPolicy> const PropertyBase& PropertyContainer<Kt,ErrorPolicy>::get(const key_type& id) const { - PropertyMap::const_iterator it = properties_.find( id ); + typename PropertyMap::const_iterator it = properties_.find( id ); if (it == properties_.end()) { this->onNotFound(id); // should throw! @@ -150,7 +150,7 @@ template<typename Kt, template <typename> class ErrorPolicy> PropertyBase& PropertyContainer<Kt,ErrorPolicy>::get(const key_type& id) { - PropertyMap::const_iterator it = properties_.find( id ); + typename PropertyMap::const_iterator it = properties_.find( id ); if (it == properties_.end()) { this->onNotFound(id); // should throw! @@ -161,7 +161,7 @@ template<typename Kt, template <typename> class ErrorPolicy> PropertyPtr PropertyContainer<Kt,ErrorPolicy>::getPtr(const key_type& id) const { - PropertyMap::const_iterator it = properties_.find( id ); + typename PropertyMap::const_iterator it = properties_.find( id ); if (it == properties_.end()) { //this->onNotFound(id); // should throw! @@ -173,7 +173,7 @@ template<typename Kt, template <typename> class ErrorPolicy> bool PropertyContainer<Kt,ErrorPolicy>::has(const key_type& id) const { - PropertyMap::const_iterator it = properties_.find( id ); + typename PropertyMap::const_iterator it = properties_.find( id ); return (it != properties_.end()); } Modified: trunk/yake/yake/property/stream_operators.h =================================================================== --- trunk/yake/yake/property/stream_operators.h 2007-08-06 20:30:19 UTC (rev 1783) +++ trunk/yake/yake/property/stream_operators.h 2007-08-06 20:31:00 UTC (rev 1784) @@ -52,12 +52,12 @@ return out; } - template<typename Kt, typename ErrorPolicy> + template<typename Kt, template<class> class ErrorPolicy> inline std::ostream& operator << (std::ostream& out, const PropertyContainer<Kt,ErrorPolicy>& rhs) { typedef PropertyContainer<Kt,ErrorPolicy> cont_t; out << "PropertyContainer<Kt=" << getCleanTypeName<Kt>() << ",ErrorPolicy=..." /*<< getCleanTypeName<typename cont_t::error_policy_t>() <<*/ ">(\n"; - for (cont_t::const_property_iterator it = rhs.begin(); it != rhs.end(); ++it) + for (typename cont_t::const_iterator it = rhs.begin(); it != rhs.end(); ++it) { out << " '" << it->first << "': " << *it->second << "\n"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-06 20:30:16
|
Revision: 1783 http://yake.svn.sourceforge.net/yake/?rev=1783&view=rev Author: psyclonist Date: 2007-08-06 13:30:19 -0700 (Mon, 06 Aug 2007) Log Message: ----------- [logging] fixed deadlock problem Modified Paths: -------------- trunk/yake/yake/base/yakeLog.h Modified: trunk/yake/yake/base/yakeLog.h =================================================================== --- trunk/yake/yake/base/yakeLog.h 2007-08-02 16:37:47 UTC (rev 1782) +++ trunk/yake/yake/base/yakeLog.h 2007-08-06 20:30:19 UTC (rev 1783) @@ -37,6 +37,7 @@ #include <yake/base/native/yakeThreads.h> #include <boost/thread/mutex.hpp> +#include <boost/thread/recursive_mutex.hpp> namespace yake { namespace logging { @@ -98,14 +99,14 @@ EnableMap enabledSeverities_; typedef std::map<std::string,bool> EnableLogIdMap; EnableLogIdMap enabledLogs_; - boost::mutex mtx_; + boost::recursive_mutex mtx_; struct scoped_lock; friend struct scoped_lock; struct scoped_lock : public boost::noncopyable { scoped_lock(); private: - boost::mutex::scoped_lock lck_; + boost::recursive_mutex::scoped_lock lck_; }; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-08-02 16:37:44
|
Revision: 1782 http://yake.svn.sourceforge.net/yake/?rev=1782&view=rev Author: psyclonist Date: 2007-08-02 09:37:47 -0700 (Thu, 02 Aug 2007) Log Message: ----------- sampleEntFsm: bind 'this' Modified Paths: -------------- trunk/yake/samples/ent/sampleEntFsm/demo.cpp Modified: trunk/yake/samples/ent/sampleEntFsm/demo.cpp =================================================================== --- trunk/yake/samples/ent/sampleEntFsm/demo.cpp 2007-07-31 15:26:35 UTC (rev 1781) +++ trunk/yake/samples/ent/sampleEntFsm/demo.cpp 2007-08-02 16:37:47 UTC (rev 1782) @@ -181,6 +181,8 @@ 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 @@ -211,7 +213,10 @@ 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; + // 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. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-31 15:26:33
|
Revision: 1781 http://yake.svn.sourceforge.net/yake/?rev=1781&view=rev Author: psyclonist Date: 2007-07-31 08:26:35 -0700 (Tue, 31 Jul 2007) Log Message: ----------- added scripts/msvc80/make_single.cmd Added Paths: ----------- trunk/yake/scripts/msvc80/make_single.cmd Added: trunk/yake/scripts/msvc80/make_single.cmd =================================================================== --- trunk/yake/scripts/msvc80/make_single.cmd (rev 0) +++ trunk/yake/scripts/msvc80/make_single.cmd 2007-07-31 15:26:35 UTC (rev 1781) @@ -0,0 +1,43 @@ +@echo off +rem ---------------------------------------------------------------------------- +rem Uses devenv.com to build all targets of Yake's libraries and plugins. +rem ---------------------------------------------------------------------------- + +if $%1$ == $$ ( + echo Usage: make_single [project] + echo. + goto end +) + +if not exist %1.vcproj ( + echo ERROR: %1.vcproj not found. Did you run build.cmd? + goto end +) + +rem if not exist yake.sln ( +rem echo ERROR: yake.sln not found. Did you run build.cmd? +rem goto end +rem ) + +if $"%VS80COMNTOOLS%"$ == $""$ ( + echo ERROR: System variable VS80COMNTOOLS not set! + echo Is Visual Studio 2005 installed? + goto end +) +if not exist "%VS80COMNTOOLS%..\IDE\devenv.com" ( + echo ERROR: Could not locate Visual Studio's devenv.com. + echo File: %VS80COMNTOOLS%..\IDE\devenv.com + echo. + goto end +) + +echo Building '%1' (and its dependencies in the solution) ... +echo Starting build for 'Debug' target... +call "%VS80COMNTOOLS%..\IDE\devenv.com" /build Debug /project net %1.vcproj 2>&1 | find "error(s)" +echo Starting build for 'DebugLib' target... +echo Starting build for 'Release' target... +echo Starting build for 'ReleaseLib' target... +echo Starting build for 'ReleaseWithSymbols' target... + +:end +pause This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-31 15:25:09
|
Revision: 1780 http://yake.svn.sourceforge.net/yake/?rev=1780&view=rev Author: psyclonist Date: 2007-07-31 08:25:07 -0700 (Tue, 31 Jul 2007) Log Message: ----------- added docs on bindings.lua (events, properties) Modified Paths: -------------- trunk/yake/documentation/manual/yake-manual.txt Modified: trunk/yake/documentation/manual/yake-manual.txt =================================================================== --- trunk/yake/documentation/manual/yake-manual.txt 2007-07-31 14:08:38 UTC (rev 1779) +++ trunk/yake/documentation/manual/yake-manual.txt 2007-07-31 15:25:07 UTC (rev 1780) @@ -770,14 +770,55 @@ Entity Scripting Using Lua ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Properties +.......... + +Add property to current entity ("this"):: + + this:properties():create("age",42) -- Adds property of type 'int' + this:properties():create("name","Jack") -- Adds property of type string (yake::String) + +Query property object:: + + local age = this:properties():get("age") -- stores property pointer in age + print(age:get()) -- prints 42 + +Or alternatively:: + + local age = this:property("age") + print(age:get()) + +Or without local object:: + + print( this:property("age"):get() ) + +Setting values:: + + this:property("age"):set(32) -- Yay for un-aging! + +Setting values of incorrect type (and handling the error):: + + if not this:property("age"):set(32) do + print("Failed to reset my age!") + end + +Built-in properties are registered as Lua properties and can be accessed in +a more convenient way. One of the default built-in properties is ent::Object's +"id" property:: + + print( this.id ) -- prints 'ObjectId(..,..)' + this.id = yake.ObjectId(42,12) -- Is that a good idea? Well, ... + + Events ...... -Add event to current entity ("self"):: +Add event to current entity ("this"):: - self:events():add("tick") + this:events():add("tick") -Add event to current entity ("self") with shortcut syntax:: +Add event to current entity ("this") with shortcut syntax:: events():add("tick") @@ -793,14 +834,15 @@ events("tick"):fire() --prints: nil events("tick"):fire(42) --prints: 42 - + events("tick"):fire(self.id) --prints: ObjectId(..,..) + .. note:: The event parameter on the C++ side is stored in a boost::any. Types that can be stored in a boost any have to be explicitly registered with Lua. Therefore not all types may be available as parameters. If you use an unsupported type - execution will result in an error. - + execution will stop and an error will be reported. + Scheduler/Executor .................. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-31 14:08:36
|
Revision: 1779 http://yake.svn.sourceforge.net/yake/?rev=1779&view=rev Author: psyclonist Date: 2007-07-31 07:08:38 -0700 (Tue, 31 Jul 2007) Log Message: ----------- use yake::TypeInfo instead of std::type_info Modified Paths: -------------- trunk/yake/src/bindings.lua/detail/property.lua.cpp Modified: trunk/yake/src/bindings.lua/detail/property.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-07-31 14:08:08 UTC (rev 1778) +++ trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-07-31 14:08:38 UTC (rev 1779) @@ -58,7 +58,7 @@ } PropertyPtr createPropertyFromAny(const boost::any& o) { - const std::type_info* ti = &o.type(); + const TypeInfo ti( &o.type() ); PropertyFromAnyMap::const_iterator it = any_property_creators().find( ti ); if (it == any_property_creators().end() || !it->second) return PropertyPtr(); //@todo log this? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-31 14:08:08
|
Revision: 1778 http://yake.svn.sourceforge.net/yake/?rev=1778&view=rev Author: psyclonist Date: 2007-07-31 07:08:08 -0700 (Tue, 31 Jul 2007) Log Message: ----------- [bindings.lua] any converters need only be registered once Modified Paths: -------------- trunk/yake/src/bindings.lua/detail/base.lua.cpp trunk/yake/src/bindings.lua/detail/ent.lua.cpp Modified: trunk/yake/src/bindings.lua/detail/base.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/base.lua.cpp 2007-07-27 16:46:44 UTC (rev 1777) +++ trunk/yake/src/bindings.lua/detail/base.lua.cpp 2007-07-31 14:08:08 UTC (rev 1778) @@ -39,19 +39,27 @@ namespace yake { namespace math { + //------------------------------------------------------------------------- + namespace { + struct AnyConverterIniter + { + AnyConverterIniter() + { + register_any_converter<Color>(); + register_any_converter<Vector3>(); + register_any_converter<Quaternion>(); + register_any_converter<Matrix3>(); + } + } g_initer; + } // namespace + //------------------------------------------------------------------------- void bind(lua_State* L) { YAKE_ASSERT(L); if (!L) return; // - register_any_converter<Color>(); - register_any_converter<Vector3>(); - register_any_converter<Quaternion>(); - register_any_converter<Matrix3>(); - - // using namespace luabind; #define YAKE_MATH_MODULE L, "yake" Modified: trunk/yake/src/bindings.lua/detail/ent.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-07-27 16:46:44 UTC (rev 1777) +++ trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-07-31 14:08:08 UTC (rev 1778) @@ -42,7 +42,19 @@ namespace yake { namespace ent { + //------------------------------------------------------------------------- + namespace { + struct AnyConverterIniter + { + AnyConverterIniter() + { + register_any_converter<ObjectId>(); + //register_property_value_converter<ObjectId>(); + } + } g_initer; + } // namespace + //------------------------------------------------------------------------- // For Lua's tostring(): // std::ostream& operator<<(std::ostream& out, const ObjectId& rhs) // { @@ -140,10 +152,6 @@ return; // - register_any_converter<ObjectId>(); - //register_property_value_converter<ObjectId>(); - - // using namespace luabind; using namespace yake::model; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-27 16:46:44
|
Revision: 1777 http://yake.svn.sourceforge.net/yake/?rev=1777&view=rev Author: psyclonist Date: 2007-07-27 09:46:44 -0700 (Fri, 27 Jul 2007) Log Message: ----------- * bindings.lua: any converter now uses type_info wrapper Modified Paths: -------------- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h Modified: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp 2007-07-27 16:41:39 UTC (rev 1776) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp 2007-07-27 16:46:44 UTC (rev 1777) @@ -50,10 +50,10 @@ void convert_cpp_to_lua(lua_State* L, const boost::any& a) { typedef void(*conv_t)(lua_State* L, const boost::any&); - const std::type_info* ti = &a.type(); + const yake::TypeInfo ti( &a.type() ); // special case: 'boost::any(void)' is converted to 'nil' - if (ti == &typeid(void)) + if (YAKE_TYPEINFO_EQ(ti,YAKE_TYPEID(void))) { //std::cout << "(warning: converted void to nil)\n"; lua_pushnil(L); @@ -64,14 +64,14 @@ any_converter_map::const_iterator it = convs.begin(); while (it != convs.end()) { - if (*(it->first) == *ti) + if (YAKE_TYPEINFO_EQ(it->first,ti)) break; ++it; } //any_converter_map::const_iterator it = convs.find(ti); if (it == any_converters().end()) //@todo We could just push nil ? - throw yake::Exception(std::string("convert_cpp_to_lua() failed to convert '") + ti->name() + "'."); + throw yake::Exception(std::string("convert_cpp_to_lua() failed to convert '") + YAKE_TYPEINFO_NAME(ti) + "'."); conv_t conv = it->second; conv(L, a); } Modified: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-07-27 16:41:39 UTC (rev 1776) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-07-27 16:46:44 UTC (rev 1777) @@ -29,6 +29,7 @@ // #include <yake/base/yakePrerequisites.h> +#include <yake/base/type_info.h> #include <yake/bindings.lua/prerequisites.h> #include <yake/bindings.lua/common/yake.lua.common.h> #include <map> @@ -44,11 +45,11 @@ struct PropertyBase; typedef PropertyBase*(*PropertyFromAnyFn)(const boost::any&); - typedef std::map<const std::type_info*,PropertyFromAnyFn> PropertyFromAnyMap; + typedef std::map<TypeInfo,PropertyFromAnyFn> PropertyFromAnyMap; YAKE_LUA_ANY_CONVERTER_API PropertyFromAnyMap& any_property_creators(); typedef PropertyBase*(*PropertyFromObjectFn)(const luabind::object&); - typedef std::map<const std::type_info*,PropertyFromObjectFn> PropertyFromObjectMap; + typedef std::map<TypeInfo,PropertyFromObjectFn> PropertyFromObjectMap; YAKE_LUA_ANY_CONVERTER_API PropertyFromObjectMap& object_property_creators(); typedef luabind::class_<PropertyBase> LuabindClass_PropertyBase; @@ -79,10 +80,10 @@ // luabind::object -> boost::any (for everything except native Lua types): typedef bool(*TryAnyFromObjectFn)(const luabind::object&); - typedef std::map<const std::type_info*,TryAnyFromObjectFn> TryAnyFromObjectMap; + typedef std::map<yake::TypeInfo,TryAnyFromObjectFn> TryAnyFromObjectMap; YAKE_LUA_ANY_CONVERTER_API TryAnyFromObjectMap& try_any_from_object_map(); typedef bool(*AnyFromObjectFn)(const luabind::object&,boost::any&); - typedef std::map<const std::type_info*,AnyFromObjectFn> AnyFromObjectMap; + typedef std::map<yake::TypeInfo,AnyFromObjectFn> AnyFromObjectMap; YAKE_LUA_ANY_CONVERTER_API AnyFromObjectMap& any_from_object_map(); // boost::any bindings @@ -142,7 +143,7 @@ } }; - typedef std::map<const std::type_info*, void(*)(lua_State*, const boost::any&)> any_converter_map; + typedef std::map<yake::TypeInfo, void(*)(lua_State*, const boost::any&)> any_converter_map; YAKE_LUA_ANY_CONVERTER_API any_converter_map& any_converters(); //any_converter_map any_converters; @@ -151,8 +152,9 @@ template<class T> inline void register_property_value_converter() { - yake::property::any_property_creators()[&typeid(T)] = convert_any<T>::yake_createValuePropertyFromAny; - yake::property::object_property_creators()[&typeid(T)] = convert_any<T>::yake_createValuePropertyFromObject; + const yake::TypeInfo ti = YAKE_TYPEID(T); + yake::property::any_property_creators()[ti] = convert_any<T>::yake_createValuePropertyFromAny; + yake::property::object_property_creators()[ti] = convert_any<T>::yake_createValuePropertyFromObject; yake::property::setPropertyValue_binders().push_back( convert_any<T>::yake_bind_setPropertyValue ); } #endif @@ -160,9 +162,10 @@ template<class T> inline void register_any_converter() { - any_converters()[&typeid(T)] = convert_any<T>::convert; - any_from_object_map()[&typeid(T)] = convert_any<T>::yake_anyFromObject; - try_any_from_object_map()[&typeid(T)] = convert_any<T>::yake_tryAnyFromObject; + const yake::TypeInfo ti = YAKE_TYPEID(T); + any_converters()[ti] = convert_any<T>::convert; + any_from_object_map()[ti] = convert_any<T>::yake_anyFromObject; + try_any_from_object_map()[ti] = convert_any<T>::yake_tryAnyFromObject; #if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: register_property_value_converter<T>(); #endif @@ -176,9 +179,10 @@ template<> inline void register_any_converter<luabind::object>() { - any_converters()[&typeid(luabind::object)] = convert_any<luabind::object>::convert; + const yake::TypeInfo ti = YAKE_TYPEID(luabind::object); + any_converters()[ti] = convert_any<luabind::object>::convert; #if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: - yake::property::any_property_creators()[&typeid(luabind::object)] = convert_any<luabind::object>::yake_createValuePropertyFromAny; + yake::property::any_property_creators()[ti] = convert_any<luabind::object>::yake_createValuePropertyFromAny; yake::property::setPropertyValue_binders().push_back( convert_any<luabind::object>::yake_bind_setPropertyValue ); #endif } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-27 16:41:38
|
Revision: 1776 http://yake.svn.sourceforge.net/yake/?rev=1776&view=rev Author: psyclonist Date: 2007-07-27 09:41:39 -0700 (Fri, 27 Jul 2007) Log Message: ----------- Rewrite of std::type_info wrapper Modified Paths: -------------- trunk/yake/yake/base/type_info.h Modified: trunk/yake/yake/base/type_info.h =================================================================== --- trunk/yake/yake/base/type_info.h 2007-07-27 16:09:14 UTC (rev 1775) +++ trunk/yake/yake/base/type_info.h 2007-07-27 16:41:39 UTC (rev 1776) @@ -28,83 +28,60 @@ #define _YAKE_BASE_TYPE_INFO_ #include <typeinfo> -#include <cassert> +#include <yake/base/yakePrerequisites.h> +#include <yake/base/templates/yakeSmartAssert.h> -namespace yake -{ -namespace base -{ - -class type_info -{ -public: // constructors - type_info(); // needed for containers - type_info(const std::type_info &); // non-explicit +namespace yake { - // access for the wrapped std::type_info - const std::type_info & Get() const; - // compatibility functions - bool before(const type_info & rhs) const; - const char * name() const; + struct TypeInfo + { + TypeInfo(const TypeInfo& rhs) : ti_(rhs.ti_) + {} + const TypeInfo& operator = (const TypeInfo& rhs) + { + if (this != &rhs) + ti_ = rhs.ti_; + return *this; + } + bool operator == (const TypeInfo& rhs) const + { + return (*ti_ == *rhs.ti_); + } + bool operator != (const TypeInfo& rhs) const + { + return !(*this == rhs); + } + bool operator < (const TypeInfo& rhs) const + { + return (ti_->before(*rhs.ti_)) != 0; + } + template<typename T> + static TypeInfo get() + { + return TypeInfo(&typeid(T)); + } + const char* name() const + { + return ti_->name(); + } + //private: + TypeInfo(const std::type_info* ti) : ti_(ti) + { + YAKE_ASSERT( ti ); + } + private: + const std::type_info* ti_; + }; + template<typename T> + inline TypeInfo TypeId() + { return TypeInfo::get<T>(); } -private: // data - const std::type_info * m_info; -}; +#define YAKE_TYPEID(T) (::yake::TypeId<T>()) +#define YAKE_TYPEINFO ::yake::TypeInfo +#define YAKE_TYPEINFO_EQ(A,B) (A == B) +#define YAKE_TYPEINFO_NEQ(A,B) (A != B) +#define YAKE_TYPEINFO_NAME(ti) ti.name() -/* Implementation */ - -inline type_info::type_info() -{ - class nil {}; - m_info = &typeid(nil); - assert(m_info); -} - -inline type_info::type_info(const std::type_info & ti) - : m_info(&ti) -{ assert(m_info); } - -inline bool type_info::before(const type_info & rhs) const -{ - assert(m_info); - // type_info::before return type is int in some VC libraries - return m_info->before(*rhs.m_info) != 0; -} - -inline const std::type_info& type_info::Get() const -{ - assert(m_info); - return *m_info; -} - -inline const char * type_info::name() const -{ - assert(m_info); - return m_info->name(); -} - -/* Comparison operators */ - -inline bool operator==(const type_info & lhs, const type_info & rhs) -// type_info::operator== return type is int in some VC libraries -{ return (lhs.Get() == rhs.Get()) != 0; } - -inline bool operator<(const type_info & lhs, const type_info & rhs) -{ return lhs.before(rhs); } - -inline bool operator!=(const type_info & lhs, const type_info & rhs) -{ return !(lhs == rhs); } - -inline bool operator>(const type_info & lhs, const type_info & rhs) -{ return rhs < lhs; } - -inline bool operator<=(const type_info & lhs, const type_info & rhs) -{ return !(lhs > rhs); } - -inline bool operator>=(const type_info & lhs, const type_info & rhs) -{ return !(lhs < rhs); } - -} // namespace base } // namespace yake #endif // _YAKE_BASE_TYPE_INFO_ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-27 16:09:12
|
Revision: 1775 http://yake.svn.sourceforge.net/yake/?rev=1775&view=rev Author: psyclonist Date: 2007-07-27 09:09:14 -0700 (Fri, 27 Jul 2007) Log Message: ----------- * added events to yake::ent Objects * added Lua bindings for yake::ent::Object events * provided "luabind::object to boost::any" conversion for non-built-in-Lua types (performance overhead) for all registered "boost::any to Lua converts" Modified Paths: -------------- trunk/yake/src/bindings.lua/detail/ent.lua.cpp trunk/yake/src/ent/object.cpp trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h trunk/yake/yake/ent/object.h Modified: trunk/yake/src/bindings.lua/detail/ent.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-07-26 17:57:16 UTC (rev 1774) +++ trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-07-27 16:09:14 UTC (rev 1775) @@ -60,6 +60,24 @@ typedef luabind::class_<Object::PropertyAccess> LuabindClass_Object_PropertyAccess; //------------------------------------------------------------------------- + static void Object_Event_fire_noparams(Object::Event& evt) + { + evt.fire(); + } + static void Object_Event_fire_1param(Object::Event& evt, const boost::any& a0) + { + evt.fire(a0); + } + static bool Object_Event_connect(Object::Event& evt, luabind::object o) + { + if (!o || (luabind::type(o) != LUA_TFUNCTION)) + { + std::cerr << "WARNING: Object::Event::connect: Parameter is not a function!\n"; + return false; + } + evt.connect( o ); + return true; + } static property::PropertyBase* getPropertyOfObject(Object& o, const PropertyId& id) { return o.properties().get(id).get(); @@ -73,6 +91,11 @@ { return o.get( id ).get(); } + static Object::EventAccess* getObjectEvents(Object& o) + { + Object::EventAccess& x = o.events(); + return &x; + } //------------------------------------------------------------------------- // Helper struct so that we gain access to the private member // "properties_" in Object::PropertyAccess: @@ -157,12 +180,34 @@ module( YAKE_MODEL_MODULE ) [ x_Object_PropertyAccess ]; + module( YAKE_MODEL_MODULE ) + [ + class_<Object::Event::ID>("Object::Event::ID") + .def(tostring(const_self)) + , + class_<Object::Event>("ObjectEvent") + .def( constructor<>() ) + .def( "connect", &Object::Event::connect ) + .def( "connect", &Object_Event_connect ) + //.def( self(Object::Event()) ) // call () operator + .def( "fire", &Object_Event_fire_noparams ) // without params + //.def( "fire", &Object::Event::fire ) // with 1 param + .def( "fire", &Object_Event_fire_1param ) + , + class_<Object::EventAccess>("Object::PropertyAccess") + .def( "has", &Object::EventAccess::has ) + .def( "get", &Object::EventAccess::get ) + .def( "add", &Object::EventAccess::add ) + .def( "create", &Object::EventAccess::createAndAdd ) + ]; + LuabindClass_Object x_Object("Object"); x_Object //.def( constructor<>() ) //.def( "setId", &Object::setId ) //.def( "id", &Object::getId ) .property( "id", &Object::getId, &Object::setId ) + .def( "events", &getObjectEvents ) .def( "property", &getPropertyOfObject ) .def( "properties", &getObjectPoperties ) //.def( "properties", return_reference_to(_1) ) Modified: trunk/yake/src/ent/object.cpp =================================================================== --- trunk/yake/src/ent/object.cpp 2007-07-26 17:57:16 UTC (rev 1774) +++ trunk/yake/src/ent/object.cpp 2007-07-27 16:09:14 UTC (rev 1775) @@ -82,6 +82,14 @@ } listenerConnections_.clear(); } + Object::EventAccess& Object::events() + { + return eventAccess_; + } + const Object::EventAccess& Object::events() const + { + return eventAccess_; + } Object::PropertyAccess& Object::properties() { return propertyAcess_; @@ -90,6 +98,32 @@ { return propertyAcess_; } + Object::Event::Event() + { + } + bool Object::EventAccess::has(const Event::ID& id) const + { + return (events_.find(id) != events_.end()); + } + Object::Event::pointer Object::EventAccess::get(const Event::ID& id) + { + EventMap::iterator it = events_.find(id); + return (it == events_.end()) ? 0 : it->second.get(); + } + void Object::EventAccess::add(const Event::ID& id, Event::pointer evt) + { + YAKE_ASSERT( !has(id) ).debug("duplicate entry - replacing original"); + events_[ id ] = storage(evt); + } + Object::Event::pointer Object::EventAccess::createAndAdd(const Event::ID& id) + { + YAKE_ASSERT( !has(id) ).debug("event with this id already exists"); + if (has(id)) + return 0; + storage evt( new Event() ); + events_[ id ] = evt; + return evt.get(); + } Object::PropertyAccess::PropertyAccess(NamedProperties& props) : properties_(props) { } Modified: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp 2007-07-26 17:57:16 UTC (rev 1774) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp 2007-07-27 16:09:14 UTC (rev 1775) @@ -31,9 +31,18 @@ static any_converter_map s_converters; return s_converters; } +AnyFromObjectMap& any_from_object_map() +{ + static AnyFromObjectMap s_converters; + return s_converters; +} +TryAnyFromObjectMap& try_any_from_object_map() +{ + static TryAnyFromObjectMap s_converters; + return s_converters; +} - namespace luabind { namespace converters @@ -79,6 +88,20 @@ return boost::any( object_cast<std::string>(o) ); //@todo fixme //case LUA_TFUNCTION: // return boost::any( o ); + case LUA_TUSERDATA: + { + //@todo optimize? + boost::any out; + const AnyFromObjectMap& convs = any_from_object_map(); + for (AnyFromObjectMap::const_iterator it = convs.begin(); + it != convs.end(); ++it) + { + const AnyFromObjectFn& fn = it->second; + if (fn(o,out)) + return out; + } + } + // fall-through: default: throw yake::Exception("encountered unsupported type in convert_lua_to_cpp()"); } @@ -97,6 +120,20 @@ return boost::any( object_cast<std::string>(o) ); //@todo fixme //case LUA_TFUNCTION: // return boost::any( o ); + case LUA_TUSERDATA: + { + //@todo optimize? + boost::any out; + const AnyFromObjectMap& convs = any_from_object_map(); + for (AnyFromObjectMap::const_iterator it = convs.begin(); + it != convs.end(); ++it) + { + const AnyFromObjectFn& fn = it->second; + if (fn(o,out)) + return out; + } + } + // fall-through: default: throw yake::Exception("encountered unsupported type in convert_lua_to_cpp()"); } @@ -112,6 +149,19 @@ case LUA_TSTRING: //case LUA_TFUNCTION: return 0; + case LUA_TUSERDATA: + { + //@todo optimize? + const TryAnyFromObjectMap& convs = try_any_from_object_map(); + for (TryAnyFromObjectMap::const_iterator it = convs.begin(); + it != convs.end(); ++it) + { + const TryAnyFromObjectFn& fn = it->second; + if (fn(o)) + return 0; + } + } + return -1; default: return -1; } @@ -127,6 +177,19 @@ case LUA_TSTRING: //case LUA_TFUNCTION: return 0; + case LUA_TUSERDATA: + { + //@todo optimize? + const TryAnyFromObjectMap& convs = try_any_from_object_map(); + for (TryAnyFromObjectMap::const_iterator it = convs.begin(); + it != convs.end(); ++it) + { + const TryAnyFromObjectFn& fn = it->second; + if (fn(o)) + return 0; + } + } + return -1; default: return -1; } Modified: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-07-26 17:57:16 UTC (rev 1774) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-07-27 16:09:14 UTC (rev 1775) @@ -77,6 +77,14 @@ } // namespace yake #endif + // luabind::object -> boost::any (for everything except native Lua types): + typedef bool(*TryAnyFromObjectFn)(const luabind::object&); + typedef std::map<const std::type_info*,TryAnyFromObjectFn> TryAnyFromObjectMap; + YAKE_LUA_ANY_CONVERTER_API TryAnyFromObjectMap& try_any_from_object_map(); + typedef bool(*AnyFromObjectFn)(const luabind::object&,boost::any&); + typedef std::map<const std::type_info*,AnyFromObjectFn> AnyFromObjectMap; + YAKE_LUA_ANY_CONVERTER_API AnyFromObjectMap& any_from_object_map(); + // boost::any bindings template<class T> struct convert_any @@ -117,6 +125,21 @@ x.def("set",&yake::property::setPropertyValue_Generic<T>); } #endif + static bool yake_anyFromObject(const luabind::object& a, boost::any& out) + { + boost::optional<T> value = luabind::object_cast_nothrow<T>(a); + if (!value) + return false; //@todo report error ? + out = *value; + return true; + } + static bool yake_tryAnyFromObject(const luabind::object& a) + { + boost::optional<T> value = luabind::object_cast_nothrow<T>(a); + if (!value) + return false; //@todo report error ? + return true; + } }; typedef std::map<const std::type_info*, void(*)(lua_State*, const boost::any&)> any_converter_map; @@ -138,6 +161,8 @@ inline void register_any_converter() { any_converters()[&typeid(T)] = convert_any<T>::convert; + any_from_object_map()[&typeid(T)] = convert_any<T>::yake_anyFromObject; + try_any_from_object_map()[&typeid(T)] = convert_any<T>::yake_tryAnyFromObject; #if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: register_property_value_converter<T>(); #endif Modified: trunk/yake/yake/ent/object.h =================================================================== --- trunk/yake/yake/ent/object.h 2007-07-26 17:57:16 UTC (rev 1774) +++ trunk/yake/yake/ent/object.h 2007-07-27 16:09:14 UTC (rev 1775) @@ -30,6 +30,7 @@ #include "yake/ent/prerequisites.h" #include "yake/ent/object_listener.h" #include "yake/ent/vm_holder.h" +#include "yake/base/yakeNoncopyable.h" #include "yake/prop/prop_def.h" #include "yake/prop/rtti_class.h" @@ -115,6 +116,44 @@ NamedProperties* __properties() { return &properties_; } + + // Events + struct EventAccess; + struct YAKE_ENT_API Event : public noncopyable + { + friend struct EventAccess; + //private: + Event(); + public: + typedef Event* pointer; + typedef String ID; + typedef boost::any param_type; + private: + typedef boost::signal<void(const param_type&)> EventFireSignal; + public: + typedef SignalConnection connection; + connection connect(const EventFireSignal::slot_type& slot) + { return this->sig_.connect(slot); } + void fire(const param_type& a0 = param_type()) + { this->sig_(a0); } + void operator()(const param_type& a0 = param_type()) + { this->fire(a0); } + private: + EventFireSignal sig_; + }; + struct YAKE_ENT_API EventAccess : public noncopyable + { + Event::pointer get(const Event::ID&); + bool has(const Event::ID&) const; + void add(const Event::ID&, Event::pointer); + Event::pointer createAndAdd(const Event::ID&); + private: + typedef SharedPtr<Event> storage; + typedef std::map<Event::ID,storage> EventMap; + EventMap events_; + }; + EventAccess& events(); + const EventAccess& events() const; protected: virtual void onInit() {} virtual void onTick() {} @@ -124,6 +163,7 @@ listenerconnetion_list listenerConnections_; NamedProperties properties_; PropertyAccess propertyAcess_; + EventAccess eventAccess_; }; } // namespace ent This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-26 17:57:19
|
Revision: 1774 http://yake.svn.sourceforge.net/yake/?rev=1774&view=rev Author: psyclonist Date: 2007-07-26 10:57:16 -0700 (Thu, 26 Jul 2007) Log Message: ----------- * improved Lua bindings for yake.property, yake.ent, yake.object and other components * fixed boost::any conversions where it failed in special cases * improved samples using Lua bindings * added properties to yake.ent (using yake.properties instead of yake.prop) along with default properties for ent::Object and ent::Entity etc pp * added 'default binder' functionality to basic IVM scripting interface Modified Paths: -------------- trunk/yake/samples/README.TXT trunk/yake/samples/property/lua1/demo.cpp trunk/yake/scripts/premake/samples.lua trunk/yake/src/bindings.lua/bindings.lua.cpp trunk/yake/src/bindings.lua/detail/ent.lua.cpp trunk/yake/src/bindings.lua/detail/property.lua.cpp trunk/yake/src/ent/entity.cpp trunk/yake/src/ent/object.cpp trunk/yake/src/plugins/scriptingLua/ScriptingSystemLua.cpp trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h trunk/yake/yake/ent/component.h trunk/yake/yake/ent/entity.h trunk/yake/yake/ent/object.h trunk/yake/yake/ent/prerequisites.h trunk/yake/yake/plugins/scriptingLua/ScriptingSystemLua.h trunk/yake/yake/property/accessors.h trunk/yake/yake/property/property.h trunk/yake/yake/property/property_container.h trunk/yake/yake/scripting/yakeScriptingSystem.h Added Paths: ----------- trunk/yake/yake/bindings.lua/detail/property.lua.h Modified: trunk/yake/samples/README.TXT =================================================================== --- trunk/yake/samples/README.TXT 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/samples/README.TXT 2007-07-26 17:57:16 UTC (rev 1774) @@ -11,11 +11,14 @@ raf/minimal - bare-bones RAF application raf/demo1 - initialisation of graphics and creation of a very basic scene ent/sampleEntFsm - entity scripting +ent/lua1 - C++/Lua demo demonstrating yake.ent bindings (properties, ObjectIds etc) physics/demo - basic physics demo (multiple viewports, simplistic objects) vehicle - different vehicles can be controlled (car,jet). uses RAF, entities and models. base/scripting/lua - basic scripting demo task/demo1 - basic task/executor demo task/lua1 - Lua task/execution demo +property/demo1 - C++ demo demonstrating how to use properties +property/lua1 - C++/Lua demo demonstrating the yake.properties bindings ---- in flux: (i.e. in process of being added to the main build scripts) Modified: trunk/yake/samples/property/lua1/demo.cpp =================================================================== --- trunk/yake/samples/property/lua1/demo.cpp 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/samples/property/lua1/demo.cpp 2007-07-26 17:57:16 UTC (rev 1774) @@ -10,13 +10,15 @@ typedef scripting::ScriptingSystemLua scripting_t; scripting_t scriptingSys; + // use default binder instead of: bind_base(vm); etc + typedef void(*FreeBinderFn)(scripting::IVM*); + scriptingSys.addDefaultBinder( (FreeBinderFn)&bind_base ); + scriptingSys.addDefaultBinder( (FreeBinderFn)&bind_math ); + scriptingSys.addDefaultBinder( (FreeBinderFn)&bind_property ); + scripting::VMPtr vm( scriptingSys.createVM() ); YAKE_ASSERT( vm ); - bind_base( vm.get() ); - bind_math( vm.get() ); - bind_property( vm.get() ); - // run Lua script scripting::ScriptPtr demoScript( scriptingSys.createScriptFromFile("../../../common/media/samples/property/demo.lua") ); vm->execute( demoScript ); Modified: trunk/yake/scripts/premake/samples.lua =================================================================== --- trunk/yake/scripts/premake/samples.lua 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/scripts/premake/samples.lua 2007-07-26 17:57:16 UTC (rev 1774) @@ -40,12 +40,14 @@ useComponent("base") -------------------------------------- -makeSample("sampleEntFsm","samples/ent/sampleEntFsm") -sampleUsesConsole() -useComponent("base") -useComponent("scripting") -useComponent("ent") -useComponent("bindings.lua") +if LUA_BINDINGS and ENABLE_LUA_BASE and ENABLE_LUA_PROPERTY and ENABLE_LUA_ENT then + makeSample("sampleEntFsm","samples/ent/sampleEntFsm") + sampleUsesConsole() + useComponent("base") + useComponent("scripting") + useComponent("ent") + useComponent("bindings.lua") +end -------------------------------------- makeSample("sampleAudio1","samples/audio/demo1") Modified: trunk/yake/src/bindings.lua/bindings.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/bindings.lua.cpp 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/src/bindings.lua/bindings.lua.cpp 2007-07-26 17:57:16 UTC (rev 1774) @@ -70,12 +70,12 @@ #if YAKE_ENABLE_LUA_MODEL == 1 bind_model(L); #endif +#if YAKE_ENABLE_LUA_PROPERTY == 1 + bind_property(L); +#endif #if YAKE_ENABLE_LUA_ENT == 1 bind_ent(L); #endif -#if YAKE_ENABLE_LUA_PROPERTY == 1 - bind_property(L); -#endif } void bind_all(scripting::IVM* vm) { Modified: trunk/yake/src/bindings.lua/detail/ent.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/src/bindings.lua/detail/ent.lua.cpp 2007-07-26 17:57:16 UTC (rev 1774) @@ -35,17 +35,92 @@ #include <yake/bindings.lua/common/yake.lua.shared_ptr.h> #include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <yake/bindings.lua/detail/private.h> +#include <yake/bindings.lua/detail/property.lua.h> +#include <luabind/iterator_policy.hpp> +#include <luabind/operator.hpp> + namespace yake { namespace ent { + // For Lua's tostring(): +// std::ostream& operator<<(std::ostream& out, const ObjectId& rhs) +// { +// out << "ObjectId(" << rhs.classId() << ":" << rhs.serialNo() << ")"; +// return out; +// } + std::ostream& operator<<(std::ostream& out, const Object& rhs) + { + out << "Object(id=" << rhs.id() << ")"; + return out; + } + + // + typedef luabind::class_<Object> LuabindClass_Object; + typedef luabind::class_<Object::PropertyAccess> LuabindClass_Object_PropertyAccess; + //------------------------------------------------------------------------- + static property::PropertyBase* getPropertyOfObject(Object& o, const PropertyId& id) + { + return o.properties().get(id).get(); + } + static Object::PropertyAccess* getObjectPoperties(Object& o) + { + Object::PropertyAccess& x = o.properties(); + return &x; + } + static property::PropertyBase* Object_PropertyAccess_get(Object::PropertyAccess& o, const char* id) + { + return o.get( id ).get(); + } + //------------------------------------------------------------------------- + // Helper struct so that we gain access to the private member + // "properties_" in Object::PropertyAccess: + struct LuaBinder + { + static void bind(LuabindClass_Object& x_Object) + { + using namespace luabind; + //x_Object.def_readonly( "properties", &Object::properties_, return_stl_iterator); + } + //------------------------------------------------------------------------- + static property::PropertyBase* createAndAddProperty(Object::PropertyAccess& access, const char* name, luabind::object o) + { + try { + return property::createAndAddProperty( access.properties_, name, o ); + } + catch (yake::AlreadyExistsException& ex) + { + //@todo properly report error/warning + std::cerr << "WARNING: " << ex.what() << "\n"; + return 0; + } + } + static property::PropertyBase* createAndAddPropertyFromAny(Object::PropertyAccess& access, const char* name, const boost::any& o) + { + try { + return property::createAndAddPropertyFromAny( access.properties_, name, o ); + } + catch (yake::AlreadyExistsException& ex) + { + //@todo properly report error/warning + std::cerr << "WARNING: " << ex.what() << "\n"; + return 0; + } + } + }; + //------------------------------------------------------------------------- void bind( lua_State* L ) { YAKE_ASSERT( L ); if (!L) return; + // + register_any_converter<ObjectId>(); + //register_property_value_converter<ObjectId>(); + + // using namespace luabind; using namespace yake::model; @@ -59,16 +134,48 @@ module( YAKE_MODEL_MODULE ) [ - class_<Object>( "Object" ) - .def( constructor<>() ) - .def( "setId", &Object::setId ) - .def( "id", &Object::getId ) + class_<ObjectId>( "ObjectId" ) + .def( constructor<>() ) + .def( constructor<ClassId,ObjectSerialNo>() ) + .def("isNull", &ObjectId::isNull) + .property("classId", &ObjectId::classId) + .property("serialNo", &ObjectId::serialNo) + .def(tostring(const_self)) + .def(const_self == other<ObjectId>()) ]; + LuabindClass_Object_PropertyAccess x_Object_PropertyAccess("Object::PropertyAccess"); + x_Object_PropertyAccess + .def( "get", &Object_PropertyAccess_get ) + .def( "has", &Object::PropertyAccess::has ) + + // For native Lua types which can simply mapped to C++: + .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 ) + ; module( YAKE_MODEL_MODULE ) + [ x_Object_PropertyAccess ]; + + LuabindClass_Object x_Object("Object"); + x_Object + //.def( constructor<>() ) + //.def( "setId", &Object::setId ) + //.def( "id", &Object::getId ) + .property( "id", &Object::getId, &Object::setId ) + .def( "property", &getPropertyOfObject ) + .def( "properties", &getObjectPoperties ) + //.def( "properties", return_reference_to(_1) ) + .def(tostring(const_self)) + ; + LuaBinder::bind(x_Object); + module( YAKE_MODEL_MODULE ) + [ x_Object ]; + + module( YAKE_MODEL_MODULE ) [ class_<Entity,Object>( "Entity" ) - .def( constructor<>() ) + //.def( constructor<>() ) .def( "setModel", &Entity::setModel ) .def( "getModel", &Entity::getModel ) @@ -97,11 +204,10 @@ namespace detail { void executeOfTable_2(scripting::IVM& vm, const std::string& tbl1name, const std::string& tbl2name, const std::string& fn) { + scripting::LuaVM& luaVM = static_cast<scripting::LuaVM&>(vm); + lua_State* luaState = luaVM.getLuaState(); + YAKE_ASSERT( luaState ); try { - scripting::LuaVM& luaVM = static_cast<scripting::LuaVM&>(vm); - lua_State* luaState = luaVM.getLuaState(); - YAKE_ASSERT( luaState ); - luabind::object tbl1 = luabind::globals(luaState)[tbl1name.c_str()]; if (luabind::type(tbl1) == LUA_TNIL) //if (!tbl1) @@ -109,7 +215,7 @@ std::cerr << "vm error: could not find table '" << tbl1name << "'.\n"; return; } - assert( luabind::type(tbl1) == LUA_TTABLE ); + YAKE_ASSERT( luabind::type(tbl1) == LUA_TTABLE ); luabind::object tbl2 = tbl1[tbl2name.c_str()]; if (luabind::type(tbl2) == LUA_TNIL) @@ -118,16 +224,22 @@ std::cerr << "vm error: could not find table '" << tbl1name << "." << tbl2name << "'.\n"; return; } - assert( luabind::type(tbl2) == LUA_TTABLE ); + YAKE_ASSERT( luabind::type(tbl2) == LUA_TTABLE ); luabind::object fnObj = tbl2[fn.c_str()]; - assert( luabind::type(fnObj) == LUA_TFUNCTION ); + YAKE_ASSERT( luabind::type(fnObj) == LUA_TFUNCTION ); fnObj(); } + catch (luabind::error& e) + { + std::string err = lua_tostring(luaState, -1); + lua_pop(luaState, 2); + YAKE_EXCEPT(String("Luabind error:") + e.what() + ": " + err); + } catch (...) { - YAKE_EXCEPT("executeOfTable_2(): Bad cast! VM is not a Lua VM!"); + YAKE_EXCEPT("executeOfTable_2(): Exception caught!"); } } } Modified: trunk/yake/src/bindings.lua/detail/property.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-07-26 17:57:16 UTC (rev 1774) @@ -37,6 +37,7 @@ #include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <yake/bindings.lua/detail/private.h> +#include <yake/bindings.lua/detail/property.lua.h> namespace yake { namespace property { @@ -55,7 +56,6 @@ static BindSetPropertyFnList s_binders; return s_binders; } - typedef PropertyContainer<String> NamedPropertyContainer; PropertyPtr createPropertyFromAny(const boost::any& o) { const std::type_info* ti = &o.type(); @@ -83,7 +83,8 @@ // Brute-force through list of 'luabind::object -> c++' converters: // @todo performance? - for (PropertyFromObjectMap::const_iterator it = object_property_creators().begin(); it != object_property_creators().end(); ++it) + const PropertyFromObjectMap& creators = object_property_creators(); + for (PropertyFromObjectMap::const_iterator it = creators.begin(); it != creators.end(); ++it) { PropertyFromObjectFn fn = it->second; YAKE_ASSERT( fn ); @@ -91,6 +92,12 @@ if (prop.get()) return prop; } + // As a last resort try to convert to luabind::object property: + // For details read the comments for register_any_converter<luabind::object>() + // specialization. + PropertyPtr prop( convert_any<luabind::object>::yake_createValuePropertyFromObject( o ) ); + if (prop.get()) + return prop; //@todo use proper logging: std::cerr << "ERROR: bindings.lua:yake.property.createProperty: unhandled type\n"; @@ -146,11 +153,10 @@ #define YAKE_MODEL_MODULE L, "yake" //class: PropertyBase - class_<PropertyBase/*,PropertyPtr*/> x( "PropertyBase" ); + LuabindClass_PropertyBase x( "PropertyBase" ); x .def( "type", &PropertyBase::type ) - //.def( "set", &PropertyBase::setAny ) - .def( "set", &setPropertyValue ) // for boost::any + //.def( "set", &setPropertyValue ) // for boost::any .def( "get", (boost::any(PropertyBase::*)()const)&PropertyBase::getAny ) ; // register additional 'set' overloads: @@ -167,7 +173,7 @@ [ class_<NamedPropertyContainer>( "NamedPropertyContainer" ) .def( constructor<>() ) - .def( "add", (void(NamedPropertyContainer::*)(const String&,PropertyPtr))&NamedPropertyContainer::add ) + //.def( "add", (void(NamedPropertyContainer::*)(const String&,PropertyPtr))&NamedPropertyContainer::add ) .def( "has", &NamedPropertyContainer::has ) //.def( "get", (PropertyBase&(NamedPropertyContainer::*)(const String&))&NamedPropertyContainer::get ) //.def( "get", (PropertyPtr(NamedPropertyContainer::*)(const String&)const)&NamedPropertyContainer::getPtr ) @@ -180,7 +186,7 @@ ]; } - YAKE_WRAP_BINDER(model,::yake::property::bind); + YAKE_WRAP_BINDER(property,::yake::property::bind); } // namespace model void bind_property(lua_State* L) Modified: trunk/yake/src/ent/entity.cpp =================================================================== --- trunk/yake/src/ent/entity.cpp 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/src/ent/entity.cpp 2007-07-26 17:57:16 UTC (rev 1774) @@ -32,6 +32,10 @@ IMPL_OBJECT(Entity) + Entity::Entity() + { + properties().add("model", property::makePointerProperty<ModelPtr>(&model_) ); + } 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/object.cpp =================================================================== --- trunk/yake/src/ent/object.cpp 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/src/ent/object.cpp 2007-07-26 17:57:16 UTC (rev 1774) @@ -32,6 +32,10 @@ IMPL_OBJECT(Object) + Object::Object() : propertyAcess_(properties_) + { + properties().add("id", property::makePointerProperty<ObjectId>(&id_) ); + } void Object::setId(const ObjectId& id) { YAKE_ASSERT( id != MessageTraits::kNoSource )(MessageTraits::kNoSource)(id); @@ -78,6 +82,33 @@ } listenerConnections_.clear(); } + Object::PropertyAccess& Object::properties() + { + return propertyAcess_; + } + const Object::PropertyAccess& Object::properties() const + { + return propertyAcess_; + } + Object::PropertyAccess::PropertyAccess(NamedProperties& props) : properties_(props) + { + } + PropertyPtr Object::PropertyAccess::get(const PropertyId& id) const + { + return properties_.getPtr(id); + } + bool Object::PropertyAccess::has(const PropertyId& id) const + { + return properties_.has(id); + } + void Object::PropertyAccess::add(const PropertyId& id, property::PropertyBase* prop) + { + this->add( id, PropertyPtr(prop) ); + } + void Object::PropertyAccess::add(const PropertyId& id, PropertyPtr prop) + { + properties_.add( id, prop ); + } } } Modified: trunk/yake/src/plugins/scriptingLua/ScriptingSystemLua.cpp =================================================================== --- trunk/yake/src/plugins/scriptingLua/ScriptingSystemLua.cpp 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/src/plugins/scriptingLua/ScriptingSystemLua.cpp 2007-07-26 17:57:16 UTC (rev 1774) @@ -87,9 +87,16 @@ //------------------------------------------------------ void LuaVM::execute( const String & rData ) { + YAKE_ASSERT( mLuaState ); + if (!mLuaState) + return; + std::string err; try { - if (mLuaState) - luaL_dostring( mLuaState, rData.c_str() ); + if (luaL_dostring( mLuaState, rData.c_str() )) + { + err = lua_tostring(mLuaState, -1); + lua_pop(mLuaState, 2); + } } catch (luabind::error& e) { @@ -103,12 +110,15 @@ { throw Exception(String("LuaVM: caught exception: ") + e.what()); } + if (!err.empty()) + throw Exception(String("LuaVM: error: ") + err); } //------------------------------------------------------ void LuaVM::execute( ScriptPtr pScript ) { YAKE_ASSERT( pScript ); + std::string err; try { YAKE_ASSERT( pScript->getCreator()->getLanguage() == scripting::IScriptingSystem::L_LUA ); if ( ( pScript->getCreator()->getLanguage() != scripting::IScriptingSystem::L_LUA ) || @@ -122,19 +132,19 @@ if (luaL_loadfile(mLuaState, rFileName.c_str())) { - std::string err(lua_tostring(mLuaState, -1)); + err = lua_tostring(mLuaState, -1); lua_pop(mLuaState, 2); // pop 2: cclosure and error string - throw Exception( err.c_str() ); } - - if (lua_pcall(mLuaState, 0, 0, -2)) + else { - std::string err(lua_tostring(mLuaState, -1)); - lua_pop(mLuaState, 2); - throw Exception( err.c_str() ); + if (lua_pcall(mLuaState, 0, 0, -2)) + { + err = lua_tostring(mLuaState, -1); + lua_pop(mLuaState, 2); + } + else + lua_pop(mLuaState, 1); } - - lua_pop(mLuaState, 1); } catch (luabind::error& e) { @@ -152,6 +162,8 @@ { throw Exception(String("LuaVM: caught exception: ") + e.what()); } + if (!err.empty()) + throw Exception(String("LuaVM: error: ") + err); } //------------------------------------------------------ @@ -168,6 +180,12 @@ VMPtr ScriptingSystemLua::createVM() { VMPtr vm( new LuaVM(this/*this->shared_from_this()*/) ); + + YAKE_FOR_EACH( BinderList::const_iterator, it, mDefaultBinders ) + { + (*it)( vm.get() ); + } + return vm; } Modified: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp 2007-07-26 17:57:16 UTC (rev 1774) @@ -51,8 +51,17 @@ return; } // lookup converter & run (or bail out if no converter found) - any_converter_map::const_iterator it = any_converters().find(ti); + const any_converter_map& convs = any_converters(); + any_converter_map::const_iterator it = convs.begin(); + while (it != convs.end()) + { + if (*(it->first) == *ti) + break; + ++it; + } + //any_converter_map::const_iterator it = convs.find(ti); if (it == any_converters().end()) + //@todo We could just push nil ? throw yake::Exception(std::string("convert_cpp_to_lua() failed to convert '") + ti->name() + "'."); conv_t conv = it->second; conv(L, a); @@ -68,6 +77,8 @@ return boost::any( object_cast<int>(o) ); case LUA_TSTRING: return boost::any( object_cast<std::string>(o) ); //@todo fixme + //case LUA_TFUNCTION: + // return boost::any( o ); default: throw yake::Exception("encountered unsupported type in convert_lua_to_cpp()"); } @@ -84,6 +95,8 @@ return boost::any( object_cast<int>(o) ); case LUA_TSTRING: return boost::any( object_cast<std::string>(o) ); //@todo fixme + //case LUA_TFUNCTION: + // return boost::any( o ); default: throw yake::Exception("encountered unsupported type in convert_lua_to_cpp()"); } @@ -97,6 +110,7 @@ case LUA_TBOOLEAN: case LUA_TNUMBER: case LUA_TSTRING: + //case LUA_TFUNCTION: return 0; default: return -1; @@ -111,6 +125,7 @@ case LUA_TBOOLEAN: case LUA_TNUMBER: case LUA_TSTRING: + //case LUA_TFUNCTION: return 0; default: return -1; Modified: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-07-26 17:57:16 UTC (rev 1774) @@ -51,7 +51,10 @@ typedef std::map<const std::type_info*,PropertyFromObjectFn> PropertyFromObjectMap; YAKE_LUA_ANY_CONVERTER_API PropertyFromObjectMap& object_property_creators(); - typedef void(*BindSetPropertyFn)(luabind::class_<PropertyBase>&); + typedef luabind::class_<PropertyBase> LuabindClass_PropertyBase; + //typedef luabind::class_<PropertyBase,PropertyPtr> LuabindClass_PropertyBase; + + typedef void(*BindSetPropertyFn)(LuabindClass_PropertyBase&); typedef std::vector<BindSetPropertyFn> BindSetPropertyFnList; YAKE_LUA_ANY_CONVERTER_API BindSetPropertyFnList& setPropertyValue_binders(); @@ -109,7 +112,7 @@ YAKE_ASSERT( prop ); return prop; } - static void yake_bind_setPropertyValue(luabind::class_<yake::property::PropertyBase>& x) + static void yake_bind_setPropertyValue(::yake::property::LuabindClass_PropertyBase& x) { x.def("set",&yake::property::setPropertyValue_Generic<T>); } @@ -121,17 +124,40 @@ //any_converter_map any_converters; +#if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: template<class T> - void register_any_converter() + inline void register_property_value_converter() { - any_converters()[&typeid(T)] = convert_any<T>::convert; -#if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: yake::property::any_property_creators()[&typeid(T)] = convert_any<T>::yake_createValuePropertyFromAny; yake::property::object_property_creators()[&typeid(T)] = convert_any<T>::yake_createValuePropertyFromObject; yake::property::setPropertyValue_binders().push_back( convert_any<T>::yake_bind_setPropertyValue ); + } #endif + + template<class T> + inline void register_any_converter() + { + any_converters()[&typeid(T)] = convert_any<T>::convert; +#if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: + register_property_value_converter<T>(); +#endif } + // NB The specialization for luabind::object is required as for + // this type we do not store a creator in object_property_creators(). + // This creator is to be used as a last resort only. If it is stored + // with all the other creators it may get called before a better option + // can be called. + template<> + inline void register_any_converter<luabind::object>() + { + any_converters()[&typeid(luabind::object)] = convert_any<luabind::object>::convert; +#if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: + yake::property::any_property_creators()[&typeid(luabind::object)] = convert_any<luabind::object>::yake_createValuePropertyFromAny; + yake::property::setPropertyValue_binders().push_back( convert_any<luabind::object>::yake_bind_setPropertyValue ); +#endif + } + namespace luabind { namespace converters Added: trunk/yake/yake/bindings.lua/detail/property.lua.h =================================================================== --- trunk/yake/yake/bindings.lua/detail/property.lua.h (rev 0) +++ trunk/yake/yake/bindings.lua/detail/property.lua.h 2007-07-26 17:57:16 UTC (rev 1774) @@ -0,0 +1,52 @@ +/* + ------------------------------------------------------------------------------------ + 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_LUA_BINDINGS_PROPERTYLUA_H +#define YAKE_LUA_BINDINGS_PROPERTYLUA_H + +#include <yake/config.h> + +#if YAKE_ENABLE_LUA_PROPERTY == 1 +#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! +#include <yake/base/yake.h> +#include <yake/property/property.h> +#include <boost/any.hpp> + +namespace yake { +namespace property { + typedef PropertyContainer<String> NamedPropertyContainer; + PropertyPtr createPropertyFromAny(const boost::any& o); + PropertyPtr createProperty(luabind::object o); + PropertyBase* createAndAddProperty(NamedPropertyContainer& ctr, const char* name, luabind::object o); + 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); +} // namespace property +} // namespace yake + +#endif // YAKE_ENABLE_LUA_PROPERTY + +#endif Modified: trunk/yake/yake/ent/component.h =================================================================== --- trunk/yake/yake/ent/component.h 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/yake/ent/component.h 2007-07-26 17:57:16 UTC (rev 1774) @@ -28,7 +28,8 @@ #define YAKE_ENT_OBJECT_COMPONENT_H #include "yake/ent/prerequisites.h" -#include "yake/prop/yakeProperty.h" +#include "yake/prop/prop_def.h" +#include "yake/prop/rtti_class.h" namespace yake { namespace ent { @@ -48,7 +49,7 @@ @note If only property storage is needed this class can be used in its current form. @note Derived classes have to use the DECL_CO() and IMPL_CO_1() macros. */ - struct YAKE_ENT_API Component : public PropHolder<Component> + struct YAKE_ENT_API Component : public boost::noncopyable { virtual ~Component() {} Modified: trunk/yake/yake/ent/entity.h =================================================================== --- trunk/yake/yake/ent/entity.h 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/yake/ent/entity.h 2007-07-26 17:57:16 UTC (rev 1774) @@ -28,6 +28,7 @@ #define YAKE_ENT_ENTITY_H #include "yake/ent/prerequisites.h" +#include "yake/property/property.h" #include "yake/ent/object.h" #include "yake/model/model.h" //@todo reduce dependency ... @@ -36,11 +37,12 @@ typedef model::ModelPtr ModelPtr; /** Represents complex objects with components, unique ids, properties, state machines, scripting machines. + @note properties: model (ModelPtr) */ struct YAKE_ENT_API Entity : public Object { DECL_OBJECT(Entity,"Entity") - Entity() {} + Entity(); virtual ~Entity() {} typedef object_fsm::state_type fsm_state_type; @@ -66,30 +68,11 @@ scripting::VMPtr getFsmVM() const; + // Model / components + void setModel(ModelPtr); ModelPtr getModel() const; -#if 0 //@todo fixme replace this with a simple contained Model (which is component based). - //@group name Component management - //@{ - /** Adds a component with the given tag. */ - void addComponent(const CoTag&, Component*); - - /** Removes the component with the given pointer. */ - Component* removeComponent(const Component*); - - /** Removes a component by its tag. - Returns the pointer to the component object on successful removal, otherwise 0. - */ - Component* removeComponent(const CoTag&); - - /** Returns the pointer to the component object for the given tag, or 0 if no - component has been registered with this tag. */ - Component* getComponent(const CoTag&) const; - - //@} -#endif - // signals typedef boost::signal<void(const String&,scripting::VMPtr)> VmInitializedSignal; boost::signals::connection subscribeToVmInitialized(const VmInitializedSignal::slot_type&); Modified: trunk/yake/yake/ent/object.h =================================================================== --- trunk/yake/yake/ent/object.h 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/yake/ent/object.h 2007-07-26 17:57:16 UTC (rev 1774) @@ -31,8 +31,14 @@ #include "yake/ent/object_listener.h" #include "yake/ent/vm_holder.h" +#include "yake/prop/prop_def.h" +#include "yake/prop/rtti_class.h" + +struct lua_State; + namespace yake { namespace ent { + struct LuaBinder; #define DECL_OBJECT(CLASS,DESC) \ DECL_CLASS_RTTI(CLASS,DESC) \ @@ -54,11 +60,14 @@ } /** Base class for complex objects with unique ids, properties and default events. + @note properties: id (ObjectId) */ - struct YAKE_ENT_API Object : public yake::PropHolder<Object>, public ObjectListenerManager + struct YAKE_ENT_API Object : public ObjectListenerManager { + friend struct LuaBinder; + DECL_OBJECT(Object,"Object") - Object() {} + Object(); virtual ~Object() {} // id operations @@ -83,6 +92,29 @@ void processMessage(const int&); void registerMessageListeners(detail::message_router_type& msgRouter); + + // Properties + public: + struct YAKE_ENT_API PropertyAccess : public noncopyable + { + friend struct LuaBinder; + friend struct Object; + private: + PropertyAccess(NamedProperties&); + NamedProperties& properties_; + public: + PropertyPtr get(const PropertyId&) const; + bool has(const PropertyId&) const; + void add(const PropertyId&, property::PropertyBase*); // <- may throw on error! + void add(const PropertyId&, PropertyPtr); // <- may throw on error! + size_t size() const + { return properties_.size(); } + }; + PropertyAccess& properties(); + const PropertyAccess& properties() const; + + NamedProperties* __properties() + { return &properties_; } protected: virtual void onInit() {} virtual void onTick() {} @@ -90,6 +122,8 @@ ObjectId id_; typedef std::deque<detail::ListenerConnection> listenerconnetion_list; listenerconnetion_list listenerConnections_; + NamedProperties properties_; + PropertyAccess propertyAcess_; }; } // namespace ent Modified: trunk/yake/yake/ent/prerequisites.h =================================================================== --- trunk/yake/yake/ent/prerequisites.h 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/yake/ent/prerequisites.h 2007-07-26 17:57:16 UTC (rev 1774) @@ -27,7 +27,7 @@ #ifndef YAKE_OBJECT_PREREQUISITES_H #define YAKE_OBJECT_PREREQUISITES_H -#include "yake/prop/yakeProperty.h" +#include "yake/property/property.h" #include "yake/statemachine/fsm_core.h" #include "yake/base/yakeTaggedListenerManager.h" #include "yake/base/templates/yakeVector.h" @@ -51,6 +51,7 @@ typedef object::ObjectId<object::default_objectid_traits> ObjectId; typedef ObjectId::ClassId ClassId; + typedef ObjectId::SerialNo ObjectSerialNo; } // namespace ent } // namespace yake @@ -95,6 +96,10 @@ //static const MessageSource kAnySource = MessageTraits::kAnySource; //static const MessageTarget kBroadcastTarget = MessageTraits::kBroadcastTarget; + typedef property::PropertyPtr PropertyPtr; + typedef String PropertyId; + typedef property::PropertyContainer<PropertyId> NamedProperties; + } // namespace ent } // namespace yake Modified: trunk/yake/yake/plugins/scriptingLua/ScriptingSystemLua.h =================================================================== --- trunk/yake/yake/plugins/scriptingLua/ScriptingSystemLua.h 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/yake/plugins/scriptingLua/ScriptingSystemLua.h 2007-07-26 17:57:16 UTC (rev 1774) @@ -75,9 +75,14 @@ */ virtual ScriptPtr createScriptFromFile( const String & rFile ); + virtual void addDefaultBinder(BinderFn fn) + { if (fn) mDefaultBinders.push_back(fn); } protected: // not for pulic use: using boost::enable_shared_from_this<ScriptingSystemLua>::shared_from_this; + private: + typedef std::deque<BinderFn> BinderList; + BinderList mDefaultBinders; }; //----------------------------------------------------- Modified: trunk/yake/yake/property/accessors.h =================================================================== --- trunk/yake/yake/property/accessors.h 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/yake/property/accessors.h 2007-07-26 17:57:16 UTC (rev 1774) @@ -71,12 +71,12 @@ return new ValueHolder<T>(defaultValue); } - template<typename T> + template<typename T, typename PtrT = T*> class PointerAccessor : public AccessorBase<T> { public: - typedef T* value_ptr; - PointerAccessor(value_ptr px) : px_(px) + typedef PtrT value_ptr; + PointerAccessor(PtrT px) : px_(px) { assert( px_ ); } @@ -91,7 +91,7 @@ return *px_; } private: - value_ptr px_; + PtrT px_; }; template<typename T> inline PointerAccessor<T>* makePointerAccessor(T* px) Modified: trunk/yake/yake/property/property.h =================================================================== --- trunk/yake/yake/property/property.h 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/yake/property/property.h 2007-07-26 17:57:16 UTC (rev 1774) @@ -41,7 +41,7 @@ template<typename T> inline Property<T>* makePointerProperty(T* px) { - return new Property<T>(makePointerAccessor(px)); + return new Property<T>(makePointerAccessor<T>(px)); } template<typename T, typename ArgT> inline Property<T>* makeValueProperty(const ArgT& defaultValue = ArgT()) Modified: trunk/yake/yake/property/property_container.h =================================================================== --- trunk/yake/yake/property/property_container.h 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/yake/property/property_container.h 2007-07-26 17:57:16 UTC (rev 1774) @@ -64,6 +64,12 @@ template<typename Kt, template <typename> class ErrorPolicy = DefaultErrorPolicy> struct PropertyContainer : public boost::noncopyable, public ErrorPolicy<Kt>//, public OperatorPolicy<PropertyContainer<Kt,ErrorPolicy> > { + PropertyContainer() + { + } + ~PropertyContainer() + { + } typedef ErrorPolicy<Kt> error_policy_t; typedef Kt key_type; void add(const key_type& id, PropertyBase* prop); @@ -72,16 +78,29 @@ PropertyBase& get(const key_type& id); PropertyPtr getPtr(const key_type& id) const; // <= doesn't throw. bool has(const key_type& id) const; + size_t size() const + { return properties_.size(); } + // private: typedef std::map<key_type,PropertyPtr> PropertyMap; public: - typedef typename PropertyMap::const_iterator const_property_iterator; - const_property_iterator begin() const + typedef typename PropertyMap::const_iterator const_iterator; + const_iterator begin() const { return properties_.begin(); } - const_property_iterator end() const + const_iterator end() const { return properties_.end(); } + // Private interface used in Lua bindings: + /* + const PropertyMap& __getInternalMap() const + { return properties_; } + typedef typename PropertyMap::iterator iterator; + iterator begin() + { return properties_.begin(); } + iterator end() + { return properties_.end(); } + */ private: PropertyMap properties_; }; Modified: trunk/yake/yake/scripting/yakeScriptingSystem.h =================================================================== --- trunk/yake/yake/scripting/yakeScriptingSystem.h 2007-07-26 17:51:59 UTC (rev 1773) +++ trunk/yake/yake/scripting/yakeScriptingSystem.h 2007-07-26 17:57:16 UTC (rev 1774) @@ -34,6 +34,7 @@ #include <yake/base/templates/yakePointer.h> #include <yake/base/templates/yakeManager.h> #include <yake/base/templates/yakeRegistry.h> +#include <yake/base/templates/yakeFunction.h> #if defined( YAKE_SCRIPTING_EXPORTS ) # define YAKE_SCRIPTING_API YAKE_EXPORT_API @@ -174,6 +175,12 @@ \see IVM */ virtual ScriptPtr createScriptFromFile( const String & file ) = 0; + + /** Add a default binding function. Will applied to all + newly created VMs. + */ + typedef boost::function<void(IVM*)> BinderFn; + virtual void addDefaultBinder(BinderFn) = 0; }; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-26 17:51:56
|
Revision: 1773 http://yake.svn.sourceforge.net/yake/?rev=1773&view=rev Author: psyclonist Date: 2007-07-26 10:51:59 -0700 (Thu, 26 Jul 2007) Log Message: ----------- added demo 'ent/lua1' Added Paths: ----------- trunk/yake/samples/ent/lua1/ trunk/yake/samples/ent/lua1/demo.cpp Added: trunk/yake/samples/ent/lua1/demo.cpp =================================================================== --- trunk/yake/samples/ent/lua1/demo.cpp (rev 0) +++ trunk/yake/samples/ent/lua1/demo.cpp 2007-07-26 17:51:59 UTC (rev 1773) @@ -0,0 +1,33 @@ +#include <yake/plugins/scriptingLua/ScriptingSystemLua.h> +#include <yake/bindings.lua/bindings.lua.h> + +void main() +{ + using namespace yake; + + try { + // init scripting VM + typedef scripting::ScriptingSystemLua scripting_t; + scripting_t scriptingSys; + + // use default binder instead of: bind_base(vm); etc + typedef void(*FreeBinderFn)(scripting::IVM*); + scriptingSys.addDefaultBinder( (FreeBinderFn)&bind_base ); + scriptingSys.addDefaultBinder( (FreeBinderFn)&bind_math ); + scriptingSys.addDefaultBinder( (FreeBinderFn)&bind_property ); + + scripting::VMPtr vm( scriptingSys.createVM() ); + YAKE_ASSERT( vm ); + + // run Lua script + scripting::ScriptPtr demoScript( scriptingSys.createScriptFromFile("../../../common/media/samples/property/demo.lua") ); + vm->execute( demoScript ); + + // clean up + vm.reset(); + } + catch (Exception& ex) + { + std::cerr << "Exception: " << ex.what() << "\n"; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-19 15:19:36
|
Revision: 1772 http://svn.sourceforge.net/yake/?rev=1772&view=rev Author: psyclonist Date: 2007-07-19 08:19:36 -0700 (Thu, 19 Jul 2007) Log Message: ----------- fixed line endings Modified Paths: -------------- trunk/yake/src/bindings.lua/detail/property.lua.cpp Modified: trunk/yake/src/bindings.lua/detail/property.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-07-18 19:04:13 UTC (rev 1771) +++ trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-07-19 15:19:36 UTC (rev 1772) @@ -72,12 +72,12 @@ { case LUA_TBOOLEAN: return PropertyPtr(makeValueProperty<bool>( luabind::object_cast<bool>(o) )); - case LUA_TNUMBER: - return PropertyPtr(makeValueProperty<double>( luabind::object_cast<double>(o) )); - case LUA_TSTRING: - return PropertyPtr(makeValueProperty<String>( luabind::object_cast<String>(o) )); - case LUA_TFUNCTION: - return PropertyPtr(makeValueProperty<luabind::object>( o )); + case LUA_TNUMBER: + return PropertyPtr(makeValueProperty<double>( luabind::object_cast<double>(o) )); + case LUA_TSTRING: + return PropertyPtr(makeValueProperty<String>( luabind::object_cast<String>(o) )); + case LUA_TFUNCTION: + return PropertyPtr(makeValueProperty<luabind::object>( o )); default: //throw Exception("bindings.lua:yake.property.createProperty: unhandled type"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-18 19:04:11
|
Revision: 1771 http://svn.sourceforge.net/yake/?rev=1771&view=rev Author: psyclonist Date: 2007-07-18 12:04:13 -0700 (Wed, 18 Jul 2007) Log Message: ----------- improved library "yake::property": * 'boost::any' converters do now also automatically register 'property' value setters * Modified Paths: -------------- trunk/yake/common/media/samples/property/demo.lua trunk/yake/samples/property/lua1/demo.cpp trunk/yake/src/bindings.lua/bindings.lua.cpp trunk/yake/src/bindings.lua/detail/base.lua.cpp trunk/yake/src/bindings.lua/detail/property.lua.cpp trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h Modified: trunk/yake/common/media/samples/property/demo.lua =================================================================== --- trunk/yake/common/media/samples/property/demo.lua 2007-07-18 16:43:58 UTC (rev 1770) +++ trunk/yake/common/media/samples/property/demo.lua 2007-07-18 19:04:13 UTC (rev 1771) @@ -23,20 +23,36 @@ print("create property 'name' of implicit type 'String'"); p = props:create("name","aloha"); +assert( p ); print(" type = " .. p:type()); print(" value = " .. tostring(p:get()) ); -p:set("waikiki"); +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 ); +--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 Modified: trunk/yake/samples/property/lua1/demo.cpp =================================================================== --- trunk/yake/samples/property/lua1/demo.cpp 2007-07-18 16:43:58 UTC (rev 1770) +++ trunk/yake/samples/property/lua1/demo.cpp 2007-07-18 19:04:13 UTC (rev 1771) @@ -14,6 +14,7 @@ YAKE_ASSERT( vm ); bind_base( vm.get() ); + bind_math( vm.get() ); bind_property( vm.get() ); // run Lua script Modified: trunk/yake/src/bindings.lua/bindings.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/bindings.lua.cpp 2007-07-18 16:43:58 UTC (rev 1770) +++ trunk/yake/src/bindings.lua/bindings.lua.cpp 2007-07-18 19:04:13 UTC (rev 1771) @@ -48,6 +48,7 @@ register_any_converter<double>(); register_any_converter<bool>(); register_any_converter<String>(); + register_any_converter<luabind::object>(); } } g_registerDefaultAnyConverters; Modified: trunk/yake/src/bindings.lua/detail/base.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/base.lua.cpp 2007-07-18 16:43:58 UTC (rev 1770) +++ trunk/yake/src/bindings.lua/detail/base.lua.cpp 2007-07-18 19:04:13 UTC (rev 1771) @@ -45,7 +45,13 @@ YAKE_ASSERT(L); if (!L) return; + // + register_any_converter<Color>(); + register_any_converter<Vector3>(); + register_any_converter<Quaternion>(); + register_any_converter<Matrix3>(); + // using namespace luabind; #define YAKE_MATH_MODULE L, "yake" @@ -85,6 +91,7 @@ .def_readwrite( "x", &yake::math::Vector3::x ) .def_readwrite( "y", &yake::math::Vector3::y ) .def_readwrite( "z", &yake::math::Vector3::z ) + .def( constructor<>() ) .def( constructor< real, real, real >() ) .def( constructor< const real* const >() ) .def( constructor< Vector3 const& >() ) @@ -167,6 +174,8 @@ if (!L) return; + // + using namespace luabind; #define YAKE_BASE_MODULE L, "yake" Modified: trunk/yake/src/bindings.lua/detail/property.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-07-18 16:43:58 UTC (rev 1770) +++ trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-07-18 19:04:13 UTC (rev 1771) @@ -40,7 +40,31 @@ namespace yake { namespace property { + PropertyFromAnyMap& any_property_creators() + { + static PropertyFromAnyMap s_creators; + return s_creators; + } + PropertyFromObjectMap& object_property_creators() + { + static PropertyFromObjectMap s_creators; + return s_creators; + } + BindSetPropertyFnList& setPropertyValue_binders() + { + static BindSetPropertyFnList s_binders; + return s_binders; + } typedef PropertyContainer<String> NamedPropertyContainer; + PropertyPtr createPropertyFromAny(const boost::any& o) + { + const std::type_info* ti = &o.type(); + PropertyFromAnyMap::const_iterator it = any_property_creators().find( ti ); + if (it == any_property_creators().end() || !it->second) + return PropertyPtr(); //@todo log this? + PropertyBase* prop = (*it->second)(o); + return PropertyPtr(prop); + } PropertyPtr createProperty(luabind::object o) { assert( o.is_valid() ); @@ -56,6 +80,18 @@ return PropertyPtr(makeValueProperty<luabind::object>( o )); default: //throw Exception("bindings.lua:yake.property.createProperty: unhandled type"); + + // Brute-force through list of 'luabind::object -> c++' converters: + // @todo performance? + for (PropertyFromObjectMap::const_iterator it = object_property_creators().begin(); it != object_property_creators().end(); ++it) + { + PropertyFromObjectFn fn = it->second; + YAKE_ASSERT( fn ); + PropertyPtr prop( fn( o ) ); + if (prop.get()) + return prop; + } + //@todo use proper logging: std::cerr << "ERROR: bindings.lua:yake.property.createProperty: unhandled type\n"; return PropertyPtr(); @@ -69,6 +105,14 @@ ctr.add( name, prop ); return prop.get(); } + PropertyBase* createAndAddPropertyFromAny(NamedPropertyContainer& ctr, const char* name, const boost::any& o) + { + PropertyPtr prop = createPropertyFromAny(o); + if (!prop.get()) + return 0; + ctr.add( name, prop ); + return prop.get(); + } PropertyBase* getProperty(NamedPropertyContainer& ctr, const char* name) { PropertyPtr prop = ctr.getPtr(name); @@ -86,6 +130,10 @@ } } + void bind_PropertyBase_set(luabind::class_<PropertyBase>& x) + { + x.def("set", &setPropertyValue_Generic<Vector3>); + } void bind( lua_State* L ) { @@ -97,17 +145,26 @@ #define YAKE_MODEL_MODULE L, "yake" + //class: PropertyBase + class_<PropertyBase/*,PropertyPtr*/> x( "PropertyBase" ); + x + .def( "type", &PropertyBase::type ) + //.def( "set", &PropertyBase::setAny ) + .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 ] ; + + // module( YAKE_MODEL_MODULE ) [ - //def( "createProperty", &createProperty ), - class_<PropertyBase/*,PropertyPtr*/>( "PropertyBase" ) - .def( "type", &PropertyBase::type ) - //.def( "set", &PropertyBase::setAny ) - .def( "set", &setPropertyValue ) - .def( "get", (boost::any(PropertyBase::*)()const)&PropertyBase::getAny ) - ]; - module( YAKE_MODEL_MODULE ) - [ class_<NamedPropertyContainer>( "NamedPropertyContainer" ) .def( constructor<>() ) .def( "add", (void(NamedPropertyContainer::*)(const String&,PropertyPtr))&NamedPropertyContainer::add ) @@ -115,7 +172,11 @@ //.def( "get", (PropertyBase&(NamedPropertyContainer::*)(const String&))&NamedPropertyContainer::get ) //.def( "get", (PropertyPtr(NamedPropertyContainer::*)(const String&)const)&NamedPropertyContainer::getPtr ) .def( "get", &getProperty ) - .def( "create", &createAndAddProperty ) + + // 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: + .def( "create", (PropertyBase*(*)(NamedPropertyContainer&,const char*,luabind::object))&createAndAddProperty ) ]; } Modified: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-07-18 16:43:58 UTC (rev 1770) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-07-18 19:04:13 UTC (rev 1771) @@ -34,6 +34,46 @@ #include <map> #include <boost/any.hpp> +#define YAKE_LUA_ANY_CONVERTER_API YAKE_BINDINGS_LUA_API + + +#if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: +# include <yake/property/property.h> + namespace yake { + namespace property { + struct PropertyBase; + + typedef PropertyBase*(*PropertyFromAnyFn)(const boost::any&); + typedef std::map<const std::type_info*,PropertyFromAnyFn> PropertyFromAnyMap; + YAKE_LUA_ANY_CONVERTER_API PropertyFromAnyMap& any_property_creators(); + + typedef PropertyBase*(*PropertyFromObjectFn)(const luabind::object&); + typedef std::map<const std::type_info*,PropertyFromObjectFn> PropertyFromObjectMap; + YAKE_LUA_ANY_CONVERTER_API PropertyFromObjectMap& object_property_creators(); + + typedef void(*BindSetPropertyFn)(luabind::class_<PropertyBase>&); + typedef std::vector<BindSetPropertyFn> BindSetPropertyFnList; + YAKE_LUA_ANY_CONVERTER_API BindSetPropertyFnList& setPropertyValue_binders(); + + template<typename T> + bool setPropertyValue_Generic(PropertyBase& prop, const T& value) + { + try { + prop.setAny( value ); + return true; + } + catch (BadCastException&) + { + //@todo report error! throw exception? + std::cerr << ">>> Warning: Type mismatch on setting of property value!\n"; + std::cerr << " value type=" << typeid(T).name() << " expected type=" << prop.type() << "\n"; + return false; + } + } + } // namespace property + } // namespace yake +#endif + // boost::any bindings template<class T> struct convert_any @@ -44,12 +84,39 @@ //conv.apply(L, *boost::any_cast<T>(&a)); luabind::detail::convert_to_lua(L, *boost::any_cast<T>(&a)); } +#if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: + static yake::property::PropertyBase* yake_createValuePropertyFromAny(const boost::any& a) + { + try + { + yake::property::Property<T>* prop = yake::property::makeValueProperty<T>( boost::any_cast<T>(a) ); + YAKE_ASSERT( prop ); + return prop; + } + catch (boost::bad_any_cast&) + { + return 0;//@todo report error + } + } + static yake::property::PropertyBase* yake_createValuePropertyFromObject(const luabind::object& a) + { + //int type = luabind::type(a); + boost::optional<T> value = luabind::object_cast_nothrow<T>(a); + if (!value) + return 0; //@todo report error + // + yake::property::Property<T>* prop = yake::property::makeValueProperty<T>( *value ); + YAKE_ASSERT( prop ); + return prop; + } + static void yake_bind_setPropertyValue(luabind::class_<yake::property::PropertyBase>& x) + { + x.def("set",&yake::property::setPropertyValue_Generic<T>); + } +#endif }; typedef std::map<const std::type_info*, void(*)(lua_State*, const boost::any&)> any_converter_map; - -#define YAKE_LUA_ANY_CONVERTER_API YAKE_BINDINGS_LUA_API - YAKE_LUA_ANY_CONVERTER_API any_converter_map& any_converters(); //any_converter_map any_converters; @@ -58,6 +125,11 @@ void register_any_converter() { any_converters()[&typeid(T)] = convert_any<T>::convert; +#if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: + yake::property::any_property_creators()[&typeid(T)] = convert_any<T>::yake_createValuePropertyFromAny; + yake::property::object_property_creators()[&typeid(T)] = convert_any<T>::yake_createValuePropertyFromObject; + yake::property::setPropertyValue_binders().push_back( convert_any<T>::yake_bind_setPropertyValue ); +#endif } namespace luabind This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-18 16:45:49
|
Revision: 1770 http://svn.sourceforge.net/yake/?rev=1770&view=rev Author: psyclonist Date: 2007-07-18 09:43:58 -0700 (Wed, 18 Jul 2007) Log Message: ----------- cleaned up code of demo 'property/lua1' Modified Paths: -------------- trunk/yake/samples/property/lua1/demo.cpp Modified: trunk/yake/samples/property/lua1/demo.cpp =================================================================== --- trunk/yake/samples/property/lua1/demo.cpp 2007-07-18 16:38:32 UTC (rev 1769) +++ trunk/yake/samples/property/lua1/demo.cpp 2007-07-18 16:43:58 UTC (rev 1770) @@ -1,9 +1,6 @@ -#include <yake/task/task.h> #include <yake/plugins/scriptingLua/ScriptingSystemLua.h> #include <yake/bindings.lua/bindings.lua.h> -#include <luabind/luabind.hpp> - void main() { using namespace yake; @@ -15,10 +12,8 @@ scripting::VMPtr vm( scriptingSys.createVM() ); YAKE_ASSERT( vm ); - lua_State* L = static_cast<scripting::LuaVM*>(vm.get())->getLuaState(); - YAKE_ASSERT( L ); - bind_base( L ); + bind_base( vm.get() ); bind_property( vm.get() ); // run Lua script This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-18 16:38:36
|
Revision: 1769 http://svn.sourceforge.net/yake/?rev=1769&view=rev Author: psyclonist Date: 2007-07-18 09:38:32 -0700 (Wed, 18 Jul 2007) Log Message: ----------- * added sample 'property/lua1' demonstrating the Lua bindings for the 'property' library * added Lua bindings for the 'property' library * general improvements of Lua bindings code * improved interface of 'property' library Modified Paths: -------------- trunk/yake/scripts/premake/samples.lua trunk/yake/src/bindings.lua/bindings.lua.cpp trunk/yake/yake/bindings.lua/bindings.lua.h trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h trunk/yake/yake/property/detail/property.impl.h trunk/yake/yake/property/property_container.h Added Paths: ----------- trunk/yake/common/media/samples/property/ trunk/yake/common/media/samples/property/demo.lua trunk/yake/samples/property/lua1/ trunk/yake/samples/property/lua1/demo.cpp trunk/yake/src/bindings.lua/detail/property.lua.cpp Added: trunk/yake/common/media/samples/property/demo.lua =================================================================== --- trunk/yake/common/media/samples/property/demo.lua (rev 0) +++ trunk/yake/common/media/samples/property/demo.lua 2007-07-18 16:38:32 UTC (rev 1769) @@ -0,0 +1,42 @@ + +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"); +print(" type = " .. p:type()); +print(" value = " .. tostring(p:get()) ); +p:set("waikiki"); +print(" value = " .. tostring(p:get()) ); + +print("store a function in a property 'sayHello'"); +p = props:create("sayHello",function() print("'hello, i'm property 'sayHello'!'"); end); +print(" type = " .. p:type()); +print("running function stored in property 'sayHello'"); +assert( p:get() ); +p:get()(); + +print("attempt to create property of unsupported type 'thread'"); +p = props:create("thread", coroutine.create(function() print("thread"); end)); +assert( not p ); + +print("\nAll tests done."); \ No newline at end of file Added: trunk/yake/samples/property/lua1/demo.cpp =================================================================== --- trunk/yake/samples/property/lua1/demo.cpp (rev 0) +++ trunk/yake/samples/property/lua1/demo.cpp 2007-07-18 16:38:32 UTC (rev 1769) @@ -0,0 +1,35 @@ +#include <yake/task/task.h> +#include <yake/plugins/scriptingLua/ScriptingSystemLua.h> +#include <yake/bindings.lua/bindings.lua.h> +#include <luabind/luabind.hpp> + + +void main() +{ + using namespace yake; + + try { + // init scripting VM + typedef scripting::ScriptingSystemLua scripting_t; + scripting_t scriptingSys; + + scripting::VMPtr vm( scriptingSys.createVM() ); + YAKE_ASSERT( vm ); + lua_State* L = static_cast<scripting::LuaVM*>(vm.get())->getLuaState(); + YAKE_ASSERT( L ); + + bind_base( L ); + bind_property( vm.get() ); + + // run Lua script + scripting::ScriptPtr demoScript( scriptingSys.createScriptFromFile("../../../common/media/samples/property/demo.lua") ); + vm->execute( demoScript ); + + // clean up + vm.reset(); + } + catch (Exception& ex) + { + std::cerr << "Exception: " << ex.what() << "\n"; + } +} Modified: trunk/yake/scripts/premake/samples.lua =================================================================== --- trunk/yake/scripts/premake/samples.lua 2007-07-17 22:27:43 UTC (rev 1768) +++ trunk/yake/scripts/premake/samples.lua 2007-07-18 16:38:32 UTC (rev 1769) @@ -125,6 +125,18 @@ useComponent("base") -------------------------------------- +if LUA_BINDINGS and ENABLE_LUA_BASE and ENABLE_LUA_PROPERTY then + makeSample("samplePropertyLua1","samples/property/lua1") + sampleUsesConsole() + useComponent("base") + useComponent("scripting") + useComponent("bindings.lua") + useComponent("scriptingLua") + useDep("lua") + useDep("luabind") +end + +-------------------------------------- if SAMPLES_NET then makeSample("sampleNetMessage1","samples/net2/message1") sampleUsesConsole() @@ -195,15 +207,15 @@ -------------------------------------- if LUA_BINDINGS and ENABLE_LUA_BASE and ENABLE_LUA_TASK then - makeSample("sampleTaskLua1","samples/task/lua1") - sampleUsesConsole() - useComponent("base") - useComponent("task") - useComponent("scripting") - useComponent("bindings.lua") - useComponent("scriptingLua") - useDep("lua") - useDep("luabind") + makeSample("sampleTaskLua1","samples/task/lua1") + sampleUsesConsole() + useComponent("base") + useComponent("task") + useComponent("scripting") + useComponent("bindings.lua") + useComponent("scriptingLua") + useDep("lua") + useDep("luabind") end end Modified: trunk/yake/src/bindings.lua/bindings.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/bindings.lua.cpp 2007-07-17 22:27:43 UTC (rev 1768) +++ trunk/yake/src/bindings.lua/bindings.lua.cpp 2007-07-18 16:38:32 UTC (rev 1769) @@ -38,19 +38,27 @@ #include <yake/bindings.lua/common/yake.lua.any_converter.cpp> namespace yake { + namespace { + struct RegisterDefaultAnyConverters + { + RegisterDefaultAnyConverters() + { + register_any_converter<int>(); + register_any_converter<float>(); + register_any_converter<double>(); + register_any_converter<bool>(); + register_any_converter<String>(); + register_any_converter<luabind::object>(); + } + } g_registerDefaultAnyConverters; + } // namespace + void bind_all(lua_State* L) { YAKE_ASSERT( L ); // - register_any_converter<int>(); - register_any_converter<float>(); - register_any_converter<double>(); - register_any_converter<bool>(); - register_any_converter<String>(); - // - #if YAKE_ENABLE_LUA_BASE == 1 bind_base(L); bind_math(L); @@ -64,6 +72,9 @@ #if YAKE_ENABLE_LUA_ENT == 1 bind_ent(L); #endif +#if YAKE_ENABLE_LUA_PROPERTY == 1 + bind_property(L); +#endif } void bind_all(scripting::IVM* vm) { Added: trunk/yake/src/bindings.lua/detail/property.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/property.lua.cpp (rev 0) +++ trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-07-18 16:38:32 UTC (rev 1769) @@ -0,0 +1,137 @@ +/* +------------------------------------------------------------------------------------ +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_PROPERTY == 1 + +#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/property/property.h> + +#include <yake/bindings.lua/common/yake.lua.any_converter.h> +#include <yake/bindings.lua/detail/private.h> + +namespace yake { + namespace property { + typedef PropertyContainer<String> NamedPropertyContainer; + PropertyPtr createProperty(luabind::object o) + { + assert( o.is_valid() ); + switch (luabind::type(o)) + { + case LUA_TBOOLEAN: + return PropertyPtr(makeValueProperty<bool>( luabind::object_cast<bool>(o) )); + case LUA_TNUMBER: + return PropertyPtr(makeValueProperty<double>( luabind::object_cast<double>(o) )); + case LUA_TSTRING: + return PropertyPtr(makeValueProperty<String>( luabind::object_cast<String>(o) )); + case LUA_TFUNCTION: + return PropertyPtr(makeValueProperty<luabind::object>( o )); + default: + //throw Exception("bindings.lua:yake.property.createProperty: unhandled type"); + //@todo use proper logging: + std::cerr << "ERROR: bindings.lua:yake.property.createProperty: unhandled type\n"; + return PropertyPtr(); + } + } + PropertyBase* createAndAddProperty(NamedPropertyContainer& ctr, const char* name, luabind::object o) + { + PropertyPtr prop = createProperty(o); + if (!prop.get()) + return 0; + ctr.add( name, prop ); + return prop.get(); + } + PropertyBase* getProperty(NamedPropertyContainer& ctr, const char* name) + { + PropertyPtr prop = ctr.getPtr(name); + return prop.get(); + } + bool setPropertyValue(PropertyBase& prop, const boost::any& value) + { + try { + prop.setAny( value ); + return true; + } + catch (BadCastException& ex) + { + return false; + } + } + + + void bind( lua_State* L ) + { + YAKE_ASSERT( L ); + if (!L) + return; + + using namespace luabind; + +#define YAKE_MODEL_MODULE L, "yake" + + module( YAKE_MODEL_MODULE ) + [ + //def( "createProperty", &createProperty ), + class_<PropertyBase/*,PropertyPtr*/>( "PropertyBase" ) + .def( "type", &PropertyBase::type ) + //.def( "set", &PropertyBase::setAny ) + .def( "set", &setPropertyValue ) + .def( "get", (boost::any(PropertyBase::*)()const)&PropertyBase::getAny ) + ]; + module( YAKE_MODEL_MODULE ) + [ + class_<NamedPropertyContainer>( "NamedPropertyContainer" ) + .def( constructor<>() ) + .def( "add", (void(NamedPropertyContainer::*)(const String&,PropertyPtr))&NamedPropertyContainer::add ) + .def( "has", &NamedPropertyContainer::has ) + //.def( "get", (PropertyBase&(NamedPropertyContainer::*)(const String&))&NamedPropertyContainer::get ) + //.def( "get", (PropertyPtr(NamedPropertyContainer::*)(const String&)const)&NamedPropertyContainer::getPtr ) + .def( "get", &getProperty ) + .def( "create", &createAndAddProperty ) + ]; + } + + YAKE_WRAP_BINDER(model,::yake::property::bind); + + } // namespace model + void bind_property(lua_State* L) + { + YAKE_ASSERT(L); + property::bind(L); + } + void bind_property(scripting::IVM* vm) + { + scripting::LuaVM* luavm = static_cast<scripting::LuaVM*>(vm); + YAKE_ASSERT( luavm ); + bind_property(luavm->getLuaState()); + } +} // namespace yake +#endif // YAKE_ENABLE_LUA_PROPERTY \ No newline at end of file Modified: trunk/yake/yake/bindings.lua/bindings.lua.h =================================================================== --- trunk/yake/yake/bindings.lua/bindings.lua.h 2007-07-17 22:27:43 UTC (rev 1768) +++ trunk/yake/yake/bindings.lua/bindings.lua.h 2007-07-18 16:38:32 UTC (rev 1769) @@ -52,6 +52,10 @@ YAKE_BINDINGS_LUA_API void bind_ent(lua_State*); YAKE_BINDINGS_LUA_API void bind_ent(scripting::IVM*); #endif +#if YAKE_ENABLE_LUA_PROPERTY == 1 + YAKE_BINDINGS_LUA_API void bind_property(lua_State*); + YAKE_BINDINGS_LUA_API void bind_property(scripting::IVM*); +#endif } // namespace yake #endif Modified: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-07-17 22:27:43 UTC (rev 1768) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-07-18 16:38:32 UTC (rev 1769) @@ -29,6 +29,7 @@ // #include <yake/base/yakePrerequisites.h> +#include <yake/bindings.lua/prerequisites.h> #include <yake/bindings.lua/common/yake.lua.common.h> #include <map> #include <boost/any.hpp> @@ -47,11 +48,7 @@ typedef std::map<const std::type_info*, void(*)(lua_State*, const boost::any&)> any_converter_map; -#if defined(YAKE_EXPORT_LUA_ANY_CONVERTER) -# define YAKE_LUA_ANY_CONVERTER_API YAKE_EXPORT_API -#else -# define YAKE_LUA_ANY_CONVERTER_API YAKE_IMPORT_API -#endif +#define YAKE_LUA_ANY_CONVERTER_API YAKE_BINDINGS_LUA_API YAKE_LUA_ANY_CONVERTER_API any_converter_map& any_converters(); Modified: trunk/yake/yake/property/detail/property.impl.h =================================================================== --- trunk/yake/yake/property/detail/property.impl.h 2007-07-17 22:27:43 UTC (rev 1768) +++ trunk/yake/yake/property/detail/property.impl.h 2007-07-18 16:38:32 UTC (rev 1769) @@ -113,7 +113,7 @@ } catch (boost::bad_any_cast&) { - throw; + throw BadCastException("Property<>::setAny(): bad_any_cast"); } } virtual void getAny(boost::any& out) const Modified: trunk/yake/yake/property/property_container.h =================================================================== --- trunk/yake/yake/property/property_container.h 2007-07-17 22:27:43 UTC (rev 1768) +++ trunk/yake/yake/property/property_container.h 2007-07-18 16:38:32 UTC (rev 1769) @@ -37,7 +37,7 @@ template<typename Kt> struct DefaultErrorPolicy { - void onNotFound(const Kt& key) + void onNotFound(const Kt& key) const { throw NotFoundException("id/key not found"); } @@ -67,8 +67,10 @@ typedef ErrorPolicy<Kt> error_policy_t; typedef Kt key_type; void add(const key_type& id, PropertyBase* prop); + void add(const key_type& id, PropertyPtr prop); const PropertyBase& get(const key_type& id) const; PropertyBase& get(const key_type& id); + PropertyPtr getPtr(const key_type& id) const; // <= doesn't throw. bool has(const key_type& id) const; private: @@ -100,6 +102,22 @@ properties_.insert( std::make_pair(id,PropertyPtr(prop)) ); } template<typename Kt, template <typename> class ErrorPolicy> + void PropertyContainer<Kt,ErrorPolicy>::add(const key_type &id, PropertyPtr prop) + { + if (!prop) + { + this->onInvalidInput("null pointer"); + return; + } + PropertyMap::const_iterator it = properties_.find( id ); + if (it != properties_.end()) + { + this->onAlreadyExists(id); //@todo possible memory leak if client doesn't clean up "prop" + return; + } + properties_.insert( std::make_pair(id,prop) ); + } + template<typename Kt, template <typename> class ErrorPolicy> const PropertyBase& PropertyContainer<Kt,ErrorPolicy>::get(const key_type& id) const { PropertyMap::const_iterator it = properties_.find( id ); @@ -122,6 +140,18 @@ return *it->second; } template<typename Kt, template <typename> class ErrorPolicy> + PropertyPtr PropertyContainer<Kt,ErrorPolicy>::getPtr(const key_type& id) const + { + PropertyMap::const_iterator it = properties_.find( id ); + if (it == properties_.end()) + { + //this->onNotFound(id); // should throw! + //throw NotFoundException("property with this id not found"); // fallback if error handler doesn't throw + return PropertyPtr(); + } + return it->second; + } + template<typename Kt, template <typename> class ErrorPolicy> bool PropertyContainer<Kt,ErrorPolicy>::has(const key_type& id) const { PropertyMap::const_iterator it = properties_.find( id ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-17 23:19:34
|
Revision: 1767 http://svn.sourceforge.net/yake/?rev=1767&view=rev Author: psyclonist Date: 2007-07-17 15:26:53 -0700 (Tue, 17 Jul 2007) Log Message: ----------- premake yake.lua: do not compile net2 as it's a header-only lib Modified Paths: -------------- trunk/yake/scripts/premake/yake.lua Modified: trunk/yake/scripts/premake/yake.lua =================================================================== --- trunk/yake/scripts/premake/yake.lua 2007-07-17 22:26:11 UTC (rev 1766) +++ trunk/yake/scripts/premake/yake.lua 2007-07-17 22:26:53 UTC (rev 1767) @@ -157,8 +157,13 @@ addDependency("model") -------------------------------------- -makeComponent("net2","YAKE_NET_EXPORTS") ---addDependency("base") -- for logging +-- net2 is a header-only library +-- For MSVC8: Create project. +-- For Linux/GCC: Do not create project. +if windows then + makeComponent("net2","YAKE_NET_EXPORTS") + --addDependency("base") -- for logging +end -------------------------------------- makeComponent("net","YAKE_NET_EXPORTS") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-17 22:40:54
|
Revision: 1768 http://svn.sourceforge.net/yake/?rev=1768&view=rev Author: psyclonist Date: 2007-07-17 15:27:43 -0700 (Tue, 17 Jul 2007) Log Message: ----------- premake samples.lua: conditional compilation Modified Paths: -------------- trunk/yake/scripts/premake/samples.lua Modified: trunk/yake/scripts/premake/samples.lua =================================================================== --- trunk/yake/scripts/premake/samples.lua 2007-07-17 22:26:53 UTC (rev 1767) +++ trunk/yake/scripts/premake/samples.lua 2007-07-17 22:27:43 UTC (rev 1768) @@ -55,31 +55,37 @@ --useComponent("audioOpenAL") -------------------------------------- -makeSample("samplePhysics1","samples/physics/demo") -useComponent("base") -useComponent("physics") -useComponent("graphics") +if PLUGIN_GRAPHICS_OGRE then + makeSample("samplePhysics1","samples/physics/demo") + useComponent("base") + useComponent("physics") + useComponent("graphics") +end -------------------------------------- -makeSample("sampleVehicle","samples/vehicle") -useComponent("base") -useComponent("physics") -useComponent("graphics") -useComponent("input") -useComponent("model") -useComponent("ent") -useComponent("raf") -useComponent("vehicle") +if PLUGIN_GRAPHICS_OGRE then + makeSample("sampleVehicle","samples/vehicle") + useComponent("base") + useComponent("physics") + useComponent("graphics") + useComponent("input") + useComponent("model") + useComponent("ent") + useComponent("raf") + useComponent("vehicle") +end -------------------------------------- -makeSample("sampleCmdrMayhem","samples/cmdrmayhem") -useComponent("base") -useComponent("physics") -useComponent("graphics") -useComponent("input") -useComponent("model") -useComponent("raf") -useDep("cegui") +if PLUGIN_GRAPHICS_OGRE then + makeSample("sampleCmdrMayhem","samples/cmdrmayhem") + useComponent("base") + useComponent("physics") + useComponent("graphics") + useComponent("input") + useComponent("model") + useComponent("raf") + useDep("cegui") +end -------------------------------------- if SAMPLES_RAF then @@ -91,23 +97,27 @@ useComponent("scripting") -------------------------------------- - makeSample("sampleRafDemo1","samples/raf/demo1") - useComponent("base") - useComponent("raf") + if PLUGIN_GRAPHICS_OGRE then + makeSample("sampleRafDemo1","samples/raf/demo1") + useComponent("base") + useComponent("raf") + end end -------------------------------------- -makeSample("sampleGuiConsole","samples/gui/console") -useComponent("base") -useComponent("input") -useComponent("scripting") -useComponent("scriptingLua") -useComponent("graphics") -useComponent("audio") -useComponent("physics") -useDep("cegui") -useDep("lua") -useDep("luabind") +if PLUGIN_GRAPHICS_OGRE then + makeSample("sampleGuiConsole","samples/gui/console") + useComponent("base") + useComponent("input") + useComponent("scripting") + useComponent("scriptingLua") + useComponent("graphics") + useComponent("audio") + useComponent("physics") + useDep("cegui") + useDep("lua") + useDep("luabind") +end -------------------------------------- makeSample("sampleProperty1","samples/property/demo1") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-17 22:40:47
|
Revision: 1766 http://svn.sourceforge.net/yake/?rev=1766&view=rev Author: psyclonist Date: 2007-07-17 15:26:11 -0700 (Tue, 17 Jul 2007) Log Message: ----------- premake plugins.lua: conditional compilation Modified Paths: -------------- trunk/yake/scripts/premake/plugins.lua Modified: trunk/yake/scripts/premake/plugins.lua =================================================================== --- trunk/yake/scripts/premake/plugins.lua 2007-07-17 22:13:50 UTC (rev 1765) +++ trunk/yake/scripts/premake/plugins.lua 2007-07-17 22:26:11 UTC (rev 1766) @@ -25,17 +25,19 @@ end -------------------------------------- -makeComponentPlugin("audioOpenAL","YAKE_AUDIO_OPENAL_EXPORTS") -addDependency("base") -addDependency("audio") +if PLUGIN_AUDIO_OPENAL then + makeComponentPlugin("audioOpenAL","YAKE_AUDIO_OPENAL_EXPORTS") + addDependency("base") + addDependency("audio") -if (windows) then - useDep("oalpp") -else - addPkgConfigLib(package,"libopenalpp.so") - --addPkgConfigLib(package,"openalpp") --@todo Why does this not pick up the correct lib to link to? + if (windows) then + useDep("oalpp") + else + addPkgConfigLib(package,"libopenalpp.so") + --addPkgConfigLib(package,"openalpp") --@todo Why does this not pick up the correct lib to link to? + end + addIncludePath("dependencies/openalpp/include") end -addIncludePath("dependencies/openalpp/include") -------------------------------------- makeComponentPlugin("scriptingLua","YAKE_SCRIPTINGLUA_EXPORTS") @@ -46,7 +48,8 @@ useDep("lua") useDep("luabind") else - addPkgConfigLib(package,"liblua50.so.5") + --addPkgConfigLib(package,"lua5.1.so.0") + table.insert(package.linkoptions,"/usr/lib/liblua5.1.so.0") end -------------------------------------- @@ -57,12 +60,14 @@ useDep("ode") -------------------------------------- -makeComponentPlugin("ceguiOgreRendererAdapter","YAKE_CEGUIRENDERERADAPTER_OGRE_EXPORTS") -addDependency("base") -addDependency("graphics") +if PLUGIN_INPUT_OGRE and PLUGIN_GRAPHICS_OGRE then + makeComponentPlugin("ceguiOgreRendererAdapter","YAKE_CEGUIRENDERERADAPTER_OGRE_EXPORTS") + addDependency("base") + addDependency("graphics") -useDep("ogre") -useDep("cegui") + useDep("ogre") + useDep("cegui") +end -------------------------------------- if PLUGIN_INPUT_OGRE then @@ -84,13 +89,15 @@ end -------------------------------------- -makeComponentPlugin("graphicsOgre","YAKE_GRAPHICSCONCRETEAPI_EXPORTS") -addDependency("base") -addDependency("graphics") -addMatching("dependencies/oSceneLoaderLib/src/*.cpp") -addMatching("dependencies/oSceneLoaderLib/TinyXML/*.cpp") -addMatching("dependencies/oSceneLoaderLib/TinyXML/*.h") +if PLUGIN_GRAPHICS_OGRE then + makeComponentPlugin("graphicsOgre","YAKE_GRAPHICSCONCRETEAPI_EXPORTS") + addDependency("base") + addDependency("graphics") + addMatching("dependencies/oSceneLoaderLib/src/*.cpp") + addMatching("dependencies/oSceneLoaderLib/TinyXML/*.cpp") + addMatching("dependencies/oSceneLoaderLib/TinyXML/*.h") -useDep("osm") -useDep("ogre") + useDep("osm") + useDep("ogre") +end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-17 22:13:49
|
Revision: 1765 http://svn.sourceforge.net/yake/?rev=1765&view=rev Author: psyclonist Date: 2007-07-17 15:13:50 -0700 (Tue, 17 Jul 2007) Log Message: ----------- fixed type mismatch when ODE's dReal is a double Modified Paths: -------------- trunk/yake/src/plugins/physicsODE/OdeAvatar.cpp Modified: trunk/yake/src/plugins/physicsODE/OdeAvatar.cpp =================================================================== --- trunk/yake/src/plugins/physicsODE/OdeAvatar.cpp 2007-07-17 21:21:56 UTC (rev 1764) +++ trunk/yake/src/plugins/physicsODE/OdeAvatar.cpp 2007-07-17 22:13:50 UTC (rev 1765) @@ -417,7 +417,13 @@ { if (mShape->getType() == ST_CYLINDER) { - dGeomCapsuleGetParams (dGeomTransformGetGeom (mShape->_getOdeGeomID()), &radius, &height); + // Use temporary variables for cases when yake::real != dReal. + // (e.g. yake::real=float and dReal=double) + dReal r = 0.; + dReal h = 0.; + dGeomCapsuleGetParams (dGeomTransformGetGeom (mShape->_getOdeGeomID()), &r, &h); + radius = real(r); + height = real(h); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-17 21:21:56
|
Revision: 1764 http://svn.sourceforge.net/yake/?rev=1764&view=rev Author: psyclonist Date: 2007-07-17 14:21:56 -0700 (Tue, 17 Jul 2007) Log Message: ----------- switched to yake::Exception Modified Paths: -------------- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp Modified: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp 2007-07-17 19:31:14 UTC (rev 1763) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp 2007-07-17 21:21:56 UTC (rev 1764) @@ -53,7 +53,7 @@ // lookup converter & run (or bail out if no converter found) any_converter_map::const_iterator it = any_converters().find(ti); if (it == any_converters().end()) - throw std::runtime_error(std::string("convert_cpp_to_lua() failed to convert '") + ti->name() + "'."); + throw yake::Exception(std::string("convert_cpp_to_lua() failed to convert '") + ti->name() + "'."); conv_t conv = it->second; conv(L, a); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2007-07-17 19:31:14
|
Revision: 1763 http://svn.sourceforge.net/yake/?rev=1763&view=rev Author: psyclonist Date: 2007-07-17 12:31:14 -0700 (Tue, 17 Jul 2007) Log Message: ----------- fixed GCC 4.1.2 related standard compliance issues and added a workaround for a Luabind bug regarding get_const_holder overloads Modified Paths: -------------- trunk/yake/src/bindings.lua/detail/task.lua.cpp trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp Modified: trunk/yake/src/bindings.lua/detail/task.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/task.lua.cpp 2007-06-22 17:31:05 UTC (rev 1762) +++ trunk/yake/src/bindings.lua/detail/task.lua.cpp 2007-07-17 19:31:14 UTC (rev 1763) @@ -27,6 +27,20 @@ #include <yake/config.h> #if YAKE_ENABLE_LUA_TASK == 1 +// We include yake.lua.shared_ptr.h PRIOR to including any Luabind headers. +// Reasoning: While on MSVC 8 there's no problem GCC 4.1.x fails miserably complaining +// about "you_need_to_define_a_get_const_holder_function_for_your_smart_ptr". +// This is intended to be the indicator that the luabind::get_const_holder() +// overload was not defined for the smart pointer. +// BUT: +// This is actually a bug in Luabind as "it assumes that overloaded functions +// are bound at instantiation time of templates, but overloaded functions are +// bound at definition time, so the luabind" code "only sees the +// luabind::get_const_holder(...) catch all handler. +// (Source: http://osdir.com/ml/lang.lua.bind.user/2006-02/msg00008.html) +// Solution: Include the overloads for our smart pointers PRIOR to any Luabind headers. +#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> @@ -34,11 +48,11 @@ #include <yake/bindings.lua/detail/private.h> #include <yake/bindings.lua/common/lua.helpers.h> #include <yake/bindings.lua/common/vminfo.lua.h> -#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> #include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <yake/task/task.h> + namespace yake { namespace task { Modified: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp 2007-06-22 17:31:05 UTC (rev 1762) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.cpp 2007-07-17 19:31:14 UTC (rev 1763) @@ -41,7 +41,7 @@ void convert_cpp_to_lua(lua_State* L, const boost::any& a) { typedef void(*conv_t)(lua_State* L, const boost::any&); - const type_info* ti = &a.type(); + const std::type_info* ti = &a.type(); // special case: 'boost::any(void)' is converted to 'nil' if (ti == &typeid(void)) @@ -69,9 +69,9 @@ case LUA_TSTRING: return boost::any( object_cast<std::string>(o) ); //@todo fixme default: - throw std::exception("encountered unsupported type in convert_lua_to_cpp()"); + throw yake::Exception("encountered unsupported type in convert_lua_to_cpp()"); } - throw std::exception("encountered unsupported type in convert_lua_to_cpp()"); + throw yake::Exception("encountered unsupported type in convert_lua_to_cpp()"); } boost::any convert_lua_to_cpp(lua_State* L, by_const_reference<boost::any>, int index) { @@ -85,9 +85,9 @@ case LUA_TSTRING: return boost::any( object_cast<std::string>(o) ); //@todo fixme default: - throw std::exception("encountered unsupported type in convert_lua_to_cpp()"); + throw yake::Exception("encountered unsupported type in convert_lua_to_cpp()"); } - throw std::exception("encountered unsupported type in convert_lua_to_cpp()"); + throw yake::Exception("encountered unsupported type in convert_lua_to_cpp()"); } int match_lua_to_cpp(lua_State* L, by_value<boost::any>, int index) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |