SFML community forums

Help => General => Topic started by: natchos on August 17, 2012, 12:00:09 am

Title: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 17, 2012, 12:00:09 am
So I'm back with another fairly stupid question :P

Is there a 2.0 equivalent to 1.6 sprite::GetSize() function, or is getGlobalBounds() the closest thing to that that we get?

I'm just wondering because I am in the middle of changing my project from 1.6 to 2.0, so I would just like to know, since it would change the structure of some crucial functions.(Not in a bad way, I just wonder whether I have to rewrite them :P)
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: eXpl0it3r on August 17, 2012, 12:21:33 am
Is there a 2.0 equivalent to 1.6 sprite::GetSize() function, or is getGlobalBounds() the closest thing to that that we get?
Why "closest thing"? getGlobal/LocalBounds() is the function for getting dimensions. ;)
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: natchos on August 17, 2012, 12:24:21 am
Aye, but it returns a rect whereas GetPosition returns a vector :P
Also localbounds returns the size, right? Whereas globalbounds return the size and position and rotation?

Thanks for the fast reply :)

EDIT: Sorry, meant GetSize
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: eXpl0it3r on August 17, 2012, 12:51:55 am
Aye, but it returns a rect whereas GetPosition returns a vector :P
Also localbounds returns the size, right? Whereas globalbounds return the size and position and rotation?
GetPosition has nothing to do with GetSize, there's still a getPosition() function. ;)
The local bounds will return a rect with top = left = 0 and the width and height of the initial sprite size, whereas the global bounds acctually represents more the bounding box of the sprite, i.e. it takes into account the rotation, scale and position. ;)
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: natchos on August 17, 2012, 12:54:45 am
Ya, sorry wrote wrong :) I meant GetSize, anyhow, thank you very much for the clarification.
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: natchos on August 17, 2012, 01:36:58 am
New question! :D
Is there any specific reason as to why sf::rect.offset() was removed from 2.0?

EDIT: Also, why the removal of Right and Bottom coordinates in a rect?
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: FRex on August 17, 2012, 01:42:36 am
I guess it's mostly qeustion for Laurent but I guess it's kind of useless/feature bloat and in 2.0 the rect is defined by left,top,width,height so if you want to move it, it's just 2 changes to left and top and in 1.6 it was defined by left,top,right,bottom so moving it would take 4 changes to each of these, which is a bit much already.

Edit: Again it's very Laurent focused question BUT it seems extremely unituitive to have right and bottom instead of width and height. And it makes getting width and height in 1.6 a pain if you're not careful and use two methods(2 more methods = more feature bloat).
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: natchos on August 17, 2012, 01:53:31 am
Ah yea, I see your point.

Still, now you have to change 2 values, instead of just calling a single function.
But I'm no expert on the inner workings of either Laurents mind or SFML, so I'll just accept the new classes as they are :)
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: Laurent on August 17, 2012, 07:56:56 am
sf::Rect members are public, so there's nothing you can't implement yourself on top of it -- like an offset function. Don't stop at what SFML directly provides, such functions are mostly for convenience (they don't bring new features), so add whatever is convenient for you ;)
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: natchos on August 17, 2012, 10:59:25 pm
So was Randomizer completely removed in 2.0? I can always construct my own randomizer, but if SFML already has one I see no reason to make my own instead of adding to the existing one.
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: Laurent on August 17, 2012, 11:07:40 pm
Quote
So was Randomizer completely removed in 2.0?
Yes. It was nothing more than a very thin wrapper around std::rand.
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: natchos on August 17, 2012, 11:08:22 pm
Aight, I'll get to making my own then :D
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: natchos on August 17, 2012, 11:40:46 pm
Time for next question :D

Why was getFrameTime removed? Feature bloat? Is there any good way to get the frame time?

EDIT: Can sf::RenderWindow::pollEvent in 2.0 be used in a similar way to sf::RenderWindow::GetInput from 1.6?
EDIT2: Nope it cannot I saw now. How should you handle inputs in 2.0?
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: eXpl0it3r on August 18, 2012, 01:09:28 am
Why was getFrameTime removed? Feature bloat? Is there any good way to get the frame time?
It was a design decision; it's actually a bit too highlevel and can get easily implemented with a sf::Clock:
sf::Clock clock;
float dt = 0.f;
while(window.isOpen())
{
    dt = clock.restart().asSeconds();
    // ...
}

Nope it cannot I saw now. How should you handle inputs in 2.0?
The Input class got replaced by the three classes sf::Mouse, sf::Keyboard and sf::Joystick. See the documentation and/or tutorials for more information on the usage. ;)
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: natchos on August 18, 2012, 08:51:02 am
Alright I will. Thank you for the helpful reply :)

EDIT: How do you check for a released key?
Since sf::Keyboard::"key" returns a bool on whether it is pressed or not, how do you check for a released key as opposed to a key which was never pressed?
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: natchos on August 18, 2012, 09:17:01 am
Ok so I am using a fairly standard looped switch statement to poll/get events, how do I check for released keys?

