void Start() { if (Instance != null) { Destroy(this); Debug.LogError("Two Pathfinding managers exist in the scene. Deleting one"); return; } Instance = this; lightingManager = GetComponent <LightingManager>(); probeData = new NativeArray <TilePathfindingData>(lightingManager.totalProbes, Allocator.Persistent); for (int i = 0; i < lightingManager.totalProbes; i++) { probeData[i] = new TilePathfindingData { distance = 99999, closestSeen = 99999, occupied = true }; } directionData = new NativeArray <float2>(lightingManager.totalProbes, Allocator.Persistent); lightingManager.OnLightingProbesMoved += HandleProbesMoved; }
GameWorld(GameSession session) { Session = session; Entities = new List <Entity>(512); EntityQueue = new List <Entity>(64); // Particles Particles = new List <Particle>(8192); // Load lighting Lighting = new LightingManager(session.Game); // Physics Physics = new World(new Vector2(0, 0)) { Tag = this }; // Physical engine debug view DebugView = new DebugView(Physics) { Enabled = true }; DebugView.LoadContent(Game.GraphicsDevice, Game.Content); // Default camera _camera = new Camera(Game); PrepareRenderData((int)Game.Resolution.X, (int)Game.Resolution.Y); Game.OnResolutionChange += PrepareRenderData; }
private void OnDestroy() { LightingPerProbeBuffer.Release(); LightingPerPixelBuffer.Release(); WallBuffer.Release(); Instance = null; }
public WorldManager(LightingManager LightManager = null, RigidBodyManager myManager = null) { myRigidBodyManager = myManager; myLightManager = LightManager; myCurrentResourceManager = new ResourceManager(); myArchetypeSystem = new ArchetypeManager(); myWorldManager = this; }
private void OnEnable() { manager = target as LightingManager; if (manager == null) { return; } selectedGroup = manager.activeGroup; }
public void Awake() { if (Instance != null) { Destroy(gameObject); Debug.LogError($"Two instances of {this} found. This is supposed to be a singleton"); return; } Instance = this; }
public VulkanInitializer(String WindowName, RendererWindow WindowHandle, GraphicsSettings mySettings, IPreferredGraphicsDeviceFilter myGraphicsDeviceFilter = null, IPreferredComputeDeviceFilter myComputeDeviceFilter = null) { var Window = new VulkanInstance(WindowName, WindowHandle.WindowHandle); var Surface = new SurfaceKHR(Window); var myDeviceList = new VulkanSupportedDevices(Window, Surface, myGraphicsDeviceFilter, myComputeDeviceFilter); var SelectedPhysicalGraphicsDevice = myDeviceList.GetBestGraphicsDevice(); var SelectedLogicalGraphicsDevice = new VulkanLogicalDevice(SelectedPhysicalGraphicsDevice); DescriptorSetPoolManager myDescriptorPoolGraphicsManager; DescriptorSetPoolManager myDescriptorPoolComputeManager; Renderer.Vulkan.Queue myGraphicsQueue = null; Renderer.Vulkan.Queue myComputeQueue = null; var SelectedPhysicalComputeDevice = myDeviceList.GetNextComputeDevice(); VulkanLogicalDevice SelectedLogicalComputeDevice; if (myDeviceList.Count == 1) { //Compute and Renderer will share a device. SelectedLogicalComputeDevice = new VulkanLogicalDevice(SelectedPhysicalGraphicsDevice); myDescriptorPoolGraphicsManager = new DescriptorSetPoolManager(SelectedLogicalGraphicsDevice); myDescriptorPoolComputeManager = myDescriptorPoolGraphicsManager; myGraphicsQueue = SelectedLogicalGraphicsDevice.QueueManager.GetQueue(QueueFlags.Graphics); myComputeQueue = SelectedLogicalGraphicsDevice.QueueManager.GetQueue(QueueFlags.Compute); } else { //TODO: iterate through queue to find next best device for compute SelectedLogicalComputeDevice = new VulkanLogicalDevice(SelectedPhysicalComputeDevice); myDescriptorPoolGraphicsManager = new DescriptorSetPoolManager(SelectedLogicalGraphicsDevice); myDescriptorPoolComputeManager = new DescriptorSetPoolManager(SelectedLogicalComputeDevice); myGraphicsQueue = SelectedLogicalGraphicsDevice.QueueManager.GetQueue(QueueFlags.Graphics); myComputeQueue = SelectedLogicalComputeDevice.QueueManager.GetQueue(QueueFlags.Compute); } myLightingManager = new LightingManager(); var Renderer = new VulkanRenderer(myLightingManager, Surface, Window, SelectedLogicalGraphicsDevice, myDescriptorPoolGraphicsManager, SelectedPhysicalGraphicsDevice, myGraphicsQueue, mySettings); var Compute = new VulkanCompute(SelectedLogicalComputeDevice, myDescriptorPoolComputeManager, SelectedPhysicalComputeDevice, myComputeQueue); RenderingManager = Renderer; //Make sure they know about eachother's fences so they don't draw or do compute shaders at the same time! Renderer.SetComputeFence(Compute.GetFinishedFence());//Semaphore or fence? Compute.SetRendererFence(Renderer.GetFinshedFence()); ComputeManager = Compute; }
protected override void Initialize() { LoadContent(); DoorBombed.ResetBombedDoors(); DoorClosed.ResetClosedDoors(); DoorLocked.ResetLockedfDoors(); LootManagement.ResetLoot(); player = new Link(this); player.Position = new Vector2(0, 160); LinkSpriteFactory.Instance.player = player; if (playerDebug) { player.Health = 1000; player.TotalHealth = 1000; player.ItemCounts[ItemType.Map]++; player.ItemCounts[ItemType.Compass]++; player.ItemCounts[ItemType.Rupee] = 89; } player.ItemCounts[ItemType.Rupee] += 10; hud = new HeadsUpDisplay(this, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); screen = new NormalScreen(this, GraphicsDevice, graphics); gameState = new NormalGameState(this); this.IsMouseVisible = true; base.Initialize(); currentRoom = new Room1(this, new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2 + 84), floortilebase); currentRoom.LoadRoom("RoomC6"); if (playerDebug) { currentRoom.LoadRoom("RoomDEBUG"); } roomIndex = Array.FindIndex(rooms, x => x == "RoomC6"); lightingManager = new LightingManager(this); savedPlayer = new Link(this); savedRoom = new Room1(this, new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2 + 84), floortilebase); savedScreen = new NormalScreen(this, GraphicsDevice, graphics); notificationsQueue = new Queue <INotification>(); SoundFactory.Instance.musicDungeonLoop.Play(); }
public override void OnInspectorGUI() { DrawDefaultInspector(); LightingManager myScript = (LightingManager)target; GUILayout.Space(20); if (GUILayout.Button("Calm Lighting")) { myScript.SetCalm(); } if (GUILayout.Button("Combat Lighting")) { myScript.SetCombat(); } }
public MapRenderer(Map map, LightingManager lightingManager, Camera camera) : base(camera) { _map = map; _lightingManager = lightingManager; // Find any tiles with animations. for (int x = 0; x < _map.Width; x++) { for (int y = 0; y < _map.Height; y++) { Tile tile = _map.GetTile(x, y); if (!string.IsNullOrWhiteSpace(tile.Animation)) { if (!_tileAnimations.ContainsKey(tile.Animation)) { AnimatedSprite animation = Engine.Assets.GetAsset <Animation>(tile.Animation).NewAnimatedSprite(); _tileAnimations.Add(tile.Animation, animation); } } } } }
public bool Initialize() { var gameFiles = ResolveOrCreate <IGameFiles>(); if (!gameFiles.Initialize()) { return(false); } coroutineManager = new(); dbcManager = ResolveOrCreate <DbcManager>(); SetMap(1); foreach (var store in dbcManager.Stores()) { registry.RegisterInstance(store.Item1, store.Item2); } notificationsCenter = ResolveOrCreate <NotificationsCenter>(); timeManager = ResolveOrCreate <TimeManager>(); screenSpaceSelector = ResolveOrCreate <ScreenSpaceSelector>(); loadingManager = ResolveOrCreate <LoadingManager>(); textureManager = ResolveOrCreate <WoWTextureManager>(); meshManager = ResolveOrCreate <WoWMeshManager>(); mdxManager = ResolveOrCreate <MdxManager>(); wmoManager = ResolveOrCreate <WmoManager>(); worldManager = ResolveOrCreate <WorldManager>(); chunkManager = ResolveOrCreate <ChunkManager>(); cameraManager = ResolveOrCreate <CameraManager>(); lightingManager = ResolveOrCreate <LightingManager>(); areaTriggerManager = ResolveOrCreate <AreaTriggerManager>(); raycastSystem = ResolveOrCreate <RaycastSystem>(); moduleManager = ResolveOrCreate <ModuleManager>(); IsInitialized = true; return(true); }
protected override void LoadContent() { this.MapContent = new ContentManager(this.Services); this.MapContent.RootDirectory = this.Content.RootDirectory; GeeUIMain.Font = this.Content.Load<SpriteFont>(this.Font); if (this.firstLoadContentCall) { this.firstLoadContentCall = false; if (!Directory.Exists(this.MapDirectory)) Directory.CreateDirectory(this.MapDirectory); string challengeDirectory = Path.Combine(this.MapDirectory, "Challenge"); if (!Directory.Exists(challengeDirectory)) Directory.CreateDirectory(challengeDirectory); #if VR if (this.VR) { this.vrLeftMesh.Load(this, Ovr.Eye.Left, this.vrLeftFov); this.vrRightMesh.Load(this, Ovr.Eye.Right, this.vrRightFov); new CommandBinding(this.ReloadedContent, (Action)this.vrLeftMesh.Reload); new CommandBinding(this.ReloadedContent, (Action)this.vrRightMesh.Reload); this.reallocateVrTargets(); this.vrCamera = new Camera(); this.AddComponent(this.vrCamera); } #endif this.GraphicsDevice.PresentationParameters.PresentationInterval = PresentInterval.Immediate; this.GeeUI = new GeeUIMain(); this.AddComponent(GeeUI); this.ConsoleUI = new ConsoleUI(); this.AddComponent(ConsoleUI); this.Console = new Console.Console(); this.AddComponent(Console); Lemma.Console.Console.BindType(null, this); Lemma.Console.Console.BindType(null, Console); // Initialize Wwise AkGlobalSoundEngineInitializer initializer = new AkGlobalSoundEngineInitializer(Path.Combine(this.Content.RootDirectory, "Wwise")); this.AddComponent(initializer); this.Listener = new AkListener(); this.Listener.Add(new Binding<Vector3>(this.Listener.Position, this.Camera.Position)); this.Listener.Add(new Binding<Vector3>(this.Listener.Forward, this.Camera.Forward)); this.Listener.Add(new Binding<Vector3>(this.Listener.Up, this.Camera.Up)); this.AddComponent(this.Listener); // Create the renderer. this.LightingManager = new LightingManager(); this.AddComponent(this.LightingManager); this.Renderer = new Renderer(this, true, true, true, true, true); this.AddComponent(this.Renderer); this.Renderer.ReallocateBuffers(this.ScreenSize); this.renderParameters = new RenderParameters { Camera = this.Camera, IsMainRender = true }; // Load strings this.Strings.Load(Path.Combine(this.Content.RootDirectory, "Strings.xlsx")); this.UI = new UIRenderer(); this.UI.GeeUI = this.GeeUI; this.AddComponent(this.UI); PCInput input = new PCInput(); this.AddComponent(input); Lemma.Console.Console.BindType(null, input); Lemma.Console.Console.BindType(null, UI); Lemma.Console.Console.BindType(null, Renderer); Lemma.Console.Console.BindType(null, LightingManager); input.Add(new CommandBinding(input.GetChord(new PCInput.Chord { Modifier = Keys.LeftAlt, Key = Keys.S }), delegate() { // High-resolution screenshot bool originalModelsVisible = Editor.EditorModelsVisible; Editor.EditorModelsVisible.Value = false; Screenshot s = new Screenshot(); this.AddComponent(s); s.Take(new Point(4096, 2304), delegate() { string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string path; int i = 0; do { path = Path.Combine(desktop, string.Format("lemma-screen{0}.png", i)); i++; } while (File.Exists(path)); Screenshot.SavePng(s.Buffer, path); Editor.EditorModelsVisible.Value = originalModelsVisible; s.Delete.Execute(); }); })); this.performanceMonitor = new ListContainer(); this.performanceMonitor.Add(new Binding<Vector2, Point>(performanceMonitor.Position, x => new Vector2(x.X, 0), this.ScreenSize)); this.performanceMonitor.AnchorPoint.Value = new Vector2(1, 0); this.performanceMonitor.Visible.Value = false; this.performanceMonitor.Name.Value = "PerformanceMonitor"; this.UI.Root.Children.Add(this.performanceMonitor); Action<string, Property<double>> addTimer = delegate(string label, Property<double> property) { TextElement text = new TextElement(); text.FontFile.Value = this.Font; text.Add(new Binding<string, double>(text.Text, x => label + ": " + (x * 1000.0).ToString("F") + "ms", property)); this.performanceMonitor.Children.Add(text); }; Action<string, Property<int>> addCounter = delegate(string label, Property<int> property) { TextElement text = new TextElement(); text.FontFile.Value = this.Font; text.Add(new Binding<string, int>(text.Text, x => label + ": " + x.ToString(), property)); this.performanceMonitor.Children.Add(text); }; TextElement frameRateText = new TextElement(); frameRateText.FontFile.Value = this.Font; frameRateText.Add(new Binding<string, float>(frameRateText.Text, x => "FPS: " + x.ToString("0"), this.frameRate)); this.performanceMonitor.Children.Add(frameRateText); addTimer("Physics", this.physicsTime); addTimer("Update", this.updateTime); addTimer("Render", this.renderTime); addCounter("Draw calls", this.drawCalls); addCounter("Triangles", this.triangles); addCounter("Working set", this.workingSet); Lemma.Console.Console.AddConCommand(new ConCommand("perf", "Toggle the performance monitor", delegate(ConCommand.ArgCollection args) { this.performanceMonitor.Visible.Value = !this.performanceMonitor.Visible; })); try { IEnumerable<string> globalStaticScripts = Directory.GetFiles(Path.Combine(this.Content.RootDirectory, "GlobalStaticScripts"), "*", SearchOption.AllDirectories).Select(x => Path.Combine("..\\GlobalStaticScripts", Path.GetFileNameWithoutExtension(x))); foreach (string scriptName in globalStaticScripts) this.executeStaticScript(scriptName); } catch (IOException) { } this.UIFactory = new UIFactory(); this.AddComponent(this.UIFactory); this.AddComponent(this.Menu); // Have to do this here so the menu's Awake can use all our loaded stuff this.Spawner = new Spawner(); this.AddComponent(this.Spawner); this.UI.IsMouseVisible.Value = true; AKRESULT akresult = AkBankLoader.LoadBank("SFX_Bank_01.bnk"); if (akresult != AKRESULT.AK_Success) Log.d(string.Format("Failed to load main sound bank: {0}", akresult)); #if ANALYTICS this.SessionRecorder = new Session.Recorder(this); this.SessionRecorder.Add("Position", delegate() { Entity p = PlayerFactory.Instance; if (p != null && p.Active) return p.Get<Transform>().Position; else return Vector3.Zero; }); this.SessionRecorder.Add("Health", delegate() { Entity p = PlayerFactory.Instance; if (p != null && p.Active) return p.Get<Player>().Health; else return 0.0f; }); this.SessionRecorder.Add("Framerate", delegate() { return this.frameRate; }); this.SessionRecorder.Add("WorkingSet", delegate() { return this.workingSet; }); this.AddComponent(this.SessionRecorder); this.SessionRecorder.Add(new Binding<bool, Config.RecordAnalytics>(this.SessionRecorder.EnableUpload, x => x == Config.RecordAnalytics.On, this.Settings.Analytics)); #endif this.DefaultLighting(); new SetBinding<float>(this.Settings.SoundEffectVolume, delegate(float value) { AkSoundEngine.SetRTPCValue(AK.GAME_PARAMETERS.VOLUME_SFX, MathHelper.Clamp(value, 0.0f, 1.0f)); }); new SetBinding<float>(this.Settings.MusicVolume, delegate(float value) { AkSoundEngine.SetRTPCValue(AK.GAME_PARAMETERS.VOLUME_MUSIC, MathHelper.Clamp(value, 0.0f, 1.0f)); }); new TwoWayBinding<LightingManager.DynamicShadowSetting>(this.Settings.DynamicShadows, this.LightingManager.DynamicShadows); new TwoWayBinding<float>(this.Settings.MotionBlurAmount, this.Renderer.MotionBlurAmount); new TwoWayBinding<float>(this.Settings.Gamma, this.Renderer.Gamma); new TwoWayBinding<bool>(this.Settings.Bloom, this.Renderer.EnableBloom); new TwoWayBinding<bool>(this.Settings.SSAO, this.Renderer.EnableSSAO); new Binding<float>(this.Camera.FieldOfView, this.Settings.FieldOfView); foreach (string file in Directory.GetFiles(this.MapDirectory, "*.xlsx", SearchOption.TopDirectoryOnly)) this.Strings.Load(file); new Binding<string, Config.Lang>(this.Strings.Language, x => x.ToString(), this.Settings.Language); new NotifyBinding(this.SaveSettings, this.Settings.Language); new CommandBinding(this.MapLoaded, delegate() { this.Renderer.BlurAmount.Value = 0.0f; this.Renderer.Tint.Value = new Vector3(1.0f); }); #if VR if (this.VR) { Action loadVrEffect = delegate() { this.vrEffect = this.Content.Load<Effect>("Effects\\Oculus"); }; loadVrEffect(); new CommandBinding(this.ReloadedContent, loadVrEffect); this.UI.Add(new Binding<Point>(this.UI.RenderTargetSize, this.ScreenSize)); this.VRUI = new Lemma.Components.ModelNonPostProcessed(); this.VRUI.MapContent = false; this.VRUI.DrawOrder.Value = 100000; // On top of everything this.VRUI.Filename.Value = "Models\\plane"; this.VRUI.EffectFile.Value = "Effects\\VirtualUI"; this.VRUI.Add(new Binding<Microsoft.Xna.Framework.Graphics.RenderTarget2D>(this.VRUI.GetRenderTarget2DParameter("Diffuse" + Lemma.Components.Model.SamplerPostfix), this.UI.RenderTarget)); this.VRUI.Add(new Binding<Matrix>(this.VRUI.Transform, delegate() { Matrix rot = this.Camera.RotationMatrix; Matrix mat = Matrix.Identity; mat.Forward = rot.Right; mat.Right = rot.Forward; mat.Up = rot.Up; mat *= Matrix.CreateScale(7); mat.Translation = this.Camera.Position + rot.Forward * 4.0f; return mat; }, this.Camera.Position, this.Camera.RotationMatrix)); this.AddComponent(this.VRUI); this.UI.Setup3D(this.VRUI.Transform); } #endif #if ANALYTICS bool editorLastEnabled = this.EditorEnabled; new CommandBinding<string>(this.LoadingMap, delegate(string newMap) { if (this.MapFile.Value != null && !editorLastEnabled) { this.SessionRecorder.RecordEvent("ChangedMap", newMap); if (!this.IsChallengeMap(this.MapFile) && this.MapFile.Value != Main.MenuMap) this.SaveAnalytics(); } this.SessionRecorder.Reset(); editorLastEnabled = this.EditorEnabled; }); #endif new CommandBinding<string>(this.LoadingMap, delegate(string newMap) { this.CancelScheduledSave(); }); #if !DEVELOPMENT IO.MapLoader.Load(this, MenuMap); this.Menu.Show(initial: true); #endif #if ANALYTICS if (this.Settings.Analytics.Value == Config.RecordAnalytics.Ask) { this.Menu.ShowDialog("\\analytics prompt", "\\enable analytics", delegate() { this.Settings.Analytics.Value = Config.RecordAnalytics.On; }, "\\disable analytics", delegate() { this.Settings.Analytics.Value = Config.RecordAnalytics.Off; }); } #endif #if VR if (this.oculusNotFound) this.Menu.HideMessage(null, this.Menu.ShowMessage(null, "Error: no Oculus found."), 6.0f); if (this.VR) { this.Menu.EnableInput(false); Container vrMsg = this.Menu.BuildMessage("\\vr message", 300.0f); vrMsg.AnchorPoint.Value = new Vector2(0.5f, 0.5f); vrMsg.Add(new Binding<Vector2, Point>(vrMsg.Position, x => new Vector2(x.X * 0.5f, x.Y * 0.5f), this.ScreenSize)); this.UI.Root.Children.Add(vrMsg); input.Bind(this.Settings.RecenterVRPose, PCInput.InputState.Down, this.VRHmd.RecenterPose); input.Bind(this.Settings.RecenterVRPose, PCInput.InputState.Down, delegate() { if (vrMsg != null) { vrMsg.Delete.Execute(); vrMsg = null; } this.Menu.EnableInput(true); }); } else #endif { input.Bind(this.Settings.ToggleFullscreen, PCInput.InputState.Down, delegate() { if (this.Settings.Fullscreen) // Already fullscreen. Go to windowed mode. this.ExitFullscreen(); else // In windowed mode. Go to fullscreen. this.EnterFullscreen(); }); } input.Bind(this.Settings.QuickSave, PCInput.InputState.Down, delegate() { this.SaveWithNotification(true); }); } else { this.ReloadingContent.Execute(); foreach (IGraphicsComponent c in this.graphicsComponents) c.LoadContent(true); this.ReloadedContent.Execute(); } this.GraphicsDevice.RasterizerState = new RasterizerState { MultiSampleAntiAlias = false }; if (this.spriteBatch != null) this.spriteBatch.Dispose(); this.spriteBatch = new SpriteBatch(this.GraphicsDevice); }
/// <summary> /// The class constructor /// </summary> /// <param name="graphicsDevice">The GraphicsDevice to use for rendering</param> /// <param name="contentManager">The ContentManager from which to load Effects</param> public Renderer(Main main, Point size, bool allowMotionBlur, bool allowBloom, bool allowSSAO) { this.allowMotionBlur = allowMotionBlur; this.allowBloom = allowBloom; this.allowSSAO = allowSSAO; this.lightingManager = main.LightingManager; this.screenSize = size; }
protected override void LoadContent() { if (this.firstLoadContentCall) { // First time loading content. Create the renderer. this.LightingManager = new LightingManager(); this.AddComponent(this.LightingManager); this.Renderer = new Renderer(this, this.ScreenSize, true, true, false); this.AddComponent(this.Renderer); this.renderParameters = new RenderParameters { Camera = this.Camera, IsMainRender = true }; this.firstLoadContentCall = false; this.UI = new UIRenderer(); this.AddComponent(this.UI); #if PERFORMANCE_MONITOR ListContainer performanceMonitor = new ListContainer(); performanceMonitor.Add(new Binding<Vector2, Point>(performanceMonitor.Position, x => new Vector2(0, x.Y), this.ScreenSize)); performanceMonitor.AnchorPoint.Value = new Vector2(0, 1); performanceMonitor.Visible.Value = false; performanceMonitor.Name.Value = "PerformanceMonitor"; this.UI.Root.Children.Add(performanceMonitor); Action<string, Property<double>> addLabel = delegate(string label, Property<double> property) { TextElement text = new TextElement(); text.FontFile.Value = "Font"; text.Add(new Binding<string, double>(text.Text, x => label + ": " + (x * 1000.0).ToString("F") + "ms", property)); performanceMonitor.Children.Add(text); }; TextElement frameRateText = new TextElement(); frameRateText.FontFile.Value = "Font"; frameRateText.Add(new Binding<string, float>(frameRateText.Text, x => "FPS: " + x.ToString("0"), this.frameRate)); performanceMonitor.Children.Add(frameRateText); addLabel("Physics", this.physicsTime); addLabel("Update", this.updateTime); addLabel("Pre-frame", this.preframeTime); addLabel("Raw render", this.rawRenderTime); addLabel("Shadow render", this.shadowRenderTime); addLabel("Post-process", this.postProcessTime); PCInput input = new PCInput(); input.Add(new CommandBinding(input.GetChord(new PCInput.Chord { Modifier = Keys.LeftAlt, Key = Keys.P }), delegate() { performanceMonitor.Visible.Value = !performanceMonitor.Visible; })); this.AddComponent(input); #endif IEnumerable<string> globalStaticScripts = Directory.GetFiles(Path.Combine(this.Content.RootDirectory, "Maps", "GlobalStaticScripts"), "*", SearchOption.AllDirectories).Select(x => Path.Combine("Maps", "GlobalStaticScripts", Path.GetFileNameWithoutExtension(x))); foreach (string scriptName in globalStaticScripts) this.executeStaticScript(scriptName); } else { foreach (IComponent c in this.components) c.LoadContent(true); this.ReloadedContent.Execute(); } }
protected override void LoadContent() { if (this.firstLoadContentCall) { // Initialize Wwise AkGlobalSoundEngineInitializer initializer = new AkGlobalSoundEngineInitializer(Path.Combine(this.Content.RootDirectory, "Wwise")); this.AddComponent(initializer); this.Listener = new AkListener(); this.Listener.Add(new Binding<Vector3>(this.Listener.Position, this.Camera.Position)); this.Listener.Add(new Binding<Vector3>(this.Listener.Forward, this.Camera.Forward)); this.Listener.Add(new Binding<Vector3>(this.Listener.Up, this.Camera.Up)); this.AddComponent(this.Listener); // Create the renderer. this.LightingManager = new LightingManager(); this.AddComponent(this.LightingManager); this.Renderer = new Renderer(this, this.ScreenSize, true, true, true, true); this.AddComponent(this.Renderer); this.renderParameters = new RenderParameters { Camera = this.Camera, IsMainRender = true }; this.firstLoadContentCall = false; this.UI = new UIRenderer(); this.AddComponent(this.UI); GeeUI.GeeUI.Initialize(this); this.ConsoleUI = new ConsoleUI(); this.AddComponent(ConsoleUI); this.Console = new Console.Console(); this.AddComponent(Console); PCInput input = new PCInput(); this.AddComponent(input); #if DEVELOPMENT input.Add(new CommandBinding(input.GetChord(new PCInput.Chord { Modifier = Keys.LeftAlt, Key = Keys.S }), delegate() { // High-resolution screenshot Screenshot s = new Screenshot(); this.AddComponent(s); s.Take(new Point(4096, 2304), delegate() { string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string path; int i = 0; do { path = Path.Combine(desktop, "lemma-screen" + i.ToString() + ".png"); i++; } while (File.Exists(path)); using (Stream stream = File.OpenWrite(path)) s.Buffer.SaveAsPng(stream, s.Size.X, s.Size.Y); s.Delete.Execute(); }); })); #endif #if PERFORMANCE_MONITOR this.performanceMonitor = new ListContainer(); this.performanceMonitor.Add(new Binding<Vector2, Point>(performanceMonitor.Position, x => new Vector2(0, x.Y), this.ScreenSize)); this.performanceMonitor.AnchorPoint.Value = new Vector2(0, 1); this.performanceMonitor.Visible.Value = false; this.performanceMonitor.Name.Value = "PerformanceMonitor"; this.UI.Root.Children.Add(this.performanceMonitor); Action<string, Property<double>> addTimer = delegate(string label, Property<double> property) { TextElement text = new TextElement(); text.FontFile.Value = "Font"; text.Add(new Binding<string, double>(text.Text, x => label + ": " + (x * 1000.0).ToString("F") + "ms", property)); this.performanceMonitor.Children.Add(text); }; Action<string, Property<int>> addCounter = delegate(string label, Property<int> property) { TextElement text = new TextElement(); text.FontFile.Value = "Font"; text.Add(new Binding<string, int>(text.Text, x => label + ": " + x.ToString(), property)); this.performanceMonitor.Children.Add(text); }; TextElement frameRateText = new TextElement(); frameRateText.FontFile.Value = "Font"; frameRateText.Add(new Binding<string, float>(frameRateText.Text, x => "FPS: " + x.ToString("0"), this.frameRate)); this.performanceMonitor.Children.Add(frameRateText); addTimer("Physics", this.physicsTime); addTimer("Update", this.updateTime); addTimer("Pre-frame", this.preframeTime); addTimer("Raw render", this.rawRenderTime); addTimer("Shadow render", this.shadowRenderTime); addTimer("Post-process", this.postProcessTime); addTimer("Non-post-processed", this.unPostProcessedTime); addCounter("Draw calls", this.drawCalls); addCounter("Triangles", this.triangles); input.Add(new CommandBinding(input.GetChord(new PCInput.Chord { Modifier = Keys.LeftAlt, Key = Keys.P }), delegate() { this.performanceMonitor.Visible.Value = !this.performanceMonitor.Visible; })); #endif try { IEnumerable<string> globalStaticScripts = Directory.GetFiles(Path.Combine(this.Content.RootDirectory, "GlobalStaticScripts"), "*", SearchOption.AllDirectories).Select(x => Path.Combine("..\\GlobalStaticScripts", Path.GetFileNameWithoutExtension(x))); foreach (string scriptName in globalStaticScripts) this.executeStaticScript(scriptName); } catch (IOException) { } } else { foreach (IDrawableComponent c in this.drawables) c.LoadContent(true); foreach (IDrawableAlphaComponent c in this.alphaDrawables) c.LoadContent(true); foreach (IDrawablePostAlphaComponent c in this.postAlphaDrawables) c.LoadContent(true); foreach (IDrawablePreFrameComponent c in this.preframeDrawables) c.LoadContent(true); foreach (INonPostProcessedDrawableComponent c in this.nonPostProcessedDrawables) c.LoadContent(true); this.ReloadedContent.Execute(); } this.GraphicsDevice.RasterizerState = new RasterizerState { MultiSampleAntiAlias = false }; }
public CreatureRenderer(IReadOnlyList <Creature> creatures, Map map, LightingManager lightingManager, Camera camera) : base(camera) { _creatures = creatures; _map = map; _lightingManager = lightingManager; }