Beispiel #1
0
        internal void deregisterAllComponents()
        {
            for (var i = 0; i < _components.length; i++)
            {
                var component = _components.buffer[i];

                // deal with renderLayer list if necessary
                if (component is RenderableComponent)
                {
                    _entity.scene.renderableComponents.remove(component as RenderableComponent);
                }

                // deal with IUpdatable
                if (component is IUpdatable)
                {
                    _updatableComponents.remove(component as IUpdatable);
                }

                if (Core.entitySystemsEnabled)
                {
                    _entity.componentBits.set(ComponentTypeManager.getIndexFor(component.GetType()), false);
                    _entity.scene.entityProcessors.onComponentRemoved(_entity);
                }
            }
        }
Beispiel #2
0
        public Core(int width = 1280, int height = 720, bool isFullScreen = false, bool enableEntitySystems = true)
        {
            _instance = this;
            emitter   = new Emitter <CoreEvents>(new CoreEventsComparer());

            var graphicsManager = new GraphicsDeviceManager(this);

            graphicsManager.PreferredBackBufferWidth  = width;
            graphicsManager.PreferredBackBufferHeight = height;
            graphicsManager.IsFullScreen = isFullScreen;
            graphicsManager.SynchronizeWithVerticalRetrace = true;
            graphicsManager.DeviceReset += onGraphicsDeviceReset;
            graphicsManager.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;
            Screen.initialize(graphicsManager);

            Content.RootDirectory = "Content";
            contentManager        = new NezContentManager(Services, Content.RootDirectory);
            IsMouseVisible        = true;
            IsFixedTimeStep       = false;

            entitySystemsEnabled = enableEntitySystems;
            if (enableEntitySystems)
            {
                ComponentTypeManager.initialize();
            }
        }
        void handleRemove(Component component)
        {
            // deal with renderLayer list if necessary
            if (component is RenderableComponent)
            {
                _entity.scene.renderableComponents.remove(component as RenderableComponent);
            }

            // deal with IUpdatable
            if (component is IUpdatable)
            {
                _updatableComponents.remove(component as IUpdatable);
            }

            if (component is INetworkComponent)
            {
                _networkingComponents.Value.remove(component as INetworkComponent);
            }

            if (Core.entitySystemsEnabled)
            {
                _entity.componentBits.set(ComponentTypeManager.getIndexFor(component.GetType()), false);
                _entity.scene.entityProcessors.onComponentRemoved(_entity);
            }

            component.onRemovedFromEntity();
            component.entity = null;
        }
        internal void registerAllComponents()
        {
            for (var i = 0; i < _components.length; i++)
            {
                var component = _components.buffer[i];
                if (component is RenderableComponent)
                {
                    _entity.scene.renderableComponents.add(component as RenderableComponent);
                }

                if (component is IUpdatable)
                {
                    _updatableComponents.add(component as IUpdatable);
                }
                if (component is INetworkComponent)
                {
                    _networkingComponents.Value.add(component as INetworkComponent);
                }

                if (Core.entitySystemsEnabled)
                {
                    _entity.componentBits.set(ComponentTypeManager.getIndexFor(component.GetType()));
                    _entity.scene.entityProcessors.onComponentAdded(_entity);
                }
            }
        }
Beispiel #5
0
        public Matcher one(params Type[] types)
        {
            foreach (var type in types)
            {
                oneSet.set(ComponentTypeManager.getIndexFor(type));
            }

            return(this);
        }
Beispiel #6
0
        public Matcher Exclude(params Type[] types)
        {
            foreach (var type in types)
            {
                exclusionSet.Set(ComponentTypeManager.GetIndexFor(type));
            }

            return(this);
        }
Beispiel #7
0
        public Matcher All(params Type[] types)
        {
            foreach (var type in types)
            {
                allSet.Set(ComponentTypeManager.GetIndexFor(type));
            }

            return(this);
        }
Beispiel #8
0
        static void appendTypes(StringBuilder builder, string headerMessage, BitSet typeBits)
        {
            var firstType = true;

            builder.Append(headerMessage);
            foreach (var type in ComponentTypeManager.getTypesFromBits(typeBits))
            {
                if (!firstType)
                {
                    builder.Append(", ");
                }
                builder.Append(type.Name);

                firstType = false;
            }

            builder.AppendLine();
        }
Beispiel #9
0
        internal void RegisterAllComponents()
        {
            for (var i = 0; i < _components.Length; i++)
            {
                var component = _components.Buffer[i];
                if (component is RenderableComponent)
                {
                    _entity.Scene.RenderableComponents.Add(component as RenderableComponent);
                }

                if (component is IUpdatable)
                {
                    _updatableComponents.Add(component as IUpdatable);
                }

                if (Core.entitySystemsEnabled)
                {
                    _entity.componentBits.Set(ComponentTypeManager.GetIndexFor(component.GetType()));
                    _entity.Scene.EntityProcessors.OnComponentAdded(_entity);
                }
            }
        }