It looks like this
                        while(App.pollEvent(Event))
                        {
                                switch(Event.Type)
                                {
                                case sf::Event::Closed:
                                        App.Close();
                                        break;
                                case sf::Event::EventType::KeyPressed:
                                        switch(sf::Keyboard::isKeyPressed)
                                        {
                                        case sf::Keyboard::isKeyPressed(sf::Keyboard::Left):
                                                theEye.move(-PlayerMove,0);
                                                break;
                                        case sf::Keyboard::isKeyPressed(sf::Keyboard::Right):
                                                theEye.move(PlayerMove,0);
                                        case sf::Keyboard::Escape:
                                                App.Close();
                                                break;
                                        case sf::Keyboard::isKeyPressed(sf::Keyboard::Space):
                                                 startingposition = Jump(pYVel,pJumped,ptheEye, ElapsedTime);
                                                 break;
                                        }
                                case sf::EventType::KeyReleased:
                                        switch(sf::Event::)
                                        {
                                        case sf::Keyboard::Left:
                                        case sf::Keyboard::Right:
                                                break;
                                        case sf::Key::Down:
                                                YReduceVelocity = 1;
                                                break;
                                        }
                                        break;
                        }
                }

The last portion is unfinished because I don't understand how to check for released keys.

EDIT: Just thought of something, could you case a false return? something like case !sf::Key::Down?
Trying that now.
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: eXpl0it3r on August 18, 2012, 09:48:42 am
Since sf::Keyboard::"key" returns a bool
It does not, sf::Keyboard::isKeyPressed(key) does return a boolean. ;)
There are multiple ways to do it, an easy one would be to use the event system which has a KeyReleased event.
Another way would be to use a boolean and set it to true when isKeyPressed() returns true and as soon as it returns false and the boolean is set to true, you know the key got released.
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: natchos on August 18, 2012, 10:00:17 am
Aye, but can you differentiate between different keys being released or pressed simultaneously?

Also, I've begun delving in the new sf::clock code.
In 1.6 I constructed my own stopwatch clock, since sf::clock doesn't offer that, however I used float, which doesn't have all the precision I need.

Therefore, I was just wondering is there any way that you can get m_startTime directly, or do you have to create your own at initialization? I am hesitant to do that, since I generally use timeGetTime, and I'm not sure whether it is as accurate as the default m_startTime value that it gets in the sf::Clock ctor.
Title: Re: sfml 1.6 sprite::GetSize equivalent?
Post by: eXpl0it3r on August 18, 2012, 10:36:42 am
Aye, but can you differentiate between different keys being released or pressed simultaneously?
Yes either with the event system (not recommended for key press events, since they only get triggered within a certain interval) or with multiple booleans that tell if a key is still being pressed or if once should call release.
For example
bool keyA = false;
while(window.isOpen())
{
    // Event handling
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
    {
        // Do stuff with key pressed
        keyA = true;
    }
    else if(keyA = true)
    {
        // Do stuff with key released
        keyA = false;
    }
    else
    {
        // Maybe do stuff if key is not pressed nor released
    }


Therefore, I was just wondering is there any way that you can get m_startTime directly, or do you have to create your own at initialization? I am hesitant to do that, since I generally use timeGetTime, and I'm not sure whether it is as accurate as the default m_startTime value that it gets in the sf::Clock ctor.
No there's no way to catch private internal varibles but you can use a sf::Time object and get time from the clock. With the sf::Time class you won't lose precision and you can always decide whether you want to have the result as seconds, milliseconds or microseconds. But keep in mind the sf::Clock is only as precice as the underlying system's "timer".

If this is no solution for you, you could take a look at SFML corssplatform implementation of the sf::Clock and copy it for your porject, but this won't be a trivial task if you don't know your way around building scripts... ;)

Btw: Since you started ask various questions could you maybe update the title of your first post and add something like " and other questions", so one does not get confused. :D
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 18, 2012, 03:18:43 pm
Alright. Kind of seems like a two steps forward one step back approach to input but I should be able to fashion something for my needs.

As to the answer to my clock question, do you mean something like this

class Stopclock : public sf::clock
private:
sf::Time start_time
Stopclock::Stopclock()
{
start_time = this->getElapsedTime()
}
 
