public Cutscene(IEnumerable <ThnScript> scripts, SpaceGameplay gameplay) { this.game = gameplay.FlGame; this.gameData = gameplay.FlGame.GameData; World = gameplay.world; spawnObjects = false; camera = new ThnCamera(gameplay.FlGame.Viewport); //thn = script; var evs = new List <ThnEvent>(); foreach (var thn in scripts) { totalDuration = Math.Max(totalDuration, thn.Duration); foreach (var ev in thn.Events) { ev.TimeOffset = 0; evs.Add(ev); } AddEntities(thn); } evs.Sort((x, y) => x.Time.CompareTo(y.Time)); foreach (var item in evs) { events.Enqueue(item); } }
public Cutscene(ThnScriptContext context, GameDataManager gameData, Rectangle viewport, Game game) { scriptContext = context; this.game = game; this.gameData = gameData; camera = new ThnCamera(viewport); }
public Cutscene(ThnScriptContext context, SpaceGameplay gameplay) { game = gameplay.FlGame; gameData = gameplay.FlGame.GameData; World = gameplay.world; spawnObjects = false; camera = new ThnCamera(gameplay.FlGame.RenderContext.CurrentViewport); scriptContext = context; }
public Cutscene(ThnScriptContext context, GameDataManager gameData, Viewport viewport, Game game) { this.game = game; this.gameData = gameData; scriptContext = context; camera = new ThnCamera(viewport); Renderer = new SystemRenderer(camera, gameData, game.GetService <GameResourceManager>(), game); World = new GameWorld(Renderer, false); //thn = script; var evs = new List <ThnEvent>(); foreach (var thn in context.Scripts) { totalDuration = Math.Max(totalDuration, thn.Duration); foreach (var ev in thn.Events) { ev.TimeOffset = 0; evs.Add(ev); } AddEntities(thn); } //work around SET_CAMERA not being called in disco (match vanilla behaviour) var firstCamera = Objects.Values.Where(x => x.Camera != null).FirstOrDefault(); if (firstCamera != null) { camera.Transform = firstCamera.Camera; } evs.Sort((x, y) => x.Time.CompareTo(y.Time)); foreach (var item in evs) { events.Enqueue(item); } //Add starspheres in the right order var sorted = ((IEnumerable <Tuple <IDrawable, ThnObject> >)layers).Reverse().OrderBy(x => x.Item2.Entity.SortGroup).ToArray(); Renderer.StarSphereModels = new RigidModel[sorted.Length]; Renderer.StarSphereWorlds = new Matrix4x4[sorted.Length]; Renderer.StarSphereLightings = new Lighting[sorted.Length]; starSphereObjects = new ThnObject[sorted.Length]; for (int i = 0; i < sorted.Length; i++) { Renderer.StarSphereModels[i] = (sorted[i].Item1 as IRigidModelFile).CreateRigidModel(true); Renderer.StarSphereWorlds[i] = sorted[i].Item2.Rotate * Matrix4x4.CreateTranslation(sorted[i].Item2.Translate); Renderer.StarSphereLightings[i] = Lighting.Empty; starSphereObjects[i] = sorted[i].Item2; } //Add objects to the renderer World.RegisterAll(); }
public Cutscene(IEnumerable <ThnScript> scripts, FreelancerGame game, GameObject playerShip = null) { this.playerShip = playerShip; this.game = game; camera = new ThnCamera(game.Viewport); Renderer = new SystemRenderer(camera, game.GameData, game.ResourceManager, game); World = new GameWorld(Renderer); //thn = script; var evs = new List <ThnEvent>(); foreach (var thn in scripts) { totalDuration = Math.Max(totalDuration, thn.Duration); foreach (var ev in thn.Events) { ev.TimeOffset = 0; evs.Add(ev); } AddEntities(thn); } //work around SET_CAMERA not being called in disco (match vanilla behaviour) var firstCamera = Objects.Values.Where(x => x.Camera != null).FirstOrDefault(); if (firstCamera != null) { camera.Transform = firstCamera.Camera; } evs.Sort((x, y) => x.Time.CompareTo(y.Time)); foreach (var item in evs) { events.Enqueue(item); } //Add starspheres in the right order var sorted = ((IEnumerable <Tuple <IDrawable, Matrix4, int> >)layers).Reverse().OrderBy(x => x.Item3).ToArray(); Renderer.StarSphereModels = new IDrawable[sorted.Length]; Renderer.StarSphereWorlds = new Matrix4[sorted.Length]; for (int i = 0; i < sorted.Length; i++) { Renderer.StarSphereModels[i] = sorted[i].Item1; Renderer.StarSphereWorlds[i] = sorted[i].Item2; } //Add objects to the renderer World.RegisterAll(); }
public Cutscene(IEnumerable <ThnScript> scripts, FreelancerGame game, GameObject playerShip = null) { this.playerShip = playerShip; this.game = game; camera = new ThnCamera(game.Viewport); Renderer = new SystemRenderer(camera, game.GameData, game.ResourceManager, game); World = new GameWorld(Renderer); //thn = script; var evs = new List <ThnEvent>(); foreach (var thn in scripts) { totalDuration = Math.Max(totalDuration, thn.Duration); foreach (var ev in thn.Events) { ev.TimeOffset = 0; evs.Add(ev); } AddEntities(thn); } evs.Sort((x, y) => x.Time.CompareTo(y.Time)); foreach (var item in evs) { events.Enqueue(item); } //Add starspheres in the right order layers.Sort((x, y) => x.Item3.CompareTo(y.Item3)); Renderer.StarSphereModels = new IDrawable[layers.Count]; Renderer.StarSphereWorlds = new Matrix4[layers.Count]; for (int i = 0; i < layers.Count; i++) { Renderer.StarSphereModels[i] = layers[i].Item1; Renderer.StarSphereWorlds[i] = layers[i].Item2; } //Add objects to the renderer World.RegisterAll(); }
public Cutscene(IEnumerable <ThnScript> scripts, FreelancerGame game) { camera = new ThnCamera(game.Viewport); Renderer = new SystemRenderer(camera, game.GameData, game.ResourceManager); World = new GameWorld(Renderer); //thn = script; var evs = new List <ThnEvent>(); bool hasScene = false; List <Tuple <IDrawable, Matrix4, int> > layers = new List <Tuple <IDrawable, Matrix4, int> >(); foreach (var thn in scripts) { foreach (var ev in thn.Events) { evs.Add(ev); } foreach (var kv in thn.Entities) { if ((kv.Value.ObjectFlags & ThnObjectFlags.Reference) == ThnObjectFlags.Reference) { continue; } var obj = new ThnObject(); obj.Name = kv.Key; obj.Translate = kv.Value.Position ?? Vector3.Zero; obj.Rotate = kv.Value.RotationMatrix ?? Matrix4.Identity; if (kv.Value.Type == EntityTypes.Compound) { //Fetch model IDrawable drawable; switch (kv.Value.MeshCategory.ToLowerInvariant()) { case "solar": drawable = game.GameData.GetSolar(kv.Value.Template); break; case "spaceship": var sh = game.GameData.GetShip(kv.Value.Template); drawable = sh.Drawable; break; case "prop": drawable = game.GameData.GetProp(kv.Value.Template); break; case "room": drawable = game.GameData.GetRoom(kv.Value.Template); break; case "equipment cart": drawable = game.GameData.GetCart(kv.Value.Template); break; case "equipment": var eq = game.GameData.GetEquipment(kv.Value.Template); drawable = eq.GetDrawable(); break; case "asteroid": drawable = game.GameData.GetAsteroid(kv.Value.Template); break; default: throw new NotImplementedException("Mesh Category " + kv.Value.MeshCategory); } if (kv.Value.UserFlag != 0) { //This is a starsphere var transform = (kv.Value.RotationMatrix ?? Matrix4.Identity) * Matrix4.CreateTranslation(kv.Value.Position ?? Vector3.Zero); layers.Add(new Tuple <IDrawable, Matrix4, int>(drawable, transform, kv.Value.SortGroup)); } else { obj.Object = new GameObject(drawable, game.ResourceManager, false); obj.Object.PhysicsComponent = null; //Jitter seems to interfere with directly setting orientation var r = (ModelRenderer)obj.Object.RenderComponent; r.LightGroup = kv.Value.LightGroup; r.LitDynamic = (kv.Value.ObjectFlags & ThnObjectFlags.LitDynamic) == ThnObjectFlags.LitDynamic; r.LitAmbient = (kv.Value.ObjectFlags & ThnObjectFlags.LitAmbient) == ThnObjectFlags.LitAmbient; //HIDDEN just seems to be an editor flag? //r.Hidden = (kv.Value.ObjectFlags & ThnObjectFlags.Hidden) == ThnObjectFlags.Hidden; r.NoFog = kv.Value.NoFog; } } else if (kv.Value.Type == EntityTypes.PSys) { var fx = game.GameData.GetEffect(kv.Value.Template); obj.Object = new GameObject(); obj.Object.RenderComponent = new ParticleEffectRenderer(fx) { Active = false }; } else if (kv.Value.Type == EntityTypes.Scene) { if (hasScene) { //throw new Exception("Thn can only have one scene"); //TODO: This needs to be handled better continue; } var amb = kv.Value.Ambient.Value; if (amb.X == 0 && amb.Y == 0 && amb.Z == 0) { continue; } hasScene = true; Renderer.SystemLighting.Ambient = new Color4(amb.X / 255f, amb.Y / 255f, amb.Z / 255f, 1); } else if (kv.Value.Type == EntityTypes.Light) { var lt = new DynamicLight(); lt.LightGroup = kv.Value.LightGroup; lt.Active = kv.Value.LightProps.On; lt.Light = kv.Value.LightProps.Render; obj.Light = lt; if (kv.Value.RotationMatrix.HasValue) { var m = kv.Value.RotationMatrix.Value; lt.Light.Direction = (new Vector4(lt.Light.Direction.Normalized(), 0) * m).Xyz.Normalized(); } Renderer.SystemLighting.Lights.Add(lt); } else if (kv.Value.Type == EntityTypes.Camera) { obj.Camera = new ThnCameraTransform(); obj.Camera.Position = kv.Value.Position.Value; obj.Camera.Orientation = kv.Value.RotationMatrix ?? Matrix4.Identity; obj.Camera.FovH = kv.Value.FovH ?? obj.Camera.FovH; obj.Camera.AspectRatio = kv.Value.HVAspect ?? obj.Camera.AspectRatio; } else if (kv.Value.Type == EntityTypes.Marker) { obj.Object = new GameObject(); obj.Object.Name = "Marker"; obj.Object.Nickname = ""; } if (obj.Object != null) { Vector3 transform = kv.Value.Position ?? Vector3.Zero; obj.Object.Transform = (kv.Value.RotationMatrix ?? Matrix4.Identity) * Matrix4.CreateTranslation(transform); World.Objects.Add(obj.Object); } obj.Entity = kv.Value; Objects.Add(kv.Key, obj); } } evs.Sort((x, y) => x.Time.CompareTo(y.Time)); foreach (var item in evs) { events.Enqueue(item); } //Add starspheres in the right order layers.Sort((x, y) => x.Item3.CompareTo(y.Item3)); Renderer.StarSphereModels = new IDrawable[layers.Count]; Renderer.StarSphereWorlds = new Matrix4[layers.Count]; for (int i = 0; i < layers.Count; i++) { Renderer.StarSphereModels[i] = layers[i].Item1; Renderer.StarSphereWorlds[i] = layers[i].Item2; } //Add objects to the renderer World.RegisterAll(); }