Search in sources :

Example 1 with IComponent

use of ilargia.entitas.api.IComponent in project Entitas-Java by Rubentxu.

the class Entity method replaceComponentInternal.

private void replaceComponentInternal(int index, IComponent replacement) {
    IComponent previousComponent = _components[index];
    if (replacement != previousComponent) {
        _components[index] = replacement;
        _componentsCache = null;
        if (replacement != null) {
            notifyComponentReplaced(index, previousComponent, replacement);
        } else {
            _componentIndicesCache = null;
            notifyComponentRemoved(index, previousComponent);
        }
        getComponentPool(index).push(previousComponent);
    } else {
        notifyComponentReplaced(index, previousComponent, replacement);
    }
}
Also used : IComponent(ilargia.entitas.api.IComponent)

Example 2 with IComponent

use of ilargia.entitas.api.IComponent in project Entitas-Java by Rubentxu.

the class Entity method getComponents.

@Override
public IComponent[] getComponents() {
    if (_componentsCache == null) {
        List<IComponent> componentsCache = EntitasCache.getIComponentList();
        for (int i = 0; i < _components.length; i++) {
            IComponent component = _components[i];
            if (component != null) {
                componentsCache.add(component);
            }
        }
        _componentsCache = new IComponent[componentsCache.size()];
        componentsCache.toArray(_componentsCache);
        EntitasCache.pushIComponentList(componentsCache);
    }
    return _componentsCache;
}
Also used : IComponent(ilargia.entitas.api.IComponent)

Example 3 with IComponent

use of ilargia.entitas.api.IComponent in project Entitas-Java by Rubentxu.

the class ContextTest method updateGroupsComponentReplacedTest.

@Test
public void updateGroupsComponentReplacedTest() {
    Position position = new Position();
    Position position2 = new Position();
    Group<TestEntity> groupE = context.getGroup(TestMatcher.Position());
    groupE.OnEntityUpdated((IGroup<TestEntity> group, final TestEntity entity, int index, IComponent previousComponent, IComponent nc) -> {
        System.out.println("Removed...........");
        assertEquals(position2, nc);
    });
    entity.addComponent(TestComponentIds.Position, position);
    context.updateGroupsComponentReplaced(entity, TestComponentIds.Position, position, position2, context._groupsForIndex);
}
Also used : TestEntity(ilargia.entitas.utils.TestEntity) Position(ilargia.entitas.components.Position) IComponent(ilargia.entitas.api.IComponent) IGroup(ilargia.entitas.api.IGroup) Test(org.junit.Test)

Example 4 with IComponent

use of ilargia.entitas.api.IComponent in project Entitas-Java by Rubentxu.

the class SceneManagerGDX method initialize.

@Override
public void initialize() {
    if (engine.getManager(PhysicsManagerGDX.class) == null)
        throw new EntitasException("SceneManagerGDX", "SceneManagerGDX needs load PhysicsManagerGDX on the engine");
    physics = engine.getManager(PhysicsManagerGDX.class);
    rayHandler = new RayHandler(physics.getPhysics());
    PreferencesManagerGDX preferences = engine.getManager(PreferencesManagerGDX.class);
    rayHandler.setAmbientLight(preferences.AMBIENT_LIGHT);
    rayHandler.setBlur(preferences.BLUR);
    rayHandler.setCulling(preferences.CULLING);
    rayHandler.setGammaCorrection(preferences.GAMMA_CORRECTION);
    rayHandler.setBlurNum(preferences.BLUR_NUM);
    rayHandler.setShadows(preferences.SHADOWS);
    rayHandler.useDiffuseLight(preferences.USE_DIFFUSE_LIGHT);
    //rayHandler.update();
    AssetsManagerGDX assetsManager = engine.getManager(AssetsManagerGDX.class);
    for (EntityFactory factory : entityFactories.values()) {
        factory.loadAssets(engine);
    }
    assetsManager.finishLoading();
    addLightFactory(PointLight.class, (SceneManager sceneManager, IComponent c) -> {
        CPointLight component = (CPointLight) c;
        return new PointLight(rayHandler, component.raysNum, component.color, component.distance, component.position.x, component.position.y);
    });
    addLightFactory(DirectionalLight.class, (SceneManager sceneManager, IComponent c) -> {
        LogManagerGDX.debug("SceneManager", "create directional ligth");
        CDirectionalLight component = (CDirectionalLight) c;
        return new DirectionalLight(rayHandler, component.raysNum, component.color, component.direcction);
    });
    addLightFactory(ChainLight.class, (SceneManager sceneManager, IComponent c) -> {
        LogManagerGDX.debug("SceneManager", "create ChainLight");
        CChainLight component = (CChainLight) c;
        return new ChainLight(rayHandler, component.raysNum, component.color, component.distance, component.rayDirecction, component.chain);
    });
    addLightFactory(ConeLight.class, (SceneManager sceneManager, IComponent c) -> {
        LogManagerGDX.debug("SceneManager", "create ConeLight");
        CConeLight component = (CConeLight) c;
        return new ConeLight(rayHandler, component.raysNum, component.color, component.distance, component.position.x, component.position.y, component.directionDegree, component.coneDegree);
    });
}
Also used : CConeLight(ilargia.egdx.logicbricks.component.scene.CConeLight) SceneManager(ilargia.egdx.api.managers.SceneManager) IComponent(ilargia.entitas.api.IComponent) CChainLight(ilargia.egdx.logicbricks.component.scene.CChainLight) CChainLight(ilargia.egdx.logicbricks.component.scene.CChainLight) CDirectionalLight(ilargia.egdx.logicbricks.component.scene.CDirectionalLight) CConeLight(ilargia.egdx.logicbricks.component.scene.CConeLight) EntitasException(ilargia.entitas.api.entitas.EntitasException) CPointLight(ilargia.egdx.logicbricks.component.scene.CPointLight) CPointLight(ilargia.egdx.logicbricks.component.scene.CPointLight) EntityFactory(ilargia.egdx.api.factories.EntityFactory) CDirectionalLight(ilargia.egdx.logicbricks.component.scene.CDirectionalLight)

Example 5 with IComponent

use of ilargia.entitas.api.IComponent in project Entitas-Java by Rubentxu.

the class ContextTest method clearComponentPoolTest.

@Test
public void clearComponentPoolTest() {
    Stack[] cpool = context.getComponentPools();
    cpool[0] = new Stack<IComponent>();
    cpool[0].push(new Position());
    assertEquals(1, cpool[0].size());
    context.clearComponentPool(0);
    assertTrue(cpool[0].empty());
}
Also used : Position(ilargia.entitas.components.Position) IComponent(ilargia.entitas.api.IComponent) Test(org.junit.Test)

Aggregations

IComponent (ilargia.entitas.api.IComponent)8 Test (org.junit.Test)5 Position (ilargia.entitas.components.Position)4 IEntity (ilargia.entitas.api.entitas.IEntity)2 EntityFactory (ilargia.egdx.api.factories.EntityFactory)1 SceneManager (ilargia.egdx.api.managers.SceneManager)1 CChainLight (ilargia.egdx.logicbricks.component.scene.CChainLight)1 CConeLight (ilargia.egdx.logicbricks.component.scene.CConeLight)1 CDirectionalLight (ilargia.egdx.logicbricks.component.scene.CDirectionalLight)1 CPointLight (ilargia.egdx.logicbricks.component.scene.CPointLight)1 IGroup (ilargia.entitas.api.IGroup)1 EntitasException (ilargia.entitas.api.entitas.EntitasException)1 Motion (ilargia.entitas.components.Motion)1 TestEntity (ilargia.entitas.utils.TestEntity)1