or is there a better way to do it?
Also, is sf::clock more accurate than timeGetTime? Else I'll just stick with my old clock I suppose, since it's been accurate enough sofar.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: Nexus on August 18, 2012, 04:28:38 pm
What do you exactly want to achieve? If you need a pausable clock, you can take a look at thor::StopWatch (http://www.bromeon.ch/libraries/thor/v2.0/doc/classthor_1_1_stop_watch.html) in my library Thor, which works for SFML 2.

By the way, please open separate threads for separate topics.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: eXpl0it3r on August 18, 2012, 04:38:43 pm
Alright. Kind of seems like a two steps forward one step back approach to input but I should be able to fashion something for my needs.
What are you trying to do? Maybe there's a better way of handling things.

As to the answer to my clock question, do you mean something like this
No sf::Clock is not designed for a parent class. You can use an sf::Clock internally. For example you have the functions Start() and Check(). In the Start() function your querying the clock for a time and save it into a sf::Time, now whenever Check() is called you can compaire the save time with the current clock time and the difference makes the runtime. Implementing Stop(), Pause() and Resume() won't be much harder. ;)

Also, is sf::clock more accurate than timeGetTime? Else I'll just stick with my old clock I suppose, since it's been accurate enough sofar.
I don't really remember what SFML uses internally but I think for POSIX system it's using timeGetTime, so it will be equal, but using your own function calls to OS APIs will make your class non-portable and since you already got a nice layer with sf::Clock it's also not very logical to use your own calls. ;)
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: binary1248 on August 18, 2012, 05:33:53 pm
Also, is sf::clock more accurate than timeGetTime? Else I'll just stick with my old clock I suppose, since it's been accurate enough sofar.
I don't really remember what SFML uses internally but I think for POSIX system it's using timeGetTime, so it will be equal, but using your own function calls to OS APIs will make your class non-portable and since you already got a nice layer with sf::Clock it's also not very logical to use your own calls. ;)
On Windows it uses QueryPerformanceCounter and QueryPerformanceFrequency which should get you the highest precision available on your hardware. On Mac OS X it is based on mach_absolute_time which also makes use of CPU counters and should get you the highest precision available on your hardware. On all other POSIX compliant systems (incl. Linux) it uses clock_gettime which has differing amounts of precision depending on the timers available for your hardware/kernel, most of the time and with newer hardware you can be sure it is in the nanosecond area. Just remember all these precision values are theoretical and clocks are always subject to inherent skew and so many other factors it isn't worth it to try to get an exact value. Therefore using one high-resolution timer over another should just be a matter of interface preference and not accuracy. And as eXpl0it3r already said, using sf::Clock is a free-of-charge guarantee that your code will work on almost all systems out of the box.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 18, 2012, 08:32:30 pm
What do you exactly want to achieve? If you need a pausable clock, you can take a look at thor::StopWatch (http://www.bromeon.ch/libraries/thor/v2.0/doc/classthor_1_1_stop_watch.html) in my library Thor, which works for SFML 2.

By the way, please open separate threads for separate topics.

I use C++ 2008 which is why I do not use Thor, and I have no plans of doing so in the near future.
I would open seperate threads, yet I felt that it was unnecesary to flood the general board with 5 different topics which all pertained to the transition between 1.6 and 2.0.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: eXpl0it3r on August 18, 2012, 08:41:48 pm
I use C++ 2008
There's no such thing as C++ 2008. There's C++98, C++03 and C++11. ;)
Also you essentially don't need to use Thor but you could take a look at its source code and if you think the code does fit your needs you can just copy it. ;)
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 19, 2012, 01:36:49 pm
I use C++ 2008
There's no such thing as C++ 2008. There's C++98, C++03 and C++11. ;)
Also you essentially don't need to use Thor but you could take a look at its source code and if you think the code does fit your needs you can just copy it. ;)

Meant Visual C++ 2008, which as far as I know does not use C++ 11
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 19, 2012, 10:14:23 pm
Alright. Kind of seems like a two steps forward one step back approach to input but I should be able to fashion something for my needs.
What are you trying to do? Maybe there's a better way of handling things.
I merely meant that since the code needed to check for a key being released was implemented in 1.6 it seems like a rather odd design decision to remove that inherent feature.

As to the answer to my clock question, do you mean something like this
No sf::Clock is not designed for a parent class. You can use an sf::Clock internally. For example you have the functions Start() and Check(). In the Start() function your querying the clock for a time and save it into a sf::Time, now whenever Check() is called you can compaire the save time with the current clock time and the difference makes the runtime. Implementing Stop(), Pause() and Resume() won't be much harder. ;)

Also, is sf::clock more accurate than timeGetTime? Else I'll just stick with my old clock I suppose, since it's been accurate enough sofar.
I don't really remember what SFML uses internally but I think for POSIX system it's using timeGetTime, so it will be equal, but using your own function calls to OS APIs will make your class non-portable and since you already got a nice layer with sf::Clock it's also not very logical to use your own calls. ;)

