Class Attributes

java.lang.Object
gaiasky.util.gdx.shader.attribute.Attributes
All Implemented Interfaces:
Comparable<Attributes>, Iterable<Attribute>, Comparator<Attribute>
Direct Known Subclasses:
Environment, Material

public class Attributes extends Object implements Iterable<Attribute>, Comparator<Attribute>, Comparable<Attributes>
  • Field Details

    • attributes

      protected final com.badlogic.gdx.utils.Array<Attribute> attributes
    • mask

      protected Bits mask
    • sorted

      protected boolean sorted
  • Constructor Details

    • Attributes

      public Attributes()
  • Method Details

    • sort

      public final void sort()
      Sort the attributes by their ID
    • getMask

      public final Bits getMask()
      Returns:
      Bitwise mask of the ID's of all the containing attributes
    • get

      public final Attribute get(int index)
      Example usage: ((BlendingAttribute)material.get(BlendingAttribute.ID)).sourceFunction;
      Returns:
      The attribute (which can safely be cast) if any, otherwise null
    • get

      public final <T extends Attribute> T get(Class<T> clazz, int index)
      Example usage: ((BlendingAttribute)material.get(BlendingAttribute.ID)).sourceFunction;
      Returns:
      The attribute if any, otherwise null
    • clear

      public void clear()
      Removes all attributes
    • size

      public int size()
      Returns:
      The amount of attributes this material contains.
    • set

      public final void set(Attribute attribute)
      Add an attribute to this material. If the material already contains an attribute of the same type it is overwritten.
    • set

      public final void set(Attribute attribute1, Attribute attribute2)
      Add multiple attributes to this material. If the material already contains an attribute of the same type it is overwritten.
    • set

      public final void set(Attribute attribute1, Attribute attribute2, Attribute attribute3)
      Add multiple attributes to this material. If the material already contains an attribute of the same type it is overwritten.
    • set

      public final void set(Attribute attribute1, Attribute attribute2, Attribute attribute3, Attribute attribute4)
      Add multiple attributes to this material. If the material already contains an attribute of the same type it is overwritten.
    • set

      public final void set(Attribute... attributes)
      Add an array of attributes to this material. If the material already contains an attribute of the same type it is overwritten.
    • set

      public final void set(Iterable<Attribute> attributes)
      Add an array of attributes to this material. If the material already contains an attribute of the same type it is overwritten.
    • remove

      public final void remove(Bits mask)
      Removes the attribute from the material, i.e.: material.remove(BlendingAttribute.ID); Can also be used to remove multiple attributes also, i.e. remove(AttributeA.ID | AttributeB.ID);
    • remove

      public final void remove(int index)
    • has

      public final boolean has(Bits mask)
      Returns:
      True if this collection has the specified attribute, i.e. attributes.has(ColorAttribute.Diffuse); Or when multiple attribute types are specified, true if this collection has all specified attributes, i.e. attributes.has(out, ColorAttribute.Diffuse | ColorAttribute.Specular | TextureAttribute.Diffuse);
    • has

      public final boolean has(int index)
    • indexOf

      protected int indexOf(int index)
      Returns:
      the index of the attribute with the specified type or negative if not available.
    • same

      public final boolean same(Attributes other, boolean compareValues)
      Check if this collection has the same attributes as the other collection. If compareValues is true, it also compares the values of each attribute.
      Parameters:
      compareValues - True to compare attribute values, false to only compare attribute types
      Returns:
      True if this collection contains the same attributes (and optionally attribute values) as the other.
    • same

      public final boolean same(Attributes other)
      Returns:
      True if this collection contains the same attributes (but not values) as the other.
    • compare

      public final int compare(Attribute arg0, Attribute arg1)
      Used for sorting attributes by type (not by value)
      Specified by:
      compare in interface Comparator<Attribute>
    • iterator

      public final Iterator<Attribute> iterator()
      Used for iterating through the attributes
      Specified by:
      iterator in interface Iterable<Attribute>
    • attributesHash

      public int attributesHash()
      Returns:
      A hash code based on only the attribute values, which might be different compared to hashCode() because the latter might include other properties as well, i.e. the material id.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Specified by:
      equals in interface Comparator<Attribute>
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(Attributes other)
      Specified by:
      compareTo in interface Comparable<Attributes>