Package org.jbox2d.testbed.framework
Class TestbedTest
- java.lang.Object
-
- org.jbox2d.testbed.framework.TestbedTest
-
- All Implemented Interfaces:
ContactListener
,JbDeserializer.ObjectListener
,JbSerializer.ObjectSigner
,UnsupportedListener
- Direct Known Subclasses:
ApplyForce
,BlobTest4
,BodyTypes
,Breakable
,Cantilever
,Car
,Chain
,CharacterCollision
,CircleStress
,CollisionFiltering
,CollisionProcessing
,CompoundShapes
,ConfinedTest
,ContinuousTest
,ConvexHull
,ConveyorBelt
,DistanceTest
,DominoTest
,DominoTower
,DynamicTreeTest
,EdgeShapes
,FixedPendulumTest
,FreePendulumTest
,Gears
,LiquidTest
,OneSidedTest
,PistonTest
,PolyShapes
,PrismaticTest
,Pulleys
,PyramidTest
,RayCastTest
,RevoluteTest
,RopeTest
,SensorTest
,ShapeEditing
,SliderCrankTest
,SphereStack
,TheoJansen
,Tumbler
,VaryingFrictionTest
,VaryingRestitution
,VerticalStack
,Web
public abstract class TestbedTest extends java.lang.Object implements ContactListener, JbDeserializer.ObjectListener, JbSerializer.ObjectSigner, UnsupportedListener
-
-
Field Summary
Fields Modifier and Type Field Description private AABB
aabb
private Body
bomb
protected static long
BOMB_TAG
private boolean
bombSpawning
private Vec2
bombSpawnPoint
private Vec2
cachedCameraPos
private float
cachedCameraScale
private TestQueryCallback
callback
private Color3f
color1
private Color3f
color2
private Color3f
color3
private Color3f
color4
private Color3f
color5
private JbDeserializer
deserializer
protected DestructionListener
destructionListener
private boolean
dialogOnSaveLoadErrors
protected static long
GROUND_BODY_TAG
protected Body
groundBody
private boolean
hasCachedCamera
private java.util.LinkedList<QueueItem>
inputQueue
private boolean
loadPending
private static org.slf4j.Logger
log
protected int
m_textLine
protected World
m_world
Only visible for compatibility.static int
MAX_CONTACT_POINTS
private TestbedModel
model
protected static long
MOUSE_JOINT_TAG
private Color3f
mouseColor
private MouseJoint
mouseJoint
private Vec2
mouseWorld
private Vec2
p
private Vec2
p1
private Vec2
p2
private int
pointCount
static ContactPoint[]
points
private AABB
queryAABB
private boolean
resetPending
private boolean
savePending
private JbSerializer
serializer
private Collision.PointState[]
state1
private Collision.PointState[]
state2
private java.util.List<java.lang.String>
statsList
private int
stepCount
private Vec2
tangent
private java.util.LinkedList<java.lang.String>
textList
private java.lang.String
title
private Vec2
v
private Vec2
vel
private WorldManifold
worldManifold
-
Constructor Summary
Constructors Constructor Description TestbedTest()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
_load()
protected void
_reset()
protected void
_save()
void
addTextLine(java.lang.String argTextLine)
Adds a text line to the reporting areavoid
beginContact(Contact contact)
Called when two fixtures begin to touch.void
completeBombSpawn(Vec2 p)
void
endContact(Contact contact)
Called when two fixtures cease to touch.void
exit()
called when the tests exitsBody
getBomb()
Gets the 'bomb' body if it's presentVec2
getCachedCameraPos()
float
getCachedCameraScale()
static ContactPoint[]
getContactPoints()
Gets the contact points for the current testDebugDraw
getDebugDraw()
Gets the debug draw for the testbedVec2
getDefaultCameraPos()
Override for a different default camera posfloat
getDefaultCameraScale()
Override for a different default camera scalejava.lang.String
getFilename()
Gets the filename of the current test.Body
getGroundBody()
Gets the ground body of the world, used for some jointsTestbedModel
getModel()
Gets the testbed modelint
getPointCount()
The number of contact points we're storingint
getStepCount()
java.lang.Long
getTag(Shape shape)
java.lang.Long
getTag(Body body)
java.lang.Long
getTag(Fixture fixture)
java.lang.Long
getTag(Joint joint)
java.lang.Long
getTag(World world)
abstract java.lang.String
getTestName()
The name of the testWorld
getWorld()
Gets the current worldVec2
getWorldMouse()
Gets the world position of the mousevoid
init(World argWorld, boolean argDeserialized)
void
init(TestbedModel argModel)
abstract void
initTest(boolean deserialized)
Initializes the current testboolean
isDialogOnSaveLoadErrors()
boolean
isHasCachedCamera()
boolean
isSaveLoadEnabled()
Override to enable saving and loading.boolean
isUnsupported(UnsupportedObjectException exception)
Called when an object is unsupported by the de/serializer.void
jointDestroyed(Joint joint)
void
keyPressed(char keyCar, int keyCode)
void
keyReleased(char keyChar, int keyCode)
void
lanchBomb()
void
launchBomb(Vec2 position, Vec2 velocity)
void
load()
Loads the test from filevoid
mouseDown(Vec2 p)
Called for mouse-downvoid
mouseMove(Vec2 p)
Called when mouse is movedvoid
mouseUp(Vec2 p)
Called for mouse-upvoid
postSolve(Contact contact, ContactImpulse impulse)
This lets you inspect a contact after the solver is finished.void
preSolve(Contact contact, Manifold oldManifold)
This is called after a contact is updated.void
processBody(Body body, java.lang.Long tag)
void
processFixture(Fixture fixture, java.lang.Long tag)
void
processJoint(Joint joint, java.lang.Long tag)
void
processShape(Shape shape, java.lang.Long tag)
void
processWorld(World world, java.lang.Long tag)
void
queueKeyPressed(char c, int code)
void
queueKeyReleased(char c, int code)
void
queueMouseDown(Vec2 p)
void
queueMouseMove(Vec2 p)
void
queueMouseUp(Vec2 p)
void
queueShiftMouseDown(Vec2 p)
void
reset()
Resets the testvoid
save()
Saves the testvoid
setCachedCameraPos(Vec2 argPos)
void
setCachedCameraScale(float cachedCameraScale)
void
setCamera(Vec2 argPos)
void
setCamera(Vec2 argPos, float scale)
Sets the current testbed cameravoid
setDialogOnSaveLoadErrors(boolean dialogOnSaveLoadErrors)
void
setHasCachedCamera(boolean hasCachedCamera)
void
setTitle(java.lang.String argTitle)
Sets the title of the testvoid
shiftMouseDown(Vec2 p)
Called when shift-mouse down occursvoid
spawnBomb(Vec2 worldPt)
void
step(TestbedSettings settings)
void
update()
-
-
-
Field Detail
-
MAX_CONTACT_POINTS
public static final int MAX_CONTACT_POINTS
- See Also:
- Constant Field Values
-
GROUND_BODY_TAG
protected static final long GROUND_BODY_TAG
- See Also:
- Constant Field Values
-
BOMB_TAG
protected static final long BOMB_TAG
- See Also:
- Constant Field Values
-
MOUSE_JOINT_TAG
protected static final long MOUSE_JOINT_TAG
- See Also:
- Constant Field Values
-
log
private static final org.slf4j.Logger log
-
points
public static final ContactPoint[] points
-
m_world
protected World m_world
Only visible for compatibility. Should usegetWorld()
instead.
-
groundBody
protected Body groundBody
-
mouseJoint
private MouseJoint mouseJoint
-
bomb
private Body bomb
-
bombSpawnPoint
private final Vec2 bombSpawnPoint
-
bombSpawning
private boolean bombSpawning
-
mouseWorld
private final Vec2 mouseWorld
-
pointCount
private int pointCount
-
stepCount
private int stepCount
-
model
private TestbedModel model
-
destructionListener
protected DestructionListener destructionListener
-
inputQueue
private final java.util.LinkedList<QueueItem> inputQueue
-
title
private java.lang.String title
-
m_textLine
protected int m_textLine
-
textList
private final java.util.LinkedList<java.lang.String> textList
-
cachedCameraScale
private float cachedCameraScale
-
cachedCameraPos
private final Vec2 cachedCameraPos
-
hasCachedCamera
private boolean hasCachedCamera
-
serializer
private JbSerializer serializer
-
deserializer
private JbDeserializer deserializer
-
dialogOnSaveLoadErrors
private boolean dialogOnSaveLoadErrors
-
savePending
private boolean savePending
-
loadPending
private boolean loadPending
-
resetPending
private boolean resetPending
-
color1
private final Color3f color1
-
color2
private final Color3f color2
-
color3
private final Color3f color3
-
color4
private final Color3f color4
-
color5
private final Color3f color5
-
mouseColor
private final Color3f mouseColor
-
p1
private final Vec2 p1
-
p2
private final Vec2 p2
-
tangent
private final Vec2 tangent
-
statsList
private final java.util.List<java.lang.String> statsList
-
queryAABB
private final AABB queryAABB
-
callback
private final TestQueryCallback callback
-
p
private final Vec2 p
-
v
private final Vec2 v
-
aabb
private final AABB aabb
-
vel
private final Vec2 vel
-
state1
private final Collision.PointState[] state1
-
state2
private final Collision.PointState[] state2
-
worldManifold
private final WorldManifold worldManifold
-
-
Method Detail
-
init
public void init(TestbedModel argModel)
-
init
public void init(World argWorld, boolean argDeserialized)
-
getWorld
public World getWorld()
Gets the current world- Returns:
-
getModel
public TestbedModel getModel()
Gets the testbed model- Returns:
-
getContactPoints
public static ContactPoint[] getContactPoints()
Gets the contact points for the current test- Returns:
-
getGroundBody
public Body getGroundBody()
Gets the ground body of the world, used for some joints- Returns:
-
getDebugDraw
public DebugDraw getDebugDraw()
Gets the debug draw for the testbed- Returns:
-
getWorldMouse
public Vec2 getWorldMouse()
Gets the world position of the mouse- Returns:
-
getStepCount
public int getStepCount()
-
getPointCount
public int getPointCount()
The number of contact points we're storing- Returns:
-
getBomb
public Body getBomb()
Gets the 'bomb' body if it's present- Returns:
-
getCachedCameraScale
public float getCachedCameraScale()
-
setCachedCameraScale
public void setCachedCameraScale(float cachedCameraScale)
-
getCachedCameraPos
public Vec2 getCachedCameraPos()
-
setCachedCameraPos
public void setCachedCameraPos(Vec2 argPos)
-
isHasCachedCamera
public boolean isHasCachedCamera()
-
setHasCachedCamera
public void setHasCachedCamera(boolean hasCachedCamera)
-
isDialogOnSaveLoadErrors
public boolean isDialogOnSaveLoadErrors()
-
setDialogOnSaveLoadErrors
public void setDialogOnSaveLoadErrors(boolean dialogOnSaveLoadErrors)
-
getDefaultCameraPos
public Vec2 getDefaultCameraPos()
Override for a different default camera pos- Returns:
-
getDefaultCameraScale
public float getDefaultCameraScale()
Override for a different default camera scale- Returns:
-
getFilename
public java.lang.String getFilename()
Gets the filename of the current test. Default implementation uses the test name with no spaces".- Returns:
-
reset
public void reset()
Resets the test
-
save
public void save()
Saves the test
-
load
public void load()
Loads the test from file
-
_reset
protected void _reset()
-
_save
protected void _save()
-
_load
protected void _load()
-
setCamera
public void setCamera(Vec2 argPos)
-
setCamera
public void setCamera(Vec2 argPos, float scale)
Sets the current testbed camera- Parameters:
argPos
-scale
-
-
initTest
public abstract void initTest(boolean deserialized)
Initializes the current test- Parameters:
argDeserialized
- if the test was deserialized from a file. If so, all physics objects were already added.
-
getTestName
public abstract java.lang.String getTestName()
The name of the test- Returns:
-
exit
public void exit()
called when the tests exits
-
update
public void update()
-
step
public void step(TestbedSettings settings)
-
queueShiftMouseDown
public void queueShiftMouseDown(Vec2 p)
-
queueMouseUp
public void queueMouseUp(Vec2 p)
-
queueMouseDown
public void queueMouseDown(Vec2 p)
-
queueMouseMove
public void queueMouseMove(Vec2 p)
-
queueKeyPressed
public void queueKeyPressed(char c, int code)
-
queueKeyReleased
public void queueKeyReleased(char c, int code)
-
shiftMouseDown
public void shiftMouseDown(Vec2 p)
Called when shift-mouse down occurs- Parameters:
p
-
-
mouseUp
public void mouseUp(Vec2 p)
Called for mouse-up- Parameters:
p
-
-
mouseDown
public void mouseDown(Vec2 p)
Called for mouse-down- Parameters:
p
-
-
mouseMove
public void mouseMove(Vec2 p)
Called when mouse is moved- Parameters:
p
-
-
setTitle
public void setTitle(java.lang.String argTitle)
Sets the title of the test- Parameters:
argTitle
-
-
addTextLine
public void addTextLine(java.lang.String argTextLine)
Adds a text line to the reporting area- Parameters:
argTextLine
-
-
lanchBomb
public void lanchBomb()
-
spawnBomb
public void spawnBomb(Vec2 worldPt)
-
completeBombSpawn
public void completeBombSpawn(Vec2 p)
-
isSaveLoadEnabled
public boolean isSaveLoadEnabled()
Override to enable saving and loading. Remember to also override theJbDeserializer.ObjectListener
andJbSerializer.ObjectSigner
methods if you need to- Returns:
-
getTag
public java.lang.Long getTag(Body body)
- Specified by:
getTag
in interfaceJbSerializer.ObjectSigner
- Returns:
- the tag for the body. can be null.
-
getTag
public java.lang.Long getTag(Fixture fixture)
- Specified by:
getTag
in interfaceJbSerializer.ObjectSigner
- Returns:
- the tag for the fixture. can be null.
-
getTag
public java.lang.Long getTag(Joint joint)
- Specified by:
getTag
in interfaceJbSerializer.ObjectSigner
- Returns:
- the tag for the joint. can be null.
-
getTag
public java.lang.Long getTag(Shape shape)
- Specified by:
getTag
in interfaceJbSerializer.ObjectSigner
- Returns:
- the tag for the shape. can be null.
-
getTag
public java.lang.Long getTag(World world)
- Specified by:
getTag
in interfaceJbSerializer.ObjectSigner
- Returns:
- the tag for the world. can be null.
-
processBody
public void processBody(Body body, java.lang.Long tag)
- Specified by:
processBody
in interfaceJbDeserializer.ObjectListener
-
processFixture
public void processFixture(Fixture fixture, java.lang.Long tag)
- Specified by:
processFixture
in interfaceJbDeserializer.ObjectListener
-
processJoint
public void processJoint(Joint joint, java.lang.Long tag)
- Specified by:
processJoint
in interfaceJbDeserializer.ObjectListener
-
processShape
public void processShape(Shape shape, java.lang.Long tag)
- Specified by:
processShape
in interfaceJbDeserializer.ObjectListener
-
processWorld
public void processWorld(World world, java.lang.Long tag)
- Specified by:
processWorld
in interfaceJbDeserializer.ObjectListener
-
isUnsupported
public boolean isUnsupported(UnsupportedObjectException exception)
Description copied from interface:UnsupportedListener
Called when an object is unsupported by the de/serializer.- Specified by:
isUnsupported
in interfaceUnsupportedListener
- Parameters:
exception
- the exception describing the error- Returns:
- if the process should stop and the exception be thrown
-
jointDestroyed
public void jointDestroyed(Joint joint)
-
beginContact
public void beginContact(Contact contact)
Description copied from interface:ContactListener
Called when two fixtures begin to touch.- Specified by:
beginContact
in interfaceContactListener
-
endContact
public void endContact(Contact contact)
Description copied from interface:ContactListener
Called when two fixtures cease to touch.- Specified by:
endContact
in interfaceContactListener
-
postSolve
public void postSolve(Contact contact, ContactImpulse impulse)
Description copied from interface:ContactListener
This lets you inspect a contact after the solver is finished. This is useful for inspecting impulses. Note: the contact manifold does not include time of impact impulses, which can be arbitrarily large if the sub-step is small. Hence the impulse is provided explicitly in a separate data structure. Note: this is only called for contacts that are touching, solid, and awake.- Specified by:
postSolve
in interfaceContactListener
impulse
- this is usually a pooled variable, so it will be modified after this call
-
preSolve
public void preSolve(Contact contact, Manifold oldManifold)
Description copied from interface:ContactListener
This is called after a contact is updated. This allows you to inspect a contact before it goes to the solver. If you are careful, you can modify the contact manifold (e.g. disable contact). A copy of the old manifold is provided so that you can detect changes. Note: this is called only for awake bodies. Note: this is called even when the number of contact points is zero. Note: this is not called for sensors. Note: if you set the number of contact points to zero, you will not get an EndContact callback. However, you may get a BeginContact callback the next step. Note: the oldManifold parameter is pooled, so it will be the same object for every callback for each thread.- Specified by:
preSolve
in interfaceContactListener
-
keyPressed
public void keyPressed(char keyCar, int keyCode)
-
keyReleased
public void keyReleased(char keyChar, int keyCode)
-
-