public void CreateStarScroller_ShouldCreateStars()
        {
            base.InitializeCluwneLib(1280, 720, false, 60);
            Stars       = new StarScroller();
            renderimage = new RenderImage("StarScroller", 1920, 1080);

            while (CluwneLib.IsRunning)
            {
                var lastFrameTime = clock.ElapsedTimeAsSeconds();
                clock.Restart();
                _frameEvent = new FrameEventArgs(lastFrameTime);
                CluwneLib.ClearCurrentRendertarget(Color4.Black);
                CluwneLib.Window.DispatchEvents();

                renderimage.BeginDrawing();                     // set temp as CRT (Current Render Target)
                renderimage.Clear();                            //Clear
                base.GetResourceCache.GetSprite("AAAA").Draw(); //Draw NoSpritelogo

                renderimage.EndDrawing();                       // set previous rendertarget as CRT (screen in this case)

                renderimage.Blit(0, 0, 1280, 768);              // draw blurred nosprite logo

                CluwneLib.Window.Graphics.Display();
            }
        }
Example #2
0
        public void GaussianBlurRadius9_ShouldBlur()
        {
            preblur       = new RenderImage("testGaussianBlur", 1280, 768);
            blur          = new RenderImage("testGaussianBlur1", 1280, 768);
            _gaussianBlur = new GaussianBlur(_resourceCache);

            _gaussianBlur.SetRadius(9);
            _gaussianBlur.SetAmount(2);
            _gaussianBlur.SetSize(new Vector2(preblur.Width, preblur.Height));

            while (CluwneLib.IsRunning)
            {
                var lastFrameTime = clock.ElapsedTimeAsSeconds();
                clock.Restart();
                _frameEvent = new FrameEventArgs(lastFrameTime);
                CluwneLib.ClearCurrentRendertarget(Color4.Black);
                CluwneLib.Window.DispatchEvents();

                preblur.BeginDrawing();                             // set temp as CRT
                preblur.Clear();                                    //Clear
                _resourceCache.GetSprite("flashlight_mask").Draw(); //Draw NoSpritelogo
                preblur.EndDrawing();                               // set previous rendertarget as CRT (screen in this case)

                _gaussianBlur.PerformGaussianBlur(preblur);         // blur rendertarget

                preblur.Blit(0, 0, 1280, 768);                      // draw blurred nosprite logo

                CluwneLib.Window.Graphics.Display();
            }
        }
Example #3
0
        public void GaussianBlurRadius11_ShouldBlur()
        {
            preblur       = new RenderImage("testGaussianBlur", 1280, 768);
            _gaussianBlur = new GaussianBlur(_resourceCache);

            _gaussianBlur.SetRadius(11);
            _gaussianBlur.SetAmount(2);
            _gaussianBlur.SetSize(preblur.Size);

            while (CluwneLib.IsRunning)
            {
                var lastFrameTime = clock.ElapsedTimeAsSeconds();
                clock.Restart();
                _frameEvent = new FrameEventArgs(lastFrameTime);
                CluwneLib.ClearCurrentRendertarget(Color4.Black);
                CluwneLib.Window.DispatchEvents();

                preblur.BeginDrawing(); // set temp as CRT (Current Render Target)
                //preblur.Clear();       //Clear
                sprite          = _resourceCache.GetSprite("flashlight_mask");
                sprite.Position = Vector2.Zero;
                sprite.Draw();
                preblur.EndDrawing();  // set previous rendertarget as CRT (screen in this case)

                //_gaussianBlur.PerformGaussianBlur(preblur); // blur rendertarget

                preblur.Blit(0, 0, preblur.Width, preblur.Height, Color.White, BlitterSizeMode.Crop); // draw blurred nosprite logo

                CluwneLib.Window.Graphics.Display();
            }
        }
Example #4
0
 /// <summary>
 /// Runs a tick of the simulation.
 /// </summary>
 /// <param name="e">Current GameTiming.FrameTime</param>
 private void Update(FrameEventArgs e)
 {
     _networkManager.ProcessPackets();
     CluwneLib.RunIdle(this, e);
     AssemblyLoader.BroadcastUpdate(AssemblyLoader.UpdateLevel.PreEngine, e.Elapsed);
     _stateManager.Update(e);
     AssemblyLoader.BroadcastUpdate(AssemblyLoader.UpdateLevel.PostEngine, e.Elapsed);
 }
Example #5
0
 public void StartCluwneLibLoop()
 {
     while (CluwneLib.IsRunning)
     {
         var lastFrameTime = GetClock.ElapsedTimeAsSeconds();
         GetClock.Restart();
         frameEvent = new FrameEventArgs(lastFrameTime);
         CluwneLib.ClearCurrentRendertarget(Color4.Black);
         CluwneLib.Window.DispatchEvents();
         InjectedMethod();
         CluwneLib.Window.Graphics.Display();
     }
 }
Example #6
0
        //These methods are called directly from the main loop to allow for cross-state ui elements. (Console maybe)

        /// <summary>
        ///     Updates the logic of UI Components.
        /// </summary>
        public void Update(FrameEventArgs e)
        {
            if (_console.Visible)
            {
                _console.Update(e.Elapsed);
            }

            if (moveMode && movingComp != null)
            {
                movingComp.Position = MousePos - dragOffset;
            }

            foreach (var component in _components)
            {
                component.Update(e.Elapsed);
            }
        }
