/// <summary> /// Creates and returns a file stream with constants such as baked array lengths /// </summary> /// <returns>Stream with HLSL code</returns> private Stream GetShaderConstantsStream() { string hlslString = $"static const int sphereCount = {RaymarchRenderer.PrimitiveCount<Sphere>()};" + $"static const int boxCount = {RaymarchRenderer.PrimitiveCount<Box>()};" + $"static const int planeCount = {RaymarchRenderer.PrimitiveCount<Plane>()};"; Debug.WriteLine(hlslString); byte[] byteArray = Encoding.ASCII.GetBytes(hlslString); return(new MemoryStream(byteArray)); }
/// <summary> /// /// </summary> public Engine(AutoUpdateable gameLogic) { { // Init window renderForm = new RenderForm("RaymarchEngine"); renderForm.AutoSize = false; renderForm.ClientSize = new Size( Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height ); renderForm.AllowUserResizing = false; renderForm.IsFullscreen = isFullscreen; renderForm.StartPosition = FormStartPosition.Manual; renderForm.Location = new Point(0, 0); renderForm.WindowState = FormWindowState.Maximized; renderForm.MinimizeBox = false; renderForm.Show(); } this.gameLogic = gameLogic; RaymarchRenderer.Init(); // Create main scene Scene.CurrentScene = new Scene(); // Start physics library physics = new PhysicsHandler(PhysicsReady); // Init input device InputDevice.Init(renderForm); int unixTime = Util.ConvertToUnixTimestamp(DateTime.Now); // Execute all start methods StaticUpdater.ExecuteStartActions(unixTime); // Execute each scene object's components' Start method foreach (GameObject gameObject in Scene.CurrentScene.GameObjects) { foreach (IComponent component in gameObject.Components) { component.Start(unixTime); } } // It's important that render device is created after scene and game logic start renderDevice = new RenderDevice(renderForm, new Resolution(2560, 1440)); // Start stopwatch for deltaTime stopwatch = new Stopwatch(); stopwatch.Start(); }