Game Development Community

Mission Loading Question: Materials and Datablocks

by Michael Perry · in Torque Game Engine Advanced · 12/12/2006 (9:32 am) · 1 replies

Hello all! I'm playing around with the TGEA demo, and I've come up with a question that I hope someone can help me out with.

Here's the hypothetical scenario:

Let's say I have 5 missions. Creation of these missions and their objects has led to a grand total of 500 materials, 30 shaders and 50 datablocks.

Now, I'm working with a 128 MB ATI card with only Shader 1.4 support, so I don't want to load all 500 materials into memory for the entire duration of the game. What's more, loading of all of those datablocks bogs down the mission start time.

So, how could I go about loading shaders, materials, and datablocks that will be used in the mission, while leaving the rest out?

I have a couple ideas, but they require brute force, so I'd like your opinions.

Thanks in advance.

#1
12/12/2006 (12:24 pm)
Our project has lots of missions, materials, shaders and datablocks. If we just let them all load up at the same time it takes almost 2 minutes to get to the initial menu. Our project more or less can be broken up into small mini games and so for each of those games we have them exec the material files that the game needs. We took out the loadMaterials() function call in init.cs. In order to not overwrite materials that have already been loaded we set up a system similar to the C pre-processor where at the top of each material file we call a function that creates a new ScriptObject with the name specified in the materials.cs file. The function checks whether or not that ScriptObject already exists, if it does then it doesn't load the materials.cs file again because those materials should already be loaded. One catch is which SimGroup the materials get added to when they are created. To ensure they exist between missions we change the $instantGroup variable to a SimGroup that isn't in the MissionCleanup group before we exec a block of materials, then change it back to what it was after we are done with the execs.

So that is how we do it, but that might not be the best way for you. (And in fact, if I get some more time I will probably look into trying to get rid of the requirement of having to define a string in each materials.cs file, since it can be a pain if you do it late in the project when lots of material files already exist.) I would still recommend removing the loadMaterials() function call and only loading the materials you need for your menu (if you have one). Then when you are loading a mission, if each of your assets are under specific directories you might want to just change the loadMaterials() function definition to take a string pattern that would only include the directories you want to load the materials from. That doesn't particularly work if you have lots of shared assets however. In the case of lots of assets being shared you will most likely have to have a list of materials files that are needed for each mission and then just go through and exec them. Unless you wanted to try to load them all dynamically which I briefly made a comment on in this thread.