/// <summary> /// Render splash screen /// </summary> public bool Render() { BaseGame.UI.UpdateCarInMenu(); ShadowMapShader.PrepareGameShadows(); // Render background and black bar BaseGame.UI.RenderGameBackground(); BaseGame.UI.RenderMenuTrackBackground(); BaseGame.UI.RenderBlackBar(518, 61); // Show shadows we calculated above if (BaseGame.AllowShadowMapping) { ShaderEffect.shadowMapping.ShowShadows(); } // Show Press Start to continue. if ((int)(BaseGame.TotalTime / 0.375f) % 3 != 0) { BaseGame.UI.Headers.RenderOnScreen( BaseGame.CalcRectangleCenteredWithGivenHeight( 512, 518 + 61 / 2, 26, UIRenderer.PressStartGfxRect), UIRenderer.PressStartGfxRect); } // Clicking or pressing start will go to the menu return(Input.MouseLeftButtonJustPressed || Input.KeyboardSpaceJustPressed || Input.KeyboardEscapeJustPressed || Input.GamePadStartPressed); }
} // Dispose(someObject) /// <summary> /// Dispose /// </summary> /// <param name="someObject">Some object</param> public static void Dispose(ref ShadowMapShader someObject) { if (someObject != null) { someObject.Dispose(); } someObject = null; } // Dispose(someObject)
// For uniforms and shaders setup. Does not handle vertex/index buffers private static unsafe void EncodeShadowMap(RendererBGFXInstance *sys, bgfx.Encoder *encoder, ref ShadowMapShader shadowMapShader, ushort viewId, ref float4x4 tx, byte flipCulling, float4 bias #if DEBUG , float4 debugColor #endif ) { ulong state = (ulong)(bgfx.StateFlags.WriteZ | bgfx.StateFlags.DepthTestLess | bgfx.StateFlags.CullCcw); if (flipCulling != 0) { state = FlipCulling(state); } #if DEBUG state |= (ulong)bgfx.StateFlags.WriteRgb | (ulong)bgfx.StateFlags.WriteA; bgfx.encoder_set_uniform(encoder, shadowMapShader.m_uniformDebugColor, &debugColor, 1); #endif bgfx.encoder_set_state(encoder, state, 0); unsafe { fixed(float4x4 *p = &tx) bgfx.encoder_set_transform(encoder, p, 1); } bgfx.encoder_set_uniform(encoder, shadowMapShader.m_uniformBias, &bias, 1); bgfx.encoder_submit(encoder, viewId, shadowMapShader.m_prog, 0, (byte)bgfx.DiscardFlags.All); }
/// <summary> /// Dispose /// </summary> /// <param name="someObject">Some object</param> public static void Dispose(ref ShadowMapShader someObject) { if (someObject != null) someObject.Dispose(); someObject = null; }
/// <summary> /// Render game screen. Called each frame. /// </summary> public bool Render() { ShadowMapShader.PrepareGameShadows(); // This starts both menu and in game post screen shader! BaseGame.UI.PostScreenGlowShader.Start(); // Render background sky and lensflare. BaseGame.UI.RenderGameBackground(); // Render landscape with track and all objects RacingGameManager.Landscape.Render(); // Render car with matrix we got from CarPhysics RacingGameManager.CarModel.RenderCar( RacingGameManager.currentCarNumber, RacingGameManager.CarColor, false, RacingGameManager.Player.CarRenderMatrix); // And flush all models to be rendered BaseGame.MeshRenderManager.Render(); // Use data from best replay for the shadow car Matrix bestReplayCarMatrix = RacingGameManager.Landscape.BestReplay.GetCarMatrixAtTime( RacingGameManager.Player.GameTimeMilliseconds / 1000.0f); // For rendering rotate car to stay correctly on the road bestReplayCarMatrix = Matrix.CreateRotationX(MathHelper.Pi / 2.0f) * Matrix.CreateRotationZ(MathHelper.Pi) * bestReplayCarMatrix; // Also render the shadow car (if the game has started)! if (RacingGameManager.Player.GameTimeMilliseconds > 0) { RacingGameManager.CarModel.RenderCar( 0, RacingGameManager.CarColor, true, bestReplayCarMatrix); } // Show shadows we calculated above if (BaseGame.AllowShadowMapping) { ShaderEffect.shadowMapping.ShowShadows(); } // Apply post screen shader here before doing the UI BaseGame.UI.PostScreenGlowShader.Show(); // Play motor sound Sound.UpdateGearSound(RacingGameManager.Player.Speed, RacingGameManager.Player.Acceleration); // Show on screen UI for the game. // Note: Could be improved by using the latest checkpoints and // check times this way! BaseGame.UI.RenderGameUI( (int)RacingGameManager.Player.GameTimeMilliseconds, // Best time and current lap (int)RacingGameManager.Player.BestTimeMilliseconds, RacingGameManager.Player.CurrentLap + 1, RacingGameManager.Player.Speed * CarPhysics.MeterPerSecToMph, // Gear logic with sound (could be improved ^^) 1 + (int)(5 * RacingGameManager.Player.Speed / CarPhysics.MaxPossibleSpeed), // Motormeter 0.5f * RacingGameManager.Player.Speed / CarPhysics.MaxPossibleSpeed + // This could be improved 0.5f * RacingGameManager.Player.Acceleration, RacingGameManager.Landscape.CurrentTrackName, Highscores.GetTop5LapTimes(TrackSelection.SelectedTrackNumber)); if (Input.KeyboardEscapeJustPressed || Input.GamePadBackJustPressed || (RacingGameManager.Player.GameOver && (Input.KeyboardSpaceJustPressed || Input.GamePadAJustPressed || Input.GamePadBJustPressed || Input.GamePadXJustPressed || Input.GamePadXJustPressed || Input.MouseLeftButtonJustPressed))) { // Stop motor sound Sound.StopGearSound(); // Play menu music again Sound.Play(Sound.Sounds.MenuMusic); // Return to menu return(true); } return(false); }
/// <summary> /// Render game screen. Called each frame. /// </summary> public bool Render() { ShadowMapShader.PrepareGameShadows(); // This starts both menu and in game post screen shader! BaseGame.UI.PostScreenGlowShader.Start(); // Render background sky and lensflare. BaseGame.UI.RenderGameBackground(); // Render landscape with track and all objects RacingGameManager.Landscape.Render(); // Render car with matrix we got from CarPhysics RacingGameManager.CarModel.RenderCar( !RacingGameManager.Player.ShowCyclist, RacingGameManager.LocalPlayerCarColor, RacingGameManager.Player.CarRenderMatrix); int index = 0; Dictionary <string, RemotePlayer> remotePlayers = RacingGameManager.RemotePlayers; foreach (var e in remotePlayers) { RacingGameManager.RemoteCarModel[index].TimeScale = e.Value.Speed / CarPhysics.DefaultMaxSpeed; // Render car with matrix we got from CarPhysics RacingGameManager.RemoteCarModel[index++].RenderCar( true, e.Value.CarColor, e.Value.Transform); } // And flush all models to be rendered BaseGame.MeshRenderManager.Render(); //// Use data from best replay for the shadow car //Matrix bestReplayCarMatrix = // RacingGameManager.Landscape.BestReplay.GetCarMatrixAtTime( // RacingGameManager.Player.GameTimeMilliseconds / 1000.0f); //// For rendering rotate car to stay correctly on the road //bestReplayCarMatrix = // Matrix.CreateRotationX(MathHelper.Pi / 2.0f) * // Matrix.CreateRotationZ(MathHelper.Pi) * // bestReplayCarMatrix; //// Also render the shadow car (if the game has started)! //if (RacingGameManager.Player.GameTimeMilliseconds > 0) // RacingGameManager.CarModel.RenderCar( // 0, RacingGameManager.CarColor, // true, bestReplayCarMatrix); // Show shadows we calculated above if (BaseGame.AllowShadowMapping) { ShaderEffect.shadowMapping.ShowShadows(); } // Apply post screen shader here before doing the UI BaseGame.UI.PostScreenGlowShader.Show(); // Play motor sound Sound.UpdateGearSound(RacingGameManager.Player.Speed, RacingGameManager.Player.Acceleration); // Show on screen UI for the game. // Note: Could be improved by using the latest checkpoints and // check times this way! BaseGame.UI.RenderGameUI( (int)RacingGameManager.Player.GameTimeMilliseconds, // Best time and current lap (int)RacingGameManager.Player.BestTimeMilliseconds, RacingGameManager.Player.CurrentLap + 1, RacingGameManager.Player.Speed * CarPhysics.MeterPerSecToMph, // Gear logic with sound (could be improved ^^) 1 + (int)(5 * RacingGameManager.Player.Speed / CarPhysics.MaxPossibleSpeed), // Motormeter 0.5f * RacingGameManager.Player.Speed / CarPhysics.MaxPossibleSpeed + // This could be improved 0.5f * RacingGameManager.Player.Acceleration, RacingGameManager.Landscape.CurrentTrackName, RacingGameManager.RemotePlayers); if (isExiting) { RacingGameManager.InputInterface.Escape -= InputInterface_Escape; // Return to menu return(true); } return(false); }