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

Show Posts

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.


Topics - AFS

Pages: [1]
1
General / [Solved] Stuttering on windowed mode
« on: April 14, 2017, 10:56:04 pm »
Hello.

I hate to ask, but this has been bothering me for months and I still can't find a solution on my own.

I experience stuttering every second or so on my desktop (Win 7, i5 3.0 ghz, GeForce 780, 8 GB RAM), but only if I run the application on a window that's smaller than the desktop resolution. In other words, it works smoothly either at fullscreen or on a borderless window the same size as the desktop, but smaller windows get stutter, borderless or not. This happens either with Vsync or or off, or with a fixed or variable timestep. 

Weirdly enough, I don't experience this on my much less powerful laptop (Surface Pro 2, with Intel Integrated Graphics).

At first I thought it was a problem with my project, but then I realized that it also happens with the following minimal code. It draws a circle shape on screen and uses the A and D keys to move the view left and right respectively, which makes the stutter noticeable.

int main() {

    // Options.

    int resolutionX = 1920;
    int resolutionY = 1080;

    bool fullscreen = false;
    bool borderless = false;

    bool vsync = true;

    bool unlimitedFrames = false;
    bool variableTimestep = false;

    bool printFPS = true;

    // Create window.

    int style = sf::Style::Default;

    if (fullscreen)
        style = sf::Style::Fullscreen;

    else if (borderless)
        style = sf::Style::None;

    sf::RenderWindow window( sf::VideoMode(resolutionX, resolutionY), "Frame Test", style );

    if (vsync)
        window.setVerticalSyncEnabled(true);
    else if (unlimitedFrames)
        window.setFramerateLimit(0);
    else
        window.setFramerateLimit(60);

    // Shape.
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Red);

    // Game loop.
    sf::Clock frameClock;
    float frameTime = 0;

    while ( window.isOpen() ) {

        // Poll events.
        sf::Event event;
        while ( window.pollEvent(event)) {

            if (event.type == sf::Event::Closed)
                window.close();
        }

        // Close window with either ESC or Delete.
        bool esc = sf::Keyboard::isKeyPressed( sf::Keyboard::Escape );
        bool del = sf::Keyboard::isKeyPressed( sf::Keyboard::Delete );

        if (esc || del)
            window.close();

        // Move camera with keyboard.
        bool left = sf::Keyboard::isKeyPressed( sf::Keyboard::A );
        bool right = sf::Keyboard::isKeyPressed( sf::Keyboard::D );

        if ( left || right ) {

            float movement = 1000;
            if (left)
                movement *= -1;

            if (variableTimestep)
                movement *= frameTime;
            else
                movement *= 1 / 60.0;

            sf::View view = window.getView();
            view.move( movement, 0 );
            window.setView(view);
        }

        // Draw.
        window.clear(sf::Color::White);
        window.draw(shape);
        window.display();

        // Get frame time, just in case.
        frameTime = frameClock.restart().asSeconds();

        if ( printFPS ) {

            int framesPerSecond = 1 / frameTime;
            std::cout << framesPerSecond << "\n";

        }

    }

    return 1;

}
 

Unfortunately I couldn't record the stuttering, because Shadowplay itself also causes stutter, even at fullscreen, and recording with Fraps kind of stops the stuttering a little bit for some reason. However, I found a similar topic (https://en.sfml-dev.org/forums/index.php?topic=16449.0) which has the following video that perfectly describes my problem:



Some considerations:

- As mentioned, it happens either with Vsync on or off. I have Vsync enabled in my Nvidia Control Panel. It also happens if I force Vsync on it.
- I have "Threaded optimization" disabled in the control panel. Doesn't make a difference.
- I don't have F.lux installed. I did have it months ago, but I unistalled it, restoring Windows default color settings.
- I just updated to SFML 2.4.2, but the problem persists. I also updated my Nvidia drivers, but no dice.
- Recording with Shadowplay (or enabling it to always record the last 5 minutes) causes the stutter to happen even at fullscreen, as mentioned. It only happens with SFML; I can record other games smoothly.
- Fully disabling Shadowplay doesn't make a difference.
- It happens both on my 720p monitor or my 1080p TV.
- I don't get stutter on other non-SFML games. I haven't tested other people SFML games, though.

Finally, in the code snippet above you can print the FPS counter in the console, getting interesting numbers. I'm aware that this affects performance, but the stutter happens even without doing it.

With Vsync, it usually prints the following sequence: ..., 59, 60, 59, 60, 59, 31, 190, 59, 60, 59, 60..., every second or so. It usually prints 30 or a very close number first, and then prints a high number like 150, 200, sometimes even 500.

Without Vsync, limiting it to 60 frames per second, it usually prints the folllowing sequence: ..., 62, 62, 62, 62, 62, 30, 62, 62, 62..., every second or so. It usually is 30 or some very close number.

On fullscreen, with or without Vsync, it prints: 59, 59, 59, 60, 59, 59..., as expected. It looks very smooth.

Honestly, I'm baffled, I have no idea what's causing it. Probably it's something on my end, but unfortunately I'm not knowledgeable enough to guess what exactly is happening.

Thanks in advance for any help.

2
SFML projects / "Our Dear Paper Fighters" - Top down shooter
« on: January 17, 2016, 10:54:54 pm »
Hello.

This is a a pet project of mine. I've been working on this since August 2015, although the code behind it is much older.

The game itself is nothing fancy, just a top down shooter inspired by games like Desert Strike and Urban Strike, which I played on the SNES when I was a kid.


- One of the first screenies. January 2016


