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

Author Topic: SFML Game Development -- A book on SFML  (Read 285224 times)

0 Members and 3 Guests are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development -- A book on SFML
« Reply #150 on: November 30, 2013, 02:11:48 pm »
I need a technique to draw the interactions, so I can reference them now and then until they sink in.  Do you have any recommendations for this type of approach?
There are quite a few diagrams in the book, especially one that visualizes how events and commands are propagated through the different classes. You could take them as inspiration, and expand them according to your needs. What do you have in mind concretely?

Next, I have a couple c++ 11 questions.
this can be considered an implicit function parameter. If you call a member function (createProjectiles()) in a lambda expression, you need to capture this. If you bind a member function, you can use _1 to forward the first parameter as this.

Finally, in chapter 7 under the subtitle Displaying Text the author mentions the method Aircraft::update when they meant Aircraft::updateTexts.  I wanted to point this out in case it hasn't been noticed.
Thanks for the notice!
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: SFML Game Development -- A book on SFML
« Reply #151 on: November 30, 2013, 04:37:50 pm »
The diagram you used to demonstrate the flow of commands in Ch 4 was very helpful.  It's what made me realize it be really helpful to have a visual representation of classes and their interactions.  That got me wondering whether there was an popularized convention for diagramming different aspects of code?

Also, could you respond to the std::placeholders question?  I looked up a number of references, but still don't understand why a placeholder is being set for a function that doesn't have a parameter.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development -- A book on SFML
« Reply #152 on: November 30, 2013, 05:19:58 pm »
That got me wondering whether there was an popularized convention for diagramming different aspects of code?
UML is quite hyped in the field of OOP. But especially when you do it for yourself, it's questionable whether strictly adhering to such standards is helpful -- depending on the programming language and personal preference, it may be worthwhile to model code design in a different way. Personally, I like to sketch things with pen and paper, similar to the diagrams in the book (and sometimes with more information).

Also, could you respond to the std::placeholders question?
I did. To expand on my previous answer: In std::bind() contexts, this is always considered the first parameter.

Let's look at our example: We are given
void Aircraft::increaseSpread();
, a member function with no parameter. This declaration is, apart from access rights, semantically equivalent to a global function with one parameter, namely a pointer to the object -- in other words, this.
void increaseSpread(Aircraft* this);

When you bind this function, you can therefore use the placeholder _1 to forward the first argument of the resulting callable as the this pointer in the original function.
std::bind(&Aircraft::increaseSpread, _1);
yields a unary functor:
struct Bound
{
    void operator() (Aircraft& argumentToForward);
};

If it's still not clear, I suggest reading the documentation of std::bind() in details. These things are all explained.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

georger

  • Guest
Re: SFML Game Development -- A book on SFML
« Reply #153 on: November 30, 2013, 06:15:33 pm »
That got me wondering whether there was an popularized convention for diagramming different aspects of code?
UML is quite hyped in the field of OOP. But especially when you do it for yourself, it's questionable whether strictly adhering to such standards is helpful -- depending on the programming language and personal preference, it may be worthwhile to model code design in a different way. Personally, I like to sketch things with pen and paper, similar to the diagrams in the book (and sometimes with more information).
I drew UML class diagrams for chapters 3, 4 and 5 with Violet UML Editor - it's free and very easy to use.
I'm a visual learner, so the class diagrams really helped me to figure things out.

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: SFML Game Development -- A book on SFML
« Reply #154 on: November 30, 2013, 07:53:48 pm »
Thanks Nexus, you made that very clear.  Also, thanks georger for the heads up.  I downloaded Violet and will give it a shot.  I think this will be very helpful for me.

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: SFML Game Development -- A book on SFML
« Reply #155 on: December 03, 2013, 09:14:57 pm »
Previously, I had said chapters 8-10 were crashing on entering gameplay (reply #127).  I've made it to chapter 8 and started looking into it.  What happens is an exception is thrown when trying to load the jungle texture.  The message i receive is "Failed to create texture, its internal size is to high (1024x4023, maximum is 2048x2048)."

I've switched to the desert texture and it allows me to play the game.  I've never seen the intended gameplay, but it's running at about 26-30 fps and feels a little choppy.  The effect on HP text, bullets, and pickups seems to be leaving cloud bursts (I've attached a screenshot).  I'm assuming these are the shader effects that are being introduced.
« Last Edit: December 08, 2013, 01:29:50 pm by Kanefa »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: SFML Game Development -- A book on SFML
« Reply #156 on: December 03, 2013, 09:32:58 pm »
The error simply means, that your graphics card can only handle texture with a maximum size of 2048x2048 and the jungle texture is bigger than that.
In combination with the low FPS, it really seems like your graphics card is not directly made for the developed game.

