Commits

Michael Ludwig committed 421d47b

Rename controllers to be more descriptive.

  • Participants
  • Parent commits fe82f9f

Comments (0)

Files changed (8)

ferox-scene/src/main/java/com/ferox/scene/controller/BuildVisibilityIndexTask.java

+/*
+ * Ferox, a graphics and game library in Java
+ *
+ * Copyright (c) 2012, Michael Ludwig
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ *     Redistributions of source code must retain the above copyright notice,
+ *         this list of conditions and the following disclaimer.
+ *     Redistributions in binary form must reproduce the above copyright notice,
+ *         this list of conditions and the following disclaimer in the
+ *         documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.ferox.scene.controller;
+
+import java.util.Collections;
+import java.util.Set;
+
+import com.ferox.math.AxisAlignedBox;
+import com.ferox.math.bounds.BoundedSpatialIndex;
+import com.ferox.math.bounds.SpatialIndex;
+import com.ferox.scene.Renderable;
+import com.lhkbob.entreri.ComponentData;
+import com.lhkbob.entreri.ComponentIterator;
+import com.lhkbob.entreri.Entity;
+import com.lhkbob.entreri.EntitySystem;
+import com.lhkbob.entreri.task.Job;
+import com.lhkbob.entreri.task.ParallelAware;
+import com.lhkbob.entreri.task.Task;
+
+public class BuildVisibilityIndexTask implements Task, ParallelAware {
+    private final SpatialIndex<Entity> index;
+
+    private AxisAlignedBox worldBounds;
+
+    // could be local scope but we can save GC work
+    private Renderable renderable;
+    private ComponentIterator iterator;
+
+    public BuildVisibilityIndexTask(SpatialIndex<Entity> index) {
+        this.index = index;
+    }
+
+    public void report(BoundsResult result) {
+        worldBounds = result.getBounds();
+    }
+
+    @Override
+    public void reset(EntitySystem system) {
+        if (renderable == null) {
+            renderable = system.createDataInstance(Renderable.class);
+            iterator = new ComponentIterator(system).addRequired(renderable);
+        }
+
+        index.clear(true);
+        worldBounds = null;
+        iterator.reset();
+    }
+
+    @Override
+    public Task process(EntitySystem system, Job job) {
+        if (index instanceof BoundedSpatialIndex) {
+            ((BoundedSpatialIndex<Entity>) index).setExtent(worldBounds);
+        }
+
+        while (iterator.next()) {
+            index.add(renderable.getEntity(), renderable.getWorldBounds());
+        }
+
+        // send the built index to everyone listened
+        job.report(new SpatialIndexResult(index));
+
+        return null;
+    }
+
+    @Override
+    public Set<Class<? extends ComponentData<?>>> getAccessedComponents() {
+        return Collections.<Class<? extends ComponentData<?>>> singleton(Renderable.class);
+    }
+
+    @Override
+    public boolean isEntitySetModified() {
+        return false;
+    }
+}

ferox-scene/src/main/java/com/ferox/scene/controller/CameraController.java

-/*
- * Ferox, a graphics and game library in Java
- *
- * Copyright (c) 2012, Michael Ludwig
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *     Redistributions of source code must retain the above copyright notice,
- *         this list of conditions and the following disclaimer.
- *     Redistributions in binary form must reproduce the above copyright notice,
- *         this list of conditions and the following disclaimer in the
- *         documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.ferox.scene.controller;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import com.ferox.math.Matrix4;
-import com.ferox.math.Vector3;
-import com.ferox.math.bounds.Frustum;
-import com.ferox.scene.Camera;
-import com.ferox.scene.Transform;
-import com.lhkbob.entreri.ComponentData;
-import com.lhkbob.entreri.ComponentIterator;
-import com.lhkbob.entreri.EntitySystem;
-import com.lhkbob.entreri.task.Job;
-import com.lhkbob.entreri.task.ParallelAware;
-import com.lhkbob.entreri.task.Task;
-
-/**
- * CameraController is a controller that synchronizes a {@link Camera}'s Frustum
- * location and orientation with an attached {@link Transform}. When run, all
- * entities with a Camera and Transform will have the Camera's Frustum's
- * orientation equal that stored in the transform.
- * 
- * @author Michael Ludwig
- */
-public class CameraController implements Task, ParallelAware {
-    private static final Set<Class<? extends ComponentData<?>>> COMPONENTS;
-    static {
-        Set<Class<? extends ComponentData<?>>> types = new HashSet<Class<? extends ComponentData<?>>>();
-        types.add(Camera.class);
-        types.add(Transform.class);
-        COMPONENTS = Collections.unmodifiableSet(types);
-    }
-
-    // could exist in local scope but we can prevent extra garbage this way
-    private Camera camera;
-    private Transform transform;
-    private ComponentIterator iterator;
-
-    @Override
-    public void reset(EntitySystem system) {
-        if (camera == null) {
-            camera = system.createDataInstance(Camera.class);
-            transform = system.createDataInstance(Transform.class);
-            iterator = new ComponentIterator(system).addRequired(camera)
-                                                    .addRequired(transform);
-        }
-
-        iterator.reset();
-    }
-
-    @Override
-    public Task process(EntitySystem system, Job job) {
-        while (iterator.next()) {
-            double aspect = camera.getSurface().getWidth() / (double) camera.getSurface()
-                                                                            .getHeight();
-            Frustum f = new Frustum(camera.getFieldOfView(),
-                                    aspect,
-                                    camera.getNearZDistance(),
-                                    camera.getFarZDistance());
-
-            Matrix4 m = transform.getMatrix();
-            f.setOrientation(new Vector3(m.m03, m.m13, m.m23), new Vector3(m.m02,
-                                                                           m.m12,
-                                                                           m.m22),
-                             new Vector3(m.m01, m.m11, m.m21));
-
-            job.report(new FrustumResult(camera.getComponent(), f));
-        }
-
-        return null;
-    }
-
-    @Override
-    public Set<Class<? extends ComponentData<?>>> getAccessedComponents() {
-        return COMPONENTS;
-    }
-
-    @Override
-    public boolean isEntitySetModified() {
-        return false;
-    }
-}

