// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // //! 更新 protected void Update() { // 毎フレ更新処理 IUpdatable updatable = null; int listLength = _allUpdatable.Count; for (int i = 0; i < listLength; ++i) { updatable = _allUpdatable[i]; // 状態更新 updatable.UpdateChangeState(); // 処理更新 updatable.Update(); // viewを変更する if (updatable.IsWillChangeView) { IEntityLogic obj = (IEntityLogic)updatable; IEntityView changeView = (IEntityView)updatable.GetWillChangeView(); _lifeCycleView.RemoveEntity(obj); updatable.SetView(changeView); _lifeCycleView.AddEntity(obj, changeView); updatable.EndChangeView(); } } }
public Guid NewEntity(IEntityLogic logic, Guid controllerSim, float updatePeriod = 100) { if (Role == InstanceRole.OWNER) { var id = Guid.NewGuid(); var entityAdded = new EntityAdded() { EntityId = id, UpdatePeriod = updatePeriod, CreationInfo = logic.GetCreationInfo(), InitialSnapshot = logic.TakeSnapshot(), ControllerSimId = controllerSim, AuthoritySimId = Id }; _addedEntites.Add(entityAdded); var entity = CreateLocalEntity(logic, entityAdded); AddRemoteEntites(entity, entityAdded); return(id); } else { throw new Exception("Can only create entities on OWNER instance"); } }
private LocalEntity CreateLocalEntity(IEntityLogic logic, EntityAdded added) { var entity = new LocalEntity(added.EntityId, logic, this, GetRoleForSim(Id, added), added.UpdatePeriod); _entities[entity.Id] = entity; logic.ApplySnapshot(added.InitialSnapshot); return(entity); }
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // //! ライフサイクルからObject削除 public void RemoveEntityToLifeCycle(IEntityLogic entity) { entity.Release(); RemoveEntityToAllList(entity); _lifeCycleView.RemoveEntity(entity); }
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // //! ライフサイクルにObject追加 public void AddEntityToLifeCycle(IEntityLogic logic, IEntityView view) { logic.Init(_entityFieldLogic, view, _kind); AddEntityToAllList(logic); _lifeCycleView.AddEntity(logic, view); logic.Start(); }
public LocalEntity(Guid id, IEntityLogic logic, SimultaneousSim sim, EntityRole role, float updatePeriod = 100f) { Id = id; _logic = logic; _sim = sim; Role = role; _recordedFrameSnapshots = new List <FrameSnapshot>(); _recordedFrameCommands = new List <FrameCommands>(); _recievedEnvelopes = new List <RecievedCmdEnvelope>(); _clientEntities = new List <IEntity>(); UpdatePeriod = updatePeriod; NetworkEntityAdded(this); }
/// <summary> /// Update an entity's properties from a JObject (during a PATCH). Validation is performed, but no changes are saved. /// </summary> /// <param name="entity">Entity to be updated.</param> /// <param name="changes">Changes as a JObject.</param> protected virtual void UpdateFromJObject <T1>(T1 entity, JObject changes) where T1 : class, IEntity { Dictionary <string, object> changedProperties = new Dictionary <string, object>(); Type entityType = typeof(T1); foreach (var pair in changes) { if (!ProcessJTokenUpdate(entity, pair.Key, pair.Value)) { var convertedPair = JsonExtensions.ConvertToType <T1>(pair); changedProperties.Add(convertedPair.Key, convertedPair.Value); } } IEntityLogic logic = BusinessLogicHelper.GetBusinessLogic <T1>(unitOfWork); unitOfWork.GetRepository <T1>().UpdateChangedProperties(entity, changedProperties, p => logic.Validate(p)); }
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // //! 削除 protected void Remove() { int updatableLength = _allUpdatable.Count; for (int i = 0; i < updatableLength; ++i) { if (_allUpdatable[i].IsWillRemove) { IEntityLogic removeObj = (IEntityLogic)_allUpdatable[i]; _willRemoveList.Add(removeObj); } } int willRemoveListLenght = _willRemoveList.Count; for (int i = 0; i < willRemoveListLenght; ++i) { RemoveEntityToLifeCycle(_willRemoveList[i]); } if (willRemoveListLenght > 0) { _willRemoveList.Clear(); } }
public PagesController(IEntityLogic <Product> logic) { _pageLogic = logic as PageLogic; }
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // //! Entity削除 protected virtual void RemoveEntityToAllList(IEntityLogic entity) { RemoveToList(_allMovable, entity); RemoveToList(_allUpdatable, entity); }
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // //! Entity追加 protected virtual void AddEntityToAllList(IEntityLogic entity) { AddToList(_allMovable, entity); AddToList(_allUpdatable, entity); }