Well yes, but sf::clock is fairly useless on it's own except for very rudimentary timing tasks. That's why I will most likely be constructing my own stopwatch.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: Laurent on August 19, 2012, 10:24:23 pm
Quote
I merely meant that since the code needed to check for a key being released was implemented in 1.6 it seems like a rather odd design decision to remove that inherent feature.
Nothing was removed. With both SFML 1.6 and SFML 2.0 you have two things:
- the key-released event: sf::Event::KeyReleased (same in both versions)
- the key-released state: !sf::Keyboard::isKeyPressed(key) (SFML 2.0), !window.GetInput().IsKeyDown(key) (SFML 1.6)
So what do you mean?
(sorry if I missed something, I didn't read the middle of this thread)

Quote
Well yes, but sf::clock is fairly useless on it's own except for very rudimentary timing tasks. That's why I will most likely be constructing my own stopwatch.
sf::Clock is not meant to be the final powerful timing class. But it provides a solid base for timing (best resolution and monotonicity), then it's up to you to add whatever high-level feature that you need on top of it.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 19, 2012, 11:36:26 pm
In 1.6 you could directly check for released keys using
sf::Event::KeyReleased
atleast, I would assume that was what it did?

And yes I know that sf::Clock is meant to be built upon, I was merely trying to find a reason as to why I should use sf::Clock, instead of constructing my own using timeGetTime(), since I prefer a clock where I can access the start time directly, should that be necessary.
Now that binary so kindly supplied me with the information that sf::Clock should be more accurate than timeGetTime(), I will be building a clock class with an internal sf::Clock.

EDIT: One other feature which I feel that a clock needs is the ability to not only return elapsed time but also current time. That's what basically makes sf::clock not a completely perfect choice for me.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: eXpl0it3r on August 19, 2012, 11:40:51 pm
In 1.6 you could directly check for released keys using
sf::Event::KeyReleased
atleast, I would assume that was what it did?
You still can check for KeyRelease that's the event system we've been refering to all the time (and which is already explained in the official SFML 2 tutorial...):
while(window.isOpen())
{
    sf::Event event;
    while(window.pollEvent(event))
    {
        if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::A)
            std::cout << "The key A was released!" << std::endl;
    }
}

Now that binary so kindly supplied me with the information that sf::Clock should be more accurate than timeGetTime(), I will be building a clock class with an internal sf::Clock.
Not only that it's also more crossplatform. ;)

One other feature which I feel that a clock needs is the ability to not only return elapsed time but also current time. That's what basically makes sf::clock not a completely perfect choice for me.
Date/time handling is already provided through the standard (ctime header (http://www.cplusplus.com/reference/clibrary/ctime/)), thus having this in SFML would be redundant and creating a date/time class is extremly hard if you want to satisfy everyone thus it's better to let such higherlevel wrapping to the user or they can choose other existing classes/libraries. ;)
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 19, 2012, 11:44:25 pm
In 1.6 you could directly check for released keys using
sf::Event::KeyReleased
atleast, I would assume that was what it did?
You still can check for KeyRelease that's the event system we've been refering to all the time (and which is already explained in the official SFML 2 tutorial...):
while(window.isOpen())
{
    sf::Event event;
    while(window.pollEvent(event))
    {
        if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::A)
            std::cout << "The key A was released!" << std::endl;
    }
}

Now that binary so kindly supplied me with the information that sf::Clock should be more accurate than timeGetTime(), I will be building a clock class with an internal sf::Clock.
Not only that it's also more crossplatform. ;)

Ah you see if you had thrown this solution to me at the start I would never have continued badgering you. :)

I read the tutorial but obviously I must have missed that section. Very truly sorry. You can believe that I am thoroughly embarrassed right now.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 20, 2012, 12:10:53 am
snip
Quote
Well yes, but sf::clock is fairly useless on it's own except for very rudimentary timing tasks. That's why I will most likely be constructing my own stopwatch.
sf::Clock is not meant to be the final powerful timing class. But it provides a solid base for timing (best resolution and monotonicity), then it's up to you to add whatever high-level feature that you need on top of it.

But why is there no direct accessor to the m_startTime variable? Having it available through a interface would make it vastly easier for less experienced and skillful programmers (such as myself) to build upon. Just throwing it out there.

Also; expl0it3r, are sf::time and time_t (as returned by time function from time.h) comparable or easily converitble? If they are not, that would be another reason as to why sf::time should include a getCurrentTime function, since being able comparing elapsed time to current time is something that I personally would find to be useful in some timing functions.
EDIT: Nevermind. I found that the time function in ctime returns the time in seconds lol.
Anyhow, after googling around a bit I've found that I'd rather go for timeGetTime and sf::Clock, and forgo accuracy and crossplatforming for reliability and easier programming. Also QPC seems to have it's own fair share of bugs, at least according to the internet.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: eXpl0it3r on August 20, 2012, 12:35:11 am
But why is there no direct accessor to the m_startTime variable? Having it available through a interface would make it vastly easier for less experienced and skillful programmers (such as myself) to build upon. Just throwing it out there.
Because it would be a bad design decision and just because it could be easier for a few particuallar chases it doesn't justify the spoiling of the variable to derived classes.
It's anyways better as I already said to use a sf::Clock as memeber variable instead of deriving from it. ;)

