public void OnTick(EngineEntity entity) { var movable = entity.Current <IMovable>(); if (!movable.TargetPosition.HasValue) { return; } var transform = entity.Current <ITransform>(); var diff = movable.TargetPosition.Value - transform.Position; var distance = diff.Magnitude; // Detect when arrived at destination if (distance < movable.MoveSpeed * _timeService.Step) { _logger.Info($"Entity `{entity.Id}` has arrived at destination {movable.TargetPosition}"); entity.Modify <IWriteableTransform>().Position = movable.TargetPosition.Value; entity.Modify <IWriteableMovable>().TargetPosition = null; return; } var moveAmount = movable.MoveSpeed * _timeService.Step; entity.Modify <IWriteableTransform>().Position = transform.Position + moveAmount * diff.Normalized; }
public void InitializeEvents(EngineEntity _owner, EngineValueData _data) { for (int i = 0; i < valueEvents.Length; i++) { valueEvents[i].Initialize(_owner, _data); } }
public void EntityCommitsDirtyComponentOnlyWhenDirty() { var mockWEntity = new Mock <IWriteableSimpleComponent>(); var mockEntity = mockWEntity.As <ISimpleComponent>(); var cloneWEntity = new Mock <IWriteableSimpleComponent>(); var cloneEntity = cloneWEntity.As <ISimpleComponent>(); mockEntity.SetupGet(c => c.Type).Returns(typeof(ISimpleComponent)); mockEntity.Setup(c => c.Clone()).Returns(() => cloneEntity.Object); // Setup entity and mark ISimpleComponent as dirty var entity = new EngineEntity(0, new IComponent[] { mockEntity.Object }, Mock.Of <IEventDispatcher>()); // Ensure a commit with the component non-dirty doesn't trigger a copy. entity.Commit(); cloneEntity.Verify(c => c.CopyTo(mockEntity.Object), Times.Never()); // Modify the component to set as dirty entity.Modify <IWriteableSimpleComponent>(); // Trigger an entity commit, which should cause the entity to replicate // changes from `Next` to `Current`. entity.Commit(); cloneEntity.Verify(c => c.CopyTo(mockEntity.Object), Times.Once()); }
public void EntityThrowsOnMultipleModifyCalls() { var entity = new EngineEntity(0, new IComponent[] { new SimpleComponent() }, Mock.Of <IEventDispatcher>()); Should.NotThrow(() => entity.Modify <IWriteableSimpleComponent>()); Should.Throw <ComponentAccessException>(() => entity.Modify <IWriteableSimpleComponent>()); }
public static Object search(Object o) { try { Hashtable param = (Hashtable)o; EngineEntity engine = (EngineEntity)param["engine"]; engine.Status = "处理中"; String searchKey = HttpUtility.UrlEncode((String)param["searchKey"], Encoding.UTF8); IEngine search = engine.Search; Dictionary <String, String> urlMap = new Dictionary <String, String>(); Int32 timeout = Convert.ToInt32(ConfigService.get("parse.request.timeout")) * 1000; String html = String.Empty; Int32 unParseURL = 0; //出错50次算结束,连续5次没抓到邮箱算结束,大于设置最大邮箱数算结束 while (!search.isEndPage(html, engine) && engine.PageCnt <= engine.MaxPageCnt && engine.ErrorCnt < 50 && unParseURL < 5) { String url = search.getPageUrl(html, engine, searchKey); try { html = WebClientUtils.getHTML(url, timeout); if (!String.Empty.Equals(html)) { if (search.addUrl(CommonUtils.getHTMLinkArray(url, html), engine) == 0) { unParseURL++; } else { unParseURL = 0; } } engine.PageCnt = engine.PageCnt + 1; } catch (Exception ex) { engine.ErrorCnt = engine.ErrorCnt + 1; search.error(engine, ex); html = String.Empty; } } engine.Status = "处理结束"; } catch { } return(null); }
public void RegisterPlayerEntity(EngineEntity playerEntity) { if (!playerEntity.HasComponent<IPlayer>()) { throw new ArgumentException("Entity must have an IPlayer component.", nameof(playerEntity)); } _playerEntities.Add(playerEntity); }
public void RegisterPlayerEntity(EngineEntity playerEntity) { if (!playerEntity.HasComponent <IPlayer>()) { throw new ArgumentException("Entity must have an IPlayer component.", nameof(playerEntity)); } _playerEntities.Add(playerEntity); }
public virtual String getPageUrl(String perHTML, EngineEntity entity, String searchKey) { String result = entity.Url; result = result.Replace("${searchKey}", searchKey); result = result.Replace("${pageStart}", Convert.ToString(entity.PageCnt * entity.PageSize)); result = result.Replace("${pageCnt}", Convert.ToString(entity.PageCnt)); return result; }
public void EntityReturnsCorrectComponent() { var entity = new EngineEntity(0, new IComponent[] { new SimpleComponent() }, Mock.Of <IEventDispatcher>()); var c = entity.Current <ISimpleComponent>(); c.ShouldNotBeNull(); c.ShouldBeOfType <SimpleComponent>(); }
public void EntityContainsInitialComponents() { var entity = new EngineEntity(0, new IComponent[] { new SimpleComponent(), new OtherSimpleComponent() }, Mock.Of <IEventDispatcher>()); entity.HasComponent <ISimpleComponent>().ShouldBeTrue(); entity.HasComponent <IOtherSimpleComponent>().ShouldBeTrue(); entity.HasComponent <ISimpleAsyncComponent>().ShouldBeFalse(); }
public void EntityNotifiesPostsComponentChangeEvent() { var mock = new Mock <IEventDispatcher>(); var entity = new EngineEntity(0, new IComponent[] { new SimpleComponent() }, mock.Object); entity.Modify <IWriteableSimpleComponent>(); mock.Verify(poster => poster.Post(It.IsAny <EntityComponentModified>()), Times.AtLeastOnce); }
public override void CreateEngineInstance(bool bCreateChildren) { _engineInstance = new EngineInstanceEntity("CameraPositionEntity", null, this, null, true); base.CreateEngineInstance(bCreateChildren); SetEngineInstanceBaseProperties(); // sets the position etc. EngineEntity.SetVariable("FovX", _fCustomFOV.ToString()); EngineEntity.SetVariable("NearClipDistance", NearClipDistance.ToString()); EngineEntity.SetVariable("FarClipDistance", FarClipDistance.ToString()); }
public EngineEntity CreateEntity(IEnumerable <IComponent> components) { CheckAddEntityGate(); _logger.Info("Creating new entity from components."); var entity = new EngineEntity(_idProvider.Next(), components, _eventDispatcher); InternalAddEntity(entity); return(entity); }
public void EntityCommitsChangesToDirtyComponents() { var entity = new EngineEntity(0, new IComponent[] { new SimpleComponent() }, Mock.Of <IEventDispatcher>()); var initialValue = entity.Current <ISimpleComponent>().Value; entity.Modify <IWriteableSimpleComponent>().Value = 5; entity.Current <ISimpleComponent>().Value.ShouldBe(initialValue); entity.Commit(); entity.Current <ISimpleComponent>().Value.ShouldBe(5); }
public override bool OnExport(SceneExportInfo info) { EngineEntity.SetVariable("FovX", _fCustomFOV.ToString()); EngineEntity.SetVariable("NearClipDistance", NearClipDistance.ToString()); EngineEntity.SetVariable("FarClipDistance", FarClipDistance.ToString()); EngineEntity.SetVariable("m_fTimeOfDay", _bApplyTimeOfDay ? _fCustomTimeOfDay.ToString() : "-1.0"); // on the runtime side a negative value disables it bool bResult = base.OnExport(info); return(bResult); }
public virtual Int32 addUrl(String[] linkArray, EngineEntity entity) { Int32 addCnt = 0; foreach (String link in linkArray) { if (link.Length < 2000 && link.IndexOf(entity.EngineName) == -1) { addCnt += entity.addUrl(link) ? 1 : 0; } } return addCnt; }
public void DoValueDelta(EngineEntity _entity) { int id = valueSelection.valueData.ID; var val = _entity.EngineValueContainer.GetEngineValue(id); if (engineValueType == EngineValueType.Reset) { _entity.ResetValueToDefault(id); } else if (engineValueType == EngineValueType.Recharge) { val.Recharge(rechargeSpeed); } else if (engineValueType == EngineValueType.Overheat) { val.OverHeat(overheatTime); } else { var delta = valueDelta; if (deltaType == DeltaType.FromData) { if (engineValueData) { delta = engineValueData.FloatValue; } } if (engineValueType == EngineValueType.Add) { if (valueSelection.valueData.GetType() == typeof(EngineFloatData)) { _entity.AddEngineFloatValue(id, delta); } else if (valueSelection.valueData.GetType() == typeof(EngineIntData)) { _entity.AddEngineIntValue(id, (int)delta); } } else if (engineValueType == EngineValueType.Subtract) { if (valueSelection.valueData.GetType() == typeof(EngineFloatData)) { _entity.SubtractEngineFloatValue(id, Mathf.Abs(delta)); } else if (valueSelection.valueData.GetType() == typeof(EngineIntData)) { _entity.SubtractEngineIntValue(id, (int)Mathf.Abs(delta)); } } } }
public override String getPageUrl(String perHTML, EngineEntity entity, String searchKey) { String result = entity.Url; result = result.Replace("${searchKey}", searchKey); if (entity.PageCnt > 0) { result += "&page=" + Convert.ToString(entity.PageCnt); } return(result); }
public void RemovesEntityFromSystem() { var oneComponentSystem = new OneComponentSystem(); var manager = new RuntimeSystemManager(new ISystem[] { oneComponentSystem }, Mock.Of <ILogger>()); var oneComponentEntity = new EngineEntity(0, new IComponent[] { new SimpleComponent() }, Mock.Of <IEventDispatcher>()); manager.AddEntities(new[] { oneComponentEntity }); manager.RemoveEntities(new[] { oneComponentEntity }); manager.Systems.Single().Entities.ShouldNotContain(oneComponentEntity); }
public void RemovesEntityFromSystem() { var oneComponentSystem = new OneComponentSystem(); var manager = new RuntimeSystemManager(new ISystem[] {oneComponentSystem}, Mock.Of<ILogger>()); var oneComponentEntity = new EngineEntity(0, new IComponent[] {new SimpleComponent()}, Mock.Of<IEventDispatcher>()); manager.AddEntities(new[] {oneComponentEntity}); manager.RemoveEntities(new[] {oneComponentEntity}); manager.Systems.Single().Entities.ShouldNotContain(oneComponentEntity); }
// GET: EngineEntities/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var viewModel = new VMEngines(); EngineEntity engineEntity = _engineRepository.GetWhere(x => x.Id == id.Value).SingleOrDefault(); viewModel.EngineEntity = engineEntity; if (engineEntity == null) { return(HttpNotFound()); } return(View(viewModel)); }
public override void error(EngineEntity entity, Exception ex) { try { if (ex.GetType() == typeof(WebException)) { WebException exception = (WebException)ex; //exception.Response String html = WebClientUtils.getResponseHTML((HttpWebResponse)exception.Response); //得到image路径 String imagepath = String.Empty; foreach (String url in CommonUtils.getHTMLinkArray(entity.Url, html)) { if (url.IndexOf("/sorry/image") > -1) { imagepath = url; break; } } HttpWebResponse response = null; try { response = WebClientUtils.request(imagepath, 60000); captchaForm.tb_captcha.Text = String.Empty; captchaForm.pb_captcha.Image = Image.FromStream(response.GetResponseStream()); captchaForm.ShowDialog(); } finally { if (response != null) { response.Close(); } } String id = imagepath.Substring(imagepath.IndexOf("id=") + 3, imagepath.IndexOf("&") - imagepath.IndexOf("id=") - 3); WebClientUtils.request("http://www.google.com.hk/sorry/Captcha?id=" + id + "&captcha=" + Convert.ToString(captchaForm.Tag), 60000); } } catch { } }
public override Int32 addUrl(String[] linkArray, EngineEntity entity) { Int32 addCnt = 0; foreach (String link in linkArray) { if (link.Length < 4000 && link.IndexOf("bnjs.php") > 0) { String rlink = HttpUtility.UrlDecode(link.Substring(link.IndexOf("as=") + 3)); if (rlink.IndexOf(entity.EngineName) == -1) { addCnt += entity.addUrl(rlink) ? 1 : 0; } } } return(addCnt); }
public virtual Boolean isEndPage(String html, EngineEntity entity) { Boolean result = false; if (!"".Equals(html)) { if (entity.PreString == null || "".Equals(entity.PreString)) { result = (html.IndexOf(entity.NextString) == -1); } else { result = (html.IndexOf(entity.PreString) > 0 && html.IndexOf(entity.NextString) == -1); } } return result; }
public void RemoveEntity(EngineEntity entity) { _logger.Info("Removing entity `{0}`", entity.Id); var didRemove = false; lock (_removedEntities) { if (!_removedEntities.Contains(entity)) { _removedEntities.Add(entity); didRemove = true; } } if (didRemove) { _eventDispatcher.Post(new EntityRemoved(entity.Id)); } }
public EngineEntity CreateEntity(string prototype) { if (TemplateProvider == null) { throw new InvalidOperationException( "EntityTemplateProvider was not provided when creating RuntimeEntityService"); } CheckAddEntityGate(); _logger.Info("Creating entity with prototype `{0}`.", prototype); var template = TemplateProvider.Get(prototype); var entity = new EngineEntity(_idProvider.Next(), template.Components.Select(p => p.Clone()), _eventDispatcher); entity.Prototype = prototype; InternalAddEntity(entity); return(entity); }
public void InitializeContainer(EngineEntity _owner) { owner = _owner; var data = _owner.Data; var dataSels = data.engineValueSelections; List <EngineValueSelection> sels = new List <EngineValueSelection>(); for (int i = 0; i < dataSels.Length; i++) { var sel = dataSels[i]; sels.Add(sel.valueSelection); var bytes = SerializationUtility.SerializeValue(sel, DataFormat.Binary, out List <Object> serObjs); var deSerialized = SerializationUtility.DeserializeValue <EngineValueEntity>(bytes, DataFormat.Binary, serObjs); allUnitSelections.Add(deSerialized); } base.InitializeContainer(data.engineValueManager, sels.ToArray()); InitializeEngineValueEntityEvents(); SyncEvents(); }
public void Initialize(EngineEntity _owner, EngineValueData _data) { owner = _owner; var floatData = _data as EngineFloatData; if (floatData) { maxValue = floatData.maxValue; minValue = floatData.minValue; lastValue = floatData.floatValue; return; } var intData = _data as EngineIntData; if (intData) { maxValue = intData.maxValue; minValue = intData.minValue; lastValue = intData.intValue; return; } }
public void CorrectlyFilterEntitiesIntoSystemInstances() { var oneComponentSystem = new OneComponentSystem(); var twoComponentSystem = new TwoComponentSystem(); var manager = new RuntimeSystemManager(new ISystem[] {oneComponentSystem, twoComponentSystem}, Mock.Of<ILogger>()); var oneComponentEntity = new EngineEntity(0, new IComponent[] {new SimpleComponent()}, Mock.Of<IEventDispatcher>()); var twoComponentEntity = new EngineEntity(0, new IComponent[] {new SimpleComponent(), new OtherSimpleComponent(),}, Mock.Of<IEventDispatcher>()); manager.AddEntities(new[] {oneComponentEntity, twoComponentEntity}); manager.Systems.Single(p => p.System == oneComponentSystem).Entities.ShouldContain(oneComponentEntity); manager.Systems.Single(p => p.System == oneComponentSystem).Entities.ShouldContain(twoComponentEntity); manager.Systems.Single(p => p.System == twoComponentSystem).Entities.ShouldContain(twoComponentEntity); manager.Systems.Single(p => p.System == twoComponentSystem).Entities.ShouldNotContain(oneComponentEntity); }
public void CorrectlyFilterEntitiesIntoSystemInstances() { var oneComponentSystem = new OneComponentSystem(); var twoComponentSystem = new TwoComponentSystem(); var manager = new RuntimeSystemManager(new ISystem[] { oneComponentSystem, twoComponentSystem }, Mock.Of <ILogger>()); var oneComponentEntity = new EngineEntity(0, new IComponent[] { new SimpleComponent() }, Mock.Of <IEventDispatcher>()); var twoComponentEntity = new EngineEntity(0, new IComponent[] { new SimpleComponent(), new OtherSimpleComponent() }, Mock.Of <IEventDispatcher>()); manager.AddEntities(new[] { oneComponentEntity, twoComponentEntity }); manager.Systems.Single(p => p.System == oneComponentSystem).Entities.ShouldContain(oneComponentEntity); manager.Systems.Single(p => p.System == oneComponentSystem).Entities.ShouldContain(twoComponentEntity); manager.Systems.Single(p => p.System == twoComponentSystem).Entities.ShouldContain(twoComponentEntity); manager.Systems.Single(p => p.System == twoComponentSystem).Entities.ShouldNotContain(oneComponentEntity); }
public override Boolean isEndPage(String html, EngineEntity entity) { return(html.IndexOf("There were no results for your search query") > 0); }
public override Boolean isEndPage(String html, EngineEntity entity) { return(html.IndexOf("找不到和您的查询") > 0); }
public void OnTick(EngineEntity entity) { entity.Modify <IWriteableSimpleComponent>(); }
public EngineEntity CreateEntity(string prototype) { if (TemplateProvider == null) { throw new InvalidOperationException( "EntityTemplateProvider was not provided when creating RuntimeEntityService"); } CheckAddEntityGate(); _logger.Info("Creating entity with prototype `{0}`.", prototype); var template = TemplateProvider.Get(prototype); var entity = new EngineEntity(_idProvider.Next(), template.Components.Select(p => p.Clone()), _eventDispatcher); entity.Prototype = prototype; InternalAddEntity(entity); return entity; }
private void InternalAddEntity(EngineEntity e) { _logger.Info("Adding entity with ID `{0}`.", e.Id); _addedEntities.Add(e); _eventDispatcher.Post(new EntityAdded(e.Id)); }
public EngineEntity CreateEntity(IEnumerable<IComponent> components) { CheckAddEntityGate(); _logger.Info("Creating new entity from components."); var entity = new EngineEntity(_idProvider.Next(), components, _eventDispatcher); InternalAddEntity(entity); return entity; }