コード例 #1
0
        protected override void Load()
        {
            Thread.CurrentThread.Name = "FreelancerGame UIThread";
            //Move to stop _TSGetMainThread error on OSX
            MinimumWindowSize = new Point(640, 480);
            SetVSync(Config.VSync);
            new IdentityCamera(this);
            uithread       = Thread.CurrentThread.ManagedThreadId;
            useintromovies = _cfg.IntroMovies;
            FLLog.Info("Platform", Platform.RunningOS.ToString() + (IntPtr.Size == 4 ? " 32-bit" : " 64-bit"));
            FLLog.Info("Available Threads", Environment.ProcessorCount.ToString());
            //Cache
            ResourceManager = new GameResourceManager(this);
            //Init Audio
            FLLog.Info("Audio", "Initialising Audio");
            Audio = new AudioManager(this);
            if (_cfg.MuteMusic)
            {
                Audio.Music.Volume = 0f;
            }
            //Load data
            FLLog.Info("Game", "Loading game data");
            GameData    = new GameDataManager(_cfg.FreelancerPath, ResourceManager);
            IntroMovies = GameData.GetIntroMovies();
            MpvOverride = _cfg.MpvOverride;
            Thread GameDataLoaderThread = new Thread(() =>
            {
                GameData.LoadData();
                Sound = new SoundManager(GameData, Audio);
                FLLog.Info("Game", "Finished loading game data");
                InitialLoadComplete = true;
            });

            GameDataLoaderThread.Name = "GamedataLoader";
            GameDataLoaderThread.Start();
            //
            Renderer2D      = new Renderer2D(RenderState);
            Fonts           = new FontManager(this);
            Billboards      = new Billboards();
            Nebulae         = new NebulaVertices();
            ViewportManager = new ViewportManager(RenderState);
            ViewportManager.Push(0, 0, Width, Height);
            Screenshots = new ScreenshotManager(this);

            Services.Add(Billboards);
            Services.Add(Nebulae);
            Services.Add(ResourceManager);
            Services.Add(Renderer2D);
            Services.Add(Config);
            Services.Add(Fonts);

            if (useintromovies && IntroMovies.Count > 0)
            {
                ChangeState(new IntroMovie(this, 0));
            }
            else
            {
                ChangeState(new LoadingDataState(this));
            }
        }
コード例 #2
0
        void GameThread()
        {
            if (needLoadData)
            {
                FLLog.Info("Server", "Loading Game Data...");
                GameData.LoadData();
                FLLog.Info("Server", "Finished Loading Game Data");
            }
            if (!string.IsNullOrWhiteSpace(DbConnectionString))
            {
                Database = new ServerDatabase(DbConnectionString);
            }
            Listener?.Start();
            Stopwatch sw       = Stopwatch.StartNew();
            double    lastTime = 0;

            while (running)
            {
                while (!localPackets.IsEmpty && localPackets.TryDequeue(out var local))
                {
                    LocalPlayer.ProcessPacket(local);
                }
                Action a;
                if (worldRequests.Count > 0 && worldRequests.TryDequeue(out a))
                {
                    a();
                }
                //Start Loop
                var time    = sw.Elapsed.TotalMilliseconds;
                var elapsed = (time - lastTime);
                if (elapsed < 2)
                {
                    continue;
                }
                elapsed /= 1000f;
                lastTime = time;
                //Update
                LocalPlayer?.UpdateMissionRuntime(TimeSpan.FromSeconds(elapsed));
                foreach (var world in worlds.Values)
                {
                    world.Update(TimeSpan.FromSeconds(elapsed));
                }
                //Sleep
                Thread.Sleep(0);
            }
            Listener?.Stop();
        }
コード例 #3
0
ファイル: GameServer.cs プロジェクト: Regenhardt/Librelancer
        void GameThread()
        {
            if (needLoadData)
            {
                FLLog.Info("Server", "Loading Game Data...");
                GameData.LoadData(null);
                FLLog.Info("Server", "Finished Loading Game Data");
            }
            InitBaselinePrices();
            Database = new ServerDatabase(this);
            Listener?.Start();
            double lastTime = 0;

            processingLoop = new ServerLoop(Process);
            processingLoop.Start();
            Listener?.Stop();
        }
