Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualServant of the Lord

Posted 28 March 2013 - 09:58 AM

wintertime's solution is a good one - I was making the mistake of assuming that performance was already a problem.


Both Box2D and SFML are open source. Recompile one of them to use the other's vector.

this a good idea but, it'll be a problem with me since sfml using template to define it's vector and i'm still don't know how to use it. moreover b2vec2 using struct to define it's vector and of course it'll make me confusing


Just use SFML's sf::Vector2f typedef, and it'll work fine. The fact that SFML's vector struct/class is a template doesn't harm anything.

For example, if SFML had a templated struct like this:
template <typename Type>
struct MyStruct
{
    Type x;
    Type y;
};
Then it's really, as the name implies, just a "template" that the actual struct is generated from.

Doing this:
MyStruct<int> myIntStruct;
Tells it to generate a struct, using the template, with 'int' instead of 'Type', like this:
/* template <typename Type> */
struct MyStruct_ForInts 
{
    /* Type */ int x;
    /* Type */ int y;
};

MyStruct_ForInts myIntStruct;
Then they can create a second almost-identical struct, with floats instead:
MyStruct<float> myFloatStruct;
Which creates:
struct MyStruct_ForFloats
{
    float x;
    float y;
};

MyStruct_ForFloats myFloatStruct;
The actual name is generated by the compiler, but MyStruct<float> is the generated "name" of the class type that you, as the programmer, use in your code. So you don't actually use 'MyStruct_ForFloats variableName;', you use 'MyStruct<float> variableName;'

This is just to explain templates - I'd still use wintertime's suggestion.

#2Servant of the Lord

Posted 28 March 2013 - 09:58 AM

wintertime's solution is a good one - I was making the mistake of assuming that performance was already a problem.


Both Box2D and SFML are open source. Recompile one of them to use the other's vector.

this a good idea but, it'll be a problem with me since sfml using template to define it's vector and i'm still don't know how to use it. moreover b2vec2 using struct to define it's vector and of course it'll make me confusing


Just use SFML's sf::Vector2f typedef, and it'll work fine. The fact that SFML's vector struct/class is a template doesn't harm anything.

For example, if SFML had a templated struct like this:
template <typename Type>
struct MyStruct
{
    Type x;
    Type y;
};
Then it's really, as the name implies, just a "template" that the actual struct is generated from.
Doing this:
MyStruct<int> myIntStruct;
Tells it to generate a struct, using the template, with 'int' instead of 'Type', like this:
/* template <typename Type> */
struct MyStruct_ForInts 
{
    /* Type */ int x;
    /* Type */ int y;
};

MyStruct_ForInts myIntStruct;
Then they can create a second almost-identical struct, with floats instead:
MyStruct<float> myFloatStruct;
Which creates:
struct MyStruct_ForFloats
{
    float x;
    float y;
};

MyStruct_ForFloats myFloatStruct;
The actual name is generated by the compiler, but MyStruct<float> is the generated "name" of the class type that you, as the programmer, use in your code. So you don't actually use 'MyStruct_ForFloats variableName;', you use 'MyStruct<float> variableName;'

This is just to explain templates - I'd still use wintertime's suggestion.

#1Servant of the Lord

Posted 28 March 2013 - 09:56 AM

Both Box2D and SFML are open source. Recompile one of them to use the other's vector.

this a good idea but, it'll be a problem with me since sfml using template to define it's vector and i'm still don't know how to use it. moreover b2vec2 using struct to define it's vector and of course it'll make me confusing

Just use SFML's sf::Vector2f typedef, and it'll work fine. The fact that SFML's vector struct/class is a template doesn't harm anything.

For example, if SFML had a templated struct like this:

template <typename Type>
struct MyStruct
{
    Type x;
    Type y;
};

Then it's really, as the name implies, just a "template" that the actual struct is generated from.
Doing this:

MyStruct<int> myIntStruct;

Tells it to generate a struct, using the template, with 'int' instead of 'Type', like this:

/* template <typename Type> */
struct MyStruct_ForInts 
{
    /* Type */ int x;
    /* Type */ int y;
};

MyStruct_ForInts myIntStruct;

Then they can create a second almost-identical struct, with floats instead:

MyStruct<float> myFloatStruct;

Which creates:

struct MyStruct_ForFloats
{
    float x;
    float y;
};

MyStruct_ForFloats myFloatStruct;

The actual name is generated by the compiler, but MyStruct<float> is the generated "name" of the class type that you, as the programmer, use in your code. So you don't actually use 'MyStruct_ForFloats variableName;', you use 'MyStruct<float> variableName;'


PARTNERS