Skip to content

Commit

Permalink
interval delta
Browse files Browse the repository at this point in the history
  • Loading branch information
junkdog committed Oct 13, 2014
1 parent 8f8ed4d commit 111d2da
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 10 deletions.
9 changes: 0 additions & 9 deletions artemis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
<description>Fork of Artemis Entity System Framework.</description>
<url>https://github.com/junkdog/artemis-odb</url>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
5 changes: 5 additions & 0 deletions artemis/src/main/java/com/artemis/EntityEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public final class EntityEdit {
componentBits = new BitSet();
}

/**
* Delete the entity from the world. The entity is considered to be
* in a final state once invoked; adding or removing components from an
* entity scheduled for deletion will likely throw exceptions.
*/
public void deleteEntity() {
scheduledDeletion = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public abstract class IntervalEntitySystem extends EntitySystem {
/** How long to wait between updates. */
private final float interval;

private float intervalDelta;

/**
* Creates a new IntervalEntitySystem.
Expand All @@ -38,11 +39,22 @@ protected boolean checkProcessing() {
acc += getTimeDelta();
if(acc >= interval) {
acc -= interval;
intervalDelta = (acc - intervalDelta);

return true;
}
return false;
}

/**
* Gets the actual delta since this system was last processed.
*
* @return Time passed since last process round.
*/
protected float getIntervalDelta() {
return interval + intervalDelta;
}

protected float getTimeDelta() {
return world.getDelta();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.artemis.systems;

import static org.junit.Assert.*;

import org.junit.Test;

import com.artemis.Aspect;
import com.artemis.Entity;
import com.artemis.World;
import com.artemis.component.ComponentX;
import com.artemis.utils.ImmutableBag;

@SuppressWarnings("static-method")
public class IntervalEntitySystemTest {

private static final float ACC = 0.0001f;

@Test
public void test_interval_delta() {

World world = new World();
IntervalSystem es = world.setSystem(new IntervalSystem());
world.initialize();

world.delta = 1.1f;
world.process();
assertEquals(1.1, es.getIntervalDelta(), ACC);

world.delta = 0.95f;
world.process();
assertEquals(0.95, es.getIntervalDelta(), ACC);
}

private static class IntervalSystem extends IntervalEntitySystem {

@SuppressWarnings("unchecked")
public IntervalSystem() {
super(Aspect.getAspectForAll(ComponentX.class), 1);
}

@Override
protected void processEntities(ImmutableBag<Entity> entities) {

}
}
}
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<asm.version>4.1</asm.version>
<junit.version>4.11</junit.version>
<gwt.version>2.6.0</gwt.version>
</properties>

<scm>
Expand Down Expand Up @@ -51,7 +53,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down

0 comments on commit 111d2da

Please sign in to comment.