- A more recent screenshot. It has a different HUD for the healh and fuel, plus the adition of ammo. April 2017


- The first gif of the game, when buildings were just part of the background and the screen-shake was obnoxiously strong. For some reason the GIF came out too dark. January 2016

http://youtu.be/18G0E6pvhNE
- First gameplay video, with awfully loud sounds. February 2016

http://www.youtube.com/watch?v=OV1xO9Rz_bA
- Making a small part of the level with the editor. May 2016

https://www.youtube.com/watch?v=H2FA5esHWwk
- More recent gameplay, showing the general structure of a level. April 2017


Sorry for not sharing the source, this is made on a personal engine-of-sorts. Feel free to ask how anything is made, though, and I'll try to answer the best way I can :P

Cheers!

3
SFML wiki / Letterbox effect using a view
« on: November 27, 2014, 01:59:10 am »
Hello.

I added a little code example to archieve a letterbox effect when resizing the window, having black bars on the sides in case the aspect ratio of the window is different than the aspect ratio of the view.

https://github.com/SFML/SFML/wiki/Source:-Letterbox-effect-using-a-view

I was unsure whether this is "wiki material" or not, but I decided to post it regardless. Maybe someone finds it useful.

Any corrections or suggestions are welcome, of course.

Cheers!

Edit: typo.

4
SFML projects / A video of a little shooter I made
« on: November 14, 2014, 04:27:55 am »
Hello.

I tried to make a little shooter four months ago, and made some things here and there like randomly generated pilots with different stats, and a level with some scripted events. Most of this was done reusing code from previous projects and making very simple placeholder graphics.

Anyway, I got busy with other stuff and forgot about the project. Only yesterday, three months later, I remembered the thing and decided to make a video of it because I never showed it to anyone and I would really appreciate some honest opinions.

http://www.youtube.com/watch?v=-q1gu28dmVo

(Watch at 60 FPS if you can ;) )

The idea was to have a list of pilots with different stats and send them on missions, and if they die they die for good, and they gain experience and salvage parts to make their planes better and, well, you get the idea. Hopefully someday I'll finish it, but right now the project is on hold.

Anyway, I would really appreciate some opinions if you have the time, thanks  ;D

5
Graphics / How to reduce draw calls? (and some questions)
« on: July 01, 2013, 08:24:41 am »
Hello everyone :D

I'm making a game, and I'm having performance issues, sadly. At first I thought it was because of some code of mine (like collision detection) but after spending some hours I noticed that it's really because of the amount of sprites.

I have all my sprites on a linked list, and draw them one by one, thinking that this is the only way of drawing a lot of stuff. The code is simply like this:


std::list <sf::Sprite> :: iterator i;

for (i = mySprites.begin(); i != mySprites.end(); i++)
      myWindow.draw(*mySprite);

 

So, I get an awful performance hit while drawing like 30 or so sprites, which is a pretty low amount for my needs. The sprites use one of 8 or so textures, which have a size of around 400x400 pixels each.

However, I noticed that I can draw a lot of sprites without the performance hit (like 200 or so) if all the sprites have the same texture. The performance gets worse the bigger the amount of different textures used by the sprites, even if I draw the exact same amount of them. Why is that?

I kind of imagine the reason, but hopefully someone could give me an explanation :)

Anyway, while searching for a couple of hours, I read that performance may improve if I reduce the number of draw calls, and to do so I need to use "batching" (a new concept to me) and/or use sf::VectorArray (I don't know if using the vector array is actually part of batching or just a different process).

So, why batching/using a vector array is better than drawing each sprite one by one? And finally, could somebody please show me a small example of code with a vector array in action?

Sorry for the long post and for the dumb questions. I searched a lot but I didn't really understood what I found, it's like chinese to me  :P

Thanks in advance.

6
SFML projects / Platformer Editor (testing vector collision detection)
« on: March 15, 2013, 09:04:07 pm »
Hi.

I made a little app to test collission detection using vectors, that is, placing two of them on the map and joining them, forming a line. The objects will react to that line.

Here's a video for a quick demostration:
http://www.youtube.com/watch?v=X9AFVGTaNNg

Here's the download link if you want to test it, though it may be buggy. Beware!
http://www.mediafire.com/?5ho3zzi0nknnknp

(Walls are not implemented yet, so avoid placing them!)

I made this because I want to create a platformer of course, but I was thinking about a more flexible way of handling collision (from the game maker's point of view) instead of using a grid or bounding boxes.

I loved the results, but I noticed that the main drawback is that placing the nodes and joining them can become a little tedious, as you need to do it manually every time. Still, it shouldn't be hard to make that the editor place the nodes automatically as you put a background tile.

So, what do you think? Is it worth it to use this type of collision or you prefer other types? I'm very ignorant regarding collision, and I want to see what are my options.

Also, what do you think about the editor? Any suggestions are welcome.

Finally, if you make a map with your own graphics and all, please share it, I would definitely want see it :P

Cheers.

7
SFML projects / Isometric Hexagonal Tile Map
« on: January 07, 2013, 11:16:55 pm »
Hello, I'm new here. I wanted to show you people a little project I'm making. It's pretty much what says on the title.

I don't want to upload the code or the executable just yet, because the code is very messy and the application is a little unstable, and I still need to work on some details, but to compensate I made a little video showing its features:

http://www.youtube.com/watch?v=eFRRyXXk2z0

Please let me know what you think.

By the way, thanks to Laurent for making SFML. I fell in love with it. Is that wrong?

Have a nice day.

Pages: [1]
anything