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

Author Topic: SFML Game Development by Example - 4th SFML book  (Read 184216 times)

0 Members and 4 Guests are viewing this topic.

seyuup

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #45 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!

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #46 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! :)

seyuup

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #47 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.

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #48 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. :)

zmertens

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #49 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!
The truth will set you free but first it will piss you off.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: SFML Game Development by Example - 4th SFML book
« Reply #50 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.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #51 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.
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. :)

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #52 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
« Last Edit: February 04, 2016, 01:05:18 am by Nayk0_x »

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #53 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!

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #54 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)

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #55 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!

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #56 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

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #57 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 :)

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #58 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  :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML Game Development by Example - 4th SFML book
« Reply #59 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...

Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything