Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable dynamic block allocation. #4036

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.terasology.world.block.Block;
import org.terasology.world.block.BlockManager;
import org.terasology.world.block.family.SymmetricFamily;
import org.terasology.world.block.internal.BlockManagerImpl;
import org.terasology.world.block.loader.BlockFamilyDefinition;
import org.terasology.world.block.loader.BlockFamilyDefinitionData;
import org.terasology.world.chunks.Chunk;
Expand All @@ -75,6 +76,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -158,6 +160,7 @@ public void setup() throws Exception {
data.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("test:testblock"), data, BlockFamilyDefinition.class);
assetManager.loadAsset(new ResourceUrn("test:testblock2"), data, BlockFamilyDefinition.class);
((BlockManagerImpl)blockManager).initialise(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
testBlock = context.get(BlockManager.class).getBlock("test:testblock");
testBlock2 = context.get(BlockManager.class).getBlock("test:testblock2");

Expand Down
12 changes: 7 additions & 5 deletions engine-tests/src/test/java/org/terasology/world/ChunkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.terasology.world.chunks.blockdata.ExtraBlockDataManager;
import org.terasology.world.chunks.internal.ChunkImpl;

import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ChunkTest extends TerasologyTestingEnvironment {
Expand All @@ -50,20 +52,20 @@ public class ChunkTest extends TerasologyTestingEnvironment {
public void setup() throws Exception {
super.setup();
AssetManager assetManager = CoreRegistry.get(AssetManager.class);
blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
CoreRegistry.put(BlockManager.class, blockManager);

ExtraBlockDataManager extraDataManager = new ExtraBlockDataManager();

chunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, extraDataManager);

BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
solidData.getBaseSection().setDisplayName("Stone");
solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
solidData.getBaseSection().setTranslucent(false);
solidData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
blockManager.initialise(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
CoreRegistry.put(BlockManager.class, blockManager);
solid = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));

chunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, extraDataManager);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,32 @@
import org.terasology.world.internal.ChunkViewCoreImpl;

import java.io.IOException;
import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ChunkViewTest extends TerasologyTestingEnvironment {

Block airBlock;
Block solidBlock;
private BlockManager blockManager;
private BlockManagerImpl blockManager;
private ExtraBlockDataManager extraDataManager;

@BeforeEach
public void setup() throws IOException {
AssetManager assetManager = CoreRegistry.get(AssetManager.class);
blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
CoreRegistry.put(BlockManager.class, blockManager);
airBlock = blockManager.getBlock(BlockManager.AIR_ID);

extraDataManager = new ExtraBlockDataManager();

BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
solidData.getBaseSection().setDisplayName("Stone");
solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
solidData.getBaseSection().setTranslucent(false);
solidData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
blockManager.initialise(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
CoreRegistry.put(BlockManager.class, blockManager);
airBlock = blockManager.getBlock(BlockManager.AIR_ID);
solidBlock = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@
import org.terasology.world.block.family.BlockFamily;
import org.terasology.world.block.family.HorizontalFamily;
import org.terasology.world.block.family.SymmetricFamily;
import org.terasology.world.block.internal.BlockManagerImpl;
import org.terasology.world.block.loader.BlockFamilyDefinition;
import org.terasology.world.block.loader.BlockFamilyDefinitionData;
import org.terasology.world.internal.EntityAwareWorldProvider;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;

Expand Down Expand Up @@ -91,38 +93,45 @@ public void setup() throws Exception {
AssetManager assetManager = context.get(AssetManager.class);
BlockManager blockManager = context.get(BlockManager.class);

airBlock = blockManager.getBlock(BlockManager.AIR_ID);

worldStub = new WorldProviderCoreStub(airBlock);
worldProvider = new EntityAwareWorldProvider(worldStub, context);

plainBlock = createBlock("test:plainblock", assetManager, blockManager);
createBlock("test:plainblock", assetManager);
prefabWithString = createPrefabWithString("test:prefabWithString", "Test", assetManager);
blockWithString = createBlockWithPrefab("test:blockWithString", prefabWithString, false, assetManager, blockManager);
keepActiveBlock = createBlockWithPrefab("test:keepActiveBlock", prefabWithString, true, assetManager, blockManager);
createBlockWithPrefab("test:blockWithString", prefabWithString, false, assetManager);
createBlockWithPrefab("test:keepActiveBlock", prefabWithString, true, assetManager);
Prefab prefabWithDifferentString = createPrefabWithString("test:prefabWithDifferentString", "Test2", assetManager);
blockWithDifferentString = createBlockWithPrefab("test:prefabWithDifferentString", prefabWithDifferentString, false, assetManager, blockManager);
createBlockWithPrefab("test:prefabWithDifferentString", prefabWithDifferentString, false, assetManager);

BlockFamily blockFamily = createBlockFamily("test:blockFamily", prefabWithString, assetManager, blockManager);
Iterator<Block> iterator = blockFamily.getBlocks().iterator();
blockInFamilyOne = iterator.next();
blockInFamilyTwo = iterator.next();
createBlockFamily("test:blockFamily", prefabWithString, assetManager);

PrefabData retainedPrefabData = new PrefabData();
retainedPrefabData.addComponent(new RetainedOnBlockChangeComponent(3));
Prefab retainedPrefab = assetManager.loadAsset(new ResourceUrn("test:retainedPrefab"), retainedPrefabData, Prefab.class);

blockWithRetainedComponent = createBlockWithPrefab("test:blockWithRetainedComponent", retainedPrefab, false, assetManager, blockManager);
createBlockWithPrefab("test:blockWithRetainedComponent", retainedPrefab, false, assetManager);

((BlockManagerImpl)blockManager).initialise(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
airBlock = blockManager.getBlock(BlockManager.AIR_ID);
plainBlock = blockManager.getBlock("test:plainblock");
blockWithString = blockManager.getBlock("test:blockWithString");
keepActiveBlock = blockManager.getBlock("test:keepActiveBlock");
blockWithDifferentString = blockManager.getBlock("test:prefabWithDifferentString");
BlockFamily blockFamily = blockManager.getBlockFamily("test:blockFamily");
Iterator<Block> iterator = blockFamily.getBlocks().iterator();
blockInFamilyOne = iterator.next();
blockInFamilyTwo = iterator.next();
blockWithRetainedComponent = blockManager.getBlock("test:blockWithRetainedComponent");

worldStub = new WorldProviderCoreStub(airBlock);
worldProvider = new EntityAwareWorldProvider(worldStub, context);

worldProvider.initialise();
}

private Block createBlockWithPrefab(String urn, Prefab prefab, boolean keepActive, AssetManager assetManager, BlockManager blockManager) {
private void createBlockWithPrefab(String urn, Prefab prefab, boolean keepActive, AssetManager assetManager) {
BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
data.setBlockFamily(SymmetricFamily.class);
data.getBaseSection().getEntity().setPrefab(prefab);
data.getBaseSection().getEntity().setKeepActive(keepActive);
assetManager.loadAsset(new ResourceUrn(urn), data, BlockFamilyDefinition.class);
return blockManager.getBlock(urn);
}

private Prefab createPrefabWithString(String urn, String text, AssetManager assetManager) {
Expand All @@ -131,20 +140,18 @@ private Prefab createPrefabWithString(String urn, String text, AssetManager asse
return assetManager.loadAsset(new ResourceUrn(urn), prefabData, Prefab.class);
}

private Block createBlock(String urn, AssetManager assetManager, BlockManager blockManager) {
private void createBlock(String urn, AssetManager assetManager) {
BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
data.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn(urn), data, BlockFamilyDefinition.class);
return blockManager.getBlock(urn);
}

private BlockFamily createBlockFamily(String urn, Prefab prefab, AssetManager assetManager, BlockManager blockManager) {
private void createBlockFamily(String urn, Prefab prefab, AssetManager assetManager) {
BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
data.setBlockFamily(HorizontalFamily.class);
data.getBaseSection().getEntity().setKeepActive(true);
data.getBaseSection().getEntity().setPrefab(prefab);
assetManager.loadAsset(new ResourceUrn(urn), data, BlockFamilyDefinition.class);
return blockManager.getBlockFamily(urn);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.terasology.world.chunks.internal.ChunkImpl;
import org.terasology.world.propagation.light.InternalLightProcessor;

import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class InternalLightGeneratorTest extends TerasologyTestingEnvironment {
Expand All @@ -43,27 +45,26 @@ public class InternalLightGeneratorTest extends TerasologyTestingEnvironment {
public void setup() throws Exception {
super.setup();
AssetManager assetManager = CoreRegistry.get(AssetManager.class);
blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
CoreRegistry.put(BlockManager.class, blockManager);
airBlock = blockManager.getBlock(BlockManager.AIR_ID);


extraDataManager = new ExtraBlockDataManager();

BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
solidData.getBaseSection().setDisplayName("Stone");
solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
solidData.getBaseSection().setTranslucent(false);
solidData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
solidBlock = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));

BlockFamilyDefinitionData fullLightData = new BlockFamilyDefinitionData();
fullLightData.getBaseSection().setDisplayName("Torch");
fullLightData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
fullLightData.getBaseSection().setLuminance(Chunks.MAX_LIGHT);
fullLightData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:torch"), fullLightData, BlockFamilyDefinition.class);

blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
((BlockManagerImpl)blockManager).initialise(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
CoreRegistry.put(BlockManager.class, blockManager);
airBlock = blockManager.getBlock(BlockManager.AIR_ID);
solidBlock = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
fullLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:torch")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.terasology.world.propagation.light.SunlightWorldView;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -63,16 +64,16 @@ public void setup() throws Exception {
AssetManager assetManager = CoreRegistry.get(AssetManager.class);

regenRules = new SunlightRegenPropagationRules();
blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager, true);
CoreRegistry.put(BlockManager.class, blockManager);
extraDataManager = new ExtraBlockDataManager();

BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
solidData.getBaseSection().setDisplayName("Stone");
solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
solidData.getBaseSection().setTranslucent(false);
solidData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager, true);
blockManager.initialise(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
CoreRegistry.put(BlockManager.class, blockManager);
solid = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));

regenWorldView = new SunlightRegenWorldView(provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.terasology.world.chunks.Chunks;
import org.terasology.world.propagation.light.LightPropagationRules;

import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class BulkLightPropagationTest extends TerasologyTestingEnvironment {
Expand All @@ -60,53 +62,50 @@ public void setup() throws Exception {
super.setup();
lightRules = new LightPropagationRules();
AssetManager assetManager = CoreRegistry.get(AssetManager.class);
blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager, true);
CoreRegistry.put(BlockManager.class, blockManager);
BlockFamilyDefinitionData fullLightData = new BlockFamilyDefinitionData();
fullLightData.getBaseSection().setDisplayName("Torch");
fullLightData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
fullLightData.getBaseSection().setLuminance(Chunks.MAX_LIGHT);
fullLightData.getBaseSection().setTranslucent(true);
fullLightData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:torch"), fullLightData, BlockFamilyDefinition.class);
fullLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:torch")));

BlockFamilyDefinitionData weakLightData = new BlockFamilyDefinitionData();
weakLightData.getBaseSection().setDisplayName("PartLight");
weakLightData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
weakLightData.getBaseSection().setLuminance((byte) 2);
weakLightData.getBaseSection().setTranslucent(true);
weakLightData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:weakLight"), weakLightData, BlockFamilyDefinition.class);
weakLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:weakLight")));

BlockFamilyDefinitionData mediumLightData = new BlockFamilyDefinitionData();
mediumLightData.getBaseSection().setDisplayName("MediumLight");
mediumLightData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
mediumLightData.getBaseSection().setLuminance((byte) 5);
mediumLightData.getBaseSection().setTranslucent(true);
mediumLightData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:mediumLight"), mediumLightData, BlockFamilyDefinition.class);
mediumLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:mediumLight")));

BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
solidData.getBaseSection().setDisplayName("Stone");
solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
solidData.getBaseSection().setTranslucent(false);
solidData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
solid = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));

BlockFamilyDefinitionData solidMediumLightData = new BlockFamilyDefinitionData();
solidMediumLightData.getBaseSection().setDisplayName("SolidMediumLight");
solidMediumLightData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
solidMediumLightData.getBaseSection().setTranslucent(false);
solidMediumLightData.getBaseSection().setLuminance((byte) 5);
solidMediumLightData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:solidMediumLight"), solidMediumLightData,
BlockFamilyDefinition.class);
solidMediumLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:solidMediumLight")));
assetManager.loadAsset(new ResourceUrn("engine:solidMediumLight"), solidMediumLightData, BlockFamilyDefinition.class);

blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager, true);
blockManager.initialise(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
CoreRegistry.put(BlockManager.class, blockManager);

fullLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:torch")));
weakLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:weakLight")));
mediumLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:mediumLight")));
solid = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
solidMediumLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:solidMediumLight")));
air = blockManager.getBlock(BlockManager.AIR_ID);
}

Expand Down
Loading