SFML community forums

General => General discussions => Topic started by: OrderNexus on December 29, 2015, 10:06:08 pm

Title: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on December 29, 2015, 10:06:08 pm
Good day, fellow SFML developers!

I'm extremely happy to announce that the fourth book in the SFML series has just been published! It's called "SFML Game Development by Example" and can be found here:

https://www.packtpub.com/game-development/sfml-game-development-example (https://www.packtpub.com/game-development/sfml-game-development-example)
(https://d255esdrn735hr.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/7343_B04284_SFML%20Game%20Development%20By%20Example_.jpg)

I have put a lot of work and effort into this project, and I really hope that those of you who decide to purchase it will enjoy it. Since this is a "by example" publication, I've tried to explore some additional aspects of game development and programming, such as game programming patterns, implementing a flexible G.U.I. system, utilizing the entity component system paradigm, and much more. This is also the first SFML book to tackle the topic of networking, as the final project is a small RPG-style multiplayer game, where players can duke it out by using very basic combat. It looks a little something like this:
(http://i.imgur.com/5gNKHOv.png)

I think I have managed to produce a fairly smooth learning experience throughout the book, by addressing most of the issues a beginner game developer might face in a carefully compartmentalized manner. The book will guide you through three projects in total. The first one is a snake remake. Why snake? Well, it's simple and awesome. :) The second project is a side-scrolling platformer, which you can see on the cover of the book. It introduces a lot of common concepts of game development to the reader and serves as an intermediary project, which leads them nicely into the last project. Sound and music management, G.U.I. and ECS are all implemented here, along with the grand finale of networking, which spans the last two chapters.

With that said, I hope you enjoy the book if you do decide to purchase it. I'd like to express the deepest thanks to Laurent, without whom I wouldn't have had this opportunity. Also, feel free to contact me if you have any issues or questions. You can leave a message here or contact me via e-mail at: order.nexus.dev@gmail.com

Have a nice day!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: SeriousITGuy on December 29, 2015, 10:36:57 pm
As the book is on sale I just grabbed a copy and gone through the TOC. Looks very interesting, some things seem familiar from previous books, but some things look very interesting. Thanks for the work, I look forward to read and test it ;)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Elias Daler on December 29, 2015, 11:15:54 pm
Looks very interesting. Great job. I'll check it out when I have some money, ha-ha. (would be interesting to see your implementations of ECS).
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: zsbzsb on December 29, 2015, 11:23:29 pm
Is the source code available on github as with some of the other SFML books?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on December 29, 2015, 11:40:28 pm
Thank you for all of the nice comments, guys!

Is the source code available on github as with some of the other SFML books?
I will make it publicly available soon, just as I make sure the publisher has no problems with me doing so. Until then, the source code can always be downloaded from their website: https://www.packtpub.com/books/content/support/21835 (https://www.packtpub.com/books/content/support/21835)

As the book is on sale I just grabbed a copy and gone through the TOC. Looks very interesting, some things seem familiar from previous books, but some things look very interesting. Thanks for the work, I look forward to read and test it ;)
Thanks for your support! I really hope you enjoy it. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Sanction on December 30, 2015, 09:17:15 pm
Awesome looking foreword to adding it to my collection :D
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on December 30, 2015, 11:26:27 pm
Awesome looking foreword to adding it to my collection :D
Great! I hope you enjoy it :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Resethel on December 31, 2015, 11:57:45 am
Ah!!! Waited for it for 6 months now :D, thanks a lot  ;D
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Mario on December 31, 2015, 11:07:25 pm
+1 alone for a fitting cover image rather than some generic and unrelated thingy. :)

I'm not sure about the screenshot in your post, though. That nearest neighbour stretching has some very noticeable amount of inconsistent pixel sizes (reminds me of the latest Final Fantasy PC ports).
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on December 31, 2015, 11:51:47 pm
Ah!!! Waited for it for 6 months now :D, thanks a lot  ;D
Thank you! I can't believe someone has been waiting for it to come out for so long :) I hope you enjoy it!

+1 alone for a fitting cover image rather than some generic and unrelated thingy. :)

I'm not sure about the screenshot in your post, though. That nearest neighbour stretching has some very noticeable amount of inconsistent pixel sizes (reminds me of the latest Final Fantasy PC ports).
Thank you! It felt like a book about game development should have a cover that can't be mistaken for something else :)

As far as the graphics go, I suppose it's a matter of taste. To me personally, it felt more like an old school RPG with texture smoothing disabled. To each their own, I guess :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Mario on January 01, 2016, 01:11:36 am
You misunderstood me. I love retro-games (and still enjoy playing old NES/SNES era games). But compare the width/height of pixels. Some rows will be higher than others, which can create a very inconsistent look.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 01, 2016, 03:02:17 am
You misunderstood me. I love retro-games (and still enjoy playing old NES/SNES era games). But compare the width/height of pixels. Some rows will be higher than others, which can create a very inconsistent look.
Ah, I see what you're saying. Sorry about that. It may have something to do with the zoom value of the view being used, in addition to the texture not being smoothed, which results in "nearest neighbor" being used. It may also have to do with the view's center or size not being integers, since this effect is different depending on where the player stands. This might be something I could address in an errata, if it ever comes to it. Thanks for pointing it out :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Mario on January 01, 2016, 10:38:57 am
It's probably caused by a scaling factor being not close to an integer and smaller than 2. The higher it is, the less noticeable are some misaligned rows. With a scaling factor of 1.5 every second row is inconsistent, with 2.0 all are perfect, with 2.2 only every tenth(?) row is affected, etc.

It's nothing critical, but rendering looks inconsistent.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 02, 2016, 07:54:52 pm
It's probably caused by a scaling factor being not close to an integer and smaller than 2. The higher it is, the less noticeable are some misaligned rows. With a scaling factor of 1.5 every second row is inconsistent, with 2.0 all are perfect, with 2.2 only every tenth(?) row is affected, etc.

It's nothing critical, but rendering looks inconsistent.
You're right. Like I said, if Packt allows me to make further revisions, it will definitely be resolved. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Jesper Juhl on January 02, 2016, 08:55:10 pm
Looks interresting. I might buy this.
(especially if it's free of di/tri-graphs unlike some other book ;) and uses modern C++).
Anyway; congratulations on getting published. Great to have another SFML book out there.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: zsbzsb on January 03, 2016, 01:40:10 am
(... and uses modern C++)

This is why I asked about the source code, because if you look at the cover (I know you shouldn't judge a book by it's cover) you will see the following line of code blended into the background...

sf::Texture* texture = new sf::Texture();
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 03, 2016, 07:20:11 am
(... and uses modern C++)

This is why I asked about the source code, because if you look at the cover (I know you shouldn't judge a book by it's cover) you will see the following line of code blended into the background...

sf::Texture* texture = new sf::Texture();
With the exception of smart pointers, all of the code used in this book is modern. I have made a decision quite early on during the writing stage to stick to raw pointers for educational purposes. If you're picking this book up, it's fair to assume that you have at least a decent knowledge of C++, hence you probably have used smart pointers or at the very least have heard of them. At least to me, it seemed that learning how to properly dispose of dynamically allocated objects was more beneficial than using a feature that does it for you, especially since so many newbies have problems with memory leaks. Instead of using smart pointers and swiping the problem under a rug, I attempted to tackle it in a way that seemed the most fit. I guess we'll just have to wait and see how it works out in the long run though. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Jesper Juhl on January 03, 2016, 11:37:46 am
With the exception of smart pointers, all of the code used in this book is modern. I have made a decision quite early on during the writing stage to stick to raw pointers for educational purposes. If you're picking this book up, it's fair to assume that you have at least a decent knowledge of C++, hence you probably have used smart pointers or at the very least have heard of them. At least to me, it seemed that learning how to properly dispose of dynamically allocated objects was more beneficial than using a feature that does it for you, especially since so many newbies have problems with memory leaks. Instead of using smart pointers and swiping the problem under a rug, I attempted to tackle it in a way that seemed the most fit. I guess we'll just have to wait and see how it works out in the long run though. :)
I would argue that the correct way to manage dynamically allocated memory is with RAII and smart pointers. Teaching manual memory management seems misguided to me - especially since it's incredibly hard to get right and code te ds to get pretty ugly with lots of try-catch blocks if you really want to handle all possible leaks and smart pointers solve the whole problem quite elegantly.
I'd have written that line from the book cover as
auto texture = std::make_unique<sf::Texture>();
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 03, 2016, 06:15:14 pm
With the exception of smart pointers, all of the code used in this book is modern. I have made a decision quite early on during the writing stage to stick to raw pointers for educational purposes. If you're picking this book up, it's fair to assume that you have at least a decent knowledge of C++, hence you probably have used smart pointers or at the very least have heard of them. At least to me, it seemed that learning how to properly dispose of dynamically allocated objects was more beneficial than using a feature that does it for you, especially since so many newbies have problems with memory leaks. Instead of using smart pointers and swiping the problem under a rug, I attempted to tackle it in a way that seemed the most fit. I guess we'll just have to wait and see how it works out in the long run though. :)
I would argue that the correct way to manage dynamically allocated memory is with RAII and smart pointers. Teaching manual memory management seems misguided to me - especially since it's incredibly hard to get right and code te ds to get pretty ugly with lots of try-catch blocks if you really want to handle all possible leaks and smart pointers solve the whole problem quite elegantly.
I'd have written that line from the book cover as
auto texture = std::make_unique<sf::Texture>();

I agree, it is a more elegant solution. Not sure I'm on the same page about teaching manual memory management being misguided though. It's a useful skill to have, hence a subject worthy of being taught, as you yourself said that it's hard to get right. At the end of the day, it came down to a simple choice: Do I want a more elegant yet educationally lacking solution for non-production code, or one that is unjustly so looked down upon by many C++ modernists, but with a purpose of teaching something. I chose the latter, obviously, with relatively little negatives to show for it. Performance wasn't impacted in any way, which should always be your number one concern. Whether it was the right choice for the book remains to be seen, so I guess we'll just have to let time do its thing. :) Besides, we shouldn't be judging usage of raw pointers too harshly. The source code of SFML itself has lines like this in it:
m_impl = new priv::ThreadImpl(this);
...
delete m_impl;
m_impl = NULL;

On a side note, it wouldn't really be a huge task for the reader to utilize smart pointers while reading this book, should they choose to do so. The rest of the code is fairly modern and uses C++11 standards. With that said, I think we should wrap up this discussion, since it's really just a matter of opinion at this point. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Laurent on January 03, 2016, 06:48:23 pm
Quote
Besides, we shouldn't be judging usage of raw pointers too harshly. The source code of SFML itself has lines like this in it
Sadly, C++98 has no proper alternative to offer, so this code is necessary. But all this crap will vanish once SFML (3) finally moves to C++11.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: hobby on January 03, 2016, 09:27:41 pm
I'd have written that line from the book cover as
auto texture = std::make_unique<sf::Texture>();
I prefer to not start a religious war here, but since the previous discussion was on smart vs. raw pointers I'll allow myself to question the merit of auto in this example.
Usually over the course of a project, a line of code is read many more times than it is written. Surely if several people are involved in the project. Do you find auto better than the explicit std::unique_ptr<sf::Texture>?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: eXpl0it3r on January 03, 2016, 09:52:35 pm
Usually over the course of a project, a line of code is read many more times than it is written. Surely if several people are involved in the project. Do you find auto better than the explicit std::unique_ptr<sf::Texture>?
It's quite redundant since the factory (i.e. std::make_unique<sf::Texture>) already indicates the type. Having it written out twice, could be interpreted as a bit of noise.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Elias Daler on January 03, 2016, 10:26:25 pm
Usually over the course of a project, a line of code is read many more times than it is written. Surely if several people are involved in the project. Do you find auto better than the explicit std::unique_ptr<sf::Texture>?
It's quite redundant since the factory (i.e. std::make_unique<sf::Texture>) already indicates the type. Having it written out twice, could be interpreted as a bit of noise.
Agreed. And auto makes it easier to refactor this code later. Suppose you want to change unique_ptr to shared_ptr. You'd need to change it twice (instead of only once) if you've written it this way:
std::unique_ptr<sf::Texture> texture = std::make_unique<sf::Texture>();

Or, suppose, you decide to change sf::Texture to another class, again, you'd have to change the same thing twice, which is a bad sign because some day you'll forget to change it somewhere which will lead (at best) to compilation errors and to hard-to-spot bugs at worst.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: hobby on January 03, 2016, 10:58:01 pm
It's quite redundant since the factory (i.e. std::make_unique<sf::Texture>) already indicates the type. Having it written out twice, could be interpreted as a bit of noise.
I tend to agree, in my view this example lies on the border (I had to start the discussion with something...) Have you seen auto i = 0; used in practice (I have)?

Agreed. And auto makes it easier to refactor this code later. Suppose you want to change unique_ptr to shared_ptr. You'd need to change it twice (instead of only once) if you've written it this way:
std::unique_ptr<sf::Texture> texture = std::make_unique<sf::Texture>();

Or, suppose, you decide to change sf::Texture to another class, again, you'd have to change the same thing twice, which is a bad sign because some day you'll forget to change it somewhere which will lead (at best) to compilation errors and to hard-to-spot bugs at worst.
Dynamically-typed languages (https://en.wikipedia.org/wiki/Dynamic_programming_language) excel at minimizing the code changes required for refactoring, and SFML has bindings in some of them. Still, I wouldn't go on to claim that they enable easier refactoring - the number of keystrokes is not the only metrics. I think the same holds for considering to which extent to adopt auto in C++.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: eXpl0it3r on January 03, 2016, 11:50:41 pm
I tend to agree, in my view this example lies on the border (I had to start the discussion with something...) Have you seen auto i = 0; used in practice (I have)?
I don't think, this is the place for a general discussion about auto, especially if it's just for discussion's sake.
If you're really unsure, which to me doesn't seem like it, then you can read all the existing discussions on the web by various people some better known than others.

Let's not further hijack this thread.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Sanction on January 05, 2016, 12:41:37 am
I just got the book today, skimmed threw it at work. Lots of content and some advance game programming techniques looking forward to going back and following it threw and studding the content.

I didn't like how the code was smushed together, being still a novice I like to see the pattern more clearly, but like I said there was lots of content and you can easily open up an example and see it more clearly.

I really liked how it walked you threw the system / pattern and keep adding to it. So like for the ECS you get a more clear understanding of how the ESC works and later shows you adding more components and systems adding even more.

Overall I'm really excited and I'll be sure to post more :D
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 05, 2016, 03:37:17 pm
I just got the book today, skimmed threw it at work. Lots of content and some advance game programming techniques looking forward to going back and following it threw and studding the content.

I didn't like how the code was smushed together, being still a novice I like to see the pattern more clearly, but like I said there was lots of content and you can easily open up an example and see it more clearly.

I really liked how it walked you threw the system / pattern and keep adding to it. So like for the ECS you get a more clear understanding of how the ESC works and later shows you adding more components and systems adding even more.

Overall I'm really excited and I'll be sure to post more :D
Thanks for showing your support! I hope you enjoy the rest of the book. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: eXpl0it3r on January 06, 2016, 11:34:05 am
Who could say no to a 5 bucks eBook. ;)

I very quickly went a bit over the source code and it looks quite good, even though I don't agree with some of the design decisions.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 06, 2016, 06:36:31 pm
Who could say no to a 5 bucks eBook. ;)

I very quickly went a bit over the source code and it looks quite good, even though I don't agree with some of the design decisions.
I'm glad to hear it's acceptable. Regarding the design choices, I can already imagine what those would be for the most part. :) I hope that doesn't ruin the book for you, and you find something useful in it still. Thanks so much for purchasing it!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: AncientGrief on January 11, 2016, 09:51:11 pm
Hey,

I bought your book a couple of days ago. Working on the Snake chapter atm. Nice to read :) I think using pointers etc. is okay ... I for myself try to avoid them and will exchange your pointers to smart pointers...but I have a question:

The Game class in chapter 2 -> Building the game class has the method
Window* GetWindow();
 

why using a pointer instead of this?:
const Window& GetWindow() const;
//EDIT: the const may be ignored, later on it will be stupid to make it return a const Window...
 


Btw.: I try to be more const correct than the book, but I don't see it as a flaw, since the code is much more readable while learning :) Nice work so far! I also prefer it over the first book so far!

Edit2:
What does the prefix l_ for function parameters stand for?! LValue?!
Snake::Render(sf::RenderWindow& l_window)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 12, 2016, 09:53:34 pm
Hey,

I bought your book a couple of days ago. Working on the Snake chapter atm. Nice to read :) I think using pointers etc. is okay ... I for myself try to avoid them and will exchange your pointers to smart pointers...but I have a question:

The Game class in chapter 2 -> Building the game class has the method
Window* GetWindow();
 

why using a pointer instead of this?:
const Window& GetWindow() const;
//EDIT: the const may be ignored, later on it will be stupid to make it return a const Window...
 


Btw.: I try to be more const correct than the book, but I don't see it as a flaw, since the code is much more readable while learning :) Nice work so far! I also prefer it over the first book so far!

Edit2:
What does the prefix l_ for function parameters stand for?! LValue?!
Snake::Render(sf::RenderWindow& l_window)
Hi! Thanks for purchasing and reading the book! I'm glad you like it so far. :)

For the GetWindow() method, you absolutely could use a reference. It actually makes more sense in most cases, unless nullptr is a valid return value, in which case using a pointer would be best. Regarding const correctness, you're absolutely right. That was actually my intention. Shoving everything into one publication just seemed like too much, not to mention it would cause formatting problems every once in a while.

