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 Details

    • MAX_CONTACT_POINTS

      public static final int MAX_CONTACT_POINTS
      See Also:
    • GROUND_BODY_TAG

      protected static final long GROUND_BODY_TAG
      See Also:
    • BOMB_TAG

      protected static final long BOMB_TAG
      See Also:
    • MOUSE_JOINT_TAG

      protected static final long MOUSE_JOINT_TAG
      See Also:
    • 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 use getWorld() 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
  • Constructor Details

    • TestbedTest

      public TestbedTest()
  • Method Details

    • 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()
    • launchBomb

      public void launchBomb(Vec2 position, Vec2 velocity)
    • 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 the JbDeserializer.ObjectListener and JbSerializer.ObjectSigner methods if you need to
      Returns:
    • getTag

      public java.lang.Long getTag(Body body)
      Specified by:
      getTag in interface JbSerializer.ObjectSigner
      Parameters:
      body -
      Returns:
      the tag for the body. can be null.
    • getTag

      public java.lang.Long getTag(Fixture fixture)
      Specified by:
      getTag in interface JbSerializer.ObjectSigner
      Parameters:
      fixture -
      Returns:
      the tag for the fixture. can be null.
    • getTag

      public java.lang.Long getTag(Joint joint)
      Specified by:
      getTag in interface JbSerializer.ObjectSigner
      Parameters:
      joint -
      Returns:
      the tag for the joint. can be null.
    • getTag

      public java.lang.Long getTag(Shape shape)
      Specified by:
      getTag in interface JbSerializer.ObjectSigner
      Parameters:
      shape -
      Returns:
      the tag for the shape. can be null.
    • getTag

      public java.lang.Long getTag(World world)
      Specified by:
      getTag in interface JbSerializer.ObjectSigner
      Parameters:
      world -
      Returns:
      the tag for the world. can be null.
    • processBody

      public void processBody(Body body, java.lang.Long tag)
      Specified by:
      processBody in interface JbDeserializer.ObjectListener
    • processFixture

      public void processFixture(Fixture fixture, java.lang.Long tag)
      Specified by:
      processFixture in interface JbDeserializer.ObjectListener
    • processJoint

      public void processJoint(Joint joint, java.lang.Long tag)
      Specified by:
      processJoint in interface JbDeserializer.ObjectListener
    • processShape

      public void processShape(Shape shape, java.lang.Long tag)
      Specified by:
      processShape in interface JbDeserializer.ObjectListener
    • processWorld

      public void processWorld(World world, java.lang.Long tag)
      Specified by:
      processWorld in interface JbDeserializer.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 interface UnsupportedListener
      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 interface ContactListener
      Parameters:
      contact -
    • endContact

      public void endContact(Contact contact)
      Description copied from interface: ContactListener
      Called when two fixtures cease to touch.
      Specified by:
      endContact in interface ContactListener
      Parameters:
      contact -
    • 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 interface ContactListener
      Parameters:
      contact -
      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 interface ContactListener
      Parameters:
      contact -
      oldManifold -
    • keyPressed

      public void keyPressed(char keyCar, int keyCode)
    • keyReleased

      public void keyReleased(char keyChar, int keyCode)