framerate independence

pull/1/head
Bronwen 2023-01-03 02:17:23 -05:00
parent e8b94f9900
commit 3cc774a312
11 changed files with 23 additions and 23 deletions

View File

@ -72,8 +72,8 @@ public class Job extends GameObject {
public Vector2i[] getLocations() {
return subject.getWorkablePositions();
}
public boolean doWork() {
return subject.doWork();
public boolean doWork(float dTime) {
return subject.doWork(dTime);
}
@Override

View File

@ -168,8 +168,8 @@ public class Tile extends WorldObject implements IWorkable {
}
@Override
public boolean doWork() {
tillLevel += 0.005f;
public boolean doWork(float dTime) {
tillLevel += 0.005f * dTime;
tillLevel = Math.min(tillLevel, 1);
return tillLevel >= 1;
}

View File

@ -49,7 +49,7 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
@Override
public void update(float dTime) {
if(animation < animationMax) animation ++;
if(animation < animationMax) animation += dTime;
if(animation > animationMax) animation = animationMax;
// if(!active) return;

View File

@ -87,8 +87,8 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
}
@Override
public boolean doWork() {
choppage ++;
public boolean doWork(float dTime) {
choppage += dTime;
return getProgress() >= 1;
}

View File

@ -14,7 +14,7 @@ public abstract class Activity implements Serializable {
public abstract boolean isUrgent();
public abstract float getBenefit();
public abstract boolean isValid();
public abstract void act();
public abstract void act(float dTime);
public abstract void begin(ActivityCancellationCallback callback);
public abstract void end();
public abstract String toString();

View File

@ -32,8 +32,8 @@ public class JobActivity extends Activity {
}
@Override
public void act() {
if (doJob()) return;
public void act(float dTime) {
if (doJob(dTime)) return;
}
@ -83,7 +83,7 @@ public class JobActivity extends Activity {
job = null;
}
private boolean doJob() {
private boolean doJob(float dTime) {
if(!jobboard.workerHasJob(worker)) return false;
JobStep step = job.getCurrentStep();
// if we're not at the location of the job...
@ -91,7 +91,7 @@ public class JobActivity extends Activity {
if(step instanceof Job.Work) {
Job.Work workStep = (Job.Work)step;
if(workStep.doWork()) step.next();
if(workStep.doWork(dTime)) step.next();
return true;
} else if(step instanceof Job.PickupItem) {
Job.PickupItem pickupStep = (Job.PickupItem) step;

View File

@ -14,12 +14,12 @@ public class Needs implements Serializable {
private float decay = 0.000004f;
public void update(float dTime) {
energy = Math.max(energy - decay, 0);
recreation = Math.max(recreation - decay, 0);
energy = Math.max(energy - decay * dTime, 0);
recreation = Math.max(recreation - decay * dTime, 0);
}
public void sleep() {
energy = Math.min(energy + decay * restRatio, 1);
public void sleep(float dTime) {
energy = Math.min(energy + decay * dTime * restRatio, 1);
}
public float getSleepNeed() {

View File

@ -177,11 +177,11 @@ public class Pawn extends Agent {
// TODO at some point rewrite this to use an actor component array
// where we loop through until something _does_ sometihng.
@Override
protected boolean act() {
if(super.act()) return true;
protected boolean act(float dTime) {
if(super.act(dTime)) return true;
// if(doJob()) return true;
if(currentActivity != null) {
currentActivity.act();
currentActivity.act(dTime);
return true;
}
return false;

View File

@ -47,8 +47,8 @@ public class SleepActivity extends Activity {
}
@Override
public void act() {
needs.sleep();
public void act(float dTime) {
needs.sleep(dTime);
if(needs.getSleepNeed() == 0) {
callback.apply(this);
}

View File

@ -29,7 +29,7 @@ public class WanderActivity extends Activity {
}
@Override
public void act() {
public void act(float dTime) {
// since wandering is literally just pathing.
}

View File

@ -3,7 +3,7 @@ package xyz.valnet.hadean.interfaces;
import xyz.valnet.engine.math.Vector2i;
public interface IWorkable {
public boolean doWork();
public boolean doWork(float dTime);
public Vector2i[] getWorkablePositions();
public String getJobName();
}