Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: What is the best way to animate large frames?  (Read 1689 times)

0 Members and 1 Guest are viewing this topic.

Me-Myself-And-I

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
What is the best way to animate large frames?
« on: April 29, 2024, 01:45:07 am »
I have a class called "Life" which loads each frame into a vector of images and plays it when needed. I need something that can load 960x540 frames so I surely abandoned trying to use spritesheets. This method i'm using now works but is extremely inefficient. Just using the load function causes the entire program to stop till the process of loading finishes. 10 or so frames causes a 1/2 second pause and any decent length animation of 200 frames  causes a whopping 10 to 15 second lag. Of course I can't have this. Is this method impossible? I know there must be some way to load and play the frames of an animation that is 960x540. I just don't know how.


Here is my loading code.
                DIR *dr;
               
                struct dirent *en;
               
                dr=opendir(folder.c_str());
                for(int a=1;a<2000;a++)
                {

                        if(en=readdir(dr))
                        {
                                if(en->d_name==NULL)
                                {
                                        break;
                                }
                                if(a>2)
                                {
                                        Image newimage;
                                        newimage.loadFromFile(folder+en->d_name);
                                        image.push_back(newimage);
                                }
                        }
                        else
                                break;
                               
                               
                }
                closedir(dr);
 

I'm sure its not dirent that is causing the process pause because I manually loaded each frame to test if it was dirent or not and it still halted the processing the same.

I also tried loading only portions at a time as needed by loading the next few frames as needed. This still caused a 1/2 second lag that happened every few frames.



I know that loading from files is not good on performance, since several have told me that before. So I'm looking for either a new method,or a fix to this current method. So any ideas?

I also would like to know if it  would work to load into each image one loop at a time instead of all in one for() iterator.

 
« Last Edit: April 29, 2024, 02:06:45 am by Me-Myself-And-I »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: What is the best way to animate large frames?
« Reply #1 on: April 29, 2024, 08:38:16 am »
At what point would it make sense to use a video format instead of trying to manually create an animation of images? ;)

On one hand make sure you're measuring the "performance" in release mode.
Then to make sure you're optimizing for the right bottleneck use profiling tools to find the hot paths.

Assuming it's the reading from disk part, there isn't much you can do, as you'll have to read the image data into memory at one point.
You could perform the reading in a separate thread, so you don't block your "UI" thread, but make sure to only do this for the disk reading part (i.e. sf::Image) and not to try to do any OpenGL calls in a separate thread.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Me-Myself-And-I

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: What is the best way to animate large frames?
« Reply #2 on: April 30, 2024, 04:54:55 am »
Quote
At what point would it make sense to use a video format instead of trying to manually create an animation of images? ;)
That was my first choice but I haven't been too successful at playing videos in an SFML window. Also I was under the impression that something like sfeMovie doesn't support drawing sprites on-top of the video as its playing, which is something I need. I also notice a slight blur that usually occurs when you scale up a video as opposed to a scaled up image which does not blur. And by scaled up I mean zoomed into by the view.  Maybe its just some setting I have wrong for that so i'm open to considering using a video instead.



Quote
You could perform the reading in a separate thread, so you don't block your "UI" thread, but make sure to only do this for the disk reading part (i.e. sf::Image) and not to try to do any OpenGL calls in a separate thread.

Could you please show me how to do that? I'm not too good at doing multithreading for class objects.
 I would really appreciate it.

 

anything