public static Timer ( DirectXTimer command ) : float | ||
command | DirectXTimer | |
리턴 | float |
public void DrawGoo() { float CurrTime = DXUtil.Timer(DirectXTimer.GetApplicationTime); float fTime = (float)(((CurrTime % 180.0f) / 180.0f) * (2 * Math.PI)); WorldMatrix = DirectX.Matrix.RotationYawPitchRoll((float)((CurrTime % 240) / 240 * Math.PI), 0, 0) * DirectX.Matrix.Translation(0, -45, -400); DirectX.Matrix WorldViewMatrix = WorldMatrix * ViewMatrix; DirectX.Matrix WorldViewProjMatrix = WorldMatrix * ViewMatrix * ProjectionMatrix; GooEffect.SetValue("fMixTime", fTime); GooEffect.SetValue("WorldView", WorldViewMatrix); GooEffect.SetValue("WorldViewProjection", WorldViewProjMatrix); GameDevice.RenderState.AlphaBlendEnable = false; int numPasses = GooEffect.Begin(0); for (int i = 0; i < numPasses; i++) { GooEffect.BeginPass(i); GooMesh.DrawSubset(0); GooEffect.EndPass(); } GooEffect.End(); // Restore alpha blend setting GameDevice.RenderState.AlphaBlendEnable = true; }
// The GameClass constructor. Here we create, but not show, the GameSettings form. // The public GameClass(MainClass mainClass, Control owner) { gameState = GameStates.Loading; this.owner = owner; this.mainClass = mainClass; splash = new SplashScreen(this); splash.ShowDialog(); gameSettings = new SpaceWar.GameSettings(this); gameSettings.Location = new Point(owner.Bounds.Right, owner.Bounds.Top); gravity = gameSettings.Gravity; gameSpeed = gameSettings.GameSpeed; bounceBack = gameSettings.Bounce; inverseGravity = gameSettings.InverseGravity; blackHole = gameSettings.BlackHole; localDevice = new Microsoft.DirectX.DirectDraw.Device(); localDevice.SetCooperativeLevel(owner, Microsoft.DirectX.DirectDraw.CooperativeLevelFlags.Normal); DXUtil.Timer(DirectXTimer.Start); SpaceWar.RotatableShape.CreateShapes(); input = new InputClass(this.owner); soundHandler = new SoundHandler(this.owner); try { netPeer = new PlayClass(this); } catch (DirectXException e) { MessageBox.Show(owner, e.ToString()); } }
private void Draw() { float AppTime = DXUtil.Timer(DirectXTimer.GetApplicationTime); Vector3 campos = new Vector3(80f * (float)Math.Cos(AppTime), 38, 80f * (float)Math.Sin(AppTime)); if (camMode) { campos = new Vector3(0, 200, -30); } viewMatrix = Matrix.LookAtLH(campos, new Vector3(), new Vector3(0, 1, 0)); Matrix worldViewProj = viewMatrix * projMatrix; // Update the effect's variables effect.SetValue(handle1, ambient); effect.SetValue(handle2, worldViewProj); effect.SetValue(handle3, new float[] { Terrain.size *0.5f *(float)Math.Sin(AppTime), 80, Terrain.size * 0.5f * (float)Math.Cos(AppTime) }); // Begin rendering with the effect effect.Begin(0); // There's only one pass effect.BeginPass(0); t.Draw(); effect.EndPass(); effect.End(); }
public Explosion(Direct3D.Device NewDevice, DirectX.Vector3 NewPosition) { this.CurrDevice = NewDevice; this.ExplosionTexture = Direct3D.TextureLoader.FromFile(CurrDevice, GameConfig.Files.ExplosionPoint); this.LightTexture = Direct3D.TextureLoader.FromFile(CurrDevice, GameConfig.Files.ExplosionLight); this.ExplosionPosition = NewPosition; this.Rand = new Random(); this.UniversalGravity = .50f; this.ParticleCount = 100; this.NeedsDelete = false; this.Particles = new ArrayList(); for (int i = 0; i < this.ParticleCount; i++) { Particles.Add(new Particle(this.UniversalGravity, ExplosionPosition, new DirectX.Vector3((float)(Rand.NextDouble() * 0.75f - 0.375f), (float)(Rand.NextDouble() * 0.5f - 0.1f), 0.0f), DXUtil.Timer(DirectXTimer.GetApplicationTime))); } ExplosionFlash = new Flash(ExplosionPosition, DXUtil.Timer(DirectXTimer.GetApplicationTime)); this.LastUpdateTime = DXUtil.Timer(DirectXTimer.GetApplicationTime); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if (device.Disposed) { return; } // Get elapsed time to calculate FPS ElapsedTime = DXUtil.Timer(DirectXTimer.GetElapsedTime); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.CornflowerBlue, 1.0f, 0); device.BeginScene(); Draw(); // Drawing multiple lines of text on the same sprite is more efficient using (Sprite s = new Sprite(device)) { s.Begin(SpriteFlags.AlphaBlend); int y = 5; font.DrawText(s, string.Format("FPS: {0}", ((int)(1f / ElapsedTime)).ToString()), new Rectangle(4, y, 0, 0), DrawTextFormat.NoClip, Color.FromArgb(64, 255, 255, 255)); y += 22; font.DrawText(s, string.Format("Ambient light: {0}%", (int)(ambient * 100)), new Rectangle(4, y, 0, 0), DrawTextFormat.NoClip, Color.FromArgb(64, 255, 255, 255)); s.End(); } device.EndScene(); device.Present(); // The onPaint event must be called again this.Invalidate(); }
public SplashScreen(string filename, int nDuration) { image = new Image(filename); m_StartTime = DXUtil.Timer(TIMER.GETABSOLUTETIME); m_EndTime = m_StartTime + nDuration; m_vb = new VertexBuffer(typeof(CustomVertex.TransformedTextured), 4, CGameEngine.Device3D, Usage.WriteOnly, CustomVertex.TransformedTextured.Format, Pool.Default); }
public void Draw() { Particle tmpParticle; float CurrTime; float TimeDiff; if (this.Particles.Count < 1) { NeedsDelete = true; } CurrTime = DXUtil.Timer(DirectXTimer.GetApplicationTime); TimeDiff = CurrTime - LastUpdateTime; for (int i = 0; i < Particles.Count; i++) { tmpParticle = (Particle)Particles[i]; tmpParticle.Velocities.Y -= tmpParticle.Gravity * TimeDiff; tmpParticle.Positions.X += tmpParticle.Velocities.X * TimeDiff; tmpParticle.Positions.Y += tmpParticle.Velocities.Y * TimeDiff; tmpParticle.Positions.Z += tmpParticle.Velocities.Z * TimeDiff; if (CurrTime - tmpParticle.TimeCreated <= 1.5f) { tmpParticle.Height = 1.5f * (1.5f - (CurrTime - tmpParticle.TimeCreated)); tmpParticle.Width = 1.5f * (1.5f - (CurrTime - tmpParticle.TimeCreated)); tmpParticle.GenerateVerticies(); } this.CurrDevice.Transform.World = DirectX.Matrix.RotationYawPitchRoll(0, 0, 0) * DirectX.Matrix.Translation(tmpParticle.Positions.X, tmpParticle.Positions.Y, tmpParticle.Positions.Z) * SpaceAndTime.ScaleStandard; this.CurrDevice.SetTexture(0, ExplosionTexture); CurrDevice.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleStrip, 2, tmpParticle.Verticies); if (tmpParticle.Positions.Y < -2.0f) { this.Particles.Remove(tmpParticle); } } if (CurrTime - ExplosionFlash.TimeCreated <= .25) { ExplosionFlash.Height = 256 * (CurrTime - ExplosionFlash.TimeCreated); ExplosionFlash.Width = 256 * (CurrTime - ExplosionFlash.TimeCreated); ExplosionFlash.GenerateVerticies(); } else { ExplosionFlash.Height = 0.0f; ExplosionFlash.Width = 0.0f; ExplosionFlash.GenerateVerticies(); } this.CurrDevice.Transform.World = DirectX.Matrix.RotationYawPitchRoll(0, 0, 0) * DirectX.Matrix.Translation(ExplosionFlash.Positions.X, ExplosionFlash.Positions.Y, ExplosionFlash.Positions.Z) * SpaceAndTime.ScaleStandard; this.CurrDevice.SetTexture(0, LightTexture); CurrDevice.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleStrip, 2, ExplosionFlash.Verticies); this.LastUpdateTime = DXUtil.Timer(DirectXTimer.GetApplicationTime); }
/// <summary> /// Called once per frame, the call is the entry point for 3d rendering. This /// function sets up render states, clears the viewport, and renders the scene. /// </summary> protected override void Render() { input.GetInputState(); //Clear the backbuffer to a Blue color device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Gray, 1.0f, 0); //Begin the scene device.BeginScene(); device.Lights[0].Enabled = true; // Setup the world, view, and projection matrices Matrix m = new Matrix(); if (destination.Y != 0) { y += DXUtil.Timer(DirectXTimer.GetElapsedTime) * (destination.Y * 25); } if (destination.X != 0) { x += DXUtil.Timer(DirectXTimer.GetElapsedTime) * (destination.X * 25); } m = Matrix.Translation(0.0f, 0.75f, 0.0f); m *= Matrix.RotationY(y); m *= Matrix.RotationX(x); device.Transform.World = m; // Render the teapot. teapot.DrawSubset(0); m = new Matrix(); m = Matrix.Translation(0.0f, -0.75f, 0.0f); m *= Matrix.RotationY(y); m *= Matrix.RotationX(x); device.Transform.World = m; //render the box box.DrawSubset(0); device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 3.0f, -5.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f)); device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.0f, 1.0f, 100.0f); device.EndScene(); }
/// <summary> /// Do all the processing for this quadro before we render it /// </summary> private void processaProximoQuadro() { // Get the current elapsed time tempoDecorrido = DXUtil.Timer(DirectXTimer.GetElapsedTime); // Set the world matrix Matrix worldMatrix = Matrix.Translation(objetoCentro); device.Transform.World = worldMatrix; if (quadroRaiz.AnimationController != null) { quadroRaiz.AnimationController.AdvanceTime(tempoDecorrido, null); } quadro_AtualizarMatrizes((QuadroDerivado)quadroRaiz.FrameHierarchy, worldMatrix); } // processaProximoQuadro().fim
/// <summary> /// Create the animation hierarchy for this file /// </summary> private void carregarModeloAnimado(string file, PresentParameters presentParams) { // Create our allocate hierarchy derived class HierarquiaAlojamento alloc = new HierarquiaAlojamento(this); // Load our file quadroRaiz = Mesh.LoadHierarchyFromFile(file, MeshFlags.Managed, device, alloc, null); // Calculate the center and radius of a bounding sphere objetoRaio = Frame.CalculateBoundingSphere(quadroRaiz.FrameHierarchy, out objetoCentro); // Setup the matrices for animation ossos_ConfigurarMatrizes((QuadroDerivado)quadroRaiz.FrameHierarchy); // Start the timer DXUtil.Timer(DirectXTimer.Start); } // carregarModeloAnimado().fim
public GameWorld(MainForm _mainform) { // // TODO: Add constructor logic here // mainform = _mainform; DXUtil.Timer(DirectXTimer.Start); peer = new NETPlayer(this); if (peer.InSession) { if (peer.IsHost) { timer.Tick += new EventHandler(TimerEvent); timer.Interval = 4500; timer.Start(); } } InitializeKeyboard(); }
public void DataReceived(object sender, ReceiveEventArgs rea) { int senderID = rea.Message.SenderID; byte mType = (byte)rea.Message.ReceiveData.Read(typeof(byte)); MessageType messageType = (MessageType)mType; switch (messageType) { case MessageType.PlayerUpdateID: { PlayerUpdate update = (PlayerUpdate)rea.Message.ReceiveData.Read(typeof(PlayerUpdate)); rea.Message.ReceiveData.Dispose(); lock (otherPlayers) { object playerObject = otherPlayers[senderID]; if (null == playerObject) { return; } RemotePlayer player = (RemotePlayer)playerObject; player.Position = update.position; player.Velocity = update.velocity; player.UpdateTime = DateTime.Now; player.Active = true; otherPlayers[senderID] = player; } break; } case MessageType.GameTime: { float stime = (float)rea.Message.ReceiveData.Read(typeof(float)); rea.Message.ReceiveData.Dispose(); serverTime = stime - DXUtil.Timer(DirectXTimer.GetApplicationTime); break; } case MessageType.GameChat: { MessageUpdate update = (MessageUpdate)rea.Message.ReceiveData.Read(typeof(MessageUpdate)); string s = ""; s += rea.Message.ReceiveData.ReadString(); rea.Message.ReceiveData.Dispose(); lock (otherPlayers) { object playerObject = otherPlayers[senderID]; if (null == playerObject) { return; } RemotePlayer player = (RemotePlayer)playerObject; mainform.textBox2.Text += player.ToString() + s + "\r\n"; } break; } } }
unsafe private void CheckTimer(object aCpuNo) { CheckResults ThreadSummary = new CheckResults(); ThreadSummary.TimerResolution = 0; ThreadSummary.StopwatchResolution = 0; try { try { short currentCpu = (short)aCpuNo; SetThreadAffinityMask(GetCurrentThread(), new IntPtr(1 << currentCpu)); float MpAccuracy = DXUtil.Timer(DirectXTimer.GetAbsoluteTime); MpAccuracy = DXUtil.Timer(DirectXTimer.GetAbsoluteTime) - MpAccuracy; Stopwatch TimerWatch = new Stopwatch(); TimerWatch.Start(); TimerWatch.Stop(); double NetAccuracyMs = ((double)TimerWatch.ElapsedTicks / (double)Stopwatch.Frequency) * 1000; string NetAccuracyResult = NetAccuracyMs.ToString("N5"); long TicksPerSec = 0; if (!QueryPerformanceFrequency(ref TicksPerSec)) { MessageBox.Show("This system does not support accurate timing!"); return; } long TempTime = 0; double StartTime = 0; QueryPerformanceCounter(ref TempTime); // we neglect the overhead of these assignments in between.. StartTime = TempTime; QueryPerformanceCounter(ref TempTime); // The timespan between two timer results in ms double SysAccuracyMs = ((TempTime - StartTime) / TicksPerSec) * 1000; string SysAccuracyResult = SysAccuracyMs.ToString("N5"); if (SysAccuracyMs < fMaxAccuracy) { fMaxAccuracy = SysAccuracyMs; } ThreadSummary.ResultOutput = string.Format("CPU {0}: Ticks per second: {1} / MP accuracy: {2} / .NET accuracy: {3} / Approx. accurary in ms: {4}", currentCpu, TicksPerSec, MpAccuracy, NetAccuracyResult, SysAccuracyResult); ThreadSummary.TimerResolution = SysAccuracyMs; ThreadSummary.StopwatchResolution = NetAccuracyMs; Thread.Sleep(0); } catch (ThreadAbortException tae) { ThreadSummary.ResultOutput = tae.Message; } catch (ThreadStateException tse) { ThreadSummary.ResultOutput = tse.Message; } // Let the GUI thread add our result to the listbox Invoke(new MethodListViewItems(ThreadedListItemAdder), new object[] { ThreadSummary }); } catch (Exception) { } }
public void MainLoop() { float minFrameTime = gameSettings.GameSpeed * 0.005f; if (lastFrameTime < minFrameTime) { lastFrameTime += DXUtil.Timer(DirectXTimer.GetElapsedTime); return; } lastFrameTime = 0.0f; try { if (gameState == GameStates.Paused) { Word paused = new Word("PAUSED", Constants.LetterSize * 1.5f); paused.Draw(surfaceSecondary, Color.White.ToArgb(), Constants.LetterSpacing * 2, new Point(windowBounds.Left + 50, windowBounds.Top + 50)); surfacePrimary.Draw(surfaceSecondary, DrawFlags.DoNotWait); } // Clear the ship's sound flags ship.Sounds = (Sounds)0; // process input HandleKeys(); if (gameState != GameStates.Running) { return; } surfaceSecondary.ColorFill(Color.Black); surfaceSecondary.DrawWidth = 1; // update my position, and tell others about it... ship.UpdatePosition(); // update my state, and draw myself... ship.UpdateState(); //If there are other players, send them our ship info if (netPeer.InSession && otherPlayers.Count > 0) { SendMyPlayerUpdate(); } WriteScores(); stars.Draw(surfaceSecondary); int shipColor = Color.White.ToArgb(); int shotColor = Color.White.ToArgb(); ship.Draw(surfaceSecondary, shipColor, shotColor); // Handle other ships // walk through all other players. For each player // 1) draw the ship // 2) check to see whether the other ship has killed us // 3) figure the score // 4) see if we need to time-out this ship int shipIndex = 0; Sounds otherShipSounds = (Sounds)0; DateTime now = DateTime.Now; lock (otherPlayers) { foreach (RemotePlayer player in otherPlayers.Values) { if (!player.Active) { continue; } player.Ship.Draw(surfaceSecondary, shipColors[shipIndex].ToArgb(), shotColor); shipIndex = (shipIndex + 1) % shipColors.Length; ship.TestShip(player); otherShipSounds |= player.Ship.Sounds; // if we haven't gotten an update in a while, // mark the player as inactive... TimeSpan delta = now - player.UpdateTime; if (delta.Seconds > Constants.RemoteTickTimeout) { player.Active = false; } } } // Draw the sun only if the "Black Hole" option isn't enabled if (!blackHole) { sun.Draw(surfaceSecondary); } surfacePrimary.Draw(surfaceSecondary, DrawFlags.DoNotWait); PlaySounds(otherShipSounds); } catch (SurfaceLostException) { // The surface can be lost if power saving // mode kicks in, or any other number of reasons. CreateSurfaces(); } }
public void StartZero() { _isRunning = true; _startTime = (uint)(DXUtil.Timer(DirectXTimer.GetAbsoluteTime) * 1000.0); }
private void TimerEvent(Object myObject, EventArgs myEventArgs) { peer.SendTimeUpdate(DXUtil.Timer(DirectXTimer.GetApplicationTime)); }
public void Loop() { float minFrameTime = Speed * 0.005f; if (lastFrameTime < minFrameTime) { lastFrameTime += DXUtil.Timer(DirectXTimer.GetElapsedTime); return; } // read input ReadKeyboard(); if (appTime - appTimeOld > 0.1) { appTimeOld = appTime; if (peer.InSession && otherPlayers.Count > 0) { SendMyPlayerUpdate(); } } DateTime now = DateTime.Now; lock (otherPlayers) { foreach (RemotePlayer player in otherPlayers.Values) { if (!player.Active) { continue; } TimeSpan delta = now - player.UpdateTime; if (delta.Seconds > RemoteTickTimeout) { player.Active = false; } } } // compute all if (peer.InSession) { if (peer.IsHost) { appTime = DXUtil.Timer(DirectXTimer.GetApplicationTime); } else { appTime = DXUtil.Timer(DirectXTimer.GetApplicationTime) + serverTime; } } mainform.Text = "" + appTime; Update(appTime); // network respond // render // me mainform.clear(); mainform.setDot(position); // others lock (otherPlayers) { foreach (RemotePlayer player in otherPlayers.Values) { if (!player.Active) { continue; } mainform.setDot(player.Position); } } lastFrameTime = 0.0f; }
private bool _paused; // is timer paused? // -------------------------------------------------------------------- // Returns absolute system time; static; requires no timer objects // -------------------------------------------------------------------- public static float Now() { return(DXUtil.Timer(DirectXTimer.GetAbsoluteTime)); }
public bool Render() { try { bool fog_state = CGameEngine.Device3D.RenderState.FogEnable; CGameEngine.Device3D.RenderState.FogEnable = false; CustomVertex.TransformedTextured[] data = new CustomVertex.TransformedTextured[4]; data[0].X = 0.0f; data[0].Y = 0.0f; data[0].Z = 0.0f; data[0].Tu = 0.0f; data[0].Tv = 0.0f; data[1].X = CGameEngine.Device3D.Viewport.Width; data[1].Y = 0.0f; data[1].Z = 0.0f; data[1].Tu = 1.0f; data[1].Tv = 0.0f; data[2].X = 0.0f; data[2].Y = CGameEngine.Device3D.Viewport.Height; data[2].Z = 0.0f; data[2].Tu = 0.0f; data[2].Tv = 1.0f; data[3].X = CGameEngine.Device3D.Viewport.Width; data[3].Y = CGameEngine.Device3D.Viewport.Height; data[3].Z = 0.0f; data[3].Tu = 1.0f; data[3].Tv = 1.0f; m_vb.SetData(data, 0, 0); CGameEngine.Device3D.SetStreamSource(0, m_vb, 0); CGameEngine.Device3D.VertexFormat = CustomVertex.TransformedTextured.Format; // Set the texture CGameEngine.Device3D.SetTexture(0, image.GetTexture()); // Render the face CGameEngine.Device3D.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); CGameEngine.Device3D.RenderState.FogEnable = fog_state; } catch (DirectXException d3de) { Console.AddLine("Unable to display SplashScreen "); Console.AddLine(d3de.ErrorString); } catch (Exception e) { Console.AddLine("Unable to display SplashScreen "); Console.AddLine(e.Message); } // check for timeout float fCurrentTime = DXUtil.Timer(TIMER.GETABSOLUTETIME); fTimeLeft = m_EndTime - fCurrentTime; return(fCurrentTime > m_EndTime); }