Exemple #1
0
        public void Start(int hertz, IEntityContainer entityContainer)
        {
            var ms = (int)(1000f / hertz);

            Running = true;
            var task = new Task(() =>
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                while (Running)
                {
                    PlaySounds(entityContainer);
                    stopwatch.Stop();
                    var dt = ms - (int)stopwatch.ElapsedMilliseconds;
                    if (dt > 0)
                    {
                        Thread.Sleep(dt);
                    }

                    stopwatch.Restart();
                }
            });

            task.Start();
        }
 // ========================================
 // constructor
 // ========================================
 public IDictionaryWrapper(IEntityContainer container, object owner, IDictionary <TKey, TValue> real)
 {
     _container = container;
     _owner     = owner;
     _entity    = container.AsEntity(owner);
     _real      = real;
 }
        public ImpositionTool(IEntityContainer container)
        {
            _initialEntities = container;

            using (PicFactory factory = new PicFactory(container))
            {
                // compute lengthes
                PicVisitorDieCutLength visitor = new PicVisitorDieCutLength();
                factory.ProcessVisitor(visitor);
                Dictionary <PicGraphics.LT, double> lengthes = visitor.Lengths;
                _unitLengthCut  = lengthes.ContainsKey(PicGraphics.LT.LT_CUT) ? visitor.Lengths[PicGraphics.LT.LT_CUT] : 0.0;
                _unitLengthFold = lengthes.ContainsKey(PicGraphics.LT.LT_CREASING) ? visitor.Lengths[PicGraphics.LT.LT_CREASING] : 0.0;
                // compute area
                try
                {
                    PicToolArea picToolArea = new PicToolArea();
                    factory.ProcessTool(picToolArea);
                    _unitArea = picToolArea.Area;
                }
                catch (PicToolTooLongException /*ex*/)
                {
                    _unitArea = 0;
                }
            }
        }
Exemple #4
0
            public override PicEntity Clone(IEntityContainer factory)
            {
                PicPoint point = new PicPoint(factory.GetNewEntityId(), LineType);

                point._pt = this._pt;
                return(point);
            }
Exemple #5
0
        /// <summary>
        /// Spawn this new into the live world into a specified container
        /// </summary>
        /// <param name="spawnTo">the location/container this should spawn into</param>
        public override void SpawnNewInWorld(IContains spawnTo)
        {
            var ch = (ICharacter)DataTemplate;

            BirthMark = Birthmarker.GetBirthmark(ch);
            Keywords  = new string[] { ch.Name.ToLower(), ch.SurName.ToLower() };
            Birthdate = DateTime.Now;

            if (spawnTo == null)
            {
                spawnTo = GetBaseSpawn();
            }

            CurrentLocation = spawnTo;

            //Set the data context's stuff too so we don't have to do this over again
            ch.LastKnownLocation     = spawnTo.DataTemplate.ID.ToString();
            ch.LastKnownLocationType = spawnTo.GetType().Name;
            ch.Save();

            spawnTo.MoveInto <IPlayer>(this);

            Inventory = new EntityContainer <IInanimate>();

            LiveCache.Add(this);
        }
Exemple #6
0
 public override PicEntity Clone(IEntityContainer factory)
 {
     PicSegment segment = new PicSegment(factory.GetNewEntityId(), LineType);
     segment._pt0 = this._pt0;
     segment._pt1 = this._pt1;
     return segment;
 }
Exemple #7
0
 public override PicEntity Clone(IEntityContainer factory)
 {
     return(new PicPoint(factory.GetNewEntityId(), LineType)
     {
         Pt = this.Pt
     });
 }
Exemple #8
0
        /// <summary>
        /// Spawn this new into the live world into a specified container
        /// </summary>
        /// <param name="spawnTo">the location/container this should spawn into</param>
        public override void SpawnNewInWorld(IContains spawnTo)
        {
            //We can't even try this until we know if the data is there
            if (DataTemplate == null)
            {
                throw new InvalidOperationException("Missing backing data store on NPC spawn event.");
            }

            var backingStore = (INonPlayerCharacter)DataTemplate;

            BirthMark = Birthmarker.GetBirthmark(backingStore);
            Keywords  = new string[] { backingStore.Name.ToLower() };
            Birthdate = DateTime.Now;

            if (spawnTo == null)
            {
                throw new NotImplementedException("NPCs can't spawn to nothing");
            }

            CurrentLocation = spawnTo;

            spawnTo.MoveInto <IIntelligence>(this);

            Inventory = new EntityContainer <IInanimate>();

            LiveCache.Add(this);
        }
