31
SFML projects / Airport
« on: October 19, 2011, 12:21:38 am »Quote from: "Naufr4g0"
I also think that the game is very fun and original!
Maybe not as original as you think have you seen this?
Been playing it for a few years now
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
I also think that the game is very fun and original!
You also should declare the static members outside the class.
Foo.cppCode: [Select]sf::Image Foo::image;
sf::Sprite Foo::sprite;
class Foo {
private:
static sf::Image image;
static sf::Sprite sprite;
}
sf::Image Foo::image;
sf::Sprite Foo::sprite;
Maybe I am wrong, but your "temp" sf::Texture goes out of scope, doesn't it ? When that happens the sf::Texture* objects in your map are pointing to non-existent objects. And then you iterate through the map and try to delete an invalid pointer.
if( temp->LoadFromFile(fileName) == false )
return false;
if( temp->LoadFromFile(fileName) == false ) {
delete temp;
return false;
}
I would even say the best approach is to keep it as local as possible, i.e. inside the loop. Then it is clear where the variable is used, code becomes more readable, and it can not happen that it is accidentally accessed outside the loop.
The construction and destruction of a sf::Event requires no time, as stated above it is a POD type.
...
As already mentioned, you should always declare variables as local and as late as possible, except if there is a good reason not to do so
void SomeFunction () {
some code here
SomeType temporaryObject;
for(int i = 1; i <= n; i++ ) {
temporaryObject = some value;
more code
}
some more code here
}
Then it is clear where the variable is used, code becomes more readable, and it can not happen that it is accidentally accessed outside the loop.
void SomeFunction () {
some code here
for(int i = 1; i <= n; i++ ) {
SomeType temporaryObject(some value);
more code
}
some more code here
}
QuoteI am using the Xcode 4 templates.Which one ? Not the SFML-ones I assume. At least your project doesn't look like you use them.
Yeah? Because a frame took pretty much time. If we reset it to 0 then we will start skipping seconds. Meaning that if we have 20 FPS and it took 1200 ms( So the last frame was pretty heavy ) and we reset it to zero, we will have somehow magically gained 1/5th performance from nowhere and get 20 FPS again next "second" when we should have only had 16 FPS!
Trust me, removing a second instead of resetting is the accurate way.
EDIT: Why that last frame was "extra" heavy can be anything from windows thread scheduling screwing you over or special case being handled like a trigger being activated. And since this is handled with a >= operator it will work even if that happens every second( that we reach over 1000 ) because it will be invoked some frames earlier each second iteration.
Code: [Select]
Code:
1inline unsigned int GetFrameRate(void)
2 {
3 static unsigned int frameCounter = 0, fps = 0;
4 static float nextSecond = 0.0f, prevSecond = 0.0f;
5 frameCounter++;
6 nextSecond += window.GetFrameTime() * .001f;
7 std::cout << nextSecond << std::endl;
8
9 if(nextSecond - prevSecond > 1.0f)
10 {
11 prevSecond = nextSecond;
12 fps = frameCounter;
13 frameCounter = 0;
14 }
15 return fps;
16 }
printf("FPS: %f FRAMETIME: %f\n", (float)(1.f / window.GetFrameTime()), (float)(window.GetFrameTime()));