But there are things you could do. If you're not already doing so, you should run the game in release mode. Then you can also split the texture into smaller pieces. This will require some extra logic, but at least that way you can use the image. How is the performance if you turn off shaders?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: SFML Game Development -- A book on SFML
« Reply #157 on: December 07, 2013, 08:59:29 pm »
I only mentioned the issue with the jungle texture, because previously I had said chapters 8-10 were crashing and that was the issue. 

I've finished chapter 8 now and can definitely say the issue is the bloom effect which uses shaders.

Quote
PostEffect::isSupported()

This returns true, but my video card just can't handle it, so I have simply commented out the alternative draw code in World::draw().  The previously FPS numbers were from release mode.  With shaders disabled I have jumped up to 160 FPS from 1 FPS in debug mode.
« Last Edit: December 08, 2013, 01:34:52 pm by Kanefa »

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: SFML Game Development -- A book on SFML
« Reply #158 on: December 08, 2013, 01:28:39 pm »
With Ch 8's code I have been experiencing a crash when the game transitions from the GameOverState from either finishing the level or dying.  I've set a breakpoint within StateStack::applyPendingChanges() on mStack.clear().  The mPendingList contains an Action to perform a clear and then push the MenuState.  The stack itself contains the GameState and the GameOverState.  Everything looks good.  When I continue I get the following.

Quote
Unhandled exception at 0x1002CA1C (ig4icd32.dll) in 08_Graphics.exe 0xC0000005: Access violation writing  location 0x0000001C.

To be safe I got the most recent code from Laurent's SFML-Game-Development-Book repo.  I realized this did not occur in Ch 7, so I began removing new additions.  To be clear the following two changes are the only changes I have made to the code.

First I comment out the drawing of the shader.

Quote
void World::draw()
{
//   if (PostEffect::isSupported())
//   {
//      mSceneTexture.clear();
//      mSceneTexture.setView(mWorldView);
//      mSceneTexture.draw(mSceneGraph);
//      mSceneTexture.display();
//      mBloomEffect.apply(mSceneTexture, mTarget);
//   }
//   else
//   {
      mTarget.setView(mWorldView);
      mTarget.draw(mSceneGraph);
//   }
}

The crash will still occur, but if I then comment out the following line from the body of World's ctor the crash goes away.

Quote
// mSceneTexture.create(mTarget.getSize().x, mTarget.getSize().y);

My understanding of the access violation is that a read or write is occurring to memory that cannot be accessed.  The usage of the sf::RenderTexture looks nearly identical to documentation provided on this site.  I've inspected the object and that looks good too. 

I'm not so concerned with the issue.  I can't use shaders regardless, but it does bother me I don't have an idea how to debug this.  What approach should I take?  Thanks.
« Last Edit: December 08, 2013, 01:41:27 pm by Kanefa »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development -- A book on SFML
« Reply #159 on: December 08, 2013, 01:59:42 pm »
Does your system support render textures? As far as I know, SFML provides a fallback when FBOs are not supported, but I don't know the details here.

Shaders are not supported at all, or do the examples in the SFML SDK work?

Is there an error message on the console?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: SFML Game Development -- A book on SFML
« Reply #160 on: December 08, 2013, 07:49:40 pm »
Quote
Does your system support render textures?

