コード例 #1
0
int main ()
{
  printf ("Results of mathlib_performance test:\n");
  
  try
  {
    Environment env;
    
    Shell shell ("lua", env);

    xtl::com_ptr<IInterpreter> script (shell.Interpreter ());            

    env.Library ("global").Register ("typename", make_invoker (&get_typename));
  
    env.BindLibraries ("Math");
    load_script       (*script, SCRIPT_FILE_NAME);

    printf ("Test c++ performance:\n");
    
    size_t start_time = common::milliseconds ();

    float test_result = test ();
    
    printf ("Duration = %u ms, result = %f\n", common::milliseconds () - start_time, test_result);
    
    printf ("Test lua performance:\n");

    start_time = common::milliseconds ();
    
    test_result = invoke<float> (*script, "test");
    
    printf ("Duration = %u ms, result = %f\n", common::milliseconds () - start_time, test_result);
  }
  catch (xtl::bad_any_cast& exception)
  {
    printf ("%s: %s -> %s\n", exception.what (), exception.source_type ().name (), exception.target_type ().name ());
  }    
  catch (std::exception& exception)
  {
    printf ("exception: %s\n", exception.what ());
  }

  return 0;
}
コード例 #2
0
void bind_axis_aligned_box_library (Environment& environment)
{
  typedef axis_aligned_box<T>         box_type;
  typedef typename box_type::vec_type vec_type;  

  InvokerRegistry lib        = environment.CreateLibrary (BV_AXIS_ALIGNED_BOX_LIBRARY);
  InvokerRegistry global_lib = environment.Library ("global");
  
    //регистрация функций создания

  lib.Register ("Create", make_invoker (
                            make_invoker ((box_type (*)(T, T, T, T, T, T))&create_axis_aligned_box<T>),
                            make_invoker ((box_type (*)(const vec_type&, const vec_type&))&create_axis_aligned_box<T>),
                            make_invoker ((box_type (*)())&create_axis_aligned_box<T>)
                          ));
  global_lib.Register ("AABB", lib, "Create");

    //регистрация статических переменных

  bind_static_axis_aligned_box_library (environment);

    //регистрация операций

  lib.Register ("set_Minimum", make_invoker (implicit_cast<void (axis_aligned_box<T>::*) (const typename axis_aligned_box<T>::vec_type&)> 
                                            (&box_type::set_minimum)));
  lib.Register ("set_Maximum", make_invoker (implicit_cast<void (box_type::*) (const typename box_type::vec_type&)> 
                                            (&box_type::set_maximum)));
  lib.Register ("get_Minimum", make_invoker (&box_type::minimum));
  lib.Register ("get_Maximum", make_invoker (&box_type::maximum));

  lib.Register ("get_Center", make_invoker (&box_type::center));
  lib.Register ("get_Size",   make_invoker (&box_type::size));
  lib.Register ("get_Radius", make_invoker (&box_type::radius));
  lib.Register ("get_Empty",  make_invoker (&box_type::empty));

  lib.Register ("SetExtents", make_invoker (implicit_cast<void (box_type::*)
               (const typename box_type::vec_type&, const typename box_type::vec_type&)> (&box_type::set_extents)));

  lib.Register ("Corner", make_invoker (&box_type::corner));

  lib.Register ("Reset", make_invoker (&box_type::reset));

  lib.Register ("__add", make_invoker (implicit_cast<box_type (box_type::*) 
                                      (const box_type&) const> (&box_type::operator +)));
  lib.Register ("__mul", make_invoker (
    make_invoker (implicit_cast<box_type (box_type::*) (const matrix<T, 4>&) const> (&box_type::operator *)),
    make_invoker (implicit_cast<box_type (box_type::*) (const quat<T>&) const> (&box_type::operator *))
  ));
//  lib.Register ("__eq",  make_invoker (&box_type::operator ==));

  lib.Register ("get_Volume", make_invoker (&bound_volumes::volume<T>));
  lib.Register ("Equal", make_invoker (xtl::implicit_cast<bool (*)(const box_type&, const box_type&, const T& eps)> (&bound_volumes::equal<T>)));
  lib.Register ("Intersects", make_invoker (implicit_cast<bool (*) (const box_type&, const box_type&)> (&bound_volumes::intersects)));
  lib.Register ("Contains", make_invoker (
    make_invoker (implicit_cast<bool (*) (const box_type&, const box_type&)> (&bound_volumes::contains)),
    make_invoker (implicit_cast<bool (*) (const box_type&, const math::vector<T, 3>&)> (&bound_volumes::contains))
  ));
  lib.Register ("Intersection", make_invoker (implicit_cast<box_type (*) (const box_type&, const box_type&)> (&bound_volumes::intersection)));

    //регистрация типов данных

  environment.RegisterType<box_type> (BV_AXIS_ALIGNED_BOX_LIBRARY);
}