Jump to content
pieomy00

What is the best way LoadFromFile & Thread? (FMX)

Recommended Posts

 

Hi,

what is the best way LoadFromFile & Thread? (FMX ios and android)

 

I'm using this code but i dont know this is good or bad

also there is any usage limit for this? (same time with different bitmaplistanimation components)

 

my main goal is make sprite sheet animation based game, I have a lot of sprite animation and I need load and unload on runtime.

thank you.

 

 

TThread.CreateAnonymousThread(procedure ()
  begin
    try
      BitmapListAnimation1.AnimationBitmap.LoadFromFile(MyFile);
    finally
    end;
    
    TThread.Synchronize (TThread.CurrentThread,
      procedure ()
      begin
        BitmapListAnimation1.Enabled:=true;
      end);
  end).Start;

 

Share this post


Link to post

Best for my main goal.

I dont know Threads, still searching and trying understand but complicated topic. I need just for LoadFromFile

this solution working usually but I got crash sometimes 

Share this post


Link to post
5 hours ago, pieomy00 said:

my main goal is make sprite sheet animation based game, I have a lot of sprite animation and I need load and unload on runtime.

thank you.

this

 

Share this post


Link to post
8 hours ago, pieomy00 said:

try       BitmapListAnimation1.AnimationBitmap.LoadFromFile(MyFile);     finally     end;

I'm no expert in threads, but I'm shure that a LoadFromFile should be synchronized. As stated above the try/finally is pointless. 

 

If you only have these two commands in the thread, and both will be synchronized, there will be no point in putting them in a thread. It will probably just slow your program down.

Share this post


Link to post
9 hours ago, Hans J. Ellingsgaard said:

I'm no expert in threads, but I'm shure that a LoadFromFile should be synchronized. As stated above the try/finally is pointless. 

 

If you only have these two commands in the thread, and both will be synchronized, there will be no point in putting them in a thread. It will probably just slow your program down.

I have only this 2 commands, LoadFromFile must inside thread other way pointless process. I am searching best way for this. (try/finally can be remove, it doesn't matter)

Share this post


Link to post
9 hours ago, Vandrovnik said:

Thank you but this is for after LoadFromFile, for drawing and BitmapListAnimation using this method already.

 

I dont have problem drawing sprites, my problem is load texture from file on runtime without application freeze

Share this post


Link to post

What if somewhere this BitmapListAnimation1 is used while you call LoadFromFile?

We don't see your code so what advice do you expect?

19 hours ago, pieomy00 said:

      BitmapListAnimation1.AnimationBitmap.LoadFromFile(MyFile);

 

Share this post


Link to post

Just load it all at application or scene start. How large can those sprites be? It's a game, you may waste resources, it's kind of being expected anyway.

Share this post


Link to post
3 hours ago, Cristian Peța said:

What if somewhere this BitmapListAnimation1 is used while you call LoadFromFile?

We don't see your code so what advice do you expect?

 

BitmapListAnimation1 does not have properties like UI components. I am just stoping before LoadFromFile.

I dont know what can else its simple component and every BitmapListAnimation components separated 

 

You can ignore my codes, I am just searching how can load textures from file on runtime without application freeze

Thanks

Share this post


Link to post

Load them in a thread, but don't expect speedup unless every single texture is stored on its own hard drive.  You should also generate an AnimationBitmap object for each loaded image, and once the thread is done, or it once it needs to be used be used, synchronized assign it to the main thread BitmapListAnimation.

Share this post


Link to post
3 hours ago, Sherlock said:

Just load it all at application or scene start. How large can those sprites be? It's a game, you may waste resources, it's kind of being expected anyway.

 

This is my scene, I have 5 enemy and have 25 different skin (sprite animation), when someone is down I need to respawn with new skin.

Can not load all skins to ram, very high usage (and iphones crash if you over limits https://stackoverflow.com/questions/5887248/ios-app-maximum-memory-budget )

I have to load sprites on runtime from file smoothly. Need help for this.

Thank you.

 

ezgif-6-d7a0be0a6ce1.gif.a16c7f05f89646c7f2e6fd01a4176cfb.gif

  • Like 1

Share this post


Link to post

That looks pretty cool. I don't know why, but I thought you where on a PC. But still the loading should be possible in a thread, where you can also prepare almost all the objects needed, and in the end just assign them to the main thread (synchronized!)

Share this post


Link to post

Still don't understand why you need to reload on-the-fly, instead of pre-load all relevant bitmap lists,

and just switch them on demand.

Share this post


Link to post
4 minutes ago, Rollo62 said:

Still don't understand why you need to reload on-the-fly, instead of pre-load all relevant bitmap lists,

and just switch them on demand.

My main scene using ~500MB ram already, on this scene I have 25 different kind texture but need only 5 live (5 enemy on screen),

I can not pre-load all because iPhone 6 devices crash after 645MB usage 

  • Like 1

Share this post


Link to post
5 minutes ago, pieomy00 said:

 ~500MB ram already,

Ups, the scene doesn't look like that much.

What you mean by "main scene" ?

What I meant was just loading liles needed for the current view, not keeping in background.
When switching from scene1 to scene2 you have maybe enough time to load, even with a little delay, but this is maybe not visible

or you could cover this by some scene change splash image.

 

If scenes move linear, you could hold and prepare the last and next view maybe in the background, while running the current view.

 

If you have one view really needing 500MB, OK then I'm out :classic_biggrin:

Edited by Rollo62

Share this post


Link to post

 

this is main scene (form) and using ~500MB ram.

I wanna add 2. scene but have only 150 MB left (for iphone 6) 

on 2. scene I can not pre-load textures (150 mb dosen't enough for pre-load) and need load textures runtime for this 

 

Screenshot_2020-03-11-19-13-20.thumb.png.b0bc6f0ed6e3afdc1bddd85af7b6c2e4.png

 

 

  • Like 1

Share this post


Link to post
On 3/10/2020 at 8:36 PM, pieomy00 said:

 

Hi,

what is the best way LoadFromFile & Thread? (FMX ios and android)

 

I'm using this code but i dont know this is good or bad

also there is any usage limit for this? (same time with different bitmaplistanimation components)

 

my main goal is make sprite sheet animation based game, I have a lot of sprite animation and I need load and unload on runtime.

thank you.

 

 


TThread.CreateAnonymousThread(procedure ()
  begin
    try
      BitmapListAnimation1.AnimationBitmap.LoadFromFile(MyFile);
    finally
    end;
    
    TThread.Synchronize (TThread.CurrentThread,
      procedure ()
      begin
        BitmapListAnimation1.Enabled:=true;
      end);
  end).Start;

 

 

You said that [there is any usage limit], what is your mean?

 

LoadFromFile need some time because your file is very large, even if you put it into a thread, it still need the same duration.

 

Maybe you need put it into a thread, and run this thread at a right time such as before you want show these pictures. Such as, your game is nearly to the end of scense, but there are some seconds needed, then you start load file thread, and your user is still playing game, and when the game go end, your load file operation is complete.

 

If you must free the resource of previous scense and then you have enough memory space to load the files the second scense need, then you need to show a transitions to user and then load file in a thread. 

 

Share this post


Link to post

You cant be loading the image and displaying it at the same time. you are going to have to load it before you display it. Which means somehow you are going to have to anticipate what images you will need before you need them.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×