Exemple #9
0
 // ========================================
 // constructor
 // ========================================
 public IListWrapper(IEntityContainer container, object owner, IList <T> real)
 {
     _container = container;
     _owner     = owner;
     _entity    = container.AsEntity(owner);
     _real      = real;
 }
Exemple #10
0
        internal EntitySet(
            bool needClearing,
            World world,
            Predicate <ComponentEnum> filter,
            Predicate <int> predicate,
            List <Func <EntityContainerWatcher, World, IDisposable> > subscriptions)
        {
            _needClearing     = needClearing;
            _worldId          = world.WorldId;
            _worldMaxCapacity = world.MaxCapacity;
            _container        = new EntityContainerWatcher(this, filter, predicate);
            _subscriptions    = subscriptions.Select(s => s(_container, world)).Merge();

            _mapping  = EmptyArray <int> .Value;
            _entities = EmptyArray <Entity> .Value;
            Count     = 0;

            if (!_needClearing)
            {
                IEntityContainer @this = this;
                for (int i = 0; i <= Math.Min(world.EntityInfos.Length, world.LastEntityId); ++i)
                {
                    if (filter(world.EntityInfos[i].Components) && predicate(i))
                    {
                        @this.Add(i);
                    }
                }
            }

            _sortedIndex = Math.Max(0, Count - 1);
            world.Add(this);
        }
Exemple #11
0
 protected Entity(Asset asset, IEntityContainer entityContainer)
 {
     DataLayer       = ServiceLocator.Instance.Get <IDataLayerInternal>();
     EntityContainer = entityContainer;
     Logger          = DataLayer.Logger;
     Asset           = asset;
 }
Exemple #12
0
        public static bool ComputePositionDefault(IEntityContainer factory, Box2D boxBorder, Vector2D spaceBetween, ref List <BPosition> lPos, ref Box2D bbox)
        {
            if (boxBorder.Width <= 0.0 || boxBorder.Height <= 0.0)
            {
                return(false);
            }

            ImpositionTool tool = Instantiate(factory, new ImpositionSettings(boxBorder.Width, boxBorder.Height));

            tool.SpaceBetween = spaceBetween;
            tool.AllowOrthogonalImposition = true;
            tool.AllowBothDirection        = false;
            tool.HorizontalAlignment       = ImpositionSettings.HAlignment.HALIGN_LEFT;
            tool.VerticalAlignment         = ImpositionSettings.VAlignment.VALIGN_BOTTOM;
            tool.GenerateSortedSolutionList(null, out List <ImpositionSolution> solutions);
            if (solutions.Count > 0)
            {
                ImpositionSolution impSol       = solutions[0];
                Vector2D           cardboardPos = impSol.CardboardPosition;
                foreach (var p in impSol.Positions)
                {
                    BPosition pos = p;
                    pos.Pt += boxBorder.PtMin - cardboardPos;
                    lPos.Add(pos);
                }
                Vector2D ptMin = impSol.Bbox.PtMin + boxBorder.PtMin;
                Vector2D ptMax = impSol.Bbox.PtMax + boxBorder.PtMin;
                bbox = new Box2D(ptMin, ptMax);
            }
            return(lPos.Count > 0);
        }
Exemple #13
0
        private bool TryAddInternal(IEntityContainer holder, Entity item, int index, bool replace)
        {
            if (item == null || holder == null || holder.Contains(item))
            {
                return(false);
            }
            var inventoryItem = item.Get <InventoryItem>();

            if (inventoryItem == null)
            {
                return(false);
            }
            if (holder[index] != null)
            {
                if (!replace)
                {
                    return(false);
                }
                holder.Remove(holder[index]);
            }
            if (inventoryItem.Inventory != null)
            {
                inventoryItem.Inventory.Remove(item);
            }
            holder.ContainerSystemSet(item, index);
            ProcessHolderChange(holder, item, inventoryItem, index);
            return(true);
        }
Exemple #14
0
        public void Start(int hertz, IEntityContainer entityContainer)
        {
            var timeStep = 1f / hertz;
            var ms       = (int)(timeStep * 1000);

            Running = true;
            var task = new Task(() =>
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                while (Running)
                {
                    Simulate(timeStep, entityContainer);
                    stopwatch.Stop();
                    var dt = ms - (int)stopwatch.ElapsedMilliseconds;
                    if (dt > 0)
                    {
                        Thread.Sleep(dt);
                    }

                    stopwatch.Restart();
                }
            });

            task.Start();
        }
Exemple #15
0
 public MapQueryService(
     IMap map,
     IEntityContainer entityContainer)
 {
     _map             = map;
     _entityContainer = entityContainer;
 }
