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

Pages: [1]
1
General / Fixed timestep CPU usage
« on: February 12, 2016, 11:34:16 pm »
Hello. I have implemented a fixed timestep. The problem with this is that my CPU usually goes to about 30-40% and I don't understand why. A solution would be to just use the setFramerateLimit method or vsync, but I don't understand why would I need a fixed timestep if I use one of those. If someone can shed some light here that would be much appreciated.

const sf::Time m_frameTime = sf::seconds(1.f/60.f);
sf::Clock clock;
sf::Time passedTime = sf::Time::Zero;

while (window.isOpen())
{
        sf::Time elapsedTime = clock.restart();
        passedTime += elapsedTime;

        while (passedTime > m_frameTime)
        {
                passedTime -= m_frameTime;

                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
                update(m_frameTime);
        }
               
        window.clear()
        window.display();

}

2
General / Memory management
« on: August 21, 2015, 05:36:08 pm »
This is not really a SFML-related post but I would really appreciate your help.

At the moment, I'm using a std::vector of std::unique_ptr.
I push state objects created with std::make_unique using std::move when I want to change state and then I erase the stack.

I'm testing things out using 2 states: one has some textures in it and the other one is empty.
What happens when I repeatedly switch between states is that memory usage increases per switch.

I also tried making the textures raw pointers. When I manually delete them before switching states there is no increase in memory. But if I try to make them shared pointers or unique pointers the memory will still increase.
I'm curious how should I handle these states and pointers.

I change states using this method:
void StateManager::changeState(std::unique_ptr<State> state)
{
    //If the vector isn't empty destroy the current states
    //Clear the vector
    if (states.empty() == false)
    {
        for (auto i = 0; i < states.size(); i++)
        {
            states[i]->destroy(*window);
        }
        states.clear();
    }

    //Move the new state inside the vector
    states.push_back(std::move(state));

    //Initiate the state
    if (states.empty() == false)
    {
        states[MAINSTATE]->init(*window); //MAINSTATE = 0
    }
}

3
Graphics / getLocalBounds and getGlobalBounds
« on: August 09, 2015, 03:55:42 pm »
So I'm trying to make a button but I can't resize and center the text because both getLocalBounds and getGlobalBounds are returning 0. Here is the code:

       
void Button::setString(sf::String string)
        {
                m_string = string;
                m_text.setString(m_string);
                std::cout << m_text.getGlobalBounds().width; //This returns  0
    }
 

m_text is a private sf::Text variable.
The text is drawn on the screen, the setChar size method works as well. The only thing that isn't right here is that getGlobalBounds().width/height and getLocalBounds().width/height always return 0.

4
General / TGUI question
« on: June 21, 2015, 12:22:07 pm »
I have a header file in which there are extern variables.
Should I declare :
extern tgui::Gui gui;
//and use it once in main:
gui.setWindow(window);
 

Or should i just declare it once in every class I have?

I'm asking because in SFGUI you shouldn't declare it globally.


5
Window / Transparent window
« on: May 22, 2015, 01:13:03 pm »
Is there any way i could make a transparent splashscreen?

Transparent window with a rendered image, like the one photoshop uses.

http://www.optimiced.com/wp-uploads/2010/07/photoshop-cs5-white-rabbit-splash-screen.jpg

6
System / [SOLVED] Event text unicode
« on: May 20, 2015, 10:37:20 pm »
So i have this code:
case sf::Event::TextEntered:
c = static_cast<char>(event.text.unicode);
break;
 

My question is, how do I make this ignore keys that are not letters?

edit: bad englando

For anyone interested this is the solution:
if (((event.text.unicode > 64) && (event.text.unicode < 91)) || ((event.text.unicode > 96) && (event.text.unicode < 123)))

7
Window / Window crashes
« on: May 19, 2015, 04:43:37 pm »
The program works just fine, the code is not the problem.
But I get this error when trying to close the window from the X button.

http://imgur.com/a/YNnhi

plz halp

Pages: [1]