Android Open Source - RubeLoader Rube World Serializer






From Project

Back to project page RubeLoader.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUC...

If you think the Android project RubeLoader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gushikustudios.rube.loader.serializers;
/*from   w w  w . j  ava2  s. co m*/
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonValue;
import com.badlogic.gdx.utils.Json.ReadOnlySerializer;
import com.gushikustudios.rube.RubeDefaults;
import com.gushikustudios.rube.RubeScene;

public class RubeWorldSerializer extends ReadOnlySerializer<RubeScene>
{
  private WorldSerializer mWorldSerializer;
  private RubeScene scene;
  private boolean mScenePopulated;
   
  public RubeWorldSerializer(Json json)
  {
    scene = new RubeScene();
    mWorldSerializer = new WorldSerializer(scene,json);
    json.setSerializer(World.class, mWorldSerializer);
    json.setIgnoreUnknownFields(true);
  }
  
  public void resetScene()
  {
     if (scene != null)
     {
        World world = scene.getWorld();
        if (world != null)
        {
           world.dispose();
        }
        scene.clear();
     }
     mScenePopulated = false;
  }
  
  public void usePreexistingWorld(World world)
  {
     if (scene != null)
     {
        scene.setWorld(world);
     }
     mScenePopulated = true; // prevent a new world from being defined
  }
  
  @SuppressWarnings("rawtypes")
  @Override
  public RubeScene read(Json json, JsonValue jsonData, Class type) 
  {
     if (!mScenePopulated)
     {
        scene.stepsPerSecond     = json.readValue("stepsPerSecond",     int.class, RubeDefaults.World.stepsPerSecond,     jsonData);
        scene.positionIterations   = json.readValue("positionIterations",   int.class, RubeDefaults.World.positionIterations,   jsonData);
        scene.velocityIterations   = json.readValue("velocityIterations",   int.class, RubeDefaults.World.velocityIterations,   jsonData);
        scene.setWorld(json.readValue(World.class,  jsonData));
        mScenePopulated = true;
     }
     else
     {
        // ignore scene related items.  The read below will add items to the world and scene previously read
        json.readValue(World.class, jsonData);
     }
    return scene;
  }
}




Java Source Code List

com.gushikustudios.rube.MainActivity.java
com.gushikustudios.rube.PolySpatial.java
com.gushikustudios.rube.PolySpatial.java
com.gushikustudios.rube.RubeDefaults.java
com.gushikustudios.rube.RubeLoaderTestDesktop.java
com.gushikustudios.rube.RubeLoaderTestDesktop.java
com.gushikustudios.rube.RubeLoaderTest.java
com.gushikustudios.rube.RubeLoaderTest.java
com.gushikustudios.rube.RubeScene.java
com.gushikustudios.rube.SimpleSpatial.java
com.gushikustudios.rube.SimpleSpatial.java
com.gushikustudios.rube.loader.RubeSceneAsyncLoader.java
com.gushikustudios.rube.loader.RubeSceneLoader.java
com.gushikustudios.rube.loader.RubeSceneSyncLoader.java
com.gushikustudios.rube.loader.serializers.BodySerializer.java
com.gushikustudios.rube.loader.serializers.FixtureSerializer.java
com.gushikustudios.rube.loader.serializers.ImageSerializer.java
com.gushikustudios.rube.loader.serializers.JointSerializer.java
com.gushikustudios.rube.loader.serializers.RubeWorldSerializer.java
com.gushikustudios.rube.loader.serializers.Vector2Serializer.java
com.gushikustudios.rube.loader.serializers.WorldSerializer.java
com.gushikustudios.rube.loader.serializers.utils.RubeImage.java
com.gushikustudios.rube.loader.serializers.utils.RubeVertexArray.java