Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411609 Posts in 69388 Topics- by 58448 Members - Latest Member: NESIA

May 09, 2024, 08:29:32 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)issues with SFML ->normal or am I too noob ? + what do you think of Godot engine
Pages: [1]
Print
Author Topic: issues with SFML ->normal or am I too noob ? + what do you think of Godot engine  (Read 1963 times)
Adinimys
Level 0
**


View Profile
« on: September 05, 2015, 01:09:36 PM »

Hello everyone Smiley I hope that I'm posting in the good section.

I recently started coding my own 2d game using SFML. It has quite simple requirments as I only want simple tile based 2d without any physics and collision detection.
One of the computer I'm using is a really basic laptop with 1Ghz processor, 2Go RAM (and about the GPU, I'm sure you can guess it's not a GTX980  Tongue) and with some non-moving sprites my game was running around 50fps. But has soon has I start moving the mouse it's lagging horribly, down to 1-5fps. I'm using a sprite for my cursos and each frame I use the sf::Mouse to get the position of the mouse and compare it to previous position to update the position of the mouse.
I have checked several times that there was no stupid overhead in the calculation of the cursor position and I still don't understand the issue.

So my questions are :
    -from your experience with SFML, could you confirm that it's efficient enough to run on such a computer for basic stuff (so that you have a scale of power, it can run Super Meat Boy and Crypt of the Necrodancer with only small slowdowns when killing monsters) ? Has someone encountered such a thing before ?
    -how are you managing the cursor position ? Is it different from my solution ? (i don't see anything else to do...)


And the second question is regarding using Godot engine instead of building my own stuff. I'm not highly experienced in programming (this work with SFML is partly a learning exercise for me) so I might not be able to create something good enough to be played. Thus I considered using Godot (side note : I tested a demo of 2d platformer running with godot and it was fluid on my computer, so the issue is not wit the hardware but rather SFML or my crappy code, probably the second  Shrug)
Has someone had experience with it and how was it ? What about ease of design / learning curve of the script / C++ API / performance / documentation ?

And if someone had experience with SFML and with Godot : what would you use if you had to choose between both now ?



« Last Edit: September 05, 2015, 01:21:12 PM by Adinimys » Logged
Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #1 on: September 05, 2015, 01:25:54 PM »

We can't see the issue in your code without seeing the code. It's very unlikely that this is a problem with SFML.
Logged
Adinimys
Level 0
**


View Profile
« Reply #2 on: September 05, 2015, 01:31:37 PM »

Yes I know, I'll post it soon. I had no access to it on the computer from which I posted but I realize my first question is kind of pointless then...
But in general the essence of my question was more about your experience with SFML and Godot and the performance vs usablitiy of both Smiley
(I'm searching the code, I'll post it quickly)


Edit :

So here is the code

Code:
void InputManager::UpdateMousePosition()
{
    Cursor->setPosition(Vector2f(Mouse.getPosition() - mQuarterOfScreen));

    //CheckHovering(); //I was using this function but for the sake of debugging slowdowns I commented it out. It is still slowing down when moving the cursor though
}

Cursor is a sf::Sprite* and Mouse a sf::Mouse.


Each frame the cursor is drawn using :

Code:
void InputManager::DrawCursor()
{
    Engine::GetMainWindow()->draw(*Cursor, CameraState);
}

With camera state being a sf::RenderStates that gets updated only when the camera moves so that the cursor is not "atached to the world" bit moving with the camera.


With this code it's around 50-55fps when not touching the mouse and between 2-15fps when moving it.
« Last Edit: September 05, 2015, 03:05:37 PM by Adinimys » Logged
Sik
Level 10
*****


View Profile WWW
« Reply #3 on: September 05, 2015, 01:48:40 PM »

    -from your experience with SFML, could you confirm that it's efficient enough to run on such a computer for basic stuff (so that you have a scale of power, it can run Super Meat Boy and Crypt of the Necrodancer with only small slowdowns when killing monsters) ? Has someone encountered such a thing before ?

I don't use SFML but it definitely shouldn't have trouble with that. Your issue sounds like there's something you aren't aware of and that it's biting you back.
Logged
TheLastBanana
Level 9
****



View Profile WWW
« Reply #4 on: September 05, 2015, 02:52:35 PM »

What does the CheckHovering function do? It doesn't look like the problem is in the code you've shown us.
Logged
Adinimys
Level 0
**


View Profile
« Reply #5 on: September 05, 2015, 03:04:07 PM »

Oh crap, I did a bad copy-paste  Facepalm
In fact I tested without this function (it is searching for sprites in the hud that contains the cursor), I commented it and it is still slow.
But still it makes no sense to have CheckHovering slowing during cursor movement because the logic involved in my function is not tied to moving the cursor.
This is really what seems strange to me : it's only while moving that the slowdowns are appearing even if for now nothing in my game is tied to the mouse having moved or not...
Logged
TheLastBanana
Level 9
****



View Profile WWW
« Reply #6 on: September 05, 2015, 03:41:11 PM »

Can you reduce it to a minimal case in which the lag still happens? It would help to be able to see all of the code, but I imagine that's spread across many files, so try removing code until the problem stops happening, then show us the code just before you made the last change.
Logged
Adinimys
Level 0
**


View Profile
« Reply #7 on: September 06, 2015, 08:35:34 AM »

While I was cutting in my code to have a minimal case I found the issue :

I'm doing this each frame :

Code:
while(pWindow->pollEvent(mEvent))
    {
        if(//check event type here)
            //do something
        else if (//the same for all events of interst)
    }

I thought that the events where only clicks and key presses but this time I double checked (dumb me for not having done this before  Facepalm what's the point of open source libraries if you're not reading the code you use...  Shrug). So the movements of the mouse are included in the std::queue<Event> m_events of the window which means that all my mouse movements where adding a huge amount of event to process.

So now I'm left wondering if the best solution for me is to modify the code of the SFML to cut all the event processing that I won't need in my game or if there is an easier solution that would avoid the overhead of usless events and only focus on the one I need ?

What have you done if you used SFML before for the inputs ?
Logged
TheLastBanana
Level 9
****



View Profile WWW
« Reply #8 on: September 06, 2015, 09:07:38 AM »

That still shouldn't be causing that much lag -- it certainly isn't in my project. It would be silly if you had to cut out parts of the library just to get it to run at a reasonable speed. Tongue

Out of curiosity, what suggests to you that the mouse movement events are the root of the problem? Did you try removing the event polling loop and find that the lag was gone? If so, can you show the code within that while loop?
Logged
Adinimys
Level 0
**


View Profile
« Reply #9 on: September 06, 2015, 12:23:43 PM »

During my tests I went down to a minimalistic event pooling loop like this :

Code:
void InputManager::ProcessInput()
    {
        while(pWindow->pollEvent(mEvent))
        {
            if(mEvent.type == Event::Closed)
                pWindow->close();  // to ensure that the player can properly close the window
        }
       
        UpdateMousePosition();
    }


void InputManager::UpdateMousePosition()
{
     Cursor->setPosition(Vector2f(Mouse.getPosition() - mQuarterOfScreen));
}

In this situation it's running at around 45fps without moving the mouse and it dropped to 3fps when moving it. More importantly if my mouse is out of the window, my code is still moving the cursor but it's not receiving event of the mouse moving so it's running at 45fps.
If I comment out UpdateMousePosition() it's running at roughly the same framerate (maybe 2-3 more but given the accuracy of my short time measurment it's not important).
But... when I comment out my while loop (meaning that I can no longer close the window and I have to kill the process) it gives...
 BETWEEN 400 AND 600FPS  Shocked

So... it's pretty obvious to me that the bottleneck is this while loop. I read the source code of the event processing and it involves a lot of conditional checks to correctly answer the different events and it seems that it's too much for my low-end CPU.

Quote
It would be silly if you had to cut out parts of the library just to get it to run at a reasonable speed. Tongue

Well, I guess that's called optimizing for the target platform and for the game. For example I already know that I won't need a joystick so that could be one less function called for each event processed. I won't need to detect mouse movement either, at least not with an event. So I guess that cutting in the library could be the solution but if someone as a better idea I'm totally open to it, maybe I missed something about the way to handle events...
Logged
Cheesegrater
Level 1
*



View Profile
« Reply #10 on: September 06, 2015, 01:03:37 PM »

Sounds like this problem: http://en.sfml-dev.org/forums/index.php?topic=6079.0
Logged
Adinimys
Level 0
**


View Profile
« Reply #11 on: September 06, 2015, 01:20:03 PM »

Wow, thanks for the link, I don't know how I missed this xD
Well anyway I was currently trying the solution that they are suggesting (even more drastically because I'm removing the event for when the mouse moves and the event that are touchscreen related). It's taking sometimes because I'm not use to comiling library myself and for some reason my program is no longer able to find the library now...
Anyway I'll post about it when it'll be done, I hope this will solve the issue Smiley

Apart from that : is anyone having some sort of feedback about the Godot engine ? I'll guess I'll hve to try it myself but I would have love to have some insight before diving in  Smiley
Logged
Adinimys
Level 0
**


View Profile
« Reply #12 on: September 06, 2015, 01:37:14 PM »

Ok, here are the results...

A steady 850+FPS !  Kiss
It's just complaining in std::out about some events that are not handled but it shows no bugs and the desired events are still produced. I'll guess I'll head over the SFML forum to see if it's an issue that's being worked on or if it's intended like this, running on better CPU (my i5 3,5GHz isn't complaining at all xD)
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic