Seq.
This commit is contained in:
@@ -7,7 +7,7 @@ import arc.struct.*;
|
||||
* {@code BoundedSlotAssignmentStrategy} is an abstract implementation of {@link SlotAssignmentStrategy} that supports roles.
|
||||
* Generally speaking, there are hard and soft roles. Hard roles cannot be broken, soft roles can.
|
||||
* <p>
|
||||
* This abstract class provides an implementation of the {@link #calculateNumberOfSlots(Array) calculateNumberOfSlots} method that
|
||||
* This abstract class provides an implementation of the {@link #calculateNumberOfSlots(Seq) calculateNumberOfSlots} method that
|
||||
* is more general (and costly) than the simplified implementation in {@link FreeSlotAssignmentStrategy}. It scans the assignment
|
||||
* list to find the number of filled slots, which is the highest slot number in the assignments.
|
||||
* @author davebaol
|
||||
@@ -15,10 +15,10 @@ import arc.struct.*;
|
||||
public abstract class BoundedSlotAssignmentStrategy implements SlotAssignmentStrategy{
|
||||
|
||||
@Override
|
||||
public abstract void updateSlotAssignments(Array<SlotAssignment> assignments);
|
||||
public abstract void updateSlotAssignments(Seq<SlotAssignment> assignments);
|
||||
|
||||
@Override
|
||||
public int calculateNumberOfSlots(Array<SlotAssignment> assignments){
|
||||
public int calculateNumberOfSlots(Seq<SlotAssignment> assignments){
|
||||
// Find the number of filled slots: it will be the
|
||||
// highest slot number in the assignments
|
||||
int filledSlots = -1;
|
||||
@@ -32,7 +32,7 @@ public abstract class BoundedSlotAssignmentStrategy implements SlotAssignmentStr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSlotAssignment(Array<SlotAssignment> assignments, int index){
|
||||
public void removeSlotAssignment(Seq<SlotAssignment> assignments, int index){
|
||||
int sn = assignments.get(index).slotNumber;
|
||||
for(int i = 0; i < assignments.size; i++){
|
||||
SlotAssignment sa = assignments.get(i);
|
||||
|
||||
@@ -13,8 +13,8 @@ public class DistanceAssignmentStrategy implements SlotAssignmentStrategy{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSlotAssignments(Array<SlotAssignment> assignments){
|
||||
IntArray slots = IntArray.range(0, assignments.size);
|
||||
public void updateSlotAssignments(Seq<SlotAssignment> assignments){
|
||||
IntSeq slots = IntSeq.range(0, assignments.size);
|
||||
|
||||
for(SlotAssignment slot : assignments){
|
||||
int mindex = 0;
|
||||
@@ -35,12 +35,12 @@ public class DistanceAssignmentStrategy implements SlotAssignmentStrategy{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculateNumberOfSlots(Array<SlotAssignment> assignments){
|
||||
public int calculateNumberOfSlots(Seq<SlotAssignment> assignments){
|
||||
return assignments.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSlotAssignment(Array<SlotAssignment> assignments, int index){
|
||||
public void removeSlotAssignment(Seq<SlotAssignment> assignments, int index){
|
||||
assignments.remove(index);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import arc.struct.*;
|
||||
public class Formation{
|
||||
|
||||
/** A list of slots assignments. */
|
||||
public Array<SlotAssignment> slotAssignments;
|
||||
public Seq<SlotAssignment> slotAssignments;
|
||||
|
||||
/** The anchor point of this formation. */
|
||||
public Vec3 anchor;
|
||||
@@ -74,7 +74,7 @@ public class Formation{
|
||||
this.slotAssignmentStrategy = slotAssignmentStrategy;
|
||||
this.motionModerator = motionModerator;
|
||||
|
||||
this.slotAssignments = new Array<>();
|
||||
this.slotAssignments = new Seq<>();
|
||||
this.driftOffset = new Vec3();
|
||||
this.positionOffset = new Vec2(anchor.x, anchor.y).cpy();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public abstract class FormationMotionModerator{
|
||||
* @param pattern the pattern
|
||||
* @return the given location for chaining.
|
||||
*/
|
||||
public Vec3 calculateDriftOffset(Vec3 centerOfMass, Array<SlotAssignment> slotAssignments, FormationPattern pattern){
|
||||
public Vec3 calculateDriftOffset(Vec3 centerOfMass, Seq<SlotAssignment> slotAssignments, FormationPattern pattern){
|
||||
// Clear the center of mass
|
||||
centerOfMass.x = centerOfMass.y = 0;
|
||||
float centerOfMassOrientation = 0;
|
||||
|
||||
@@ -13,7 +13,7 @@ import arc.struct.*;
|
||||
public class FreeSlotAssignmentStrategy implements SlotAssignmentStrategy{
|
||||
|
||||
@Override
|
||||
public void updateSlotAssignments(Array<SlotAssignment> assignments){
|
||||
public void updateSlotAssignments(Seq<SlotAssignment> assignments){
|
||||
// A very simple assignment algorithm: we simply go through
|
||||
// each assignment in the list and assign sequential slot numbers
|
||||
for(int i = 0; i < assignments.size; i++)
|
||||
@@ -21,12 +21,12 @@ public class FreeSlotAssignmentStrategy implements SlotAssignmentStrategy{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculateNumberOfSlots(Array<SlotAssignment> assignments){
|
||||
public int calculateNumberOfSlots(Seq<SlotAssignment> assignments){
|
||||
return assignments.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSlotAssignment(Array<SlotAssignment> assignments, int index){
|
||||
public void removeSlotAssignment(Seq<SlotAssignment> assignments, int index){
|
||||
assignments.remove(index);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,12 +9,12 @@ import arc.struct.*;
|
||||
public interface SlotAssignmentStrategy{
|
||||
|
||||
/** Updates the assignment of members to slots */
|
||||
void updateSlotAssignments(Array<SlotAssignment> assignments);
|
||||
void updateSlotAssignments(Seq<SlotAssignment> assignments);
|
||||
|
||||
/** Calculates the number of slots from the assignment data. */
|
||||
int calculateNumberOfSlots(Array<SlotAssignment> assignments);
|
||||
int calculateNumberOfSlots(Seq<SlotAssignment> assignments);
|
||||
|
||||
/** Removes the slot assignment at the specified index. */
|
||||
void removeSlotAssignment(Array<SlotAssignment> assignments, int index);
|
||||
void removeSlotAssignment(Seq<SlotAssignment> assignments, int index);
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import arc.util.*;
|
||||
public class SoftRoleSlotAssignmentStrategy extends BoundedSlotAssignmentStrategy{
|
||||
protected SlotCostProvider slotCostProvider;
|
||||
protected float costThreshold;
|
||||
private BooleanArray filledSlots;
|
||||
private BoolSeq filledSlots;
|
||||
|
||||
/**
|
||||
* Creates a {@code SoftRoleSlotAssignmentStrategy} with the given slot cost provider and no cost threshold.
|
||||
@@ -46,14 +46,14 @@ public class SoftRoleSlotAssignmentStrategy extends BoundedSlotAssignmentStrateg
|
||||
this.slotCostProvider = slotCostProvider;
|
||||
this.costThreshold = costThreshold;
|
||||
|
||||
this.filledSlots = new BooleanArray();
|
||||
this.filledSlots = new BoolSeq();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSlotAssignments(Array<SlotAssignment> assignments){
|
||||
public void updateSlotAssignments(Seq<SlotAssignment> assignments){
|
||||
|
||||
// Holds a list of member and slot data for each member.
|
||||
Array<MemberAndSlots> memberData = new Array<>();
|
||||
Seq<MemberAndSlots> memberData = new Seq<>();
|
||||
|
||||
// Compile the member data
|
||||
int numberOfAssignments = assignments.size;
|
||||
@@ -146,12 +146,12 @@ public class SoftRoleSlotAssignmentStrategy extends BoundedSlotAssignmentStrateg
|
||||
static class MemberAndSlots implements Comparable<MemberAndSlots>{
|
||||
FormationMember member;
|
||||
float assignmentEase;
|
||||
Array<CostAndSlot> costAndSlots;
|
||||
Seq<CostAndSlot> costAndSlots;
|
||||
|
||||
public MemberAndSlots(FormationMember member){
|
||||
this.member = member;
|
||||
this.assignmentEase = 0f;
|
||||
this.costAndSlots = new Array<>();
|
||||
this.costAndSlots = new Seq<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user