Exemple #1
0
 /// <summary>
 /// adds an Entity to the Scene's Entities list
 /// </summary>
 /// <param name="entity">The Entity to add</param>
 public T addEntity <T>(T entity) where T : Entity
 {
     Insist.isFalse(entities.contains(entity), "You are attempting to add the same entity to a scene twice: {0}", entity);
     entities.add(entity);
     entity.scene = this;
     return(entity);
 }
Exemple #2
0
        /// <summary>
        /// sets up the deadzone centered in the current cameras bounds with the given size
        /// </summary>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        public void setCenteredDeadzone(int width, int height)
        {
            Insist.isFalse(camera == null, "camera is null. We cant get its bounds if its null. Either set it or wait until after this Component is added to the Entity.");
            var cameraBounds = camera.bounds;

            deadzone = new RectangleF((cameraBounds.width - width) / 2, (cameraBounds.height - height) / 2, width, height);
        }
        public void addVertex(Vector2 vertex, Color color, PrimitiveType primitiveType)
        {
            Insist.isTrue(_hasBegun, "Invalid state. Begin must be called before AddVertex can be called.");
            Insist.isFalse(primitiveType == PrimitiveType.LineStrip || primitiveType == PrimitiveType.TriangleStrip, "The specified primitiveType is not supported by PrimitiveBatch");

            if (primitiveType == PrimitiveType.TriangleList)
            {
                if (_triangleVertsCount >= _triangleVertices.Length)
                {
                    flushTriangles();
                }

                _triangleVertices[_triangleVertsCount].Position = new Vector3(vertex, 0);
                _triangleVertices[_triangleVertsCount].Color    = color;
                _triangleVertsCount++;
            }

            if (primitiveType == PrimitiveType.LineList)
            {
                if (_lineVertsCount >= _lineVertices.Length)
                {
                    flushLines();
                }

                _lineVertices[_lineVertsCount].Position = new Vector3(vertex, 0);
                _lineVertices[_lineVertsCount].Color    = color;
                _lineVertsCount++;
            }
        }
        /// <summary>
        /// Begin is called to tell the PrimitiveBatch what kind of primitives will be drawn, and to prepare the graphics card to render those primitives.
        /// Use camera.projectionMatrix and camera.transformMatrix if the batch should be in camera space.
        /// </summary>
        /// <param name="projection">The projection.</param>
        /// <param name="view">The view.</param>
        public void begin(ref Matrix projection, ref Matrix view)
        {
            Insist.isFalse(_hasBegun, "Invalid state. End must be called before Begin can be called again.");

            // tell our basic effect to begin.
            _basicEffect.Projection = projection;
            _basicEffect.View       = view;
            _basicEffect.CurrentTechnique.Passes[0].Apply();

            // flip the error checking boolean. It's now ok to call AddVertex, Flush, and End.
            _hasBegun = true;
        }
        /// <summary>
        /// Create a new empty bit set, with a given size.  This
        /// constructor reserves enough space to represent the integers
        /// from <code>0</code> to <code>nbits-1</code>.
        /// </summary>
        /// <param name="nbits">nbits the initial size of the bit set</param>
        public BitSet(int nbits)
        {
            Insist.isFalse(nbits < 0, "nbits may not be negative");

            var length = (uint)nbits >> 6;

            if ((nbits & LONG_MASK) != 0)
            {
                length++;
            }
            bits = new long[length];
        }
