pieomy00 3 Posted March 10, 2020 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
David Heffernan 2345 Posted March 10, 2020 Define "best" please. Also, the try/finally seems a little pointless. Share this post Link to post
pieomy00 3 Posted March 10, 2020 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
David Heffernan 2345 Posted March 10, 2020 We don't really know what your main goal is. Hard to give useful advice. Share this post Link to post
pieomy00 3 Posted March 10, 2020 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
Hans J. Ellingsgaard 21 Posted March 10, 2020 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
Vandrovnik 214 Posted March 10, 2020 I think loading bitmaps can be run in a thread: http://docwiki.embarcadero.com/RADStudio/Rio/en/Multi-Threading_for_TBitmap,_TCanvas,_and_TContext3D 1 Share this post Link to post
pieomy00 3 Posted March 11, 2020 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
pieomy00 3 Posted March 11, 2020 9 hours ago, Vandrovnik said: I think loading bitmaps can be run in a thread: http://docwiki.embarcadero.com/RADStudio/Rio/en/Multi-Threading_for_TBitmap,_TCanvas,_and_TContext3D 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
Cristian Peța 103 Posted March 11, 2020 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
Sherlock 663 Posted March 11, 2020 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
pieomy00 3 Posted March 11, 2020 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
Sherlock 663 Posted March 11, 2020 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
pieomy00 3 Posted March 11, 2020 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. 1 Share this post Link to post
Sherlock 663 Posted March 11, 2020 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
Rollo62 536 Posted March 11, 2020 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
pieomy00 3 Posted March 11, 2020 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 1 Share this post Link to post
Rollo62 536 Posted March 11, 2020 (edited) 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 Edited March 11, 2020 by Rollo62 Share this post Link to post
pieomy00 3 Posted March 11, 2020 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 1 Share this post Link to post
pcplayer99 11 Posted March 17, 2020 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
Doug Rudd 2 Posted May 5, 2020 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