Example #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));
            }
        }
Example #2
0
        public static Font FromSystemFont(Renderer2D t, string name, FontStyles styles = FontStyles.Regular)
        {
            FontStyles s               = styles;
            var        face            = Platform.LoadSystemFace(t.FT, name, ref s);
            bool       emulate_bold    = false;
            bool       emulate_italics = false;

            if (s != styles)
            {
                switch (styles)
                {
                case FontStyles.Bold:
                    emulate_bold = true;
                    break;

                case FontStyles.Italic:
                    emulate_italics = true;
                    break;

                case FontStyles.Bold | FontStyles.Italic:
                    emulate_bold    = s != FontStyles.Bold;
                    emulate_italics = s != FontStyles.Italic;
                    break;
                }
            }
            return(new Font(t, face, emulate_bold, emulate_italics));
        }
Example #3
0
        public void Draw(Renderer2D renderer)
        {
            var rect = new Rectangle((int)X + 2, (int)Y + 2, (int)Width, (int)Height);

            renderer.FillRectangle(rect, Color4.Black);
            rect.X -= 2; rect.Y -= 2;
            renderer.FillRectangle(rect, Color4.White);

            var off        = 2;
            var heightTrue = Height - 2 * off;

            foreach (var line in graphLines)
            {
                if (line.Points.Count < 2)
                {
                    continue;
                }
                var dX = Width / line.Points.Count;
                for (int i = 0; i < line.Points.Count - 1; i++)
                {
                    var point0 = new Vector2(X + dX * i, Y + off + PlotY(line, i, heightTrue));
                    var point1 = new Vector2(X + dX * (i + 1), Y + off + PlotY(line, i + 1, heightTrue));
                    renderer.DrawLine(line.Color, point0, point1);
                }
            }
        }
Example #4
0
 public static void DrawShadowedText(Renderer2D trender, float size, string text, float x, float y, Color4?col = null)
 {
     trender.DrawString("Arial",
                        size,
                        text,
                        new Vector2(x, y) + new Vector2(2),
                        Color4.Black);
     trender.DrawString("Arial",
                        size,
                        text,
                        new Vector2(x, y),
                        col ?? Color4.White);
 }
Example #5
0
 public static void DrawShadowedText(Renderer2D trender, Font font, float size, string text, float x, float y, Color4?col = null)
 {
     trender.DrawString(font,
                        size,
                        text,
                        x + 2, y + 2,
                        Color4.Black);
     trender.DrawString(font,
                        size,
                        text,
                        x, y,
                        col ?? Color4.White);
 }
Example #6
0
 private Font(Renderer2D t, Face f, bool bold, bool italic)
 {
     ren             = t;
     emulate_bold    = bold;
     emulate_italics = italic;
     this.Face       = f;
     textures.Add(new Texture2D(
                      TEXTURE_SIZE,
                      TEXTURE_SIZE,
                      false,
                      SurfaceFormat.R8
                      ));
     facename = Face.FamilyName;
 }
Example #7
0
        public void Draw(Renderer2D renderer, Mouse m)
        {
            var pos = new Vector2(m.X, m.Y) - (Hotspot * Scale);
            var dst = new Rectangle(
                (int)pos.X, (int)pos.Y,
                (int)(Dimensions.Width * Scale), (int)(Dimensions.Height * Scale)
                );

            renderer.Draw(
                (Texture2D)Resources.FindTexture(Texture),
                Dimensions,
                dst,
                Color,
                BlendMode.Additive
                );
        }
Example #8
0
        public DemoSystemView(FreelancerGame g) : base(g)
        {
            FLLog.Info("Game", "Starting System Viewer Demo");
            sys         = g.GameData.GetSystem("li01");
            camera      = new DebugCamera(g.Viewport);
            camera.Zoom = 5000;
            sysrender   = new SystemRenderer(camera, g.GameData, g.ResourceManager, g);
            world       = new GameWorld(sysrender);
            world.LoadSystem(sys, g.ResourceManager);
            g.Sound.PlayMusic(sys.MusicSpace);
            camera.UpdateProjection();

            trender               = new Renderer2D(Game.RenderState);
            font                  = g.Fonts.GetSystemFont("Agency FB");
            g.Keyboard.KeyDown   += G_Keyboard_KeyDown;
            g.Keyboard.TextInput += G_Keyboard_TextInput;
        }