Exemple #16
0
        internal EntityMap(
            bool needClearing,
            World world,
            Predicate <ComponentEnum> filter,
            List <Predicate <int> > predicates,
            List <Func <EntityContainerWatcher, World, IDisposable> > subscriptions,
            IEqualityComparer <TKey> comparer)
        {
            _needClearing     = needClearing;
            _worldId          = world.WorldId;
            _worldMaxCapacity = world.MaxCapacity;
            _container        = new EntityContainerWatcher(this, filter, predicates);
            _subscriptions    = Enumerable.Repeat(world.Subscribe <ComponentChangedMessage <TKey> >(OnChange), 1).Concat(subscriptions.Select(s => s(_container, world))).Merge();

            _previousComponents = ComponentManager <TKey> .GetOrCreatePrevious(_worldId);

            _components = ComponentManager <TKey> .GetOrCreate(_worldId);

            _entities = new Dictionary <TKey, Entity>(comparer);

            _entityIds = EmptyArray <bool> .Value;

            if (!_needClearing)
            {
                IEntityContainer @this = this as IEntityContainer;
                foreach (Entity entity in _components.GetEntities())
                {
                    if (filter(entity.Components))
                    {
                        @this.Add(entity.EntityId);
                    }
                }
            }
        }
Exemple #17
0
            /// <summary>
            /// Create a new block from an external container
            /// </summary>
            /// <param name="container">An object of a class that implements the <see cref="IEntityContainerInterface"/>. Either a <see cref="PicFactory"/> or a <see cref="PicBlock"/> instance.</param>
            /// <param name="transf">Transformation applied to all drawable entities</param>
            /// <returns></returns>
            public PicBlock AddBlock(IEntityContainer container, Transform2D transf)
            {
                PicBlock block = PicBlock.CreateNewBlock(GetNewEntityId(), container, transf);

                AddEntity(block);
                return(block);
            }
 public ImpositionSolution(IEntityContainer container, string patternName, bool hasRotationInRows, bool hasRotationInCols)
 {
     _container         = container;
     _patternName       = patternName;
     _hasRotationInRows = hasRotationInRows;
     _hasRotationInCols = hasRotationInCols;
 }
Exemple #19
0
        public override void OnUpdate(IEntityContainer container, float deltaTime)
        {
            foreach (var e in this.playFilter.Target)
            {
                var audio       = e.GetTrait <Audio>();
                var renderer    = e.GetTrait <Renderer>();
                var audioSource = GetOrAddComponent <AudioSource>(renderer.View);
                var refSet      = ResourcesManager.GetManagedRefSet(renderer.View);
                var clip        = ResourcesManager.LoadAsset <AudioClip>(audio.Path, refSet);
                audio.Duration   = clip.length;
                audioSource.clip = clip;
                audioSource.Play();

                e.AddTag(Audio.Playing);
            }

            foreach (var e in this.updateFilter.Target)
            {
                var audio = e.GetTrait <Audio>();
                audio.Duration -= deltaTime;
                if (audio.Duration <= 0)
                {
                    e.RemoveTrait <Audio>();
                    e.RemoveTag(Audio.Playing);
                }
            }
        }
        public override void OnInit(IEntityContainer container)
        {
            var m = container.NewMatcher();

            m.HasTrait <Message>();
            this.filter = container.GetFilter(this, TupleType.Job, m);
        }
Exemple #21
0
        /// <summary>
        /// Tries to find this entity in the world based on its ID or gets a new one from the db and puts it in the world
        /// </summary>
        public void GetFromWorldOrSpawn()
        {
            //Try to see if they are already there
            var me = LiveCache.Get <Player>(DataTemplate.ID);

            //Isn't in the world currently
            if (me == default(IPlayer))
            {
                SpawnNewInWorld();
            }
            else
            {
                BirthMark    = me.BirthMark;
                Birthdate    = me.Birthdate;
                DataTemplate = me.DataTemplate;
                Inventory    = me.Inventory;
                Keywords     = me.Keywords;

                if (me.CurrentLocation == null)
                {
                    var newLoc = GetBaseSpawn();
                    newLoc.MoveInto <IPlayer>(this);
                }
                else
                {
                    me.CurrentLocation.MoveInto <IPlayer>(this);
                }
            }
        }
Exemple #22
0
        public void Create(IEntityContainer container)
        {
            IEntity z1 = container.CreateEntity();

            z1.SetComponent(new MultiverseIdComponent(226747));

            z1.GetComponent <EffectStackComponent>().AddEffect(new DamageEffect(3));
        }
Exemple #23
0
        public override PicEntity Clone(IEntityContainer factory)
        {
            PicSegment segment = new PicSegment(factory.GetNewEntityId(), LineType);

            segment._pt0 = this._pt0;
            segment._pt1 = this._pt1;
            return(segment);
        }
Exemple #24
0
        public RepositoryContainer(IEntityContainer entityContainer, string connection = "")
        {
            container        = new UnityContainer();
            _entityContainer = entityContainer;

            container.RegisterType <IRepositoryConnection, SQLRepositoryConnection>(new ContainerControlledLifetimeManager(), new InjectionConstructor(connection));
            container.RegisterType <IRepositoryProcedure, StoredProcedure>(new InjectionConstructor(typeof(IRepositoryConnection)));
        }
        private void HandleEditScriptEvent(IEntityContainer entity, LuaScript script)
        {
            this.entity = entity;
            this.script = script;

            input.text = script.code;
            Open();
        }
 public IConnectionString GetConnectionString(IEntityContainer entityContainer, IEntityMapper mapper, object entity)
 {
     // 从实体容器中配置的默认连接字符串自动生成连接字符串 这适用于使用同一个用户名和密码管理各切片数据库的场景
     return(entityContainer.DefaultConnectionString.AcquireConnectionString(
                entityContainer.DefaultConnectionString.DataSource,
                entityContainer.DefaultConnectionString.Database + DateTime.Today.Year.ToString()
                ));
 }
 /// <summary>
 /// Visits all entities at the entity container.
 /// </summary>
 /// <param name="entityContainer">The entities of this container ar visited.</param>
 private void VisitEnities(IEntityContainer entityContainer)
 {
     entityContainer.Classes.ForEach(nrClass => nrClass.Accept(this));
     entityContainer.Structs.ForEach(nrStruct => nrStruct.Accept(this));
     entityContainer.Interfaces.ForEach(nrInterface => nrInterface.Accept(this));
     entityContainer.Enums.ForEach(nrEnum => nrEnum.Accept(this));
     entityContainer.Delegates.ForEach(nrDelegate => nrDelegate.Accept(this));
 }
        /// <summary>
        /// Deselects the current entity choice
        /// </summary>
        public void UnselectEntity()
        {
            currentEntity = null;
            circle.Deactivate();
            ActivateTool(ToolType.None);

            eventTable?.Invoke("OnEntityDeselect");
        }
Exemple #29
0
 /// <summary>
 /// Prints all entities of the given <see cref="IEntityContainer"/>.
 /// </summary>
 /// <param name="entityContainer">An <see cref="IEntityContainer"/> containing the enities to print.</param>
 private void PrintEntities(IEntityContainer entityContainer)
 {
     PrintEntities("delegates", entityContainer.Delegates);
     PrintEntities("interfaces", entityContainer.Interfaces);
     PrintEntities("structs", entityContainer.Structs);
     PrintEntities("enums", entityContainer.Enums);
     PrintEntities("classes", entityContainer.Classes);
 }
        public override void OnInit(IEntityContainer container)
        {
            var m = container.NewMatcher();

            m.HasTag(Player.MainPlayer).HasTrait <Renderer>().HasTag(Renderer.Loaded);
            this.filter = container.GetFilter(this, TupleType.Reactive, m);

            this.follower = Camera.main.GetComponent <CameraFollow>();
        }
 public PosDataService(IEntityContainer container, IBackOfficeApi backOfficeApi, IAuthorizationApi authorizationApi, ITerminalApi terminalApi, string login, string password)
 {
     _backOfficeApi    = backOfficeApi;
     _authorizationApi = authorizationApi;
     _terminalApi      = terminalApi;
     _login            = login;
     _password         = password;
     _db = container.Context;
 }
        public static Workitem CreateWorkitem(AssetFactory assetFactory, string assetType, Workitem parent, IEntityContainer entityContainer) {
            Asset asset;

            switch (assetType) {
                case Entity.TaskType:
                case Entity.TestType:
                    asset = assetFactory.CreateAssetForSecondaryWorkitem(assetType, parent);
                    var workitem = CreateWorkitem(asset, parent, entityContainer);
                    parent.Children.Add(workitem);
                    break;
                case Entity.DefectType:
                    asset = assetFactory.CreateAssetForPrimaryWorkitem(Entity.DefectType);
                    break;
                default:
                    throw new NotSupportedException(assetType + " is not supported.");
            }

            return CreateWorkitem(asset, parent, entityContainer);
        }
        internal Workitem(Asset asset, Workitem parent, IEntityContainer entityContainer) : base(asset, entityContainer) {
            Parent = parent;

            //TODO maybe make one more constructor for tests instead of this?
            // the following check is for unit tests            
            if(asset == null || asset.Children == null) {
                return;
            }

            if(!SupportedTypes.Contains(asset.AssetType.Token)) {
                throw new ArgumentException(string.Format("Illegal asset type, '{0}' is not supported.", asset.AssetType.Token));
            }

            foreach (var childAsset in asset.Children.Where(childAsset => DataLayer.ShowAllTasks || DataLayer.AssetPassesShowMyTasksFilter(childAsset))) {
                Children.Add(WorkitemFactory.CreateWorkitem(childAsset, this, entityContainer));
                Children.Sort(new WorkitemComparer(TestType, TaskType));
            }

            Children.TrimExcess();
        }