Also; expl0it3r, are sf::time and time_t (as returned by time function from time.h) comparable or easily converitble? If they are not, that would be another reason as to why sf::time should include a getCurrentTime function, since being able comparing elapsed time to current time is something that I personally would find to be useful in some timing functions.
sf::Time and sf::Clock do not have anything to do with date/time. ;)
sf::Time is just a class for representing a time interval and provides an interface to return the time either as seconds, milliseconds or microseconds, whereas sf::Clock is just a class that 'enlarges' the time intervall starting from some given point (= up on creation or when calling restart()).
Although the actual type of time_t isn't specified it's mostly a "integral value holding the number of seconds since 00:00, Jan 1 1970 UTC" (source (http://en.cppreference.com/w/cpp/chrono/c/time_t)) thus you can use the function sf::seconds(static_cast<float>(time_t)) to get a sf::Time object with the interval from 00:00, Jan 1 1970 UTC.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 20, 2012, 01:01:53 am
But why is there no direct accessor to the m_startTime variable? Having it available through a interface would make it vastly easier for less experienced and skillful programmers (such as myself) to build upon. Just throwing it out there.
Because it would be a bad design decision and just because it could be easier for a few particuallar chases it doesn't justify the spoiling of the variable to derived classes.
It's anyways better as I already said to use a sf::Clock as memeber variable instead of deriving from it. ;)

Yes, but why would having a function like
sf::Time getStartTime()
{
return m_startTime;
}
ruin the class?
No matter if you have it as a member or a parent class m_startTime is completely inaccessible.
Also; expl0it3r, are sf::time and time_t (as returned by time function from time.h) comparable or easily converitble? If they are not, that would be another reason as to why sf::time should include a getCurrentTime function, since being able comparing elapsed time to current time is something that I personally would find to be useful in some timing functions.
sf::Time and sf::Clock do not have anything to do with date/time. ;)
sf::Time is just a class for representing a time interval and provides an interface to return the time either as seconds, milliseconds or microseconds, whereas sf::Clock is just a class that 'enlarges' the time intervall starting from some given point (= up on creation or when calling restart()).
Although the actual type of time_t isn't specified it's mostly a "integral value holding the number of seconds since 00:00, Jan 1 1970 UTC" (source (http://en.cppreference.com/w/cpp/chrono/c/time_t)) thus you can use the function sf::seconds(static_cast<float>(time_t)) to get a sf::Time object with the interval from 00:00, Jan 1 1970 UTC.

Yes, but if I would need to accurately get the "current time" in a form that at least has a resolution of 5 milliseconds?

I'll post the old code I used for timing and then if you can give me a better way of doing it, I promise I'll go away and never mentions clocks again(except in praise :D).

class SPClock
        {
        private:
                sf::Time timer_start;
                sf::Time stopwatch_start;
                bool paused;
        public:

                SPClock(void)
                {
                        timer_start = timeGetTime();
                        reset();
                }

                float getTimer()
                {
                        return (float) (timeGetTime());
                }

                void sleep(int ms)
                {
                        Time sleep_start = sf::milliseconds(timeGetTime());
                        Time msperiod = sf::milliseconds(ms);
                        while (sleep_start + msperiod > my_Clock.getElapsedTime());
                }

                void reset()
                {
                        my_Clock.restart();
                        stopwatch_start = sf::milliseconds(timeGetTime());
                        paused = false;
                }

                bool stopwatch(int ms)
                {
                        if ( my_Clock.getElapsedTime() > stopwatch_start + sf::milliseconds(ms) )
                        {
                                stopwatch_start = my_Clock.getElapsedTime();
                                if(paused) paused = false;
                                return true;
                        }
                        else
                        {
                                return false;                  
                        }
                }

}

I know that the code isn't good, and that float isn't really accurate enough, but it's worked decently sofar. Now is there any smoother/easier way to do it with sf::Clock or a class which doesn't access any kind current time variable?
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: Laurent on August 20, 2012, 08:33:05 pm
Quote
But why is there no direct accessor to the m_startTime variable?
And what do you want to do with it? It has no special meaning, it's only purpose is to calculate the elapsed time.

Quote
If they are not, that would be another reason as to why sf::time should include a getCurrentTime function, since being able comparing elapsed time to current time is something that I personally would find to be useful in some timing functions.
As the doc and tutorials explain it, sf::Time is a time span, not an absolute date-time. So there's no such thing as a "current" sf::Time.

Quote
Yes, but if I would need to accurately get the "current time" in a form that at least has a resolution of 5 milliseconds?
What do you want to do with the "current time" ? Usually it's not a useful information, all you need are time spans. Especially if you need it with such a low resolution. It doesn't make sense.

I have the feeling that, for you, "current time" is what timeGetTime() returns. For me, it's more "monday 20 august, 20:34:56 and 568 milliseconds". The time returned by timeGetTime() is just a time span relative to the last boot of the PC.
So in fact what you need is a function that returns time values all relative to the same time point, right? In this case it's not hard to do.
sf::Time now()
{
    static sf::Clock clock;
    return clock.getElapsedTime();
}
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 21, 2012, 12:20:33 am
Quote
But why is there no direct accessor to the m_startTime variable?
And what do you want to do with it? It has no special meaning, it's only purpose is to calculate the elapsed time.

Quote
If they are not, that would be another reason as to why sf::time should include a getCurrentTime function, since being able comparing elapsed time to current time is something that I personally would find to be useful in some timing functions.
As the doc and tutorials explain it, sf::Time is a time span, not an absolute date-time. So there's no such thing as a "current" sf::Time.

Quote
Yes, but if I would need to accurately get the "current time" in a form that at least has a resolution of 5 milliseconds?
What do you want to do with the "current time" ? Usually it's not a useful information, all you need are time spans. Especially if you need it with such a low resolution. It doesn't make sense.

I have the feeling that, for you, "current time" is what timeGetTime() returns. For me, it's more "monday 20 august, 20:34:56 and 568 milliseconds". The time returned by timeGetTime() is just a time span relative to the last boot of the PC.
So in fact what you need is a function that returns time values all relative to the same time point, right? In this case it's not hard to do.
sf::Time now()
{
    static sf::Clock clock;
    return clock.getElapsedTime();
}

Fair enough. I was wrong. I was frustrated because I had to go over 500+ errors from switch from 1.6 to 2.0. Now the change is almost done.
I've only got 23 errors, and all of those are relating to the same thing.

Namely that fact that VC++ 2008 has decided that my clock class is missing a ; somewhere.
AND I JUST CANT FIND THE BUGGERING LINE. I've removed every single call inside of every single function. I've split the class, I've put a ; at the end of every function and double-checked all calls so that they are correct. I've even rewritten the entire innards of the class. So I know that this is a big favour, but could someone please try my clock, and see why it refuses to work?

#pragma once
#include "SFML\System\Clock.hpp"
#include "SFML\System\Time.hpp"
#include "SFML\System\Export.hpp"

namespace sf{

        class SPClock
        {
        private:
                sf::Time stopwatch_start;
                sf::Time sleep_start;
                bool paused;
                sf::Clock my_Clock;
        public:
        SPClock::SPClock(void)
        {
                        stopwatch_start = my_Clock.getElapsedTime();
        }
        SPClock::~SPClock(void)
        {
        }


        sf::Time SPClock::GetElapsedTime()
                {
                        my_Clock.getElapsedTime();
                }

        void SPClock::sleep(int ms)
                {
                        sleep_start = my_Clock.getElapsedTime();
                        Time msperiod = sf::milliseconds(ms);
                        while (sleep_start + msperiod > my_Clock.getElapsedTime());
                }

        void SPClock::reset()
                {
                        my_Clock.restart();
                        stopwatch_start = my_Clock.getElapsedTime();
                        paused = false;
                }

        void SPClock::Pause(void)
                {
                        // If not yet paused...
                        if (!paused)
                        {
                                paused = true;
                                stopwatch_start += my_Clock.getElapsedTime();
                        }
                }
        void SPClock::UnPause(void)
                {
                        if (paused)
                        {
                                paused = false;
                        }
                }

        bool SPClock::stopwatch(int ms)
                {
                        if ( my_Clock.getElapsedTime() > stopwatch_start + sf::milliseconds(ms) )
                        {
                                stopwatch_start = my_Clock.getElapsedTime();
                                if(paused) paused = false;
                                return true;
                        }
                        else
                        {
                                return false;                  
                        }
                }

        bool SPClock::IsPaused()
                {
                        return paused;
                }
        };
}
 
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: eXpl0it3r on August 21, 2012, 12:29:20 am
Works perfectly on my end... ;)

As a hint for the sleep function, SFML comes with a sf::sleep(sf::Time) function, which is not implemented as busy-waiting loop, thus it doesn't waste CPU time. ;)
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 21, 2012, 12:42:50 am
Works perfectly on my end... ;)

As a hint for the sleep function, SFML comes with a sf::sleep(sf::Time) function, which is not implemented as busy-waiting loop, thus it doesn't waste CPU time. ;)

Sweet... I wonder what is wrong on my end then :C

anyhow I changed the sleep function to
        void  sleep(int ms)
                {
                        sf::sleep(sf::milliseconds(ms));
                }

Anyhow, should I redownload SFML, reinstall Visual C++ 2008 or just wreck my computer? ^^
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: eXpl0it3r on August 21, 2012, 12:47:58 am
Anyhow, should I redownload SFML, reinstall Visual C++ 2008 or just wreck my computer? ^^
Throwing the PC out of the window is always a solution, eventhough not the best one... :D
So maybe you could provide more details on the actual error messages you get and/or maybe zip everything up (the project file etc) and upload it somewhere so one can take a look at it.
Is there a specific reason why you're still using such an old IDE as 2008? I mean there's VS10 express... ;)
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 21, 2012, 12:53:01 am
Anyhow, should I redownload SFML, reinstall Visual C++ 2008 or just wreck my computer? ^^
Throwing the PC out of the window is always a solution, eventhough not the best one... :D
So maybe you could provide more details on the actual error messages you get and/or maybe zip everything up (the project file etc) and upload it somewhere so one can take a look at it.
Is there a specific reason why you're still using such an old IDE as 2008? I mean there's VS10 express... ;)