ferox-scene/src/main/java/com/ferox/scene/controller/ComputeCameraFrustumTask.java

+/*
+ * Ferox, a graphics and game library in Java
+ *
+ * Copyright (c) 2012, Michael Ludwig
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ *     Redistributions of source code must retain the above copyright notice,
+ *         this list of conditions and the following disclaimer.
+ *     Redistributions in binary form must reproduce the above copyright notice,
+ *         this list of conditions and the following disclaimer in the
+ *         documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.ferox.scene.controller;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import com.ferox.math.Matrix4;
+import com.ferox.math.Vector3;
+import com.ferox.math.bounds.Frustum;
+import com.ferox.scene.Camera;
+import com.ferox.scene.Transform;
+import com.lhkbob.entreri.ComponentData;
+import com.lhkbob.entreri.ComponentIterator;
+import com.lhkbob.entreri.EntitySystem;
+import com.lhkbob.entreri.task.Job;
+import com.lhkbob.entreri.task.ParallelAware;
+import com.lhkbob.entreri.task.Task;
+
+/**
+ * CameraController is a controller that synchronizes a {@link Camera}'s Frustum
+ * location and orientation with an attached {@link Transform}. When run, all
+ * entities with a Camera and Transform will have the Camera's Frustum's
+ * orientation equal that stored in the transform.
+ * 
+ * @author Michael Ludwig
+ */
+public class ComputeCameraFrustumTask implements Task, ParallelAware {
+    private static final Set<Class<? extends ComponentData<?>>> COMPONENTS;
+    static {
+        Set<Class<? extends ComponentData<?>>> types = new HashSet<Class<? extends ComponentData<?>>>();
+        types.add(Camera.class);
+        types.add(Transform.class);
+        COMPONENTS = Collections.unmodifiableSet(types);
+    }
+
+    // could exist in local scope but we can prevent extra garbage this way
+    private Camera camera;
+    private Transform transform;
+    private ComponentIterator iterator;
+
+    @Override
+    public void reset(EntitySystem system) {
+        if (camera == null) {
+            camera = system.createDataInstance(Camera.class);
+            transform = system.createDataInstance(Transform.class);
+            iterator = new ComponentIterator(system).addRequired(camera)
+                                                    .addRequired(transform);
+        }
+
+        iterator.reset();
+    }
+
+    @Override
+    public Task process(EntitySystem system, Job job) {
+        while (iterator.next()) {
+            double aspect = camera.getSurface().getWidth() / (double) camera.getSurface()
+                                                                            .getHeight();
+            Frustum f = new Frustum(camera.getFieldOfView(),
+                                    aspect,
+                                    camera.getNearZDistance(),
+                                    camera.getFarZDistance());
+
+            Matrix4 m = transform.getMatrix();
+            f.setOrientation(new Vector3(m.m03, m.m13, m.m23), new Vector3(m.m02,
+                                                                           m.m12,
+                                                                           m.m22),
+                             new Vector3(m.m01, m.m11, m.m21));
+
+            job.report(new FrustumResult(camera.getComponent(), f));
+        }
+
+        return null;
+    }
+
+    @Override
+    public Set<Class<? extends ComponentData<?>>> getAccessedComponents() {
+        return COMPONENTS;
+    }
+
+    @Override
+    public boolean isEntitySetModified() {
+        return false;
+    }
+}

