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

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

0 Members and 1 Guest are viewing this topic.

BM

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

OrderNexus

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

BM

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

OrderNexus

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

BM

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

OrderNexus

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

PewPew

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

OrderNexus

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

PewPew

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #113 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;
                                        }
« Last Edit: July 19, 2016, 07:43:07 am by PewPew »

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML Game Development by Example - 4th SFML book
« Reply #114 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 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

OrderNexus

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

PewPew

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

PewPew

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

PewPew

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

OrderNexus

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