Beispiel #10
0
        void HandleRemove(Component component)
        {
            // deal with renderLayer list if necessary
            if (component is RenderableComponent)
            {
                _entity.Scene.RenderableComponents.Remove(component as RenderableComponent);
            }

            // deal with IUpdatable
            if (component is IUpdatable)
            {
                _updatableComponents.Remove(component as IUpdatable);
            }

            if (Core.entitySystemsEnabled)
            {
                _entity.componentBits.Set(ComponentTypeManager.GetIndexFor(component.GetType()), false);
                _entity.Scene.EntityProcessors.OnComponentRemoved(_entity);
            }

            component.OnRemovedFromEntity();
            component.Entity = null;
        }
Beispiel #11
0
        /// <summary>
        /// handles any Components that need to be removed or added
        /// </summary>
        void updateLists()
        {
            // handle removals
            if (_componentsToRemove.Count > 0)
            {
                for (int i = 0, count = _componentsToRemove.Count; i < count; i++)
                {
                    handleRemove(_componentsToRemove[i]);
                    _components.remove(_componentsToRemove[i]);
                }
                _componentsToRemove.Clear();
            }

            // handle additions
            if (_componentsToAdd.Count > 0)
            {
                for (int i = 0, count = _componentsToAdd.Count; i < count; i++)
                {
                    var component = _componentsToAdd[i];
                    if (component is RenderableComponent)
                    {
                        _entity.scene.renderableComponents.add(component as RenderableComponent);
                    }

                    if (component is IUpdatable)
                    {
                        _updatableComponents.add(component as IUpdatable);
                    }

                    if (Core.entitySystemsEnabled)
                    {
                        _entity.componentBits.set(ComponentTypeManager.getIndexFor(component.GetType()));
                        _entity.scene.entityProcessors.onComponentAdded(_entity);
                    }

                    _components.add(component);
                    _tempBufferList.Add(component);
                }

                // clear before calling onAddedToEntity in case more Components are added then
                _componentsToAdd.Clear();
                _isComponentListUnsorted = true;

                // now that all components are added to the scene, we loop through again and call onAddedToEntity/onEnabled
                for (var i = 0; i < _tempBufferList.Count; i++)
                {
                    var component = _tempBufferList[i];
                    component.onAddedToEntity();

                    // component.enabled checks both the Entity and the Component
                    if (component.enabled)
                    {
                        component.onEnabled();
                    }
                }

                _tempBufferList.Clear();
            }

            if (_isComponentListUnsorted)
            {
                _updatableComponents.sort(compareUpdatableOrder);
                _isComponentListUnsorted = false;
            }
        }
Beispiel #12
0
        public void updateLists()
        {
            // handle removals
            if (_componentsToRemove.Count > 0)
            {
                for (var i = 0; i < _componentsToRemove.Count; i++)
                {
                    var component = _componentsToRemove[i];

                    // deal with renderLayer list if necessary
                    if (component is RenderableComponent)
                    {
                        _entity.scene.renderableComponents.remove(component as RenderableComponent);
                    }

                    // deal with IUpdatable
                    if (component is IUpdatable)
                    {
                        _updatableComponents.Remove(component as IUpdatable);
                    }

                    if (Core.entitySystemsEnabled)
                    {
                        _entity.componentBits.set(ComponentTypeManager.getIndexFor(component.GetType()), false);
                        _entity.scene.entityProcessors.onComponentRemoved(_entity);
                    }

                    _components.Remove(component);
                    component.onRemovedFromEntity();
                    component.entity = null;
                }
                _componentsToRemove.Clear();
            }

            // handle additions
            if (_componentsToAdd.Count > 0)
            {
                for (var i = 0; i < _componentsToAdd.Count; i++)
                {
                    var component = _componentsToAdd[i];

                    if (component is RenderableComponent)
                    {
                        _entity.scene.renderableComponents.add(component as RenderableComponent);
                    }

                    if (component is IUpdatable)
                    {
                        _updatableComponents.Add(component as IUpdatable);
                    }

                    if (Core.entitySystemsEnabled)
                    {
                        _entity.componentBits.set(ComponentTypeManager.getIndexFor(component.GetType()));
                        _entity.scene.entityProcessors.onComponentAdded(_entity);
                    }

                    _components.Add(component);
                    _tempBufferList.Add(component);
                }

                // clear before calling onAddedToEntity in case more Components are added then
                _componentsToAdd.Clear();
                _isComponentListUnsorted = true;

                // now that all components are added to the scene, we loop through again and call onAddedToEntity/onEnabled
                for (var i = 0; i < _tempBufferList.Count; i++)
                {
                    var component = _tempBufferList[i];
                    component.onAddedToEntity();

                    if (_entity.enabled && component.enabled)
                    {
                        component.onEnabled();
                    }
                }

                _tempBufferList.Clear();
            }

            if (_isComponentListUnsorted)
            {
                _updatableComponents.Sort(compareUpdatableOrder);
                _isComponentListUnsorted = false;
            }
        }