I get 23 error messages. Here is the build output.

 1>------ Build started: Project: New Game, Configuration: Debug Win32 ------
1>Compiling...
1>Block.cpp
1>gEntity.cpp
1>main.cpp
1>c:\users\admin\desktop\small game\new game\randomizer.cpp(7) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(87) : warning C4227: anachronism used : qualifiers on reference are ignored
1>c:\users\admin\desktop\small game\new game\main.cpp(120) : warning C4227: anachronism used : qualifiers on reference are ignored
1>c:\users\admin\desktop\small game\new game\main.cpp(134) : error C2146: syntax error : missing ';' before identifier 'JumpClock'
1>c:\users\admin\desktop\small game\new game\main.cpp(134) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\admin\desktop\small game\new game\main.cpp(134) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\admin\desktop\small game\new game\main.cpp(144) : error C2146: syntax error : missing ';' before identifier 'Stopwatch'
1>c:\users\admin\desktop\small game\new game\main.cpp(144) : error C2065: 'Stopwatch' : undeclared identifier
1>c:\users\admin\desktop\small game\new game\main.cpp(145) : error C2065: 'pStopwatch' : undeclared identifier
1>c:\users\admin\desktop\small game\new game\main.cpp(145) : error C2065: 'Stopwatch' : undeclared identifier
1>c:\users\admin\desktop\small game\new game\main.cpp(148) : warning C4244: 'argument' : conversion from 'const int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(148) : warning C4244: 'argument' : conversion from 'const int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(149) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(149) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(225) : error C2065: 'Stopwatch' : undeclared identifier
1>c:\users\admin\desktop\small game\new game\main.cpp(225) : error C2228: left of '.reset' must have class/struct/union
1>        type is ''unknown-type''
1>c:\users\admin\desktop\small game\new game\main.cpp(226) : error C2228: left of '.reset' must have class/struct/union
1>        type is 'int'
1>c:\users\admin\desktop\small game\new game\main.cpp(227) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(227) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(232) : error C2146: syntax error : missing ';' before identifier 'FrameClock'
1>c:\users\admin\desktop\small game\new game\main.cpp(232) : error C2065: 'FrameClock' : undeclared identifier
1>c:\users\admin\desktop\small game\new game\main.cpp(233) : error C2065: 'FrameClock' : undeclared identifier
1>c:\users\admin\desktop\small game\new game\main.cpp(233) : error C2228: left of '.restart' must have class/struct/union
1>        type is ''unknown-type''
1>c:\users\admin\desktop\small game\new game\main.cpp(233) : error C2228: left of '.asSeconds' must have class/struct/union
1>c:\users\admin\desktop\small game\new game\main.cpp(238) : error C2065: 'Stopwatch' : undeclared identifier
1>c:\users\admin\desktop\small game\new game\main.cpp(238) : error C2228: left of '.getElapsedSecs' must have class/struct/union
1>        type is ''unknown-type''
1>c:\users\admin\desktop\small game\new game\main.cpp(288) : warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(289) : warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(308) : error C2065: 'FrameClock' : undeclared identifier
1>c:\users\admin\desktop\small game\new game\main.cpp(308) : error C2228: left of '.reset' must have class/struct/union
1>        type is ''unknown-type''
1>c:\users\admin\desktop\small game\new game\main.cpp(308) : error C2228: left of '.asSeconds' must have class/struct/union
1>c:\users\admin\desktop\small game\new game\main.cpp(383) : error C2228: left of '.reset' must have class/struct/union
1>        type is 'int'
1>c:\users\admin\desktop\small game\new game\main.cpp(400) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(400) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(405) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(405) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(410) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(410) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(445) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(445) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(454) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(454) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(462) : error C2228: left of '.GetElapsedMillis' must have class/struct/union
1>        type is 'int'
1>c:\users\admin\desktop\small game\new game\main.cpp(462) : error C2228: left of '.asMilliseconds' must have class/struct/union
1>c:\users\admin\desktop\small game\new game\main.cpp(465) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(465) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(475) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(475) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(517) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(517) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(683) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(683) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(691) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(691) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(695) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(695) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(695) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(695) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(700) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(700) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(704) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(704) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(704) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>c:\users\admin\desktop\small game\new game\main.cpp(704) : warning C4244: 'argument' : conversion from 'unsigned int' to 'float', possible loss of data
1>physics.cpp
1>Watch.cpp
1>Generating Code...
1>Build log was saved at "file://c:\Users\Admin\Desktop\Small Game\New Game\Debug\BuildLog.htm"
1>New Game - 23 error(s), 41 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I'm mostly using 2008 out of laziness I suppose. Hitherto I have simply not found a compelling reason to upgrade to vs2010.