Example #9
0
        public void Draw(Renderer2D renderer, Mouse m, double globalTime)
        {
            //var pos = new Vector2(m.X, m.Y) - (Hotspot * Scale);
            var dst = new Rectangle(
                (int)m.X, (int)m.Y,
                (int)(Dimensions.Width * Scale), (int)(Dimensions.Height * Scale)
                );
            var angle = MathHelper.WrapF((float)globalTime * Spin, -MathF.PI, MathF.PI);
            var hp    = new Vector2((int)(Hotspot.X * Scale), (int)(Hotspot.Y * Scale));

            renderer.DrawRotated(
                (Texture2D)Resources.FindTexture(Texture),
                Dimensions,
                dst,
                hp,
                Color,
                BlendMode.Additive,
                angle
                );
            renderer.FillRectangle(new Rectangle(m.X, m.Y, 1, 1), Color4.Red);
        }
Example #10
0
		public NebulaRenderer(Nebula n, ICamera c, Game g)
		{
			Nebula = n;
			camera = c;
			game = g;
            nverts = g.GetService<NebulaVertices>();
            render2D = g.GetService<Renderer2D>();
            resman = g.GetService<ResourceManager>();
            billboards = g.GetService<Billboards>();
			rand = new Random();
			if (n.HasInteriorClouds)
			{
				puffsinterior = new InteriorPuff[n.InteriorCloudCount];
				for (int i = 0; i < n.InteriorCloudCount; i++)
					puffsinterior[i].Spawned = false;
			}
			GenerateExteriorPuffs();
			//Set Timers
			dynLightningTimer = Nebula.DynamicLightningGap;
			bckLightningTimer = Nebula.BackgroundLightningGap;
		}
Example #11
0
        public static List <string> WrapText(Renderer2D renderer, Font font, int sz, string text, int maxLineWidth, int x, out int newX, ref int dY)
        {
            List <string> strings = new List <string>();

            string[]      words      = text.Split(' ');
            StringBuilder sb         = new StringBuilder();
            int           lineWidth  = x;
            int           spaceWidth = renderer.MeasureString(font, sz, " ").X;

            for (int i = 0; i < words.Length; i++)
            {
                var size = renderer.MeasureString(font, sz, words[i]);
                if (lineWidth + size.X < maxLineWidth)
                {
                    lineWidth += size.X + spaceWidth;
                }
                else
                {
                    if (sb.Length > 0)
                    {
                        strings.Add(sb.ToString());
                        sb.Clear();
                    }
                    dY       += (int)font.LineHeight(sz);
                    lineWidth = size.X + spaceWidth;
                }
                sb.Append(words[i]);
                if (i != words.Length - 1)
                {
                    sb.Append(" ");
                }
            }
            newX = lineWidth;
            if (sb.Length > 0)
            {
                strings.Add(sb.ToString());
                sb.Clear();
            }
            return(strings);
        }
Example #12
0
 public Font(Renderer2D t, string filename, bool bold = false, bool italic = false)
     : this(t, new Face(t.FT, filename), bold, italic)
 {
 }
Example #13
0
        public SpaceGameplay(FreelancerGame g, GameSession session) : base(g)
        {
            FLLog.Info("Game", "Starting Gameplay Demo");
            sys = g.GameData.GetSystem(session.PlayerSystem);
            var shp = g.GameData.GetShip(session.PlayerShip);

            //Set up player object + camera
            this.session = session;
            player       = new GameObject(shp.Drawable, g.ResourceManager, false);
            control      = new ShipControlComponent(player);
            control.Ship = shp;
            player.Components.Add(control);
            powerCore = new PowerCoreComponent(player)
            {
                ThrustCapacity   = 1000,
                ThrustChargeRate = 100
            };
            player.Components.Add(powerCore);
            player.PhysicsComponent.Position             = session.PlayerPosition;
            player.PhysicsComponent.Orientation          = session.PlayerOrientation;
            player.PhysicsComponent.Material.Restitution = 1;
            player.PhysicsComponent.Mass = shp.Mass;
            player.Nickname = "player";
            foreach (var equipment in session.MountedEquipment)
            {
                var equip = g.GameData.GetEquipment(equipment.Value);
                var obj   = new GameObject(equip, player.GetHardpoint(equipment.Key), player);
                player.Children.Add(obj);
            }

            camera = new ChaseCamera(Game.Viewport);
            camera.ChasePosition    = session.PlayerPosition;
            camera.ChaseOrientation = new Matrix4(player.PhysicsComponent.Orientation);
            camera.Reset();

            sysrender = new SystemRenderer(camera, g.GameData, g.ResourceManager, g);
            world     = new GameWorld(sysrender);
            world.LoadSystem(sys, g.ResourceManager);
            world.Objects.Add(player);
            world.Physics.SetDampingFactors(0.01f, 1f);
            world.RenderUpdate  += World_RenderUpdate;
            world.PhysicsUpdate += World_PhysicsUpdate;
            var eng = new GameData.Items.Engine()
            {
                FireEffect = "gf_li_smallengine02_fire", LinearDrag = 600, MaxForce = 48000
            };

            player.Components.Add((ecpt = new EngineComponent(player, eng, g)));
            ecpt.Speed = 0;
            player.Register(sysrender, world.Physics);
            g.Sound.PlayMusic(sys.MusicSpace);
            trender = new Renderer2D(Game.RenderState);
            font    = g.Fonts.GetSystemFont("Agency FB");
            g.Keyboard.TextInput += G_Keyboard_TextInput;
            debugphysics          = new PhysicsDebugRenderer();
            cur_arrow             = g.ResourceManager.GetCursor("cross");
            cur_reticle           = g.ResourceManager.GetCursor("fire_neutral");
            current_cur           = cur_arrow;
            hud = new Hud(g);
            hud.SetManeuver("FreeFlight");
            Game.Keyboard.TextInput += Game_TextInput;
            g.Keyboard.KeyDown      += Keyboard_KeyDown;
            input = new InputManager(Game);
            input.ToggleActivated       += Input_ToggleActivated;
            input.ToggleUp              += Input_ToggleUp;
            hud.OnManeuverSelected      += Hud_OnManeuverSelected;
            hud.OnEntered               += Hud_OnTextEntry;
            pilotcomponent               = new AutopilotComponent(player);
            pilotcomponent.DockComplete += Pilotcomponent_DockComplete;
            player.Components.Add(pilotcomponent);
            player.World              = world;
            world.MessageBroadcasted += World_MessageBroadcasted;
        }
