Removed sizeof from @MappedType, it's calculated automatically now.

Added padding to @MappedType, defaults to 0.
Added support for @Pointer long fields for easier interaction with pointer data.
This commit is contained in:
Ioannis Tsakpinis 2011-07-23 22:02:01 +00:00
parent 896e363979
commit d0cb1f8c90
14 changed files with 388 additions and 221 deletions

View file

@ -35,7 +35,7 @@ import org.lwjgl.util.mapped.MappedObject;
import org.lwjgl.util.mapped.MappedType;
/** @author Riven */
@MappedType(sizeof = 4)
@MappedType
public class MappedFloat extends MappedObject {
public MappedFloat() {

View file

@ -82,7 +82,7 @@ public class MappedObjectTests3 {
System.out.println("current.view=" + some.view + ", not " + elementCount + ", as you might expect");
}
@MappedType(sizeof = 12)
@MappedType
public static class Xyz extends MappedObject {
int x, y, z;

View file

@ -32,7 +32,11 @@
package org.lwjgl.test.mapped;
import org.lwjgl.MemoryUtil;
import org.lwjgl.PointerBuffer;
import org.lwjgl.opengl.Display;
import org.lwjgl.util.mapped.MappedObject;
import org.lwjgl.util.mapped.MappedType;
import org.lwjgl.util.mapped.Pointer;
import java.io.File;
import java.nio.ByteBuffer;
@ -112,4 +116,35 @@ public class MappedObjectTests4 {
}
}
@MappedType
public static class MappedPointer extends MappedObject {
int foo;
@Pointer long pointer;
int bar;
}
public static void testPointer() {
MappedPointer data = MappedPointer.malloc(100);
assert (data.backingByteBuffer().capacity() == 100 * (4 + 4 + PointerBuffer.getPointerSize()));
for ( int i = 0; i < 100; i++ ) {
data.view = i;
data.foo = i;
data.pointer = i * 1000;
data.bar = i * 2;
}
for ( int i = 0; i < 100; i++ ) {
data.view = i;
assert (data.foo == i);
assert (data.pointer == i * 1000);
assert (data.bar == i * 2);
}
}
}

View file

@ -38,7 +38,7 @@ import org.lwjgl.util.mapped.MappedType;
import java.nio.ByteBuffer;
/** @author Riven */
@MappedType(sizeof = 64)
@MappedType
public class MappedSomething extends MappedObject {
@MappedField(byteOffset = 0)

View file

@ -35,7 +35,7 @@ import org.lwjgl.util.mapped.MappedObject;
import org.lwjgl.util.mapped.MappedType;
/** @author Riven */
@MappedType(sizeof = 8)
@MappedType
public class MappedVec2 extends MappedObject {
public float x;

View file

@ -35,7 +35,7 @@ import org.lwjgl.util.mapped.MappedObject;
import org.lwjgl.util.mapped.MappedType;
/** @author Riven */
@MappedType(sizeof = 12)
@MappedType
public class MappedVec3 extends MappedObject {
public float x;

View file

@ -51,6 +51,7 @@ public class TestMappedObject {
MappedObjectTransformer.register(MappedVec3.class);
MappedObjectTransformer.register(MappedSomething.class);
MappedObjectTransformer.register(MappedObjectTests3.Xyz.class);
MappedObjectTransformer.register(MappedObjectTests4.MappedPointer.class);
if ( MappedObjectClassLoader.fork(TestMappedObject.class, args) ) {
return;
@ -72,9 +73,8 @@ public class TestMappedObject {
MappedObjectTests3.testMappedSet();
MappedObjectTests4.testLocalView();
//MappedObjectTests4.testLWJGL();
MappedObjectTests4.testPointer();
System.out.println("done");
}

View file

@ -204,14 +204,14 @@ public final class SpriteShootoutMapped {
return texID;
}
@MappedType(sizeof = 4)
@MappedType
public static class Pixel4b extends MappedObject {
public byte r, g, b, a;
}
@MappedType(sizeof = 3, align = 3)
@MappedType(align = 3)
public static class Pixel3b extends MappedObject {
public byte r, g, b;
@ -413,15 +413,15 @@ public final class SpriteShootoutMapped {
Display.destroy();
}
@MappedType(sizeof = 4 * 4)
@MappedType
public static class Sprite extends MappedObject {
public float x, y;
public float dx, dy;
public float x, dx;
public float y, dy;
}
@MappedType(sizeof = 2 * 4)
@MappedType
public static class SpriteRender extends MappedObject {
public float x, y;
@ -536,12 +536,15 @@ public final class SpriteShootoutMapped {
x += dx * delta;
if ( x < ballRadius ) {
x = ballRadius;
sprites[b].dx = -dx;
dx = -dx;
} else if ( x > boundW ) {
x = boundW;
sprites[b].dx = -dx;
dx = -dx;
}
sprites[b].x = x;
sprites[b].dx = dx;
spritesRender[r].x = x;
float y = sprites[b].y;
float dy = sprites[b].dy;
@ -549,14 +552,14 @@ public final class SpriteShootoutMapped {
y += dy * delta;
if ( y < ballRadius ) {
y = ballRadius;
sprites[b].dy = -dy;
dy = -dy;
} else if ( y > boundH ) {
y = boundH;
sprites[b].dy = -dy;
dy = -dy;
}
sprites[b].y = y;
spritesRender[r].x = x;
sprites[b].y = y;
sprites[b].dy = dy;
spritesRender[r].y = y;
}
}