I've got a zipped project now ^^ can you post files directly here/send through PM or should I go find a uploader/downloader site.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: eXpl0it3r on August 21, 2012, 01:04:18 am
Well most of them are 'just' conversion warnings and there are quite a few other problems like undeclared variables etc...
The "error C2146: syntax error : missing ';' before identifier 'JumpClock'" is often just any syntax error...

Quote
I've got a zipped project now ^^ can you post files directly here/send through PM or should I go find a uploader/downloader site.
If the file is under 128kb then you could add it to the post, otherwise you'll have to use an external website. (Unfortunatly the creater of sfmluploads.org didn't want to hand over his scripts so someone else could've carried on his work... >:( )
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 21, 2012, 01:09:57 am
Yah the warnings aren't bad.

However all (and I do mean all) errors are from declaring or using watch/clock objects.

1>c:\users\admin\desktop\small game\new game\main.cpp(134) : error C2146: syntax error : missing ';' before identifier 'JumpClock'

comes from this line

Watch JumpClock;

Watch is the name of class.
I have a hard time of seeing what the hell the error could be except the Watch class implementation. Aaaaaaanyhow, the folder is some 15 mbs.

Do you have a google account with drive on? If so I think that you can directly transfer/share files.

EDIT: Just remembered that you probs don't need the art files (or really, anything except the code)
EDIT2: Welp just the code clocks in at a solid 4000 kb so I might aswell give you the whole thing with art and all.
EDIT3: Going to bed now. I'll share/upload in the morning.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 21, 2012, 10:52:01 am
I fixed the problem.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: eXpl0it3r on August 21, 2012, 11:51:22 am
I fixed the problem.
Yeah your Watch class is inside a the sf namespace...