コード例 #4
0
ファイル: GameServer.cs プロジェクト: youndoldman/Librelancer
        void NetThread()
        {
            FLLog.Info("Server", "Loading Game Data...");
            GameData.LoadData();
            FLLog.Info("Server", "Finished Loading Game Data");
            Database = new ServerDatabase(DbConnectionString);
            var netconf = new NetPeerConfiguration(AppIdentifier);

            netconf.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            netconf.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            netconf.EnableMessageType(NetIncomingMessageType.UnconnectedData);
            netconf.Port = Port;
            netconf.MaximumConnections = 200;
            NetServer = new NetServer(netconf);
            NetServer.Start();
            FLLog.Info("Server", "Listening on port " + Port);
            NetIncomingMessage im;

            while (running)
            {
                while ((im = NetServer.ReadMessage()) != null)
                {
                    switch (im.MessageType)
                    {
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.ErrorMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.VerboseDebugMessage:
                        FLLog.Info("Lidgren", im.ReadString());
                        NetServer.Recycle(im);
                        break;

                    case NetIncomingMessageType.ConnectionApproval:
                        //Ban IP?
                        im.SenderConnection.Approve();
                        NetServer.Recycle(im);
                        break;

                    case NetIncomingMessageType.DiscoveryRequest:
                        NetOutgoingMessage dresp = NetServer.CreateMessage();
                        //Include Server Data
                        dresp.Write(ServerName);
                        dresp.Write(ServerDescription);
                        dresp.Write(GameData.DataVersion);
                        dresp.Write(NetServer.ConnectionsCount);
                        dresp.Write(NetServer.Configuration.MaximumConnections);
                        //Send off
                        NetServer.SendDiscoveryResponse(dresp, im.SenderEndPoint);
                        NetServer.Recycle(im);
                        break;

                    case NetIncomingMessageType.UnconnectedData:
                        //Respond to pings
                        try
                        {
                            if (im.ReadUInt32() == NetConstants.PING_MAGIC)
                            {
                                var om = NetServer.CreateMessage();
                                om.Write(NetConstants.PING_MAGIC);
                                NetServer.SendUnconnectedMessage(om, im.SenderEndPoint);
                            }
                        }
                        catch (Exception)
                        {
                        }
                        break;

                    case NetIncomingMessageType.StatusChanged:
                        NetConnectionStatus status = (NetConnectionStatus)im.ReadByte();

                        string reason = im.ReadString();
                        FLLog.Info("Lidgren", NetUtility.ToHexString(im.SenderConnection.RemoteUniqueIdentifier) + " " + status + ": " + reason);

                        if (status == NetConnectionStatus.Connected)
                        {
                            FLLog.Info("Lidgren", "Remote hail: " + im.SenderConnection.RemoteHailMessage.ReadString());
                            BeginAuthentication(NetServer, im.SenderConnection);
                        }
                        else if (status == NetConnectionStatus.Disconnected)
                        {
                            FLLog.Info("Lidgren", im.SenderEndPoint.ToString() + " disconnected");
                            if (im.SenderConnection.Tag is NetPlayer)
                            {
                                ((NetPlayer)im.SenderConnection.Tag).Disconnected();
                            }
                        }
                        NetServer.Recycle(im);
                        break;

                    case NetIncomingMessageType.Data:
                        var pkt = im.ReadPacket();
                        if (im.SenderConnection.Tag == TagConnecting)
                        {
                            if (pkt is AuthenticationReplyPacket)
                            {
                                var auth = (AuthenticationReplyPacket)pkt;

                                //im.SenderConnection.Disconnect("boilerplate reason from server");

                                /*
                                 *                                  var authkind = (AuthenticationKind)im.ReadByte();
                                 *                                  var guid = new Guid(im.ReadBytes(16));
                                 *                                  if (guid == Guid.Empty) im.SenderConnection.Disconnect("Invalid UUID");
                                 *                                  FLLog.Info("Lidgren", "GUID for " + im.SenderEndPoint + " = " + guid.ToString());
                                 *                                  var p = new NetPlayer(im.SenderConnection, this, guid);
                                 *                                  im.SenderConnection.Tag = p;
                                 *                                  AsyncManager.RunTask(() => p.DoAuthSuccess());*/

                                var p = new NetPlayer(im.SenderConnection, this, auth.Guid);
                                im.SenderConnection.Tag = p;
                                AsyncManager.RunTask(() => p.DoAuthSuccess());
                            }
                            else
                            {
                                im.SenderConnection.Disconnect("Invalid Packet");
                            }
                            NetServer.Recycle(im);
                        }
                        else
                        {
                            var player = (NetPlayer)im.SenderConnection.Tag;
                            AsyncManager.RunTask(() => player.ProcessPacket(pkt));
                            NetServer.Recycle(im);
                        }
                        break;
                    }
                }
                Thread.Sleep(0);                 //Reduce CPU load
            }
            NetServer.Shutdown("Shutdown");
            Database.Dispose();
        }
