// Go to World Editor Scene public static void ToWorldEditor(string worldId = "") { GameHandler handler = Systems.handler; // TODO: Limit worldId to the user's username. // Load World to Edit (unless it's already loaded) if (worldId != handler.worldContent.worldId) { // Get World Path & Retrieve World Data if (!handler.worldContent.LoadWorldData(worldId)) { // If this is a personal world, allow it to be created. if (worldId == "__WORLD") { handler.worldContent.data = WorldContent.BuildEmptyWorld(worldId); handler.worldContent.worldId = worldId; } else { #if debug throw new Exception("Unable to load world data."); #endif return; } } } // Prepare Next Scene SceneTransition.nextScene = new WEScene(); }
public static async Task <bool> WorldRequest(string worldId) { // Make sure the world doesn't already exist locally. If it does, there's no need to call the online API. if (WorldContent.WorldExists(worldId)) { Systems.handler.worldContent.LoadWorldData(worldId); return(true); } try { string json = await Systems.httpClient.GetStringAsync(GameValues.CreoAPI + "world/" + worldId); // Load World WorldFormat worldData = JsonConvert.DeserializeObject <WorldFormat>(json); // If the retrieval fails: if (worldData.id != worldId) { UIHandler.AddNotification(UIAlertType.Error, "Invalid World", "Was unable to locate the world ID `" + worldId + "`.", 300); return(false); } worldData.id = worldId; Systems.handler.worldContent.LoadWorldData(worldData); // Save World Systems.handler.worldContent.SaveWorld(); return(true); } catch (Exception ex) { return(false); } }
public void DrawHeadline3D(GraphicsDevice device, WorldState world) { if (Headline == null || Headline.IsDisposed) { return; } var gd = world.Device; var effect = WorldContent.GetBE(gd); effect.TextureEnabled = true; effect.VertexColorEnabled = false; Vector3 scale; Quaternion rotation; Vector3 translation; world.Camera.View.Decompose(out scale, out rotation, out translation); var headpos = Avatar.Skeleton.GetBone("HEAD").AbsolutePosition / 3.0f; var tHead1 = Vector3.Transform(new Vector3(headpos.X, headpos.Z, headpos.Y), Matrix.CreateRotationZ((float)(RadianDirection + Math.PI))); var newWorld = Matrix.CreateScale(Headline.Width / 64f, Headline.Height / -64f, 1) * Matrix.Invert(Matrix.CreateFromQuaternion(rotation)) * Matrix.CreateTranslation(new Vector3(tHead1.X * 3, 1.6f + tHead1.Z * 3, tHead1.Y * 3)) * this.World; effect.DiffuseColor = Color.White.ToVector3(); effect.World = newWorld; effect.Texture = Headline; effect.View = world.Camera.View; effect.Projection = world.Camera.Projection; effect.CurrentTechnique.Passes[0].Apply(); gd.SetVertexBuffer(WorldContent.GetTextureVerts(gd)); gd.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); }
public WorldScene() : base() { // UI State UIHandler.SetUIOptions(false, false); UIHandler.SetMenu(null, false); // Prepare Components this.worldUI = new WorldUI(this); this.playerInput = Systems.localServer.MyPlayer.input; this.campaign = Systems.handler.campaignState; this.atlas = Systems.mapper.atlas[(byte)AtlasGroup.World]; // Prepare Mapper Data this.WorldTerrain = Systems.mapper.WorldTerrain; this.WorldLayers = Systems.mapper.WorldLayers; this.WorldObjects = new Dictionary <byte, string>(); this.WorldCharacters = Systems.mapper.WorldCharacters; this.PrepareWorldObjects(); // Prepare World Content this.worldContent = Systems.handler.worldContent; this.worldData = this.worldContent.data; // Prepare Campaign Details this.campaign.LoadCampaign(Systems.handler.worldContent.worldId, this.worldData.start); // Load World Character this.character = new WorldChar(this); }
public void DrawHeadline3D(GraphicsDevice device, WorldState world) { if (Headline == null || Headline.IsDisposed) { return; } var gd = world.Device; var effect = WorldContent.GetBE(gd); effect.TextureEnabled = true; effect.VertexColorEnabled = false; Vector3 scale; Quaternion rotation; Vector3 translation; world.View.Decompose(out scale, out rotation, out translation); var tHead1 = GetHeadlinePos(); var hScale = GetHeadlineScale(); var newWorld = Matrix.CreateScale(hScale * Headline.Width / 64f, hScale * Headline.Height / -64f, 1) * Matrix.Invert(Matrix.CreateFromQuaternion(rotation)) * Matrix.CreateTranslation(new Vector3(tHead1.X * 3, 1.6f + tHead1.Z * 3, tHead1.Y * 3)) * this.World; effect.DiffuseColor = Color.White.ToVector3(); effect.World = newWorld; effect.Texture = Headline; effect.View = world.View; effect.Projection = world.Projection; effect.CurrentTechnique.Passes[0].Apply(); gd.SetVertexBuffer(WorldContent.GetTextureVerts(gd)); gd.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); }
public WorldUI(WorldScene scene) { this.scene = scene; this.atlas = Systems.mapper.atlas[(byte)AtlasGroup.Tiles]; this.bottomRow = (short)(Systems.screen.viewHeight - (byte)WorldmapEnum.TileHeight); this.worldContent = this.scene.worldContent; this.statusText = new UIStatusText(null, (short)Systems.screen.viewHalfWidth, 5); }
// ---------------------- // // --- Node Detection --- // // ---------------------- // public static bool IsNodeAtLocation(WorldContent worldContent, WorldZoneFormat zone, byte gridX, byte gridY, bool dotsCount = true, bool invisibleDotsCount = true, bool playableOnly = false) { // Check if a node is located here: byte[] wtData = worldContent.GetWorldTileData(zone, (byte)gridX, (byte)gridY); // If a node is not located here, continue. return(NodeData.IsObjectANode(wtData[5], dotsCount, invisibleDotsCount, playableOnly)); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; GameFacade.Linux = (pid == PlatformID.MacOSX || pid == PlatformID.Unix); FSO.Content.Content.Init(GlobalSettings.Default.StartupPath, GraphicsDevice); base.Initialize(); GameFacade.SoundManager = new FSO.Client.Sound.SoundManager(); GameFacade.GameThread = Thread.CurrentThread; SceneMgr = new _3DLayer(); SceneMgr.Initialize(GraphicsDevice); GameFacade.Controller = new GameController(); GameFacade.Screens = uiLayer; GameFacade.Scenes = SceneMgr; GameFacade.GraphicsDevice = GraphicsDevice; GameFacade.GraphicsDeviceManager = Graphics; GameFacade.Cursor = new CursorManager(this.Window); if (!GameFacade.Linux) { GameFacade.Cursor.Init(FSO.Content.Content.Get().GetPath("")); } /** Init any computed values **/ GameFacade.Init(); GameFacade.Strings = new ContentStrings(); GameFacade.Controller.StartLoading(); GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.None }; if (!GameFacade.Linux) { BassNet.Registration("*****@*****.**", "2X3163018312422"); Bass.BASS_Init(-1, 8000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero, System.Guid.Empty); } this.IsMouseVisible = true; this.IsFixedTimeStep = true; WorldContent.Init(this.Services, Content.RootDirectory); base.Screen.Layers.Add(SceneMgr); base.Screen.Layers.Add(uiLayer); GameFacade.LastUpdateState = base.Screen.State; if (!GlobalSettings.Default.Windowed) { Graphics.ToggleFullScreen(); } }
public static void Draw(GraphicsDevice gd, RenderTarget2D targ) { var effect = WorldContent.SSAA; gd.BlendState = BlendState.Opaque; effect.CurrentTechnique = effect.Techniques[0]; effect.Parameters["SSAASize"].SetValue(new Vector2(1f / targ.Width, 1f / targ.Height)); effect.Parameters["tex"].SetValue(targ); effect.CurrentTechnique.Passes[0].Apply(); gd.SetVertexBuffer(WorldContent.GetTextureVerts(gd)); gd.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); }
public void Draw(GraphicsDevice gd, WorldState state) { if (VertBuffer == null) { if (Vertices.Count == 0) { return; } //upload VertBuffer = new VertexBuffer(gd, typeof(VertexPositionColor), Vertices.Count, BufferUsage.None); VertBuffer.SetData(Vertices.ToArray()); IndBuffer = new IndexBuffer(gd, IndexElementSize.ThirtyTwoBits, Indices.Count, BufferUsage.None); IndBuffer.SetData(Indices.ToArray()); PrimCount = Indices.Count / 2; } var effect = WorldContent.GetBE(gd); effect.LightingEnabled = false; effect.Alpha = 1; effect.DiffuseColor = Vector3.One; effect.AmbientLightColor = Vector3.One; effect.VertexColorEnabled = true; effect.TextureEnabled = false; //var view = view;state.Camera.View; var view = state.View; var projection = state.Projection; effect.View = view; effect.Projection = projection;// (state.Camera as WorldCamera3D)?.BaseProjection() ?? state.Camera.Projection; effect.World = Matrix.CreateTranslation(0, (Level - 1) * 2.95f, 0) * Matrix.CreateScale(3f); gd.DepthStencilState = DepthStencilState.Default; gd.RasterizerState = RasterizerState.CullNone; gd.BlendState = BlendState.AlphaBlend; foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); gd.Indices = IndBuffer; gd.SetVertexBuffer(VertBuffer); gd.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, PrimCount); } gd.DepthStencilState = DepthStencilState.Default; }
public TSOGame() : base() { GameFacade.Game = this; Content.RootDirectory = FSOEnvironment.GFXContentDir; WorldContent.Init(this.Services, Content.RootDirectory); Graphics.SynchronizeWithVerticalRetrace = true; Graphics.PreferredBackBufferWidth = GlobalSettings.Default.GraphicsWidth; Graphics.PreferredBackBufferHeight = GlobalSettings.Default.GraphicsHeight; // Graphics.HardwareModeSwitch = false; Graphics.ApplyChanges(); Console.WriteLine(IsActive); //disabled for now. It's a hilarious mess and is causing linux to freak out. //Log.UseSensibleDefaults(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { tso.content.Content.Init(GlobalSettings.Default.StartupPath, GraphicsDevice); // TODO: Add your initialization logic here if (GlobalSettings.Default.Windowed) { Graphics.IsFullScreen = false; } else { Graphics.IsFullScreen = false; } GraphicsDevice.RenderState.CullMode = CullMode.CullClockwiseFace; BassNet.Registration("*****@*****.**", "2X3163018312422"); Bass.BASS_Init(-1, 8000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero, System.Guid.Empty); this.IsMouseVisible = true; this.IsFixedTimeStep = true; Graphics.SynchronizeWithVerticalRetrace = true; //why was this disabled Graphics.PreferredBackBufferWidth = GlobalSettings.Default.GraphicsWidth; Graphics.PreferredBackBufferHeight = GlobalSettings.Default.GraphicsHeight; //800 * 600 is the default resolution. Since all resolutions are powers of 2, just scale using //the width (because the height would end up with the same scalefactor). GlobalSettings.Default.ScaleFactor = GlobalSettings.Default.GraphicsWidth / 800; WorldContent.Init(this.Services, Content.RootDirectory); Graphics.ApplyChanges(); base.Initialize(); base.Screen.Layers.Add(SceneMgr); base.Screen.Layers.Add(uiLayer); GameFacade.LastUpdateState = base.Screen.State; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; GameFacade.Linux = (pid == PlatformID.MacOSX || pid == PlatformID.Unix); FSO.Content.Content.Init(GlobalSettings.Default.StartupPath, GraphicsDevice); base.Initialize(); GameFacade.GameThread = Thread.CurrentThread; SceneMgr = new _3DLayer(); SceneMgr.Initialize(GraphicsDevice); GameFacade.Controller = new GameController(); GameFacade.Screens = uiLayer; GameFacade.Scenes = SceneMgr; GameFacade.GraphicsDevice = GraphicsDevice; GameFacade.GraphicsDeviceManager = Graphics; GameFacade.Cursor = new CursorManager(this.Window); if (!GameFacade.Linux) { GameFacade.Cursor.Init(FSO.Content.Content.Get().GetPath("")); } /** Init any computed values **/ GameFacade.Init(); //init audio now HITVM.Init(); GameFacade.Strings = new ContentStrings(); GameFacade.Controller.StartLoading(); GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.None }; try { var audioTest = new SoundEffect(new byte[2], 44100, AudioChannels.Mono); //initialises XAudio. audioTest.CreateInstance().Play(); } catch (Exception e) { MessageBox.Show("Failed to initialize audio: \r\n\r\n" + e.StackTrace); } this.IsMouseVisible = true; this.IsFixedTimeStep = true; WorldContent.Init(this.Services, Content.RootDirectory); base.Screen.Layers.Add(SceneMgr); base.Screen.Layers.Add(uiLayer); GameFacade.LastUpdateState = base.Screen.State; this.Window.TextInput += GameScreen.TextInput; this.Window.Title = "FreeSO"; if (!GlobalSettings.Default.Windowed) { GameFacade.GraphicsDeviceManager.ToggleFullScreen(); } }
public static (byte objectId, byte gridX, byte gridY) LocateNearestNode(WorldContent worldContent, WorldZoneFormat zone, byte gridX, byte gridY, DirCardinal dir, byte range = 5) { (byte objectId, byte gridX, byte gridY)tuple = (objectId : 0, gridX : 0, gridY : 0); // Vertical UP Node Scan - Scans for any nodes above this location. if (dir == DirCardinal.Up) { byte xRange = 1; // Do a first scan for vertical line: for (int y = gridY - 1; y >= gridY - range; y--) { byte objectId = NodeData.GetNodeAtLocation(worldContent, zone, gridX, (byte)y); if (objectId == 0) { continue; } return(objectId, gridX, (byte)y); } // Do a scan for angled versions: for (int y = gridY - 1; y >= gridY - range; y--) { for (int x = gridX - xRange; x <= gridX + xRange; x++) { // If a node is located, track it, and make sure it's more centered than any other by looping through X values again. byte objectId = NodeData.GetNodeAtLocation(worldContent, zone, (byte)x, (byte)y); if (objectId == 0) { continue; } // Keep the node closest to center: if (tuple.objectId != 0) { int dist1 = Math.Abs(gridX - tuple.gridX); int dist2 = Math.Abs(gridX - x); if (dist1 < dist2) { continue; } } tuple.objectId = objectId; tuple.gridX = (byte)x; tuple.gridY = (byte)y; } xRange++; // If a node is located, end test. if (tuple.objectId > 0) { return(tuple); } } } // Vertical DOWN Node Scan - Scans for any nodes below this location. else if (dir == DirCardinal.Down) { byte xRange = 1; // Do a first scan for vertical line: for (int y = gridY + 1; y <= gridY + range; y++) { byte objectId = NodeData.GetNodeAtLocation(worldContent, zone, gridX, (byte)y); if (objectId == 0) { continue; } return(objectId, gridX, (byte)y); } // Do a scan for angled versions: for (int y = gridY + 1; y <= gridY + range; y++) { for (int x = gridX - xRange; x <= gridX + xRange; x++) { // If a node is located, track it, and make sure it's more centered than any other by looping through X values again. byte objectId = NodeData.GetNodeAtLocation(worldContent, zone, (byte)x, (byte)y); if (objectId == 0) { continue; } // Keep the node closest to center: if (tuple.objectId != 0) { int dist1 = Math.Abs(gridX - tuple.gridX); int dist2 = Math.Abs(gridX - x); if (dist1 < dist2) { continue; } } tuple.objectId = objectId; tuple.gridX = (byte)x; tuple.gridY = (byte)y; } xRange++; // If a node is located, end test. if (tuple.objectId > 0) { return(tuple); } } } // Horizontal LEFT Node Scan - scans for any nodes left of this location. else if (dir == DirCardinal.Left) { byte yRange = 0; // Do a first scan for horizontal line: for (int x = gridX - 1; x >= gridX - range; x--) { byte objectId = NodeData.GetNodeAtLocation(worldContent, zone, (byte)x, gridY); if (objectId == 0) { continue; } return(objectId, (byte)x, gridY); } // Do a scan for angled versions: for (int x = gridX - 1; x >= gridX - range; x--) { for (int y = gridY - yRange; y <= gridY + yRange; y++) { // If a node was located, track it, then make sure it's more centered than any other by looping through Y values again. byte objectId = NodeData.GetNodeAtLocation(worldContent, zone, (byte)x, (byte)y); if (objectId == 0) { continue; } // Keep the node closest to center: if (tuple.objectId != 0) { int dist1 = Math.Abs(gridY - tuple.gridY); int dist2 = Math.Abs(gridY - y); if (dist1 < dist2) { continue; } } tuple.objectId = objectId; tuple.gridX = (byte)x; tuple.gridY = (byte)y; } yRange++; // If a node is located, end test. if (tuple.objectId > 0) { return(tuple); } } } // Horizontal RIGHT Node Scan - scans for any nodes right of this location. else if (dir == DirCardinal.Right) { byte yRange = 0; // Do a first scan for horizontal line: for (int x = gridX + 1; x <= gridX + range; x++) { byte objectId = NodeData.GetNodeAtLocation(worldContent, zone, (byte)x, gridY); if (objectId == 0) { continue; } return(objectId, (byte)x, gridY); } // Do a scan for angled versions: for (int x = gridX + 1; x <= gridX + range; x++) { for (int y = gridY - yRange; y <= gridY + yRange; y++) { // If a node was located, track it, then make sure it's more centered than any other by looping through Y values again. byte objectId = NodeData.GetNodeAtLocation(worldContent, zone, (byte)x, (byte)y); if (objectId == 0) { continue; } // Keep the node closest to center: if (tuple.objectId != 0) { int dist1 = Math.Abs(gridY - tuple.gridY); int dist2 = Math.Abs(gridY - y); if (dist1 < dist2) { continue; } } tuple.objectId = objectId; tuple.gridX = (byte)x; tuple.gridY = (byte)y; } yRange++; // If a node is located, end test. if (tuple.objectId > 0) { return(tuple); } } } // Return No Results return(tuple); }
public static (byte objectId, byte gridX, byte gridY) LocateNodeConnection(WorldContent worldContent, WorldZoneFormat zone, byte gridX, byte gridY, DirCardinal dir) { var matchNode = NodeData.LocateNearestNode(worldContent, zone, gridX, gridY, dir); if (dir == DirCardinal.Up) { // If the matching node cannot connect in this direction, it doesn't. Return early. if (!NodeData.IsDirectionAllowed(matchNode.objectId, DirCardinal.Down)) { return(0, 0, 0); } if (matchNode.objectId > 0) { var revNode = NodeData.LocateNearestNode(worldContent, zone, matchNode.gridX, matchNode.gridY, DirCardinal.Down); // If the discovered node has no alternative to connect to, it matches with this one. if (revNode.objectId == 0) { return(matchNode); } // If the Matching Node's Connection connects back, it matches. if (revNode.gridX == gridX && revNode.gridY == gridY) { return(matchNode); } // If alternative node is on the same X level, it matches this one. if (matchNode.gridX == gridX) { return(matchNode); } // If matching node is NOT on the same X level, but its reverse is, the reverse is chosen. else if (matchNode.gridX == revNode.gridX) { return(0, 0, 0); } // If alternative node is further away than this one, it matches this one. if (revNode.gridY > gridY) { return(matchNode); } } } else if (dir == DirCardinal.Left) { // If the matching node cannot connect in this direction, it doesn't. Return early. if (!NodeData.IsDirectionAllowed(matchNode.objectId, DirCardinal.Right)) { return(0, 0, 0); } if (matchNode.objectId > 0) { var revNode = NodeData.LocateNearestNode(worldContent, zone, matchNode.gridX, matchNode.gridY, DirCardinal.Right); // If the discovered node has no alternative to connect to, it matches with this one. if (revNode.objectId == 0) { return(matchNode); } // If the Matching Node's Connection connects back, it matches. if (revNode.gridX == gridX && revNode.gridY == gridY) { return(matchNode); } // If alternative node is on the same Y level, it matches this one. if (matchNode.gridY == gridY) { return(matchNode); } // If matching node is NOT on the same Y level, but its reverse is, the reverse is chosen. else if (matchNode.gridY == revNode.gridY) { return(0, 0, 0); } // If alternative node is further away than this one, it matches this one. if (revNode.gridX > gridX) { return(matchNode); } } } else if (dir == DirCardinal.Right) { // If the matching node cannot connect in this direction, it doesn't. Return early. if (!NodeData.IsDirectionAllowed(matchNode.objectId, DirCardinal.Left)) { return(0, 0, 0); } if (matchNode.objectId > 0) { var revNode = NodeData.LocateNearestNode(worldContent, zone, matchNode.gridX, matchNode.gridY, DirCardinal.Left); // If the discovered node has no alternative to connect to, it matches with this one. if (revNode.objectId == 0) { return(matchNode); } // If the Matching Node's Connection connects back, it matches. if (revNode.gridX == gridX && revNode.gridY == gridY) { return(matchNode); } // If alternative node is on the same Y level, it matches this one. if (matchNode.gridY == gridY) { return(matchNode); } // If matching node is NOT on the same Y level, but its reverse is, the reverse is chosen. else if (matchNode.gridY == revNode.gridY) { return(0, 0, 0); } // If alternative node is further away than this one, it matches this one. if (revNode.gridX < gridX) { return(matchNode); } } } else if (dir == DirCardinal.Down) { // If the matching node cannot connect in this direction, it doesn't. Return early. if (!NodeData.IsDirectionAllowed(matchNode.objectId, DirCardinal.Up)) { return(0, 0, 0); } if (matchNode.objectId > 0) { var revNode = NodeData.LocateNearestNode(worldContent, zone, matchNode.gridX, matchNode.gridY, DirCardinal.Up); // If the discovered node has no alternative to connect to, it matches with this one. if (revNode.objectId == 0) { return(matchNode); } // If the Matching Node's Connection connects back, it matches. if (revNode.gridX == gridX && revNode.gridY == gridY) { return(matchNode); } // If alternative node is on the same X level, it matches this one. if (matchNode.gridX == gridX) { return(matchNode); } // If matching node is NOT on the same X level, but its reverse is, the reverse is chosen. else if (matchNode.gridX == revNode.gridX) { return(0, 0, 0); } // If alternative node is further away than this one, it matches this one. if (revNode.gridY < gridY) { return(matchNode); } } } return(0, 0, 0); }
public void Draw(GraphicsDevice gd, WorldState state) { var ocolor = state.OutsideColor.ToVector4(); var effect = WorldContent.GetBE(gd); var color = ocolor - new Vector4(0.35f) * 1.5f + new Vector4(0.35f); color.W = 1; FogColor = color * new Color(0x80, 0xC0, 0xFF, 0xFF).ToVector4(); effect.LightingEnabled = false; effect.DiffuseColor = new Vector3(Math.Min(1, color.X), Math.Min(1, color.Y), Math.Min(1, color.Z)); //effect.AmbientLightColor = new Vector3(color.X, color.Y, color.Z); effect.VertexColorEnabled = true; effect.TextureEnabled = false; var view = state.Camera.View; view.M41 = 0; view.M42 = 0; view.M43 = 0; effect.View = view; effect.Projection = (state.Camera as WorldCamera3D)?.BaseProjection() ?? state.Camera.Projection; effect.World = Matrix.CreateScale(5f); gd.DepthStencilState = DepthStencilState.None; gd.RasterizerState = RasterizerState.CullNone; gd.BlendState = BlendState.Opaque; foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); gd.Indices = Indices; gd.SetVertexBuffer(Verts); gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, PrimCount); } gd.BlendState = BlendState.NonPremultiplied; var night = state.Light?.Night ?? false; //draw the sun or moon var pos = state.Light?.SunVector ?? new Vector3(0, 1, 0); var z = -pos.X; pos.X = pos.Z; pos.Z = z; var dist = 0.5f + pos.Y * 2; dist *= dist; dist += 0.5f; if (night) { dist = 35; } var sunMat = Matrix.CreateTranslation(0, 0, dist) * Matrix.CreateBillboard(pos, new Vector3(0, 0.4f, 0), Vector3.Up, null); var geom = WorldContent.GetTextureVerts(gd); effect.World = sunMat; effect.VertexColorEnabled = false; effect.TextureEnabled = true; effect.Texture = (night)? TextureGenerator.GetMoon(gd) : TextureGenerator.GetSun(gd); effect.DiffuseColor = new Vector3(color.X, color.Y, color.Z) * 2f; foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); gd.SetVertexBuffer(geom); gd.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } gd.DepthStencilState = DepthStencilState.Default; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { var settings = GlobalSettings.Default; if (FSOEnvironment.DPIScaleFactor != 1 || FSOEnvironment.SoftwareDepth) { settings.GraphicsWidth = GraphicsDevice.Viewport.Width / FSOEnvironment.DPIScaleFactor; settings.GraphicsHeight = GraphicsDevice.Viewport.Height / FSOEnvironment.DPIScaleFactor; } FSO.LotView.WorldConfig.Current = new FSO.LotView.WorldConfig() { LightingMode = 3, SmoothZoom = settings.SmoothZoom, SurroundingLots = settings.SurroundingLotMode, AA = settings.AntiAlias }; OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; GameFacade.Linux = (pid == PlatformID.MacOSX || pid == PlatformID.Unix); FSO.Content.Content.Target = FSO.Content.FSOEngineMode.TS1; FSO.Content.Content.TS1HybridBasePath = GlobalSettings.Default.TS1HybridPath; if (FSOEnvironment.Enable3D) { FSO.Files.RC.DGRP3DMesh.InitRCWorkers(); } //FSO.Content.Content.Init(GlobalSettings.Default.StartupPath, GraphicsDevice); base.Initialize(); GameFacade.GameThread = Thread.CurrentThread; SceneMgr = new _3DLayer(); SceneMgr.Initialize(GraphicsDevice); GameFacade.Scenes = SceneMgr; GameFacade.GraphicsDevice = GraphicsDevice; GameFacade.GraphicsDeviceManager = Graphics; GameFacade.Cursor = new CursorManager(GraphicsDevice); if (!GameFacade.Linux) { GameFacade.Cursor.Init(GlobalSettings.Default.TS1HybridPath, true); } /** Init any computed values **/ GameFacade.Init(); //init audio now HITVM.Init(); var hit = HITVM.Get(); hit.SetMasterVolume(HITVolumeGroup.FX, GlobalSettings.Default.FXVolume / 10f); hit.SetMasterVolume(HITVolumeGroup.MUSIC, GlobalSettings.Default.MusicVolume / 10f); hit.SetMasterVolume(HITVolumeGroup.VOX, GlobalSettings.Default.VoxVolume / 10f); hit.SetMasterVolume(HITVolumeGroup.AMBIENCE, GlobalSettings.Default.AmbienceVolume / 10f); ContentStrings.TS1 = true; GameFacade.Strings = new ContentStrings(); GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.None }; try { var audioTest = new SoundEffect(new byte[2], 44100, AudioChannels.Mono); //initialises XAudio. audioTest.CreateInstance().Play(); } catch (Exception e) { //MessageBox.Show("Failed to initialize audio: \r\n\r\n" + e.StackTrace); } this.IsFixedTimeStep = true; WorldContent.Init(this.Services, Content.RootDirectory); base.Screen.Layers.Add(SceneMgr); base.Screen.Layers.Add(uiLayer); GameFacade.LastUpdateState = base.Screen.State; if (!GlobalSettings.Default.Windowed && !GameFacade.GraphicsDeviceManager.IsFullScreen) { GameFacade.GraphicsDeviceManager.ToggleFullScreen(); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { var kernel = new StandardKernel( new RegulatorsModule(), new NetworkModule(), new CacheModule() ); FSOFacade.Kernel = kernel; var settings = GlobalSettings.Default; if (FSOEnvironment.SoftwareDepth) { settings.GraphicsWidth = (int)(GraphicsDevice.Viewport.Width / FSOEnvironment.DPIScaleFactor); settings.GraphicsHeight = (int)(GraphicsDevice.Viewport.Height / FSOEnvironment.DPIScaleFactor); } //manage settings if (settings.LightingMode == -1) { if (settings.Lighting) { if (settings.Shadows3D) { settings.LightingMode = 2; } else { settings.LightingMode = 1; } } else { settings.LightingMode = 0; } settings.Save(); } LotView.WorldConfig.Current = new LotView.WorldConfig() { LightingMode = settings.LightingMode, SmoothZoom = settings.SmoothZoom, SurroundingLots = settings.SurroundingLotMode, AA = settings.AntiAlias, }; FeatureLevelTest.UpdateFeatureLevel(GraphicsDevice); if (!FSOEnvironment.TexCompressSupport) { settings.TexCompression = 0; } else if ((settings.TexCompression & 2) == 0) { settings.TexCompression = 1; } FSOEnvironment.TexCompress = (!IffFile.RETAIN_CHUNK_DATA) && (settings.TexCompression & 1) > 0; //end settings management OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; GameFacade.Linux = (pid == PlatformID.MacOSX || pid == PlatformID.Unix); FSO.Content.Content.TS1Hybrid = GlobalSettings.Default.TS1HybridEnable; FSO.Content.Content.TS1HybridBasePath = GlobalSettings.Default.TS1HybridPath; FSO.Content.Content.Init(GlobalSettings.Default.StartupPath, GraphicsDevice); VMContext.InitVMConfig(); base.Initialize(); GameFacade.GameThread = Thread.CurrentThread; SceneMgr = new _3DLayer(); SceneMgr.Initialize(GraphicsDevice); FSOFacade.Controller = kernel.Get <GameController>(); GameFacade.Screens = uiLayer; GameFacade.Scenes = SceneMgr; GameFacade.GraphicsDevice = GraphicsDevice; GameFacade.GraphicsDeviceManager = Graphics; GameFacade.Emojis = new Common.Rendering.Emoji.EmojiProvider(GraphicsDevice); GameFacade.Cursor = new CursorManager(GraphicsDevice); if (!GameFacade.Linux) { GameFacade.Cursor.Init(FSO.Content.Content.Get().GetPath(""), false); } /** Init any computed values **/ GameFacade.Init(); //init audio now HITVM.Init(); var hit = HITVM.Get(); hit.SetMasterVolume(HITVolumeGroup.FX, GlobalSettings.Default.FXVolume / 10f); hit.SetMasterVolume(HITVolumeGroup.MUSIC, GlobalSettings.Default.MusicVolume / 10f); hit.SetMasterVolume(HITVolumeGroup.VOX, GlobalSettings.Default.VoxVolume / 10f); hit.SetMasterVolume(HITVolumeGroup.AMBIENCE, GlobalSettings.Default.AmbienceVolume / 10f); GameFacade.Strings = new ContentStrings(); FSOFacade.Controller.StartLoading(); GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.None }; try { var audioTest = new SoundEffect(new byte[2], 44100, AudioChannels.Mono); //initialises XAudio. audioTest.CreateInstance().Play(); } catch (Exception e) { //MessageBox.Show("Failed to initialize audio: \r\n\r\n" + e.StackTrace); } this.IsMouseVisible = true; this.IsFixedTimeStep = true; WorldContent.Init(this.Services, Content.RootDirectory); DGRP3DMesh.InitRCWorkers(); if (!FSOEnvironment.SoftwareKeyboard) { AddTextInput(); } base.Screen.Layers.Add(SceneMgr); base.Screen.Layers.Add(uiLayer); GameFacade.LastUpdateState = base.Screen.State; //Bind ninject objects kernel.Bind <FSO.Content.Content>().ToConstant(FSO.Content.Content.Get()); kernel.Load(new ClientDomainModule()); //Have to be eager with this, it sets a singleton instance on itself to avoid packets having //to be created using Ninject for performance reasons kernel.Get <cTSOSerializer>(); var ds = kernel.Get <DataService>(); ds.AddProvider(new ClientAvatarProvider()); this.Window.Title = "FreeSO"; DiscordRpcEngine.Init(); if (!GlobalSettings.Default.Windowed && !GameFacade.GraphicsDeviceManager.IsFullScreen) { GameFacade.GraphicsDeviceManager.ToggleFullScreen(); } }
static void Main(string[] args) { FSO.Windows.Program.InitWindows(); TimedReferenceController.SetMode(CacheType.PERMANENT); Console.WriteLine("Loading Config..."); try { var configString = File.ReadAllText("facadeconfig.json"); Config = Newtonsoft.Json.JsonConvert.DeserializeObject <FacadeConfig>(configString); } catch (Exception e) { Console.WriteLine("Could not find configuration file 'facadeconfig.json'. Please ensure it is valid and present in the same folder as this executable."); return; } Console.WriteLine("Locating The Sims Online..."); string baseDir = AppDomain.CurrentDomain.BaseDirectory; Directory.SetCurrentDirectory(baseDir); //Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException); OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; ILocator gameLocator; bool linux = pid == PlatformID.MacOSX || pid == PlatformID.Unix; if (linux && Directory.Exists("/Users")) { gameLocator = new MacOSLocator(); } else if (linux) { gameLocator = new LinuxLocator(); } else { gameLocator = new WindowsLocator(); } bool useDX = true; FSOEnvironment.Enable3D = true; GameThread.NoGame = true; GameThread.UpdateExecuting = true; var path = gameLocator.FindTheSimsOnline(); if (path != null) { FSOEnvironment.ContentDir = "Content/"; FSOEnvironment.GFXContentDir = "Content/" + (useDX ? "DX/" : "OGL/"); FSOEnvironment.Linux = linux; FSOEnvironment.DirectX = useDX; FSOEnvironment.GameThread = Thread.CurrentThread; FSO.HIT.HITVM.Init(); FSO.HIT.HITVM.Get().SetMasterVolume(FSO.HIT.Model.HITVolumeGroup.AMBIENCE, 0); FSO.HIT.HITVM.Get().SetMasterVolume(FSO.HIT.Model.HITVolumeGroup.FX, 0); FSO.HIT.HITVM.Get().SetMasterVolume(FSO.HIT.Model.HITVolumeGroup.MUSIC, 0); FSO.HIT.HITVM.Get().SetMasterVolume(FSO.HIT.Model.HITVolumeGroup.VOX, 0); FSO.Files.Formats.IFF.Chunks.STR.DefaultLangCode = FSO.Files.Formats.IFF.Chunks.STRLangCode.EnglishUS; } Console.WriteLine("Creating Graphics Device..."); var gds = new GraphicsDeviceServiceMock(); var gd = gds.GraphicsDevice; //set up some extra stuff like the content manager var services = new GameServiceContainer(); var content = new ContentManager(services); content.RootDirectory = FSOEnvironment.GFXContentDir; services.AddService <IGraphicsDeviceService>(gds); var vitaboyEffect = content.Load <Effect>("Effects/Vitaboy"); FSO.Vitaboy.Avatar.setVitaboyEffect(vitaboyEffect); WorldConfig.Current = new WorldConfig() { LightingMode = 3, SmoothZoom = true, SurroundingLots = 0 }; DGRP3DMesh.Sync = true; Console.WriteLine("Looks like that worked. Loading FSO Content!"); VMContext.InitVMConfig(false); Content.Init(path, gd); WorldContent.Init(services, content.RootDirectory); VMAmbientSound.ForceDisable = true; Layer = new _3DLayer(); Layer.Initialize(gd); GD = gd; Console.WriteLine("Starting Worker Loop!"); WorkerLoop(); Console.WriteLine("Exiting."); GameThread.Killed = true; GameThread.OnKilled.Set(); gds.Release(); }
public void Draw(GraphicsDevice gd, Color outsideColor, Matrix view, Matrix projection, float time, WeatherController weather, Vector3 sunVector, float scale) { var ocolor = outsideColor.ToVector4(); var effect = WorldContent.GetBE(gd); if (LastSkyPos != time) BuildSkyDome(gd, time); var color = ocolor - new Vector4(0.35f) * 1.5f + new Vector4(0.35f); color.W = 1; var wint = Math.Min(1f, weather.WeatherIntensity); effect.LightingEnabled = false; effect.Texture = GradTex; effect.Alpha = (1 - (float)Math.Sqrt(wint) * 0.75f); effect.DiffuseColor = Vector3.One; effect.AmbientLightColor = Vector3.One; //effect.DiffuseColor = new Vector3(Math.Min(1, color.X), Math.Min(1, color.Y), Math.Min(1, color.Z)); //effect.AmbientLightColor = new Vector3(color.X, color.Y, color.Z); effect.VertexColorEnabled = false; effect.TextureEnabled = true; //var view = view;state.Camera.View; view.M41 = 0; view.M42 = 0; view.M43 = 0; effect.View = view; effect.Projection = projection;// (state.Camera as WorldCamera3D)?.BaseProjection() ?? state.Camera.Projection; effect.World = Matrix.CreateScale(5f * scale); gd.DepthStencilState = DepthStencilState.None; gd.RasterizerState = RasterizerState.CullNone; gd.BlendState = BlendState.AlphaBlend; gd.SamplerStates[0] = SamplerState.LinearWrap; foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); gd.Indices = Indices; gd.SetVertexBuffer(Verts); gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, PrimCount); } gd.BlendState = BlendState.NonPremultiplied; var night = Night(time); //draw the sun or moon var pos = sunVector; var z = -pos.X; pos.X = pos.Z; pos.Z = z; var dist = 0.5f + pos.Y * 2; dist *= dist; dist += 0.5f; if (night) dist = 35; var sunMat = Matrix.CreateTranslation(0, 0, dist) * Matrix.CreateBillboard(pos, new Vector3(0, 0.4f, 0), Vector3.Up, null); var geom = WorldContent.GetTextureVerts(gd); effect.World = sunMat; effect.VertexColorEnabled = false; effect.TextureEnabled = true; effect.Texture = (night) ? TextureGenerator.GetMoon(gd) : TextureGenerator.GetSun(gd); effect.DiffuseColor = new Vector3(color.X, color.Y, color.Z) * ((night) ? 2f : 0.6f); gd.BlendState = (night) ? BlendState.NonPremultiplied : BlendState.Additive; foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); gd.SetVertexBuffer(geom); gd.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } gd.BlendState = BlendState.NonPremultiplied; gd.DepthStencilState = DepthStencilState.Default; effect.Alpha = 1f; }
static void Main(string[] args) { FSO.Windows.Program.InitWindows(); TimedReferenceController.SetMode(CacheType.PERMANENT); Console.WriteLine("Loading Config..."); _config = FacadeConfig.Default; Console.WriteLine("Locating The Sims Online..."); string baseDir = AppDomain.CurrentDomain.BaseDirectory; Directory.SetCurrentDirectory(baseDir); //Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException); var os = Environment.OSVersion; var pid = os.Platform; var linux = pid == PlatformID.MacOSX || pid == PlatformID.Unix; bool useDX = true; FSOEnvironment.Enable3D = false; GameThread.NoGame = true; GameThread.UpdateExecuting = true; var path = Pathfinder.GamePath; if (path != null) { FSOEnvironment.ContentDir = "Content/"; FSOEnvironment.GFXContentDir = "Content/" + (useDX ? "DX/" : "OGL/"); FSOEnvironment.Linux = linux; FSOEnvironment.DirectX = useDX; FSOEnvironment.GameThread = Thread.CurrentThread; FSO.HIT.HITVM.Init(); FSO.HIT.HITVM.Get.SetMasterVolume(FSO.HIT.Model.HITVolumeGroup.AMBIENCE, 0); FSO.HIT.HITVM.Get.SetMasterVolume(FSO.HIT.Model.HITVolumeGroup.FX, 0); FSO.HIT.HITVM.Get.SetMasterVolume(FSO.HIT.Model.HITVolumeGroup.MUSIC, 0); FSO.HIT.HITVM.Get.SetMasterVolume(FSO.HIT.Model.HITVolumeGroup.VOX, 0); FSO.Files.Formats.IFF.Chunks.STR.DefaultLangCode = FSO.Files.Formats.IFF.Chunks.STRLangCode.EnglishUS; } Console.WriteLine("Creating Graphics Device..."); var gds = new GraphicsDeviceServiceMock(); var gd = gds.GraphicsDevice; //set up some extra stuff like the content manager var services = new GameServiceContainer(); var content = new ContentManager(services) { RootDirectory = FSOEnvironment.GFXContentDir }; services.AddService <IGraphicsDeviceService>(gds); var vitaboyEffect = content.Load <Effect>("Effects/Vitaboy"); FSO.Vitaboy.Avatar.setVitaboyEffect(vitaboyEffect); WorldConfig.Current = new WorldConfig() { LightingMode = 3, SmoothZoom = true, SurroundingLots = 0 }; DGRP3DMesh.Sync = true; Console.WriteLine("Looks like that worked. Loading FSO Content!"); // VMContext.InitVMConfig(false); // Content.Init(path, gd); WorldContent.Init(services, content.RootDirectory); // VMAmbientSound.ForceDisable = true; _layer = new _3DLayer(); _layer.Initialize(gd); _gd = gd; Console.WriteLine("Starting Worker Loop!"); WorkerLoop(); Console.WriteLine("Exiting."); GameThread.Killed = true; GameThread.OnKilled.Set(); gds.Release(); }