Search in sources :

Example 31 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class StorageManagerTest method testPlayerRelevanceLocationSurvivesStorage.

@Test
public void testPlayerRelevanceLocationSurvivesStorage() {
    Vector3f loc = new Vector3f(1, 2, 3);
    character.addComponent(new LocationComponent(loc));
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    PlayerStore restored = esm.loadPlayerStore(PLAYER_ID);
    assertEquals(loc, restored.getRelevanceLocation());
}
Also used : PlayerStore(org.terasology.engine.persistence.PlayerStore) Vector3f(org.joml.Vector3f) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Test(org.junit.jupiter.api.Test)

Example 32 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class StorageManagerTest method testEntitySurvivesStorageInChunkStore.

@Test
public void testEntitySurvivesStorageInChunkStore() throws Exception {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, extraDataManager);
    chunk.setBlock(0, 0, 0, testBlock);
    chunk.markReady();
    ChunkProvider chunkProvider = mock(ChunkProvider.class);
    when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
    CoreRegistry.put(ChunkProvider.class, chunkProvider);
    EntityRef entity = entityManager.create();
    long id = entity.getId();
    LocationComponent locationComponent = new LocationComponent();
    AABBfc aabb = chunk.getAABB();
    Vector3f positionInChunk = new Vector3f(aabb.minX(), aabb.minY(), aabb.minZ());
    positionInChunk.x += 1;
    positionInChunk.y += 1;
    positionInChunk.z += 1;
    locationComponent.setWorldPosition(positionInChunk);
    entity.addComponent(locationComponent);
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    newSM.loadGlobalStore();
    ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
    restored.restoreEntities();
    EntityRef ref = newEntityManager.getEntity(id);
    assertTrue(ref.exists());
    assertTrue(ref.isActive());
}
Also used : AABBfc(org.terasology.joml.geom.AABBfc) EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3f(org.joml.Vector3f) StorageManager(org.terasology.engine.persistence.StorageManager) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ChunkStore(org.terasology.engine.persistence.ChunkStore) Test(org.junit.jupiter.api.Test)

Example 33 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class StorageManagerTest method testGetUnstoredPlayerReturnsNewStor.

@Test
@Order(1)
public void testGetUnstoredPlayerReturnsNewStor() {
    PlayerStore store = esm.loadPlayerStore(PLAYER_ID);
    assertNotNull(store);
    assertEquals(new Vector3f(), store.getRelevanceLocation());
    assertFalse(store.hasCharacter());
    assertEquals(PLAYER_ID, store.getId());
}
Also used : PlayerStore(org.terasology.engine.persistence.PlayerStore) Vector3f(org.joml.Vector3f) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 34 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class VertexResourceTest method testInterleave.

@Test
public void testInterleave() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
    VertexByteAttributeBinding a2 = builder.add(0, GLAttributes.BYTE_1_VERTEX_ATTRIBUTE);
    VertexResource resource = builder.build();
    a1.put(new Vector3f(10, 0, -4));
    a2.put(UnsignedBytes.checkedCast(2));
    a2.put(UnsignedBytes.checkedCast(10));
    assertEquals(2, a2.getPosition());
    assertEquals(1, a1.getPosition());
    int stride = (Float.BYTES * 3) + Byte.BYTES;
    resource.writeBuffer(buffer -> {
        assertEquals(buffer.limit(), stride * 2);
        assertEquals(10, buffer.getFloat((0 * Float.BYTES)), 0.001f);
        assertEquals(0, buffer.getFloat((1 * Float.BYTES)), 0.001f);
        assertEquals(-4, buffer.getFloat(2 * Float.BYTES), 0.001f);
        assertEquals(2, buffer.get((3 * Float.BYTES)));
        assertEquals(0, buffer.getFloat(stride + (0 * Float.BYTES)), 0.001f);
        assertEquals(0, buffer.getFloat(stride + (1 * Float.BYTES)), 0.001f);
        assertEquals(0, buffer.getFloat(stride + (2 * Float.BYTES)), 0.001f);
        assertEquals(10, buffer.get(stride + (3 * Float.BYTES)));
    });
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) Vector3fc(org.joml.Vector3fc) VertexByteAttributeBinding(org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Vector3f(org.joml.Vector3f) Test(org.junit.Test)

Example 35 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class VertexResourceTest method testReplaceBufferedResource.

@Test
public void testReplaceBufferedResource() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
    VertexResource firstResource = builder.build();
    a1.put(new Vector3f(12.0f, 0.0f, 13.0f));
    a1.put(new Vector3f(12.5f, 13f, 1.5f));
    builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector3fc, Vector3f> b2 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
    VertexResource secondResource = builder.build();
    b2.put(new Vector3f(13.0f, 0.0f, 1.5f));
    firstResource.replace(secondResource);
    assertEquals(1, a1.elements());
    VectorAssert.assertEquals(new Vector3f(13.0f, 0.0f, 1.5f), a1.get(0, new Vector3f()), .0001f);
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) Vector3fc(org.joml.Vector3fc) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Vector3f(org.joml.Vector3f) Test(org.junit.Test)

Aggregations

Vector3f (org.joml.Vector3f)261 LocationComponent (org.terasology.engine.logic.location.LocationComponent)50 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)49 Matrix4f (org.joml.Matrix4f)34 Quaternionf (org.joml.Quaternionf)29 Test (org.junit.jupiter.api.Test)20 Vector3i (org.joml.Vector3i)19 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)18 FloatBuffer (java.nio.FloatBuffer)17 ClientComponent (org.terasology.engine.network.ClientComponent)17 ByteBuffer (java.nio.ByteBuffer)16 Vector3fc (org.joml.Vector3fc)15 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)15 Vector2f (org.joml.Vector2f)13 Vector4f (org.joml.Vector4f)13 ArrayList (java.util.ArrayList)10 HitResult (org.terasology.engine.physics.HitResult)10 IOException (java.io.IOException)8 Test (org.junit.Test)8 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)8