ferox-scene/src/main/java/com/ferox/scene/controller/ComputePVSTask.java

+/*
+ * Ferox, a graphics and game library in Java
+ *
+ * Copyright (c) 2012, Michael Ludwig
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ *     Redistributions of source code must retain the above copyright notice,
+ *         this list of conditions and the following disclaimer.
+ *     Redistributions in binary form must reproduce the above copyright notice,
+ *         this list of conditions and the following disclaimer in the
+ *         documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.ferox.scene.controller;
+
+import java.util.Collections;
+import java.util.Set;
+
+import com.ferox.math.AxisAlignedBox;
+import com.ferox.math.Const;
+import com.ferox.math.bounds.QueryCallback;
+import com.ferox.math.bounds.SpatialIndex;
+import com.ferox.scene.Renderable;
+import com.ferox.util.Bag;
+import com.lhkbob.entreri.ComponentData;
+import com.lhkbob.entreri.Entity;
+import com.lhkbob.entreri.EntitySystem;
+import com.lhkbob.entreri.task.Job;
+import com.lhkbob.entreri.task.ParallelAware;
+import com.lhkbob.entreri.task.Task;
+
+public class ComputePVSTask implements Task, ParallelAware {
+    // results
+    private final Bag<FrustumResult> frustums;
+    private SpatialIndex<Entity> index;
+
+    public ComputePVSTask() {
+        frustums = new Bag<FrustumResult>();
+    }
+
+    public void report(FrustumResult result) {
+        frustums.add(result);
+    }
+
+    public void report(SpatialIndexResult result) {
+        index = result.getIndex();
+    }
+
+    @Override
+    public void reset(EntitySystem system) {
+        frustums.clear(true);
+        index = null;
+    }
+
+    @Override
+    public Task process(EntitySystem system, Job job) {
+        if (index != null) {
+            for (FrustumResult f : frustums) {
+                VisibilityCallback query = new VisibilityCallback(system);
+                index.query(f.getFrustum(), query);
+
+                // sort the PVS by entity id before reporting it so that
+                // iteration over the bag has more optimal cache behavior when
+                // accessing entity properties
+                query.pvs.sort();
+                job.report(new PVSResult(f.getSource(), f.getFrustum(), query.pvs));
+            }
+        }
+
+        return null;
+    }
+
+    private static class VisibilityCallback implements QueryCallback<Entity> {
+        private final Renderable renderable;
+
+        private final Bag<Entity> pvs;
+
+        /**
+         * Create a new VisibilityCallback that set each discovered Entity with
+         * a Transform's visibility to true for the given entity,
+         * <tt>camera</tt>.
+         * 
+         * @param camera The Entity that will be flagged as visible
+         * @throws NullPointerException if camera is null
+         */
+        public VisibilityCallback(EntitySystem system) {
+            renderable = system.createDataInstance(Renderable.class);
+            pvs = new Bag<Entity>();
+        }
+
+        @Override
+        public void process(Entity r, @Const AxisAlignedBox bounds) {
+            // using ComponentData to query existence is faster
+            // than pulling in the actual Component
+            if (r.get(renderable)) {
+                pvs.add(r);
+            }
+        }
+    }
+
+    @Override
+    public Set<Class<? extends ComponentData<?>>> getAccessedComponents() {
+        return Collections.<Class<? extends ComponentData<?>>> singleton(Renderable.class);
+    }
+
+    @Override
+    public boolean isEntitySetModified() {
+        return false;
+    }
+}

