Framerate-independent building speed
This commit is contained in:
@@ -33,6 +33,7 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
|||||||
@SyncLocal Queue<BuildPlan> plans = new Queue<>(1);
|
@SyncLocal Queue<BuildPlan> plans = new Queue<>(1);
|
||||||
@SyncLocal boolean updateBuilding = true;
|
@SyncLocal boolean updateBuilding = true;
|
||||||
|
|
||||||
|
private transient float buildCounter;
|
||||||
private transient BuildPlan lastActive;
|
private transient BuildPlan lastActive;
|
||||||
private transient int lastSize;
|
private transient int lastSize;
|
||||||
transient float buildAlpha = 0f;
|
transient float buildAlpha = 0f;
|
||||||
@@ -61,6 +62,11 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
|||||||
float finalPlaceDst = state.rules.infiniteResources ? Float.MAX_VALUE : type.buildRange;
|
float finalPlaceDst = state.rules.infiniteResources ? Float.MAX_VALUE : type.buildRange;
|
||||||
boolean infinite = state.rules.infiniteResources || team().rules().infiniteResources;
|
boolean infinite = state.rules.infiniteResources || team().rules().infiniteResources;
|
||||||
|
|
||||||
|
buildCounter += Time.delta;
|
||||||
|
|
||||||
|
while(buildCounter >= 1){
|
||||||
|
buildCounter -= 1f;
|
||||||
|
|
||||||
Iterator<BuildPlan> it = plans.iterator();
|
Iterator<BuildPlan> it = plans.iterator();
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
BuildPlan req = it.next();
|
BuildPlan req = it.next();
|
||||||
@@ -73,7 +79,7 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
|||||||
var core = core();
|
var core = core();
|
||||||
|
|
||||||
//nothing to build.
|
//nothing to build.
|
||||||
if(buildPlan() == null) return;
|
if(buildPlan() == null) continue;
|
||||||
|
|
||||||
//find the next build request
|
//find the next build request
|
||||||
if(plans.size > 1){
|
if(plans.size > 1){
|
||||||
@@ -93,7 +99,7 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
|||||||
buildAlpha = 1f;
|
buildAlpha = 1f;
|
||||||
if(current.breaking) lastSize = tile.block().size;
|
if(current.breaking) lastSize = tile.block().size;
|
||||||
|
|
||||||
if(!within(tile, finalPlaceDst)) return;
|
if(!within(tile, finalPlaceDst)) continue;
|
||||||
|
|
||||||
if(!headless){
|
if(!headless){
|
||||||
Vars.control.sound.loop(Sounds.build, tile, 0.51f);
|
Vars.control.sound.loop(Sounds.build, tile, 0.51f);
|
||||||
@@ -112,11 +118,11 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
|||||||
Call.beginBreak(self(), team, current.x, current.y);
|
Call.beginBreak(self(), team, current.x, current.y);
|
||||||
}else{
|
}else{
|
||||||
plans.removeFirst();
|
plans.removeFirst();
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
}else if((tile.team() != team && tile.team() != Team.derelict) || (!current.breaking && (cb.current != current.block || cb.tile != current.tile()))){
|
}else if((tile.team() != team && tile.team() != Team.derelict) || (!current.breaking && (cb.current != current.block || cb.tile != current.tile()))){
|
||||||
plans.removeFirst();
|
plans.removeFirst();
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tile.build instanceof ConstructBuild && !current.initialized){
|
if(tile.build instanceof ConstructBuild && !current.initialized){
|
||||||
@@ -126,7 +132,7 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
|||||||
|
|
||||||
//if there is no core to build with or no build entity, stop building!
|
//if there is no core to build with or no build entity, stop building!
|
||||||
if((core == null && !infinite) || !(tile.build instanceof ConstructBuild entity)){
|
if((core == null && !infinite) || !(tile.build instanceof ConstructBuild entity)){
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float bs = 1f / entity.buildCost * Time.delta * type.buildSpeed * buildSpeedMultiplier * state.rules.buildSpeed(team);
|
float bs = 1f / entity.buildCost * Time.delta * type.buildSpeed * buildSpeedMultiplier * state.rules.buildSpeed(team);
|
||||||
@@ -141,6 +147,7 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
|||||||
current.stuck = Mathf.equal(current.progress, entity.progress);
|
current.stuck = Mathf.equal(current.progress, entity.progress);
|
||||||
current.progress = entity.progress;
|
current.progress = entity.progress;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Draw all current build plans. Does not draw the beam effect, only the positions. */
|
/** Draw all current build plans. Does not draw the beam effect, only the positions. */
|
||||||
void drawBuildPlans(){
|
void drawBuildPlans(){
|
||||||
|
|||||||
Reference in New Issue
Block a user