I thought so.  The call to
mSceneTexture.create(mTarget.getSize().x, mTarget.getSize().y);
returns true.  That being said I searched around and dug a couple threads on render textures and Intel GPUs.   

http://en.sfml-dev.org/forums/index.php?topic=9149.0
https://github.com/SFML/SFML/issues/418

Both issues have been fixed and neither sounds similar to what I am experiencing, but it is concerning as I have an Intel GPU.

Quote
Shaders are not supported at all, or do the examples in the SFML SDK work?

Shaders are supported.  I can run the book code, but it just performs poorly.  I tested the SFML SDK shader example and it ran smoothly.

Quote
Is there an error message on the console?

No error message.
« Last Edit: December 08, 2013, 08:26:01 pm by Kanefa »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development -- A book on SFML
« Reply #161 on: December 08, 2013, 09:14:43 pm »
Might it be that the size is too big for the sf::RenderTexture (since you reported a similar issue with sf::Texture)? As far as I know however, in OpenGL the FBO size is only limited by the size of the attached texture, and 2048x2048 is bigger than the window. Another OpenGL error might also be possible (e.g. out of memory), but they should be reported by SFML. Do you compile in debug mode, and link the SFML debug libraries?

Can you use a sf::RenderTexture with the same size in a separate project?

Generally, the "Access violation writing  location 0x0000001C" may indicate null pointer dereferencing (the address is quite close to 0). Do you have the stack trace for it? Is the access violation invoked during clear()? If so, there is undefined behavior elsewhere...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: SFML Game Development -- A book on SFML
« Reply #162 on: December 09, 2013, 03:34:11 pm »
Quote
Do you compile in debug mode, and link the SFML debug libraries?

Yes, I do.

Quote
Can you use a sf::RenderTexture with the same size in a separate project?

No , I cannot.  I have created a very small test that generates the exact same error.

Quote
Unhandled exception at 0x1002CA1C (ig4icd32.dll) in HelloWorld.exe: 0xC0000005: Access violation writing location 0x0000001C.

When you close the window the access violation will occur.  The timing is similar to what is occurring with the book's code.  The book's access violation occurs when the player either dies or finishing the mission causing the GameState and GameOverState to begining destroying its resources.

You'll notice I only create the RenderTexture and never use it.  The access violation occurs regardless.

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(1024, 768), "SFML works!");

        sf::RenderTexture mSceneTexture;
        mSceneTexture.create(1024, 768);

        sf::Texture mTexture;
        mTexture.loadFromFile("Textures/Entities.png");
        sf::Sprite mSprite;
        mSprite.setTexture(mTexture);
        mSprite.setPosition(100.f, 100.f);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(mSprite);
        window.display();
    }

    return 0;
}

Quote
Do you have the stack trace for it?

        ig4icd32.dll!1002ca1c() Unknown
        [Frames below may be incorrect and/or missing, no symbols loaded for ig4icd32.dll]     
        ig4icd32.dll!1002dae2() Unknown
        sfml-graphics-d-2.dll!589c6bf0()        Unknown
        sfml-graphics-d-2.dll!589c7326()        Unknown
        sfml-graphics-d-2.dll!5899bf72()        Unknown
        Sandbox.exe!`eh vector destructor iterator'(void * ptr, unsigned int size, int count, void (void *) * pDtor)    C++
        Sandbox.exe!std::array<sf::RenderTexture,2>::~array<sf::RenderTexture,2>()      C++
        Sandbox.exe!BloomEffect::~BloomEffect() C++
        Sandbox.exe!World::~World()     C++
        Sandbox.exe!GameState::~GameState()     C++
        Sandbox.exe!GameState::`scalar deleting destructor'