ferox-scene/src/main/java/com/ferox/scene/controller/SpatialIndexController.java

-/*
- * Ferox, a graphics and game library in Java
- *
- * Copyright (c) 2012, Michael Ludwig
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *     Redistributions of source code must retain the above copyright notice,
- *         this list of conditions and the following disclaimer.
- *     Redistributions in binary form must reproduce the above copyright notice,
- *         this list of conditions and the following disclaimer in the
- *         documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.ferox.scene.controller;
-
-import java.util.Collections;
-import java.util.Set;
-
-import com.ferox.math.AxisAlignedBox;
-import com.ferox.math.bounds.BoundedSpatialIndex;
-import com.ferox.math.bounds.SpatialIndex;
-import com.ferox.scene.Renderable;
-import com.lhkbob.entreri.ComponentData;
-import com.lhkbob.entreri.ComponentIterator;
-import com.lhkbob.entreri.Entity;
-import com.lhkbob.entreri.EntitySystem;
-import com.lhkbob.entreri.task.Job;
-import com.lhkbob.entreri.task.ParallelAware;
-import com.lhkbob.entreri.task.Task;
-
-public class SpatialIndexController implements Task, ParallelAware {
-    private final SpatialIndex<Entity> index;
-
-    private AxisAlignedBox worldBounds;
-
-    // could be local scope but we can save GC work
-    private Renderable renderable;
-    private ComponentIterator iterator;
-
-    public SpatialIndexController(SpatialIndex<Entity> index) {
-        this.index = index;
-    }
-
-    public void report(BoundsResult result) {
-        worldBounds = result.getBounds();
-    }
-
-    @Override
-    public void reset(EntitySystem system) {
-        if (renderable == null) {
-            renderable = system.createDataInstance(Renderable.class);
-            iterator = new ComponentIterator(system).addRequired(renderable);
-        }
-
-        index.clear(true);
-        worldBounds = null;
-        iterator.reset();
-    }
-
-    @Override
-    public Task process(EntitySystem system, Job job) {
-        if (index instanceof BoundedSpatialIndex) {
-            ((BoundedSpatialIndex<Entity>) index).setExtent(worldBounds);
-        }
-
-        while (iterator.next()) {
-            index.add(renderable.getEntity(), renderable.getWorldBounds());
-        }
-
-        // send the built index to everyone listened
-        job.report(new SpatialIndexResult(index));
-
-        return null;
-    }
-
-    @Override
-    public Set<Class<? extends ComponentData<?>>> getAccessedComponents() {
-        return Collections.<Class<? extends ComponentData<?>>> singleton(Renderable.class);
-    }
-
-    @Override
-    public boolean isEntitySetModified() {
-        return false;
-    }
-}

ferox-scene/src/main/java/com/ferox/scene/controller/UpdateWorldBoundsTask.java

+/*
+ * Ferox, a graphics and game library in Java
+ *
+ * Copyright (c) 2012, Michael Ludwig
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ *     Redistributions of source code must retain the above copyright notice,
+ *         this list of conditions and the following disclaimer.
+ *     Redistributions in binary form must reproduce the above copyright notice,
+ *         this list of conditions and the following disclaimer in the
+ *         documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.ferox.scene.controller;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import com.ferox.math.AxisAlignedBox;
+import com.ferox.scene.Renderable;
+import com.ferox.scene.Transform;
+import com.lhkbob.entreri.ComponentData;
+import com.lhkbob.entreri.ComponentIterator;
+import com.lhkbob.entreri.EntitySystem;
+import com.lhkbob.entreri.task.Job;
+import com.lhkbob.entreri.task.ParallelAware;
+import com.lhkbob.entreri.task.Task;
+
+public class UpdateWorldBoundsTask implements Task, ParallelAware {
+    private static final Set<Class<? extends ComponentData<?>>> COMPONENTS;
+    static {
+        Set<Class<? extends ComponentData<?>>> types = new HashSet<Class<? extends ComponentData<?>>>();
+        types.add(Renderable.class);
+        types.add(Transform.class);
+        COMPONENTS = Collections.unmodifiableSet(types);
+    }
+
+    // cached local instances
+    private Renderable renderable;
+    private Transform transform;
+    private ComponentIterator iterator;
+
+    @Override
+    public void reset(EntitySystem system) {
+        if (renderable == null) {
+            renderable = system.createDataInstance(Renderable.class);
+            transform = system.createDataInstance(Transform.class);
+            iterator = new ComponentIterator(system).addRequired(renderable)
+                                                    .addRequired(transform);
+        }
+
+        iterator.reset();
+    }
+
+    @Override
+    public Task process(EntitySystem system, Job job) {
+        AxisAlignedBox worldBounds = new AxisAlignedBox();
+        AxisAlignedBox sceneBounds = new AxisAlignedBox();
+        boolean first = true;
+
+        while (iterator.next()) {
+            worldBounds.transform(renderable.getLocalBounds(), transform.getMatrix());
+            renderable.setWorldBounds(worldBounds);
+
+            if (first) {
+                sceneBounds.set(worldBounds);
+            } else {
+                sceneBounds.union(worldBounds);
+            }
+        }
+
+        job.report(new BoundsResult(sceneBounds));
+
+        return null;
+    }
+
+    @Override
+    public Set<Class<? extends ComponentData<?>>> getAccessedComponents() {
+        return COMPONENTS;
+    }
+
+    @Override
+    public boolean isEntitySetModified() {
+        return false;
+    }
+
+}

ferox-scene/src/main/java/com/ferox/scene/controller/VisibilityController.java

-/*
- * Ferox, a graphics and game library in Java
- *
- * Copyright (c) 2012, Michael Ludwig
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *     Redistributions of source code must retain the above copyright notice,
- *         this list of conditions and the following disclaimer.
- *     Redistributions in binary form must reproduce the above copyright notice,
- *         this list of conditions and the following disclaimer in the
- *         documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.ferox.scene.controller;
-
-import java.util.Collections;
-import java.util.Set;
-
-import com.ferox.math.AxisAlignedBox;
-import com.ferox.math.Const;
-import com.ferox.math.bounds.QueryCallback;
-import com.ferox.math.bounds.SpatialIndex;
-import com.ferox.scene.Renderable;
-import com.ferox.util.Bag;
-import com.lhkbob.entreri.ComponentData;
-import com.lhkbob.entreri.Entity;
-import com.lhkbob.entreri.EntitySystem;
-import com.lhkbob.entreri.task.Job;
-import com.lhkbob.entreri.task.ParallelAware;
-import com.lhkbob.entreri.task.Task;
-
-public class VisibilityController implements Task, ParallelAware {
-    // results
-    private final Bag<FrustumResult> frustums;
-    private SpatialIndex<Entity> index;
-
-    public VisibilityController() {
-        frustums = new Bag<FrustumResult>();
-    }
-
-    public void report(FrustumResult result) {
-        frustums.add(result);
-    }
-
-    public void report(SpatialIndexResult result) {
-        index = result.getIndex();
-    }
-
-    @Override
-    public void reset(EntitySystem system) {
-        frustums.clear(true);
-        index = null;
-    }
-
-    @Override
-    public Task process(EntitySystem system, Job job) {
-        if (index != null) {
-            for (FrustumResult f : frustums) {
-                VisibilityCallback query = new VisibilityCallback(system);
-                index.query(f.getFrustum(), query);
-
-                // sort the PVS by entity id before reporting it so that
-                // iteration over the bag has more optimal cache behavior when
-                // accessing entity properties
-                query.pvs.sort();
-                job.report(new PVSResult(f.getSource(), f.getFrustum(), query.pvs));
-            }
-        }
-
-        return null;
-    }
-
-    private static class VisibilityCallback implements QueryCallback<Entity> {
-        private final Renderable renderable;
-
-        private final Bag<Entity> pvs;
-
-        /**
-         * Create a new VisibilityCallback that set each discovered Entity with
-         * a Transform's visibility to true for the given entity,
-         * <tt>camera</tt>.
-         * 
-         * @param camera The Entity that will be flagged as visible
-         * @throws NullPointerException if camera is null
-         */
-        public VisibilityCallback(EntitySystem system) {
-            renderable = system.createDataInstance(Renderable.class);
-            pvs = new Bag<Entity>();
-        }
-
-        @Override
-        public void process(Entity r, @Const AxisAlignedBox bounds) {
-            // using ComponentData to query existence is faster
-            // than pulling in the actual Component
-            if (r.get(renderable)) {
-                pvs.add(r);
-            }
-        }
-    }
-
-    @Override
-    public Set<Class<? extends ComponentData<?>>> getAccessedComponents() {
-        return Collections.<Class<? extends ComponentData<?>>> singleton(Renderable.class);
-    }
-
-    @Override
-    public boolean isEntitySetModified() {
-        return false;
-    }
-}