The "l_" prefix stands for local, meaning the argument is local to the function/method. There are better alternatives to using Hungarian notation though, so take that with a grain of salt.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: eXpl0it3r on January 13, 2016, 02:00:42 am
For the GetWindow() method, you absolutely could use a reference. It actually makes more sense in most cases, assuming nullptr is a valid return value.
Not sure if you meant to say that differently, but nullptr is not a valid return value for a reference of a window.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Hapax on January 13, 2016, 02:49:01 am
The "l_" prefix stands for local, meaning the argument is local to the function/method. There are better alternatives to using Hungarian notation though, so take that with a grain of salt.
Should a parameter know where it comes from?
Not sure which function/method it is local to. The one it's passed to or the one it's passed from?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 13, 2016, 03:18:52 am
For the GetWindow() method, you absolutely could use a reference. It actually makes more sense in most cases, assuming nullptr is a valid return value.
Not sure if you meant to say that differently, but nullptr is not a valid return value for a reference of a window.
Yes, you're right. Sorry, I was replying in a rush. It's fixed now. I did mean that pointers should be used, provided nullptr being returned is a possibility.

The "l_" prefix stands for local, meaning the argument is local to the function/method. There are better alternatives to using Hungarian notation though, so take that with a grain of salt.
Should a parameter know where it comes from?
Not sure which function/method it is local to. The one it's passed to or the one it's passed from?
I agree, it's not widely used and debatably unnecessary. It can be useful if the method/function has a similarly named local variable inside the body somewhere. This, as well as most of the design choices in the book are entirely optional and up to the reader to leave in.
Title: SFML Game Development by Example - 4th SFML book
Post by: eXpl0it3r on January 13, 2016, 03:19:55 am
He meant local as in local scope as in that function body. I personally rather go with prefixing member variables, that way I know that every none prefixed variable is a local one.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Hapax on January 13, 2016, 03:57:11 am
Ah, I get it now. It's so you can tell which one is only available to that function when they are named similarly (I use the member prefix method that eXpl0it3r mentioned).
I think I would probably consider a parameter to be passed from the outside though so "local" for something external seems odd to me. Of course, technically, if it's passed by value, that actual copy is only local but still...
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Mario on January 13, 2016, 09:49:41 am
If the naming confuses you, don't use it. However, you could also just use a different naming scheme, e.g. prefixing params with "a" for "argument".
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: SpeCter on January 13, 2016, 10:29:31 am
For member variables i use the prefix "m_".
For function parameter names I use "t_" .
For local variables I just use no prefix.

But honestly, the only thing I care about is that people are consistent with their naming scheme and stick to it for the whole project.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: AncientGrief on January 13, 2016, 07:23:50 pm
Hi! Thanks for purchasing and reading the book! I'm glad you like it so far. :)

For the GetWindow() method, you absolutely could use a reference. It actually makes more sense in most cases, unless nullptr is a valid return value, in which case using a pointer would be best. Regarding const correctness, you're absolutely right. That was actually my intention. Shoving everything into one publication just seemed like too much, not to mention it would cause formatting problems every once in a while.

The "l_" prefix stands for local, meaning the argument is local to the function/method. There are better alternatives to using Hungarian notation though, so take that with a grain of salt.

Thanks for the clarification :) I'm done with the Chapter "EventManager" now and I really got some new inspirations from this one! Nice work! And btw.:
enum StateType{
    Intro = 1, Intro_MainMenu, MainMenu, Game, MainMenu_Game
    Paused, GameOver, MainMenu_GameOver, Credits, MainMenu_Credits
    ...
    // Crying in the corner.
};
 

I had to laugh :D Love it when a book is not to strictly serious!

Edit: converting the code using smart pointers is not so hard as I first though...but remember: std::move is your friend ... totally forgot about this at first and wondered what the hell is wrong x_X  >:( ;D

Edit2: I am always coding with -Wall compiler flag and encountered some warnings:
   - Some class/struct ctor member intializations are in the wrong order (not in the order of their declaration)
   - LoadBingings() in the EventManager class => int end = keyval.find(delimiter); => changed it to size_t
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Cenobite on January 20, 2016, 09:02:58 pm
The e-book costs €43.54 while the print+ebook costs €44.99. That's strange. I would expect e-book to be significantly cheaper. This book has everything that I would like to learn (well, except a chapter about SFML android development). I am going to buy it, but it's not exactly cheap.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Tank on January 20, 2016, 09:18:03 pm
Cenobite: There might be a discount in a couple of days.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: eXpl0it3r on January 21, 2016, 04:01:22 am
(on the ebook that is, like the rest of the SFML ebooks by Packt)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: seyuup on January 21, 2016, 10:11:06 am
Loving the book so far, however, I've hit a snag.

I'm at the beginning of Chapter 7 and just finished testing the Tile/Mapping classes. The background texture loads, but when I hit the close button or click the "exit" button on the main menu, I receive an exception. I believe the error is occurring because the Game object's deconstructor is called when the window closes, causing my SharedContext object to lose scope.

Thus, other objects that depend on the SharedContext for releasing resources cause an error. Also, the ResourceManager's deconstructor is being called first, so it purges all of the resources before the map can do so itself.

I hope someone will be able to assist me!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Sanction on January 21, 2016, 02:27:17 pm
The e-book costs €43.54 while the print+ebook costs €44.99. That's strange. I would expect e-book to be significantly cheaper. This book has everything that I would like to learn (well, except a chapter about SFML android development). I am going to buy it, but it's not exactly cheap.

I got the eBook for $5.00 :P
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 21, 2016, 06:48:12 pm
Loving the book so far, however, I've hit a snag.

I'm at the beginning of Chapter 7 and just finished testing the Tile/Mapping classes. The background texture loads, but when I hit the close button or click the "exit" button on the main menu, I receive an exception. I believe the error is occurring because the Game object's deconstructor is called when the window closes, causing my SharedContext object to lose scope.

Thus, other objects that depend on the SharedContext for releasing resources cause an error. Also, the ResourceManager's deconstructor is being called first, so it purges all of the resources before the map can do so itself.

I hope someone will be able to assist me!
That's really odd. I just tested it myself, and it seems to be working fine. Please feel free to send me your code through either the PM function on these forums, or directly to my email address: order.nexus.dev@gmail.com. I would be happy to help you out!

Edit: One thing you should check is the order in which data members of the classes are declared. Since they're allocated on the stack, the destruction of these objects will follow in the reverse order of declaration. Make sure to consult the code that came with the book, and if that doesn't work, please feel free to contact me! :)
The e-book costs €43.54 while the print+ebook costs €44.99. That's strange. I would expect e-book to be significantly cheaper. This book has everything that I would like to learn (well, except a chapter about SFML android development). I am going to buy it, but it's not exactly cheap.
The e-book on packtpub.com (http://packtpub.com) is priced at €35.99, while the paperback version + e-book costs €44.99. I'm not sure where you saw that price for just the e-book alone, but it doesn't seem right.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: seyuup on January 21, 2016, 07:07:51 pm
That's really odd. I just tested it myself, and it seems to be working fine. Please feel free to send me your code through either the PM function on these forums, or directly to my email address: order.nexus.dev@gmail.com. I would be happy to help you out!

Edit: One thing you should check is the order in which data members of the classes are declared. Since they're allocated on the stack, the destruction of these objects will follow in the reverse order of declaration. Make sure to consult the code that came with the book, and if that doesn't work, please feel free to contact me! :)

Ahh! You beat me to it! I just figured it out and was about to post it! Hahah! You are correct, it was the order the members were created, such a simple mistake.

Thanks!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 21, 2016, 07:08:50 pm
That's really odd. I just tested it myself, and it seems to be working fine. Please feel free to send me your code through either the PM function on these forums, or directly to my email address: order.nexus.dev@gmail.com. I would be happy to help you out!

Edit: One thing you should check is the order in which data members of the classes are declared. Since they're allocated on the stack, the destruction of these objects will follow in the reverse order of declaration. Make sure to consult the code that came with the book, and if that doesn't work, please feel free to contact me! :)

Ahh! You beat me to it! I just figured it out and was about to post it! Hahah! You are correct, it was the order the members were created, such a simple mistake.

Thanks!
No problem! Thank you so much for reading, and I hope you enjoy the rest of the book! :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: seyuup on January 21, 2016, 07:16:05 pm
Question: What would you say is the method you are using for frame rate? It seems like the game is running with variable time step, is this correct? If it is, I'm curious if a different method is used later in the book. It might just be my computer, but the bouncing mushroom seems to be moving quite variably.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 21, 2016, 07:25:35 pm
Question: What would you say is the method you are using for frame rate? It seems like the game is running with variable time step, is this correct? If it is, I'm curious if a different method is used later in the book. It might just be my computer, but the bouncing mushroom seems to be moving quite variably.
The first project (snake) uses a fixed timestep, unlike the last two that rely on a variable timestep. The first bouncing mushroom example actually wasn't capped or adjusted in any way, and was later used to underline the issue of different execution times between varying systems. It was then adjusted to use delta time in order to run at a constant speed near the end of Chapter 2, so if you noticed that behavior before, you were absolutely correct. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: zmertens on January 26, 2016, 02:09:38 am
This is also the first SFML book to tackle the topic of networking ...

Didn't the first SFML book cover this in the last chapter? Either way the book looks great and interesting!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: zsbzsb on January 26, 2016, 02:15:23 am
Didn't the first SFML book cover this in the last chapter? Either way the book looks great and interesting!

Yes (https://github.com/SFML/SFML-Game-Development-Book/tree/master/10_Network).
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 26, 2016, 05:20:15 am
Didn't the first SFML book cover this in the last chapter? Either way the book looks great and interesting!

Yes (https://github.com/SFML/SFML-Game-Development-Book/tree/master/10_Network).
Up until this point, I haven't actually read any of the previously published SFML books. Before the writing process began, I was told by my editor that the networking subject hasn't been tackled yet, and this would be the first time. I stand corrected. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on February 03, 2016, 10:34:18 pm
EDIT 2: I managed to make it work by starting over again with a fresh C::B project and with modifying the line (added a macro at line 2999) in Basic_string.h again. I didn't try to go further at the moment (chapter 4 works perfectly now) but it should be fine  ;D

Hi,

First of, really nice book ! I'm a total beginner in game development but I'm enjoying it so far :)

However, I'm having trouble compiling with Codeblocks. Everything works fine till chapter 4 (EventManager) but then, I can't seem to make it work. I even tried to download and use the source code (from packt) but same issue.

I managed to solve one of the problem (which was related to the MinGW version, issue with the "stoi" function solved by a little "hack" in the basic_string.h file, took from an answer on stackoverflow), I managed to run the code from chapter 4 but the "Mouse left click + Left shift" didn't work at all despite being the original code (only the mouse left key code appeared when I debugged it with std::cout but not the LShift one)

So my guess is that it comes from C::B or the line I changed on the basic_string.h file (but then I can't compile at all if I reverse it).

I hope you will be able to help me, I really want to start the next project (The scroll platform one)  ;D

EDIT: I didn't mention it but I already read the first book (the one with the aircraft shooter game) and I was able to run it perfectly (with SFML 2.1 at the time, tho) on CodeBlocks
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on February 04, 2016, 01:48:27 am
EDIT 2: I managed to make it work by starting over again with a fresh C::B project and with modifying the line (added a macro at line 2999) in Basic_string.h again. I didn't try to go further at the moment (chapter 4 works perfectly now) but it should be fine  ;D

Hi,

First of, really nice book ! I'm a total beginner in game development but I'm enjoying it so far :)

However, I'm having trouble compiling with Codeblocks. Everything works fine till chapter 4 (EventManager) but then, I can't seem to make it work. I even tried to download and use the source code (from packt) but same issue.

I managed to solve one of the problem (which was related to the MinGW version, issue with the "stoi" function solved by a little "hack" in the basic_string.h file, took from an answer on stackoverflow), I managed to run the code from chapter 4 but the "Mouse left click + Left shift" didn't work at all despite being the original code (only the mouse left key code appeared when I debugged it with std::cout but not the LShift one)

So my guess is that it comes from C::B or the line I changed on the basic_string.h file (but then I can't compile at all if I reverse it).

I hope you will be able to help me, I really want to start the next project (The scroll platform one)  ;D

EDIT: I didn't mention it but I already read the first book (the one with the aircraft shooter game) and I was able to run it perfectly (with SFML 2.1 at the time, tho) on CodeBlocks
Hello! First of all, thank you so much for showing support and purchasing the book! I hope you enjoy it the rest of the way :)

The shift key problem you're experiencing is a result of tiny changes between SFML versions. The sf::Keyboard::Key enum values are different after version 2.1, so you have to edit the "keys.cfg" file, specifically the "Move 9:0 24:38" line, and change the number 38 to whatever numerical index the LShift key happens to fall under in 2.1.

Please let me know if you have any more problems on the way!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on February 07, 2016, 11:38:16 pm
EDIT 2: I managed to make it work by starting over again with a fresh C::B project and with modifying the line (added a macro at line 2999) in Basic_string.h again. I didn't try to go further at the moment (chapter 4 works perfectly now) but it should be fine  ;D

Hi,

First of, really nice book ! I'm a total beginner in game development but I'm enjoying it so far :)

However, I'm having trouble compiling with Codeblocks. Everything works fine till chapter 4 (EventManager) but then, I can't seem to make it work. I even tried to download and use the source code (from packt) but same issue.

I managed to solve one of the problem (which was related to the MinGW version, issue with the "stoi" function solved by a little "hack" in the basic_string.h file, took from an answer on stackoverflow), I managed to run the code from chapter 4 but the "Mouse left click + Left shift" didn't work at all despite being the original code (only the mouse left key code appeared when I debugged it with std::cout but not the LShift one)

So my guess is that it comes from C::B or the line I changed on the basic_string.h file (but then I can't compile at all if I reverse it).

I hope you will be able to help me, I really want to start the next project (The scroll platform one)  ;D

EDIT: I didn't mention it but I already read the first book (the one with the aircraft shooter game) and I was able to run it perfectly (with SFML 2.1 at the time, tho) on CodeBlocks
Hello! First of all, thank you so much for showing support and purchasing the book! I hope you enjoy it the rest of the way :)

The shift key problem you're experiencing is a result of tiny changes between SFML versions. The sf::Keyboard::Key enum values are different after version 2.1, so you have to edit the "keys.cfg" file, specifically the "Move 9:0 24:38" line, and change the number 38 to whatever numerical index the LShift key happens to fall under in 2.1.

Please let me know if you have any more problems on the way!

I'm done writing the code for chapter 5 but I have a problem with the "unordered_map", it says that the "emplace" and "find" methods does not exists and it redirect me to hashtable_policy.h at line 85 (noexcept(declval<const _Hash&>()(declval<const _Key&>()))>).

I searched a little bit on stackoverflow and it might be a problem with C++11, however I have enabled C++11 in build options. I'm using Codeblocks (16.01). Any idea ? (I also tried to run the original code with no success)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on February 08, 2016, 12:01:59 am
EDIT 2: I managed to make it work by starting over again with a fresh C::B project and with modifying the line (added a macro at line 2999) in Basic_string.h again. I didn't try to go further at the moment (chapter 4 works perfectly now) but it should be fine  ;D

Hi,

First of, really nice book ! I'm a total beginner in game development but I'm enjoying it so far :)

However, I'm having trouble compiling with Codeblocks. Everything works fine till chapter 4 (EventManager) but then, I can't seem to make it work. I even tried to download and use the source code (from packt) but same issue.

I managed to solve one of the problem (which was related to the MinGW version, issue with the "stoi" function solved by a little "hack" in the basic_string.h file, took from an answer on stackoverflow), I managed to run the code from chapter 4 but the "Mouse left click + Left shift" didn't work at all despite being the original code (only the mouse left key code appeared when I debugged it with std::cout but not the LShift one)

So my guess is that it comes from C::B or the line I changed on the basic_string.h file (but then I can't compile at all if I reverse it).

I hope you will be able to help me, I really want to start the next project (The scroll platform one)  ;D

EDIT: I didn't mention it but I already read the first book (the one with the aircraft shooter game) and I was able to run it perfectly (with SFML 2.1 at the time, tho) on CodeBlocks
Hello! First of all, thank you so much for showing support and purchasing the book! I hope you enjoy it the rest of the way :)

The shift key problem you're experiencing is a result of tiny changes between SFML versions. The sf::Keyboard::Key enum values are different after version 2.1, so you have to edit the "keys.cfg" file, specifically the "Move 9:0 24:38" line, and change the number 38 to whatever numerical index the LShift key happens to fall under in 2.1.

Please let me know if you have any more problems on the way!

I'm done writing the code for chapter 5 but I have a problem with the "unordered_map", it says that the "emplace" and "find" methods does not exists and it redirect me to hashtable_policy.h at line 85 (noexcept(declval<const _Hash&>()(declval<const _Key&>()))>).

I searched a little bit on stackoverflow and it might be a problem with C++11, however I have enabled C++11 in build options. I'm using Codeblocks (16.01). Any idea ? (I also tried to run the original code with no success)
I believe this may be related to Code Blocks not knowing how to hash a particular data type, since it's the key in an unordered_map. VS doesn't require you to do this, but Code Blocks might. I know for sure this problem occurs when compiling code for linux using gcc. What you can do is provide a way for the map to hash custom data types as the third argument. You can do it by using this code:
struct CustomHash
{
    template <typename T>
    std::size_t operator()(T t) const
    {
        return static_cast<std::size_t>(t);
    }
};
You can stick this in a new header file. When defining data types that use unordered_map with custom keys, make sure you provide a third argument like so:
using StateFactory = std::unordered_map<StateType, std::function<BaseState*(void)>, CustomHash>;

Give it a try!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on February 08, 2016, 06:48:51 pm
I'm done writing the code for chapter 5 but I have a problem with the "unordered_map", it says that the "emplace" and "find" methods does not exists and it redirect me to hashtable_policy.h at line 85 (noexcept(declval<const _Hash&>()(declval<const _Key&>()))>).

