public static void SaveCircuitGraph() { Bitmap b = new Bitmap(800, 600); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage((Image)b); foreach (var comp in Components.ComponentsManager.Components) { if (comp is Components.Joint) { try { Components.Joint j = (Components.Joint)comp; g.FillRectangle(new SolidBrush(Color.FromArgb((int)(255 * j.Voltage / 5f), 0, 0)), j.Graphics.Position.X - 1, j.Graphics.Position.Y - 1, 3, 3); //for (int i = 0; i < j.ConnectedJoints.Count; i++) //{ // g.DrawLine(new Pen(Color.FromArgb((int)(255 * j.Voltage / 5f), 0, 0)), // j.Graphics.Position.X, j.Graphics.Position.Y, // j.ConnectedJoints[i].Graphics.Position.X, j.ConnectedJoints[i].Graphics.Position.Y); //} } catch { } } } int t = System.IO.Directory.GetFiles("Debug").Length; b.Save("Debug/" + t.ToString() + ".bmp"); }
public override void Bind(Entity entity, Main main, bool creating = false) { Components.Joint joint = entity.GetOrCreate <Components.Joint>("Joint"); Spinner spinner = entity.GetOrCreate <Spinner>("Spinner"); spinner.Add(new Binding <Direction>(spinner.Direction, joint.Direction)); JointFactory.Bind(entity, main, spinner.CreateJoint, true, creating); DynamicVoxel voxel = entity.Get <DynamicVoxel>(); voxel.KineticFriction.Value = voxel.StaticFriction.Value = 0; entity.Add("On", spinner.On); entity.Add("Off", spinner.Off); entity.Add("Forward", spinner.Forward); entity.Add("Backward", spinner.Backward); entity.Add("HitMax", spinner.HitMax); entity.Add("HitMin", spinner.HitMin); entity.Add("Direction", joint.Direction); entity.Add("Minimum", spinner.Minimum); entity.Add("Maximum", spinner.Maximum); entity.Add("Locked", spinner.Locked); entity.Add("Speed", spinner.Speed); entity.Add("Goal", spinner.Goal); entity.Add("Servo", spinner.Servo); entity.Add("CannotSuspendByDistance", entity.Get <DynamicVoxel>().CannotSuspendByDistance); }
public void Init(Components.Joint j) { potentialGrounds.Clear(); potentialPowerSources.Clear(); _processInitJoint(j); InitMatrixes(); SubscribeToEvents(); Recalculate = true; }
private bool AreConnectedWiresIsolated(Components.Joint j) { foreach (var w in j.ConnectedWires) { if (!w.IsIsolated) { return(false); } } return(true); }
private void _processInitJoint(Components.Joint j) { if (j == null || j.IsInSubCircuit) { return; } j.IsInSubCircuit = true; joints.Add(j); j.circuitPart = this; jointIDIndex.Add(j.ID, joints.Count - 1); if (j.CanBeGround) { j.localGroundInd = potentialGrounds.Count; potentialGrounds.Add((int)jointIDIndex[j.ID]); } if (j.CanProvidePower) { j.localProviderInd = potentialPowerSources.Count; potentialPowerSources.Add((int)jointIDIndex[j.ID]); } Serialize(); for (int i = 0; i < j.ConnectedWires.Count; i++) { if (j.ConnectedWires[i].IsUpdated) { continue; } j.ConnectedWires[i].IsUpdated = true; if (j.ConnectedWires[i].J1.ID == j.ID) { _processInitJoint(j.ConnectedWires[i].J2); j.ConnectedWires[i].localJointInd1 = (int)jointIDIndex[j.ID]; j.ConnectedWires[i].localJointInd2 = (int)jointIDIndex[j.ConnectedWires[i].J2.ID]; } else { _processInitJoint(j.ConnectedWires[i].J1); j.ConnectedWires[i].localJointInd1 = (int)jointIDIndex[j.ID]; j.ConnectedWires[i].localJointInd2 = (int)jointIDIndex[j.ConnectedWires[i].J1.ID]; } j.ConnectedWires[i].localIndSelf = wires.Count; if (j.ConnectedWires[i].CanSendVoltageOrCurrent) { wirePotentialSendingVoltageCount++; } wires.Add(j.ConnectedWires[i]); j.ConnectedWires[i].circuitPart = this; Serialize(); } }
public static bool CanReach(Components.Joint from, Components.Joint to) { if (from == null || to == null) { return(false); } Components.Joint t = null; Components.Joint[] ta; List <Components.Joint> open = new List <Components.Joint>(); int curOpenInd = 0; open.Add(from); int i, j; while (open.Count > curOpenInd && (t = open[curOpenInd]) != to) { for (i = 0; i < t.ContainingComponents.Count; i++)//find connections through components { ta = t.ContainingComponents[i].FindAccessibleJoints(t); for (j = 0; j < ta.Length; j++) { if (!open.Contains(ta[j])) { open.Add(ta[j]); } } } for (i = 0; i < t.ConnectedWires.Count; i++)//find connections through wire { if (t.ConnectedWires[i].Graphics.Visible && t.ConnectedWires[i].IsConnected) { if (t.ConnectedWires[i].J1 == t) { if (t.ConnectedWires[i].Direction != Components.Wire.WireDirection.J2ToJ1 && !open.Contains(t.ConnectedWires[i].J2)) { open.Add(t.ConnectedWires[i].J2); } } else if (t.ConnectedWires[i].Direction != Components.Wire.WireDirection.J1ToJ2 && !open.Contains(t.ConnectedWires[i].J1)) { open.Add(t.ConnectedWires[i].J1); } } } curOpenInd++; } return(t == to); }
private static void attachEditorComponents(Entity entity, Main main, bool directional) { Transform transform = entity.Get <Transform>(); Components.Joint joint = entity.Get <Components.Joint>(); EntityConnectable.AttachEditorComponents(entity, "Parent", joint.Parent); if (directional) { ModelAlpha model = new ModelAlpha(); model.Filename.Value = "AlphaModels\\cone"; model.Serialize = false; model.Add(new Binding <bool>(model.Enabled, Editor.EditorModelsVisible)); entity.Add("DirectionModel", model); Transform mapTransform = entity.Get <Transform>("MapTransform"); model.Add(new Binding <Matrix>(model.Transform, delegate() { Matrix m = Matrix.Identity; m.Translation = transform.Position; if (joint.Direction == Direction.None) { m.Forward = m.Right = m.Up = Vector3.Zero; } else { Vector3 normal = Vector3.TransformNormal(joint.Direction.Value.GetVector(), mapTransform.Matrix); m.Forward = -normal; if (normal.Equals(Vector3.Up)) { m.Right = Vector3.Left; } else if (normal.Equals(Vector3.Down)) { m.Right = Vector3.Right; } else { m.Right = Vector3.Normalize(Vector3.Cross(normal, Vector3.Down)); } m.Up = -Vector3.Cross(normal, m.Left); } return(m); }, transform.Matrix, mapTransform.Matrix, joint.Direction)); } }
public override void Bind(Entity entity, Main main, bool creating = false) { Slider slider = entity.GetOrCreate <Slider>("Slider"); JointFactory.Bind(entity, main, slider.CreateJoint, false, creating); Components.Joint joint = entity.GetOrCreate <Components.Joint>("Joint"); slider.Add(new Binding <Direction>(slider.Direction, joint.Direction)); DynamicVoxel voxel = entity.Get <DynamicVoxel>(); voxel.KineticFriction.Value = voxel.StaticFriction.Value = 0; AkGameObjectTracker.Attach(entity, voxel.Transform); SoundKiller.Add(entity, AK.EVENTS.STOP_ALL_OBJECT); if (main.EditorEnabled) { entity.Add(new Binding <Matrix>(entity.GetOrCreate <SliderCommon>("SliderCommon").OriginalTransform, voxel.Transform)); } entity.Add("Forward", slider.Forward); entity.Add("Backward", slider.Backward); entity.Add("OnHitMax", slider.OnHitMax); entity.Add("OnHitMin", slider.OnHitMin); entity.Add("MovementLoop", slider.MovementLoop, new PropertyEntry.EditorData { Options = WwisePicker.Get(main) }); entity.Add("MovementStop", slider.MovementStop, new PropertyEntry.EditorData { Options = WwisePicker.Get(main) }); entity.Add("Direction", joint.Direction); entity.Add("Minimum", slider.Minimum); entity.Add("Maximum", slider.Maximum); entity.Add("Locked", slider.Locked); entity.Add("Speed", slider.Speed); entity.Add("Goal", slider.Goal); entity.Add("Servo", slider.Servo); entity.Add("StartAtMinimum", slider.StartAtMinimum); entity.Add("MaxForce", slider.MaxForce); entity.Add("UVRotation", voxel.UVRotation); entity.Add("UVOffset", voxel.UVOffset); entity.Add("CannotSuspendByDistance", voxel.CannotSuspendByDistance); }
public static void ScheduleReupdate(Components.Joint jc) { for (int i = 0; i < SubCircuits.Count; i++) { for (int j = 0; j < SubCircuits[i].joints.Count; j++) { if (jc == SubCircuits[i].joints[j]) { for (int k = 0; k < reUpdateList.Count; k++) { if (reUpdateList[k] == SubCircuits[i]) { return; } } reUpdateList.Add(SubCircuits[i]); SubCircuits[i].Recalculate = true; return; } } } }
public override void Bind(Entity entity, Main main, bool creating = false) { Slider slider = entity.GetOrCreate <Slider>("Slider"); JointFactory.Bind(entity, main, slider.CreateJoint, false, creating); Components.Joint joint = entity.GetOrCreate <Components.Joint>("Joint"); slider.Add(new Binding <Direction>(slider.Direction, joint.Direction)); DynamicVoxel voxel = entity.Get <DynamicVoxel>(); voxel.KineticFriction.Value = voxel.StaticFriction.Value = 0; if (main.EditorEnabled) { entity.Add(new Binding <Matrix>(entity.GetOrCreate <SliderCommon>("SliderCommon").OriginalTransform, voxel.Transform)); } entity.Add("Forward", slider.Forward); entity.Add("Backward", slider.Backward); entity.Add("OnHitMax", slider.OnHitMax); entity.Add("OnHitMin", slider.OnHitMin); entity.Add("Direction", joint.Direction); entity.Add("Minimum", slider.Minimum); entity.Add("Maximum", slider.Maximum); entity.Add("Locked", slider.Locked); entity.Add("Speed", slider.Speed); entity.Add("Goal", slider.Goal); entity.Add("Servo", slider.Servo); entity.Add("StartAtMinimum", slider.StartAtMinimum); entity.Add("MaxForce", slider.MaxForce); entity.Add("UVRotation", voxel.UVRotation); entity.Add("UVOffset", voxel.UVOffset); entity.Add("CannotSuspendByDistance", voxel.CannotSuspendByDistance); }
public override void Bind(Entity entity, Main main, bool creating = false) { Components.Joint joint = entity.GetOrCreate <Components.Joint>("Joint"); Spinner spinner = entity.GetOrCreate <Spinner>("Spinner"); spinner.Add(new Binding <Direction>(spinner.Direction, joint.Direction)); JointFactory.Bind(entity, main, spinner.CreateJoint, true, creating); DynamicVoxel voxel = entity.Get <DynamicVoxel>(); voxel.KineticFriction.Value = voxel.StaticFriction.Value = 0; if (main.EditorEnabled) { spinner.Add(new Binding <Quaternion, Matrix>(spinner.OriginalRotation, x => Quaternion.CreateFromRotationMatrix(x), voxel.Transform)); } entity.Add("Forward", spinner.Forward); entity.Add("Backward", spinner.Backward); entity.Add("HitMax", spinner.HitMax); entity.Add("HitMin", spinner.HitMin); entity.Add("MovementLoop", spinner.MovementLoop, new PropertyEntry.EditorData { Options = WwisePicker.Get(main) }); entity.Add("MovementStop", spinner.MovementStop, new PropertyEntry.EditorData { Options = WwisePicker.Get(main) }); entity.Add("Direction", joint.Direction); entity.Add("Minimum", spinner.Minimum); entity.Add("Maximum", spinner.Maximum); entity.Add("Locked", spinner.Locked); entity.Add("Speed", spinner.Speed); entity.Add("Goal", spinner.Goal); entity.Add("Servo", spinner.Servo); entity.Add("CannotSuspendByDistance", entity.Get <DynamicVoxel>().CannotSuspendByDistance); }
public override void Bind(Entity entity, Main main, bool creating = false) { Bouncer bouncer = entity.GetOrCreate <Bouncer>("Bouncer"); JointFactory.Bind(entity, main, bouncer.CreateJoint, false, creating, false); Components.Joint joint = entity.GetOrCreate <Components.Joint>("Joint"); bouncer.Add(new Binding <Entity.Handle>(bouncer.Parent, joint.Parent)); bouncer.Add(new Binding <Voxel.Coord>(bouncer.Coord, joint.Coord)); DynamicVoxel voxel = entity.Get <DynamicVoxel>(); voxel.KineticFriction.Value = voxel.StaticFriction.Value = 0; bouncer.Add(new CommandBinding(voxel.PhysicsUpdated, delegate() { bouncer.PhysicsUpdated.Execute(voxel.PhysicsEntity.Mass, voxel.PhysicsEntity.Volume); })); entity.Add("UVRotation", voxel.UVRotation); entity.Add("UVOffset", voxel.UVOffset); entity.Add("CannotSuspendByDistance", voxel.CannotSuspendByDistance); }
public static void Bind(Entity entity, Main main, Func <BEPUphysics.Entities.Entity, BEPUphysics.Entities.Entity, Vector3, Vector3, Vector3, ISpaceObject> createJoint, bool allowRotation, bool creating = false, bool directional = true) { Transform mapTransform = entity.GetOrCreate <Transform>("MapTransform"); mapTransform.Selectable.Value = false; Transform transform = entity.GetOrCreate <Transform>("Transform"); Factory.Get <DynamicVoxelFactory>().InternalBind(entity, main, creating, mapTransform); DynamicVoxel map = entity.Get <DynamicVoxel>(); Components.Joint jointData = entity.GetOrCreate <Components.Joint>("Joint"); Action refreshMapTransform = delegate() { Entity parent = jointData.Parent.Value.Target; if (parent != null && parent.Active) { Voxel staticMap = parent.Get <Voxel>(); jointData.Coord.Value = staticMap.GetCoordinate(transform.Matrix.Value.Translation); mapTransform.Position.Value = staticMap.GetAbsolutePosition(staticMap.GetRelativePosition(jointData.Coord) - new Vector3(0.5f) + staticMap.Offset + map.Offset.Value); if (allowRotation) { if (main.EditorEnabled) { mapTransform.Quaternion.Value = transform.Quaternion; } } else { Matrix parentOrientation = staticMap.Transform; parentOrientation.Translation = Vector3.Zero; mapTransform.Quaternion.Value = Quaternion.CreateFromRotationMatrix(parentOrientation); } } else { mapTransform.Matrix.Value = transform.Matrix; } }; if (main.EditorEnabled) { entity.Add(new NotifyBinding(refreshMapTransform, transform.Matrix, transform.Quaternion, map.Offset, jointData.Parent)); } ISpaceObject joint = null; CommandBinding jointDeleteBinding = null, parentPhysicsUpdateBinding = null; Action updateJoint = null; Action rebuildJoint = null; rebuildJoint = delegate() { if (jointDeleteBinding != null) { entity.Remove(jointDeleteBinding); } jointDeleteBinding = null; if (parentPhysicsUpdateBinding != null) { entity.Remove(parentPhysicsUpdateBinding); } parentPhysicsUpdateBinding = null; updateJoint(); }; updateJoint = delegate() { if (joint != null) { if (joint.Space != null) { main.Space.Remove(joint); } joint = null; } Entity parent = jointData.Parent.Value.Target; if (main.EditorEnabled) { refreshMapTransform(); } else if (parent != null && parent.Active) { Voxel parentStaticMap = parent.Get <Voxel>(); //map.PhysicsEntity.Position = mapTransform.Position; if (!allowRotation) { map.PhysicsEntity.Orientation = mapTransform.Quaternion; } if (jointData.Direction != Direction.None) { Vector3 relativeLineAnchor = parentStaticMap.GetRelativePosition(jointData.Coord) - new Vector3(0.5f) + parentStaticMap.Offset + map.Offset; Vector3 lineAnchor = parentStaticMap.GetAbsolutePosition(relativeLineAnchor); DynamicVoxel parentDynamicMap = parent.Get <DynamicVoxel>(); joint = createJoint(map.PhysicsEntity, parentDynamicMap == null ? null : parentDynamicMap.PhysicsEntity, lineAnchor, parentStaticMap.GetAbsoluteVector(jointData.Direction.Value.GetVector()), parentStaticMap.GetAbsolutePosition(jointData.Coord)); main.Space.Add(joint); map.PhysicsEntity.ActivityInformation.Activate(); if (parentDynamicMap != null && parentPhysicsUpdateBinding == null) { parentPhysicsUpdateBinding = new CommandBinding(parentDynamicMap.PhysicsUpdated, updateJoint); entity.Add(parentPhysicsUpdateBinding); } if (jointDeleteBinding == null) { jointDeleteBinding = new CommandBinding(parent.Delete, delegate() { jointData.Parent.Value = null; }); entity.Add(jointDeleteBinding); } } } }; entity.Add(new CommandBinding(map.PhysicsUpdated, updateJoint)); entity.Add(new NotifyBinding(rebuildJoint, jointData.Parent)); entity.Add(new CommandBinding(entity.Delete, delegate() { if (joint != null && joint.Space != null) { main.Space.Remove(joint); joint = null; } })); entity.Add(new CommandBinding(map.OnSuspended, delegate() { if (joint != null && joint.Space != null) { main.Space.Remove(joint); } })); entity.Add(new CommandBinding(map.OnResumed, delegate() { if (joint != null && joint.Space == null) { main.Space.Add(joint); } })); entity.Add(new PostInitialization { rebuildJoint }); if (main.EditorEnabled) { JointFactory.attachEditorComponents(entity, main, directional); } }
public static void onButtonUp(InputEngine.MouseArgs e) { if (Graphics.GUI.Scene.PlacableAreasCreator.create) { Graphics.GUI.Scene.PlacableAreasCreator.create = false; int x2 = e.curState.X; int y2 = e.curState.Y; GridHelper.GridCoords(ref x2, ref y2); isPlacableAreaPending = false; PlacableAreasManager.Add(new Rectangle((int)pendingWireP1.X, (int)pendingWireP1.Y, (int)(x2 - pendingWireP1.X), (int)(y2 - pendingWireP1.Y))); return; } if (resizeComponent != null) { resizeComponent.OnResizeFinished(resizeType); resizeComponent = null; resizeType = Direction.None; return; } if (isDragDrop) { isDragDrop = false; DragDropComponent = null; return; } if (isLine) { int x2 = e.curState.X; int y2 = e.curState.Y; PlacableAreasManager.MakePlacable(ref x2, ref y2); GridHelper.GridCoords(ref x2, ref y2); if (pendingWireP1.X == x2 && pendingWireP1.Y == y2) { isLine = false; pendingWireP1 = new Vector2(); return; } Components.Joint tj1 = HasJointAtCoord((int)pendingWireP1.X, (int)pendingWireP1.Y), tj2 = HasJointAtCoordForWire(x2, y2); var a1 = Components.ComponentsManager.VisibilityMap.GetAStarValue((int)pendingWireP1.X + 2, (int)pendingWireP1.Y + 2); var a2 = tj2 == null ? Components.ComponentsManager.VisibilityMap.GetAStarValue((int)x2 + 2, (int)y2 + 2) : 0; if (tj2 == null) { tj2 = GetJointForCoordIfCan(x2, y2); if (tj2 == null) { isLine = false; pendingWireP1 = new Vector2(); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); return; } } if ((pendingWireP1.X != tj2.Graphics.Position.X || pendingWireP1.Y != tj2.Graphics.Position.Y) && !Components.Graphics.WireGraphics.CanFindPath(tj1, tj2, (int)pendingWireP1.X + 4, (int)pendingWireP1.Y + 4, (int)pendingWireP2.X + 4, (int)pendingWireP2.Y + 4)) { isLine = false; pendingWireP1 = new Vector2(); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); return; } if (pendingWireP1.X != tj2.Graphics.Position.X || pendingWireP1.Y != tj2.Graphics.Position.Y) { MicroWorld.Logics.ChangeHistory.Push(); Statistics.ElementsPlaced++; j1 = GetJointForCoord(pendingWireP1); Components.Joint j2 = GetJointForCoord((int)tj2.Graphics.Position.X, (int)tj2.Graphics.Position.Y); //w Components.Wire w = new Components.Wire(j1, j2); w.Initialize(); Graphics.GUI.GUIEngine.s_componentSelector.DecreaseComponentAvilability("Wire"); Components.ComponentsManager.Add(w); w.OnPlaced(); if (a1 == Components.VisibilityMap.WIRE) { var a = GetWiresForCoord((int)pendingWireP1.X, (int)pendingWireP1.Y); for (int i = 0; i < a.Count; i++) { if (a[i] != w && a[i].J1 != j1 && a[i].J2 != j1) SplitWire(a[i], j1); } } if (a2 == Components.VisibilityMap.WIRE) { var a = GetWiresForCoord((int)tj2.Graphics.Position.X, (int)tj2.Graphics.Position.Y); for (int i = 0; i < a.Count; i++) { if (a[i] != w && a[i].J1 != j2 && a[i].J2 != j2) SplitWire(a[i], j2); } } CircuitManager.ReCreate(); } isLine = false; return; } if (isComponentDnD) { int x2 = e.curState.X; int y2 = e.curState.Y; PlacableAreasManager.MakePlacable(ref x2, ref y2); GridHelper.GridCoords(ref x2, ref y2); if (pendingWireP1.X == x2 && pendingWireP1.Y == y2) { isComponentDnD = false; pendingWireP1 = new Vector2(); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); DnDComponent = null; return; } if (!DnDComponent.CanEnd((int)pendingWireP1.X, (int)pendingWireP1.Y, x2, y2)) { isComponentDnD = false; pendingWireP1 = new Vector2(); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); DnDComponent = null; return; } MicroWorld.Logics.ChangeHistory.Push(); DnDComponent.Place((int)pendingWireP1.X, (int)pendingWireP1.Y, x2, y2); MicroWorld.Graphics.GUI.GUIEngine.s_componentSelector.DecreaseComponentAvilability((DnDComponent as Components.Component).Graphics.GetCSToolTip()); CircuitManager.ReCreate(); isComponentDnD = false; pendingWireP1 = new Vector2(); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); DnDComponent = null; return; } if (e.button == 0 && InputEngine.LeftMouseButtonDownPos != null && MicroWorld.Graphics.GUI.GUIEngine.s_componentSelector.SelectedComponent.IsIn( (int)InputEngine.LeftMouseButtonDownPos.Value.X, (int)InputEngine.LeftMouseButtonDownPos.Value.Y)) { TryPlaceComponent(ref e); } }