ferox-scene/src/main/java/com/ferox/scene/controller/WorldBoundsController.java

-/*
- * Ferox, a graphics and game library in Java
- *
- * Copyright (c) 2012, Michael Ludwig
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *     Redistributions of source code must retain the above copyright notice,
- *         this list of conditions and the following disclaimer.
- *     Redistributions in binary form must reproduce the above copyright notice,
- *         this list of conditions and the following disclaimer in the
- *         documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.ferox.scene.controller;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import com.ferox.math.AxisAlignedBox;
-import com.ferox.scene.Renderable;
-import com.ferox.scene.Transform;
-import com.lhkbob.entreri.ComponentData;
-import com.lhkbob.entreri.ComponentIterator;
-import com.lhkbob.entreri.EntitySystem;
-import com.lhkbob.entreri.task.Job;
-import com.lhkbob.entreri.task.ParallelAware;
-import com.lhkbob.entreri.task.Task;
-
-public class WorldBoundsController implements Task, ParallelAware {
-    private static final Set<Class<? extends ComponentData<?>>> COMPONENTS;
-    static {
-        Set<Class<? extends ComponentData<?>>> types = new HashSet<Class<? extends ComponentData<?>>>();
-        types.add(Renderable.class);
-        types.add(Transform.class);
-        COMPONENTS = Collections.unmodifiableSet(types);
-    }
-
-    // cached local instances
-    private Renderable renderable;
-    private Transform transform;
-    private ComponentIterator iterator;
-
-    @Override
-    public void reset(EntitySystem system) {
-        if (renderable == null) {
-            renderable = system.createDataInstance(Renderable.class);
-            transform = system.createDataInstance(Transform.class);
-            iterator = new ComponentIterator(system).addRequired(renderable)
-                                                    .addRequired(transform);
-        }
-
-        iterator.reset();
-    }
-
-    @Override
-    public Task process(EntitySystem system, Job job) {
-        AxisAlignedBox worldBounds = new AxisAlignedBox();
-        AxisAlignedBox sceneBounds = new AxisAlignedBox();
-        boolean first = true;
-
-        while (iterator.next()) {
-            worldBounds.transform(renderable.getLocalBounds(), transform.getMatrix());
-            renderable.setWorldBounds(worldBounds);
-
-            if (first) {
-                sceneBounds.set(worldBounds);
-            } else {
-                sceneBounds.union(worldBounds);
-            }
-        }
-
-        job.report(new BoundsResult(sceneBounds));
-
-        return null;
-    }
-
-    @Override
-    public Set<Class<? extends ComponentData<?>>> getAccessedComponents() {
-        return COMPONENTS;
-    }
-
-    @Override
-    public boolean isEntitySetModified() {
-        return false;
-    }
-
-}