mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 16:49:12 +00:00
Pack the values in GameObject into a single integer, to reduce memory usage.
This commit is contained in:
@@ -12,19 +12,9 @@ import org.apollo.game.model.def.ObjectDefinition;
|
|||||||
public final class GameObject extends Entity {
|
public final class GameObject extends Entity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The object's definition.
|
* The config value that stores the object's id, type, and orientation.
|
||||||
*/
|
*/
|
||||||
private final ObjectDefinition definition;
|
private final int config;
|
||||||
|
|
||||||
/**
|
|
||||||
* The object's orientation.
|
|
||||||
*/
|
|
||||||
private final int orientation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The object type.
|
|
||||||
*/
|
|
||||||
private final int type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a game object.
|
* Creates a game object.
|
||||||
@@ -36,9 +26,7 @@ public final class GameObject extends Entity {
|
|||||||
*/
|
*/
|
||||||
public GameObject(int id, Position position, int type, int orientation) {
|
public GameObject(int id, Position position, int type, int orientation) {
|
||||||
super(position);
|
super(position);
|
||||||
this.type = type;
|
this.config = (id * 256) + (type * 4) + orientation;
|
||||||
this.orientation = orientation;
|
|
||||||
definition = ObjectDefinition.lookup(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,7 +35,7 @@ public final class GameObject extends Entity {
|
|||||||
* @return The object's definition.
|
* @return The object's definition.
|
||||||
*/
|
*/
|
||||||
public ObjectDefinition getDefinition() {
|
public ObjectDefinition getDefinition() {
|
||||||
return definition;
|
return ObjectDefinition.lookup(getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -61,7 +49,7 @@ public final class GameObject extends Entity {
|
|||||||
* @return The id.
|
* @return The id.
|
||||||
*/
|
*/
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return definition.getId();
|
return config / 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,7 +58,7 @@ public final class GameObject extends Entity {
|
|||||||
* @return The orientation.
|
* @return The orientation.
|
||||||
*/
|
*/
|
||||||
public int getRotation() {
|
public int getRotation() {
|
||||||
return orientation;
|
return config & 0x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,13 +67,13 @@ public final class GameObject extends Entity {
|
|||||||
* @return The type.
|
* @return The type.
|
||||||
*/
|
*/
|
||||||
public int getType() {
|
public int getType() {
|
||||||
return type;
|
return (config >> 2) & 0x3F;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return GameObject.class.getName() + " [id=" + definition.getId() + ", type=" + type + ", rotation="
|
return GameObject.class.getName() + " [id=" + getId() + ", type=" + getType() + ", rotation=" + getRotation()
|
||||||
+ orientation + "]";
|
+ "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user