Beispiel #1
0
        public virtual void OnAttached(GameObject owner)
        {
            if (owner == null)
                throw new ArgumentNullException("owner");

            Owner = owner;
            World = Owner.World;
            Stage = World.Stage;
        }
Beispiel #2
0
        void UpdateLoop()
        {
            WaitHandle.WaitAll(new WaitHandle[] { RendererReady });

            Physics.Resources.ResourceLoaders.Init(CoreResources, FileSystem);
            Physics.Resources.ResourceLoaders.Init(GameResources, FileSystem);

            DeferredRenderer = new Graphics.Deferred.DeferredRenderer(CoreResources, GraphicsBackend, GraphicsBackend.Width, GraphicsBackend.Height);
            PostEffectManager = new Graphics.Post.PostEffectManager(FileSystem, CoreResources, GraphicsBackend, GraphicsBackend.Width, GraphicsBackend.Height);

            AudioSystem = new Audio.AudioSystem(FileSystem);
            PhysicsWorld = new Triton.Physics.World(GraphicsBackend, GameResources);

            Stage = new Graphics.Stage(GameResources);
            Camera = new Graphics.Camera(new Vector2(GraphicsBackend.Width, GraphicsBackend.Height));

            InputManager = new Input.InputManager(Window.Bounds);

            GameWorld = new World.GameObjectManager(Stage, InputManager, GameResources, PhysicsWorld, Camera);

            LoadCoreResources();

            // Wait until all initial resources have been loaded
            while (!CoreResources.AllResourcesLoaded())
            {
                Thread.Sleep(1);
            }

            Log.WriteLine("Core resources loaded");

            LoadResources();

            while (!GameResources.AllResourcesLoaded())
            {
                Thread.Sleep(1);
            }

            var watch = new System.Diagnostics.Stopwatch();
            watch.Start();

            var accumulator = 0.0f;

            while (Running)
            {
                FrameCount++;
                watch.Restart();

                ElapsedTime += FrameTime;

                if (Window.Focused)
                {
                    InputManager.Update();
                }

                accumulator += FrameTime;
                while (accumulator >= PhysicsStepSize)
                {
                    PhysicsWorld.Update(PhysicsStepSize);
                    accumulator -= PhysicsStepSize;
                }

                AudioSystem.Update();

                GameWorld.Update(FrameTime);

                Update(FrameTime);

                RenderScene(FrameTime, watch);
                FrameTime = (float)watch.Elapsed.TotalSeconds;

                Thread.Sleep(1);
            }
        }