public override void Unregister()
 {
     Game.Keyboard.TextInput -= Game_TextInput;
     Game.Keyboard.KeyDown   -= Keyboard_KeyDown;
     input.Dispose();
     hud.Dispose();
     sysrender.Dispose();
     world.Dispose();
 }
 public override void Unregister()
 {
     Game.Keyboard.TextInput -= Game_TextInput;
     Game.Keyboard.KeyDown   -= Keyboard_KeyDown;
     Game.Mouse.MouseDown    -= Mouse_MouseDown;
     input?.Dispose();
     sysrender?.Dispose();
     world?.Dispose();
 }
Beispiel #3
0
 public void Finish()
 {
     GameWorld.Dispose();
 }
Beispiel #4
0
        void SceneSetup(ThnScript[] scripts, bool resetObjects = true)
        {
            hasScene = false;
            currentTime = 0;
            if (resetObjects)
            {
                sceneObjects = new Dictionary<string, ThnObject>(StringComparer.OrdinalIgnoreCase);
                layers = new List<Tuple<IDrawable, ThnObject>>();
            }

            if (spawnObjects && resetObjects) {
                if (Renderer != null)
                {
                    Renderer.Dispose();
                    World.Dispose();
                }
                Renderer = new SystemRenderer(camera, gameData, game.GetService<GameResourceManager>(), game);
                World = new GameWorld(Renderer, false);
            }
            if (scriptContext.SetScript != null && resetObjects)
            {
                var inst = new ThnScriptInstance(this, scriptContext.SetScript);
                inst.ConstructEntities(sceneObjects, spawnObjects);
            }
            if (instances != null && resetObjects)
            {
                foreach (var inst in instances)
                    inst.Cleanup();
            }
            if(resetObjects)
                instances = new List<ThnScriptInstance>();
            foreach (var script in scripts)
            {
                var ts = new ThnScriptInstance(this, script);
                ts.ConstructEntities(sceneObjects, spawnObjects && resetObjects);
                instances.Add(ts);
            }

            if (resetObjects)
            {
                var firstCamera = sceneObjects.Values.FirstOrDefault(x => x.Camera != null);
                if (firstCamera == null) firstCamera = sceneObjects.Values.FirstOrDefault(x => x.Camera != null);
                if (firstCamera != null)
                {
                    camera.Transform = firstCamera.Camera;
                }
            }

            if (spawnObjects && resetObjects)
            {
                //Add starspheres in the right order
                var sorted = ((IEnumerable<Tuple<IDrawable, ThnObject>>) layers).Reverse()
                    .OrderBy(x => x.Item2.Entity.SortGroup).ToArray();
                Renderer.StarSphereModels = new RigidModel[sorted.Length];
                Renderer.StarSphereWorlds = new Matrix4x4[sorted.Length];
                Renderer.StarSphereLightings = new Lighting[sorted.Length];
                starSphereObjects = new ThnObject[sorted.Length];
                for (int i = 0; i < sorted.Length; i++)
                {
                    Renderer.StarSphereModels[i] = (sorted[i].Item1 as IRigidModelFile).CreateRigidModel(true);
                    Renderer.StarSphereWorlds[i] =
                        sorted[i].Item2.Rotate * Matrix4x4.CreateTranslation(sorted[i].Item2.Translate);
                    Renderer.StarSphereLightings[i] = Lighting.Empty;
                    starSphereObjects[i] = sorted[i].Item2;
                }
                //Add objects to the renderer
                World.RegisterAll();
            }

            lagCounter = 0;
            //Init
            _Update(0);
            running = true;
        }