/// <summary> /// Renders the game. /// </summary> private void Render() { if (deviceLost) { // This should only become true if we're using D3D9, so we can assume the // D3D9 context is valid at this point. if (Device.TestCooperativeLevel() == SlimDX.Direct3D9.ResultCode.DeviceNotReset) { Device.Reset(Context9.PresentParameters); deviceLost = false; OnResetDevice(); } else { Thread.Sleep(100); return; } } frameAccumulator += FrameDelta; ++frameCount; if (frameAccumulator >= 1.0f) { FramesPerSecond = frameCount / frameAccumulator; frameAccumulator = 0.0f; frameCount = 0; } try { OnRender(); } catch (SlimDX.Direct3D9.Direct3D9Exception e) { if (e.ResultCode == SlimDX.Direct3D9.ResultCode.DeviceLost) { OnLostDevice(); deviceLost = true; } else { throw; } } }
private void Render() { if (deviceLost) { // This should only become true if we're using D3D9, so we can assume the // D3D9 context is valid at this point. if (Device.TestCooperativeLevel() == global::SlimDX.Direct3D9.ResultCode.DeviceNotReset) { Device.Reset(Context9.PresentParameters); deviceLost = false; OnResetDevice(); } else { Thread.Sleep(100); return; } } try { Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0); Device.BeginScene(); foreach (CollisionObject colObj in Demo.World.CollisionObjectArray) { if (colObj is SoftBody) { if (Demo.IsDebugDrawEnabled) { continue; } Device.Material = SoftBodyMaterial; Device.SetTransform(TransformState.World, Matrix.Identity); _meshFactory.RenderSoftBody(colObj as SoftBody); } else { if ("Ground".Equals(colObj.UserObject)) { Device.Material = GroundMaterial; } else if (colObj.ActivationState == ActivationState.ActiveTag) { Device.Material = ActiveMaterial; } else { Device.Material = PassiveMaterial; } _meshFactory.Render(colObj); } } if (Demo.IsDebugDrawEnabled) { (Demo.World.DebugDrawer as PhysicsDebugDraw).DrawDebugWorld(Demo.World); } Info.OnRender(Demo.FramesPerSecond); Device.EndScene(); Device.Present(); } catch (global::SlimDX.Direct3D9.Direct3D9Exception e) { if (e.ResultCode == global::SlimDX.Direct3D9.ResultCode.DeviceLost) { OnLostDevice(); deviceLost = true; } else { throw; } } }