Compare commits

..
Author SHA1 Message Date
Thomas Geymayer ea8023e51f Canvas: Provide sane default bounding box (For Image & Text) 2013-01-09 12:11:19 +01:00
Thomas Geymayer 8a9693a28e Fix canvas mouse intersection test
Bounding box of drawables use other coordinate frame
then bounding sphere of MatrixTransform...
2013-01-05 00:44:19 +01:00
Thomas Geymayer 724fba4af9 canvas::Element: parse full 3x3 matrix
This doesn't change any existing behaviour but allows specifying
full 3x3 matrix to eg. perform a perspective transform needed
for some HUDs.
2013-01-01 14:18:39 +01:00
Thomas Geymayer beca1cbf96 Allow nasal::Ghost to only wrap classes by their shared pointers
This removes support for exposing and managing classes by just
raw pointers as this made lifetime management of instances
from C++ to Nasal and especially the other way round nearly
impossible. Always using smart pointers saves us from a lot
of headaches.
2012-12-29 17:49:22 +01:00
James Turner b74d2ae9fa Notify all requests on name lookup failures.
Since there's no active request during a name lookup failure, explicitly fail all sent and queued requests, so the Request subclasses can take regular failure action.
2012-12-29 14:36:38 +00:00
James Turner ec82a0154b Expose the current members of a subsystem group. 2012-12-28 14:54:00 +00:00
James Turner 0ea8dbea10 Add SGPath to the Nasal conversion helpers. 2012-12-28 14:53:31 +00:00
James Turner a131f44247 OS-X specific sleep helper, more stable. 2012-12-23 23:30:40 +00:00
Thomas Geymayer 0423aedffc Revert to old way of including everything from SGMath.hxx 2012-12-23 01:30:41 +01:00
James Turner afc89cdd95 Tweak libSvn usage: fixes a crash on Mac.
Work-around a crash on certain Mac builds (I can't tell why other work fine) where the called parameters to apr_pool_create_ex are problematic. Explicitly pass the default values for the function.
2012-12-22 23:55:37 +00:00
Mathias Froehlich 541606e00d hla: Lower the log level of two alerts.
Trying to interpret the object template in a yet
unimplemented format is not worth an alert.
2012-12-22 10:12:45 +01:00
17 changed files with 208 additions and 196 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ namespace canvas
// Don't check collision with root element (2nd element in _target_path) // Don't check collision with root element (2nd element in _target_path)
// do event listeners attached to the canvas itself (its root group) // do event listeners attached to the canvas itself (its root group)
// always get called even if no element has been hit. // always get called even if no element has been hit.
if( _target_path.size() > 2 && !el.hitBound(local_pos) ) if( _target_path.size() > 2 && !el.hitBound(pos, local_pos) )
return false; return false;
const osg::Vec2f& delta = _target_path.back().local_delta; const osg::Vec2f& delta = _target_path.back().local_delta;
+26 -7
View File
@@ -88,14 +88,24 @@ namespace canvas
{ {
case TT_MATRIX: case TT_MATRIX:
tf = osg::Matrix( tf_node->getDoubleValue("m[0]", 1), tf = osg::Matrix( tf_node->getDoubleValue("m[0]", 1),
tf_node->getDoubleValue("m[1]", 0), 0, 0, tf_node->getDoubleValue("m[1]", 0),
0,
tf_node->getDoubleValue("m[6]", 0),
tf_node->getDoubleValue("m[2]", 0), tf_node->getDoubleValue("m[2]", 0),
tf_node->getDoubleValue("m[3]", 1), 0, 0, tf_node->getDoubleValue("m[3]", 1),
0,
tf_node->getDoubleValue("m[7]", 0),
0,
0,
1,
0,
0, 0, 1, 0,
tf_node->getDoubleValue("m[4]", 0), tf_node->getDoubleValue("m[4]", 0),
tf_node->getDoubleValue("m[5]", 0), 0, 1 ); tf_node->getDoubleValue("m[5]", 0),
0,
tf_node->getDoubleValue("m[8]", 1) );
break; break;
case TT_TRANSLATE: case TT_TRANSLATE:
tf.makeTranslate( osg::Vec3f( tf_node->getDoubleValue("t[0]", 0), tf.makeTranslate( osg::Vec3f( tf_node->getDoubleValue("t[0]", 0),
@@ -182,18 +192,19 @@ namespace canvas
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool Element::hitBound(const osg::Vec2f& pos) const bool Element::hitBound( const osg::Vec2f& pos,
const osg::Vec2f& local_pos ) const
{ {
const osg::Vec3f pos3(pos, 0); const osg::Vec3f pos3(pos, 0);
// Drawables have a bounding box... // Drawables have a bounding box...
if( _drawable ) if( _drawable )
{ {
if( !_drawable->getBound().contains(pos3) ) if( !_drawable->getBound().contains(osg::Vec3f(local_pos, 0)) )
return false; return false;
} }
// ... for other elements, i.e. groups only a bounding sphere is available // ... for other elements, i.e. groups only a bounding sphere is available
else if( !_transform->getBound().contains(pos3) ) else if( !_transform->getBound().contains(osg::Vec3f(pos, 0)) )
return false; return false;
return true; return true;
@@ -394,7 +405,15 @@ namespace canvas
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
osg::BoundingBox Element::getTransformedBounds(const osg::Matrix& m) const osg::BoundingBox Element::getTransformedBounds(const osg::Matrix& m) const
{ {
if( !_drawable )
return osg::BoundingBox(); return osg::BoundingBox();
osg::BoundingBox transformed;
const osg::BoundingBox& bb = _drawable->getBound();
for(int i = 0; i < 4; ++i)
transformed.expandBy( m * bb.corner(i) );
return transformed;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
+2 -1
View File
@@ -79,7 +79,8 @@ namespace canvas
void callListeners(const canvas::EventPtr& event); void callListeners(const canvas::EventPtr& event);
virtual bool hitBound(const osg::Vec2f& pos) const; virtual bool hitBound( const osg::Vec2f& pos,
const osg::Vec2f& local_pos ) const;
osg::ref_ptr<osg::MatrixTransform> getMatrixTransform(); osg::ref_ptr<osg::MatrixTransform> getMatrixTransform();
+2 -2
View File
@@ -787,7 +787,7 @@ HLAFederate::processMessages()
bool bool
HLAFederate::readRTI13ObjectModelTemplate(const std::string& objectModel) HLAFederate::readRTI13ObjectModelTemplate(const std::string& objectModel)
{ {
SG_LOG(SG_IO, SG_ALERT, "HLA version RTI13 not yet(!?) supported."); SG_LOG(SG_IO, SG_WARN, "HLA version RTI13 not yet(!?) supported.");
return false; return false;
} }
@@ -816,7 +816,7 @@ HLAFederate::readRTI1516ObjectModelTemplate(const std::string& objectModel)
bool bool
HLAFederate::readRTI1516EObjectModelTemplate(const std::string& objectModel) HLAFederate::readRTI1516EObjectModelTemplate(const std::string& objectModel)
{ {
SG_LOG(SG_IO, SG_ALERT, "HLA version RTI1516E not yet(!?) supported."); SG_LOG(SG_IO, SG_WARN, "HLA version RTI1516E not yet(!?) supported.");
return false; return false;
} }
+11
View File
@@ -88,6 +88,17 @@ public:
virtual void handleError(int error) virtual void handleError(int error)
{ {
if (error == ENOENT) { if (error == ENOENT) {
// name lookup failure
// we won't have an active request yet, so the logic below won't
// fire to actually call setFailure. Let's fail all of the requests
BOOST_FOREACH(Request_ptr req, sentRequests) {
req->setFailure(error, "hostname lookup failure");
}
BOOST_FOREACH(Request_ptr req, queuedRequests) {
req->setFailure(error, "hostname lookup failure");
}
// name lookup failure, abandon all requests on this connection // name lookup failure, abandon all requests on this connection
sentRequests.clear(); sentRequests.clear();
queuedRequests.clear(); queuedRequests.clear();
-4
View File
@@ -18,10 +18,6 @@
#ifndef SGVec2_H #ifndef SGVec2_H
#define SGVec2_H #define SGVec2_H
#include "SGLimits.hxx"
#include "SGMathFwd.hxx"
#include "SGMisc.hxx"
#include <iosfwd> #include <iosfwd>
/// 2D Vector Class /// 2D Vector Class
+85 -159
View File
@@ -29,6 +29,7 @@
#include <boost/call_traits.hpp> #include <boost/call_traits.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
#include <boost/lambda/lambda.hpp> #include <boost/lambda/lambda.hpp>
#include <boost/mpl/has_xxx.hpp>
#include <boost/utility/enable_if.hpp> #include <boost/utility/enable_if.hpp>
#include <map> #include <map>
@@ -39,117 +40,6 @@
namespace nasal namespace nasal
{ {
/**
* Traits for C++ classes exposed as Ghost. This is the basic template for
* raw types.
*/
template<class T>
struct GhostTypeTraits
{
/** Whether the class is passed by shared pointer or raw pointer */
typedef boost::false_type::type is_shared;
/** The raw class type (Without any shared pointer) */
typedef T raw_type;
};
template<class T>
struct GhostTypeTraits<boost::shared_ptr<T> >
{
typedef boost::true_type::type is_shared;
typedef T raw_type;
};
#ifdef OSG_REF_PTR
template<class T>
struct GhostTypeTraits<osg::ref_ptr<T> >
{
typedef boost::true_type::type is_shared;
typedef T raw_type;
};
#endif
#ifdef SGSharedPtr_HXX
template<class T>
struct GhostTypeTraits<SGSharedPtr<T> >
{
typedef boost::true_type::type is_shared;
typedef T raw_type;
};
#endif
/**
* Policy for creating ghost instances from shared pointer objects.
*/
template<class T>
struct SharedPointerPolicy
{
typedef typename GhostTypeTraits<T>::raw_type raw_type;
typedef T pointer;
typedef boost::false_type returns_dynamic_type;
/**
* Create a shared pointer on the heap to handle the reference counting for
* the passed shared pointer while it is used in Nasal space.
*/
static T* createInstance(const T& ptr)
{
return ptr ? new T(ptr) : 0;
}
static pointer getPtr(void* ptr)
{
if( ptr )
return *static_cast<T*>(ptr);
else
return pointer();
}
static raw_type* getRawPtr(void* ptr)
{
if( ptr )
return static_cast<T*>(ptr)->get();
else
return 0;
}
static raw_type* getRawPtr(const T& ptr)
{
return ptr.get();
}
};
/**
* Policy for creating ghost instances as raw objects on the heap.
*/
template<class T>
struct RawPointerPolicy
{
typedef typename GhostTypeTraits<T>::raw_type raw_type;
typedef raw_type* pointer;
typedef boost::true_type returns_dynamic_type;
/**
* Create a new object instance on the heap
*/
static T* createInstance()
{
return new T();
}
static pointer getPtr(void* ptr)
{
BOOST_STATIC_ASSERT((boost::is_same<pointer, T*>::value));
return static_cast<T*>(ptr);
}
static raw_type* getRawPtr(void* ptr)
{
BOOST_STATIC_ASSERT((boost::is_same<raw_type, T>::value));
return static_cast<T*>(ptr);
}
};
namespace internal namespace internal
{ {
/** /**
@@ -217,6 +107,8 @@ namespace nasal
return nasal::to_nasal(c, _parents); return nasal::to_nasal(c, _parents);
} }
}; };
BOOST_MPL_HAS_XXX_TRAIT_DEF(element_type)
} }
/** /**
@@ -278,12 +170,14 @@ namespace nasal
* *
* naRef myMember(naContext c, int argc, naRef* args); * naRef myMember(naContext c, int argc, naRef* args);
* } * }
* typedef boost::shared_ptr<MyClass> MyClassPtr;
* *
* void exposeClasses() * void exposeClasses()
* { * {
* // Register a nasal ghost type for MyClass. This needs to be done only * // Register a nasal ghost type for MyClass. This needs to be done only
* // once before creating the first ghost instance. * // once before creating the first ghost instance. The exposed class needs
* Ghost<MyClass>::init("MyClass") * // to be wrapped inside a shared pointer, eg. boost::shared_ptr.
* Ghost<MyClassPtr>::init("MyClass")
* // Members can be exposed by getters and setters * // Members can be exposed by getters and setters
* .member("x", &MyClass::getX, &MyClass::setX) * .member("x", &MyClass::getX, &MyClass::setX)
* // For readonly variables only pass a getter * // For readonly variables only pass a getter
@@ -298,15 +192,13 @@ namespace nasal
*/ */
template<class T> template<class T>
class Ghost: class Ghost:
public internal::GhostMetadata, public internal::GhostMetadata
protected boost::mpl::if_< typename GhostTypeTraits<T>::is_shared,
SharedPointerPolicy<T>,
RawPointerPolicy<T> >::type
{ {
BOOST_STATIC_ASSERT( internal::has_element_type<T>::value );
public: public:
typedef T value_type; typedef typename T::element_type raw_type;
typedef typename GhostTypeTraits<T>::raw_type raw_type; typedef T pointer;
typedef typename Ghost::pointer pointer;
typedef naRef (raw_type::*member_func_t)(const CallContext&); typedef naRef (raw_type::*member_func_t)(const CallContext&);
typedef naRef (*free_func_t)(raw_type&, const CallContext&); typedef naRef (*free_func_t)(raw_type&, const CallContext&);
typedef boost::function<naRef(naContext, raw_type&)> getter_t; typedef boost::function<naRef(naContext, raw_type&)> getter_t;
@@ -361,22 +253,27 @@ namespace nasal
* registers on its own before it can be used as base class. * registers on its own before it can be used as base class.
* *
* @tparam BaseGhost Type of base class already wrapped into Ghost class * @tparam BaseGhost Type of base class already wrapped into Ghost class
* (Ghost<Base>) * (Ghost<BasePtr>)
* *
* @code{cpp} * @code{cpp}
* Ghost<MyBase>::init("MyBase"); * Ghost<MyBasePtr>::init("MyBase");
* Ghost<MyClass>::init("MyClass") * Ghost<MyClassPtr>::init("MyClass")
* .bases<Ghost<MyBase> >(); * .bases<Ghost<MyBasePtr> >();
* @endcode * @endcode
*/ */
template<class BaseGhost> template<class BaseGhost>
typename boost::enable_if_c typename boost::enable_if
< boost::is_base_of<GhostMetadata, BaseGhost>::value <
&& boost::is_base_of<typename BaseGhost::raw_type, raw_type>::value, boost::is_base_of<GhostMetadata, BaseGhost>,
Ghost Ghost
>::type& >::type&
bases() bases()
{ {
BOOST_STATIC_ASSERT
((
boost::is_base_of<typename BaseGhost::raw_type, raw_type>::value
));
BaseGhost* base = BaseGhost::getSingletonPtr(); BaseGhost* base = BaseGhost::getSingletonPtr();
base->addDerived base->addDerived
( (
@@ -417,22 +314,27 @@ namespace nasal
* Register a base class for this ghost. The base class needs to be * Register a base class for this ghost. The base class needs to be
* registers on its own before it can be used as base class. * registers on its own before it can be used as base class.
* *
* @tparam Base Type of base class (Base as used in Ghost<Base>) * @tparam Base Type of base class (Base as used in Ghost<BasePtr>)
* *
* @code{cpp} * @code{cpp}
* Ghost<MyBase>::init("MyBase"); * Ghost<MyBasePtr>::init("MyBase");
* Ghost<MyClass>::init("MyClass") * Ghost<MyClassPtr>::init("MyClass")
* .bases<MyBase>(); * .bases<MyBasePtr>();
* @endcode * @endcode
*/ */
template<class Base> template<class Base>
typename boost::enable_if_c typename boost::disable_if
< !boost::is_base_of<GhostMetadata, Base>::value <
&& boost::is_base_of<typename Ghost<Base>::raw_type, raw_type>::value, boost::is_base_of<GhostMetadata, Base>,
Ghost Ghost
>::type& >::type&
bases() bases()
{ {
BOOST_STATIC_ASSERT
((
boost::is_base_of<typename Ghost<Base>::raw_type, raw_type>::value
));
return bases< Ghost<Base> >(); return bases< Ghost<Base> >();
} }
@@ -537,7 +439,7 @@ namespace nasal
* naRef myMethod(naContext c, int argc, naRef* args); * naRef myMethod(naContext c, int argc, naRef* args);
* } * }
* *
* Ghost<MyClass>::init("Test") * Ghost<MyClassPtr>::init("Test")
* .method<&MyClass::myMethod>("myMethod"); * .method<&MyClass::myMethod>("myMethod");
* @endcode * @endcode
*/ */
@@ -563,7 +465,7 @@ namespace nasal
* class MyClass; * class MyClass;
* naRef myMethod(MyClass& obj, naContext c, int argc, naRef* args); * naRef myMethod(MyClass& obj, naContext c, int argc, naRef* args);
* *
* Ghost<MyClass>::init("Test") * Ghost<MyClassPtr>::init("Test")
* .method_func<&myMethod>("myMethod"); * .method_func<&myMethod>("myMethod");
* @endcode * @endcode
*/ */
@@ -580,10 +482,11 @@ namespace nasal
* *
* @param c Active Nasal context * @param c Active Nasal context
*/ */
static naRef create( naContext c ) // TODO check if default constructor exists
{ // static naRef create( naContext c )
return makeGhost(c, Ghost::createInstance()); // {
} // return makeGhost(c, createInstance());
// }
/** /**
* Create a Nasal instance of this ghost. * Create a Nasal instance of this ghost.
@@ -594,7 +497,7 @@ namespace nasal
template<class A1> template<class A1>
static naRef create( naContext c, const A1& a1 ) static naRef create( naContext c, const A1& a1 )
{ {
return makeGhost(c, Ghost::createInstance(a1)); return makeGhost(c, createInstance(a1));
} }
/** /**
@@ -627,7 +530,7 @@ namespace nasal
{ {
// Check if it's a ghost and if it can be converted // Check if it's a ghost and if it can be converted
if( isBaseOf( naGhost_type(me) ) ) if( isBaseOf( naGhost_type(me) ) )
return Ghost::getPtr( naGhost_ptr(me) ); return getPtr( naGhost_ptr(me) );
// Now if it is derived from a ghost (hash with ghost in parent vector) // Now if it is derived from a ghost (hash with ghost in parent vector)
else if( naIsHash(me) ) else if( naIsHash(me) )
@@ -663,6 +566,36 @@ namespace nasal
typedef std::vector<type_checker_t> DerivedList; typedef std::vector<type_checker_t> DerivedList;
DerivedList _derived_types; DerivedList _derived_types;
/**
* Create a shared pointer on the heap to handle the reference counting
* for the passed shared pointer while it is used in Nasal space.
*/
static pointer* createInstance(const pointer& ptr)
{
return ptr ? new pointer(ptr) : 0;
}
static pointer getPtr(void* ptr)
{
if( ptr )
return *static_cast<pointer*>(ptr);
else
return pointer();
}
static raw_type* getRawPtr(void* ptr)
{
if( ptr )
return static_cast<pointer*>(ptr)->get();
else
return 0;
}
static raw_type* getRawPtr(const pointer& ptr)
{
return ptr.get();
}
void addDerived( const internal::GhostMetadata* derived_meta, void addDerived( const internal::GhostMetadata* derived_meta,
const type_checker_t& derived_info ) const type_checker_t& derived_info )
{ {
@@ -724,7 +657,7 @@ namespace nasal
static raw_type& requireObject(naContext c, naRef me) static raw_type& requireObject(naContext c, naRef me)
{ {
raw_type* obj = Ghost::getRawPtr( fromNasal(c, me) ); raw_type* obj = getRawPtr( fromNasal(c, me) );
naGhostType* ghost_type = naGhost_type(me); naGhostType* ghost_type = naGhost_type(me);
if( !obj ) if( !obj )
@@ -800,20 +733,13 @@ namespace nasal
static naRef makeGhost(naContext c, void *ptr) static naRef makeGhost(naContext c, void *ptr)
{ {
if( Ghost::getRawPtr(ptr) ) if( getRawPtr(ptr) )
{ {
naGhostType* ghost_type = 0; // We are wrapping shared pointers to already existing objects which
if( Ghost::returns_dynamic_type::value ) // will then be hold be a new shared pointer. We therefore have to
// For pointer policies already returning instances of an object // check for the dynamic type of the object as it might differ from
// with the dynamic type of this Ghost's raw_type the type is always // the passed static type.
// the same. naGhostType* ghost_type = getTypeFor<Ghost>( getRawPtr(ptr) );
ghost_type = &getSingletonPtr()->_ghost_type;
else
// If wrapping eg. shared pointers the users passes an already
// existing instance of an object which will then be hold be a new
// shared pointer. We therefore have to check for the dynamic type
// of the object as it might differ from the passed static type.
ghost_type = getTypeFor<Ghost>( Ghost::getRawPtr(ptr) );
if( ghost_type ) if( ghost_type )
return naNewGhost2(c, ghost_type, ptr); return naNewGhost2(c, ghost_type, ptr);
@@ -825,7 +751,7 @@ namespace nasal
static void destroyGhost(void *ptr) static void destroyGhost(void *ptr)
{ {
delete static_cast<T*>(ptr); delete static_cast<pointer*>(ptr);
} }
/** /**
@@ -852,7 +778,7 @@ namespace nasal
if( member->second.func ) if( member->second.func )
*out = nasal::to_nasal(c, member->second.func); *out = nasal::to_nasal(c, member->second.func);
else if( !member->second.getter.empty() ) else if( !member->second.getter.empty() )
*out = member->second.getter(c, *Ghost::getRawPtr(g)); *out = member->second.getter(c, *getRawPtr(g));
else else
return "Read-protected member"; return "Read-protected member";
@@ -873,7 +799,7 @@ namespace nasal
if( member->second.setter.empty() ) if( member->second.setter.empty() )
naRuntimeError(c, "ghost: Write protected member: %s", key.c_str()); naRuntimeError(c, "ghost: Write protected member: %s", key.c_str());
member->second.setter(c, *Ghost::getRawPtr(g), val); member->second.setter(c, *getRawPtr(g), val);
} }
}; };
+5 -15
View File
@@ -1,4 +1,4 @@
#include <simgear/math/SGVec2.hxx> #include <simgear/math/SGMath.hxx>
#include "Ghost.hxx" #include "Ghost.hxx"
#include "NasalHash.hxx" #include "NasalHash.hxx"
@@ -111,31 +111,21 @@ int main(int argc, char* argv[])
Hash mod = hash.createHash("mod"); Hash mod = hash.createHash("mod");
mod.set("parent", hash); mod.set("parent", hash);
Ghost<Base>::init("Base") Ghost<BasePtr>::init("BasePtr")
.method<&Base::member>("member") .method<&Base::member>("member")
.member("str", &Base::getString, &Base::setString); .member("str", &Base::getString, &Base::setString);
Ghost<Derived>::init("Derived")
.bases<Base>()
.member("x", &Derived::getX, &Derived::setX)
.member("x_alternate", &f_derivedGetX)
.method_func<&member>("free_member");
naRef derived = Ghost<Derived>::create(c);
VERIFY( naIsGhost(derived) );
VERIFY( std::string("Derived") == naGhost_type(derived)->name );
Ghost<BasePtr>::init("BasePtr");
Ghost<DerivedPtr>::init("DerivedPtr") Ghost<DerivedPtr>::init("DerivedPtr")
.bases<BasePtr>() .bases<BasePtr>()
.member("x", &Derived::getX, &Derived::setX) .member("x", &Derived::getX, &Derived::setX)
.member("x_alternate", &f_derivedGetX)
.method_func<&member>("free_member"); .method_func<&member>("free_member");
Ghost<DoubleDerivedPtr>::init("DoubleDerivedPtr") Ghost<DoubleDerivedPtr>::init("DoubleDerivedPtr")
.bases<DerivedPtr>(); .bases<DerivedPtr>();
Ghost<DoubleDerived2Ptr>::init("DoubleDerived2Ptr") Ghost<DoubleDerived2Ptr>::init("DoubleDerived2Ptr")
.bases<DerivedPtr>(); .bases< Ghost<DerivedPtr> >();
BasePtr d( new Derived ); BasePtr d( new Derived );
derived = Ghost<BasePtr>::create(c, d); naRef derived = Ghost<BasePtr>::create(c, d);
VERIFY( naIsGhost(derived) ); VERIFY( naIsGhost(derived) );
VERIFY( std::string("DerivedPtr") == naGhost_type(derived)->name ); VERIFY( std::string("DerivedPtr") == naGhost_type(derived)->name );
+8
View File
@@ -19,6 +19,8 @@
#include "from_nasal_detail.hxx" #include "from_nasal_detail.hxx"
#include "NasalHash.hxx" #include "NasalHash.hxx"
#include <simgear/misc/sg_path.hxx>
namespace nasal namespace nasal
{ {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@@ -53,6 +55,12 @@ namespace nasal
return std::string(naStr_data(na_str), naStr_len(na_str)); return std::string(naStr_data(na_str), naStr_len(na_str));
} }
SGPath from_nasal_helper(naContext c, naRef ref, SGPath*)
{
naRef na_str = naStringValue(c, ref);
return SGPath(std::string(naStr_data(na_str), naStr_len(na_str)));
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
Hash from_nasal_helper(naContext c, naRef ref, Hash*) Hash from_nasal_helper(naContext c, naRef ref, Hash*)
{ {
@@ -31,6 +31,8 @@
#include <typeinfo> // std::bad_cast #include <typeinfo> // std::bad_cast
#include <vector> #include <vector>
class SGPath;
namespace nasal namespace nasal
{ {
class Hash; class Hash;
@@ -75,6 +77,11 @@ namespace nasal
*/ */
std::string from_nasal_helper(naContext c, naRef ref, std::string*); std::string from_nasal_helper(naContext c, naRef ref, std::string*);
/**
* Convert a Nasal string to an SGPath
*/
SGPath from_nasal_helper(naContext c, naRef ref, SGPath*);
/** /**
* Convert a Nasal hash to a nasal::Hash * Convert a Nasal hash to a nasal::Hash
*/ */
+7
View File
@@ -19,6 +19,8 @@
#include "to_nasal.hxx" #include "to_nasal.hxx"
#include "NasalHash.hxx" #include "NasalHash.hxx"
#include <simgear/misc/sg_path.hxx>
namespace nasal namespace nasal
{ {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@@ -53,4 +55,9 @@ namespace nasal
return ref; return ref;
} }
//----------------------------------------------------------------------------
naRef to_nasal(naContext c, const SGPath& path)
{
return to_nasal(c, path.str());
}
} // namespace nasal } // namespace nasal
+4
View File
@@ -30,6 +30,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
class SGPath;
namespace nasal namespace nasal
{ {
class Hash; class Hash;
@@ -60,6 +62,8 @@ namespace nasal
*/ */
naRef to_nasal(naContext c, naRef ref); naRef to_nasal(naContext c, naRef ref);
naRef to_nasal(naContext c, const SGPath& path);
/** /**
* Convert a numeric type to Nasal number * Convert a numeric type to Nasal number
*/ */
+9 -2
View File
@@ -597,8 +597,15 @@ int SGTerraSync::SvnThread::svnClientSetup(void)
return EXIT_FAILURE; return EXIT_FAILURE;
#endif #endif
apr_pool_t *pool; apr_pool_t *pool = NULL;
apr_pool_create(&pool, NULL);
apr_allocator_t* allocator = NULL;
int aprErr = apr_allocator_create(&allocator);
if (aprErr != APR_SUCCESS)
return EXIT_FAILURE;
apr_pool_create_ex(&pool, NULL /* parent pool */, NULL /* abort func */, allocator);
svn_error_t *err = NULL; svn_error_t *err = NULL;
SVN_VERSION_DEFINE(_svn_version); SVN_VERSION_DEFINE(_svn_version);
err = svn_ver_check_list(&_svn_version, mysvn_checklist); err = svn_ver_check_list(&_svn_version, mysvn_checklist);
+2
View File
@@ -48,6 +48,8 @@ class SGWeakPtr;
template<typename T> template<typename T>
class SGSharedPtr { class SGSharedPtr {
public: public:
typedef T element_type;
SGSharedPtr(void) : _ptr(0) SGSharedPtr(void) : _ptr(0)
{} {}
SGSharedPtr(T* ptr) : _ptr(ptr) SGSharedPtr(T* ptr) : _ptr(ptr)
+10
View File
@@ -281,6 +281,16 @@ SGSubsystemGroup::resume ()
_members[i]->subsystem->resume(); _members[i]->subsystem->resume();
} }
string_list
SGSubsystemGroup::member_names() const
{
string_list result;
for (unsigned int i = 0; i < _members.size(); i++)
result.push_back( _members[i]->name );
return result;
}
bool bool
SGSubsystemGroup::is_suspended () const SGSubsystemGroup::is_suspended () const
{ {
+7 -1
View File
@@ -32,7 +32,7 @@
#include <simgear/timing/timestamp.hxx> #include <simgear/timing/timestamp.hxx>
#include <simgear/structure/SGSharedPtr.hxx> #include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/misc/strutils.hxx>
class TimingInfo class TimingInfo
{ {
@@ -321,6 +321,12 @@ public:
* *
*/ */
void set_fixed_update_time(double fixed_dt); void set_fixed_update_time(double fixed_dt);
/**
* retrive list of member subsystem names
*/
string_list member_names() const;
private: private:
class Member; class Member;
+18
View File
@@ -255,6 +255,24 @@ bool SGTimeStamp::sleepFor(const SGTimeStamp& reltime)
// Don't know, but may be win32 has something better today?? // Don't know, but may be win32 has something better today??
Sleep(static_cast<DWORD>(reltime.toMSecs())); Sleep(static_cast<DWORD>(reltime.toMSecs()));
return true; return true;
#elif defined __APPLE__
// the generic version below behaves badly on Mac; use nanosleep directly,
// similar to the POSIX timers version
struct timespec ts;
ts.tv_sec = reltime._sec;
ts.tv_nsec = reltime._nsec;
for (;;) {
struct timespec rem;
int ret = nanosleep(&ts, &rem);
if (-1 == ret && errno != EINTR)
return false;
if (ret == 0)
break;
// Use the remainder for the next cycle.
ts = rem;
}
return true;
#else #else
SGTimeStamp abstime; SGTimeStamp abstime;
abstime.stamp(); abstime.stamp();