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

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

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development -- A book on SFML
« Reply #135 on: October 26, 2013, 11:21:16 am »
Good to hear, thank you :)

By the way, the private issue was fixed on GitHub.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
Re: SFML Game Development -- A book on SFML
« Reply #136 on: October 27, 2013, 05:53:48 pm »
Just trying my first attempt at compiling the book files with Cmake and encountered this error...

The C compiler identification is MSVC 16.0.30319.1
The CXX compiler identification is MSVC 16.0.30319.1
Check for working C compiler using: Visual Studio 10
Check for working C compiler using: Visual Studio 10 -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "C:/Program Files (x86)/Microsoft Visual Studio
  10.0/VC/bin/cl.exe" is not able to compile a simple test program.

Is my compiler at fault here? I don't have much experience with CMake.
{much better code}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
AW: SFML Game Development -- A book on SFML
« Reply #137 on: October 27, 2013, 06:31:40 pm »
The error can be of multiple origins. Make sure you run the latest version of CMake and make sure you've installed all updates for VS 2010 - in fact I'd suggest to upgrade to VS 2013. ;)

Also don't forget to clear the CMake cache and a clean rebuilt.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
Re: SFML Game Development -- A book on SFML
« Reply #138 on: October 28, 2013, 12:16:08 am »
Latest CMake - check.
VS2010 up to date - check.
Cache cleared - check.

These were all checked prior to posting. Tried VS2013 (it has some nice things in it, I like! :) ). I'll leave it and SFML until they're officially married.

Still an odd thing though with VS2010 on my PC. Not sure why CMake is so upset.
No biggie, I'll play around with the source in a fresh project and see how it goes.
{much better code}

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: SFML Game Development -- A book on SFML
« Reply #139 on: October 28, 2013, 02:57:01 pm »
As I read the book I find myself wanting to ask a few questions.  Is there a forum or appropriate place to discuss aspects of the book?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development -- A book on SFML
« Reply #140 on: October 28, 2013, 03:01:07 pm »
Here :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: SFML Game Development -- A book on SFML
« Reply #141 on: October 28, 2013, 03:01:40 pm »
There isn't a dedicated place for the SFML book - maybe Laurent could create a sub forum?
But people have been using this thread and been creating thread here on the forum when they had questions about certain things, so feel free to do so as well. Nexus, Grimshaw and Groogy (the three authors) are more or less regularly on the forum and other readers of the book might know a few things to say as well. :)
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 #142 on: October 28, 2013, 06:00:13 pm »
I'm having an issue understanding the syntax of the derivedAction function.  Using std::function is new to me and is the crux of the issue.  I have included the entire function at the bottom.

std::function<void(SceneNode&, sf::Time)> derivedAction(Function fn)
 

The "std::function<void(SceneNode&, sf::Time)>" specifies the signature for the function derivedAction takes as a parameter.  However, this doesn't seem to jive with the examples from http://en.cppreference.com/w/cpp/utility/functional/function.  My understanding is that it should be specifying the signature for derivedAction.

moveLeft.action = derivedAction<Aircraft>(AircraftMover(-playerSpeed, 0.f));
 

I'm confused with the use of "<Aircraft>". 


template <typename GameObject, typename Function>
std::function<void(SceneNode&, sf::Time)> derivedAction(Function fn)
{
        return [=] (SceneNode& node, sf:Time dt)
        {
                // Check if cast is safe
                assert(dynamic_cast<GameObject*>(&node) != nullptr);

                // Downcast node and invoke function on it
                fn(static_cast<GameObject&>(node), dt)
        };
}
 
« Last Edit: October 28, 2013, 06:14:12 pm by Kanefa »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development -- A book on SFML
« Reply #143 on: October 28, 2013, 06:18:37 pm »
derivedAction<GameObject, Function> is a function template, that is, when you fill in the template parameters, a function is instantiated. There are two template parameters:
  • GameObject: The derived class that you specify explicitly in calling code. A possible argument for this template parameter is Aircraft.
  • Function: The type of callable object you pass as a function parameter, which is deduced by the compiler. "Callable object" can be a function pointer, a functor, or a lambda expression.
