Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML game dev. Book, chapter 3 textureholder  (Read 2508 times)

0 Members and 1 Guest are viewing this topic.

danielsega

  • Newbie
  • *
  • Posts: 6
    • View Profile
SFML game dev. Book, chapter 3 textureholder
« on: March 09, 2014, 05:16:18 am »
I am following the book and i started implementing the aircraft constructor, when i really got confused with the book:

//--Aircraft
Aircraft::Aircraft(Type type, const TextureHolder& textures) : mType(type), mSprite(textures.get(toTextureID(type)))
{
        sf::FloatRect bounds = mSprite.getLocalBounds();
        mSprite.setOrigin(bounds.width / 2.0f, bounds.height / quote);
}

//--ResourceIden
template <typename Resource, typename Identifier>
class ResourceHolder;

typedef ResourceHolder<sf::Texture, Textures::ID>       TextureHolder;
}

How does TextureHolder have access to a get function member, since ResourceHolder is not defined?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML game dev. Book, chapter 3 textureholder
« Reply #1 on: March 09, 2014, 11:32:15 am »
It is defined at the point where it is used: in the header ResourceHolder.hpp.

ResourceIdentifiers.hpp just contains a forward declaration for the typedefs. Typedef doesn't require complete types.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

danielsega

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: SFML game dev. Book, chapter 3 textureholder
« Reply #2 on: March 09, 2014, 06:58:51 pm »
It is defined at the point where it is used: in the header ResourceHolder.hpp.

ResourceIdentifiers.hpp just contains a forward declaration for the typedefs. Typedef doesn't require complete types.

I get that, but according to the book sample, there is no pre-processor operation that includes ResourceHolder on ResourceIdentifiers. The the aircraft doesn't know about ResourceHolder, it only knows about ResourceIdentifiers, so it does not know about ResourceHolder,  unless if it becomes static. I don't see how they are linked.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML game dev. Book, chapter 3 textureholder
« Reply #3 on: March 09, 2014, 07:02:58 pm »
The the aircraft doesn't know about ResourceHolder
Yes, it does. See Aircraft.cpp, line 2.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: SFML game dev. Book, chapter 3 textureholder
« Reply #4 on: March 09, 2014, 07:40:33 pm »
I think daniel doesn't understand what #include does.

#include basically copies the file to that point.

When you compile, there will essentially be one .cpp file that all your code is in. So, substitute the code in.

Quick example:
Code: [Select]
// Foo.hpp
struct Foo
{
    Foo(int j) {x = j;}
    ~Foo() {}

    int x;
};

// Bar.hpp
struct Foo; // Forward declaration, notice the absence of a #include

struct Bar
{
    Bar(Foo f) {x = f;}
    ~Bar() {}

    Foo x
};

// main.cpp
#include "Bar.hpp" // insert contents of Bar.hpp here
#include "Foo.hpp" // insert contents of Foo.hpp here

int main()
{
    Bar(Foo(5)) baz;
    return 0;
}

Does that make more sense?

danielsega

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: SFML game dev. Book, chapter 3 textureholder
« Reply #5 on: March 10, 2014, 05:25:15 am »
The the aircraft doesn't know about ResourceHolder
Yes, it does. See Aircraft.cpp, line 2.

My bad, i somehow thought that was resourseidentifier.