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.


Messages - Ushi

Pages: [1]
1
General / Re: Float precision and pixel accuracy
« on: March 05, 2017, 11:46:12 pm »
In my engine entitiy's have these two member variables:

sf::Vector2f m_position;
sf::Vector2i m_coord;

all of the physics calculations happen using the position variable, like so:

m_velocity += m_acceleration;
m_position += m_velocity;

A couple notes: 1, this assumes that the velocity is in units of [pixels moved per update], otherwise we would need a time variable. 2, this is called symplectic euler integration and it really only works deterministically if acceleration only changes instantaneously.

Then, right before drawing, I round the position of the entity like this:

m_coord = sf::Vector2i(std::round(m_position.x), std::round(m_position.y));

Then the drawing uses m_coord instead of m_position.

All the physics happens smoothly and the sprites never stray from the pixels.

2
General / Re: Event loop causes stuttering
« on: March 05, 2017, 11:03:23 pm »
Is there anything that can be done against it beside compile SFML without joystick support?

From my experience it seems that if you want to use SFML on Windows 10, you're gonna have to build SFML without joystick event polling.

Possible solutions:
- I built SFML with no joy and implemented XInput. It works great and wasn't too hard since DirectX is installed with Virtual Studio now, but I'll have to add DInput eventually to make my game work with old controllers
- I think Windows 7 would work assuming they haven't deprecated WinMM there as well
- And then you could of course try other OSs entirely like Mac OS

Here's my no-joystick build of SFML; it's only static, but has both debug and release libraries:
https://www.dropbox.com/s/rfhbd6zj78lh54e/SFML%202.4.1%20STATIC%20NOJOY.zip?dl=0

Edit: Also I tried this old XInput wrapper for SFML and it worked fine: http://en.sfml-dev.org/forums/index.php?topic=12155.0

3
General / Re: Event loop causes stuttering
« on: January 24, 2017, 04:31:37 am »
My original stutters did appear to be every 500 ms.

My program is now starting up fine, but then gradually starts stuttering more and more. About a minute after start it's just stuttering all over the place, but the biggest stutters happen about every 500 ms.

It seems like you've uncovered most of the issue, Wolfhound. I guess it's my turn to build SFML without joystick polling and switch over to DirectInput.

Edit: All this trouble is starting to make me consider giving in to evil Microsoft and just learning DirectX. But surely that can't be a good idea for someone who taught himself how to program starting a few months ago.

4
General / Stuttering Returns!
« on: January 23, 2017, 04:41:02 pm »
The stuttering returned! I realized I hadn't actually used Joystick events since reinstalling VS2015; I had only been using  sf::Joystick::isButtonPressed(x, x) outside the event loop. I believe the stuttering began this time when i first compiled after putting a Joystick event in the event loop.

However, retracing my steps and reinstalling VS2015 did nothing! I'm back to square one! I'm using SFML mainly for this controller support so I can't remove it from the library.

I'm happy to just use conditionals for the Joystick outside the event loop, which worked fine yesterday. But now the problem remains even after removing the Joystick event and repairing and reinstalling VS2015 and everything it came with.

EDIT: So I've been using a PS4 controller connected via bluetooth to my PC, which surely complicates things, but it was working fine yesterday. I unpaired it and then disconnected and reconnected my Logitech USB controller (which I had tried when the problem first arose to no success), but this time it worked! No stuttering! I will try reinstalling drivers to see if I can get my PS4 controller working again if I don't use Joystick events.

EDIT 2: Stuttering returned without noticeable cause. Then, following Wolfhound's advice, I disabled vJoy (which my Logitech controller wasn't using) and the stuttering stopped again. I agree that a future means of ignoring specific devices could be useful.

5
General / Stuttering Stopped!
« on: January 22, 2017, 09:51:10 pm »
Reinstalling VS2015 solved the problem!

Yes, I think the stuttering only began when I started using Joystick events. However, it remained even when I disconnected the joystick and created a new program without Joystick events. I noticed that removing window.pollEvent() stopped the stuttering and I tried to replace it with sf::Joystick::update() only to find that caused stuttering too.

The profiler showed a constant fps and minimal GPU/CPU usage. I decided to repair VS; didn't work. I decided to reinstall without the Mobile Platform and Web SDKs. Problem solved!--even with joystick input! My sprite's jumping and running around like Mario! No stutters!

I'll try adding those extra SDKs and report back if the stutters return. I feel like this is probably buggy old Windows 10's fault. I didn't even have to erase my VS projects directory. Sorry for not trying this obvious solution sooner and thank you all for your support! 

6
General / Re: Event Loop Causes Stuttering
« on: January 21, 2017, 04:29:32 pm »
First: don't remove event polling at any case, you may cause event queue overflow

I do not want to remove event polling, but when I tried commenting out each line to find the source of the problem, that stopped the stuttering, indicating that some part of the PollEvent() function is the source. I would definitely like to fix the problem without removing event polling.

Quote
Secondly: did you try to remove std::cout call? standard output operations may slow down your code a little bit. So, consider testing the code by using VS2015 debugger.

The sprite stutters exactly the same without the std::cout call. I have this same problem in Windows application projects that don't use the console at all. I've tried commenting out each line one at a time and the only thing that stops the stuttering is removing the event loop.

I am currently reading up on how to use the VS2015 debugger tools (I'm pretty new to coding). Is there a specific tool I should be using here?

7
General / Event loop causes stuttering
« on: January 21, 2017, 02:25:04 am »
My SFML programs stutter about 80 ms every half second. I've created a simple program of a sprite moving to demonstrate. Removing the event loop stops the stuttering.

The length of time of each game loop iteration, dt, is printed. dt is usually 0.3 ms, except for every half second or so, when it is 80 ms. And the sprite's stuttering is clearly visible. If I remove the event loop, dt goes up to only 2 ms every half second or so, and the sprite moves smoothly.

#include "stdafx.h"
#include <iostream>
#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(1920, 1080), "GAME TEST 1");

        sf::Texture texture;
        texture.loadFromFile("media/cat.png");
        sf::Sprite sprite;
        sprite.setTexture(texture);

        //physics
        sf::Vector2f position(50, 100);
        sf::Vector2f velocity(20, 0);
        sf::Clock clock;

        while (window.isOpen())
        {
                float dt = clock.restart().asSeconds();

                sf::Event event;
                while (window.pollEvent(event))
                {
                        switch (event.type)
                        {
                        case sf::Event::Closed:
                                window.close();
                                break;
                        default:
                                break;
                        }
                }

                // update physics
                position += velocity*dt;
                sprite.setPosition(position);

                //render
                window.clear(sf::Color::Red);
                window.draw(sprite);
                window.display();

                //report
                std::cout << dt << std::endl;
        }
        return 0;
}
 

Even if the event loop is empty the stuttering occurs. Replacing the loop with sf::Joystick::update() also causes stuttering. VSync makes dt more like 16 ms, but it still stutters at 80 ms at the same rate.

I am using:
Visual Studio 2015
Windows 10
SFML 2.4.1 C++14
All static SFML libraries

I've also tried SFML 2.4.0 and 2.3.2 with no success. Any help would be greatly appreciated!

Pages: [1]