I searched a little bit on stackoverflow and it might be a problem with C++11, however I have enabled C++11 in build options. I'm using Codeblocks (16.01). Any idea ? (I also tried to run the original code with no success)
I believe this may be related to Code Blocks not knowing how to hash a particular data type, since it's the key in an unordered_map. VS doesn't require you to do this, but Code Blocks might. I know for sure this problem occurs when compiling code for linux using gcc. What you can do is provide a way for the map to hash custom data types as the third argument. You can do it by using this code:
struct CustomHash
{
    template <typename T>
    std::size_t operator()(T t) const
    {
        return static_cast<std::size_t>(t);
    }
};
You can stick this in a new header file. When defining data types that use unordered_map with custom keys, make sure you provide a third argument like so:
using StateFactory = std::unordered_map<StateType, std::function<BaseState*(void)>, CustomHash>;

Give it a try!
Thank you for the nice customer support  ;D I tried to add your piece of code but there is a problem with the loadBindings() function:
Code: [Select]
CustomHash.hpp|9|error: invalid static_cast from type 'std::basic_string<char>' to type 'std::size_t {aka unsigned int}'|
Do I have to use "std::make_tuple" for both "find" and "emplace" methods in order to add the "CustomHash" argument or I don't have to touch them ? The question is more related to C++ than SFML/Your book tho
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on February 08, 2016, 07:20:33 pm
I'm done writing the code for chapter 5 but I have a problem with the "unordered_map", it says that the "emplace" and "find" methods does not exists and it redirect me to hashtable_policy.h at line 85 (noexcept(declval<const _Hash&>()(declval<const _Key&>()))>).

I searched a little bit on stackoverflow and it might be a problem with C++11, however I have enabled C++11 in build options. I'm using Codeblocks (16.01). Any idea ? (I also tried to run the original code with no success)
I believe this may be related to Code Blocks not knowing how to hash a particular data type, since it's the key in an unordered_map. VS doesn't require you to do this, but Code Blocks might. I know for sure this problem occurs when compiling code for linux using gcc. What you can do is provide a way for the map to hash custom data types as the third argument. You can do it by using this code:
struct CustomHash
{
    template <typename T>
    std::size_t operator()(T t) const
    {
        return static_cast<std::size_t>(t);
    }
};
You can stick this in a new header file. When defining data types that use unordered_map with custom keys, make sure you provide a third argument like so:
using StateFactory = std::unordered_map<StateType, std::function<BaseState*(void)>, CustomHash>;

Give it a try!
Thank you for the nice customer support  ;D I tried to add your piece of code but there is a problem with the loadBindings() function:
Code: [Select]
CustomHash.hpp|9|error: invalid static_cast from type 'std::basic_string<char>' to type 'std::size_t {aka unsigned int}'|
Do I have to use "std::make_tuple" for both "find" and "emplace" methods in order to add the "CustomHash" argument or I don't have to touch them ? The question is more related to C++ than SFML/Your book tho
std::string should be hashable by default, if I'm not mistaken, so you don't need to provide the third argument for the binding container. You only need to do that with non-fundamental data types, such as "enum class" or anything else you might use as the key. It's also fair to point out that the CustomHash posted above works only with types that can be statically cast to std::size_t (unsigned integer). The binding container's key is a string, so that would require a different approach. Hope this helps :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on February 08, 2016, 07:42:21 pm
I'm done writing the code for chapter 5 but I have a problem with the "unordered_map", it says that the "emplace" and "find" methods does not exists and it redirect me to hashtable_policy.h at line 85 (noexcept(declval<const _Hash&>()(declval<const _Key&>()))>).

I searched a little bit on stackoverflow and it might be a problem with C++11, however I have enabled C++11 in build options. I'm using Codeblocks (16.01). Any idea ? (I also tried to run the original code with no success)
I believe this may be related to Code Blocks not knowing how to hash a particular data type, since it's the key in an unordered_map. VS doesn't require you to do this, but Code Blocks might. I know for sure this problem occurs when compiling code for linux using gcc. What you can do is provide a way for the map to hash custom data types as the third argument. You can do it by using this code:
struct CustomHash
{
    template <typename T>
    std::size_t operator()(T t) const
    {
        return static_cast<std::size_t>(t);
    }
};
You can stick this in a new header file. When defining data types that use unordered_map with custom keys, make sure you provide a third argument like so:
using StateFactory = std::unordered_map<StateType, std::function<BaseState*(void)>, CustomHash>;

Give it a try!
Thank you for the nice customer support  ;D I tried to add your piece of code but there is a problem with the loadBindings() function:
Code: [Select]
CustomHash.hpp|9|error: invalid static_cast from type 'std::basic_string<char>' to type 'std::size_t {aka unsigned int}'|
Do I have to use "std::make_tuple" for both "find" and "emplace" methods in order to add the "CustomHash" argument or I don't have to touch them ? The question is more related to C++ than SFML/Your book tho
std::string should be hashable by default, if I'm not mistaken, so you don't need to provide the third argument for the binding container. You only need to do that with non-fundamental data types, such as "enum class" or anything else you might use as the key. It's also fair to point out that the CustomHash posted above works only with types that can be statically cast to std::size_t (unsigned integer). The binding container's key is a string, so that would require a different approach. Hope this helps :)

Thanks, it worked ! I just added CustomHash to unordered_maps that used "StateType" (well, that was exactly what you said earlier, but I thought I had to add it to every unordered_map container for some reason..) and everything runs perfectly  :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: eXpl0it3r on February 09, 2016, 10:24:06 am
Please refrain from full quotes. It's unnecessary and clutters the thread, plus this is really ugly...

(http://i.imgur.com/y0qamH7.png)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: seyuup on February 09, 2016, 07:35:25 pm
The first project (snake) uses a fixed timestep, unlike the last two that rely on a variable timestep. The first bouncing mushroom example actually wasn't capped or adjusted in any way, and was later used to underline the issue of different execution times between varying systems. It was then adjusted to use delta time in order to run at a constant speed near the end of Chapter 2, so if you noticed that behavior before, you were absolutely correct. :)
So, the platformer game and the RPG-styled game both run in variable timestep, correct? I ask because I'm currently trying to make a platformer game following your example. Could you explain your reason for using a variable timestep method for your platformer example over the other methods (fixed timestep, minimum timestep)?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on February 10, 2016, 05:03:27 pm
The first project (snake) uses a fixed timestep, unlike the last two that rely on a variable timestep. The first bouncing mushroom example actually wasn't capped or adjusted in any way, and was later used to underline the issue of different execution times between varying systems. It was then adjusted to use delta time in order to run at a constant speed near the end of Chapter 2, so if you noticed that behavior before, you were absolutely correct. :)
So, the platformer game and the RPG-styled game both run in variable timestep, correct? I ask because I'm currently trying to make a platformer game following your example. Could you explain your reason for using a variable timestep method for your platformer example over the other methods (fixed timestep, minimum timestep)?
Correct. The main reason behind using variable time-step is performance. Using a fixed time-step across multiple machines would produce different results. Variable time-step allows the simulation to remain the same, even if the application is running at a lower framerate.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: eXpl0it3r on February 10, 2016, 05:33:13 pm


Using a fixed time-step across multiple machines would produce different results. Variable time-step allows the simulation to remain the same, even if the application is running at a lower framerate.
Then you misunderstood the concept, because it's the other way around. A fixed time step provides a consistent time frame for the simulation across any machine. If one machine has a weaker CPU the simulation will run the same, but the FPS might drop.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on February 10, 2016, 06:25:57 pm
Then you misunderstood the concept, because it's the other way around. A fixed time step provides a consistent time frame for the simulation across any machine. If one machine has a weaker CPU the simulation will run the same, but the FPS might drop.
What I meant was that FPS is directly tied to the simulation in a case of a variable time-step. If it goes down, the simulation will be advanced just that much more in between the frames, which would produce consistent results across different hardware. Depending on your fixed time-step implementation and setup, you may get slightly different results on different machines (ex. 2 updates per frame, then 3, then 2 again), assuming the frame time is still being accumulated and used to determine how many updates should take place in case of lag. I've also seen games that do not accumulate the frame-time at all, in which case the simulation is entirely dependent on the hardware it's being executed on.

While the variable time-step may not be ideal for physics simulations, it can keep the results slightly more consistent. That's not to say it doesn't have problems of its own, of course.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Jesper Juhl on February 10, 2016, 06:36:01 pm
Read this: Fix Your Timestep! (http://gafferongames.com/game-physics/fix-your-timestep/)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on February 10, 2016, 06:39:42 pm
Read this: Fix Your Timestep! (http://gafferongames.com/game-physics/fix-your-timestep/)
I have. Like I said, the results depend heavily on the implementation. It's a good resource to reference though :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Hapax on February 10, 2016, 10:58:40 pm
Read this: Fix Your Timestep! (http://gafferongames.com/game-physics/fix-your-timestep/)
I have. Like I said, the results depend heavily on the implementation. It's a good resource to reference though :)
The "fixed time step" that people are (I hope) referring to is the one seen in the part of that article labelled "Free The Physics" (not "Fixed Delta Time"). This creates a time-step that is fixed and regular which effectively means that you always use the same time-step and the results are the same on all machines (and is identically repeatable).
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: seyuup on February 11, 2016, 01:51:20 am
The "fixed time step" that people are (I hope) referring to is the one seen in the part of that article labelled "Free The Physics" (not "Fixed Delta Time"). This creates a time-step that is fixed and regular which effectively means that you always use the same time-step and the results are the same on all machines (and is identically repeatable).
Would this (fixed time step) not be the preferred method of choice for all applications? For a simple platformer game like Super Mario Bros. would this method be the ideal? I may be misunderstanding, as I am new to certain aspects of game development.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Hapax on February 11, 2016, 05:04:32 am
The fixed time-step described in "Free The Physics" would indeed be ideal for all applications. It helps to secure the reliability of your logic and physics.
If you would like a small library to help with using this (or just to help visualise what's going on), feel free to have a look at my Timestep (https://github.com/Hapaxia/Kairos/wiki/Timestep) class in my Kairos timing library (https://github.com/Hapaxia/Kairos/wiki).
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: nicox11 on March 04, 2016, 03:10:06 pm
Interesting book. It is good for theory that the last book didn't cover like the Entity Component System, the Event and Messages delivery between system and the network. But, the implementation is quite huge and really hard to follow, it would be much better focusing on detailed examples instead of a full compilable project (that's my opinion).

On the other hand, it seams less modern than the previous book, not always using modern feature (Still raw pointer, i don't really know why). For example the tilemapping system doesn't use vertex, but even the Laurent's tutorial demonstrate how to gain perfomance with it.

To conclude, it's for me a great book to go further after the previous one and try to elaborate greater architectures, but only try to follow the architecture instead of the code presented.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: seyuup on April 04, 2016, 10:39:06 pm
Is there a reason why when falling vertically past the maximum map height, the map will be recreated (tiles will be placed) except for the leftmost tiles?

I assume it has to do with the tile map variable within the Map class.

I'm sorry if the description did not make sense. I'll try to provide pictures when I can.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on April 05, 2016, 03:51:09 pm
Is there a reason why when falling vertically past the maximum map height, the map will be recreated (tiles will be placed) except for the leftmost tiles?

I assume it has to do with the tile map variable within the Map class.

I'm sorry if the description did not make sense. I'll try to provide pictures when I can.

The player should die if they fall outside the boundaries of the map, and get respawned at the beginning shortly. The console will print out a message every time that happens. Assuming this check is taken out, the map being repeated would have to do with the way tile indexes are represented in the tile container.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: FloatPeasant on April 11, 2016, 10:52:13 pm
is the ebook on packtpub different from the one on playstore?
on packtpub it says 44.98€ for the ebook and 44.99 for printed + ebook?
google play store basically has it for half the price.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on April 11, 2016, 11:11:58 pm
is the ebook on packtpub different from the one on playstore?
on packtpub it says 44.98€ for the ebook and 44.99 for printed + ebook?
google play store basically has it for half the price.
I don't think it is. Try switching the prices on packtpub to US dollars. For me, it currently states that the e-book is $39.99 and the print + ebook is $49.99. Either way, I highly doubt that any content would be stripped from the copy on playstore.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: FloatPeasant on April 11, 2016, 11:41:57 pm
still says 49.98$ for just the ebook, on the other hand it would be pretty sweet to have a printed copy.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: eXpl0it3r on April 12, 2016, 12:19:12 am
Don't forget that for the SFML eBook from Packt you can use the promo code from the Learn page (http://www.sfml-dev.org/learn.php) to get 50% off.

But lol what the heck is this? The print + ebook is €22.50 and the ebook by itself is €35.99, what is going on there? ;D
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on April 12, 2016, 12:57:45 am
That's really weird. It doesn't do that on my end at all, no matter which currency is selected. Either way, Amazon also offers both versions of the book, so you could check that out as well:

http://www.amazon.com/SFML-Development-Example-Raimondas-Pupius-ebook/dp/B01061QAH4/ref=tmm_kin_swatch_0?_encoding=UTF8&qid=&sr= (http://www.amazon.com/SFML-Development-Example-Raimondas-Pupius-ebook/dp/B01061QAH4/ref=tmm_kin_swatch_0?_encoding=UTF8&qid=&sr=)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: FloatPeasant on April 12, 2016, 04:42:06 pm
Are we allowed to use the code in the examples however we want or is it just for training?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on April 12, 2016, 04:46:45 pm
Are we allowed to use the code in the examples however we want or is it just for training?
Feel free to use it in whatever manner you choose. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: FloatPeasant on April 13, 2016, 09:04:57 pm
Very happy to hear, bought the book hopefully i learn some useful stuff   :D
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: first_sputnik on May 06, 2016, 10:40:35 pm
Can I use this book as my first SFML book? Or should I start with another one?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on May 07, 2016, 06:50:42 pm
Can I use this book as my first SFML book? Or should I start with another one?
The book does start off explaining all of the fundamentals. It is also extremely verbose as far as code examples go, so I would say yes. Just make sure you have a decent amount of C++ experience. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: first_sputnik on May 08, 2016, 04:47:53 am
The book does start off explaining all of the fundamentals. It is also extremely verbose as far as code examples go, so I would say yes. Just make sure you have a decent amount of C++ experience. :)

Thank you sir!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: northLynx on June 19, 2016, 02:31:57 am
I am on the third chapter of the book and followed the code from the book to make the snake game. Right when I call the render functions for the snake and world I realized that that whats passed into the function is not a function that the book made me created. The function is called GetRenderWindow() and its called like *m_window.GetRenderWindow() and passed into the render function like that as well. I checked the chapter again to see if I missed it but I dont see it. Is it something that I need to make because GetRenderWindow is not a function either for the window class.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on June 19, 2016, 04:44:34 pm
I am on the third chapter of the book and followed the code from the book to make the snake game. Right when I call the render functions for the snake and world I realized that that whats passed into the function is not a function that the book made me created. The function is called GetRenderWindow() and its called like *m_window.GetRenderWindow() and passed into the render function like that as well. I checked the chapter again to see if I missed it but I dont see it. Is it something that I need to make because GetRenderWindow is not a function either for the window class.

Oh, I'm so sorry about that. Perhaps an older version of the code has made it into production somehow. Anyway, it's just a simple getter that returns a pointer to the sf::RenderWindow like this:
sf::RenderWindow* Window::GetRenderWindow() { return &m_window; }
Please add that in to the Window class (don't forget to declare it in the header as well), and let me know if it works. Thanks for the feedback! :)

Edit: Come to think of it, it may have even been emitted in order to save some space as well, along with a few other setter/getter methods. Either way, the code files of the book contain everything you will need. Nothing is left out there. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: northLynx on June 19, 2016, 07:23:13 pm
Yes that did the trick! Now I am getting an error with the float timestep variable the book created. I compared the m_elapsed sf::Time variable I created from chapter 2 and I am assuming the book says that you need to compare that with the float timestep,but it is giving me an error. Is it suppose to give me an error?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on June 19, 2016, 08:23:38 pm
Yes that did the trick! Now I am getting an error with the float timestep variable the book created. I compared the m_elapsed sf::Time variable I created from chapter 2 and I am assuming the book says that you need to compare that with the float timestep,but it is giving me an error. Is it suppose to give me an error?
The m_elapsed data member should be a float, not sf::Time. That's why it gets compared to another float.
class Game{
...
private:
        ...
        float m_elapsed; // <---
        ...
};
The way it's manipulated is by using the .asSeconds() method of sf::Time when time is being added:
void Game::RestartClock(){ m_elapsed += m_clock.restart().asSeconds(); }
It sounds like you have something mixed up, but it's not the end of the world. You can either adjust your code so that the m_elapsed data member is a floating point number, or simply use .asSeconds() to retrieve a float value from sf::Time. Hope that clears it up a little. If you're still having problems, feel free to send me a PM with your code attached (preferably on pastebin). I will take a look at it and help you out more.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: northLynx on June 26, 2016, 06:19:03 am
I got to the chapter 4 and now I am having a problem with one of the functions of the eventmanager. I call setfocus in window.cpp but I realized the book never implemented it. Should I know how to implement it? Also, the same with the void togglefullscreen function that was introduced as well in chapter 4.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on June 26, 2016, 06:52:51 pm
I got to the chapter 4 and now I am having a problem with one of the functions of the eventmanager. I call setfocus in window.cpp but I realized the book never implemented it. Should I know how to implement it? Also, the same with the void togglefullscreen function that was introduced as well in chapter 4.
Sorry about that. If it was emitted in the chapter for whatever reason, you can still find it in the code files that came with the book.
The SetFocus method is actually really simple. All it does is reset a boolean inside the class:
void EventManager::SetFocus(bool l_focus){ m_hasFocus = l_focus; }
ToggleFullscreen method just flips its own boolean that holds the full-screen state, then destroys and re-creates the window:
void Window::ToggleFullscreen(EventDetails* l_details){
        m_isFullscreen = !m_isFullscreen;
        m_window.close();
        Create();
}
Once again, please consult the code files that came with the book, as it should all be included in there. Hope this helps.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: GameBear on July 04, 2016, 02:13:55 pm
Just got the book in by mail :)

Thanks a lot, looks good so far... just finished Chapter 2.
I'll admit, I've read other C++ books before, also on game creation, This one has its cons and pros if you ask me.

Chapter 1:
Pro:
Easy and straight forward, if you know your way around VC.
Con:
The setting up could use more attention to detail (page 5: Where do you put what in? C++/Linker and so far) the way it is now, you could just as well write a link to the SFML tutorial and a list over what to include.

Chapter 2:
Pro:
Fast intro to the "meat of stuff" and nice not to do 3 different "hello world" examples for once.
Con:
The code is still so short here that it could be include fully. leaving out " #include "SFML/Graphics.h"  "on page 20 & page 25, as well as cutting the Game Class Cpp and header down seems pointless to me.
All it did was letting me get more familiar with the error output window in VC


When all that is all said and done, i really liked the book so far and look forward to see what it will bring me.

Thanks for making it :)


-EDIT-

on to chapter 3:
*m_window.GetRenderWindow();

This function is required on page 55. it is not mentioned in the book.
A bit of hacking later and i have a solution:

in Window.h as a public function:

sf::RenderWindow* GetRenderWindow();

and in Window.cpp

sf::RenderWindow* Window::getRenderWindow() {
   return &m_window;
}


This works.

*Please note, the things i write is not meant to put you down from the book,its a first edition, i realize that and its still awesome. I hope to see a second edition with the different typos and left outs corrected.
Still awesome and keep it up.. also glad to see you interact with your readers :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 05, 2016, 06:16:23 pm
Thanks a lot for buying it! Yes, one of the most common things people like to bring up about it is the fact that some snippets of code are left out. It's what I had to do during the final draft stage, due to page count limitations. It may not seem like much, but those lines really do start adding up. If I have a chance to fix it up, I will do so in the next edition, as you said. :) The code you brought up in Chapter 3 has already been addressed, by the way. On this very page, northLynx was posting about having the same issue. Keep in mind that if you ever notice missing code pieces from the book, that means they were most likely simple setter/getter methods/functions. You can always consult the code files that came with the book in order to see the complete version with everything intact. Also, I will be watching this thread constantly, so if you have any additional questions, feel free to either shoot me a PM, or simply post here. I will do my best to address your concerns.

Once again, thank you so much for reading, and I hope the rest of it goes smoothly! Keep in touch if you have any more questions.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: GameBear on July 06, 2016, 03:55:01 pm
Thanks for the reply.

:) ah yes, i see it up there, and glad to see the solution was the same as mine:) (I'll be honest, i did only read the first 4 pages of the thread :)

About the snippets of code. well I do hope you get the chance to edit it in, or at least mention that setters/getters are left out, so that people will know that before hand... adding them will make the book more "beginner friendly" but then again, your target audience doe not seem to be the absolute beginner :)

one thing i was wondering.

in chapter 3, you have this piece of code:

Quote
void Snake::Extend() {
   if (m_snakeBody.empty()) { return; }
   SnakeSegment& tail_head = m_snakeBody[m_snakeBody.size() - 1];

   if (m_snakeBody.size() < 1) {
      SnakeSegment& tail_bone = m_snakeBody[m_snakeBody.size() - 2];
      if (tail_head.position.x == tail_bone.position.x) {
         if (tail_head.position.y == tail_bone.position.y) {
            m_snakeBody.push_back(SnakeSegment(tail_head.position.x, tail_head.position.y + 1));
         }
         else {
            m_snakeBody.push_back(SnakeSegment(tail_head.position.x, tail_head.position.y - 1));
         }
      }
      else if (tail_head.position.y == tail_bone.position.y) {
         if (tail_head.position.x > tail_bone.position.x) {
            m_snakeBody.push_back(SnakeSegment(tail_head.position.x + 1, tail_head.position.y));
         }
         else {
            m_snakeBody.push_back(SnakeSegment(tail_head.position.x - 1, tail_head.position.y));
         }
      }
   }
   else {
      if (m_dir == Direction::Up) {
         m_snakeBody.push_back(SnakeSegment(tail_head.position.x, tail_head.position.y + 1));
      }
      else if (m_dir == Direction::Down) {
         m_snakeBody.push_back(SnakeSegment(tail_head.position.x, tail_head.position.y - 1));
      }
      else if (m_dir == Direction::Left) {
         m_snakeBody.push_back(SnakeSegment(tail_head.position.x+1, tail_head.position.y));
      }
      else if (m_dir == Direction::Right) {
         m_snakeBody.push_back(SnakeSegment(tail_head.position.x-1, tail_head.position.y));
      }
   }
}

While its a nice little algorithm, and nice way of explaining how to find direction from two "objects" i do not see the point of it.

As the game is made i cant see there ever being a time where you are only 1 segment long (reset makes us 3 long) and since we move in tiles, i dont see why you place the new segment behind the last one.
I'd just do something like this:

Quote
void Snake::Extend() {
   int i = m_snakeBody.size();
   m_snakeBody.push_back(SnakeSegment(m_snakeBody[i ].x,m_snakeBody[i ].y));
}
This will place the new segment on top of the last one, allowing it to "pop out" whenever the snake moves next.

of course, the other way teaches us more, but seems a bit overkill for its functionality...

or am i lost here?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 06, 2016, 07:42:51 pm
You are absolutely correct. However, in order for your code to work, you need to make sure you subtract one from the size of the container:
void Snake::Extend(){
        if (m_snakeBody.empty()){ return; }

        size_t last = m_snakeBody.size() - 1;
        m_snakeBody.push_back(SnakeSegment(
                m_snakeBody[last].position.x, m_snakeBody[last].position.y));
}
It's still a good idea to leave the empty container check in.

The longer segment of the code was intended to more clearly illustrate how the pieces would get positioned in space. I think I was leaning towards taking that out at some point, but I decided to leave it in at the last minute, because I thought it made the positioning more clear. I guess, since you picked up on it, I was at least partially right. :D
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: GameBear on July 06, 2016, 08:19:30 pm
Ah yes, my suspicion was correct.
And while it is "unnecessary" in this regard, it is as you said a nice way to illustrate how to get a direction, I can see this used for multiple things, (fire back port weapons?)

and oh yea, i did not implement the code, but i see what you mean about the size-1, i always forget that i returns from 1+ and not 0+ as normal counting :)

