public void testSignalNext() { var signal = new Signal <int>(); var accum = new Accum <int>(); var accum3 = new Accum <int>(); signal.Next().OnSuccess(accum.Adder()); signal.Filter(v => v == 3).Next().OnSuccess(accum3.Adder()); signal.Emit(1); // adder should only receive this value accum.AssertContains(1); accum3.AssertContains(); signal.Emit(2); accum.AssertContains(1); accum3.AssertContains(); signal.Emit(3); accum.AssertContains(1); accum3.AssertContains(3); // signal should no longer have connections at this point Assert.False(signal.HasConnections()); signal.Emit(3); // adder3 should not receive multiple threes accum3.AssertContains(3); }
/// <summary> /// Performs movement and collision detection in the Z plane. /// </summary> protected virtual void DoZMovement() { Accum velZAbs = FixedMath.Abs(vel.Z); if (vel.Z == Accum.Zero) { DoZCollisionDetection(true); } else if (velZAbs < this.Height) { bCylinder.Position += vel; if (DoZCollisionDetection(true) == CollisionType.SpcColResp_StopMovement) { vel = Vector3k.Zero; } } else { Accum moveCount = FixedMath.Ceil(velZAbs / this.Height); Accum stepVel = vel.Z / this.Height; for (int i = 0; i < moveCount; i += 1) { bCylinder.Position += stepVel; if (DoZCollisionDetection(true) == CollisionType.SpcColResp_StopMovement) { vel = Vector3k.Zero; return; } } if (DoZCollisionDetection(true) == CollisionType.SpcColResp_StopMovement) { vel = Vector3k.Zero; } } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["ReservationId"] != null) { DataView dv = (DataView)VidSelect.Select(DataSourceSelectArguments.Empty); Session["vvid"] = (int)dv.Table.Rows[0][0]; DataView dvx = (DataView)sumamnty.Select(DataSourceSelectArguments.Empty); Double tl = (Double)dvx.Table.Rows[0][0]; amntytotal.Text = tl.ToString("n2"); DataView dvy = (DataView)sumfac.Select(DataSourceSelectArguments.Empty); Double tl1 = (Double)dvy.Table.Rows[0][0]; factotal.Text = tl1.ToString("n2"); DataView dvz = (DataView)summisc.Select(DataSourceSelectArguments.Empty); Double tl2 = (Double)dvz.Table.Rows[0][0]; misctotal.Text = tl2.ToString("n2"); x = Convert.ToDouble(amntytotal.Text); y = Convert.ToDouble(factotal.Text); z = Convert.ToDouble(misctotal.Text); DataView acum = (DataView)Accum.Select(DataSourceSelectArguments.Empty); Double w = (Double)acum.Table.Rows[0][0]; w = w + x + y + z; Label12.Text = w.ToString("n2"); Session["accum"] = w; accumUpdate.Update(); } Label11.Text = ""; }
[Test] public void testRemoveDuringDispatch() { var signal = new Signal <int>(); var toPreRemove = new Accum <int>(); var preConn = signal.OnEmit(toPreRemove.Adder()); var toPostRemove = new Accum <int>(); IDisposable postConn = null; // dispatch one event and make sure it's... signal.Emit(5); toPreRemove.AssertContains(5); // received toPostRemove.AssertContains(); // not received // add our remover and then our accum after our remover signal.OnEmit(value => { preConn.Dispose(); postConn.Dispose(); }); postConn = signal.OnEmit(toPostRemove.Adder()); // now emit a signal signal.Emit(42); // both listeners should receive the event because dispatch takes place on a copy of the // listener list created prior to dispatch toPreRemove.AssertContains(5, 42); toPostRemove.AssertContains(42); // finally dispatch one more event and make sure no one gets it (i.e. we were really removed) signal.Emit(9); toPreRemove.AssertContains(5, 42); toPostRemove.AssertContains(42); }
[Test] public void testAddAndRemoveDuringDispatch() { var signal = new Signal <int>(); var toAdd = new Accum <int>(); var toRemove = new Accum <int>(); var rconn = signal.OnEmit(toRemove.Adder()); // dispatch one event and make sure it's received by toRemove signal.Emit(5); toRemove.AssertContains(5); // now add our adder/remover signal, and dispatch again signal.OnEmit(value => { rconn.Dispose(); signal.OnEmit(toAdd.Adder()); }); signal.Emit(42); // make sure toRemove got this event and toAdd didn't toRemove.AssertContains(5, 42); toAdd.AssertContains(); // finally emit one more and ensure that toAdd got it and toRemove didn't signal.Emit(9); toAdd.AssertContains(9); toRemove.AssertContains(5, 42); }
[Test] public void testDispatchDuringDispatch() { var signal = new Signal <int>(); var counter = new Accum <int>(); signal.OnEmit(counter.Adder()); // connect a slot that will emit during dispatch IDisposable conn = null; conn = signal.OnEmit(value => { conn.Dispose(); if (value == 5) { signal.Emit(value * 2); } // ensure that we're not notified twice even though we emit during dispatch else { Assert.Fail("lner notified after Dispose()"); } }); // dispatch one event and make sure that both events are received signal.Emit(5); counter.AssertContains(5, 10); }
/// <summary> /// Performs movement and collision detection in the XY plane. /// </summary> protected virtual void DoMovement() { if ((vel.X | vel.Y) == Accum.Zero) { DoXYCollisionDetection(true); } else if (FixedMath.Abs(vel.X * vel.X + vel.Y * vel.Y) < (this.Radius * this.Radius)) { bCylinder.X += vel.X; bCylinder.Y += vel.Y; if (DoXYCollisionDetection(true) == CollisionType.SpcColResp_StopMovement) { vel = Vector3k.Zero; } } else { Accum moveCount = FixedMath.Ceil((vel.X * vel.X + vel.Y * vel.Y) / this.Radius); Vector3k stepVel = new Vector3k(vel.X / this.Radius, vel.Y / this.Radius, Accum.Zero); for (int i = 0; i < moveCount; i += 1) { bCylinder.X += vel.X; bCylinder.Y += vel.Y; if (DoXYCollisionDetection(true) == CollisionType.SpcColResp_StopMovement) { vel = Vector3k.Zero; return; } } if (DoXYCollisionDetection(true) == CollisionType.SpcColResp_StopMovement) { vel = Vector3k.Zero; } } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["ReservationId"] != null) { DataView dv = (DataView)VidSelect.Select(DataSourceSelectArguments.Empty); Session["vvid"] = (int)dv.Table.Rows[0][0]; DataView dvx = (DataView)sumamnty.Select(DataSourceSelectArguments.Empty); Double tl = (Double)dvx.Table.Rows[0][0]; DataView dvy = (DataView)sumfac.Select(DataSourceSelectArguments.Empty); Double tl1 = (Double)dvy.Table.Rows[0][0]; DataView dvz = (DataView)summisc.Select(DataSourceSelectArguments.Empty); Double tl2 = (Double)dvz.Table.Rows[0][0]; DataView acum = (DataView)Accum.Select(DataSourceSelectArguments.Empty); Double w = (Double)acum.Table.Rows[0][0]; DataView dmg = (DataView)dmgSum.Select(DataSourceSelectArguments.Empty); Double dgs = (Double)dmg.Table.Rows[0][0]; Label1.Text = dgs.ToString("n2"); w = tl + tl1 + tl2 + w + dgs; Label12.Text = w.ToString("n2"); Session["accum"] = w; accumUpdate.Update(); } }
/// <summary> /// Gets a Sprite from the rotation set. /// </summary> /// <param name="angle">The angle of the sprite.</param> /// <returns>A Sprite.</returns> public Sprite GetSprite(Accum angle) { angle = MathUtils.WrapAngle(angle); if (angle > Accum.Zero) { angle = new Accum(-360) + angle; } return(sprites [(int)Math.Floor(Math.Abs((double)angle / directionDiff))]); }
protected Actor() { maxHealth = health = 1000; prevPos = bCylinder.Position = vel = Vector3k.Zero; speed = angle = pitch = Accum.Zero; prevAngle = prevPitch = Accum.Zero; flags = 0; gravity = Accum.One; bCylinder = new BoundingCylinder(new Accum(16), new Accum(20), new Vector3k(Accum.Zero, Accum.Zero, Accum.Zero)); cam = new Camera(); }
[Test] public void testSignalToSlot() { var signal = new Signal <int>(); var accum = new Accum <int>(); signal.OnEmit(accum.Adder()); signal.Emit(1); signal.Emit(2); signal.Emit(3); accum.AssertContains(1, 2, 3); }
/// <summary> /// Changes the actor's height /// </summary> /// <param name="newHeight">The value to change the actor's height by</param> /// <param name="checkSpace">Check for space. Reverts the change and returns false if the actor didn't fit after the height change.</param> /// <returns>If checkSpace is true, returns true if the new height was set successfully, and returns false if the actor didn't fit. /// If checkSpace is false, always returns true.</returns> public virtual bool ChangeHeight(Accum heightOff, bool checkSpace) { bCylinder.Height += heightOff; if (checkSpace && IsColliding()) { bCylinder.Height -= heightOff; return(false); } else { return(true); } }
/// <summary> /// Changes the actor's radius /// </summary> /// <param name="newHeight">The value to change the actor's radius by</param> /// <param name="checkSpace">Check for space. Reverts the change and returns false if the actor didn't fit after the radius change.</param> /// <returns>If checkSpace is true, returns true if the new radius was set successfully, and returns false if the actor didn't fit. /// If checkSpace is false, always returns true.</returns> public virtual bool ChangeRadius(Accum radiusOff, bool checkSpace) { bCylinder.Radius += radiusOff; if (checkSpace && IsColliding()) { bCylinder.Radius -= radiusOff; return(false); } else { return(true); } }
public override void Tick() { base.Tick(); Camera.UpdateFromActor(this); if (state == null) { ObjFlags |= GameObjFlags.EuthanizeMe; } else if (stTime != -1 && --stTime <= 0) { if (state.Next != null) { ChangeState(state.Next); } else { GConsole.Debug.WriteLine("Actor tried to change to null state."); stTime = -1; } } if (ObjFlags.HasFlag(GameObjFlags.EuthanizeMe)) { return; } DoMovement(); DoZMovement(); Accum friction = GetFriction(); vel.X *= ((Math.Abs(vel.X.Value) > MINVELOCITY) ? friction : Accum.Zero); vel.Y *= ((Math.Abs(vel.Y.Value) > MINVELOCITY) ? friction : Accum.Zero); if (bCylinder.X < Constants.CoordinatesMin || bCylinder.Y < Constants.CoordinatesMin || bCylinder.Z < Constants.CoordinatesMin || bCylinder.X > Constants.CoordinatesMax || bCylinder.Y > Constants.CoordinatesMax || bCylinder.Z > Constants.CoordinatesMax) { this.Destroy(); } if (!flags.HasFlag(ActorFlags.NoGravity) && gravity > 0 && bCylinder.Z > 0) { vel.Z -= ((flags & ActorFlags.NoInteraction) == ActorFlags.NoInteraction) ? GetLocalGravity() : GetGravity(); } prevPos = bCylinder.Position; }
// Height /// <summary> /// Sets the actor's height /// </summary> /// <param name="newHeight">The actor's new height</param> /// <param name="checkSpace">Check for space. Reverts the change and returns false if the actor didn't fit after the height change.</param> /// <returns>If checkSpace is true, returns true if the new height was set successfully, and returns false if the actor didn't fit. /// If checkSpace is false, always returns true.</returns> public virtual bool SetHeight(Accum newHeight, bool checkSpace) { Accum oldHeight = bCylinder.Height; bCylinder.Height = newHeight; if (checkSpace && IsColliding()) { bCylinder.Height = oldHeight; return(false); } else { return(true); } }
// Radius /// <summary> /// Sets the actor's radius /// </summary> /// <param name="newHeight">The actor's new radius</param> /// <param name="checkSpace">Check for space. Reverts the change and returns false if the actor didn't fit after the radius change.</param> /// <returns>If checkSpace is true, returns true if the new radius was set successfully, and returns false if the actor didn't fit. /// If checkSpace is false, always returns true.</returns> public virtual bool SetRadius(Accum newRadius, bool checkSpace) { Accum oldRadius = bCylinder.Radius; bCylinder.Radius = newRadius; if (checkSpace && IsColliding()) { bCylinder.Radius = oldRadius; return(false); } else { return(true); } }
[Test] public void testAddDuringDispatch() { var signal = new Signal <int>(); var toAdd = new Accum <int>(); IDisposable once = null; once = signal.OnEmit(value => { signal.OnEmit(toAdd.Adder()); once.Dispose(); }); // this will connect our new signal but not dispatch to it signal.Emit(5); Assert.AreEqual(0, toAdd.values.Count); // now dispatch an event that should go to the added signal signal.Emit(42); toAdd.AssertContains(42); }
[Test] public void testSingleFailure() { var signal = new Signal <int>(); var preCounter = new Accum <int>(); signal.OnEmit(preCounter.Adder()); signal.OnEmit(value => { throw new InvalidOperationException("Bang!"); }); var postCounter = new Accum <int>(); signal.OnEmit(postCounter.Adder()); try { signal.Emit(0); Assert.Fail("Emit should have thrown."); } catch (AggregateException e) { Assert.AreEqual(1, e.InnerExceptions.Count); } // both pre and post counter should have received notifications preCounter.AssertContains(0); postCounter.AssertContains(0); }
/// <summary> /// Detects collisions in the Z plane. /// </summary> /// <param name="performResponse">Whether to fix any collisions. Defaults to true.</param> /// <returns>A CollisionType indicating whether a collision happened.</returns> public virtual CollisionType DoZCollisionDetection(bool performResponse = true) { if (this.CheckFlags(ActorFlags.NoInteraction)) // Don't do collision detection if NoInteraction is set. { return(CollisionType.None); } Actor firstCollision = null; bool spcColRespStopMove = false; Accum deltaDist = bCylinder.Z; foreach (Actor act in Core.Ticker.Thinkers) // Iterate through all actors. { if (act == null || act == this) // Skip if the actor is null or act refers to itself { continue; } if (act.CheckFlags(ActorFlags.NoBlockmap) || act.CheckFlags(ActorFlags.NoInteraction)) // Skip the actor if it has NoBlockmap or NoInteraction { continue; } if (!bCylinder.IntersectsXY(act.bCylinder)) // If we're not colliding in the XY axes, skip. They can't be colliding in the Z axis if they aren't colliding in the XY axes! { continue; } if (bCylinder.Z >= act.bCylinder.Z) { if (performResponse) { bCylinder.Z = act.bCylinder.Top; } if (firstCollision == null) { firstCollision = act; } if (SpecialCollisionResponseZ(performResponse, act, act == firstCollision)) { spcColRespStopMove = true; } } else if (bCylinder.Top <= act.bCylinder.Top) { if (performResponse) { bCylinder.Z = act.bCylinder.Z - Height; } if (firstCollision == null) { firstCollision = act; } if (SpecialCollisionResponseZ(performResponse, act, act == firstCollision)) { spcColRespStopMove = true; } } } if (performResponse) { bCylinder.Z = deltaDist; } if (spcColRespStopMove) { return(CollisionType.SpcColResp_StopMovement); } else if (firstCollision != null) { return(CollisionType.Collision); } else { return(CollisionType.None); } }
/// <summary> /// Changes the actor's angle (In radians) /// </summary> /// <param name="x">The value to change the angle by</param> /// <param name="interpolate">If true, the change will be interpolated</param> public virtual void ChangeAngleRadians(Accum x, bool interpolate = false) { prevAngle = (interpolate ? angle : prevAngle); angle = MathUtils.WrapAngle(angle + FixedMath.RadiansToDegrees(x)); }
/// <summary> /// Changes the actor's pitch (In radians) /// </summary> /// <param name="x">The value to change the pitch by</param> /// <param name="interpolate">If true, the change will be interpolated</param> public virtual void ChangePitchRadians(Accum x, bool interpolate = false) { prevPitch = (interpolate ? pitch : prevPitch); pitch = FixedMath.ClampInt((pitch + FixedMath.RadiansToDegrees(x)), -90, 90); }
public BoundingCylinder(Accum radius, Accum height, Vector3k pos) { Radius = radius; Height = height; _position = pos; }
/// <summary> /// Gets an empty sprite. /// </summary> /// <param name="angle">Does nothing.</param> /// <returns>A Sprite.</returns> public Sprite GetSprite(Accum angle) { return(Sprite.EmptySprite); }
/// <summary> /// Changes the actor's pitch /// </summary> /// <param name="x">The value to change the pitch by</param> /// <param name="interpolate">If true, the change will be interpolated</param> public virtual void ChangePitch(Accum x, bool interpolate = false) { prevPitch = (interpolate ? pitch : prevPitch); pitch = FixedMath.ClampInt((pitch + x), -90, 90); }
protected void Page_Load(object sender, EventArgs e) { DataView dvx = (DataView)sumamnty.Select(DataSourceSelectArguments.Empty); Double tl = (Double)dvx.Table.Rows[0][0]; Label7.Text = tl.ToString("n2"); DataView dvy = (DataView)sumfac.Select(DataSourceSelectArguments.Empty); Double tl1 = (Double)dvy.Table.Rows[0][0]; Label8.Text = tl1.ToString("n2"); DataView dvz = (DataView)summisc.Select(DataSourceSelectArguments.Empty); Double tl2 = (Double)dvz.Table.Rows[0][0]; Label9.Text = tl2.ToString("n2"); DataView dmg = (DataView)dmgSum.Select(DataSourceSelectArguments.Empty); Double dgs = (Double)dmg.Table.Rows[0][0]; Label10.Text = dgs.ToString("n2"); DataView acum = (DataView)Accum.Select(DataSourceSelectArguments.Empty); Double w = (Double)acum.Table.Rows[0][0]; Label6.Text = w.ToString("n2"); x = Convert.ToDouble(Label7.Text); y = Convert.ToDouble(Label8.Text); z = Convert.ToDouble(Label9.Text); total = x + y + z + w + dgs; Label12.Text = total.ToString("n2"); Label2.Text = DateTime.Now.ToLongDateString(); DataView PBD = (DataView)PB.Select(DataSourceSelectArguments.Empty); Double P = (Double)PBD.Table.Rows[0][0]; P = P - total; if (P >= 0) { Label14.Text = "Refundable Amount "; Label13.Text = P.ToString("n2"); } else { P = Math.Abs(P); Label13.Text = P.ToString("n2"); Label14.Text = "Remaining Balance"; } DataView dv5 = (DataView)DetailsSelect.Select(DataSourceSelectArguments.Empty); string vn, en, cn, cc; DateTime ddate; TimeSpan st, et; vn = (string)dv5.Table.Rows[0][0]; ddate = (DateTime)dv5.Table.Rows[0][1]; st = (TimeSpan)dv5.Table.Rows[0][2]; et = (TimeSpan)dv5.Table.Rows[0][3]; en = (string)dv5.Table.Rows[0][4]; cn = (string)dv5.Table.Rows[0][5]; cc = (string)dv5.Table.Rows[0][6]; Venue.Text = vn; EventDate.Text = ddate.ToLongDateString(); StartTime.Text = ConvertMode(st.ToString()); EndTime.Text = ConvertMode(et.ToString()); EventName.Text = en; Label3.Text = cn; Label4.Text = cc; }
/// <summary> /// Changes the actor's angle /// </summary> /// <param name="x">The value to change the angle by</param> /// <param name="interpolate">If true, the change will be interpolated</param> public virtual void ChangeAngle(Accum x, bool interpolate = false) { prevAngle = (interpolate ? angle : prevAngle); angle = MathUtils.WrapAngle(angle + x); }