Search in sources :

Example 1 with PojoEntityManager

use of org.terasology.entitySystem.entity.internal.PojoEntityManager in project Terasology by MovingBlocks.

the class ReadWriteStorageManager method createPrivateEntityManager.

private static EngineEntityManager createPrivateEntityManager(ComponentLibrary componentLibrary) {
    PojoEntityManager pojoEntityManager = new PojoEntityManager();
    pojoEntityManager.setComponentLibrary(componentLibrary);
    pojoEntityManager.setTypeSerializerLibrary(CoreRegistry.get(TypeSerializationLibrary.class));
    return pojoEntityManager;
}
Also used : PojoEntityManager(org.terasology.entitySystem.entity.internal.PojoEntityManager) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary)

Example 2 with PojoEntityManager

use of org.terasology.entitySystem.entity.internal.PojoEntityManager in project Terasology by MovingBlocks.

the class IterateMultipleComponentBenchmark method setup.

@Override
public void setup() {
    FastRandom rand = new FastRandom(0L);
    rawEntityData = Lists.newArrayList();
    for (int i = 0; i < 1000; ++i) {
        List<Component> entityData = Lists.newArrayList();
        if (rand.nextFloat() < 0.75f) {
            entityData.add(new LocationComponent());
        }
        if (rand.nextFloat() < 0.5f) {
            entityData.add(new MeshComponent());
        }
        if (rand.nextFloat() < 0.25f) {
            entityData.add(new BlockComponent());
        }
        rawEntityData.add(entityData);
    }
    entityManager = new PojoEntityManager();
    for (List<Component> rawEntity : rawEntityData) {
        entityManager.create(rawEntity);
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) MeshComponent(org.terasology.rendering.logic.MeshComponent) PojoEntityManager(org.terasology.entitySystem.entity.internal.PojoEntityManager) FastRandom(org.terasology.utilities.random.FastRandom) MeshComponent(org.terasology.rendering.logic.MeshComponent) BlockComponent(org.terasology.world.block.BlockComponent) Component(org.terasology.entitySystem.Component) LocationComponent(org.terasology.logic.location.LocationComponent) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 3 with PojoEntityManager

use of org.terasology.entitySystem.entity.internal.PojoEntityManager in project Terasology by MovingBlocks.

the class EntitySystemSetupUtil method addEntityManagementRelatedClasses.

/**
 * Objects for the following classes must be available in the context:
 * <ul>
 * <li>{@link ModuleEnvironment}</li>
 * <li>{@link NetworkSystem}</li>
 * <li>{@link ReflectFactory}</li>
 * <li>{@link CopyStrategyLibrary}</li>
 * <li>{@link org.terasology.persistence.typeHandling.TypeSerializationLibrary}</li>
 * </ul>
 * <p>
 * The method will make objects for the following classes available in the context:
 * <ul>
 * <li>{@link EngineEntityManager}</li>
 * <li>{@link ComponentLibrary}</li>
 * <li>{@link EventLibrary}</li>
 * <li>{@link PrefabManager}</li>
 * <li>{@link EventSystem}</li>
 * </ul>
 */
public static void addEntityManagementRelatedClasses(Context context) {
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    NetworkSystem networkSystem = context.get(NetworkSystem.class);
    // Entity Manager
    PojoEntityManager entityManager = new PojoEntityManager();
    context.put(EntityManager.class, entityManager);
    context.put(EngineEntityManager.class, entityManager);
    // Standard serialization library
    TypeSerializationLibrary typeSerializationLibrary = context.get(TypeSerializationLibrary.class);
    typeSerializationLibrary.add(EntityRef.class, new EntityRefTypeHandler(entityManager));
    entityManager.setTypeSerializerLibrary(typeSerializationLibrary);
    // Prefab Manager
    PrefabManager prefabManager = new PojoPrefabManager(context);
    entityManager.setPrefabManager(prefabManager);
    context.put(PrefabManager.class, prefabManager);
    EntitySystemLibrary library = context.get(EntitySystemLibrary.class);
    entityManager.setComponentLibrary(library.getComponentLibrary());
    // Event System
    EventSystem eventSystem = new EventSystemImpl(library.getEventLibrary(), networkSystem);
    entityManager.setEventSystem(eventSystem);
    context.put(EventSystem.class, eventSystem);
    // TODO: Review - NodeClassLibrary related to the UI for behaviours. Should not be here and probably not even in the CoreRegistry
    context.put(OneOfProviderFactory.class, new OneOfProviderFactory());
    registerComponents(library.getComponentLibrary(), environment);
    registerEvents(entityManager.getEventSystem(), environment);
}
Also used : OneOfProviderFactory(org.terasology.rendering.nui.properties.OneOfProviderFactory) PojoPrefabManager(org.terasology.entitySystem.prefab.internal.PojoPrefabManager) ModuleEnvironment(org.terasology.module.ModuleEnvironment) EntitySystemLibrary(org.terasology.entitySystem.metadata.EntitySystemLibrary) PojoEntityManager(org.terasology.entitySystem.entity.internal.PojoEntityManager) PojoPrefabManager(org.terasology.entitySystem.prefab.internal.PojoPrefabManager) PrefabManager(org.terasology.entitySystem.prefab.PrefabManager) NetworkSystem(org.terasology.network.NetworkSystem) EntityRefTypeHandler(org.terasology.persistence.typeHandling.extensionTypes.EntityRefTypeHandler) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) ModuleManager(org.terasology.engine.module.ModuleManager) EventSystemImpl(org.terasology.entitySystem.event.internal.EventSystemImpl)

