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() { public Vector2i[] getLocations() {
return subject.getWorkablePositions(); return subject.getWorkablePositions();
} }
public boolean doWork() { public boolean doWork(float dTime) {
return subject.doWork(); return subject.doWork(dTime);
} }
@Override @Override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,12 +14,12 @@ public class Needs implements Serializable {
private float decay = 0.000004f; private float decay = 0.000004f;
public void update(float dTime) { public void update(float dTime) {
energy = Math.max(energy - decay, 0); energy = Math.max(energy - decay * dTime, 0);
recreation = Math.max(recreation - decay, 0); recreation = Math.max(recreation - decay * dTime, 0);
} }
public void sleep() { public void sleep(float dTime) {
energy = Math.min(energy + decay * restRatio, 1); energy = Math.min(energy + decay * dTime * restRatio, 1);
} }
public float getSleepNeed() { 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 // TODO at some point rewrite this to use an actor component array
// where we loop through until something _does_ sometihng. // where we loop through until something _does_ sometihng.
@Override @Override
protected boolean act() { protected boolean act(float dTime) {
if(super.act()) return true; if(super.act(dTime)) return true;
// if(doJob()) return true; // if(doJob()) return true;
if(currentActivity != null) { if(currentActivity != null) {
currentActivity.act(); currentActivity.act(dTime);
return true; return true;
} }
return false; return false;

View File

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

View File

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

View File

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