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 - maltman

Pages: [1]
1
System / What is wrong with my self made frame rate limit code?
« on: December 20, 2019, 08:05:49 am »
Using window.setFramerateLimit(60), I get consistent FPS between 58-62, but I wanted to do things myself to be sure I understand how it works, so I made this code here: (notice the code in the loop function at the bottom.)


class SystemClock
        {
        public:
                void establishFrameTime()
                {
                        frametime = (double)frameClock.restart().asMicroseconds()/e6;

                        if (tempavgFrameTime == 0.0)
                        {
                                tempavgFrameTime = frametime;
                        }
                        else
                        {
                                tempavgFrameTime = (tempavgFrameTime + frametime) / 2.0;
                        }
                        accumulatedFrameTime += frametime;
                        if (accumulatedFrameTime >= 1.0)
                        {
                                avgFrameTime = tempavgFrameTime;
                                FPS = 1 / avgFrameTime;
                                accumulatedFrameTime = 0.0;
                                tempavgFrameTime = 0.0;
                        }
                }

                double const fixedTimeStep{ 1.0 / 60.0 };
                double const e6{ 1000000 };
                sf::Clock tickClock;
                sf::Clock frameClock;
                sf::Clock timeClock;

                // time data
                double FPS{ 0.0 };
                double frametime{ 0.0 };
                double avgFrameTime{ 0.0 };

        private:
                double tempavgFrameTime{ 0.0 };
                double accumulatedFrameTime{ 0.0 };
        };


        void loop()
        {
                while (systemWindow.window.isOpen())
                {
                        systemClock.establishFrameTime();
                        if (systemClock.frametime < systemClock.fixedTimeStep)
                        {
                                sf::Int64 remainder{ (sf::Int64)((systemClock.fixedTimeStep - systemClock.frametime) * systemClock.e6)};
                                sf::sleep(sf::microseconds(remainder));
                        }
                        update();
                        render();
                }
        }
 


When I run this, the framerate fluctuates between 80-100 sometimes spiking to 160. Why are my frames running too fast, am I not using sf::sleep correctly? Or is it my IDE im running visual studio in debug mode(but then why would there be a difference between this and window.setframerateLimit()

2
General / Re: What is a good way to handle new line characters? \n
« on: April 26, 2019, 10:28:28 pm »
Is it possible to add a cursor without making your own geometry? I couldn't figure it out using the standard sf:: classes.

I am going through your code and the sf::Text code and trying to learn for my own project, I may have other questions about it I hope you don't mind.

3
General / Re: What is a good way to handle new line characters? \n
« on: April 25, 2019, 12:35:31 am »
This is great thanks. I want to program my own because I need the practice. I'll definitely follow the Selba Tutorials.

Right now I am struggling to think how should I handle input into my window.

I currently am using a singleton for my AppWindow and I when I handle the sf events I set std::bitsets for each key press.
In my console.update I check the bitsets like this:
AppWindow::instance().get_IsKeyPressed().any()

I don't want to couple my console to my AppWindow singleton class so this sucks.

@FRex : I see that your ConsoleInput takes an sf::event. How and where do you pass the event to the function?
https://github.com/FRex/LuaConsole/blob/master/src/LuaConsole/LuaSFMLConsoleInput.cpp



auto const keybits = AppWindow::instance().get_IsKeyPressed();
        if (keybits.none())
        {
                return;
        }
        if (keybits[sf::Keyboard::Key::BackSpace])
        {
                std::cout << "backspace\n";
        }
        if (keybits[sf::Keyboard::Key::Delete])
        {
                std::cout << "delete\n";
        }
        if (keybits[sf::Keyboard::Key::Enter])
        {
                m_model.add_to_session(m_model.get_promptLine());
                m_model.reset_promptLine();
        }
 

I also have this nasty stuff.

4
General / Re: What is a good way to handle new line characters? \n
« on: April 11, 2019, 01:48:27 am »
Ahh! I see yes it does work with \n. I was expecting it to work with '\r' (carriage return) as well, since that is what I've been getting from event.text.unicode when I press enter.

I wrote a simple if statement to turn \r into \n and everything is working fine. I ditched the vector of substrings.

So all that stuff you wrote was just to have multi color text? That is pretty cool. I might have to steal it if I continue with this.

5
General / What is a good way to handle new line characters? \n
« on: April 10, 2019, 09:30:09 pm »
Hi, I'm making a console window with SFML and I've reached my first uncertainty: new line characters.

I want a new line character to create a new line. There seems to be no function in sf::Text to do this automatically.

So, with efficiency in mind, should I create a loop for each sub-string delineated by new line characters and call RenderWindow::Draw on each sub-string? or is there a better way.

https://github.com/FRex/LuaConsole/blob/master/src/LuaConsole/LuaSFMLConsoleView.cpp

^^This guy doesn't even use sf::Text. He creates his own vertex thingies using the glyphs from the font.

What is the recommended approach here?

Edit:
Here is what I have now(it functions but seems wasteful):

        {
                float lineSpacing = sessionText.getCharacterSize() + sessionText.getLineSpacing();
                int i{ 0 };
                for (std::string const & substring : model.get_sessionString())
                {
                        sf::Transform t;
                        t.translate(0.f, lineSpacing * i);
                        sessionText.setString(substring);
                        AppWindow::instance().getAppWindow().draw(sessionText, t);
                        i++;
                }
        }

Pages: [1]