Commits

Michael Ludwig  committed bb2899b

Rough out influence specifying components.

  • Participants
  • Parent commits fc9ff7d

Comments (0)

Files changed (7)

File ferox-scene/src/main/java/com/ferox/scene/EntitySetComponent.java

     
     protected EntitySetComponent() { }
     
-    protected boolean contains(int entityId) {
+    protected boolean containsInternal(int entityId) {
         final int[] ids = firstCache.getIndexedData();
         final int index = getIndex() * SCALE;
         
         }
     }
     
-    protected void put(int entityId) {
+    protected void putInternal(int entityId) {
         int[] ids = firstCache.getIndexedData();
         int index = getIndex() * SCALE;
         
         }
     }
     
-    protected void remove(int entityId) {
+    protected void removeInternal(int entityId) {
         int index = getIndex() * SCALE;
         int[] ids = firstCache.getIndexedData();
         
         }
     }
     
-    protected boolean remove(int entityId, int[] array, int from, int to) {
+    private boolean remove(int entityId, int[] array, int from, int to) {
         int index = Arrays.binarySearch(array, from, to, entityId);
         if (index >= 0) {
             // found it in this array
         }
     }
     
-    protected void clear() {
+    protected void clearInternal() {
         int index = getIndex() * SCALE;
 
         // reset cache counts to 0, and null the second cache

File ferox-scene/src/main/java/com/ferox/scene/Influence.java

-package com.ferox.scene;
-
-import java.util.Set;
-
-import com.ferox.entity2.Entity;
-import com.ferox.entity2.TypedComponent;
-import com.ferox.math.bounds.ReadOnlyAxisAlignedBox;
-
-// FIXME: does it make more sense to set this on the actor,
-// or the things that can be acted upon?
-// e.g. say a renderable claims it must or cannot be influenced by a light?
-public class Influence extends TypedComponent<Influence> {
-    private final ReadOnlyAxisAlignedBox bounds;
-    private float radius;
-    
-    private final Set<Entity> exclude;
-    private final Set<Entity> limitTo;
-    
-    public Influence() {
-        super(null, false);
-        // FIXME:
-    }
-    
-    public Influence(Influence clone) {
-        super(clone, true);
-        // FIXME:
-    }
-    //FIXME: Influences will be a limitTo-only component and is added to the actor
-    // FIXME: Add a NotInfluenced that is exclude-only and is added to the acted-on
-
-}

File ferox-scene/src/main/java/com/ferox/scene/InfluenceBounds.java

-package com.ferox.scene;
-
-public class InfluenceBounds {
-    // FIXME: sphere or aabb bounds?
-}

File ferox-scene/src/main/java/com/ferox/scene/InfluenceRegion.java

+package com.ferox.scene;
+
+import com.ferox.math.Const;
+import com.ferox.math.bounds.AxisAlignedBox;
+import com.ferox.math.entreri.AxisAlignedBoxProperty;
+import com.lhkbob.entreri.ComponentData;
+import com.lhkbob.entreri.TypeId;
+import com.lhkbob.entreri.Unmanaged;
+import com.lhkbob.entreri.property.BooleanProperty;
+
+public final class InfluenceRegion extends ComponentData<InfluenceRegion> {
+    /**
+     * TypeId for InfluenceRegion component type.
+     */
+    public static final TypeId<InfluenceRegion> ID = TypeId.get(InfluenceRegion.class);
+    
+    private AxisAlignedBoxProperty bounds;
+    private BooleanProperty negate;
+    
+    @Unmanaged
+    private final AxisAlignedBox boundsCache = new AxisAlignedBox();
+    
+    private InfluenceRegion() { }
+    
+    public @Const AxisAlignedBox getBounds() {
+        return boundsCache;
+    }
+    
+    public InfluenceRegion setBounds(@Const AxisAlignedBox bounds) {
+        if (bounds == null)
+            throw new NullPointerException("Bounds cannot be null");
+        boundsCache.set(bounds);
+        this.bounds.set(bounds, getIndex());
+        return this;
+    }
+    
+    public boolean isNegated() {
+        return negate.get(getIndex(), 0);
+    }
+    
+    public InfluenceRegion setNegated(boolean negate) {
+        this.negate.set(negate, getIndex(), 0);
+        return this;
+    }
+    
+    @Override
+    protected void onSet(int index) {
+        bounds.get(index, boundsCache);
+    }
+}

File ferox-scene/src/main/java/com/ferox/scene/Influences.java

+package com.ferox.scene;
+
+import com.lhkbob.entreri.Entity;
+import com.lhkbob.entreri.TypeId;
+
+public final class Influences extends EntitySetComponent<Influences> {
+    /**
+     * TypeId for Influences Component type
+     */
+    public static final TypeId<Influences> ID = TypeId.get(Influences.class);
+    
+    private Influences() { }
+    
+    public Influences setInfluenced(Entity e, boolean canInfluence) {
+        return setInfluenced(e.getId(), canInfluence);
+    }
+    
+    public Influences setInfluenced(int entityId, boolean canInfluence) {
+        if (canInfluence)
+            putInternal(entityId);
+        else
+            removeInternal(entityId);
+        return this;
+    }
+    
+    public boolean canInfluence(Entity e) {
+        return canInfluence(e.getId());
+    }
+    
+    public boolean canInfluence(int entityId) {
+        return containsInternal(entityId);
+    }
+}

File ferox-scene/src/main/java/com/ferox/scene/Material.java

      * @throws NullPointerException if e is null
      */
     public boolean isLit(Entity e) {
-        return contains(e.getId());
+        return containsInternal(e.getId());
     }
 
     /**
      *         this entity
      */
     public boolean isLit(int entityId) {
-        return contains(entityId);
+        return containsInternal(entityId);
     }
 
     /**
     @SuppressWarnings("unchecked")
     public T setLit(int entityId, boolean lit) {
         if (lit)
-            put(entityId);
+            putInternal(entityId);
         else
-            remove(entityId);
+            removeInternal(entityId);
         return (T) this;
     }
 
      */
     @SuppressWarnings("unchecked")
     public T resetLightInfluences() {
-        clear();
+        clearInternal();
         return (T) this;
     }
 }

File ferox-scene/src/main/java/com/ferox/scene/Renderable.java

      * @throws NullPointerException if f is null
      */
     public boolean isVisible(Entity e) {
-        return contains(e.getId());
+        return containsInternal(e.getId());
     }
 
     /**
      * @return Whether or not this component's entity is visible to entityId
      */
     public boolean isVisible(int entityId) {
-        return contains(entityId);
+        return containsInternal(entityId);
     }
 
     /**
      */
     public Renderable setVisible(int entityId, boolean pv) {
         if (pv)
-            put(entityId);
+            putInternal(entityId);
         else
-            remove(entityId);
+            removeInternal(entityId);
         return this;
     }
 
      * @return This component, for chaining purposes
      */
     public Renderable resetVisibility() {
-        clear();
+        clearInternal();
         return this;
     }