e( int diameter ) {
ParicleState( 0, 0, 0, 0, diameter );
}
///////////////////////////////////////////////
// postion information (pixels)
public double xPos, yPos;
// velocity information (pixels/second)
public double xVel, yVel;
// postion and extent on screen
public Rectangle scrPos = new Retangle();
// true when the particle is showing
public boolean isShown = false;
///////////////////////////////////////////////
// calculate speed relative to origin
public final double getVelMag() {
return Math.sqrt( xVel*xVel + yVel*yVel );
}
// calculate distance relative to origin or other PariticleState object
public final double getDistance() {
return Math.sqrt( xPos*xPos + yPos*yPos );
}
public final double getDistance( ParticleState other ) {
double xDist = xPos - other.xPos;
double yDist = yPos - other.yPos;
return Math.sqrt( xDist*xDist + yDist*yDist );
}
public String toString() {
return "Postition = (" + xPos + ',' + yPos + "); Velocity = (" + xVel + ',' + yVel + ')';
}
}
/////////////////////////////////////////
// Force State Object
/////////////////////////////////////////
private static class ForceState {
public double xF, yF;
}
/////////////////////////////////////////
// Exceptions
/////////////////////////////////////////
public static class ParticleTypeRegistrationException extends Exception {
public ParticleTypeRegistrationException() {}
public ParticleTypeRegistrationException( String msg ) { super( msg ); }
}
}
--- END NBodyAnimate.java ---
(Review ID: 30065)
======================================================================
Name: eyC74480 Date: 05/11/98
I recieved the following message during a compile:
--- BEGIN SCREEN SHOT ---
sun.tools.java.CompilerError: addReference EDU.ARIZONA.CS.calverts.NBodyAnimate this
at sun.tools.java.ClassDefinition.addReference(ClassDefinition.java)
at sun.tools.java.ClassDefinition.getReference(ClassDefinition.java)
at sun.tools.tree.Context.noteReference(Context.java)
at sun.tools.tree.Context.makeReference(Context.java)
at sun.tools.tree.ThisExpression.checkValue(ThisExpression.java)
at sun.tools.tree.Expression.checkAmbigName(Expression.java)
at sun.tools.tree.FieldExpression.checkCommon(FieldExpression.java)
at sun.tools.tree.FieldExpression.checkValue(FieldExpression.java)
at sun.tools.tree.IdentifierExpression.checkValue(IdentifierExpression.java)
at sun.tools.tree.Expression.checkInitializer(Expression.java)
at sun.tools.javac.SourceField.check(SourceField.java)
at sun.tools.javac.SourceClass.checkFields(SourceClass.java)
at sun.tools.javac.SourceClass.checkInternal(SourceClass.java)
at sun.tools.javac.SourceClass.check(SourceClass.java)
at sun.tools.javac.Main.compile(Main.java)
at sun.tools.javac.Main.main(Main.java)
error: An error has occurred in the compiler; please file a bug report (http://java.sun.com/cgi-bin/bugreport.cgi).
1 error
--- END SCREEN SHOT ---
This is the java source file causing the error:
--- BEGIN NBodyAnimate.java ---
/** NBodyAnimate
NBodyAnimate is a custom component which pairs a generic numerical
2D n-body problem solver with a full speed visualization of the
particles in motion.
Particles are modeled according to classical mechanics.
Two different calculation engines are provided: a simple single threaded
solver and a multi-threaded solver targeted for shared memory multiprocessors.
*/
package EDU.ARIZONA.CS.calverts;
import java.awt.*;
import java.util.*;
public class NBodyAnimate extends Component {
public NBodyAnimate() {
// setup on thread animation
calcEngine = new CalcEngine();
}
public NBodyAnimate( int workerCount ) {
// setup a configurable number of worker thread
calcEngine = new CalcEngine( workerCount );
}
// Since paint redraws the entire area, prevent background redraw.
// The prevents flicker during repaints
public void update( Graphics g ) { paint( g ); }
/////////////////////////////////////////
// Force Models
// The 2nd order and 4th order forces are support independently configurable
// force models. When forces are electrical like charges repel. Gravitational
// force modeling assumes all charges are positive and all forces are attractive.
/////////////////////////////////////////
public final byte MIN_FORCE_MODEL = 1;
public final byte FM_GRAVITATIONAL = MIN_FORCE_MODEL;
public final byte FM_ELECTRICAL = FM_GRAVITATIONAL + 1;
public final byte MAX_FROCE_MODEL = FM_ELECTRICAL;
/////////////////////////////////////////
// Registered Particle Types
/////////////////////////////////////////
// registers a new particle type, noop if type already exists
public void registerParticleType( ParticleTypeDescriptor newP ) {
ParticleTypeDescriptor newA[] = new ParticleTypeDescriptopr[1];
newA[1] = newP;
registerParticleTypes( newA );
}
// registers a number of new particle types at once, noop for types already present
public synchronized void registerParticleTypes( ParticleTypeDescriptor newP[] ) {
//ParticleTypeDescriptor lastAdded = null;
// walk array, add new types if not repeats
for( int i=0; i < newP.length; i++ ) {
// check if this type is the same as the last
if( newP[i] == lastAdded )
continue;
lastAdded = newP;
// check that this type isn't already present
if( partDescriptorsRegistered.lookup( newP[i] ) )
continue;
// add type to the registered types
partDescriptorsRegistered.insert( newP[i] );
}
}
// removes an existing particle type registration and removes all
// particles of that type, throws exceptions if type not present
public synchronized void removeParticleType( ParticleTypeDescriptor dead )
throws ParticleTypeRegistrationException {
// pause the simulation
byte simState = calcEngine.getState();
calcEngine.setPaused();
// remove the dead particle type, throw if not present
if( !partDescriptorsRegistered.delete( dead ) )
throw new ParticleTypeRegistrationException( "particle type not present" );
// make vector of dead particle's indexes
Vector deadParticles = new Vector();
for( int i=0; i < partDescriptors.length; i++ ) {
if( partDescriptors[i] == dead )
deadParticles.addElement( new Integer( i ) );
}
// make array of deadParticles
int deadParticleCount = deadParticles.size();
int deadParticleArray[] = new int[deadParticleCount];
for( int i=0; i < deadParticleCount; i++ )
deadParticleArray[i] = ((Integer)deadParticles.elementAt( i )).intValue();
// remove the found particles from the simulation status
removeParticles( deadParticleArray );
// restore the simulation's state
calcEngine.setState( simState );
}
protected ParticleTypeDescriptor partDescriptorsRegistered = new Set();
/////////////////////////////////////////
// Simulated Particles
/////////////////////////////////////////
public void insertParticle( ParticleTypeDescriptor type,
ParticleState state ) {
ParticleTypeDescriptor typeA[] = new ParticleTypeDescriptor[1];
typeA[1] = type;
ParticleTypeDescriptor stateA[] = new ParticleState[1];
stateA[1] = state;
return insertParticles( typeA, stateA );
}
public synchronized void insertParticles( ParticleTypeDescriptor types[],
ParticleState states[] ) {
// must be an equal number of types and states
ARGCHECK.checkTrue( types.length == states.length,
"must be equal number of types and states" );
final int countNew = types.length;
final int countOld = partDescriptors.length;
final int countTotal = countNew + countOld;
// pause the simulation
byte simState = calcEngine.getState();
calcEngine.setPaused();
// register any new particle types
registerParticleTypes( types );
// resize particle arrays
ParticleTypeDescriptor newDescriptors[] = new ParticleTypeDescriptor[countTotal];
ParticleState newCurrentStates[] = new ParticleState[countTotal];
ParticleState newLastStates[] = new ParticleState[countTotal];
arraycopy( partDescriptors, 0, newDescriptors, 0, countOld );
arraycopy( partStateCurrent, 0, newCurrentStates, 0, countOld );
arraycopy( partStateLast, 0, newLastStates, 0, countOld );
partDescriptors = newDescriptors;
partStateCurrent = newCurrentStates;
partStateLast = newLastStates;
// add new particles to back of array
arraycopy( types, 0, partDescriptors, countOld, countNew );
for( int src=0, dst=countOld; src < countNew; src++, dst++ ) {
partStateCurrent[dst] = states[src].clone();
partStateLast[dst] = states[src].clone();
}
// grow force state arrays if needed
if( forces.length < countTotal ) {
// allocate a longer top level array and move existing low level arrays to it
final int partCount = countTotal * 2;
ForceState newForces = new ForceState[countTotal][];
arraycopy( forces, 0, newForces, 0, forces.length );
// add new force pair state arrays to back of top level array
for( int row = forces.length; row < partCount; row++ ) {
newForces[row] = new ForceState[row];
for( int col = 0; col < row; col++ )
newForces[row][col] = new ForceState();
}
}
// restore the simulation's state
calcEngine.setState( simState );
}
public synchronized void removeParticle( int dead ) {
int[] deadA = new int[1];
deadA[1] = dead;
removeParticles( deadA );
}
// assumes particle indexes are sorted into increasing order
protected synchronized void removeParticles( int dead[] )
throws IllegalExecutionRequestException {
final int deadCount = dead.length;
final int oldLen = ParticleTypeDescriptor.length;
final int newLen = oldLen - deadCount;
// pause the simulation
byte simState = calcEninge.getState();
calcEngine.setPaused();
// create smaller arrays
ParticleTypeDescriptor newDescriptors[] = new ParticleTypeDescriptor[newLen];
ParticleState newCurrentStates[] = new ParticleState[newLen];
ParticleState newLastStates[] = new ParticleState[newLen];
// move non-deleted particles into new arrays
for( int i=0, srcIndx=0; i < deadCount; srcIndx = dead[i]+1, i++ ) {
final int dstIndx = srcIndx - i;
final int blockSize = dead[i] - startIndx - 1;
arraycopy( partDescriptors, srcIndx, newDescriptors, dstIndx, blockSize );
arraycopy( partStateCurrent, srcIndx, newCurrentStates, dstIndx, blockSize );
arraycopy( partStateLast, srcIndx, newLastStates, dstIndx, blockSize );
}
final int srcIndx = dead[deadCount]+1;
final int dstIndx = srcIndx - deadCount;
final int blockSize = oldLen - srcIndx;
arraycopy( partDescriptors, srcIndx, newDescriptors, dstIndx, blockSize );
arraycopy( partStateCurrent, srcIndx, newCurrentStates, dstIndx, blockSize );
arraycopy( partStateLast, srcIndx, newLastStates, dstIndx, blockSize );
// replace old arrays with new ones
partDescriptors = newDescriptors;
partStateCurrent = newCurrentStates;
partStateLast = newLastStates;
// restore the simulation's state
calcEngine.setState( simState );
}
// descriptors for each particle in simumulation
ParticleTypeDescriptor partDescriptors[] = new ParticleTypeDescriptor[0];
// two states are held for each particle in simulation, they are refernced by the
// arrays partStateCurrent, partStateNext, partStateLast
ParticleState partStateLast[] = new ParticleState[0];
ParticleState partStateCurrent[] = new ParticleState[0];
ParticleState partStateNext[] = null;
// force pair arrays, output by the CALC_FORCES phase and used by CALC_STATES
ForceState forces[][] = null;
/////////////////////////////////////////
// Off-screen Image Buffer
/////////////////////////////////////////
Image offScreen;
Rectangle screenBounds = new Retangle();
/////////////////////////////////////////
// Calculation Engine
// Use these functions to control the flow of the simulation
//
// STOPPED: Worker threads do not exist. Simulation state is stable and consistent.
// State is STOPPED at construction.
// PAUSED: Worker threads exist but are blocked. Simulation state is stable
// and consistent.
// RUNNING: Worker threads are alive and working. Only worker threads may change
// simulation state.
// KILLED: Worker threads were murdered asynchronously. Simulation state is
// unrecoverably trashed.
//////////////////////////////////////////
public static final byte MIN_STATE = 1;
public static final byte STOPPED = MIN_STATE;
public static final byte PAUSED = STOPPED + 1;
public static final byte CEASE_PENDING = PAUSED + 1; // never visible to outsiders
public static final byte RUNNING = CEASE_PENDING + 1;
public static final byte KILLED = RUNNING + 1;
public static final byte MAX_STATE = KILLED;
// link to calculation engine object
private CalcEngine calcEngine;
public synchronized void changeWorkerCount( int workerCount ) {
calcEngine.changeWorkerCount( workerCount );
}
public synchronized byte getState() {
return calcEngine.getState();
}
public synchronized void setRunning() {
calcEngine.setRunning();
}
public synchronized void setPaused() {
calcEngine.setPaused();
}
public synchronized void setStopped() {
calcEngine.setStopped();
}
public synchronized void KILL() {
calcEngine.KILLALL();
}
/////////////////////////////////////////
// ParticleTypeDescriptor (non-synchronized)
// Holds physics/display information for a class of particles
/////////////////////////////////////////
public static class ParticleTypeDescriptor
extends Object
implements Cloneable {
protected static int _instanceCount = 0;
public ParticleTypeDescriptor ( double coefFriction,
double chargeF1, double chargeF2, double chargeF3,
double mass,
byte displayDiameter,
Color diplayColor,
String name, String description ) {
// validate parameters
ARGCHECK.checkTrue( coefFriction >= 0, "coefFriction must be non-negative" );
ARGCHECK.checkTrue( mass >= 0, "mass must be non-negative" );
ARGCHECK.checkTrue( displayDiameter > 0, "displayDiameter must be positive" );
ARGCHECK.checkNotNull( diplayColor, "displayColor must not be null" );
// fill in default name if name is null
if( name == null )
name = "Particle Type " + _instanceCount;
// save parameters
this.coefFriction = -coefFriction;
this.chargeF1 = chargeF1; this.chargeF2 = chargeF2; this.chargeF3 = chargeF3;
this.mass = mass; this.invMass = 1/mass;
this.displayDiameter = displayDiameter;
this.displayColor = displayColor;
this.name = name; this.description = description;
// increment _instanceCount
_instanceCount++;
}
public String toString() {
return name
+ "\n\tcoefFriction = " + coefFriction
+ "\n\tchargeF1 = " + chargeF1 + ", chargeF2 = " + chargeF2 + ", chargeF3 = " + chargeF3
+ "\n\tmass = " + mass
+ "\n\tdiplayDiameter = " + displayDiameter
+ "\n\tdiplayColor = " + displayColor;
}
// physical characteristics
// calculations are unit correct
// distance is expresed in pixels, time in seconds
public final double coefFriction;
public final double chargeF1, chargeF2, chargeF3;
public final double mass, invMass;
// display characteristics
public final byte displayDiameter;
public final Color displayColor;
// name and description
public final String name, description;
}
/////////////////////////////////////////
// ParticleState (non-synchronized)
// Holds postion and velocity information for a particle
/////////////////////////////////////////
public static class ParticleState
extends Object
implements Cloneable {
///////////////////////////////////////////////
static int _instanceCount = 0;
public ParticleState( double xPos, double yPos, double xVel, double yVel, int diameter ) {
this.xPos = xPos; this.yPos = yPos;
this.xVel = xVel; this.yVel = yVel;
scrPos.x = -(diameter/2); scrPos.y = -(diameter/2) ;
scrPos.width = radius; scrPos.height = radius;
_instanceCount++;
}
public ParticleState( double xPos, double yPos, int diameter ) {
ParticleState( xPos, yPos, 0, 0, diameter );
}
public ParticleStat
ParicleState( 0, 0, 0, 0, diameter );
}
///////////////////////////////////////////////
// postion information (pixels)
public double xPos, yPos;
// velocity information (pixels/second)
public double xVel, yVel;
// postion and extent on screen
public Rectangle scrPos = new Retangle();
// true when the particle is showing
public boolean isShown = false;
///////////////////////////////////////////////
// calculate speed relative to origin
public final double getVelMag() {
return Math.sqrt( xVel*xVel + yVel*yVel );
}
// calculate distance relative to origin or other PariticleState object
public final double getDistance() {
return Math.sqrt( xPos*xPos + yPos*yPos );
}
public final double getDistance( ParticleState other ) {
double xDist = xPos - other.xPos;
double yDist = yPos - other.yPos;
return Math.sqrt( xDist*xDist + yDist*yDist );
}
public String toString() {
return "Postition = (" + xPos + ',' + yPos + "); Velocity = (" + xVel + ',' + yVel + ')';
}
}
/////////////////////////////////////////
// Force State Object
/////////////////////////////////////////
private static class ForceState {
public double xF, yF;
}
/////////////////////////////////////////
// Exceptions
/////////////////////////////////////////
public static class ParticleTypeRegistrationException extends Exception {
public ParticleTypeRegistrationException() {}
public ParticleTypeRegistrationException( String msg ) { super( msg ); }
}
}
--- END NBodyAnimate.java ---
(Review ID: 30065)
======================================================================
Name: eyC74480 Date: 05/11/98
I recieved the following message during a compile:
--- BEGIN SCREEN SHOT ---
sun.tools.java.CompilerError: addReference EDU.ARIZONA.CS.calverts.NBodyAnimate this
at sun.tools.java.ClassDefinition.addReference(ClassDefinition.java)
at sun.tools.java.ClassDefinition.getReference(ClassDefinition.java)
at sun.tools.tree.Context.noteReference(Context.java)
at sun.tools.tree.Context.makeReference(Context.java)
at sun.tools.tree.ThisExpression.checkValue(ThisExpression.java)
at sun.tools.tree.Expression.checkAmbigName(Expression.java)
at sun.tools.tree.FieldExpression.checkCommon(FieldExpression.java)
at sun.tools.tree.FieldExpression.checkValue(FieldExpression.java)
at sun.tools.tree.IdentifierExpression.checkValue(IdentifierExpression.java)
at sun.tools.tree.Expression.checkInitializer(Expression.java)
at sun.tools.javac.SourceField.check(SourceField.java)
at sun.tools.javac.SourceClass.checkFields(SourceClass.java)
at sun.tools.javac.SourceClass.checkInternal(SourceClass.java)
at sun.tools.javac.SourceClass.check(SourceClass.java)
at sun.tools.javac.Main.compile(Main.java)
at sun.tools.javac.Main.main(Main.java)
error: An error has occurred in the compiler; please file a bug report (http://java.sun.com/cgi-bin/bugreport.cgi).
1 error
--- END SCREEN SHOT ---
This is the java source file causing the error:
--- BEGIN NBodyAnimate.java ---
/** NBodyAnimate
NBodyAnimate is a custom component which pairs a generic numerical
2D n-body problem solver with a full speed visualization of the
particles in motion.
Particles are modeled according to classical mechanics.
Two different calculation engines are provided: a simple single threaded
solver and a multi-threaded solver targeted for shared memory multiprocessors.
*/
package EDU.ARIZONA.CS.calverts;
import java.awt.*;
import java.util.*;
public class NBodyAnimate extends Component {
public NBodyAnimate() {
// setup on thread animation
calcEngine = new CalcEngine();
}
public NBodyAnimate( int workerCount ) {
// setup a configurable number of worker thread
calcEngine = new CalcEngine( workerCount );
}
// Since paint redraws the entire area, prevent background redraw.
// The prevents flicker during repaints
public void update( Graphics g ) { paint( g ); }
/////////////////////////////////////////
// Force Models
// The 2nd order and 4th order forces are support independently configurable
// force models. When forces are electrical like charges repel. Gravitational
// force modeling assumes all charges are positive and all forces are attractive.
/////////////////////////////////////////
public final byte MIN_FORCE_MODEL = 1;
public final byte FM_GRAVITATIONAL = MIN_FORCE_MODEL;
public final byte FM_ELECTRICAL = FM_GRAVITATIONAL + 1;
public final byte MAX_FROCE_MODEL = FM_ELECTRICAL;
/////////////////////////////////////////
// Registered Particle Types
/////////////////////////////////////////
// registers a new particle type, noop if type already exists
public void registerParticleType( ParticleTypeDescriptor newP ) {
ParticleTypeDescriptor newA[] = new ParticleTypeDescriptopr[1];
newA[1] = newP;
registerParticleTypes( newA );
}
// registers a number of new particle types at once, noop for types already present
public synchronized void registerParticleTypes( ParticleTypeDescriptor newP[] ) {
//ParticleTypeDescriptor lastAdded = null;
// walk array, add new types if not repeats
for( int i=0; i < newP.length; i++ ) {
// check if this type is the same as the last
if( newP[i] == lastAdded )
continue;
lastAdded = newP;
// check that this type isn't already present
if( partDescriptorsRegistered.lookup( newP[i] ) )
continue;
// add type to the registered types
partDescriptorsRegistered.insert( newP[i] );
}
}
// removes an existing particle type registration and removes all
// particles of that type, throws exceptions if type not present
public synchronized void removeParticleType( ParticleTypeDescriptor dead )
throws ParticleTypeRegistrationException {
// pause the simulation
byte simState = calcEngine.getState();
calcEngine.setPaused();
// remove the dead particle type, throw if not present
if( !partDescriptorsRegistered.delete( dead ) )
throw new ParticleTypeRegistrationException( "particle type not present" );
// make vector of dead particle's indexes
Vector deadParticles = new Vector();
for( int i=0; i < partDescriptors.length; i++ ) {
if( partDescriptors[i] == dead )
deadParticles.addElement( new Integer( i ) );
}
// make array of deadParticles
int deadParticleCount = deadParticles.size();
int deadParticleArray[] = new int[deadParticleCount];
for( int i=0; i < deadParticleCount; i++ )
deadParticleArray[i] = ((Integer)deadParticles.elementAt( i )).intValue();
// remove the found particles from the simulation status
removeParticles( deadParticleArray );
// restore the simulation's state
calcEngine.setState( simState );
}
protected ParticleTypeDescriptor partDescriptorsRegistered = new Set();
/////////////////////////////////////////
// Simulated Particles
/////////////////////////////////////////
public void insertParticle( ParticleTypeDescriptor type,
ParticleState state ) {
ParticleTypeDescriptor typeA[] = new ParticleTypeDescriptor[1];
typeA[1] = type;
ParticleTypeDescriptor stateA[] = new ParticleState[1];
stateA[1] = state;
return insertParticles( typeA, stateA );
}
public synchronized void insertParticles( ParticleTypeDescriptor types[],
ParticleState states[] ) {
// must be an equal number of types and states
ARGCHECK.checkTrue( types.length == states.length,
"must be equal number of types and states" );
final int countNew = types.length;
final int countOld = partDescriptors.length;
final int countTotal = countNew + countOld;
// pause the simulation
byte simState = calcEngine.getState();
calcEngine.setPaused();
// register any new particle types
registerParticleTypes( types );
// resize particle arrays
ParticleTypeDescriptor newDescriptors[] = new ParticleTypeDescriptor[countTotal];
ParticleState newCurrentStates[] = new ParticleState[countTotal];
ParticleState newLastStates[] = new ParticleState[countTotal];
arraycopy( partDescriptors, 0, newDescriptors, 0, countOld );
arraycopy( partStateCurrent, 0, newCurrentStates, 0, countOld );
arraycopy( partStateLast, 0, newLastStates, 0, countOld );
partDescriptors = newDescriptors;
partStateCurrent = newCurrentStates;
partStateLast = newLastStates;
// add new particles to back of array
arraycopy( types, 0, partDescriptors, countOld, countNew );
for( int src=0, dst=countOld; src < countNew; src++, dst++ ) {
partStateCurrent[dst] = states[src].clone();
partStateLast[dst] = states[src].clone();
}
// grow force state arrays if needed
if( forces.length < countTotal ) {
// allocate a longer top level array and move existing low level arrays to it
final int partCount = countTotal * 2;
ForceState newForces = new ForceState[countTotal][];
arraycopy( forces, 0, newForces, 0, forces.length );
// add new force pair state arrays to back of top level array
for( int row = forces.length; row < partCount; row++ ) {
newForces[row] = new ForceState[row];
for( int col = 0; col < row; col++ )
newForces[row][col] = new ForceState();
}
}
// restore the simulation's state
calcEngine.setState( simState );
}
public synchronized void removeParticle( int dead ) {
int[] deadA = new int[1];
deadA[1] = dead;
removeParticles( deadA );
}
// assumes particle indexes are sorted into increasing order
protected synchronized void removeParticles( int dead[] )
throws IllegalExecutionRequestException {
final int deadCount = dead.length;
final int oldLen = ParticleTypeDescriptor.length;
final int newLen = oldLen - deadCount;
// pause the simulation
byte simState = calcEninge.getState();
calcEngine.setPaused();
// create smaller arrays
ParticleTypeDescriptor newDescriptors[] = new ParticleTypeDescriptor[newLen];
ParticleState newCurrentStates[] = new ParticleState[newLen];
ParticleState newLastStates[] = new ParticleState[newLen];
// move non-deleted particles into new arrays
for( int i=0, srcIndx=0; i < deadCount; srcIndx = dead[i]+1, i++ ) {
final int dstIndx = srcIndx - i;
final int blockSize = dead[i] - startIndx - 1;
arraycopy( partDescriptors, srcIndx, newDescriptors, dstIndx, blockSize );
arraycopy( partStateCurrent, srcIndx, newCurrentStates, dstIndx, blockSize );
arraycopy( partStateLast, srcIndx, newLastStates, dstIndx, blockSize );
}
final int srcIndx = dead[deadCount]+1;
final int dstIndx = srcIndx - deadCount;
final int blockSize = oldLen - srcIndx;
arraycopy( partDescriptors, srcIndx, newDescriptors, dstIndx, blockSize );
arraycopy( partStateCurrent, srcIndx, newCurrentStates, dstIndx, blockSize );
arraycopy( partStateLast, srcIndx, newLastStates, dstIndx, blockSize );
// replace old arrays with new ones
partDescriptors = newDescriptors;
partStateCurrent = newCurrentStates;
partStateLast = newLastStates;
// restore the simulation's state
calcEngine.setState( simState );
}
// descriptors for each particle in simumulation
ParticleTypeDescriptor partDescriptors[] = new ParticleTypeDescriptor[0];
// two states are held for each particle in simulation, they are refernced by the
// arrays partStateCurrent, partStateNext, partStateLast
ParticleState partStateLast[] = new ParticleState[0];
ParticleState partStateCurrent[] = new ParticleState[0];
ParticleState partStateNext[] = null;
// force pair arrays, output by the CALC_FORCES phase and used by CALC_STATES
ForceState forces[][] = null;
/////////////////////////////////////////
// Off-screen Image Buffer
/////////////////////////////////////////
Image offScreen;
Rectangle screenBounds = new Retangle();
/////////////////////////////////////////
// Calculation Engine
// Use these functions to control the flow of the simulation
//
// STOPPED: Worker threads do not exist. Simulation state is stable and consistent.
// State is STOPPED at construction.
// PAUSED: Worker threads exist but are blocked. Simulation state is stable
// and consistent.
// RUNNING: Worker threads are alive and working. Only worker threads may change
// simulation state.
// KILLED: Worker threads were murdered asynchronously. Simulation state is
// unrecoverably trashed.
//////////////////////////////////////////
public static final byte MIN_STATE = 1;
public static final byte STOPPED = MIN_STATE;
public static final byte PAUSED = STOPPED + 1;
public static final byte CEASE_PENDING = PAUSED + 1; // never visible to outsiders
public static final byte RUNNING = CEASE_PENDING + 1;
public static final byte KILLED = RUNNING + 1;
public static final byte MAX_STATE = KILLED;
// link to calculation engine object
private CalcEngine calcEngine;
public synchronized void changeWorkerCount( int workerCount ) {
calcEngine.changeWorkerCount( workerCount );
}
public synchronized byte getState() {
return calcEngine.getState();
}
public synchronized void setRunning() {
calcEngine.setRunning();
}
public synchronized void setPaused() {
calcEngine.setPaused();
}
public synchronized void setStopped() {
calcEngine.setStopped();
}
public synchronized void KILL() {
calcEngine.KILLALL();
}
/////////////////////////////////////////
// ParticleTypeDescriptor (non-synchronized)
// Holds physics/display information for a class of particles
/////////////////////////////////////////
public static class ParticleTypeDescriptor
extends Object
implements Cloneable {
protected static int _instanceCount = 0;
public ParticleTypeDescriptor ( double coefFriction,
double chargeF1, double chargeF2, double chargeF3,
double mass,
byte displayDiameter,
Color diplayColor,
String name, String description ) {
// validate parameters
ARGCHECK.checkTrue( coefFriction >= 0, "coefFriction must be non-negative" );
ARGCHECK.checkTrue( mass >= 0, "mass must be non-negative" );
ARGCHECK.checkTrue( displayDiameter > 0, "displayDiameter must be positive" );
ARGCHECK.checkNotNull( diplayColor, "displayColor must not be null" );
// fill in default name if name is null
if( name == null )
name = "Particle Type " + _instanceCount;
// save parameters
this.coefFriction = -coefFriction;
this.chargeF1 = chargeF1; this.chargeF2 = chargeF2; this.chargeF3 = chargeF3;
this.mass = mass; this.invMass = 1/mass;
this.displayDiameter = displayDiameter;
this.displayColor = displayColor;
this.name = name; this.description = description;
// increment _instanceCount
_instanceCount++;
}
public String toString() {
return name
+ "\n\tcoefFriction = " + coefFriction
+ "\n\tchargeF1 = " + chargeF1 + ", chargeF2 = " + chargeF2 + ", chargeF3 = " + chargeF3
+ "\n\tmass = " + mass
+ "\n\tdiplayDiameter = " + displayDiameter
+ "\n\tdiplayColor = " + displayColor;
}
// physical characteristics
// calculations are unit correct
// distance is expresed in pixels, time in seconds
public final double coefFriction;
public final double chargeF1, chargeF2, chargeF3;
public final double mass, invMass;
// display characteristics
public final byte displayDiameter;
public final Color displayColor;
// name and description
public final String name, description;
}
/////////////////////////////////////////
// ParticleState (non-synchronized)
// Holds postion and velocity information for a particle
/////////////////////////////////////////
public static class ParticleState
extends Object
implements Cloneable {
///////////////////////////////////////////////
static int _instanceCount = 0;
public ParticleState( double xPos, double yPos, double xVel, double yVel, int diameter ) {
this.xPos = xPos; this.yPos = yPos;
this.xVel = xVel; this.yVel = yVel;
scrPos.x = -(diameter/2); scrPos.y = -(diameter/2) ;
scrPos.width = radius; scrPos.height = radius;
_instanceCount++;
}
public ParticleState( double xPos, double yPos, int diameter ) {
ParticleState( xPos, yPos, 0, 0, diameter );
}
public ParticleStat
- duplicates
-
JDK-4062064 javac: sun.tools.java.CompilerError: addReference <whatever> this
-
- Closed
-