Exemple #34
0
 public override PicEntity Clone(IEntityContainer factory)
 {
     PicNurb nurb = new PicNurb(factory.GetNewEntityId(), LineType);
     return nurb;
 }
 /// <returns>An entity to be saved in a new factory</returns>
 public override Pic.Factory2D.PicEntity Clone(IEntityContainer factory)
 {
     return new PicCotationVertical(factory.GetNewEntityId(), new Vector2D(_pt0), new Vector2D(_pt1), _offset, 1);
 }
 public ImpositionToolCardboardFormat(IEntityContainer container, CardboardFormat cardboardFormat)
     : base(container)
 {
     _cardboardFormat = cardboardFormat;
 }
 public override PicEntity Clone(IEntityContainer factory)
 {
     return new PicCotationDistance(factory.GetNewEntityId(), new Vector2D(_pt0), new Vector2D(_pt1), _offset, _noDecimals);
 }
Exemple #38
0
 /// <summary>
 /// Enables to copy an entity in a new factory
 /// </summary>
 /// <returns>An entity to be saved in a new factory</returns>
 public abstract PicEntity Clone(IEntityContainer factory);
 private static Workitem CreatePersistentWorkitem(Asset asset, Workitem parent, IEntityContainer entityContainer) {
     return new Workitem(asset, parent, entityContainer);
 }
 private static Workitem CreateVirtualWorkitem(Asset asset, Workitem parent, IEntityContainer entityContainer) {
     return new VirtualWorkitem(asset, parent, entityContainer);
 }
Exemple #41
0
 public ImpositionToolXY(IEntityContainer container, int noInX, int noInY)
     : base(container)
 {
     _noColsExpected = noInX;
     _noRowsExpected = noInY;
 }
 public TestWorkitem(string id, bool isPrimary, IEntityContainer entityContainer) : base(null, null, entityContainer) {
     this.id = id;
     this.isPrimary = isPrimary;
 }
 public Workitem CreateWorkitem(string assetType, Workitem parent, IEntityContainer entityContainer) {
     var assetFactory = new AssetFactory(this, CurrentProject, LoggerFactory, AttributesToQuery);
     return WorkitemFactory.CreateWorkitem(assetFactory, assetType, parent, entityContainer);
 }
Exemple #44
0
 public override PicEntity Clone(IEntityContainer factory)
 {
     PicCardboardFormat cbf = new PicCardboardFormat(factory.GetNewEntityId(), Vector2D.Zero, _dimensions);
     return cbf;            
 }
 public static Workitem CreateWorkitem(Asset asset, Workitem parent, IEntityContainer entityContainer) {
     return asset.Oid.IsNull ? CreateVirtualWorkitem(asset, parent, entityContainer) : CreatePersistentWorkitem(asset, parent, entityContainer);
 }
 internal VirtualWorkitem(Asset asset, Workitem parent, IEntityContainer entityContainer) : base(asset, parent, entityContainer) { }
 protected Entity(Asset asset, IEntityContainer entityContainer) {
     DataLayer = ServiceLocator.Instance.Get<IDataLayerInternal>();
     EntityContainer = entityContainer;
     Logger = DataLayer.Logger;
     Asset = asset;
 }
Exemple #48
0
 public override PicEntity Clone(IEntityContainer factory)
 {
     PicPoint point = new PicPoint(factory.GetNewEntityId(), LineType);
     point._pt = this._pt;
     return point;
 }
Exemple #49
0
 /// <returns>An entity to be saved in a new factory</returns>
 public override Pic.Factory2D.PicEntity Clone(IEntityContainer factory)
 {
     throw new NotImplementedException();
 }
Exemple #50
0
 public override PicEntity Clone(IEntityContainer factory)
 {
     PicArc arc = new PicArc(factory.GetNewEntityId(), LineType);
     arc._center = this._center;
     arc._radius = this._radius;
     arc._angleBeg = this._angleBeg;
     arc._angleEnd = this._angleEnd;
     return arc;
 }