Skip to content

Commit

Permalink
Merge pull request #7 from TheDudeFromCI/quality-of-life-tweaks
Browse files Browse the repository at this point in the history
Quality of life tweaks
  • Loading branch information
TheDudeFromCI authored Jan 29, 2020
2 parents f9c2101 + 4a03a74 commit a538ba1
Show file tree
Hide file tree
Showing 43 changed files with 1,828 additions and 934 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class CullGameObjectsAction implements IPipelineAction
public class CullGameObjectsPipeline implements IPipelineAction
{
private final List<GameObject> gameObjects = new CopyOnWriteArrayList<>();

Expand All @@ -30,6 +30,6 @@ public void disableGameObject(GameObject gameObject)
@Override
public int getPriority()
{
return 40000;
return PipelineConstants.DISPOSE_GAMEOBJECTS;
}
}
19 changes: 12 additions & 7 deletions src/main/java/net/whg/we/main/GameObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import net.whg.we.util.IDisposable;

/**
Expand Down Expand Up @@ -129,11 +128,12 @@ public void removeBehavior(AbstractBehavior behavior)
* @return The behavior with the given superclass, or null if no matching
* behavior is found.
*/
public AbstractBehavior getBehavior(Class<? extends AbstractBehavior> behaviorType)
@SuppressWarnings("unchecked")
public <T> T getBehavior(Class<? extends T> behaviorType)
{
for (AbstractBehavior behavior : behaviors)
if (behaviorType.isAssignableFrom(behavior.getClass()))
return behavior;
return (T) behavior;

return null;
}
Expand All @@ -156,11 +156,16 @@ public List<AbstractBehavior> getBehaviors()
* - The type of behaviors to get.
* @return A list of behaviors with the given superclass.
*/
public List<AbstractBehavior> getBehaviors(Class<? extends AbstractBehavior> behaviorType)
@SuppressWarnings("unchecked")
public <T> List<T> getBehaviors(Class<? extends T> behaviorType)
{
return behaviors.stream()
.filter(behavior -> behaviorType.isAssignableFrom(behavior.getClass()))
.collect(Collectors.toList());
List<T> list = new ArrayList<>();

for (AbstractBehavior behavior : behaviors)
if (behaviorType.isAssignableFrom(behavior.getClass()))
list.add((T) behavior);

return list;
}

/**
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/net/whg/we/main/IPipelineAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,7 @@
* <p>
* Pipeline actions should also override the default priority level for loop
* actions to ensure pipeline actions occur in the desired order. Default
* priorities are:
* <ul>
* <li><i>Calculate Time Stamps</i> at <strong>-1000000</strong></li>
* <li><i>Physics Updates</i> at <strong>-10000</strong></li>
* <li><i>Updates</i> at <strong>0</strong></li>
* <li><i>Animation Updates</i> at <strong>10000</strong></li>
* <li><i>Late Updates</i> at <strong>20000</strong></li>
* <li><i>Rendering Solids</i> at <strong>30000</strong></li>
* <li><i>Rendering Transparents</i> at <strong>32500</strong></li>
* <li><i>Dispose GameObjects</i> at <strong>40000</strong></li>
* <li><i>End Frame</i> at <strong>1000000</strong></li>
* </ul>
* priorities are defined in the {@link PipelineConstants}.
*/
public interface IPipelineAction extends ILoopAction
{
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/net/whg/we/main/IUpdateable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public interface IUpdateable
{
/**
* Called once each frame to update this object.
*
* @param timer
* - The timer associated with the update pipeline. Used to retrieve delta
* times.
*/
void update();
void update(Timer timer);
}
248 changes: 0 additions & 248 deletions src/main/java/net/whg/we/main/Input.java

This file was deleted.

57 changes: 57 additions & 0 deletions src/main/java/net/whg/we/main/PhysicsPipeline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.whg.we.main;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
* The physics pipeline action is an action in charge of triggering physics
* updates each frame based on the physics framerate.
*/
public class PhysicsPipeline implements IPipelineAction
{
private final List<IFixedUpdateable> objects = new CopyOnWriteArrayList<>();
private final Timer timer;

/**
* Creates a new Physics pipeline action.
*
* @param timer
* - The timer to being this action to.
*/
public PhysicsPipeline(Timer timer)
{
this.timer = timer;
}

@Override
public void run()
{
while (timer.getPhysicsFrame() < timer.getIdealPhysicsFrame())
{
timer.incrementPhysicsFrame();

for (IFixedUpdateable obj : objects)
obj.fixedUpdate();
}
}

@Override
public void enableBehavior(AbstractBehavior behavior)
{
if (behavior instanceof IFixedUpdateable)
objects.add((IFixedUpdateable) behavior);
}

@Override
public void disableBehavior(AbstractBehavior behavior)
{
if (behavior instanceof IFixedUpdateable)
objects.remove((IFixedUpdateable) behavior);
}

@Override
public int getPriority()
{
return PipelineConstants.PHYSICS_UPDATES;
}
}
Loading

0 comments on commit a538ba1

Please sign in to comment.