コード例 #5
0
        protected override void Load()
        {
            Thread.CurrentThread.Name = "FreelancerGame UIThread";
            //Move to stop _TSGetMainThread error on OSX
            MinimumWindowSize = new Point(640, 480);
            SetVSync(Config.Settings.VSync);
            Config.Settings.RenderContext = RenderContext;
            new IdentityCamera(this);
            uithread       = Thread.CurrentThread.ManagedThreadId;
            useintromovies = _cfg.IntroMovies;
            FLLog.Info("Platform", Platform.RunningOS.ToString() + (IntPtr.Size == 4 ? " 32-bit" : " 64-bit"));
            FLLog.Info("Available Threads", Environment.ProcessorCount.ToString());
            //Cache
            ResourceManager = new GameResourceManager(this);
            //Init Audio
            FLLog.Info("Audio", "Initialising Audio");
            Audio = new AudioManager(this);
            Audio.WaitReady();
            Audio.MasterVolume = _cfg.Settings.MasterVolume;
            Audio.Music.Volume = _cfg.Settings.MusicVolume;
            //Load data
            FLLog.Info("Game", "Loading game data");
            GameData    = new GameDataManager(_cfg.FreelancerPath, ResourceManager);
            IntroMovies = GameData.GetIntroMovies();
            MpvOverride = _cfg.MpvOverride;
            Saves       = new SaveGameFolder();
            var    saveLoadTask         = Task.Run(() => Saves.Load(GetSaveFolder()));
            Thread GameDataLoaderThread = new Thread(() =>
            {
                GameData.LoadData(this, () =>
                {
                    Sound = new SoundManager(GameData, Audio, this);
                    Services.Add(Sound);
                    InisLoaded = true;
                });
                FLLog.Info("Game", "Finished loading game data");
                saveLoadTask.Wait();
                Saves.Infocards     = GameData.Ini.Infocards;
                InitialLoadComplete = true;
            });

            GameDataLoaderThread.Name = "GamedataLoader";
            GameDataLoaderThread.Start();
            //
            Fonts      = new FontManager();
            Billboards = new Billboards();
            Nebulae    = new NebulaVertices();
            RenderContext.PushViewport(0, 0, Width, Height);
            Screenshots = new ScreenshotManager(this);
            Typewriter  = new Typewriter(this);

            Services.Add(Billboards);
            Services.Add(Nebulae);
            Services.Add(ResourceManager);
            Services.Add(Config);
            Services.Add(Fonts);
            Services.Add(GameData);
            Services.Add(Sound);
            Services.Add(Typewriter);
            Debug = new DebugView(this);
            if (useintromovies && IntroMovies.Count > 0)
            {
                ChangeState(new IntroMovie(this, 0));
            }
            else
            {
                ChangeState(new LoadingDataState(this));
            }
        }
コード例 #6
0
        void GameThread()
        {
            if (needLoadData)
            {
                FLLog.Info("Server", "Loading Game Data...");
                GameData.LoadData();
                FLLog.Info("Server", "Finished Loading Game Data");
            }
            Database = new ServerDatabase(this);
            Listener?.Start();
            Stopwatch sw       = Stopwatch.StartNew();
            double    lastTime = 0;

            while (running)
            {
                while (!localPackets.IsEmpty && localPackets.TryDequeue(out var local))
                {
                    LocalPlayer.ProcessPacket(local);
                }
                Action a;
                if (worldRequests.Count > 0 && worldRequests.TryDequeue(out a))
                {
                    a();
                }
                //Start Loop
                var time    = sw.Elapsed.TotalMilliseconds;
                var elapsed = (time - lastTime);
                if (elapsed < 2)
                {
                    continue;
                }
                elapsed /= 1000f;
                lastTime = time;
                //Update
                LocalPlayer?.UpdateMissionRuntime(TimeSpan.FromSeconds(elapsed));
                ConcurrentBag <StarSystem> toSpinDown = new ConcurrentBag <StarSystem>();
                Parallel.ForEach(worlds, (world) =>
                {
                    if (!world.Value.Update(TimeSpan.FromSeconds(elapsed)))
                    {
                        toSpinDown.Add(world.Key);
                    }
                });
                //Remove
                if (toSpinDown.Count > 0)
                {
                    lock (availableWorlds)
                    {
                        foreach (var w in toSpinDown)
                        {
                            if (worlds[w].PlayerCount <= 0)
                            {
                                worlds[w].Finish();
                                availableWorlds.Remove(w);
                                worlds.Remove(w);
                                FLLog.Info("Server", $"Shut down world {w.Nickname} ({w.Name})");
                            }
                        }
                    }
                }
                //Sleep
                Thread.Sleep(0);
            }
            Listener?.Stop();
        }