Search in sources :

Example 36 with Chunk

use of org.terasology.world.chunks.Chunk in project Terasology by MovingBlocks.

the class LocalChunkProviderTest method mockChunkWithReadinessStateAt.

private static Chunk mockChunkWithReadinessStateAt(final int x, final int y, final int z) {
    final Chunk chunk = mockChunkAt(x, y, z);
    AtomicBoolean chunkReady = new AtomicBoolean();
    when(chunk.isReady()).thenAnswer(i -> chunkReady.get());
    doAnswer(i -> {
        chunkReady.set(true);
        return null;
    }).when(chunk).markReady();
    return chunk;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Chunk(org.terasology.world.chunks.Chunk)

Example 37 with Chunk

use of org.terasology.world.chunks.Chunk in project Terasology by MovingBlocks.

the class LocalChunkProviderTest method testCompleteUpdateGeneratesStoredEntitiesFromPrefab.

@Test
public void testCompleteUpdateGeneratesStoredEntitiesFromPrefab() throws Exception {
    final Chunk chunk = mockChunkAt(0, 0, 0);
    final Prefab prefab = mock(Prefab.class);
    final ChunkProviderTestComponent testComponent = new ChunkProviderTestComponent();
    final EntityStore entityStore = createEntityStoreWithPrefabAndComponents(prefab, testComponent);
    final List<EntityStore> entityStores = Collections.singletonList(entityStore);
    final ReadyChunkInfo readyChunkInfo = ReadyChunkInfo.createForNewChunk(chunk, new TShortObjectHashMap<>(), entityStores);
    when(chunkFinalizer.completeFinalization()).thenReturn(readyChunkInfo);
    final EntityRef mockEntity = mock(EntityRef.class);
    when(entityManager.create(any(Prefab.class))).thenReturn(mockEntity);
    chunkProvider.completeUpdate();
    verify(entityManager).create(eq(prefab));
    verify(mockEntity).addComponent(eq(testComponent));
}
Also used : ReadyChunkInfo(org.terasology.world.chunks.internal.ReadyChunkInfo) EntityStore(org.terasology.entitySystem.entity.EntityStore) Chunk(org.terasology.world.chunks.Chunk) Prefab(org.terasology.entitySystem.prefab.Prefab) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 38 with Chunk

use of org.terasology.world.chunks.Chunk in project Terasology by MovingBlocks.

the class LocalChunkProviderTest method testCompleteUpdateMarksChunkReady.

@Test
public void testCompleteUpdateMarksChunkReady() throws Exception {
    final Chunk chunk = mockChunkAt(0, 0, 0);
    final ReadyChunkInfo readyChunkInfo = ReadyChunkInfo.createForNewChunk(chunk, new TShortObjectHashMap<>(), Collections.emptyList());
    when(chunkFinalizer.completeFinalization()).thenReturn(readyChunkInfo);
    chunkProvider.completeUpdate();
    verify(chunk).markReady();
}
Also used : ReadyChunkInfo(org.terasology.world.chunks.internal.ReadyChunkInfo) Chunk(org.terasology.world.chunks.Chunk) Test(org.junit.Test)

Example 39 with Chunk

use of org.terasology.world.chunks.Chunk in project Terasology by MovingBlocks.

the class LocalChunkProviderTest method testCompleteUpdateHandlesFinalizedChunkIfReady.

@Test
public void testCompleteUpdateHandlesFinalizedChunkIfReady() throws Exception {
    final Chunk chunk = mockChunkAt(0, 0, 0);
    final ReadyChunkInfo readyChunkInfo = ReadyChunkInfo.createForNewChunk(chunk, new TShortObjectHashMap<>(), Collections.emptyList());
    when(chunkFinalizer.completeFinalization()).thenReturn(readyChunkInfo);
    chunkProvider.completeUpdate();
    final InOrder inOrderVerification = inOrder(worldEntity);
    inOrderVerification.verify(worldEntity).send(any(OnChunkGenerated.class));
    inOrderVerification.verify(worldEntity).send(any(OnChunkLoaded.class));
}
Also used : OnChunkLoaded(org.terasology.world.chunks.event.OnChunkLoaded) InOrder(org.mockito.InOrder) OnChunkGenerated(org.terasology.world.chunks.event.OnChunkGenerated) ReadyChunkInfo(org.terasology.world.chunks.internal.ReadyChunkInfo) Chunk(org.terasology.world.chunks.Chunk) Test(org.junit.Test)

Example 40 with Chunk

use of org.terasology.world.chunks.Chunk in project Terasology by MovingBlocks.

the class LocalChunkProviderTest method testCompleteUpdateGeneratesStoredEntities.

@Test
public void testCompleteUpdateGeneratesStoredEntities() throws Exception {
    final Chunk chunk = mockChunkAt(0, 0, 0);
    final ChunkProviderTestComponent testComponent = new ChunkProviderTestComponent();
    final EntityStore entityStore = createEntityStoreWithComponents(testComponent);
    final List<EntityStore> entityStores = Collections.singletonList(entityStore);
    final ReadyChunkInfo readyChunkInfo = ReadyChunkInfo.createForNewChunk(chunk, new TShortObjectHashMap<>(), entityStores);
    when(chunkFinalizer.completeFinalization()).thenReturn(readyChunkInfo);
    final EntityRef mockEntity = mock(EntityRef.class);
    when(entityManager.create()).thenReturn(mockEntity);
    chunkProvider.completeUpdate();
    verify(mockEntity).addComponent(eq(testComponent));
}
Also used : ReadyChunkInfo(org.terasology.world.chunks.internal.ReadyChunkInfo) EntityStore(org.terasology.entitySystem.entity.EntityStore) Chunk(org.terasology.world.chunks.Chunk) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Aggregations

Chunk (org.terasology.world.chunks.Chunk)50 Vector3i (org.terasology.math.geom.Vector3i)31 Test (org.junit.Test)28 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)18 ReadyChunkInfo (org.terasology.world.chunks.internal.ReadyChunkInfo)9 ManagedChunk (org.terasology.world.chunks.ManagedChunk)8 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 ChunkStore (org.terasology.persistence.ChunkStore)7 EntityRef (org.terasology.entitySystem.entity.EntityRef)5 ChunkViewCore (org.terasology.world.internal.ChunkViewCore)5 ChunkProvider (org.terasology.world.chunks.ChunkProvider)3 TIntList (gnu.trove.list.TIntList)2 TShortObjectHashMap (gnu.trove.map.hash.TShortObjectHashMap)2 EntityStore (org.terasology.entitySystem.entity.EntityStore)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 Event (org.terasology.entitySystem.event.Event)2 LocationComponent (org.terasology.logic.location.LocationComponent)2 Side (org.terasology.math.Side)2 StorageManager (org.terasology.persistence.StorageManager)2 Block (org.terasology.world.block.Block)2