The whole idea behind derivedAction() is to take a function that operates on derived classes, using the signature
void(GameObject& object, sf::Time dt)
and to transform it to a function that operates on base classes with the signature
void(SceneNode& object, sf::Time dt)
This allows to store multiple commands in the same container, although they internally dispatch to different classes.

These are rather advanced techniques, but they allow a great simplification. Without derivedAction, we would have to downcast the parameter every time we define a command that runs on a derived class. The derivedAction function template encapsulates this task.

If you don't understand some of the terminology I used in this post, I recommend looking up function templates, function objects and std::function. These are very powerful C++ concepts, and the command system described in the book relies heavily on them.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tommas

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: SFML Game Development -- A book on SFML
« Reply #144 on: October 30, 2013, 04:51:54 am »
I'm loving the book so far!

I had a quick question. How does the second toString function, in chapter 6's Utility.hpp file, work? I can't figure out what, exactly,
 #define BOOK_KEYTOSTRING_CASE(KEY) case sf::Keyboard::KEY: return #KEY;
does. Any help would be appreciated!


Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: SFML Game Development -- A book on SFML
« Reply #145 on: October 30, 2013, 05:04:41 am »
I haven't read the book but I assume the crux of your question/confusion is the special meaning of # in preprocessor macros.  Basically, #KEY turns into "KEY".  So sf::Keyboard::A turns into "A", and so on.

icancto

  • Guest
Re: SFML Game Development -- A book on SFML
« Reply #146 on: November 07, 2013, 03:35:07 pm »
I really like the book. I remember about reading about keys that are pressed down. There was an information about this special behavior computers have where if you have a cursor in a document and you hold down a key (let's say right arrow) in order to move the cursor right, it will move instantly, then pause for a split second and then move very fast.
I think it was in a chapter about events, but I read it again and didn't find it.
If anyone of you, guys, know in which chapter it is or if you can explain to me how it works and how it affects the game, please let me know, because I can't even find it on Google :-)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: SFML Game Development -- A book on SFML
« Reply #147 on: November 07, 2013, 03:57:51 pm »
I currently don't have to book next to me, but you can find some explanation in the official SFML tutorial.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development -- A book on SFML
« Reply #148 on: November 07, 2013, 04:12:04 pm »
You mean key repetition? That should be explained in the chapter about user input.

You can also read the docs of sf::Window::setKeyRepeatEnabled().
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 #149 on: November 30, 2013, 01:27:08 pm »
I have a few questions related to the book.

First, I am looking for a way to draw/visualize the systems used in the book.  For example, I have read and reread how commands are applied to the SceneGraph.  However, I just keep forgetting how they interact and this is true of a number of systems.  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?

Next, I have a couple c++ 11 questions. 

In the following snippet of code why is this needed in the capture list?  Is it so createProjectile is in scope?

Quote
mMissileCommand.action   = [this, &textures] (SceneNode& node, sf::Time)
{
   createProjectile(node, Projectile::Missile, 0.f, 0.5, textures);
};

Why is the std::placeholders::_1 used here, when the increaseSpread function takes zero parameters.

Quote
data[Pickup::FireSpread].action = std::bind(&Aircraft::increaseSpread, _1);

void Aircraft::increaseSpread()
{
   if (mSpreadLevel < 3)
      ++mSpreadLevel;
}

Finally, here's a small correction I noticed in chapter 7 under the subtitle Displaying Text.  The author mentions the method Aircraft::update when they meant Aircraft::updateTexts. 

Quote
In the method Aircraft::update(), we check for the current hitpoints, and convert them to a string, using our custom toString() function.
« Last Edit: November 30, 2013, 01:48:19 pm by Kanefa »