Alright, I won’t rule out it’s my code. Here are the two classes. The attached set of rooms is told to execute removeSelf() and the new
batch of rooms is told to exectute attachSelf(). They are also told to updateCenterObject() when a specific action in gameplay occurs. Doors are first called to do attachSelf(), and then each new floor they are told to reset(). They are also told to unlock() and open() during gameplay. These are the only places I load models so the memory issue must be in here, if there even is one. It’s entirely possible that I’m freaking out about nothing, that the garbage collector will begin to do it’s job when the judges are testing.
[java]
public class Room
{
protected Main app;
private String event;
private String scenario;
private String question;
private String solution;
private String correction;
protected int x;
protected int z;
private boolean scene;
private Spatial roomScene;
private RigidBodyControl roomControl;
private CollisionShape sceneShape;
private Spatial centerObject;
private RigidBodyControl centerObjectControl;
private CollisionShape centerObjectShape;
protected static int numberOfRooms = 0;
protected String roomID;
private boolean updateCenter;
public Room(String event, String scenario, String question, String solution, String correction, Boolean scene, Boolean updateCenter, Main app)
{
this.app = app;
this.event = event;
this.scenario = scenario;
this.question = question;
this.solution = solution;
this.correction = correction;
this.scene = scene;
this.updateCenter = updateCenter;
x = 0;
z = 0;
numberOfRooms++;
roomID = "Room" + numberOfRooms + "!";
}
public Room(Main app)
{
this.app = app;
numberOfRooms++;
roomID = "BonusRoom" + numberOfRooms + "!";
}
public void attachSelf(int givenX, int givenZ)
{
x = givenX;
z = givenZ;
if ( scene )
{
roomScene = app.getAssetManager().loadModel("Models/Rooms/" + event + " Scene/" + event + " Scene.j3o");
roomScene.setLocalScale(1.35f);
roomScene.setLocalTranslation(22 * x, 2, -22 * z);
roomScene.setName("Scenery!");
sceneShape = CollisionShapeFactory.createMeshShape((Node) roomScene);
roomControl = new RigidBodyControl(sceneShape, 0);
roomScene.addControl(roomControl);
app.getBulletAppState().getPhysicsSpace().add(roomControl);
app.getCollidables().attachChild(roomScene);
}
centerObject = app.getAssetManager().loadModel("Models/Rooms/" + event + "/" + event + ".j3o");
centerObject.setLocalScale(1.35f);
centerObject.setName(roomID);
centerObject.setLocalTranslation(22 * x, 2, -22 * z);
centerObjectShape = CollisionShapeFactory.createMeshShape((Node) centerObject);
centerObjectControl = new RigidBodyControl(centerObjectShape, 0);
centerObject.addControl(centerObjectControl);
app.getBulletAppState().getPhysicsSpace().add(centerObjectControl);
app.getCollidables().attachChild(centerObject);
}
public void updateCenterObject()
{
if (updateCenter)
{
centerObject.removeControl(centerObjectControl);
app.getBulletAppState().getPhysicsSpace().remove(centerObjectControl);
app.getCollidables().detachChild(centerObject);
centerObject = app.getAssetManager().loadModel("Models/Rooms/" + event + " Complete/" + event + " Complete.j3o");
centerObject.setLocalScale(1.35f);
centerObject.setName(roomID);
centerObject.setLocalTranslation(22 * x, 2, -22 * z);
centerObjectShape = CollisionShapeFactory.createMeshShape((Node) centerObject);
centerObjectControl = new RigidBodyControl(centerObjectShape, 0);
centerObject.addControl(centerObjectControl);
app.getBulletAppState().getPhysicsSpace().add(centerObjectControl);
app.getCollidables().attachChild(centerObject);
}
( (DesktopAssetManager) app.getAssetManager()).clearCache();
}
public void removeSelf()
{
if ( roomScene != null )
{
roomScene.removeControl(roomControl);
app.getBulletAppState().getPhysicsSpace().remove(roomControl);
app.getCollidables().detachChild(roomScene);
roomScene = null;
roomControl = null;
sceneShape = null;
}
centerObject.removeControl(centerObjectControl);
app.getBulletAppState().getPhysicsSpace().remove(centerObjectControl);
app.getCollidables().detachChild(centerObject);
centerObject = null;
centerObjectControl = null;
centerObjectShape = null;
event = null;
scenario = null;
question = null;
solution = null;
correction = null;
roomID = null;
}
}
[/java]
[java]
public class Door
{
private Main app;
private Spatial doorModel;
private RigidBodyControl rigidDoor;
private CollisionShape doorShape;
private int x;
private int z;
private boolean orientation; /* true = horizontal, false = vertical */
private static int numberOfDoors = 0;
private boolean unlocked;
private boolean opened;
public Door(Main app, int x, int z, boolean orientation)
{
/* The class constructor; initializes member variables */
this.app = app;
this.x = x;
this.z = z;
this.orientation = orientation;
numberOfDoors++;
unlocked = false;
opened = false;
}
public void createDoor()
{
this.doorModel = app.getAssetManager().loadModel("Models/Door/Door.j3o");
doorModel.setName("Door" + numberOfDoors + "!");
doorModel.setLocalScale(2f);
doorModel.setLocalTranslation(x, 2f, z);
if (!orientation)
{
doorModel.rotate(0f, -1 * FastMath.HALF_PI , 0f);
}
doorShape = CollisionShapeFactory.createMeshShape((Node) doorModel);
rigidDoor = new RigidBodyControl(doorShape, 0);
doorModel.addControl(rigidDoor);
app.getBulletAppState().getPhysicsSpace().add(rigidDoor);
app.getCollidables().attachChild(doorModel);
}
public void unlock()
{
unlocked = true;
}
public void open()
{
if (unlocked && !opened)
{
app.getAudioManager().playAudioNode("door");
doorModel.removeControl(rigidDoor);
app.getBulletAppState().getPhysicsSpace().remove(rigidDoor);
doorModel.rotate(0f, FastMath.PI, 0f);
opened = true;
}
}
public void reset(Main app)
{
unlocked = false;
opened = false;
app.getCollidables().detachChild(doorModel);
doorModel.setLocalRotation(Quaternion.ZERO);
if (!orientation)
{
Quaternion doorRotate = new Quaternion();
doorModel.setLocalRotation(doorRotate.fromAngleAxis(-1f * FastMath.HALF_PI, Vector3f.UNIT_Y));
}
doorModel.addControl(rigidDoor);
app.getBulletAppState().getPhysicsSpace().add(rigidDoor);
app.getCollidables().attachChild(doorModel);
}
}
[/java]