(unsigned int)       C++
>       Sandbox.exe!std::default_delete<State>::operator()(State * _Ptr) Line 1152      C++
        Sandbox.exe!std::unique_ptr<State,std::default_delete<State> >::_Delete() Line 1445     C++
        Sandbox.exe!std::unique_ptr<State,std::default_delete<State> >::~unique_ptr<State,std::default_delete<State> >() Line 1400      C++
        Sandbox.exe!std::unique_ptr<State,std::default_delete<State> >::`scalar deleting destructor'(unsigned int)      C++
        Sandbox.exe!std::allocator<std::unique_ptr<State,std::default_delete<State> > >::destroy<std::unique_ptr<State,std::default_delete<State> > >(std::unique_ptr<State,std::default_delete<State> > * _Ptr) Line 624       C++
        Sandbox.exe!std::allocator_traits<std::allocator<std::unique_ptr<State,std::default_delete<State> > > >::destroy<std::unique_ptr<State,std::default_delete<State> > >(std::allocator<std::unique_ptr<State,std::default_delete<State> > > & _Al, std::unique_ptr<State,std::default_delete<State> > * _Ptr) Line 758    C++
        Sandbox.exe!std::_Wrap_alloc<std::allocator<std::unique_ptr<State,std::default_delete<State> > > >::destroy<std::unique_ptr<State,std::default_delete<State> > >(std::unique_ptr<State,std::default_delete<State> > * _Ptr) Line 909    C++
        Sandbox.exe!std::_Destroy_range<std::_Wrap_alloc<std::allocator<std::unique_ptr<State,std::default_delete<State> > > > >(std::unique_ptr<State,std::default_delete<State> > * _First, std::unique_ptr<State,std::default_delete<State> > * _Last, std::_Wrap_alloc<std::allocator<std::unique_ptr<State,std::default_delete<State> > > > & _Al, std::_Nonscalar_ptr_iterator_tag __formal) Line 89      C++
        Sandbox.exe!std::_Destroy_range<std::_Wrap_alloc<std::allocator<std::unique_ptr<State,std::default_delete<State> > > > >(std::unique_ptr<State,std::default_delete<State> > * _First, std::unique_ptr<State,std::default_delete<State> > * _Last, std::_Wrap_alloc<std::allocator<std::unique_ptr<State,std::default_delete<State> > > > & _Al) Line 80 C++
        Sandbox.exe!std::vector<std::unique_ptr<State,std::default_delete<State> >,std::allocator<std::unique_ptr<State,std::default_delete<State> > > >::_Destroy(std::unique_ptr<State,std::default_delete<State> > * _First, std::unique_ptr<State,std::default_delete<State> > * _Last) Line 1480   C++
        Sandbox.exe!std::vector<std::unique_ptr<State,std::default_delete<State> >,std::allocator<std::unique_ptr<State,std::default_delete<State> > > >::clear() Line 1416     C++
        Sandbox.exe!StateStack::applyPendingChanges() Line 91   C++
        Sandbox.exe!StateStack::update(sf::Time dt) Line 24     C++
        Sandbox.exe!Application::update(sf::Time dt) Line 81    C++
        Sandbox.exe!Application::run() Line 57  C++
        Sandbox.exe!main() Line 13      C++
        Sandbox.exe!__tmainCRTStartup() Line 536        C
        Sandbox.exe!mainCRTStartup() Line 377   C
        kernel32.dll!74bd336a() Unknown
        ntdll.dll!76f69f72()    Unknown
        ntdll.dll!76f69f45()    Unknown


Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development -- A book on SFML
« Reply #163 on: December 09, 2013, 07:46:34 pm »
Quote
Can you use a sf::RenderTexture with the same size in a separate project?
No , I cannot.  I have created a very small test that generates the exact same error.
Okay, so it's definitely a problem with SFML or the graphics driver (I tend to assume the latter, since render textures seem to work fine on most systems).

I don't know how much you can do apart from debugging your minimal example and trying to find out the cause (maybe open a new thread if you want to discuss this further). But it might as well be a waste of time if it's a driver bug of an old graphics card that will never be fixed :-\

Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: SFML Game Development -- A book on SFML
« Reply #164 on: December 10, 2013, 05:16:03 pm »
I think it will be easy to let this one go.  I want to wrap up the book and begin my own project.  Thanks again.