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

Pages: [1]
1
General / Re: Loading all png files from a folder?
« on: February 01, 2017, 05:11:21 pm »
Why not use a textures.txt file or something?
Just edit the file whenever you want to change textures.  It'll remove a platform-dependent filesystem API usage.
Kinda like this?

texture1.png
someothertexture.png
somethingelse.png
...

Then in your code:

std::string filename{ "" };
std::ifstream file("path_to_textures.txt");

while (file >> filename) {
    my_textures.push_back({});
    if (!my_textures.back().loadFromFile(filename))
        report error
}

Cool solution, although it still requires some effort from the user. I think it's worth it though. Will try when I get the chance, many thanks!

2
General / Loading all png files from a folder?
« on: February 01, 2017, 03:51:20 pm »
Hi,
My application (c++/sfml) needs a lot of separate images. I have a folder of 17 png images, with potentially more to be added. I want my program to load all the images from a folder in my app directory into a vector in chronological order (1,2 etc). I have only ever loaded the images into a texture data type individually, which means going into the code every time one is added. (I am using this program to visualize a bunch of images). I plan on adding up to 40 or more, so this is not very intuitive. The code already handles each texture.

What's the best way to implement this? I am having a hard time finding solutions on the internet.

3
The "test" doesn't matter as long as the code doesn't represent an actual application. You ndver call clear abd display. Plus you're most likely running this in debug mode, which again invalidates the result.

It's actually interesting that you get so little CPU usage, since you never call display the loop will run as fast as the CPU allows it, which should usually end up with one CPU core being utilized to the max.

Finally if you are ever worried about performance, which btw. should not be your highest priority, then use a profiler to find the bottlenecks.

Yes this is being run in debug mode, why would this code affect the cpu in debug mode? The code I showed doesn't include everything, I do have the window.clear/draw/display in the actual source code. And I have the framerate limited to 60, sorry I did not show everything, just for simplicity' sake. Hmm, I will look into the profiler. Thanks!

4
Well, window.create executes lots of commands, in short: window.create() is pretty expensive operation. Just looks at SFML/ source and you'll understand what I am taking about.  ;)

That doesn't make sense, the window.create() statement is not being run everytime the application is looped, not even close. Is there something I am missing?


5
Hi,
I'm new to SFML and a beginner with C++. I have the below code that I am interested about, because I'm really into making sure applications run as efficiently as possible.

       
while (window.isOpen())
        {
                sf::Event event;

                while (window.pollEvent(event))
                {
                        switch (event.type)
                        {
                        //case sf::Event::KeyReleased:
                        //      switch (event.key.code)
                        //      {
                        //      case sf::Keyboard::Return:
                        //              if (isFullscreen == true)
                        //              {
                        //              window.create(sf::VideoMode(1366, 768), "Smaller Window", sf::Style::Default);
                        //              isFullscreen = false;
                        //              }
                        //              else
                        //              {
                        //              window.create(sf::VideoMode(1920, 1080), "Bigger Window",sf::Style::Fullscreen);
                        //              isFullscreen = true;
                        //              }
                        //      }
                        //      break;
                        case sf::Event::Closed:
                                window.close();
                                break;
                        case sf::Event::MouseButtonPressed:
                                cout << "Mouse Pressed" << endl;
                                break;
                        }
                }

        }

important:


without the code that is commented above, my application runs with max cpu usage of 2% and will go to 0% at idle.

with the code that is commented above, my application runs with a sporadic cpu usage between 4 and 8%. It will not go to 0% at idle.

This is very strange to me as a beginner. I feel like it should have virtually no affect on cpu usage when the user is not changing the window resolution.

Thoughts?

Pages: [1]