any ways, still reading and glad to read it all :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 06, 2016, 08:29:37 pm
Ah yes, my suspicion was correct.
And while it is "unnecessary" in this regard, it is as you said a nice way to illustrate how to get a direction, I can see this used for multiple things, (fire back port weapons?)

and oh yea, i did not implement the code, but i see what you mean about the size-1, i always forget that i returns from 1+ and not 0+ as normal counting :)

any ways, still reading and glad to read it all :)
It's an honest mistake. Happens to the best of us, trust me. *cough* Mars Climate Orbiter *cough*.
Either way, please let me know if you have any further concerns, and happy reading! :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: BM on July 16, 2016, 09:05:15 pm
I've slowly been going over the book and it's been a great help understanding the inner workings of a game. I'm on chapter 5 now at the state manager part, I'm stuck and I can't figure out what's wrong. When I write the constructor for the statemanager class (p100) :

StateManager::StateManager(SharedContext* l_shared)
 : m_shared(l_shared)
{
 RegisterState<State_Intro>(StateType::Intro);
 RegisterState<State_MainMenu>(StateType::MainMenu);
 RegisterState<State_Game>(StateType::Game);
 RegisterState<State_Paused>(StateType::Paused);
}

the compiler doesn't recognize the RegisterState method or any of the <State_***> arguments (which I'm not sure what they're supposed to be at this point, different state classes?). As in the book, I've implemented the RegisterState method in the StateManager header as follow :

template<class T>
void RegisterState(const StateType& type)
{
        m_stateFactory[type] = [this]() -> BaseState*
        {
                return new T(this);
        }
};
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 16, 2016, 09:20:42 pm
You're right, they are different state classes. You could include them in the StateManager.h file, or even in the .cpp, since the class definition itself doesn't rely on them. The first state "Intro" will be covered on page 110, and will be followed by the rest. For now, you can simply comment those RegisterState<...>(...) lines out, but remember to add them back in once the states are created.

It's odd that the compiler doesn't recognize the RegisterState method itself. Make sure it's defined in the StateManager.h file, inside the class as a member function like so:
class StateManager{
public:
  ...
private:
  ...
  template<class T>
  void RegisterState(const StateType& l_type){
    m_stateFactory[l_type] = [this]() -> BaseState*
    {
      return new T(this);
    };
  }
  ...
};
If the problem still persists, please feel free to paste in the errors you're getting. Good luck! :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: BM on July 16, 2016, 09:35:54 pm
You're right, they are different state classes. You could include them in the StateManager.h file, or even in the .cpp, since the class definition itself doesn't rely on them. The first state "Intro" will be covered on page 110, and will be followed by the rest. For now, you can simply comment those RegisterState<...>(...) lines out, but remember to add them back in once the states are created.

If the problem still persists, please feel free to paste in the errors you're getting. Good luck! :)

I figured it out just as you answered. What threw me off is that on page 110, just before "creating the intro state" section, it says the code should compile to give a black screen. Since it didn't work, I thought that I'd try to get that black screen before continuing on. The good news is that I have another problem!

Still in the state manager, in the SwitchTo method this time. The very first line calls the SetCurrentState method from the event manager class. On p.104, it says the SetCurrentState method will be covered shortly but I can't seem to find it, even by searching the entire document with ctr+f and "SetCurrentState".
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 16, 2016, 09:39:26 pm
Odd. It may have been taken out, because it's a simple one-liner:
void EventManager::SetCurrentState(StateType l_state){ m_currentState = l_state; }
Sorry about that. Hope this helps!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: BM on July 16, 2016, 09:59:10 pm
Odd. It may have been taken out, because it's a simple one-liner:
void EventManager::SetCurrentState(StateType l_state){ m_currentState = l_state; }
Sorry about that. Hope this helps!

Ah yea, I was thinking it would be only one line like that.

I still have an error, hopefully the last one before I can get the fabled black screen. On p.109, in the constructor for the game class
Game::Game(): m_window("Chapter 5", sf::Vector2u(800, 600)), m_stateManager(&m_context)

The compiler tells me that m_context is undefined. If I look at the state manager header, there's no m_context member variable either. Is it a typo for
SharedContext* m_shared;
or is it something else?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 16, 2016, 10:02:27 pm
Yes, the data member should be:
SharedContext m_context;
It's really weird, because I checked my code submissions, and it's correct there. It must've been "flubbed" during the final stages of the editing process somehow. My apologies.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: BM on July 16, 2016, 10:15:33 pm
Yes, the data member should be:
SharedContext m_context;
It's really weird, because I checked my code submissions, and it's correct there. It must've been "flubbed" during the final stages of the editing process somehow. My apologies.

No worry, it's still immensively helpful.

I've changed all the instances of m_shared to m_context but I still get the m_context is undefined in the game constructor. Do you have any idea as to what might be the problem here?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 16, 2016, 10:17:43 pm
Did you include it in the Game.h header?
#include "SharedContext.h"
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: BM on July 16, 2016, 10:27:32 pm
I don't have a SharedContext.h file. I've defined 
struct SharedContext
{
        SharedContext() : m_wind(nullptr), m_eventManager(nullptr) {}
        Window* m_wind;
        EventManager* m_eventManager;
};

in the BaseState header. Even if I include BaseState.h, the m_context variable stays undefined.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 16, 2016, 10:36:12 pm
Your definition of the SharedContext structure is fine. Move it to SharedContext.h file though. It will be used in many more places later on, and you don't want it sitting inside the BaseState header.

Aside from that, make sure that the SharedContext.h header file is included in the StateManager.h header as well. Try to compile it and paste the error it gives you if it doesn't work.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: BM on July 16, 2016, 10:48:15 pm
This is the error I get :

1>c:\c_fun\sfml_5_1\sfml_5_1\game.cpp(9): error C2065: 'm_context': undeclared identifier

that line is  :
Game::Game() : m_window("Chapter 5", sf::Vector2u(800,600)), m_stateManager(&m_context)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 16, 2016, 10:55:38 pm
Can you pastebin your StateManager.h and Game.h files? At this point it looks like you're not defining the m_context data member inside the Game class.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: BM on July 16, 2016, 11:06:34 pm
This is Game.h : http://pastebin.com/0D7UuAy5
and the StateManager.h : http://pastebin.com/PpsnL6Kc

You're right, there is no m_context defined in game.h.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 16, 2016, 11:08:57 pm
This is Game.h : http://pastebin.com/0D7UuAy5
and the StateManager.h : http://pastebin.com/PpsnL6Kc

You're right, there is no m_context defined in game.h.
That's the problem. You need to define a SharedContext data member inside the Game class like so:
class Game{
public:
        ...
private:
        SharedContext m_context;
        ...
};
Can't manipulate or pass in members that don't exist. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: BM on July 16, 2016, 11:15:03 pm
Sounds logical ! But it wasn't written in the book to add it.

Finaly managed to get that black screen! Thanks a lot.

I'll probably be back sooner than later for more questions!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 16, 2016, 11:16:53 pm
Sounds logical ! But it wasn't written in the book to add it.

Finaly managed to get that black screen! Thanks a lot.

I'll probably be back sooner than later for more questions!
I'll make sure to fix that, should the publishers ever allow me to do a second edition. Either way, I'm happy to help! Hope you're enjoying the book so far, albeit with minor hiccups. Thanks for reading! :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: PewPew on July 17, 2016, 06:45:34 pm
Im on the event chapter now. I still dont understand why did you do this

        Keyboard = sf::Event::Count + 1, Mouse, Joystick

I check the value of the count and in my console it says 23. I check the meaning of the event::count and it says that    

Quote
Keep last – the total number of event types.

So i got 23 event types. How did I even get 23?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 17, 2016, 07:18:33 pm
This is because all event types are unified. Here's the full enumeration of the type:
enum class EventType{
        KeyDown = sf::Event::KeyPressed,
        KeyUp = sf::Event::KeyReleased,
        MButtonDown = sf::Event::MouseButtonPressed,
        MButtonUp = sf::Event::MouseButtonReleased,
        MouseWheel = sf::Event::MouseWheelMoved,
        WindowResized = sf::Event::Resized,
        GainedFocus = sf::Event::GainedFocus,
        LostFocus = sf::Event::LostFocus,
        MouseEntered = sf::Event::MouseEntered,
        MouseLeft = sf::Event::MouseLeft,
        Closed = sf::Event::Closed,
        TextEntered = sf::Event::TextEntered,
        Keyboard = sf::Event::Count + 1, Mouse, Joystick
};
Everything leading up to Keyboard isn't necessarily in order, and we may be adding new events later, so everything after that point is given the maximum possible value in order to avoid clashing. There aren't necessarily 23 event types here, but sf::Event provides that amount - 1.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: PewPew on July 19, 2016, 07:41:29 am
There is a lot of confusing stuff in this Chapter about events without the book explaining it. Even a comment on the source code might help.

This code

void Clear(){
                m_size = sf::Vector2i(0, 0);
                m_textEntered = 0;
                m_mouse = sf::Vector2i(0, 0);
                m_mouseWheelDelta = 0;
                m_keyCode = -1;
        }

why is m_keyCode initialize in -1? Whats wrong with 0? Is it because 0 is also a value in SFML events?

Cause later on this m_keyCode will be used in if statement

                if (bind->m_details.m_keyCode != -1){
                                                bind->m_details.m_keyCode = e_itr.second.m_code;
                                        }
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Hapax on July 19, 2016, 01:57:49 pm
why is m_keyCode initialize in -1? Whats wrong with 0? Is it because 0 is also a value in SFML events?
I would assume that this is linked to the fact that zero is in fact a key code ('A', in fact) in SFML's keyboard enum (http://www.sfml-dev.org/documentation/2.3.2/classsf_1_1Keyboard.php) whereas negative one represents "unknown" so is an apt value.
However, this could have been used much clearer by using the actual value sf::Keyboard::Unknown instead of the 'magic' -1.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 19, 2016, 05:08:36 pm
That's correct. I will definitely end up changing the 'magics' into something more obvious if I get to do some revisions. Needless to say, -1 is meant to represent the 'uninitialized' value.

Speaking of which, I also just caught a mistake that was fixed in the final drafts, but somehow made it into production:
if (bind->m_details.m_keyCode == -1) { // <-- Supposed to be ==, not !=.
     bind->m_details.m_keyCode = e_itr.second.m_code;
}

Again, I don't know how that happened, but I will be fixing it if I get a chance.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: PewPew on July 20, 2016, 08:02:35 am


Speaking of which, I also just caught a mistake that was fixed in the final drafts, but somehow made it into production:
if (bind->m_details.m_keyCode == -1) { // <-- Supposed to be ==, not !=.
     bind->m_details.m_keyCode = e_itr.second.m_code;
}


Weird cause somehow it is working the way the book expected it to work
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: PewPew on July 20, 2016, 08:14:26 am

However, this could have been used much clearer by using the actual value sf::Keyboard::Unknown instead of the 'magic' -1.

