Exemplo n.º 1
0
        public void StartServer()
        {
            DontDestroyOnLoad(gameObject);
            _logicTimer    = new LogicTimer(OnLogicUpdate);
            _playerManager = new ServerPlayerManager(this);

            //_packetProcessor = new NetPacketProcessor();

            ////register auto serializable vector2
            //_packetProcessor.RegisterNestedType((w, v) => w.Put(v), r => r.GetVector2());

            ////register auto serializable PlayerState
            //_packetProcessor.RegisterNestedType<PlayerState>();

            //_packetProcessor.SubscribeReusable<JoinPacket, NetPeer>(OnJoinReceived);
            //_netManager = new NetManager(this)
            //{
            //    AutoRecycle = true
            //};

            _netManager      = G.CSEngineApp.LiteNet._netManager;
            _packetProcessor = G.CSEngineApp.LiteNet._packetProcessor;
            _packetProcessor.RegisterNestedType((w, v) => w.Put(v), r => r.GetVector2());
            _packetProcessor.RegisterNestedType <PlayerState>();
            _packetProcessor.SubscribeReusable <JoinPacket, NetPeer>(OnJoinReceived);
            _netManager.Start(10515);
            _logicTimer.Start();
        }
Exemplo n.º 2
0
 public void StartServer()
 {
     if (_netManager.IsRunning)
     {
         return;
     }
     _netManager.Start(10515);
     _logicTimer.Start();
 }
        void INetEventListener.OnPeerConnected(NetPeer peer)
        {
            Logger.Log("[C] Connected to server: " + peer.EndPoint + " (" + peer.Id + ")");
            _server = peer;

            // Tell listeners we connected
            OnClientConnected?.Invoke();

            _logicTimer.Start();
        }
Exemplo n.º 4
0
        public void Start(int port)
        {
            if (_netManager.IsRunning)
            {
                return;
            }

            _netManager.Start(port);
            _logicTimer.Start();
        }
Exemplo n.º 5
0
    public void StartServer()
    {
        if (netManager.IsRunning)
        {
            return;
        }
        netManager.Start(port);
        logicTimer.Start();

        Debug.Log("Server started");
    }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var config = new GravityConfig()
            {
                AutoGenerateParticleData   = true,
                GeneratedParticleDataCount = 75,

                ParticleCount = 1500,

                MinimumInitialPositionX = 0,
                MaximumInitialPositionX = 15000,

                MinimumInitialPositionY = 0,
                MaximumInitialPositionY = 15000,

                MinimumMass = 6,
                MaximumMass = 150,


                MinimumInitialVelocity = -50,
                MaximumInitialVelocity = 50,

                BatchCount = 125
            };

            //var scene = new TwoBodyCollisionScene();
            //var config = scene.Config;

            var logicController = new LogicController(config);
            var window          = new Window(config);
            var space           = logicController.StartLogic();

            space.Particles.Add(
                logicController.ParticleController.CreateParticle(new GravityParticleData(1000000, 850, Color.Yellow), new Vector2(7400, 7400))
                );

            space.Particles.Add(
                logicController.ParticleController.CreateParticle(new GravityParticleData(1100000, 750, Color.Blue), new Vector2(9400, 7400))
                );

            space.Particles.Add(
                logicController.ParticleController.CreateParticle(new GravityParticleData(1100000, 950, Color.Red), new Vector2(8400, 5400))
                );
            //scene.Initialize(logicController, space);

            window.Run();

            var stopwatch    = new Stopwatch();
            var fpsStopwatch = new Stopwatch();

            var ms = new List <double>();

            fpsStopwatch.Start();

            var timer = new LogicTimer(() =>
            {
                stopwatch.Restart();

                logicController.UpdateLogic(space);
                window.Update(space.Particles);

                if (fpsStopwatch.ElapsedMilliseconds >= 1000)
                {
                    fpsStopwatch.Restart();
                    if (ms.Count > 0)
                    {
                        Console.WriteLine("Average FPS: " + ms.Average());
                    }
                    ms.Clear();
                }

                stopwatch.Stop();

                ms.Add(1000.0 / stopwatch.Elapsed.TotalMilliseconds);

                LogicTimer.DeltaTime = 1f / (1000f / (float)stopwatch.Elapsed.TotalMilliseconds);

                if (LogicTimer.DeltaTime < LogicTimer.FixedDelta)
                {
                    LogicTimer.DeltaTime = LogicTimer.FixedDelta;
                }
            });

            timer.Start();

            while (true)
            {
                timer.Update();
            }
        }