// HACK: The reduction provider will deprecate this at some point void SynchronizeStateTo(Agent agent) { // Send the parcel overlay server.Parcels.SendParcelOverlay(agent); // Send object updates for objects and avatars sceneObjects.ForEach(delegate(SimulationObject obj) { ObjectUpdatePacket update = SimulationObject.BuildFullUpdate(obj.Prim, obj.Prim.RegionHandle, 0, obj.Prim.Flags); server.UDP.SendPacket(agent.AgentID, update, PacketCategory.State); }); // Send appearances for all avatars lock (server.Agents) { foreach (Agent otherAgent in server.Agents.Values) { if (otherAgent != agent) { // Send appearances for this avatar AvatarAppearancePacket appearance = BuildAppearancePacket(otherAgent); server.UDP.SendPacket(agent.AgentID, appearance, PacketCategory.State); } } } // Send terrain data SendLayerData(agent); }
// Determines the items that should be displayed in the context menu private void SetMenuItems(SimulationObject value) { contextMenuStrip.Items.Clear(); // Cannon /* * if (value is Cannon) * { * contextMenuStrip.Items.AddRange(new ToolStripItem[] { * fireCannonToolStripMenuItem, * toolStripSeparator2 }); * } */ // Stopwatch if (value is Stopwatch) { contextMenuStrip.Items.AddRange(new ToolStripItem[] { addStartTriggerToolStripMenuItem, addStopTriggerToolStripMenuItem, toolStripSeparator3 }); } // Simulation Object contextMenuStrip.Items.AddRange(new ToolStripItem[] { cutToolStripMenuItem, copyToolStripMenuItem, pasteToolStripMenuItem, toolStripSeparator1, deleteToolStripMenuItem }); }
void BroadcastObjectUpdate(SimulationObject obj) { ObjectUpdatePacket update = SimulationObject.BuildFullUpdate(obj.Prim, server.RegionHandle, 0, obj.Prim.Flags); server.UDP.BroadcastPacket(update, PacketCategory.State); }
public void AvatarAppearance(object sender, Agent agent, Primitive.TextureEntry textures, byte[] visualParams) { if (OnAvatarAppearance != null) { OnAvatarAppearance(sender, agent, textures, visualParams); } // Update the avatar agent.Avatar.Textures = textures; if (visualParams != null) { agent.VisualParams = visualParams; } // Broadcast the object update ObjectUpdatePacket update = SimulationObject.BuildFullUpdate(agent.Avatar, server.RegionHandle, agent.State, agent.Flags); server.UDP.BroadcastPacket(update, PacketCategory.State); // Send the appearance packet to all other clients AvatarAppearancePacket appearance = BuildAppearancePacket(agent); lock (server.Agents) { foreach (Agent recipient in server.Agents.Values) { if (recipient != agent) { server.UDP.SendPacket(recipient.AgentID, appearance, PacketCategory.State); } } } }
public override void ApplyMove(SimulationBox box, SimulationObject mcObject) { var deltaX = JobEngine.Rand.NextDouble() * 2 * MaxDistance - MaxDistance; var deltaY = JobEngine.Rand.NextDouble() * 2 * MaxDistance - MaxDistance; mcObject.X += deltaX; mcObject.Y += deltaY; if (mcObject.X > box.XLength) { mcObject.X -= box.XLength; } if (mcObject.Y > box.YLength) { mcObject.Y -= box.YLength; } if (mcObject.X < 0) { mcObject.X += box.XLength; } if (mcObject.Y < 0) { mcObject.Y += box.YLength; } }
public override void SetValues(SimulationObject target) { var data = _siteAndItem(); var site = data.Item1; var item = data.Item2; target.Variables.Add("Site", site.Id); if (!string.IsNullOrEmpty(site.Host)) { target.Variables.Add("Host", "https://" + site.Host.Split('|')[0]); } var lang = target.GetVariable <string>("Language"); if (!string.IsNullOrEmpty(lang) && item.Language != lang) { item = _itemInfo.GetItemInfo(item.Id.ToString(), lang); } var url = item.SiteUrls[site.Id].Url; if (url.Contains("://")) { url = new Uri(url).PathAndQuery; } var campaignId = target.GetVariable <string>("Campaign"); if (!string.IsNullOrEmpty(campaignId)) { url += (url.Contains("?") ? "&" : "?") + "sc_camp=" + campaignId; } target.Variables.Add("LandingPage", url); }
protected override void RunInternal() { double previousEnergy = Box.CalculateEnergy(); for (int i = 0; i < Cycles; i++) { _currentCycle = i; for (int j = 0; j < MovesPerCycle; j++) { SimulationObject mcObject = Box.GetRandomObject(); SimulationMove moveType = mcObject.GetRandomMove(); moveType.ApplyMove(Box, mcObject); } var energy = Box.CalculateEnergy(); if (IsMoveAcceptable(previousEnergy, energy)) { previousEnergy = energy; Box.AcceptAllMoves(); OnChanged(); } else { Box.RejectAllMoves(); } OnProgress(); } }
public override void Run() { double currentEnergy = Box.CalculateEnergy(); for (int i = 0; i < Cycles; i++) { for (int j = 0; j < MovesPerCycle; j++) { SimulationObject mcObject = Box.GetRandomObject(); SimulationMove move = mcObject.GetRandomMove(); move.ApplyMove(Box, mcObject); } double newEnergy = Box.CalculateEnergy(); if (IsMoveAcceptable(currentEnergy, newEnergy)) { Box.AcceptAllMoves(); currentEnergy = newEnergy; Console.WriteLine(currentEnergy); } else { Box.RejectAllMoves(); } } }
public static void HierarchyPositionTest() { Console.WriteLine(MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); Scene scene = new Scene(); SimulationObject so0 = scene.AddObject(); so0.Name = "0"; Transform transform0 = so0.GetComponent <Transform>(); SimulationObject so1 = scene.AddObject(); so1.Name = "1"; Transform transform1 = so1.GetComponent <Transform>(); transform0.LocalPosition = new Vector3(0, 10, 0); transform1.LocalPosition = new Vector3(0, 5, 0); transform1.SetParent(transform0); Console.WriteLine(so0.Name + "\n" + transform0.LocalPosition + " " + transform0.Position); Console.WriteLine(so1.Name + "\n" + transform1.LocalPosition + " " + transform1.Position); transform1.Position = new Vector3(0, 20, 0); Console.WriteLine(so0.Name + "\n" + transform0.LocalPosition + " " + transform0.Position); Console.WriteLine(so1.Name + "\n" + transform1.LocalPosition + " " + transform1.Position); }
public override void SetValues(SimulationObject target) { var city = _getCity(); if (city == null) { return; } target.Variables["Country"] = city.CountryCode; target.Variables["Continent"] = city.Country.Continent; target.Variables["Region"] = city.RegionCode; target.Variables["City"] = city.AsciiName; target.Variables["Tld"] = city.Country.TopLevelDomain; target.Variables["DomainPostfix"] = city.Country.DomainPostFix; target.Variables["Latitude"] = city.Latitude; target.Variables["Longitude"] = city.Longitude; target.Variables["Currency"] = city.Country.CurrencyCode; target.Variables["TimeZone"] = city.TimeZoneInfo.StandardName; if (!AdjustToTimeZone) { return; } target.Start = DateTime.SpecifyKind(target.Start, DateTimeKind.Utc); target.End = DateTime.SpecifyKind(target.End, DateTimeKind.Utc); target.Start = TimeZoneInfo.ConvertTimeFromUtc(target.Start, city.TimeZoneInfo); target.End = TimeZoneInfo.ConvertTimeFromUtc(target.End, city.TimeZoneInfo); }
public static void ScaleTest() { Console.WriteLine(MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); Scene scene = new Scene(); SimulationObject so0 = scene.AddObject(); so0.Name = "0"; Transform transform0 = so0.GetComponent <Transform>(); SimulationObject so1 = scene.AddObject(); so1.Name = "1"; Transform transform1 = so1.GetComponent <Transform>(); transform1.SetParent(transform0); transform1.LocalScale = new Vector3(4, 2, 1); Console.WriteLine(so1.Name + " " + transform1.LocalScale + " " + transform1.LossyScale); transform0.LocalScale = new Vector3(1, 2, 4); Console.WriteLine(so0.Name + " " + transform0.LocalScale + " " + transform0.LossyScale); Console.WriteLine(so1.Name + " " + transform1.LocalScale + " " + transform1.LossyScale); ETE.Engine.Object.DestroyImmediate(so0); }
private void createModel() { loadAllFiles(); // Create Camera { //Create Camera Components SimulationObject cameraObject = model.AddObject(); cameraObject.Name = "cameraObj"; Transform transform_camera = cameraObject.GetComponent <Transform>(); transform_camera.Position = new Vector3(0.0f, 40.0f, 250.0f); ETE.Render.Component.Camera comp_camera = cameraObject.AddComponent <ETE.Render.Component.Camera>(); comp_camera.TargetDisplay = 0; comp_camera.BackGround_Color = new Vector4(0.2f, 0.2f, 0.4f, 1.0f); comp_camera.CameraOrder = 0; comp_camera.Near = 2.0f; comp_camera.Far = 10000.0f; comp_camera.FOV = 35.0f; comp_camera.Aspect_Ratio = 1.7021f; } createGTModel(); }
public static void RotationTest() { Console.WriteLine(MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); Scene scene = new Scene(); SimulationObject so0 = scene.AddObject(); so0.Name = "0"; Transform transform0 = so0.GetComponent <Transform>(); SimulationObject so1 = scene.AddObject(); so1.Name = "1"; Transform transform1 = so1.GetComponent <Transform>(); transform1.SetParent(transform0); transform1.LocalRotation = Quaternion.Euler(45, 30, 15); transform0.LocalRotation = Quaternion.Euler(15, 30, 45); Console.WriteLine(so0.Name + " " + transform0.LocalRotation + " " + transform0.LocalEulerAngles); Console.WriteLine(so0.Name + " " + transform0.Rotation + " " + transform0.EulerAngles); Console.WriteLine(so1.Name + " " + transform1.LocalRotation + " " + transform1.LocalEulerAngles); Console.WriteLine(so1.Name + " " + transform1.Rotation + " " + transform1.EulerAngles); }
public static void ApplicationRun() { Console.WriteLine(MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); Console.WriteLine("시뮬레이션 종료 : Ctrl + Q"); Console.WriteLine("예외 처리 테스트 : Ctrl + X"); Console.WriteLine("컴포넌트 활성/비활성: E"); Scene scene = new Scene(); SimulationObject simObj = null; LifecycleUserComponent lcCom = null; for (int i = 0; i < 2; i++) { simObj = scene.AddObject(); simObj.Name = "Obj" + i.ToString(); lcCom = simObj.AddComponent <LifecycleUserComponent>(); } AsyncScheduler sc = new AsyncScheduler(); sc.AddRepetitionTask(new Action(() => { if (true == ConsoleKeyboard.IsKeyDown(ConsoleKey.X) && true == ConsoleKeyboard.IsKeyDown(ConsoleModifiers.Control)) { Console.WriteLine("예외(Exception) 처리를 테스트합니다."); Console.WriteLine("{0:H}", 0); } if (true == ConsoleKeyboard.IsKeyDown(ConsoleKey.E)) { Console.WriteLine("컴포넌트를 활성/비활성화합니다."); Application.Current.Scheduler.Run(() => { lcCom.Enabled = !lcCom.Enabled; }); } })); app = new Application(); app.UnhandledException += App_UnhandledExceptionHandler; app.Scheduler = sc; scene.AddSubSystem(new UserSubsystem()); app.LoadScene(scene); app.Start(); bool isRun = true; while (true == isRun) { if (true == ConsoleKeyboard.IsKeyDown(ConsoleKey.Q) && true == ConsoleKeyboard.IsKeyDown(ConsoleModifiers.Control)) { Console.WriteLine("시뮬레이션 엔진을 종료합니다."); isRun = false; } Thread.Sleep(16); } app.Stop(); }
public BattleSimulationArmy(SimulationObject simulationObject, BattleContender contender) : base(simulationObject) { if (simulationObject == null) { throw new ArgumentNullException("simulationObject"); } if (contender == null) { throw new ArgumentNullException("contender"); } this.contender = contender; if (contender.DefaultTargetingStrategy != null) { StaticString armyBattleTargetingStrategy = contender.DefaultTargetingStrategy; this.ArmyBattleTargetingStrategy = armyBattleTargetingStrategy; this.ArmyBattleTargetingWantedStrategy = armyBattleTargetingStrategy; } else { StaticString armyBattleTargetingStrategy = BattleEncounter.GetDefaultStrategy(); this.ArmyBattleTargetingWantedStrategy = armyBattleTargetingStrategy; this.ArmyBattleTargetingStrategy = armyBattleTargetingStrategy; } this.WaitingArmyActions = new List <BattleArmyAction>(); }
void ObjectDuplicateHandler(Packet packet, Agent agent) { ObjectDuplicatePacket duplicate = (ObjectDuplicatePacket)packet; PrimFlags flags = (PrimFlags)duplicate.SharedData.DuplicateFlags; Vector3 offset = duplicate.SharedData.Offset; for (int i = 0; i < duplicate.ObjectData.Length; i++) { uint dupeID = duplicate.ObjectData[i].ObjectLocalID; SimulationObject obj; if (server.Scene.TryGetObject(dupeID, out obj)) { SimulationObject newObj = new SimulationObject(obj); newObj.Prim.Position += offset; newObj.Prim.ID = UUID.Random(); server.Scene.ObjectAdd(this, agent, newObj, flags); } else { Logger.Log("ObjectDuplicate sent for missing object " + dupeID, Helpers.LogLevel.Warning); KillObjectPacket kill = new KillObjectPacket(); kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); kill.ObjectData[0].ID = dupeID; server.UDP.SendPacket(agent.AgentID, kill, PacketCategory.State); } } }
//checks if the simulation object in the map is a box private bool isBox(SimulationObject obj) { if (obj.getName().Equals("b")) { return(true); } return(false); }
public static void ObjectAddTest() { Scene s = new Scene(); SimulationObject o = s.AddObject(); Console.WriteLine(o.GetType().Name); Console.WriteLine(o); }
private void DisplayProperty(float indent, SimulationProperty property, SimulationObject context) { int propertyIndex = context.GetPropertyIndex(property.Name); context.DebugInfo.SetPropertyContent(propertyIndex, this.IndentedToggle(indent, context.DebugInfo.DisplayPropertyContent(propertyIndex), "{0} = <color=orange>{1}</color> {2}", new object[] { property.Name, property.Value, (!context.IsPropertyDirty(property.Name)) ? string.Empty : "<size=11><color=red>(Dirty)</color></size>" })); if (context.DebugInfo.DisplayPropertyContent(propertyIndex)) { indent += 20f; UnityEngine.GUILayout.BeginVertical(new GUILayoutOption[0]); this.IndentedLabel(indent, "<size=11><color=grey>Index: <b>{0}</b></color></size>", new object[] { context.GetPropertyIndex(property.Name) }); this.IndentedLabel(indent, "BaseValue:", " <b>{0}</b>", new object[] { property.BaseValue }); this.IndentedLabel(indent, "Value:", " <b>{0}</b>", new object[] { property.Value }); if (property.InternalPropertyDescriptor.Composition != SimulationPropertyComposition.None) { this.IndentedLabel(indent, "Composition:", " <b>{0}</b>", new object[] { property.PropertyDescriptor.Composition.ToString() }); } string text = (property.PropertyDescriptor.MinValue != float.MinValue) ? ("[" + property.PropertyDescriptor.MinValue.ToString("F")) : "]-inf"; string text2 = (property.PropertyDescriptor.MaxValue != float.MaxValue) ? (property.PropertyDescriptor.MaxValue.ToString("F") + "]") : "inf["; this.IndentedLabel(indent, "Range:", " <b>{0},{1}</b>", new object[] { text, text2 }); UnityEngine.GUILayout.EndVertical(); Diagnostics.Assert(property.ModifierProviders != null); if (property.ModifierProviders.Count > 0) { context.DebugInfo.SetPropertyModifier(propertyIndex, this.IndentedToggle(indent, context.DebugInfo.DisplayPropertyModifier(propertyIndex), "<b>Modifiers</b>", new object[0])); if (context.DebugInfo.DisplayPropertyModifier(propertyIndex)) { indent += 20f; for (int i = 0; i < property.ModifierProviders.Count; i++) { this.DisplayModifier(indent, property.ModifierProviders.Data[i], context); } indent -= 20f; } } indent -= 20f; } }
public static void ObjectDestroyTest() { Scene s = new Scene(); SimulationObject o = s.AddObject(); ETE.Engine.Object.DestroyImmediate(o); Console.WriteLine(o.GetType().Name); Console.WriteLine(o); }
public static void RemoveRoot(SimulationObject root) { object syncObject = SimulationObject.SyncObject; lock (syncObject) { SimulationGlobal.Unsafe_RemoveRoot(root); } }
private void GenerateDistrictProxy(int empireIndex, WorldPosition worldPosition, SimulationObject districtProxy) { districtProxy.RemoveAllDescriptors_ModifierForwardType_ChildrenOnly(); if (this.WorldPositionningService != null) { DepartmentOfTheInterior.ApplyDistrictProxyDescriptors(base.Game.Empires[empireIndex], districtProxy, worldPosition, DistrictType.Exploitation, true, false); districtProxy.Refresh(); } }
public static void ComponentAddTest() { Scene s = new Scene(); SimulationObject o = s.AddObject(); LifeCycleComponent c = o.AddComponent <LifeCycleComponent>(); Console.WriteLine(c.GetType().Name); Console.WriteLine(c); }
public override bool Check(SimulationObject simulationObject) { bool flag = this.CheckOnSimulationObject(simulationObject); if (base.Inverted) { flag = !flag; } return(flag); }
public static void ComponentDestroyTest() { Scene s = new Scene(); SimulationObject o = s.AddObject(); LifeCycleComponent c = o.AddComponent <LifeCycleComponent>(); ETE.Engine.Object.DestroyImmediate(c); Console.WriteLine(c.GetType().Name); Console.WriteLine(c); }
public static void HandleCreateSimulationObject(PacketStream P, ref CityClient C) { byte PacketLength = (byte)P.ReadByte(); //Length of the unencrypted data, excluding the header (ID, length, unencrypted length). byte UnencryptedLength = (byte)P.ReadByte(); BinaryFormatter BinFormatter = new BinaryFormatter(); SimulationObject CreatedSimObject = (SimulationObject)BinFormatter.Deserialize(P); //TODO: Add the object to the client's lot's VM... }
void ObjectDelinkHandler(Packet packet, Agent agent) { ObjectDelinkPacket delink = (ObjectDelinkPacket)packet; List <SimulationObject> linkSet = new List <SimulationObject>(); for (int i = 0; i < delink.ObjectData.Length; i++) { SimulationObject obj; if (!server.Scene.TryGetObject(delink.ObjectData[i].ObjectLocalID, out obj)) { //TODO: send an error message return; } else if (obj.Prim.OwnerID != agent.AgentID) { //TODO: send an error message return; } else { linkSet.Add(obj); } } ObjectUpdatePacket update = new ObjectUpdatePacket(); update.RegionData.RegionHandle = server.RegionHandle; update.RegionData.TimeDilation = UInt16.MaxValue; update.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[linkSet.Count]; for (int i = 0; i < linkSet.Count; i++) { update.ObjectData[i] = SimulationObject.BuildUpdateBlock(linkSet[i].Prim, server.RegionHandle, 0, linkSet[i].Prim.Flags); update.ObjectData[i].ParentID = 0; linkSet[i].LinkNumber = 0; //add root prim orientation to child prims if (i > 0) { linkSet[i].Prim.Position = linkSet[0].Prim.Position + Vector3.Transform(linkSet[i].Prim.Position, Matrix4.CreateFromQuaternion(linkSet[0].Prim.Rotation)); linkSet[i].Prim.Rotation *= linkSet[0].Prim.Rotation; } update.ObjectData[i].ObjectData = SimulationObject.BuildObjectData( linkSet[i].Prim.Position, linkSet[i].Prim.Rotation, Vector3.Zero, Vector3.Zero, Vector3.Zero); } server.UDP.BroadcastPacket(update, PacketCategory.State); }
private bool CheckOnSimulationObject(SimulationObject simulationObject) { IGameService service = Services.GetService <IGameService>(); if (service != null) { global::Game game = service.Game as global::Game; if (game != null && game.Empires != null) { global::Empire empire = game.Empires.FirstOrDefault((global::Empire match) => match is MajorEmpire && match.SimulationObject.Name == simulationObject.Name); if (empire != null) { if (empire.IsControlledByAI) { return(true); } if (this.sessionService == null) { this.sessionService = Services.GetService <ISessionService>(); Diagnostics.Assert(this.sessionService != null && this.sessionService.Session != null); } if (this.sessionService.Session.SessionMode == SessionMode.Single) { if (this.achievementService == null) { this.achievementService = Services.GetService <IAchievementService>(); Diagnostics.Assert(this.achievementService != null); } return(this.achievementService.GetAchievement(this.QuestAchievement.ToString())); } if (this.playerRepositoryService == null) { this.playerRepositoryService = service.Game.Services.GetService <IPlayerRepositoryService>(); Diagnostics.Assert(this.playerRepositoryService != null); } Player[] playersByEmpireIndex = this.playerRepositoryService.GetPlayersByEmpireIndex(empire.Index); uint num = 1u << (int)this.QuestAchievement; foreach (Player player in playersByEmpireIndex) { if ((this.sessionService.Session.GetLobbyMemberData <uint>(player.SteamID, "QuestAchievementsCompletion", 0u) & num) == 0u) { return(false); } } if (playersByEmpireIndex.Length != 0) { return(true); } } } } return(false); }
private void MakeSimulator() { MakeDefault(); MakeDefaultSystem(); // Model에 시뮬레이션 오브젝트를 추가하고 컴포넌트를 연결합니다. SimulationObject SimObj = model.AddObject(); SimObj.Name = "Triangle"; SimObj.AddComponent <GLDrawComponent>(); SimObj.AddComponent <TransformBehavior>(); }
/// <summary> /// Sends a packet to create a SimulationObject on ter server. /// Assumes the player is on a lot that he owns. /// </summary> /// <param name="CreatedObject">The SimulationObject to create.</param> public static void SendCreatedSimulationObject(SimulationObject CreatedObject) { //TODO: Change this ID! PacketStream CreateSimulationObjectPacket = new PacketStream(0x11, 0); BinaryFormatter BinFormatter = new BinaryFormatter(); BinFormatter.Serialize(CreateSimulationObjectPacket, CreatedObject); PlayerAccount.Client.Send(FinalizePacket(0x11, new DESCryptoServiceProvider(), CreateSimulationObjectPacket.ToArray())); }
/// <summary> /// Updates the object's screenLine /// </summary> /// <param name="obj"></param> /// <param name="_screenLine">the screen line. null, if no screen line exists</param> /// <returns>returns a screen line if a screenline needs to be created</returns> public static ScreenLine UpdateBeam(this SimulationObject obj, ScreenLine _screenLine, SimulationObject destination, Vector Direction) { if (obj.LastTableObject.RotationDefined) { if (_screenLine == null) { //recreate it _screenLine = new ScreenLine(obj.LastTableObject.Center, Direction * 1000, ScreenLine.EScreenLineElementType.Arrow); return _screenLine; } else { //just modify //If destination is set, let the screen line end.if not:infinite if (destination != null) { _screenLine.Source = obj.LastTableObject.Center; _screenLine.Destination = destination.LastTableObject.Center; } else { _screenLine.Source = obj.LastTableObject.Center; TPoint dest = new TPoint( Convert.ToInt32(obj.LastTableObject.Center.ScreenX + Direction.X * 1000), Convert.ToInt32(obj.LastTableObject.Center.ScreenY + Direction.Y * 1000), TPoint.PointCreationType.screen); _screenLine.Destination = dest; } } } return null; }