Totally agree! Readable without having to guess what that means
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: PewPew on July 24, 2016, 08:45:09 am
Hello. Im still on chapter 4 input and events. Ive been trying to debug how the game handles single input only on mouse? at what part of the code it handles it? Ive been trying to do a simple prototype of the code couldnt achieve the same result.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on July 25, 2016, 09:35:52 pm
Hello. Im still on chapter 4 input and events. Ive been trying to debug how the game handles single input only on mouse? at what part of the code it handles it? Ive been trying to do a simple prototype of the code couldnt achieve the same result.
I'm not sure I know what you mean by that. Handling mouse events is the same as any other event. All you have to do is give it a name by adding it to the keys.cfg file, and then register a callback for an event with that name.
Title: Re : SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on August 01, 2016, 11:57:14 pm
EDIT: Looks like I missed some includes, no more error for the SharedContext. But now I have another bunch of errors  8) I will try to correct them first before posting them

Hello  :)

I have an issue in Chapter 7 regarding the header of the class "Map".

When I try to build the code, there is an error here:

struct TileInfo {
    /// C-tor & D-tor ///
    TileInfo(SharedContext* context, const std::string &texture = "", TileId id = 0)

[...]Map.hpp|17|error: expected ')' before '*' token|

So it seems there is a problem with the "SharedContext *" parameter. The SharedContext header should be good:

class Map;
struct SharedContext
{
    SharedContext():
    mWindow(nullptr)
    , mEventManager(nullptr)
    , mTextureManager(nullptr)
    , mEntityManager(nullptr)
    , mGameMap(nullptr)
    {}

    Window          *mWindow;
    EventManager    *mEventManager;
    TextureManager  *mTextureManager;
    EntityManager   *mEntityManager;
    Map             *mGameMap;
};
 

I read somewhere in previous answers that
SharedContext *
member in StateManager.hpp should be
SharedContext
but it doesn't seem to resolve the problem  :(
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on August 02, 2016, 01:28:30 am
I was just about to reply to you about including the shared context header. Please make sure you consult the code files that came with the book. You will find complete source code there, with all of the necessary includes in place.
Title: Re : SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on August 02, 2016, 02:44:24 am
Quote
I was just about to reply to you about including the shared context header. Please make sure you consult the code files that came with the book. You will find complete source code there, with all of the necessary includes in place.

Yes, I'm going through your code line by line at the moment and found some answers to my problem.

There is however one last error that I didn't manage to resolve:
[...]\Character.cpp|7|undefined reference to `EntityManager::getContext()'|

and the code snippet:
Character::Character(EntityManager *entityMgr)
: EntityBase(entityMgr)
, mSpriteSheet(mEntityManager->getContext()->mTextureManager)

I probably missed something in your code (I should be sleeping but this error bugs me so hard !)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on August 02, 2016, 03:50:45 am
In EntityManager.h, SharedContext is forward-declared:
struct SharedContext;
This means it has to be included in the EntityManager.cpp file:
#include "SharedContext.h"
Also, make sure Character.cpp includes EntityManager.h:
#include "EntityManager.h"

In case you don't have the GetContext() method defined for the EntityManager class, here's what you need to add:
Header:
class EntityManager{
public:
        ...
        SharedContext* GetContext();
private:
        ...
        SharedContext* m_context;
};
Implementation:
SharedContext* EntityManager::GetContext(){ return m_context; }
Title: Re : SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on August 02, 2016, 11:23:19 am
EDIT: I didn't link to libshlwapi.a correclty, now it works  :)
Thank you, I didn't implement the getContext() method, no more errors about that.

There is now a problem with the method
PathRemoveFileSpec(path);
from
#include <Shlwapi.h>

Utilities.hpp|22|undefined reference to `_imp__PathRemoveFileSpecA@4'|

I assumed it's a linker error and tried to add the
Shlwapi.dll
in the bin folder but with no success (I'm using CodeBlocks, if that matters)
Title: Re : SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on August 02, 2016, 02:10:34 pm
Hello again,

It seems like
strcat_s(path, "\\")
can't be used in CodeBlocks (or am I wrong ?)
It's supposed to be a Visual C++ or Visual Studio function, is there an alternative ? Like using std::string
instead of a char* ?

The code:

#pragma once
#define RUNNING_WINDOWS
#include <iostream>
#include <cstring>
#include <algorithm>

namespace Utils
{
    #ifdef RUNNING_WINDOWS
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <Shlwapi.h>
    inline std::string getWorkingDirectory()
    {
        HMODULE hModule = GetModuleHandle(nullptr);
        if(hModule)
        {
            char path[256];
            GetModuleFileName(hModule, path, sizeof(path));
            PathRemoveFileSpecA(path);
            strcat_s(path, "\\");
            return std::string(path);
        }
        return "";
    }

and the error:

Utilities.hpp|21|error: 'strcat_s' was not declared in this scope|
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on August 02, 2016, 05:22:57 pm
Try using std::strcat instead of strcat_s. When doing so, make sure that <cstring> is included as well.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on August 02, 2016, 11:12:03 pm
I already tried that and it failed to load any files (so no more build errors but it just crash when trying to load the files).
I tried to build and run your code and same thing, crashed when trying to load any files.
I even tried to change the location of the media and config files with no success.

The old loading method (without using methods from Utilities.h) works well but I don't want to use that since it's not optimized.

The worst thing is that I'm pretty sure the solution is so obvious that I can't see it  ;D
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on August 03, 2016, 12:10:38 am
In that case, just get rid of strcat_s completely and return like this:
inline std::string GetWorkingDirectory() {
        HMODULE hModule = GetModuleHandle(nullptr);
        if (!hModule) { return ""; }
        char path[256];
        GetModuleFileName(hModule,path,sizeof(path));
        PathRemoveFileSpec(path);
        return std::string(path) + "\\";
}
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on August 03, 2016, 01:21:09 am
It still crashes after it tried to load keys.cfg, textures.cfg and EnemyList.list.

Something has to be wrong about how I named some of my paths or the location (I placed them just like you did, in a "Resources" folder).

I also have a LOT of warning messages but it's mostly "X will be initialized after", I don't know if it can be the root of my problem.

Thank you for your patience tho, I feel like a total noob with these loading problems  :P
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on August 03, 2016, 04:03:39 am
Without really having access to your code, I can't really say what might be wrong with it at this point. If you could archive all of your code, as well as the Resources folder, and send it to me in a PM, that would be great. I'll take a look at it and get back to you as soon as I can. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on August 03, 2016, 04:20:17 pm
OK thank you ! I will send it to you in 2 days (not at home for now)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: stenol on August 10, 2016, 02:12:11 pm
Since 2 weeks, I'm reading your book and I really love it. I'm now in the middle of chapter 7.I have some little projects in mind for when I will finish your book. I will probably use the framework that we build in the book to make my own little engine while making my own little game. Can I use it to do this ? Do I have some licence restriction ? Grats again for your book :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on August 10, 2016, 09:59:05 pm
Thank you! I'm glad you're enjoying the book so far. :) Yes, you are free to use the code as you please. I'd appreciate if you gave credit, but you are by no means obligated to do so. That's just for the code though. Make sure you check the licenses of whatever resources you're going to use from the book. If you use the same graphics, and/or music/sounds, I can't guarantee that the original copyright holders won't mind. All of the resources used in the book have been linked to, however, so you can easily find them and make sure.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: stenol on August 11, 2016, 01:37:25 pm
Tank you for your answer. I will certainly give you credit. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Bryan Pope on August 19, 2016, 03:29:09 am
Good evening,

I am trying to compile the code from Chapter 11, but unfortunately I am getting a couple errors:
- std::unordered_map has no member rbegin or rend
- Utilities.h, char * is incompatible with Utils::LPWSTR

Do I need to do some other setup in VS2015?  (Other than VC++ Directories, C/C++ Preprocessor, Linker General and Input)

Thanks,

Bryan Pope
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on August 19, 2016, 04:02:05 am
Hello Bryan,

First of all, thank you for buying the book. I really hope you are enjoying it so far, and sorry about the problems you're experiencing.

For the first issue, somehow the type definitions didn't get updated along with the rest of the code. You don't want to use unordered_map for the GUI_Interfaces container type. Instead, you could simply switch to std::map, or try something that looks like this:
using GUI_InterfaceType = std::pair<std::string, std::unique_ptr<GUI_Interface>>; // Smart pointer or raw, doesn't matter.
using GUI_Interfaces = std::vector<GUI_InterfaceType>; // Vector DOES support reverse iterators.
using GUI_Container = std::unordered_map<StateType, GUI_Interfaces>;
std::map would be an easier switch. Obviously some GUI code might have to change a little bit, because of the way information is accessed if it's a vector. I will try to contact Packt and get this fixed, as it should have been updated in the final product.

The second issue you're experiencing simply has to do with the encoding of your project. Your IDE is set to use wide characters, so instead of the char type you could simply use wchar_t, or you could re-work the function like this (use the 'A' suffix for two functions):
inline std::string GetWorkingDirectory() {
        HMODULE hModule = GetModuleHandle(0);
        if (hModule) {
                char path[256];
                GetModuleFileNameA(hModule, path, sizeof(path));
                PathRemoveFileSpecA(path);
                strcat_s(path, "\\");
                return std::string(path);
        }
        return "";
}
I would recommend the former, but it's your call. More information on that can be found here: http://www.cplusplus.com/forum/windows/185258/ (http://www.cplusplus.com/forum/windows/185258/)

Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Bryan Pope on August 20, 2016, 04:34:50 am
I finally got the Chapter 11 code to work! :)  But I had to do a little bit more than your suggestions:

- I went with std::map to replace std::unordered_map for GUI_Interfaces
- I finally went and used the "A" versions of GetModuleFileName and PathRemoveFileSpec, as I would have needed to change path back to a char, plus I was getting linker errors on the W versions of those two functions..
- but that also had issues - there were linker errors here as well for both functions
- after some googling, I added shlwapi.lib to my dependencies and also included PathCch.h and Shlwapi.h to Utilities.h.  But I then received quite a few errors "No target architecture".  To fix this I also included Windows.h in Utilities.h.
- when I ran it I was getting a nullptr error
- to fix this I copied the *contents* of the Asset directory into the Debug directory, plus I also had to remove the .txt extension from each of the .cfg files.

Next step is to play around with the code a bit!

Cheers,

Bryan Pope
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on August 20, 2016, 05:03:48 am
Hello again, Bryan,

I'm glad you got the code working! The shlwapi.lib inclusion is actually covered in the beginning of Chapter 6, as well as Shlwapi.h and Windows.h. I actually doubt that PathCch.h is required. You can give it a try and remove it, as the code runs just fine on my end without it. As far as the .txt extensions, someone else had the same issue. Were they like that in the code package you downloaded? If so, it might be something worthy of reporting to Packt, as it clearly wasn't intended to be like that.

Please feel free to let me know if you have any more issues. I will do my best to help you whenever possible. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Bryan Pope on August 20, 2016, 08:26:25 pm
Good afternoon,

Yes you are correct about the Shlwapi.h, windows.h and shlwapi.lib being covered in Chapter 6, I had forgotten that.  Also, you are right, I do not need PathCch.h.

Yes, in the Code Download zip file chapters 4, 5, 7, 8, 9, 11, 12 and 14 have .cfg files that also have a .txt appended to them.  I have reported this to Packt using their submit errata.

Thanks so much!,

Bryan
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: CleverBoy on August 23, 2016, 12:46:13 pm
Thanks for making it available and sharing your knowledge. I  am your happy customer. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on August 23, 2016, 02:12:20 pm
Thanks for making it available and sharing your knowledge. I  am your happy customer. :)
Thank you for your kind words! I'm really glad to know you found it useful. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: BonBons on October 10, 2016, 11:42:49 am
Hello there! Thank you so much for this book it has been invaluable because I am teaching myself to program with C++and learning how to do it through a project like this has been great.

I must ask though how do you save a tiled map in the format that you do. Meaning this: http://imgur.com/YA9kw13

I can't seem to find any information on this at all. I am having some issues with trying to save a tile map in a certain way so that I can read it into my game.

Thank you!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on October 10, 2016, 05:13:11 pm
Hello, BonBons! Thank you for your kind words. I'm really glad you're enjoying the book so far. :)

By tiled, do you mean the Tiled Map Editor? (http://www.mapeditor.org/ (http://www.mapeditor.org/)) If you do, I'm afraid I have no experience with it and wouldn't know if they even use the same type of elevation principles, not to mention other parameters necessary for their own format. I'm sure you could build a tool that somehow parses their format and writes it out however you want, but I can't say too much without looking at it.

If you simply mean how a map file like that can be saved, there's a big hint at the top of the file. As you can see, it's all saved as plain-text, making it easy to read and understand should you want to make revisions. All the lines that begin with the pipe symbol "|" are ignored by the code and treated as comments. Just above each new type of map file entry, there's a comment that explains exactly what parameters are stored in that line. For example, entities are stored by writing in the name of the entity type first, then the X and Y coordinates of the entity, and finally the elevation. Tiles store an additional value for their solidity, which can be either 0 or 1. That's pretty much all there is to it. If you can do basic file I/O, you know enough to save your entities and tiles in this format.

Hopefully this answers your question. I'm currently working on something that I can't say too much about, but let's just say that a portion of it deals with creating software that helps you build your own maps really easily. It should be out soon, so stay tuned. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: BonBons on October 13, 2016, 11:44:35 am
Hey there would just like to say that your book has really taught me how to program in C++ and I've recently made a littel portfolio which I used to apply to Universities. And I actually got accepted from the basis from what I've learned from your books so thank you so much for that!

Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on October 13, 2016, 04:54:51 pm
Hey there would just like to say that your book has really taught me how to program in C++ and I've recently made a littel portfolio which I used to apply to Universities. And I actually got accepted from the basis from what I've learned from your books so thank you so much for that!
Congratulations! I can't begin to explain to you how happy that makes me. Keep on doing great work, and good luck with your studies! :)
Title: Re : SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on October 15, 2016, 04:33:17 pm
Hey  :)

When I try to run the code in chapter 11 (in VS 2015), I get a "std::invalid_argument" error when it's trying to add the callback for "MainMenu_Play".

When debugging, it looks like the element contained in "eventInfo.gui.mElement" canno't be read in memory.

Is it possible that it comes from the fact that I compiled it in a x86 process ? (I read it somewhere on stackoverflow but I don't really think it's the problem here).

Tell me if you need me to post parts of the code or the debugger output !
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on October 15, 2016, 05:33:32 pm
Hello. Yes, I'd like to see your GUI_Event struct, the EventInfo struct, and the code where the compiler notes the crash. At this point, it's hard to say what may have gone wrong, as it looks like you're modifying the code a little bit. :)
Title: Re : SFML Game Development by Example - 4th SFML book
Post by: Nayk0_x on October 15, 2016, 06:49:21 pm
(You can find attached a pic from the debugger)

GUI_Event
struct GUI_Event {
        GUI_EventType mType;
        const char *mElement;
        const char *mInterface;
        union {
                ClickCoordinates mClickCoords;
        };
};

EventInfo
struct EventInfo {
    EventInfo() { mCode = 0; }
    EventInfo(int event) { mCode = event; }
        EventInfo(GUI_Event &guiEvent) { gui = guiEvent; }
    union
    {
        int mCode;
                GUI_Event gui;
    };
};

and to me, it looks like it is crashing around here (from EventManager::loadBindings())

if (type == EventType::GUI_Click || type == EventType::GUI_Hover ||
                type == EventType::GUI_Release || type == EventType::GUI_Leave)
{
        start = end + delimiter.length();
        end = keyval.find(delimiter, start);
        std::string window = keyval.substr(start, end - start);
        std::string element;

    if (end != std::string::npos) {
                start = end + delimiter.length();
                end = keyval.length();
                element = keyval.substr(start, end);
        }
        char *w = new char[window.length() + 1]; // +1 for '\0'
        char *e = new char[element.length() + 1];

        strcpy_s(w, window.length() + 1, window.c_str());
        strcpy_s(e, element.length() + 1, element.c_str());

        eventInfo.gui.mInterface = w;
        eventInfo.gui.mElement = e;
}
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on October 15, 2016, 08:19:52 pm
Everything above looks fine. Is there a way you could just archive all of your code and PM it to me so I can debug it?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Laurent on October 15, 2016, 08:48:18 pm
Quote
    union
    {
        int mCode;
        GUI_Event gui;
    };
That union looks wrong. Once the owner EventInfo instance is initialized, how do you know which member of the union is used? And when "gui" is used, is it always correctly constructed first?

And these old-style strings with manual memory management... ???
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on October 15, 2016, 09:37:40 pm
The usage of the appropriate union member is left up to a different structure that keeps track of the type of event as well. The older style strings stuck around because of content length limitations. I was already penalized for exceeding the projected length of the book, and things like this added up quickly, believe it or not. I've already updated the code on my end to use std::string and custom construction/move semantics. I'm just waiting for a chance to revise the book now.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Mario on October 16, 2016, 09:28:01 am
Wait, they don't allow your book to get longer even if it  helps the overall goal of the book? Those profit margins can't be that low.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on October 16, 2016, 09:52:58 am
Wait, they don't allow your book to get longer even if it  helps the overall goal of the book? Those profit margins can't be that low.
Originally, it was supposed to be around 320-380 pages max. That number was left in the dust somewhere around the halfway point. During the final stages, I was asked to cut out roughly 30-50 pages, which gave it the final length of 522 pages. Apparently there is a sweet-spot as far as the length and price of the book goes. The individual lengths of each chapter also couldn't have been exceeded, so some chapters ended up being split into two as well. During the planning stages there were supposed to be only 10 chapters, yet the final product has 14.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Bryan Pope on October 27, 2016, 01:43:37 am
I for one would pay more for a second edition that was longer and had even more well-written information.  I personally really like this book more for the C++ and great discussion of creating a basic game engine using the Entity Component System design pattern and less about the SFML.  Maybe use... errr... I don't know..,,  bgfx in your next book?