Man you should really take a look at other existing source codebases. There's quite a mess in your code. :-\

I hope those few points help you to get a nicer codebase. ;)
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 21, 2012, 03:46:16 pm
I will try to implement your suggestions.

I am pretty sure that I have setup SFML 2.0 incorrectly, because I am getting some 13 linking errors.
Should you or should you not "compile" sfml 2.0 rc with cmake? If so how? When I tried to, I got this error:
CMake Error: The source directory "C:/Users/Admin/Desktop/Small Game/SFML-2.0-rc" does not appear to contain CMakeLists.txt.

Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: eXpl0it3r on August 21, 2012, 03:52:48 pm
I am pretty sure that I have setup SFML 2.0 incorrectly, because I am getting some 13 linking errors.
If you follow the tutorial  (http://www.sfml-dev.org/tutorials/2.0/start-vc.php)step by step it should work. ;)

Should you or should you not "compile" sfml 2.0 rc with cmake? If so how? When I tried to, I got this error:
CMake Error: The source directory "C:/Users/Admin/Desktop/Small Game/SFML-2.0-rc" does not appear to contain CMakeLists.txt.
You either use the provided binaries with the SFML RC release or you get the source and build it yourself.
If you want to build SFML on your own with CMake then you'll have to get the source directly from GitHub (https://github.com/SFML/SFML). ;)
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 21, 2012, 04:36:42 pm
Fixed :D I'm so close to it compiling ( I think).
One last error (I think).

1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Randomizer::~Randomizer(void)" (??1Randomizer@@QAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'theRandom''(void)" (??__FtheRandom@@YAXXZ)

I have no clue what the error message is supposed to tell me.
Randomizer is my own class which I constructed to generate random numbers.
The words "dynamic atexit destructor" had me thinking that the fault was in the destructor function, but it seems fine to me(it's just an empty destructor).
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: eXpl0it3r on August 21, 2012, 04:40:07 pm
The problem is although you declare a destructor you don't define it. Your code looks like this:
~Randomizer();
Now either you just delete it, since it isn't needed anyways and the compiler will generate a default destructor or you change to:
~Randomizer() {}
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 21, 2012, 04:55:36 pm
The problem is although you declare a destructor you don't define it. Your code looks like this:
~Randomizer();
Now either you just delete it, since it isn't needed anyways and the compiler will generate a default destructor or you change to:
~Randomizer() {}

Aye I thought of that first and changed it into
~Randomizer() {}
it still doesn't work.

EDIT: Also tried deleting it. Didn't work either.
Title: Re: sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
Post by: natchos on August 21, 2012, 05:00:52 pm
Whelp, I changed from linking to static to linking to dynamic. That fixed it.