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 5 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 @@ -49,19 +49,17 @@ 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);
CoreRegistry.put(BlockManager.class, blockManager);
solid = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ public class ChunkViewTest extends TerasologyTestingEnvironment {
@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);
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 @@ -55,27 +55,22 @@ 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(ChunkConstants.MAX_LIGHT);
fullLightData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:torch"), fullLightData, BlockFamilyDefinition.class);

blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
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 @@ -76,16 +76,14 @@ 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);
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 @@ -61,52 +61,43 @@ 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(ChunkConstants.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")));

blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager, true);
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ public void setup() throws Exception {

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

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);
CoreRegistry.put(BlockManager.class, blockManager);
solid = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));

air = blockManager.getBlock(BlockManager.AIR_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@

import org.terasology.context.Context;
import org.terasology.engine.modes.SingleStepLoadProcess;
import org.terasology.entitySystem.Component;
import org.terasology.entitySystem.entity.EntityBuilder;
import org.terasology.entitySystem.entity.EntityManager;
import org.terasology.entitySystem.entity.EntityRef;
import org.terasology.entitySystem.prefab.Prefab;
import org.terasology.entitySystem.prefab.PrefabManager;
import org.terasology.network.NetworkComponent;
import org.terasology.world.block.Block;
import org.terasology.world.block.BlockManager;
import org.terasology.world.block.family.BlockFamily;
import org.terasology.world.block.internal.BlockManagerImpl;
import org.terasology.world.block.typeEntity.BlockTypeEntityGenerator;
import org.terasology.world.block.typeEntity.BlockTypeComponent;

import java.util.Optional;

public class InitialiseBlockTypeEntities extends SingleStepLoadProcess {

Expand All @@ -38,7 +48,38 @@ public String getMessage() {
@Override
public boolean step() {
BlockManagerImpl blockManager = (BlockManagerImpl) context.get(BlockManager.class);
blockManager.subscribe(new BlockTypeEntityGenerator(context.get(EntityManager.class), blockManager));
EntityManager entityManager = context.get(EntityManager.class);
Prefab blockTypePrefab = entityManager.getPrefabManager().getPrefab("engine:blockType");

// connect existing entities
for (EntityRef entity : entityManager.getEntitiesWith(BlockTypeComponent.class)) {
BlockTypeComponent blockTypeComp = entity.getComponent(BlockTypeComponent.class);
if (blockTypeComp.block == null) {
entity.destroy();
} else {
blockTypeComp.block.setEntity(entity);
}
}

// generate for existing blocks
for (BlockFamily blockFamily : blockManager.listRegisteredBlockFamilies()) {
for (Block block : blockFamily.getBlocks()) {
if (!block.getEntity().exists()) {
EntityBuilder builder = entityManager.newBuilder(blockTypePrefab);
builder.getComponent(BlockTypeComponent.class).block = block;
// TODO: Copy across settings as necessary
Optional<Prefab> prefab = block.getPrefab();
if (prefab.isPresent()) {
for (Component comp : prefab.get().iterateComponents()) {
if (!(comp instanceof NetworkComponent)) {
builder.addComponent(entityManager.getComponentLibrary().copy(comp));
}
}
}
block.setEntity(builder.build());
}
}
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@

import org.terasology.context.Context;
import org.terasology.engine.modes.SingleStepLoadProcess;
import org.terasology.entitySystem.Component;
import org.terasology.entitySystem.entity.EntityManager;
import org.terasology.entitySystem.metadata.ComponentMetadata;
import org.terasology.entitySystem.prefab.Prefab;
import org.terasology.world.block.Block;
import org.terasology.world.block.BlockManager;
import org.terasology.world.block.family.BlockFamily;
import org.terasology.world.block.internal.BlockManagerImpl;
import org.terasology.world.block.internal.BlockPrefabManager;

import java.util.Optional;

/**
*/
Expand All @@ -40,7 +46,29 @@ public String getMessage() {
@Override
public boolean step() {
BlockManagerImpl blockManager = (BlockManagerImpl) context.get(BlockManager.class);
blockManager.subscribe(new BlockPrefabManager(context.get(EntityManager.class), blockManager));
EntityManager entityManager = context.get(EntityManager.class);

for (BlockFamily blockFamily : blockManager.listRegisteredBlockFamilies()) {
for (Block block : blockFamily.getBlocks()) {
Optional<Prefab> prefab = block.getPrefab();
boolean keepActive = block.isKeepActive();
boolean requiresLifecycleEvents = false;
if (prefab.isPresent()) {
for (Component comp : prefab.get().iterateComponents()) {
ComponentMetadata<?> metadata = entityManager.getComponentLibrary().getMetadata(comp.getClass());
if (metadata.isForceBlockActive()) {
keepActive = true;
break;
}
if (metadata.isBlockLifecycleEventsRequired()) {
requiresLifecycleEvents = true;
}
}
}
block.setKeepActive(keepActive);
block.setLifecycleEventsRequired(requiresLifecycleEvents && !keepActive);
}
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ public boolean step() {


BlockManagerImpl blockManager;
if (networkSystem.getMode().isAuthority()) {
blockManager = new BlockManagerImpl(atlas, context.get(AssetManager.class), true);
blockManager.subscribe(context.get(NetworkSystem.class));
} else {
blockManager = new BlockManagerImpl(atlas, context.get(AssetManager.class), false);
}
blockManager = new BlockManagerImpl(atlas, context.get(AssetManager.class), networkSystem.getMode().isAuthority());
context.put(BlockManager.class, blockManager);
context.get(TypeHandlerLibrary.class).addTypeHandler(Block.class, new BlockTypeHandler(blockManager));
context.get(TypeHandlerLibrary.class).addTypeHandler(BlockFamily.class, new BlockFamilyTypeHandler(blockManager));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
import org.terasology.network.exceptions.HostingFailedException;
import org.terasology.nui.Color;
import org.terasology.world.BlockEntityRegistry;
import org.terasology.world.block.internal.BlockRegistrationListener;
import org.terasology.world.chunks.remoteChunkProvider.RemoteChunkProvider;

/**
* Interface for the network system
*
*/
// TODO: Refactor the core gameplay components like the list of players into a separate system.
public interface NetworkSystem extends BlockRegistrationListener {
public interface NetworkSystem {

void host(int port, boolean dedicatedServer) throws HostingFailedException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,15 +987,4 @@ private <T> Map<Class<? extends T>, Integer> applySerializationInfo(List<NetData
void mockHost() {
mode = NetworkMode.DEDICATED_SERVER;
}

@Override
public void onBlockFamilyRegistered(BlockFamily family) {
if (mode.isServer()) {
for (NetClient client : netClientList) {
client.blockFamilyRegistered(family);
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ private void processMessages() {
if (message.hasTime()) {
time.updateTimeFromServer(message.getTime());
}
processBlockRegistrations(message);
processReceivedChunks(message);
processInvalidatedChunks(message);
processBlockChanges(message);
Expand Down Expand Up @@ -341,27 +340,6 @@ private void processReceivedChunks(NetData.NetMessage message) {
}
}

private void processBlockRegistrations(NetData.NetMessage message) {
for (NetData.BlockFamilyRegisteredMessage blockFamily : message.getBlockFamilyRegisteredList()) {
if (blockFamily.getBlockIdCount() != blockFamily.getBlockUriCount()) {
logger.error("Received block registration with mismatched id<->uri mapping");
} else if (blockFamily.getBlockUriCount() == 0) {
logger.error("Received empty block registration");
} else {
try {
BlockUri family = new BlockUri(blockFamily.getBlockUri(0)).getFamilyUri();
Map<String, Integer> registrationMap = Maps.newHashMap();
for (int i = 0; i < blockFamily.getBlockIdCount(); ++i) {
registrationMap.put(blockFamily.getBlockUri(i), blockFamily.getBlockId(i));
}
blockManager.receiveFamilyRegistration(family, registrationMap);
} catch (BlockUriParseException e) {
logger.error("Received invalid block uri {}", blockFamily.getBlockUri(0));
}
}
}
}

private void updateEntity(NetData.UpdateEntityMessage updateEntity) {
EntityRef currentEntity = networkSystem.getEntity(updateEntity.getNetId());
if (currentEntity.exists()) {
Expand Down
Loading