Example 4 with PojoEntityManager

use of org.terasology.entitySystem.entity.internal.PojoEntityManager in project Terasology by MovingBlocks.

the class PojoEventSystemTests method setup.

@Before
public void setup() {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    ReflectFactory reflectFactory = new ReflectionReflectFactory();
    CopyStrategyLibrary copyStrategies = new CopyStrategyLibrary(reflectFactory);
    TypeSerializationLibrary serializationLibrary = new TypeSerializationLibrary(reflectFactory, copyStrategies);
    EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, serializationLibrary);
    compLibrary = entitySystemLibrary.getComponentLibrary();
    entityManager = new PojoEntityManager();
    entityManager.setComponentLibrary(entitySystemLibrary.getComponentLibrary());
    entityManager.setPrefabManager(new PojoPrefabManager(context));
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    eventSystem = new EventSystemImpl(entitySystemLibrary.getEventLibrary(), networkSystem);
    entityManager.setEventSystem(eventSystem);
    entity = entityManager.create();
}
Also used : ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) PojoPrefabManager(org.terasology.entitySystem.prefab.internal.PojoPrefabManager) EntitySystemLibrary(org.terasology.entitySystem.metadata.EntitySystemLibrary) PojoEntityManager(org.terasology.entitySystem.entity.internal.PojoEntityManager) NetworkSystem(org.terasology.network.NetworkSystem) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) ContextImpl(org.terasology.context.internal.ContextImpl) EventSystemImpl(org.terasology.entitySystem.event.internal.EventSystemImpl) Before(org.junit.Before)

Example 5 with PojoEntityManager

use of org.terasology.entitySystem.entity.internal.PojoEntityManager in project Terasology by MovingBlocks.

the class EntityCreateBenchmark method run.

@Override
public void run() {
    PojoEntityManager entityManager = new PojoEntityManager();
    rawEntityData.forEach(entityManager::create);
}
Also used : PojoEntityManager(org.terasology.entitySystem.entity.internal.PojoEntityManager)

Aggregations

PojoEntityManager (org.terasology.entitySystem.entity.internal.PojoEntityManager)6 TypeSerializationLibrary (org.terasology.persistence.typeHandling.TypeSerializationLibrary)3 Component (org.terasology.entitySystem.Component)2 EventSystemImpl (org.terasology.entitySystem.event.internal.EventSystemImpl)2 EntitySystemLibrary (org.terasology.entitySystem.metadata.EntitySystemLibrary)2 PojoPrefabManager (org.terasology.entitySystem.prefab.internal.PojoPrefabManager)2 LocationComponent (org.terasology.logic.location.LocationComponent)2 NetworkSystem (org.terasology.network.NetworkSystem)2 MeshComponent (org.terasology.rendering.logic.MeshComponent)2 FastRandom (org.terasology.utilities.random.FastRandom)2 BlockComponent (org.terasology.world.block.BlockComponent)2 Before (org.junit.Before)1 ContextImpl (org.terasology.context.internal.ContextImpl)1 ModuleManager (org.terasology.engine.module.ModuleManager)1 EventSystem (org.terasology.entitySystem.event.internal.EventSystem)1 PrefabManager (org.terasology.entitySystem.prefab.PrefabManager)1 ModuleEnvironment (org.terasology.module.ModuleEnvironment)1 EntityRefTypeHandler (org.terasology.persistence.typeHandling.extensionTypes.EntityRefTypeHandler)1 CopyStrategyLibrary (org.terasology.reflection.copy.CopyStrategyLibrary)1 ReflectFactory (org.terasology.reflection.reflect.ReflectFactory)1