Example #7
0
        /// <summary>
        /// Renders the view of the simulation.
        /// </summary>
        /// <param name="e">Current GameTiming.RealFrameTime</param>
        private void Render(FrameEventArgs e)
        {
            CluwneLib.ClearCurrentRendertarget(Color4.Black);
            CluwneLib.Window.DispatchEvents();

            // draw everything
            _stateManager.Render(e);

            // interface runs in realtime, so it is updated here
            _userInterfaceManager.Update(e);

            _userInterfaceManager.Render(e);

            _netGrapher.Update();

            // swap buffers to show the screen
            CluwneLib.Window.Graphics.Display();
        }
Example #8
0
        /// <summary>
        ///     Renders UI Components to screen.
        /// </summary>
        public void Render(FrameEventArgs e)
        {
            foreach (var component in _components)
            {
                component.Draw();
            }

            if (_console.Visible)
            {
                _console.Draw();
            }

            if (showCursor)
            {
                _cursorSprite = DragInfo.DragSprite != null && DragInfo.IsActive
                    ? DragInfo.DragSprite
                    : _resourceCache.GetSprite("cursor");

                _cursorSprite.Position = MousePos;
                _cursorSprite.Draw();
            }
        }
Example #9
0
        public void Run()
        {
            Logger.Debug("Initializing GameController.");

            _configurationManager.LoadFromFile(PathHelpers.ExecutableRelativeFile("client_config.toml"));

            _resourceCache.LoadBaseResources();
            // Load resources used by splash screen and main menu.
            LoadSplashResources();
            ShowSplashScreen();

            _resourceCache.LoadLocalResources();

            LoadContentAssembly <GameShared>("Shared");
            LoadContentAssembly <GameClient>("Client");

            IoCManager.Resolve <ILightManager>().Initialize();

            // Call Init in game assemblies.
            AssemblyLoader.BroadcastRunLevel(AssemblyLoader.RunLevel.Init);

            //Setup Cluwne first, as the rest depends on it.
            SetupCluwne();
            CleanupSplashScreen();

            //Initialization of private members
            _tileDefinitionManager.InitializeResources();

            _serializer.Initialize();
            var prototypeManager = IoCManager.Resolve <IPrototypeManager>();

            prototypeManager.LoadDirectory(@"Prototypes");
            prototypeManager.Resync();
            _networkManager.Initialize(false);
            _netGrapher.Initialize();
            _userInterfaceManager.Initialize();
            _mapManager.Initialize();
            _placementManager.Initialize();

            _networkManager.RegisterNetMessage <MsgFullState>(MsgFullState.NAME, (int)MsgFullState.ID, message => IoCManager.Resolve <IGameStateManager>().HandleFullStateMessage((MsgFullState)message));
            _networkManager.RegisterNetMessage <MsgStateUpdate>(MsgStateUpdate.NAME, (int)MsgStateUpdate.ID, message => IoCManager.Resolve <IGameStateManager>().HandleStateUpdateMessage((MsgStateUpdate)message));
            _networkManager.RegisterNetMessage <MsgEntity>(MsgEntity.NAME, (int)MsgEntity.ID, message => IoCManager.Resolve <IClientEntityManager>().HandleEntityNetworkMessage((MsgEntity)message));

            _stateManager.RequestStateChange <MainScreen>();

            #region GameLoop

            // maximum number of ticks to queue before the loop slows down.
            const int maxTicks = 5;

            _time.ResetRealTime();
            var maxTime = TimeSpan.FromTicks(_time.TickPeriod.Ticks * maxTicks);

            while (CluwneLib.IsRunning)
            {
                var accumulator = _time.RealTime - _lastTick;

                // If the game can't keep up, limit time.
                if (accumulator > maxTime)
                {
                    // limit accumulator to max time.
                    accumulator = maxTime;

                    // pull lastTick up to the current realTime
                    // This will slow down the simulation, but if we are behind from a
                    // lag spike hopefully it will be able to catch up.
                    _lastTick = _time.RealTime - maxTime;

                    // announce we are falling behind
                    if ((_time.RealTime - _lastKeepUpAnnounce).TotalSeconds >= 15.0)
                    {
                        Logger.Warning("[SRV] MainLoop: Cannot keep up!");
                        _lastKeepUpAnnounce = _time.RealTime;
                    }
                }

                _time.StartFrame();

                var realFrameEvent = new FrameEventArgs((float)_time.RealFrameTime.TotalSeconds);

                // process Net/KB/Mouse input
                Process(realFrameEvent);

                _time.InSimulation = true;
                // run the simulation for every accumulated tick
                while (accumulator >= _time.TickPeriod)
                {
                    accumulator -= _time.TickPeriod;
                    _lastTick   += _time.TickPeriod;

                    // only run the sim if unpaused, but still use up the accumulated time
                    if (!_time.Paused)
                    {
                        // update the simulation
                        var simFrameEvent = new FrameEventArgs((float)_time.FrameTime.TotalSeconds);
                        Update(simFrameEvent);
                        _time.CurTick++;
                    }
                }

                // if not paused, save how close to the next tick we are so interpolation works
                if (!_time.Paused)
                {
                    _time.TickRemainder = accumulator;
                }

                _time.InSimulation = false;

                // render the simulation
                Render(realFrameEvent);
            }

            #endregion GameLoop

            _networkManager.ClientDisconnect("Client disconnected from game.");
            CluwneLib.Terminate();
            Logger.Info("GameController terminated.");

            IoCManager.Resolve <IConfigurationManager>().SaveToFile();
        }
Example #10
0
 /// <summary>
 /// Processes all simulation I/O. Keyboard/Mouse/Network code gets called here.
 /// </summary>
 private void Process(FrameEventArgs e)
 {
     //TODO: Keyboard/Mouse input needs to be processed here.
 }