how to load a buttload of textures while still drawing...
OK, here is the situation. In most of the software I''ve written so far, I''ve loaded all my graphics prior to doing any drawing on the screen. I''m now in a situation where I would like to load an alternate set of textures once I''ve started drawing to the screen. Unfortunatly, if I just load the textures as normal (basically the same way the NEHE lessons do it) the software doesnt get to the drawing code until after the loading has been completed - and therefor, the image onscreen just freezes until the loading has finished. I guess I have to set up some kind of multithreaded file loading or something? How would one go about this. For example, how would I draw and update a ''loading progress'' meter while I''m busy loading textures???
having a hard time finding any info on gamedev or gamasutra and would appreciate any help.
jason feser
http://members.nbci.com/bucketsofcode
Jason FeserCode Geek / Visuals Guyelasticmediaproductionshttp://www.elasticvisuals.com
quote:
Original post by jasonf
I guess I have to set up some kind of multithreaded file loading or something? How would one go about this. For example, how would I draw and update a ''loading progress'' meter while I''m busy loading textures???
Exactly. If you use SDL, it has some easy to use cross platform threading functions in there. Otherwise (for Win32) see CreateThread in the MSDN, it has about all you need to know.
[Resist Windows XP''s Invasive Production Activation Technology!]
Yes, use threads 
If all that matters is the drawing, one thread will usualy cut it, but if you need more, like gaming logic and IO operations, you are best to use threads.
Let me write it in pseudocode:
Now this is not runnable code, but I would do it something like that
Is it obvious that I do most of my coding in Java?

If all that matters is the drawing, one thread will usualy cut it, but if you need more, like gaming logic and IO operations, you are best to use threads.
Let me write it in pseudocode:
Thread Render
{
void drawScene();
{
...
}
void updateProgressbar(int status)
{
...
}
}
Thread IO
{
void loadTextures(...)
{
....
Render.updatProgressbar(completionpercentage);
}
}
Now this is not runnable code, but I would do it something like that

Is it obvious that I do most of my coding in Java?

"There is a $500 fine for detonating explosives within the confines of a city"
jasonf - i notice your site is at xoom/nbci , where mine also is. i havent been able to upload any files for the last ±2 weeks there have u been able to?
what is the reason for loading while rendering? just wondering. Isn''t this something you would want to avoid if possible. I would think that if your doing any animation, it would crawl.
Jamie
Jamie
it's all about a good time!AOLIM name: -LOKAPUJA-
Well, I''m a self employed ''visualist''. Basically this means that I project trippy visuals at raves, clubs etc..If I bring my pc to a gig (to do beatmatching etc) I would like to be able to load an alternate graphic set while still outputting visuals. It doesn''t have to be excessivly smooth as I can just do a transitioning slide show or something easy on the processor while the loading is taking place. That would only be 4 triangles with texturing and dynamic alpha values....I should be able to render that type of thing while loading...I''ve got a gigahertz pc, 512 megs of ram and a geforce 3. Geez, If I cant render 4 tris with this rig while loading i''m giving up on pc''s 
hehee...
I still haven''t figured out multithreading....It''s just not sticking. I would assume I need two threads, one for my file input, and another for everything else. It''s just that every example I check is far more complex than that, and deals with blockers, mutex''s, message pipes etc...arg!
If I can''t figure it out by the end of today, I''m just going to have a loop that gets called that loads one texture and updates whatever is onscreen every time through the main loop until all the textures have been loaded. Also, one of the main reasons I want this multithreaded is that some of my textures are extremely hi res...2048*2048. These take a while to load

hehee...
I still haven''t figured out multithreading....It''s just not sticking. I would assume I need two threads, one for my file input, and another for everything else. It''s just that every example I check is far more complex than that, and deals with blockers, mutex''s, message pipes etc...arg!
If I can''t figure it out by the end of today, I''m just going to have a loop that gets called that loads one texture and updates whatever is onscreen every time through the main loop until all the textures have been loaded. Also, one of the main reasons I want this multithreaded is that some of my textures are extremely hi res...2048*2048. These take a while to load

Jason FeserCode Geek / Visuals Guyelasticmediaproductionshttp://www.elasticvisuals.com
Well in Java its very simple 
Perhaps you should try some OpenGL coding there..
But all your thread has to do is to load the textures
Im convinced though that you should load them before applying, it would be a lot quicker that way
The reason for the slowness is because IO tends to block the rest of the Thread, so if you make a seperate thread, everything will be running more smoothly
Also, how do you do your IO?
Greetz

Perhaps you should try some OpenGL coding there..
But all your thread has to do is to load the textures

Im convinced though that you should load them before applying, it would be a lot quicker that way

The reason for the slowness is because IO tends to block the rest of the Thread, so if you make a seperate thread, everything will be running more smoothly

Also, how do you do your IO?
Greetz
"There is a $500 fine for detonating explosives within the confines of a city"
Since we''re on the subject, what''s the best way to spawn a new thread in C++? I''ve seen several thread libraries within the MSDN help files, and I want to know which is best to use. Platform-independence is a nice thing to use too. ^_~ Oh, and I can''t use the std template libraries for some strange reason...
Currently I''m using _beginthread(void (*f)(void*)) to do it. Is there something better?
~ Dragonus
Currently I''m using _beginthread(void (*f)(void*)) to do it. Is there something better?
~ Dragonus
Well, for your purposes, you can get away with a fairly simple thread structure. Pretty much all you''d have to do is create a thread via CreateThread() (for Win32). The thread that you create would only have to handle loading the images. Then in your main thread you would just have to poll the i/o thread every once in a while to see if it has ended, and then when it has ended just do the final clean up, and switch to the new task. The only thing that you might have to watch out for is that the variable that you check to determine when the thread has exited is thread safe. I''ve seen the problem arise where if the variable is not thread safe, then if one thread ended before the other one, then it would just get stuck in a loop, and never end, whereas if it happened in the other order, it worked just fine.
J.W.
J.W.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement