Game Development Community

Loading a level WITHOUT 'schedule'

by Richard Skala · in iTorque 2D · 06/08/2010 (9:42 pm) · 3 replies

I've been looking through the forums for the proper way to load a .t2d level, and every one I've found uses the schedule() function to call loadLevel() at a later time.

I've seen people on these forums (rightfully) call that "duct tape", and I am uncomfortable having a function called at some later time as it could have unpredictable behavior, and it's also bad programming practice.

Has anyone successfully loaded a level WITHOUT schedule()? I can't imagine Torque being developed without proper level loading methods, so I'm guessing that there has to be a way.

#1
06/09/2010 (12:16 pm)
You should be able to load a level without schedule. I've done it in my games.
#2
06/09/2010 (1:03 pm)
Did you use a script call or did you use some C++ function call?

I should clarify about what I asked previously. I understand that you can't load a level immediately, as you are most likely in some object's update, and therefore loading must be put off until possibly the next update. It is the uncertainty of some future scheduling that makes me uneasy. Is a function called from a schedule guaranteed to be called before other update functions (such as the object list)?
#3
06/13/2010 (9:52 am)
We ended up writing a custom resource management system that replaces the load level calls. What it does is simply enough accept a list of resource elements along with a command to eval on completion, then loads them one at a time, being careful to watch what has been loaded and what still needs to be loaded. It doesn't use any schedules because it pays attention to the count of objects loaded vs. what still needs to be loaded. Then, once it is able to ensure that everything requested has been loaded, it executes the on-completion eval. I would suggest taking a few hours out of your time to write a custom resource loader rather than using the .t2d level files if your game relies on loading multiple levels. If it only has one level, then loading the one .t2d level at start should work fine, just make sure that the level is completely empty and only add in objects as you need them.
#4
06/13/2010 (9:52 am)
<Removed Duplicate Posting>