Cheers,

Bryan
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on October 28, 2016, 04:56:37 am
You know what? Thanks for saying that! It gets kind of frustrating and overwhelming when there's a bunch of other people, all with their own ideas and principles, trying to tweak and manage something like this. It can lose the essence of what it originally aimed to be fairly quickly that way.

As far as the next book, I can't really say too much, but it's close to being done now. Although it doesn't focus on bgfx, I'm still trying to keep it as close to what it should be as possible. All of the feedback from this thread really helped me fix a bunch of things and use a more modern approach. Hopefully everyone will be happier with it than they were with the first one. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: HoodedSpectre on November 10, 2016, 02:33:08 am
I have just one question, I have been working with this book for quite some time. I am attempting to run your source code for the final chapter so I can see what it looks like before I actually start reading. It will not work at all, when I launch the server.exe it just goes through the tile ids saying was not found then it hits map loaded and does nothing more. Do I need to just follow the entire book and code it myself? There are quite a few differences between the source code you provided and the book.

Aside from those questions, you are really helping me understand the parts of game development I don't think people really touch on. Being able to see how the client and server are structured exactly will really help in my personal studies. Thank you for the great book.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on November 10, 2016, 05:10:07 am
I have just one question, I have been working with this book for quite some time. I am attempting to run your source code for the final chapter so I can see what it looks like before I actually start reading. It will not work at all, when I launch the server.exe it just goes through the tile ids saying was not found then it hits map loaded and does nothing more. Do I need to just follow the entire book and code it myself? There are quite a few differences between the source code you provided and the book.

Aside from those questions, you are really helping me understand the parts of game development I don't think people really touch on. Being able to see how the client and server are structured exactly will really help in my personal studies. Thank you for the great book.
Hello, lurkerz. First of all, I'd like to thank you for reading the book! I'm really glad it helped you out.

The actual server itself simply loads the map and listens for incoming connections, so that they can be handled. The console itself spits out four lines of text when everything is fine, which are the port information, a notification that it began listening for connections, the loading map line, and "Map Loaded!" line. If you're getting tile IDs that weren't found, your tiles.cfg file is probably missing or misplaced. It's as simple as that.

Please let me know if you have any further problems down the line. I hope I was of any assistance. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: HoodedSpectre on November 10, 2016, 10:54:48 pm
Awesome, I was able to get it to work. I guess my working directory was setup weird so I made the change and now it works. Thanks for your help.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: HoodedSpectre on December 15, 2016, 01:47:37 am
Is there currently a way to create a map in tiled and export it into a format that would work with this engine? Or would I need to figure that out myself?

Also what is the purpose of the following keys?
Key_P 5:15 -
Key_T 5:19 -
Key_K 5:10 -
Key_O 5:14 - Enables debug mode
Key_X 5:23 -
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on December 15, 2016, 07:10:08 am
Is there currently a way to create a map in tiled and export it into a format that would work with this engine? Or would I need to figure that out myself?

Also what is the purpose of the following keys?
Key_P 5:15 -
Key_T 5:19 -
Key_K 5:10 -
Key_O 5:14 - Enables debug mode
Key_X 5:23 -
Not that I'm aware of, sorry. I'm sure that it wouldn't be that hard to parse existing tiled maps and convert them to the format used in the book, although that format is completely arbitrary. You could simply roll your own, or adapt the map class to store information exactly the same way tiled does, provided it follows the same principles of layering and rendering.

As far as the keys go, some of them aren't used. They just exist in the key config file because of previous testing, and I may have forgotten to take them out. If you search the code around for the strings of these keys, you should be able to easily figure out which ones are still being used.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: HoodedSpectre on December 15, 2016, 11:55:51 pm
Hey thanks for all the help, I'm still in school so I'm trying to absorb as much as I can from your book. It has been the most helpful of any book I've read. I noticed you mentioned you are working on another book, I know you can't say much about it but I'm excited to see it. I will definitely be purchasing it when it comes out, can you tell me a time frame of when you expect it may be out? Or at least announced?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on December 16, 2016, 04:47:55 am
Hey thanks for all the help, I'm still in school so I'm trying to absorb as much as I can from your book. It has been the most helpful of any book I've read. I noticed you mentioned you are working on another book, I know you can't say much about it but I'm excited to see it. I will definitely be purchasing it when it comes out, can you tell me a time frame of when you expect it may be out? Or at least announced?
Sure, don't mention it. :) Yes, I'm currently working on another book, and it's almost done. I should be done with the last two chapters this weekend, and it should be out in a couple of weeks. It has already been announced on the Packt website. I'd link to it, but their site seems to be down at the moment. :D

Edit: It's back up now: https://www.packtpub.com/game-development/mastering-sfml-game-development
The description doesn't include this, but the last couple of chapters focus on advanced lighting, shadows, and optimizations.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: jamesL on December 16, 2016, 12:44:14 pm
...Yes, I'm currently working on another book, and it's almost done. I should be done with the last two chapters this weekend, and it should be out in a couple of weeks. It has already been announced on the Packt website. I'd link to it, but their site seems to be down at the moment. :D

Edit: It's back up now: https://www.packtpub.com/game-development/mastering-sfml-game-development
The description doesn't include this, but the last couple of chapters focus on advanced lighting, shadows, and optimizations.

I hope this doesn't adversely affect your income, but the ebook version of that book is currently on sale for 5 dollars


Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on December 16, 2016, 05:33:07 pm
...Yes, I'm currently working on another book, and it's almost done. I should be done with the last two chapters this weekend, and it should be out in a couple of weeks. It has already been announced on the Packt website. I'd link to it, but their site seems to be down at the moment. :D

Edit: It's back up now: https://www.packtpub.com/game-development/mastering-sfml-game-development
The description doesn't include this, but the last couple of chapters focus on advanced lighting, shadows, and optimizations.

I hope this doesn't adversely affect your income, but the ebook version of that book is currently on sale for 5 dollars
I'm just happy as long as my work is useful to someone. The revenue is just a cherry on top. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: HoodedSpectre on December 16, 2016, 09:38:44 pm
Awesome I did not see it on the website when I was looking the other day. I just ordered it and I look forward to read it!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: jamesL on December 17, 2016, 12:00:20 am
remember
these are Ebooks

I have a year subscription to that site so I get everything

so I'm not positive what exactly what ebook means

I am able to download pdfs of books,
I am able to get some books on my kindle
I am able to read all books on the site as web pages 

so I'm not sure what you got for $5
I guess any of those could be considered an "ebook" 
you may get all of that for $5




Title: Re: SFML Game Development by Example - 4th SFML book
Post by: HoodedSpectre on December 17, 2016, 01:35:52 am
remember
these are Ebooks

I have a year subscription to that site so I get everything

so I'm not positive what exactly what ebook means

I was a member for a long time but I didn't use the site enough, between school and work. As far as the eBook only goes it's everything that isn't a physical copy if I do recall correctly.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Mario on December 17, 2016, 10:22:11 am
remember
these are Ebooks

I have a year subscription to that site so I get everything

so I'm not positive what exactly what ebook means

I am able to download pdfs of books,
I am able to get some books on my kindle
I am able to read all books on the site as web pages 

so I'm not sure what you got for $5
I guess any of those could be considered an "ebook" 
you may get all of that for $5

Their 5$ offer is for eBooks only, which is essentially the same content you get as a "flatrate" using the Mapt subscription. The only thing you won't get is a physical paper copy for that price.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: mequint on December 19, 2016, 09:35:34 pm
First off, I want to say that this has been one of the best game development books I've come across.  There are a lot of concepts that I had only heard about before that are fully implemented in this book.  That's cool!

I am having a bit of a problem.

Using Visual Studio 2015, I have tried implementing the code in Chapter 7 and I am getting a runtime error in the MainGame_State where the Character class throws an exception when attempting to get the name of the "Idle" animation in the Animate method.   It seems to happen when the AnimBase class calls the GetName() method. 

I tried comparing it to the original source code provided and I'm not seeing any problems in the code.  I also tried creating a new project and adding the complete source so that I could move on to Chapter 8 but that didn't even get past the Intro screen code...

Help!
Title: SFML Game Development by Example - 4th SFML book
Post by: eXpl0it3r on December 19, 2016, 11:04:05 pm
Build as debug build and step in with the compiler. Then you can check if the object you're trying to access is valid and you can provide the call stack.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on December 20, 2016, 01:07:43 am
First off, I want to say that this has been one of the best game development books I've come across.  There are a lot of concepts that I had only heard about before that are fully implemented in this book.  That's cool!

I am having a bit of a problem...
Thank you for your kind words! :)

As eXpl0it3r said, you should really provide a call-stack of the exception. It's very possible that, perhaps, some old code made its way to production stages. It's not unheard of with Packt. I ran my own version of both chapters just now and they work fine. Feel free to post the stack here and I'll try to help you out.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: mequint on December 22, 2016, 05:54:38 am
Well, here is the callstack:

>   Game World.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Check_offset(const unsigned int _Off) Line 2271   C++
    Game World.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Right, unsigned int _Roff, unsigned int _Count) Line 1151   C++
    Game World.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Right) Line 783   C++
    Game World.exe!AnimBase::GetName() Line 65   C++
    Game World.exe!Character::Animate() Line 237   C++
    Game World.exe!Character::Update(float dt) Line 195   C++
    Game World.exe!Enemy::Update(float dt) Line 38   C++
    Game World.exe!EntityManager::Update(float dt) Line 73   C++
    Game World.exe!State_Game::Update(const sf::Time & time) Line 72   C++
    Game World.exe!StateManager::Update(const sf::Time & time) Line 46   C++
    Game World.exe!Game::Update() Line 27   C++
    Game World.exe!main() Line 9   C++
    [External Code]   
    [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]   

I at first thought that this could be a loading problem but the resources loaded fine for the rest of the project. 

I'm running through the code one more time just to make sure it wasn't a coding error.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on December 24, 2016, 09:07:42 am
Your current animation in the SpriteSheet class may be null for some reason. Please zip up and send me all of the code that makes up the project, along with any entity or configuration files. I'll check it out and let you know what the problem is.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: mequint on December 27, 2016, 09:56:30 pm
I have zipped up the code and sent it your way. 
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on December 28, 2016, 12:59:48 am
I have zipped up the code and sent it your way.
Alright, thanks. I got your email. I'll try to get back to you about the code as soon as I can, but I'm quite busy at the moment, so it will be a day or two. Still, I'll try to find some time earlier and keep you in the loop.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: HoodedSpectre on January 05, 2017, 10:49:51 pm
OrderNexus this wait is killing me, do you have an estimate on how much longer until your new book comes out? I know you can't give a specific day but I'm eagerly awaiting it.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 06, 2017, 10:08:09 am
OrderNexus this wait is killing me, do you have an estimate on how much longer until your new book comes out? I know you can't give a specific day but I'm eagerly awaiting it.
I'm finishing up the last chapter tomorrow, so it will definitely be out in January. I would say probably in the next week or two.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 06, 2017, 10:49:32 am
Well, here is the callstack:
...
One really common and stupid mistake I've made that I'd like to acknowledge here is the necessity to take out line 201 in the EventManager.cpp, inside LoadBindings():
int code = std::stoi(keyval.substr(end + delimiter.length(), keyval.find(delimiter, end + delimiter.length())));
I really don't know why this line stayed in, but after all of the GUI stuff is implemented, this line needs to be removed. Outside of that, I have compiled a list of other quick things I caught with a debugger in your code that were probably just simple copying errors. Please look them over, and I also recommend you comb your code with a debugger as well. Perhaps a static-analysis tool as well, that will be useful when catching weird bugs. I'm sure you just missed an initialization somewhere, and that's what the call-stack looks like to me. AnimBase or one of the parent classes is probably nullptr.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: jamesL on January 20, 2017, 12:04:38 am
OrderNexus this wait is killing me, do you have an estimate on how much longer until your new book comes out? I know you can't give a specific day but I'm eagerly awaiting it.
I'm finishing up the last chapter tomorrow, so it will definitely be out in January. I would say probably in the next week or two.

Amazon says
February 6, 2017
Mastering SFML Game Development Paperback 
https://www.amazon.com/Mastering-SFML-Development-Raimondas-Pupius/dp/178646988X/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1484866397&sr=8-10

packtpub says January
https://www.packtpub.com/game-development/mastering-sfml-game-development

no table of contents yet, but there's this description

"It begins by going over some of the foundational code necessary in order to make our RPG project run.

By the end of chapter 3, we will have successfully picked up and deployed a fast and efficient particle system that makes the game look much more 'alive'.

Throughout the next couple of chapters, you will be successfully editing the game maps with ease, all thanks to the custom tools we’re going to be building.

... After being introduced to the use of shaders and raw OpenGL, you will be guided through implementing dynamic scene lighting, the use of normal and specular maps, and dynamic soft shadows.

However, no project is complete without being optimized first. The very last chapter will wrap up our project by making it lightning fast and efficient."

What You Will Learn
* Build custom tools, designed to work with your specific game
* Use raw modern OpenGL and go beyond SFML
* Apply GLSL and advanced lighting techniques to really light up the screen with custom effects
* Implement a very fast and efficient particle system by using a cache-friendly design
* Use advanced lighting techniques to add that extra touch of sophistication
* Revamp your code for better structural design, faster rendering, and flashier graphics
* Utilize networking to build better software for group projects.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 20, 2017, 03:13:44 am
The book is going to be up by Monday (23rd). All chapters have already been finished by me and are now in the final stages. Also, some of those points are outdated and are going to be edited before it comes out.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: jamesL on January 20, 2017, 03:57:40 am
23rd

awesome

I hope you were able to include a lot of the opengl stuff

that's the kind of sfml book I'd really like to see
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: HoodedSpectre on January 21, 2017, 12:05:59 am
One more question I have, does it utilize the game(s) from the previous book or is it a fresh start with new games and new everything?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 21, 2017, 05:21:42 am
Yes, it does utilize the third project from the last book, which is the RPG. The last three-four chapters deal with OpenGL stuff by implementing advanced lighting and 3D omni-directional point light shadows, as well as optimizing the project.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: _Imperial_ on January 23, 2017, 03:25:16 pm
Hi OrderNexus. It's been a while I got your book, but only 2 weeks ago I could start going through it. It's an amazing work. Good job! I'm also looking forward to reading the Mastering SFML Game Development.
Anyway, my question is: I'm in chapter 11 (in the end). Just finished and compiled and ready to go to chapter 12 when...... BOOM! I don't have a GUI  :'(
I don't understand what I did wrong. I am very careful to follow all the code and understand all that I am doing. It compiles without any errors (I use VS Community 2015).

Basically, it loads the Intro and when we go to MainMenu it doesn't show any GUI. I tried to bypass to see it the problem is in the Main Menu, so what I did was testing it by simply jumping from Intro_continue to Game. And nope, nothing wrong with the states. The game runs ok, the map loads.... but also no GUI in the game mode.

Summarizing: No GUI elements show anywhere, but the GUI_(something).h and GUI_(something).cpp look all fine. (I also ajusted the SharedContext, Satte_MainMenu and EventManager per your instructions).
I don't know what else to do.

Btw, there is also a minor bug that's been anoying me for a while (but it's no big deal). So, when you close the game using the 'X' button in the window, it purges all resources, all goes well, but the last second it displays a message saying (see attachment). That bug doesn't make the game unplayable or anything... it's just there since chapter 7 and I can't find the reason why.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 24, 2017, 06:37:25 am
Hi _Imperial_.

First and foremost, thanks for reading! I really appreciate your kind words. The new book is supposed to come out either tomorrow or the day after, actually. I have just approved the pre-finals of the last couple of chapters, as well as the cover, and it should be made available soon.

Regarding Chapter 11, it's really hard for me to say what the problem might be without looking at the code. From what you told me, it seems that it may be some sort of simple issue where either the interface file itself isn't correctly defined, isn't properly loaded, or something else of that variety. I'd have to take a look at it and see in order to make sure, but if you want to do it yourself, simply break the program on the point where an interface is created in the main menu state and track it line by line to figure out what the problem is. Seeing the branches your code takes can be a great tool in trying to figure out what the problem might be.

The same deal applies to the error message you attached. While in debug mode, hit retry and look at your stack trace. It will give you a detailed overview of where the program failed. It's most likely my fault, as I probably overlooked something. Rest assured though, it seems like an easy fix.

If you still can't figure it out, zip your code up and send it my way. I'll try to run it on my end and track the problem down when I have a moment.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: HoodedSpectre on January 24, 2017, 09:28:11 pm
Sorry I hate to be that nagging person but this anticipation is killing me! The book was supposed to be out yesterday.. Just a delay from packtpub? Or has it been delayed for another reason?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 24, 2017, 10:59:24 pm
Sorry I hate to be that nagging person but this anticipation is killing me! The book was supposed to be out yesterday.. Just a delay from packtpub? Or has it been delayed for another reason?
No, trust me, you're fine! I'm the same way. The book is completely finished and as they informed me, it has been "uploaded". From my previous impressions, I got the feeling that "uploading" it means it will be published, but apparently it will take a couple more days for them to do that for whatever reason. Rest assured though, it will be out sometime this week or the beginning of next week, as all of the final drafts were already finished long before. It's on the fast track to the finish line now.

UPDATE: I just got word that it will be published by this Friday.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: _Imperial_ on January 26, 2017, 02:15:45 am
Does anyone had this compiling problem? All other C_(something) are fed into the template just fine, just the SoundListener component that can't be instantiated. It says it's abstract.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: sjaustirni on January 26, 2017, 07:16:01 pm
Abstract class means it contains at least one pure virtual method. The aforementioned error is common when overriding an ABC (Abstract base class) while forgetting to implement one of its pure virtual methods. Look for pure virtual methods in the base classes and then make sure you've implemented all of them in the SoundListener.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: HoodedSpectre on January 28, 2017, 12:21:53 am
I'm a little disappointed I still don't have it available yet. Packt pub come on, this was going to be my weekend project haha.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: jamesL on January 28, 2017, 04:18:39 am
I'm sure making it into a kindle version or pdf is easy