Example #14
0
            public override void Draw(ref bool is2d, TimeSpan delta, Rectangle bounds, Renderer2D render2d)
            {
                if (!Enabled)
                {
                    return;
                }
                if (is2d)
                {
                    render2d.Finish();
                }
                is2d = false;
                if (Style.Color != null || Panel.modelColor != null)
                {
                    SetupModifiedMaterials();
                    Color4 color;
                    if (Panel.modelColor != null)
                    {
                        color = Panel.modelColor.Value;
                    }
                    else
                    {
                        color = Style.Color.Value;
                    }
                    for (int i = 0; i < Materials.Count; i++)
                    {
                        Materials[i].Mat.Dc = color;
                    }
                }
                Panel.mcam.CreateTransform(Panel.Scene.Manager.Game, bounds);
                Drawable.Update(Panel.mcam, delta, TimeSpan.FromSeconds(Panel.Scene.Manager.Game.TotalTime));
                Matrix4 rot = Matrix4.Identity;

                if (Panel.modelRotate != Vector3.Zero)
                {
                    rot = Matrix4.CreateRotationX(Panel.modelRotate.X) *
                          Matrix4.CreateRotationY(Panel.modelRotate.Y) *
                          Matrix4.CreateRotationZ(Panel.modelRotate.Z);
                }
                Panel.Scene.Manager.Game.RenderState.Cull = false;
                Drawable.Draw(Panel.Scene.Manager.Game.RenderState, Transform * rot, Lighting.Empty);
                Panel.Scene.Manager.Game.RenderState.Cull = true;
                if (Style.Color != null || Panel.modelColor != null)
                {
                    for (int i = 0; i < Materials.Count; i++)
                    {
                        Materials[i].Mat.Dc = Materials[i].Dc;
                    }
                }
            }
Example #15
0
 public abstract void Draw(ref bool is2d, TimeSpan delta, Rectangle bounds, Renderer2D render2d);
Example #16
0
            public override void Draw(ref bool is2d, TimeSpan delta, Rectangle bounds, Renderer2D render2d)
            {
                if (!Enabled)
                {
                    return;
                }
                if (Style.Color == null && Style.BorderColor == null)
                {
                    return;
                }
                if (!is2d)
                {
                    render2d.Start(Panel.Scene.GWidth, Panel.Scene.GHeight);
                }
                is2d = true;
                var r = GetRectangle(bounds);

                if (Style.Color != null)
                {
                    render2d.FillRectangle(r, Style.Color.Value);
                }
                if (Style.BorderColor != null)
                {
                    render2d.DrawRectangle(r, Style.BorderColor.Value, 1);
                }
            }
Example #17
0
 public override void Draw(ref bool is2d, TimeSpan delta, Rectangle bounds, Renderer2D render2d)
 {
     if (!Enabled)
     {
         return;
     }
     if (!is2d)
     {
         render2d.Start(Panel.Scene.GWidth, Panel.Scene.GHeight);
     }
     is2d = true;
     Text.Draw(Panel.Scene.Manager, bounds);
 }