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> /// 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); }
/// <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); }
/// <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]; }
/// <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); }
/// <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); }
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)); }