but it probably takes some time to get it set up into their web Mapt version

they also probably want to release all versions (including the print version) at around the same time -- and I'm sure it takes time to get that printed

and amazon has moved the "book available" date from Feb 6 to March 6
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 28, 2017, 05:12:49 am
Yeah, I've been done with the book for a while now. The dates they keep giving me are almost always get moved further down, although it shouldn't be much longer. I was honestly expecting it to be out today, but it will probably be out this Monday at the latest. That would be my best guess. Sorry guys. I hope you enjoy it when it comes out though!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: jamesL on January 30, 2017, 03:51:33 pm
regarding the new book
Mastering SFML Game Development

https://www.packtpub.com/game-development/mastering-sfml-game-development

code files are now available for download

one zip file full of .rar files

can't read the book online yet, but the pdf is available for download

I have not downloaded it yet

I'll let the book author start a new thread specific for the book

hmmm, wondering if this is the final code

some unusual files names for maps in this folder
B05590_10_code / Build / Media / Maps

map1[newNotStressTest].map

map1[old].map

Title: Re: SFML Game Development by Example - 4th SFML book
Post by: HoodedSpectre on January 30, 2017, 06:21:19 pm
I read the first two chapters then did a skim over the rest, it looks great. I'm wondering how I would go about incorporating this text into the server from the project in the final chapter of the last book. Can the shaders and lighting affects be handled solely on the client portion? I'm new to networked programming and just trying to learn everything I can.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 30, 2017, 11:01:22 pm
regarding the new book
...
Yeah, the book is actually available now! Regarding the code files, the additional map stuff was left in by me. Those were, more or less, just backups for me that I forgot to take out. They simply contain different versions of the game map that hold more entities and lights for stress testing during Chapter 10. Feel free to ditch them, as they're not essential.
I read the first two chapters then did a skim over the rest, it looks great. I'm wondering how I would go about incorporating this text into the server from the project in the final chapter of the last book. Can the shaders and lighting affects be handled solely on the client portion? I'm new to networked programming and just trying to learn everything I can.
I'm really glad it looks good to you at this point. Thanks so much for reading! This book only deals with client-side techniques, so you could easily take all of them and apply them to the client. Lights themselves, as they're part of the map, may need to be updated on the server side if you want to move them around. The approach taken in the first book assumes that the maps are both the same on the client and server sides, but you'd probably either want to only read in tiles on the client side, or just send everything to the client from the server to ensure continuity. When writing networking programs for anything beyond mere testing, client input should never be trusted.

Side note: Packt really messed up by uploading the archives of the code to GitHub, rather than the code files themselves. I have no idea why they did it like that, but it kind of misses the point of source-control if you ask me.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Nightmare_82 on January 31, 2017, 07:46:48 pm
Hi,

I just wanted to say that your new book looks great! I preordered it a while ago and didn't have time to read everything yet but I looked at all chapters and it contains a lot of very cool/advanced topics and good explanations!

Thanks for making this book  :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on January 31, 2017, 08:48:10 pm
Hi,

I just wanted to say that your new book looks great! I preordered it a while ago and didn't have time to read everything yet but I looked at all chapters and it contains a lot of very cool/advanced topics and good explanations!

Thanks for making this book  :)
Hello! Thank you for reading. I really appreciate it. Hope you enjoy the book! :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Grundkurs on February 05, 2017, 12:32:54 pm
i just ordered the book at packtpub, can't wait to read it.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on February 06, 2017, 05:02:48 am
i just ordered the book at packtpub, can't wait to read it.
Thanks for buying it! I really hope you enjoy it. :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Xorlium on February 13, 2017, 02:50:48 pm
I want to buy the new book (it's on sale!) , but I have a couple of questions first:
1. Is it multiplatform? Im on linux.
2. Is it required to have the first book?

Thanks.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on February 13, 2017, 05:50:52 pm
I want to buy the new book (it's on sale!) , but I have a couple of questions first:
1. Is it multiplatform? Im on linux.
2. Is it required to have the first book?

Thanks.
1) It should work with other platforms just fine, albeit with a little tweaking on your part if some concepts don't carry over. Nothing about the code screams certain platform dependence, but I've developed it on a Windows machine, so some things may be leaning slightly towards VS. Still, the tweaking should be minor, if any. Take it with a grain of salt and use it as a reference book, while making the necessary adjustments when needed, provided you know C++ rather well.

2) The first book isn't required at all. It uses the third RPG project from the first title, but covers the code-base fairly well so you can jump into it without looking at too much of the underlying code. It may be useful for you to have the first book just to understand the concepts, but if you do already, it's not necessary.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Xorlium on February 14, 2017, 02:36:54 pm
Thanks. I bought it :) Looks good.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on February 14, 2017, 06:12:55 pm
Thanks. I bought it :) Looks good.
Thanks! I really appreciate your support. Hope you enjoy it! :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Sidious78 on March 01, 2017, 04:59:42 pm
I´m working with both this book and the new book at the same time.

Any plans of making a thread for the new book?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on March 03, 2017, 06:15:21 am
I´m working with both this book and the new book at the same time.

Any plans of making a thread for the new book?
Yeah, I'll be making a thread soon. I haven't had much time lately to really maintain my online presence, but I'll at least get a thread started when I have more than a minute. In the meantime, if you have any questions or concerns, feel free to just shoot a PM my way and I'll do my best to help you out. Thanks for reading! :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Bryan Pope on April 28, 2017, 01:20:05 am
Good evening,

In the downloaded code, chapter 10, ECS/Core/System_Manager.h has an #include "../../Debug/DebugOverlay.h", but that directory/file does not exist in any of the downloaded code's chapters.

Maybe it was clobbered because Visual Studio uses the Debug directory when compiling?  I commented this line out and was able to successfully compile.

Cheers,

Bryan
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on April 28, 2017, 02:15:33 am
Good evening,

In the downloaded code, chapter 10, ECS/Core/System_Manager.h has an #include "../../Debug/DebugOverlay.h", but that directory/file does not exist in any of the downloaded code's chapters.

Maybe it was clobbered because Visual Studio uses the Debug directory when compiling?  I commented this line out and was able to successfully compile.

Cheers,

Bryan
No, it was just an include directive that either somehow got left behind by me, or it was not the most recent code file used by Packt, as we have gone over a couple of revisions and they're not the best when it comes to using the most up-to-date code sent in by the author. Either way, it can safely be left out to execute the code. Thanks for bringing this to my attention though.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: _Imperial_ on May 03, 2017, 07:09:26 pm
Hi, OrderNexus. I bought the Mastering SFML book. Big fan of your work. I want to dive deeper into openGL. Looks promising. Btw, I just thought you might like this small change on the codebase (that is, if you didn't do this yet in this specific part of the code). Anyways, on the StateManager.cpp file, consider using reverse_iterators, they are good for what you wanted to accomplish in the update and draw methods, but with less hastle.  8) Here is what I did. It has less lines of code and does the exact same thing and also uses the STL facilities "rbegin" and "rend". Thanks!!  ;)

void StateManager::update(const sf::Time& time) {
   if (statesContainer.empty()) { return; }
   if (statesContainer.back().second->isTranscendent() && statesContainer.size() > 1) {
      for (auto statesItr = statesContainer.rbegin(); statesItr != statesContainer.rend(); ++statesItr) {
         if (!statesItr->second->isTranscendent()) { break; }
      }
      for (auto statesItr = statesContainer.begin(); statesItr != statesContainer.end(); ++statesItr) {
         statesItr->second->update(time);
      }
   }
   else { statesContainer.back().second->update(time); }
}

void StateManager::draw() {
   if (statesContainer.empty()) { return; }
   if (statesContainer.back().second->isTransparent() && statesContainer.size() > 1) {
      for (auto statesItr = statesContainer.rbegin(); statesItr != statesContainer.rend(); ++statesItr) {
         if (!statesItr->second->isTransparent()) { break; }
      }
      for (auto statesItr = statesContainer.begin(); statesItr != statesContainer.end(); ++statesItr) {
         locator->window->getRenderWindow()->setView(statesItr->second->getView());
         statesItr->second->draw();
      }
   }
   else {
      locator->window->getRenderWindow()->setView(statesContainer.back().second->getView());
      statesContainer.back().second->getView();
   }
}
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on May 04, 2017, 06:10:29 am
Hey thanks, _Imperial_! I appreciate your kind words and the input on the book(s). You are absolutely right, I should've used reverse iterators. The way your code is written though, every single state will be updated and drawn. The main point of having two loops in each method is first finding the state that is no longer supposed to be "transparent", and then tracing back from that point all the way till the end of the container to update and render the states that are supposed to be "on top of each other". In the code that you posted, that first loop in each method does absolutely nothing.

With that being said, you can definitely still use the reverse iterators. In retrospect, that's what I should have done. I guess I just wanted to outline the process I just explained more clearly. Not sure how well that worked, all things considered.

Either way, thank you so much for your support and the suggestion. Reverse iterators are useful. If I ever get to make editions to either one of the books, I will make sure to put that in. It's on my list! :)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: _Imperial_ on May 09, 2017, 04:49:00 am
void StateManager::update(const sf::Time& time) {
   if (statesContainer.empty()) { return; }
   if (statesContainer.back().second->isTranscendent() && statesContainer.size() > 1) {
      bool reversing = true;
      for (auto statesItr = statesContainer.end() - 1; statesItr != statesContainer.end(); (reversing ? --statesItr : ++statesItr)) {
         if (!statesItr->second->isTranscendent() || statesItr == statesContainer.begin()) {
            reversing = false;
            if (!statesItr->second->isTranscendent()) { continue; }
         }
         if (!reversing) {
            statesItr->second->update(time);
         }
      }
   }
   else { statesContainer.back().second->update(time); }
}

void StateManager::draw() {
   if (statesContainer.empty()) { return; }
   if (statesContainer.back().second->isTransparent() && statesContainer.size() > 1) {
      bool reversing = true;
      for (auto statesItr = statesContainer.end() - 1; statesItr != statesContainer.end(); (reversing ? --statesItr : ++statesItr)) {
         if (!statesItr->second->isTransparent() || statesItr == statesContainer.begin()) {
            reversing = false;
            if (!statesItr->second->isTransparent()) { continue; }
         }
         if (!reversing) {
            locator->window->getRenderWindow()->setView(statesItr->second->getView());
            statesItr->second->draw();
         }
      }
   }
   else {
      locator->window->getRenderWindow()->setView(statesContainer.back().second->getView());
      statesContainer.back().second->draw();
   }
}

Yes OrderNexus, you are right. The previous approach wasn't doing any work inside the first loop. Sorry for the delay to reply. I wasn't able to dive into the engine code for a couple days, too busy. Anyway, after returning to it, I took my time to understand what needed to be accomplished there and I believe I got it right this time. Actually it uses only one for loop now. 8)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on May 09, 2017, 06:00:54 pm
Nice job! From looking at it quickly, it seems like it should work as intended.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: drewbarbs on July 03, 2017, 09:19:44 pm
Just started going through this book and enjoying it so far. Chapter 3, after introducing the basic code for the snake game, has a section on finding bugs. At the end of this it says:

Quote
There's one more fault with the game that didn't get addressed here on purpose. Try to find it and fix it in order to practise resolving problems like this in the future.

Hint: It has to do with how many segments the snake has when the game starts.

I'm stumped as to what this could be. I thought this could be referring the case where our world is smaller than the space required to accommodate our hardcoded initial position, but that seems overly paranoid. Also, I've added some code to ensure the apple spawn isnt in a position occupied by the snake. I've looked at the finished code online, and fail to see what is fixed there that wasn't described in the text. Anyone know what this is referring to?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Eyfenna on August 20, 2017, 11:23:59 pm
its my second sfml book and have to say thanks for the many stimula though i started to rebuild the examples with smart pointers i'm able to get nearly everything  to run.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on August 23, 2017, 10:16:28 pm
its my second sfml book and have to say thanks for the many stimula though i started to rebuild the examples with smart pointers i'm able to get nearly everything  to run.
I'm happy to hear that! Let me know if you have any problems.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Eyfenna on August 25, 2017, 06:52:16 pm
so far what does not run is the register state template that captures this in the lambda. even enabling shared from this and creating a shared ptr inside the class with self and vapturing self by ref gets me a bad weak ptr error.
the other thing is the utility get working directory macro the char array is not accepted by the winapi function in vs 2015.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Grundkurs on August 27, 2017, 12:50:36 pm
so far what does not run is the register state template that captures this in the lambda. even enabling shared from this and creating a shared ptr inside the class with self and vapturing self by ref gets me a bad weak ptr error.
since the States stored in the StateContainer and StateFactory are not shared among other entities, i recommend using std::unique_ptr<> instead of std::shared_ptr.
using StateContainer = std::vector<std::pair<StateType, std::unique_ptr<State>>>;
using StateFactory = std::unordered_map<StateType, std::function<std::unique_ptr<State>()>>;
...
template<class T>
void StateManager::registerState(StateType stateType){
        mFactory[stateType] = [this]()->std::unique_ptr<State>{
                return std::make_unique<T>(this);
        };
}
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Eyfenna on August 30, 2017, 02:03:27 pm
so far what does not run is the register state template that captures this in the lambda. even enabling shared from this and creating a shared ptr inside the class with self and vapturing self by ref gets me a bad weak ptr error.
since the States stored in the StateContainer and StateFactory are not shared among other entities, i recommend using std::unique_ptr<> instead of std::shared_ptr.
using StateContainer = std::vector<std::pair<StateType, std::unique_ptr<State>>>;
using StateFactory = std::unordered_map<StateType, std::function<std::unique_ptr<State>()>>;
...
template<class T>
void StateManager::registerState(StateType stateType){
        mFactory[stateType] = [this]()->std::unique_ptr<State>{
                return std::make_unique<T>(this);
        };
}

thanks that helped and header include juggling, it does work properly now.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: jamesL on September 21, 2017, 09:59:47 am
is free on September 21 2017

go here

https://www.packtpub.com/packt/offers/free-learning

make an account

download free pdf of book
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Grundkurs on October 17, 2017, 03:21:13 pm
i may have found a bug in the code-base of "SFML Game Development by Example". Please correct me if i'm wrong:
AnimBase.h
using Frame = unsigned int;
class AnimBase{
...
    Frame m_frameCurrent;
    Frame m_frameStart;
    Frame m_frameEnd;
    Frame m_frameRow;
};
 
AnimDirectional.cpp
void Anim_Directional::FrameStep(){
    if (m_frameStart < m_frameEnd){ ++m_frameCurrent; }
    else { --m_frameCurrent; }

    if ((m_frameStart < m_frameEnd && m_frameCurrent > m_frameEnd) ||
        (m_frameStart > m_frameEnd && m_frameCurrent < m_frameEnd)){
        if (m_loop){ m_frameCurrent = m_frameStart; return; }
        m_frameCurrent = m_frameEnd;
        Pause();
    }
}
 

In the if-Statement in Anim_Directional::FrameStep() a check is performed if
m_frameCurrent is smaller than m_frameEnd. This is problematic in the case that the Animation runs backwards (like m_frameStart = 4; m_frameEnd = 0), because given m_frameEnd is set to 0, m_frameCurrent will never be smaller than m_frameEnd because both variables are of type unsigned int. So when m_frameCurrent is set to smaller then 0 with "--m_frameCurrent" it will automatically "roll over" to the highest possible unsigned int-value since its unsigned and therefore the if-statement (m_frameCurrent < m_frameEnd) will never trigger.

A workaround by shifting m_frameStart and m_frameEnd one to the right (m_frameStart = 5; m_frameEnd = 1) is not solving the problem because it produces other issues when cropping the sprite from the spritesheet.

