Game Development Community

Unloading. Implementation feedback.

by Matthew Hoesterey · in Torque X 2D · 06/19/2010 (10:56 am) · 0 replies

Heya Guys. I ran into an issue with unloading and just wanted to get some implementation feedback.

I use multiple scene files and then dump everything to a shared scene graph.
for (int i = 0; i < count; i++)
            {
                T2DSceneObject obj = objects[i] as T2DSceneObject;

                if (obj != null)
                {
                    //first we add to our last level objects # I added this to fix the problem
                    _lastLevelObjects.Add(obj);

                    //then we set the objects scenegraphs.
                    obj.SceneGraph = Game.Instance.SharedSceneGraph;
                }
            }

Then later when I unload I leave all the shared data loaded and just unload the level data.
Game.Instance.SceneLoader.Unload(@"data\levels\tribleSleep.txscene");

So I found that not all the objects in the level are actually being unloaded. So I added the list in the above code and on unload I do this:
//Unload last level Objects that where missed.
                    for (int i = 0; i < _lastLevelObjects.Count; i++)
                    {
                        if (_lastLevelObjects[i] != null && !_lastLevelObjects[i].IsTemplate && _lastLevelObjects[i].Manager != null)
                            _lastLevelObjects[i].MarkForDelete = true;
                    }
                    _lastLevelObjects.Clear();


Can anyone see any issues with the above?

I dont want to unload my shared data as that would drastically increase my load times. thanks!.