Search in sources :

Example 6 with ReadyChunkInfo

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

the class LocalChunkProviderTest method testCompleteUpdateRestoresEntitiesForRestoredChunks.

@Test
public void testCompleteUpdateRestoresEntitiesForRestoredChunks() throws Exception {
    final Chunk chunk = mockChunkAt(0, 0, 0);
    final ChunkStore chunkStore = mock(ChunkStore.class);
    final ReadyChunkInfo readyChunkInfo = ReadyChunkInfo.createForRestoredChunk(chunk, new TShortObjectHashMap<>(), chunkStore, Collections.emptyList());
    when(chunkFinalizer.completeFinalization()).thenReturn(readyChunkInfo);
    chunkProvider.completeUpdate();
    verify(chunkStore).restoreEntities();
}
Also used : ReadyChunkInfo(org.terasology.world.chunks.internal.ReadyChunkInfo) Chunk(org.terasology.world.chunks.Chunk) ChunkStore(org.terasology.persistence.ChunkStore) Test(org.junit.Test)

Example 7 with ReadyChunkInfo

use of org.terasology.world.chunks.internal.ReadyChunkInfo 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 8 with ReadyChunkInfo

use of org.terasology.world.chunks.internal.ReadyChunkInfo 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 9 with ReadyChunkInfo

use of org.terasology.world.chunks.internal.ReadyChunkInfo 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 10 with ReadyChunkInfo

use of org.terasology.world.chunks.internal.ReadyChunkInfo 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

ReadyChunkInfo (org.terasology.world.chunks.internal.ReadyChunkInfo)10 Chunk (org.terasology.world.chunks.Chunk)9 Test (org.junit.Test)7 EntityRef (org.terasology.entitySystem.entity.EntityRef)4 ChunkStore (org.terasology.persistence.ChunkStore)4 TIntList (gnu.trove.list.TIntList)2 TShortObjectHashMap (gnu.trove.map.hash.TShortObjectHashMap)2 EntityStore (org.terasology.entitySystem.entity.EntityStore)2 Event (org.terasology.entitySystem.event.Event)2 Vector3i (org.terasology.math.geom.Vector3i)2 ManagedChunk (org.terasology.world.chunks.ManagedChunk)2 TShortObjectMap (gnu.trove.map.TShortObjectMap)1 InOrder (org.mockito.InOrder)1 Prefab (org.terasology.entitySystem.prefab.Prefab)1 OnActivatedBlocks (org.terasology.world.block.OnActivatedBlocks)1 OnAddedBlocks (org.terasology.world.block.OnAddedBlocks)1 BeforeChunkUnload (org.terasology.world.chunks.event.BeforeChunkUnload)1 OnChunkGenerated (org.terasology.world.chunks.event.OnChunkGenerated)1 OnChunkLoaded (org.terasology.world.chunks.event.OnChunkLoaded)1 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)1