Setting "Frame m_frameCurrent" to "int m_frameCurrent" to allow m_frameCurrent to be assigned to negative values evokes other problems because then you are comparing an int (m_frameCurrent) to an unsigned int (m_frameEnd) in the mentioned if-statement, which can lead to further problems (see https://stackoverflow.com/questions/8233161/compare-int-and-unsigned-int/8233184#8233184). In my case the if-statement didnt trigger even though m_frameCurrent was smaller than m_frameEnd (which was set to 0). So i ended up using int instead of "Frame" aka unsigned int in AnimBase.h. That solved all my problems.
   
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on November 03, 2017, 07:03:28 am
First of all, sorry about the late response. I should've tackled this sooner.

You're right, this is something that got overlooked by me during the writing process. Funny thing is, I had that corner case pinned in my notes and I completely "goofed" it when making final alterations before submitting it. My bad on that one.

Setting the type of m_frameCurrent to a regular integer would indeed fix the issue, or you could simply add >= and <= checks in the right half of the lowest if-statement. I haven't tested this yet, but upon first glance after a long time of not looking at this code, it seems like that might be a good way of dealing with the issue as well. Having negative frames was never really intended behavior, so it's important to avoid that as much as possible, since it could produce unexpected bugs later on. The code would then look like this:

void Anim_Directional::FrameStep(){
    ...
    if ((m_frameStart < m_frameEnd && m_frameCurrent >= m_frameEnd) ||
        (m_frameStart > m_frameEnd && m_frameCurrent <= m_frameEnd)){
        if (m_loop){ m_frameCurrent = m_frameStart; return; }
        m_frameCurrent = m_frameEnd;
        Pause();
    }
}
The m_frameCurrent = m_frameEnd; line is still kept, simply to ensure we didn't blow through the intended range somehow. This should allow you to switch back to the 'Frame' typedef for continuity.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: BetokHaney on November 30, 2017, 07:47:07 pm
I just bought the book, and have a question regarding items in Chapter 4:

The keys.cfg file uses key numerical values for key bindings, like:

Fullscreen_toggle 5:89

...where KeyDown is represented by 5, and the F5 key by the number 89.

Where do the key number values come from?  I can't for the life of me find how the various keys on the keyboard are tied to a numerical value in SFML.

Thanks for your help.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Arcade on November 30, 2017, 08:29:56 pm
I haven't bought or read through the book, but it seems likely that those numbers represent the position of those values within their corresponding enum. KeyPressed is equal to 5 in enum sf::Event::EventType (https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1Event.php#af41fa9ed45c02449030699f671331d4a) (start counting from 0), and F5 is likely equal to 89 in  
enum sf::Keyboard::Key (https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1Keyboard.php#acb4cacd7cc5802dec45724cf3314a142)
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: BetokHaney on December 01, 2017, 05:31:18 pm
I haven't bought or read through the book, but it seems likely that those numbers represent the position of those values within their corresponding enum. KeyPressed is equal to 5 in enum sf::Event::EventType (https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1Event.php#af41fa9ed45c02449030699f671331d4a) (start counting from 0), and F5 is likely equal to 89 in  
enum sf::Keyboard::Key (https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1Keyboard.php#acb4cacd7cc5802dec45724cf3314a142)

This is it!  Thank you so much.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Devo on December 20, 2017, 02:32:57 am
I've been working through the book with a Mac and enjoying it quite a bit. There are a few roadblocks for Mac users,  and so I thought I'd share the ones I've encountered so far to possibly spare others some pain.

- Make sure to use the ResourcePath helper function that comes with the OS X SFML installation whenever you need to load something from the file system (e.g. graphics, fonts, etc.)

- Earlier in this thread there is a discussion about errors caused by unordered_map and hashing custom objects. This applies to Xcode as well, and you will need to create and use the CustomHash header file as described.

- If you try to read in text files that come with the source code download, your code will throw a runtime error due to a null pointer (this first happens with keys.cfg in the EventManager and StateManager chapters). It took me forever to figure out that this appears to be due to the different end-of-line characters between Windows and OS X. A solution is to recreate the files on the Mac, I just typed them in using nano in a terminal window.

- More to come I'm sure!

Devo
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Sanction on January 15, 2018, 03:31:47 am
I'm having some problems with Chapter 4 covering the Event Manager.

At the end you should be able to move a simple texture around with Mouse Left Click and also the LShift key.

However when I load the keys.cfg I found a weird problem.
(click to show/hide)


I do have my code on github:https://github.com/SanctionMan/SFML_Project/ (https://github.com/SanctionMan/SFML_Project/)
I have went back though my code again and copy and pasted the code from the example code and I still have the same problem. I've also walked thought this form post hoping to find the same problem. Maybe I'm missing something here.

I am using SFML 2.4.2 ATM and also have changed the following that you showed in a post before here.
if (bind->m_details.m_keyCode == -1) {
// changed != to ==
 

I'v created a function that prints out all the bindings and events in each binding and its reading them all.
(click to show/hide)



Title: Re: SFML Game Development by Example - 4th SFML book
Post by: yreaction on February 09, 2018, 09:25:53 am
Mac usere here aswell, figured out the first issues but the endline for keys.cfg saved me a lot of headcheds. Thanks mate.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: theo on March 02, 2018, 04:03:57 pm
First of all: I like the book a lot. Thanks for it.

At the moment I'm going through the event manager chapter. I have one question and one remark.

The question:
You store the Binding objects in an unordered_map keyed on name. The only reason for this seems to be to enforce only one Binding per callback, since you never access the bindings map on name. Why is that important? I would drop that restriction, since there are reasons to want multiple bindings to the same callback. For example, if you want to bind <ctrl>-c to some event, you need two bindings: one for left control and one for right control. Differentiating between left and right shift, alt and control seems artificial to me. The user shouldn't be bothered with the technical fact that left and right key have different keycodes. So I would use a std::vector<Binding*> (or better still: std::vector<std::unique_ptr<Binding>> and even silently include double bindings when the user wants ctrl/alt/shift combinations.

The remark:
You do a great job of abstracting the event side of the event manager, but the callbacks are just wrapped function pointers. Why not put a Command pattern on the callback side? See http://gameprogrammingpatterns.com/command.html for a nice explanation. Of course that adds some code and complexity, but it enables some cool features:
1- if the AI also puts Command objects on the queue, enemies (and a demo mode, if applicable) can use the exact same control mechanism as the user-controlled character.
2- you can control all kinds of actors. So the player character is an actor, but the Window class can also be an actor (to handle focus gained/lost, toggle full screen). You could make anything that receives input an actor, using the same mechanism without messy exceptions to the rule.
3- it makes undo easy. In certain situations (think a strategy game where the player has to plan actions for many units before committing the turn) this could be a really nice touch.
Abstracting the callback side as well as the event side makes the event manager even more versatile.

And a minor point: you have many functions return a bool to indicate succes. It seems cleaner and more natural to me to use exceptions for that kind of behaviour. But that could just be me, I do java for a living.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: theo on March 08, 2018, 11:22:23 am
I got to the statemanager chapter. A few constructive remarks:

1- You tend to pass very small data-items bij const ref: e.g. void f (const bool&). I don't see what's the merit in that. A bool or an int is probably even smaller than a pointer. Just pass these things by value and use const refs where a copy is (potentially) expensive.
2- You have a tendency of declaring empty destructors. Probably power of habit, but in C++11 this prevents the generation of move constructor and assignment. This will of course not be a problem with classes like eventmanager and statemanager because they will not be moved around anyway, but this is not a good habit.
3- In the draw and update functions of the statemanager, you traverse back and forth to find the last non-transparent state. In the past I used to be a C programmer, so traversing pointer structures is nothing new for me, but the C++ Committee gave us the algorithms library to be used. This code can be rewritten to be a lot more obvious:


#include <algorithm>

using State_elem = std::pair<StateType, BaseState*>>;  // convenience

void StateManager::Draw()
{
  if (m_states.empty() {return;}
  if (m_states.back().second->IsTransparent() && m_states.size() > 1)
  {
    // find last non-transparent state. find_if normally finds the first element that satisfies its predicate,
    // but if we feed it reverse iterators, it searches backwards.
    // I use find_if_not to avoid confusing negative logic.
    auto r_itr = std::find_if_not (m_states.rbegin(), m_states.rend(), [](State_elem e) {return e.second->isTransparent();});
    // we gave find_if_not reverse iterators, it also gives us a reverse iterator. So we have to trick it:
    for (; r_itr != m_states.rbegin(); --r_itr)
    {
      r_itr -> second -> Draw();
    }
  }
  else
  {
    m_states.back().second->Draw();
  }
}



IMHO this code is self-explanatory, except for the little trick with the reverse iterators.

It might be possible to just say

auto r_itr = std::find_if_not (m_states.rbegin(), m_states.rend(), [](auto e) {return e.second -> isTransparent();});


and let the compiler figure out the type of the argument of the predicate.
The algorithm library works brilliantly with lambdas. Every new C++ programmer should learn about that. This also goes for the HasState function: it can be simplified a lot by using find_if. Use find_if to find the state in m_states and use find to find it in m_toRemove. If the state is found in m_states and not found in m_toRemove, the result is true. Otherwise the result is false.


bool StateManager::HasState(const StateType type)  // type is an int, just pass by value
{
  auto state = std::find_if (m_states.begin(), m_states.end(), [type](State_elem e) {return e.first == type;});
  auto remove = std::find(m_toRemove.begin(), m_toRemove.end(), type);
  if (state != m_states.end() && remove == m_toRemove.end())  // found in m_states, not found in m_toRemove
  {
    return true;
  }
  else
  {
    return false;
  }
}


4- The draw and update functions are almost identical. Duplicate code is Not Very Nice. The only differences are the functions calles (IsTransparent vs IsTranscendent, Draw vs Update). It should be possible to make a private helper function that does the searching and that accepts the functions that are used. I haven't worked this out yet. Probably it isn't worth the trouble in this simple case.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Stormik on April 17, 2018, 11:31:46 am
Hello,
first of all congratulations for the book, that is really well written.
Reading through chapter 5 I have encountered a problem, while the code works I cannot go past the intro state because the program doesn't recognize the input, and this problem is encountered both in my code and in the sample code and I don't understand why since the code in chapter 4 worked.
I'm using SFML 2.4.2.

Best regards

Michele
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on April 19, 2018, 03:24:53 am
Hello,
first of all congratulations for the book, that is really well written.
Reading through chapter 5 I have encountered a problem, while the code works I cannot go past the intro state because the program doesn't recognize the input, and this problem is encountered both in my code and in the sample code and I don't understand why since the code in chapter 4 worked.
I'm using SFML 2.4.2.

Best regards

Michele
I've sent you a PM back. I'll keep this thread updated on the issue and solution once more specifics come into play.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Dazedi on April 24, 2018, 02:46:20 am
Hello, I'm really enjoying the book. It's been such a long time since I've used C++ so this has worked nicely as a reminder as well!
Anyways, I got up to chapter 7 until I encountered a problem I just haven't been able to solve. Any help would be appreciated!

The problem is that when the map file is being read and the entityManager's Add is being called with EntityType::Player, it throws an exception at the first find in the function.
Exception is "Exception thrown: read access violation. **this** was 0x50"
I did a lot of googling and even tried directly copying some of the code from the provided files with no success.

Thanks! I look forward to being able to proceed with this project.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: kaim3lis on March 28, 2019, 03:16:58 pm
Hello,
first of all congratulations for the book, that is really well written.
Reading through chapter 5 I have encountered a problem, while the code works I cannot go past the intro state because the program doesn't recognize the input, and this problem is encountered both in my code and in the sample code and I don't understand why since the code in chapter 4 worked.
I'm using SFML 2.4.2.

Best regards

Michele

Hi guys. I also have the same problem. I hope someone could tell me how to fix it.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on April 14, 2019, 01:29:54 am
It sounds like that's a fairly common issue. Between different SFML version releases, the enums being used end up changing in value. The default keys.cfg file that comes with the projects uses "old" values. You'll have to look up the values you need in the enumeration and use those in your file instead.

Another common issue people have with loading files in general is the extensions. If you have your extensions hidden, even if you save a file as something like "keys.cfg" from your notepad, it will save as keys.cfg.txt, and since you have file extensions hidden, you won't see the difference. I'd suggest enabling the file extension visibility or using a more robust piece of software that doesn't assume a .txt file type.

Hello, I'm really enjoying the book. It's been such a long time since I've used C++ so this has worked nicely as a reminder as well!
Anyways, I got up to chapter 7 until I encountered a problem I just haven't been able to solve. Any help would be appreciated!

The problem is that when the map file is being read and the entityManager's Add is being called with EntityType::Player, it throws an exception at the first find in the function.
Exception is "Exception thrown: read access violation. **this** was 0x50"
I did a lot of googling and even tried directly copying some of the code from the provided files with no success.

Thanks! I look forward to being able to proceed with this project.

Is this happening with the unaltered code that was included? Can you include a snippet of the code that throws this error?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: mequint on May 24, 2019, 05:39:49 am
Hey OrderNexus,

Finally finishing up the Networking Portion of the book and I've run into a snag with the Chapter 14 code.  When I compile the code for the Client, I get the following errors everywhere an instance of the Shared Context is referenced.

Output (VS2017)
1>c:\src\sfml-2.4.2\include\sfml\network\sockethandle.hpp(46): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\src\sfml-2.4.2\include\sfml\network\sockethandle.hpp(46): error C2146: syntax error: missing ';' before identifier 'SocketHandle'
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(140): error C3646: 'getHandle': unknown override specifier
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(140): error C2059: syntax error: '('
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(140): error C2238: unexpected token(s) preceding ';'
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(159): error C2061: syntax error: identifier 'SocketHandle'
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(159): error C2535: 'void sf::Socket::create(void)': member function already defined or declared
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(148): note: see declaration of 'sf::Socket::create'
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(177): error C3646: 'm_socket': unknown override specifier
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(177): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

The culprit seems to be in the SocketHandle.hpp (SFML/Networking) with the following line of code:

#if defined(SFML_SYSTEM_WINDOWS)

    typedef UINT_PTR SocketHandle;

#else
 

I've determined that the problem is coming from the Client somewhere, and yet when I run the same code in Chapter 13, it works as intended.  Odd.

I was hoping to finish this chapter before moving onto your next book (Mastering SFML).

Q1: Any ideas how I can fix this?  Are there any changes you are aware of in SFML since 2.4 in Networking?
Q2: Is the Networking module for SFML needed in Mastering SFML?

I'd like to get the code working as intended

Thank you!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: mequint on December 01, 2019, 01:30:53 am
This is still a problem...it doesn't have anything to do with the Shared Context.  Something is wrong with the S_Network...the strange thing is that the Chapter 13 project works fine.

Furthermore, I'm seeing some other problems...there seems to be another error with Rect.inl in the API and this project.  Fortunately, it isn't necessary for the next book but it would be nice to get it implemented successfully.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: OrderNexus on December 01, 2019, 06:46:52 am
Hey OrderNexus,

Finally finishing up the Networking Portion of the book and I've run into a snag with the Chapter 14 code.  When I compile the code for the Client, I get the following errors everywhere an instance of the Shared Context is referenced.

Output (VS2017)
1>c:\src\sfml-2.4.2\include\sfml\network\sockethandle.hpp(46): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\src\sfml-2.4.2\include\sfml\network\sockethandle.hpp(46): error C2146: syntax error: missing ';' before identifier 'SocketHandle'
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(140): error C3646: 'getHandle': unknown override specifier
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(140): error C2059: syntax error: '('
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(140): error C2238: unexpected token(s) preceding ';'
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(159): error C2061: syntax error: identifier 'SocketHandle'
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(159): error C2535: 'void sf::Socket::create(void)': member function already defined or declared
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(148): note: see declaration of 'sf::Socket::create'
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(177): error C3646: 'm_socket': unknown override specifier
1>c:\src\sfml-2.4.2\include\sfml\network\socket.hpp(177): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

The culprit seems to be in the SocketHandle.hpp (SFML/Networking) with the following line of code:

#if defined(SFML_SYSTEM_WINDOWS)

    typedef UINT_PTR SocketHandle;

#else
 

I've determined that the problem is coming from the Client somewhere, and yet when I run the same code in Chapter 13, it works as intended.  Odd.

I was hoping to finish this chapter before moving onto your next book (Mastering SFML).

Q1: Any ideas how I can fix this?  Are there any changes you are aware of in SFML since 2.4 in Networking?
Q2: Is the Networking module for SFML needed in Mastering SFML?

I'd like to get the code working as intended

Thank you!

Q2: networking isn't covered at all in the "Mastering" title.


This is still a problem...it doesn't have anything to do with the Shared Context.  Something is wrong with the S_Network...the strange thing is that the Chapter 13 project works fine.

Furthermore, I'm seeing some other problems...there seems to be another error with Rect.inl in the API and this project.  Fortunately, it isn't necessary for the next book but it would be nice to get it implemented successfully.

If I had to guess at the moment (I don't have the source code available), I'd say this is probably some kind of include order issue. I vaguely recall running into something like this in conjunction with some windows-specific includes, specifically in "Utilities.h". I might be completely wrong, but I can't verify this at the moment. Does anyone else have memory of / experience with this type of issue?
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Grundkurs on October 27, 2020, 11:47:21 pm
Hi OrderNexus,
i may have discovered a subtle bug in the EventManager-Class.

EventManager.h
struct EventInfo{
        EventInfo(){ m_code = 0; }
        EventInfo(int l_event){ m_code = l_event; }
        EventInfo(const GUI_Event& l_guiEvent){ m_gui = l_guiEvent; }
        union {
                int m_code;
                GUI_Event m_gui;
        };
};
If no argument is passed to an EventInfo Constructor during Object-Creation, the EventInfo's default constructor is invoked which initializes the union member int m_code to 0. So when creating an EventInfo object with a default constructor you are not allowed to use the other union member (here m_gui), this would lead to undefined behaviour.

EventManager.cpp
void EventManager::LoadBindings(){
    ...
        EventInfo eventInfo;
        if (type == EventType::GUI_Click || type == EventType::GUI_Release ||
            type == EventType::GUI_Hover || type == EventType::GUI_Leave)
        {
               ...
        eventInfo.m_gui.m_interface = w;
        eventInfo.m_gui.m_element = e;
        }
 ....

in EventManager::LoadBindings() an EventInfo-object is created with a default constructor (EventInfo eventInfo). However further down below, if the EventType is some GUI-Type, the eventInfo.m_gui-variable is getting assigned to the data that is read from the config-file (here w & e). I consider this assignmeht as undefined since the created EventInfo-Object can only use the "int"-variable from its union-members. Or am i missing here something?

Title: Re: SFML Game Development by Example - 4th SFML book
Post by: Jack Lam on February 26, 2022, 02:49:05 pm
Really appreciate your work, thank you!
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: jamesnozyz on January 08, 2024, 01:11:34 pm
I'm at the beginning of Chapter 7 and just finished testing the Tile/Mapping classes. The background texture loads, but when I hit the close button or click the "exit" button on the main menu, I receive an exception. I believe the error is occurring because the Game object's deconstructor is called when the window closes, causing my SharedContext object to lose scope.
Title: Re: SFML Game Development by Example - 4th SFML book
Post by: dronycroin on January 21, 2024, 06:23:16 pm
I think I would probably consider a parameter to be passed from the outside though so "local" for something external seems odd to me. Of course, technically, if it's passed by value, that actual copy is only local but still...
Markomojo.com (https://markomojo.com/)