Skip to content

Commit a538ba1

Browse files
Merge pull request #7 from TheDudeFromCI/quality-of-life-tweaks
Quality of life tweaks
2 parents f9c2101 + 4a03a74 commit a538ba1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1828
-934
lines changed

src/main/java/net/whg/we/main/CullGameObjectsAction.java renamed to src/main/java/net/whg/we/main/CullGameObjectsPipeline.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.List;
44
import java.util.concurrent.CopyOnWriteArrayList;
55

6-
public class CullGameObjectsAction implements IPipelineAction
6+
public class CullGameObjectsPipeline implements IPipelineAction
77
{
88
private final List<GameObject> gameObjects = new CopyOnWriteArrayList<>();
99

@@ -30,6 +30,6 @@ public void disableGameObject(GameObject gameObject)
3030
@Override
3131
public int getPriority()
3232
{
33-
return 40000;
33+
return PipelineConstants.DISPOSE_GAMEOBJECTS;
3434
}
3535
}

src/main/java/net/whg/we/main/GameObject.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.List;
55
import java.util.UUID;
66
import java.util.concurrent.CopyOnWriteArrayList;
7-
import java.util.stream.Collectors;
87
import net.whg.we.util.IDisposable;
98

109
/**
@@ -129,11 +128,12 @@ public void removeBehavior(AbstractBehavior behavior)
129128
* @return The behavior with the given superclass, or null if no matching
130129
* behavior is found.
131130
*/
132-
public AbstractBehavior getBehavior(Class<? extends AbstractBehavior> behaviorType)
131+
@SuppressWarnings("unchecked")
132+
public <T> T getBehavior(Class<? extends T> behaviorType)
133133
{
134134
for (AbstractBehavior behavior : behaviors)
135135
if (behaviorType.isAssignableFrom(behavior.getClass()))
136-
return behavior;
136+
return (T) behavior;
137137

138138
return null;
139139
}
@@ -156,11 +156,16 @@ public List<AbstractBehavior> getBehaviors()
156156
* - The type of behaviors to get.
157157
* @return A list of behaviors with the given superclass.
158158
*/
159-
public List<AbstractBehavior> getBehaviors(Class<? extends AbstractBehavior> behaviorType)
159+
@SuppressWarnings("unchecked")
160+
public <T> List<T> getBehaviors(Class<? extends T> behaviorType)
160161
{
161-
return behaviors.stream()
162-
.filter(behavior -> behaviorType.isAssignableFrom(behavior.getClass()))
163-
.collect(Collectors.toList());
162+
List<T> list = new ArrayList<>();
163+
164+
for (AbstractBehavior behavior : behaviors)
165+
if (behaviorType.isAssignableFrom(behavior.getClass()))
166+
list.add((T) behavior);
167+
168+
return list;
164169
}
165170

166171
/**

src/main/java/net/whg/we/main/IPipelineAction.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,7 @@
1111
* <p>
1212
* Pipeline actions should also override the default priority level for loop
1313
* actions to ensure pipeline actions occur in the desired order. Default
14-
* priorities are:
15-
* <ul>
16-
* <li><i>Calculate Time Stamps</i> at <strong>-1000000</strong></li>
17-
* <li><i>Physics Updates</i> at <strong>-10000</strong></li>
18-
* <li><i>Updates</i> at <strong>0</strong></li>
19-
* <li><i>Animation Updates</i> at <strong>10000</strong></li>
20-
* <li><i>Late Updates</i> at <strong>20000</strong></li>
21-
* <li><i>Rendering Solids</i> at <strong>30000</strong></li>
22-
* <li><i>Rendering Transparents</i> at <strong>32500</strong></li>
23-
* <li><i>Dispose GameObjects</i> at <strong>40000</strong></li>
24-
* <li><i>End Frame</i> at <strong>1000000</strong></li>
25-
* </ul>
14+
* priorities are defined in the {@link PipelineConstants}.
2615
*/
2716
public interface IPipelineAction extends ILoopAction
2817
{

src/main/java/net/whg/we/main/IUpdateable.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public interface IUpdateable
99
{
1010
/**
1111
* Called once each frame to update this object.
12+
*
13+
* @param timer
14+
* - The timer associated with the update pipeline. Used to retrieve delta
15+
* times.
1216
*/
13-
void update();
17+
void update(Timer timer);
1418
}

src/main/java/net/whg/we/main/Input.java

Lines changed: 0 additions & 248 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package net.whg.we.main;
2+
3+
import java.util.List;
4+
import java.util.concurrent.CopyOnWriteArrayList;
5+
6+
/**
7+
* The physics pipeline action is an action in charge of triggering physics
8+
* updates each frame based on the physics framerate.
9+
*/
10+
public class PhysicsPipeline implements IPipelineAction
11+
{
12+
private final List<IFixedUpdateable> objects = new CopyOnWriteArrayList<>();
13+
private final Timer timer;
14+
15+
/**
16+
* Creates a new Physics pipeline action.
17+
*
18+
* @param timer
19+
* - The timer to being this action to.
20+
*/
21+
public PhysicsPipeline(Timer timer)
22+
{
23+
this.timer = timer;
24+
}
25+
26+
@Override
27+
public void run()
28+
{
29+
while (timer.getPhysicsFrame() < timer.getIdealPhysicsFrame())
30+
{
31+
timer.incrementPhysicsFrame();
32+
33+
for (IFixedUpdateable obj : objects)
34+
obj.fixedUpdate();
35+
}
36+
}
37+
38+
@Override
39+
public void enableBehavior(AbstractBehavior behavior)
40+
{
41+
if (behavior instanceof IFixedUpdateable)
42+
objects.add((IFixedUpdateable) behavior);
43+
}
44+
45+
@Override
46+
public void disableBehavior(AbstractBehavior behavior)
47+
{
48+
if (behavior instanceof IFixedUpdateable)
49+
objects.remove((IFixedUpdateable) behavior);
50+
}
51+
52+
@Override
53+
public int getPriority()
54+
{
55+
return PipelineConstants.PHYSICS_UPDATES;
56+
}
57+
}

0 commit comments

Comments
 (0)