Exemple #6
0
        /// <summary>
        /// Submit a text string of sprites for drawing in the current batch.
        /// </summary>
        /// <param name="batcher">Batcher.</param>
        /// <param name="font">Font.</param>
        /// <param name="text">Text.</param>
        /// <param name="position">Position.</param>
        /// <param name="color">Color.</param>
        /// <param name="rotation">Rotation.</param>
        /// <param name="origin">Origin.</param>
        /// <param name="scale">Scale.</param>
        /// <param name="effects">Effects.</param>
        /// <param name="layerDepth">Layer depth.</param>
        public static void drawString(this Batcher batcher, IFont font, StringBuilder text, Vector2 position, Color color,
                                      float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
        {
            Insist.isFalse(text == null);

            if (text.Length == 0)
            {
                return;
            }

            font.drawInto(batcher, text, position, color, rotation, origin, scale, effects, layerDepth);
        }
Exemple #7
0
        /// <summary>
        /// adds an Entity to the Scene's Entities list
        /// </summary>
        /// <param name="entity">The Entity to add</param>
        public Entity addEntity(Entity entity)
        {
            Insist.isFalse(entities.contains(entity), "You are attempting to add the same entity to a scene twice: {0}", entity);
            entities.add(entity);
            entity.scene = this;

            for (var i = 0; i < entity.transform.childCount; i++)
            {
                addEntity(entity.transform.getChild(i).entity);
            }

            return(entity);
        }
        void addToRenderLayerList(IRenderable component, int renderLayer)
        {
            var list = componentsWithRenderLayer(renderLayer);

            Insist.isFalse(list.contains(component), "Component renderLayer list already contains this component");

            list.add(component);
            if (!_unsortedRenderLayers.Contains(renderLayer))
            {
                _unsortedRenderLayers.Add(renderLayer);
            }
            _componentsNeedSort = true;
        }
        public static void drawString(this Batcher batcher, NezSpriteFont spriteFont, string text, Vector2 position, Color color, float rotation,
                                      Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
        {
            Insist.isFalse(text == null);

            if (text.Length == 0)
            {
                return;
            }

            var source = new FontCharacterSource(text);

            spriteFont.drawInto(batcher, ref source, position, color, rotation, origin, scale, effects, layerDepth);
        }
Exemple #10
0
        internal void begin()
        {
            Insist.isFalse(_renderers.length == 0, "Scene has begun with no renderer. At least one renderer must be present before beginning a scene.");
            Physics.reset();

            // prep our render textures
            updateResolutionScaler();
            Core.graphicsDevice.setRenderTarget(_sceneRenderTarget);

            if (entityProcessors != null)
            {
                entityProcessors.begin();
            }
            Core.emitter.addObserver(CoreEvents.GraphicsDeviceReset, onGraphicsDeviceReset);

            _didSceneBegin = true;
            onStart();
        }
        public void begin(BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState,
                          Effect effect, Matrix transformationMatrix, bool disableBatching)
        {
            Insist.isFalse(_beginCalled, "Begin has been called before calling End after the last call to Begin. Begin cannot be called again until End has been successfully called.");
            _beginCalled = true;

            _blendState        = blendState ?? BlendState.AlphaBlend;
            _samplerState      = samplerState ?? Core.defaultSamplerState;
            _depthStencilState = depthStencilState ?? DepthStencilState.None;
            _rasterizerState   = rasterizerState ?? RasterizerState.CullCounterClockwise;

            _customEffect    = effect;
            _transformMatrix = transformationMatrix;
            _disableBatching = disableBatching;

            if (_disableBatching)
            {
                prepRenderState();
            }
        }
 /// <summary>
 /// gets all the colliders that fall within the specified circle
 /// </summary>
 /// <returns>the number of Colliders returned</returns>
 /// <param name="center">Center.</param>
 /// <param name="radius">Radius.</param>
 /// <param name="results">Results.</param>
 /// <param name="layerMask">Layer mask.</param>
 public static int overlapCircleAll(Vector2 center, float radius, Collider[] results, int layerMask = allLayers)
 {
     Insist.isFalse(results.Length == 0, "An empty results array was passed in. No results will ever be returned.");
     return(_spatialHash.overlapCircle(center, radius, results, layerMask));
 }
 /// <summary>
 /// gets all the colliders that fall within the specified rect
 /// </summary>
 /// <returns>the number of Colliders returned</returns>
 /// <param name="rect">Rect.</param>
 /// <param name="results">Results.</param>
 /// <param name="layerMask">Layer mask.</param>
 public static int overlapRectangleAll(ref RectangleF rect, Collider[] results, int layerMask = allLayers)
 {
     Insist.isFalse(results.Length == 0, "An empty results array was passed in. No results will ever be returned.");
     return(_spatialHash.overlapRectangle(ref rect, results, layerMask));
 }
 /// <summary>
 /// casts a line through the spatial hash and fills the hits array up with any colliders that the line hits
 /// </summary>
 /// <returns>The all.</returns>
 /// <param name="start">Start.</param>
 /// <param name="end">End.</param>
 /// <param name="hits">Hits.</param>
 /// <param name="layerMask">Layer mask.</param>
 public static int linecastAll(Vector2 start, Vector2 end, RaycastHit[] hits, int layerMask = allLayers)
 {
     Insist.isFalse(hits.Length == 0, "An empty hits array was passed in. No hits will ever be returned.");
     return(_spatialHash.linecast(start, end, hits, layerMask));
 }