Esempio n. 1
0
        // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
        //! 更新
        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);
        }
Esempio n. 4
0
        // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
        //! ライフサイクルからObject削除
        public void RemoveEntityToLifeCycle(IEntityLogic entity)
        {
            entity.Release();

            RemoveEntityToAllList(entity);

            _lifeCycleView.RemoveEntity(entity);
        }
Esempio n. 5
0
        // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
        //! ライフサイクルにObject追加
        public void AddEntityToLifeCycle(IEntityLogic logic, IEntityView view)
        {
            logic.Init(_entityFieldLogic, view, _kind);

            AddEntityToAllList(logic);

            _lifeCycleView.AddEntity(logic, view);
            logic.Start();
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        /// <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));
        }
Esempio n. 8
0
        // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
        //! 削除
        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();
            }
        }
Esempio n. 9
0
 public PagesController(IEntityLogic <Product> logic)
 {
     _pageLogic = logic as PageLogic;
 }
Esempio n. 10
0
 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
 //! Entity削除
 protected virtual void RemoveEntityToAllList(IEntityLogic entity)
 {
     RemoveToList(_allMovable, entity);
     RemoveToList(_allUpdatable, entity);
 }
Esempio n. 11
0
 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
 //! Entity追加
 protected virtual void AddEntityToAllList(IEntityLogic entity)
 {
     AddToList(_allMovable, entity);
     AddToList(_allUpdatable, entity);
 }