## gravity-simulator.api
#
# Define interface to our (primitive) physics engine.
# This runs a thread regularly updating the positions
# of the planets according to n-body gravitational interactions.
# Compiled by:
#
src/lib/x-kit/tut/nbody/nbody-app.lib# This api is implemented in:
#
src/lib/x-kit/tut/nbody/gravity-simulator.pkgstipulate
include package threadkit; # threadkit is from
src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkgherein
api Gravity_Simulator {
package v: api {
Vector = (Float, Float); # Was abstract, had to make concrete to get nbody.pkg to compile. -- 2009-12-10 CrT
proj2d: Vector -> { x: Float, y: Float };
};
Vector = v::Vector;
Planet(X)
=
{ position: Vector, # 2-D Float position.
velocity: Vector, # 2-D Float velocity.
mass: Float, # Mass in grams.
user_data: X # Arbitrary user data associated with planet.
};
Plea_Mail(X)
= SET_SIMSECS_PER_SIMSTEP Float # Seconds of simulation time per gravity simulation step.
| SET_SIMSTEPS_PER_50MS Int
# Number of orbiting bodies.
| ADD_PLANET Planet(X)
# New orbiting body.
| GET_PLANETS Mailslot( List( Planet(X) ))
# Return list of currently orbiting planets.
| STOP
;
start:
{ g: Float, # Gravitational constant in CGS ("centimeter-gram-seconds") system (6.67428e-8)
planets: List( Planet(X) ), # List of orbiting bodies.
#
simsecs_per_simstep: Float, # Seconds of simulation time per gravitational simulation step.
simsteps_per_50ms: Int, # Set relationship between simulation time and real wallclock time.
plea_slot: Mailslot( Plea_Mail(X) )
}
->
Microthread;
};
end;