public class Vertex3f extends MemoryMappedObject {
public float x;
public float y;
public float y;
public Vertex3f(ByteBuffer bb) {
super(bb);
}
// … some Vertex3f specific methods
}
where MemoryMappedObject would implement position/sliding method, normally visible, without any tricks.
Bytecode weaver would do following:
- If something extends MemoryMappedObject, remove the public fields, create correct getters/setters with any magic inside which is needed (depending on implementation), probably also pass SIZEOF as extra argument to super constructor
- If something accesses any field from MemoryMappedObject, convert get/putfield to getter/setter calls.
On top of that, I could imagine few extra properties/annotations
a) possibility of explicitly giving sizeof parameter (passing to super constructor, or in annotation which would be weaved to be passed in constructor) - for easy alignment
b) specifying explicit offset of particular field
c) specifying endianess of particular field
d) (optionally, not sure about that, especially about multiple-dimensions) posibility to denote arrays of values, like
public Matrix4f extends MemoryMappedObject {
@Dimension(4,4)
public float[][] data;
}
with calls like matrix.data[x][y] would be automatically converted to matrix.getData(x*4+y)
With enough magic, it could even work on stuff like
@Alignment(128)
public VertexData extends MemoryMappedObject {
@Offset(16) public Color4f rgba;
@Offset(32) public Vector3f position;
@Offset(48) public Vector3f normal;
public float m1,z2,f3;
}
With Color4f and Vector3f being other MMO, expanded inline for VertexData. Alignment/Offset can be replaced with padding elements, so they are not required -I’m just throwing ideas around.