I currently have a program that has four content loading threads(to reduce lag), and one rendering thread. I just found out that the reason why my program was using 20% more CPU was because the ALLEGRO_FONT does not have the current display set, because it's loaded in the content thread, which does not have a current display. So I set the display and then I start to see a lot of crashing. Well, now I have just found out this is because I call al_hold_bitmap_drawing(true) in the rendering thread, and that interferes when loading bitmaps/fonts. So, my whole method is screwed now, and I pretty much need to redo my whole base of the program, woohoo!
Since the four content threads are pretty much useless, I'm going to get rid of those and do the content loading in the rendering thread. Now, before I went and jumped on programming that, I was thinking about how I can make sure that lag doesn't happen here. This is where my problem comes in. How can I make sure that whenever the redrawTimer is set off that it will stop loading the bitmap, if its trying to load one, and redraw? A friend of mine mentioned making a queue to set priorities on, or even having two queues, checking the first one first since it has higher priority. That solves that but I still need to make sure that the al_load_bitmap or al_load_font function won't take longer than needed. Since the FPS is 20, if it starts loading a bitmap right when a redraw event is emitted, it could stop the thread and it'd have to wait a bit longer to be redrawn. Is there anyway to do this?
I do apologize about the title of this thread, I was not sure what to name the topic.
The way to do it is via threads. I'd figure out how to fix whatever is causing you grief.
The only other way to do it without writing your own loading functions would be to write your own file interface that was stacked on top of the normal one. If you override the reading function to look like:
size_t my_read(ALLEGRO_FILE *f, void *ptr, size_t size) { if (timer_ticked) { do_logic(); do_gfx(); } // read data into buffer return read_bytes; }
Then if you loaded a bitmap, it would periodically call your logic / graphics while in the middle. I don't know what horrible side effects this might cause.
I doubt having that many loading threads would actually increase performance anyway.
I'm sure the hard disk would just be a bottleneck.
Are you trying to remove loading screens while in-game perhaps?
Now that's premature optimization. Four threads? do you really need all those threads?, and do you know that you can't access to the memory at the same time using different threads right?, the main thread it also counts.
Indeed the hard disk will be the bottleneck anyway.
I was thinking about how I can make sure that lag doesn't happen here.
Place a loading screen, and start loading your resource, that at least your are loading the textures and meshes of "Heavy Rain" it shouldn't take much time anyway.
How can I make sure that whenever the redrawTimer is set off that it will stop loading the bitmap
Now that's premature optimization... I had to say it... Believe me, you don't want to do that. Load everything you can before using it.
Since the FPS is 20
20 FPS?... Why such low refresh rate? are you developing a game for a really really old computer?.
Is there anyway to do this?
Yes, there is... But I think that is not the right question .
Don't try this at home:
A poorly implemented demo of loading a bitmap in the main thread without interrupting the flow of the game.
Press any key to start loading "test.png". It should continue to flash black/white every second. Press 'q' to quit.